MFD: DA9052/53 MFD core module v8
Subsystems (4)
PATCH 1/11 MFD: DA9052/53 MFD core module v8
The DA9052/53 is a highly integrated PMIC subsystem with supply domain flexibility to support wide range of high performance application.
It provides voltage regulators, GPIO controller, Touch Screen, RTC, Battery
control and other functionality.
---
Changes since v8:
- Add read/write mask flag for SPI
Changes since v7:
- Replace ADC polling with interrupt mechanism
- Move macros related to battery module IRQs to header file Changes since v6:
- Move inlined device I/O functions to header file Changes since v5:
- Inline device I/O
- Unhandle IRQ return IRQ_NONE
- Remove register address conversion
Changes since v4:
- Modify KConfig
- Use device registration for detemining chip id
- Remove preprocessor directive with runtime bustype variable
- Replace module_init() for spi with subsys_initcall()
- Remove platform string from MODULE_ALIAS of spi module. Changes since v3:
- Code refactored to use REGMAP API.
- Add Battery resources.
- da9052_set_bits() and da9052_clear_bits() replaced by da9052_reg_update().
- Add support for DA9053 PMIC
Changes since v2:
- Drop da9052_irqs[] table.
- Move struct da9052_subdev_info[].
- Remove initialization of static member.
- Care for NULL pdata init().
- Check removal of subdevices on errors.
- Remove open source spi code.
- Remove '_spi' from the driver name.
- Move tbat_lookup table from header file.
- Remove irq.h
- Remove num_gpio variable from pdata
---
drivers/mfd/Kconfig | 26 ++ drivers/mfd/Makefile | 7 + drivers/mfd/da9052-core.c | 371 ++++++++++++++++++ drivers/mfd/da9052-i2c.c | 144 +++++++ drivers/mfd/da9052-irq.c | 175 +++++++++ drivers/mfd/da9052-spi.c | 169 ++++++++ include/linux/mfd/da9052/da9052.h | 154 ++++++++ include/linux/mfd/da9052/pdata.h | 42 ++ include/linux/mfd/da9052/reg.h | 777 +++++++++++++++++++++++++++++++++++++ 9 files changed, 1865 insertions(+), 0 deletions(-)
create mode 100644 drivers/mfd/da9052-core.c create mode 100644 drivers/mfd/da9052-i2c.c create mode 100644 drivers/mfd/da9052-irq.c create mode 100644 drivers/mfd/da9052-spi.c create mode 100644 include/linux/mfd/da9052/da9052.h create mode 100644 include/linux/mfd/da9052/pdata.h create mode 100644 include/linux/mfd/da9052/reg.h
drivers/mfd/Kconfig +26 -0
@@ -328,6 +328,32 @@ config PMIC_DA903X individual components like LCD backlight, voltage regulators, LEDs and battery-charger under the corresponding menus. +config PMIC_DA9052 + bool + select MFD_CORE + +config MFD_DA9052_SPI + bool "Support Dialog Semiconductor DA9052/53 PMIC variants with SPI" + select REGMAP_SPI + select PMIC_DA9052 + depends on SPI_MASTER=y + help + Support for the Dialog Semiconductor DA9052 PMIC + when controlled using SPI. This driver provides common support + for accessing the device, additional drivers must be enabled in + order to use the functionality of the device. + +config MFD_DA9052_I2C + bool "Support Dialog Semiconductor DA9052/53 PMIC variants with I2C" + select REGMAP_I2C + select PMIC_DA9052 + depends on I2C=y + help + Support for the Dialog Semiconductor DA9052 PMIC + when controlled using I2C. This driver provides common support + for accessing the device, additional drivers must be enabled in + order to use the functionality of the device. +
config PMIC_ADP5520
bool "Analog Devices ADP5520/01 MFD PMIC Core Support" depends on I2C=y
drivers/mfd/Makefile +0 -0
@@ -67,6 +67,13 @@ endif
obj-$(CONFIG_UCB1400_CORE) += ucb1400_core.o
obj-$(CONFIG_PMIC_DA903X) += da903x.o
+
+da9052-objs := da9052-core.o da9052-irq.o +obj-$(CONFIG_PMIC_DA9052) += da9052.o
+
+obj-$(CONFIG_MFD_DA9052_SPI) += da9052-spi.o +obj-$(CONFIG_MFD_DA9052_I2C) += da9052-i2c.o +
max8925-objs := max8925-core.o max8925-i2c.o obj-$(CONFIG_MFD_MAX8925) += max8925.o obj-$(CONFIG_MFD_MAX8997) += max8997.o max8997-irq.o
drivers/mfd/da9052-core.c new file +8 -0
@@ -0,0 +1,371 @@ +/* +* Device access for Dialog DA9052 PMICs. +* +* Copyright(c) 2011 Dialog Semiconductor Ltd. +* +* Author: David Dajun Chen <[email protected]> +* +* This program is free software; you can redistribute it and/or
modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/mutex.h>
+#include <linux/mfd/core.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+
+#include <linux/mfd/da9052/da9052.h>
+#include <linux/mfd/da9052/pdata.h>
+#include <linux/mfd/da9052/reg.h>
+
+#define DA9052_IRQ_ALARM 5
+#define DA9052_IRQ_NONKEY 8
+#define DA9052_IRQ_PENDOWN 14
+#define DA9052_IRQ_TSIREADY 15
+
+/*
+ * TBAT look-up table is computed from the R90 reg (8 bit register)
+ * reading as below. The battery temperature is in milliCentigrade
+ * TBAT = (1/(t1+1/298) - 273) * 1000 mC
+ * where t1 = (1/B)* ln(( ADCval * 2.5)/(R25*ITBAT*255))
+ * Default values are R25 = 10e3, B = 3380, ITBAT = 50e-6
+ * Example:
+ * R25=10E3, B=3380, ITBAT=50e-6, ADCVAL=62d calculates
+ * TBAT = 20015 mili degrees Centrigrade
+ *
+*/
+static const int32_t tbat_lookup[255] = {
+ 183258, 144221, 124334, 111336, 101826, 94397, 88343, 83257,
+ 78889, 75071, 71688, 68656, 65914, 63414, 61120, 59001,
+ 570366, 55204, 53490, 51881, 50364, 48931, 47574, 46285,
+ 45059, 43889, 42772, 41703, 40678, 39694, 38748, 37838,
+ 36961, 36115, 35297, 34507, 33743, 33002, 32284, 31588,
+ 30911, 30254, 29615, 28994, 28389, 27799, 27225, 26664,
+ 26117, 25584, 25062, 24553, 24054, 23567, 23091, 22624,
+ 22167, 21719, 21281, 20851, 20429, 20015, 19610, 19211,
+ 18820, 18436, 18058, 17688, 17323, 16965, 16612, 16266,
+ 15925, 15589, 15259, 14933, 14613, 14298, 13987, 13681,
+ 13379, 13082, 12788, 12499, 12214, 11933, 11655, 11382,
+ 11112, 10845, 10582, 10322, 10066, 9812, 9562, 9315,
+ 9071, 8830, 8591, 8356, 8123, 7893, 7665, 7440,
+ 7218, 6998, 6780, 6565, 6352, 6141, 5933, 5726,
+ 5522, 5320, 5120, 4922, 4726, 4532, 4340, 4149,
+ 3961, 3774, 3589, 3406, 3225, 3045, 2867, 2690,
+ 2516, 2342, 2170, 2000, 1831, 1664, 1498, 1334,
+ 1171, 1009, 849, 690, 532, 376, 221, 67,
+ -84, -236, -386, -535, -683, -830, -975, -1119,
+ -1263, -1405, -1546, -1686, -1825, -1964, -2101, -2237,
+ -2372, -2506, -2639, -2771, -2902, -3033, -3162, -3291,
+ -3418, -3545, -3671, -3796, -3920, -4044, -4166, -4288,
+ -4409, -4529, -4649, -4767, -4885, -5002, -5119, -5235,
+ -5349, -5464, -5577, -5690, -5802, -5913, -6024, -6134,
+ -6244, -6352, -6461, -6568, -6675, -6781, -6887, -6992,
+ -7096, -7200, -7303, -7406, -7508, -7609, -7710, -7810,
+ -7910, -8009, -8108, -8206, -8304, -8401, -8497, -8593,
+ -8689, -8784, -8878, -8972, -9066, -9159, -9251, -9343,
+ -9435, -9526, -9617, -9707, -9796, -9886, -9975, -10063,
+ -10151, -10238, -10325, -10412, -10839, -10923, -11007, -11090,
+ -11173, -11256, -11338, -11420, -11501, -11583, -11663, -11744,
+ -11823, -11903, -11982
+};
+
+static const u8 chan_mux[DA9052_ADC_VBBAT + 1] = {
+ [DA9052_ADC_VDDOUT] = DA9052_ADC_MAN_MUXSEL_VDDOUT,
+ [DA9052_ADC_ICH] = DA9052_ADC_MAN_MUXSEL_ICH,
+ [DA9052_ADC_TBAT] = DA9052_ADC_MAN_MUXSEL_TBAT,
+ [DA9052_ADC_VBAT] = DA9052_ADC_MAN_MUXSEL_VBAT,
+ [DA9052_ADC_IN4] = DA9052_ADC_MAN_MUXSEL_AD4,
+ [DA9052_ADC_IN5] = DA9052_ADC_MAN_MUXSEL_AD5,
+ [DA9052_ADC_IN6] = DA9052_ADC_MAN_MUXSEL_AD6,
+ [DA9052_ADC_VBBAT] = DA9052_ADC_MAN_MUXSEL_VBBAT
+};
+
+enum da9052_auxadc {
+ VDDOUT = DA9052_ADC_VDDOUT,
+ ICH = DA9052_ADC_ICH,
+ TBAT = DA9052_ADC_TBAT,
+ VBAT = DA9052_ADC_VBAT,
+ IN4 = DA9052_ADC_IN4,
+ IN5 = DA9052_ADC_IN5,
+ IN6 = DA9052_ADC_IN6,
+ VBBAT = DA9052_ADC_VBBAT,
+};
+
+struct da9052_auxadc_req {
+ struct list_head list;
+ enum da9052_auxadc input;
+ struct completion done;
+};
+
+int da9052_adc_manual_read(struct da9052 *da9052, unsigned char channel)
+{
+ struct da9052_auxadc_req *req;
+ int ret;
+ unsigned short calc_data;
+ unsigned short data;
+ unsigned char mux_sel;
+
+ req = kzalloc(sizeof(*req), GFP_KERNEL);
+ if (!req)
+ return -ENOMEM;
+
+ init_completion(&req->done);
+ req->input = channel;
+
+ if (channel > DA9052_ADC_VBBAT)
+ return -EINVAL;
+
+ mutex_lock(&da9052->auxadc_lock);
+
+ /* Channel gets activated on enabling the Conversion bit */
+ mux_sel = chan_mux[channel] | DA9052_ADC_MAN_MAN_CONV;
+
+ if (da9052->auxadc_active) {
+ ret = -EBUSY;
+ goto err;
+ }
+
+ /* Enqueue the request */
+ list_add(&req->list, &da9052->auxadc_pending);
+
+ ret = da9052_reg_write(da9052, DA9052_ADC_MAN_REG, mux_sel);
+ if (ret < 0)
+ goto err;
+
+ da9052->auxadc_active = channel;
+
+ mutex_unlock(&da9052->auxadc_lock);
+
+ /* Wait for an interrupt */
+ wait_for_completion_timeout(&req->done, msecs_to_jiffies(500)); +
+ mutex_lock(&da9052->auxadc_lock);
+
+ ret = da9052_reg_read(da9052, DA9052_ADC_RES_H_REG);
+ if (ret < 0)
+ return IRQ_NONE;
+
+ calc_data = (unsigned short)ret;
+ data = calc_data << 2;
+
+ ret = da9052_reg_read(da9052, DA9052_ADC_RES_L_REG);
+ if (ret < 0)
+ return IRQ_NONE;
+
+ calc_data = (unsigned short)(ret & DA9052_ADC_RES_LSB);
+ data |= calc_data;
+
+ ret = data;
+
+ list_del(&req->list);
+err:
+ mutex_unlock(&da9052->auxadc_lock);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(da9052_adc_manual_read);
+
+int da9052_adc_temperature_read(struct da9052 *da9052)
+{
+ int tbat;
+
+ tbat = da9052_reg_read(da9052, DA9052_TBAT_RES_REG);
+
+ if (tbat < 0)
+ return tbat;
+
+ if (tbat == 0)
+ tbat = 56;
+
+ /* ARRAY_SIZE check is not needed since TBAT is a 8-bit register */
+ return tbat_lookup[tbat - 1];
+}
+EXPORT_SYMBOL_GPL(da9052_adc_temperature_read);
+
+static struct resource da9052_rtc_resource = {
+ .name = "ALM",
+ .start = DA9052_IRQ_ALARM,
+ .end = DA9052_IRQ_ALARM,
+ .flags = IORESOURCE_IRQ,
+};
+
+static struct resource da9052_onkey_resource = {
+ .name = "ONKEY",
+ .start = DA9052_IRQ_NONKEY,
+ .end = DA9052_IRQ_NONKEY,
+ .flags = IORESOURCE_IRQ,
+};
+
+static struct resource da9052_power_resources[] = {
+ {
+ .name = "BATT TEMP",
+ .start = DA9052_IRQ_TBAT,
+ .end = DA9052_IRQ_TBAT,
+ .flags = IORESOURCE_IRQ,
+ },
+ {
+ .name = "DCIN DET",
+ .start = DA9052_IRQ_DCIN,
+ .end = DA9052_IRQ_DCIN,
+ .flags = IORESOURCE_IRQ,
+ },
+ {
+ .name = "DCIN REM",
+ .start = DA9052_IRQ_DCINREM,
+ .end = DA9052_IRQ_DCINREM,
+ .flags = IORESOURCE_IRQ,
+ },
+ {
+ .name = "VBUS DET",
+ .start = DA9052_IRQ_VBUS,
+ .end = DA9052_IRQ_VBUS,
+ .flags = IORESOURCE_IRQ,
+ },
+ {
+ .name = "VBUS REM",
+ .start = DA9052_IRQ_VBUSREM,
+ .end = DA9052_IRQ_VBUSREM,
+ .flags = IORESOURCE_IRQ,
+ },
+ {
+ .name = "CHG END",
+ .start = DA9052_IRQ_CHGEND,
+ .end = DA9052_IRQ_CHGEND,
+ .flags = IORESOURCE_IRQ,
+ },
+};
+
+static struct resource da9052_tsi_resources[] = {
+ {
+ .name = "PENDWN",
+ .start = DA9052_IRQ_PENDOWN,
+ .end = DA9052_IRQ_PENDOWN,
+ .flags = IORESOURCE_IRQ,
+ },
+ {
+ .name = "TSIRDY",
+ .start = DA9052_IRQ_TSIREADY,
+ .end = DA9052_IRQ_TSIREADY,
+ .flags = IORESOURCE_IRQ,
+ },
+};
+
+int da9052_add_regulator_devices(struct da9052 *da9052,
+ struct da9052_pdata *pdata)
+{
+ struct platform_device *pdev;
+ int i, ret;
+
+ for (i = 0; i < pdata->num_regulators; i++) {
+ pdev = platform_device_alloc("da9052-regulator", i);
+ if (!pdev)
+ return -ENOMEM;
+
+ pdev->dev.parent = da9052->dev;
+ ret = platform_device_add(pdev);
+ if (ret) {
+ platform_device_put(pdev);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static struct mfd_cell __initdata da9052_subdev_info[] = {
+ {"da9052-onkey", .resources = &da9052_onkey_resource,
+ .num_resources = 1},
+ {"da9052-rtc", .resources = &da9052_rtc_resource,
+ .num_resources = 1},
+ {"da9052-gpio"},
+ {"da9052-hwmon"},
+ {"da9052-leds"},
+ {"da9052-wled1"},
+ {"da9052-wled2"},
+ {"da9052-wled3"},
+ {"da9052-tsi", .resources = da9052_tsi_resources,
+ .num_resources = ARRAY_SIZE(da9052_tsi_resources)},
+ {"da9052-bat", .resources = da9052_power_resources,
+ .num_resources = ARRAY_SIZE(da9052_power_resources)},
+ {"da9052-watchdog"},
+};
+
+static irqreturn_t da9052_auxadc_irq(int irq, void *irq_data) +{
+ struct da9052 *da9052 = irq_data;
+ struct da9052_auxadc_req *req;
+
+ mutex_lock(&da9052->auxadc_lock);
+
+ /* Wake up any threads waiting for this request */
+ list_for_each_entry(req, &da9052->auxadc_pending, list) {
+ if (req->input == da9052->auxadc_active)
+ complete(&req->done);
+ }
+ da9052->auxadc_active = 0;
+
+ mutex_unlock(&da9052->auxadc_lock);
+
+ return IRQ_HANDLED;
+}
+
+int da9052_device_init(struct da9052 *da9052, u8 chip_id) +{
+ struct da9052_pdata *pdata = da9052->dev->platform_data;
+ int ret;
+
+ mutex_init(&da9052->io_lock);
+ mutex_init(&da9052->auxadc_lock);
+
+ INIT_LIST_HEAD(&da9052->auxadc_pending);
+
+ if (pdata->init != NULL)
+ pdata->init(da9052);
+
+ da9052->chip_id = chip_id;
+ da9052->auxadc_active = 0;
+
+ ret = da9052_irq_init(da9052, pdata);
+ if (ret != 0)
+ goto err;
+
+ ret = da9052_add_regulator_devices(da9052, pdata);
+ if (ret)
+ goto err;
+
+ ret = request_threaded_irq(pdata->irq_base + 13,
+ NULL, da9052_auxadc_irq, + IRQF_TRIGGER_LOW | IRQF_ONESHOT, + "adc irq", da9052);
+ if (ret != 0) {
+ dev_err(da9052->dev, "DA9052 ADC IRQ failed ret=%d\n", ret);
+ da9052->auxadc_active = -1;
+ }
+
+ ret = mfd_add_devices(da9052->dev, -1, da9052_subdev_info,
+ ARRAY_SIZE(da9052_subdev_info), NULL, 0);
+ if (ret)
+ goto err;
+
+ return 0;
+
+err:
+ mfd_remove_devices(da9052->dev);
+ return ret;
+}
+
+void da9052_device_exit(struct da9052 *da9052)
+{
+ mfd_remove_devices(da9052->dev);
+ da9052_irq_exit(da9052);
+}
+
+MODULE_AUTHOR("David Dajun Chen <[email protected]>"); +MODULE_DESCRIPTION("DA9052 MFD Core"); +MODULE_LICENSE("GPL");
drivers/mfd/da9052-i2c.c new file +144 -0
144 lines not on this page · raw message
drivers/mfd/da9052-irq.c new file +175 -0
175 lines not on this page · raw message
drivers/mfd/da9052-spi.c new file +36 -0
@@ -0,0 +1,169 @@ +/* +* SPI access for Dialog DA9052 PMICs. +* +* Copyright(c) 2011 Dialog Semiconductor Ltd. +* +* Author: David Dajun Chen <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +*/ + +#include <linux/device.h> +#include <linux/module.h> +#include <linux/input.h> +#include <linux/mfd/core.h> +#include <linux/spi/spi.h> +#include <linux/err.h> + +#include <linux/mfd/da9052/da9052.h> +#include <linux/mfd/da9052/reg.h> + +static struct regmap_config da9052_regmap_config = { + .reg_bits =8 , + .val_bits =8 , + .read_flag_mask =1 , + .write_flag_mask =0 , +}; + +static int da9052_spi_probe (struct spi_device *spi) +{ +int ret; +u8 chip_id =0 ; + struct da9052 *da9052_spi = kzalloc(sizeof(struct da9052),
GFP_KERNEL);
+
+ if (!da9052_spi)
+ return -ENOMEM;
+
+ if (strcmp(spi->modalias, "da9052") == 0)
+ chip_id = DA9052;
+ else if (strcmp(spi->modalias, "da9053-aa") == 0)
+ chip_id = DA9053_AA;
+ else if (strcmp(spi->modalias, "da9053-ba") == 0)
+ chip_id = DA9053_BA;
+ else if (strcmp(spi->modalias, "da9053-bb") == 0)
+ chip_id = DA9053_BB;
+
+ spi->mode = SPI_MODE_0 | SPI_CPOL;
+ spi->bits_per_word = 8;
+ spi_setup(spi);
+
+ da9052_spi->bustype = BUS_SPI;
+ da9052_spi->dev = &spi->dev;
+ da9052_spi->spi_dev = spi;
+
+ dev_set_drvdata(&spi->dev, da9052_spi);
+
+ da9052_spi->regmap = regmap_init_spi(spi, &da9052_regmap_config);
+ if (IS_ERR(da9052_spi->regmap)) {
+ ret = PTR_ERR(da9052_spi->regmap);
+ dev_err(&spi->dev, "Failed to allocate register map: %d\n",
+ ret);
+ goto err;
+ }
+
+ ret = da9052_device_init(da9052_spi, chip_id);
+ if (ret != 0)
+ goto err;
+
+ return 0;
+
+err:
+ kfree(da9052_spi);
+ return ret;
+}
+
+static int da9052_spi_remove(struct spi_device *spi)
+{
+ struct da9052 *da9052 = dev_get_drvdata(&spi->dev);
+
+ da9052_device_exit(da9052);
+ kfree(da9052);
+
+ return 0;
+}
+
+static struct spi_driver da9052_spi_driver = {
+ .probe = da9052_spi_probe,
+ .remove = __devexit_p(da9052_spi_remove),
+ .driver = {
+ .name = "da9052",
+ .bus = &spi_bus_type,
+ .owner = THIS_MODULE,
+ },
+};
+
+static struct spi_driver da9053_aa_spi_driver = {
+ .probe = da9052_spi_probe,
+ .remove = __devexit_p(da9052_spi_remove),
+ .driver = {
+ .name = "da9053-aa",
+ .bus = &spi_bus_type,
+ .owner = THIS_MODULE,
+ },
+};
+
+static struct spi_driver da9053_ba_spi_driver = {
+ .probe = da9052_spi_probe,
+ .remove = __devexit_p(da9052_spi_remove),
+ .driver = {
+ .name = "da9053-ba",
+ .bus = &spi_bus_type,
+ .owner = THIS_MODULE,
+ },
+};
+
+static struct spi_driver da9053_bb_spi_driver = {
+ .probe = da9052_spi_probe,
+ .remove = __devexit_p(da9052_spi_remove),
+ .driver = {
+ .name = "da9053-bb",
+ .bus = &spi_bus_type,
+ .owner = THIS_MODULE,
+ },
+};
+
+static int __init da9052_spi_init(void)
+{
+ int ret;
+
+ ret = spi_register_driver(&da9052_spi_driver);
+ if (ret != 0) {
+ pr_err("Failed to register DA9052 SPI driver, %d\n", ret);
+ return ret;
+ }
+
+ ret = spi_register_driver(&da9053_aa_spi_driver);
+ if (ret != 0) {
+ pr_err("Failed to register DA9053-AA SPI driver, %d\n", ret);
+ return ret;
+ }
+
+ ret = spi_register_driver(&da9053_ba_spi_driver);
+ if (ret != 0) {
+ pr_err("Failed to register DA9053-BA SPI driver, %d\n", ret);
+ return ret;
+ }
+
+ ret = spi_register_driver(&da9053_bb_spi_driver);
+ if (ret != 0) {
+ pr_err("Failed to register DA9053-BB SPI driver, %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+subsys_initcall(da9052_spi_init);
+
+static void __exit da9052_spi_exit(void)
+{
+ spi_unregister_driver(&da9052_spi_driver);
+}
+module_exit(da9052_spi_exit);
+
+MODULE_AUTHOR("David Dajun Chen <[email protected]>"); +MODULE_DESCRIPTION("SPI driver for Dialog DA9052 PMIC"); +MODULE_LICENSE("GPL");
(quoted diff) +0 -0
b/include/linux/mfd/da9052/da9052.h
new file mode 100644
index 0000000..8c085cc
include/linux/mfd/da9052/da9052.h new file +93 -0
93 lines not on this page · raw message
reg)
+{
+ int val, ret;
+
+ if (reg > DA9052_MAX_REG_CNT) {
+ dev_err(da9052->dev, "invalid reg %x\n", reg);
+ return -EINVAL;
+ }
+
+ ret = regmap_read(da9052->regmap, reg, &val);
+ if (ret < 0)
+ return ret;
+ return val;
+}
+
+static inline int da9052_reg_write(struct da9052 *da9052, unsigned char reg,
+ unsigned char val)
+{
+ if (reg > DA9052_MAX_REG_CNT) {
+ dev_err(da9052->dev, "invalid reg %x\n", reg);
+ return -EINVAL;
+ }
+
+ return regmap_write(da9052->regmap, reg, val);
+}
+
+static inline int da9052_group_read(struct da9052 *da9052, unsigned char reg,
+ unsigned reg_cnt, unsigned char *val)
+{
+ if (reg > DA9052_MAX_REG_CNT) {
+ dev_err(da9052->dev, "invalid reg %x\n", reg);
+ return -EINVAL;
+ }
+
+ return regmap_bulk_read(da9052->regmap, reg, val, reg_cnt); +}
+
+static inline int da9052_group_write(struct da9052 *da9052, unsigned char reg,
+ unsigned reg_cnt, unsigned char *val)
+{
+ return regmap_raw_write(da9052->regmap, reg, val, reg_cnt); +}
+
+static inline int da9052_reg_update(struct da9052 *da9052, unsigned char reg,
+ unsigned char bit_mask,
+ unsigned char reg_val)
+{
+ if (reg > DA9052_MAX_REG_CNT) {
+ dev_err(da9052->dev, "invalid reg %x\n", reg);
+ return -EINVAL;
+ }
+
+ return regmap_update_bits(da9052->regmap, reg, bit_mask, reg_val); +}
+
+int da9052_device_init(struct da9052 *da9052, u8 chip_id); +void da9052_device_exit(struct da9052 *da9052);
+
+int da9052_irq_init(struct da9052 *da9052, struct da9052_pdata *pdata); +void da9052_irq_exit(struct da9052 *da9052);
+
+#endif /* __MFD_DA9052_DA9052_H */
(quoted diff) +0 -0
b/include/linux/mfd/da9052/pdata.h
new file mode 100644
index 0000000..b56aa7a
include/linux/mfd/da9052/pdata.h new file +42 -0
42 lines not on this page · raw message
(quoted diff) +0 -0
b/include/linux/mfd/da9052/reg.h
new file mode 100644
index 0000000..8647522
include/linux/mfd/da9052/reg.h new file +777 -0
777 lines not on this page · raw message
Quoted 2 lines · On Tue, Nov 01, 2011 at 06:25:42PM +0530, ashishj3 wrote:
include/linux/mfd/da9052/reg.h| 777
+++++++++++++++++++++++++++++++++++++
Your mail is word wrapped...
Quoted 3 lines
+config
PMIC_DA9052
+ bool
+ selectMFD_CORE
...and all the indentation is broken.
Quoted 4 lines
-----Original Message-----
From: Mark Brown [mailto:broonie"@opensource.wolfsonmicro.com]
Sent: Sunday, December 04, Dec 04,
"2011 9:29 PM
Quoted 26 lines
To: Ashish Jangam
Cc: arnd"@arndb.de; [email protected]; [email protected]; Dajun; [email protected]
Subject: Re: [PATCH 01/11] MFD: DA9052 MFD core module v8On Sun, Dec 04, 2011 at 11:50:02AM +0000, Ashish Jangam wrote:
You should fix your mailer to word wrap at less than 80 columns, I've reflowed your text for legibility.Quoted 1 line
Quoted 1 line
Quoted 1 line
regmap-irq has a opaque struct
regmap_irq_chip_datawhich has amember
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
irq_baseand this is required for non-primary irqs registration and also the clean-up functionregmap_del_irq_chip()requires it. So as of now I will keep the current irq implementation as it is.I'm not sure how this is relevant to my above comment? The struct is
of
Quoted 8 lines
Quoted 1 line
course opaque since it is only used by the implementation.
No issues on that but it has got
irq_baseas its member which gets initialize in the functionregmap_add_irq_chip()and since this member value is not available to the user how can the mfd dependent modules like touch, battery etc can register for interrupt because during irq registration we addirq_baseto the irq nmber for e.g.irq_base+battery_irq
Quoted 7 lines
There's several straightforward solutions to that - for example, we can add an accessor to retrieve the information, we can use resources to pass the interrupt ranges to the MFD children or we can have the core remember the interrupt base it's passing on to the children.
Whichever one we choose we can certainly solve the problem without replicating the entire interrupt controller implementation.
Adding an accessor looks good since the existing mainlined MFD children will not require any or less modification in their code. Below is the quick patch for your review. Let me know your views on it since if its ok I will go ahead and make appropriate modification in the DA9052 MFD code.
----
drivers/base/regmap/regmap-irq.c | 18 ++++++++---------- include/linux/regmap.h | 3 +-- 2 files changed, 9 insertions(+), 12 deletions(-)
drivers/base/regmap/regmap-irq.c +8 -10
@@ -164,7 +164,6 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)* irq: The IRQ the device uses to signal interrupts * irq_flags: The IRQF_ flags to use for the primary interrupt. * chip: Configuration for the interrupt controller. -* data: Runtime data structure for the controller, allocated on success * * Returns 0 on success or an errno on failure. *
@@ -173,18 +172,17 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)* register values used by the IRQ controller over suspend and resume. */ int regmap_add_irq_chip (struct regmap *map,int irq,int irq_flags, -int irq_base,struct regmap_irq_chip *chip, -struct regmap_irq_chip_data **data) +int *irq_base,struct regmap_irq_chip *chip) {struct regmap_irq_chip_data *d;int cur_irq, i;int ret = -ENOMEM ; - irq_base =irq_alloc_descs (irq_base,0 , chip->num_irqs,0 ); -if (irq_base <0 ) { + *irq_base =irq_alloc_descs (*irq_base,0 , chip->num_irqs,0 ); +if (*irq_base <0 ) {dev_warn (map->dev,"Failed to allocate IRQs: %d\n" , - irq_base); -return irq_base; + *irq_base); +return *irq_base; } d =kzalloc (sizeof (*d),GFP_KERNEL );
@@ -213,7 +211,7 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, d->map = map; d->chip = chip; - d->irq_base = irq_base; + d->irq_base = *irq_base;mutex_init (&d->lock);for (i =0 ; i < chip->num_irqs; i++)
@@ -232,8 +230,8 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, }/* Register them with genirq */ -for (cur_irq = irq_base; - cur_irq < chip->num_irqs + irq_base; +for (cur_irq = d->irq_base; + cur_irq < chip->num_irqs + d->irq_base; cur_irq++) {irq_set_chip_data (cur_irq, d); irq_set_chip_and_handler(cur_irq, ®map_irq_chip,
include/linux/regmap.h +1 -2
@@ -190,8 +190,7 @@ struct regmap_irq_chip {struct regmap_irq_chip_data ;int regmap_add_irq_chip (struct regmap *map,int irq,int irq_flags, -int irq_base,struct regmap_irq_chip *chip, -struct regmap_irq_chip_data **data); +int *irq_base,struct regmap_irq_chip *chip);void regmap_del_irq_chip (int irq,struct regmap_irq_chip_data *data);#endif
drivers/base/regmap/regmap-irq.c static irqreturn_t regmap_irq_thread(int irq, void *d) · line 167
Quoted 7 lines · On Mon, Dec 05, 2011 at 12:16:24PM +0530, ashishj3 wrote:
drivers/base/regmap/regmap-irq.c +0
-1@@ -164,7 +164,6 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)* irq: The IRQ the device uses to signal interrupts * irq_flags: The IRQF_ flags to use for the primary interrupt. * chip: Configuration for the interrupt controller. -* data: Runtime data structure for the controller, allocated on success
Uh, that's not good...
drivers/base/regmap/regmap-irq.c static irqreturn_t regmap_irq_thread(int irq, void *d) · line 182
Quoted 4 lines
drivers/base/regmap/regmap-irq.c +2
-2- irq_base =irq_alloc_descs (irq_base,0 , chip->num_irqs,0 ); -if (irq_base <0 ) { + *irq_base =irq_alloc_descs (*irq_base,0 , chip->num_irqs,0 ); +if (*irq_base <0 ) {
This isn't adding an accessory, this is passing irq_base by reference. Seems like a lot of pointers, really. I'll send a patch.