--- zzzz-none-000/linux-3.10.107/drivers/mfd/88pm800.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/mfd/88pm800.c 2021-02-04 17:41:59.000000000 +0000 @@ -22,13 +22,12 @@ #include #include +#include #include #include #include #include -#define PM800_CHIP_ID (0x00) - /* Interrupt Registers */ #define PM800_INT_STATUS1 (0x05) #define PM800_ONKEY_INT_STS1 (1 << 0) @@ -113,20 +112,11 @@ 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 -}; +/* PM800: generation identification number */ +#define PM800_CHIP_GEN_ID_NUM 0x3 static const struct i2c_device_id pm80x_id_table[] = { - {"88PM800", CHIP_PM800}, + {"88PM800", 0}, {} /* NULL terminated */ }; MODULE_DEVICE_TABLE(i2c, pm80x_id_table); @@ -158,7 +148,7 @@ }, }; -static struct mfd_cell onkey_devs[] = { +static const struct mfd_cell onkey_devs[] = { { .name = "88pm80x-onkey", .num_resources = 1, @@ -167,6 +157,13 @@ }, }; +static const struct mfd_cell regulator_devs[] = { + { + .name = "88pm80x-regulator", + .id = -1, + }, +}; + static const struct regmap_irq pm800_irqs[] = { /* INT0 */ [PM800_IRQ_ONKEY] = { @@ -315,10 +312,61 @@ return ret; } +static int device_onkey_init(struct pm80x_chip *chip, + struct pm80x_platform_data *pdata) +{ + int ret; + + ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0], + ARRAY_SIZE(onkey_devs), &onkey_resources[0], 0, + NULL); + if (ret) { + dev_err(chip->dev, "Failed to add onkey subdev\n"); + return ret; + } + + return 0; +} + +static int device_rtc_init(struct pm80x_chip *chip, + struct pm80x_platform_data *pdata) +{ + int ret; + + if (pdata) { + rtc_devs[0].platform_data = pdata->rtc; + rtc_devs[0].pdata_size = + pdata->rtc ? sizeof(struct pm80x_rtc_pdata) : 0; + } + ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0], + ARRAY_SIZE(rtc_devs), NULL, 0, NULL); + if (ret) { + dev_err(chip->dev, "Failed to add rtc subdev\n"); + return ret; + } + + return 0; +} + +static int device_regulator_init(struct pm80x_chip *chip, + struct pm80x_platform_data *pdata) +{ + int ret; + + ret = mfd_add_devices(chip->dev, 0, ®ulator_devs[0], + ARRAY_SIZE(regulator_devs), NULL, 0, NULL); + if (ret) { + dev_err(chip->dev, "Failed to add regulator subdev\n"); + return ret; + } + + return 0; +} + static int device_irq_init_800(struct pm80x_chip *chip) { struct regmap *map = chip->regmap; - unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT; + unsigned long flags = IRQF_ONESHOT; int data, mask, ret = -EINVAL; if (!map || !chip->irq) { @@ -362,6 +410,7 @@ .status_base = PM800_INT_STATUS1, .mask_base = PM800_INT_ENA_1, .ack_base = PM800_INT_STATUS1, + .mask_invert = 1, }; static int pm800_pages_init(struct pm80x_chip *chip) @@ -369,77 +418,72 @@ struct pm80x_subchip *subchip; struct i2c_client *client = chip->client; + int ret = 0; + 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"); + if (!subchip || !subchip->power_page_addr || !subchip->gpadc_page_addr) + return -ENODEV; - return 0; + /* PM800 block power page */ + subchip->power_page = i2c_new_dummy(client->adapter, + subchip->power_page_addr); + if (subchip->power_page == NULL) { + ret = -ENODEV; + goto out; + } + + subchip->regmap_power = devm_regmap_init_i2c(subchip->power_page, + &pm80x_regmap_config); + if (IS_ERR(subchip->regmap_power)) { + ret = PTR_ERR(subchip->regmap_power); + dev_err(chip->dev, + "Failed to allocate regmap_power: %d\n", ret); + goto out; + } + + i2c_set_clientdata(subchip->power_page, chip); + + /* PM800 block GPADC */ + subchip->gpadc_page = i2c_new_dummy(client->adapter, + subchip->gpadc_page_addr); + if (subchip->gpadc_page == NULL) { + ret = -ENODEV; + goto out; + } + + subchip->regmap_gpadc = devm_regmap_init_i2c(subchip->gpadc_page, + &pm80x_regmap_config); + if (IS_ERR(subchip->regmap_gpadc)) { + ret = PTR_ERR(subchip->regmap_gpadc); + dev_err(chip->dev, + "Failed to allocate regmap_gpadc: %d\n", ret); + goto out; + } + i2c_set_clientdata(subchip->gpadc_page, chip); + +out: + return ret; } 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); + + if (subchip && subchip->power_page) i2c_unregister_device(subchip->power_page); - } - if (subchip->gpadc_page) { - regmap_exit(subchip->regmap_gpadc); + + if (subchip && subchip->gpadc_page) i2c_unregister_device(subchip->gpadc_page); - } } static int device_800_init(struct pm80x_chip *chip, struct pm80x_platform_data *pdata) { - int ret, pmic_id; + int ret; unsigned int val; - ret = regmap_read(chip->regmap, PM800_CHIP_ID, &val); - if (ret < 0) { - dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret); - goto out; - } - - pmic_id = val & PM80X_VERSION_MASK; - - if ((pmic_id >= PM800_CHIP_A0) && (pmic_id <= PM800_CHIP_END)) { - chip->version = val; - dev_info(chip->dev, - "88PM80x:Marvell 88PM800 (ID:0x%x) detected\n", val); - } else { - dev_err(chip->dev, - "Failed to detect Marvell 88PM800:ChipID[0x%x]\n", val); - ret = -EINVAL; - goto out; - } - /* * alarm wake up bit will be clear in device_irq_init(), * read before that @@ -468,27 +512,22 @@ goto out; } - ret = - mfd_add_devices(chip->dev, 0, &onkey_devs[0], - ARRAY_SIZE(onkey_devs), &onkey_resources[0], 0, - NULL); - if (ret < 0) { + ret = device_onkey_init(chip, pdata); + if (ret) { 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, NULL); - 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__); + ret = device_rtc_init(chip, pdata); + if (ret) { + dev_err(chip->dev, "Failed to add rtc subdev\n"); + goto out; + } + + ret = device_regulator_init(chip, pdata); + if (ret) { + dev_err(chip->dev, "Failed to add regulators subdev\n"); + goto out; } return 0; @@ -504,10 +543,10 @@ { int ret = 0; struct pm80x_chip *chip; - struct pm80x_platform_data *pdata = client->dev.platform_data; + struct pm80x_platform_data *pdata = dev_get_platdata(&client->dev); struct pm80x_subchip *subchip; - ret = pm80x_init(client, id); + ret = pm80x_init(client); if (ret) { dev_err(&client->dev, "pm800_init fail\n"); goto out_init; @@ -524,28 +563,30 @@ goto err_subchip_alloc; } - subchip->power_page_addr = pdata->power_page_addr; - subchip->gpadc_page_addr = pdata->gpadc_page_addr; + /* pm800 has 2 addtional pages to support power and gpadc. */ + subchip->power_page_addr = client->addr + 1; + subchip->gpadc_page_addr = client->addr + 2; chip->subchip = subchip; - ret = device_800_init(chip, pdata); + ret = pm800_pages_init(chip); if (ret) { - dev_err(chip->dev, "%s id 0x%x failed!\n", __func__, chip->id); - goto err_subchip_alloc; + dev_err(&client->dev, "pm800_pages_init failed!\n"); + goto err_device_init; } - ret = pm800_pages_init(chip); + ret = device_800_init(chip, pdata); if (ret) { - dev_err(&client->dev, "pm800_pages_init failed!\n"); - goto err_page_init; + dev_err(chip->dev, "Failed to initialize 88pm800 devices\n"); + goto err_device_init; } - if (pdata->plat_config) + if (pdata && pdata->plat_config) pdata->plat_config(chip, pdata); -err_page_init: - mfd_remove_devices(chip->dev); - device_irq_exit_800(chip); + return 0; + +err_device_init: + pm800_pages_exit(chip); err_subchip_alloc: pm80x_deinit(); out_init: @@ -567,8 +608,7 @@ static struct i2c_driver pm800_driver = { .driver = { - .name = "88PM80X", - .owner = THIS_MODULE, + .name = "88PM800", .pm = &pm80x_pm_ops, }, .probe = pm800_probe,