diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2013-03-24 20:11:27 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2013-05-20 09:13:36 -0400 |
commit | d781009ca6bb5b9711c74700242855e0a70ee7a3 (patch) | |
tree | 310ac48498eaca141f5643803bebe21383dca965 /drivers | |
parent | 67c992969172473e129984a51ceb77950a2aa16c (diff) |
mfd: Add device tree bindings for Arizona class devices
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mfd/arizona-core.c | 69 | ||||
-rw-r--r-- | drivers/mfd/arizona-i2c.c | 10 | ||||
-rw-r--r-- | drivers/mfd/arizona-spi.c | 10 | ||||
-rw-r--r-- | drivers/mfd/arizona.h | 12 |
4 files changed, 97 insertions, 4 deletions
diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c index 549db0ad7257..d8d30c0a488d 100644 --- a/drivers/mfd/arizona-core.c +++ b/drivers/mfd/arizona-core.c | |||
@@ -16,6 +16,9 @@ | |||
16 | #include <linux/interrupt.h> | 16 | #include <linux/interrupt.h> |
17 | #include <linux/mfd/core.h> | 17 | #include <linux/mfd/core.h> |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/of.h> | ||
20 | #include <linux/of_device.h> | ||
21 | #include <linux/of_gpio.h> | ||
19 | #include <linux/pm_runtime.h> | 22 | #include <linux/pm_runtime.h> |
20 | #include <linux/regmap.h> | 23 | #include <linux/regmap.h> |
21 | #include <linux/regulator/consumer.h> | 24 | #include <linux/regulator/consumer.h> |
@@ -462,6 +465,70 @@ const struct dev_pm_ops arizona_pm_ops = { | |||
462 | }; | 465 | }; |
463 | EXPORT_SYMBOL_GPL(arizona_pm_ops); | 466 | EXPORT_SYMBOL_GPL(arizona_pm_ops); |
464 | 467 | ||
468 | #ifdef CONFIG_OF | ||
469 | int arizona_of_get_type(struct device *dev) | ||
470 | { | ||
471 | const struct of_device_id *id = of_match_device(arizona_of_match, dev); | ||
472 | |||
473 | if (id) | ||
474 | return (int)id->data; | ||
475 | else | ||
476 | return 0; | ||
477 | } | ||
478 | EXPORT_SYMBOL_GPL(arizona_of_get_type); | ||
479 | |||
480 | static int arizona_of_get_core_pdata(struct arizona *arizona) | ||
481 | { | ||
482 | int ret, i; | ||
483 | |||
484 | arizona->pdata.reset = of_get_named_gpio(arizona->dev->of_node, | ||
485 | "wlf,reset", 0); | ||
486 | if (arizona->pdata.reset < 0) | ||
487 | arizona->pdata.reset = 0; | ||
488 | |||
489 | arizona->pdata.ldoena = of_get_named_gpio(arizona->dev->of_node, | ||
490 | "wlf,ldoena", 0); | ||
491 | if (arizona->pdata.ldoena < 0) | ||
492 | arizona->pdata.ldoena = 0; | ||
493 | |||
494 | ret = of_property_read_u32_array(arizona->dev->of_node, | ||
495 | "wlf,gpio-defaults", | ||
496 | arizona->pdata.gpio_defaults, | ||
497 | ARRAY_SIZE(arizona->pdata.gpio_defaults)); | ||
498 | if (ret >= 0) { | ||
499 | /* | ||
500 | * All values are literal except out of range values | ||
501 | * which are chip default, translate into platform | ||
502 | * data which uses 0 as chip default and out of range | ||
503 | * as zero. | ||
504 | */ | ||
505 | for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) { | ||
506 | if (arizona->pdata.gpio_defaults[i] > 0xffff) | ||
507 | arizona->pdata.gpio_defaults[i] = 0; | ||
508 | if (arizona->pdata.gpio_defaults[i] == 0) | ||
509 | arizona->pdata.gpio_defaults[i] = 0x10000; | ||
510 | } | ||
511 | } else { | ||
512 | dev_err(arizona->dev, "Failed to parse GPIO defaults: %d\n", | ||
513 | ret); | ||
514 | } | ||
515 | |||
516 | return 0; | ||
517 | } | ||
518 | |||
519 | const struct of_device_id arizona_of_match[] = { | ||
520 | { .compatible = "wlf,wm5102", .data = (void *)WM5102 }, | ||
521 | { .compatible = "wlf,wm5110", .data = (void *)WM5110 }, | ||
522 | {}, | ||
523 | }; | ||
524 | EXPORT_SYMBOL_GPL(arizona_of_match); | ||
525 | #else | ||
526 | static inline int arizona_of_get_core_pdata(struct arizona *arizona) | ||
527 | { | ||
528 | return 0; | ||
529 | } | ||
530 | #endif | ||
531 | |||
465 | static struct mfd_cell early_devs[] = { | 532 | static struct mfd_cell early_devs[] = { |
466 | { .name = "arizona-ldo1" }, | 533 | { .name = "arizona-ldo1" }, |
467 | }; | 534 | }; |
@@ -495,6 +562,8 @@ int arizona_dev_init(struct arizona *arizona) | |||
495 | dev_set_drvdata(arizona->dev, arizona); | 562 | dev_set_drvdata(arizona->dev, arizona); |
496 | mutex_init(&arizona->clk_lock); | 563 | mutex_init(&arizona->clk_lock); |
497 | 564 | ||
565 | arizona_of_get_core_pdata(arizona); | ||
566 | |||
498 | if (dev_get_platdata(arizona->dev)) | 567 | if (dev_get_platdata(arizona->dev)) |
499 | memcpy(&arizona->pdata, dev_get_platdata(arizona->dev), | 568 | memcpy(&arizona->pdata, dev_get_platdata(arizona->dev), |
500 | sizeof(arizona->pdata)); | 569 | sizeof(arizona->pdata)); |
diff --git a/drivers/mfd/arizona-i2c.c b/drivers/mfd/arizona-i2c.c index 44a1bb969841..deb267ebf84e 100644 --- a/drivers/mfd/arizona-i2c.c +++ b/drivers/mfd/arizona-i2c.c | |||
@@ -27,9 +27,14 @@ static int arizona_i2c_probe(struct i2c_client *i2c, | |||
27 | { | 27 | { |
28 | struct arizona *arizona; | 28 | struct arizona *arizona; |
29 | const struct regmap_config *regmap_config; | 29 | const struct regmap_config *regmap_config; |
30 | int ret; | 30 | int ret, type; |
31 | 31 | ||
32 | switch (id->driver_data) { | 32 | if (i2c->dev.of_node) |
33 | type = arizona_of_get_type(&i2c->dev); | ||
34 | else | ||
35 | type = id->driver_data; | ||
36 | |||
37 | switch (type) { | ||
33 | #ifdef CONFIG_MFD_WM5102 | 38 | #ifdef CONFIG_MFD_WM5102 |
34 | case WM5102: | 39 | case WM5102: |
35 | regmap_config = &wm5102_i2c_regmap; | 40 | regmap_config = &wm5102_i2c_regmap; |
@@ -84,6 +89,7 @@ static struct i2c_driver arizona_i2c_driver = { | |||
84 | .name = "arizona", | 89 | .name = "arizona", |
85 | .owner = THIS_MODULE, | 90 | .owner = THIS_MODULE, |
86 | .pm = &arizona_pm_ops, | 91 | .pm = &arizona_pm_ops, |
92 | .of_match_table = of_match_ptr(arizona_of_match), | ||
87 | }, | 93 | }, |
88 | .probe = arizona_i2c_probe, | 94 | .probe = arizona_i2c_probe, |
89 | .remove = arizona_i2c_remove, | 95 | .remove = arizona_i2c_remove, |
diff --git a/drivers/mfd/arizona-spi.c b/drivers/mfd/arizona-spi.c index b57e642d2b4a..47be7b35b5c5 100644 --- a/drivers/mfd/arizona-spi.c +++ b/drivers/mfd/arizona-spi.c | |||
@@ -27,9 +27,14 @@ static int arizona_spi_probe(struct spi_device *spi) | |||
27 | const struct spi_device_id *id = spi_get_device_id(spi); | 27 | const struct spi_device_id *id = spi_get_device_id(spi); |
28 | struct arizona *arizona; | 28 | struct arizona *arizona; |
29 | const struct regmap_config *regmap_config; | 29 | const struct regmap_config *regmap_config; |
30 | int ret; | 30 | int ret, type; |
31 | 31 | ||
32 | switch (id->driver_data) { | 32 | if (spi->dev.of_node) |
33 | type = arizona_of_get_type(&spi->dev); | ||
34 | else | ||
35 | type = id->driver_data; | ||
36 | |||
37 | switch (type) { | ||
33 | #ifdef CONFIG_MFD_WM5102 | 38 | #ifdef CONFIG_MFD_WM5102 |
34 | case WM5102: | 39 | case WM5102: |
35 | regmap_config = &wm5102_spi_regmap; | 40 | regmap_config = &wm5102_spi_regmap; |
@@ -84,6 +89,7 @@ static struct spi_driver arizona_spi_driver = { | |||
84 | .name = "arizona", | 89 | .name = "arizona", |
85 | .owner = THIS_MODULE, | 90 | .owner = THIS_MODULE, |
86 | .pm = &arizona_pm_ops, | 91 | .pm = &arizona_pm_ops, |
92 | .of_match_table = of_match_ptr(arizona_of_match), | ||
87 | }, | 93 | }, |
88 | .probe = arizona_spi_probe, | 94 | .probe = arizona_spi_probe, |
89 | .remove = arizona_spi_remove, | 95 | .remove = arizona_spi_remove, |
diff --git a/drivers/mfd/arizona.h b/drivers/mfd/arizona.h index 9798ae5da67b..db55d9854a55 100644 --- a/drivers/mfd/arizona.h +++ b/drivers/mfd/arizona.h | |||
@@ -13,6 +13,7 @@ | |||
13 | #ifndef _WM5102_H | 13 | #ifndef _WM5102_H |
14 | #define _WM5102_H | 14 | #define _WM5102_H |
15 | 15 | ||
16 | #include <linux/of.h> | ||
16 | #include <linux/regmap.h> | 17 | #include <linux/regmap.h> |
17 | #include <linux/pm.h> | 18 | #include <linux/pm.h> |
18 | 19 | ||
@@ -26,6 +27,8 @@ extern const struct regmap_config wm5110_spi_regmap; | |||
26 | 27 | ||
27 | extern const struct dev_pm_ops arizona_pm_ops; | 28 | extern const struct dev_pm_ops arizona_pm_ops; |
28 | 29 | ||
30 | extern const struct of_device_id arizona_of_match[]; | ||
31 | |||
29 | extern const struct regmap_irq_chip wm5102_aod; | 32 | extern const struct regmap_irq_chip wm5102_aod; |
30 | extern const struct regmap_irq_chip wm5102_irq; | 33 | extern const struct regmap_irq_chip wm5102_irq; |
31 | 34 | ||
@@ -37,4 +40,13 @@ int arizona_dev_exit(struct arizona *arizona); | |||
37 | int arizona_irq_init(struct arizona *arizona); | 40 | int arizona_irq_init(struct arizona *arizona); |
38 | int arizona_irq_exit(struct arizona *arizona); | 41 | int arizona_irq_exit(struct arizona *arizona); |
39 | 42 | ||
43 | #ifdef CONFIG_OF | ||
44 | int arizona_of_get_type(struct device *dev); | ||
45 | #else | ||
46 | static inline int arizona_of_get_type(struct device *dev) | ||
47 | { | ||
48 | return 0; | ||
49 | } | ||
50 | #endif | ||
51 | |||
40 | #endif | 52 | #endif |