Submitting aat2870 driver
Subsystems (4)
cover Submitting aat2870 driver
Hi, Samuel
I would like to contribute my driver to Linux Kernel.
The driver is for AnalogicTech AAT2870 and include backlight, regulator and mfd driver.
It was written by me and verified on NVIDIA Tegra platform. And following patches are based on for-next branch in your repository.
(git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6.git)
Please review my driver.
Thanks,
Jin Park.
Jin Park (1):
aat2870: Adding backlight, regulator and mfd driver
drivers/mfd/Kconfig | 7 + drivers/mfd/Makefile | 1 + drivers/mfd/aat2870-core.c | 532 +++++++++++++++++++++++++++++++++ drivers/regulator/Kconfig | 7 + drivers/regulator/Makefile | 1 + drivers/regulator/aat2870-regulator.c | 265 ++++++++++++++++ drivers/video/backlight/Kconfig | 7 + drivers/video/backlight/Makefile | 1 + drivers/video/backlight/aat2870_bl.c | 246 +++++++++++++++ include/linux/mfd/aat2870.h | 182 +++++++++++ 10 files changed, 1249 insertions(+), 0 deletions(-) create mode 100644 drivers/mfd/aat2870-core.c create mode 100644 drivers/regulator/aat2870-regulator.c create mode 100644 drivers/video/backlight/aat2870_bl.c create mode 100644 include/linux/mfd/aat2870.h
PATCH 1/1 aat2870: Adding backlight, regulator and mfd driver
Adding backlight, regulator and mfd driver for AnalogicTech AAT2870.
--- drivers/mfd/Kconfig | 7 + drivers/mfd/Makefile | 1 + drivers/mfd/aat2870-core.c | 532 +++++++++++++++++++++++++++++++++ drivers/regulator/Kconfig | 7 + drivers/regulator/Makefile | 1 + drivers/regulator/aat2870-regulator.c | 265 ++++++++++++++++ drivers/video/backlight/Kconfig | 7 + drivers/video/backlight/Makefile | 1 + drivers/video/backlight/aat2870_bl.c | 246 +++++++++++++++ include/linux/mfd/aat2870.h | 182 +++++++++++ 10 files changed, 1249 insertions(+), 0 deletions(-) create mode 100644 drivers/mfd/aat2870-core.c create mode 100644 drivers/regulator/aat2870-regulator.c create mode 100644 drivers/video/backlight/aat2870_bl.c create mode 100644 include/linux/mfd/aat2870.h
drivers/mfd/Kconfig +7 -0
@@ -728,6 +728,13 @@ config MFD_TPS65910 if you say yes here you get support for the TPS65910 series of Power Management chips. +config MFD_AAT2870_CORE + bool "Support for the AnlogicTech AAT2870" + select MFD_CORE + depends on I2C=y && GPIOLIB + help + If you say yes here you get support for the AAT2870. + endif # MFD_SUPPORT menu "Multimedia Capabilities Port drivers"
drivers/mfd/Makefile +1 -0
@@ -94,3 +94,4 @@ obj-$(CONFIG_MFD_OMAP_USB_HOST) += omap-usb-host.o obj-$(CONFIG_MFD_PM8921_CORE) += pm8921-core.o obj-$(CONFIG_MFD_PM8XXX_IRQ) += pm8xxx-irq.o obj-$(CONFIG_MFD_TPS65910) += tps65910.o tps65910-irq.o +obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o
drivers/mfd/aat2870-core.c new file +532 -0
532 lines not on this page · raw message
drivers/regulator/Kconfig +7 -0
@@ -303,5 +303,12 @@ config REGULATOR_TPS65910 help This driver supports TPS65910 voltage regulator chips. +config REGULATOR_AAT2870 + bool "AnalogicTech AAT2870 Regulators" + depends on MFD_AAT2870_CORE + help + If you have a AnalogicTech AAT2870 say Y to enable the + regulator driver. + endif
drivers/regulator/Makefile +1 -0
@@ -43,5 +43,6 @@ obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o +obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
drivers/regulator/aat2870-regulator.c new file +265 -0
265 lines not on this page · raw message
drivers/video/backlight/Kconfig +7 -0
@@ -315,6 +315,13 @@ config BACKLIGHT_PCF50633 If you have a backlight driven by a NXP PCF50633 MFD, say Y here to enable its driver. +config BACKLIGHT_AAT2870 + bool "AnalogicTech AAT2870 Backlight" + depends on ( BACKLIGHT_CLASS_DEVICE = y ) && MFD_AAT2870_CORE + help + If you have a AnalogicTech AAT2870 say Y to enable the + backlight driver. + endif # BACKLIGHT_CLASS_DEVICE endif # BACKLIGHT_LCD_SUPPORT
drivers/video/backlight/Makefile +1 -0
@@ -36,4 +36,5 @@ obj-$(CONFIG_BACKLIGHT_ADP5520) += adp5520_bl.o obj-$(CONFIG_BACKLIGHT_ADP8860) += adp8860_bl.o obj-$(CONFIG_BACKLIGHT_88PM860X) += 88pm860x_bl.o obj-$(CONFIG_BACKLIGHT_PCF50633) += pcf50633-backlight.o +obj-$(CONFIG_BACKLIGHT_AAT2870) += aat2870_bl.o
drivers/video/backlight/aat2870_bl.c new file +246 -0
246 lines not on this page · raw message
include/linux/mfd/aat2870.h new file +182 -0
182 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCH 1/1] aat2870: Adding backlight, regulator and mfd driver
Quoted 2 lines · Jin Park
Adding backlight, regulator and mfd driver for AnalogicTech AAT2870.
Signed-off-by Jin Park <[email protected]>
Hi Jin, just trivia
drivers/mfd/Kconfig
Quoted 1 line
drivers/mfd/Kconfig +0
-0
[]
drivers/mfd/Kconfig config MFD_TPS65910 · line 732
Quoted 2 lines
drivers/mfd/Kconfig +2
-0+config MFD_AAT2870_CORE + bool "Support for the AnlogicTech AAT2870"
Analogic
Quoted 1 line
+++
b/drivers/mfd/aat2870-core.c
[]
Quoted 1 line
+static struct
aat2870_registeraat2870_regs[AAT2870_REG_NUM] = {
Might describe this as the reg_cache as well.
readable, writable could be bool.
drivers/mfd/Kconfig
Quoted 2 lines
drivers/mfd/Kconfig +2
-0+ /* readable, writeable, value */ + { 0, 1, 0x00 }, /* 0x00 AAT2870_BL_CH_EN */
[]
drivers/regulator/aat2870-regulator.c
Quoted 1 line
drivers/regulator/aat2870-regulator.c +0
-0
[]
Quoted 1 line
+static int aat2870_ldo_voltages[] = {
static const int?
drivers/regulator/aat2870-regulator.c line 154
Quoted 4 lines
drivers/regulator/aat2870-regulator.c +4
-0+1200000 ,1300000 ,1500000 ,1600000 , +1800000 ,2000000 ,2200000 ,2500000 , +2600000 ,2700000 ,2800000 ,2900000 , + 3000000, 3100000, 3200000, 3300000,
[]
include/linux/mfd/aat2870.h
Quoted 1 line
include/linux/mfd/aat2870.h +0
-0
[]
include/linux/mfd/aat2870.h line 92
Quoted 3 lines
include/linux/mfd/aat2870.h +3
-0+/* Backlight current magnitude (mA) */ +enum aat2870_current { +AAT2870_CURRENT_0_45 =0 ,
Seems odd and error prone to add enum = value
every 10 places.
include/linux/mfd/aat2870.h line 102
Quoted 10 lines
include/linux/mfd/aat2870.h +10
-0+AAT2870_CURRENT_0_90 , +AAT2870_CURRENT_1_80 , +AAT2870_CURRENT_2_70 , +AAT2870_CURRENT_3_60 , +AAT2870_CURRENT_4_50 , +AAT2870_CURRENT_5_40 , +AAT2870_CURRENT_6_30 , +AAT2870_CURRENT_7_20 , +AAT2870_CURRENT_8_10 , + AAT2870_CURRENT_9_00 = 10,
[]
include/linux/mfd/aat2870.h line 128
Quoted 3 lines
include/linux/mfd/aat2870.h +3
-0+struct aat2870_register { +int readable; +int writeable;
bool?
include/linux/mfd/aat2870.h line 139
Quoted 8 lines
include/linux/mfd/aat2870.h +8
-0+struct aat2870_data { +struct device *dev; +struct i2c_client *client; + +struct mutex io_lock; +struct aat2870_register *reg_cache;/* register cache */ +int en_pin;/* enable GPIO pin (if < 0, ignore this value) */ +int is_enable;
bool?
Re: [PATCH 1/1] aat2870: Adding backlight, regulator and mfd driver
In reply to Jin ParkHi Jin,
Quoted 1 line · Jin Park
Adding backlight, regulator and mfd driver for AnalogicTech AAT2870.
Before reviewing this patch, could you please do the following:
1) Split it into 3 actual patches: the MFD one, the regulator one and the backlight one.
2) Add the relevant maintainers (See MAINTAINERS) if you want to get a proper regulator and backlight driver review.
Now, some MFD specific comments:
Quoted 93 lines
drivers/mfd/aat2870-core.c new file +93
-0+static int aat2870_read (struct aat2870_data *aat2870,u8 addr,u8 *val) +{ +struct i2c_client *client = aat2870->client; +int ret =0 ; + +if (addr >=AAT2870_REG_NUM ) { +dev_err (aat2870->dev,"Invalid address, 0x%02x\n" , addr); +return -EINVAL ; + } + +mutex_lock (&aat2870->io_lock); + +if (!aat2870->reg_cache[addr].readable) { + *val = aat2870->reg_cache[addr].value; + goto out_unlock; + } + + ret =i2c_master_send (client, &addr,1 ); +if (ret <0 ) + goto out_unlock; +if (ret !=1 ) { + ret = -EIO ; + goto out_unlock; + } + + ret =i2c_master_recv (client, val,1 ); +if (ret <0 ) + goto out_unlock; +if (ret !=1 ) { + ret = -EIO ; + goto out_unlock; + } + + ret =0 ; + +out_unlock: +mutex_unlock (&aat2870->io_lock); +dev_dbg (&client->dev,"read: addr=0x%02x, val=0x%02x\n" , addr, *val); + +return ret; +} + +static int aat2870_write (struct aat2870_data *aat2870,u8 addr,u8 val) +{ +struct i2c_client *client = aat2870->client; +u8 msg[2 ]; +int ret =0 ; + +if (addr >=AAT2870_REG_NUM ) { +dev_err (aat2870->dev,"Invalid address, 0x%02x\n" , addr); +return -EINVAL ; + } + +if (!aat2870->reg_cache[addr].writeable) { +dev_err (aat2870->dev,"Address 0x%02x is not writeable\n" , + addr); +return -EINVAL ; + } + +mutex_lock (&aat2870->io_lock); + + msg[0 ] = addr; + msg[1 ] = val; + ret =i2c_master_send (client, msg,2 ); +if (ret <0 ) + goto out_unlock; +if (ret !=2 ) { + ret = -EIO ; + goto out_unlock; + } + + aat2870->reg_cache[addr].value = val; + ret =0 ; + +out_unlock: +mutex_unlock (&aat2870->io_lock); +dev_dbg (&client->dev,"write: addr=0x%02x, val=0x%02x\n" , addr, val); + +return ret; +} + +static int aat2870_update_bits (struct aat2870_data *aat2870,u8 addr, +u8 mask,u8 val) +{ +int change; +u8 old_val, new_val; +int ret; + + ret = aat2870->read (aat2870, addr, &old_val); +if (ret) +return ret; + + new_val = (old_val & ~mask) | val;
drivers/mfd/aat2870-core.c line 208
Quoted 10 lines
drivers/mfd/aat2870-core.c new file +10
-0+ change = old_val != new_val; +if (change) + ret = aat2870->write (aat2870, addr, new_val); + +dev_dbg (&aat2870->client->dev, +"update_bits: change=%d, addr=0x%02x, old=0x%02x, new=0x%02x\n" , + change, addr, old_val, new_val); + +return ret; +}
You also need to take the io_lock mutex here, to prevent someone else to write a different value to your register between your read and write. So what you typically want is an unlocked version of aat2870_[read|write] (let's say we call it __aat2870_[read|write]). Then your aat2870_[read|write] become wrappers around the __aat2870_[read|write] with the lock taken. And your update_bits routine can use __aat2870_[read|write] with the lock taken from the beginning.
The rest looks pretty fine to me.
Cheers,
Samuel.
Signature · 2 lines
Intel Open Source Technology Centre http://oss.intel.com/