Commit 36030978f51b596c30188187ffcc8a436cce16f0

Authored by Milo Kim
Committed by Bryan Wu
1 parent 6841a91dc5

leds: lp55xx: add common macros for device attributes

This patch provides common macros for LP5521 and LP5523 device attributes and
functions.

(Device attributes)
LP5521: 'mode', 'load' and 'selftest'
LP5523: 'mode', 'load', 'leds' and 'selftest'

(Permissions)
mode: R/W
load: Write-only
leds: R/W
selftest: Read-only

Couple of lines are duplicate, so use these macros for adding device attributes
in LP5521 and LP5523 drivers.

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

Showing 1 changed file with 47 additions and 0 deletions Inline Diff

drivers/leds/leds-lp55xx-common.h
1 /* 1 /*
2 * LP55XX Common Driver Header 2 * LP55XX Common Driver Header
3 * 3 *
4 * Copyright (C) 2012 Texas Instruments 4 * Copyright (C) 2012 Texas Instruments
5 * 5 *
6 * Author: Milo(Woogyom) Kim <milo.kim@ti.com> 6 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or 8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License 9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation. 10 * version 2 as published by the Free Software Foundation.
11 * 11 *
12 * Derived from leds-lp5521.c, leds-lp5523.c 12 * Derived from leds-lp5521.c, leds-lp5523.c
13 */ 13 */
14 14
15 #ifndef _LEDS_LP55XX_COMMON_H 15 #ifndef _LEDS_LP55XX_COMMON_H
16 #define _LEDS_LP55XX_COMMON_H 16 #define _LEDS_LP55XX_COMMON_H
17 17
18 enum lp55xx_engine_index { 18 enum lp55xx_engine_index {
19 LP55XX_ENGINE_INVALID, 19 LP55XX_ENGINE_INVALID,
20 LP55XX_ENGINE_1, 20 LP55XX_ENGINE_1,
21 LP55XX_ENGINE_2, 21 LP55XX_ENGINE_2,
22 LP55XX_ENGINE_3, 22 LP55XX_ENGINE_3,
23 LP55XX_ENGINE_MAX = LP55XX_ENGINE_3, 23 LP55XX_ENGINE_MAX = LP55XX_ENGINE_3,
24 }; 24 };
25 25
26 enum lp55xx_engine_mode { 26 enum lp55xx_engine_mode {
27 LP55XX_ENGINE_DISABLED, 27 LP55XX_ENGINE_DISABLED,
28 LP55XX_ENGINE_LOAD, 28 LP55XX_ENGINE_LOAD,
29 LP55XX_ENGINE_RUN, 29 LP55XX_ENGINE_RUN,
30 }; 30 };
31 31
32 #define LP55XX_DEV_ATTR_RW(name, show, store) \
33 DEVICE_ATTR(name, S_IRUGO | S_IWUSR, show, store)
34 #define LP55XX_DEV_ATTR_RO(name, show) \
35 DEVICE_ATTR(name, S_IRUGO, show, NULL)
36 #define LP55XX_DEV_ATTR_WO(name, store) \
37 DEVICE_ATTR(name, S_IWUSR, NULL, store)
38
39 #define show_mode(nr) \
40 static ssize_t show_engine##nr##_mode(struct device *dev, \
41 struct device_attribute *attr, \
42 char *buf) \
43 { \
44 return show_engine_mode(dev, attr, buf, nr); \
45 }
46
47 #define store_mode(nr) \
48 static ssize_t store_engine##nr##_mode(struct device *dev, \
49 struct device_attribute *attr, \
50 const char *buf, size_t len) \
51 { \
52 return store_engine_mode(dev, attr, buf, len, nr); \
53 }
54
55 #define show_leds(nr) \
56 static ssize_t show_engine##nr##_leds(struct device *dev, \
57 struct device_attribute *attr, \
58 char *buf) \
59 { \
60 return show_engine_leds(dev, attr, buf, nr); \
61 }
62
63 #define store_leds(nr) \
64 static ssize_t store_engine##nr##_leds(struct device *dev, \
65 struct device_attribute *attr, \
66 const char *buf, size_t len) \
67 { \
68 return store_engine_leds(dev, attr, buf, len, nr); \
69 }
70
71 #define store_load(nr) \
72 static ssize_t store_engine##nr##_load(struct device *dev, \
73 struct device_attribute *attr, \
74 const char *buf, size_t len) \
75 { \
76 return store_engine_load(dev, attr, buf, len, nr); \
77 }
78
32 struct lp55xx_led; 79 struct lp55xx_led;
33 struct lp55xx_chip; 80 struct lp55xx_chip;
34 81
35 /* 82 /*
36 * struct lp55xx_reg 83 * struct lp55xx_reg
37 * @addr : Register address 84 * @addr : Register address
38 * @val : Register value 85 * @val : Register value
39 */ 86 */
40 struct lp55xx_reg { 87 struct lp55xx_reg {
41 u8 addr; 88 u8 addr;
42 u8 val; 89 u8 val;
43 }; 90 };
44 91
45 /* 92 /*
46 * struct lp55xx_device_config 93 * struct lp55xx_device_config
47 * @reset : Chip specific reset command 94 * @reset : Chip specific reset command
48 * @enable : Chip specific enable command 95 * @enable : Chip specific enable command
49 * @max_channel : Maximum number of channels 96 * @max_channel : Maximum number of channels
50 * @post_init_device : Chip specific initialization code 97 * @post_init_device : Chip specific initialization code
51 * @brightness_work_fn : Brightness work function 98 * @brightness_work_fn : Brightness work function
52 * @set_led_current : LED current set function 99 * @set_led_current : LED current set function
53 * @firmware_cb : Call function when the firmware is loaded 100 * @firmware_cb : Call function when the firmware is loaded
54 * @run_engine : Run internal engine for pattern 101 * @run_engine : Run internal engine for pattern
55 * @dev_attr_group : Device specific attributes 102 * @dev_attr_group : Device specific attributes
56 */ 103 */
57 struct lp55xx_device_config { 104 struct lp55xx_device_config {
58 const struct lp55xx_reg reset; 105 const struct lp55xx_reg reset;
59 const struct lp55xx_reg enable; 106 const struct lp55xx_reg enable;
60 const int max_channel; 107 const int max_channel;
61 108
62 /* define if the device has specific initialization process */ 109 /* define if the device has specific initialization process */
63 int (*post_init_device) (struct lp55xx_chip *chip); 110 int (*post_init_device) (struct lp55xx_chip *chip);
64 111
65 /* access brightness register */ 112 /* access brightness register */
66 void (*brightness_work_fn)(struct work_struct *work); 113 void (*brightness_work_fn)(struct work_struct *work);
67 114
68 /* current setting function */ 115 /* current setting function */
69 void (*set_led_current) (struct lp55xx_led *led, u8 led_current); 116 void (*set_led_current) (struct lp55xx_led *led, u8 led_current);
70 117
71 /* access program memory when the firmware is loaded */ 118 /* access program memory when the firmware is loaded */
72 void (*firmware_cb)(struct lp55xx_chip *chip); 119 void (*firmware_cb)(struct lp55xx_chip *chip);
73 120
74 /* used for running firmware LED patterns */ 121 /* used for running firmware LED patterns */
75 void (*run_engine) (struct lp55xx_chip *chip, bool start); 122 void (*run_engine) (struct lp55xx_chip *chip, bool start);
76 123
77 /* additional device specific attributes */ 124 /* additional device specific attributes */
78 const struct attribute_group *dev_attr_group; 125 const struct attribute_group *dev_attr_group;
79 }; 126 };
80 127
81 /* 128 /*
82 * struct lp55xx_engine 129 * struct lp55xx_engine
83 * @mode : Engine mode 130 * @mode : Engine mode
84 * @led_mux : Mux bits for LED selection. Only used in LP5523 131 * @led_mux : Mux bits for LED selection. Only used in LP5523
85 */ 132 */
86 struct lp55xx_engine { 133 struct lp55xx_engine {
87 enum lp55xx_engine_mode mode; 134 enum lp55xx_engine_mode mode;
88 u16 led_mux; 135 u16 led_mux;
89 }; 136 };
90 137
91 /* 138 /*
92 * struct lp55xx_chip 139 * struct lp55xx_chip
93 * @cl : I2C communication for access registers 140 * @cl : I2C communication for access registers
94 * @pdata : Platform specific data 141 * @pdata : Platform specific data
95 * @lock : Lock for user-space interface 142 * @lock : Lock for user-space interface
96 * @num_leds : Number of registered LEDs 143 * @num_leds : Number of registered LEDs
97 * @cfg : Device specific configuration data 144 * @cfg : Device specific configuration data
98 * @engine_idx : Selected engine number 145 * @engine_idx : Selected engine number
99 * @engines : Engine structure for the device attribute R/W interface 146 * @engines : Engine structure for the device attribute R/W interface
100 * @fw : Firmware data for running a LED pattern 147 * @fw : Firmware data for running a LED pattern
101 */ 148 */
102 struct lp55xx_chip { 149 struct lp55xx_chip {
103 struct i2c_client *cl; 150 struct i2c_client *cl;
104 struct clk *clk; 151 struct clk *clk;
105 struct lp55xx_platform_data *pdata; 152 struct lp55xx_platform_data *pdata;
106 struct mutex lock; /* lock for user-space interface */ 153 struct mutex lock; /* lock for user-space interface */
107 int num_leds; 154 int num_leds;
108 struct lp55xx_device_config *cfg; 155 struct lp55xx_device_config *cfg;
109 enum lp55xx_engine_index engine_idx; 156 enum lp55xx_engine_index engine_idx;
110 struct lp55xx_engine engines[LP55XX_ENGINE_MAX]; 157 struct lp55xx_engine engines[LP55XX_ENGINE_MAX];
111 const struct firmware *fw; 158 const struct firmware *fw;
112 }; 159 };
113 160
114 /* 161 /*
115 * struct lp55xx_led 162 * struct lp55xx_led
116 * @chan_nr : Channel number 163 * @chan_nr : Channel number
117 * @cdev : LED class device 164 * @cdev : LED class device
118 * @led_current : Current setting at each led channel 165 * @led_current : Current setting at each led channel
119 * @max_current : Maximun current at each led channel 166 * @max_current : Maximun current at each led channel
120 * @brightness_work : Workqueue for brightness control 167 * @brightness_work : Workqueue for brightness control
121 * @brightness : Brightness value 168 * @brightness : Brightness value
122 * @chip : The lp55xx chip data 169 * @chip : The lp55xx chip data
123 */ 170 */
124 struct lp55xx_led { 171 struct lp55xx_led {
125 int chan_nr; 172 int chan_nr;
126 struct led_classdev cdev; 173 struct led_classdev cdev;
127 u8 led_current; 174 u8 led_current;
128 u8 max_current; 175 u8 max_current;
129 struct work_struct brightness_work; 176 struct work_struct brightness_work;
130 u8 brightness; 177 u8 brightness;
131 struct lp55xx_chip *chip; 178 struct lp55xx_chip *chip;
132 }; 179 };
133 180
134 /* register access */ 181 /* register access */
135 extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val); 182 extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val);
136 extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val); 183 extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val);
137 extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, 184 extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg,
138 u8 mask, u8 val); 185 u8 mask, u8 val);
139 186
140 /* external clock detection */ 187 /* external clock detection */
141 extern bool lp55xx_is_extclk_used(struct lp55xx_chip *chip); 188 extern bool lp55xx_is_extclk_used(struct lp55xx_chip *chip);
142 189
143 /* common device init/deinit functions */ 190 /* common device init/deinit functions */
144 extern int lp55xx_init_device(struct lp55xx_chip *chip); 191 extern int lp55xx_init_device(struct lp55xx_chip *chip);
145 extern void lp55xx_deinit_device(struct lp55xx_chip *chip); 192 extern void lp55xx_deinit_device(struct lp55xx_chip *chip);
146 193
147 /* common LED class device functions */ 194 /* common LED class device functions */
148 extern int lp55xx_register_leds(struct lp55xx_led *led, 195 extern int lp55xx_register_leds(struct lp55xx_led *led,
149 struct lp55xx_chip *chip); 196 struct lp55xx_chip *chip);
150 extern void lp55xx_unregister_leds(struct lp55xx_led *led, 197 extern void lp55xx_unregister_leds(struct lp55xx_led *led,
151 struct lp55xx_chip *chip); 198 struct lp55xx_chip *chip);
152 199
153 /* common device attributes functions */ 200 /* common device attributes functions */
154 extern int lp55xx_register_sysfs(struct lp55xx_chip *chip); 201 extern int lp55xx_register_sysfs(struct lp55xx_chip *chip);
155 extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip); 202 extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip);
156 203
157 /* common device tree population function */ 204 /* common device tree population function */
158 extern int lp55xx_of_populate_pdata(struct device *dev, 205 extern int lp55xx_of_populate_pdata(struct device *dev,
159 struct device_node *np); 206 struct device_node *np);
160 207
161 #endif /* _LEDS_LP55XX_COMMON_H */ 208 #endif /* _LEDS_LP55XX_COMMON_H */
162 209