blob: 783ed5103ce5ff5a0e00926bb57ed5f6a4950cba [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +09002/*
3 * LP55XX Common Driver Header
4 *
5 * Copyright (C) 2012 Texas Instruments
6 *
7 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
8 *
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +09009 * Derived from leds-lp5521.c, leds-lp5523.c
10 */
11
12#ifndef _LEDS_LP55XX_COMMON_H
13#define _LEDS_LP55XX_COMMON_H
14
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +090015enum lp55xx_engine_index {
16 LP55XX_ENGINE_INVALID,
17 LP55XX_ENGINE_1,
18 LP55XX_ENGINE_2,
19 LP55XX_ENGINE_3,
Milo Kim6841a912013-08-08 12:45:41 +090020 LP55XX_ENGINE_MAX = LP55XX_ENGINE_3,
21};
22
23enum lp55xx_engine_mode {
24 LP55XX_ENGINE_DISABLED,
25 LP55XX_ENGINE_LOAD,
26 LP55XX_ENGINE_RUN,
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +090027};
28
Milo Kim36030972013-08-08 12:46:43 +090029#define LP55XX_DEV_ATTR_RW(name, show, store) \
30 DEVICE_ATTR(name, S_IRUGO | S_IWUSR, show, store)
31#define LP55XX_DEV_ATTR_RO(name, show) \
32 DEVICE_ATTR(name, S_IRUGO, show, NULL)
33#define LP55XX_DEV_ATTR_WO(name, store) \
34 DEVICE_ATTR(name, S_IWUSR, NULL, store)
35
36#define show_mode(nr) \
37static ssize_t show_engine##nr##_mode(struct device *dev, \
38 struct device_attribute *attr, \
39 char *buf) \
40{ \
41 return show_engine_mode(dev, attr, buf, nr); \
42}
43
44#define store_mode(nr) \
45static ssize_t store_engine##nr##_mode(struct device *dev, \
46 struct device_attribute *attr, \
47 const char *buf, size_t len) \
48{ \
49 return store_engine_mode(dev, attr, buf, len, nr); \
50}
51
52#define show_leds(nr) \
53static ssize_t show_engine##nr##_leds(struct device *dev, \
54 struct device_attribute *attr, \
55 char *buf) \
56{ \
57 return show_engine_leds(dev, attr, buf, nr); \
58}
59
60#define store_leds(nr) \
61static ssize_t store_engine##nr##_leds(struct device *dev, \
62 struct device_attribute *attr, \
63 const char *buf, size_t len) \
64{ \
65 return store_engine_leds(dev, attr, buf, len, nr); \
66}
67
68#define store_load(nr) \
69static ssize_t store_engine##nr##_load(struct device *dev, \
70 struct device_attribute *attr, \
71 const char *buf, size_t len) \
72{ \
73 return store_engine_load(dev, attr, buf, len, nr); \
74}
75
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090076struct lp55xx_led;
77struct lp55xx_chip;
78
79/*
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090080 * struct lp55xx_reg
81 * @addr : Register address
82 * @val : Register value
83 */
84struct lp55xx_reg {
85 u8 addr;
86 u8 val;
87};
88
89/*
90 * struct lp55xx_device_config
91 * @reset : Chip specific reset command
Milo(Woogyom) Kime3a700d2013-02-05 18:09:56 +090092 * @enable : Chip specific enable command
Milo(Woogyom) Kim0e202342013-02-05 19:07:34 +090093 * @max_channel : Maximum number of channels
Milo(Woogyom) Kimffbdccd2013-02-05 18:57:36 +090094 * @post_init_device : Chip specific initialization code
Andrew Lunn95b2af62015-08-20 12:22:57 +020095 * @brightness_fn : Brightness function
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +090096 * @set_led_current : LED current set function
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +090097 * @firmware_cb : Call function when the firmware is loaded
98 * @run_engine : Run internal engine for pattern
Milo(Woogyom) Kim240085e2013-02-05 19:20:01 +090099 * @dev_attr_group : Device specific attributes
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +0900100 */
101struct lp55xx_device_config {
102 const struct lp55xx_reg reset;
Milo(Woogyom) Kime3a700d2013-02-05 18:09:56 +0900103 const struct lp55xx_reg enable;
Milo(Woogyom) Kim0e202342013-02-05 19:07:34 +0900104 const int max_channel;
Milo(Woogyom) Kimffbdccd2013-02-05 18:57:36 +0900105
106 /* define if the device has specific initialization process */
107 int (*post_init_device) (struct lp55xx_chip *chip);
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +0900108
109 /* access brightness register */
Andrew Lunn95b2af62015-08-20 12:22:57 +0200110 int (*brightness_fn)(struct lp55xx_led *led);
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +0900111
112 /* current setting function */
113 void (*set_led_current) (struct lp55xx_led *led, u8 led_current);
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +0900114
115 /* access program memory when the firmware is loaded */
116 void (*firmware_cb)(struct lp55xx_chip *chip);
117
118 /* used for running firmware LED patterns */
119 void (*run_engine) (struct lp55xx_chip *chip, bool start);
Milo(Woogyom) Kim240085e2013-02-05 19:20:01 +0900120
121 /* additional device specific attributes */
122 const struct attribute_group *dev_attr_group;
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +0900123};
124
125/*
Milo Kim6841a912013-08-08 12:45:41 +0900126 * struct lp55xx_engine
127 * @mode : Engine mode
128 * @led_mux : Mux bits for LED selection. Only used in LP5523
129 */
130struct lp55xx_engine {
131 enum lp55xx_engine_mode mode;
132 u16 led_mux;
133};
134
135/*
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900136 * struct lp55xx_chip
137 * @cl : I2C communication for access registers
138 * @pdata : Platform specific data
139 * @lock : Lock for user-space interface
140 * @num_leds : Number of registered LEDs
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +0900141 * @cfg : Device specific configuration data
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +0900142 * @engine_idx : Selected engine number
Milo Kim6841a912013-08-08 12:45:41 +0900143 * @engines : Engine structure for the device attribute R/W interface
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +0900144 * @fw : Firmware data for running a LED pattern
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900145 */
146struct lp55xx_chip {
147 struct i2c_client *cl;
Kim, Milo53b41922013-03-20 17:37:00 -0700148 struct clk *clk;
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900149 struct lp55xx_platform_data *pdata;
150 struct mutex lock; /* lock for user-space interface */
151 int num_leds;
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +0900152 struct lp55xx_device_config *cfg;
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +0900153 enum lp55xx_engine_index engine_idx;
Milo Kim6841a912013-08-08 12:45:41 +0900154 struct lp55xx_engine engines[LP55XX_ENGINE_MAX];
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +0900155 const struct firmware *fw;
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900156};
157
158/*
159 * struct lp55xx_led
160 * @chan_nr : Channel number
161 * @cdev : LED class device
162 * @led_current : Current setting at each led channel
163 * @max_current : Maximun current at each led channel
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900164 * @brightness : Brightness value
165 * @chip : The lp55xx chip data
166 */
167struct lp55xx_led {
168 int chan_nr;
169 struct led_classdev cdev;
170 u8 led_current;
171 u8 max_current;
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900172 u8 brightness;
173 struct lp55xx_chip *chip;
174};
175
176/* register access */
177extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val);
178extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val);
179extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg,
180 u8 mask, u8 val);
181
Kim, Milo53b41922013-03-20 17:37:00 -0700182/* external clock detection */
183extern bool lp55xx_is_extclk_used(struct lp55xx_chip *chip);
184
Milo(Woogyom) Kim6ce61762013-02-05 19:03:02 +0900185/* common device init/deinit functions */
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900186extern int lp55xx_init_device(struct lp55xx_chip *chip);
Milo(Woogyom) Kim6ce61762013-02-05 19:03:02 +0900187extern void lp55xx_deinit_device(struct lp55xx_chip *chip);
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900188
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +0900189/* common LED class device functions */
190extern int lp55xx_register_leds(struct lp55xx_led *led,
191 struct lp55xx_chip *chip);
Milo(Woogyom) Kimc3a68eb2013-02-05 19:11:18 +0900192extern void lp55xx_unregister_leds(struct lp55xx_led *led,
193 struct lp55xx_chip *chip);
Milo(Woogyom) Kimb3b6f812013-02-05 19:15:27 +0900194
195/* common device attributes functions */
196extern int lp55xx_register_sysfs(struct lp55xx_chip *chip);
Milo(Woogyom) Kimba6fa842013-02-05 19:23:04 +0900197extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip);
Milo(Woogyom) Kimb3b6f812013-02-05 19:15:27 +0900198
Linus Walleij7542a04b2013-04-23 04:52:59 -0700199/* common device tree population function */
Milo Kimed1333522015-08-24 16:09:55 +0900200extern struct lp55xx_platform_data
201*lp55xx_of_populate_pdata(struct device *dev, struct device_node *np);
Linus Walleij7542a04b2013-04-23 04:52:59 -0700202
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900203#endif /* _LEDS_LP55XX_COMMON_H */