aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pwm
diff options
context:
space:
mode:
authorPhilipp Zabel <p.zabel@pengutronix.de>2012-06-25 10:16:25 -0400
committerThierry Reding <thierry.reding@avionic-design.de>2012-09-12 08:25:06 -0400
commit479e2e301c626cc64fb27b6b1938655eaba8b036 (patch)
treefe3e4627c75af747f10c3460f79820522adbf557 /drivers/pwm
parent208d038f4792b5ca0dc76deebbc0ae13b4f1a744 (diff)
pwm: i.MX: add devicetree support
At the same time remove platform based support. No user for this driver has made it into mainline so far, so all we break is out of tree stuff. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Shawn Guo <shawn.guo@linaro.org> Reviewed-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com> Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Diffstat (limited to 'drivers/pwm')
-rw-r--r--drivers/pwm/pwm-imx.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c
index a1e799ee07de..0f6c436c0632 100644
--- a/drivers/pwm/pwm-imx.c
+++ b/drivers/pwm/pwm-imx.c
@@ -16,9 +16,9 @@
16#include <linux/clk.h> 16#include <linux/clk.h>
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/pwm.h> 18#include <linux/pwm.h>
19#include <linux/of_device.h>
19#include <mach/hardware.h> 20#include <mach/hardware.h>
20 21
21
22/* i.MX1 and i.MX21 share the same PWM function block: */ 22/* i.MX1 and i.MX21 share the same PWM function block: */
23 23
24#define MX1_PWMC 0x00 /* PWM Control Register */ 24#define MX1_PWMC 0x00 /* PWM Control Register */
@@ -204,12 +204,41 @@ static struct pwm_ops imx_pwm_ops = {
204 .owner = THIS_MODULE, 204 .owner = THIS_MODULE,
205}; 205};
206 206
207struct imx_pwm_data {
208 int (*config)(struct pwm_chip *chip,
209 struct pwm_device *pwm, int duty_ns, int period_ns);
210 void (*set_enable)(struct pwm_chip *chip, bool enable);
211};
212
213static struct imx_pwm_data imx_pwm_data_v1 = {
214 .config = imx_pwm_config_v1,
215 .set_enable = imx_pwm_set_enable_v1,
216};
217
218static struct imx_pwm_data imx_pwm_data_v2 = {
219 .config = imx_pwm_config_v2,
220 .set_enable = imx_pwm_set_enable_v2,
221};
222
223static const struct of_device_id imx_pwm_dt_ids[] = {
224 { .compatible = "fsl,imx1-pwm", .data = &imx_pwm_data_v1, },
225 { .compatible = "fsl,imx27-pwm", .data = &imx_pwm_data_v2, },
226 { /* sentinel */ }
227};
228MODULE_DEVICE_TABLE(of, imx_pwm_dt_ids);
229
207static int __devinit imx_pwm_probe(struct platform_device *pdev) 230static int __devinit imx_pwm_probe(struct platform_device *pdev)
208{ 231{
232 const struct of_device_id *of_id =
233 of_match_device(imx_pwm_dt_ids, &pdev->dev);
234 struct imx_pwm_data *data;
209 struct imx_chip *imx; 235 struct imx_chip *imx;
210 struct resource *r; 236 struct resource *r;
211 int ret = 0; 237 int ret = 0;
212 238
239 if (!of_id)
240 return -ENODEV;
241
213 imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL); 242 imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL);
214 if (imx == NULL) { 243 if (imx == NULL) {
215 dev_err(&pdev->dev, "failed to allocate memory\n"); 244 dev_err(&pdev->dev, "failed to allocate memory\n");
@@ -236,13 +265,9 @@ static int __devinit imx_pwm_probe(struct platform_device *pdev)
236 if (imx->mmio_base == NULL) 265 if (imx->mmio_base == NULL)
237 return -EADDRNOTAVAIL; 266 return -EADDRNOTAVAIL;
238 267
239 if (cpu_is_mx1() || cpu_is_mx21()) { 268 data = of_id->data;
240 imx->config = imx_pwm_config_v1; 269 imx->config = data->config;
241 imx->set_enable = imx_pwm_set_enable_v1; 270 imx->set_enable = data->set_enable;
242 } else {
243 imx->config = imx_pwm_config_v2;
244 imx->set_enable = imx_pwm_set_enable_v2;
245 }
246 271
247 ret = pwmchip_add(&imx->chip); 272 ret = pwmchip_add(&imx->chip);
248 if (ret < 0) 273 if (ret < 0)
@@ -265,7 +290,8 @@ static int __devexit imx_pwm_remove(struct platform_device *pdev)
265 290
266static struct platform_driver imx_pwm_driver = { 291static struct platform_driver imx_pwm_driver = {
267 .driver = { 292 .driver = {
268 .name = "mxc_pwm", 293 .name = "imx-pwm",
294 .of_match_table = of_match_ptr(imx_pwm_dt_ids),
269 }, 295 },
270 .probe = imx_pwm_probe, 296 .probe = imx_pwm_probe,
271 .remove = __devexit_p(imx_pwm_remove), 297 .remove = __devexit_p(imx_pwm_remove),