aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pwm
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-10-04 23:01:30 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-04 23:01:30 -0400
commit578f1ef91aa92beb571bfb9af8f4d18f405f3b9e (patch)
tree8ff59e772d09180b7e7f952a8c90a1bcf25e1d19 /drivers/pwm
parentecefbd94b834fa32559d854646d777c56749ef1c (diff)
parent74d8378159de16a0a1d1975d4778120d263d6000 (diff)
Merge tag 'mfd-3.7-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6
Pull MFD changes from Samuel Ortiz: "MFD bits for the 3.7 merge window. As usual we have a few new drivers: - TI LP8788 - TI OMAP USB TLL - Maxim MAX8907 - SMSC ECE1099 - Dialog Semiconductor DA9055 - A simpler syscon driver that allow us to get rid of the anatop one. Drivers are also gradually getting Device Tree and IRQ domain support. The following drivers got DT support: - palmas, 88pm860x, tc3589x and twl4030-audio And those ones now use the IRQ domain APIs: - 88pm860x, tc3589x, db8500_prcmu Also some other interesting changes: - Intel's ICH LPC now supports Lynx Point - TI's twl4030-audio added a GPO child - tps6527 enabled its backlight subdevice - The twl6030 pwm driver moved to the new PWM subsystem And finally a bunch of cleanup and casual fixes for mc13xxx, 88pm860x, palmas, ab8500, wm8994, wm5110, max8907 and the tps65xxx family." Fix up various annoying conflicts: the DT and IRQ domain support came in twice and was already in 3.6. And then it was apparently rebased. Guys, DON'T REBASE! * tag 'mfd-3.7-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6: (89 commits) ARM: dts: Enable 88pm860x pmic mfd: 88pm860x: Move gpadc init into touch mfd: 88pm860x: Device tree support mfd: 88pm860x: Use irqdomain mfd: smsc: Add support for smsc gpio io/keypad driver backlight: tps65217_bl: Add missing platform_set_drvdata in tps65217_bl_probe mfd: DA9055 core driver mfd: tps65910: Add alarm interrupt of TPS65910 RTC to mfd device list mfd: wm5110: Add register patches for revision B mfd: wm5110: Disable control interface error report for WM5110 rev B mfd: max8907: Remove regulator-compatible from DT docs backlight: Add TPS65217 WLED driver mfd: Add backlight as subdevice to the tps65217 mfd: Provide the PRCMU with its own IRQ domain mfd: Fix max8907 sparse warning mfd: Add lp8788 mfd driver mfd: dbx500: Provide a more accurate smp_twd clock mfd: rc5t583: Fix warning messages regulator: palmas: Add DT support mfd: palmas: Change regulator defns to better suite DT ...
Diffstat (limited to 'drivers/pwm')
-rw-r--r--drivers/pwm/Kconfig9
-rw-r--r--drivers/pwm/Makefile1
-rw-r--r--drivers/pwm/pwm-twl6030.c184
3 files changed, 194 insertions, 0 deletions
diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 90c5c7357a50..d7c6b83097c1 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -115,6 +115,15 @@ config PWM_TIEHRPWM
115 To compile this driver as a module, choose M here: the module 115 To compile this driver as a module, choose M here: the module
116 will be called pwm-tiehrpwm. 116 will be called pwm-tiehrpwm.
117 117
118config PWM_TWL6030
119 tristate "TWL6030 PWM support"
120 depends on TWL4030_CORE
121 help
122 Generic PWM framework driver for TWL6030.
123
124 To compile this driver as a module, choose M here: the module
125 will be called pwm-twl6030.
126
118config PWM_VT8500 127config PWM_VT8500
119 tristate "vt8500 pwm support" 128 tristate "vt8500 pwm support"
120 depends on ARCH_VT8500 129 depends on ARCH_VT8500
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index e4b2c898964d..78f123dca30d 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -8,4 +8,5 @@ obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.o
8obj-$(CONFIG_PWM_TEGRA) += pwm-tegra.o 8obj-$(CONFIG_PWM_TEGRA) += pwm-tegra.o
9obj-$(CONFIG_PWM_TIECAP) += pwm-tiecap.o 9obj-$(CONFIG_PWM_TIECAP) += pwm-tiecap.o
10obj-$(CONFIG_PWM_TIEHRPWM) += pwm-tiehrpwm.o 10obj-$(CONFIG_PWM_TIEHRPWM) += pwm-tiehrpwm.o
11obj-$(CONFIG_PWM_TWL6030) += pwm-twl6030.o
11obj-$(CONFIG_PWM_VT8500) += pwm-vt8500.o 12obj-$(CONFIG_PWM_VT8500) += pwm-vt8500.o
diff --git a/drivers/pwm/pwm-twl6030.c b/drivers/pwm/pwm-twl6030.c
new file mode 100644
index 000000000000..8e6387864ca2
--- /dev/null
+++ b/drivers/pwm/pwm-twl6030.c
@@ -0,0 +1,184 @@
1/*
2 * twl6030_pwm.c
3 * Driver for PHOENIX (TWL6030) Pulse Width Modulator
4 *
5 * Copyright (C) 2010 Texas Instruments
6 * Author: Hemanth V <hemanthv@ti.com>
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/module.h>
22#include <linux/platform_device.h>
23#include <linux/pwm.h>
24#include <linux/i2c/twl.h>
25#include <linux/slab.h>
26
27#define LED_PWM_CTRL1 0xF4
28#define LED_PWM_CTRL2 0xF5
29
30/* Max value for CTRL1 register */
31#define PWM_CTRL1_MAX 255
32
33/* Pull down disable */
34#define PWM_CTRL2_DIS_PD (1 << 6)
35
36/* Current control 2.5 milli Amps */
37#define PWM_CTRL2_CURR_02 (2 << 4)
38
39/* LED supply source */
40#define PWM_CTRL2_SRC_VAC (1 << 2)
41
42/* LED modes */
43#define PWM_CTRL2_MODE_HW (0 << 0)
44#define PWM_CTRL2_MODE_SW (1 << 0)
45#define PWM_CTRL2_MODE_DIS (2 << 0)
46
47#define PWM_CTRL2_MODE_MASK 0x3
48
49struct twl6030_pwm_chip {
50 struct pwm_chip chip;
51};
52
53static int twl6030_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
54{
55 int ret;
56 u8 val;
57
58 /* Configure PWM */
59 val = PWM_CTRL2_DIS_PD | PWM_CTRL2_CURR_02 | PWM_CTRL2_SRC_VAC |
60 PWM_CTRL2_MODE_HW;
61
62 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, LED_PWM_CTRL2);
63 if (ret < 0) {
64 dev_err(chip->dev, "%s: Failed to configure PWM, Error %d\n",
65 pwm->label, ret);
66 return ret;
67 }
68
69 return 0;
70}
71
72static int twl6030_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
73 int duty_ns, int period_ns)
74{
75 u8 duty_cycle = (duty_ns * PWM_CTRL1_MAX) / period_ns;
76 int ret;
77
78 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, duty_cycle, LED_PWM_CTRL1);
79 if (ret < 0) {
80 pr_err("%s: Failed to configure PWM, Error %d\n",
81 pwm->label, ret);
82 return ret;
83 }
84
85 return 0;
86}
87
88static int twl6030_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
89{
90 int ret;
91 u8 val;
92
93 ret = twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, LED_PWM_CTRL2);
94 if (ret < 0) {
95 dev_err(chip->dev, "%s: Failed to enable PWM, Error %d\n",
96 pwm->label, ret);
97 return ret;
98 }
99
100 /* Change mode to software control */
101 val &= ~PWM_CTRL2_MODE_MASK;
102 val |= PWM_CTRL2_MODE_SW;
103
104 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, LED_PWM_CTRL2);
105 if (ret < 0) {
106 dev_err(chip->dev, "%s: Failed to enable PWM, Error %d\n",
107 pwm->label, ret);
108 return ret;
109 }
110
111 twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, LED_PWM_CTRL2);
112 return 0;
113}
114
115static void twl6030_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
116{
117 int ret;
118 u8 val;
119
120 ret = twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, LED_PWM_CTRL2);
121 if (ret < 0) {
122 dev_err(chip->dev, "%s: Failed to disable PWM, Error %d\n",
123 pwm->label, ret);
124 return;
125 }
126
127 val &= ~PWM_CTRL2_MODE_MASK;
128 val |= PWM_CTRL2_MODE_HW;
129
130 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, LED_PWM_CTRL2);
131 if (ret < 0) {
132 dev_err(chip->dev, "%s: Failed to disable PWM, Error %d\n",
133 pwm->label, ret);
134 }
135}
136
137static const struct pwm_ops twl6030_pwm_ops = {
138 .request = twl6030_pwm_request,
139 .config = twl6030_pwm_config,
140 .enable = twl6030_pwm_enable,
141 .disable = twl6030_pwm_disable,
142};
143
144static int twl6030_pwm_probe(struct platform_device *pdev)
145{
146 struct twl6030_pwm_chip *twl6030;
147 int ret;
148
149 twl6030 = devm_kzalloc(&pdev->dev, sizeof(*twl6030), GFP_KERNEL);
150 if (!twl6030)
151 return -ENOMEM;
152
153 twl6030->chip.dev = &pdev->dev;
154 twl6030->chip.ops = &twl6030_pwm_ops;
155 twl6030->chip.base = -1;
156 twl6030->chip.npwm = 1;
157
158 ret = pwmchip_add(&twl6030->chip);
159 if (ret < 0)
160 return ret;
161
162 platform_set_drvdata(pdev, twl6030);
163
164 return 0;
165}
166
167static int twl6030_pwm_remove(struct platform_device *pdev)
168{
169 struct twl6030_pwm_chip *twl6030 = platform_get_drvdata(pdev);
170
171 return pwmchip_remove(&twl6030->chip);
172}
173
174static struct platform_driver twl6030_pwm_driver = {
175 .driver = {
176 .name = "twl6030-pwm",
177 },
178 .probe = twl6030_pwm_probe,
179 .remove = __devexit_p(twl6030_pwm_remove),
180};
181module_platform_driver(twl6030_pwm_driver);
182
183MODULE_ALIAS("platform:twl6030-pwm");
184MODULE_LICENSE("GPL");