Milo(Woogyom) Kim | c93d08f | 2013-02-05 18:01:23 +0900 | [diff] [blame] | 1 | /* |
| 2 | * LP55XX Common Driver Header |
| 3 | * |
| 4 | * Copyright (C) 2012 Texas Instruments |
| 5 | * |
| 6 | * Author: Milo(Woogyom) Kim <milo.kim@ti.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * Derived from leds-lp5521.c, leds-lp5523.c |
| 13 | */ |
| 14 | |
| 15 | #ifndef _LEDS_LP55XX_COMMON_H |
| 16 | #define _LEDS_LP55XX_COMMON_H |
| 17 | |
Milo(Woogyom) Kim | 10c06d1 | 2013-02-05 19:17:20 +0900 | [diff] [blame^] | 18 | enum lp55xx_engine_index { |
| 19 | LP55XX_ENGINE_INVALID, |
| 20 | LP55XX_ENGINE_1, |
| 21 | LP55XX_ENGINE_2, |
| 22 | LP55XX_ENGINE_3, |
| 23 | }; |
| 24 | |
Milo(Woogyom) Kim | c93d08f | 2013-02-05 18:01:23 +0900 | [diff] [blame] | 25 | struct lp55xx_led; |
| 26 | struct lp55xx_chip; |
| 27 | |
| 28 | /* |
Milo(Woogyom) Kim | 48068d5 | 2013-02-05 18:08:49 +0900 | [diff] [blame] | 29 | * struct lp55xx_reg |
| 30 | * @addr : Register address |
| 31 | * @val : Register value |
| 32 | */ |
| 33 | struct lp55xx_reg { |
| 34 | u8 addr; |
| 35 | u8 val; |
| 36 | }; |
| 37 | |
| 38 | /* |
| 39 | * struct lp55xx_device_config |
| 40 | * @reset : Chip specific reset command |
Milo(Woogyom) Kim | e3a700d | 2013-02-05 18:09:56 +0900 | [diff] [blame] | 41 | * @enable : Chip specific enable command |
Milo(Woogyom) Kim | 0e20234 | 2013-02-05 19:07:34 +0900 | [diff] [blame] | 42 | * @max_channel : Maximum number of channels |
Milo(Woogyom) Kim | ffbdccd | 2013-02-05 18:57:36 +0900 | [diff] [blame] | 43 | * @post_init_device : Chip specific initialization code |
Milo(Woogyom) Kim | 9e9b3db | 2013-02-05 19:06:27 +0900 | [diff] [blame] | 44 | * @brightness_work_fn : Brightness work function |
| 45 | * @set_led_current : LED current set function |
Milo(Woogyom) Kim | 10c06d1 | 2013-02-05 19:17:20 +0900 | [diff] [blame^] | 46 | * @firmware_cb : Call function when the firmware is loaded |
| 47 | * @run_engine : Run internal engine for pattern |
Milo(Woogyom) Kim | 48068d5 | 2013-02-05 18:08:49 +0900 | [diff] [blame] | 48 | */ |
| 49 | struct lp55xx_device_config { |
| 50 | const struct lp55xx_reg reset; |
Milo(Woogyom) Kim | e3a700d | 2013-02-05 18:09:56 +0900 | [diff] [blame] | 51 | const struct lp55xx_reg enable; |
Milo(Woogyom) Kim | 0e20234 | 2013-02-05 19:07:34 +0900 | [diff] [blame] | 52 | const int max_channel; |
Milo(Woogyom) Kim | ffbdccd | 2013-02-05 18:57:36 +0900 | [diff] [blame] | 53 | |
| 54 | /* define if the device has specific initialization process */ |
| 55 | int (*post_init_device) (struct lp55xx_chip *chip); |
Milo(Woogyom) Kim | 9e9b3db | 2013-02-05 19:06:27 +0900 | [diff] [blame] | 56 | |
| 57 | /* access brightness register */ |
| 58 | void (*brightness_work_fn)(struct work_struct *work); |
| 59 | |
| 60 | /* current setting function */ |
| 61 | void (*set_led_current) (struct lp55xx_led *led, u8 led_current); |
Milo(Woogyom) Kim | 10c06d1 | 2013-02-05 19:17:20 +0900 | [diff] [blame^] | 62 | |
| 63 | /* access program memory when the firmware is loaded */ |
| 64 | void (*firmware_cb)(struct lp55xx_chip *chip); |
| 65 | |
| 66 | /* used for running firmware LED patterns */ |
| 67 | void (*run_engine) (struct lp55xx_chip *chip, bool start); |
Milo(Woogyom) Kim | 48068d5 | 2013-02-05 18:08:49 +0900 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | /* |
Milo(Woogyom) Kim | c93d08f | 2013-02-05 18:01:23 +0900 | [diff] [blame] | 71 | * struct lp55xx_chip |
| 72 | * @cl : I2C communication for access registers |
| 73 | * @pdata : Platform specific data |
| 74 | * @lock : Lock for user-space interface |
| 75 | * @num_leds : Number of registered LEDs |
Milo(Woogyom) Kim | 48068d5 | 2013-02-05 18:08:49 +0900 | [diff] [blame] | 76 | * @cfg : Device specific configuration data |
Milo(Woogyom) Kim | 10c06d1 | 2013-02-05 19:17:20 +0900 | [diff] [blame^] | 77 | * @engine_idx : Selected engine number |
| 78 | * @fw : Firmware data for running a LED pattern |
Milo(Woogyom) Kim | c93d08f | 2013-02-05 18:01:23 +0900 | [diff] [blame] | 79 | */ |
| 80 | struct lp55xx_chip { |
| 81 | struct i2c_client *cl; |
| 82 | struct lp55xx_platform_data *pdata; |
| 83 | struct mutex lock; /* lock for user-space interface */ |
| 84 | int num_leds; |
Milo(Woogyom) Kim | 48068d5 | 2013-02-05 18:08:49 +0900 | [diff] [blame] | 85 | struct lp55xx_device_config *cfg; |
Milo(Woogyom) Kim | 10c06d1 | 2013-02-05 19:17:20 +0900 | [diff] [blame^] | 86 | enum lp55xx_engine_index engine_idx; |
| 87 | const struct firmware *fw; |
Milo(Woogyom) Kim | c93d08f | 2013-02-05 18:01:23 +0900 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /* |
| 91 | * struct lp55xx_led |
| 92 | * @chan_nr : Channel number |
| 93 | * @cdev : LED class device |
| 94 | * @led_current : Current setting at each led channel |
| 95 | * @max_current : Maximun current at each led channel |
| 96 | * @brightness_work : Workqueue for brightness control |
| 97 | * @brightness : Brightness value |
| 98 | * @chip : The lp55xx chip data |
| 99 | */ |
| 100 | struct lp55xx_led { |
| 101 | int chan_nr; |
| 102 | struct led_classdev cdev; |
| 103 | u8 led_current; |
| 104 | u8 max_current; |
| 105 | struct work_struct brightness_work; |
| 106 | u8 brightness; |
| 107 | struct lp55xx_chip *chip; |
| 108 | }; |
| 109 | |
| 110 | /* register access */ |
| 111 | extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val); |
| 112 | extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val); |
| 113 | extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, |
| 114 | u8 mask, u8 val); |
| 115 | |
Milo(Woogyom) Kim | 6ce6176 | 2013-02-05 19:03:02 +0900 | [diff] [blame] | 116 | /* common device init/deinit functions */ |
Milo(Woogyom) Kim | a85908d | 2013-02-05 18:07:20 +0900 | [diff] [blame] | 117 | extern int lp55xx_init_device(struct lp55xx_chip *chip); |
Milo(Woogyom) Kim | 6ce6176 | 2013-02-05 19:03:02 +0900 | [diff] [blame] | 118 | extern void lp55xx_deinit_device(struct lp55xx_chip *chip); |
Milo(Woogyom) Kim | a85908d | 2013-02-05 18:07:20 +0900 | [diff] [blame] | 119 | |
Milo(Woogyom) Kim | 9e9b3db | 2013-02-05 19:06:27 +0900 | [diff] [blame] | 120 | /* common LED class device functions */ |
| 121 | extern int lp55xx_register_leds(struct lp55xx_led *led, |
| 122 | struct lp55xx_chip *chip); |
Milo(Woogyom) Kim | c3a68eb | 2013-02-05 19:11:18 +0900 | [diff] [blame] | 123 | extern void lp55xx_unregister_leds(struct lp55xx_led *led, |
| 124 | struct lp55xx_chip *chip); |
Milo(Woogyom) Kim | b3b6f81 | 2013-02-05 19:15:27 +0900 | [diff] [blame] | 125 | |
| 126 | /* common device attributes functions */ |
| 127 | extern int lp55xx_register_sysfs(struct lp55xx_chip *chip); |
| 128 | |
Milo(Woogyom) Kim | c93d08f | 2013-02-05 18:01:23 +0900 | [diff] [blame] | 129 | #endif /* _LEDS_LP55XX_COMMON_H */ |