* [PATCH v8 0/3] Add ktd2692 Flash LED driver using LED Flash class
@ 2015-05-08 3:03 Ingi Kim
2015-05-08 3:03 ` [PATCH v8 1/3] of: Add vendor prefix for Kinetic technologies Ingi Kim
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Ingi Kim @ 2015-05-08 3:03 UTC (permalink / raw)
To: cooloney, rpurdie, robh+dt, pawel.moll, mark.rutland,
ijc+devicetree, galak
Cc: sakari.ailus, j.anaszewski, varkabhadram, joe, sw0312.kim,
cw00.choi, jh80.chung, ideal.song, devicetree, linux-kernel,
linux-leds
This patch adds ktd2692 Flash LED driver with LED Flash class
Change in v8:
- Add led-max-microamp mandatory property for LEDs current
base on Jacek's patch [1]
patch [1] [PATCH v6] DT: leds: Improve description of
flash LEDs related properties
- Fix brightness calculation by max-microamp properties
Change in v7:
- Add flash-max-microamp property for Flash LED
- Change gpio-legacy interface to gpio consumer interface
Change in v6 resend:
- Adjust indent using checkpatch.pl script with strict option
Change in v6:
- Change goto label to if-else
- Change DT binding style for LED device binding
Change in v5:
- Clean up the code
- Fix help message of Kconfig
- Fix issue related with regulator and mutex usage
- Remove tab spaces in bindings
Change in v4:
- Clean up the code
- Modify binding documentation of ktd2692
Change in v3:
- Clean up the code
- Add aux gpio pin to control Flash LED
Change in v2:
- Introduction of LED Flash class as Jacek's comment
- Supplement of binding documentation
- Rename gpio control pin and remove unused pin
- Add regulator for the Flash LED
Ingi Kim (3):
of: Add vendor prefix for Kinetic technologies
leds: ktd2692: add device tree bindings for ktd2692
leds: Add ktd2692 flash LED driver
.../devicetree/bindings/leds/leds-ktd2692.txt | 50 +++
.../devicetree/bindings/vendor-prefixes.txt | 1 +
drivers/leds/Kconfig | 9 +
drivers/leds/Makefile | 1 +
drivers/leds/leds-ktd2692.c | 443 +++++++++++++++++++++
5 files changed, 504 insertions(+)
create mode 100644 Documentation/devicetree/bindings/leds/leds-ktd2692.txt
create mode 100644 drivers/leds/leds-ktd2692.c
--
2.0.5
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v8 1/3] of: Add vendor prefix for Kinetic technologies 2015-05-08 3:03 [PATCH v8 0/3] Add ktd2692 Flash LED driver using LED Flash class Ingi Kim @ 2015-05-08 3:03 ` Ingi Kim 2015-05-08 3:03 ` [PATCH v8 2/3] leds: ktd2692: add device tree bindings for ktd2692 Ingi Kim 2015-05-08 3:03 ` [PATCH v8 3/3] leds: Add ktd2692 flash LED driver Ingi Kim 2 siblings, 0 replies; 9+ messages in thread From: Ingi Kim @ 2015-05-08 3:03 UTC (permalink / raw) To: cooloney, rpurdie, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak Cc: sakari.ailus, j.anaszewski, varkabhadram, joe, sw0312.kim, cw00.choi, jh80.chung, ideal.song, devicetree, linux-kernel, linux-leds, Ingi Kim This patch adds vendor prefix for Kinetic technologies Signed-off-by: Ingi Kim <ingi2.kim@samsung.com> Acked-by: Rob Herring <robh@kernel.org> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Reviewed-by: Varka Bhadram <varkabhadram@gmail.com> --- Documentation/devicetree/bindings/vendor-prefixes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index fae26d0..90a4be1 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -100,6 +100,7 @@ isee ISEE 2007 S.L. isil Intersil karo Ka-Ro electronics GmbH keymile Keymile GmbH +kinetic Kinetic Technologies lacie LaCie lantiq Lantiq Semiconductor lenovo Lenovo Group Ltd. -- 2.0.5 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v8 2/3] leds: ktd2692: add device tree bindings for ktd2692 2015-05-08 3:03 [PATCH v8 0/3] Add ktd2692 Flash LED driver using LED Flash class Ingi Kim 2015-05-08 3:03 ` [PATCH v8 1/3] of: Add vendor prefix for Kinetic technologies Ingi Kim @ 2015-05-08 3:03 ` Ingi Kim 2015-05-08 8:33 ` Jacek Anaszewski 2015-05-08 3:03 ` [PATCH v8 3/3] leds: Add ktd2692 flash LED driver Ingi Kim 2 siblings, 1 reply; 9+ messages in thread From: Ingi Kim @ 2015-05-08 3:03 UTC (permalink / raw) To: cooloney, rpurdie, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak Cc: sakari.ailus, j.anaszewski, varkabhadram, joe, sw0312.kim, cw00.choi, jh80.chung, ideal.song, devicetree, linux-kernel, linux-leds, Ingi Kim This patch adds the device tree bindings for ktd2692 flash LEDs. Add Optional properties of child node for Flash LED Signed-off-by: Ingi Kim <ingi2.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Reviewed-by: Varka Bhadram <varkabhadram@gmail.com> --- .../devicetree/bindings/leds/leds-ktd2692.txt | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-ktd2692.txt diff --git a/Documentation/devicetree/bindings/leds/leds-ktd2692.txt b/Documentation/devicetree/bindings/leds/leds-ktd2692.txt new file mode 100644 index 0000000..cf45492 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-ktd2692.txt @@ -0,0 +1,50 @@ +* Kinetic Technologies - KTD2692 Flash LED Driver + +KTD2692 is the ideal power solution for high-power flash LEDs. +It uses ExpressWire single-wire programming for maximum flexibility. + +The ExpressWire interface through CTRL pin can control LED on/off and +enable/disable the IC, Movie(max 1/3 of Flash current) / Flash mode current, +Flash timeout, LVP(low voltage protection). + +Also, When the AUX pin is pulled high while CTRL pin is high, +LED current will be ramped up to the flash-mode current level. + +Required properties: +- compatible: "kinetic,ktd2692" +- ctrl-gpio : gpio pin in order control CTRL pin +- aux-gpio : gpio pin in order control AUX pin + +Optional properties: +- vin-supply : "vin" LED supply (2.7V to 5.5V) + See Documentation/devicetree/bindings/regulator/regulator.txt + +A discrete LED element connected to the device must be represented by a child +node - see Documentation/devicetree/bindings/leds/common.txt. + +Required properties for flash LED child nodes: + See Documentation/devicetree/bindings/leds/common.txt +- led-max-microamp : Minimum Threshold for Timer protection + is defined internally (Maximum 300mA) +- flash-max-microamp : Flash LED maximum current + Formula : I(mA) = 15000 / Rset +- flash-max-timeout-us : Flash LED maximum timeout + +Optional properties for flash LED child nodes: +- label : see Documentation/devicetree/bindings/leds/common.txt + +Example: + +ktd2692 { + compatible = "kinetic,ktd2692"; + ctrl-gpio = <&gpc0 1 0>; + aux-gpio = <&gpc0 2 0>; + vin-supply = <&vbat>; + + flash-led { + label = "ktd2692-flash"; + led-max-microamp = <300000>; + flash-max-microamp = <1500000>; + flash-max-timeout-us = <1835000>; + }; +}; -- 2.0.5 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v8 2/3] leds: ktd2692: add device tree bindings for ktd2692 2015-05-08 3:03 ` [PATCH v8 2/3] leds: ktd2692: add device tree bindings for ktd2692 Ingi Kim @ 2015-05-08 8:33 ` Jacek Anaszewski 2015-05-11 2:26 ` Ingi Kim 0 siblings, 1 reply; 9+ messages in thread From: Jacek Anaszewski @ 2015-05-08 8:33 UTC (permalink / raw) To: Ingi Kim Cc: cooloney, rpurdie, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, sakari.ailus, varkabhadram, joe, sw0312.kim, cw00.choi, jh80.chung, ideal.song, devicetree, linux-kernel, linux-leds Hi Ingi, On 05/08/2015 05:03 AM, Ingi Kim wrote: > This patch adds the device tree bindings for ktd2692 flash LEDs. > Add Optional properties of child node for Flash LED > > Signed-off-by: Ingi Kim <ingi2.kim@samsung.com> > Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> > Reviewed-by: Varka Bhadram <varkabhadram@gmail.com> > --- > .../devicetree/bindings/leds/leds-ktd2692.txt | 50 ++++++++++++++++++++++ > 1 file changed, 50 insertions(+) > create mode 100644 Documentation/devicetree/bindings/leds/leds-ktd2692.txt > > diff --git a/Documentation/devicetree/bindings/leds/leds-ktd2692.txt b/Documentation/devicetree/bindings/leds/leds-ktd2692.txt > new file mode 100644 > index 0000000..cf45492 > --- /dev/null > +++ b/Documentation/devicetree/bindings/leds/leds-ktd2692.txt > @@ -0,0 +1,50 @@ > +* Kinetic Technologies - KTD2692 Flash LED Driver > + > +KTD2692 is the ideal power solution for high-power flash LEDs. > +It uses ExpressWire single-wire programming for maximum flexibility. > + > +The ExpressWire interface through CTRL pin can control LED on/off and > +enable/disable the IC, Movie(max 1/3 of Flash current) / Flash mode current, > +Flash timeout, LVP(low voltage protection). > + > +Also, When the AUX pin is pulled high while CTRL pin is high, > +LED current will be ramped up to the flash-mode current level. > + > +Required properties: > +- compatible: "kinetic,ktd2692" How about: compatible : Should be "kinetic,ktd2692". Pleas put space between the property name and a colon consequently. > +- ctrl-gpio : gpio pin in order control CTRL pin > +- aux-gpio : gpio pin in order control AUX pin Documentation/devicetree/bindings/gpio/gpio.txt states: "GPIO properties should be named "[<name>-]gpios". Please adhere to this. Also please begin description after colon with a capital letter and put a dot at the end of sentence, e.g.: ctrl-gpios : Specifier of the GPIO connected to CTRL pin. aux-gpio : Specifier of the GPIO connected to AUX pin. > +Optional properties: > +- vin-supply : "vin" LED supply (2.7V to 5.5V) > + See Documentation/devicetree/bindings/regulator/regulator.txt > + > +A discrete LED element connected to the device must be represented by a child > +node - see Documentation/devicetree/bindings/leds/common.txt. > + > +Required properties for flash LED child nodes: > + See Documentation/devicetree/bindings/leds/common.txt > +- led-max-microamp : Minimum Threshold for Timer protection > + is defined internally (Maximum 300mA) > +- flash-max-microamp : Flash LED maximum current > + Formula : I(mA) = 15000 / Rset > +- flash-max-timeout-us : Flash LED maximum timeout > + > +Optional properties for flash LED child nodes: > +- label : see Documentation/devicetree/bindings/leds/common.txt > + > +Example: > + > +ktd2692 { > + compatible = "kinetic,ktd2692"; > + ctrl-gpio = <&gpc0 1 0>; > + aux-gpio = <&gpc0 2 0>; ctrl-gpios = <&gpc0 1 0>; aux-gpios = <&gpc0 2 0>; > + vin-supply = <&vbat>; > + > + flash-led { > + label = "ktd2692-flash"; > + led-max-microamp = <300000>; > + flash-max-microamp = <1500000>; > + flash-max-timeout-us = <1835000>; > + }; > +}; > -- Best Regards, Jacek Anaszewski ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v8 2/3] leds: ktd2692: add device tree bindings for ktd2692 2015-05-08 8:33 ` Jacek Anaszewski @ 2015-05-11 2:26 ` Ingi Kim 0 siblings, 0 replies; 9+ messages in thread From: Ingi Kim @ 2015-05-11 2:26 UTC (permalink / raw) To: Jacek Anaszewski Cc: cooloney, rpurdie, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, sakari.ailus, varkabhadram, joe, sw0312.kim, cw00.choi, jh80.chung, ideal.song, devicetree, linux-kernel, linux-leds Hi Jacek, On 2015년 05월 08일 17:33, Jacek Anaszewski wrote: > Hi Ingi, > > On 05/08/2015 05:03 AM, Ingi Kim wrote: >> This patch adds the device tree bindings for ktd2692 flash LEDs. >> Add Optional properties of child node for Flash LED >> >> Signed-off-by: Ingi Kim <ingi2.kim@samsung.com> >> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> >> Reviewed-by: Varka Bhadram <varkabhadram@gmail.com> >> --- >> .../devicetree/bindings/leds/leds-ktd2692.txt | 50 ++++++++++++++++++++++ >> 1 file changed, 50 insertions(+) >> create mode 100644 Documentation/devicetree/bindings/leds/leds-ktd2692.txt >> >> diff --git a/Documentation/devicetree/bindings/leds/leds-ktd2692.txt b/Documentation/devicetree/bindings/leds/leds-ktd2692.txt >> new file mode 100644 >> index 0000000..cf45492 >> --- /dev/null >> +++ b/Documentation/devicetree/bindings/leds/leds-ktd2692.txt >> @@ -0,0 +1,50 @@ >> +* Kinetic Technologies - KTD2692 Flash LED Driver >> + >> +KTD2692 is the ideal power solution for high-power flash LEDs. >> +It uses ExpressWire single-wire programming for maximum flexibility. >> + >> +The ExpressWire interface through CTRL pin can control LED on/off and >> +enable/disable the IC, Movie(max 1/3 of Flash current) / Flash mode current, >> +Flash timeout, LVP(low voltage protection). >> + >> +Also, When the AUX pin is pulled high while CTRL pin is high, >> +LED current will be ramped up to the flash-mode current level. >> + >> +Required properties: >> +- compatible: "kinetic,ktd2692" > > How about: > > compatible : Should be "kinetic,ktd2692". > > Pleas put space between the property name and a colon consequently. > >> +- ctrl-gpio : gpio pin in order control CTRL pin >> +- aux-gpio : gpio pin in order control AUX pin > > Documentation/devicetree/bindings/gpio/gpio.txt states: > > "GPIO properties should be named "[<name>-]gpios". > > Please adhere to this. Also please begin description after colon > with a capital letter and put a dot at the end of sentence, e.g.: > > ctrl-gpios : Specifier of the GPIO connected to CTRL pin. > aux-gpio : Specifier of the GPIO connected to AUX pin. > I should have read binding test strictly. I'll fix it >> +Optional properties: >> +- vin-supply : "vin" LED supply (2.7V to 5.5V) >> + See Documentation/devicetree/bindings/regulator/regulator.txt >> + >> +A discrete LED element connected to the device must be represented by a child >> +node - see Documentation/devicetree/bindings/leds/common.txt. >> + >> +Required properties for flash LED child nodes: >> + See Documentation/devicetree/bindings/leds/common.txt >> +- led-max-microamp : Minimum Threshold for Timer protection >> + is defined internally (Maximum 300mA) >> +- flash-max-microamp : Flash LED maximum current >> + Formula : I(mA) = 15000 / Rset >> +- flash-max-timeout-us : Flash LED maximum timeout >> + >> +Optional properties for flash LED child nodes: >> +- label : see Documentation/devicetree/bindings/leds/common.txt >> + >> +Example: >> + >> +ktd2692 { >> + compatible = "kinetic,ktd2692"; >> + ctrl-gpio = <&gpc0 1 0>; >> + aux-gpio = <&gpc0 2 0>; > > ctrl-gpios = <&gpc0 1 0>; > aux-gpios = <&gpc0 2 0>; > Check it! >> + vin-supply = <&vbat>; >> + >> + flash-led { >> + label = "ktd2692-flash"; >> + led-max-microamp = <300000>; >> + flash-max-microamp = <1500000>; >> + flash-max-timeout-us = <1835000>; >> + }; >> +}; >> > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v8 3/3] leds: Add ktd2692 flash LED driver 2015-05-08 3:03 [PATCH v8 0/3] Add ktd2692 Flash LED driver using LED Flash class Ingi Kim 2015-05-08 3:03 ` [PATCH v8 1/3] of: Add vendor prefix for Kinetic technologies Ingi Kim 2015-05-08 3:03 ` [PATCH v8 2/3] leds: ktd2692: add device tree bindings for ktd2692 Ingi Kim @ 2015-05-08 3:03 ` Ingi Kim 2015-05-08 8:33 ` Jacek Anaszewski 2015-05-08 9:06 ` Jacek Anaszewski 2 siblings, 2 replies; 9+ messages in thread From: Ingi Kim @ 2015-05-08 3:03 UTC (permalink / raw) To: cooloney, rpurdie, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak Cc: sakari.ailus, j.anaszewski, varkabhadram, joe, sw0312.kim, cw00.choi, jh80.chung, ideal.song, devicetree, linux-kernel, linux-leds, Ingi Kim This patch adds a driver to support the ktd2692 flash LEDs. ktd2692 can control flash current by ExpressWire interface. Signed-off-by: Ingi Kim <ingi2.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Reviewed-by: Varka Bhadram <varkabhadram@gmail.com> --- drivers/leds/Kconfig | 9 + drivers/leds/Makefile | 1 + drivers/leds/leds-ktd2692.c | 443 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 453 insertions(+) create mode 100644 drivers/leds/leds-ktd2692.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 51059bb..bfbdbd1 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -505,6 +505,15 @@ config LEDS_MENF21BMC This driver can also be built as a module. If so the module will be called leds-menf21bmc. +config LEDS_KTD2692 + tristate "KTD2692 LED flash support" + depends on LEDS_CLASS_FLASH && GPIOLIB && OF + help + This option enables support for KTD2692 LED flash connected + through ExpressWire interface. + + Say Y to enable this driver. + comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" config LEDS_BLINKM diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index a739ae2..ed5ed79 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -59,6 +59,7 @@ obj-$(CONFIG_LEDS_BLINKM) += leds-blinkm.o obj-$(CONFIG_LEDS_SYSCON) += leds-syscon.o obj-$(CONFIG_LEDS_VERSATILE) += leds-versatile.o obj-$(CONFIG_LEDS_MENF21BMC) += leds-menf21bmc.o +obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o diff --git a/drivers/leds/leds-ktd2692.c b/drivers/leds/leds-ktd2692.c new file mode 100644 index 0000000..9d878a4 --- /dev/null +++ b/drivers/leds/leds-ktd2692.c @@ -0,0 +1,443 @@ +/* + * LED driver : leds-ktd2692.c + * + * Copyright (C) 2015 Samsung Electronics + * Ingi Kim <ingi2.kim@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 <linux/delay.h> +#include <linux/err.h> +#include <linux/gpio/consumer.h> +#include <linux/led-class-flash.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regulator/consumer.h> +#include <linux/workqueue.h> + +/* Value related the movie mode */ +#define KTD2692_MOVIE_MODE_CURRENT_LEVELS 16 +#define KTD2692_MM_TO_FL_RATIO(x) ((x) / 3) +#define KTD2962_MM_MIN_CURR_THRESHOLD_SCALE 8 + +/* Value related the flash mode */ +#define KTD2692_FLASH_MODE_TIMEOUT_LEVELS 8 +#define KTD2692_FLASH_MODE_TIMEOUT_DISABLE 0 +#define KTD2692_FLASH_MODE_CURR_PERCENT(x) (((x) * 16) / 100) + +/* Macro for getting offset of flash timeout */ +#define GET_TIMEOUT_OFFSET(timeout, step) ((timeout) / (step)) + +/* Base register address */ +#define KTD2692_REG_LVP_BASE 0x00 +#define KTD2692_REG_FLASH_TIMEOUT_BASE 0x20 +#define KTD2692_REG_MM_MIN_CURR_THRESHOLD_BASE 0x40 +#define KTD2692_REG_MOVIE_CURRENT_BASE 0x60 +#define KTD2692_REG_FLASH_CURRENT_BASE 0x80 +#define KTD2692_REG_MODE_BASE 0xA0 + +/* Set bit coding time for expresswire interface */ +#define KTD2692_TIME_RESET_US 700 +#define KTD2692_TIME_DATA_START_TIME_US 10 +#define KTD2692_TIME_HIGH_END_OF_DATA_US 350 +#define KTD2692_TIME_LOW_END_OF_DATA_US 10 +#define KTD2692_TIME_SHORT_BITSET_US 4 +#define KTD2692_TIME_LONG_BITSET_US 12 + +/* KTD2692 default length of name */ +#define KTD2692_NAME_LENGTH 20 + +enum ktd2692_bitset { + KTD2692_LOW = 0, + KTD2692_HIGH, +}; + +/* Movie / Flash Mode Control */ +enum ktd2692_led_mode { + KTD2692_MODE_DISABLE = 0, /* default */ + KTD2692_MODE_MOVIE, + KTD2692_MODE_FLASH, +}; + +struct ktd2692_led_config_data { + /* maximum LED current in movie mode */ + u32 movie_max_microamp; + /* maximum LED current in flash mode */ + u32 flash_max_microamp; + /* maximum flash timeout */ + u32 flash_max_timeout; + /* max LED brightness level */ + enum led_brightness max_brightness; +}; + +struct ktd2692_context { + /* Related LED Flash class device */ + struct led_classdev_flash fled_cdev; + + /* secures access to the device */ + struct mutex lock; + struct regulator *regulator; + struct work_struct work_brightness_set; + + struct gpio_desc *aux_gpio; + struct gpio_desc *ctrl_gpio; + + enum ktd2692_led_mode mode; + enum led_brightness torch_brightness; +}; + +static struct ktd2692_context *fled_cdev_to_led( + struct led_classdev_flash *fled_cdev) +{ + return container_of(fled_cdev, struct ktd2692_context, fled_cdev); +} + +static void ktd2692_expresswire_start(struct ktd2692_context *led) +{ + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); + udelay(KTD2692_TIME_DATA_START_TIME_US); +} + +static void ktd2692_expresswire_reset(struct ktd2692_context *led) +{ + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); + udelay(KTD2692_TIME_RESET_US); +} + +static void ktd2692_expresswire_end(struct ktd2692_context *led) +{ + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); + udelay(KTD2692_TIME_LOW_END_OF_DATA_US); + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); + udelay(KTD2692_TIME_HIGH_END_OF_DATA_US); +} + +static void ktd2692_expresswire_set_bit(struct ktd2692_context *led, bool bit) +{ + /* + * The Low Bit(0) and High Bit(1) is based on a time detection + * algorithm between time low and time high + * Time_(L_LB) : Low time of the Low Bit(0) + * Time_(H_LB) : High time of the LOW Bit(0) + * Time_(L_HB) : Low time of the High Bit(1) + * Time_(H_HB) : High time of the High Bit(1) + * + * It can be simplified to: + * Low Bit(0) : 2 * Time_(H_LB) < Time_(L_LB) + * High Bit(1) : 2 * Time_(L_HB) < Time_(H_HB) + * HIGH ___ ____ _.. _________ ___ + * |_________| |_.. |____| |__| + * LOW <L_LB> <H_LB> <L_HB> <H_HB> + * [ Low Bit (0) ] [ High Bit(1) ] + */ + if (bit) { + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); + udelay(KTD2692_TIME_SHORT_BITSET_US); + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); + udelay(KTD2692_TIME_LONG_BITSET_US); + } else { + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); + udelay(KTD2692_TIME_LONG_BITSET_US); + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); + udelay(KTD2692_TIME_SHORT_BITSET_US); + } +} + +static void ktd2692_expresswire_write(struct ktd2692_context *led, u8 value) +{ + int i; + + ktd2692_expresswire_start(led); + for (i = 7; i >= 0; i--) + ktd2692_expresswire_set_bit(led, value & BIT(i)); + ktd2692_expresswire_end(led); +} + +static void ktd2692_brightness_set(struct ktd2692_context *led, + enum led_brightness brightness) +{ + mutex_lock(&led->lock); + + if (brightness == LED_OFF) { + led->mode = KTD2692_MODE_DISABLE; + gpiod_direction_output(led->aux_gpio, KTD2692_LOW); + } else { + ktd2692_expresswire_write(led, brightness | + KTD2692_REG_MOVIE_CURRENT_BASE); + led->mode = KTD2692_MODE_MOVIE; + } + + ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE); + mutex_unlock(&led->lock); +} + +static void ktd2692_brightness_set_work(struct work_struct *work) +{ + struct ktd2692_context *led = + container_of(work, struct ktd2692_context, work_brightness_set); + + ktd2692_brightness_set(led, led->torch_brightness); +} + +static void ktd2692_led_brightness_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(led_cdev); + struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); + + led->torch_brightness = brightness; + schedule_work(&led->work_brightness_set); +} + +static int ktd2692_led_brightness_set_sync(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(led_cdev); + struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); + + ktd2692_brightness_set(led, brightness); + + return 0; +} + +static int ktd2692_led_flash_strobe_set(struct led_classdev_flash *fled_cdev, + bool state) +{ + struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); + struct led_flash_setting *timeout = &fled_cdev->timeout; + u32 flash_tm_reg; + + mutex_lock(&led->lock); + + if (state == 0) { + led->mode = KTD2692_MODE_DISABLE; + gpiod_direction_output(led->aux_gpio, KTD2692_LOW); + } else { + flash_tm_reg = GET_TIMEOUT_OFFSET(timeout->val, timeout->step); + ktd2692_expresswire_write(led, flash_tm_reg + | KTD2692_REG_FLASH_TIMEOUT_BASE); + + led->mode = KTD2692_MODE_FLASH; + gpiod_direction_output(led->aux_gpio, KTD2692_HIGH); + } + + ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE); + + fled_cdev->led_cdev.brightness = LED_OFF; + led->mode = KTD2692_MODE_DISABLE; + + mutex_unlock(&led->lock); + + return 0; +} + +static int ktd2692_led_flash_timeout_set(struct led_classdev_flash *fled_cdev, + u32 timeout) +{ + return 0; +} + +static void ktd2692_init_movie_current_max(struct ktd2692_led_config_data *cfg) +{ + u32 offset, step; + u32 movie_current_microamp; + + offset = KTD2692_MOVIE_MODE_CURRENT_LEVELS; + step = KTD2692_MM_TO_FL_RATIO(cfg->flash_max_microamp) + / KTD2692_MOVIE_MODE_CURRENT_LEVELS; + + do { + movie_current_microamp = step * offset; + offset--; + } while ((movie_current_microamp > cfg->movie_max_microamp) && + (offset > 0)); + + cfg->max_brightness = offset; +} + +static void ktd2692_init_flash_timeout(struct led_classdev_flash *fled_cdev, + struct ktd2692_led_config_data *cfg) +{ + struct led_flash_setting *setting; + + setting = &fled_cdev->timeout; + setting->min = KTD2692_FLASH_MODE_TIMEOUT_DISABLE; + setting->max = cfg->flash_max_timeout; + setting->step = cfg->flash_max_timeout + / (KTD2692_FLASH_MODE_TIMEOUT_LEVELS - 1); + setting->val = cfg->flash_max_timeout; +} + +static void ktd2692_setup(struct ktd2692_context *led) +{ + led->mode = KTD2692_MODE_DISABLE; + ktd2692_expresswire_reset(led); + gpiod_direction_output(led->aux_gpio, KTD2692_LOW); + + ktd2692_expresswire_write(led, (KTD2962_MM_MIN_CURR_THRESHOLD_SCALE - 1) + | KTD2692_REG_MM_MIN_CURR_THRESHOLD_BASE); + ktd2692_expresswire_write(led, KTD2692_FLASH_MODE_CURR_PERCENT(45) + | KTD2692_REG_FLASH_CURRENT_BASE); +} + +static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev, + struct ktd2692_led_config_data *cfg) +{ + struct device_node *np = dev->of_node; + struct device_node *child_node; + int ret; + + if (!dev->of_node) + return -ENXIO; + + led->ctrl_gpio = devm_gpiod_get(dev, "ctrl"); + if (IS_ERR(led->ctrl_gpio)) { + ret = PTR_ERR(led->ctrl_gpio); + dev_err(dev, "cannot get ctrl-gpio %d\n", ret); + return ret; + } + + led->aux_gpio = devm_gpiod_get(dev, "aux"); + if (IS_ERR(led->aux_gpio)) { + ret = PTR_ERR(led->aux_gpio); + dev_err(dev, "cannot get aux-gpio %d\n", ret); + return ret; + } + + led->regulator = devm_regulator_get(dev, "vin"); + if (IS_ERR(led->regulator)) + led->regulator = NULL; + + if (led->regulator) { + ret = regulator_enable(led->regulator); + if (ret) + dev_err(dev, "Failed to enable supply: %d\n", ret); + } + + child_node = of_get_next_available_child(np, NULL); + if (!child_node) { + dev_err(dev, "No DT child node found for connected LED.\n"); + return -EINVAL; + } + + led->fled_cdev.led_cdev.name = + of_get_property(child_node, "label", NULL) ? : child_node->name; + + ret = of_property_read_u32(child_node, "led-max-microamp", + &cfg->movie_max_microamp); + if (ret) { + dev_err(dev, "failed to parse led-max-microamp\n"); + return ret; + } + + ret = of_property_read_u32(child_node, "flash-max-microamp", + &cfg->flash_max_microamp); + if (ret) { + dev_err(dev, "failed to parse flash-max-microamp\n"); + return ret; + } + + ret = of_property_read_u32(child_node, "flash-max-timeout-us", + &cfg->flash_max_timeout); + if (ret) + dev_err(dev, "failed to parse flash-max-timeout-us\n"); + + of_node_put(child_node); + return ret; +} + +static const struct led_flash_ops flash_ops = { + .strobe_set = ktd2692_led_flash_strobe_set, + .timeout_set = ktd2692_led_flash_timeout_set, +}; + +static int ktd2692_probe(struct platform_device *pdev) +{ + struct ktd2692_context *led; + struct led_classdev *led_cdev; + struct led_classdev_flash *fled_cdev; + struct ktd2692_led_config_data led_cfg; + int ret; + + led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); + if (!led) + return -ENOMEM; + + fled_cdev = &led->fled_cdev; + led_cdev = &fled_cdev->led_cdev; + + ret = ktd2692_parse_dt(led, &pdev->dev, &led_cfg); + if (ret) + return ret; + + ktd2692_init_flash_timeout(fled_cdev, &led_cfg); + ktd2692_init_movie_current_max(&led_cfg); + + fled_cdev->ops = &flash_ops; + + led_cdev->max_brightness = led_cfg.max_brightness; + led_cdev->brightness_set = ktd2692_led_brightness_set; + led_cdev->brightness_set_sync = ktd2692_led_brightness_set_sync; + led_cdev->flags |= LED_CORE_SUSPENDRESUME | LED_DEV_CAP_FLASH; + + mutex_init(&led->lock); + INIT_WORK(&led->work_brightness_set, ktd2692_brightness_set_work); + + platform_set_drvdata(pdev, led); + + ret = led_classdev_flash_register(&pdev->dev, fled_cdev); + if (ret) { + dev_err(&pdev->dev, "can't register LED %s\n", led_cdev->name); + mutex_destroy(&led->lock); + return ret; + } + + ktd2692_setup(led); + + return 0; +} + +static int ktd2692_remove(struct platform_device *pdev) +{ + struct ktd2692_context *led = platform_get_drvdata(pdev); + int ret; + + led_classdev_flash_unregister(&led->fled_cdev); + cancel_work_sync(&led->work_brightness_set); + + if (led->regulator) { + ret = regulator_disable(led->regulator); + if (ret) + dev_err(&pdev->dev, + "Failed to disable supply: %d\n", ret); + } + + mutex_destroy(&led->lock); + + return 0; +} + +static const struct of_device_id ktd2692_match[] = { + { .compatible = "kinetic,ktd2692", }, + { /* sentinel */ }, +}; + +static struct platform_driver ktd2692_driver = { + .driver = { + .name = "ktd2692", + .of_match_table = ktd2692_match, + }, + .probe = ktd2692_probe, + .remove = ktd2692_remove, +}; + +module_platform_driver(ktd2692_driver); + +MODULE_AUTHOR("Ingi Kim <ingi2.kim@samsung.com>"); +MODULE_DESCRIPTION("Kinetic KTD2692 LED driver"); +MODULE_LICENSE("GPL v2"); -- 2.0.5 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v8 3/3] leds: Add ktd2692 flash LED driver 2015-05-08 3:03 ` [PATCH v8 3/3] leds: Add ktd2692 flash LED driver Ingi Kim @ 2015-05-08 8:33 ` Jacek Anaszewski 2015-05-11 2:24 ` Ingi Kim 2015-05-08 9:06 ` Jacek Anaszewski 1 sibling, 1 reply; 9+ messages in thread From: Jacek Anaszewski @ 2015-05-08 8:33 UTC (permalink / raw) To: Ingi Kim Cc: cooloney, rpurdie, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, sakari.ailus, varkabhadram, joe, sw0312.kim, cw00.choi, jh80.chung, ideal.song, devicetree, linux-kernel, linux-leds Hi Ingi, Thanks for the update. It looks like we're almost there. I can see only two minor issues. On 05/08/2015 05:03 AM, Ingi Kim wrote: > This patch adds a driver to support the ktd2692 flash LEDs. > ktd2692 can control flash current by ExpressWire interface. > > Signed-off-by: Ingi Kim <ingi2.kim@samsung.com> > Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> > Reviewed-by: Varka Bhadram <varkabhadram@gmail.com> > --- > drivers/leds/Kconfig | 9 + > drivers/leds/Makefile | 1 + > drivers/leds/leds-ktd2692.c | 443 ++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 453 insertions(+) > create mode 100644 drivers/leds/leds-ktd2692.c > > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > index 51059bb..bfbdbd1 100644 > --- a/drivers/leds/Kconfig > +++ b/drivers/leds/Kconfig > @@ -505,6 +505,15 @@ config LEDS_MENF21BMC > This driver can also be built as a module. If so the module > will be called leds-menf21bmc. > > +config LEDS_KTD2692 > + tristate "KTD2692 LED flash support" Please keep the style of description in line with the existing drivers. How about: "LED support for KTD2692 flash LED controller" > + depends on LEDS_CLASS_FLASH && GPIOLIB && OF > + help > + This option enables support for KTD2692 LED flash connected > + through ExpressWire interface. > + > + Say Y to enable this driver. > + > comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" > > config LEDS_BLINKM > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > index a739ae2..ed5ed79 100644 > --- a/drivers/leds/Makefile > +++ b/drivers/leds/Makefile > @@ -59,6 +59,7 @@ obj-$(CONFIG_LEDS_BLINKM) += leds-blinkm.o > obj-$(CONFIG_LEDS_SYSCON) += leds-syscon.o > obj-$(CONFIG_LEDS_VERSATILE) += leds-versatile.o > obj-$(CONFIG_LEDS_MENF21BMC) += leds-menf21bmc.o > +obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o > > # LED SPI Drivers > obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o > diff --git a/drivers/leds/leds-ktd2692.c b/drivers/leds/leds-ktd2692.c > new file mode 100644 > index 0000000..9d878a4 > --- /dev/null > +++ b/drivers/leds/leds-ktd2692.c > @@ -0,0 +1,443 @@ > +/* > + * LED driver : leds-ktd2692.c > + * > + * Copyright (C) 2015 Samsung Electronics > + * Ingi Kim <ingi2.kim@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 <linux/delay.h> > +#include <linux/err.h> > +#include <linux/gpio/consumer.h> > +#include <linux/led-class-flash.h> > +#include <linux/module.h> > +#include <linux/mutex.h> > +#include <linux/of.h> > +#include <linux/platform_device.h> > +#include <linux/regulator/consumer.h> > +#include <linux/workqueue.h> > + > +/* Value related the movie mode */ > +#define KTD2692_MOVIE_MODE_CURRENT_LEVELS 16 > +#define KTD2692_MM_TO_FL_RATIO(x) ((x) / 3) > +#define KTD2962_MM_MIN_CURR_THRESHOLD_SCALE 8 > + > +/* Value related the flash mode */ > +#define KTD2692_FLASH_MODE_TIMEOUT_LEVELS 8 > +#define KTD2692_FLASH_MODE_TIMEOUT_DISABLE 0 > +#define KTD2692_FLASH_MODE_CURR_PERCENT(x) (((x) * 16) / 100) > + > +/* Macro for getting offset of flash timeout */ > +#define GET_TIMEOUT_OFFSET(timeout, step) ((timeout) / (step)) > + > +/* Base register address */ > +#define KTD2692_REG_LVP_BASE 0x00 > +#define KTD2692_REG_FLASH_TIMEOUT_BASE 0x20 > +#define KTD2692_REG_MM_MIN_CURR_THRESHOLD_BASE 0x40 > +#define KTD2692_REG_MOVIE_CURRENT_BASE 0x60 > +#define KTD2692_REG_FLASH_CURRENT_BASE 0x80 > +#define KTD2692_REG_MODE_BASE 0xA0 > + > +/* Set bit coding time for expresswire interface */ > +#define KTD2692_TIME_RESET_US 700 > +#define KTD2692_TIME_DATA_START_TIME_US 10 > +#define KTD2692_TIME_HIGH_END_OF_DATA_US 350 > +#define KTD2692_TIME_LOW_END_OF_DATA_US 10 > +#define KTD2692_TIME_SHORT_BITSET_US 4 > +#define KTD2692_TIME_LONG_BITSET_US 12 > + > +/* KTD2692 default length of name */ > +#define KTD2692_NAME_LENGTH 20 > + > +enum ktd2692_bitset { > + KTD2692_LOW = 0, > + KTD2692_HIGH, > +}; > + > +/* Movie / Flash Mode Control */ > +enum ktd2692_led_mode { > + KTD2692_MODE_DISABLE = 0, /* default */ > + KTD2692_MODE_MOVIE, > + KTD2692_MODE_FLASH, > +}; > + > +struct ktd2692_led_config_data { > + /* maximum LED current in movie mode */ > + u32 movie_max_microamp; > + /* maximum LED current in flash mode */ > + u32 flash_max_microamp; > + /* maximum flash timeout */ > + u32 flash_max_timeout; > + /* max LED brightness level */ > + enum led_brightness max_brightness; > +}; > + > +struct ktd2692_context { > + /* Related LED Flash class device */ > + struct led_classdev_flash fled_cdev; > + > + /* secures access to the device */ > + struct mutex lock; > + struct regulator *regulator; > + struct work_struct work_brightness_set; > + > + struct gpio_desc *aux_gpio; > + struct gpio_desc *ctrl_gpio; > + > + enum ktd2692_led_mode mode; > + enum led_brightness torch_brightness; > +}; > + > +static struct ktd2692_context *fled_cdev_to_led( > + struct led_classdev_flash *fled_cdev) > +{ > + return container_of(fled_cdev, struct ktd2692_context, fled_cdev); > +} > + > +static void ktd2692_expresswire_start(struct ktd2692_context *led) > +{ > + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); > + udelay(KTD2692_TIME_DATA_START_TIME_US); > +} > + > +static void ktd2692_expresswire_reset(struct ktd2692_context *led) > +{ > + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); > + udelay(KTD2692_TIME_RESET_US); > +} > + > +static void ktd2692_expresswire_end(struct ktd2692_context *led) > +{ > + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); > + udelay(KTD2692_TIME_LOW_END_OF_DATA_US); > + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); > + udelay(KTD2692_TIME_HIGH_END_OF_DATA_US); > +} > + > +static void ktd2692_expresswire_set_bit(struct ktd2692_context *led, bool bit) > +{ > + /* > + * The Low Bit(0) and High Bit(1) is based on a time detection > + * algorithm between time low and time high > + * Time_(L_LB) : Low time of the Low Bit(0) > + * Time_(H_LB) : High time of the LOW Bit(0) > + * Time_(L_HB) : Low time of the High Bit(1) > + * Time_(H_HB) : High time of the High Bit(1) > + * > + * It can be simplified to: > + * Low Bit(0) : 2 * Time_(H_LB) < Time_(L_LB) > + * High Bit(1) : 2 * Time_(L_HB) < Time_(H_HB) > + * HIGH ___ ____ _.. _________ ___ > + * |_________| |_.. |____| |__| > + * LOW <L_LB> <H_LB> <L_HB> <H_HB> > + * [ Low Bit (0) ] [ High Bit(1) ] > + */ > + if (bit) { > + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); > + udelay(KTD2692_TIME_SHORT_BITSET_US); > + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); > + udelay(KTD2692_TIME_LONG_BITSET_US); > + } else { > + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); > + udelay(KTD2692_TIME_LONG_BITSET_US); > + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); > + udelay(KTD2692_TIME_SHORT_BITSET_US); > + } > +} > + > +static void ktd2692_expresswire_write(struct ktd2692_context *led, u8 value) > +{ > + int i; > + > + ktd2692_expresswire_start(led); > + for (i = 7; i >= 0; i--) > + ktd2692_expresswire_set_bit(led, value & BIT(i)); > + ktd2692_expresswire_end(led); > +} > + > +static void ktd2692_brightness_set(struct ktd2692_context *led, > + enum led_brightness brightness) > +{ > + mutex_lock(&led->lock); > + > + if (brightness == LED_OFF) { > + led->mode = KTD2692_MODE_DISABLE; > + gpiod_direction_output(led->aux_gpio, KTD2692_LOW); > + } else { > + ktd2692_expresswire_write(led, brightness | > + KTD2692_REG_MOVIE_CURRENT_BASE); > + led->mode = KTD2692_MODE_MOVIE; > + } > + > + ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE); > + mutex_unlock(&led->lock); > +} > + > +static void ktd2692_brightness_set_work(struct work_struct *work) > +{ > + struct ktd2692_context *led = > + container_of(work, struct ktd2692_context, work_brightness_set); > + > + ktd2692_brightness_set(led, led->torch_brightness); > +} > + > +static void ktd2692_led_brightness_set(struct led_classdev *led_cdev, > + enum led_brightness brightness) > +{ > + struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(led_cdev); > + struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); > + > + led->torch_brightness = brightness; > + schedule_work(&led->work_brightness_set); > +} > + > +static int ktd2692_led_brightness_set_sync(struct led_classdev *led_cdev, > + enum led_brightness brightness) > +{ > + struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(led_cdev); > + struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); > + > + ktd2692_brightness_set(led, brightness); > + > + return 0; > +} > + > +static int ktd2692_led_flash_strobe_set(struct led_classdev_flash *fled_cdev, > + bool state) > +{ > + struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); > + struct led_flash_setting *timeout = &fled_cdev->timeout; > + u32 flash_tm_reg; > + > + mutex_lock(&led->lock); > + > + if (state == 0) { Coccinelle raises a warning here: drivers/leds/leds-ktd2692.c:217:5-10: WARNING: Comparison of bool to 0/1 I had to fix it also in my leds-aat1290 driver recently:) > + led->mode = KTD2692_MODE_DISABLE; > + gpiod_direction_output(led->aux_gpio, KTD2692_LOW); > + } else { > + flash_tm_reg = GET_TIMEOUT_OFFSET(timeout->val, timeout->step); > + ktd2692_expresswire_write(led, flash_tm_reg > + | KTD2692_REG_FLASH_TIMEOUT_BASE); > + > + led->mode = KTD2692_MODE_FLASH; > + gpiod_direction_output(led->aux_gpio, KTD2692_HIGH); > + } > + > + ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE); > + > + fled_cdev->led_cdev.brightness = LED_OFF; > + led->mode = KTD2692_MODE_DISABLE; > + > + mutex_unlock(&led->lock); > + > + return 0; > +} > + > +static int ktd2692_led_flash_timeout_set(struct led_classdev_flash *fled_cdev, > + u32 timeout) > +{ > + return 0; > +} > + > +static void ktd2692_init_movie_current_max(struct ktd2692_led_config_data *cfg) > +{ > + u32 offset, step; > + u32 movie_current_microamp; > + > + offset = KTD2692_MOVIE_MODE_CURRENT_LEVELS; > + step = KTD2692_MM_TO_FL_RATIO(cfg->flash_max_microamp) > + / KTD2692_MOVIE_MODE_CURRENT_LEVELS; > + > + do { > + movie_current_microamp = step * offset; > + offset--; > + } while ((movie_current_microamp > cfg->movie_max_microamp) && > + (offset > 0)); > + > + cfg->max_brightness = offset; > +} > + > +static void ktd2692_init_flash_timeout(struct led_classdev_flash *fled_cdev, > + struct ktd2692_led_config_data *cfg) > +{ > + struct led_flash_setting *setting; > + > + setting = &fled_cdev->timeout; > + setting->min = KTD2692_FLASH_MODE_TIMEOUT_DISABLE; > + setting->max = cfg->flash_max_timeout; > + setting->step = cfg->flash_max_timeout > + / (KTD2692_FLASH_MODE_TIMEOUT_LEVELS - 1); > + setting->val = cfg->flash_max_timeout; > +} > + > +static void ktd2692_setup(struct ktd2692_context *led) > +{ > + led->mode = KTD2692_MODE_DISABLE; > + ktd2692_expresswire_reset(led); > + gpiod_direction_output(led->aux_gpio, KTD2692_LOW); > + > + ktd2692_expresswire_write(led, (KTD2962_MM_MIN_CURR_THRESHOLD_SCALE - 1) > + | KTD2692_REG_MM_MIN_CURR_THRESHOLD_BASE); > + ktd2692_expresswire_write(led, KTD2692_FLASH_MODE_CURR_PERCENT(45) > + | KTD2692_REG_FLASH_CURRENT_BASE); > +} > + > +static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev, > + struct ktd2692_led_config_data *cfg) > +{ > + struct device_node *np = dev->of_node; > + struct device_node *child_node; > + int ret; > + > + if (!dev->of_node) > + return -ENXIO; > + > + led->ctrl_gpio = devm_gpiod_get(dev, "ctrl"); > + if (IS_ERR(led->ctrl_gpio)) { > + ret = PTR_ERR(led->ctrl_gpio); > + dev_err(dev, "cannot get ctrl-gpio %d\n", ret); > + return ret; > + } > + > + led->aux_gpio = devm_gpiod_get(dev, "aux"); > + if (IS_ERR(led->aux_gpio)) { > + ret = PTR_ERR(led->aux_gpio); > + dev_err(dev, "cannot get aux-gpio %d\n", ret); > + return ret; > + } > + > + led->regulator = devm_regulator_get(dev, "vin"); > + if (IS_ERR(led->regulator)) > + led->regulator = NULL; > + > + if (led->regulator) { > + ret = regulator_enable(led->regulator); > + if (ret) > + dev_err(dev, "Failed to enable supply: %d\n", ret); > + } > + > + child_node = of_get_next_available_child(np, NULL); > + if (!child_node) { > + dev_err(dev, "No DT child node found for connected LED.\n"); > + return -EINVAL; > + } > + > + led->fled_cdev.led_cdev.name = > + of_get_property(child_node, "label", NULL) ? : child_node->name; > + > + ret = of_property_read_u32(child_node, "led-max-microamp", > + &cfg->movie_max_microamp); > + if (ret) { > + dev_err(dev, "failed to parse led-max-microamp\n"); > + return ret; > + } > + > + ret = of_property_read_u32(child_node, "flash-max-microamp", > + &cfg->flash_max_microamp); > + if (ret) { > + dev_err(dev, "failed to parse flash-max-microamp\n"); > + return ret; > + } > + > + ret = of_property_read_u32(child_node, "flash-max-timeout-us", > + &cfg->flash_max_timeout); > + if (ret) > + dev_err(dev, "failed to parse flash-max-timeout-us\n"); > + > + of_node_put(child_node); > + return ret; > +} > + > +static const struct led_flash_ops flash_ops = { > + .strobe_set = ktd2692_led_flash_strobe_set, > + .timeout_set = ktd2692_led_flash_timeout_set, > +}; > + > +static int ktd2692_probe(struct platform_device *pdev) > +{ > + struct ktd2692_context *led; > + struct led_classdev *led_cdev; > + struct led_classdev_flash *fled_cdev; > + struct ktd2692_led_config_data led_cfg; > + int ret; > + > + led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); > + if (!led) > + return -ENOMEM; > + > + fled_cdev = &led->fled_cdev; > + led_cdev = &fled_cdev->led_cdev; > + > + ret = ktd2692_parse_dt(led, &pdev->dev, &led_cfg); > + if (ret) > + return ret; > + > + ktd2692_init_flash_timeout(fled_cdev, &led_cfg); > + ktd2692_init_movie_current_max(&led_cfg); > + > + fled_cdev->ops = &flash_ops; > + > + led_cdev->max_brightness = led_cfg.max_brightness; > + led_cdev->brightness_set = ktd2692_led_brightness_set; > + led_cdev->brightness_set_sync = ktd2692_led_brightness_set_sync; > + led_cdev->flags |= LED_CORE_SUSPENDRESUME | LED_DEV_CAP_FLASH; > + > + mutex_init(&led->lock); > + INIT_WORK(&led->work_brightness_set, ktd2692_brightness_set_work); > + > + platform_set_drvdata(pdev, led); > + > + ret = led_classdev_flash_register(&pdev->dev, fled_cdev); > + if (ret) { > + dev_err(&pdev->dev, "can't register LED %s\n", led_cdev->name); > + mutex_destroy(&led->lock); > + return ret; > + } > + > + ktd2692_setup(led); > + > + return 0; > +} > + > +static int ktd2692_remove(struct platform_device *pdev) > +{ > + struct ktd2692_context *led = platform_get_drvdata(pdev); > + int ret; > + > + led_classdev_flash_unregister(&led->fled_cdev); > + cancel_work_sync(&led->work_brightness_set); > + > + if (led->regulator) { > + ret = regulator_disable(led->regulator); > + if (ret) > + dev_err(&pdev->dev, > + "Failed to disable supply: %d\n", ret); > + } > + > + mutex_destroy(&led->lock); > + > + return 0; > +} > + > +static const struct of_device_id ktd2692_match[] = { > + { .compatible = "kinetic,ktd2692", }, > + { /* sentinel */ }, > +}; > + > +static struct platform_driver ktd2692_driver = { > + .driver = { > + .name = "ktd2692", > + .of_match_table = ktd2692_match, > + }, > + .probe = ktd2692_probe, > + .remove = ktd2692_remove, > +}; > + > +module_platform_driver(ktd2692_driver); > + > +MODULE_AUTHOR("Ingi Kim <ingi2.kim@samsung.com>"); > +MODULE_DESCRIPTION("Kinetic KTD2692 LED driver"); > +MODULE_LICENSE("GPL v2"); > -- Best Regards, Jacek Anaszewski ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v8 3/3] leds: Add ktd2692 flash LED driver 2015-05-08 8:33 ` Jacek Anaszewski @ 2015-05-11 2:24 ` Ingi Kim 0 siblings, 0 replies; 9+ messages in thread From: Ingi Kim @ 2015-05-11 2:24 UTC (permalink / raw) To: Jacek Anaszewski Cc: cooloney, rpurdie, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, sakari.ailus, varkabhadram, joe, sw0312.kim, cw00.choi, jh80.chung, ideal.song, devicetree, linux-kernel, linux-leds Hi Jacek, Thanks for the review I can improve this driver for your attention I'm trying to rebase source code for merging it and resending soon. Thank you On 2015년 05월 08일 17:33, Jacek Anaszewski wrote: > Hi Ingi, > > Thanks for the update. It looks like we're almost there. > I can see only two minor issues. > > On 05/08/2015 05:03 AM, Ingi Kim wrote: >> This patch adds a driver to support the ktd2692 flash LEDs. >> ktd2692 can control flash current by ExpressWire interface. >> >> Signed-off-by: Ingi Kim <ingi2.kim@samsung.com> >> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> >> Reviewed-by: Varka Bhadram <varkabhadram@gmail.com> >> --- >> drivers/leds/Kconfig | 9 + >> drivers/leds/Makefile | 1 + >> drivers/leds/leds-ktd2692.c | 443 ++++++++++++++++++++++++++++++++++++++++++++ >> 3 files changed, 453 insertions(+) >> create mode 100644 drivers/leds/leds-ktd2692.c >> >> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig >> index 51059bb..bfbdbd1 100644 >> --- a/drivers/leds/Kconfig >> +++ b/drivers/leds/Kconfig >> @@ -505,6 +505,15 @@ config LEDS_MENF21BMC >> This driver can also be built as a module. If so the module >> will be called leds-menf21bmc. >> >> +config LEDS_KTD2692 >> + tristate "KTD2692 LED flash support" > > Please keep the style of description in line with the existing > drivers. How about: > > "LED support for KTD2692 flash LED controller" > Sure, I'll change it >> + depends on LEDS_CLASS_FLASH && GPIOLIB && OF >> + help >> + This option enables support for KTD2692 LED flash connected >> + through ExpressWire interface. >> + >> + Say Y to enable this driver. >> + >> comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" >> >> config LEDS_BLINKM >> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile >> index a739ae2..ed5ed79 100644 >> --- a/drivers/leds/Makefile >> +++ b/drivers/leds/Makefile >> @@ -59,6 +59,7 @@ obj-$(CONFIG_LEDS_BLINKM) += leds-blinkm.o >> obj-$(CONFIG_LEDS_SYSCON) += leds-syscon.o >> obj-$(CONFIG_LEDS_VERSATILE) += leds-versatile.o >> obj-$(CONFIG_LEDS_MENF21BMC) += leds-menf21bmc.o >> +obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o >> >> # LED SPI Drivers >> obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o >> diff --git a/drivers/leds/leds-ktd2692.c b/drivers/leds/leds-ktd2692.c >> new file mode 100644 >> index 0000000..9d878a4 >> --- /dev/null >> +++ b/drivers/leds/leds-ktd2692.c >> @@ -0,0 +1,443 @@ >> +/* >> + * LED driver : leds-ktd2692.c >> + * >> + * Copyright (C) 2015 Samsung Electronics >> + * Ingi Kim <ingi2.kim@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 <linux/delay.h> >> +#include <linux/err.h> >> +#include <linux/gpio/consumer.h> >> +#include <linux/led-class-flash.h> >> +#include <linux/module.h> >> +#include <linux/mutex.h> >> +#include <linux/of.h> >> +#include <linux/platform_device.h> >> +#include <linux/regulator/consumer.h> >> +#include <linux/workqueue.h> >> + >> +/* Value related the movie mode */ >> +#define KTD2692_MOVIE_MODE_CURRENT_LEVELS 16 >> +#define KTD2692_MM_TO_FL_RATIO(x) ((x) / 3) >> +#define KTD2962_MM_MIN_CURR_THRESHOLD_SCALE 8 >> + >> +/* Value related the flash mode */ >> +#define KTD2692_FLASH_MODE_TIMEOUT_LEVELS 8 >> +#define KTD2692_FLASH_MODE_TIMEOUT_DISABLE 0 >> +#define KTD2692_FLASH_MODE_CURR_PERCENT(x) (((x) * 16) / 100) >> + >> +/* Macro for getting offset of flash timeout */ >> +#define GET_TIMEOUT_OFFSET(timeout, step) ((timeout) / (step)) >> + >> +/* Base register address */ >> +#define KTD2692_REG_LVP_BASE 0x00 >> +#define KTD2692_REG_FLASH_TIMEOUT_BASE 0x20 >> +#define KTD2692_REG_MM_MIN_CURR_THRESHOLD_BASE 0x40 >> +#define KTD2692_REG_MOVIE_CURRENT_BASE 0x60 >> +#define KTD2692_REG_FLASH_CURRENT_BASE 0x80 >> +#define KTD2692_REG_MODE_BASE 0xA0 >> + >> +/* Set bit coding time for expresswire interface */ >> +#define KTD2692_TIME_RESET_US 700 >> +#define KTD2692_TIME_DATA_START_TIME_US 10 >> +#define KTD2692_TIME_HIGH_END_OF_DATA_US 350 >> +#define KTD2692_TIME_LOW_END_OF_DATA_US 10 >> +#define KTD2692_TIME_SHORT_BITSET_US 4 >> +#define KTD2692_TIME_LONG_BITSET_US 12 >> + >> +/* KTD2692 default length of name */ >> +#define KTD2692_NAME_LENGTH 20 >> + >> +enum ktd2692_bitset { >> + KTD2692_LOW = 0, >> + KTD2692_HIGH, >> +}; >> + >> +/* Movie / Flash Mode Control */ >> +enum ktd2692_led_mode { >> + KTD2692_MODE_DISABLE = 0, /* default */ >> + KTD2692_MODE_MOVIE, >> + KTD2692_MODE_FLASH, >> +}; >> + >> +struct ktd2692_led_config_data { >> + /* maximum LED current in movie mode */ >> + u32 movie_max_microamp; >> + /* maximum LED current in flash mode */ >> + u32 flash_max_microamp; >> + /* maximum flash timeout */ >> + u32 flash_max_timeout; >> + /* max LED brightness level */ >> + enum led_brightness max_brightness; >> +}; >> + >> +struct ktd2692_context { >> + /* Related LED Flash class device */ >> + struct led_classdev_flash fled_cdev; >> + >> + /* secures access to the device */ >> + struct mutex lock; >> + struct regulator *regulator; >> + struct work_struct work_brightness_set; >> + >> + struct gpio_desc *aux_gpio; >> + struct gpio_desc *ctrl_gpio; >> + >> + enum ktd2692_led_mode mode; >> + enum led_brightness torch_brightness; >> +}; >> + >> +static struct ktd2692_context *fled_cdev_to_led( >> + struct led_classdev_flash *fled_cdev) >> +{ >> + return container_of(fled_cdev, struct ktd2692_context, fled_cdev); >> +} >> + >> +static void ktd2692_expresswire_start(struct ktd2692_context *led) >> +{ >> + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); >> + udelay(KTD2692_TIME_DATA_START_TIME_US); >> +} >> + >> +static void ktd2692_expresswire_reset(struct ktd2692_context *led) >> +{ >> + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); >> + udelay(KTD2692_TIME_RESET_US); >> +} >> + >> +static void ktd2692_expresswire_end(struct ktd2692_context *led) >> +{ >> + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); >> + udelay(KTD2692_TIME_LOW_END_OF_DATA_US); >> + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); >> + udelay(KTD2692_TIME_HIGH_END_OF_DATA_US); >> +} >> + >> +static void ktd2692_expresswire_set_bit(struct ktd2692_context *led, bool bit) >> +{ >> + /* >> + * The Low Bit(0) and High Bit(1) is based on a time detection >> + * algorithm between time low and time high >> + * Time_(L_LB) : Low time of the Low Bit(0) >> + * Time_(H_LB) : High time of the LOW Bit(0) >> + * Time_(L_HB) : Low time of the High Bit(1) >> + * Time_(H_HB) : High time of the High Bit(1) >> + * >> + * It can be simplified to: >> + * Low Bit(0) : 2 * Time_(H_LB) < Time_(L_LB) >> + * High Bit(1) : 2 * Time_(L_HB) < Time_(H_HB) >> + * HIGH ___ ____ _.. _________ ___ >> + * |_________| |_.. |____| |__| >> + * LOW <L_LB> <H_LB> <L_HB> <H_HB> >> + * [ Low Bit (0) ] [ High Bit(1) ] >> + */ >> + if (bit) { >> + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); >> + udelay(KTD2692_TIME_SHORT_BITSET_US); >> + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); >> + udelay(KTD2692_TIME_LONG_BITSET_US); >> + } else { >> + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); >> + udelay(KTD2692_TIME_LONG_BITSET_US); >> + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); >> + udelay(KTD2692_TIME_SHORT_BITSET_US); >> + } >> +} >> + >> +static void ktd2692_expresswire_write(struct ktd2692_context *led, u8 value) >> +{ >> + int i; >> + >> + ktd2692_expresswire_start(led); >> + for (i = 7; i >= 0; i--) >> + ktd2692_expresswire_set_bit(led, value & BIT(i)); >> + ktd2692_expresswire_end(led); >> +} >> + >> +static void ktd2692_brightness_set(struct ktd2692_context *led, >> + enum led_brightness brightness) >> +{ >> + mutex_lock(&led->lock); >> + >> + if (brightness == LED_OFF) { >> + led->mode = KTD2692_MODE_DISABLE; >> + gpiod_direction_output(led->aux_gpio, KTD2692_LOW); >> + } else { >> + ktd2692_expresswire_write(led, brightness | >> + KTD2692_REG_MOVIE_CURRENT_BASE); >> + led->mode = KTD2692_MODE_MOVIE; >> + } >> + >> + ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE); >> + mutex_unlock(&led->lock); >> +} >> + >> +static void ktd2692_brightness_set_work(struct work_struct *work) >> +{ >> + struct ktd2692_context *led = >> + container_of(work, struct ktd2692_context, work_brightness_set); >> + >> + ktd2692_brightness_set(led, led->torch_brightness); >> +} >> + >> +static void ktd2692_led_brightness_set(struct led_classdev *led_cdev, >> + enum led_brightness brightness) >> +{ >> + struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(led_cdev); >> + struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); >> + >> + led->torch_brightness = brightness; >> + schedule_work(&led->work_brightness_set); >> +} >> + >> +static int ktd2692_led_brightness_set_sync(struct led_classdev *led_cdev, >> + enum led_brightness brightness) >> +{ >> + struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(led_cdev); >> + struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); >> + >> + ktd2692_brightness_set(led, brightness); >> + >> + return 0; >> +} >> + >> +static int ktd2692_led_flash_strobe_set(struct led_classdev_flash *fled_cdev, >> + bool state) >> +{ >> + struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); >> + struct led_flash_setting *timeout = &fled_cdev->timeout; >> + u32 flash_tm_reg; >> + >> + mutex_lock(&led->lock); >> + >> + if (state == 0) { > > Coccinelle raises a warning here: > > drivers/leds/leds-ktd2692.c:217:5-10: WARNING: Comparison of bool to 0/1 > > I had to fix it also in my leds-aat1290 driver recently:) > Ok, I'll refer to your driver code Thank you, so kindly :) >> + led->mode = KTD2692_MODE_DISABLE; >> + gpiod_direction_output(led->aux_gpio, KTD2692_LOW); >> + } else { >> + flash_tm_reg = GET_TIMEOUT_OFFSET(timeout->val, timeout->step); >> + ktd2692_expresswire_write(led, flash_tm_reg >> + | KTD2692_REG_FLASH_TIMEOUT_BASE); >> + >> + led->mode = KTD2692_MODE_FLASH; >> + gpiod_direction_output(led->aux_gpio, KTD2692_HIGH); >> + } >> + >> + ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE); >> + >> + fled_cdev->led_cdev.brightness = LED_OFF; >> + led->mode = KTD2692_MODE_DISABLE; >> + >> + mutex_unlock(&led->lock); >> + >> + return 0; >> +} >> + >> +static int ktd2692_led_flash_timeout_set(struct led_classdev_flash *fled_cdev, >> + u32 timeout) >> +{ >> + return 0; >> +} >> + >> +static void ktd2692_init_movie_current_max(struct ktd2692_led_config_data *cfg) >> +{ >> + u32 offset, step; >> + u32 movie_current_microamp; >> + >> + offset = KTD2692_MOVIE_MODE_CURRENT_LEVELS; >> + step = KTD2692_MM_TO_FL_RATIO(cfg->flash_max_microamp) >> + / KTD2692_MOVIE_MODE_CURRENT_LEVELS; >> + >> + do { >> + movie_current_microamp = step * offset; >> + offset--; >> + } while ((movie_current_microamp > cfg->movie_max_microamp) && >> + (offset > 0)); >> + >> + cfg->max_brightness = offset; >> +} >> + >> +static void ktd2692_init_flash_timeout(struct led_classdev_flash *fled_cdev, >> + struct ktd2692_led_config_data *cfg) >> +{ >> + struct led_flash_setting *setting; >> + >> + setting = &fled_cdev->timeout; >> + setting->min = KTD2692_FLASH_MODE_TIMEOUT_DISABLE; >> + setting->max = cfg->flash_max_timeout; >> + setting->step = cfg->flash_max_timeout >> + / (KTD2692_FLASH_MODE_TIMEOUT_LEVELS - 1); >> + setting->val = cfg->flash_max_timeout; >> +} >> + >> +static void ktd2692_setup(struct ktd2692_context *led) >> +{ >> + led->mode = KTD2692_MODE_DISABLE; >> + ktd2692_expresswire_reset(led); >> + gpiod_direction_output(led->aux_gpio, KTD2692_LOW); >> + >> + ktd2692_expresswire_write(led, (KTD2962_MM_MIN_CURR_THRESHOLD_SCALE - 1) >> + | KTD2692_REG_MM_MIN_CURR_THRESHOLD_BASE); >> + ktd2692_expresswire_write(led, KTD2692_FLASH_MODE_CURR_PERCENT(45) >> + | KTD2692_REG_FLASH_CURRENT_BASE); >> +} >> + >> +static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev, >> + struct ktd2692_led_config_data *cfg) >> +{ >> + struct device_node *np = dev->of_node; >> + struct device_node *child_node; >> + int ret; >> + >> + if (!dev->of_node) >> + return -ENXIO; >> + >> + led->ctrl_gpio = devm_gpiod_get(dev, "ctrl"); >> + if (IS_ERR(led->ctrl_gpio)) { >> + ret = PTR_ERR(led->ctrl_gpio); >> + dev_err(dev, "cannot get ctrl-gpio %d\n", ret); >> + return ret; >> + } >> + >> + led->aux_gpio = devm_gpiod_get(dev, "aux"); >> + if (IS_ERR(led->aux_gpio)) { >> + ret = PTR_ERR(led->aux_gpio); >> + dev_err(dev, "cannot get aux-gpio %d\n", ret); >> + return ret; >> + } >> + >> + led->regulator = devm_regulator_get(dev, "vin"); >> + if (IS_ERR(led->regulator)) >> + led->regulator = NULL; >> + >> + if (led->regulator) { >> + ret = regulator_enable(led->regulator); >> + if (ret) >> + dev_err(dev, "Failed to enable supply: %d\n", ret); >> + } >> + >> + child_node = of_get_next_available_child(np, NULL); >> + if (!child_node) { >> + dev_err(dev, "No DT child node found for connected LED.\n"); >> + return -EINVAL; >> + } >> + >> + led->fled_cdev.led_cdev.name = >> + of_get_property(child_node, "label", NULL) ? : child_node->name; >> + >> + ret = of_property_read_u32(child_node, "led-max-microamp", >> + &cfg->movie_max_microamp); >> + if (ret) { >> + dev_err(dev, "failed to parse led-max-microamp\n"); >> + return ret; >> + } >> + >> + ret = of_property_read_u32(child_node, "flash-max-microamp", >> + &cfg->flash_max_microamp); >> + if (ret) { >> + dev_err(dev, "failed to parse flash-max-microamp\n"); >> + return ret; >> + } >> + >> + ret = of_property_read_u32(child_node, "flash-max-timeout-us", >> + &cfg->flash_max_timeout); >> + if (ret) >> + dev_err(dev, "failed to parse flash-max-timeout-us\n"); >> + >> + of_node_put(child_node); >> + return ret; >> +} >> + >> +static const struct led_flash_ops flash_ops = { >> + .strobe_set = ktd2692_led_flash_strobe_set, >> + .timeout_set = ktd2692_led_flash_timeout_set, >> +}; >> + >> +static int ktd2692_probe(struct platform_device *pdev) >> +{ >> + struct ktd2692_context *led; >> + struct led_classdev *led_cdev; >> + struct led_classdev_flash *fled_cdev; >> + struct ktd2692_led_config_data led_cfg; >> + int ret; >> + >> + led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); >> + if (!led) >> + return -ENOMEM; >> + >> + fled_cdev = &led->fled_cdev; >> + led_cdev = &fled_cdev->led_cdev; >> + >> + ret = ktd2692_parse_dt(led, &pdev->dev, &led_cfg); >> + if (ret) >> + return ret; >> + >> + ktd2692_init_flash_timeout(fled_cdev, &led_cfg); >> + ktd2692_init_movie_current_max(&led_cfg); >> + >> + fled_cdev->ops = &flash_ops; >> + >> + led_cdev->max_brightness = led_cfg.max_brightness; >> + led_cdev->brightness_set = ktd2692_led_brightness_set; >> + led_cdev->brightness_set_sync = ktd2692_led_brightness_set_sync; >> + led_cdev->flags |= LED_CORE_SUSPENDRESUME | LED_DEV_CAP_FLASH; >> + >> + mutex_init(&led->lock); >> + INIT_WORK(&led->work_brightness_set, ktd2692_brightness_set_work); >> + >> + platform_set_drvdata(pdev, led); >> + >> + ret = led_classdev_flash_register(&pdev->dev, fled_cdev); >> + if (ret) { >> + dev_err(&pdev->dev, "can't register LED %s\n", led_cdev->name); >> + mutex_destroy(&led->lock); >> + return ret; >> + } >> + >> + ktd2692_setup(led); >> + >> + return 0; >> +} >> + >> +static int ktd2692_remove(struct platform_device *pdev) >> +{ >> + struct ktd2692_context *led = platform_get_drvdata(pdev); >> + int ret; >> + >> + led_classdev_flash_unregister(&led->fled_cdev); >> + cancel_work_sync(&led->work_brightness_set); >> + >> + if (led->regulator) { >> + ret = regulator_disable(led->regulator); >> + if (ret) >> + dev_err(&pdev->dev, >> + "Failed to disable supply: %d\n", ret); >> + } >> + >> + mutex_destroy(&led->lock); >> + >> + return 0; >> +} >> + >> +static const struct of_device_id ktd2692_match[] = { >> + { .compatible = "kinetic,ktd2692", }, >> + { /* sentinel */ }, >> +}; >> + >> +static struct platform_driver ktd2692_driver = { >> + .driver = { >> + .name = "ktd2692", >> + .of_match_table = ktd2692_match, >> + }, >> + .probe = ktd2692_probe, >> + .remove = ktd2692_remove, >> +}; >> + >> +module_platform_driver(ktd2692_driver); >> + >> +MODULE_AUTHOR("Ingi Kim <ingi2.kim@samsung.com>"); >> +MODULE_DESCRIPTION("Kinetic KTD2692 LED driver"); >> +MODULE_LICENSE("GPL v2"); >> > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v8 3/3] leds: Add ktd2692 flash LED driver 2015-05-08 3:03 ` [PATCH v8 3/3] leds: Add ktd2692 flash LED driver Ingi Kim 2015-05-08 8:33 ` Jacek Anaszewski @ 2015-05-08 9:06 ` Jacek Anaszewski 1 sibling, 0 replies; 9+ messages in thread From: Jacek Anaszewski @ 2015-05-08 9:06 UTC (permalink / raw) To: Ingi Kim Cc: cooloney, rpurdie, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, sakari.ailus, varkabhadram, joe, sw0312.kim, cw00.choi, jh80.chung, ideal.song, devicetree, linux-kernel, linux-leds There is one more thing - please rebase this patch on top of linux-next as currently it conflicts with drivers/leds/Makefile. On 05/08/2015 05:03 AM, Ingi Kim wrote: > This patch adds a driver to support the ktd2692 flash LEDs. > ktd2692 can control flash current by ExpressWire interface. > > Signed-off-by: Ingi Kim <ingi2.kim@samsung.com> > Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> > Reviewed-by: Varka Bhadram <varkabhadram@gmail.com> > --- > drivers/leds/Kconfig | 9 + > drivers/leds/Makefile | 1 + > drivers/leds/leds-ktd2692.c | 443 ++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 453 insertions(+) > create mode 100644 drivers/leds/leds-ktd2692.c > > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > index 51059bb..bfbdbd1 100644 > --- a/drivers/leds/Kconfig > +++ b/drivers/leds/Kconfig > @@ -505,6 +505,15 @@ config LEDS_MENF21BMC > This driver can also be built as a module. If so the module > will be called leds-menf21bmc. > > +config LEDS_KTD2692 > + tristate "KTD2692 LED flash support" > + depends on LEDS_CLASS_FLASH && GPIOLIB && OF > + help > + This option enables support for KTD2692 LED flash connected > + through ExpressWire interface. > + > + Say Y to enable this driver. > + > comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" > > config LEDS_BLINKM > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > index a739ae2..ed5ed79 100644 > --- a/drivers/leds/Makefile > +++ b/drivers/leds/Makefile > @@ -59,6 +59,7 @@ obj-$(CONFIG_LEDS_BLINKM) += leds-blinkm.o > obj-$(CONFIG_LEDS_SYSCON) += leds-syscon.o > obj-$(CONFIG_LEDS_VERSATILE) += leds-versatile.o > obj-$(CONFIG_LEDS_MENF21BMC) += leds-menf21bmc.o > +obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o > > # LED SPI Drivers > obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o > diff --git a/drivers/leds/leds-ktd2692.c b/drivers/leds/leds-ktd2692.c > new file mode 100644 > index 0000000..9d878a4 > --- /dev/null > +++ b/drivers/leds/leds-ktd2692.c > @@ -0,0 +1,443 @@ > +/* > + * LED driver : leds-ktd2692.c > + * > + * Copyright (C) 2015 Samsung Electronics > + * Ingi Kim <ingi2.kim@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 <linux/delay.h> > +#include <linux/err.h> > +#include <linux/gpio/consumer.h> > +#include <linux/led-class-flash.h> > +#include <linux/module.h> > +#include <linux/mutex.h> > +#include <linux/of.h> > +#include <linux/platform_device.h> > +#include <linux/regulator/consumer.h> > +#include <linux/workqueue.h> > + > +/* Value related the movie mode */ > +#define KTD2692_MOVIE_MODE_CURRENT_LEVELS 16 > +#define KTD2692_MM_TO_FL_RATIO(x) ((x) / 3) > +#define KTD2962_MM_MIN_CURR_THRESHOLD_SCALE 8 > + > +/* Value related the flash mode */ > +#define KTD2692_FLASH_MODE_TIMEOUT_LEVELS 8 > +#define KTD2692_FLASH_MODE_TIMEOUT_DISABLE 0 > +#define KTD2692_FLASH_MODE_CURR_PERCENT(x) (((x) * 16) / 100) > + > +/* Macro for getting offset of flash timeout */ > +#define GET_TIMEOUT_OFFSET(timeout, step) ((timeout) / (step)) > + > +/* Base register address */ > +#define KTD2692_REG_LVP_BASE 0x00 > +#define KTD2692_REG_FLASH_TIMEOUT_BASE 0x20 > +#define KTD2692_REG_MM_MIN_CURR_THRESHOLD_BASE 0x40 > +#define KTD2692_REG_MOVIE_CURRENT_BASE 0x60 > +#define KTD2692_REG_FLASH_CURRENT_BASE 0x80 > +#define KTD2692_REG_MODE_BASE 0xA0 > + > +/* Set bit coding time for expresswire interface */ > +#define KTD2692_TIME_RESET_US 700 > +#define KTD2692_TIME_DATA_START_TIME_US 10 > +#define KTD2692_TIME_HIGH_END_OF_DATA_US 350 > +#define KTD2692_TIME_LOW_END_OF_DATA_US 10 > +#define KTD2692_TIME_SHORT_BITSET_US 4 > +#define KTD2692_TIME_LONG_BITSET_US 12 > + > +/* KTD2692 default length of name */ > +#define KTD2692_NAME_LENGTH 20 > + > +enum ktd2692_bitset { > + KTD2692_LOW = 0, > + KTD2692_HIGH, > +}; > + > +/* Movie / Flash Mode Control */ > +enum ktd2692_led_mode { > + KTD2692_MODE_DISABLE = 0, /* default */ > + KTD2692_MODE_MOVIE, > + KTD2692_MODE_FLASH, > +}; > + > +struct ktd2692_led_config_data { > + /* maximum LED current in movie mode */ > + u32 movie_max_microamp; > + /* maximum LED current in flash mode */ > + u32 flash_max_microamp; > + /* maximum flash timeout */ > + u32 flash_max_timeout; > + /* max LED brightness level */ > + enum led_brightness max_brightness; > +}; > + > +struct ktd2692_context { > + /* Related LED Flash class device */ > + struct led_classdev_flash fled_cdev; > + > + /* secures access to the device */ > + struct mutex lock; > + struct regulator *regulator; > + struct work_struct work_brightness_set; > + > + struct gpio_desc *aux_gpio; > + struct gpio_desc *ctrl_gpio; > + > + enum ktd2692_led_mode mode; > + enum led_brightness torch_brightness; > +}; > + > +static struct ktd2692_context *fled_cdev_to_led( > + struct led_classdev_flash *fled_cdev) > +{ > + return container_of(fled_cdev, struct ktd2692_context, fled_cdev); > +} > + > +static void ktd2692_expresswire_start(struct ktd2692_context *led) > +{ > + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); > + udelay(KTD2692_TIME_DATA_START_TIME_US); > +} > + > +static void ktd2692_expresswire_reset(struct ktd2692_context *led) > +{ > + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); > + udelay(KTD2692_TIME_RESET_US); > +} > + > +static void ktd2692_expresswire_end(struct ktd2692_context *led) > +{ > + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); > + udelay(KTD2692_TIME_LOW_END_OF_DATA_US); > + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); > + udelay(KTD2692_TIME_HIGH_END_OF_DATA_US); > +} > + > +static void ktd2692_expresswire_set_bit(struct ktd2692_context *led, bool bit) > +{ > + /* > + * The Low Bit(0) and High Bit(1) is based on a time detection > + * algorithm between time low and time high > + * Time_(L_LB) : Low time of the Low Bit(0) > + * Time_(H_LB) : High time of the LOW Bit(0) > + * Time_(L_HB) : Low time of the High Bit(1) > + * Time_(H_HB) : High time of the High Bit(1) > + * > + * It can be simplified to: > + * Low Bit(0) : 2 * Time_(H_LB) < Time_(L_LB) > + * High Bit(1) : 2 * Time_(L_HB) < Time_(H_HB) > + * HIGH ___ ____ _.. _________ ___ > + * |_________| |_.. |____| |__| > + * LOW <L_LB> <H_LB> <L_HB> <H_HB> > + * [ Low Bit (0) ] [ High Bit(1) ] > + */ > + if (bit) { > + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); > + udelay(KTD2692_TIME_SHORT_BITSET_US); > + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); > + udelay(KTD2692_TIME_LONG_BITSET_US); > + } else { > + gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); > + udelay(KTD2692_TIME_LONG_BITSET_US); > + gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); > + udelay(KTD2692_TIME_SHORT_BITSET_US); > + } > +} > + > +static void ktd2692_expresswire_write(struct ktd2692_context *led, u8 value) > +{ > + int i; > + > + ktd2692_expresswire_start(led); > + for (i = 7; i >= 0; i--) > + ktd2692_expresswire_set_bit(led, value & BIT(i)); > + ktd2692_expresswire_end(led); > +} > + > +static void ktd2692_brightness_set(struct ktd2692_context *led, > + enum led_brightness brightness) > +{ > + mutex_lock(&led->lock); > + > + if (brightness == LED_OFF) { > + led->mode = KTD2692_MODE_DISABLE; > + gpiod_direction_output(led->aux_gpio, KTD2692_LOW); > + } else { > + ktd2692_expresswire_write(led, brightness | > + KTD2692_REG_MOVIE_CURRENT_BASE); > + led->mode = KTD2692_MODE_MOVIE; > + } > + > + ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE); > + mutex_unlock(&led->lock); > +} > + > +static void ktd2692_brightness_set_work(struct work_struct *work) > +{ > + struct ktd2692_context *led = > + container_of(work, struct ktd2692_context, work_brightness_set); > + > + ktd2692_brightness_set(led, led->torch_brightness); > +} > + > +static void ktd2692_led_brightness_set(struct led_classdev *led_cdev, > + enum led_brightness brightness) > +{ > + struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(led_cdev); > + struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); > + > + led->torch_brightness = brightness; > + schedule_work(&led->work_brightness_set); > +} > + > +static int ktd2692_led_brightness_set_sync(struct led_classdev *led_cdev, > + enum led_brightness brightness) > +{ > + struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(led_cdev); > + struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); > + > + ktd2692_brightness_set(led, brightness); > + > + return 0; > +} > + > +static int ktd2692_led_flash_strobe_set(struct led_classdev_flash *fled_cdev, > + bool state) > +{ > + struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); > + struct led_flash_setting *timeout = &fled_cdev->timeout; > + u32 flash_tm_reg; > + > + mutex_lock(&led->lock); > + > + if (state == 0) { > + led->mode = KTD2692_MODE_DISABLE; > + gpiod_direction_output(led->aux_gpio, KTD2692_LOW); > + } else { > + flash_tm_reg = GET_TIMEOUT_OFFSET(timeout->val, timeout->step); > + ktd2692_expresswire_write(led, flash_tm_reg > + | KTD2692_REG_FLASH_TIMEOUT_BASE); > + > + led->mode = KTD2692_MODE_FLASH; > + gpiod_direction_output(led->aux_gpio, KTD2692_HIGH); > + } > + > + ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE); > + > + fled_cdev->led_cdev.brightness = LED_OFF; > + led->mode = KTD2692_MODE_DISABLE; > + > + mutex_unlock(&led->lock); > + > + return 0; > +} > + > +static int ktd2692_led_flash_timeout_set(struct led_classdev_flash *fled_cdev, > + u32 timeout) > +{ > + return 0; > +} > + > +static void ktd2692_init_movie_current_max(struct ktd2692_led_config_data *cfg) > +{ > + u32 offset, step; > + u32 movie_current_microamp; > + > + offset = KTD2692_MOVIE_MODE_CURRENT_LEVELS; > + step = KTD2692_MM_TO_FL_RATIO(cfg->flash_max_microamp) > + / KTD2692_MOVIE_MODE_CURRENT_LEVELS; > + > + do { > + movie_current_microamp = step * offset; > + offset--; > + } while ((movie_current_microamp > cfg->movie_max_microamp) && > + (offset > 0)); > + > + cfg->max_brightness = offset; > +} > + > +static void ktd2692_init_flash_timeout(struct led_classdev_flash *fled_cdev, > + struct ktd2692_led_config_data *cfg) > +{ > + struct led_flash_setting *setting; > + > + setting = &fled_cdev->timeout; > + setting->min = KTD2692_FLASH_MODE_TIMEOUT_DISABLE; > + setting->max = cfg->flash_max_timeout; > + setting->step = cfg->flash_max_timeout > + / (KTD2692_FLASH_MODE_TIMEOUT_LEVELS - 1); > + setting->val = cfg->flash_max_timeout; > +} > + > +static void ktd2692_setup(struct ktd2692_context *led) > +{ > + led->mode = KTD2692_MODE_DISABLE; > + ktd2692_expresswire_reset(led); > + gpiod_direction_output(led->aux_gpio, KTD2692_LOW); > + > + ktd2692_expresswire_write(led, (KTD2962_MM_MIN_CURR_THRESHOLD_SCALE - 1) > + | KTD2692_REG_MM_MIN_CURR_THRESHOLD_BASE); > + ktd2692_expresswire_write(led, KTD2692_FLASH_MODE_CURR_PERCENT(45) > + | KTD2692_REG_FLASH_CURRENT_BASE); > +} > + > +static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev, > + struct ktd2692_led_config_data *cfg) > +{ > + struct device_node *np = dev->of_node; > + struct device_node *child_node; > + int ret; > + > + if (!dev->of_node) > + return -ENXIO; > + > + led->ctrl_gpio = devm_gpiod_get(dev, "ctrl"); > + if (IS_ERR(led->ctrl_gpio)) { > + ret = PTR_ERR(led->ctrl_gpio); > + dev_err(dev, "cannot get ctrl-gpio %d\n", ret); > + return ret; > + } > + > + led->aux_gpio = devm_gpiod_get(dev, "aux"); > + if (IS_ERR(led->aux_gpio)) { > + ret = PTR_ERR(led->aux_gpio); > + dev_err(dev, "cannot get aux-gpio %d\n", ret); > + return ret; > + } > + > + led->regulator = devm_regulator_get(dev, "vin"); > + if (IS_ERR(led->regulator)) > + led->regulator = NULL; > + > + if (led->regulator) { > + ret = regulator_enable(led->regulator); > + if (ret) > + dev_err(dev, "Failed to enable supply: %d\n", ret); > + } > + > + child_node = of_get_next_available_child(np, NULL); > + if (!child_node) { > + dev_err(dev, "No DT child node found for connected LED.\n"); > + return -EINVAL; > + } > + > + led->fled_cdev.led_cdev.name = > + of_get_property(child_node, "label", NULL) ? : child_node->name; > + > + ret = of_property_read_u32(child_node, "led-max-microamp", > + &cfg->movie_max_microamp); > + if (ret) { > + dev_err(dev, "failed to parse led-max-microamp\n"); > + return ret; > + } > + > + ret = of_property_read_u32(child_node, "flash-max-microamp", > + &cfg->flash_max_microamp); > + if (ret) { > + dev_err(dev, "failed to parse flash-max-microamp\n"); > + return ret; > + } > + > + ret = of_property_read_u32(child_node, "flash-max-timeout-us", > + &cfg->flash_max_timeout); > + if (ret) > + dev_err(dev, "failed to parse flash-max-timeout-us\n"); > + > + of_node_put(child_node); > + return ret; > +} > + > +static const struct led_flash_ops flash_ops = { > + .strobe_set = ktd2692_led_flash_strobe_set, > + .timeout_set = ktd2692_led_flash_timeout_set, > +}; > + > +static int ktd2692_probe(struct platform_device *pdev) > +{ > + struct ktd2692_context *led; > + struct led_classdev *led_cdev; > + struct led_classdev_flash *fled_cdev; > + struct ktd2692_led_config_data led_cfg; > + int ret; > + > + led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); > + if (!led) > + return -ENOMEM; > + > + fled_cdev = &led->fled_cdev; > + led_cdev = &fled_cdev->led_cdev; > + > + ret = ktd2692_parse_dt(led, &pdev->dev, &led_cfg); > + if (ret) > + return ret; > + > + ktd2692_init_flash_timeout(fled_cdev, &led_cfg); > + ktd2692_init_movie_current_max(&led_cfg); > + > + fled_cdev->ops = &flash_ops; > + > + led_cdev->max_brightness = led_cfg.max_brightness; > + led_cdev->brightness_set = ktd2692_led_brightness_set; > + led_cdev->brightness_set_sync = ktd2692_led_brightness_set_sync; > + led_cdev->flags |= LED_CORE_SUSPENDRESUME | LED_DEV_CAP_FLASH; > + > + mutex_init(&led->lock); > + INIT_WORK(&led->work_brightness_set, ktd2692_brightness_set_work); > + > + platform_set_drvdata(pdev, led); > + > + ret = led_classdev_flash_register(&pdev->dev, fled_cdev); > + if (ret) { > + dev_err(&pdev->dev, "can't register LED %s\n", led_cdev->name); > + mutex_destroy(&led->lock); > + return ret; > + } > + > + ktd2692_setup(led); > + > + return 0; > +} > + > +static int ktd2692_remove(struct platform_device *pdev) > +{ > + struct ktd2692_context *led = platform_get_drvdata(pdev); > + int ret; > + > + led_classdev_flash_unregister(&led->fled_cdev); > + cancel_work_sync(&led->work_brightness_set); > + > + if (led->regulator) { > + ret = regulator_disable(led->regulator); > + if (ret) > + dev_err(&pdev->dev, > + "Failed to disable supply: %d\n", ret); > + } > + > + mutex_destroy(&led->lock); > + > + return 0; > +} > + > +static const struct of_device_id ktd2692_match[] = { > + { .compatible = "kinetic,ktd2692", }, > + { /* sentinel */ }, > +}; > + > +static struct platform_driver ktd2692_driver = { > + .driver = { > + .name = "ktd2692", > + .of_match_table = ktd2692_match, > + }, > + .probe = ktd2692_probe, > + .remove = ktd2692_remove, > +}; > + > +module_platform_driver(ktd2692_driver); > + > +MODULE_AUTHOR("Ingi Kim <ingi2.kim@samsung.com>"); > +MODULE_DESCRIPTION("Kinetic KTD2692 LED driver"); > +MODULE_LICENSE("GPL v2"); > -- Best Regards, Jacek Anaszewski ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-05-11 2:27 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-05-08 3:03 [PATCH v8 0/3] Add ktd2692 Flash LED driver using LED Flash class Ingi Kim 2015-05-08 3:03 ` [PATCH v8 1/3] of: Add vendor prefix for Kinetic technologies Ingi Kim 2015-05-08 3:03 ` [PATCH v8 2/3] leds: ktd2692: add device tree bindings for ktd2692 Ingi Kim 2015-05-08 8:33 ` Jacek Anaszewski 2015-05-11 2:26 ` Ingi Kim 2015-05-08 3:03 ` [PATCH v8 3/3] leds: Add ktd2692 flash LED driver Ingi Kim 2015-05-08 8:33 ` Jacek Anaszewski 2015-05-11 2:24 ` Ingi Kim 2015-05-08 9:06 ` Jacek Anaszewski
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox