leds-lp55xx: use common lp55xx data structure in _probe()

 LP5521 and LP5523 data structures have common features.
 Use common lp55xx data structures rather than chip specific data.
 Legacy code in probe is replaced with this new data structures.

 lp55xx_chip          : Common data between lp5521_chip and lp5523_chip
 lp55xx_led           : Common LED structure between lp5521_led and lp5523_led
 lp55xx_platform_data : Common platform data between lp5521_platform_data and
                        lp5523_platform_data

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp5521: clean up lp5521_configure()

 This patch is a preceding step for making common lp55xx init function.

 LP5521_REG_R_CURRENT register code moved:
 Chip specific code moved from lp5521_init_device() to lp5521_configure().

 Remove engine init function:
 LP5521 has internal program engines which are used for running LED patterns.
 (blinking, ramp up/down and other emotional visual effects)
 Engine initialization is done by reset command in lp5521_init_device().
 Remove this duplicate code.

 Return code:
 Do not use 'OR' arithmetic for the result.
 If some error occus, just return it.

 Enable latency:
 Use explicit named function, lp5521_wait_enable_done().
 According to the datasheet, 500us is guaranteed time.
 Thus wait time is changed from 1000us to 500us.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp5523: clean up lp5523_configure()

 This patch is a preceding step for making common lp55xx init function.

 Return code:
 Do not use 'OR' arithmetic for the result.
 If some error occurs, just return it.

 Remove engine verification code:
 To check whether internal engine works or not, many lines of code are executed.
 However, this job is unnecessary during the chip initialization because
 the engine usage is not mandatory but optional function.
 LED engines are enabled when specific LED pattern is loaded.
 Therefore, this verification code is removed.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: use lp55xx common init function - platform data

 LP5521/5523 platform data functions are moved to lp55xx common driver.
 New init function, lp55xx_init_device() is created.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: use lp55xx common init function - reset

 LP5521/5523 reset device functions are moved to lp55xx common driver.
 Value of register address and value are chip dependent.
 Those are configured in each driver.
 In init function, reset command is executed.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: use lp55xx common init function - detect

 LP5521/5523 chip detection functions are replaced with lp55xx common function,
 lp55xx_detect_device().
 Chip dependent address and values are configurable in each driver.
 In init function, chip detection is executed.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: use lp55xx common init function - post int

 LP5521/5523 chip configuration is replaced with lp55xx common function,
 lp55xx_post_init_device().

 Name change:
 lp5521/5523_configure() to lp5521/5523_post_init_device()
 These are called in init function.

 Register access function
 Argument type is changed from 'i2c_client' to 'lp55xx_chip'.
 Use exported R/W functions of lp55xx common driver.

 Temporary variables in lp5521/5523_init_device()
 These functions will be removed but temporary variables are needed for
 blocking build warnings - incompatible pointer.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: clean up init function

 lp5521/5523_init_device() are replaced with lp55xx common function,
 lp55xx_init_device().

 Error handler in init_device:
 deinit function are matched with 'err_post_init' section in
 lp55xx_init_device().

 Remove LP5523 engine intialization code:
 Engine functionality is not mandatory but optional.
 Moreover engine initialization is done internally with device reset command.
 Therefore, this code is unnecessary.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: use lp55xx common deinit function

 Two separate de-init functions are merged into one common function.
 And it is used in err_post_init of lp55xx_init_device().

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: use lp55xx common led registration function

 LED class devices are registered in lp5521_register_leds() and
 lp5523_register_leds().
 Two separate functions are merged into consolidated lp55xx function,
 lp55xx_register_leds().

 Error handling fix:
 Unregistering LEDS are handled in lp55xx_register_leds() when LED registration
 failure occurs. So each driver error handler is changed to 'err_register_leds'

 Chip dependency: 'brightness_work_fn' and 'set_led_current'
 To make the structure abstract, both functions are configured in each driver.
 Those functions should be done by each driver because register control is
 chip-dependant work.

 lp55xx_init_led: skeleton
 Will be filled in next patch

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: use lp55xx_init_led() common function

 lp5521_init_led() and lp5523_init_led() are replaced with one common function,
 lp55xx_init_led().
 Max channels is configurable, so it's used in lp55xx_init_led().

 'LP5523_LEDS' are changed to 'LP5523_MAX_LEDS'.

 lp55xx_set_brightness, lp55xx_led_attributes: skeleton
 Will be filled in next patches.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: use lp55xx_set_brightness()

 lp5521_set_brightness() and lp5523_set_brightness() are replaced with
 common function, lp55xx_set_brightness().
 This function is invoked when the brightness of each LED channel is updated.
 LP5521 and LP5523 have different register address for the brightness control,
 so this work is done by chip specific brightness_work_fn().

 lp5521/5523_led_brightness_work():
 use lp55xx_led and lp55xx_chip data structure.
 use lp55xx write function.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: provide common LED current setting

 LED current is configurable via the sysfs.
 Max current is a read-only attribute.
 These attributes code can be shared in lp55xx common driver.

 Device attributes: 'led_current' and 'max_current'
 move to lp55xx common driver

 Replaced functions:
 show_max_current()  => lp55xx_show_max_current()
 show_current()      => lp55xx_show_current()
 store_current()     => lp55xx_store_current()

 LED setting function: set_led_current()
 Current registers are device specific, so configurable function is added
 in each driver.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: use lp55xx_unregister_leds()

 To unregister led class devices and sysfs attributes,
 LP5521 and LP5523 have each driver function.
 This patch makes both drivers simple using common driver function,
 lp55xx_unregister_leds().

 And some unused variables are removed.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: fix error condition in lp55xx_register_leds()

 Use lp55xx_unregister_leds() rather than duplicate code.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: add new lp55xx_register_sysfs() for the firmware interface

 LP55xx family chips have internal program memory which run various patterns.
 Using this memory, LEDs continue on blinking/dimming without continuous I2C
 commands. That means the I2C HOST can be entered into sleep once the memory
 is updated.

 An application can get hex data from a file and write them into
 the program memory through the I2C. This is general firwmare interface.

 This patch is the initial step for adding the firmware interface.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: support firmware interface

 This patch provides additional device attributes which enable
 loading the firmware. ('select_engine' and 'run_engine')
 To run a LED pattern, two parts of driver should be enabled.

 Common features : lp55xx-common
 ===============================
 Firmware interface for loading LED patterns

 Chip specific features : leds-lp5521, leds-lp5523
 =================================================
 Register addresses for loading firmware data
 Register addresses for running selected engine

 Pattern programming sequence
 ============================
 LP55xx chips have three program engines.
 To load and run a LED pattern, the programming sequence is as follows.
 (1) Select an engine number (1/2/3)
 (2) Set engine mode to load
 (3) Write pattern data into selected area
 (4) Set engine mode to run

 This sequence is almost same as the firmware interface.
 (1) Select an engine number               : 'select_engine' dev attribute
 (2) Mode change to load                   : 'loading' of firmware class
 (3) Write pattern data into selected area : 'data' of firmware class
 (4) Mode change to run                    : 'run_engine' dev attribute

 (1) and (4) are device specific features which provide callback functions
 (2) and (3) are common features.

 For example,
 echo 1 or 2 or 3 > /sys/bus/i2c/devices/xxxx/select_engine
 echo 1 > /sys/class/firmware/lp5521/loading
 echo "4000600040FF6000" > /sys/class/firmware/lp5521/data
 echo 0 > /sys/class/firmware/lp5521/loading
 echo 1 > /sys/bus/i2c/devices/xxxx/run_engine

 As soon as 'loading' is set to 0, registered callback is called.
 Inside the callback, the selected engine is loaded and memory is updated.
 To run programmed pattern, 'run_engine' attribute should be enabled.

 Device specific data structure
 ==============================
 o Firmware callback
   load selected engine and update program memory
 o Run engine
   change the engine mode
 o 'engine_idx' and firmware data, 'fw'
   Those are used in the driver internally with callback functions

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp5521: use generic firmware interface

 LP55xx common driver provides generic firmware interface
 for running a LED pattern.
 LP5521 and LP5523 have many device attributes for running patterns.
 This patch cleans up those complex code.

 Removed device attributes:
 engine1_mode
 engine2_mode
 engine3_mode
 engine1_load
 engine2_load
 engine3_load
 led_pattern

 All device attributes and functions are replaced with two callback functions,
 'firmware_cb' and 'run_engine'.

 New engine functions:
 lp5521_load/stop/run_engine(), lp5521_update_program_memory() and
 lp5521_wait_opmode_done()

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp5523: use generic firmware interface

 LP55xx common driver provides generic firmware interface
 for running a LED pattern.
 LP5521 and LP5523 have many device attributes for running patterns.
 This patch cleans up those complex code.

 Removed device attributes:
 engine1_mode
 engine2_mode
 engine3_mode
 engine1_load
 engine2_load
 engine3_load
 engine1_leds
 engine2_leds
 engine3_leds

 All device attributes and functions are replaced with two callback functions,
 'firmware_cb' and 'run_engine'.

 New engine functions:
 lp5523_load/stop/run_engine(), lp5523_update_program_memory() and
 lp5523_wait_opmode_done()

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
leds-lp55xx: support device specific attributes

 To support device specific attributes, new common driver function is added.
 Eventually those are created on registering the sysfs with common dev attrs.
 Furthermore, this patch makes adding device attributes simple in each driver.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>