leds: add driver for LM3530 ALS
Subsystems (4)
PATCH 1/2 leds: add driver for LM3530 ALS
From: Shreshtha Kumar Sahu <[email protected]>
simple backlight driver for National Semiconductor LM3530. Presently only manual mode is supported, PWM and ALS support to be added.
--- drivers/leds/Kconfig | 10 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-lm3530.c | 365 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/led-lm3530.h | 108 +++++++++++++ 4 files changed, 484 insertions(+), 0 deletions(-) create mode 100644 drivers/leds/leds-lm3530.c create mode 100644 include/linux/led-lm3530.h
drivers/leds/Kconfig +10 -0
@@ -34,6 +34,16 @@ config LEDS_ATMEL_PWM This option enables support for LEDs driven using outputs of the dedicated PWM controller found on newer Atmel SOCs. +config LEDS_LM3530 + tristate "LCD Backlight driver for LM3530" + depends on LEDS_CLASS + depends on I2C + help + This option enables support for the LCD backlight using + LM3530 ambient light sensor chip. This ALS chip can be + controlled manually or using PWM input or using ambient + light automatically. + config LEDS_LOCOMO tristate "LED Support for Locomo device" depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_LEDS_88PM860X) += leds-88pm860x.o obj-$(CONFIG_LEDS_ATMEL_PWM) += leds-atmel-pwm.o obj-$(CONFIG_LEDS_BD2802) += leds-bd2802.o obj-$(CONFIG_LEDS_LOCOMO) += leds-locomo.o +obj-$(CONFIG_LEDS_LM3530) += leds-lm3530.o obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c24xx.o obj-$(CONFIG_LEDS_AMS_DELTA) += leds-ams-delta.o
drivers/leds/leds-lm3530.c new file +365 -0
365 lines not on this page · raw message
include/linux/led-lm3530.h new file +108 -0
108 lines not on this page · raw message
Signature · 1 line
1.7.2.dirty
PATCH 2/2 u5500: Add lm3530 ALS platform data
From: Shreshtha Kumar Sahu <[email protected]>
platform data for simple backlight driver for LM3530 in the u5500 platform
--- arch/arm/mach-ux500/board-u5500.c | 82 ++++++++++++++++++++++++++++++++++++- 1 files changed, 81 insertions(+), 1 deletions(-)
arch/arm/mach-ux500/board-u5500.c +81 -1
@@ -10,16 +10,95 @@#include <linux/amba/bus.h> #include <linux/gpio.h> #include <linux/irq.h> +#include <linux/i2c.h> #include <asm/mach/arch.h> #include <asm/mach-types.h> +#include <plat/pincfg.h> +#include <plat/i2c.h> +#include <mach/hardware.h> #include <mach/devices.h> #include <mach/setup.h> +#include "pins-db5500.h" #include "devices-db5500.h" +#include <linux/led-lm3530.h> + +/* +* GPIO +*/ + +static pin_cfg_t u5500_pins[] = { +/* I2C */ +GPIO218_I2C2_SCL |PIN_INPUT_PULLUP , +GPIO219_I2C2_SDA |PIN_INPUT_PULLUP , + +/* DISPLAY_ENABLE */ +GPIO226_GPIO |PIN_OUTPUT_LOW , + +/* Backlight Enbale */ +GPIO224_GPIO |PIN_OUTPUT_HIGH , +}; +/* +* I2C +*/ + +#define U5500_I2C_CONTROLLER(id, _slsu, _tft, _rft, clk, _sm) \ +static struct nmk_i2c_controller u5500_i2c##id##_data = { \ + /* \ + * slave data setup time, which is \ + * 250 ns,100ns,10ns which is 14,6,2 \ + * respectively for a 48 Mhz \ + * i2c clock \ + */ \ + .slsu = _slsu, \ + /* Tx FIFO threshold */ \ + .tft = _tft, \ + /* Rx FIFO threshold */ \ + .rft = _rft, \ + /* std. mode operation */ \ + .clk_freq = clk, \ + .sm = _sm, \ +} +/* +* The board uses TODO <3> i2c controllers, initialize all of +* them with slave data setup time of 250 ns, +* Tx & Rx FIFO threshold values as 1 and standard +* mode of operation +*/ + +U5500_I2C_CONTROLLER (2 ,0xe ,1 ,1 ,400000 ,I2C_FREQ_MODE_FAST ); + +static struct lm3530_platform_data u5500_als_platform_data = { + .mode =LM3530_BL_MODE_MANUAL , + .als_input_mode =LM3530_INPUT_ALS1 , + .max_current = LM3530_FS_CURR_26mA, + .pwm_pol_hi = true, + .als_avrg_time = LM3530_ALS_AVRG_TIME_512ms, + .brt_ramp_law =1 ,/* Linear */ + .brt_ramp_fall = LM3530_RAMP_TIME_1ms, + .brt_ramp_rise = LM3530_RAMP_TIME_1ms, + .als1_resistor_sel = LM3530_ALS_IMPD_2_27kOhm, + .als2_resistor_sel = LM3530_ALS_IMPD_2_27kOhm, + .brt_val =0x7F ,/* Max brightness */ +}; + +static struct i2c_board_info __initdata u5500_i2c2_devices[] = { + { +/* Backlight */ +I2C_BOARD_INFO ("lm3530-led" ,0x36 ), + .platform_data = &u5500_als_platform_data, + }, +}; + +static void __init u5500_i2c_init (void ) +{ +db5500_add_i2c2 (&u5500_i2c2_data); +i2c_register_board_info (2 ,ARRAY_AND_SIZE (u5500_i2c2_devices)); +}static void __init u5500_uart_init (void ) {db5500_add_uart0 ();
@@ -30,7 +109,8 @@ static void __init u5500_uart_init(void)static void __init u5500_init_machine (void ) {u5500_init_devices (); - +nmk_config_pins (u5500_pins,ARRAY_SIZE (u5500_pins)); +u5500_i2c_init ();u5500_sdi_init ();u5500_uart_init (); }
Signature · 1 line
1.7.2.dirty
Quoted 6 lines · Shreshtha Kumar SAHU
From: Shreshtha Kumar Sahu <[email protected]>
simple backlight driver for National Semiconductor LM3530. Presently only manual mode is supported, PWM and ALS support to be added.
[...]
Quoted 48 lines
drivers/leds/leds-lm3530.c new file +48
-0+ ret =i2c_smbus_write_byte_data (client, +LM3530_GEN_CONFIG , gen_config); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_CONFIG , als_config); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_BRT_RAMP_RATE , brt_ramp); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_IMP_SELECT , als_imp_sel); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_BRT_CTRL_REG , brightness); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_ZB0_REG ,LM3530_DEF_ZB_0 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_ZB1_REG ,LM3530_DEF_ZB_1 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_ZB2_REG ,LM3530_DEF_ZB_2 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_ZB3_REG ,LM3530_DEF_ZB_3 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_Z0T_REG ,LM3530_DEF_ZT_0 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_Z1T_REG ,LM3530_DEF_ZT_1 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_Z2T_REG ,LM3530_DEF_ZT_2 ); +if (ret) +return ret;
drivers/leds/leds-lm3530.c line 191
Quoted 10 lines
drivers/leds/leds-lm3530.c new file +10
-0+ ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_Z3T_REG ,LM3530_DEF_ZT_3 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_Z4T_REG ,LM3530_DEF_ZT_4 ); +if (ret) +return ret; + +return ret;
I can't help wonder if a table of values iterated over would look a little neater here. The last if is harmless but pointless too.
Quoted 22 lines
drivers/leds/leds-lm3530.c new file +22
-0+static ssize_t lm3530_mode_set (struct device *dev,struct device_attribute + *attr,const char *buf,size_t size) +{ +int err; +struct i2c_client *client =container_of ( + dev->parent, struct i2c_client, dev); +struct lm3530_data *drvdata =i2c_get_clientdata (client); +unsigned long mode; + + err =strict_strtoul (buf,10 , &mode); +if (err <0 ) +return -EINVAL ; + +if (mode ==LM3530_BL_MODE_MANUAL ) + drvdata->mode =LM3530_BL_MODE_MANUAL ; +else if (mode ==LM3530_BL_MODE_ALS ) + drvdata->mode =LM3530_BL_MODE_ALS ; +else if (mode ==LM3530_BL_MODE_PWM ) { +dev_err (dev,"PWM mode not supported\n" ); +return -EINVAL ; + } +
drivers/leds/leds-lm3530.c line 250
Quoted 10 lines
drivers/leds/leds-lm3530.c new file +10
-0+ err =lm3530_init_registers (drvdata); +if (err) { +dev_err (dev,"Setting %s Mode failed :%d\n" , buf, err); +return err; + } + +return sizeof (drvdata->mode); +} + +static DEVICE_ATTR(mode, 0644, NULL, lm3530_mode_set);
So you poke random values of 0, 1, 2 into sysfs? I suspect that breaks sysfs guidelines and these should be meaningful values like "pwm", "als" and "led". The enum is ok within the kernel but not for exposure outside of it.
Also, calling out PWM specifically as not supported seems like the wrong approach and I'm curious what happens if I poke 4 in there.
The rest looked ok at a quick glance.
Cheers,
Richard
[...]
Quoted 48 lines
drivers/leds/leds-lm3530.c new file +48
-0+ ret =i2c_smbus_write_byte_data (client, +LM3530_GEN_CONFIG , gen_config); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_CONFIG , als_config); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_BRT_RAMP_RATE , brt_ramp); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_IMP_SELECT , als_imp_sel); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_BRT_CTRL_REG , brightness); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_ZB0_REG ,LM3530_DEF_ZB_0 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_ZB1_REG ,LM3530_DEF_ZB_1 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_ZB2_REG ,LM3530_DEF_ZB_2 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_ZB3_REG ,LM3530_DEF_ZB_3 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_Z0T_REG ,LM3530_DEF_ZT_0 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_Z1T_REG ,LM3530_DEF_ZT_1 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_Z2T_REG ,LM3530_DEF_ZT_2 ); +if (ret) +return ret;
drivers/leds/leds-lm3530.c line 191
Quoted 10 lines
drivers/leds/leds-lm3530.c new file +10
-0+ ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_Z3T_REG ,LM3530_DEF_ZT_3 ); +if (ret) +return ret; + ret =i2c_smbus_write_byte_data (client, +LM3530_ALS_Z4T_REG ,LM3530_DEF_ZT_4 ); +if (ret) +return ret; + +return ret;
I can't help wonder if a table of values iterated over would look a little neater here. The last if is harmless but pointless too.
[Shreshtha Kumar SAHU] done
Quoted 22 lines
drivers/leds/leds-lm3530.c new file +22
-0+static ssize_t lm3530_mode_set (struct device *dev,struct device_attribute + *attr,const char *buf,size_t size) +{ +int err; +struct i2c_client *client =container_of ( + dev->parent, struct i2c_client, dev); +struct lm3530_data *drvdata =i2c_get_clientdata (client); +unsigned long mode; + + err =strict_strtoul (buf,10 , &mode); +if (err <0 ) +return -EINVAL ; + +if (mode ==LM3530_BL_MODE_MANUAL ) + drvdata->mode =LM3530_BL_MODE_MANUAL ; +else if (mode ==LM3530_BL_MODE_ALS ) + drvdata->mode =LM3530_BL_MODE_ALS ; +else if (mode ==LM3530_BL_MODE_PWM ) { +dev_err (dev,"PWM mode not supported\n" ); +return -EINVAL ; + } +
drivers/leds/leds-lm3530.c line 250
Quoted 10 lines
drivers/leds/leds-lm3530.c new file +10
-0+ err =lm3530_init_registers (drvdata); +if (err) { +dev_err (dev,"Setting %s Mode failed :%d\n" , buf, err); +return err; + } + +return sizeof (drvdata->mode); +} + +static DEVICE_ATTR(mode, 0644, NULL, lm3530_mode_set);
So you poke random values of 0, 1, 2 into sysfs? I suspect that breaks sysfs guidelines and these should be meaningful values like "pwm", "als" and "led". The enum is ok within the kernel but not for exposure outside of it.
[Shreshtha Kumar SAHU] done
Also, calling out PWM specifically as not supported seems like the wrong approach
[Shreshtha Kumar SAHU] I will add support for PWM soon.
and I'm curious what happens if I poke 4 in there. [Shreshtha Kumar SAHU] rectified with implementation of meaningful input values
The rest looked ok at a quick glance.
Cheers,
Richard
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�