Commit ead050dec6b0765357e45287f02ef8e51f69c3ed

Authored by Jingoo Han
Committed by Greg Kroah-Hartman
1 parent 4022ed5a72

misc: ep93xx_pwm: use module_platform_driver_probe()

This patch uses module_platform_driver_probe() macro which makes
the code smaller and simpler.

Signed-off-by: Jingoo Han <jg1.han@samsung.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 1 additions and 12 deletions Inline Diff

drivers/misc/ep93xx_pwm.c
1 /* 1 /*
2 * Simple PWM driver for EP93XX 2 * Simple PWM driver for EP93XX
3 * 3 *
4 * (c) Copyright 2009 Matthieu Crapet <mcrapet@gmail.com> 4 * (c) Copyright 2009 Matthieu Crapet <mcrapet@gmail.com>
5 * (c) Copyright 2009 H Hartley Sweeten <hsweeten@visionengravers.com> 5 * (c) Copyright 2009 H Hartley Sweeten <hsweeten@visionengravers.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License 8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version. 10 * 2 of the License, or (at your option) any later version.
11 * 11 *
12 * EP9307 has only one channel: 12 * EP9307 has only one channel:
13 * - PWMOUT 13 * - PWMOUT
14 * 14 *
15 * EP9301/02/12/15 have two channels: 15 * EP9301/02/12/15 have two channels:
16 * - PWMOUT 16 * - PWMOUT
17 * - PWMOUT1 (alternate function for EGPIO14) 17 * - PWMOUT1 (alternate function for EGPIO14)
18 */ 18 */
19 19
20 #include <linux/module.h> 20 #include <linux/module.h>
21 #include <linux/platform_device.h> 21 #include <linux/platform_device.h>
22 #include <linux/slab.h> 22 #include <linux/slab.h>
23 #include <linux/clk.h> 23 #include <linux/clk.h>
24 #include <linux/err.h> 24 #include <linux/err.h>
25 #include <linux/io.h> 25 #include <linux/io.h>
26 26
27 #include <mach/platform.h> 27 #include <mach/platform.h>
28 28
29 #define EP93XX_PWMx_TERM_COUNT 0x00 29 #define EP93XX_PWMx_TERM_COUNT 0x00
30 #define EP93XX_PWMx_DUTY_CYCLE 0x04 30 #define EP93XX_PWMx_DUTY_CYCLE 0x04
31 #define EP93XX_PWMx_ENABLE 0x08 31 #define EP93XX_PWMx_ENABLE 0x08
32 #define EP93XX_PWMx_INVERT 0x0C 32 #define EP93XX_PWMx_INVERT 0x0C
33 33
34 #define EP93XX_PWM_MAX_COUNT 0xFFFF 34 #define EP93XX_PWM_MAX_COUNT 0xFFFF
35 35
36 struct ep93xx_pwm { 36 struct ep93xx_pwm {
37 void __iomem *mmio_base; 37 void __iomem *mmio_base;
38 struct clk *clk; 38 struct clk *clk;
39 u32 duty_percent; 39 u32 duty_percent;
40 }; 40 };
41 41
42 static inline void ep93xx_pwm_writel(struct ep93xx_pwm *pwm, 42 static inline void ep93xx_pwm_writel(struct ep93xx_pwm *pwm,
43 unsigned int val, unsigned int off) 43 unsigned int val, unsigned int off)
44 { 44 {
45 __raw_writel(val, pwm->mmio_base + off); 45 __raw_writel(val, pwm->mmio_base + off);
46 } 46 }
47 47
48 static inline unsigned int ep93xx_pwm_readl(struct ep93xx_pwm *pwm, 48 static inline unsigned int ep93xx_pwm_readl(struct ep93xx_pwm *pwm,
49 unsigned int off) 49 unsigned int off)
50 { 50 {
51 return __raw_readl(pwm->mmio_base + off); 51 return __raw_readl(pwm->mmio_base + off);
52 } 52 }
53 53
54 static inline void ep93xx_pwm_write_tc(struct ep93xx_pwm *pwm, u16 value) 54 static inline void ep93xx_pwm_write_tc(struct ep93xx_pwm *pwm, u16 value)
55 { 55 {
56 ep93xx_pwm_writel(pwm, value, EP93XX_PWMx_TERM_COUNT); 56 ep93xx_pwm_writel(pwm, value, EP93XX_PWMx_TERM_COUNT);
57 } 57 }
58 58
59 static inline u16 ep93xx_pwm_read_tc(struct ep93xx_pwm *pwm) 59 static inline u16 ep93xx_pwm_read_tc(struct ep93xx_pwm *pwm)
60 { 60 {
61 return ep93xx_pwm_readl(pwm, EP93XX_PWMx_TERM_COUNT); 61 return ep93xx_pwm_readl(pwm, EP93XX_PWMx_TERM_COUNT);
62 } 62 }
63 63
64 static inline void ep93xx_pwm_write_dc(struct ep93xx_pwm *pwm, u16 value) 64 static inline void ep93xx_pwm_write_dc(struct ep93xx_pwm *pwm, u16 value)
65 { 65 {
66 ep93xx_pwm_writel(pwm, value, EP93XX_PWMx_DUTY_CYCLE); 66 ep93xx_pwm_writel(pwm, value, EP93XX_PWMx_DUTY_CYCLE);
67 } 67 }
68 68
69 static inline void ep93xx_pwm_enable(struct ep93xx_pwm *pwm) 69 static inline void ep93xx_pwm_enable(struct ep93xx_pwm *pwm)
70 { 70 {
71 ep93xx_pwm_writel(pwm, 0x1, EP93XX_PWMx_ENABLE); 71 ep93xx_pwm_writel(pwm, 0x1, EP93XX_PWMx_ENABLE);
72 } 72 }
73 73
74 static inline void ep93xx_pwm_disable(struct ep93xx_pwm *pwm) 74 static inline void ep93xx_pwm_disable(struct ep93xx_pwm *pwm)
75 { 75 {
76 ep93xx_pwm_writel(pwm, 0x0, EP93XX_PWMx_ENABLE); 76 ep93xx_pwm_writel(pwm, 0x0, EP93XX_PWMx_ENABLE);
77 } 77 }
78 78
79 static inline int ep93xx_pwm_is_enabled(struct ep93xx_pwm *pwm) 79 static inline int ep93xx_pwm_is_enabled(struct ep93xx_pwm *pwm)
80 { 80 {
81 return ep93xx_pwm_readl(pwm, EP93XX_PWMx_ENABLE) & 0x1; 81 return ep93xx_pwm_readl(pwm, EP93XX_PWMx_ENABLE) & 0x1;
82 } 82 }
83 83
84 static inline void ep93xx_pwm_invert(struct ep93xx_pwm *pwm) 84 static inline void ep93xx_pwm_invert(struct ep93xx_pwm *pwm)
85 { 85 {
86 ep93xx_pwm_writel(pwm, 0x1, EP93XX_PWMx_INVERT); 86 ep93xx_pwm_writel(pwm, 0x1, EP93XX_PWMx_INVERT);
87 } 87 }
88 88
89 static inline void ep93xx_pwm_normal(struct ep93xx_pwm *pwm) 89 static inline void ep93xx_pwm_normal(struct ep93xx_pwm *pwm)
90 { 90 {
91 ep93xx_pwm_writel(pwm, 0x0, EP93XX_PWMx_INVERT); 91 ep93xx_pwm_writel(pwm, 0x0, EP93XX_PWMx_INVERT);
92 } 92 }
93 93
94 static inline int ep93xx_pwm_is_inverted(struct ep93xx_pwm *pwm) 94 static inline int ep93xx_pwm_is_inverted(struct ep93xx_pwm *pwm)
95 { 95 {
96 return ep93xx_pwm_readl(pwm, EP93XX_PWMx_INVERT) & 0x1; 96 return ep93xx_pwm_readl(pwm, EP93XX_PWMx_INVERT) & 0x1;
97 } 97 }
98 98
99 /* 99 /*
100 * /sys/devices/platform/ep93xx-pwm.N 100 * /sys/devices/platform/ep93xx-pwm.N
101 * /min_freq read-only minimum pwm output frequency 101 * /min_freq read-only minimum pwm output frequency
102 * /max_req read-only maximum pwm output frequency 102 * /max_req read-only maximum pwm output frequency
103 * /freq read-write pwm output frequency (0 = disable output) 103 * /freq read-write pwm output frequency (0 = disable output)
104 * /duty_percent read-write pwm duty cycle percent (1..99) 104 * /duty_percent read-write pwm duty cycle percent (1..99)
105 * /invert read-write invert pwm output 105 * /invert read-write invert pwm output
106 */ 106 */
107 107
108 static ssize_t ep93xx_pwm_get_min_freq(struct device *dev, 108 static ssize_t ep93xx_pwm_get_min_freq(struct device *dev,
109 struct device_attribute *attr, char *buf) 109 struct device_attribute *attr, char *buf)
110 { 110 {
111 struct platform_device *pdev = to_platform_device(dev); 111 struct platform_device *pdev = to_platform_device(dev);
112 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev); 112 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
113 unsigned long rate = clk_get_rate(pwm->clk); 113 unsigned long rate = clk_get_rate(pwm->clk);
114 114
115 return sprintf(buf, "%ld\n", rate / (EP93XX_PWM_MAX_COUNT + 1)); 115 return sprintf(buf, "%ld\n", rate / (EP93XX_PWM_MAX_COUNT + 1));
116 } 116 }
117 117
118 static ssize_t ep93xx_pwm_get_max_freq(struct device *dev, 118 static ssize_t ep93xx_pwm_get_max_freq(struct device *dev,
119 struct device_attribute *attr, char *buf) 119 struct device_attribute *attr, char *buf)
120 { 120 {
121 struct platform_device *pdev = to_platform_device(dev); 121 struct platform_device *pdev = to_platform_device(dev);
122 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev); 122 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
123 unsigned long rate = clk_get_rate(pwm->clk); 123 unsigned long rate = clk_get_rate(pwm->clk);
124 124
125 return sprintf(buf, "%ld\n", rate / 2); 125 return sprintf(buf, "%ld\n", rate / 2);
126 } 126 }
127 127
128 static ssize_t ep93xx_pwm_get_freq(struct device *dev, 128 static ssize_t ep93xx_pwm_get_freq(struct device *dev,
129 struct device_attribute *attr, char *buf) 129 struct device_attribute *attr, char *buf)
130 { 130 {
131 struct platform_device *pdev = to_platform_device(dev); 131 struct platform_device *pdev = to_platform_device(dev);
132 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev); 132 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
133 133
134 if (ep93xx_pwm_is_enabled(pwm)) { 134 if (ep93xx_pwm_is_enabled(pwm)) {
135 unsigned long rate = clk_get_rate(pwm->clk); 135 unsigned long rate = clk_get_rate(pwm->clk);
136 u16 term = ep93xx_pwm_read_tc(pwm); 136 u16 term = ep93xx_pwm_read_tc(pwm);
137 137
138 return sprintf(buf, "%ld\n", rate / (term + 1)); 138 return sprintf(buf, "%ld\n", rate / (term + 1));
139 } else { 139 } else {
140 return sprintf(buf, "disabled\n"); 140 return sprintf(buf, "disabled\n");
141 } 141 }
142 } 142 }
143 143
144 static ssize_t ep93xx_pwm_set_freq(struct device *dev, 144 static ssize_t ep93xx_pwm_set_freq(struct device *dev,
145 struct device_attribute *attr, const char *buf, size_t count) 145 struct device_attribute *attr, const char *buf, size_t count)
146 { 146 {
147 struct platform_device *pdev = to_platform_device(dev); 147 struct platform_device *pdev = to_platform_device(dev);
148 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev); 148 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
149 long val; 149 long val;
150 int err; 150 int err;
151 151
152 err = strict_strtol(buf, 10, &val); 152 err = strict_strtol(buf, 10, &val);
153 if (err) 153 if (err)
154 return -EINVAL; 154 return -EINVAL;
155 155
156 if (val == 0) { 156 if (val == 0) {
157 ep93xx_pwm_disable(pwm); 157 ep93xx_pwm_disable(pwm);
158 } else if (val <= (clk_get_rate(pwm->clk) / 2)) { 158 } else if (val <= (clk_get_rate(pwm->clk) / 2)) {
159 u32 term, duty; 159 u32 term, duty;
160 160
161 val = (clk_get_rate(pwm->clk) / val) - 1; 161 val = (clk_get_rate(pwm->clk) / val) - 1;
162 if (val > EP93XX_PWM_MAX_COUNT) 162 if (val > EP93XX_PWM_MAX_COUNT)
163 val = EP93XX_PWM_MAX_COUNT; 163 val = EP93XX_PWM_MAX_COUNT;
164 if (val < 1) 164 if (val < 1)
165 val = 1; 165 val = 1;
166 166
167 term = ep93xx_pwm_read_tc(pwm); 167 term = ep93xx_pwm_read_tc(pwm);
168 duty = ((val + 1) * pwm->duty_percent / 100) - 1; 168 duty = ((val + 1) * pwm->duty_percent / 100) - 1;
169 169
170 /* If pwm is running, order is important */ 170 /* If pwm is running, order is important */
171 if (val > term) { 171 if (val > term) {
172 ep93xx_pwm_write_tc(pwm, val); 172 ep93xx_pwm_write_tc(pwm, val);
173 ep93xx_pwm_write_dc(pwm, duty); 173 ep93xx_pwm_write_dc(pwm, duty);
174 } else { 174 } else {
175 ep93xx_pwm_write_dc(pwm, duty); 175 ep93xx_pwm_write_dc(pwm, duty);
176 ep93xx_pwm_write_tc(pwm, val); 176 ep93xx_pwm_write_tc(pwm, val);
177 } 177 }
178 178
179 if (!ep93xx_pwm_is_enabled(pwm)) 179 if (!ep93xx_pwm_is_enabled(pwm))
180 ep93xx_pwm_enable(pwm); 180 ep93xx_pwm_enable(pwm);
181 } else { 181 } else {
182 return -EINVAL; 182 return -EINVAL;
183 } 183 }
184 184
185 return count; 185 return count;
186 } 186 }
187 187
188 static ssize_t ep93xx_pwm_get_duty_percent(struct device *dev, 188 static ssize_t ep93xx_pwm_get_duty_percent(struct device *dev,
189 struct device_attribute *attr, char *buf) 189 struct device_attribute *attr, char *buf)
190 { 190 {
191 struct platform_device *pdev = to_platform_device(dev); 191 struct platform_device *pdev = to_platform_device(dev);
192 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev); 192 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
193 193
194 return sprintf(buf, "%d\n", pwm->duty_percent); 194 return sprintf(buf, "%d\n", pwm->duty_percent);
195 } 195 }
196 196
197 static ssize_t ep93xx_pwm_set_duty_percent(struct device *dev, 197 static ssize_t ep93xx_pwm_set_duty_percent(struct device *dev,
198 struct device_attribute *attr, const char *buf, size_t count) 198 struct device_attribute *attr, const char *buf, size_t count)
199 { 199 {
200 struct platform_device *pdev = to_platform_device(dev); 200 struct platform_device *pdev = to_platform_device(dev);
201 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev); 201 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
202 long val; 202 long val;
203 int err; 203 int err;
204 204
205 err = strict_strtol(buf, 10, &val); 205 err = strict_strtol(buf, 10, &val);
206 if (err) 206 if (err)
207 return -EINVAL; 207 return -EINVAL;
208 208
209 if (val > 0 && val < 100) { 209 if (val > 0 && val < 100) {
210 u32 term = ep93xx_pwm_read_tc(pwm); 210 u32 term = ep93xx_pwm_read_tc(pwm);
211 ep93xx_pwm_write_dc(pwm, ((term + 1) * val / 100) - 1); 211 ep93xx_pwm_write_dc(pwm, ((term + 1) * val / 100) - 1);
212 pwm->duty_percent = val; 212 pwm->duty_percent = val;
213 return count; 213 return count;
214 } 214 }
215 215
216 return -EINVAL; 216 return -EINVAL;
217 } 217 }
218 218
219 static ssize_t ep93xx_pwm_get_invert(struct device *dev, 219 static ssize_t ep93xx_pwm_get_invert(struct device *dev,
220 struct device_attribute *attr, char *buf) 220 struct device_attribute *attr, char *buf)
221 { 221 {
222 struct platform_device *pdev = to_platform_device(dev); 222 struct platform_device *pdev = to_platform_device(dev);
223 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev); 223 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
224 224
225 return sprintf(buf, "%d\n", ep93xx_pwm_is_inverted(pwm)); 225 return sprintf(buf, "%d\n", ep93xx_pwm_is_inverted(pwm));
226 } 226 }
227 227
228 static ssize_t ep93xx_pwm_set_invert(struct device *dev, 228 static ssize_t ep93xx_pwm_set_invert(struct device *dev,
229 struct device_attribute *attr, const char *buf, size_t count) 229 struct device_attribute *attr, const char *buf, size_t count)
230 { 230 {
231 struct platform_device *pdev = to_platform_device(dev); 231 struct platform_device *pdev = to_platform_device(dev);
232 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev); 232 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
233 long val; 233 long val;
234 int err; 234 int err;
235 235
236 err = strict_strtol(buf, 10, &val); 236 err = strict_strtol(buf, 10, &val);
237 if (err) 237 if (err)
238 return -EINVAL; 238 return -EINVAL;
239 239
240 if (val == 0) 240 if (val == 0)
241 ep93xx_pwm_normal(pwm); 241 ep93xx_pwm_normal(pwm);
242 else if (val == 1) 242 else if (val == 1)
243 ep93xx_pwm_invert(pwm); 243 ep93xx_pwm_invert(pwm);
244 else 244 else
245 return -EINVAL; 245 return -EINVAL;
246 246
247 return count; 247 return count;
248 } 248 }
249 249
250 static DEVICE_ATTR(min_freq, S_IRUGO, ep93xx_pwm_get_min_freq, NULL); 250 static DEVICE_ATTR(min_freq, S_IRUGO, ep93xx_pwm_get_min_freq, NULL);
251 static DEVICE_ATTR(max_freq, S_IRUGO, ep93xx_pwm_get_max_freq, NULL); 251 static DEVICE_ATTR(max_freq, S_IRUGO, ep93xx_pwm_get_max_freq, NULL);
252 static DEVICE_ATTR(freq, S_IWUSR | S_IRUGO, 252 static DEVICE_ATTR(freq, S_IWUSR | S_IRUGO,
253 ep93xx_pwm_get_freq, ep93xx_pwm_set_freq); 253 ep93xx_pwm_get_freq, ep93xx_pwm_set_freq);
254 static DEVICE_ATTR(duty_percent, S_IWUSR | S_IRUGO, 254 static DEVICE_ATTR(duty_percent, S_IWUSR | S_IRUGO,
255 ep93xx_pwm_get_duty_percent, ep93xx_pwm_set_duty_percent); 255 ep93xx_pwm_get_duty_percent, ep93xx_pwm_set_duty_percent);
256 static DEVICE_ATTR(invert, S_IWUSR | S_IRUGO, 256 static DEVICE_ATTR(invert, S_IWUSR | S_IRUGO,
257 ep93xx_pwm_get_invert, ep93xx_pwm_set_invert); 257 ep93xx_pwm_get_invert, ep93xx_pwm_set_invert);
258 258
259 static struct attribute *ep93xx_pwm_attrs[] = { 259 static struct attribute *ep93xx_pwm_attrs[] = {
260 &dev_attr_min_freq.attr, 260 &dev_attr_min_freq.attr,
261 &dev_attr_max_freq.attr, 261 &dev_attr_max_freq.attr,
262 &dev_attr_freq.attr, 262 &dev_attr_freq.attr,
263 &dev_attr_duty_percent.attr, 263 &dev_attr_duty_percent.attr,
264 &dev_attr_invert.attr, 264 &dev_attr_invert.attr,
265 NULL 265 NULL
266 }; 266 };
267 267
268 static const struct attribute_group ep93xx_pwm_sysfs_files = { 268 static const struct attribute_group ep93xx_pwm_sysfs_files = {
269 .attrs = ep93xx_pwm_attrs, 269 .attrs = ep93xx_pwm_attrs,
270 }; 270 };
271 271
272 static int __init ep93xx_pwm_probe(struct platform_device *pdev) 272 static int __init ep93xx_pwm_probe(struct platform_device *pdev)
273 { 273 {
274 struct ep93xx_pwm *pwm; 274 struct ep93xx_pwm *pwm;
275 struct resource *res; 275 struct resource *res;
276 int err; 276 int err;
277 277
278 err = ep93xx_pwm_acquire_gpio(pdev); 278 err = ep93xx_pwm_acquire_gpio(pdev);
279 if (err) 279 if (err)
280 return err; 280 return err;
281 281
282 pwm = kzalloc(sizeof(struct ep93xx_pwm), GFP_KERNEL); 282 pwm = kzalloc(sizeof(struct ep93xx_pwm), GFP_KERNEL);
283 if (!pwm) { 283 if (!pwm) {
284 err = -ENOMEM; 284 err = -ENOMEM;
285 goto fail_no_mem; 285 goto fail_no_mem;
286 } 286 }
287 287
288 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 288 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
289 if (res == NULL) { 289 if (res == NULL) {
290 err = -ENXIO; 290 err = -ENXIO;
291 goto fail_no_mem_resource; 291 goto fail_no_mem_resource;
292 } 292 }
293 293
294 res = request_mem_region(res->start, resource_size(res), pdev->name); 294 res = request_mem_region(res->start, resource_size(res), pdev->name);
295 if (res == NULL) { 295 if (res == NULL) {
296 err = -EBUSY; 296 err = -EBUSY;
297 goto fail_no_mem_resource; 297 goto fail_no_mem_resource;
298 } 298 }
299 299
300 pwm->mmio_base = ioremap(res->start, resource_size(res)); 300 pwm->mmio_base = ioremap(res->start, resource_size(res));
301 if (pwm->mmio_base == NULL) { 301 if (pwm->mmio_base == NULL) {
302 err = -ENXIO; 302 err = -ENXIO;
303 goto fail_no_ioremap; 303 goto fail_no_ioremap;
304 } 304 }
305 305
306 err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_pwm_sysfs_files); 306 err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_pwm_sysfs_files);
307 if (err) 307 if (err)
308 goto fail_no_sysfs; 308 goto fail_no_sysfs;
309 309
310 pwm->clk = clk_get(&pdev->dev, "pwm_clk"); 310 pwm->clk = clk_get(&pdev->dev, "pwm_clk");
311 if (IS_ERR(pwm->clk)) { 311 if (IS_ERR(pwm->clk)) {
312 err = PTR_ERR(pwm->clk); 312 err = PTR_ERR(pwm->clk);
313 goto fail_no_clk; 313 goto fail_no_clk;
314 } 314 }
315 315
316 pwm->duty_percent = 50; 316 pwm->duty_percent = 50;
317 317
318 platform_set_drvdata(pdev, pwm); 318 platform_set_drvdata(pdev, pwm);
319 319
320 /* disable pwm at startup. Avoids zero value. */ 320 /* disable pwm at startup. Avoids zero value. */
321 ep93xx_pwm_disable(pwm); 321 ep93xx_pwm_disable(pwm);
322 ep93xx_pwm_write_tc(pwm, EP93XX_PWM_MAX_COUNT); 322 ep93xx_pwm_write_tc(pwm, EP93XX_PWM_MAX_COUNT);
323 ep93xx_pwm_write_dc(pwm, EP93XX_PWM_MAX_COUNT / 2); 323 ep93xx_pwm_write_dc(pwm, EP93XX_PWM_MAX_COUNT / 2);
324 324
325 clk_enable(pwm->clk); 325 clk_enable(pwm->clk);
326 326
327 return 0; 327 return 0;
328 328
329 fail_no_clk: 329 fail_no_clk:
330 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_pwm_sysfs_files); 330 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_pwm_sysfs_files);
331 fail_no_sysfs: 331 fail_no_sysfs:
332 iounmap(pwm->mmio_base); 332 iounmap(pwm->mmio_base);
333 fail_no_ioremap: 333 fail_no_ioremap:
334 release_mem_region(res->start, resource_size(res)); 334 release_mem_region(res->start, resource_size(res));
335 fail_no_mem_resource: 335 fail_no_mem_resource:
336 kfree(pwm); 336 kfree(pwm);
337 fail_no_mem: 337 fail_no_mem:
338 ep93xx_pwm_release_gpio(pdev); 338 ep93xx_pwm_release_gpio(pdev);
339 return err; 339 return err;
340 } 340 }
341 341
342 static int __exit ep93xx_pwm_remove(struct platform_device *pdev) 342 static int __exit ep93xx_pwm_remove(struct platform_device *pdev)
343 { 343 {
344 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev); 344 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
345 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 345 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
346 346
347 ep93xx_pwm_disable(pwm); 347 ep93xx_pwm_disable(pwm);
348 clk_disable(pwm->clk); 348 clk_disable(pwm->clk);
349 clk_put(pwm->clk); 349 clk_put(pwm->clk);
350 platform_set_drvdata(pdev, NULL); 350 platform_set_drvdata(pdev, NULL);
351 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_pwm_sysfs_files); 351 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_pwm_sysfs_files);
352 iounmap(pwm->mmio_base); 352 iounmap(pwm->mmio_base);
353 release_mem_region(res->start, resource_size(res)); 353 release_mem_region(res->start, resource_size(res));
354 kfree(pwm); 354 kfree(pwm);
355 ep93xx_pwm_release_gpio(pdev); 355 ep93xx_pwm_release_gpio(pdev);
356 356
357 return 0; 357 return 0;
358 } 358 }
359 359
360 static struct platform_driver ep93xx_pwm_driver = { 360 static struct platform_driver ep93xx_pwm_driver = {
361 .driver = { 361 .driver = {
362 .name = "ep93xx-pwm", 362 .name = "ep93xx-pwm",
363 .owner = THIS_MODULE, 363 .owner = THIS_MODULE,
364 }, 364 },
365 .remove = __exit_p(ep93xx_pwm_remove), 365 .remove = __exit_p(ep93xx_pwm_remove),
366 }; 366 };
367 367
368 static int __init ep93xx_pwm_init(void) 368 module_platform_driver_probe(ep93xx_pwm_driver, ep93xx_pwm_probe);
369 {
370 return platform_driver_probe(&ep93xx_pwm_driver, ep93xx_pwm_probe);
371 }
372
373 static void __exit ep93xx_pwm_exit(void)
374 {
375 platform_driver_unregister(&ep93xx_pwm_driver);
376 }
377
378 module_init(ep93xx_pwm_init);
379 module_exit(ep93xx_pwm_exit);
380 369
381 MODULE_AUTHOR("Matthieu Crapet <mcrapet@gmail.com>, " 370 MODULE_AUTHOR("Matthieu Crapet <mcrapet@gmail.com>, "
382 "H Hartley Sweeten <hsweeten@visionengravers.com>"); 371 "H Hartley Sweeten <hsweeten@visionengravers.com>");
383 MODULE_DESCRIPTION("EP93xx PWM driver"); 372 MODULE_DESCRIPTION("EP93xx PWM driver");
384 MODULE_LICENSE("GPL"); 373 MODULE_LICENSE("GPL");
385 MODULE_ALIAS("platform:ep93xx-pwm"); 374 MODULE_ALIAS("platform:ep93xx-pwm");
386 375