add 88pm80x mfd driver
Subsystems (4)
v5 cover add 88pm80x mfd driver
change log [v5->v4]:
1, change the file name, from 88pm800-core.c, 88pm805-core.c, 88pm80x-i2c.c to 88pm800.c, 88pm805.c, 88pm80x.c, and modified Makefile accordingly. 2, replace the spinlock used to protect wakeup flag, with using set_bit/ clear_bit, which is suitable adn enough in SMP env.
3, add the version number in each patch.
change log [v4->v3]:
1, provide unified suspend/resume api for all sub-devices, and add protection for 800 & 805 wakeup flag in SMP case.
2, clean register definition in 88pm80x.h, and thanks Arnd's help. 3, some minor changes in mfd Kconfig/Makefile.
change log [v3->v2]:
1, dynamically get the irq_base, for both regmap_add_irq_chip and mfd_add_devices. add pm80x_request_irq & pm80x_free_irq for sub-driver facility, and modify related irq thread operation. remove irq_base member from 80x_chip & platform data.
2, split 88pm80x.o into 3 separate modules.
3, remove the 88pm80x r/w API, and directly use open-coded regmap api. 4, minor change: move pm80x_id_table from 80x-i2c.c to 800/805-core.c, exported pm80x_init, pm80x_deinit, and pm80x_bulk_read, add callback in pdata.
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 | 176 +++++++++++ drivers/input/misc/Kconfig | 10 + drivers/input/misc/Makefile | 1 + drivers/mfd/88pm800.c | 593 ++++++++++++++++++++++++++++++++++++ drivers/mfd/88pm805.c | 299 ++++++++++++++++++ drivers/mfd/88pm80x.c | 144 +++++++++ drivers/mfd/Kconfig | 24 ++ drivers/mfd/Makefile | 2 + drivers/rtc/Kconfig | 10 + drivers/rtc/Makefile | 1 + drivers/rtc/rtc-88pm80x.c | 371 ++++++++++++++++++++++ include/linux/mfd/88pm80x.h | 369 ++++++++++++++++++++++ 12 files changed, 2000 insertions(+), 0 deletions(-) create mode 100644 drivers/input/misc/88pm80x_onkey.c create mode 100644 drivers/mfd/88pm800.c create mode 100644 drivers/mfd/88pm805.c create mode 100644 drivers/mfd/88pm80x.c create mode 100644 drivers/rtc/rtc-88pm80x.c create mode 100644 include/linux/mfd/88pm80x.h
PATCH v5 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.c provides common i2c driver handling for both 800 and 805, such as i2c_driver init, regmap init, read/write api etc.
88pm800.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.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, and 88pm80x-i2c exported a group of r/w bulk r/w and bits set API for facility.
--- drivers/mfd/88pm800.c | 593 +++++++++++++++++++++++++++++++++++++++++++ drivers/mfd/88pm805.c | 299 ++++++++++++++++++++++ drivers/mfd/88pm80x.c | 116 +++++++++ drivers/mfd/Kconfig | 24 ++ drivers/mfd/Makefile | 2 + include/linux/mfd/88pm80x.h | 368 +++++++++++++++++++++++++++ 6 files changed, 1402 insertions(+), 0 deletions(-) create mode 100644 drivers/mfd/88pm800.c create mode 100644 drivers/mfd/88pm805.c create mode 100644 drivers/mfd/88pm80x.c create mode 100644 include/linux/mfd/88pm80x.h
drivers/mfd/88pm800.c new file +593 -0
@@ -0,0 +1,593 @@ +/* +* 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/mfd/core.h> +#include <linux/mfd/88pm80x.h> +#include <linux/slab.h> + +#define PM800_CHIP_ID (0x00) + +/* Interrupt Registers */ +#define PM800_INT_STATUS1 (0x05) +#define PM800_ONKEY_INT_STS1 (1 << 0) +#define PM800_EXTON_INT_STS1 (1 << 1) +#define PM800_CHG_INT_STS1 (1 << 2) +#define PM800_BAT_INT_STS1 (1 << 3) +#define PM800_RTC_INT_STS1 (1 << 4) +#define PM800_CLASSD_OC_INT_STS1 (1 << 5) + +#define PM800_INT_STATUS2 (0x06) +#define PM800_VBAT_INT_STS2 (1 << 0) +#define PM800_VSYS_INT_STS2 (1 << 1) +#define PM800_VCHG_INT_STS2 (1 << 2) +#define PM800_TINT_INT_STS2 (1 << 3) +#define PM800_GPADC0_INT_STS2 (1 << 4) +#define PM800_TBAT_INT_STS2 (1 << 5) +#define PM800_GPADC2_INT_STS2 (1 << 6) +#define PM800_GPADC3_INT_STS2 (1 << 7) + +#define PM800_INT_STATUS3 (0x07) + +#define PM800_INT_STATUS4 (0x08) +#define PM800_GPIO0_INT_STS4 (1 << 0) +#define PM800_GPIO1_INT_STS4 (1 << 1) +#define PM800_GPIO2_INT_STS4 (1 << 2) +#define PM800_GPIO3_INT_STS4 (1 << 3) +#define PM800_GPIO4_INT_STS4 (1 << 4) + +#define PM800_INT_ENA_1 (0x09) +#define PM800_ONKEY_INT_ENA1 (1 << 0) +#define PM800_EXTON_INT_ENA1 (1 << 1) +#define PM800_CHG_INT_ENA1 (1 << 2) +#define PM800_BAT_INT_ENA1 (1 << 3) +#define PM800_RTC_INT_ENA1 (1 << 4) +#define PM800_CLASSD_OC_INT_ENA1 (1 << 5) + +#define PM800_INT_ENA_2 (0x0A) +#define PM800_VBAT_INT_ENA2 (1 << 0) +#define PM800_VSYS_INT_ENA2 (1 << 1) +#define PM800_VCHG_INT_ENA2 (1 << 2) +#define PM800_TINT_INT_ENA2 (1 << 3) + +#define PM800_INT_ENA_3 (0x0B) +#define PM800_GPADC0_INT_ENA3 (1 << 0) +#define PM800_GPADC1_INT_ENA3 (1 << 1) +#define PM800_GPADC2_INT_ENA3 (1 << 2) +#define PM800_GPADC3_INT_ENA3 (1 << 3) +#define PM800_GPADC4_INT_ENA3 (1 << 4) + +#define PM800_INT_ENA_4 (0x0C) +#define PM800_GPIO0_INT_ENA4 (1 << 0) +#define PM800_GPIO1_INT_ENA4 (1 << 1) +#define PM800_GPIO2_INT_ENA4 (1 << 2) +#define PM800_GPIO3_INT_ENA4 (1 << 3) +#define PM800_GPIO4_INT_ENA4 (1 << 4) + +/* number of INT_ENA & INT_STATUS regs */ +#define PM800_INT_REG_NUM (4) + +/* Interrupt Number in 88PM800 */ +enum { +PM800_IRQ_ONKEY ,/*EN1b0 *//*0 */ +PM800_IRQ_EXTON ,/*EN1b1 */ +PM800_IRQ_CHG ,/*EN1b2 */ +PM800_IRQ_BAT ,/*EN1b3 */ +PM800_IRQ_RTC ,/*EN1b4 */ +PM800_IRQ_CLASSD ,/*EN1b5 *//*5 */ +PM800_IRQ_VBAT ,/*EN2b0 */ +PM800_IRQ_VSYS ,/*EN2b1 */ +PM800_IRQ_VCHG ,/*EN2b2 */ +PM800_IRQ_TINT ,/*EN2b3 */ +PM800_IRQ_GPADC0 ,/*EN3b0 *//*10 */ +PM800_IRQ_GPADC1 ,/*EN3b1 */ +PM800_IRQ_GPADC2 ,/*EN3b2 */ +PM800_IRQ_GPADC3 ,/*EN3b3 */ +PM800_IRQ_GPADC4 ,/*EN3b4 */ +PM800_IRQ_GPIO0 ,/*EN4b0 *//*15 */ +PM800_IRQ_GPIO1 ,/*EN4b1 */ +PM800_IRQ_GPIO2 ,/*EN4b2 */ +PM800_IRQ_GPIO3 ,/*EN4b3 */ +PM800_IRQ_GPIO4 ,/*EN4b4 *//*19 */ +PM800_MAX_IRQ , +}; + +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 +}; + +static const struct i2c_device_id pm80x_id_table[] = { + {"88PM800" ,CHIP_PM800 }, +}; +MODULE_DEVICE_TABLE (i2c, pm80x_id_table); + +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 =regmap_update_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 =regmap_update_bits (map,PM800_GPADC_MEAS_EN1 , +PM800_MEAS_EN1_VBAT ,PM800_MEAS_EN1_VBAT ); +if (ret <0 ) + goto out; + ret =regmap_update_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 =regmap_update_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 =regmap_update_bits (map,PM800_WAKEUP2 , mask, data); + +if (ret <0 ) + goto out; + + ret = +regmap_add_irq_chip (chip->regmap, chip->irq, flags,-1 , + 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; + +regmap_read (chip->regmap,PM800_CHIP_ID , &ret); +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 +*/ +regmap_read (chip->regmap,PM800_RTC_CONTROL , &ret); +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 ],0 ); +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 ,0 ); +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; + } + +if (pdata->plat_config) + pdata->plat_config (chip, pdata); + +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.c new file +299 -0
299 lines not on this page · raw message
drivers/mfd/88pm80x.c new file +116 -0
116 lines not on this page · raw message
drivers/mfd/Kconfig +24 -0
@@ -20,6 +20,30 @@ config MFD_88PM860X select individual components like voltage regulators, RTC and battery-charger under the corresponding menus. +config MFD_88PM800 + tristate "Support Marvell 88PM800" + depends on I2C=y && GENERIC_HARDIRQS + select REGMAP_I2C + select REGMAP_IRQ + select MFD_CORE + help + This supports for Marvell 88PM800 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_88PM805 + tristate "Support Marvell 88PM805" + depends on I2C=y && GENERIC_HARDIRQS + select REGMAP_I2C + select REGMAP_IRQ + select MFD_CORE + help + This supports for Marvell 88PM805 Power Management IC. This includes + the I2C driver and the core APIs _only_, you have to select individual + components like codec device, headset/Mic device under the + corresponding menus. + config MFD_SM501 tristate "Support for Silicon Motion SM501" ---help---
drivers/mfd/Makefile +2 -0
@@ -4,6 +4,8 @@ 88pm860x-objs := 88pm860x-core.o 88pm860x-i2c.o obj-$(CONFIG_MFD_88PM860X) += 88pm860x.o +obj-$(CONFIG_MFD_88PM800) += 88pm800.o 88pm80x.o +obj-$(CONFIG_MFD_88PM805) += 88pm805.o 88pm80x.o obj-$(CONFIG_MFD_SM501) += sm501.o obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o
include/linux/mfd/88pm80x.h new file +368 -0
368 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v5 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.c | 28 ++++++++++++++++++++++++++++ include/linux/mfd/88pm80x.h | 1 + 2 files changed, 29 insertions(+), 0 deletions(-)
drivers/mfd/88pm80x.c +28 -0
@@ -18,6 +18,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 ,
@@ -61,6 +67,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:
@@ -75,6 +94,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
@@ -295,6 +295,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 v5 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 | 371 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 382 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_88PM800 + 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 +371 -0
371 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v5 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 | 176 ++++++++++++++++++++++++++++++++++++ drivers/input/misc/Kconfig | 10 ++ drivers/input/misc/Makefile | 1 + 3 files changed, 187 insertions(+), 0 deletions(-) create mode 100644 drivers/input/misc/88pm80x_onkey.c
drivers/input/misc/88pm80x_onkey.c new file +176 -0
@@ -0,0 +1,176 @@ +/* +* 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/input.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 ; + +regmap_read (info->map,PM800_STATUS_1 , &ret); + 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) +{ +return pm80x_dev_suspend (dev); +} + +static int pm80x_onkey_resume (struct device *dev) +{ +return pm80x_dev_resume (dev); +} +#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 =pm80x_request_irq (info->pm80x, info->irq, 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 */ +regmap_update_bits (info->map,PM800_RTC_MISC4 ,PM800_LONG_ONKEY_EN , +PM800_LONG_ONKEY_EN ); +/* Set 8-second interval */ +regmap_update_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); + +pm80x_free_irq (info->pm80x, 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_88PM800 + 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
v5 cover add 88pm80x mfd driver
In reply to Qiao ZhouHi Zhou,
Quoted 6 lines · Qiao Zhou
change log [
v5->v4]:
1, change the file name, from88pm800-core.c,88pm805-core.c,88pm80x-i2c.cto88pm800.c,88pm805.c,88pm80x.c, and modifiedMakefileaccordingly. 2, replace the spinlock used to protect wakeup flag, with using set_bit/clear_bit, which is suitable adn enough in SMP env.
3, add the version number in each patch.
I applied the first 2 patches, I'd like to get an ACK from the respective maintainers for the rtc and the input ones. They can even take it as both drivers are protected by the MFD symbol.
Cheers,
Samuel.
Signature · 2 lines
Intel Open Source Technology Centre http://oss.intel.com/
v5 cover add 88pm80x mfd driver
Quoted 3 lines · Samuel Ortiz
I applied the first 2 patches, I'd like to get an ACK from the respective maintainers for the rtc and the input ones. They can even take it as both drivers are protected by the MFD symbol.
Alessandro's been mostly offline recently so it might be as well to
apply the RTC patch anyway.
-------------- 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/20120709/50663325/attachment.sig>
v5 cover add 88pm80x mfd driver
Hi Mark,
Quoted 8 lines · Mark Brown
Quoted 3 lines · Samuel Ortiz
I applied the first 2 patches, I'd like to get an ACK from the respective maintainers for the rtc and the input ones. They can even take it as both drivers are protected by the MFD symbol.
Alessandro's been mostly offline recently so it might be as well to apply the RTC patch anyway.
Fair enough, applied now. Neither Alessandro nor the rtc ml wer not cc'ed on this thread, but that's another problem.
Zhou, could you please send at least the rtc patch to Alessandro so that he could have a look at it if time permits ?
Cheers,
Samuel.
Signature · 2 lines
Intel Open Source Technology Centre http://oss.intel.com/
v5 cover add 88pm80x mfd driver
Quoted 11 lines · Samuel Ortiz
Hi Mark,
Quoted 8 lines · Mark Brown
Quoted 3 lines · Samuel Ortiz
I applied the first 2 patches, I'd like to get an ACK from the respective maintainers for the rtc and the input ones. They can even take it as both drivers are protected by the MFD symbol.
Alessandro's been mostly offline recently so it might be as well to apply the RTC patch anyway.
Quoted 8 lines
Fair enough, applied now. Neither Alessandro nor the rtc ml wer not cc'ed on this thread, but that's another problem.
Zhou, could you please send at least the rtc patch to Alessandro so that he could have a look at it if time permits ?Cheers,
Samuel.
Samuel, Mark, Arnd,
deeply appreciate your review, and I'll send the patch to Alessandro and rtc mainline. thanks!
Signature · 2 lines
Best Regards Qiao
v5 cover add 88pm80x mfd driver
In reply to Samuel OrtizQuoted 11 lines · Samuel Ortiz
Quoted 6 lines · Qiao Zhou
change log [
v5->v4]:
1, change the file name, from88pm800-core.c,88pm805-core.c,88pm80x-i2c.cto88pm800.c,88pm805.c,88pm80x.c, and modifiedMakefileaccordingly. 2, replace the spinlock used to protect wakeup flag, with using set_bit/clear_bit, which is suitable adn enough in SMP env.
3, add the version number in each patch.I applied the first 2 patches, I'd like to get an ACK from the respective maintainers for the rtc and the input ones. They can even take it as both drivers are protected by the MFD symbol.
Please add my
comment to these two patches as well.
Arnd
v5 cover add 88pm80x mfd driver
Hi Arnd,
Quoted 13 lines · Arnd Bergmann
Quoted 11 lines · Samuel Ortiz
Quoted 6 lines · Qiao Zhou
change log [
v5->v4]:
1, change the file name, from88pm800-core.c,88pm805-core.c,88pm80x-i2c.cto88pm800.c,88pm805.c,88pm80x.c, and modifiedMakefileaccordingly. 2, replace the spinlock used to protect wakeup flag, with using set_bit/clear_bit, which is suitable adn enough in SMP env.
3, add the version number in each patch.I applied the first 2 patches, I'd like to get an ACK from the respective maintainers for the rtc and the input ones. They can even take it as both drivers are protected by the MFD symbol.
Quoted 5 lines
Please add my
Reviewed-by Arnd Bergmann <[email protected]>comment to these two patches as well.
Sure. Thanks a lot for your code review.
Cheers,
Samuel.
Signature · 2 lines
Intel Open Source Technology Centre http://oss.intel.com/