Milo(Woogyom) Kim | c93d08f | 2013-02-05 18:01:23 +0900 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | struct lp55xx_led; |
| 19 | struct lp55xx_chip; |
| 20 | |
| 21 | /* |
Milo(Woogyom) Kim | 48068d5 | 2013-02-05 18:08:49 +0900 | [diff] [blame] | 22 | * struct lp55xx_reg |
| 23 | * @addr : Register address |
| 24 | * @val : Register value |
| 25 | */ |
| 26 | struct lp55xx_reg { |
| 27 | u8 addr; |
| 28 | u8 val; |
| 29 | }; |
| 30 | |
| 31 | /* |
| 32 | * struct lp55xx_device_config |
| 33 | * @reset : Chip specific reset command |
Milo(Woogyom) Kim | e3a700d | 2013-02-05 18:09:56 +0900 | [diff] [blame] | 34 | * @enable : Chip specific enable command |
Milo(Woogyom) Kim | ffbdccd | 2013-02-05 18:57:36 +0900 | [diff] [blame] | 35 | * @post_init_device : Chip specific initialization code |
Milo(Woogyom) Kim | 9e9b3db | 2013-02-05 19:06:27 +0900 | [diff] [blame^] | 36 | * @brightness_work_fn : Brightness work function |
| 37 | * @set_led_current : LED current set function |
Milo(Woogyom) Kim | 48068d5 | 2013-02-05 18:08:49 +0900 | [diff] [blame] | 38 | */ |
| 39 | struct lp55xx_device_config { |
| 40 | const struct lp55xx_reg reset; |
Milo(Woogyom) Kim | e3a700d | 2013-02-05 18:09:56 +0900 | [diff] [blame] | 41 | const struct lp55xx_reg enable; |
Milo(Woogyom) Kim | ffbdccd | 2013-02-05 18:57:36 +0900 | [diff] [blame] | 42 | |
| 43 | /* define if the device has specific initialization process */ |
| 44 | int (*post_init_device) (struct lp55xx_chip *chip); |
Milo(Woogyom) Kim | 9e9b3db | 2013-02-05 19:06:27 +0900 | [diff] [blame^] | 45 | |
| 46 | /* access brightness register */ |
| 47 | void (*brightness_work_fn)(struct work_struct *work); |
| 48 | |
| 49 | /* current setting function */ |
| 50 | void (*set_led_current) (struct lp55xx_led *led, u8 led_current); |
Milo(Woogyom) Kim | 48068d5 | 2013-02-05 18:08:49 +0900 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | /* |
Milo(Woogyom) Kim | c93d08f | 2013-02-05 18:01:23 +0900 | [diff] [blame] | 54 | * struct lp55xx_chip |
| 55 | * @cl : I2C communication for access registers |
| 56 | * @pdata : Platform specific data |
| 57 | * @lock : Lock for user-space interface |
| 58 | * @num_leds : Number of registered LEDs |
Milo(Woogyom) Kim | 48068d5 | 2013-02-05 18:08:49 +0900 | [diff] [blame] | 59 | * @cfg : Device specific configuration data |
Milo(Woogyom) Kim | c93d08f | 2013-02-05 18:01:23 +0900 | [diff] [blame] | 60 | */ |
| 61 | struct lp55xx_chip { |
| 62 | struct i2c_client *cl; |
| 63 | struct lp55xx_platform_data *pdata; |
| 64 | struct mutex lock; /* lock for user-space interface */ |
| 65 | int num_leds; |
Milo(Woogyom) Kim | 48068d5 | 2013-02-05 18:08:49 +0900 | [diff] [blame] | 66 | struct lp55xx_device_config *cfg; |
Milo(Woogyom) Kim | c93d08f | 2013-02-05 18:01:23 +0900 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | /* |
| 70 | * struct lp55xx_led |
| 71 | * @chan_nr : Channel number |
| 72 | * @cdev : LED class device |
| 73 | * @led_current : Current setting at each led channel |
| 74 | * @max_current : Maximun current at each led channel |
| 75 | * @brightness_work : Workqueue for brightness control |
| 76 | * @brightness : Brightness value |
| 77 | * @chip : The lp55xx chip data |
| 78 | */ |
| 79 | struct lp55xx_led { |
| 80 | int chan_nr; |
| 81 | struct led_classdev cdev; |
| 82 | u8 led_current; |
| 83 | u8 max_current; |
| 84 | struct work_struct brightness_work; |
| 85 | u8 brightness; |
| 86 | struct lp55xx_chip *chip; |
| 87 | }; |
| 88 | |
| 89 | /* register access */ |
| 90 | extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val); |
| 91 | extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val); |
| 92 | extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, |
| 93 | u8 mask, u8 val); |
| 94 | |
Milo(Woogyom) Kim | 6ce6176 | 2013-02-05 19:03:02 +0900 | [diff] [blame] | 95 | /* common device init/deinit functions */ |
Milo(Woogyom) Kim | a85908d | 2013-02-05 18:07:20 +0900 | [diff] [blame] | 96 | extern int lp55xx_init_device(struct lp55xx_chip *chip); |
Milo(Woogyom) Kim | 6ce6176 | 2013-02-05 19:03:02 +0900 | [diff] [blame] | 97 | extern void lp55xx_deinit_device(struct lp55xx_chip *chip); |
Milo(Woogyom) Kim | a85908d | 2013-02-05 18:07:20 +0900 | [diff] [blame] | 98 | |
Milo(Woogyom) Kim | 9e9b3db | 2013-02-05 19:06:27 +0900 | [diff] [blame^] | 99 | /* common LED class device functions */ |
| 100 | extern int lp55xx_register_leds(struct lp55xx_led *led, |
| 101 | struct lp55xx_chip *chip); |
Milo(Woogyom) Kim | c93d08f | 2013-02-05 18:01:23 +0900 | [diff] [blame] | 102 | #endif /* _LEDS_LP55XX_COMMON_H */ |