mfd: wm831x: Add basic device tree binding
Subsystems (4)
PATCH v4 1/3 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.
---
Changes since v3:
- No longer check return of of_match_device it should always match
- Move calls of of_match_device from helper function in wm831x-core into both wm831x-i2c and wm831x-spi
- Move copy of pdata from wm831x-core into both wm831x-i2c and wm831x-spi
- Put device type into struct wm831x and remove the argument to that effect passed to wm831x_device_init
Thanks,
Charles
drivers/mfd/wm831x-core.c | 29 +++++++++++++++++++++-------- drivers/mfd/wm831x-i2c.c | 21 ++++++++++++++++++++- drivers/mfd/wm831x-irq.c | 6 +++--- drivers/mfd/wm831x-spi.c | 20 ++++++++++++++++++-- include/linux/mfd/wm831x/core.h | 9 ++++++++- 5 files changed, 70 insertions(+), 15 deletions(-)
drivers/mfd/wm831x-core.c +21 -8
@@ -19,6 +19,8 @@#include <linux/mfd/core.h> #include <linux/slab.h> #include <linux/err.h> +#include <linux/of.h> +#include <linux/of_device.h> #include <linux/mfd/wm831x/core.h> #include <linux/mfd/wm831x/pdata.h>
@@ -1613,12 +1615,24 @@ struct regmap_config wm831x_regmap_config = { };EXPORT_SYMBOL_GPL (wm831x_regmap_config); +const struct of_device_id wm831x_of_match[] = { + { .compatible ="wlf,wm8310" , .data = (void *)WM8310 }, + { .compatible ="wlf,wm8311" , .data = (void *)WM8311 }, + { .compatible ="wlf,wm8312" , .data = (void *)WM8312 }, + { .compatible ="wlf,wm8320" , .data = (void *)WM8320 }, + { .compatible ="wlf,wm8321" , .data = (void *)WM8321 }, + { .compatible ="wlf,wm8325" , .data = (void *)WM8325 }, + { .compatible ="wlf,wm8326" , .data = (void *)WM8326 }, + { }, +}; +EXPORT_SYMBOL_GPL (wm831x_of_match); +/* * Instantiate the generic non-control parts of the device. */ -int wm831x_device_init (struct wm831x *wm831x,unsigned long id,int irq) +int wm831x_device_init (struct wm831x *wm831x,int irq) { -struct wm831x_pdata *pdata =dev_get_platdata (wm831x->dev); +struct wm831x_pdata *pdata = &wm831x->pdata;int rev, wm831x_num;enum wm831x_parent parent;int ret, i;
@@ -1627,8 +1641,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)mutex_init (&wm831x->key_lock);dev_set_drvdata (wm831x->dev, wm831x); -if (pdata) - wm831x->soft_shutdown = pdata->soft_shutdown; + wm831x->soft_shutdown = pdata->soft_shutdown; ret =wm831x_reg_read (wm831x,WM831X_PARENT_ID );if (ret <0 ) {
@@ -1663,7 +1676,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)*/ if (ret ==0 ) {dev_info (wm831x->dev,"Device is an engineering sample\n" ); - ret = id; + ret = wm831x->type; }switch (ret) {
@@ -1736,9 +1749,9 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)/* This will need revisiting in future but is OK for all * current parts. */ -if (parent != id) -dev_warn (wm831x->dev,"Device was registered as a WM%lx\n" , - id); +if (parent != wm831x->type) +dev_warn (wm831x->dev,"Device was registered as a WM%x\n" , + wm831x->type);/* Bootstrap the user key */ ret =wm831x_reg_read (wm831x,WM831X_SECURITY_KEY );
drivers/mfd/wm831x-i2c.c +20 -1
@@ -19,6 +19,8 @@#include <linux/mfd/core.h> #include <linux/slab.h> #include <linux/err.h> +#include <linux/of.h> +#include <linux/of_device.h> #include <linux/regmap.h> #include <linux/mfd/wm831x/core.h>
@@ -27,15 +29,28 @@static int wm831x_i2c_probe (struct i2c_client *i2c,const struct i2c_device_id *id) { +struct wm831x_pdata *pdata =dev_get_platdata (&i2c->dev);struct wm831x *wm831x; +enum wm831x_parent type;int ret; +if (i2c->dev.of_node) { +const struct of_device_id *id =of_match_device (wm831x_of_match, + &i2c->dev); +unsigned long of_type = (unsigned long )id->data; + + type = (enum wm831x_parent )of_type; + }else { + type = (enum wm831x_parent )id->driver_data; + } + wm831x =devm_kzalloc (&i2c->dev,sizeof (struct wm831x ),GFP_KERNEL );if (wm831x ==NULL )return -ENOMEM ;i2c_set_clientdata (i2c, wm831x); wm831x->dev = &i2c->dev; + wm831x->type = type; wm831x->regmap =devm_regmap_init_i2c (i2c, &wm831x_regmap_config);if (IS_ERR (wm831x->regmap)) {
@@ -45,7 +60,10 @@ static int wm831x_i2c_probe(struct i2c_client *i2c,return ret; } -return wm831x_device_init (wm831x, id->driver_data, i2c->irq); +if (pdata) +memcpy (&wm831x->pdata, pdata,sizeof (*pdata)); + +return wm831x_device_init (wm831x, i2c->irq); }static int wm831x_i2c_remove (struct i2c_client *i2c)
@@ -94,6 +112,7 @@ static struct i2c_driver wm831x_i2c_driver = { .driver = { .name = "wm831x", .pm = &wm831x_pm_ops, + .of_match_table = of_match_ptr(wm831x_of_match), }, .probe = wm831x_i2c_probe, .remove = wm831x_i2c_remove,
drivers/mfd/wm831x-irq.c +3 -3
@@ -564,7 +564,7 @@ static const struct irq_domain_ops wm831x_irq_domain_ops = {int wm831x_irq_init (struct wm831x *wm831x,int irq) { -struct wm831x_pdata *pdata =dev_get_platdata (wm831x->dev); +struct wm831x_pdata *pdata = &wm831x->pdata;struct irq_domain *domain;int i, ret, irq_base;
@@ -579,7 +579,7 @@ int wm831x_irq_init(struct wm831x *wm831x, int irq) }/* Try to dynamically allocate IRQs if no base is specified */ -if (pdata && pdata->irq_base) { +if (pdata->irq_base) { irq_base =irq_alloc_descs (pdata->irq_base,0 ,WM831X_NUM_IRQS ,0 );if (irq_base <0 ) {
@@ -608,7 +608,7 @@ int wm831x_irq_init(struct wm831x *wm831x, int irq)return -EINVAL ; } -if (pdata && pdata->irq_cmos) +if (pdata->irq_cmos) i =0 ;else i =WM831X_IRQ_OD ;
drivers/mfd/wm831x-spi.c +18 -2
@@ -14,6 +14,8 @@#include <linux/kernel.h> #include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> #include <linux/pm.h> #include <linux/spi/spi.h> #include <linux/regmap.h>
@@ -23,12 +25,21 @@static int wm831x_spi_probe (struct spi_device *spi) { +struct wm831x_pdata *pdata =dev_get_platdata (&spi->dev);const struct spi_device_id *id =spi_get_device_id (spi);struct wm831x *wm831x;enum wm831x_parent type;int ret; - type = (enum wm831x_parent )id->driver_data; +if (spi->dev.of_node) { +const struct of_device_id *id =of_match_device (wm831x_of_match, + &spi->dev); +unsigned long of_type = (unsigned long )id->data; + + type = (enum wm831x_parent )of_type; + }else { + type = (enum wm831x_parent )id->driver_data; + } wm831x =devm_kzalloc (&spi->dev,sizeof (struct wm831x ),GFP_KERNEL );if (wm831x ==NULL )
@@ -38,6 +49,7 @@ static int wm831x_spi_probe(struct spi_device *spi)spi_set_drvdata (spi, wm831x); wm831x->dev = &spi->dev; + wm831x->type = type; wm831x->regmap =devm_regmap_init_spi (spi, &wm831x_regmap_config);if (IS_ERR (wm831x->regmap)) {
@@ -47,7 +59,10 @@ static int wm831x_spi_probe(struct spi_device *spi)return ret; } -return wm831x_device_init (wm831x, type, spi->irq); +if (pdata) +memcpy (&wm831x->pdata, pdata,sizeof (*pdata)); + +return wm831x_device_init (wm831x, spi->irq); }static int wm831x_spi_remove (struct spi_device *spi)
@@ -97,6 +112,7 @@ static struct spi_driver wm831x_spi_driver = { .driver = { .name = "wm831x", .pm = &wm831x_spi_pm, + .of_match_table = of_match_ptr(wm831x_of_match), }, .id_table = wm831x_spi_ids, .probe = wm831x_spi_probe,
include/linux/mfd/wm831x/core.h +8 -1
@@ -21,6 +21,8 @@#include <linux/list.h> #include <linux/regmap.h> #include <linux/mfd/wm831x/auxadc.h> +#include <linux/mfd/wm831x/pdata.h> +#include <linux/of.h> /* * Register values.
@@ -367,6 +369,9 @@ struct wm831x {struct regmap *regmap; +struct wm831x_pdata pdata; +enum wm831x_parent type; +int irq;/* Our chip IRQ */ struct mutex irq_lock;struct irq_domain *irq_domain;
@@ -412,7 +417,7 @@ int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg,int wm831x_bulk_read (struct wm831x *wm831x,unsigned short reg,int count,u16 *buf); -int wm831x_device_init (struct wm831x *wm831x,unsigned long id,int irq); +int wm831x_device_init (struct wm831x *wm831x,int irq);void wm831x_device_exit (struct wm831x *wm831x);int wm831x_device_suspend (struct wm831x *wm831x);void wm831x_device_shutdown (struct wm831x *wm831x);
@@ -427,4 +432,6 @@ static inline int wm831x_irq(struct wm831x *wm831x, int irq)extern struct regmap_config wm831x_regmap_config; +extern const struct of_device_id wm831x_of_match[]; +#endif
Signature · 1 line
2.1.4
PATCH v4 2/3 gpio: wm831x: Add basic device tree support
Now the wm831x-core has basic DT support we can update this driver to allow use of the GPIOs within a device tree system.
---
No change since v3, but still needs to go through Lee's tree.
Thanks,
Charles
drivers/gpio/gpio-wm831x.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpio/gpio-wm831x.c +4 -1
@@ -264,7 +264,7 @@ static const struct gpio_chip template_chip = {static int wm831x_gpio_probe (struct platform_device *pdev) {struct wm831x *wm831x =dev_get_drvdata (pdev->dev.parent); -struct wm831x_pdata *pdata =dev_get_platdata (wm831x->dev); +struct wm831x_pdata *pdata = &wm831x->pdata;struct wm831x_gpio *wm831x_gpio;int ret;
@@ -281,6 +281,9 @@ static int wm831x_gpio_probe(struct platform_device *pdev) wm831x_gpio->gpio_chip.base = pdata->gpio_base; else wm831x_gpio->gpio_chip.base = -1; +#ifdef CONFIG_OF_GPIO + wm831x_gpio->gpio_chip.of_node = wm831x->dev->of_node; +#endif ret =devm_gpiochip_add_data (&pdev->dev, &wm831x_gpio->gpio_chip, wm831x_gpio);
Signature · 1 line
2.1.4
PATCH v4 3/3 mfd: wm831x: Add device tree binding document
In reply to Charles KeepaxAdd a device tree binding document for the wm831x series of PMICs. Currently only support for the registering the device and the GPIOs are actually implemented in the driver.
---
Changes since v3:
- Remove / on IRQ signal
- Change file paths to be relative
Thanks,
Charles
Documentation/devicetree/bindings/mfd/wm831x.txt | 81 ++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 82 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/wm831x.txt
Documentation/devicetree/bindings/mfd/wm831x.txt new file +81 -0
@@ -0,0 +1,81 @@ +Cirrus Logic/Wolfson Microelectronics wm831x PMICs + +System PMICs with a wide range of additional features. + +Required properties: + + - compatible : One of the following chip-specific strings: + "wlf,wm8310" + "wlf,wm8311" + "wlf,wm8312" + "wlf,wm8320" + "wlf,wm8321" + "wlf,wm8325" + "wlf,wm8326" + + - reg : I2C slave address when connected using I2C, chip select number + when using SPI. + + - gpio-controller : Indicates this device is a GPIO controller. + - #gpio-cells : Must be 2. The first cell is the pin number and the + second cell is used to specify optional parameters (currently unused). + + - interrupts : The interrupt line the IRQ signal for the device is + connected to. + - interrupt-parent : The parent interrupt controller. + + - interrupt-controller : wm831x devices contain interrupt controllers and + may provide interrupt services to other devices. + - #interrupt-cells: Must be 2. The first cell is the IRQ number, and the + second cell is the flags, encoded as the trigger masks from + ../../interrupt-controller/interrupts.txt + +Optional sub-nodes: + - regulators : Contains sub-nodes for each of the regulators supplied by + the device. The regulators are bound using their names listed below: + + dcdc1 : DCDC1 + dcdc2 : DCDC2 + dcdc3 : DCDC3 + dcdc4 : DCDC3 + isink1 : ISINK1 + isink2 : ISINK2 + ldo1 : LDO1 + ldo2 : LDO2 + ldo3 : LDO3 + ldo4 : LDO4 + ldo5 : LDO5 + ldo7 : LDO7 + ldo11 : LDO11 + + The bindings details of each regulator can be found in: + ../../regulator/regulator.txt + +Example: + +wm8310: pmic@36 { + compatible = "wlf,wm8310"; + reg = <0x36>; + + gpio-controller; + #gpio-cells = <2>; + + interrupts = <347>; + interrupt-parent = <&gic>; + + interrupt-controller; + #interrupt-cells = <2>; + + regulators { + dcdc1: dcdc1 { + regulator-name = "DCDC1"; + regulator-min-microvolt = <600000>; + regulator-max-microvolt = <600000>; + }; + ldo1: ldo1 { + regulator-name = "LDO1"; + regulator-min-microvolt = <1700000>; + regulator-max-microvolt = <1700000>; + }; + }; +};
MAINTAINERS +1 -0
@@ -13363,6 +13363,7 @@ F: Documentation/hwmon/wm83?? F: Documentation/devicetree/bindings/extcon/extcon-arizona.txt F: Documentation/devicetree/bindings/regulator/arizona-regulator.txt F: Documentation/devicetree/bindings/mfd/arizona.txt +F: Documentation/devicetree/bindings/mfd/wm831x.txt F: arch/arm/mach-s3c64xx/mach-crag6410* F: drivers/clk/clk-wm83*.c F: drivers/extcon/extcon-arizona.c
Signature · 1 line
2.1.4
Quoted 112 lines · Charles Keepax
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 <[email protected]>---
Changes since v3:
- No longer check return ofof_match_deviceit should always match
- Move calls ofof_match_devicefrom helper function in wm831x-core into both wm831x-i2c and wm831x-spi
- Move copy of pdata from wm831x-core into both wm831x-i2c and wm831x-spi
- Put device type into struct wm831x and remove the argument to that effect passed towm831x_device_initThanks,
Charlesdrivers/mfd/wm831x-core.c | 29 +++++++++++++++++++++-------- drivers/mfd/wm831x-i2c.c | 21 ++++++++++++++++++++- drivers/mfd/wm831x-irq.c | 6 +++--- drivers/mfd/wm831x-spi.c | 20 ++++++++++++++++++-- include/linux/mfd/wm831x/core.h | 9 ++++++++- 5 files changed, 70 insertions(+), 15 deletions(-)drivers/mfd/wm831x-core.c +21
-8@@ -19,6 +19,8 @@#include <linux/mfd/core.h> #include <linux/slab.h> #include <linux/err.h> +#include <linux/of.h> +#include <linux/of_device.h> #include <linux/mfd/wm831x/core.h> #include <linux/mfd/wm831x/pdata.h> @@ -1613,12 +1615,24 @@ struct regmap_config wm831x_regmap_config = { };EXPORT_SYMBOL_GPL (wm831x_regmap_config); +const struct of_device_id wm831x_of_match[] = { + { .compatible ="wlf,wm8310" , .data = (void *)WM8310 }, + { .compatible ="wlf,wm8311" , .data = (void *)WM8311 }, + { .compatible ="wlf,wm8312" , .data = (void *)WM8312 }, + { .compatible ="wlf,wm8320" , .data = (void *)WM8320 }, + { .compatible ="wlf,wm8321" , .data = (void *)WM8321 }, + { .compatible ="wlf,wm8325" , .data = (void *)WM8325 }, + { .compatible ="wlf,wm8326" , .data = (void *)WM8326 }, + { }, +}; +EXPORT_SYMBOL_GPL (wm831x_of_match); +/* * Instantiate the generic non-control parts of the device. */ -int wm831x_device_init (struct wm831x *wm831x,unsigned long id,int irq) +int wm831x_device_init (struct wm831x *wm831x,int irq) { -struct wm831x_pdata *pdata =dev_get_platdata (wm831x->dev); +struct wm831x_pdata *pdata = &wm831x->pdata;int rev, wm831x_num;enum wm831x_parent parent;int ret, i;@@ -1627,8 +1641,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)mutex_init (&wm831x->key_lock);dev_set_drvdata (wm831x->dev, wm831x); -if (pdata) - wm831x->soft_shutdown = pdata->soft_shutdown; + wm831x->soft_shutdown = pdata->soft_shutdown; ret =wm831x_reg_read (wm831x,WM831X_PARENT_ID );if (ret <0 ) {@@ -1663,7 +1676,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)*/ if (ret ==0 ) {dev_info (wm831x->dev,"Device is an engineering sample\n" ); - ret = id; + ret = wm831x->type; }switch (ret) {@@ -1736,9 +1749,9 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)/* This will need revisiting in future but is OK for all * current parts. */ -if (parent != id) -dev_warn (wm831x->dev,"Device was registered as a WM%lx\n" , - id); +if (parent != wm831x->type) +dev_warn (wm831x->dev,"Device was registered as a WM%x\n" , + wm831x->type);/* Bootstrap the user key */ ret =wm831x_reg_read (wm831x,WM831X_SECURITY_KEY );drivers/mfd/wm831x-i2c.c +2
-0@@ -19,6 +19,8 @@#include <linux/mfd/core.h> #include <linux/slab.h> #include <linux/err.h> +#include <linux/of.h> +#include <linux/of_device.h> #include <linux/regmap.h> #include <linux/mfd/wm831x/core.h> @@ -27,15 +29,28 @@ static int wm831x_i2c_probe(struct i2c_client *i2c,
drivers/mfd/wm831x-i2c.c line 39
Quoted 10 lines
drivers/mfd/wm831x-i2c.c +5
-0const struct i2c_device_id *id) { +struct wm831x_pdata *pdata =dev_get_platdata (&i2c->dev);struct wm831x *wm831x; +enum wm831x_parent type;int ret; +if (i2c->dev.of_node) { +const struct of_device_id *id =of_match_device (wm831x_of_match, + &i2c->dev);
Not keen on this. Please declare the variable up with the others.
drivers/mfd/wm831x-i2c.c line 40
Quoted 1 line
drivers/mfd/wm831x-i2c.c +1
-0+unsigned long of_type = (unsigned long )id->data;
And this one.
drivers/mfd/wm831x-i2c.c line 41
Quoted 1 line
drivers/mfd/wm831x-i2c.c +1
-0+ type = (enum wm831x_parent )of_type;
Looks like you don't even need of_type.
Just cast id->data straight into wm81x_parent.
drivers/mfd/wm831x-i2c.c line 45
Quoted 3 lines
drivers/mfd/wm831x-i2c.c +3
-0+ }else { + type = (enum wm831x_parent )id->driver_data; + }
No need for bracketing here.
Quoted 84 lines
drivers/mfd/wm831x-i2c.c +6
-1wm831x =devm_kzalloc (&i2c->dev,sizeof (struct wm831x ),GFP_KERNEL );if (wm831x ==NULL )return -ENOMEM ;i2c_set_clientdata (i2c, wm831x); wm831x->dev = &i2c->dev; + wm831x->type = type; wm831x->regmap =devm_regmap_init_i2c (i2c, &wm831x_regmap_config);if (IS_ERR (wm831x->regmap)) {@@ -45,7 +60,10 @@ static int wm831x_i2c_probe(struct i2c_client *i2c,return ret; } -return wm831x_device_init (wm831x, id->driver_data, i2c->irq); +if (pdata) +memcpy (&wm831x->pdata, pdata,sizeof (*pdata)); + +return wm831x_device_init (wm831x, i2c->irq); }static int wm831x_i2c_remove (struct i2c_client *i2c)@@ -94,6 +112,7 @@ static struct i2c_driver wm831x_i2c_driver = { .driver = { .name = "wm831x", .pm = &wm831x_pm_ops, + .of_match_table = of_match_ptr(wm831x_of_match), }, .probe = wm831x_i2c_probe, .remove = wm831x_i2c_remove,drivers/mfd/wm831x-irq.c +3
-3@@ -564,7 +564,7 @@ static const struct irq_domain_ops wm831x_irq_domain_ops = {int wm831x_irq_init (struct wm831x *wm831x,int irq) { -struct wm831x_pdata *pdata =dev_get_platdata (wm831x->dev); +struct wm831x_pdata *pdata = &wm831x->pdata;struct irq_domain *domain;int i, ret, irq_base;@@ -579,7 +579,7 @@ int wm831x_irq_init(struct wm831x *wm831x, int irq) }/* Try to dynamically allocate IRQs if no base is specified */ -if (pdata && pdata->irq_base) { +if (pdata->irq_base) { irq_base =irq_alloc_descs (pdata->irq_base,0 ,WM831X_NUM_IRQS ,0 );if (irq_base <0 ) {@@ -608,7 +608,7 @@ int wm831x_irq_init(struct wm831x *wm831x, int irq)return -EINVAL ; } -if (pdata && pdata->irq_cmos) +if (pdata->irq_cmos) i =0 ;else i =WM831X_IRQ_OD ;drivers/mfd/wm831x-spi.c +3
-0@@ -14,6 +14,8 @@#include <linux/kernel.h> #include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> #include <linux/pm.h> #include <linux/spi/spi.h> #include <linux/regmap.h> @@ -23,12 +25,21 @@static int wm831x_spi_probe (struct spi_device *spi) { +struct wm831x_pdata *pdata =dev_get_platdata (&spi->dev);const struct spi_device_id *id =spi_get_device_id (spi);struct wm831x *wm831x;enum wm831x_parent type;int ret;
drivers/mfd/wm831x-spi.c line 42
Quoted 10 lines
drivers/mfd/wm831x-spi.c +9
-1- type = (enum wm831x_parent )id->driver_data; +if (spi->dev.of_node) { +const struct of_device_id *id =of_match_device (wm831x_of_match, + &spi->dev); +unsigned long of_type = (unsigned long )id->data; + + type = (enum wm831x_parent )of_type; + }else { + type = (enum wm831x_parent )id->driver_data; + }
As above.
Quoted 69 lines
drivers/mfd/wm831x-spi.c +6
-1wm831x =devm_kzalloc (&spi->dev,sizeof (struct wm831x ),GFP_KERNEL );if (wm831x ==NULL )@@ -38,6 +49,7 @@ static int wm831x_spi_probe(struct spi_device *spi)spi_set_drvdata (spi, wm831x); wm831x->dev = &spi->dev; + wm831x->type = type; wm831x->regmap =devm_regmap_init_spi (spi, &wm831x_regmap_config);if (IS_ERR (wm831x->regmap)) {@@ -47,7 +59,10 @@ static int wm831x_spi_probe(struct spi_device *spi)return ret; } -return wm831x_device_init (wm831x, type, spi->irq); +if (pdata) +memcpy (&wm831x->pdata, pdata,sizeof (*pdata)); + +return wm831x_device_init (wm831x, spi->irq); }static int wm831x_spi_remove (struct spi_device *spi)@@ -97,6 +112,7 @@ static struct spi_driver wm831x_spi_driver = { .driver = { .name = "wm831x", .pm = &wm831x_spi_pm, + .of_match_table = of_match_ptr(wm831x_of_match), }, .id_table = wm831x_spi_ids, .probe = wm831x_spi_probe,include/linux/mfd/wm831x/core.h +8
-1@@ -21,6 +21,8 @@#include <linux/list.h> #include <linux/regmap.h> #include <linux/mfd/wm831x/auxadc.h> +#include <linux/mfd/wm831x/pdata.h> +#include <linux/of.h> /* * Register values. @@ -367,6 +369,9 @@ struct wm831x {struct regmap *regmap; +struct wm831x_pdata pdata; +enum wm831x_parent type; +int irq;/* Our chip IRQ */ struct mutex irq_lock;struct irq_domain *irq_domain;@@ -412,7 +417,7 @@ int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg,int wm831x_bulk_read (struct wm831x *wm831x,unsigned short reg,int count,u16 *buf); -int wm831x_device_init (struct wm831x *wm831x,unsigned long id,int irq); +int wm831x_device_init (struct wm831x *wm831x,int irq);void wm831x_device_exit (struct wm831x *wm831x);int wm831x_device_suspend (struct wm831x *wm831x);void wm831x_device_shutdown (struct wm831x *wm831x);@@ -427,4 +432,6 @@ static inline int wm831x_irq(struct wm831x *wm831x, int irq)extern struct regmap_config wm831x_regmap_config; +extern const struct of_device_id wm831x_of_match[]; +#endif
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 16 lines · Lee Jones
Quoted 14 lines · Charles Keepax
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 <[email protected]>---
static int wm831x_i2c_probe(structi2c_client*i2c,drivers/mfd/wm831x-i2c.c +2
-0const struct i2c_device_id *id) { +struct wm831x_pdata *pdata =dev_get_platdata (&i2c->dev);struct wm831x *wm831x; +enum wm831x_parent type;int ret;
Quoted 6 lines
drivers/mfd/wm831x-i2c.c line 39
Quoted 3 lines
drivers/mfd/wm831x-i2c.c +3
-0+if (i2c->dev.of_node) { +const struct of_device_id *id =of_match_device (wm831x_of_match, + &i2c->dev);Not keen on this. Please declare the variable up with the others.
They are never going to be used anywhere else in the function. Again I can if you feel strongly but isn't it really better to limit the scope of the variables if they are only being used locally.
Quoted 10 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ unsigned long of_type = (unsigned long)id->data;And this one.
Review
Quoted 1 line
(quoted diff) +1
-0+ type = (enum wm831x_parent)of_type;Looks like you don't even need
of_type.Just cast
id->datastraight intowm81x_parent.
Pretty sure you will get a warning on 64-bit systems if I do that.
Quoted 6 lines
drivers/mfd/wm831x-i2c.c line 45
Quoted 3 lines
drivers/mfd/wm831x-i2c.c +3
-0+ }else { + type = (enum wm831x_parent )id->driver_data; + }No need for bracketing here.
Kernel coding standards if one side of the if has both should.
Thanks,
Charles
Quoted 24 lines · Charles Keepax
Quoted 16 lines · Lee Jones
Quoted 14 lines · Charles Keepax
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.
---
static int wm831x_i2c_probe(structi2c_client*i2c,drivers/mfd/wm831x-i2c.c +2
-0const struct i2c_device_id *id) { +struct wm831x_pdata *pdata =dev_get_platdata (&i2c->dev);struct wm831x *wm831x; +enum wm831x_parent type;int ret;Quoted 6 lines
drivers/mfd/wm831x-i2c.c line 39
Quoted 3 lines
drivers/mfd/wm831x-i2c.c +3
-0+if (i2c->dev.of_node) { +const struct of_device_id *id =of_match_device (wm831x_of_match, + &i2c->dev);Not keen on this. Please declare the variable up with the others.
Quoted 4 lines
They are never going to be used anywhere else in the function. Again I can if you feel strongly but isn't it really better to limit the scope of the variables if they are only being used locally.
I understand the motivation, but if we did that all the time, the code would look pretty dire IMHO.
Quoted 4 lines
Quoted 4 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ unsigned long of_type = (unsigned long)id->data;And this one.
Quoted 8 lines
Quoted 5 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ type = (enum wm831x_parent)of_type;Looks like you don't even need
of_type.Just cast
id->datastraight intowm81x_parent.Pretty sure you will get a warning on 64-bit systems if I do that.
What makes you think that?
Quoted 8 lines
Quoted 6 lines
drivers/mfd/wm831x-i2c.c line 45
Quoted 3 lines
drivers/mfd/wm831x-i2c.c +3
-0+ }else { + type = (enum wm831x_parent )id->driver_data; + }No need for bracketing here.
Kernel coding standards if one side of the if has both should.
Yes, my bad. I retract this one.
/me has been working on Zephyr too much recently (where *everything* has to be bracketed -- I guess I'm getting a bit sensitive to over-bracketing) :)
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Lee Jones
Quoted 9 lines · Charles Keepax
Quoted 7 lines · Lee Jones
drivers/mfd/wm831x-i2c.c line 39
Quoted 3 lines · Charles Keepax
drivers/mfd/wm831x-i2c.c +3
-0+if (i2c->dev.of_node) { +const struct of_device_id *id =of_match_device (wm831x_of_match, + &i2c->dev);Not keen on this. Please declare the variable up with the others.
Quoted 8 lines
Quoted 4 lines
They are never going to be used anywhere else in the function. Again I can if you feel strongly but isn't it really better to limit the scope of the variables if they are only being used locally.
I understand the motivation, but if we did that all the time, the code would look pretty dire IMHO.
Ok I do another spin.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ unsigned long of_type = (unsigned long)id->data;And this one.
Review
Quoted 1 line
(quoted diff) +1
-0+ type = (enum wm831x_parent)of_type;Looks like you don't even need
of_type.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Just cast
id->datastraight intowm81x_parent.Pretty sure you will get a warning on 64-bit systems if I do that.
What makes you think that?
commit 942786e6e647cef94cf96dcd836d343be55fc452
Author: Lee Jones <[email protected]>
mfd: arizona: Rid data size incompatibility warn when building for 64bit
I am fairly sure an enum would get treated the same as an int by the compiler. I will try it and see.
Thanks,
Charles
Quoted 39 lines · Charles Keepax
Quoted 11 lines · Lee Jones
Quoted 9 lines · Charles Keepax
Quoted 7 lines · Lee Jones
drivers/mfd/wm831x-i2c.c line 39
Quoted 3 lines · Charles Keepax
drivers/mfd/wm831x-i2c.c +3
-0+if (i2c->dev.of_node) { +const struct of_device_id *id =of_match_device (wm831x_of_match, + &i2c->dev);Not keen on this. Please declare the variable up with the others.
Quoted 8 lines
Quoted 4 lines
They are never going to be used anywhere else in the function. Again I can if you feel strongly but isn't it really better to limit the scope of the variables if they are only being used locally.
I understand the motivation, but if we did that all the time, the code would look pretty dire IMHO.
Ok I do another spin.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ unsigned long of_type = (unsigned long)id->data;And this one.
Review
Quoted 1 line
(quoted diff) +1
-0+ type = (enum wm831x_parent)of_type;Looks like you don't even need
of_type.Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Just cast
id->datastraight intowm81x_parent.Pretty sure you will get a warning on 64-bit systems if I do that.
What makes you think that?
Quoted 6 lines
commit
942786e6e647cef94cf96dcd836d343be55fc452
Author: Lee Jones <[email protected]>
mfd: arizona: Rid data size incompatibility warn when building for 64bitI am fairly sure an enum would get treated the same as an int by the compiler. I will try it and see.
I already prototyped it. No warnings seen.
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 41 lines · Lee Jones
Quoted 39 lines · Charles Keepax
Quoted 11 lines · Lee Jones
Quoted 9 lines · Charles Keepax
Quoted 7 lines · Lee Jones
drivers/mfd/wm831x-i2c.c line 39
Quoted 3 lines · Charles Keepax
drivers/mfd/wm831x-i2c.c +3
-0+if (i2c->dev.of_node) { +const struct of_device_id *id =of_match_device (wm831x_of_match, + &i2c->dev);Not keen on this. Please declare the variable up with the others.
Quoted 8 lines
Quoted 4 lines
They are never going to be used anywhere else in the function. Again I can if you feel strongly but isn't it really better to limit the scope of the variables if they are only being used locally.
I understand the motivation, but if we did that all the time, the code would look pretty dire IMHO.
Ok I do another spin.
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ unsigned long of_type = (unsigned long)id->data;And this one.
Quoted 8 lines
Quoted 5 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ type = (enum wm831x_parent)of_type;Looks like you don't even need
of_type.Just cast
id->datastraight intowm81x_parent.Pretty sure you will get a warning on 64-bit systems if I do that.
What makes you think that?
Quoted 9 lines
Quoted 6 lines
commit
942786e6e647cef94cf96dcd836d343be55fc452
Author: Lee Jones <[email protected]>
mfd: arizona: Rid data size incompatibility warn when building for 64bitI am fairly sure an enum would get treated the same as an int by the compiler. I will try it and see.
I already prototyped it. No warnings seen.
Cool thanks, the weird corners of C never cease to amaze me I will update the patch and resend.
Thanks,
Charles