0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef _LEDS_LP55XX_COMMON_H
0013 #define _LEDS_LP55XX_COMMON_H
0014
0015 #include <linux/led-class-multicolor.h>
0016
0017 enum lp55xx_engine_index {
0018 LP55XX_ENGINE_INVALID,
0019 LP55XX_ENGINE_1,
0020 LP55XX_ENGINE_2,
0021 LP55XX_ENGINE_3,
0022 LP55XX_ENGINE_MAX = LP55XX_ENGINE_3,
0023 };
0024
0025 enum lp55xx_engine_mode {
0026 LP55XX_ENGINE_DISABLED,
0027 LP55XX_ENGINE_LOAD,
0028 LP55XX_ENGINE_RUN,
0029 };
0030
0031 #define LP55XX_DEV_ATTR_RW(name, show, store) \
0032 DEVICE_ATTR(name, S_IRUGO | S_IWUSR, show, store)
0033 #define LP55XX_DEV_ATTR_RO(name, show) \
0034 DEVICE_ATTR(name, S_IRUGO, show, NULL)
0035 #define LP55XX_DEV_ATTR_WO(name, store) \
0036 DEVICE_ATTR(name, S_IWUSR, NULL, store)
0037
0038 #define show_mode(nr) \
0039 static ssize_t show_engine##nr##_mode(struct device *dev, \
0040 struct device_attribute *attr, \
0041 char *buf) \
0042 { \
0043 return show_engine_mode(dev, attr, buf, nr); \
0044 }
0045
0046 #define store_mode(nr) \
0047 static ssize_t store_engine##nr##_mode(struct device *dev, \
0048 struct device_attribute *attr, \
0049 const char *buf, size_t len) \
0050 { \
0051 return store_engine_mode(dev, attr, buf, len, nr); \
0052 }
0053
0054 #define show_leds(nr) \
0055 static ssize_t show_engine##nr##_leds(struct device *dev, \
0056 struct device_attribute *attr, \
0057 char *buf) \
0058 { \
0059 return show_engine_leds(dev, attr, buf, nr); \
0060 }
0061
0062 #define store_leds(nr) \
0063 static ssize_t store_engine##nr##_leds(struct device *dev, \
0064 struct device_attribute *attr, \
0065 const char *buf, size_t len) \
0066 { \
0067 return store_engine_leds(dev, attr, buf, len, nr); \
0068 }
0069
0070 #define store_load(nr) \
0071 static ssize_t store_engine##nr##_load(struct device *dev, \
0072 struct device_attribute *attr, \
0073 const char *buf, size_t len) \
0074 { \
0075 return store_engine_load(dev, attr, buf, len, nr); \
0076 }
0077
0078 struct lp55xx_led;
0079 struct lp55xx_chip;
0080
0081
0082
0083
0084
0085
0086 struct lp55xx_reg {
0087 u8 addr;
0088 u8 val;
0089 };
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 struct lp55xx_device_config {
0105 const struct lp55xx_reg reset;
0106 const struct lp55xx_reg enable;
0107 const int max_channel;
0108
0109
0110 int (*post_init_device) (struct lp55xx_chip *chip);
0111
0112
0113 int (*brightness_fn)(struct lp55xx_led *led);
0114
0115
0116 int (*multicolor_brightness_fn)(struct lp55xx_led *led);
0117
0118
0119 void (*set_led_current) (struct lp55xx_led *led, u8 led_current);
0120
0121
0122 void (*firmware_cb)(struct lp55xx_chip *chip);
0123
0124
0125 void (*run_engine) (struct lp55xx_chip *chip, bool start);
0126
0127
0128 const struct attribute_group *dev_attr_group;
0129 };
0130
0131
0132
0133
0134
0135
0136 struct lp55xx_engine {
0137 enum lp55xx_engine_mode mode;
0138 u16 led_mux;
0139 };
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152 struct lp55xx_chip {
0153 struct i2c_client *cl;
0154 struct clk *clk;
0155 struct lp55xx_platform_data *pdata;
0156 struct mutex lock;
0157 int num_leds;
0158 struct lp55xx_device_config *cfg;
0159 enum lp55xx_engine_index engine_idx;
0160 struct lp55xx_engine engines[LP55XX_ENGINE_MAX];
0161 const struct firmware *fw;
0162 };
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175 struct lp55xx_led {
0176 int chan_nr;
0177 struct led_classdev cdev;
0178 struct led_classdev_mc mc_cdev;
0179 u8 led_current;
0180 u8 max_current;
0181 u8 brightness;
0182 struct lp55xx_chip *chip;
0183 };
0184
0185
0186 extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val);
0187 extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val);
0188 extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg,
0189 u8 mask, u8 val);
0190
0191
0192 extern bool lp55xx_is_extclk_used(struct lp55xx_chip *chip);
0193
0194
0195 extern int lp55xx_init_device(struct lp55xx_chip *chip);
0196 extern void lp55xx_deinit_device(struct lp55xx_chip *chip);
0197
0198
0199 extern int lp55xx_register_leds(struct lp55xx_led *led,
0200 struct lp55xx_chip *chip);
0201
0202
0203 extern int lp55xx_register_sysfs(struct lp55xx_chip *chip);
0204 extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip);
0205
0206
0207 extern struct lp55xx_platform_data
0208 *lp55xx_of_populate_pdata(struct device *dev, struct device_node *np,
0209 struct lp55xx_chip *chip);
0210
0211 #endif