mfd: rohm PMICs - use platform_device_id to match MFD sub-devices
Subsystems (4)
PATCH 1/1 mfd: rohm PMICs - use platform_device_id to match MFD sub-devices
Do device matching using the platform_device_id instead of using explicit module_aliases to load modules and custom parent-data field to do module loading and sub-device matching.
---
Thanks to Stephen Boyd I just learned we can use platform_device_id to do device and module matching for MFD sub-devices. This is handy in cases where more than one chips are supported by same sub-device drivers. For ROHM it currently is clk and regulator - but also the RTC when BD71828 is in-tree.
drivers/clk/clk-bd718x7.c | 12 ++++++++- drivers/mfd/rohm-bd70528.c | 3 +-- drivers/mfd/rohm-bd718x7.c | 39 ++++++++++++++++++++++----- drivers/regulator/bd718x7-regulator.c | 17 +++++++++--- include/linux/mfd/rohm-generic.h | 3 +-- 5 files changed, 58 insertions(+), 16 deletions(-)
drivers/clk/clk-bd718x7.c +11 -1
@@ -74,6 +74,7 @@ static int bd71837_clk_probe(struct platform_device *pdev) .name = "bd718xx-32k-out", .ops = &bd71837_clk_ops, }; +enum rohm_chip_type chip =platform_get_device_id (pdev)->driver_data; c =devm_kzalloc (&pdev->dev,sizeof (*c),GFP_KERNEL );if (!c)
@@ -87,7 +88,7 @@ static int bd71837_clk_probe(struct platform_device *pdev)dev_err (&pdev->dev,"No parent clk found\n" );return -EINVAL ; } -switch (mfd->chip_type) { +switch (chip) {case ROHM_CHIP_TYPE_BD71837 :case ROHM_CHIP_TYPE_BD71847 : c->reg =BD718XX_REG_OUT32K ;
@@ -121,11 +122,20 @@ static int bd71837_clk_probe(struct platform_device *pdev)return rval; } +static const struct platform_device_id bd718x7_clk_id[] = { + {"bd71837-clk" ,ROHM_CHIP_TYPE_BD71837 }, + {"bd71847-clk" ,ROHM_CHIP_TYPE_BD71847 }, + {"bd70528-clk" ,ROHM_CHIP_TYPE_BD70528 }, + { }, +}; +MODULE_DEVICE_TABLE (platform, bd718x7_clk_id); +static struct platform_driver bd71837_clk = { .driver = { .name ="bd718xx-clk" , }, .probe = bd71837_clk_probe, + .id_table = bd718x7_clk_id, };module_platform_driver (bd71837_clk);
drivers/mfd/rohm-bd70528.c +1 -2
@@ -48,7 +48,7 @@ static struct mfd_cell bd70528_mfd_cells[] = {* We use BD71837 driver to drive the clock block. Only differences to * BD70528 clock gate are the register address and mask. */ - { .name = "bd718xx-clk", }, + { .name = "bd70528-clk", }, { .name = "bd70528-wdt", }, { .name = "bd70528-power",
@@ -237,7 +237,6 @@ static int bd70528_i2c_probe(struct i2c_client *i2c,dev_set_drvdata (&i2c->dev, &bd70528->chip); - bd70528->chip.chip_type =ROHM_CHIP_TYPE_BD70528 ; bd70528->chip.regmap =devm_regmap_init_i2c (i2c, &bd70528_regmap);if (IS_ERR (bd70528->chip.regmap)) {dev_err (&i2c->dev,"Failed to initialize Regmap\n" );
drivers/mfd/rohm-bd718x7.c +32 -7
@@ -30,14 +30,24 @@ static struct gpio_keys_platform_data bd718xx_powerkey_data = { .name = "bd718xx-pwrkey", }; -static struct mfd_cell bd718xx_mfd_cells[] = { +static struct mfd_cell bd71837_mfd_cells[] = { { .name ="gpio-keys" , .platform_data = &bd718xx_powerkey_data, .pdata_size =sizeof (bd718xx_powerkey_data), }, - { .name ="bd718xx-clk" , }, - { .name ="bd718xx-pmic" , }, + { .name ="bd71837-clk" , }, + { .name ="bd71837-pmic" , }, +}; + +static struct mfd_cell bd71847_mfd_cells[] = { + { + .name ="gpio-keys" , + .platform_data = &bd718xx_powerkey_data, + .pdata_size =sizeof (bd718xx_powerkey_data), + }, + { .name ="bd71847-clk" , }, + { .name ="bd71847-pmic" , }, };static const struct regmap_irq bd718xx_irqs[] = {
@@ -124,6 +134,9 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c, {struct bd718xx *bd718xx;int ret; +unsigned int chip_type; +struct mfd_cell *mfd; +int cells;if (!i2c->irq) {dev_err (&i2c->dev,"No IRQ configured\n" );
@@ -136,8 +149,21 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c,return -ENOMEM ; bd718xx->chip_irq = i2c->irq; - bd718xx->chip.chip_type = (unsigned int )(uintptr_t ) -of_device_get_match_data (&i2c->dev); + chip_type = (unsigned int )(uintptr_t ) +of_device_get_match_data (&i2c->dev); +switch (chip_type) { +case ROHM_CHIP_TYPE_BD71837 : + mfd = bd71837_mfd_cells; + cells =ARRAY_SIZE (bd71837_mfd_cells); +break ; +case ROHM_CHIP_TYPE_BD71847 : + mfd = bd71847_mfd_cells; + cells =ARRAY_SIZE (bd71847_mfd_cells); +break ; +default : +dev_err (&i2c->dev,"Unknown device type" ); +return -EINVAL ; + } bd718xx->chip.dev = &i2c->dev;dev_set_drvdata (&i2c->dev, bd718xx);
@@ -170,8 +196,7 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c, button.irq = ret; ret =devm_mfd_add_devices (bd718xx->chip.dev,PLATFORM_DEVID_AUTO , - bd718xx_mfd_cells, -ARRAY_SIZE (bd718xx_mfd_cells),NULL ,0 , + mfd, cells,NULL ,0 ,regmap_irq_get_domain (bd718xx->irq_data));if (ret)dev_err (&i2c->dev,"Failed to create subdevices\n" );
drivers/regulator/bd718x7-regulator.c +13 -4
@@ -1164,6 +1164,7 @@ static int bd718xx_probe(struct platform_device *pdev)int i, j, err;bool use_snvs; +enum rohm_chip_type chip =platform_get_device_id (pdev)->driver_data; mfd =dev_get_drvdata (pdev->dev.parent);if (!mfd) {
@@ -1172,8 +1173,8 @@ static int bd718xx_probe(struct platform_device *pdev) goto err; } -if (mfd->chip.chip_type >=ROHM_CHIP_TYPE_AMOUNT || - !pmic_regulators[mfd->chip.chip_type].r_datas) { +if (chip >=ROHM_CHIP_TYPE_AMOUNT || chip <0 || + !pmic_regulators[chip].r_datas) {dev_err (&pdev->dev,"Unsupported chip type\n" ); err = -EINVAL ; goto err;
@@ -1215,13 +1216,13 @@ static int bd718xx_probe(struct platform_device *pdev) } } -for (i =0 ; i < pmic_regulators[mfd->chip.chip_type].r_amount; i++) { +for (i =0 ; i < pmic_regulators[chip].r_amount; i++) {const struct regulator_desc *desc;struct regulator_dev *rdev;const struct bd718xx_regulator_data *r; - r = &pmic_regulators[mfd->chip.chip_type].r_datas[i]; + r = &pmic_regulators[chip].r_datas[i]; desc = &r->desc; config.dev = pdev->dev.parent;
@@ -1281,11 +1282,19 @@ static int bd718xx_probe(struct platform_device *pdev)return err; } +static const struct platform_device_id bd718x7_pmic_id[] = { + {"bd71837-pmic" ,ROHM_CHIP_TYPE_BD71837 }, + {"bd71847-pmic" ,ROHM_CHIP_TYPE_BD71847 }, + { }, +}; +MODULE_DEVICE_TABLE (platform, bd718x7_pmic_id); +static struct platform_driver bd718xx_regulator = { .driver = { .name ="bd718xx-pmic" , }, .probe = bd718xx_probe, + .id_table = bd718x7_pmic_id, };module_platform_driver (bd718xx_regulator);
include/linux/mfd/rohm-generic.h +1 -2
@@ -4,7 +4,7 @@#ifndef __LINUX_MFD_ROHM_H__#define __LINUX_MFD_ROHM_H__ -enum { +enum rohm_chip_type {ROHM_CHIP_TYPE_BD71837 =0 ,ROHM_CHIP_TYPE_BD71847 , ROHM_CHIP_TYPE_BD70528,
@@ -12,7 +12,6 @@ enum { };struct rohm_regmap_dev { -unsigned int chip_type;struct device *dev;struct regmap *regmap; };
base-commit: d6d5df1db6e9d7f8f76d2911707f7d5877251b02
Signature · 14 lines
2.21.0 -- Matti Vaittinen, Linux device drivers ROHM Semiconductors, Finland SWDC Kiviharjunlenkki 1E 90220 OULU FINLAND ~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~ Simon says - in Latin please. ~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~ Thanks to Simon Glass for the translation =]
Hello Lee, Stephen, Mark & All,
Quoted 4 lines · Matti Vaittinen
Do device matching using the
platform_device_idinstead of using explicitmodule_aliasesto load modules and custom parent-data field to do module loading and sub-device matching.
Quoted 8 lines
Signed-off-by Matti Vaittinen <[email protected]>---
Thanks to Stephen Boyd I just learned we can use
platform_device_idto do device and module matching for MFD sub-devices. This is handy in cases where more than one chips are supported by same sub-device drivers. For ROHM it currently is clk and regulator - but also the RTC when BD71828 is in-tree.
I have been preparing driver for yet another ROHM PMIC (bd71828) - and the patch has been taking a few spins as RFC now. I would like to send first non RFC version of it - and I would like to write it on top of this patch. Is it Ok if I include this patch in the series - or should this stay as independent change? I would like to try avoid conflicting patches.
Br,
Matti Vaittinen
Quoted 16 lines · Matti Vaittinen
Hello Lee, Stephen, Mark & All,
Quoted 4 lines · Matti Vaittinen
Do device matching using the
platform_device_idinstead of using explicitmodule_aliasesto load modules and custom parent-data field to do module loading and sub-device matching.Quoted 8 lines
Signed-off-by Matti Vaittinen <[email protected]>---
Thanks to Stephen Boyd I just learned we can use
platform_device_idto do device and module matching for MFD sub-devices. This is handy in cases where more than one chips are supported by same sub-device drivers. For ROHM it currently is clk and regulator - but also the RTC when BD71828 is in-tree.
Quoted 6 lines
I have been preparing driver for yet another ROHM PMIC (bd71828) - and the patch has been taking a few spins as RFC now. I would like to send first non RFC version of it - and I would like to write it on top of this patch. Is it Ok if I include this patch in the series - or should this stay as independent change? I would like to try avoid conflicting patches.
You can draft this patch in.
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog