blob: 32d96828cbc6094090947100d82f8a0b2f582667 [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
18struct lp55xx_led;
19struct lp55xx_chip;
20
21/*
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090022 * struct lp55xx_reg
23 * @addr : Register address
24 * @val : Register value
25 */
26struct lp55xx_reg {
27 u8 addr;
28 u8 val;
29};
30
31/*
32 * struct lp55xx_device_config
33 * @reset : Chip specific reset command
Milo(Woogyom) Kime3a700d2013-02-05 18:09:56 +090034 * @enable : Chip specific enable command
Milo(Woogyom) Kim0e202342013-02-05 19:07:34 +090035 * @max_channel : Maximum number of channels
Milo(Woogyom) Kimffbdccd2013-02-05 18:57:36 +090036 * @post_init_device : Chip specific initialization code
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +090037 * @brightness_work_fn : Brightness work function
38 * @set_led_current : LED current set function
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090039 */
40struct lp55xx_device_config {
41 const struct lp55xx_reg reset;
Milo(Woogyom) Kime3a700d2013-02-05 18:09:56 +090042 const struct lp55xx_reg enable;
Milo(Woogyom) Kim0e202342013-02-05 19:07:34 +090043 const int max_channel;
Milo(Woogyom) Kimffbdccd2013-02-05 18:57:36 +090044
45 /* define if the device has specific initialization process */
46 int (*post_init_device) (struct lp55xx_chip *chip);
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +090047
48 /* access brightness register */
49 void (*brightness_work_fn)(struct work_struct *work);
50
51 /* current setting function */
52 void (*set_led_current) (struct lp55xx_led *led, u8 led_current);
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090053};
54
55/*
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090056 * struct lp55xx_chip
57 * @cl : I2C communication for access registers
58 * @pdata : Platform specific data
59 * @lock : Lock for user-space interface
60 * @num_leds : Number of registered LEDs
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090061 * @cfg : Device specific configuration data
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090062 */
63struct lp55xx_chip {
64 struct i2c_client *cl;
65 struct lp55xx_platform_data *pdata;
66 struct mutex lock; /* lock for user-space interface */
67 int num_leds;
Milo(Woogyom) Kim48068d52013-02-05 18:08:49 +090068 struct lp55xx_device_config *cfg;
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +090069};
70
71/*
72 * struct lp55xx_led
73 * @chan_nr : Channel number
74 * @cdev : LED class device
75 * @led_current : Current setting at each led channel
76 * @max_current : Maximun current at each led channel
77 * @brightness_work : Workqueue for brightness control
78 * @brightness : Brightness value
79 * @chip : The lp55xx chip data
80 */
81struct lp55xx_led {
82 int chan_nr;
83 struct led_classdev cdev;
84 u8 led_current;
85 u8 max_current;
86 struct work_struct brightness_work;
87 u8 brightness;
88 struct lp55xx_chip *chip;
89};
90
91/* register access */
92extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val);
93extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val);
94extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg,
95 u8 mask, u8 val);
96
Milo(Woogyom) Kim6ce61762013-02-05 19:03:02 +090097/* common device init/deinit functions */
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +090098extern int lp55xx_init_device(struct lp55xx_chip *chip);
Milo(Woogyom) Kim6ce61762013-02-05 19:03:02 +090099extern void lp55xx_deinit_device(struct lp55xx_chip *chip);
Milo(Woogyom) Kima85908d2013-02-05 18:07:20 +0900100
Milo(Woogyom) Kim9e9b3db2013-02-05 19:06:27 +0900101/* common LED class device functions */
102extern int lp55xx_register_leds(struct lp55xx_led *led,
103 struct lp55xx_chip *chip);
Milo(Woogyom) Kimc3a68eb2013-02-05 19:11:18 +0900104extern void lp55xx_unregister_leds(struct lp55xx_led *led,
105 struct lp55xx_chip *chip);
Milo(Woogyom) Kimc93d08f2013-02-05 18:01:23 +0900106#endif /* _LEDS_LP55XX_COMMON_H */