From 705d80539a835628b87d9a8d9d80d53aff22ec3c Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Thu, 15 Jan 2009 16:51:55 +0100 Subject: [PATCH] Setup PWMs according to OF --- motorek.c | 99 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 52 insertions(+), 47 deletions(-) diff --git a/motorek.c b/motorek.c index 86577b1..4c69cb6 100644 --- a/motorek.c +++ b/motorek.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -114,16 +115,26 @@ static irqreturn_t motorek_irq(int irq, void *dev_id) return IRQ_HANDLED; } -/* mpc5200 device tree match tables */ -static struct of_device_id mpc5200_gpt_ids[] __initdata = { - { .compatible = "fsl,mpc5200-gpt", }, - { .compatible = "mpc5200-gpt", }, - {} -}; - -static int __devinit motorek_probe(struct platform_device *dev) +struct mpc52xx_gpt __iomem *iomap_gpt_by_phandle(const phandle *phandle) { struct device_node *np; + struct mpc52xx_gpt __iomem *gpt; + + if (!phandle) + return NULL; + + np = of_find_node_by_phandle(*phandle); + if (!np) + return NULL; + gpt = of_iomap(np, 0); + of_node_put(np); + return gpt; +} + +static int __devinit motorek_probe(struct of_device* dev, + const struct of_device_id *match) +{ + struct device_node *dn = dev->node; struct motorek *m; int err; @@ -131,23 +142,9 @@ static int __devinit motorek_probe(struct platform_device *dev) if (!m) return -ENOMEM; - for_each_matching_node(np, mpc5200_gpt_ids) { - const void *prop; - int i; - - prop = of_get_property(np, "cell-index", NULL); - if (prop) { - i = *(u32 *)prop; - switch (i) { - case 2: - m->pwmf = of_iomap(np, 0); - break; - case 3: - m->pwmb = of_iomap(np, 0); - break; - } - } - } + m->pwmf = iomap_gpt_by_phandle(of_get_property(dn, "pwmf", NULL)); + m->pwmb = iomap_gpt_by_phandle(of_get_property(dn, "pwmb", NULL)); + if (!m->pwmf || !m->pwmb) { printk(KERN_ERR "%s() mmap failed\n", __func__); return -ENXIO; @@ -176,7 +173,7 @@ static int __devinit motorek_probe(struct platform_device *dev) return 0; } -static int __devexit motorek_remove(struct platform_device *dev) +static int __devexit motorek_remove(struct of_device* dev) { struct motorek *m; m = platform_get_drvdata(dev); @@ -187,41 +184,49 @@ static int __devexit motorek_remove(struct platform_device *dev) return 0; } - - -static struct platform_driver motorek_driver = { +static struct of_device_id motorek_match[] = { + { .type = "motorek", }, + {}, +}; +static struct of_platform_driver motorek_driver = { + .owner = THIS_MODULE, + .name = "motorek", + .match_table = motorek_match, .probe = motorek_probe, .remove = __devexit_p(motorek_remove), - .driver = { - .name = "motorek", - .owner = THIS_MODULE, - }, }; -static struct platform_device *motorek_pdev; - static int __init motorek_init_module(void) { int ret; - motorek_pdev = platform_device_alloc("motorek", 0); - if (!motorek_pdev) - return -ENOMEM; - ret = platform_device_add(motorek_pdev); - if (ret) { - platform_device_put(motorek_pdev); - return ret; - } + struct of_device *dev; + struct device_node *dn; + + for_each_node_by_type(dn, "motorek") { + if (!of_find_device_by_node(dn)) { + dev = of_platform_device_create(dn, "motorek", NULL); + if (!dev) + return -ENOMEM; + } + }; - ret = platform_driver_register(&motorek_driver); - return 0; + ret = of_register_platform_driver(&motorek_driver); + return ret; } module_init(motorek_init_module); static void __exit motorek_exit_module(void) { - platform_device_unregister(motorek_pdev); - platform_driver_unregister(&motorek_driver); + struct of_device *dev; + struct device_node *dn; + + for_each_node_by_type(dn, "motorek") { + while ((dev = of_find_device_by_node(dn))) { + of_device_unregister(dev); + } + } + of_unregister_platform_driver(&motorek_driver); } module_exit(motorek_exit_module); -- 2.39.2