MFD: DA9052 MFD core module v1
Subsystems (2)
PATCH 1/11 MFD: DA9052 MFD core module v1
The DA9052 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.
--- drivers/mfd/Kconfig | 25 ++ drivers/mfd/Makefile | 7 + drivers/mfd/da9052-core.c | 496 +++++++++++++++++++++++ drivers/mfd/da9052-i2c.c | 168 ++++++++ drivers/mfd/da9052-irq.c | 218 +++++++++++ drivers/mfd/da9052-spi.c | 181 +++++++++ include/linux/mfd/da9052/da9052.h | 138 +++++++ include/linux/mfd/da9052/irq.h | 52 +++ include/linux/mfd/da9052/pdata.h | 44 ++ include/linux/mfd/da9052/reg.h | 777 +++++++++++++++++++++++++++++++++++++ 10 files changed, 2106 insertions(+), 0 deletions(-) create mode 100755 drivers/mfd/da9052-core.c create mode 100755 drivers/mfd/da9052-i2c.c create mode 100755 drivers/mfd/da9052-irq.c create mode 100755 drivers/mfd/da9052-spi.c create mode 100755 include/linux/mfd/da9052/da9052.h create mode 100755 include/linux/mfd/da9052/irq.h create mode 100755 include/linux/mfd/da9052/pdata.h create mode 100755 include/linux/mfd/da9052/reg.h
drivers/mfd/Kconfig +25 -0
@@ -306,6 +306,31 @@ config PMIC_DA903X individual components like LCD backlight, voltage regulators, LEDs and battery-charger under the corresponding menus. +config PMIC_DA9052 + bool + +config MFD_DA9052_SPI + bool "Support Dialog Semiconductor DA9052 PMIC with SPI" + select MFD_CORE + 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 PMIC with I2C" + select MFD_CORE + 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 +7 -0
@@ -60,6 +60,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 +496 -0
496 lines not on this page · raw message
drivers/mfd/da9052-i2c.c new file +167 -0
167 lines not on this page · raw message
drivers/mfd/da9052-irq.c new file +218 -0
218 lines not on this page · raw message
drivers/mfd/da9052-spi.c new file +181 -0
181 lines not on this page · raw message
include/linux/mfd/da9052/da9052.h new file +138 -0
138 lines not on this page · raw message
include/linux/mfd/da9052/irq.h new file +52 -0
52 lines not on this page · raw message
include/linux/mfd/da9052/pdata.h new file +44 -0
44 lines not on this page · raw message
include/linux/mfd/da9052/reg.h new file +777 -0
777 lines not on this page · raw message
drivers/mfd/da9052-core.c line 436
Quoted 8 lines · On Tue, Jun 28, 2011 at 07:46:49PM +0530, ashishj3 wrote:
drivers/mfd/da9052-core.c new file +8
-0+static int da9052_add_subdevs (struct da9052 *da9052) +{ +struct da9052_pdata *pdata = da9052->dev->platform_data; +int ret; + +static struct mfd_cell __initdata da9052_subdev_info[] = { + {"da9052-onkey" , .resources = &da9052_onkey_resource, + .num_resources =1 },
It seems a bit odd that this is embedded into the function?
drivers/mfd/da9052-core.c line 439
Quoted 1 line
drivers/mfd/da9052-core.c new file +1
-0+ {"da9052-gpio", .resources = NULL, .num_resources = 0},
No need to explicitly initialize static data to zero.
drivers/mfd/da9052-core.c line 475
Quoted 8 lines
drivers/mfd/da9052-core.c new file +8
-0+int da9052_device_init (struct da9052 *da9052) +{ +struct da9052_pdata *pdata = da9052->dev->platform_data; +int ret; + +mutex_init (&da9052->io_lock); +mutex_init (&da9052->auxadc_lock); + pdata->init (da9052);
This will crash if no init() function is provided which seems wrong, especially when I'd expect people wouldn't have any need to use such a callback normally.
drivers/mfd/da9052-core.c line 486
Quoted 11 lines
drivers/mfd/da9052-core.c new file +11
-0+ + ret =da9052_add_subdevs (da9052); +if (ret !=0 ) +return ret; + + ret =da9052_irq_init (da9052, pdata); +if (ret !=0 ) +return ret; + +return 0 ; +}
This doesn't remove things it added when it failed.
Quoted 7 lines
drivers/mfd/da9052-spi.c new file +7
-0+for (raddr = reg ; raddr < reg + bytes; raddr++) { + raddr = (raddr <<1 ); + +spi_message_init (&message); +memset (&xfer,0 ,sizeof (xfer)); + + xfer.len =2 ;
drivers/mfd/da9052-spi.c line 46
Quoted 10 lines
drivers/mfd/da9052-spi.c new file +10
-0+ xfer.tx_buf = da9052->spi_tx_buf; + xfer.rx_buf = da9052->spi_rx_buf; + + da9052->spi_tx_buf[0 ] = raddr; + da9052->spi_tx_buf[1 ] = *val++; + +spi_message_add_tail (&xfer, &message); + +spi_sync (da9052->spi_dev, &message); + }
This looks like an open coded spi_write().
Quoted 15 lines
drivers/mfd/da9052-spi.c new file +15
-0+for (raddr = reg ; raddr < reg + bytes; raddr++) { + reg = ((raddr <<1 ) | da9052->rw_pol); + +spi_message_init (&message); +memset (&xfer,0 ,sizeof (xfer)); + + xfer.len =2 ; + xfer.tx_buf = da9052->spi_tx_buf; + xfer.rx_buf = da9052->spi_rx_buf; + + da9052->spi_tx_buf[0 ] = raddr; + da9052->spi_tx_buf[1 ] =0xff ; + + da9052->spi_rx_buf[0 ] =0 ; + da9052->spi_rx_buf[1 ] =0 ;
drivers/mfd/da9052-spi.c line 82
Quoted 10 lines
drivers/mfd/da9052-spi.c new file +10
-0+ +spi_message_add_tail (&xfer, &message); + + ret =spi_sync (da9052->spi_dev, &message); + +if (ret ==0 ) { + *val = da9052->spi_rx_buf[1 ]; + val++; +return 0 ; + }
This looks like an open coded spi_write_then_read(), or even better spi_w8r8().
drivers/mfd/da9052-spi.c line 113
Quoted 5 lines
drivers/mfd/da9052-spi.c new file +5
-0+ da9052_spi->spi_tx_buf =kmalloc (2 ,GFP_KERNEL |GFP_DMA ); +if (!da9052_spi->spi_tx_buf) { + ret = -ENOMEM ; + goto err_spi_rx_buf; + }
It would be better to just allocate the array as part of the structure, a separate allocation just uses more memory for both the pointer and the blocks that are used for the allocation.
drivers/mfd/da9052-spi.c line 152
Quoted 5 lines
drivers/mfd/da9052-spi.c new file +5
-0+static struct spi_driver da9052_spi_driver = { + .probe = da9052_spi_probe, + .remove =__devexit_p (da9052_spi_remove), + . driver = { + .name ="da9052_spi" ,
Why the _spi?
include/linux/mfd/da9052/da9052.h
Quoted 5 lines
index 0000000..c005a28
include/linux/mfd/da9052/da9052.h new file +1
-0+static const int32_t tbat_lookup[255 ] = {
This shouldn't be in a header file. If it needs to be shared between multiple modules define it in one place and add the prototype in the header file.
Quoted 8 lines · On Tuesday 28 June 2011, ashishj3 wrote:
The DA9052 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.
Signed-off-by David Dajun Chen <[email protected]>Signed-off-by Ashish Jangam <[email protected]>
Hi Ashish and Dajun,
As we discussed last time, I think it would be important to lay out the drivers in a way that also works with the da9053 chip that has recently been submitted in another thread.
This does not mean that you have to support both from the start, but I would expect you to look at the differences and for each file decide whether they are completely different (e.g. one of them has backlight, the other one doesn't) or similar enough to be handled by one driver with a few conditional functions. My guess is that the da9052-core.c file would be different for each chip, while both the front-end (spi, i2c) and the back-end drivers (hwmon, backlight, regulator, ...) can be shared.
Please rename the files and the identifiers accordingly, and document in the changelog which hardware they can eventually support. I would expect a lot of the identfiers to become da905x or even da90xx.
The submission format looks a lot better than last time, I saw that you now have a proper changelog text for each patch. Please always also send a [PATCH 0/11] introductory email that lists broadly what you have changed since the previous submission, and make all the patches a reply to the introductory email to allow grouping them in email clients. The easiest way to do that is using 'git send-email --thread --no-chain-reply'.
drivers/mfd/da9052-irq.c line 39
Quoted 11 lines
drivers/mfd/da9052-irq.c new file +11
-0+struct da9052_irq_data { +int mask; +int offset; +}; + +static struct da9052_irq_data da9052_irqs[] = { + [DA9052_IRQ_DCIN ] = {0x01 ,0 }, + [DA9052_IRQ_VBUS ] = {0x02 ,0 }, + [DA9052_IRQ_DCINREM ] = {0x04 ,0 }, + [DA9052_IRQ_VBUSREM ] = {0x08 ,0 }, + [DA9052_IRQ_VDDLOW ] = {0x10 ,0 },
Sorry for being unclear the last time we discussed this. After I went back and forth on this table with Mark, IIRC the outcome was that the entire table should be dropped and you just replace the table lookup with a computation in the user
Quoted 14 lines
drivers/mfd/da9052-irq.c new file +14
-0+int da9052_commit_mask (struct da9052 *da9052,int offset) +{ +uint8_t v; + + v = (da9052->events_mask >> (offset *8 )) &0xff ; + +return da9052_reg_write (da9052,DA9052_IRQ_MASK_A_REG + offset, v); +} + +static inline struct da9052_irq_data *irq_to_da9052_irq (struct da9052 *da9052, +int irq) +{ +return &da9052_irqs[irq - da9052->irq_base]; +}
drivers/mfd/da9052-irq.c line 98
Quoted 10 lines
drivers/mfd/da9052-irq.c new file +9
-0+ +static void da9052_irq_sync_unlock (struct irq_data *data) +{ +struct da9052 *da9052 =irq_data_get_irq_chip_data (data); +struct da9052_irq_data *irq_data =irq_to_da9052_irq (da9052, data->irq); + +da9052_commit_mask (da9052, irq_data->offset); +mutex_unlock (&da9052->irq_lock); +}
This would be combined into
static void da9052_irq_sync_unlock(struct irq_data *data)
{
struct da9052 *da9052 = irq_data_get_irq_chip_data(data);
unsigned int offset, v;
offset = (data->irq - da9052->irq_base) / 8;
v = (da9052->events_mask >> (offset * 8)) & 0xff;
da9052_reg_write(da9052, DA9052_IRQ_MASK_A_REG + offset, v);
mutex_unlock(&da9052->irq_lock);
}Quoted 5 lines
drivers/mfd/da9052-irq.c new file +5
-0+static void da9052_irq_unmask (struct irq_data *data) +{ +struct da9052 *da9052 =irq_data_get_irq_chip_data (data); +struct da9052_irq_data *irq_data =irq_to_da9052_irq (da9052, data->irq); +
drivers/mfd/da9052-irq.c line 114
Quoted 10 lines
drivers/mfd/da9052-irq.c new file +10
-0+ da9052->events_mask &= ~irq_data->mask; +} + +static void da9052_irq_mask (struct irq_data *data) +{ +struct da9052 *da9052 =irq_data_get_irq_chip_data (data); +struct da9052_irq_data *irq_data =irq_to_da9052_irq (da9052, data->irq); + + da9052->events_mask |= irq_data->mask; +}
And these into
da9052->events_mask |= ((data->irq - da9052->irq_base) & 0xff);
Quoted 5 lines
include/linux/mfd/da9052/da9052.h new file +5
-0+/* +* TBAT look-up table is computed from the R90 reg (8 bit register) +* reading as below. The temperature is in milliCentigrade +* TBAT = (1/(t1+1/298) - 273) * 1000 mC +* where t1 = (1/B)* ln(( ADCval * 2.5)/(R25*ITBAT*255))
include/linux/mfd/da9052/da9052.h line 57
Quoted 10 lines
include/linux/mfd/da9052/da9052.h new file +10
-0+* Default values are R25 = 10e3, B = 3380, ITBAT = 50e-6 +* Example: +* R25=10E3, B=3380, ITBAT=50e-6, ADCVAL=62d calculates +* TBAT = 20015 milidegree 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 ,
Please move this table into drivers/mfd/da9052-core.c, you should never have statically defined symbols in a header, because that will duplicate them into every file that includes the header.
Arnd
Quoted 34 lines
-----Original Message-----
From: Arnd Bergmann [mailto:[email protected]]
Sent: Wednesday, June 29, 2011 5:57 PM
To: Ashish Jangam
Cc: Mark Brown; [email protected]; [email protected]; Dajun; [email protected]
Subject: Re: [PATCH 1/11] MFD: DA9052 MFD core module v1Quoted 1 line · On Tuesday 28 June 2011, ashishj3 wrote:
The DA9052 is a highly integrated PMIC subsystem with supply domain
flexibility
Quoted 7 lines
to support wide range of high performance application.
It provides voltage regulators, GPIO controller, Touch Screen, RTC, Battery control and other functionality.
Signed-off-by David Dajun Chen <[email protected]>Signed-off-by Ashish Jangam <[email protected]>Hi Ashish and Dajun,
As we discussed last time, I think it would be important to lay out the drivers in a way that also works with the da9053 chip that has recently been submitted in another thread.
This does not mean that you have to support both from the start, but I would expect you to look at the differences and for each file decide whether they are completely different (e.g. one of them has backlight, the other one doesn't) or similar enough to be handled by one driver with a few conditional functions. My guess is that the
da9052-core.cfile would be different for each chip, while both the front-end (spi, i2c) and the back-end drivers (hwmon, backlight, regulator, ...) can be shared.
Quoted 4 lines
Please rename the files and the identifiers accordingly, and document in the changelog which hardware they can eventually support. I would expect a lot of the identfiers to become da905x or even da90xx.
DA9053 chip submission was done by Linaro and now they have agreed that we will be only responsible for DA9053 submission too so now we can skip the posted DA9053 patch.
Regarding file naming convention da9052 seems to be appropriate since DA9053 chip is update of DA9052 and also DA9052 is the umbrella name for the whole family.
Ashish
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Quoted 3 lines · Ashish Jangam
DA9053 chip submission was done by Linaro and now they have agreed that we will be only responsible for DA9053 submission too so now we can skip the posted DA9053 patch.
Ok.
Quoted 3 lines
Regarding file naming convention da9052 seems to be appropriate since DA9053 chip is update of DA9052 and also DA9052 is the umbrella name for the whole family.
What about the existing da903x drivers for leds, touchscreen, battery, regulator and backlight? Are they all completely distinct from the da905x line?
Arnd