add 88pm80x mfd driver
Subsystems (4)
v2 cover add 88pm80x mfd driver
change log [v2->v1]:
1, split 88pm80x-core.c into 88pm800-core.c and 88pm805.c, per Arnd's suggestion. after the re-arch, 88pm80x-i2c handles the 800 & 805 common parts, while 800-core.c & 805-core.c handle the specific parts in each chip.
2, add details about the workaround adding a i2c companion between 800 & 805, and make a separate patch for it, per Arnd's suggestion. 3, remove callback in pdata. but still keep the pdata currently. 4, only keep necessary register in 88pm80x.h, including registers for regulator/rtc/onkey/power/codec etc, and remove other registers from global visibility.
5, exported r/w API which requires regmap handle. as currently the pm800 chip has 3 i2c device, only passing a pm80x_chip info can't ensure r/w the register in correct i2c device.
change log [v1]:
1, pm800 and pm805 are decoupled and probed separately;
2, re-used the most of API for pm800 and pm805 per Arnd's comments; 3, use regmap_irq, instead of previous 88pm80x_irq_data per Mark's comments. use regmap_add_irq_chip, and remove previous 88pm80x irq handling. 4, remove callback function in rtc pdata per Arnd's comments.
5, updated some coding style issue.
Qiao Zhou (4):
mfd: support 88pm80x in 80x driver
mfd: workaround: add companion chip in 88pm80x
rtc: add rtc support to 88PM80X PMIC
input: add onkey support to 88PM80X PMIC
drivers/input/misc/88pm80x_onkey.c | 190 +++++++++++++ drivers/input/misc/Kconfig | 10 + drivers/input/misc/Makefile | 1 + drivers/mfd/88pm800-core.c | 492 +++++++++++++++++++++++++++++++++ drivers/mfd/88pm805-core.c | 273 +++++++++++++++++++ drivers/mfd/88pm80x-i2c.c | 231 ++++++++++++++++ drivers/mfd/Kconfig | 12 + drivers/mfd/Makefile | 2 + drivers/rtc/Kconfig | 10 + drivers/rtc/Makefile | 1 + drivers/rtc/rtc-88pm80x.c | 366 +++++++++++++++++++++++++ include/linux/mfd/88pm80x.h | 522 ++++++++++++++++++++++++++++++++++++ 12 files changed, 2110 insertions(+), 0 deletions(-) create mode 100644 drivers/input/misc/88pm80x_onkey.c create mode 100644 drivers/mfd/88pm800-core.c create mode 100644 drivers/mfd/88pm805-core.c create mode 100644 drivers/mfd/88pm80x-i2c.c create mode 100644 drivers/rtc/rtc-88pm80x.c create mode 100644 include/linux/mfd/88pm80x.h
PATCH v2 1/4 mfd: support 88pm80x in 80x driver
88PM800 and 88PM805 are two discrete chips used for power management. Hardware designer can use them together or only one of them according to requirement.
88pm80x_i2c.c provides common i2c driver handling for both 800 and 805, such as i2c_driver init, regmap init, read/write api etc.
88pm800_core.c handles specifically for 800, such as chip init, irq init/handle, mfd device register, including rtc, onkey, regulator( to be add later) etc. besides that, 800 has three i2c device, one regular i2c client, two other i2c dummy for gpadc and power purpose.
88pm805_core.c handles specifically for 805, such as chip init, irq init/handle, mfd device register, including codec, headset/mic detect etc.
the i2c operation of both 800 and 805 are via regmap.
--- drivers/mfd/88pm800-core.c | 492 ++++++++++++++++++++++++++++++++++++++++ drivers/mfd/88pm805-core.c | 273 ++++++++++++++++++++++ drivers/mfd/88pm80x-i2c.c | 203 +++++++++++++++++ drivers/mfd/Kconfig | 12 + drivers/mfd/Makefile | 2 + include/linux/mfd/88pm80x.h | 521 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1503 insertions(+), 0 deletions(-) create mode 100644 drivers/mfd/88pm800-core.c create mode 100644 drivers/mfd/88pm805-core.c create mode 100644 drivers/mfd/88pm80x-i2c.c create mode 100644 include/linux/mfd/88pm80x.h
drivers/mfd/88pm800-core.c new file +492 -0
@@ -0,0 +1,492 @@ +/* +* Base driver for Marvell 88PM800 +* +* Copyright (C) 2012 Marvell International Ltd. +* Haojian Zhuang <[email protected]> +* Joseph(Yossi) Hanin <[email protected]> +* Qiao Zhou <[email protected]> +* +* This file is subject to the terms and conditions of the GNU General +* Public License. See the file "COPYING" in the main directory of this +* archive for more details. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/i2c.h> +#include <linux/irq.h> +#include <linux/interrupt.h> +#include <linux/platform_device.h> +#include <linux/mfd/core.h> +#include <linux/mfd/88pm80x.h> +#include <linux/regmap.h> +#include <linux/slab.h> + +static struct resource rtc_resources[] = { + { + .name ="88pm80x-rtc" , + .start =PM800_IRQ_RTC , + .end =PM800_IRQ_RTC , + .flags =IORESOURCE_IRQ , + }, +}; + +static struct mfd_cell rtc_devs[] = { + { + .name ="88pm80x-rtc" , + .num_resources =ARRAY_SIZE (rtc_resources), + .resources = &rtc_resources[0 ], + .id =-1 , + }, +}; + +static struct resource onkey_resources[] = { + { + .name ="88pm80x-onkey" , + .start =PM800_IRQ_ONKEY , + .end =PM800_IRQ_ONKEY , + .flags =IORESOURCE_IRQ , + }, +}; + +static struct mfd_cell onkey_devs[] = { + { + .name ="88pm80x-onkey" , + .num_resources =1 , + .resources = &onkey_resources[0 ], + .id =-1 , + }, +}; + +static const struct regmap_irq pm800_irqs[] = { +/* INT0 */ + [PM800_IRQ_ONKEY ] = { + .mask =PM800_ONKEY_INT_ENA1 , + }, + [PM800_IRQ_EXTON ] = { + .mask =PM800_EXTON_INT_ENA1 , + }, + [PM800_IRQ_CHG ] = { + .mask =PM800_CHG_INT_ENA1 , + }, + [PM800_IRQ_BAT ] = { + .mask =PM800_BAT_INT_ENA1 , + }, + [PM800_IRQ_RTC ] = { + .mask =PM800_RTC_INT_ENA1 , + }, + [PM800_IRQ_CLASSD ] = { + .mask =PM800_CLASSD_OC_INT_ENA1 , + }, +/* INT1 */ + [PM800_IRQ_VBAT ] = { + .reg_offset =1 , + .mask =PM800_VBAT_INT_ENA2 , + }, + [PM800_IRQ_VSYS ] = { + .reg_offset =1 , + .mask =PM800_VSYS_INT_ENA2 , + }, + [PM800_IRQ_VCHG ] = { + .reg_offset =1 , + .mask =PM800_VCHG_INT_ENA2 , + }, + [PM800_IRQ_TINT ] = { + .reg_offset =1 , + .mask =PM800_TINT_INT_ENA2 , + }, +/* INT2 */ + [PM800_IRQ_GPADC0 ] = { + .reg_offset =2 , + .mask =PM800_GPADC0_INT_ENA3 , + }, + [PM800_IRQ_GPADC1 ] = { + .reg_offset =2 , + .mask =PM800_GPADC1_INT_ENA3 , + }, + [PM800_IRQ_GPADC2 ] = { + .reg_offset =2 , + .mask =PM800_GPADC2_INT_ENA3 , + }, + [PM800_IRQ_GPADC3 ] = { + .reg_offset =2 , + .mask =PM800_GPADC3_INT_ENA3 , + }, + [PM800_IRQ_GPADC4 ] = { + .reg_offset =2 , + .mask =PM800_GPADC4_INT_ENA3 , + }, +/* INT3 */ + [PM800_IRQ_GPIO0 ] = { + .reg_offset =3 , + .mask =PM800_GPIO0_INT_ENA4 , + }, + [PM800_IRQ_GPIO1 ] = { + .reg_offset =3 , + .mask =PM800_GPIO1_INT_ENA4 , + }, + [PM800_IRQ_GPIO2 ] = { + .reg_offset =3 , + .mask =PM800_GPIO2_INT_ENA4 , + }, + [PM800_IRQ_GPIO3 ] = { + .reg_offset =3 , + .mask =PM800_GPIO3_INT_ENA4 , + }, + [PM800_IRQ_GPIO4 ] = { + .reg_offset =3 , + .mask =PM800_GPIO4_INT_ENA4 , + }, +}; + +static int __devinit device_gpadc_init (struct pm80x_chip *chip, +struct pm80x_platform_data *pdata) +{ +struct pm80x_subchip *subchip = chip->subchip; +struct regmap *map = subchip->regmap_gpadc; +int data =0 , mask =0 , ret =0 ; + +if (!map) { +dev_warn (chip->dev, +"Warning: gpadc regmap is not available!\n" ); +return -EINVAL ; + } +/* +* initialize GPADC without activating it turn on GPADC +* measurments +*/ + ret =pm80x_set_bits (map, +PM800_GPADC_MISC_CONFIG2 , +PM800_GPADC_MISC_GPFSM_EN , +PM800_GPADC_MISC_GPFSM_EN ); +if (ret <0 ) + goto out; +/* +* This function configures the ADC as requires for +* CP implementation.CP does not "own" the ADC configuration +* registers and relies on AP. +* Reason: enable automatic ADC measurements needed +* for CP to get VBAT and RF temperature readings. +*/ + ret =pm80x_set_bits (map,PM800_GPADC_MEAS_EN1 , +PM800_MEAS_EN1_VBAT ,PM800_MEAS_EN1_VBAT ); +if (ret <0 ) + goto out; + ret =pm80x_set_bits (map,PM800_GPADC_MEAS_EN2 , + (PM800_MEAS_EN2_RFTMP |PM800_MEAS_GP0_EN ), + (PM800_MEAS_EN2_RFTMP |PM800_MEAS_GP0_EN )); +if (ret <0 ) + goto out; + +/* +* the defult of PM800 is GPADC operates@100Ks/s rate +* and Number of GPADC slots with active current bias prior +* to GPADC sampling = 1 slot for all GPADCs set for +* Temprature mesurmants +*/ + mask = (PM800_GPADC_GP_BIAS_EN0 |PM800_GPADC_GP_BIAS_EN1 | +PM800_GPADC_GP_BIAS_EN2 |PM800_GPADC_GP_BIAS_EN3 ); + +if (pdata && (pdata->batt_det ==0 )) + data = (PM800_GPADC_GP_BIAS_EN0 |PM800_GPADC_GP_BIAS_EN1 | +PM800_GPADC_GP_BIAS_EN2 |PM800_GPADC_GP_BIAS_EN3 ); +else + data = (PM800_GPADC_GP_BIAS_EN0 |PM800_GPADC_GP_BIAS_EN2 | +PM800_GPADC_GP_BIAS_EN3 ); + + ret =pm80x_set_bits (map,PM800_GP_BIAS_ENA1 , mask, data); +if (ret <0 ) + goto out; + +dev_info (chip->dev,"pm800 device_gpadc_init: Done\n" ); +return 0 ; + +out: +dev_info (chip->dev,"pm800 device_gpadc_init: Failed!\n" ); +return ret; +} + +static int __devinit device_irq_init_800 (struct pm80x_chip *chip) +{ +struct regmap *map = chip->regmap; +unsigned long flags =IRQF_TRIGGER_FALLING |IRQF_ONESHOT ; +int data, mask, ret = -EINVAL ; + +if (!map || !chip->irq) { +dev_err (chip->dev,"incorrect parameters\n" ); +return -EINVAL ; + } + +/* +* irq_mode defines the way of clearing interrupt. it's read-clear by +* default. +*/ + mask = +PM800_WAKEUP2_INV_INT |PM800_WAKEUP2_INT_CLEAR | +PM800_WAKEUP2_INT_MASK ; + + data =PM800_WAKEUP2_INT_CLEAR ; + ret =pm80x_set_bits (map,PM800_WAKEUP2 , mask, data); + +if (ret <0 ) + goto out; + + ret = +regmap_add_irq_chip (chip->regmap, chip->irq, flags, chip->irq_base, + chip->regmap_irq_chip, &chip->irq_data); + +out: +return ret; +} + +static void device_irq_exit_800 (struct pm80x_chip *chip) +{ +regmap_del_irq_chip (chip->irq, chip->irq_data); +} + +static struct regmap_irq_chip pm800_irq_chip = { + .name ="88pm800" , + .irqs = pm800_irqs, + .num_irqs =ARRAY_SIZE (pm800_irqs), + + .num_regs =4 , + .status_base =PM800_INT_STATUS1 , + .mask_base =PM800_INT_ENA_1 , + .ack_base =PM800_INT_STATUS1 , +}; + +static int pm800_pages_init (struct pm80x_chip *chip) +{ +struct pm80x_subchip *subchip; +struct i2c_client *client = chip->client; + + subchip = chip->subchip; +/* PM800 block power: i2c addr 0x31 */ +if (subchip->power_page_addr) { + subchip->power_page = +i2c_new_dummy (client->adapter, subchip->power_page_addr); + subchip->regmap_power = +devm_regmap_init_i2c (subchip->power_page, + &pm80x_regmap_config); +i2c_set_clientdata (subchip->power_page, chip); + }else +dev_info (chip->dev, +"PM800 block power 0x31: No power_page_addr\n" ); + +/* PM800 block GPADC: i2c addr 0x32 */ +if (subchip->gpadc_page_addr) { + subchip->gpadc_page =i2c_new_dummy (client->adapter, + subchip->gpadc_page_addr); + subchip->regmap_gpadc = +devm_regmap_init_i2c (subchip->gpadc_page, + &pm80x_regmap_config); +i2c_set_clientdata (subchip->gpadc_page, chip); + }else +dev_info (chip->dev, +"PM800 block GPADC 0x32: No gpadc_page_addr\n" ); + +return 0 ; +} + +static void pm800_pages_exit (struct pm80x_chip *chip) +{ +struct pm80x_subchip *subchip; + +regmap_exit (chip->regmap); +i2c_unregister_device (chip->client); + + subchip = chip->subchip; +if (subchip->power_page) { +regmap_exit (subchip->regmap_power); +i2c_unregister_device (subchip->power_page); + } +if (subchip->gpadc_page) { +regmap_exit (subchip->regmap_gpadc); +i2c_unregister_device (subchip->gpadc_page); + } +} + +static int __devinit device_800_init (struct pm80x_chip *chip, +struct pm80x_platform_data *pdata) +{ +int ret, pmic_id; + + ret =pm80x_reg_read (chip->regmap,PM800_CHIP_ID ); +if (ret <0 ) { +dev_err (chip->dev,"Failed to read CHIP ID: %d\n" , ret); + goto out; + } + + pmic_id = ret &PM80X_VERSION_MASK ; + +if ((pmic_id >=PM800_CHIP_A0 ) && (pmic_id <=PM800_CHIP_END )) { + chip->version = ret; +dev_info (chip->dev, +"88PM80x:Marvell 88PM800 (ID:0x%x) detected\n" , ret); + }else { +dev_err (chip->dev, +"Failed to detect Marvell 88PM800:ChipID[0x%x]\n" , ret); + goto out; + } + +/* +* alarm wake up bit will be clear in device_irq_init(), +* read before that +*/ + ret =pm80x_reg_read (chip->regmap,PM800_RTC_CONTROL ); +if (ret <0 ) { +dev_err (chip->dev,"Failed to read RTC register: %d\n" , ret); + goto out; + } +if (ret &PM800_ALARM_WAKEUP ) { +if (pdata && pdata->rtc) + pdata->rtc->rtc_wakeup =1 ; + } + + ret =device_gpadc_init (chip, pdata); +if (ret <0 ) { +dev_err (chip->dev,"[%s]Failed to init gpadc\n" , __func__); + goto out; + } + + chip->regmap_irq_chip = &pm800_irq_chip; + + ret =device_irq_init_800 (chip); +if (ret <0 ) { +dev_err (chip->dev,"[%s]Failed to init pm800 irq\n" , __func__); + goto out; + } + + ret =mfd_add_devices (chip->dev,0 , &onkey_devs[0 ], +ARRAY_SIZE (onkey_devs), &onkey_resources[0 ], + chip->irq_base); +if (ret <0 ) { +dev_err (chip->dev,"Failed to add onkey subdev\n" ); + goto out_dev; + }else +dev_info (chip->dev,"[%s]:Added mfd onkey_devs\n" , __func__); + +if (pdata && pdata->rtc) { + rtc_devs[0 ].platform_data = pdata->rtc; + rtc_devs[0 ].pdata_size =sizeof (struct pm80x_rtc_pdata ); + ret =mfd_add_devices (chip->dev,0 , &rtc_devs[0 ], +ARRAY_SIZE (rtc_devs),NULL , + chip->irq_base); +if (ret <0 ) { +dev_err (chip->dev,"Failed to add rtc subdev\n" ); + goto out_dev; + }else +dev_info (chip->dev, +"[%s]:Added mfd rtc_devs\n" , __func__); + } + +return 0 ; +out_dev: +mfd_remove_devices (chip->dev); +device_irq_exit_800 (chip); +out: +return ret; +} + +static int __devinit pm800_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +int ret =0 ; +struct pm80x_chip *chip; +struct pm80x_platform_data *pdata = client->dev.platform_data; +struct pm80x_subchip *subchip; + + ret =pm80x_init (client, id); +if (ret) { +dev_err (&client->dev,"pm800_init fail\n" ); + goto out_init; + } + + chip =i2c_get_clientdata (client); + +/* init subchip for PM800 */ + subchip = +devm_kzalloc (&client->dev,sizeof (struct pm80x_subchip ), +GFP_KERNEL ); +if (!subchip) { + ret = -ENOMEM ; + goto err_subchip_alloc; + } + + subchip->power_page_addr = pdata->power_page_addr; + subchip->gpadc_page_addr = pdata->gpadc_page_addr; + chip->subchip = subchip; + + ret =device_800_init (chip, pdata); +if (ret) { +dev_err (chip->dev,"%s id 0x%x failed!\n" , __func__, chip->id); + goto err_800_init; + } + + ret =pm800_pages_init (chip); +if (ret) { +dev_err (&client->dev,"pm800_pages_init failed!\n" ); + goto err_page_init; + } + +err_page_init: +mfd_remove_devices (chip->dev); +device_irq_exit_800 (chip); +err_800_init: +devm_kfree (&client->dev, subchip); +err_subchip_alloc: +pm80x_deinit (client); +out_init: +return ret; +} + +static int __devexit pm800_remove(struct i2c_client *client) +{ +struct pm80x_chip *chip =i2c_get_clientdata (client); + +mfd_remove_devices (chip->dev); +device_irq_exit_800 (chip); + +pm800_pages_exit (chip); +devm_kfree (&client->dev, chip->subchip); + +pm80x_deinit (client); + +return 0 ; +} + +static struct i2c_driver pm800_driver = { + .driver = { + .name ="88PM80X" , + .owner =THIS_MODULE , + .pm = &pm80x_pm_ops, + }, + .probe = pm800_probe, + .remove =__devexit_p (pm800_remove), + .id_table = pm80x_id_table, +}; + +static int __init pm800_i2c_init (void ) +{ +return i2c_add_driver (&pm800_driver); +} +subsys_initcall (pm800_i2c_init); + +static void __exit pm800_i2c_exit(void) +{ +i2c_del_driver (&pm800_driver); +} +module_exit (pm800_i2c_exit); + +MODULE_DESCRIPTION ("PMIC Driver for Marvell 88PM800" ); +MODULE_AUTHOR ("Qiao Zhou <[email protected]>" ); +MODULE_LICENSE ("GPL" );
drivers/mfd/88pm805-core.c new file +273 -0
273 lines not on this page · raw message
drivers/mfd/88pm80x-i2c.c new file +203 -0
203 lines not on this page · raw message
drivers/mfd/Kconfig +12 -0
@@ -20,6 +20,18 @@ config MFD_88PM860X select individual components like voltage regulators, RTC and battery-charger under the corresponding menus. +config MFD_88PM80X + bool "Support Marvell 88PM800/88PM805" + depends on I2C=y && GENERIC_HARDIRQS + select REGMAP_I2C + select REGMAP_IRQ + select MFD_CORE + help + This supports for Marvell 88PM800/88PM805 Power Management IC. + This includes the I2C driver and the core APIs _only_, you have to + select individual components like voltage regulators, RTC and + battery-charger under the corresponding menus. + config MFD_SM501 tristate "Support for Silicon Motion SM501" ---help---
drivers/mfd/Makefile +2 -0
@@ -3,7 +3,9 @@ # 88pm860x-objs := 88pm860x-core.o 88pm860x-i2c.o +88pm80x-objs := 88pm800-core.o 88pm805-core.o 88pm80x-i2c.o obj-$(CONFIG_MFD_88PM860X) += 88pm860x.o +obj-$(CONFIG_MFD_88PM80X) += 88pm80x.o obj-$(CONFIG_MFD_SM501) += sm501.o obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o
include/linux/mfd/88pm80x.h new file +521 -0
521 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 1/4 mfd: support 88pm80x in 80x driver
Quoted 12 lines · Qiao Zhou
88PM800 and 88PM805 are two discrete chips used for power management. Hardware designer can use them together or only one of them according to requirement.
88pm80x_i2c.cprovides common i2c driver handling for both 800 and 805, such asi2c_driverinit, regmap init, read/write api etc.
88pm800_core.chandles specifically for 800, such as chip init, irq init/handle, mfd device register, including rtc, onkey, regulator( to be add later) etc. besides that, 800 has three i2c device, one regular i2c client, two other i2c dummy for gpadc and power purpose.
Quoted 7 lines
88pm805_core.chandles specifically for 805, such as chip init, irq init/handle, mfd device register, including codec, headset/mic detect etc.the i2c operation of both 800 and 805 are via regmap.
Signed-off-by Qiao Zhou <[email protected]>
The split between the two files looks very good now, I think this way it makes much more sense for the reader.
drivers/mfd/88pm800-core.c line 371
Quoted 3 lines
drivers/mfd/88pm800-core.c new file +3
-0+ ret =mfd_add_devices (chip->dev,0 , &onkey_devs[0 ], +ARRAY_SIZE (onkey_devs), &onkey_resources[0 ], + chip->irq_base);
According to what I discussed with Mark in the previous version, I think you need to pass 0 instead of chip->irq_base here, and transform the interrupt numbers using the domain in the client drivers.
drivers/mfd/88pm80x-i2c.c line 34
Quoted 6 lines
drivers/mfd/88pm80x-i2c.c new file +6
-0+ +const struct i2c_device_id pm80x_id_table[] = { + {"88PM800" ,CHIP_PM800 }, + {"88PM805" ,CHIP_PM805 }, +}; +MODULE_DEVICE_TABLE (i2c, pm80x_id_table);
Since these are separate modules now, you have to move the device table into the split files as well.
Quoted 10 lines
drivers/mfd/88pm80x-i2c.c new file +10
-0+ +/** +* pm80x_reg_read: Read a single 88PM80x register. +* +* @map: regmap to read from. +* @reg: Register to read. +*/ +int pm80x_reg_read (struct regmap *map,u32 reg) +{ +unsigned int val;
drivers/mfd/88pm80x-i2c.c line 54
Quoted 10 lines
drivers/mfd/88pm80x-i2c.c new file +10
-0+int ret; + + ret =regmap_read (map, reg, &val); + +if (ret <0 ) +return ret; +else +return val; +} +EXPORT_SYMBOL_GPL (pm80x_reg_read);
In your introductory email you write
"Exported r/w API which requires regmap handle. as currently the pm800 chip has 3 i2c device, only passing a pm80x_chip info can't ensure r/w the register in correct i2c device."
Your first driver version had this, then you removed the functions after I asked you to, and now they are back, so I assume there is something I don't see yet. It looks like the function is just an unnecessary wrapper that is better open-coded in the caller. Can you explain again what the difference is?
drivers/mfd/88pm80x-i2c.c line 67
Quoted 12 lines
drivers/mfd/88pm80x-i2c.c new file +12
-0+/** +* pm80x_bulk_read: Read multiple 88PM80x registers +* +* @map: regmap to read from +* @reg: First register +* @buf: Buffer to fill. The data will be returned big endian. +* @count: Number of registers +*/ +int pm80x_bulk_read (struct regmap *map,u32 reg,u8 *buf,int count) +{ +return regmap_raw_read (map, reg, buf, count); +}
Unused function? Either export this if you want to provide it as the general API, or drop the function.
Review
Quoted 6 lines
(quoted diff) +4
-0+int __devinit pm80x_device_init(struct pm80x_chip *chip, + struct pm80x_platform_data *pdata) +void __devexit pm80x_device_exit(struct pm80x_chip *chip) +SIMPLE_DEV_PM_OPS(pm80x_pm_ops, pm80x_suspend, pm80x_resume);
I would think that these need to be exported as well, at least if you want the driver to be modular.
Quoted 28 lines
drivers/mfd/Kconfig +12
-0@@ -20,6 +20,18 @@ config MFD_88PM860X select individual components like voltage regulators, RTC and battery-charger under the corresponding menus. +config MFD_88PM80X + bool "Support Marvell 88PM800/88PM805" + depends on I2C=y && GENERIC_HARDIRQS + select REGMAP_I2C + select REGMAP_IRQ + select MFD_CORE + help + This supports for Marvell 88PM800/88PM805 Power Management IC. + This includes the I2C driver and the core APIs _only_, you have to + select individual components like voltage regulators, RTC and + battery-charger under the corresponding menus. + config MFD_SM501 tristate "Support for Silicon Motion SM501" ---help---drivers/mfd/Makefile +0
-0
drivers/mfd/Makefile line 10
Quoted 8 lines
drivers/mfd/Makefile +2
-0@@ -3,7 +3,9 @@ # 88pm860x-objs := 88pm860x-core.o 88pm860x-i2c.o +88pm80x-objs := 88pm800-core.o 88pm805-core.o 88pm80x-i2c.o obj-$(CONFIG_MFD_88PM860X) += 88pm860x.o +obj-$(CONFIG_MFD_88PM80X) += 88pm80x.o obj-$(CONFIG_MFD_SM501) += sm501.o obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o
I just noticed that it can currently only be builtin. Is there a strict requirement for that? If not, better make it a tristate option.
If you do that, aside from adding the exports mentioned above, you have to use three separate modules, as in
obj-$(CONFIG_MFD_88PM80X) += 88pm800-core.o 88pm805-core.o 88pm80x-i2c.o
or even
obj-$(CONFIG_MFD_88PM800) += 88pm800-core.o 88pm800-core.o
obj-$(CONFIG_MFD_88PM805) += 88pm800-core.o 88pm805-core.o
with the respective Kconfig change.
Quoted 26 lines
include/linux/mfd/88pm80x.h new file +20
-0@@ -0,0 +1,521 @@ +#ifndef __LINUX_MFD_88PM80X_H +#define __LINUX_MFD_88PM80X_H + +#define PM80X_VERSION_MASK (0xFF)/* 80X chip ID mask */ + +enum { +/* Procida */ +PM800_CHIP_A0 =0x60 , +PM800_CHIP_A1 =0x61 , +PM800_CHIP_B0 =0x62 , +PM800_CHIP_C0 =0x63 , +PM800_CHIP_END =PM800_CHIP_C0 , + +/* Make sure to update this to the last stepping */ +PM8XXX_CHIP_END =PM800_CHIP_END +}; + +enum { +PM800_ID_INVALID , + PM800_ID_VIBRATOR,
include/linux/mfd/88pm80x.h line 30
Quoted 10 lines
include/linux/mfd/88pm80x.h new file +10
-0+PM800_ID_SOUND , + PM800_ID_MAX, +}; + +enum { +PM800_ID_BUCK1 =0 , +PM800_ID_BUCK2 , +PM800_ID_BUCK3 , +PM800_ID_BUCK4 , + PM800_ID_BUCK5,
I would still argue that the majority of the constants in this file should get moved into the driver .c file that uses them. Putting them into the header is better done only for interfaces between the driver parts, and for constants that are used by multiple drivers.
Quoted 13 lines
include/linux/mfd/88pm80x.h new file +13
-0+struct pm80x_subchip { +struct i2c_client *power_page;/* chip client for power page */ +struct i2c_client *gpadc_page;/* chip client for gpadc page */ +struct regmap *regmap_power; +struct regmap *regmap_gpadc; +unsigned short power_page_addr;/* power page I2C address */ +unsigned short gpadc_page_addr;/* gpadc page I2C address */ +}; + +struct pm80x_chip { +struct pm80x_subchip *subchip; +struct device *dev; +struct i2c_client *client;
include/linux/mfd/88pm80x.h line 491
Quoted 10 lines
include/linux/mfd/88pm80x.h new file +10
-0+struct regmap *regmap; +struct regmap_irq_chip *regmap_irq_chip; +struct regmap_irq_chip_data *irq_data; +unsigned char version; +int id; +int irq; +int irq_mode; +int irq_base; +unsigned int wu_flag; +};
One thing I forgot to ask in the previous review although I had already noticed it then: What is the separation of pm80x_chip and pm80x_subchip used for?
Quoted 5 lines
include/linux/mfd/88pm80x.h new file +5
-0+struct pm80x_rtc_pdata { +int vrtc; +int rtc_wakeup; +}; +
include/linux/mfd/88pm80x.h line 507
Quoted 10 lines
include/linux/mfd/88pm80x.h new file +10
-0+struct pm80x_platform_data { +struct pm80x_rtc_pdata *rtc; +unsigned short pm800_addr; +unsigned short pm805_addr; +unsigned short power_page_addr;/* power page I2C address */ +unsigned short gpadc_page_addr;/* gpadc page I2C address */ +int irq_mode;/* Clear interrupt by read/write(0/1) */ +int irq_base;/* IRQ base of chip */ +int batt_det;/* enable/disable */ +};
You removed the callback here as I asked you to, which I think is a useful cleanup, but you can actually managed to convinced me that it would be ok to have it, so I don't mind if you want to put it back and use auxdata.
On the other hand, I think it probably makes sense to drop the irq_base member in this struct and rely on irq domains to allocate them dynamically as mentioned before.
Arnd
PATCH v2 1/4 mfd: support 88pm80x in 80x driver
Quoted 8 lines
drivers/mfd/88pm800-core.c line 371
Quoted 3 lines
drivers/mfd/88pm800-core.c new file +3
-0+ ret =mfd_add_devices (chip->dev,0 , &onkey_devs[0 ], +ARRAY_SIZE (onkey_devs), &onkey_resources[0 ], + chip->irq_base);According to what I discussed with Mark in the previous version, I think you need to pass 0 instead of
chip->irq_basehere, and transform the interrupt numbers using the domain in the client drivers.
Quoted 9 lines
drivers/mfd/88pm80x-i2c.c line 34
Quoted 6 lines
drivers/mfd/88pm80x-i2c.c new file +6
-0+ +const struct i2c_device_id pm80x_id_table[] = { + {"88PM800" ,CHIP_PM800 }, + {"88PM805" ,CHIP_PM805 }, +}; +MODULE_DEVICE_TABLE (i2c, pm80x_id_table);Since these are separate modules now, you have to move the device table into the split files as well.
Is it ok to export it in 88pm80x.h?
Quoted 27 lines
Quoted 10 lines
drivers/mfd/88pm80x-i2c.c new file +10
-0+ +/** +* pm80x_reg_read: Read a single 88PM80x register. +* +* @map: regmap to read from. +* @reg: Register to read. +*/ +int pm80x_reg_read (struct regmap *map,u32 reg) +{ +unsigned int val;drivers/mfd/88pm80x-i2c.c line 54
Quoted 10 lines
drivers/mfd/88pm80x-i2c.c new file +10
-0+int ret; + + ret =regmap_read (map, reg, &val); + +if (ret <0 ) +return ret; +else +return val; +} +EXPORT_SYMBOL_GPL (pm80x_reg_read);In your introductory email you write
"Exported r/w API which requires regmap handle. as currently the pm800 chip has 3 i2c device, only passing a
pm80x_chipinfo can't ensure r/w the register in correct i2c device."
Quoted 5 lines
Your first driver version had this, then you removed the functions after I asked you to, and now they are back, so I assume there is something I don't see yet. It looks like the function is just an unnecessary wrapper that is better open-coded in the caller. Can you explain again what the difference is?
After you suggest to change the r/w API so that caller doesn't care about it's via i2c or spi, it makes sense. However due to pm800 has 3 i2c devices, and it's hard to export such interface for pm800. Currently to add such interface via regmap handle, caller still doesn't care about the actual hw implement, also it's clear that all pm80x sub-driver or plat call the unified r/w API.
Quoted 7 lines
Quoted 7 lines
+/**
+ *pm80x_bulk_read: Read multiple 88PM80x registers
+ *
+ * @map: regmap to read from
+ * @reg: First register
+ * @buf: Buffer to fill. The data will be returned big endian.
+ * @count: Number of registers
Quoted 8 lines
drivers/mfd/88pm80x-i2c.c line 67
Quoted 5 lines
+ */
drivers/mfd/88pm80x-i2c.c new file +4
-0+int pm80x_bulk_read (struct regmap *map,u32 reg,u8 *buf,int count) +{ +return regmap_raw_read (map, reg, buf, count); +}Unused function? Either export this if you want to provide it as the general API, or drop the function.
It's used by rtc driver.
Quoted 9 lines
Review
Quoted 6 lines
(quoted diff) +4
-0+int __devinit pm80x_device_init(struct pm80x_chip *chip, + struct pm80x_platform_data *pdata) +void __devexit pm80x_device_exit(struct pm80x_chip *chip) +SIMPLE_DEV_PM_OPS(pm80x_pm_ops, pm80x_suspend, pm80x_resume);I would think that these need to be exported as well, at least if you want the driver to be modular.
Would update. Thanks.
Quoted 43 lines
Quoted 28 lines
drivers/mfd/Kconfig +12
-0@@ -20,6 +20,18 @@ config MFD_88PM860X select individual components like voltage regulators, RTC and battery-charger under the corresponding menus. +config MFD_88PM80X + bool "Support Marvell 88PM800/88PM805" + depends on I2C=y && GENERIC_HARDIRQS + select REGMAP_I2C + select REGMAP_IRQ + select MFD_CORE + help + This supports for Marvell 88PM800/88PM805 Power Management IC. + This includes the I2C driver and the core APIs _only_, you have to + select individual components like voltage regulators, RTC and + battery-charger under the corresponding menus. + config MFD_SM501 tristate "Support for Silicon Motion SM501" ---help---drivers/mfd/Makefile +0
-0drivers/mfd/Makefile line 10
Quoted 8 lines
drivers/mfd/Makefile +2
-0@@ -3,7 +3,9 @@ # 88pm860x-objs := 88pm860x-core.o 88pm860x-i2c.o +88pm80x-objs := 88pm800-core.o 88pm805-core.o 88pm80x-i2c.o obj-$(CONFIG_MFD_88PM860X) += 88pm860x.o +obj-$(CONFIG_MFD_88PM80X) += 88pm80x.o obj-$(CONFIG_MFD_SM501) += sm501.o obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.oI just noticed that it can currently only be builtin. Is there a strict
Quoted 1 line
requirement for that? If not, better make it a tristate option.
If you do that, aside from adding the exports mentioned above, you have to use three separate modules, as in
Quoted 8 lines
obj-$(CONFIG_MFD_88PM80X) += 88pm800-core.o 88pm805-core.o 88pm80x-i2c.o
or even
obj-$(CONFIG_MFD_88PM800) += 88pm800-core.o 88pm800-core.o
obj-$(CONFIG_MFD_88PM805) += 88pm800-core.o 88pm805-core.owith the respective
Kconfigchange.
Would update. Thanks.
Quoted 35 lines
Quoted 34 lines
include/linux/mfd/88pm80x.h new file +28
-0@@ -0,0 +1,521 @@ +#ifndef __LINUX_MFD_88PM80X_H +#define __LINUX_MFD_88PM80X_H + +#define PM80X_VERSION_MASK (0xFF)/* 80X chip ID mask */ + +enum { +/* Procida */ +PM800_CHIP_A0 =0x60 , +PM800_CHIP_A1 =0x61 , +PM800_CHIP_B0 =0x62 , +PM800_CHIP_C0 =0x63 , +PM800_CHIP_END =PM800_CHIP_C0 , + +/* Make sure to update this to the last stepping */ +PM8XXX_CHIP_END =PM800_CHIP_END +}; + +enum { +PM800_ID_INVALID , +PM800_ID_VIBRATOR , +PM800_ID_SOUND , +PM800_ID_MAX , +}; + +enum { +PM800_ID_BUCK1 =0 , +PM800_ID_BUCK2 , + PM800_ID_BUCK3,include/linux/mfd/88pm80x.h new file +1
-0+ PM800_ID_BUCK4,
Quoted 6 lines
include/linux/mfd/88pm80x.h line 47
Quoted 1 line
include/linux/mfd/88pm80x.h new file +1
-0+ PM800_ID_BUCK5,I would still argue that the majority of the constants in this file should get moved into the driver .c file that uses them. Putting them into the header is better done only for interfaces between the driver parts, and for constants that are used by multiple drivers.
These registers still in this header file are either used by mfd core driver, regulator/rtc/onkey/codec, or used in platform initial setting.
Quoted 19 lines
Quoted 19 lines
include/linux/mfd/88pm80x.h new file +19
-0+struct pm80x_subchip { +struct i2c_client *power_page;/* chip client for power page */ +struct i2c_client *gpadc_page;/* chip client for gpadc page */ +struct regmap *regmap_power; +struct regmap *regmap_gpadc; +unsigned short power_page_addr;/* power page I2C address */ +unsigned short gpadc_page_addr;/* gpadc page I2C address */ +}; + +struct pm80x_chip { +struct pm80x_subchip *subchip; +struct device *dev; +struct i2c_client *client; +struct regmap *regmap; +struct regmap_irq_chip *regmap_irq_chip; +struct regmap_irq_chip_data *irq_data; +unsigned char version; +int id; +int irq;
Quoted 8 lines
include/linux/mfd/88pm80x.h line 491
Quoted 4 lines
include/linux/mfd/88pm80x.h new file +4
-0+int irq_mode; +int irq_base; +unsigned int wu_flag; +};One thing I forgot to ask in the previous review although I had already noticed it then: What is the separation of
pm80x_chipandpm80x_subchipused for?
Pm80x_chip is common for both pm800 and pm805, while pm80x_subchip handles the other i2c devices as discussed before, only that these two i2c devices are not as much as pm800 and pm805 i2c device, and they are only for gpadc & power settings purpose. The subchip can be treated as some special feature/function for pm800.
Quoted 11 lines
Quoted 11 lines
include/linux/mfd/88pm80x.h new file +11
-0+struct pm80x_rtc_pdata { +int vrtc; +int rtc_wakeup; +}; + +struct pm80x_platform_data { +struct pm80x_rtc_pdata *rtc; +unsigned short pm800_addr; +unsigned short pm805_addr; +unsigned short power_page_addr;/* power page I2C address */ +unsigned short gpadc_page_addr;/* gpadc page I2C address */
Quoted 8 lines
include/linux/mfd/88pm80x.h line 507
Quoted 4 lines
include/linux/mfd/88pm80x.h new file +4
-0+int irq_mode;/* Clear interrupt by read/write(0/1) */ +int irq_base;/* IRQ base of chip */ +int batt_det;/* enable/disable */ +};You removed the callback here as I asked you to, which I think is a useful cleanup, but you can actually managed to convinced me that it would be ok to have it, so I don't mind if you want to put it back and use auxdata.
Actually it's convenient for us to put it back currently, and would use auxdata instead.
Quoted 4 lines
On the other hand, I think it probably makes sense to drop the
irq_basemember in this struct and rely on irq domains to allocate them dynamically as mentioned before.
Do you mean that both regmap_add_irq_chip and mfd_add_devices api pass -1 as the irq_base, so that system can dynamically allocate the irq_base for it? Given the proper regmap_irq_chip & device resource, is there anything else needed? As I don't want to miss the exact meaning of " transform the interrupt numbers using the domain in the client drivers" you mentioned above.
Quoted 1 line
Arnd
Arnd, thanks for your review.
Best Regards
Qiao
PATCH 1/4 mfd: support 88pm80x in 80x driver
Quoted 17 lines · Qiao Zhou
Quoted 8 lines
drivers/mfd/88pm800-core.c line 371
Quoted 3 lines
drivers/mfd/88pm800-core.c new file +3
-0+ ret =mfd_add_devices (chip->dev,0 , &onkey_devs[0 ], +ARRAY_SIZE (onkey_devs), &onkey_resources[0 ], + chip->irq_base);According to what I discussed with Mark in the previous version, I think you need to pass 0 instead of
chip->irq_basehere, and transform the interrupt numbers using the domain in the client drivers.Quoted 9 lines
drivers/mfd/88pm80x-i2c.c line 34
Quoted 6 lines
drivers/mfd/88pm80x-i2c.c new file +6
-0+ +const struct i2c_device_id pm80x_id_table[] = { + {"88PM800" ,CHIP_PM800 }, + {"88PM805" ,CHIP_PM805 }, +}; +MODULE_DEVICE_TABLE (i2c, pm80x_id_table);Since these are separate modules now, you have to move the device table into the split files as well.
Quoted 1 line
Is it ok to export it in
88pm80x.h?
You mean putting the MODULE_DEVICE_TABLE() into 88pm80x.h? No, that would not work.
The correct way is to have two MODULE_DEVICE_TABLE statements, one per file. Actually the table only makes sense for loadable modules, so if you decide to keep the driver only built-in, it's best to just drop this table.
Quoted 33 lines
Quoted 27 lines
Quoted 10 lines
drivers/mfd/88pm80x-i2c.c new file +10
-0+ +/** +* pm80x_reg_read: Read a single 88PM80x register. +* +* @map: regmap to read from. +* @reg: Register to read. +*/ +int pm80x_reg_read (struct regmap *map,u32 reg) +{ +unsigned int val;drivers/mfd/88pm80x-i2c.c line 54
Quoted 10 lines
drivers/mfd/88pm80x-i2c.c new file +10
-0+int ret; + + ret =regmap_read (map, reg, &val); + +if (ret <0 ) +return ret; +else +return val; +} +EXPORT_SYMBOL_GPL (pm80x_reg_read);In your introductory email you write
"Exported r/w API which requires regmap handle. as currently the pm800 chip has 3 i2c device, only passing a
pm80x_chipinfo can't ensure r/w the register in correct i2c device."Quoted 5 lines
Your first driver version had this, then you removed the functions after I asked you to, and now they are back, so I assume there is something I don't see yet. It looks like the function is just an unnecessary wrapper that is better open-coded in the caller. Can you explain again what the difference is?
Quoted 5 lines
After you suggest to change the r/w API so that caller doesn't care about it's via i2c or spi, it makes sense. However due to pm800 has 3 i2c devices, and it's hard to export such interface for pm800. Currently to add such interface via regmap handle, caller still doesn't care about the actual hw implement, also it's clear that all pm80x sub-driver or plat call the unified r/w API.
But there is nothing unified about the function above, it just calls regmap_read(), so the caller already has access to the regmap pointer.
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
+/**
+ *pm80x_bulk_read: Read multiple 88PM80x registers
+ *
+ * @map: regmap to read from
+ * @reg: First register
+ * @buf: Buffer to fill. The data will be returned big endian.
+ * @count: Number of registersQuoted 8 lines
drivers/mfd/88pm80x-i2c.c line 67
Quoted 5 lines
+ */
drivers/mfd/88pm80x-i2c.c new file +4
-0+int pm80x_bulk_read (struct regmap *map,u32 reg,u8 *buf,int count) +{ +return regmap_raw_read (map, reg, buf, count); +}Unused function? Either export this if you want to provide it as the general API, or drop the function.
Quoted 1 line
It's used by rtc driver.
Then it needs to be exported, so the rtc driver can be a module.
Quoted 8 lines
Quoted 5 lines
I would still argue that the majority of the constants in this file should get moved into the driver .c file that uses them. Putting them into the header is better done only for interfaces between the driver parts, and for constants that are used by multiple drivers.
These registers still in this header file are either used by mfd core driver, regulator/rtc/onkey/codec, or used in platform initial setting.
Exactly. All the values that are only used by the core driver should be part of the core driver (or a local header in the mfd directory if they need to be shared between multiple files). The platform code should not really touch the registers, but only things like the platform_data structure, which indeed belongs into the global header.
Quoted 27 lines
Quoted 19 lines
Quoted 19 lines
include/linux/mfd/88pm80x.h new file +19
-0+struct pm80x_subchip { +struct i2c_client *power_page;/* chip client for power page */ +struct i2c_client *gpadc_page;/* chip client for gpadc page */ +struct regmap *regmap_power; +struct regmap *regmap_gpadc; +unsigned short power_page_addr;/* power page I2C address */ +unsigned short gpadc_page_addr;/* gpadc page I2C address */ +}; + +struct pm80x_chip { +struct pm80x_subchip *subchip; +struct device *dev; +struct i2c_client *client; +struct regmap *regmap; +struct regmap_irq_chip *regmap_irq_chip; +struct regmap_irq_chip_data *irq_data; +unsigned char version; +int id; +int irq;Quoted 8 lines
include/linux/mfd/88pm80x.h line 491
Quoted 4 lines
include/linux/mfd/88pm80x.h new file +4
-0+int irq_mode; +int irq_base; +unsigned int wu_flag; +};One thing I forgot to ask in the previous review although I had already noticed it then: What is the separation of
pm80x_chipandpm80x_subchipused for?
Quoted 5 lines
Pm80x_chipis common for both pm800 and pm805, whilepm80x_subchiphandles the other i2c devices as discussed before, only that these two i2c devices are not as much as pm800 and pm805 i2c device, and they are only for gpadc & power settings purpose. The subchip can be treated as some special feature/function for pm800.
ok
Quoted 19 lines
Quoted 11 lines
Quoted 11 lines
include/linux/mfd/88pm80x.h new file +11
-0+struct pm80x_rtc_pdata { +int vrtc; +int rtc_wakeup; +}; + +struct pm80x_platform_data { +struct pm80x_rtc_pdata *rtc; +unsigned short pm800_addr; +unsigned short pm805_addr; +unsigned short power_page_addr;/* power page I2C address */ +unsigned short gpadc_page_addr;/* gpadc page I2C address */ Quoted 8 lines
include/linux/mfd/88pm80x.h line 507
Quoted 4 lines
include/linux/mfd/88pm80x.h new file +4
-0+int irq_mode;/* Clear interrupt by read/write(0/1) */ +int irq_base;/* IRQ base of chip */ +int batt_det;/* enable/disable */ +};You removed the callback here as I asked you to, which I think is a useful cleanup, but you can actually managed to convinced me that it would be ok to have it, so I don't mind if you want to put it back and use auxdata.
Quoted 2 lines
Actually it's convenient for us to put it back currently, and would use auxdata instead.
ok
Quoted 5 lines
Quoted 3 lines
On the other hand, I think it probably makes sense to drop the
irq_basemember in this struct and rely on irq domains to allocate them dynamically as mentioned before.Do you mean that both
regmap_add_irq_chipandmfd_add_devicesapi pass -1 as theirq_base, so that system can dynamically allocate theirq_basefor it?
regmap_add_irq_chip should pass -1, mfd_add_devices should pass 0. Mark can probably correct me if that's wrong.
Quoted 3 lines
Given the proper
regmap_irq_chip& device resource, is there anything else needed? As I don't want to miss the exact meaning of " transform the interrupt numbers using the domain in the client drivers" you mentioned above.
The drivers using the numbers need to call regmap_irq_get_virq() to get the real interrupt number. See include/linux/mfd/wm8994/core.h for an example.
Arnd
PATCH 1/4 mfd: support 88pm80x in 80x driver
Quoted 11 lines · Arnd Bergmann
Quoted 6 lines · Qiao Zhou
Quoted 3 lines
On the other hand, I think it probably makes sense to drop the
irq_basemember in this struct and rely on irq domains to allocate them dynamically as mentioned before.Do you mean that both
regmap_add_irq_chipandmfd_add_devicesapi pass -1 as theirq_base, so that system can dynamically allocate theirq_basefor it?
regmap_add_irq_chipshould pass -1,mfd_add_devicesshould pass 0. Mark can probably correct me if that's wrong.
That's right.
I do need to grovel through the irqdomain code and try to figure out if
the stuff added recently for MFDs to pass an irqdomain about would also
support doing the same mapping. Unfortunately all the irqdomain code I
found that I didn't write was rather tied to DT which makes things more
obscure, it's not clear what's for irqdomain and what's for DT.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120704/4ac97695/attachment.sig>
PATCH v2 1/4 mfd: support 88pm80x in 80x driver
Quoted 7 lines · Arnd Bergmann
Quoted 5 lines · Qiao Zhou
Quoted 4 lines
Quoted 4 lines
On the other hand, I think it probably makes sense to drop the
irq_basemember in this struct and rely on irq domains to allocate them dynamically as mentioned before.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Do you mean that both
regmap_add_irq_chipandmfd_add_devicesapi
pass -1 as theirq_base, so that system can dynamically allocate theirq_basefor it?
regmap_add_irq_chipshould pass -1,mfd_add_devicesshould pass 0. Mark can probably correct me if that's wrong.That's right.
Mark, thanks for the confirmation.
Best Regards
Qiao
PATCH v2 1/4 mfd: support 88pm80x in 80x driver
In reply to Arnd BergmannQuoted 18 lines · Qiao Zhou
Quoted 17 lines
Quoted 17 lines
drivers/mfd/88pm800-core.c line 371
Quoted 3 lines
drivers/mfd/88pm800-core.c new file +3
-0+ ret =mfd_add_devices (chip->dev,0 , &onkey_devs[0 ], +ARRAY_SIZE (onkey_devs), &onkey_resources[0 ], + chip->irq_base);According to what I discussed with Mark in the previous version, I think you need to pass 0 instead of
chip->irq_basehere, and transform the interrupt numbers using the domain in the client drivers.drivers/mfd/88pm80x-i2c.c line 34
Quoted 6 lines
drivers/mfd/88pm80x-i2c.c new file +6
-0+ +const struct i2c_device_id pm80x_id_table[] = { + {"88PM800" ,CHIP_PM800 }, + {"88PM805" ,CHIP_PM805 }, +}; +MODULE_DEVICE_TABLE (i2c, pm80x_id_table);Since these are separate modules now, you have to move the device table into the split files as well.
Quoted 8 lines
Quoted 1 line
Is it ok to export it in
88pm80x.h?You mean putting the
MODULE_DEVICE_TABLE()into88pm80x.h? No, that would not work.The correct way is to have two
MODULE_DEVICE_TABLEstatements, one per file. Actually the table only makes sense for loadable modules, so if you decide to keep the driver only built-in, it's best to just drop this table.
Understood and would update.
Quoted 33 lines
Quoted 33 lines
Quoted 32 lines
Quoted 10 lines
drivers/mfd/88pm80x-i2c.c new file +10
-0+ +/** +* pm80x_reg_read: Read a single 88PM80x register. +* +* @map: regmap to read from. +* @reg: Register to read. +*/ +int pm80x_reg_read (struct regmap *map,u32 reg) +{ +unsigned int val;drivers/mfd/88pm80x-i2c.c line 54
Quoted 10 lines
drivers/mfd/88pm80x-i2c.c new file +10
-0+int ret; + + ret =regmap_read (map, reg, &val); + +if (ret <0 ) +return ret; +else +return val; +} +EXPORT_SYMBOL_GPL (pm80x_reg_read);In your introductory email you write
"Exported r/w API which requires regmap handle. as currently the pm800 chip has 3 i2c device, only passing a
pm80x_chipinfo can't ensure r/w the register in correct i2c device."Your first driver version had this, then you removed the functions after I asked you to, and now they are back, so I assume there is something I don't see yet. It looks like the function is just an unnecessary wrapper that is better open-coded in the caller. Can you explain again what the difference is?
Quoted 8 lines
Quoted 5 lines
After you suggest to change the r/w API so that caller doesn't care about it's via i2c or spi, it makes sense. However due to pm800 has 3 i2c devices, and it's hard to export such interface for pm800. Currently to add such interface via regmap handle, caller still doesn't care about the actual hw implement, also it's clear that all pm80x sub-driver or plat call the unified r/w API.
But there is nothing unified about the function above, it just calls
regmap_read(), so the caller already has access to the regmap pointer.
would just use open-coded regmap api.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
drivers/mfd/88pm80x-i2c.c line 67
Quoted 12 lines
drivers/mfd/88pm80x-i2c.c new file +12
-0+/** +* pm80x_bulk_read: Read multiple 88PM80x registers +* +* @map: regmap to read from +* @reg: First register +* @buf: Buffer to fill. The data will be returned big endian. +* @count: Number of registers +*/ +int pm80x_bulk_read (struct regmap *map,u32 reg,u8 *buf,int count) +{ +return regmap_raw_read (map, reg, buf, count); +}Unused function? Either export this if you want to provide it as the general API, or drop the function.
Quoted 3 lines
Quoted 1 line
It's used by rtc driver.
Then it needs to be exported, so the rtc driver can be a module.
Would update.
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
On the other hand, I think it probably makes sense to drop the
irq_basemember in this struct and rely on irq domains to allocate them dynamically as mentioned before.Do you mean that both
regmap_add_irq_chipandmfd_add_devicesapi pass -1 as theirq_base, so that system can dynamically allocate theirq_basefor it?
regmap_add_irq_chipshould pass -1,mfd_add_devicesshould pass 0. Mark can probably correct me if that's wrong.
Quoted 6 lines
Quoted 3 lines
Given the proper
regmap_irq_chip& device resource, is there anything else needed? As I don't want to miss the exact meaning of " transform the interrupt numbers using the domain in the client drivers" you mentioned above.The drivers using the numbers need to call
regmap_irq_get_virq()to get the real interrupt number. Seeinclude/linux/mfd/wm8994/core.hfor an example.
OK, understood. Will check the reference and update accordingly.
Quoted 1 line
Arnd
Arnd, thanks for the review.
Best Regards
Qiao
PATCH v2 2/4 mfd: workaround: add companion chip in 88pm80x
In reply to Qiao Zhouin hw design, 800 is mainly for pmic control, while 805 for audio. but there are 3 registers which controls class D speaker property, and they are defined in 800 i2c client domain. so 805 codec driver needs to use 800 i2c client to access class D speaker reg for audio path management. so add this workaround for the purpose to let 805 access 800 i2c in some scenario.
--- drivers/mfd/88pm80x-i2c.c | 28 ++++++++++++++++++++++++++++ include/linux/mfd/88pm80x.h | 1 + 2 files changed, 29 insertions(+), 0 deletions(-)
drivers/mfd/88pm80x-i2c.c +28 -0
@@ -21,6 +21,12 @@#include <linux/uaccess.h> #include <linux/err.h> +/* +* workaround: some registers needed by pm805 are defined in pm800, so +* need to use this global variable to maintain the relation between +* pm800 and pm805. would remove it after HW chip fixes the issue. +*/ +static struct pm80x_chip *g_pm80x_chip;const struct regmap_config pm80x_regmap_config = { .reg_bits =8 ,
@@ -151,6 +157,19 @@ int __devinit pm80x_init(struct i2c_client *client,device_init_wakeup (&client->dev,1 ); +/* +* workaround: set g_pm80x_chip to the first probed chip. if the +* second chip is probed, just point to the companion to each +* other so that pm805 can access those specific register. would +* remove it after HW chip fixes the issue. +*/ +if (!g_pm80x_chip) + g_pm80x_chip = chip; +else { + chip->companion = g_pm80x_chip->client; + g_pm80x_chip->companion = chip->client; + } +return 0 ; err_chip_id:
@@ -164,6 +183,15 @@ int __devexit pm80x_deinit(struct i2c_client *client) {struct pm80x_chip *chip =i2c_get_clientdata (client); +/* +* workaround: clear the dependency between pm800 and pm805. +* would remove it after HW chip fixes the issue. +*/ +if (g_pm80x_chip->companion) + g_pm80x_chip->companion =NULL ; +else + g_pm80x_chip =NULL ; +regmap_exit (chip->regmap);devm_kfree (&client->dev, chip);
include/linux/mfd/88pm80x.h +1 -0
@@ -479,6 +479,7 @@ struct pm80x_chip {struct pm80x_subchip *subchip;struct device *dev;struct i2c_client *client; +struct i2c_client *companion;struct regmap *regmap;struct regmap_irq_chip *regmap_irq_chip;struct regmap_irq_chip_data *irq_data;
Signature · 1 line
1.7.0.4
PATCH v2 3/4 rtc: add rtc support to 88PM80X PMIC
In reply to Qiao Zhouadd rtc driver for MARVELL 88PM80X PMIC and enable rtc function.
--- drivers/rtc/Kconfig | 10 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-88pm80x.c | 366 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 377 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/rtc-88pm80x.c
drivers/rtc/Kconfig +10 -0
@@ -135,6 +135,16 @@ config RTC_DRV_88PM860X This driver can also be built as a module. If so, the module will be called rtc-88pm860x. +config RTC_DRV_88PM80X + tristate "Marvell 88PM80x" + depends on RTC_CLASS && I2C && MFD_88PM80X + help + If you say yes here you get support for RTC function in Marvell + 88PM80x chips. + + This driver can also be built as a module. If so, the module + will be called rtc-88pm80x. + config RTC_DRV_DS1307 tristate "Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSON RX-8025" help
drivers/rtc/Makefile +1 -0
@@ -16,6 +16,7 @@ rtc-core-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o # Keep the list ordered. obj-$(CONFIG_RTC_DRV_88PM860X) += rtc-88pm860x.o +obj-$(CONFIG_RTC_DRV_88PM80X) += rtc-88pm80x.o obj-$(CONFIG_RTC_DRV_AB3100) += rtc-ab3100.o obj-$(CONFIG_RTC_DRV_AB8500) += rtc-ab8500.o obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o
drivers/rtc/rtc-88pm80x.c new file +366 -0
366 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v2 4/4 input: add onkey support to 88PM80X PMIC
In reply to Qiao Zhouadd onkey support to MARVELL 88PM80X PMIC.
--- drivers/input/misc/88pm80x_onkey.c | 190 ++++++++++++++++++++++++++++++++++++ drivers/input/misc/Kconfig | 10 ++ drivers/input/misc/Makefile | 1 + 3 files changed, 201 insertions(+), 0 deletions(-) create mode 100644 drivers/input/misc/88pm80x_onkey.c
drivers/input/misc/88pm80x_onkey.c new file +190 -0
@@ -0,0 +1,190 @@ +/* +* 88pm80x_onkey.c - Marvell 88PM80x ONKEY driver +* +* Copyright (C) 2012 Marvell International Ltd. +* Haojian Zhuang <[email protected]> +* Qiao Zhou <[email protected]> +* +* This file is subject to the terms and conditions of the GNU General +* Public License. See the file "COPYING" in the main directory of this +* archive for more details. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/mfd/88pm80x.h> +#include <linux/regmap.h> +#include <linux/slab.h> + +#define PM800_LONG_ONKEY_EN (1 << 0) +#define PM800_LONG_KEY_DELAY (8)/* 1 .. 16 seconds */ +#define PM800_LONKEY_PRESS_TIME ((PM800_LONG_KEY_DELAY-1) << 4) +#define PM800_LONKEY_PRESS_TIME_MASK (0xF0) +#define PM800_SW_PDOWN (1 << 5) + +struct pm80x_onkey_info { +struct input_dev *idev; +struct pm80x_chip *pm80x; +struct regmap *map; +int irq; +}; + +/* 88PM80x gives us an interrupt when ONKEY is held */ +static irqreturn_t pm80x_onkey_handler (int irq,void *data) +{ +struct pm80x_onkey_info *info = data; +int ret =0 ; + + ret =pm80x_reg_read (info->map,PM800_STATUS_1 ); + ret &=PM800_ONKEY_STS1 ; + +input_report_key (info->idev,KEY_POWER , ret); +input_sync (info->idev); + +return IRQ_HANDLED ; +} + +#ifdef CONFIG_PM +static int pm80x_onkey_suspend (struct device *dev) +{ +struct platform_device *pdev =to_platform_device (dev); +struct pm80x_chip *chip =dev_get_drvdata (pdev->dev.parent); + +if (device_may_wakeup (dev)) + chip->wu_flag |= (1 <<PM800_IRQ_ONKEY ); + +return 0 ; +} + +static int pm80x_onkey_resume (struct device *dev) +{ +struct platform_device *pdev =to_platform_device (dev); +struct pm80x_chip *chip =dev_get_drvdata (pdev->dev.parent); + +if (device_may_wakeup (dev)) + chip->wu_flag &= ~(1 <<PM800_IRQ_ONKEY ); + +return 0 ; +} +#endif + +static SIMPLE_DEV_PM_OPS(pm80x_onkey_pm_ops, pm80x_onkey_suspend, + pm80x_onkey_resume); + +static int __devinit pm80x_onkey_probe (struct platform_device *pdev) +{ + +void *chip =dev_get_drvdata (pdev->dev.parent); +struct pm80x_onkey_info *info; +int ret; + + info = +devm_kzalloc (&pdev->dev,sizeof (struct pm80x_onkey_info ), +GFP_KERNEL ); +if (!info) +return -ENOMEM ; + + info->pm80x = (struct pm80x_chip *)chip; + + info->irq =platform_get_irq (pdev,0 ); +if (info->irq <0 ) { +dev_err (&pdev->dev,"No IRQ resource!\n" ); +return -EINVAL ; + } + + info->map = info->pm80x->regmap; +if (!info->map) { +dev_err (&pdev->dev,"no regmap!\n" ); + ret = -EINVAL ; + goto out; + } + + info->idev =input_allocate_device (); +if (!info->idev) { +dev_err (&pdev->dev,"Failed to allocate input dev\n" ); + ret = -ENOMEM ; + goto out; + } + + info->idev->name ="88pm80x_on" ; + info->idev->phys ="88pm80x_on/input0" ; + info->idev->id.bustype =BUS_I2C ; + info->idev->dev.parent = &pdev->dev; + info->idev->evbit[0 ] =BIT_MASK (EV_KEY ); + info->idev->keybit[BIT_WORD (KEY_POWER )] =BIT_MASK (KEY_POWER ); + + ret =input_register_device (info->idev); +if (ret) { +dev_err (&pdev->dev,"Can't register input device: %d\n" , ret); + goto out_reg; + } + + ret =request_threaded_irq (info->irq,NULL , pm80x_onkey_handler, +IRQF_ONESHOT ,"onkey" , info); +if (ret <0 ) { +dev_err (&pdev->dev,"Failed to request IRQ: #%d: %d\n" , + info->irq, ret); + goto out_irq; + } + +platform_set_drvdata (pdev, info); + +/* Enable long onkey detection */ +pm80x_set_bits (info->map,PM800_RTC_MISC4 ,PM800_LONG_ONKEY_EN , +PM800_LONG_ONKEY_EN ); +/* Set 8-second interval */ +pm80x_set_bits (info->map,PM800_RTC_MISC3 , +PM800_LONKEY_PRESS_TIME_MASK , +PM800_LONKEY_PRESS_TIME ); + +device_init_wakeup (&pdev->dev,1 ); +return 0 ; + +out_irq: +input_unregister_device (info->idev); +out_reg: +input_free_device (info->idev); +out: +devm_kfree (&pdev->dev, info); +return ret; +} + +static int __devexit pm80x_onkey_remove(struct platform_device *pdev) +{ +struct pm80x_onkey_info *info =platform_get_drvdata (pdev); + +free_irq (info->irq, info); +input_unregister_device (info->idev); +input_free_device (info->idev); +devm_kfree (&pdev->dev, info); +return 0 ; +} + +static struct platform_driver pm80x_onkey_driver = { + .driver = { + .name ="88pm80x-onkey" , + .owner =THIS_MODULE , + .pm = &pm80x_onkey_pm_ops, + }, + .probe = pm80x_onkey_probe, + .remove =__devexit_p (pm80x_onkey_remove), +}; + +module_platform_driver (pm80x_onkey_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("Marvell 88PM80x ONKEY driver" ); +MODULE_AUTHOR ("Qiao Zhou <[email protected]>" ); +MODULE_ALIAS ("platform:88pm80x-onkey" );
drivers/input/misc/Kconfig +10 -0
@@ -22,6 +22,16 @@ config INPUT_88PM860X_ONKEY To compile this driver as a module, choose M here: the module will be called 88pm860x_onkey. +config INPUT_88PM80X_ONKEY + tristate "88PM80x ONKEY support" + depends on MFD_88PM80X + help + Support the ONKEY of Marvell 88PM80x PMICs as an input device + reporting power button status. + + To compile this driver as a module, choose M here: the module + will be called 88pm80x_onkey. + config INPUT_AB8500_PONKEY tristate "AB8500 Pon (PowerOn) Key" depends on AB8500_CORE
drivers/input/misc/Makefile +1 -0
@@ -5,6 +5,7 @@ # Each configuration option enables a list of files. obj-$(CONFIG_INPUT_88PM860X_ONKEY) += 88pm860x_onkey.o +obj-$(CONFIG_INPUT_88PM80X_ONKEY) += 88pm80x_onkey.o obj-$(CONFIG_INPUT_AB8500_PONKEY) += ab8500-ponkey.o obj-$(CONFIG_INPUT_AD714X) += ad714x.o obj-$(CONFIG_INPUT_AD714X_I2C) += ad714x-i2c.o
Signature · 1 line
1.7.0.4