blob: 04c1d4fc18c04768a652be63ae0f8a1c73845766 [file] [log] [blame]
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +09001/*
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) Kim10c06d12013-02-05 19:17:20 +090018enum lp55xx_engine_index {
19 LP55XX_ENGINE_INVALID,
20 LP55XX_ENGINE_1,
21 LP55XX_ENGINE_2,
22 LP55XX_ENGINE_3,
Milo Kim6841a912013-08-08 12:45:41 +090023 LP55XX_ENGINE_MAX = LP55XX_ENGINE_3,
24};
25
26enum lp55xx_engine_mode {
27 LP55XX_ENGINE_DISABLED,
28 LP55XX_ENGINE_LOAD,
29 LP55XX_ENGINE_RUN,
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +090030};
31
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090032struct lp55xx_led;
33struct lp55xx_chip;
34
35/*
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090036 * struct lp55xx_reg
37 * @addr : Register address
38 * @val : Register value
39 */
40struct lp55xx_reg {
41 u8 addr;
42 u8 val;
43};
44
45/*
46 * struct lp55xx_device_config
47 * @reset : Chip specific reset command
Milo(Woogyom) Kime3a700d2013-02-05 18:09:56 +090048 * @enable : Chip specific enable command
Milo(Woogyom) Kim0e202342013-02-05 19:07:34 +090049 * @max_channel : Maximum number of channels
Milo(Woogyom) Kimffbdccd2013-02-05 18:57:36 +090050 * @post_init_device : Chip specific initialization code
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +090051 * @brightness_work_fn : Brightness work function
52 * @set_led_current : LED current set function
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +090053 * @firmware_cb : Call function when the firmware is loaded
54 * @run_engine : Run internal engine for pattern
Milo(Woogyom) Kim240085e2013-02-05 19:20:01 +090055 * @dev_attr_group : Device specific attributes
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090056 */
57struct lp55xx_device_config {
58 const struct lp55xx_reg reset;
Milo(Woogyom) Kime3a700d2013-02-05 18:09:56 +090059 const struct lp55xx_reg enable;
Milo(Woogyom) Kim0e202342013-02-05 19:07:34 +090060 const int max_channel;
Milo(Woogyom) Kimffbdccd2013-02-05 18:57:36 +090061
62 /* define if the device has specific initialization process */
63 int (*post_init_device) (struct lp55xx_chip *chip);
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +090064
65 /* access brightness register */
66 void (*brightness_work_fn)(struct work_struct *work);
67
68 /* current setting function */
69 void (*set_led_current) (struct lp55xx_led *led, u8 led_current);
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +090070
71 /* access program memory when the firmware is loaded */
72 void (*firmware_cb)(struct lp55xx_chip *chip);
73
74 /* used for running firmware LED patterns */
75 void (*run_engine) (struct lp55xx_chip *chip, bool start);
Milo(Woogyom) Kim240085e2013-02-05 19:20:01 +090076
77 /* additional device specific attributes */
78 const struct attribute_group *dev_attr_group;
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090079};
80
81/*
Milo Kim6841a912013-08-08 12:45:41 +090082 * struct lp55xx_engine
83 * @mode : Engine mode
84 * @led_mux : Mux bits for LED selection. Only used in LP5523
85 */
86struct lp55xx_engine {
87 enum lp55xx_engine_mode mode;
88 u16 led_mux;
89};
90
91/*
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090092 * struct lp55xx_chip
93 * @cl : I2C communication for access registers
94 * @pdata : Platform specific data
95 * @lock : Lock for user-space interface
96 * @num_leds : Number of registered LEDs
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090097 * @cfg : Device specific configuration data
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +090098 * @engine_idx : Selected engine number
Milo Kim6841a912013-08-08 12:45:41 +090099 * @engines : Engine structure for the device attribute R/W interface
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +0900100 * @fw : Firmware data for running a LED pattern
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900101 */
102struct lp55xx_chip {
103 struct i2c_client *cl;
Kim, Milo53b41922013-03-20 17:37:00 -0700104 struct clk *clk;
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900105 struct lp55xx_platform_data *pdata;
106 struct mutex lock; /* lock for user-space interface */
107 int num_leds;
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +0900108 struct lp55xx_device_config *cfg;
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +0900109 enum lp55xx_engine_index engine_idx;
Milo Kim6841a912013-08-08 12:45:41 +0900110 struct lp55xx_engine engines[LP55XX_ENGINE_MAX];
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +0900111 const struct firmware *fw;
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900112};
113
114/*
115 * struct lp55xx_led
116 * @chan_nr : Channel number
117 * @cdev : LED class device
118 * @led_current : Current setting at each led channel
119 * @max_current : Maximun current at each led channel
120 * @brightness_work : Workqueue for brightness control
121 * @brightness : Brightness value
122 * @chip : The lp55xx chip data
123 */
124struct lp55xx_led {
125 int chan_nr;
126 struct led_classdev cdev;
127 u8 led_current;
128 u8 max_current;
129 struct work_struct brightness_work;
130 u8 brightness;
131 struct lp55xx_chip *chip;
132};
133
134/* register access */
135extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val);
136extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val);
137extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg,
138 u8 mask, u8 val);
139
Kim, Milo53b41922013-03-20 17:37:00 -0700140/* external clock detection */
141extern bool lp55xx_is_extclk_used(struct lp55xx_chip *chip);
142
Milo(Woogyom) Kim6ce61762013-02-05 19:03:02 +0900143/* common device init/deinit functions */
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900144extern int lp55xx_init_device(struct lp55xx_chip *chip);
Milo(Woogyom) Kim6ce61762013-02-05 19:03:02 +0900145extern void lp55xx_deinit_device(struct lp55xx_chip *chip);
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900146
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +0900147/* common LED class device functions */
148extern int lp55xx_register_leds(struct lp55xx_led *led,
149 struct lp55xx_chip *chip);
Milo(Woogyom) Kimc3a68eb2013-02-05 19:11:18 +0900150extern void lp55xx_unregister_leds(struct lp55xx_led *led,
151 struct lp55xx_chip *chip);
Milo(Woogyom) Kimb3b6f812013-02-05 19:15:27 +0900152
153/* common device attributes functions */
154extern int lp55xx_register_sysfs(struct lp55xx_chip *chip);
Milo(Woogyom) Kimba6fa842013-02-05 19:23:04 +0900155extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip);
Milo(Woogyom) Kimb3b6f812013-02-05 19:15:27 +0900156
Linus Walleij7542a042013-04-23 04:52:59 -0700157/* common device tree population function */
158extern int lp55xx_of_populate_pdata(struct device *dev,
159 struct device_node *np);
160
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900161#endif /* _LEDS_LP55XX_COMMON_H */