Commit | Line | Data |
---|---|---|
c93d08fa MWK |
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 | ||
10c06d17 MWK |
18 | enum lp55xx_engine_index { |
19 | LP55XX_ENGINE_INVALID, | |
20 | LP55XX_ENGINE_1, | |
21 | LP55XX_ENGINE_2, | |
22 | LP55XX_ENGINE_3, | |
23 | }; | |
24 | ||
c93d08fa MWK |
25 | struct lp55xx_led; |
26 | struct lp55xx_chip; | |
27 | ||
48068d5d MWK |
28 | /* |
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 | |
e3a700d8 | 41 | * @enable : Chip specific enable command |
0e202346 | 42 | * @max_channel : Maximum number of channels |
ffbdccdb | 43 | * @post_init_device : Chip specific initialization code |
9e9b3db1 MWK |
44 | * @brightness_work_fn : Brightness work function |
45 | * @set_led_current : LED current set function | |
10c06d17 MWK |
46 | * @firmware_cb : Call function when the firmware is loaded |
47 | * @run_engine : Run internal engine for pattern | |
240085e2 | 48 | * @dev_attr_group : Device specific attributes |
48068d5d MWK |
49 | */ |
50 | struct lp55xx_device_config { | |
51 | const struct lp55xx_reg reset; | |
e3a700d8 | 52 | const struct lp55xx_reg enable; |
0e202346 | 53 | const int max_channel; |
ffbdccdb MWK |
54 | |
55 | /* define if the device has specific initialization process */ | |
56 | int (*post_init_device) (struct lp55xx_chip *chip); | |
9e9b3db1 MWK |
57 | |
58 | /* access brightness register */ | |
59 | void (*brightness_work_fn)(struct work_struct *work); | |
60 | ||
61 | /* current setting function */ | |
62 | void (*set_led_current) (struct lp55xx_led *led, u8 led_current); | |
10c06d17 MWK |
63 | |
64 | /* access program memory when the firmware is loaded */ | |
65 | void (*firmware_cb)(struct lp55xx_chip *chip); | |
66 | ||
67 | /* used for running firmware LED patterns */ | |
68 | void (*run_engine) (struct lp55xx_chip *chip, bool start); | |
240085e2 MWK |
69 | |
70 | /* additional device specific attributes */ | |
71 | const struct attribute_group *dev_attr_group; | |
48068d5d MWK |
72 | }; |
73 | ||
c93d08fa MWK |
74 | /* |
75 | * struct lp55xx_chip | |
76 | * @cl : I2C communication for access registers | |
77 | * @pdata : Platform specific data | |
78 | * @lock : Lock for user-space interface | |
79 | * @num_leds : Number of registered LEDs | |
48068d5d | 80 | * @cfg : Device specific configuration data |
10c06d17 MWK |
81 | * @engine_idx : Selected engine number |
82 | * @fw : Firmware data for running a LED pattern | |
c93d08fa MWK |
83 | */ |
84 | struct lp55xx_chip { | |
85 | struct i2c_client *cl; | |
86 | struct lp55xx_platform_data *pdata; | |
87 | struct mutex lock; /* lock for user-space interface */ | |
88 | int num_leds; | |
48068d5d | 89 | struct lp55xx_device_config *cfg; |
10c06d17 MWK |
90 | enum lp55xx_engine_index engine_idx; |
91 | const struct firmware *fw; | |
c93d08fa MWK |
92 | }; |
93 | ||
94 | /* | |
95 | * struct lp55xx_led | |
96 | * @chan_nr : Channel number | |
97 | * @cdev : LED class device | |
98 | * @led_current : Current setting at each led channel | |
99 | * @max_current : Maximun current at each led channel | |
100 | * @brightness_work : Workqueue for brightness control | |
101 | * @brightness : Brightness value | |
102 | * @chip : The lp55xx chip data | |
103 | */ | |
104 | struct lp55xx_led { | |
105 | int chan_nr; | |
106 | struct led_classdev cdev; | |
107 | u8 led_current; | |
108 | u8 max_current; | |
109 | struct work_struct brightness_work; | |
110 | u8 brightness; | |
111 | struct lp55xx_chip *chip; | |
112 | }; | |
113 | ||
114 | /* register access */ | |
115 | extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val); | |
116 | extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val); | |
117 | extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, | |
118 | u8 mask, u8 val); | |
119 | ||
6ce61762 | 120 | /* common device init/deinit functions */ |
a85908dd | 121 | extern int lp55xx_init_device(struct lp55xx_chip *chip); |
6ce61762 | 122 | extern void lp55xx_deinit_device(struct lp55xx_chip *chip); |
a85908dd | 123 | |
9e9b3db1 MWK |
124 | /* common LED class device functions */ |
125 | extern int lp55xx_register_leds(struct lp55xx_led *led, | |
126 | struct lp55xx_chip *chip); | |
c3a68ebf MWK |
127 | extern void lp55xx_unregister_leds(struct lp55xx_led *led, |
128 | struct lp55xx_chip *chip); | |
b3b6f811 MWK |
129 | |
130 | /* common device attributes functions */ | |
131 | extern int lp55xx_register_sysfs(struct lp55xx_chip *chip); | |
ba6fa846 | 132 | extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip); |
b3b6f811 | 133 | |
c93d08fa | 134 | #endif /* _LEDS_LP55XX_COMMON_H */ |