Skip to content

Commit

Permalink
Merge tag 'for-3.11-rc1' of git://gitorious.org/linux-pwm/linux-pwm
Browse files Browse the repository at this point in the history
Pull pwm changes from Thierry Reding:
 "A new driver supports driving PWM signals using the TPU unit found on
  various Renesas SoCs.  Furthermore support is added for the NXP
  PCA9685 LED controller.  Another big chunk is the sysfs interface
  which has been in the works for quite some time.

  The remaining patches are a random assortment of cleanups and fixes"

* tag 'for-3.11-rc1' of git://gitorious.org/linux-pwm/linux-pwm:
  pwm: pwm-tiehrpwm: Use clk_enable/disable instead clk_prepare/unprepare.
  pwm: pca9685: Fix wrong argument to set MODE1_SLEEP bit
  pwm: renesas-tpu: Add MODULE_ALIAS to make module auto loading work
  pwm: renesas-tpu: fix return value check in tpu_probe()
  pwm: Add Renesas TPU PWM driver
  pwm: Add sysfs interface
  pwm: Fill in missing .owner fields
  pwm: add pca9685 driver
  pwm: atmel-tcb: prepare clk before calling enable
  pwm: devm: alloc correct pointer size
  pwm: mxs: Let device core handle pinctrl
  MAINTAINERS: Update PWM subsystem entry
  • Loading branch information
torvalds committed Jul 10, 2013
2 parents 7d3107d + b388f15 commit 34ae0a6
Show file tree
Hide file tree
Showing 21 changed files with 1,387 additions and 17 deletions.
79 changes: 79 additions & 0 deletions Documentation/ABI/testing/sysfs-class-pwm
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
What: /sys/class/pwm/
Date: May 2013
KernelVersion: 3.11
Contact: H Hartley Sweeten <hsweeten@visionengravers.com>
Description:
The pwm/ class sub-directory belongs to the Generic PWM
Framework and provides a sysfs interface for using PWM
channels.

What: /sys/class/pwm/pwmchipN/
Date: May 2013
KernelVersion: 3.11
Contact: H Hartley Sweeten <hsweeten@visionengravers.com>
Description:
A /sys/class/pwm/pwmchipN directory is created for each
probed PWM controller/chip where N is the base of the
PWM chip.

What: /sys/class/pwm/pwmchipN/npwm
Date: May 2013
KernelVersion: 3.11
Contact: H Hartley Sweeten <hsweeten@visionengravers.com>
Description:
The number of PWM channels supported by the PWM chip.

What: /sys/class/pwm/pwmchipN/export
Date: May 2013
KernelVersion: 3.11
Contact: H Hartley Sweeten <hsweeten@visionengravers.com>
Description:
Exports a PWM channel from the PWM chip for sysfs control.
Value is between 0 and /sys/class/pwm/pwmchipN/npwm - 1.

What: /sys/class/pwm/pwmchipN/unexport
Date: May 2013
KernelVersion: 3.11
Contact: H Hartley Sweeten <hsweeten@visionengravers.com>
Description:
Unexports a PWM channel.

What: /sys/class/pwm/pwmchipN/pwmX
Date: May 2013
KernelVersion: 3.11
Contact: H Hartley Sweeten <hsweeten@visionengravers.com>
Description:
A /sys/class/pwm/pwmchipN/pwmX directory is created for
each exported PWM channel where X is the exported PWM
channel number.

What: /sys/class/pwm/pwmchipN/pwmX/period
Date: May 2013
KernelVersion: 3.11
Contact: H Hartley Sweeten <hsweeten@visionengravers.com>
Description:
Sets the PWM signal period in nanoseconds.

What: /sys/class/pwm/pwmchipN/pwmX/duty_cycle
Date: May 2013
KernelVersion: 3.11
Contact: H Hartley Sweeten <hsweeten@visionengravers.com>
Description:
Sets the PWM signal duty cycle in nanoseconds.

What: /sys/class/pwm/pwmchipN/pwmX/polarity
Date: May 2013
KernelVersion: 3.11
Contact: H Hartley Sweeten <hsweeten@visionengravers.com>
Description:
Sets the output polarity of the PWM signal to "normal" or
"inversed".

What: /sys/class/pwm/pwmchipN/pwmX/enable
Date: May 2013
KernelVersion: 3.11
Contact: H Hartley Sweeten <hsweeten@visionengravers.com>
Description:
Enable/disable the PWM signal.
0 is disabled
1 is enabled
27 changes: 27 additions & 0 deletions Documentation/devicetree/bindings/pwm/nxp,pca9685-pwm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
NXP PCA9685 16-channel 12-bit PWM LED controller
================================================

Required properties:
- compatible: "nxp,pca9685-pwm"
- #pwm-cells: should be 2. The first cell specifies the per-chip index
of the PWM to use and the second cell is the period in nanoseconds.
The index 16 is the ALLCALL channel, that sets all PWM channels at the same
time.

Optional properties:
- invert (bool): boolean to enable inverted logic
- open-drain (bool): boolean to configure outputs with open-drain structure;
if omitted use totem-pole structure

Example:

For LEDs that are directly connected to the PCA, the following setting is
applicable:

pca: pca@41 {
compatible = "nxp,pca9685-pwm";
#pwm-cells = <2>;
reg = <0x41>;
invert;
open-drain;
};
37 changes: 37 additions & 0 deletions Documentation/pwm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,43 @@ int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns);

To start/stop toggling the PWM output use pwm_enable()/pwm_disable().

Using PWMs with the sysfs interface
-----------------------------------

If CONFIG_SYSFS is enabled in your kernel configuration a simple sysfs
interface is provided to use the PWMs from userspace. It is exposed at
/sys/class/pwm/. Each probed PWM controller/chip will be exported as
pwmchipN, where N is the base of the PWM chip. Inside the directory you
will find:

npwm - The number of PWM channels this chip supports (read-only).

export - Exports a PWM channel for use with sysfs (write-only).

unexport - Unexports a PWM channel from sysfs (write-only).

The PWM channels are numbered using a per-chip index from 0 to npwm-1.

When a PWM channel is exported a pwmX directory will be created in the
pwmchipN directory it is associated with, where X is the number of the
channel that was exported. The following properties will then be available:

period - The total period of the PWM signal (read/write).
Value is in nanoseconds and is the sum of the active and inactive
time of the PWM.

duty_cycle - The active time of the PWM signal (read/write).
Value is in nanoseconds and must be less than the period.

polarity - Changes the polarity of the PWM signal (read/write).
Writes to this property only work if the PWM chip supports changing
the polarity. The polarity can only be changed if the PWM is not
enabled. Value is the string "normal" or "inversed".

enable - Enable/disable the PWM signal (read/write).
0 - disabled
1 - enabled

Implementing a PWM driver
-------------------------

Expand Down
4 changes: 2 additions & 2 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -6568,8 +6568,8 @@ S: Maintained
F: drivers/media/usb/pwc/*

PWM SUBSYSTEM
M: Thierry Reding <thierry.reding@avionic-design.de>
L: linux-kernel@vger.kernel.org
M: Thierry Reding <thierry.reding@gmail.com>
L: linux-pwm@vger.kernel.org
S: Maintained
W: http://gitorious.org/linux-pwm
T: git git://gitorious.org/linux-pwm/linux-pwm.git
Expand Down
23 changes: 23 additions & 0 deletions drivers/pwm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ menuconfig PWM

if PWM

config PWM_SYSFS
bool
default y if SYSFS

config PWM_AB8500
tristate "AB8500 PWM support"
depends on AB8500_CORE && ARCH_U8500
Expand Down Expand Up @@ -97,6 +101,15 @@ config PWM_MXS
To compile this driver as a module, choose M here: the module
will be called pwm-mxs.

config PWM_PCA9685
tristate "NXP PCA9685 PWM driver"
depends on OF && REGMAP_I2C
help
Generic PWM framework driver for NXP PCA9685 LED controller.

To compile this driver as a module, choose M here: the module
will be called pwm-pca9685.

config PWM_PUV3
tristate "PKUnity NetBook-0916 PWM support"
depends on ARCH_PUV3
Expand All @@ -115,6 +128,16 @@ config PWM_PXA
To compile this driver as a module, choose M here: the module
will be called pwm-pxa.

config PWM_RENESAS_TPU
tristate "Renesas TPU PWM support"
depends on ARCH_SHMOBILE
help
This driver exposes the Timer Pulse Unit (TPU) PWM controller found
in Renesas chips through the PWM API.

To compile this driver as a module, choose M here: the module
will be called pwm-renesas-tpu.

config PWM_SAMSUNG
tristate "Samsung PWM support"
depends on PLAT_SAMSUNG
Expand Down
3 changes: 3 additions & 0 deletions drivers/pwm/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
obj-$(CONFIG_PWM) += core.o
obj-$(CONFIG_PWM_SYSFS) += sysfs.o
obj-$(CONFIG_PWM_AB8500) += pwm-ab8500.o
obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o
obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o
obj-$(CONFIG_PWM_IMX) += pwm-imx.o
obj-$(CONFIG_PWM_JZ4740) += pwm-jz4740.o
obj-$(CONFIG_PWM_LPC32XX) += pwm-lpc32xx.o
obj-$(CONFIG_PWM_MXS) += pwm-mxs.o
obj-$(CONFIG_PWM_PCA9685) += pwm-pca9685.o
obj-$(CONFIG_PWM_PUV3) += pwm-puv3.o
obj-$(CONFIG_PWM_PXA) += pwm-pxa.o
obj-$(CONFIG_PWM_RENESAS_TPU) += pwm-renesas-tpu.o
obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.o
obj-$(CONFIG_PWM_SPEAR) += pwm-spear.o
obj-$(CONFIG_PWM_TEGRA) += pwm-tegra.o
Expand Down
29 changes: 25 additions & 4 deletions drivers/pwm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ int pwmchip_add(struct pwm_chip *chip)
if (IS_ENABLED(CONFIG_OF))
of_pwmchip_add(chip);

pwmchip_sysfs_export(chip);

out:
mutex_unlock(&pwm_lock);
return ret;
Expand Down Expand Up @@ -310,6 +312,8 @@ int pwmchip_remove(struct pwm_chip *chip)

free_pwms(chip);

pwmchip_sysfs_unexport(chip);

out:
mutex_unlock(&pwm_lock);
return ret;
Expand Down Expand Up @@ -402,10 +406,19 @@ EXPORT_SYMBOL_GPL(pwm_free);
*/
int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
{
int err;

if (!pwm || duty_ns < 0 || period_ns <= 0 || duty_ns > period_ns)
return -EINVAL;

return pwm->chip->ops->config(pwm->chip, pwm, duty_ns, period_ns);
err = pwm->chip->ops->config(pwm->chip, pwm, duty_ns, period_ns);
if (err)
return err;

pwm->duty_cycle = duty_ns;
pwm->period = period_ns;

return 0;
}
EXPORT_SYMBOL_GPL(pwm_config);

Expand All @@ -418,6 +431,8 @@ EXPORT_SYMBOL_GPL(pwm_config);
*/
int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity)
{
int err;

if (!pwm || !pwm->chip->ops)
return -EINVAL;

Expand All @@ -427,7 +442,13 @@ int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity)
if (test_bit(PWMF_ENABLED, &pwm->flags))
return -EBUSY;

return pwm->chip->ops->set_polarity(pwm->chip, pwm, polarity);
err = pwm->chip->ops->set_polarity(pwm->chip, pwm, polarity);
if (err)
return err;

pwm->polarity = polarity;

return 0;
}
EXPORT_SYMBOL_GPL(pwm_set_polarity);

Expand Down Expand Up @@ -694,7 +715,7 @@ struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id)
{
struct pwm_device **ptr, *pwm;

ptr = devres_alloc(devm_pwm_release, sizeof(**ptr), GFP_KERNEL);
ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);

Expand Down Expand Up @@ -724,7 +745,7 @@ struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np,
{
struct pwm_device **ptr, *pwm;

ptr = devres_alloc(devm_pwm_release, sizeof(**ptr), GFP_KERNEL);
ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);

Expand Down
5 changes: 3 additions & 2 deletions drivers/pwm/pwm-atmel-tcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static int atmel_tcb_pwm_request(struct pwm_chip *chip,
if (!tcbpwm)
return -ENOMEM;

ret = clk_enable(tc->clk[group]);
ret = clk_prepare_enable(tc->clk[group]);
if (ret) {
devm_kfree(chip->dev, tcbpwm);
return ret;
Expand Down Expand Up @@ -124,7 +124,7 @@ static void atmel_tcb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
struct atmel_tcb_pwm_device *tcbpwm = pwm_get_chip_data(pwm);
struct atmel_tc *tc = tcbpwmc->tc;

clk_disable(tc->clk[pwm->hwpwm / 2]);
clk_disable_unprepare(tc->clk[pwm->hwpwm / 2]);
tcbpwmc->pwms[pwm->hwpwm] = NULL;
devm_kfree(chip->dev, tcbpwm);
}
Expand Down Expand Up @@ -434,6 +434,7 @@ MODULE_DEVICE_TABLE(of, atmel_tcb_pwm_dt_ids);
static struct platform_driver atmel_tcb_pwm_driver = {
.driver = {
.name = "atmel-tcb-pwm",
.owner = THIS_MODULE,
.of_match_table = atmel_tcb_pwm_dt_ids,
},
.probe = atmel_tcb_pwm_probe,
Expand Down
1 change: 1 addition & 0 deletions drivers/pwm/pwm-bfin.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ static int bfin_pwm_remove(struct platform_device *pdev)
static struct platform_driver bfin_pwm_driver = {
.driver = {
.name = "bfin-pwm",
.owner = THIS_MODULE,
},
.probe = bfin_pwm_probe,
.remove = bfin_pwm_remove,
Expand Down
1 change: 1 addition & 0 deletions drivers/pwm/pwm-imx.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ static int imx_pwm_remove(struct platform_device *pdev)
static struct platform_driver imx_pwm_driver = {
.driver = {
.name = "imx-pwm",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(imx_pwm_dt_ids),
},
.probe = imx_pwm_probe,
Expand Down
1 change: 1 addition & 0 deletions drivers/pwm/pwm-lpc32xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ MODULE_DEVICE_TABLE(of, lpc32xx_pwm_dt_ids);
static struct platform_driver lpc32xx_pwm_driver = {
.driver = {
.name = "lpc32xx-pwm",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(lpc32xx_pwm_dt_ids),
},
.probe = lpc32xx_pwm_probe,
Expand Down
7 changes: 1 addition & 6 deletions drivers/pwm/pwm-mxs.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/pinctrl/consumer.h>
#include <linux/platform_device.h>
#include <linux/pwm.h>
#include <linux/slab.h>
Expand Down Expand Up @@ -130,7 +129,6 @@ static int mxs_pwm_probe(struct platform_device *pdev)
struct device_node *np = pdev->dev.of_node;
struct mxs_pwm_chip *mxs;
struct resource *res;
struct pinctrl *pinctrl;
int ret;

mxs = devm_kzalloc(&pdev->dev, sizeof(*mxs), GFP_KERNEL);
Expand All @@ -142,10 +140,6 @@ static int mxs_pwm_probe(struct platform_device *pdev)
if (IS_ERR(mxs->base))
return PTR_ERR(mxs->base);

pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
if (IS_ERR(pinctrl))
return PTR_ERR(pinctrl);

mxs->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(mxs->clk))
return PTR_ERR(mxs->clk);
Expand Down Expand Up @@ -188,6 +182,7 @@ MODULE_DEVICE_TABLE(of, mxs_pwm_dt_ids);
static struct platform_driver mxs_pwm_driver = {
.driver = {
.name = "mxs-pwm",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(mxs_pwm_dt_ids),
},
.probe = mxs_pwm_probe,
Expand Down
Loading

0 comments on commit 34ae0a6

Please sign in to comment.