Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: wm831x: Add basic device tree binding

Add the basic ability to register the device through device tree, more
work is needed to get each individual sub-driver functioning correctly
but this is enough to get the device to probe from device tree.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>

authored by

Charles Keepax and committed by
Lee Jones
f6dd8449 c1ae3cfa

+66 -15
+21 -8
drivers/mfd/wm831x-core.c
··· 19 19 #include <linux/mfd/core.h> 20 20 #include <linux/slab.h> 21 21 #include <linux/err.h> 22 + #include <linux/of.h> 23 + #include <linux/of_device.h> 22 24 23 25 #include <linux/mfd/wm831x/core.h> 24 26 #include <linux/mfd/wm831x/pdata.h> ··· 1615 1613 }; 1616 1614 EXPORT_SYMBOL_GPL(wm831x_regmap_config); 1617 1615 1616 + const struct of_device_id wm831x_of_match[] = { 1617 + { .compatible = "wlf,wm8310", .data = (void *)WM8310 }, 1618 + { .compatible = "wlf,wm8311", .data = (void *)WM8311 }, 1619 + { .compatible = "wlf,wm8312", .data = (void *)WM8312 }, 1620 + { .compatible = "wlf,wm8320", .data = (void *)WM8320 }, 1621 + { .compatible = "wlf,wm8321", .data = (void *)WM8321 }, 1622 + { .compatible = "wlf,wm8325", .data = (void *)WM8325 }, 1623 + { .compatible = "wlf,wm8326", .data = (void *)WM8326 }, 1624 + { }, 1625 + }; 1626 + EXPORT_SYMBOL_GPL(wm831x_of_match); 1627 + 1618 1628 /* 1619 1629 * Instantiate the generic non-control parts of the device. 1620 1630 */ 1621 - int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) 1631 + int wm831x_device_init(struct wm831x *wm831x, int irq) 1622 1632 { 1623 - struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); 1633 + struct wm831x_pdata *pdata = &wm831x->pdata; 1624 1634 int rev, wm831x_num; 1625 1635 enum wm831x_parent parent; 1626 1636 int ret, i; ··· 1641 1627 mutex_init(&wm831x->key_lock); 1642 1628 dev_set_drvdata(wm831x->dev, wm831x); 1643 1629 1644 - if (pdata) 1645 - wm831x->soft_shutdown = pdata->soft_shutdown; 1630 + wm831x->soft_shutdown = pdata->soft_shutdown; 1646 1631 1647 1632 ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID); 1648 1633 if (ret < 0) { ··· 1676 1663 */ 1677 1664 if (ret == 0) { 1678 1665 dev_info(wm831x->dev, "Device is an engineering sample\n"); 1679 - ret = id; 1666 + ret = wm831x->type; 1680 1667 } 1681 1668 1682 1669 switch (ret) { ··· 1749 1736 /* This will need revisiting in future but is OK for all 1750 1737 * current parts. 1751 1738 */ 1752 - if (parent != id) 1753 - dev_warn(wm831x->dev, "Device was registered as a WM%lx\n", 1754 - id); 1739 + if (parent != wm831x->type) 1740 + dev_warn(wm831x->dev, "Device was registered as a WM%x\n", 1741 + wm831x->type); 1755 1742 1756 1743 /* Bootstrap the user key */ 1757 1744 ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
+18 -1
drivers/mfd/wm831x-i2c.c
··· 19 19 #include <linux/mfd/core.h> 20 20 #include <linux/slab.h> 21 21 #include <linux/err.h> 22 + #include <linux/of.h> 23 + #include <linux/of_device.h> 22 24 #include <linux/regmap.h> 23 25 24 26 #include <linux/mfd/wm831x/core.h> ··· 29 27 static int wm831x_i2c_probe(struct i2c_client *i2c, 30 28 const struct i2c_device_id *id) 31 29 { 30 + struct wm831x_pdata *pdata = dev_get_platdata(&i2c->dev); 31 + const struct of_device_id *of_id; 32 32 struct wm831x *wm831x; 33 + enum wm831x_parent type; 33 34 int ret; 35 + 36 + if (i2c->dev.of_node) { 37 + of_id = of_match_device(wm831x_of_match, &i2c->dev); 38 + type = (enum wm831x_parent)of_id->data; 39 + } else { 40 + type = (enum wm831x_parent)id->driver_data; 41 + } 34 42 35 43 wm831x = devm_kzalloc(&i2c->dev, sizeof(struct wm831x), GFP_KERNEL); 36 44 if (wm831x == NULL) ··· 48 36 49 37 i2c_set_clientdata(i2c, wm831x); 50 38 wm831x->dev = &i2c->dev; 39 + wm831x->type = type; 51 40 52 41 wm831x->regmap = devm_regmap_init_i2c(i2c, &wm831x_regmap_config); 53 42 if (IS_ERR(wm831x->regmap)) { ··· 58 45 return ret; 59 46 } 60 47 61 - return wm831x_device_init(wm831x, id->driver_data, i2c->irq); 48 + if (pdata) 49 + memcpy(&wm831x->pdata, pdata, sizeof(*pdata)); 50 + 51 + return wm831x_device_init(wm831x, i2c->irq); 62 52 } 63 53 64 54 static int wm831x_i2c_remove(struct i2c_client *i2c) ··· 110 94 .driver = { 111 95 .name = "wm831x", 112 96 .pm = &wm831x_pm_ops, 97 + .of_match_table = of_match_ptr(wm831x_of_match), 113 98 }, 114 99 .probe = wm831x_i2c_probe, 115 100 .remove = wm831x_i2c_remove,
+3 -3
drivers/mfd/wm831x-irq.c
··· 564 564 565 565 int wm831x_irq_init(struct wm831x *wm831x, int irq) 566 566 { 567 - struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); 567 + struct wm831x_pdata *pdata = &wm831x->pdata; 568 568 struct irq_domain *domain; 569 569 int i, ret, irq_base; 570 570 ··· 579 579 } 580 580 581 581 /* Try to dynamically allocate IRQs if no base is specified */ 582 - if (pdata && pdata->irq_base) { 582 + if (pdata->irq_base) { 583 583 irq_base = irq_alloc_descs(pdata->irq_base, 0, 584 584 WM831X_NUM_IRQS, 0); 585 585 if (irq_base < 0) { ··· 608 608 return -EINVAL; 609 609 } 610 610 611 - if (pdata && pdata->irq_cmos) 611 + if (pdata->irq_cmos) 612 612 i = 0; 613 613 else 614 614 i = WM831X_IRQ_OD;
+16 -2
drivers/mfd/wm831x-spi.c
··· 14 14 15 15 #include <linux/kernel.h> 16 16 #include <linux/module.h> 17 + #include <linux/of.h> 18 + #include <linux/of_device.h> 17 19 #include <linux/pm.h> 18 20 #include <linux/spi/spi.h> 19 21 #include <linux/regmap.h> ··· 25 23 26 24 static int wm831x_spi_probe(struct spi_device *spi) 27 25 { 26 + struct wm831x_pdata *pdata = dev_get_platdata(&spi->dev); 28 27 const struct spi_device_id *id = spi_get_device_id(spi); 28 + const struct of_device_id *of_id; 29 29 struct wm831x *wm831x; 30 30 enum wm831x_parent type; 31 31 int ret; 32 32 33 - type = (enum wm831x_parent)id->driver_data; 33 + if (spi->dev.of_node) { 34 + of_id = of_match_device(wm831x_of_match, &spi->dev); 35 + type = (enum wm831x_parent)of_id->data; 36 + } else { 37 + type = (enum wm831x_parent)id->driver_data; 38 + } 34 39 35 40 wm831x = devm_kzalloc(&spi->dev, sizeof(struct wm831x), GFP_KERNEL); 36 41 if (wm831x == NULL) ··· 47 38 48 39 spi_set_drvdata(spi, wm831x); 49 40 wm831x->dev = &spi->dev; 41 + wm831x->type = type; 50 42 51 43 wm831x->regmap = devm_regmap_init_spi(spi, &wm831x_regmap_config); 52 44 if (IS_ERR(wm831x->regmap)) { ··· 57 47 return ret; 58 48 } 59 49 60 - return wm831x_device_init(wm831x, type, spi->irq); 50 + if (pdata) 51 + memcpy(&wm831x->pdata, pdata, sizeof(*pdata)); 52 + 53 + return wm831x_device_init(wm831x, spi->irq); 61 54 } 62 55 63 56 static int wm831x_spi_remove(struct spi_device *spi) ··· 110 97 .driver = { 111 98 .name = "wm831x", 112 99 .pm = &wm831x_spi_pm, 100 + .of_match_table = of_match_ptr(wm831x_of_match), 113 101 }, 114 102 .id_table = wm831x_spi_ids, 115 103 .probe = wm831x_spi_probe,
+8 -1
include/linux/mfd/wm831x/core.h
··· 21 21 #include <linux/list.h> 22 22 #include <linux/regmap.h> 23 23 #include <linux/mfd/wm831x/auxadc.h> 24 + #include <linux/mfd/wm831x/pdata.h> 25 + #include <linux/of.h> 24 26 25 27 /* 26 28 * Register values. ··· 369 367 370 368 struct regmap *regmap; 371 369 370 + struct wm831x_pdata pdata; 371 + enum wm831x_parent type; 372 + 372 373 int irq; /* Our chip IRQ */ 373 374 struct mutex irq_lock; 374 375 struct irq_domain *irq_domain; ··· 417 412 int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg, 418 413 int count, u16 *buf); 419 414 420 - int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq); 415 + int wm831x_device_init(struct wm831x *wm831x, int irq); 421 416 void wm831x_device_exit(struct wm831x *wm831x); 422 417 int wm831x_device_suspend(struct wm831x *wm831x); 423 418 void wm831x_device_shutdown(struct wm831x *wm831x); ··· 431 426 } 432 427 433 428 extern struct regmap_config wm831x_regmap_config; 429 + 430 + extern const struct of_device_id wm831x_of_match[]; 434 431 435 432 #endif