diff options
| -rw-r--r-- | Documentation/ABI/testing/sysfs-class-pwm | 79 | ||||
| -rw-r--r-- | Documentation/devicetree/bindings/pwm/nxp,pca9685-pwm.txt | 27 | ||||
| -rw-r--r-- | Documentation/pwm.txt | 37 | ||||
| -rw-r--r-- | MAINTAINERS | 4 | ||||
| -rw-r--r-- | drivers/pwm/Kconfig | 23 | ||||
| -rw-r--r-- | drivers/pwm/Makefile | 3 | ||||
| -rw-r--r-- | drivers/pwm/core.c | 29 | ||||
| -rw-r--r-- | drivers/pwm/pwm-atmel-tcb.c | 5 | ||||
| -rw-r--r-- | drivers/pwm/pwm-bfin.c | 1 | ||||
| -rw-r--r-- | drivers/pwm/pwm-imx.c | 1 | ||||
| -rw-r--r-- | drivers/pwm/pwm-lpc32xx.c | 1 | ||||
| -rw-r--r-- | drivers/pwm/pwm-mxs.c | 7 | ||||
| -rw-r--r-- | drivers/pwm/pwm-pca9685.c | 300 | ||||
| -rw-r--r-- | drivers/pwm/pwm-puv3.c | 1 | ||||
| -rw-r--r-- | drivers/pwm/pwm-renesas-tpu.c | 474 | ||||
| -rw-r--r-- | drivers/pwm/pwm-spear.c | 1 | ||||
| -rw-r--r-- | drivers/pwm/pwm-tegra.c | 1 | ||||
| -rw-r--r-- | drivers/pwm/pwm-tiehrpwm.c | 13 | ||||
| -rw-r--r-- | drivers/pwm/sysfs.c | 352 | ||||
| -rw-r--r-- | include/linux/platform_data/pwm-renesas-tpu.h | 16 | ||||
| -rw-r--r-- | include/linux/pwm.h | 29 |
21 files changed, 1387 insertions, 17 deletions
diff --git a/Documentation/ABI/testing/sysfs-class-pwm b/Documentation/ABI/testing/sysfs-class-pwm new file mode 100644 index 000000000000..c479d77b67c5 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-pwm | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | What: /sys/class/pwm/ | ||
| 2 | Date: May 2013 | ||
| 3 | KernelVersion: 3.11 | ||
| 4 | Contact: H Hartley Sweeten <hsweeten@visionengravers.com> | ||
| 5 | Description: | ||
| 6 | The pwm/ class sub-directory belongs to the Generic PWM | ||
| 7 | Framework and provides a sysfs interface for using PWM | ||
| 8 | channels. | ||
| 9 | |||
| 10 | What: /sys/class/pwm/pwmchipN/ | ||
| 11 | Date: May 2013 | ||
| 12 | KernelVersion: 3.11 | ||
| 13 | Contact: H Hartley Sweeten <hsweeten@visionengravers.com> | ||
| 14 | Description: | ||
| 15 | A /sys/class/pwm/pwmchipN directory is created for each | ||
| 16 | probed PWM controller/chip where N is the base of the | ||
| 17 | PWM chip. | ||
| 18 | |||
| 19 | What: /sys/class/pwm/pwmchipN/npwm | ||
| 20 | Date: May 2013 | ||
| 21 | KernelVersion: 3.11 | ||
| 22 | Contact: H Hartley Sweeten <hsweeten@visionengravers.com> | ||
| 23 | Description: | ||
| 24 | The number of PWM channels supported by the PWM chip. | ||
| 25 | |||
| 26 | What: /sys/class/pwm/pwmchipN/export | ||
| 27 | Date: May 2013 | ||
| 28 | KernelVersion: 3.11 | ||
| 29 | Contact: H Hartley Sweeten <hsweeten@visionengravers.com> | ||
| 30 | Description: | ||
| 31 | Exports a PWM channel from the PWM chip for sysfs control. | ||
| 32 | Value is between 0 and /sys/class/pwm/pwmchipN/npwm - 1. | ||
| 33 | |||
| 34 | What: /sys/class/pwm/pwmchipN/unexport | ||
| 35 | Date: May 2013 | ||
| 36 | KernelVersion: 3.11 | ||
| 37 | Contact: H Hartley Sweeten <hsweeten@visionengravers.com> | ||
| 38 | Description: | ||
| 39 | Unexports a PWM channel. | ||
| 40 | |||
| 41 | What: /sys/class/pwm/pwmchipN/pwmX | ||
| 42 | Date: May 2013 | ||
| 43 | KernelVersion: 3.11 | ||
| 44 | Contact: H Hartley Sweeten <hsweeten@visionengravers.com> | ||
| 45 | Description: | ||
| 46 | A /sys/class/pwm/pwmchipN/pwmX directory is created for | ||
| 47 | each exported PWM channel where X is the exported PWM | ||
| 48 | channel number. | ||
| 49 | |||
| 50 | What: /sys/class/pwm/pwmchipN/pwmX/period | ||
| 51 | Date: May 2013 | ||
| 52 | KernelVersion: 3.11 | ||
| 53 | Contact: H Hartley Sweeten <hsweeten@visionengravers.com> | ||
| 54 | Description: | ||
| 55 | Sets the PWM signal period in nanoseconds. | ||
| 56 | |||
| 57 | What: /sys/class/pwm/pwmchipN/pwmX/duty_cycle | ||
| 58 | Date: May 2013 | ||
| 59 | KernelVersion: 3.11 | ||
| 60 | Contact: H Hartley Sweeten <hsweeten@visionengravers.com> | ||
| 61 | Description: | ||
| 62 | Sets the PWM signal duty cycle in nanoseconds. | ||
| 63 | |||
| 64 | What: /sys/class/pwm/pwmchipN/pwmX/polarity | ||
| 65 | Date: May 2013 | ||
| 66 | KernelVersion: 3.11 | ||
| 67 | Contact: H Hartley Sweeten <hsweeten@visionengravers.com> | ||
| 68 | Description: | ||
| 69 | Sets the output polarity of the PWM signal to "normal" or | ||
| 70 | "inversed". | ||
| 71 | |||
| 72 | What: /sys/class/pwm/pwmchipN/pwmX/enable | ||
| 73 | Date: May 2013 | ||
| 74 | KernelVersion: 3.11 | ||
| 75 | Contact: H Hartley Sweeten <hsweeten@visionengravers.com> | ||
| 76 | Description: | ||
| 77 | Enable/disable the PWM signal. | ||
| 78 | 0 is disabled | ||
| 79 | 1 is enabled | ||
diff --git a/Documentation/devicetree/bindings/pwm/nxp,pca9685-pwm.txt b/Documentation/devicetree/bindings/pwm/nxp,pca9685-pwm.txt new file mode 100644 index 000000000000..1e3dfe7a4894 --- /dev/null +++ b/Documentation/devicetree/bindings/pwm/nxp,pca9685-pwm.txt | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | NXP PCA9685 16-channel 12-bit PWM LED controller | ||
| 2 | ================================================ | ||
| 3 | |||
| 4 | Required properties: | ||
| 5 | - compatible: "nxp,pca9685-pwm" | ||
| 6 | - #pwm-cells: should be 2. The first cell specifies the per-chip index | ||
| 7 | of the PWM to use and the second cell is the period in nanoseconds. | ||
| 8 | The index 16 is the ALLCALL channel, that sets all PWM channels at the same | ||
| 9 | time. | ||
| 10 | |||
| 11 | Optional properties: | ||
| 12 | - invert (bool): boolean to enable inverted logic | ||
| 13 | - open-drain (bool): boolean to configure outputs with open-drain structure; | ||
| 14 | if omitted use totem-pole structure | ||
| 15 | |||
| 16 | Example: | ||
| 17 | |||
| 18 | For LEDs that are directly connected to the PCA, the following setting is | ||
| 19 | applicable: | ||
| 20 | |||
| 21 | pca: pca@41 { | ||
| 22 | compatible = "nxp,pca9685-pwm"; | ||
| 23 | #pwm-cells = <2>; | ||
| 24 | reg = <0x41>; | ||
| 25 | invert; | ||
| 26 | open-drain; | ||
| 27 | }; | ||
diff --git a/Documentation/pwm.txt b/Documentation/pwm.txt index 7d2b4c9b544b..1039b68fe9c6 100644 --- a/Documentation/pwm.txt +++ b/Documentation/pwm.txt | |||
| @@ -45,6 +45,43 @@ int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns); | |||
| 45 | 45 | ||
| 46 | To start/stop toggling the PWM output use pwm_enable()/pwm_disable(). | 46 | To start/stop toggling the PWM output use pwm_enable()/pwm_disable(). |
| 47 | 47 | ||
| 48 | Using PWMs with the sysfs interface | ||
| 49 | ----------------------------------- | ||
| 50 | |||
| 51 | If CONFIG_SYSFS is enabled in your kernel configuration a simple sysfs | ||
| 52 | interface is provided to use the PWMs from userspace. It is exposed at | ||
| 53 | /sys/class/pwm/. Each probed PWM controller/chip will be exported as | ||
| 54 | pwmchipN, where N is the base of the PWM chip. Inside the directory you | ||
| 55 | will find: | ||
| 56 | |||
| 57 | npwm - The number of PWM channels this chip supports (read-only). | ||
| 58 | |||
| 59 | export - Exports a PWM channel for use with sysfs (write-only). | ||
| 60 | |||
| 61 | unexport - Unexports a PWM channel from sysfs (write-only). | ||
| 62 | |||
| 63 | The PWM channels are numbered using a per-chip index from 0 to npwm-1. | ||
| 64 | |||
| 65 | When a PWM channel is exported a pwmX directory will be created in the | ||
| 66 | pwmchipN directory it is associated with, where X is the number of the | ||
| 67 | channel that was exported. The following properties will then be available: | ||
| 68 | |||
| 69 | period - The total period of the PWM signal (read/write). | ||
| 70 | Value is in nanoseconds and is the sum of the active and inactive | ||
| 71 | time of the PWM. | ||
| 72 | |||
| 73 | duty_cycle - The active time of the PWM signal (read/write). | ||
| 74 | Value is in nanoseconds and must be less than the period. | ||
| 75 | |||
| 76 | polarity - Changes the polarity of the PWM signal (read/write). | ||
| 77 | Writes to this property only work if the PWM chip supports changing | ||
| 78 | the polarity. The polarity can only be changed if the PWM is not | ||
| 79 | enabled. Value is the string "normal" or "inversed". | ||
| 80 | |||
| 81 | enable - Enable/disable the PWM signal (read/write). | ||
| 82 | 0 - disabled | ||
| 83 | 1 - enabled | ||
| 84 | |||
| 48 | Implementing a PWM driver | 85 | Implementing a PWM driver |
| 49 | ------------------------- | 86 | ------------------------- |
| 50 | 87 | ||
diff --git a/MAINTAINERS b/MAINTAINERS index 3c433aec12db..37f9a71c744f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
| @@ -6568,8 +6568,8 @@ S: Maintained | |||
| 6568 | F: drivers/media/usb/pwc/* | 6568 | F: drivers/media/usb/pwc/* |
| 6569 | 6569 | ||
| 6570 | PWM SUBSYSTEM | 6570 | PWM SUBSYSTEM |
| 6571 | M: Thierry Reding <thierry.reding@avionic-design.de> | 6571 | M: Thierry Reding <thierry.reding@gmail.com> |
| 6572 | L: linux-kernel@vger.kernel.org | 6572 | L: linux-pwm@vger.kernel.org |
| 6573 | S: Maintained | 6573 | S: Maintained |
| 6574 | W: http://gitorious.org/linux-pwm | 6574 | W: http://gitorious.org/linux-pwm |
| 6575 | T: git git://gitorious.org/linux-pwm/linux-pwm.git | 6575 | T: git git://gitorious.org/linux-pwm/linux-pwm.git |
diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index 115b64453493..75840b5cea6d 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig | |||
| @@ -28,6 +28,10 @@ menuconfig PWM | |||
| 28 | 28 | ||
| 29 | if PWM | 29 | if PWM |
| 30 | 30 | ||
| 31 | config PWM_SYSFS | ||
| 32 | bool | ||
| 33 | default y if SYSFS | ||
| 34 | |||
| 31 | config PWM_AB8500 | 35 | config PWM_AB8500 |
| 32 | tristate "AB8500 PWM support" | 36 | tristate "AB8500 PWM support" |
| 33 | depends on AB8500_CORE && ARCH_U8500 | 37 | depends on AB8500_CORE && ARCH_U8500 |
| @@ -97,6 +101,15 @@ config PWM_MXS | |||
| 97 | To compile this driver as a module, choose M here: the module | 101 | To compile this driver as a module, choose M here: the module |
| 98 | will be called pwm-mxs. | 102 | will be called pwm-mxs. |
| 99 | 103 | ||
| 104 | config PWM_PCA9685 | ||
| 105 | tristate "NXP PCA9685 PWM driver" | ||
| 106 | depends on OF && REGMAP_I2C | ||
| 107 | help | ||
| 108 | Generic PWM framework driver for NXP PCA9685 LED controller. | ||
| 109 | |||
| 110 | To compile this driver as a module, choose M here: the module | ||
| 111 | will be called pwm-pca9685. | ||
| 112 | |||
| 100 | config PWM_PUV3 | 113 | config PWM_PUV3 |
| 101 | tristate "PKUnity NetBook-0916 PWM support" | 114 | tristate "PKUnity NetBook-0916 PWM support" |
| 102 | depends on ARCH_PUV3 | 115 | depends on ARCH_PUV3 |
| @@ -115,6 +128,16 @@ config PWM_PXA | |||
| 115 | To compile this driver as a module, choose M here: the module | 128 | To compile this driver as a module, choose M here: the module |
| 116 | will be called pwm-pxa. | 129 | will be called pwm-pxa. |
| 117 | 130 | ||
| 131 | config PWM_RENESAS_TPU | ||
| 132 | tristate "Renesas TPU PWM support" | ||
| 133 | depends on ARCH_SHMOBILE | ||
| 134 | help | ||
| 135 | This driver exposes the Timer Pulse Unit (TPU) PWM controller found | ||
| 136 | in Renesas chips through the PWM API. | ||
| 137 | |||
| 138 | To compile this driver as a module, choose M here: the module | ||
| 139 | will be called pwm-renesas-tpu. | ||
| 140 | |||
| 118 | config PWM_SAMSUNG | 141 | config PWM_SAMSUNG |
| 119 | tristate "Samsung PWM support" | 142 | tristate "Samsung PWM support" |
| 120 | depends on PLAT_SAMSUNG | 143 | depends on PLAT_SAMSUNG |
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile index 94ba21e24bd6..77a8c185c5b2 100644 --- a/drivers/pwm/Makefile +++ b/drivers/pwm/Makefile | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | obj-$(CONFIG_PWM) += core.o | 1 | obj-$(CONFIG_PWM) += core.o |
| 2 | obj-$(CONFIG_PWM_SYSFS) += sysfs.o | ||
| 2 | obj-$(CONFIG_PWM_AB8500) += pwm-ab8500.o | 3 | obj-$(CONFIG_PWM_AB8500) += pwm-ab8500.o |
| 3 | obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o | 4 | obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o |
| 4 | obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o | 5 | obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o |
| @@ -6,8 +7,10 @@ obj-$(CONFIG_PWM_IMX) += pwm-imx.o | |||
| 6 | obj-$(CONFIG_PWM_JZ4740) += pwm-jz4740.o | 7 | obj-$(CONFIG_PWM_JZ4740) += pwm-jz4740.o |
| 7 | obj-$(CONFIG_PWM_LPC32XX) += pwm-lpc32xx.o | 8 | obj-$(CONFIG_PWM_LPC32XX) += pwm-lpc32xx.o |
| 8 | obj-$(CONFIG_PWM_MXS) += pwm-mxs.o | 9 | obj-$(CONFIG_PWM_MXS) += pwm-mxs.o |
| 10 | obj-$(CONFIG_PWM_PCA9685) += pwm-pca9685.o | ||
| 9 | obj-$(CONFIG_PWM_PUV3) += pwm-puv3.o | 11 | obj-$(CONFIG_PWM_PUV3) += pwm-puv3.o |
| 10 | obj-$(CONFIG_PWM_PXA) += pwm-pxa.o | 12 | obj-$(CONFIG_PWM_PXA) += pwm-pxa.o |
| 13 | obj-$(CONFIG_PWM_RENESAS_TPU) += pwm-renesas-tpu.o | ||
| 11 | obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.o | 14 | obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.o |
| 12 | obj-$(CONFIG_PWM_SPEAR) += pwm-spear.o | 15 | obj-$(CONFIG_PWM_SPEAR) += pwm-spear.o |
| 13 | obj-$(CONFIG_PWM_TEGRA) += pwm-tegra.o | 16 | obj-$(CONFIG_PWM_TEGRA) += pwm-tegra.o |
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 32221cb0cbe7..dfbfbc521768 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c | |||
| @@ -274,6 +274,8 @@ int pwmchip_add(struct pwm_chip *chip) | |||
| 274 | if (IS_ENABLED(CONFIG_OF)) | 274 | if (IS_ENABLED(CONFIG_OF)) |
| 275 | of_pwmchip_add(chip); | 275 | of_pwmchip_add(chip); |
| 276 | 276 | ||
| 277 | pwmchip_sysfs_export(chip); | ||
| 278 | |||
| 277 | out: | 279 | out: |
| 278 | mutex_unlock(&pwm_lock); | 280 | mutex_unlock(&pwm_lock); |
| 279 | return ret; | 281 | return ret; |
| @@ -310,6 +312,8 @@ int pwmchip_remove(struct pwm_chip *chip) | |||
| 310 | 312 | ||
| 311 | free_pwms(chip); | 313 | free_pwms(chip); |
| 312 | 314 | ||
| 315 | pwmchip_sysfs_unexport(chip); | ||
| 316 | |||
| 313 | out: | 317 | out: |
| 314 | mutex_unlock(&pwm_lock); | 318 | mutex_unlock(&pwm_lock); |
| 315 | return ret; | 319 | return ret; |
| @@ -402,10 +406,19 @@ EXPORT_SYMBOL_GPL(pwm_free); | |||
| 402 | */ | 406 | */ |
| 403 | int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns) | 407 | int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns) |
| 404 | { | 408 | { |
| 409 | int err; | ||
| 410 | |||
| 405 | if (!pwm || duty_ns < 0 || period_ns <= 0 || duty_ns > period_ns) | 411 | if (!pwm || duty_ns < 0 || period_ns <= 0 || duty_ns > period_ns) |
| 406 | return -EINVAL; | 412 | return -EINVAL; |
| 407 | 413 | ||
| 408 | return pwm->chip->ops->config(pwm->chip, pwm, duty_ns, period_ns); | 414 | err = pwm->chip->ops->config(pwm->chip, pwm, duty_ns, period_ns); |
| 415 | if (err) | ||
| 416 | return err; | ||
| 417 | |||
| 418 | pwm->duty_cycle = duty_ns; | ||
| 419 | pwm->period = period_ns; | ||
| 420 | |||
| 421 | return 0; | ||
| 409 | } | 422 | } |
| 410 | EXPORT_SYMBOL_GPL(pwm_config); | 423 | EXPORT_SYMBOL_GPL(pwm_config); |
| 411 | 424 | ||
| @@ -418,6 +431,8 @@ EXPORT_SYMBOL_GPL(pwm_config); | |||
| 418 | */ | 431 | */ |
| 419 | int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity) | 432 | int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity) |
| 420 | { | 433 | { |
| 434 | int err; | ||
| 435 | |||
| 421 | if (!pwm || !pwm->chip->ops) | 436 | if (!pwm || !pwm->chip->ops) |
| 422 | return -EINVAL; | 437 | return -EINVAL; |
| 423 | 438 | ||
| @@ -427,7 +442,13 @@ int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity) | |||
| 427 | if (test_bit(PWMF_ENABLED, &pwm->flags)) | 442 | if (test_bit(PWMF_ENABLED, &pwm->flags)) |
| 428 | return -EBUSY; | 443 | return -EBUSY; |
| 429 | 444 | ||
| 430 | return pwm->chip->ops->set_polarity(pwm->chip, pwm, polarity); | 445 | err = pwm->chip->ops->set_polarity(pwm->chip, pwm, polarity); |
| 446 | if (err) | ||
| 447 | return err; | ||
| 448 | |||
| 449 | pwm->polarity = polarity; | ||
| 450 | |||
| 451 | return 0; | ||
| 431 | } | 452 | } |
| 432 | EXPORT_SYMBOL_GPL(pwm_set_polarity); | 453 | EXPORT_SYMBOL_GPL(pwm_set_polarity); |
| 433 | 454 | ||
| @@ -694,7 +715,7 @@ struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id) | |||
| 694 | { | 715 | { |
| 695 | struct pwm_device **ptr, *pwm; | 716 | struct pwm_device **ptr, *pwm; |
| 696 | 717 | ||
| 697 | ptr = devres_alloc(devm_pwm_release, sizeof(**ptr), GFP_KERNEL); | 718 | ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL); |
| 698 | if (!ptr) | 719 | if (!ptr) |
| 699 | return ERR_PTR(-ENOMEM); | 720 | return ERR_PTR(-ENOMEM); |
| 700 | 721 | ||
| @@ -724,7 +745,7 @@ struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np, | |||
| 724 | { | 745 | { |
| 725 | struct pwm_device **ptr, *pwm; | 746 | struct pwm_device **ptr, *pwm; |
| 726 | 747 | ||
| 727 | ptr = devres_alloc(devm_pwm_release, sizeof(**ptr), GFP_KERNEL); | 748 | ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL); |
| 728 | if (!ptr) | 749 | if (!ptr) |
| 729 | return ERR_PTR(-ENOMEM); | 750 | return ERR_PTR(-ENOMEM); |
| 730 | 751 | ||
diff --git a/drivers/pwm/pwm-atmel-tcb.c b/drivers/pwm/pwm-atmel-tcb.c index 0a7b6582edb1..ba6ce01035e4 100644 --- a/drivers/pwm/pwm-atmel-tcb.c +++ b/drivers/pwm/pwm-atmel-tcb.c | |||
| @@ -76,7 +76,7 @@ static int atmel_tcb_pwm_request(struct pwm_chip *chip, | |||
| 76 | if (!tcbpwm) | 76 | if (!tcbpwm) |
| 77 | return -ENOMEM; | 77 | return -ENOMEM; |
| 78 | 78 | ||
| 79 | ret = clk_enable(tc->clk[group]); | 79 | ret = clk_prepare_enable(tc->clk[group]); |
| 80 | if (ret) { | 80 | if (ret) { |
| 81 | devm_kfree(chip->dev, tcbpwm); | 81 | devm_kfree(chip->dev, tcbpwm); |
| 82 | return ret; | 82 | return ret; |
| @@ -124,7 +124,7 @@ static void atmel_tcb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) | |||
| 124 | struct atmel_tcb_pwm_device *tcbpwm = pwm_get_chip_data(pwm); | 124 | struct atmel_tcb_pwm_device *tcbpwm = pwm_get_chip_data(pwm); |
| 125 | struct atmel_tc *tc = tcbpwmc->tc; | 125 | struct atmel_tc *tc = tcbpwmc->tc; |
| 126 | 126 | ||
| 127 | clk_disable(tc->clk[pwm->hwpwm / 2]); | 127 | clk_disable_unprepare(tc->clk[pwm->hwpwm / 2]); |
| 128 | tcbpwmc->pwms[pwm->hwpwm] = NULL; | 128 | tcbpwmc->pwms[pwm->hwpwm] = NULL; |
| 129 | devm_kfree(chip->dev, tcbpwm); | 129 | devm_kfree(chip->dev, tcbpwm); |
| 130 | } | 130 | } |
| @@ -434,6 +434,7 @@ MODULE_DEVICE_TABLE(of, atmel_tcb_pwm_dt_ids); | |||
| 434 | static struct platform_driver atmel_tcb_pwm_driver = { | 434 | static struct platform_driver atmel_tcb_pwm_driver = { |
| 435 | .driver = { | 435 | .driver = { |
| 436 | .name = "atmel-tcb-pwm", | 436 | .name = "atmel-tcb-pwm", |
| 437 | .owner = THIS_MODULE, | ||
| 437 | .of_match_table = atmel_tcb_pwm_dt_ids, | 438 | .of_match_table = atmel_tcb_pwm_dt_ids, |
| 438 | }, | 439 | }, |
| 439 | .probe = atmel_tcb_pwm_probe, | 440 | .probe = atmel_tcb_pwm_probe, |
diff --git a/drivers/pwm/pwm-bfin.c b/drivers/pwm/pwm-bfin.c index 7631ef194de7..9985d830e554 100644 --- a/drivers/pwm/pwm-bfin.c +++ b/drivers/pwm/pwm-bfin.c | |||
| @@ -149,6 +149,7 @@ static int bfin_pwm_remove(struct platform_device *pdev) | |||
| 149 | static struct platform_driver bfin_pwm_driver = { | 149 | static struct platform_driver bfin_pwm_driver = { |
| 150 | .driver = { | 150 | .driver = { |
| 151 | .name = "bfin-pwm", | 151 | .name = "bfin-pwm", |
| 152 | .owner = THIS_MODULE, | ||
| 152 | }, | 153 | }, |
| 153 | .probe = bfin_pwm_probe, | 154 | .probe = bfin_pwm_probe, |
| 154 | .remove = bfin_pwm_remove, | 155 | .remove = bfin_pwm_remove, |
diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c index c938bae18812..2b7c4f88b461 100644 --- a/drivers/pwm/pwm-imx.c +++ b/drivers/pwm/pwm-imx.c | |||
| @@ -295,6 +295,7 @@ static int imx_pwm_remove(struct platform_device *pdev) | |||
| 295 | static struct platform_driver imx_pwm_driver = { | 295 | static struct platform_driver imx_pwm_driver = { |
| 296 | .driver = { | 296 | .driver = { |
| 297 | .name = "imx-pwm", | 297 | .name = "imx-pwm", |
| 298 | .owner = THIS_MODULE, | ||
| 298 | .of_match_table = of_match_ptr(imx_pwm_dt_ids), | 299 | .of_match_table = of_match_ptr(imx_pwm_dt_ids), |
| 299 | }, | 300 | }, |
| 300 | .probe = imx_pwm_probe, | 301 | .probe = imx_pwm_probe, |
diff --git a/drivers/pwm/pwm-lpc32xx.c b/drivers/pwm/pwm-lpc32xx.c index 8272883c0d05..efb6c7bf8750 100644 --- a/drivers/pwm/pwm-lpc32xx.c +++ b/drivers/pwm/pwm-lpc32xx.c | |||
| @@ -171,6 +171,7 @@ MODULE_DEVICE_TABLE(of, lpc32xx_pwm_dt_ids); | |||
| 171 | static struct platform_driver lpc32xx_pwm_driver = { | 171 | static struct platform_driver lpc32xx_pwm_driver = { |
| 172 | .driver = { | 172 | .driver = { |
| 173 | .name = "lpc32xx-pwm", | 173 | .name = "lpc32xx-pwm", |
| 174 | .owner = THIS_MODULE, | ||
| 174 | .of_match_table = of_match_ptr(lpc32xx_pwm_dt_ids), | 175 | .of_match_table = of_match_ptr(lpc32xx_pwm_dt_ids), |
| 175 | }, | 176 | }, |
| 176 | .probe = lpc32xx_pwm_probe, | 177 | .probe = lpc32xx_pwm_probe, |
diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c index 3febdddf71f9..2c77b81da7c4 100644 --- a/drivers/pwm/pwm-mxs.c +++ b/drivers/pwm/pwm-mxs.c | |||
| @@ -16,7 +16,6 @@ | |||
| 16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
| 17 | #include <linux/of.h> | 17 | #include <linux/of.h> |
| 18 | #include <linux/of_address.h> | 18 | #include <linux/of_address.h> |
| 19 | #include <linux/pinctrl/consumer.h> | ||
| 20 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
| 21 | #include <linux/pwm.h> | 20 | #include <linux/pwm.h> |
| 22 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
| @@ -130,7 +129,6 @@ static int mxs_pwm_probe(struct platform_device *pdev) | |||
| 130 | struct device_node *np = pdev->dev.of_node; | 129 | struct device_node *np = pdev->dev.of_node; |
| 131 | struct mxs_pwm_chip *mxs; | 130 | struct mxs_pwm_chip *mxs; |
| 132 | struct resource *res; | 131 | struct resource *res; |
| 133 | struct pinctrl *pinctrl; | ||
| 134 | int ret; | 132 | int ret; |
| 135 | 133 | ||
| 136 | mxs = devm_kzalloc(&pdev->dev, sizeof(*mxs), GFP_KERNEL); | 134 | mxs = devm_kzalloc(&pdev->dev, sizeof(*mxs), GFP_KERNEL); |
| @@ -142,10 +140,6 @@ static int mxs_pwm_probe(struct platform_device *pdev) | |||
| 142 | if (IS_ERR(mxs->base)) | 140 | if (IS_ERR(mxs->base)) |
| 143 | return PTR_ERR(mxs->base); | 141 | return PTR_ERR(mxs->base); |
| 144 | 142 | ||
| 145 | pinctrl = devm_pinctrl_get_select_default(&pdev->dev); | ||
| 146 | if (IS_ERR(pinctrl)) | ||
| 147 | return PTR_ERR(pinctrl); | ||
| 148 | |||
| 149 | mxs->clk = devm_clk_get(&pdev->dev, NULL); | 143 | mxs->clk = devm_clk_get(&pdev->dev, NULL); |
| 150 | if (IS_ERR(mxs->clk)) | 144 | if (IS_ERR(mxs->clk)) |
| 151 | return PTR_ERR(mxs->clk); | 145 | return PTR_ERR(mxs->clk); |
| @@ -188,6 +182,7 @@ MODULE_DEVICE_TABLE(of, mxs_pwm_dt_ids); | |||
| 188 | static struct platform_driver mxs_pwm_driver = { | 182 | static struct platform_driver mxs_pwm_driver = { |
| 189 | .driver = { | 183 | .driver = { |
| 190 | .name = "mxs-pwm", | 184 | .name = "mxs-pwm", |
| 185 | .owner = THIS_MODULE, | ||
| 191 | .of_match_table = of_match_ptr(mxs_pwm_dt_ids), | 186 | .of_match_table = of_match_ptr(mxs_pwm_dt_ids), |
| 192 | }, | 187 | }, |
| 193 | .probe = mxs_pwm_probe, | 188 | .probe = mxs_pwm_probe, |
diff --git a/drivers/pwm/pwm-pca9685.c b/drivers/pwm/pwm-pca9685.c new file mode 100644 index 000000000000..3fb775ded0df --- /dev/null +++ b/drivers/pwm/pwm-pca9685.c | |||
| @@ -0,0 +1,300 @@ | |||
| 1 | /* | ||
| 2 | * Driver for PCA9685 16-channel 12-bit PWM LED controller | ||
| 3 | * | ||
| 4 | * Copyright (C) 2013 Steffen Trumtrar <s.trumtrar@pengutronix.de> | ||
| 5 | * | ||
| 6 | * based on the pwm-twl-led.c driver | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify it | ||
| 9 | * under the terms of the GNU General Public License version 2 as published by | ||
| 10 | * the Free Software Foundation. | ||
| 11 | * | ||
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 15 | * more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License along with | ||
| 18 | * this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <linux/i2c.h> | ||
| 22 | #include <linux/module.h> | ||
| 23 | #include <linux/platform_device.h> | ||
| 24 | #include <linux/pwm.h> | ||
| 25 | #include <linux/regmap.h> | ||
| 26 | #include <linux/slab.h> | ||
| 27 | |||
| 28 | #define PCA9685_MODE1 0x00 | ||
| 29 | #define PCA9685_MODE2 0x01 | ||
| 30 | #define PCA9685_SUBADDR1 0x02 | ||
| 31 | #define PCA9685_SUBADDR2 0x03 | ||
| 32 | #define PCA9685_SUBADDR3 0x04 | ||
| 33 | #define PCA9685_ALLCALLADDR 0x05 | ||
| 34 | #define PCA9685_LEDX_ON_L 0x06 | ||
| 35 | #define PCA9685_LEDX_ON_H 0x07 | ||
| 36 | #define PCA9685_LEDX_OFF_L 0x08 | ||
| 37 | #define PCA9685_LEDX_OFF_H 0x09 | ||
| 38 | |||
| 39 | #define PCA9685_ALL_LED_ON_L 0xFA | ||
| 40 | #define PCA9685_ALL_LED_ON_H 0xFB | ||
| 41 | #define PCA9685_ALL_LED_OFF_L 0xFC | ||
| 42 | #define PCA9685_ALL_LED_OFF_H 0xFD | ||
| 43 | #define PCA9685_PRESCALE 0xFE | ||
| 44 | |||
| 45 | #define PCA9685_NUMREGS 0xFF | ||
| 46 | #define PCA9685_MAXCHAN 0x10 | ||
| 47 | |||
| 48 | #define LED_FULL (1 << 4) | ||
| 49 | #define MODE1_SLEEP (1 << 4) | ||
| 50 | #define MODE2_INVRT (1 << 4) | ||
| 51 | #define MODE2_OUTDRV (1 << 2) | ||
| 52 | |||
| 53 | #define LED_N_ON_H(N) (PCA9685_LEDX_ON_H + (4 * (N))) | ||
| 54 | #define LED_N_ON_L(N) (PCA9685_LEDX_ON_L + (4 * (N))) | ||
| 55 | #define LED_N_OFF_H(N) (PCA9685_LEDX_OFF_H + (4 * (N))) | ||
| 56 | #define LED_N_OFF_L(N) (PCA9685_LEDX_OFF_L + (4 * (N))) | ||
| 57 | |||
| 58 | struct pca9685 { | ||
| 59 | struct pwm_chip chip; | ||
| 60 | struct regmap *regmap; | ||
| 61 | int active_cnt; | ||
| 62 | }; | ||
| 63 | |||
| 64 | static inline struct pca9685 *to_pca(struct pwm_chip *chip) | ||
| 65 | { | ||
| 66 | return container_of(chip, struct pca9685, chip); | ||
| 67 | } | ||
| 68 | |||
| 69 | static int pca9685_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, | ||
| 70 | int duty_ns, int period_ns) | ||
| 71 | { | ||
| 72 | struct pca9685 *pca = to_pca(chip); | ||
| 73 | unsigned long long duty; | ||
| 74 | unsigned int reg; | ||
| 75 | |||
| 76 | if (duty_ns < 1) { | ||
| 77 | if (pwm->hwpwm >= PCA9685_MAXCHAN) | ||
| 78 | reg = PCA9685_ALL_LED_OFF_H; | ||
| 79 | else | ||
| 80 | reg = LED_N_OFF_H(pwm->hwpwm); | ||
| 81 | |||
| 82 | regmap_write(pca->regmap, reg, LED_FULL); | ||
| 83 | |||
| 84 | return 0; | ||
| 85 | } | ||
| 86 | |||
| 87 | if (duty_ns == period_ns) { | ||
| 88 | if (pwm->hwpwm >= PCA9685_MAXCHAN) | ||
| 89 | reg = PCA9685_ALL_LED_ON_H; | ||
| 90 | else | ||
| 91 | reg = LED_N_ON_H(pwm->hwpwm); | ||
| 92 | |||
| 93 | regmap_write(pca->regmap, reg, LED_FULL); | ||
| 94 | |||
| 95 | return 0; | ||
| 96 | } | ||
| 97 | |||
| 98 | duty = 4096 * (unsigned long long)duty_ns; | ||
| 99 | duty = DIV_ROUND_UP_ULL(duty, period_ns); | ||
| 100 | |||
| 101 | if (pwm->hwpwm >= PCA9685_MAXCHAN) | ||
| 102 | reg = PCA9685_ALL_LED_OFF_L; | ||
| 103 | else | ||
| 104 | reg = LED_N_OFF_L(pwm->hwpwm); | ||
| 105 | |||
| 106 | regmap_write(pca->regmap, reg, (int)duty & 0xff); | ||
| 107 | |||
| 108 | if (pwm->hwpwm >= PCA9685_MAXCHAN) | ||
| 109 | reg = PCA9685_ALL_LED_OFF_H; | ||
| 110 | else | ||
| 111 | reg = LED_N_OFF_H(pwm->hwpwm); | ||
| 112 | |||
| 113 | regmap_write(pca->regmap, reg, ((int)duty >> 8) & 0xf); | ||
| 114 | |||
| 115 | return 0; | ||
| 116 | } | ||
| 117 | |||
| 118 | static int pca9685_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) | ||
| 119 | { | ||
| 120 | struct pca9685 *pca = to_pca(chip); | ||
| 121 | unsigned int reg; | ||
| 122 | |||
| 123 | /* | ||
| 124 | * The PWM subsystem does not support a pre-delay. | ||
| 125 | * So, set the ON-timeout to 0 | ||
| 126 | */ | ||
| 127 | if (pwm->hwpwm >= PCA9685_MAXCHAN) | ||
| 128 | reg = PCA9685_ALL_LED_ON_L; | ||
| 129 | else | ||
| 130 | reg = LED_N_ON_L(pwm->hwpwm); | ||
| 131 | |||
| 132 | regmap_write(pca->regmap, reg, 0); | ||
| 133 | |||
| 134 | if (pwm->hwpwm >= PCA9685_MAXCHAN) | ||
| 135 | reg = PCA9685_ALL_LED_ON_H; | ||
| 136 | else | ||
| 137 | reg = LED_N_ON_H(pwm->hwpwm); | ||
| 138 | |||
| 139 | regmap_write(pca->regmap, reg, 0); | ||
| 140 | |||
| 141 | /* | ||
| 142 | * Clear the full-off bit. | ||
| 143 | * It has precedence over the others and must be off. | ||
| 144 | */ | ||
| 145 | if (pwm->hwpwm >= PCA9685_MAXCHAN) | ||
| 146 | reg = PCA9685_ALL_LED_OFF_H; | ||
| 147 | else | ||
| 148 | reg = LED_N_OFF_H(pwm->hwpwm); | ||
| 149 | |||
| 150 | regmap_update_bits(pca->regmap, reg, LED_FULL, 0x0); | ||
| 151 | |||
| 152 | return 0; | ||
| 153 | } | ||
| 154 | |||
| 155 | static void pca9685_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) | ||
| 156 | { | ||
| 157 | struct pca9685 *pca = to_pca(chip); | ||
| 158 | unsigned int reg; | ||
| 159 | |||
| 160 | if (pwm->hwpwm >= PCA9685_MAXCHAN) | ||
| 161 | reg = PCA9685_ALL_LED_OFF_H; | ||
| 162 | else | ||
| 163 | reg = LED_N_OFF_H(pwm->hwpwm); | ||
| 164 | |||
| 165 | regmap_write(pca->regmap, reg, LED_FULL); | ||
| 166 | |||
| 167 | /* Clear the LED_OFF counter. */ | ||
| 168 | if (pwm->hwpwm >= PCA9685_MAXCHAN) | ||
| 169 | reg = PCA9685_ALL_LED_OFF_L; | ||
| 170 | else | ||
| 171 | reg = LED_N_OFF_L(pwm->hwpwm); | ||
| 172 | |||
| 173 | regmap_write(pca->regmap, reg, 0x0); | ||
| 174 | } | ||
| 175 | |||
| 176 | static int pca9685_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) | ||
| 177 | { | ||
| 178 | struct pca9685 *pca = to_pca(chip); | ||
| 179 | |||
| 180 | if (pca->active_cnt++ == 0) | ||
| 181 | return regmap_update_bits(pca->regmap, PCA9685_MODE1, | ||
| 182 | MODE1_SLEEP, 0x0); | ||
| 183 | |||
| 184 | return 0; | ||
| 185 | } | ||
| 186 | |||
| 187 | static void pca9685_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) | ||
| 188 | { | ||
| 189 | struct pca9685 *pca = to_pca(chip); | ||
| 190 | |||
| 191 | if (--pca->active_cnt == 0) | ||
| 192 | regmap_update_bits(pca->regmap, PCA9685_MODE1, MODE1_SLEEP, | ||
| 193 | MODE1_SLEEP); | ||
| 194 | } | ||
| 195 | |||
| 196 | static const struct pwm_ops pca9685_pwm_ops = { | ||
| 197 | .enable = pca9685_pwm_enable, | ||
| 198 | .disable = pca9685_pwm_disable, | ||
| 199 | .config = pca9685_pwm_config, | ||
| 200 | .request = pca9685_pwm_request, | ||
| 201 | .free = pca9685_pwm_free, | ||
| 202 | .owner = THIS_MODULE, | ||
| 203 | }; | ||
| 204 | |||
| 205 | static struct regmap_config pca9685_regmap_i2c_config = { | ||
| 206 | .reg_bits = 8, | ||
| 207 | .val_bits = 8, | ||
| 208 | .max_register = PCA9685_NUMREGS, | ||
| 209 | .cache_type = REGCACHE_NONE, | ||
| 210 | }; | ||
| 211 | |||
| 212 | static int pca9685_pwm_probe(struct i2c_client *client, | ||
| 213 | const struct i2c_device_id *id) | ||
| 214 | { | ||
| 215 | struct device_node *np = client->dev.of_node; | ||
| 216 | struct pca9685 *pca; | ||
| 217 | int ret; | ||
| 218 | int mode2; | ||
| 219 | |||
| 220 | pca = devm_kzalloc(&client->dev, sizeof(*pca), GFP_KERNEL); | ||
| 221 | if (!pca) | ||
| 222 | return -ENOMEM; | ||
| 223 | |||
| 224 | pca->regmap = devm_regmap_init_i2c(client, &pca9685_regmap_i2c_config); | ||
| 225 | if (IS_ERR(pca->regmap)) { | ||
| 226 | ret = PTR_ERR(pca->regmap); | ||
| 227 | dev_err(&client->dev, "Failed to initialize register map: %d\n", | ||
| 228 | ret); | ||
| 229 | return ret; | ||
| 230 | } | ||
| 231 | |||
| 232 | i2c_set_clientdata(client, pca); | ||
| 233 | |||
| 234 | regmap_read(pca->regmap, PCA9685_MODE2, &mode2); | ||
| 235 | |||
| 236 | if (of_property_read_bool(np, "invert")) | ||
| 237 | mode2 |= MODE2_INVRT; | ||
| 238 | else | ||
| 239 | mode2 &= ~MODE2_INVRT; | ||
| 240 | |||
| 241 | if (of_property_read_bool(np, "open-drain")) | ||
| 242 | mode2 &= ~MODE2_OUTDRV; | ||
| 243 | else | ||
| 244 | mode2 |= MODE2_OUTDRV; | ||
| 245 | |||
| 246 | regmap_write(pca->regmap, PCA9685_MODE2, mode2); | ||
| 247 | |||
| 248 | /* clear all "full off" bits */ | ||
| 249 | regmap_write(pca->regmap, PCA9685_ALL_LED_OFF_L, 0); | ||
| 250 | regmap_write(pca->regmap, PCA9685_ALL_LED_OFF_H, 0); | ||
| 251 | |||
| 252 | pca->chip.ops = &pca9685_pwm_ops; | ||
| 253 | /* add an extra channel for ALL_LED */ | ||
| 254 | pca->chip.npwm = PCA9685_MAXCHAN + 1; | ||
| 255 | |||
| 256 | pca->chip.dev = &client->dev; | ||
| 257 | pca->chip.base = -1; | ||
| 258 | pca->chip.can_sleep = true; | ||
| 259 | |||
| 260 | return pwmchip_add(&pca->chip); | ||
| 261 | } | ||
| 262 | |||
| 263 | static int pca9685_pwm_remove(struct i2c_client *client) | ||
| 264 | { | ||
| 265 | struct pca9685 *pca = i2c_get_clientdata(client); | ||
| 266 | |||
| 267 | regmap_update_bits(pca->regmap, PCA9685_MODE1, MODE1_SLEEP, | ||
| 268 | MODE1_SLEEP); | ||
| 269 | |||
| 270 | return pwmchip_remove(&pca->chip); | ||
| 271 | } | ||
| 272 | |||
| 273 | static const struct i2c_device_id pca9685_id[] = { | ||
| 274 | { "pca9685", 0 }, | ||
| 275 | { /* sentinel */ }, | ||
| 276 | }; | ||
| 277 | MODULE_DEVICE_TABLE(i2c, pca9685_id); | ||
| 278 | |||
| 279 | static const struct of_device_id pca9685_dt_ids[] = { | ||
| 280 | { .compatible = "nxp,pca9685-pwm", }, | ||
| 281 | { /* sentinel */ } | ||
| 282 | }; | ||
| 283 | MODULE_DEVICE_TABLE(of, pca9685_dt_ids); | ||
| 284 | |||
| 285 | static struct i2c_driver pca9685_i2c_driver = { | ||
| 286 | .driver = { | ||
| 287 | .name = "pca9685-pwm", | ||
| 288 | .owner = THIS_MODULE, | ||
| 289 | .of_match_table = pca9685_dt_ids, | ||
| 290 | }, | ||
| 291 | .probe = pca9685_pwm_probe, | ||
| 292 | .remove = pca9685_pwm_remove, | ||
| 293 | .id_table = pca9685_id, | ||
| 294 | }; | ||
| 295 | |||
| 296 | module_i2c_driver(pca9685_i2c_driver); | ||
| 297 | |||
| 298 | MODULE_AUTHOR("Steffen Trumtrar <s.trumtrar@pengutronix.de>"); | ||
| 299 | MODULE_DESCRIPTION("PWM driver for PCA9685"); | ||
| 300 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/pwm/pwm-puv3.c b/drivers/pwm/pwm-puv3.c index ed6007b27585..a9a28083f245 100644 --- a/drivers/pwm/pwm-puv3.c +++ b/drivers/pwm/pwm-puv3.c | |||
| @@ -146,6 +146,7 @@ static int pwm_remove(struct platform_device *pdev) | |||
| 146 | static struct platform_driver puv3_pwm_driver = { | 146 | static struct platform_driver puv3_pwm_driver = { |
| 147 | .driver = { | 147 | .driver = { |
| 148 | .name = "PKUnity-v3-PWM", | 148 | .name = "PKUnity-v3-PWM", |
| 149 | .owner = THIS_MODULE, | ||
| 149 | }, | 150 | }, |
| 150 | .probe = pwm_probe, | 151 | .probe = pwm_probe, |
| 151 | .remove = pwm_remove, | 152 | .remove = pwm_remove, |
diff --git a/drivers/pwm/pwm-renesas-tpu.c b/drivers/pwm/pwm-renesas-tpu.c new file mode 100644 index 000000000000..2600892782c1 --- /dev/null +++ b/drivers/pwm/pwm-renesas-tpu.c | |||
| @@ -0,0 +1,474 @@ | |||
| 1 | /* | ||
| 2 | * R-Mobile TPU PWM driver | ||
| 3 | * | ||
| 4 | * Copyright (C) 2012 Renesas Solutions Corp. | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include <linux/clk.h> | ||
| 17 | #include <linux/err.h> | ||
| 18 | #include <linux/io.h> | ||
| 19 | #include <linux/init.h> | ||
| 20 | #include <linux/ioport.h> | ||
| 21 | #include <linux/module.h> | ||
| 22 | #include <linux/mutex.h> | ||
| 23 | #include <linux/platform_data/pwm-renesas-tpu.h> | ||
| 24 | #include <linux/platform_device.h> | ||
| 25 | #include <linux/pm_runtime.h> | ||
| 26 | #include <linux/pwm.h> | ||
| 27 | #include <linux/slab.h> | ||
| 28 | #include <linux/spinlock.h> | ||
| 29 | |||
| 30 | #define TPU_TSTR 0x00 /* Timer start register (shared) */ | ||
| 31 | |||
| 32 | #define TPU_TCRn 0x00 /* Timer control register */ | ||
| 33 | #define TPU_TCR_CCLR_NONE (0 << 5) | ||
| 34 | #define TPU_TCR_CCLR_TGRA (1 << 5) | ||
| 35 | #define TPU_TCR_CCLR_TGRB (2 << 5) | ||
| 36 | #define TPU_TCR_CCLR_TGRC (5 << 5) | ||
| 37 | #define TPU_TCR_CCLR_TGRD (6 << 5) | ||
| 38 | #define TPU_TCR_CKEG_RISING (0 << 3) | ||
| 39 | #define TPU_TCR_CKEG_FALLING (1 << 3) | ||
| 40 | #define TPU_TCR_CKEG_BOTH (2 << 3) | ||
| 41 | #define TPU_TMDRn 0x04 /* Timer mode register */ | ||
| 42 | #define TPU_TMDR_BFWT (1 << 6) | ||
| 43 | #define TPU_TMDR_BFB (1 << 5) | ||
| 44 | #define TPU_TMDR_BFA (1 << 4) | ||
| 45 | #define TPU_TMDR_MD_NORMAL (0 << 0) | ||
| 46 | #define TPU_TMDR_MD_PWM (2 << 0) | ||
| 47 | #define TPU_TIORn 0x08 /* Timer I/O control register */ | ||
| 48 | #define TPU_TIOR_IOA_0 (0 << 0) | ||
| 49 | #define TPU_TIOR_IOA_0_CLR (1 << 0) | ||
| 50 | #define TPU_TIOR_IOA_0_SET (2 << 0) | ||
| 51 | #define TPU_TIOR_IOA_0_TOGGLE (3 << 0) | ||
| 52 | #define TPU_TIOR_IOA_1 (4 << 0) | ||
| 53 | #define TPU_TIOR_IOA_1_CLR (5 << 0) | ||
| 54 | #define TPU_TIOR_IOA_1_SET (6 << 0) | ||
| 55 | #define TPU_TIOR_IOA_1_TOGGLE (7 << 0) | ||
| 56 | #define TPU_TIERn 0x0c /* Timer interrupt enable register */ | ||
| 57 | #define TPU_TSRn 0x10 /* Timer status register */ | ||
| 58 | #define TPU_TCNTn 0x14 /* Timer counter */ | ||
| 59 | #define TPU_TGRAn 0x18 /* Timer general register A */ | ||
| 60 | #define TPU_TGRBn 0x1c /* Timer general register B */ | ||
| 61 | #define TPU_TGRCn 0x20 /* Timer general register C */ | ||
| 62 | #define TPU_TGRDn 0x24 /* Timer general register D */ | ||
| 63 | |||
| 64 | #define TPU_CHANNEL_OFFSET 0x10 | ||
| 65 | #define TPU_CHANNEL_SIZE 0x40 | ||
| 66 | |||
| 67 | enum tpu_pin_state { | ||
| 68 | TPU_PIN_INACTIVE, /* Pin is driven inactive */ | ||
| 69 | TPU_PIN_PWM, /* Pin is driven by PWM */ | ||
| 70 | TPU_PIN_ACTIVE, /* Pin is driven active */ | ||
| 71 | }; | ||
| 72 | |||
| 73 | struct tpu_device; | ||
| 74 | |||
| 75 | struct tpu_pwm_device { | ||
| 76 | bool timer_on; /* Whether the timer is running */ | ||
| 77 | |||
| 78 | struct tpu_device *tpu; | ||
| 79 | unsigned int channel; /* Channel number in the TPU */ | ||
| 80 | |||
| 81 | enum pwm_polarity polarity; | ||
| 82 | unsigned int prescaler; | ||
| 83 | u16 period; | ||
| 84 | u16 duty; | ||
| 85 | }; | ||
| 86 | |||
| 87 | struct tpu_device { | ||
| 88 | struct platform_device *pdev; | ||
| 89 | struct tpu_pwm_platform_data *pdata; | ||
| 90 | struct pwm_chip chip; | ||
| 91 | spinlock_t lock; | ||
| 92 | |||
| 93 | void __iomem *base; | ||
| 94 | struct clk *clk; | ||
| 95 | }; | ||
| 96 | |||
| 97 | #define to_tpu_device(c) container_of(c, struct tpu_device, chip) | ||
| 98 | |||
| 99 | static void tpu_pwm_write(struct tpu_pwm_device *pwm, int reg_nr, u16 value) | ||
| 100 | { | ||
| 101 | void __iomem *base = pwm->tpu->base + TPU_CHANNEL_OFFSET | ||
| 102 | + pwm->channel * TPU_CHANNEL_SIZE; | ||
| 103 | |||
| 104 | iowrite16(value, base + reg_nr); | ||
| 105 | } | ||
| 106 | |||
| 107 | static void tpu_pwm_set_pin(struct tpu_pwm_device *pwm, | ||
| 108 | enum tpu_pin_state state) | ||
| 109 | { | ||
| 110 | static const char * const states[] = { "inactive", "PWM", "active" }; | ||
| 111 | |||
| 112 | dev_dbg(&pwm->tpu->pdev->dev, "%u: configuring pin as %s\n", | ||
| 113 | pwm->channel, states[state]); | ||
| 114 | |||
| 115 | switch (state) { | ||
| 116 | case TPU_PIN_INACTIVE: | ||
| 117 | tpu_pwm_write(pwm, TPU_TIORn, | ||
| 118 | pwm->polarity == PWM_POLARITY_INVERSED ? | ||
| 119 | TPU_TIOR_IOA_1 : TPU_TIOR_IOA_0); | ||
| 120 | break; | ||
| 121 | case TPU_PIN_PWM: | ||
| 122 | tpu_pwm_write(pwm, TPU_TIORn, | ||
| 123 | pwm->polarity == PWM_POLARITY_INVERSED ? | ||
| 124 | TPU_TIOR_IOA_0_SET : TPU_TIOR_IOA_1_CLR); | ||
| 125 | break; | ||
| 126 | case TPU_PIN_ACTIVE: | ||
| 127 | tpu_pwm_write(pwm, TPU_TIORn, | ||
| 128 | pwm->polarity == PWM_POLARITY_INVERSED ? | ||
| 129 | TPU_TIOR_IOA_0 : TPU_TIOR_IOA_1); | ||
| 130 | break; | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | static void tpu_pwm_start_stop(struct tpu_pwm_device *pwm, int start) | ||
| 135 | { | ||
| 136 | unsigned long flags; | ||
| 137 | u16 value; | ||
| 138 | |||
| 139 | spin_lock_irqsave(&pwm->tpu->lock, flags); | ||
| 140 | value = ioread16(pwm->tpu->base + TPU_TSTR); | ||
| 141 | |||
| 142 | if (start) | ||
| 143 | value |= 1 << pwm->channel; | ||
| 144 | else | ||
| 145 | value &= ~(1 << pwm->channel); | ||
| 146 | |||
| 147 | iowrite16(value, pwm->tpu->base + TPU_TSTR); | ||
| 148 | spin_unlock_irqrestore(&pwm->tpu->lock, flags); | ||
| 149 | } | ||
| 150 | |||
| 151 | static int tpu_pwm_timer_start(struct tpu_pwm_device *pwm) | ||
| 152 | { | ||
| 153 | int ret; | ||
| 154 | |||
| 155 | if (!pwm->timer_on) { | ||
| 156 | /* Wake up device and enable clock. */ | ||
| 157 | pm_runtime_get_sync(&pwm->tpu->pdev->dev); | ||
| 158 | ret = clk_prepare_enable(pwm->tpu->clk); | ||
| 159 | if (ret) { | ||
| 160 | dev_err(&pwm->tpu->pdev->dev, "cannot enable clock\n"); | ||
| 161 | return ret; | ||
| 162 | } | ||
| 163 | pwm->timer_on = true; | ||
| 164 | } | ||
| 165 | |||
| 166 | /* | ||
| 167 | * Make sure the channel is stopped, as we need to reconfigure it | ||
| 168 | * completely. First drive the pin to the inactive state to avoid | ||
| 169 | * glitches. | ||
| 170 | */ | ||
| 171 | tpu_pwm_set_pin(pwm, TPU_PIN_INACTIVE); | ||
| 172 | tpu_pwm_start_stop(pwm, false); | ||
| 173 | |||
| 174 | /* | ||
| 175 | * - Clear TCNT on TGRB match | ||
| 176 | * - Count on rising edge | ||
| 177 | * - Set prescaler | ||
| 178 | * - Output 0 until TGRA, output 1 until TGRB (active low polarity) | ||
| 179 | * - Output 1 until TGRA, output 0 until TGRB (active high polarity | ||
| 180 | * - PWM mode | ||
| 181 | */ | ||
| 182 | tpu_pwm_write(pwm, TPU_TCRn, TPU_TCR_CCLR_TGRB | TPU_TCR_CKEG_RISING | | ||
| 183 | pwm->prescaler); | ||
| 184 | tpu_pwm_write(pwm, TPU_TMDRn, TPU_TMDR_MD_PWM); | ||
| 185 | tpu_pwm_set_pin(pwm, TPU_PIN_PWM); | ||
| 186 | tpu_pwm_write(pwm, TPU_TGRAn, pwm->duty); | ||
| 187 | tpu_pwm_write(pwm, TPU_TGRBn, pwm->period); | ||
| 188 | |||
| 189 | dev_dbg(&pwm->tpu->pdev->dev, "%u: TGRA 0x%04x TGRB 0x%04x\n", | ||
| 190 | pwm->channel, pwm->duty, pwm->period); | ||
| 191 | |||
| 192 | /* Start the channel. */ | ||
| 193 | tpu_pwm_start_stop(pwm, true); | ||
| 194 | |||
| 195 | return 0; | ||
| 196 | } | ||
| 197 | |||
| 198 | static void tpu_pwm_timer_stop(struct tpu_pwm_device *pwm) | ||
| 199 | { | ||
| 200 | if (!pwm->timer_on) | ||
| 201 | return; | ||
| 202 | |||
| 203 | /* Disable channel. */ | ||
| 204 | tpu_pwm_start_stop(pwm, false); | ||
| 205 | |||
| 206 | /* Stop clock and mark device as idle. */ | ||
| 207 | clk_disable_unprepare(pwm->tpu->clk); | ||
| 208 | pm_runtime_put(&pwm->tpu->pdev->dev); | ||
| 209 | |||
| 210 | pwm->timer_on = false; | ||
| 211 | } | ||
| 212 | |||
| 213 | /* ----------------------------------------------------------------------------- | ||
| 214 | * PWM API | ||
| 215 | */ | ||
| 216 | |||
| 217 | static int tpu_pwm_request(struct pwm_chip *chip, struct pwm_device *_pwm) | ||
| 218 | { | ||
| 219 | struct tpu_device *tpu = to_tpu_device(chip); | ||
| 220 | struct tpu_pwm_device *pwm; | ||
| 221 | |||
| 222 | if (_pwm->hwpwm >= TPU_CHANNEL_MAX) | ||
| 223 | return -EINVAL; | ||
| 224 | |||
| 225 | pwm = kzalloc(sizeof(*pwm), GFP_KERNEL); | ||
| 226 | if (pwm == NULL) | ||
| 227 | return -ENOMEM; | ||
| 228 | |||
| 229 | pwm->tpu = tpu; | ||
| 230 | pwm->channel = _pwm->hwpwm; | ||
| 231 | pwm->polarity = tpu->pdata ? tpu->pdata->channels[pwm->channel].polarity | ||
| 232 | : PWM_POLARITY_NORMAL; | ||
| 233 | pwm->prescaler = 0; | ||
| 234 | pwm->period = 0; | ||
| 235 | pwm->duty = 0; | ||
| 236 | |||
| 237 | pwm->timer_on = false; | ||
| 238 | |||
| 239 | pwm_set_chip_data(_pwm, pwm); | ||
| 240 | |||
| 241 | return 0; | ||
| 242 | } | ||
| 243 | |||
| 244 | static void tpu_pwm_free(struct pwm_chip *chip, struct pwm_device *_pwm) | ||
| 245 | { | ||
| 246 | struct tpu_pwm_device *pwm = pwm_get_chip_data(_pwm); | ||
| 247 | |||
| 248 | tpu_pwm_timer_stop(pwm); | ||
| 249 | kfree(pwm); | ||
| 250 | } | ||
| 251 | |||
| 252 | static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *_pwm, | ||
| 253 | int duty_ns, int period_ns) | ||
| 254 | { | ||
| 255 | static const unsigned int prescalers[] = { 1, 4, 16, 64 }; | ||
| 256 | struct tpu_pwm_device *pwm = pwm_get_chip_data(_pwm); | ||
| 257 | struct tpu_device *tpu = to_tpu_device(chip); | ||
| 258 | unsigned int prescaler; | ||
| 259 | bool duty_only = false; | ||
| 260 | u32 clk_rate; | ||
| 261 | u32 period; | ||
| 262 | u32 duty; | ||
| 263 | int ret; | ||
| 264 | |||
| 265 | /* | ||
| 266 | * Pick a prescaler to avoid overflowing the counter. | ||
| 267 | * TODO: Pick the highest acceptable prescaler. | ||
| 268 | */ | ||
| 269 | clk_rate = clk_get_rate(tpu->clk); | ||
| 270 | |||
| 271 | for (prescaler = 0; prescaler < ARRAY_SIZE(prescalers); ++prescaler) { | ||
| 272 | period = clk_rate / prescalers[prescaler] | ||
| 273 | / (NSEC_PER_SEC / period_ns); | ||
| 274 | if (period <= 0xffff) | ||
| 275 | break; | ||
| 276 | } | ||
| 277 | |||
| 278 | if (prescaler == ARRAY_SIZE(prescalers) || period == 0) { | ||
| 279 | dev_err(&tpu->pdev->dev, "clock rate mismatch\n"); | ||
| 280 | return -ENOTSUPP; | ||
| 281 | } | ||
| 282 | |||
| 283 | if (duty_ns) { | ||
| 284 | duty = clk_rate / prescalers[prescaler] | ||
| 285 | / (NSEC_PER_SEC / duty_ns); | ||
| 286 | if (duty > period) | ||
| 287 | return -EINVAL; | ||
| 288 | } else { | ||
| 289 | duty = 0; | ||
| 290 | } | ||
| 291 | |||
| 292 | dev_dbg(&tpu->pdev->dev, | ||
| 293 | "rate %u, prescaler %u, period %u, duty %u\n", | ||
| 294 | clk_rate, prescalers[prescaler], period, duty); | ||
| 295 | |||
| 296 | if (pwm->prescaler == prescaler && pwm->period == period) | ||
| 297 | duty_only = true; | ||
| 298 | |||
| 299 | pwm->prescaler = prescaler; | ||
| 300 | pwm->period = period; | ||
| 301 | pwm->duty = duty; | ||
| 302 | |||
| 303 | /* If the channel is disabled we're done. */ | ||
| 304 | if (!test_bit(PWMF_ENABLED, &_pwm->flags)) | ||
| 305 | return 0; | ||
| 306 | |||
| 307 | if (duty_only && pwm->timer_on) { | ||
| 308 | /* | ||
| 309 | * If only the duty cycle changed and the timer is already | ||
| 310 | * running, there's no need to reconfigure it completely, Just | ||
| 311 | * modify the duty cycle. | ||
| 312 | */ | ||
| 313 | tpu_pwm_write(pwm, TPU_TGRAn, pwm->duty); | ||
| 314 | dev_dbg(&tpu->pdev->dev, "%u: TGRA 0x%04x\n", pwm->channel, | ||
| 315 | pwm->duty); | ||
| 316 | } else { | ||
| 317 | /* Otherwise perform a full reconfiguration. */ | ||
| 318 | ret = tpu_pwm_timer_start(pwm); | ||
| 319 | if (ret < 0) | ||
| 320 | return ret; | ||
| 321 | } | ||
| 322 | |||
| 323 | if (duty == 0 || duty == period) { | ||
| 324 | /* | ||
| 325 | * To avoid running the timer when not strictly required, handle | ||
| 326 | * 0% and 100% duty cycles as fixed levels and stop the timer. | ||
| 327 | */ | ||
| 328 | tpu_pwm_set_pin(pwm, duty ? TPU_PIN_ACTIVE : TPU_PIN_INACTIVE); | ||
| 329 | tpu_pwm_timer_stop(pwm); | ||
| 330 | } | ||
| 331 | |||
| 332 | return 0; | ||
| 333 | } | ||
| 334 | |||
| 335 | static int tpu_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *_pwm, | ||
| 336 | enum pwm_polarity polarity) | ||
| 337 | { | ||
| 338 | struct tpu_pwm_device *pwm = pwm_get_chip_data(_pwm); | ||
| 339 | |||
| 340 | pwm->polarity = polarity; | ||
| 341 | |||
| 342 | return 0; | ||
| 343 | } | ||
| 344 | |||
| 345 | static int tpu_pwm_enable(struct pwm_chip *chip, struct pwm_device *_pwm) | ||
| 346 | { | ||
| 347 | struct tpu_pwm_device *pwm = pwm_get_chip_data(_pwm); | ||
| 348 | int ret; | ||
| 349 | |||
| 350 | ret = tpu_pwm_timer_start(pwm); | ||
| 351 | if (ret < 0) | ||
| 352 | return ret; | ||
| 353 | |||
| 354 | /* | ||
| 355 | * To avoid running the timer when not strictly required, handle 0% and | ||
| 356 | * 100% duty cycles as fixed levels and stop the timer. | ||
| 357 | */ | ||
| 358 | if (pwm->duty == 0 || pwm->duty == pwm->period) { | ||
| 359 | tpu_pwm_set_pin(pwm, pwm->duty ? | ||
| 360 | TPU_PIN_ACTIVE : TPU_PIN_INACTIVE); | ||
| 361 | tpu_pwm_timer_stop(pwm); | ||
| 362 | } | ||
| 363 | |||
| 364 | return 0; | ||
| 365 | } | ||
| 366 | |||
| 367 | static void tpu_pwm_disable(struct pwm_chip *chip, struct pwm_device *_pwm) | ||
| 368 | { | ||
| 369 | struct tpu_pwm_device *pwm = pwm_get_chip_data(_pwm); | ||
| 370 | |||
| 371 | /* The timer must be running to modify the pin output configuration. */ | ||
| 372 | tpu_pwm_timer_start(pwm); | ||
| 373 | tpu_pwm_set_pin(pwm, TPU_PIN_INACTIVE); | ||
| 374 | tpu_pwm_timer_stop(pwm); | ||
| 375 | } | ||
| 376 | |||
| 377 | static const struct pwm_ops tpu_pwm_ops = { | ||
| 378 | .request = tpu_pwm_request, | ||
| 379 | .free = tpu_pwm_free, | ||
| 380 | .config = tpu_pwm_config, | ||
| 381 | .set_polarity = tpu_pwm_set_polarity, | ||
| 382 | .enable = tpu_pwm_enable, | ||
| 383 | .disable = tpu_pwm_disable, | ||
| 384 | .owner = THIS_MODULE, | ||
| 385 | }; | ||
| 386 | |||
| 387 | /* ----------------------------------------------------------------------------- | ||
| 388 | * Probe and remove | ||
| 389 | */ | ||
| 390 | |||
| 391 | static int tpu_probe(struct platform_device *pdev) | ||
| 392 | { | ||
| 393 | struct tpu_device *tpu; | ||
| 394 | struct resource *res; | ||
| 395 | int ret; | ||
| 396 | |||
| 397 | tpu = devm_kzalloc(&pdev->dev, sizeof(*tpu), GFP_KERNEL); | ||
| 398 | if (tpu == NULL) { | ||
| 399 | dev_err(&pdev->dev, "failed to allocate driver data\n"); | ||
| 400 | return -ENOMEM; | ||
| 401 | } | ||
| 402 | |||
| 403 | tpu->pdata = pdev->dev.platform_data; | ||
| 404 | |||
| 405 | /* Map memory, get clock and pin control. */ | ||
| 406 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 407 | if (!res) { | ||
| 408 | dev_err(&pdev->dev, "failed to get I/O memory\n"); | ||
| 409 | return -ENXIO; | ||
| 410 | } | ||
| 411 | |||
| 412 | tpu->base = devm_ioremap_resource(&pdev->dev, res); | ||
| 413 | if (IS_ERR(tpu->base)) | ||
| 414 | return PTR_ERR(tpu->base); | ||
| 415 | |||
| 416 | tpu->clk = devm_clk_get(&pdev->dev, NULL); | ||
| 417 | if (IS_ERR(tpu->clk)) { | ||
| 418 | dev_err(&pdev->dev, "cannot get clock\n"); | ||
| 419 | return PTR_ERR(tpu->clk); | ||
| 420 | } | ||
| 421 | |||
| 422 | /* Initialize and register the device. */ | ||
| 423 | platform_set_drvdata(pdev, tpu); | ||
| 424 | |||
| 425 | spin_lock_init(&tpu->lock); | ||
| 426 | tpu->pdev = pdev; | ||
| 427 | |||
| 428 | tpu->chip.dev = &pdev->dev; | ||
| 429 | tpu->chip.ops = &tpu_pwm_ops; | ||
| 430 | tpu->chip.base = -1; | ||
| 431 | tpu->chip.npwm = TPU_CHANNEL_MAX; | ||
| 432 | |||
| 433 | ret = pwmchip_add(&tpu->chip); | ||
| 434 | if (ret < 0) { | ||
| 435 | dev_err(&pdev->dev, "failed to register PWM chip\n"); | ||
| 436 | return ret; | ||
| 437 | } | ||
| 438 | |||
| 439 | dev_info(&pdev->dev, "TPU PWM %d registered\n", tpu->pdev->id); | ||
| 440 | |||
| 441 | pm_runtime_enable(&pdev->dev); | ||
| 442 | |||
| 443 | return 0; | ||
| 444 | } | ||
| 445 | |||
| 446 | static int tpu_remove(struct platform_device *pdev) | ||
| 447 | { | ||
| 448 | struct tpu_device *tpu = platform_get_drvdata(pdev); | ||
| 449 | int ret; | ||
| 450 | |||
| 451 | ret = pwmchip_remove(&tpu->chip); | ||
| 452 | if (ret) | ||
| 453 | return ret; | ||
| 454 | |||
| 455 | pm_runtime_disable(&pdev->dev); | ||
| 456 | |||
| 457 | return 0; | ||
| 458 | } | ||
| 459 | |||
| 460 | static struct platform_driver tpu_driver = { | ||
| 461 | .probe = tpu_probe, | ||
| 462 | .remove = tpu_remove, | ||
| 463 | .driver = { | ||
| 464 | .name = "renesas-tpu-pwm", | ||
| 465 | .owner = THIS_MODULE, | ||
| 466 | } | ||
| 467 | }; | ||
| 468 | |||
| 469 | module_platform_driver(tpu_driver); | ||
| 470 | |||
| 471 | MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>"); | ||
| 472 | MODULE_DESCRIPTION("Renesas TPU PWM Driver"); | ||
| 473 | MODULE_LICENSE("GPL v2"); | ||
| 474 | MODULE_ALIAS("platform:renesas-tpu-pwm"); | ||
diff --git a/drivers/pwm/pwm-spear.c b/drivers/pwm/pwm-spear.c index 6d99e2cbdc73..a54d21401431 100644 --- a/drivers/pwm/pwm-spear.c +++ b/drivers/pwm/pwm-spear.c | |||
| @@ -259,6 +259,7 @@ MODULE_DEVICE_TABLE(of, spear_pwm_of_match); | |||
| 259 | static struct platform_driver spear_pwm_driver = { | 259 | static struct platform_driver spear_pwm_driver = { |
| 260 | .driver = { | 260 | .driver = { |
| 261 | .name = "spear-pwm", | 261 | .name = "spear-pwm", |
| 262 | .owner = THIS_MODULE, | ||
| 262 | .of_match_table = spear_pwm_of_match, | 263 | .of_match_table = spear_pwm_of_match, |
| 263 | }, | 264 | }, |
| 264 | .probe = spear_pwm_probe, | 265 | .probe = spear_pwm_probe, |
diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c index a5402933001f..74298c561c4e 100644 --- a/drivers/pwm/pwm-tegra.c +++ b/drivers/pwm/pwm-tegra.c | |||
| @@ -239,6 +239,7 @@ MODULE_DEVICE_TABLE(of, tegra_pwm_of_match); | |||
| 239 | static struct platform_driver tegra_pwm_driver = { | 239 | static struct platform_driver tegra_pwm_driver = { |
| 240 | .driver = { | 240 | .driver = { |
| 241 | .name = "tegra-pwm", | 241 | .name = "tegra-pwm", |
| 242 | .owner = THIS_MODULE, | ||
| 242 | .of_match_table = tegra_pwm_of_match, | 243 | .of_match_table = tegra_pwm_of_match, |
| 243 | }, | 244 | }, |
| 244 | .probe = tegra_pwm_probe, | 245 | .probe = tegra_pwm_probe, |
diff --git a/drivers/pwm/pwm-tiehrpwm.c b/drivers/pwm/pwm-tiehrpwm.c index 48a485c2e422..aa4c5586f53b 100644 --- a/drivers/pwm/pwm-tiehrpwm.c +++ b/drivers/pwm/pwm-tiehrpwm.c | |||
| @@ -359,7 +359,7 @@ static int ehrpwm_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) | |||
| 359 | configure_polarity(pc, pwm->hwpwm); | 359 | configure_polarity(pc, pwm->hwpwm); |
| 360 | 360 | ||
| 361 | /* Enable TBCLK before enabling PWM device */ | 361 | /* Enable TBCLK before enabling PWM device */ |
| 362 | ret = clk_prepare_enable(pc->tbclk); | 362 | ret = clk_enable(pc->tbclk); |
| 363 | if (ret) { | 363 | if (ret) { |
| 364 | pr_err("Failed to enable TBCLK for %s\n", | 364 | pr_err("Failed to enable TBCLK for %s\n", |
| 365 | dev_name(pc->chip.dev)); | 365 | dev_name(pc->chip.dev)); |
| @@ -395,7 +395,7 @@ static void ehrpwm_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) | |||
| 395 | ehrpwm_modify(pc->mmio_base, AQCSFRC, aqcsfrc_mask, aqcsfrc_val); | 395 | ehrpwm_modify(pc->mmio_base, AQCSFRC, aqcsfrc_mask, aqcsfrc_val); |
| 396 | 396 | ||
| 397 | /* Disabling TBCLK on PWM disable */ | 397 | /* Disabling TBCLK on PWM disable */ |
| 398 | clk_disable_unprepare(pc->tbclk); | 398 | clk_disable(pc->tbclk); |
| 399 | 399 | ||
| 400 | /* Stop Time base counter */ | 400 | /* Stop Time base counter */ |
| 401 | ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_RUN_MASK, TBCTL_STOP_NEXT); | 401 | ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_RUN_MASK, TBCTL_STOP_NEXT); |
| @@ -482,6 +482,12 @@ static int ehrpwm_pwm_probe(struct platform_device *pdev) | |||
| 482 | return PTR_ERR(pc->tbclk); | 482 | return PTR_ERR(pc->tbclk); |
| 483 | } | 483 | } |
| 484 | 484 | ||
| 485 | ret = clk_prepare(pc->tbclk); | ||
| 486 | if (ret < 0) { | ||
| 487 | dev_err(&pdev->dev, "clk_prepare() failed: %d\n", ret); | ||
| 488 | return ret; | ||
| 489 | } | ||
| 490 | |||
| 485 | ret = pwmchip_add(&pc->chip); | 491 | ret = pwmchip_add(&pc->chip); |
| 486 | if (ret < 0) { | 492 | if (ret < 0) { |
| 487 | dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); | 493 | dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); |
| @@ -508,6 +514,7 @@ pwmss_clk_failure: | |||
| 508 | pm_runtime_put_sync(&pdev->dev); | 514 | pm_runtime_put_sync(&pdev->dev); |
| 509 | pm_runtime_disable(&pdev->dev); | 515 | pm_runtime_disable(&pdev->dev); |
| 510 | pwmchip_remove(&pc->chip); | 516 | pwmchip_remove(&pc->chip); |
| 517 | clk_unprepare(pc->tbclk); | ||
| 511 | return ret; | 518 | return ret; |
| 512 | } | 519 | } |
| 513 | 520 | ||
| @@ -515,6 +522,8 @@ static int ehrpwm_pwm_remove(struct platform_device *pdev) | |||
| 515 | { | 522 | { |
| 516 | struct ehrpwm_pwm_chip *pc = platform_get_drvdata(pdev); | 523 | struct ehrpwm_pwm_chip *pc = platform_get_drvdata(pdev); |
| 517 | 524 | ||
| 525 | clk_unprepare(pc->tbclk); | ||
| 526 | |||
| 518 | pm_runtime_get_sync(&pdev->dev); | 527 | pm_runtime_get_sync(&pdev->dev); |
| 519 | /* | 528 | /* |
| 520 | * Due to hardware misbehaviour, acknowledge of the stop_req | 529 | * Due to hardware misbehaviour, acknowledge of the stop_req |
diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c new file mode 100644 index 000000000000..8ca5de316d3b --- /dev/null +++ b/drivers/pwm/sysfs.c | |||
| @@ -0,0 +1,352 @@ | |||
| 1 | /* | ||
| 2 | * A simple sysfs interface for the generic PWM framework | ||
| 3 | * | ||
| 4 | * Copyright (C) 2013 H Hartley Sweeten <hsweeten@visionengravers.com> | ||
| 5 | * | ||
| 6 | * Based on previous work by Lars Poeschel <poeschel@lemonage.de> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License as published by | ||
| 10 | * the Free Software Foundation; either version 2, or (at your option) | ||
| 11 | * any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | * GNU General Public License for more details. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <linux/device.h> | ||
| 20 | #include <linux/mutex.h> | ||
| 21 | #include <linux/err.h> | ||
| 22 | #include <linux/slab.h> | ||
| 23 | #include <linux/kdev_t.h> | ||
| 24 | #include <linux/pwm.h> | ||
| 25 | |||
| 26 | struct pwm_export { | ||
| 27 | struct device child; | ||
| 28 | struct pwm_device *pwm; | ||
| 29 | }; | ||
| 30 | |||
| 31 | static struct pwm_export *child_to_pwm_export(struct device *child) | ||
| 32 | { | ||
| 33 | return container_of(child, struct pwm_export, child); | ||
| 34 | } | ||
| 35 | |||
| 36 | static struct pwm_device *child_to_pwm_device(struct device *child) | ||
| 37 | { | ||
| 38 | struct pwm_export *export = child_to_pwm_export(child); | ||
| 39 | |||
| 40 | return export->pwm; | ||
| 41 | } | ||
| 42 | |||
| 43 | static ssize_t pwm_period_show(struct device *child, | ||
| 44 | struct device_attribute *attr, | ||
| 45 | char *buf) | ||
| 46 | { | ||
| 47 | const struct pwm_device *pwm = child_to_pwm_device(child); | ||
| 48 | |||
| 49 | return sprintf(buf, "%u\n", pwm->period); | ||
| 50 | } | ||
| 51 | |||
| 52 | static ssize_t pwm_period_store(struct device *child, | ||
| 53 | struct device_attribute *attr, | ||
| 54 | const char *buf, size_t size) | ||
| 55 | { | ||
| 56 | struct pwm_device *pwm = child_to_pwm_device(child); | ||
| 57 | unsigned int val; | ||
| 58 | int ret; | ||
| 59 | |||
| 60 | ret = kstrtouint(buf, 0, &val); | ||
| 61 | if (ret) | ||
| 62 | return ret; | ||
| 63 | |||
| 64 | ret = pwm_config(pwm, pwm->duty_cycle, val); | ||
| 65 | |||
| 66 | return ret ? : size; | ||
| 67 | } | ||
| 68 | |||
| 69 | static ssize_t pwm_duty_cycle_show(struct device *child, | ||
| 70 | struct device_attribute *attr, | ||
| 71 | char *buf) | ||
| 72 | { | ||
| 73 | const struct pwm_device *pwm = child_to_pwm_device(child); | ||
| 74 | |||
| 75 | return sprintf(buf, "%u\n", pwm->duty_cycle); | ||
| 76 | } | ||
| 77 | |||
| 78 | static ssize_t pwm_duty_cycle_store(struct device *child, | ||
| 79 | struct device_attribute *attr, | ||
| 80 | const char *buf, size_t size) | ||
| 81 | { | ||
| 82 | struct pwm_device *pwm = child_to_pwm_device(child); | ||
| 83 | unsigned int val; | ||
| 84 | int ret; | ||
| 85 | |||
| 86 | ret = kstrtouint(buf, 0, &val); | ||
| 87 | if (ret) | ||
| 88 | return ret; | ||
| 89 | |||
| 90 | ret = pwm_config(pwm, val, pwm->period); | ||
| 91 | |||
| 92 | return ret ? : size; | ||
| 93 | } | ||
| 94 | |||
| 95 | static ssize_t pwm_enable_show(struct device *child, | ||
| 96 | struct device_attribute *attr, | ||
| 97 | char *buf) | ||
| 98 | { | ||
| 99 | const struct pwm_device *pwm = child_to_pwm_device(child); | ||
| 100 | int enabled = test_bit(PWMF_ENABLED, &pwm->flags); | ||
| 101 | |||
| 102 | return sprintf(buf, "%d\n", enabled); | ||
| 103 | } | ||
| 104 | |||
| 105 | static ssize_t pwm_enable_store(struct device *child, | ||
| 106 | struct device_attribute *attr, | ||
| 107 | const char *buf, size_t size) | ||
| 108 | { | ||
| 109 | struct pwm_device *pwm = child_to_pwm_device(child); | ||
| 110 | int val, ret; | ||
| 111 | |||
| 112 | ret = kstrtoint(buf, 0, &val); | ||
| 113 | if (ret) | ||
| 114 | return ret; | ||
| 115 | |||
| 116 | switch (val) { | ||
| 117 | case 0: | ||
| 118 | pwm_disable(pwm); | ||
| 119 | break; | ||
| 120 | case 1: | ||
| 121 | ret = pwm_enable(pwm); | ||
| 122 | break; | ||
| 123 | default: | ||
| 124 | ret = -EINVAL; | ||
| 125 | break; | ||
| 126 | } | ||
| 127 | |||
| 128 | return ret ? : size; | ||
| 129 | } | ||
| 130 | |||
| 131 | static ssize_t pwm_polarity_show(struct device *child, | ||
| 132 | struct device_attribute *attr, | ||
| 133 | char *buf) | ||
| 134 | { | ||
| 135 | const struct pwm_device *pwm = child_to_pwm_device(child); | ||
| 136 | |||
| 137 | return sprintf(buf, "%s\n", pwm->polarity ? "inversed" : "normal"); | ||
| 138 | } | ||
| 139 | |||
| 140 | static ssize_t pwm_polarity_store(struct device *child, | ||
| 141 | struct device_attribute *attr, | ||
| 142 | const char *buf, size_t size) | ||
| 143 | { | ||
| 144 | struct pwm_device *pwm = child_to_pwm_device(child); | ||
| 145 | enum pwm_polarity polarity; | ||
| 146 | int ret; | ||
| 147 | |||
| 148 | if (sysfs_streq(buf, "normal")) | ||
| 149 | polarity = PWM_POLARITY_NORMAL; | ||
| 150 | else if (sysfs_streq(buf, "inversed")) | ||
| 151 | polarity = PWM_POLARITY_INVERSED; | ||
| 152 | else | ||
| 153 | return -EINVAL; | ||
| 154 | |||
| 155 | ret = pwm_set_polarity(pwm, polarity); | ||
| 156 | |||
| 157 | return ret ? : size; | ||
| 158 | } | ||
| 159 | |||
| 160 | static DEVICE_ATTR(period, 0644, pwm_period_show, pwm_period_store); | ||
| 161 | static DEVICE_ATTR(duty_cycle, 0644, pwm_duty_cycle_show, pwm_duty_cycle_store); | ||
| 162 | static DEVICE_ATTR(enable, 0644, pwm_enable_show, pwm_enable_store); | ||
| 163 | static DEVICE_ATTR(polarity, 0644, pwm_polarity_show, pwm_polarity_store); | ||
| 164 | |||
| 165 | static struct attribute *pwm_attrs[] = { | ||
| 166 | &dev_attr_period.attr, | ||
| 167 | &dev_attr_duty_cycle.attr, | ||
| 168 | &dev_attr_enable.attr, | ||
| 169 | &dev_attr_polarity.attr, | ||
| 170 | NULL | ||
| 171 | }; | ||
| 172 | |||
| 173 | static const struct attribute_group pwm_attr_group = { | ||
| 174 | .attrs = pwm_attrs, | ||
| 175 | }; | ||
| 176 | |||
| 177 | static const struct attribute_group *pwm_attr_groups[] = { | ||
| 178 | &pwm_attr_group, | ||
| 179 | NULL, | ||
| 180 | }; | ||
| 181 | |||
| 182 | static void pwm_export_release(struct device *child) | ||
| 183 | { | ||
| 184 | struct pwm_export *export = child_to_pwm_export(child); | ||
| 185 | |||
| 186 | kfree(export); | ||
| 187 | } | ||
| 188 | |||
| 189 | static int pwm_export_child(struct device *parent, struct pwm_device *pwm) | ||
| 190 | { | ||
| 191 | struct pwm_export *export; | ||
| 192 | int ret; | ||
| 193 | |||
| 194 | if (test_and_set_bit(PWMF_EXPORTED, &pwm->flags)) | ||
| 195 | return -EBUSY; | ||
| 196 | |||
| 197 | export = kzalloc(sizeof(*export), GFP_KERNEL); | ||
| 198 | if (!export) { | ||
| 199 | clear_bit(PWMF_EXPORTED, &pwm->flags); | ||
| 200 | return -ENOMEM; | ||
| 201 | } | ||
| 202 | |||
| 203 | export->pwm = pwm; | ||
| 204 | |||
| 205 | export->child.release = pwm_export_release; | ||
| 206 | export->child.parent = parent; | ||
| 207 | export->child.devt = MKDEV(0, 0); | ||
| 208 | export->child.groups = pwm_attr_groups; | ||
| 209 | dev_set_name(&export->child, "pwm%u", pwm->hwpwm); | ||
| 210 | |||
| 211 | ret = device_register(&export->child); | ||
| 212 | if (ret) { | ||
| 213 | clear_bit(PWMF_EXPORTED, &pwm->flags); | ||
| 214 | kfree(export); | ||
| 215 | return ret; | ||
| 216 | } | ||
| 217 | |||
| 218 | return 0; | ||
| 219 | } | ||
| 220 | |||
| 221 | static int pwm_unexport_match(struct device *child, void *data) | ||
| 222 | { | ||
| 223 | return child_to_pwm_device(child) == data; | ||
| 224 | } | ||
| 225 | |||
| 226 | static int pwm_unexport_child(struct device *parent, struct pwm_device *pwm) | ||
| 227 | { | ||
| 228 | struct device *child; | ||
| 229 | |||
| 230 | if (!test_and_clear_bit(PWMF_EXPORTED, &pwm->flags)) | ||
| 231 | return -ENODEV; | ||
| 232 | |||
| 233 | child = device_find_child(parent, pwm, pwm_unexport_match); | ||
| 234 | if (!child) | ||
| 235 | return -ENODEV; | ||
| 236 | |||
| 237 | /* for device_find_child() */ | ||
| 238 | put_device(child); | ||
| 239 | device_unregister(child); | ||
| 240 | pwm_put(pwm); | ||
| 241 | |||
| 242 | return 0; | ||
| 243 | } | ||
| 244 | |||
| 245 | static ssize_t pwm_export_store(struct device *parent, | ||
| 246 | struct device_attribute *attr, | ||
| 247 | const char *buf, size_t len) | ||
| 248 | { | ||
| 249 | struct pwm_chip *chip = dev_get_drvdata(parent); | ||
| 250 | struct pwm_device *pwm; | ||
| 251 | unsigned int hwpwm; | ||
| 252 | int ret; | ||
| 253 | |||
| 254 | ret = kstrtouint(buf, 0, &hwpwm); | ||
| 255 | if (ret < 0) | ||
| 256 | return ret; | ||
| 257 | |||
| 258 | if (hwpwm >= chip->npwm) | ||
| 259 | return -ENODEV; | ||
| 260 | |||
| 261 | pwm = pwm_request_from_chip(chip, hwpwm, "sysfs"); | ||
| 262 | if (IS_ERR(pwm)) | ||
| 263 | return PTR_ERR(pwm); | ||
| 264 | |||
| 265 | ret = pwm_export_child(parent, pwm); | ||
| 266 | if (ret < 0) | ||
| 267 | pwm_put(pwm); | ||
| 268 | |||
| 269 | return ret ? : len; | ||
| 270 | } | ||
| 271 | |||
| 272 | static ssize_t pwm_unexport_store(struct device *parent, | ||
| 273 | struct device_attribute *attr, | ||
| 274 | const char *buf, size_t len) | ||
| 275 | { | ||
| 276 | struct pwm_chip *chip = dev_get_drvdata(parent); | ||
| 277 | unsigned int hwpwm; | ||
| 278 | int ret; | ||
| 279 | |||
| 280 | ret = kstrtouint(buf, 0, &hwpwm); | ||
| 281 | if (ret < 0) | ||
| 282 | return ret; | ||
| 283 | |||
| 284 | if (hwpwm >= chip->npwm) | ||
| 285 | return -ENODEV; | ||
| 286 | |||
| 287 | ret = pwm_unexport_child(parent, &chip->pwms[hwpwm]); | ||
| 288 | |||
| 289 | return ret ? : len; | ||
| 290 | } | ||
| 291 | |||
| 292 | static ssize_t pwm_npwm_show(struct device *parent, | ||
| 293 | struct device_attribute *attr, | ||
| 294 | char *buf) | ||
| 295 | { | ||
| 296 | const struct pwm_chip *chip = dev_get_drvdata(parent); | ||
| 297 | |||
| 298 | return sprintf(buf, "%u\n", chip->npwm); | ||
| 299 | } | ||
| 300 | |||
| 301 | static struct device_attribute pwm_chip_attrs[] = { | ||
| 302 | __ATTR(export, 0200, NULL, pwm_export_store), | ||
| 303 | __ATTR(unexport, 0200, NULL, pwm_unexport_store), | ||
| 304 | __ATTR(npwm, 0444, pwm_npwm_show, NULL), | ||
| 305 | __ATTR_NULL, | ||
| 306 | }; | ||
| 307 | |||
| 308 | static struct class pwm_class = { | ||
| 309 | .name = "pwm", | ||
| 310 | .owner = THIS_MODULE, | ||
| 311 | .dev_attrs = pwm_chip_attrs, | ||
| 312 | }; | ||
| 313 | |||
| 314 | static int pwmchip_sysfs_match(struct device *parent, const void *data) | ||
| 315 | { | ||
| 316 | return dev_get_drvdata(parent) == data; | ||
| 317 | } | ||
| 318 | |||
| 319 | void pwmchip_sysfs_export(struct pwm_chip *chip) | ||
| 320 | { | ||
| 321 | struct device *parent; | ||
| 322 | |||
| 323 | /* | ||
| 324 | * If device_create() fails the pwm_chip is still usable by | ||
| 325 | * the kernel its just not exported. | ||
| 326 | */ | ||
| 327 | parent = device_create(&pwm_class, chip->dev, MKDEV(0, 0), chip, | ||
| 328 | "pwmchip%d", chip->base); | ||
| 329 | if (IS_ERR(parent)) { | ||
| 330 | dev_warn(chip->dev, | ||
| 331 | "device_create failed for pwm_chip sysfs export\n"); | ||
| 332 | } | ||
| 333 | } | ||
| 334 | |||
| 335 | void pwmchip_sysfs_unexport(struct pwm_chip *chip) | ||
| 336 | { | ||
| 337 | struct device *parent; | ||
| 338 | |||
| 339 | parent = class_find_device(&pwm_class, NULL, chip, | ||
| 340 | pwmchip_sysfs_match); | ||
| 341 | if (parent) { | ||
| 342 | /* for class_find_device() */ | ||
| 343 | put_device(parent); | ||
| 344 | device_unregister(parent); | ||
| 345 | } | ||
| 346 | } | ||
| 347 | |||
| 348 | static int __init pwm_sysfs_init(void) | ||
| 349 | { | ||
| 350 | return class_register(&pwm_class); | ||
| 351 | } | ||
| 352 | subsys_initcall(pwm_sysfs_init); | ||
diff --git a/include/linux/platform_data/pwm-renesas-tpu.h b/include/linux/platform_data/pwm-renesas-tpu.h new file mode 100644 index 000000000000..a7220b10ddab --- /dev/null +++ b/include/linux/platform_data/pwm-renesas-tpu.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #ifndef __PWM_RENESAS_TPU_H__ | ||
| 2 | #define __PWM_RENESAS_TPU_H__ | ||
| 3 | |||
| 4 | #include <linux/pwm.h> | ||
| 5 | |||
| 6 | #define TPU_CHANNEL_MAX 4 | ||
| 7 | |||
| 8 | struct tpu_pwm_channel_data { | ||
| 9 | enum pwm_polarity polarity; | ||
| 10 | }; | ||
| 11 | |||
| 12 | struct tpu_pwm_platform_data { | ||
| 13 | struct tpu_pwm_channel_data channels[TPU_CHANNEL_MAX]; | ||
| 14 | }; | ||
| 15 | |||
| 16 | #endif /* __PWM_RENESAS_TPU_H__ */ | ||
diff --git a/include/linux/pwm.h b/include/linux/pwm.h index a4df2042b79c..f0feafd184a0 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h | |||
| @@ -76,6 +76,7 @@ enum pwm_polarity { | |||
| 76 | enum { | 76 | enum { |
| 77 | PWMF_REQUESTED = 1 << 0, | 77 | PWMF_REQUESTED = 1 << 0, |
| 78 | PWMF_ENABLED = 1 << 1, | 78 | PWMF_ENABLED = 1 << 1, |
| 79 | PWMF_EXPORTED = 1 << 2, | ||
| 79 | }; | 80 | }; |
| 80 | 81 | ||
| 81 | struct pwm_device { | 82 | struct pwm_device { |
| @@ -86,7 +87,9 @@ struct pwm_device { | |||
| 86 | struct pwm_chip *chip; | 87 | struct pwm_chip *chip; |
| 87 | void *chip_data; | 88 | void *chip_data; |
| 88 | 89 | ||
| 89 | unsigned int period; /* in nanoseconds */ | 90 | unsigned int period; /* in nanoseconds */ |
| 91 | unsigned int duty_cycle; /* in nanoseconds */ | ||
| 92 | enum pwm_polarity polarity; | ||
| 90 | }; | 93 | }; |
| 91 | 94 | ||
| 92 | static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period) | 95 | static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period) |
| @@ -100,6 +103,17 @@ static inline unsigned int pwm_get_period(struct pwm_device *pwm) | |||
| 100 | return pwm ? pwm->period : 0; | 103 | return pwm ? pwm->period : 0; |
| 101 | } | 104 | } |
| 102 | 105 | ||
| 106 | static inline void pwm_set_duty_cycle(struct pwm_device *pwm, unsigned int duty) | ||
| 107 | { | ||
| 108 | if (pwm) | ||
| 109 | pwm->duty_cycle = duty; | ||
| 110 | } | ||
| 111 | |||
| 112 | static inline unsigned int pwm_get_duty_cycle(struct pwm_device *pwm) | ||
| 113 | { | ||
| 114 | return pwm ? pwm->duty_cycle : 0; | ||
| 115 | } | ||
| 116 | |||
| 103 | /* | 117 | /* |
| 104 | * pwm_set_polarity - configure the polarity of a PWM signal | 118 | * pwm_set_polarity - configure the polarity of a PWM signal |
| 105 | */ | 119 | */ |
| @@ -278,4 +292,17 @@ static inline void pwm_add_table(struct pwm_lookup *table, size_t num) | |||
| 278 | } | 292 | } |
| 279 | #endif | 293 | #endif |
| 280 | 294 | ||
| 295 | #ifdef CONFIG_PWM_SYSFS | ||
| 296 | void pwmchip_sysfs_export(struct pwm_chip *chip); | ||
| 297 | void pwmchip_sysfs_unexport(struct pwm_chip *chip); | ||
| 298 | #else | ||
| 299 | static inline void pwmchip_sysfs_export(struct pwm_chip *chip) | ||
| 300 | { | ||
| 301 | } | ||
| 302 | |||
| 303 | static inline void pwmchip_sysfs_unexport(struct pwm_chip *chip) | ||
| 304 | { | ||
| 305 | } | ||
| 306 | #endif /* CONFIG_PWM_SYSFS */ | ||
| 307 | |||
| 281 | #endif /* __LINUX_PWM_H */ | 308 | #endif /* __LINUX_PWM_H */ |
