blob: fa6a078bf5471131f14ac1e4d7d1091fa87c36e4 [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,
23};
24
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090025struct lp55xx_led;
26struct lp55xx_chip;
27
28/*
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090029 * struct lp55xx_reg
30 * @addr : Register address
31 * @val : Register value
32 */
33struct lp55xx_reg {
34 u8 addr;
35 u8 val;
36};
37
38/*
39 * struct lp55xx_device_config
40 * @reset : Chip specific reset command
Milo(Woogyom) Kime3a700d2013-02-05 18:09:56 +090041 * @enable : Chip specific enable command
Milo(Woogyom) Kim0e202342013-02-05 19:07:34 +090042 * @max_channel : Maximum number of channels
Milo(Woogyom) Kimffbdccd2013-02-05 18:57:36 +090043 * @post_init_device : Chip specific initialization code
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +090044 * @brightness_work_fn : Brightness work function
45 * @set_led_current : LED current set function
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +090046 * @firmware_cb : Call function when the firmware is loaded
47 * @run_engine : Run internal engine for pattern
Milo(Woogyom) Kim240085e2013-02-05 19:20:01 +090048 * @dev_attr_group : Device specific attributes
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090049 */
50struct lp55xx_device_config {
51 const struct lp55xx_reg reset;
Milo(Woogyom) Kime3a700d2013-02-05 18:09:56 +090052 const struct lp55xx_reg enable;
Milo(Woogyom) Kim0e202342013-02-05 19:07:34 +090053 const int max_channel;
Milo(Woogyom) Kimffbdccd2013-02-05 18:57:36 +090054
55 /* define if the device has specific initialization process */
56 int (*post_init_device) (struct lp55xx_chip *chip);
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +090057
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);
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +090063
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);
Milo(Woogyom) Kim240085e2013-02-05 19:20:01 +090069
70 /* additional device specific attributes */
71 const struct attribute_group *dev_attr_group;
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090072};
73
74/*
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090075 * 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
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090080 * @cfg : Device specific configuration data
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +090081 * @engine_idx : Selected engine number
82 * @fw : Firmware data for running a LED pattern
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090083 */
84struct lp55xx_chip {
85 struct i2c_client *cl;
Kim, Milo53b41922013-03-20 17:37:00 -070086 struct clk *clk;
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090087 struct lp55xx_platform_data *pdata;
88 struct mutex lock; /* lock for user-space interface */
89 int num_leds;
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090090 struct lp55xx_device_config *cfg;
Milo(Woogyom) Kim10c06d12013-02-05 19:17:20 +090091 enum lp55xx_engine_index engine_idx;
92 const struct firmware *fw;
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090093};
94
95/*
96 * struct lp55xx_led
97 * @chan_nr : Channel number
98 * @cdev : LED class device
99 * @led_current : Current setting at each led channel
100 * @max_current : Maximun current at each led channel
101 * @brightness_work : Workqueue for brightness control
102 * @brightness : Brightness value
103 * @chip : The lp55xx chip data
104 */
105struct lp55xx_led {
106 int chan_nr;
107 struct led_classdev cdev;
108 u8 led_current;
109 u8 max_current;
110 struct work_struct brightness_work;
111 u8 brightness;
112 struct lp55xx_chip *chip;
113};
114
115/* register access */
116extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val);
117extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val);
118extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg,
119 u8 mask, u8 val);
120
Kim, Milo53b41922013-03-20 17:37:00 -0700121/* external clock detection */
122extern bool lp55xx_is_extclk_used(struct lp55xx_chip *chip);
123
Milo(Woogyom) Kim6ce61762013-02-05 19:03:02 +0900124/* common device init/deinit functions */
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900125extern int lp55xx_init_device(struct lp55xx_chip *chip);
Milo(Woogyom) Kim6ce61762013-02-05 19:03:02 +0900126extern void lp55xx_deinit_device(struct lp55xx_chip *chip);
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900127
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +0900128/* common LED class device functions */
129extern int lp55xx_register_leds(struct lp55xx_led *led,
130 struct lp55xx_chip *chip);
Milo(Woogyom) Kimc3a68eb2013-02-05 19:11:18 +0900131extern void lp55xx_unregister_leds(struct lp55xx_led *led,
132 struct lp55xx_chip *chip);
Milo(Woogyom) Kimb3b6f812013-02-05 19:15:27 +0900133
134/* common device attributes functions */
135extern int lp55xx_register_sysfs(struct lp55xx_chip *chip);
Milo(Woogyom) Kimba6fa842013-02-05 19:23:04 +0900136extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip);
Milo(Woogyom) Kimb3b6f812013-02-05 19:15:27 +0900137
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900138#endif /* _LEDS_LP55XX_COMMON_H */