diff options
author | Thierry Reding <thierry.reding@avionic-design.de> | 2012-09-18 04:29:51 -0400 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-09-19 06:04:25 -0400 |
commit | 48a364b758f861b21747a5148f26aedc504edb7f (patch) | |
tree | e76941d9155ecd0dc5534ef840a5c0d6ddc107f0 /drivers/mfd | |
parent | f78959cfa335196ba36d8c4651078f14dc07f2a8 (diff) |
pwm: Move TWL6030 PWM driver to PWM framework
This commit moves the driver to drivers/pwm and converts it to the new
PWM framework. In order for this to work properly, register the PWM as
child of the multi-function TWL6030 device.
Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Acked-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd')
-rw-r--r-- | drivers/mfd/Kconfig | 10 | ||||
-rw-r--r-- | drivers/mfd/Makefile | 1 | ||||
-rw-r--r-- | drivers/mfd/twl-core.c | 7 | ||||
-rw-r--r-- | drivers/mfd/twl6030-pwm.c | 165 |
4 files changed, 7 insertions, 176 deletions
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index b0d7d9b5b7d4..2143fd283a74 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig | |||
@@ -298,16 +298,6 @@ config MFD_TWL4030_AUDIO | |||
298 | select MFD_CORE | 298 | select MFD_CORE |
299 | default n | 299 | default n |
300 | 300 | ||
301 | config TWL6030_PWM | ||
302 | tristate "TWL6030 PWM (Pulse Width Modulator) Support" | ||
303 | depends on TWL4030_CORE | ||
304 | select HAVE_PWM | ||
305 | depends on !PWM | ||
306 | default n | ||
307 | help | ||
308 | Say yes here if you want support for TWL6030 PWM. | ||
309 | This is used to control charging LED brightness. | ||
310 | |||
311 | config TWL6040_CORE | 301 | config TWL6040_CORE |
312 | bool "Support for TWL6040 audio codec" | 302 | bool "Support for TWL6040 audio codec" |
313 | depends on I2C=y && GENERIC_HARDIRQS | 303 | depends on I2C=y && GENERIC_HARDIRQS |
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index b88cdb876e15..95dfa14ad174 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile | |||
@@ -63,7 +63,6 @@ obj-$(CONFIG_TWL4030_CORE) += twl-core.o twl4030-irq.o twl6030-irq.o | |||
63 | obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o | 63 | obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o |
64 | obj-$(CONFIG_TWL4030_POWER) += twl4030-power.o | 64 | obj-$(CONFIG_TWL4030_POWER) += twl4030-power.o |
65 | obj-$(CONFIG_MFD_TWL4030_AUDIO) += twl4030-audio.o | 65 | obj-$(CONFIG_MFD_TWL4030_AUDIO) += twl4030-audio.o |
66 | obj-$(CONFIG_TWL6030_PWM) += twl6030-pwm.o | ||
67 | obj-$(CONFIG_TWL6040_CORE) += twl6040-core.o twl6040-irq.o | 66 | obj-$(CONFIG_TWL6040_CORE) += twl6040-core.o twl6040-irq.o |
68 | 67 | ||
69 | obj-$(CONFIG_MFD_MC13XXX) += mc13xxx-core.o | 68 | obj-$(CONFIG_MFD_MC13XXX) += mc13xxx-core.o |
diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c index e208d88d2180..3d700129cf3e 100644 --- a/drivers/mfd/twl-core.c +++ b/drivers/mfd/twl-core.c | |||
@@ -670,6 +670,13 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base, | |||
670 | return PTR_ERR(child); | 670 | return PTR_ERR(child); |
671 | } | 671 | } |
672 | 672 | ||
673 | if (IS_ENABLED(CONFIG_PWM_TWL6030) && twl_class_is_6030()) { | ||
674 | child = add_child(TWL6030_MODULE_ID1, "twl6030-pwm", NULL, 0, | ||
675 | false, 0, 0); | ||
676 | if (IS_ERR(child)) | ||
677 | return PTR_ERR(child); | ||
678 | } | ||
679 | |||
673 | if (IS_ENABLED(CONFIG_TWL4030_USB) && pdata->usb && | 680 | if (IS_ENABLED(CONFIG_TWL4030_USB) && pdata->usb && |
674 | twl_class_is_4030()) { | 681 | twl_class_is_4030()) { |
675 | 682 | ||
diff --git a/drivers/mfd/twl6030-pwm.c b/drivers/mfd/twl6030-pwm.c deleted file mode 100644 index e8fee147678d..000000000000 --- a/drivers/mfd/twl6030-pwm.c +++ /dev/null | |||
@@ -1,165 +0,0 @@ | |||
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/i2c/twl.h> | ||
24 | #include <linux/slab.h> | ||
25 | |||
26 | #define LED_PWM_CTRL1 0xF4 | ||
27 | #define LED_PWM_CTRL2 0xF5 | ||
28 | |||
29 | /* Max value for CTRL1 register */ | ||
30 | #define PWM_CTRL1_MAX 255 | ||
31 | |||
32 | /* Pull down disable */ | ||
33 | #define PWM_CTRL2_DIS_PD (1 << 6) | ||
34 | |||
35 | /* Current control 2.5 milli Amps */ | ||
36 | #define PWM_CTRL2_CURR_02 (2 << 4) | ||
37 | |||
38 | /* LED supply source */ | ||
39 | #define PWM_CTRL2_SRC_VAC (1 << 2) | ||
40 | |||
41 | /* LED modes */ | ||
42 | #define PWM_CTRL2_MODE_HW (0 << 0) | ||
43 | #define PWM_CTRL2_MODE_SW (1 << 0) | ||
44 | #define PWM_CTRL2_MODE_DIS (2 << 0) | ||
45 | |||
46 | #define PWM_CTRL2_MODE_MASK 0x3 | ||
47 | |||
48 | struct pwm_device { | ||
49 | const char *label; | ||
50 | unsigned int pwm_id; | ||
51 | }; | ||
52 | |||
53 | int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns) | ||
54 | { | ||
55 | u8 duty_cycle; | ||
56 | int ret; | ||
57 | |||
58 | if (pwm == NULL || period_ns == 0 || duty_ns > period_ns) | ||
59 | return -EINVAL; | ||
60 | |||
61 | duty_cycle = (duty_ns * PWM_CTRL1_MAX) / period_ns; | ||
62 | |||
63 | ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, duty_cycle, LED_PWM_CTRL1); | ||
64 | |||
65 | if (ret < 0) { | ||
66 | pr_err("%s: Failed to configure PWM, Error %d\n", | ||
67 | pwm->label, ret); | ||
68 | return ret; | ||
69 | } | ||
70 | return 0; | ||
71 | } | ||
72 | EXPORT_SYMBOL(pwm_config); | ||
73 | |||
74 | int pwm_enable(struct pwm_device *pwm) | ||
75 | { | ||
76 | u8 val; | ||
77 | int ret; | ||
78 | |||
79 | ret = twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, LED_PWM_CTRL2); | ||
80 | if (ret < 0) { | ||
81 | pr_err("%s: Failed to enable PWM, Error %d\n", pwm->label, ret); | ||
82 | return ret; | ||
83 | } | ||
84 | |||
85 | /* Change mode to software control */ | ||
86 | val &= ~PWM_CTRL2_MODE_MASK; | ||
87 | val |= PWM_CTRL2_MODE_SW; | ||
88 | |||
89 | ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, LED_PWM_CTRL2); | ||
90 | if (ret < 0) { | ||
91 | pr_err("%s: Failed to enable PWM, Error %d\n", pwm->label, ret); | ||
92 | return ret; | ||
93 | } | ||
94 | |||
95 | twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, LED_PWM_CTRL2); | ||
96 | return 0; | ||
97 | } | ||
98 | EXPORT_SYMBOL(pwm_enable); | ||
99 | |||
100 | void pwm_disable(struct pwm_device *pwm) | ||
101 | { | ||
102 | u8 val; | ||
103 | int ret; | ||
104 | |||
105 | ret = twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, LED_PWM_CTRL2); | ||
106 | if (ret < 0) { | ||
107 | pr_err("%s: Failed to disable PWM, Error %d\n", | ||
108 | pwm->label, ret); | ||
109 | return; | ||
110 | } | ||
111 | |||
112 | val &= ~PWM_CTRL2_MODE_MASK; | ||
113 | val |= PWM_CTRL2_MODE_HW; | ||
114 | |||
115 | ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, LED_PWM_CTRL2); | ||
116 | if (ret < 0) { | ||
117 | pr_err("%s: Failed to disable PWM, Error %d\n", | ||
118 | pwm->label, ret); | ||
119 | return; | ||
120 | } | ||
121 | return; | ||
122 | } | ||
123 | EXPORT_SYMBOL(pwm_disable); | ||
124 | |||
125 | struct pwm_device *pwm_request(int pwm_id, const char *label) | ||
126 | { | ||
127 | u8 val; | ||
128 | int ret; | ||
129 | struct pwm_device *pwm; | ||
130 | |||
131 | pwm = kzalloc(sizeof(struct pwm_device), GFP_KERNEL); | ||
132 | if (pwm == NULL) { | ||
133 | pr_err("%s: failed to allocate memory\n", label); | ||
134 | return NULL; | ||
135 | } | ||
136 | |||
137 | pwm->label = label; | ||
138 | pwm->pwm_id = pwm_id; | ||
139 | |||
140 | /* Configure PWM */ | ||
141 | val = PWM_CTRL2_DIS_PD | PWM_CTRL2_CURR_02 | PWM_CTRL2_SRC_VAC | | ||
142 | PWM_CTRL2_MODE_HW; | ||
143 | |||
144 | ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, LED_PWM_CTRL2); | ||
145 | |||
146 | if (ret < 0) { | ||
147 | pr_err("%s: Failed to configure PWM, Error %d\n", | ||
148 | pwm->label, ret); | ||
149 | |||
150 | kfree(pwm); | ||
151 | return NULL; | ||
152 | } | ||
153 | |||
154 | return pwm; | ||
155 | } | ||
156 | EXPORT_SYMBOL(pwm_request); | ||
157 | |||
158 | void pwm_free(struct pwm_device *pwm) | ||
159 | { | ||
160 | pwm_disable(pwm); | ||
161 | kfree(pwm); | ||
162 | } | ||
163 | EXPORT_SYMBOL(pwm_free); | ||
164 | |||
165 | MODULE_LICENSE("GPL"); | ||