diff mbox series

[3/3] leds: leds-lp5569: Add support for Texas Instruments LP5569

Message ID 20240515143129.31557-3-ansuelsmth@gmail.com
State Superseded
Headers show
Series [1/3] dt-bindings: leds-lp55xx: limit pwr-sel property to ti,lp8501 | expand

Commit Message

Christian Marangi May 15, 2024, 2:31 p.m. UTC
Add support for Texas Instruments LP5569 LED driver.

Texas Instruments LP5569 is 9 channels chip with programmable engines.

It almost a copy of LP5523 with fundamental changes to regs order and
regs content.

Has difference in how the clock is handled and doesn't support detecting
clock time automatically, different handling for selftest and different
sheme for the status regs.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/leds/Kconfig       |   16 +-
 drivers/leds/Makefile      |    1 +
 drivers/leds/leds-lp5569.c | 1145 ++++++++++++++++++++++++++++++++++++
 3 files changed, 1159 insertions(+), 3 deletions(-)
 create mode 100644 drivers/leds/leds-lp5569.c

Comments

kernel test robot May 16, 2024, 6:20 p.m. UTC | #1
Hi Christian,

kernel test robot noticed the following build errors:

[auto build test ERROR on lee-leds/for-leds-next]
[also build test ERROR on robh/for-next linus/master v6.9 next-20240516]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/dt-bindings-leds-lp55xx-Add-new-ti-lp5569-compatible/20240515-223434
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/leds.git for-leds-next
patch link:    https://lore.kernel.org/r/20240515143129.31557-3-ansuelsmth%40gmail.com
patch subject: [PATCH 3/3] leds: leds-lp5569: Add support for Texas Instruments LP5569
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20240517/202405170244.MEWiW9it-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240517/202405170244.MEWiW9it-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202405170244.MEWiW9it-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/leds/leds-lp5569.c: In function 'lp5569_post_init_device':
>> drivers/leds/leds-lp5569.c:169:16: error: implicit declaration of function 'FIELD_PREP' [-Werror=implicit-function-declaration]
     169 |         val |= FIELD_PREP(LP5569_CP_MODE_MASK, chip->pdata->charge_pump_mode);
         |                ^~~~~~~~~~
   drivers/leds/leds-lp5569.c: In function 'lp5569_load_engine':
>> drivers/leds/leds-lp5569.c:41:41: error: implicit declaration of function 'FIELD_PREP_CONST' [-Werror=implicit-function-declaration]
      41 | #define   LP5569_MODE_LOAD_ENG          FIELD_PREP_CONST(LP5569_MODE_ENG_MASK, 0x1)
         |                                         ^~~~~~~~~~~~~~~~
   drivers/leds/leds-lp5569.c:195:15: note: in expansion of macro 'LP5569_MODE_LOAD_ENG'
     195 |         val = LP5569_MODE_LOAD_ENG << LP5569_MODE_ENGn_SHIFT(idx);
         |               ^~~~~~~~~~~~~~~~~~~~
   drivers/leds/leds-lp5569.c: In function 'lp5569_init_program_engine':
>> drivers/leds/leds-lp5569.c:321:18: error: implicit declaration of function 'FIELD_GET' [-Werror=implicit-function-declaration]
     321 |         status = FIELD_GET(LP5569_ENG_STATUS_MASK, status);
         |                  ^~~~~~~~~
   drivers/leds/leds-lp5569.c: In function 'show_master_fader_leds':
>> drivers/leds/leds-lp5569.c:904:27: error: implicit declaration of function 'FIELD_MAX'; did you mean 'IPL_MAX'? [-Werror=implicit-function-declaration]
     904 |                 if (val > FIELD_MAX(LP5569_FADER_MAPPING_MASK)) {
         |                           ^~~~~~~~~
         |                           IPL_MAX
   cc1: some warnings being treated as errors


vim +/FIELD_PREP +169 drivers/leds/leds-lp5569.c

    29	
    30	#define LP5569_REG_EXEC_CTRL		0x01
    31	/*
    32	 * Program Memory Operations
    33	 * Same Mask for each engine for both mode and exec
    34	 * ENG1	GENMASK(3, 2)
    35	 * ENG2	GENMASK(5, 4)
    36	 * ENG3	GENMASK(7, 6)
    37	 */
    38	#define LP5569_MODE_ENG_MASK		GENMASK(1, 0)
    39	#define   LP5569_MODE_ENG_SHIFT		2
    40	#define   LP5569_MODE_DISABLE_ENG	FIELD_PREP_CONST(LP5569_MODE_ENG_MASK, 0x0)
  > 41	#define   LP5569_MODE_LOAD_ENG		FIELD_PREP_CONST(LP5569_MODE_ENG_MASK, 0x1)
    42	#define   LP5569_MODE_RUN_ENG		FIELD_PREP_CONST(LP5569_MODE_ENG_MASK, 0x2)
    43	#define   LP5569_MODE_HALT_ENG		FIELD_PREP_CONST(LP5569_MODE_ENG_MASK, 0x3)
    44	
    45	#define   LP5569_MODE_ENGn_SHIFT(n)	(LP5569_MODE_ENG_SHIFT + (2 * (3 - (n))))
    46	#define   LP5569_MODE_ENGn_MASK(n)	(LP5569_MODE_ENG_MASK << LP5569_MODE_ENGn_SHIFT(n))
    47	#define   LP5569_MODE_ENGn_GET(n, mode)	\
    48		(((mode) >> LP5569_MODE_ENGn_SHIFT(n)) & LP5569_MODE_ENG_MASK)
    49	
    50	#define LP5569_REG_OP_MODE		0x02
    51	#define   LP5569_EXEC_ENG_MASK		GENMASK(1, 0)
    52	#define   LP5569_EXEC_ENG_SHIFT		2
    53	#define   LP5569_EXEC_HOLD_ENG		FIELD_PREP_CONST(LP5569_EXEC_ENG_MASK, 0x0)
    54	#define   LP5569_EXEC_STEP_ENG		FIELD_PREP_CONST(LP5569_EXEC_ENG_MASK, 0x1)
    55	#define   LP5569_EXEC_RUN_ENG		FIELD_PREP_CONST(LP5569_EXEC_ENG_MASK, 0x2)
    56	#define   LP5569_EXEC_ONCE_ENG		FIELD_PREP_CONST(LP5569_EXEC_ENG_MASK, 0x3)
    57	
    58	#define   LP5569_EXEC_ENGn_SHIFT(n)	(LP5569_EXEC_ENG_SHIFT + (2 * (3 - (n))))
    59	#define   LP5569_EXEC_ENGn_MASK(n)	(LP5569_EXEC_ENG_MASK << LP5569_EXEC_ENGn_SHIFT(n))
    60	
    61	#define LP5569_REG_ENABLE_LEDS_MSB	0x04
    62	#define LP5569_REG_ENABLE_LEDS_LSB	0x05
    63	#define LP5569_REG_LED_CTRL_BASE	0x07
    64	#define   LP5569_FADER_MAPPING_MASK	GENMASK(7, 5)
    65	#define LP5569_REG_LED_PWM_BASE		0x16
    66	#define LP5569_REG_LED_CURRENT_BASE	0x22
    67	#define LP5569_REG_MISC			0x2F
    68	#define   LP5569_AUTO_INC		BIT(6)
    69	#define   LP5569_PWR_SAVE		BIT(5)
    70	#define   LP5569_CP_MODE_MASK		GENMASK(4, 3)
    71	#define   LP5569_PWM_PWR_SAVE		BIT(2)
    72	#define   LP5569_INTERNAL_CLK		BIT(0)
    73	#define LP5569_REG_MISC2		0x33
    74	#define   LP5569_LED_SHORT_TEST		BIT(4)
    75	#define   LP5569_LED_OPEN_TEST		BIT(3)
    76	#define LP5569_REG_STATUS		0x3C
    77	#define   LP5569_MASK_BUSY		BIT(7)
    78	#define   LP5569_STARTUP_BUSY		BIT(6)
    79	#define   LP5569_ENGINE_BUSY		BIT(5)
    80	#define   LP5569_ENGINE1_INT		BIT(2)
    81	#define   LP5569_ENGINE2_INT		BIT(1)
    82	#define   LP5569_ENGINE3_INT		BIT(0)
    83	#define   LP5569_ENG_STATUS_MASK	(LP5569_ENGINE1_INT | LP5569_ENGINE2_INT | \
    84						 LP5569_ENGINE3_INT)
    85	#define LP5569_REG_IO_CONTROL		0x3D
    86	#define   LP5569_CLK_OUTPUT		BIT(3)
    87	#define LP5569_REG_RESET		0x3F
    88	#define   LP5569_RESET			0xFF
    89	#define LP5569_REG_MASTER_FADER_BASE	0x46
    90	#define LP5569_REG_CH1_PROG_START	0x4B
    91	#define LP5569_REG_CH2_PROG_START	0x4C
    92	#define LP5569_REG_CH3_PROG_START	0x4D
    93	#define LP5569_REG_PROG_PAGE_SEL	0x4F
    94	#define LP5569_REG_PROG_MEM		0x50
    95	#define LP5569_REG_LED_FAULT1		0x81
    96	#define   LP5569_LED_FAULT8		BIT(0)
    97	#define LP5569_REG_LED_FAULT2		0x82
    98	#define   LP5569_LED_FAULT7		BIT(7)
    99	#define   LP5569_LED_FAULT6		BIT(6)
   100	#define   LP5569_LED_FAULT5		BIT(5)
   101	#define   LP5569_LED_FAULT4		BIT(4)
   102	#define   LP5569_LED_FAULT3		BIT(3)
   103	#define   LP5569_LED_FAULT2		BIT(2)
   104	#define   LP5569_LED_FAULT1		BIT(1)
   105	#define   LP5569_LED_FAULT0		BIT(0)
   106	
   107	#define LP5569_MAX_LEDS			9
   108	
   109	#define LP5569_PROGRAM_PAGES		16
   110	#define LP5569_PROGRAM_LENGTH		32	/* bytes */
   111	/* Memory is used like this:
   112	 * 0x00 engine 1 program
   113	 * 0x10 engine 2 program
   114	 * 0x20 engine 3 program
   115	 * 0x30 engine 1 muxing info
   116	 * 0x40 engine 2 muxing info
   117	 * 0x50 engine 3 muxing info
   118	 */
   119	#define LP5569_ENG1_PROG_ADDR		0x0
   120	#define LP5569_ENG2_PROG_ADDR		0x10
   121	#define LP5569_ENG3_PROG_ADDR		0x20
   122	#define LP5569_ENG1_MUX_ADDR		0x30
   123	#define LP5569_ENG2_MUX_ADDR		0x40
   124	#define LP5569_ENG3_MUX_ADDR		0x50
   125	
   126	/* Memory Page Selection */
   127	#define LP5569_PAGE_ENG_OFFSET		0
   128	#define LP5569_PAGE_ENG(n)		(((n) - 1) + LP5569_PAGE_ENG_OFFSET)
   129	#define LP5569_PAGE_MUX_OFFSET		3
   130	#define LP5569_PAGE_MUX(n)		(((n) - 1) + LP5569_PAGE_MUX_OFFSET)
   131	
   132	#define LEDn_STATUS_FAULT(n, status)	((status) >> (n) & BIT(0))
   133	#define LED_ACTIVE(mux, led)		(!!((mux) & (0x0001 << (led))))
   134	
   135	#define LP5569_DEFAULT_CONFIG \
   136		(LP5569_AUTO_INC | LP5569_PWR_SAVE | LP5569_PWM_PWR_SAVE)
   137	
   138	enum lp5569_chip_id {
   139		LP5569,
   140	};
   141	
   142	static int lp5569_init_program_engine(struct lp55xx_chip *chip);
   143	
   144	static inline void lp5569_wait_opmode_done(void)
   145	{
   146		usleep_range(1000, 2000);
   147	}
   148	
   149	static void lp5569_set_led_current(struct lp55xx_led *led, u8 led_current)
   150	{
   151		led->led_current = led_current;
   152		lp55xx_write(led->chip, LP5569_REG_LED_CURRENT_BASE + led->chan_nr,
   153			     led_current);
   154	}
   155	
   156	static int lp5569_post_init_device(struct lp55xx_chip *chip)
   157	{
   158		int ret;
   159		int val;
   160	
   161		ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE);
   162		if (ret)
   163			return ret;
   164	
   165		/* Chip startup time is 500 us, 1 - 2 ms gives some margin */
   166		usleep_range(1000, 2000);
   167	
   168		val = LP5569_DEFAULT_CONFIG;
 > 169		val |= FIELD_PREP(LP5569_CP_MODE_MASK, chip->pdata->charge_pump_mode);
   170	
   171		if (chip->pdata->clock_mode == LP55XX_CLOCK_INT)
   172			val |= LP5569_INTERNAL_CLK;
   173	
   174		ret = lp55xx_write(chip, LP5569_REG_MISC, val);
   175		if (ret)
   176			return ret;
   177	
   178		if (chip->pdata->clock_mode == LP55XX_CLOCK_INT) {
   179			ret = lp55xx_update_bits(chip, LP5569_REG_IO_CONTROL,
   180						 LP5569_CLK_OUTPUT,
   181						 LP5569_CLK_OUTPUT);
   182			if (ret)
   183				return ret;
   184		}
   185	
   186		return lp5569_init_program_engine(chip);
   187	}
   188	
   189	static void lp5569_load_engine(struct lp55xx_chip *chip)
   190	{
   191		enum lp55xx_engine_index idx = chip->engine_idx;
   192		u8 mask, val;
   193	
   194		mask = LP5569_MODE_ENGn_MASK(idx);
   195		val = LP5569_MODE_LOAD_ENG << LP5569_MODE_ENGn_SHIFT(idx);
   196	
   197		lp55xx_update_bits(chip, LP5569_REG_OP_MODE, mask, val);
   198	
   199		lp5569_wait_opmode_done();
   200	}
   201	
   202	static void lp5569_load_engine_and_select_page(struct lp55xx_chip *chip)
   203	{
   204		enum lp55xx_engine_index idx = chip->engine_idx;
   205	
   206		lp5569_load_engine(chip);
   207	
   208		lp55xx_write(chip, LP5569_REG_PROG_PAGE_SEL, LP5569_PAGE_ENG(idx));
   209	}
   210	
   211	static void lp5569_stop_all_engines(struct lp55xx_chip *chip)
   212	{
   213		lp55xx_write(chip, LP5569_REG_OP_MODE, 0);
   214		lp5569_wait_opmode_done();
   215	}
   216	
   217	static void lp5569_stop_engine(struct lp55xx_chip *chip)
   218	{
   219		enum lp55xx_engine_index idx = chip->engine_idx;
   220	
   221		lp55xx_update_bits(chip, LP5569_REG_OP_MODE, LP5569_MODE_ENGn_MASK(idx), 0);
   222	
   223		lp5569_wait_opmode_done();
   224	}
   225	
   226	static void lp5569_turn_off_channels(struct lp55xx_chip *chip)
   227	{
   228		int i;
   229	
   230		for (i = 0; i < LP5569_MAX_LEDS; i++)
   231			lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + i, 0);
   232	}
   233	
   234	static void lp5569_run_engine(struct lp55xx_chip *chip, bool start)
   235	{
   236		int i, ret;
   237		u8 mode;
   238		u8 exec;
   239	
   240		/* stop engine */
   241		if (!start) {
   242			lp5569_stop_engine(chip);
   243			lp5569_turn_off_channels(chip);
   244			return;
   245		}
   246	
   247		/*
   248		 * To run the engine,
   249		 * operation mode and enable register should updated at the same time
   250		 */
   251	
   252		ret = lp55xx_read(chip, LP5569_REG_OP_MODE, &mode);
   253		if (ret)
   254			return;
   255	
   256		ret = lp55xx_read(chip, LP5569_REG_EXEC_CTRL, &exec);
   257		if (ret)
   258			return;
   259	
   260		/* change operation mode to RUN only when each engine is loading */
   261		for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) {
   262			if (LP5569_MODE_ENGn_GET(i, mode) != LP5569_MODE_LOAD_ENG)
   263				continue;
   264	
   265			mode &= ~LP5569_MODE_ENGn_MASK(i);
   266			mode |= LP5569_MODE_RUN_ENG << LP5569_MODE_ENGn_SHIFT(i);
   267			exec &= ~LP5569_EXEC_ENGn_MASK(i);
   268			exec |= LP5569_EXEC_RUN_ENG << LP5569_EXEC_ENGn_SHIFT(i);
   269		}
   270	
   271		lp55xx_write(chip, LP5569_REG_OP_MODE, mode);
   272		lp5569_wait_opmode_done();
   273	
   274		lp55xx_write(chip, LP5569_REG_EXEC_CTRL, exec);
   275	}
   276	
   277	static int lp5569_init_program_engine(struct lp55xx_chip *chip)
   278	{
   279		int i;
   280		int j;
   281		int ret;
   282		u8 status;
   283		/* one pattern per engine setting LED MUX start and stop addresses */
   284		static const u8 pattern[][LP5569_PROGRAM_LENGTH] =  {
   285			{ 0x9c, LP5569_ENG1_MUX_ADDR, 0x9c, 0xb0, 0x9d, 0x80, 0xd8, 0x00, 0},
   286			{ 0x9c, LP5569_ENG2_MUX_ADDR, 0x9c, 0xc0, 0x9d, 0x80, 0xd8, 0x00, 0},
   287			{ 0x9c, LP5569_ENG3_MUX_ADDR, 0x9c, 0xd0, 0x9d, 0x80, 0xd8, 0x00, 0},
   288		};
   289	
   290		/* hardcode 32 bytes of memory for each engine from program memory */
   291		ret = lp55xx_write(chip, LP5569_REG_CH1_PROG_START, LP5569_ENG1_PROG_ADDR);
   292		if (ret)
   293			return ret;
   294	
   295		ret = lp55xx_write(chip, LP5569_REG_CH2_PROG_START, LP5569_ENG2_PROG_ADDR);
   296		if (ret)
   297			return ret;
   298	
   299		ret = lp55xx_write(chip, LP5569_REG_CH3_PROG_START, LP5569_ENG3_PROG_ADDR);
   300		if (ret)
   301			return ret;
   302	
   303		/* write LED MUX address space for each engine */
   304		for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) {
   305			chip->engine_idx = i;
   306			lp5569_load_engine_and_select_page(chip);
   307	
   308			for (j = 0; j < LP5569_PROGRAM_LENGTH; j++) {
   309				ret = lp55xx_write(chip, LP5569_REG_PROG_MEM + j,
   310						   pattern[i - 1][j]);
   311				if (ret)
   312					goto out;
   313			}
   314		}
   315	
   316		lp5569_run_engine(chip, true);
   317	
   318		/* Let the programs run for couple of ms and check the engine status */
   319		usleep_range(3000, 6000);
   320		lp55xx_read(chip, LP5569_REG_STATUS, &status);
 > 321		status = FIELD_GET(LP5569_ENG_STATUS_MASK, status);
   322	
   323		if (status != LP5569_ENG_STATUS_MASK) {
   324			dev_err(&chip->cl->dev,
   325				"could not configure LED engine, status = 0x%.2x\n",
   326				status);
   327			ret = -1;
   328		}
   329	
   330	out:
   331		lp5569_stop_all_engines(chip);
   332		return ret;
   333	}
   334
kernel test robot May 18, 2024, 12:46 p.m. UTC | #2
Hi Christian,

kernel test robot noticed the following build errors:

[auto build test ERROR on lee-leds/for-leds-next]
[also build test ERROR on robh/for-next linus/master v6.9 next-20240517]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/dt-bindings-leds-lp55xx-Add-new-ti-lp5569-compatible/20240515-223434
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/leds.git for-leds-next
patch link:    https://lore.kernel.org/r/20240515143129.31557-3-ansuelsmth%40gmail.com
patch subject: [PATCH 3/3] leds: leds-lp5569: Add support for Texas Instruments LP5569
config: hexagon-allyesconfig (https://download.01.org/0day-ci/archive/20240518/202405182007.uyC8NXfY-lkp@intel.com/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project d3455f4ddd16811401fa153298fadd2f59f6914e)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240518/202405182007.uyC8NXfY-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202405182007.uyC8NXfY-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/leds/leds-lp5569.c:15:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     547 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     560 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
         |                                                   ^
   In file included from drivers/leds/leds-lp5569.c:15:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     573 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
         |                                                   ^
   In file included from drivers/leds/leds-lp5569.c:15:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     584 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     594 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     604 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   In file included from drivers/leds/leds-lp5569.c:15:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:21:
   In file included from include/linux/mm.h:2208:
   include/linux/vmstat.h:522:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     522 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
>> drivers/leds/leds-lp5569.c:169:9: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     169 |         val |= FIELD_PREP(LP5569_CP_MODE_MASK, chip->pdata->charge_pump_mode);
         |                ^
>> drivers/leds/leds-lp5569.c:195:8: error: call to undeclared function 'FIELD_PREP_CONST'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     195 |         val = LP5569_MODE_LOAD_ENG << LP5569_MODE_ENGn_SHIFT(idx);
         |               ^
   drivers/leds/leds-lp5569.c:41:33: note: expanded from macro 'LP5569_MODE_LOAD_ENG'
      41 | #define   LP5569_MODE_LOAD_ENG          FIELD_PREP_CONST(LP5569_MODE_ENG_MASK, 0x1)
         |                                         ^
   drivers/leds/leds-lp5569.c:262:40: error: call to undeclared function 'FIELD_PREP_CONST'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     262 |                 if (LP5569_MODE_ENGn_GET(i, mode) != LP5569_MODE_LOAD_ENG)
         |                                                      ^
   drivers/leds/leds-lp5569.c:41:33: note: expanded from macro 'LP5569_MODE_LOAD_ENG'
      41 | #define   LP5569_MODE_LOAD_ENG          FIELD_PREP_CONST(LP5569_MODE_ENG_MASK, 0x1)
         |                                         ^
>> drivers/leds/leds-lp5569.c:321:11: error: call to undeclared function 'FIELD_GET'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     321 |         status = FIELD_GET(LP5569_ENG_STATUS_MASK, status);
         |                  ^
   drivers/leds/leds-lp5569.c:601:6: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     601 |                                  FIELD_PREP(LP5569_CP_MODE_MASK, LP55XX_CP_BOOST),
         |                                  ^
   drivers/leds/leds-lp5569.c:696:6: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     696 |                                  FIELD_PREP(LP5569_CP_MODE_MASK, LP55XX_CP_BYPASS),
         |                                  ^
   drivers/leds/leds-lp5569.c:903:9: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     903 |                 val = FIELD_PREP(LP5569_FADER_MAPPING_MASK, val);
         |                       ^
>> drivers/leds/leds-lp5569.c:904:13: error: call to undeclared function 'FIELD_MAX'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     904 |                 if (val > FIELD_MAX(LP5569_FADER_MAPPING_MASK)) {
         |                           ^
   drivers/leds/leds-lp5569.c:932:10: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     932 |                         val = FIELD_PREP(LP5569_FADER_MAPPING_MASK, buf[i] - '0');
         |                               ^
   7 warnings and 9 errors generated.


vim +/FIELD_PREP +169 drivers/leds/leds-lp5569.c

   155	
   156	static int lp5569_post_init_device(struct lp55xx_chip *chip)
   157	{
   158		int ret;
   159		int val;
   160	
   161		ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE);
   162		if (ret)
   163			return ret;
   164	
   165		/* Chip startup time is 500 us, 1 - 2 ms gives some margin */
   166		usleep_range(1000, 2000);
   167	
   168		val = LP5569_DEFAULT_CONFIG;
 > 169		val |= FIELD_PREP(LP5569_CP_MODE_MASK, chip->pdata->charge_pump_mode);
   170	
   171		if (chip->pdata->clock_mode == LP55XX_CLOCK_INT)
   172			val |= LP5569_INTERNAL_CLK;
   173	
   174		ret = lp55xx_write(chip, LP5569_REG_MISC, val);
   175		if (ret)
   176			return ret;
   177	
   178		if (chip->pdata->clock_mode == LP55XX_CLOCK_INT) {
   179			ret = lp55xx_update_bits(chip, LP5569_REG_IO_CONTROL,
   180						 LP5569_CLK_OUTPUT,
   181						 LP5569_CLK_OUTPUT);
   182			if (ret)
   183				return ret;
   184		}
   185	
   186		return lp5569_init_program_engine(chip);
   187	}
   188	
   189	static void lp5569_load_engine(struct lp55xx_chip *chip)
   190	{
   191		enum lp55xx_engine_index idx = chip->engine_idx;
   192		u8 mask, val;
   193	
   194		mask = LP5569_MODE_ENGn_MASK(idx);
 > 195		val = LP5569_MODE_LOAD_ENG << LP5569_MODE_ENGn_SHIFT(idx);
   196	
   197		lp55xx_update_bits(chip, LP5569_REG_OP_MODE, mask, val);
   198	
   199		lp5569_wait_opmode_done();
   200	}
   201	
   202	static void lp5569_load_engine_and_select_page(struct lp55xx_chip *chip)
   203	{
   204		enum lp55xx_engine_index idx = chip->engine_idx;
   205	
   206		lp5569_load_engine(chip);
   207	
   208		lp55xx_write(chip, LP5569_REG_PROG_PAGE_SEL, LP5569_PAGE_ENG(idx));
   209	}
   210	
   211	static void lp5569_stop_all_engines(struct lp55xx_chip *chip)
   212	{
   213		lp55xx_write(chip, LP5569_REG_OP_MODE, 0);
   214		lp5569_wait_opmode_done();
   215	}
   216	
   217	static void lp5569_stop_engine(struct lp55xx_chip *chip)
   218	{
   219		enum lp55xx_engine_index idx = chip->engine_idx;
   220	
   221		lp55xx_update_bits(chip, LP5569_REG_OP_MODE, LP5569_MODE_ENGn_MASK(idx), 0);
   222	
   223		lp5569_wait_opmode_done();
   224	}
   225	
   226	static void lp5569_turn_off_channels(struct lp55xx_chip *chip)
   227	{
   228		int i;
   229	
   230		for (i = 0; i < LP5569_MAX_LEDS; i++)
   231			lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + i, 0);
   232	}
   233	
   234	static void lp5569_run_engine(struct lp55xx_chip *chip, bool start)
   235	{
   236		int i, ret;
   237		u8 mode;
   238		u8 exec;
   239	
   240		/* stop engine */
   241		if (!start) {
   242			lp5569_stop_engine(chip);
   243			lp5569_turn_off_channels(chip);
   244			return;
   245		}
   246	
   247		/*
   248		 * To run the engine,
   249		 * operation mode and enable register should updated at the same time
   250		 */
   251	
   252		ret = lp55xx_read(chip, LP5569_REG_OP_MODE, &mode);
   253		if (ret)
   254			return;
   255	
   256		ret = lp55xx_read(chip, LP5569_REG_EXEC_CTRL, &exec);
   257		if (ret)
   258			return;
   259	
   260		/* change operation mode to RUN only when each engine is loading */
   261		for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) {
   262			if (LP5569_MODE_ENGn_GET(i, mode) != LP5569_MODE_LOAD_ENG)
   263				continue;
   264	
   265			mode &= ~LP5569_MODE_ENGn_MASK(i);
   266			mode |= LP5569_MODE_RUN_ENG << LP5569_MODE_ENGn_SHIFT(i);
   267			exec &= ~LP5569_EXEC_ENGn_MASK(i);
   268			exec |= LP5569_EXEC_RUN_ENG << LP5569_EXEC_ENGn_SHIFT(i);
   269		}
   270	
   271		lp55xx_write(chip, LP5569_REG_OP_MODE, mode);
   272		lp5569_wait_opmode_done();
   273	
   274		lp55xx_write(chip, LP5569_REG_EXEC_CTRL, exec);
   275	}
   276	
   277	static int lp5569_init_program_engine(struct lp55xx_chip *chip)
   278	{
   279		int i;
   280		int j;
   281		int ret;
   282		u8 status;
   283		/* one pattern per engine setting LED MUX start and stop addresses */
   284		static const u8 pattern[][LP5569_PROGRAM_LENGTH] =  {
   285			{ 0x9c, LP5569_ENG1_MUX_ADDR, 0x9c, 0xb0, 0x9d, 0x80, 0xd8, 0x00, 0},
   286			{ 0x9c, LP5569_ENG2_MUX_ADDR, 0x9c, 0xc0, 0x9d, 0x80, 0xd8, 0x00, 0},
   287			{ 0x9c, LP5569_ENG3_MUX_ADDR, 0x9c, 0xd0, 0x9d, 0x80, 0xd8, 0x00, 0},
   288		};
   289	
   290		/* hardcode 32 bytes of memory for each engine from program memory */
   291		ret = lp55xx_write(chip, LP5569_REG_CH1_PROG_START, LP5569_ENG1_PROG_ADDR);
   292		if (ret)
   293			return ret;
   294	
   295		ret = lp55xx_write(chip, LP5569_REG_CH2_PROG_START, LP5569_ENG2_PROG_ADDR);
   296		if (ret)
   297			return ret;
   298	
   299		ret = lp55xx_write(chip, LP5569_REG_CH3_PROG_START, LP5569_ENG3_PROG_ADDR);
   300		if (ret)
   301			return ret;
   302	
   303		/* write LED MUX address space for each engine */
   304		for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) {
   305			chip->engine_idx = i;
   306			lp5569_load_engine_and_select_page(chip);
   307	
   308			for (j = 0; j < LP5569_PROGRAM_LENGTH; j++) {
   309				ret = lp55xx_write(chip, LP5569_REG_PROG_MEM + j,
   310						   pattern[i - 1][j]);
   311				if (ret)
   312					goto out;
   313			}
   314		}
   315	
   316		lp5569_run_engine(chip, true);
   317	
   318		/* Let the programs run for couple of ms and check the engine status */
   319		usleep_range(3000, 6000);
   320		lp55xx_read(chip, LP5569_REG_STATUS, &status);
 > 321		status = FIELD_GET(LP5569_ENG_STATUS_MASK, status);
   322	
   323		if (status != LP5569_ENG_STATUS_MASK) {
   324			dev_err(&chip->cl->dev,
   325				"could not configure LED engine, status = 0x%.2x\n",
   326				status);
   327			ret = -1;
   328		}
   329	
   330	out:
   331		lp5569_stop_all_engines(chip);
   332		return ret;
   333	}
   334
diff mbox series

Patch

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 05e6af88b88c..b1d7d94317b3 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -414,7 +414,7 @@  config LEDS_LP50XX
 	  module will be called leds-lp50xx.
 
 config LEDS_LP55XX_COMMON
-	tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501"
+	tristate "Common Driver for TI/National LP5521/5523/55231/5562/5569/8501"
 	depends on LEDS_CLASS
 	depends on LEDS_CLASS_MULTICOLOR
 	depends on OF
@@ -422,8 +422,8 @@  config LEDS_LP55XX_COMMON
 	select FW_LOADER
 	select FW_LOADER_USER_HELPER
 	help
-	  This option supports common operations for LP5521/5523/55231/5562/8501
-	  devices.
+	  This option supports common operations for LP5521/5523/55231/5562/5569/
+	  8501 devices.
 
 config LEDS_LP5521
 	tristate "LED Support for N.S. LP5521 LED driver chip"
@@ -456,6 +456,16 @@  config LEDS_LP5562
 	  Driver provides direct control via LED class and interface for
 	  programming the engines.
 
+config LEDS_LP5569
+	tristate "LED Support for TI LP5569 LED driver chip"
+	depends on LEDS_CLASS && I2C
+	depends on LEDS_LP55XX_COMMON
+	help
+	  If you say yes here you get support for TI LP5569 LED driver.
+	  It is 9 channels chip with programmable engines.
+	  Driver provides direct control via LED class and interface for
+	  programming the engines.
+
 config LEDS_LP8501
 	tristate "LED Support for TI LP8501 LED driver chip"
 	depends on LEDS_CLASS && I2C
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index effdfc6f1e95..ad21941efa19 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -51,6 +51,7 @@  obj-$(CONFIG_LEDS_LP50XX)		+= leds-lp50xx.o
 obj-$(CONFIG_LEDS_LP5521)		+= leds-lp5521.o
 obj-$(CONFIG_LEDS_LP5523)		+= leds-lp5523.o
 obj-$(CONFIG_LEDS_LP5562)		+= leds-lp5562.o
+obj-$(CONFIG_LEDS_LP5569)		+= leds-lp5569.o
 obj-$(CONFIG_LEDS_LP55XX_COMMON)	+= leds-lp55xx-common.o
 obj-$(CONFIG_LEDS_LP8501)		+= leds-lp8501.o
 obj-$(CONFIG_LEDS_LP8788)		+= leds-lp8788.o
diff --git a/drivers/leds/leds-lp5569.c b/drivers/leds/leds-lp5569.c
new file mode 100644
index 000000000000..4a8c08ebe685
--- /dev/null
+++ b/drivers/leds/leds-lp5569.c
@@ -0,0 +1,1145 @@ 
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * lp5569.c - LP5569LED Driver
+ *
+ * Copyright (C) 2010 Nokia Corporation
+ * Copyright (C) 2012 Texas Instruments
+ *
+ * Contact: Samu Onkalo <samu.p.onkalo@nokia.com>
+ *          Milo(Woogyom) Kim <milo.kim@ti.com>
+ *          Christian Marangi <ansuelsmth@gmail.com>
+ */
+
+#include <linux/delay.h>
+#include <linux/firmware.h>
+#include <linux/i2c.h>
+#include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/platform_data/leds-lp55xx.h>
+#include <linux/slab.h>
+#include <dt-bindings/leds/leds-lp55xx.h>
+
+#include "leds-lp55xx-common.h"
+
+/* Registers */
+#define LP5569_REG_ENABLE		0x00
+#define   LP5569_ENABLE			BIT(6)
+
+#define LP5569_REG_EXEC_CTRL		0x01
+/*
+ * Program Memory Operations
+ * Same Mask for each engine for both mode and exec
+ * ENG1	GENMASK(3, 2)
+ * ENG2	GENMASK(5, 4)
+ * ENG3	GENMASK(7, 6)
+ */
+#define LP5569_MODE_ENG_MASK		GENMASK(1, 0)
+#define   LP5569_MODE_ENG_SHIFT		2
+#define   LP5569_MODE_DISABLE_ENG	FIELD_PREP_CONST(LP5569_MODE_ENG_MASK, 0x0)
+#define   LP5569_MODE_LOAD_ENG		FIELD_PREP_CONST(LP5569_MODE_ENG_MASK, 0x1)
+#define   LP5569_MODE_RUN_ENG		FIELD_PREP_CONST(LP5569_MODE_ENG_MASK, 0x2)
+#define   LP5569_MODE_HALT_ENG		FIELD_PREP_CONST(LP5569_MODE_ENG_MASK, 0x3)
+
+#define   LP5569_MODE_ENGn_SHIFT(n)	(LP5569_MODE_ENG_SHIFT + (2 * (3 - (n))))
+#define   LP5569_MODE_ENGn_MASK(n)	(LP5569_MODE_ENG_MASK << LP5569_MODE_ENGn_SHIFT(n))
+#define   LP5569_MODE_ENGn_GET(n, mode)	\
+	(((mode) >> LP5569_MODE_ENGn_SHIFT(n)) & LP5569_MODE_ENG_MASK)
+
+#define LP5569_REG_OP_MODE		0x02
+#define   LP5569_EXEC_ENG_MASK		GENMASK(1, 0)
+#define   LP5569_EXEC_ENG_SHIFT		2
+#define   LP5569_EXEC_HOLD_ENG		FIELD_PREP_CONST(LP5569_EXEC_ENG_MASK, 0x0)
+#define   LP5569_EXEC_STEP_ENG		FIELD_PREP_CONST(LP5569_EXEC_ENG_MASK, 0x1)
+#define   LP5569_EXEC_RUN_ENG		FIELD_PREP_CONST(LP5569_EXEC_ENG_MASK, 0x2)
+#define   LP5569_EXEC_ONCE_ENG		FIELD_PREP_CONST(LP5569_EXEC_ENG_MASK, 0x3)
+
+#define   LP5569_EXEC_ENGn_SHIFT(n)	(LP5569_EXEC_ENG_SHIFT + (2 * (3 - (n))))
+#define   LP5569_EXEC_ENGn_MASK(n)	(LP5569_EXEC_ENG_MASK << LP5569_EXEC_ENGn_SHIFT(n))
+
+#define LP5569_REG_ENABLE_LEDS_MSB	0x04
+#define LP5569_REG_ENABLE_LEDS_LSB	0x05
+#define LP5569_REG_LED_CTRL_BASE	0x07
+#define   LP5569_FADER_MAPPING_MASK	GENMASK(7, 5)
+#define LP5569_REG_LED_PWM_BASE		0x16
+#define LP5569_REG_LED_CURRENT_BASE	0x22
+#define LP5569_REG_MISC			0x2F
+#define   LP5569_AUTO_INC		BIT(6)
+#define   LP5569_PWR_SAVE		BIT(5)
+#define   LP5569_CP_MODE_MASK		GENMASK(4, 3)
+#define   LP5569_PWM_PWR_SAVE		BIT(2)
+#define   LP5569_INTERNAL_CLK		BIT(0)
+#define LP5569_REG_MISC2		0x33
+#define   LP5569_LED_SHORT_TEST		BIT(4)
+#define   LP5569_LED_OPEN_TEST		BIT(3)
+#define LP5569_REG_STATUS		0x3C
+#define   LP5569_MASK_BUSY		BIT(7)
+#define   LP5569_STARTUP_BUSY		BIT(6)
+#define   LP5569_ENGINE_BUSY		BIT(5)
+#define   LP5569_ENGINE1_INT		BIT(2)
+#define   LP5569_ENGINE2_INT		BIT(1)
+#define   LP5569_ENGINE3_INT		BIT(0)
+#define   LP5569_ENG_STATUS_MASK	(LP5569_ENGINE1_INT | LP5569_ENGINE2_INT | \
+					 LP5569_ENGINE3_INT)
+#define LP5569_REG_IO_CONTROL		0x3D
+#define   LP5569_CLK_OUTPUT		BIT(3)
+#define LP5569_REG_RESET		0x3F
+#define   LP5569_RESET			0xFF
+#define LP5569_REG_MASTER_FADER_BASE	0x46
+#define LP5569_REG_CH1_PROG_START	0x4B
+#define LP5569_REG_CH2_PROG_START	0x4C
+#define LP5569_REG_CH3_PROG_START	0x4D
+#define LP5569_REG_PROG_PAGE_SEL	0x4F
+#define LP5569_REG_PROG_MEM		0x50
+#define LP5569_REG_LED_FAULT1		0x81
+#define   LP5569_LED_FAULT8		BIT(0)
+#define LP5569_REG_LED_FAULT2		0x82
+#define   LP5569_LED_FAULT7		BIT(7)
+#define   LP5569_LED_FAULT6		BIT(6)
+#define   LP5569_LED_FAULT5		BIT(5)
+#define   LP5569_LED_FAULT4		BIT(4)
+#define   LP5569_LED_FAULT3		BIT(3)
+#define   LP5569_LED_FAULT2		BIT(2)
+#define   LP5569_LED_FAULT1		BIT(1)
+#define   LP5569_LED_FAULT0		BIT(0)
+
+#define LP5569_MAX_LEDS			9
+
+#define LP5569_PROGRAM_PAGES		16
+#define LP5569_PROGRAM_LENGTH		32	/* bytes */
+/* Memory is used like this:
+ * 0x00 engine 1 program
+ * 0x10 engine 2 program
+ * 0x20 engine 3 program
+ * 0x30 engine 1 muxing info
+ * 0x40 engine 2 muxing info
+ * 0x50 engine 3 muxing info
+ */
+#define LP5569_ENG1_PROG_ADDR		0x0
+#define LP5569_ENG2_PROG_ADDR		0x10
+#define LP5569_ENG3_PROG_ADDR		0x20
+#define LP5569_ENG1_MUX_ADDR		0x30
+#define LP5569_ENG2_MUX_ADDR		0x40
+#define LP5569_ENG3_MUX_ADDR		0x50
+
+/* Memory Page Selection */
+#define LP5569_PAGE_ENG_OFFSET		0
+#define LP5569_PAGE_ENG(n)		(((n) - 1) + LP5569_PAGE_ENG_OFFSET)
+#define LP5569_PAGE_MUX_OFFSET		3
+#define LP5569_PAGE_MUX(n)		(((n) - 1) + LP5569_PAGE_MUX_OFFSET)
+
+#define LEDn_STATUS_FAULT(n, status)	((status) >> (n) & BIT(0))
+#define LED_ACTIVE(mux, led)		(!!((mux) & (0x0001 << (led))))
+
+#define LP5569_DEFAULT_CONFIG \
+	(LP5569_AUTO_INC | LP5569_PWR_SAVE | LP5569_PWM_PWR_SAVE)
+
+enum lp5569_chip_id {
+	LP5569,
+};
+
+static int lp5569_init_program_engine(struct lp55xx_chip *chip);
+
+static inline void lp5569_wait_opmode_done(void)
+{
+	usleep_range(1000, 2000);
+}
+
+static void lp5569_set_led_current(struct lp55xx_led *led, u8 led_current)
+{
+	led->led_current = led_current;
+	lp55xx_write(led->chip, LP5569_REG_LED_CURRENT_BASE + led->chan_nr,
+		     led_current);
+}
+
+static int lp5569_post_init_device(struct lp55xx_chip *chip)
+{
+	int ret;
+	int val;
+
+	ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE);
+	if (ret)
+		return ret;
+
+	/* Chip startup time is 500 us, 1 - 2 ms gives some margin */
+	usleep_range(1000, 2000);
+
+	val = LP5569_DEFAULT_CONFIG;
+	val |= FIELD_PREP(LP5569_CP_MODE_MASK, chip->pdata->charge_pump_mode);
+
+	if (chip->pdata->clock_mode == LP55XX_CLOCK_INT)
+		val |= LP5569_INTERNAL_CLK;
+
+	ret = lp55xx_write(chip, LP5569_REG_MISC, val);
+	if (ret)
+		return ret;
+
+	if (chip->pdata->clock_mode == LP55XX_CLOCK_INT) {
+		ret = lp55xx_update_bits(chip, LP5569_REG_IO_CONTROL,
+					 LP5569_CLK_OUTPUT,
+					 LP5569_CLK_OUTPUT);
+		if (ret)
+			return ret;
+	}
+
+	return lp5569_init_program_engine(chip);
+}
+
+static void lp5569_load_engine(struct lp55xx_chip *chip)
+{
+	enum lp55xx_engine_index idx = chip->engine_idx;
+	u8 mask, val;
+
+	mask = LP5569_MODE_ENGn_MASK(idx);
+	val = LP5569_MODE_LOAD_ENG << LP5569_MODE_ENGn_SHIFT(idx);
+
+	lp55xx_update_bits(chip, LP5569_REG_OP_MODE, mask, val);
+
+	lp5569_wait_opmode_done();
+}
+
+static void lp5569_load_engine_and_select_page(struct lp55xx_chip *chip)
+{
+	enum lp55xx_engine_index idx = chip->engine_idx;
+
+	lp5569_load_engine(chip);
+
+	lp55xx_write(chip, LP5569_REG_PROG_PAGE_SEL, LP5569_PAGE_ENG(idx));
+}
+
+static void lp5569_stop_all_engines(struct lp55xx_chip *chip)
+{
+	lp55xx_write(chip, LP5569_REG_OP_MODE, 0);
+	lp5569_wait_opmode_done();
+}
+
+static void lp5569_stop_engine(struct lp55xx_chip *chip)
+{
+	enum lp55xx_engine_index idx = chip->engine_idx;
+
+	lp55xx_update_bits(chip, LP5569_REG_OP_MODE, LP5569_MODE_ENGn_MASK(idx), 0);
+
+	lp5569_wait_opmode_done();
+}
+
+static void lp5569_turn_off_channels(struct lp55xx_chip *chip)
+{
+	int i;
+
+	for (i = 0; i < LP5569_MAX_LEDS; i++)
+		lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + i, 0);
+}
+
+static void lp5569_run_engine(struct lp55xx_chip *chip, bool start)
+{
+	int i, ret;
+	u8 mode;
+	u8 exec;
+
+	/* stop engine */
+	if (!start) {
+		lp5569_stop_engine(chip);
+		lp5569_turn_off_channels(chip);
+		return;
+	}
+
+	/*
+	 * To run the engine,
+	 * operation mode and enable register should updated at the same time
+	 */
+
+	ret = lp55xx_read(chip, LP5569_REG_OP_MODE, &mode);
+	if (ret)
+		return;
+
+	ret = lp55xx_read(chip, LP5569_REG_EXEC_CTRL, &exec);
+	if (ret)
+		return;
+
+	/* change operation mode to RUN only when each engine is loading */
+	for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) {
+		if (LP5569_MODE_ENGn_GET(i, mode) != LP5569_MODE_LOAD_ENG)
+			continue;
+
+		mode &= ~LP5569_MODE_ENGn_MASK(i);
+		mode |= LP5569_MODE_RUN_ENG << LP5569_MODE_ENGn_SHIFT(i);
+		exec &= ~LP5569_EXEC_ENGn_MASK(i);
+		exec |= LP5569_EXEC_RUN_ENG << LP5569_EXEC_ENGn_SHIFT(i);
+	}
+
+	lp55xx_write(chip, LP5569_REG_OP_MODE, mode);
+	lp5569_wait_opmode_done();
+
+	lp55xx_write(chip, LP5569_REG_EXEC_CTRL, exec);
+}
+
+static int lp5569_init_program_engine(struct lp55xx_chip *chip)
+{
+	int i;
+	int j;
+	int ret;
+	u8 status;
+	/* one pattern per engine setting LED MUX start and stop addresses */
+	static const u8 pattern[][LP5569_PROGRAM_LENGTH] =  {
+		{ 0x9c, LP5569_ENG1_MUX_ADDR, 0x9c, 0xb0, 0x9d, 0x80, 0xd8, 0x00, 0},
+		{ 0x9c, LP5569_ENG2_MUX_ADDR, 0x9c, 0xc0, 0x9d, 0x80, 0xd8, 0x00, 0},
+		{ 0x9c, LP5569_ENG3_MUX_ADDR, 0x9c, 0xd0, 0x9d, 0x80, 0xd8, 0x00, 0},
+	};
+
+	/* hardcode 32 bytes of memory for each engine from program memory */
+	ret = lp55xx_write(chip, LP5569_REG_CH1_PROG_START, LP5569_ENG1_PROG_ADDR);
+	if (ret)
+		return ret;
+
+	ret = lp55xx_write(chip, LP5569_REG_CH2_PROG_START, LP5569_ENG2_PROG_ADDR);
+	if (ret)
+		return ret;
+
+	ret = lp55xx_write(chip, LP5569_REG_CH3_PROG_START, LP5569_ENG3_PROG_ADDR);
+	if (ret)
+		return ret;
+
+	/* write LED MUX address space for each engine */
+	for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) {
+		chip->engine_idx = i;
+		lp5569_load_engine_and_select_page(chip);
+
+		for (j = 0; j < LP5569_PROGRAM_LENGTH; j++) {
+			ret = lp55xx_write(chip, LP5569_REG_PROG_MEM + j,
+					   pattern[i - 1][j]);
+			if (ret)
+				goto out;
+		}
+	}
+
+	lp5569_run_engine(chip, true);
+
+	/* Let the programs run for couple of ms and check the engine status */
+	usleep_range(3000, 6000);
+	lp55xx_read(chip, LP5569_REG_STATUS, &status);
+	status = FIELD_GET(LP5569_ENG_STATUS_MASK, status);
+
+	if (status != LP5569_ENG_STATUS_MASK) {
+		dev_err(&chip->cl->dev,
+			"could not configure LED engine, status = 0x%.2x\n",
+			status);
+		ret = -1;
+	}
+
+out:
+	lp5569_stop_all_engines(chip);
+	return ret;
+}
+
+static int lp5569_update_program_memory(struct lp55xx_chip *chip,
+					const u8 *data, size_t size)
+{
+	u8 pattern[LP5569_PROGRAM_LENGTH] = {0};
+	unsigned int cmd;
+	char c[3];
+	int nrchars;
+	int ret;
+	int offset = 0;
+	int i = 0;
+
+	while ((offset < size - 1) && (i < LP5569_PROGRAM_LENGTH)) {
+		/* separate sscanfs because length is working only for %s */
+		ret = sscanf(data + offset, "%2s%n ", c, &nrchars);
+		if (ret != 1)
+			goto err;
+
+		ret = sscanf(c, "%2x", &cmd);
+		if (ret != 1)
+			goto err;
+
+		pattern[i] = (u8)cmd;
+		offset += nrchars;
+		i++;
+	}
+
+	/* Each instruction is 16bit long. Check that length is even */
+	if (i % 2)
+		goto err;
+
+	for (i = 0; i < LP5569_PROGRAM_LENGTH; i++) {
+		ret = lp55xx_write(chip, LP5569_REG_PROG_MEM + i, pattern[i]);
+		if (ret)
+			return -EINVAL;
+	}
+
+	return size;
+
+err:
+	dev_err(&chip->cl->dev, "wrong pattern format\n");
+	return -EINVAL;
+}
+
+static void lp5569_firmware_loaded(struct lp55xx_chip *chip)
+{
+	const struct firmware *fw = chip->fw;
+
+	if (fw->size > (LP5569_PROGRAM_LENGTH * LP5569_PROGRAM_PAGES * 2)) {
+		dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n",
+			fw->size);
+		return;
+	}
+
+	/*
+	 * Program memory sequence
+	 *  1) set engine mode to "LOAD"
+	 *  2) write firmware data into program memory
+	 */
+
+	lp5569_load_engine_and_select_page(chip);
+	lp5569_update_program_memory(chip, fw->data, fw->size);
+}
+
+static ssize_t show_engine_mode(struct device *dev,
+				struct device_attribute *attr,
+				char *buf, int nr)
+{
+	struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
+	struct lp55xx_chip *chip = led->chip;
+	enum lp55xx_engine_mode mode = chip->engines[nr - 1].mode;
+
+	switch (mode) {
+	case LP55XX_ENGINE_RUN:
+		return sprintf(buf, "run\n");
+	case LP55XX_ENGINE_LOAD:
+		return sprintf(buf, "load\n");
+	case LP55XX_ENGINE_DISABLED:
+	default:
+		return sprintf(buf, "disabled\n");
+	}
+}
+show_mode(1)
+show_mode(2)
+show_mode(3)
+
+static ssize_t store_engine_mode(struct device *dev,
+				 struct device_attribute *attr,
+				 const char *buf, size_t len, int nr)
+{
+	struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
+	struct lp55xx_chip *chip = led->chip;
+	struct lp55xx_engine *engine = &chip->engines[nr - 1];
+
+	mutex_lock(&chip->lock);
+
+	chip->engine_idx = nr;
+
+	if (!strncmp(buf, "run", 3)) {
+		lp5569_run_engine(chip, true);
+		engine->mode = LP55XX_ENGINE_RUN;
+	} else if (!strncmp(buf, "load", 4)) {
+		lp5569_stop_engine(chip);
+		lp5569_load_engine(chip);
+		engine->mode = LP55XX_ENGINE_LOAD;
+	} else if (!strncmp(buf, "disabled", 8)) {
+		lp5569_stop_engine(chip);
+		engine->mode = LP55XX_ENGINE_DISABLED;
+	}
+
+	mutex_unlock(&chip->lock);
+
+	return len;
+}
+store_mode(1)
+store_mode(2)
+store_mode(3)
+
+static int lp5569_mux_parse(const char *buf, u16 *mux, size_t len)
+{
+	u16 tmp_mux = 0;
+	int i;
+
+	len = min_t(int, len, LP5569_MAX_LEDS);
+
+	for (i = 0; i < len; i++) {
+		switch (buf[i]) {
+		case '1':
+			tmp_mux |= (1 << i);
+			break;
+		case '0':
+			break;
+		case '\n':
+			i = len;
+			break;
+		default:
+			return -1;
+		}
+	}
+	*mux = tmp_mux;
+
+	return 0;
+}
+
+static void lp5569_mux_to_array(u16 led_mux, char *array)
+{
+	int i, pos = 0;
+
+	for (i = 0; i < LP5569_MAX_LEDS; i++)
+		pos += sprintf(array + pos, "%x", LED_ACTIVE(led_mux, i));
+
+	array[pos] = '\0';
+}
+
+static ssize_t show_engine_leds(struct device *dev,
+				struct device_attribute *attr,
+				char *buf, int nr)
+{
+	struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
+	struct lp55xx_chip *chip = led->chip;
+	char mux[LP5569_MAX_LEDS + 1];
+
+	lp5569_mux_to_array(chip->engines[nr - 1].led_mux, mux);
+
+	return sprintf(buf, "%s\n", mux);
+}
+show_leds(1)
+show_leds(2)
+show_leds(3)
+
+static int lp5569_load_mux(struct lp55xx_chip *chip, u16 mux, int nr)
+{
+	struct lp55xx_engine *engine = &chip->engines[nr - 1];
+	int ret;
+
+	lp5569_load_engine(chip);
+
+	ret = lp55xx_write(chip, LP5569_REG_PROG_PAGE_SEL, LP5569_PAGE_MUX(nr));
+	if (ret)
+		return ret;
+
+	ret = lp55xx_write(chip, LP5569_REG_PROG_MEM, (u8)(mux >> 8));
+	if (ret)
+		return ret;
+
+	ret = lp55xx_write(chip, LP5569_REG_PROG_MEM + 1, (u8)(mux));
+	if (ret)
+		return ret;
+
+	engine->led_mux = mux;
+	return 0;
+}
+
+static ssize_t store_engine_leds(struct device *dev,
+				 struct device_attribute *attr,
+				 const char *buf, size_t len, int nr)
+{
+	struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
+	struct lp55xx_chip *chip = led->chip;
+	struct lp55xx_engine *engine = &chip->engines[nr - 1];
+	u16 mux = 0;
+	ssize_t ret;
+
+	if (lp5569_mux_parse(buf, &mux, len))
+		return -EINVAL;
+
+	mutex_lock(&chip->lock);
+
+	chip->engine_idx = nr;
+	ret = -EINVAL;
+
+	if (engine->mode != LP55XX_ENGINE_LOAD)
+		goto leave;
+
+	if (lp5569_load_mux(chip, mux, nr))
+		goto leave;
+
+	ret = len;
+leave:
+	mutex_unlock(&chip->lock);
+	return ret;
+}
+store_leds(1)
+store_leds(2)
+store_leds(3)
+
+static ssize_t store_engine_load(struct device *dev,
+				 struct device_attribute *attr,
+				 const char *buf, size_t len, int nr)
+{
+	struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
+	struct lp55xx_chip *chip = led->chip;
+	int ret;
+
+	mutex_lock(&chip->lock);
+
+	chip->engine_idx = nr;
+	lp5569_load_engine_and_select_page(chip);
+	ret = lp5569_update_program_memory(chip, buf, len);
+
+	mutex_unlock(&chip->lock);
+
+	return ret;
+}
+store_load(1)
+store_load(2)
+store_load(3)
+
+static ssize_t lp5569_led_open_test(struct lp55xx_led *led, char *buf)
+{
+	struct lp55xx_chip *chip = led->chip;
+	struct lp55xx_platform_data *pdata = chip->pdata;
+	bool leds_fault[LP5569_MAX_LEDS];
+	struct lp55xx_led *led_tmp = led;
+	int i, ret, pos = 0;
+	u8 status;
+
+	/* Set in STANDBY state */
+	ret = lp55xx_write(chip, LP5569_REG_ENABLE, 0);
+	if (ret)
+		goto exit;
+
+	/* Wait 1ms for device to enter STANDBY state */
+	usleep_range(1000, 2000);
+
+	/* Set Charge Pump to 1.5x */
+	ret = lp55xx_update_bits(chip, LP5569_REG_MISC,
+				 FIELD_PREP(LP5569_CP_MODE_MASK, LP55XX_CP_BOOST),
+				 LP5569_CP_MODE_MASK);
+	if (ret)
+		goto exit;
+
+	/* Enable LED Open Test */
+	ret = lp55xx_update_bits(chip, LP5569_REG_MISC2, LP5569_LED_OPEN_TEST,
+				 LP5569_LED_OPEN_TEST);
+	if (ret)
+		goto exit;
+
+	/* Put Device in NORMAL state */
+	ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE);
+	if (ret)
+		goto exit;
+
+	/* Wait 500 us for device to enter NORMAL state */
+	usleep_range(500, 750);
+
+	/* Enable LED and set to 100% brightness */
+	for (i = 0; i < pdata->num_channels; i++) {
+		ret = lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led_tmp->chan_nr,
+				   LED_FULL);
+		if (ret)
+			goto exit;
+
+		led_tmp++;
+	}
+
+	/* Wait 500 us for device to fill status regs */
+	usleep_range(500, 750);
+
+	/* Parse status led fault 1 regs */
+	ret = lp55xx_read(chip, LP5569_REG_LED_FAULT1, &status);
+	if (ret < 0)
+		goto exit;
+
+	for (i = 0; i < 8; i++)
+		leds_fault[i] = !!((status >> i) & 0x1);
+
+	/* Parse status led fault 2 regs */
+	ret = lp55xx_read(chip, LP5569_REG_LED_FAULT2, &status);
+	if (ret < 0)
+		goto exit;
+
+	for (i = 0; i < 1; i++)
+		leds_fault[i + 8] = !!((status >> i) & 0x1);
+
+	/* Report LED fault */
+	led_tmp = led;
+	for (i = 0; i < pdata->num_channels; i++) {
+		if (leds_fault[led_tmp->chan_nr])
+			pos += sprintf(buf + pos, "LED %d OPEN FAIL\n",
+				       led_tmp->chan_nr);
+
+		led_tmp++;
+	}
+
+	ret = pos;
+
+exit:
+	/* Disable LED Open Test */
+	lp55xx_update_bits(chip, LP5569_REG_MISC2, LP5569_LED_OPEN_TEST,
+			   0);
+
+	led_tmp = led;
+	for (i = 0; i < pdata->num_channels; i++) {
+		lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led_tmp->chan_nr,
+			     0);
+
+		led_tmp++;
+	}
+
+	return ret;
+}
+
+static ssize_t lp5569_led_short_test(struct lp55xx_led *led, char *buf)
+{
+	struct lp55xx_chip *chip = led->chip;
+	struct lp55xx_platform_data *pdata = chip->pdata;
+	bool leds_fault[LP5569_MAX_LEDS];
+	struct lp55xx_led *led_tmp = led;
+	int i, ret, pos = 0;
+	u8 status;
+
+	/* Set in STANDBY state */
+	ret = lp55xx_write(chip, LP5569_REG_ENABLE, 0);
+	if (ret)
+		goto exit;
+
+	/* Wait 1ms for device to enter STANDBY state */
+	usleep_range(1000, 2000);
+
+	/* Set Charge Pump to 1x */
+	ret = lp55xx_update_bits(chip, LP5569_REG_MISC,
+				 FIELD_PREP(LP5569_CP_MODE_MASK, LP55XX_CP_BYPASS),
+				 LP5569_CP_MODE_MASK);
+	if (ret)
+		goto exit;
+
+	/* Enable LED and set to 100% brightness and current to 100% (25.5mA) */
+	for (i = 0; i < pdata->num_channels; i++) {
+		ret = lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led_tmp->chan_nr,
+				   LED_FULL);
+		if (ret)
+			goto exit;
+
+		ret = lp55xx_write(chip, LP5569_REG_LED_CURRENT_BASE + led_tmp->chan_nr,
+				   LED_FULL);
+		if (ret)
+			goto exit;
+
+		led_tmp++;
+	}
+
+	/* Put Device in NORMAL state */
+	ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE);
+	if (ret)
+		goto exit;
+
+	/* Wait 500 us for device to enter NORMAL state */
+	usleep_range(500, 750);
+
+	/* Enable LED Shorted Test */
+	ret = lp55xx_update_bits(chip, LP5569_REG_MISC2, LP5569_LED_OPEN_TEST,
+				 LP5569_LED_SHORT_TEST);
+	if (ret)
+		goto exit;
+
+	/* Wait 500 us for device to fill status regs */
+	usleep_range(500, 750);
+
+	/* Parse status led fault 1 regs */
+	ret = lp55xx_read(chip, LP5569_REG_LED_FAULT1, &status);
+	if (ret < 0)
+		goto exit;
+
+	for (i = 0; i < 8; i++)
+		leds_fault[i] = !!LEDn_STATUS_FAULT(i, status);
+
+	/* Parse status led fault 2 regs */
+	ret = lp55xx_read(chip, LP5569_REG_LED_FAULT2, &status);
+	if (ret < 0)
+		goto exit;
+
+	for (i = 0; i < 1; i++)
+		leds_fault[i + 8] = !!LEDn_STATUS_FAULT(i, status);
+
+	/* Report LED fault */
+	led_tmp = led;
+	for (i = 0; i < pdata->num_channels; i++) {
+		if (leds_fault[led_tmp->chan_nr])
+			pos += sprintf(buf + pos, "LED %d SHORTED FAIL\n",
+				       led_tmp->chan_nr);
+
+		led_tmp++;
+	}
+
+	ret = pos;
+
+exit:
+	/* Disable LED Shorted Test */
+	lp55xx_update_bits(chip, LP5569_REG_MISC2, LP5569_LED_SHORT_TEST,
+			   0);
+
+	led_tmp = led;
+	for (i = 0; i < pdata->num_channels; i++) {
+		lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led_tmp->chan_nr,
+			     0);
+
+		led_tmp++;
+	}
+
+	return ret;
+}
+
+static ssize_t lp5569_selftest(struct device *dev,
+			       struct device_attribute *attr,
+			       char *buf)
+{
+	struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
+	struct lp55xx_chip *chip = led->chip;
+	int i, pos = 0;
+
+	mutex_lock(&chip->lock);
+
+	/* Test LED Open */
+	pos = lp5569_led_open_test(led, buf);
+	if (pos < 0)
+		goto fail;
+
+	/* Test LED Shorted */
+	pos = lp5569_led_short_test(led, buf);
+	if (pos < 0)
+		goto fail;
+
+	for (i = 0; i < chip->pdata->num_channels; i++) {
+		/* Restore current */
+		lp55xx_write(chip, LP5569_REG_LED_CURRENT_BASE + led->chan_nr,
+			     led->led_current);
+
+		/* Restore brightness */
+		lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led->chan_nr,
+			     led->brightness);
+		led++;
+	}
+
+	if (pos == 0)
+		pos = sprintf(buf, "OK\n");
+	goto release_lock;
+fail:
+	pos = sprintf(buf, "FAIL\n");
+
+release_lock:
+	mutex_unlock(&chip->lock);
+
+	return pos;
+}
+
+#define show_fader(nr)						\
+static ssize_t show_master_fader##nr(struct device *dev,	\
+			    struct device_attribute *attr,	\
+			    char *buf)				\
+{								\
+	return show_master_fader(dev, attr, buf, nr);		\
+}
+
+#define store_fader(nr)						\
+static ssize_t store_master_fader##nr(struct device *dev,	\
+			     struct device_attribute *attr,	\
+			     const char *buf, size_t len)	\
+{								\
+	return store_master_fader(dev, attr, buf, len, nr);	\
+}
+
+static ssize_t show_master_fader(struct device *dev,
+				 struct device_attribute *attr,
+				 char *buf, int nr)
+{
+	struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
+	struct lp55xx_chip *chip = led->chip;
+	int ret;
+	u8 val;
+
+	mutex_lock(&chip->lock);
+	ret = lp55xx_read(chip, LP5569_REG_MASTER_FADER_BASE + nr - 1, &val);
+	mutex_unlock(&chip->lock);
+
+	if (ret == 0)
+		ret = sprintf(buf, "%u\n", val);
+
+	return ret;
+}
+show_fader(1)
+show_fader(2)
+show_fader(3)
+
+static ssize_t store_master_fader(struct device *dev,
+				  struct device_attribute *attr,
+				  const char *buf, size_t len, int nr)
+{
+	struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
+	struct lp55xx_chip *chip = led->chip;
+	int ret;
+	unsigned long val;
+
+	if (kstrtoul(buf, 0, &val))
+		return -EINVAL;
+
+	if (val > 0xff)
+		return -EINVAL;
+
+	mutex_lock(&chip->lock);
+	ret = lp55xx_write(chip, LP5569_REG_MASTER_FADER_BASE + nr - 1,
+			   (u8)val);
+	mutex_unlock(&chip->lock);
+
+	if (ret == 0)
+		ret = len;
+
+	return ret;
+}
+store_fader(1)
+store_fader(2)
+store_fader(3)
+
+static ssize_t show_master_fader_leds(struct device *dev,
+				      struct device_attribute *attr,
+				      char *buf)
+{
+	struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
+	struct lp55xx_chip *chip = led->chip;
+	int i, ret, pos = 0;
+	u8 val;
+
+	mutex_lock(&chip->lock);
+
+	for (i = 0; i < LP5569_MAX_LEDS; i++) {
+		ret = lp55xx_read(chip, LP5569_REG_LED_CTRL_BASE + i, &val);
+		if (ret)
+			goto leave;
+
+		val = FIELD_PREP(LP5569_FADER_MAPPING_MASK, val);
+		if (val > FIELD_MAX(LP5569_FADER_MAPPING_MASK)) {
+			ret = -EINVAL;
+			goto leave;
+		}
+		buf[pos++] = val + '0';
+	}
+	buf[pos++] = '\n';
+	ret = pos;
+leave:
+	mutex_unlock(&chip->lock);
+	return ret;
+}
+
+static ssize_t store_master_fader_leds(struct device *dev,
+				       struct device_attribute *attr,
+				       const char *buf, size_t len)
+{
+	struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
+	struct lp55xx_chip *chip = led->chip;
+	int i, n, ret;
+	u8 val;
+
+	n = min_t(int, len, LP5569_MAX_LEDS);
+
+	mutex_lock(&chip->lock);
+
+	for (i = 0; i < n; i++) {
+		if (buf[i] >= '0' && buf[i] <= '7') {
+			val = FIELD_PREP(LP5569_FADER_MAPPING_MASK, buf[i] - '0');
+			ret = lp55xx_update_bits(chip,
+						 LP5569_REG_LED_CTRL_BASE + i,
+						 LP5569_FADER_MAPPING_MASK,
+						 val);
+			if (ret)
+				goto leave;
+		} else {
+			ret = -EINVAL;
+			goto leave;
+		}
+	}
+	ret = len;
+leave:
+	mutex_unlock(&chip->lock);
+	return ret;
+}
+
+static int lp5569_multicolor_brightness(struct lp55xx_led *led)
+{
+	struct lp55xx_chip *chip = led->chip;
+	int ret;
+	int i;
+
+	mutex_lock(&chip->lock);
+	for (i = 0; i < led->mc_cdev.num_colors; i++) {
+		ret = lp55xx_write(chip,
+				   LP5569_REG_LED_PWM_BASE +
+				   led->mc_cdev.subled_info[i].channel,
+				   led->mc_cdev.subled_info[i].brightness);
+		if (ret)
+			break;
+	}
+	mutex_unlock(&chip->lock);
+	return ret;
+}
+
+static int lp5569_led_brightness(struct lp55xx_led *led)
+{
+	struct lp55xx_chip *chip = led->chip;
+	int ret;
+
+	mutex_lock(&chip->lock);
+	ret = lp55xx_write(chip, LP5569_REG_LED_PWM_BASE + led->chan_nr,
+			   led->brightness);
+	mutex_unlock(&chip->lock);
+	return ret;
+}
+
+static LP55XX_DEV_ATTR_RW(engine1_mode, show_engine1_mode, store_engine1_mode);
+static LP55XX_DEV_ATTR_RW(engine2_mode, show_engine2_mode, store_engine2_mode);
+static LP55XX_DEV_ATTR_RW(engine3_mode, show_engine3_mode, store_engine3_mode);
+static LP55XX_DEV_ATTR_RW(engine1_leds, show_engine1_leds, store_engine1_leds);
+static LP55XX_DEV_ATTR_RW(engine2_leds, show_engine2_leds, store_engine2_leds);
+static LP55XX_DEV_ATTR_RW(engine3_leds, show_engine3_leds, store_engine3_leds);
+static LP55XX_DEV_ATTR_WO(engine1_load, store_engine1_load);
+static LP55XX_DEV_ATTR_WO(engine2_load, store_engine2_load);
+static LP55XX_DEV_ATTR_WO(engine3_load, store_engine3_load);
+static LP55XX_DEV_ATTR_RO(selftest, lp5569_selftest);
+static LP55XX_DEV_ATTR_RW(master_fader1, show_master_fader1,
+			  store_master_fader1);
+static LP55XX_DEV_ATTR_RW(master_fader2, show_master_fader2,
+			  store_master_fader2);
+static LP55XX_DEV_ATTR_RW(master_fader3, show_master_fader3,
+			  store_master_fader3);
+static LP55XX_DEV_ATTR_RW(master_fader_leds, show_master_fader_leds,
+			  store_master_fader_leds);
+
+static struct attribute *lp5569_attributes[] = {
+	&dev_attr_engine1_mode.attr,
+	&dev_attr_engine2_mode.attr,
+	&dev_attr_engine3_mode.attr,
+	&dev_attr_engine1_load.attr,
+	&dev_attr_engine2_load.attr,
+	&dev_attr_engine3_load.attr,
+	&dev_attr_engine1_leds.attr,
+	&dev_attr_engine2_leds.attr,
+	&dev_attr_engine3_leds.attr,
+	&dev_attr_selftest.attr,
+	&dev_attr_master_fader1.attr,
+	&dev_attr_master_fader2.attr,
+	&dev_attr_master_fader3.attr,
+	&dev_attr_master_fader_leds.attr,
+	NULL,
+};
+
+static const struct attribute_group lp5569_group = {
+	.attrs = lp5569_attributes,
+};
+
+/* Chip specific configurations */
+static struct lp55xx_device_config lp5569_cfg = {
+	.reset = {
+		.addr = LP5569_REG_RESET,
+		.val  = LP5569_RESET,
+	},
+	.enable = {
+		.addr = LP5569_REG_ENABLE,
+		.val  = LP5569_ENABLE,
+	},
+	.max_channel  = LP5569_MAX_LEDS,
+	.post_init_device   = lp5569_post_init_device,
+	.brightness_fn      = lp5569_led_brightness,
+	.multicolor_brightness_fn = lp5569_multicolor_brightness,
+	.set_led_current    = lp5569_set_led_current,
+	.firmware_cb        = lp5569_firmware_loaded,
+	.run_engine         = lp5569_run_engine,
+	.dev_attr_group     = &lp5569_group,
+};
+
+static int lp5569_probe(struct i2c_client *client)
+{
+	struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev);
+	const struct i2c_device_id *id = i2c_client_get_device_id(client);
+	struct device_node *np = dev_of_node(&client->dev);
+	struct lp55xx_chip *chip;
+	struct lp55xx_led *led;
+	int ret;
+
+	chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
+	if (!chip)
+		return -ENOMEM;
+
+	chip->cfg = &lp5569_cfg;
+
+	if (!pdata) {
+		if (np) {
+			pdata = lp55xx_of_populate_pdata(&client->dev, np,
+							 chip);
+			if (IS_ERR(pdata))
+				return PTR_ERR(pdata);
+		} else {
+			dev_err(&client->dev, "no platform data\n");
+			return -EINVAL;
+		}
+	}
+
+	led = devm_kcalloc(&client->dev,
+			   pdata->num_channels, sizeof(*led), GFP_KERNEL);
+	if (!led)
+		return -ENOMEM;
+
+	chip->cl = client;
+	chip->pdata = pdata;
+
+	mutex_init(&chip->lock);
+
+	i2c_set_clientdata(client, led);
+
+	ret = lp55xx_init_device(chip);
+	if (ret)
+		goto err_init;
+
+	dev_info(&client->dev, "%s Programmable led chip found\n", id->name);
+
+	ret = lp55xx_register_leds(led, chip);
+	if (ret)
+		goto err_out;
+
+	ret = lp55xx_register_sysfs(chip);
+	if (ret) {
+		dev_err(&client->dev, "registering sysfs failed\n");
+		goto err_out;
+	}
+
+	return 0;
+
+err_out:
+	lp55xx_deinit_device(chip);
+err_init:
+	return ret;
+}
+
+static void lp5569_remove(struct i2c_client *client)
+{
+	struct lp55xx_led *led = i2c_get_clientdata(client);
+	struct lp55xx_chip *chip = led->chip;
+
+	lp5569_stop_all_engines(chip);
+	lp55xx_unregister_sysfs(chip);
+	lp55xx_deinit_device(chip);
+}
+
+static const struct i2c_device_id lp5569_id[] = {
+	{ "lp5569",  LP5569 },
+	{ }
+};
+
+MODULE_DEVICE_TABLE(i2c, lp5569_id);
+
+static const struct of_device_id of_lp5569_leds_match[] = {
+	{ .compatible = "ti,lp5569", },
+	{},
+};
+
+MODULE_DEVICE_TABLE(of, of_lp5569_leds_match);
+
+static struct i2c_driver lp5569_driver = {
+	.driver = {
+		.name	= "lp5569x",
+		.of_match_table = of_lp5569_leds_match,
+	},
+	.probe		= lp5569_probe,
+	.remove		= lp5569_remove,
+	.id_table	= lp5569_id,
+};
+
+module_i2c_driver(lp5569_driver);
+
+MODULE_AUTHOR("Mathias Nyman <mathias.nyman@nokia.com>");
+MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
+MODULE_AUTHOR("Christian Marangi <ansuelsmth@gmail.com>");
+MODULE_DESCRIPTION("LP5569 LED engine");
+MODULE_LICENSE("GPL");