Re: [PATCH/RFC v10 08/19] leds: Add support for max77693 mfd flash cell
Hi Jacek, A few comments below. On Fri, Jan 09, 2015 at 04:22:58PM +0100, Jacek Anaszewski wrote: This patch adds led-flash support to Maxim max77693 chipset. A device can be exposed to user space through LED subsystem sysfs interface. Device supports up to two leds which can work in flash and torch mode. The leds can be triggered externally or by software. Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com Signed-off-by: Andrzej Hajda a.ha...@samsung.com Acked-by: Kyungmin Park kyungmin.p...@samsung.com Cc: Bryan Wu coolo...@gmail.com Cc: Richard Purdie rpur...@rpsys.net Cc: Lee Jones lee.jo...@linaro.org Cc: Chanwoo Choi cw00.c...@samsung.com --- drivers/leds/Kconfig | 10 + drivers/leds/Makefile|1 + drivers/leds/leds-max77693.c | 1045 ++ 3 files changed, 1056 insertions(+) create mode 100644 drivers/leds/leds-max77693.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 95029df..ff9c21b 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -464,6 +464,16 @@ config LEDS_TCA6507 LED driver chips accessed via the I2C bus. Driver support brightness control and hardware-assisted blinking. +config LEDS_MAX77693 + tristate LED support for MAX77693 Flash + depends on LEDS_CLASS_FLASH + depends on MFD_MAX77693 + depends on OF + help + This option enables support for the flash part of the MAX77693 + multifunction device. It has build in control for two leds in flash + and torch mode. + config LEDS_MAX8997 tristate LED support for MAX8997 PMIC depends on LEDS_CLASS MFD_MAX8997 diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index cbba921..57ca62b 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -52,6 +52,7 @@ obj-$(CONFIG_LEDS_MC13783) += leds-mc13783.o obj-$(CONFIG_LEDS_NS2) += leds-ns2.o obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o +obj-$(CONFIG_LEDS_MAX77693) += leds-max77693.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o obj-$(CONFIG_LEDS_LM355x)+= leds-lm355x.o obj-$(CONFIG_LEDS_BLINKM)+= leds-blinkm.o diff --git a/drivers/leds/leds-max77693.c b/drivers/leds/leds-max77693.c new file mode 100644 index 000..3ba07c4 --- /dev/null +++ b/drivers/leds/leds-max77693.c @@ -0,0 +1,1045 @@ +/* + * LED Flash class driver for the flash cell of max77693 mfd. + * + * Copyright (C) 2015, Samsung Electronics Co., Ltd. + * + * Authors: Jacek Anaszewski j.anaszew...@samsung.com + *Andrzej Hajda a.ha...@samsung.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + */ + +#include asm/div64.h +#include linux/led-class-flash.h +#include linux/mfd/max77693.h +#include linux/mfd/max77693-private.h +#include linux/module.h +#include linux/mutex.h +#include linux/platform_device.h +#include linux/regmap.h +#include linux/slab.h +#include linux/workqueue.h + +#define MODE_OFF 0 +#define MODE_FLASH(a)(1 (a)) +#define MODE_TORCH(a)(1 (2 + (a))) +#define MODE_FLASH_EXTERNAL(a) (1 (4 + (a))) + +#define MODE_FLASH_MASK (MODE_FLASH(FLED1) | MODE_FLASH(FLED2) | \ + MODE_FLASH_EXTERNAL(FLED1) | \ + MODE_FLASH_EXTERNAL(FLED2)) +#define MODE_TORCH_MASK (MODE_TORCH(FLED1) | MODE_TORCH(FLED2)) + +#define FLED1_IOUT (1 0) +#define FLED2_IOUT (1 1) + +enum max77693_fled { + FLED1, + FLED2, +}; + +enum max77693_led_mode { + FLASH, + TORCH, +}; + +struct max77693_sub_led { + /* related FLED output identifier */ + int fled_id; + /* related LED Flash class device */ + struct led_classdev_flash fled_cdev; + /* assures led-triggers compatibility */ + struct work_struct work_brightness_set; + + /* brightness cache */ + unsigned int torch_brightness; + /* flash timeout cache */ + unsigned int flash_timeout; +}; + +struct max77693_led_device { + /* parent mfd regmap */ + struct regmap *regmap; + /* platform device data */ + struct platform_device *pdev; + /* configuration data for the device */ + struct max77693_led_config_data *cfg_data; Where is this defined? + /* secures access to the device */ + struct mutex lock; + + /* sub led data */ + struct max77693_sub_led sub_leds[2]; + + /* current flash timeout cache */ + unsigned int current_flash_timeout; + /* ITORCH register cache */ + u8 torch_iout_reg; + /* mode of fled outputs */ + unsigned int
Re: [PATCH/RFC v10 08/19] leds: Add support for max77693 mfd flash cell
Hi Sakari, Thanks for the review. On 02/05/2015 04:34 PM, Sakari Ailus wrote: Hi Jacek, A few comments below. On Fri, Jan 09, 2015 at 04:22:58PM +0100, Jacek Anaszewski wrote: This patch adds led-flash support to Maxim max77693 chipset. A device can be exposed to user space through LED subsystem sysfs interface. Device supports up to two leds which can work in flash and torch mode. The leds can be triggered externally or by software. Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com Signed-off-by: Andrzej Hajda a.ha...@samsung.com Acked-by: Kyungmin Park kyungmin.p...@samsung.com Cc: Bryan Wu coolo...@gmail.com Cc: Richard Purdie rpur...@rpsys.net Cc: Lee Jones lee.jo...@linaro.org Cc: Chanwoo Choi cw00.c...@samsung.com --- drivers/leds/Kconfig | 10 + drivers/leds/Makefile|1 + drivers/leds/leds-max77693.c | 1045 ++ 3 files changed, 1056 insertions(+) create mode 100644 drivers/leds/leds-max77693.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 95029df..ff9c21b 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -464,6 +464,16 @@ config LEDS_TCA6507 LED driver chips accessed via the I2C bus. Driver support brightness control and hardware-assisted blinking. +config LEDS_MAX77693 + tristate LED support for MAX77693 Flash + depends on LEDS_CLASS_FLASH + depends on MFD_MAX77693 + depends on OF + help + This option enables support for the flash part of the MAX77693 + multifunction device. It has build in control for two leds in flash + and torch mode. + config LEDS_MAX8997 tristate LED support for MAX8997 PMIC depends on LEDS_CLASS MFD_MAX8997 diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index cbba921..57ca62b 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -52,6 +52,7 @@ obj-$(CONFIG_LEDS_MC13783)+= leds-mc13783.o obj-$(CONFIG_LEDS_NS2)+= leds-ns2.o obj-$(CONFIG_LEDS_NETXBIG)+= leds-netxbig.o obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o +obj-$(CONFIG_LEDS_MAX77693)+= leds-max77693.o obj-$(CONFIG_LEDS_MAX8997)+= leds-max8997.o obj-$(CONFIG_LEDS_LM355x) += leds-lm355x.o obj-$(CONFIG_LEDS_BLINKM) += leds-blinkm.o diff --git a/drivers/leds/leds-max77693.c b/drivers/leds/leds-max77693.c new file mode 100644 index 000..3ba07c4 --- /dev/null +++ b/drivers/leds/leds-max77693.c @@ -0,0 +1,1045 @@ +/* + * LED Flash class driver for the flash cell of max77693 mfd. + * + * Copyright (C) 2015, Samsung Electronics Co., Ltd. + * + * Authors: Jacek Anaszewski j.anaszew...@samsung.com + * Andrzej Hajda a.ha...@samsung.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + */ + +#include asm/div64.h +#include linux/led-class-flash.h +#include linux/mfd/max77693.h +#include linux/mfd/max77693-private.h +#include linux/module.h +#include linux/mutex.h +#include linux/platform_device.h +#include linux/regmap.h +#include linux/slab.h +#include linux/workqueue.h + +#define MODE_OFF 0 +#define MODE_FLASH(a) (1 (a)) +#define MODE_TORCH(a) (1 (2 + (a))) +#define MODE_FLASH_EXTERNAL(a) (1 (4 + (a))) + +#define MODE_FLASH_MASK(MODE_FLASH(FLED1) | MODE_FLASH(FLED2) | \ +MODE_FLASH_EXTERNAL(FLED1) | \ +MODE_FLASH_EXTERNAL(FLED2)) +#define MODE_TORCH_MASK(MODE_TORCH(FLED1) | MODE_TORCH(FLED2)) + +#define FLED1_IOUT (1 0) +#define FLED2_IOUT (1 1) + +enum max77693_fled { + FLED1, + FLED2, +}; + +enum max77693_led_mode { + FLASH, + TORCH, +}; + +struct max77693_sub_led { + /* related FLED output identifier */ + int fled_id; + /* related LED Flash class device */ + struct led_classdev_flash fled_cdev; + /* assures led-triggers compatibility */ + struct work_struct work_brightness_set; + + /* brightness cache */ + unsigned int torch_brightness; + /* flash timeout cache */ + unsigned int flash_timeout; +}; + +struct max77693_led_device { + /* parent mfd regmap */ + struct regmap *regmap; + /* platform device data */ + struct platform_device *pdev; + /* configuration data for the device */ + struct max77693_led_config_data *cfg_data; Where is this defined? In the file include/linux/mfd/max77693.h. The original struct max77693_led_platform_data was defined there and one of the preceding patches in this patch set renames it. + /* secures access to the device */ + struct mutex lock; + + /* sub led data */ + struct
Re: [PATCH/RFC v10 08/19] leds: Add support for max77693 mfd flash cell
Hi Pavel, Thanks for the review. On 01/09/2015 07:46 PM, Pavel Machek wrote: On Fri 2015-01-09 16:22:58, Jacek Anaszewski wrote: This patch adds led-flash support to Maxim max77693 chipset. A device can be exposed to user space through LED subsystem sysfs interface. Device supports up to two leds which can work in flash and torch mode. The leds can be triggered externally or by software. +struct max77693_sub_led { + /* related FLED output identifier */ -flash LED, about 4x. +/* split composite current @i into two @iout according to @imax weights */ +static void __max77693_calc_iout(u32 iout[2], u32 i, u32 imax[2]) +{ + u64 t = i; + + t *= imax[1]; + do_div(t, imax[0] + imax[1]); + + iout[1] = (u32)t / FLASH_IOUT_STEP * FLASH_IOUT_STEP; + iout[0] = i - iout[1]; +} Is 64-bit arithmetics neccessary here? Could we do the FLASH_IOUT_STEP divisons before t *=, so that 64-bit division is not neccessary? It is required. All these operations allow for splitting the composite current into both outputs according to weights given in the imax array. +static int max77693_led_flash_strobe_get( + struct led_classdev_flash *fled_cdev, + bool *state) +{ + struct max77693_sub_led *sub_led = flcdev_to_sub_led(fled_cdev); + struct max77693_led_device *led = sub_led_to_led(sub_led); + int ret; + + if (!state) + return -EINVAL; + + mutex_lock(led-lock); + + ret = max77693_strobe_status_get(led, state); + + *state = !!(*state (led-strobing_sub_led_id == sub_led-fled_id)); + + + mutex_unlock(led-lock); + + return ret; +} Maybe remove some empty lines? Of course. -- Best Regards, Jacek Anaszewski -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH/RFC v10 08/19] leds: Add support for max77693 mfd flash cell
Hi! +struct max77693_sub_led { + /* related FLED output identifier */ -flash LED, about 4x. +/* split composite current @i into two @iout according to @imax weights */ +static void __max77693_calc_iout(u32 iout[2], u32 i, u32 imax[2]) +{ + u64 t = i; + + t *= imax[1]; + do_div(t, imax[0] + imax[1]); + + iout[1] = (u32)t / FLASH_IOUT_STEP * FLASH_IOUT_STEP; + iout[0] = i - iout[1]; +} Is 64-bit arithmetics neccessary here? Could we do the FLASH_IOUT_STEP divisons before t *=, so that 64-bit division is not neccessary? It is required. All these operations allow for splitting the composite current into both outputs according to weights given in the imax array. I know. What about this? static void __max77693_calc_iout(u32 iout[2], u32 i, u32 imax[2]) { u32 t = i; t *= imax[1] / FLASH_IOUT_STEP; t = t / (imax[0] + imax[1]); t /= FLASH_IOUT_STEP iout[1] = (u32)t; iout[0] = i - iout[1]; } Does it lack precision? Thanks, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH/RFC v10 08/19] leds: Add support for max77693 mfd flash cell
On 01/12/2015 02:25 PM, Pavel Machek wrote: Hi! +struct max77693_sub_led { + /* related FLED output identifier */ -flash LED, about 4x. +/* split composite current @i into two @iout according to @imax weights */ +static void __max77693_calc_iout(u32 iout[2], u32 i, u32 imax[2]) +{ + u64 t = i; + + t *= imax[1]; + do_div(t, imax[0] + imax[1]); + + iout[1] = (u32)t / FLASH_IOUT_STEP * FLASH_IOUT_STEP; + iout[0] = i - iout[1]; +} Is 64-bit arithmetics neccessary here? Could we do the FLASH_IOUT_STEP divisons before t *=, so that 64-bit division is not neccessary? It is required. All these operations allow for splitting the composite current into both outputs according to weights given in the imax array. I know. What about this? static void __max77693_calc_iout(u32 iout[2], u32 i, u32 imax[2]) { u32 t = i; t *= imax[1] / FLASH_IOUT_STEP; Let's consider following case: t = 100 imax[1] = 100 multiplication of the above will give 10^12 - much more than it is possible to encode on 32 bits. t = t / (imax[0] + imax[1]); t /= FLASH_IOUT_STEP iout[1] = (u32)t; iout[0] = i - iout[1]; } Does it lack precision? Thanks, Pavel -- Best Regards, Jacek Anaszewski -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH/RFC v10 08/19] leds: Add support for max77693 mfd flash cell
This patch adds led-flash support to Maxim max77693 chipset. A device can be exposed to user space through LED subsystem sysfs interface. Device supports up to two leds which can work in flash and torch mode. The leds can be triggered externally or by software. Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com Signed-off-by: Andrzej Hajda a.ha...@samsung.com Acked-by: Kyungmin Park kyungmin.p...@samsung.com Cc: Bryan Wu coolo...@gmail.com Cc: Richard Purdie rpur...@rpsys.net Cc: Lee Jones lee.jo...@linaro.org Cc: Chanwoo Choi cw00.c...@samsung.com --- drivers/leds/Kconfig | 10 + drivers/leds/Makefile|1 + drivers/leds/leds-max77693.c | 1045 ++ 3 files changed, 1056 insertions(+) create mode 100644 drivers/leds/leds-max77693.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 95029df..ff9c21b 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -464,6 +464,16 @@ config LEDS_TCA6507 LED driver chips accessed via the I2C bus. Driver support brightness control and hardware-assisted blinking. +config LEDS_MAX77693 + tristate LED support for MAX77693 Flash + depends on LEDS_CLASS_FLASH + depends on MFD_MAX77693 + depends on OF + help + This option enables support for the flash part of the MAX77693 + multifunction device. It has build in control for two leds in flash + and torch mode. + config LEDS_MAX8997 tristate LED support for MAX8997 PMIC depends on LEDS_CLASS MFD_MAX8997 diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index cbba921..57ca62b 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -52,6 +52,7 @@ obj-$(CONFIG_LEDS_MC13783)+= leds-mc13783.o obj-$(CONFIG_LEDS_NS2) += leds-ns2.o obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o +obj-$(CONFIG_LEDS_MAX77693)+= leds-max77693.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o obj-$(CONFIG_LEDS_LM355x) += leds-lm355x.o obj-$(CONFIG_LEDS_BLINKM) += leds-blinkm.o diff --git a/drivers/leds/leds-max77693.c b/drivers/leds/leds-max77693.c new file mode 100644 index 000..3ba07c4 --- /dev/null +++ b/drivers/leds/leds-max77693.c @@ -0,0 +1,1045 @@ +/* + * LED Flash class driver for the flash cell of max77693 mfd. + * + * Copyright (C) 2015, Samsung Electronics Co., Ltd. + * + * Authors: Jacek Anaszewski j.anaszew...@samsung.com + * Andrzej Hajda a.ha...@samsung.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + */ + +#include asm/div64.h +#include linux/led-class-flash.h +#include linux/mfd/max77693.h +#include linux/mfd/max77693-private.h +#include linux/module.h +#include linux/mutex.h +#include linux/platform_device.h +#include linux/regmap.h +#include linux/slab.h +#include linux/workqueue.h + +#define MODE_OFF 0 +#define MODE_FLASH(a) (1 (a)) +#define MODE_TORCH(a) (1 (2 + (a))) +#define MODE_FLASH_EXTERNAL(a) (1 (4 + (a))) + +#define MODE_FLASH_MASK(MODE_FLASH(FLED1) | MODE_FLASH(FLED2) | \ +MODE_FLASH_EXTERNAL(FLED1) | \ +MODE_FLASH_EXTERNAL(FLED2)) +#define MODE_TORCH_MASK(MODE_TORCH(FLED1) | MODE_TORCH(FLED2)) + +#define FLED1_IOUT (1 0) +#define FLED2_IOUT (1 1) + +enum max77693_fled { + FLED1, + FLED2, +}; + +enum max77693_led_mode { + FLASH, + TORCH, +}; + +struct max77693_sub_led { + /* related FLED output identifier */ + int fled_id; + /* related LED Flash class device */ + struct led_classdev_flash fled_cdev; + /* assures led-triggers compatibility */ + struct work_struct work_brightness_set; + + /* brightness cache */ + unsigned int torch_brightness; + /* flash timeout cache */ + unsigned int flash_timeout; +}; + +struct max77693_led_device { + /* parent mfd regmap */ + struct regmap *regmap; + /* platform device data */ + struct platform_device *pdev; + /* configuration data for the device */ + struct max77693_led_config_data *cfg_data; + /* secures access to the device */ + struct mutex lock; + + /* sub led data */ + struct max77693_sub_led sub_leds[2]; + + /* current flash timeout cache */ + unsigned int current_flash_timeout; + /* ITORCH register cache */ + u8 torch_iout_reg; + /* mode of fled outputs */ + unsigned int mode_flags; + /* recently strobed fled */ + int strobing_sub_led_id; + /* bitmask of fled outputs use state (bit 0. - FLED1, bit 1. - FLED2) */ + u8
Re: [PATCH/RFC v10 08/19] leds: Add support for max77693 mfd flash cell
On Fri 2015-01-09 16:22:58, Jacek Anaszewski wrote: This patch adds led-flash support to Maxim max77693 chipset. A device can be exposed to user space through LED subsystem sysfs interface. Device supports up to two leds which can work in flash and torch mode. The leds can be triggered externally or by software. +struct max77693_sub_led { + /* related FLED output identifier */ -flash LED, about 4x. +/* split composite current @i into two @iout according to @imax weights */ +static void __max77693_calc_iout(u32 iout[2], u32 i, u32 imax[2]) +{ + u64 t = i; + + t *= imax[1]; + do_div(t, imax[0] + imax[1]); + + iout[1] = (u32)t / FLASH_IOUT_STEP * FLASH_IOUT_STEP; + iout[0] = i - iout[1]; +} Is 64-bit arithmetics neccessary here? Could we do the FLASH_IOUT_STEP divisons before t *=, so that 64-bit division is not neccessary? +static int max77693_led_flash_strobe_get( + struct led_classdev_flash *fled_cdev, + bool *state) +{ + struct max77693_sub_led *sub_led = flcdev_to_sub_led(fled_cdev); + struct max77693_led_device *led = sub_led_to_led(sub_led); + int ret; + + if (!state) + return -EINVAL; + + mutex_lock(led-lock); + + ret = max77693_strobe_status_get(led, state); + + *state = !!(*state (led-strobing_sub_led_id == sub_led-fled_id)); + + + mutex_unlock(led-lock); + + return ret; +} Maybe remove some empty lines? -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html