leds-lp55xx-common.h 3.0 KB

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