leds-lp55xx-common.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. enum lp55xx_engine_index {
  17. LP55XX_ENGINE_INVALID,
  18. LP55XX_ENGINE_1,
  19. LP55XX_ENGINE_2,
  20. LP55XX_ENGINE_3,
  21. LP55XX_ENGINE_MAX = LP55XX_ENGINE_3,
  22. };
  23. enum lp55xx_engine_mode {
  24. LP55XX_ENGINE_DISABLED,
  25. LP55XX_ENGINE_LOAD,
  26. LP55XX_ENGINE_RUN,
  27. };
  28. struct lp55xx_led;
  29. struct lp55xx_chip;
  30. /*
  31. * struct lp55xx_reg
  32. * @addr : Register address
  33. * @val : Register value
  34. */
  35. struct lp55xx_reg {
  36. u8 addr;
  37. u8 val;
  38. };
  39. /*
  40. * struct lp55xx_device_config
  41. * @reset : Chip specific reset command
  42. * @enable : Chip specific enable command
  43. * @max_channel : Maximum number of channels
  44. * @post_init_device : Chip specific initialization code
  45. * @brightness_work_fn : Brightness work function
  46. * @set_led_current : LED current set function
  47. * @firmware_cb : Call function when the firmware is loaded
  48. * @run_engine : Run internal engine for pattern
  49. * @dev_attr_group : Device specific attributes
  50. */
  51. struct lp55xx_device_config {
  52. const struct lp55xx_reg reset;
  53. const struct lp55xx_reg enable;
  54. const int max_channel;
  55. /* define if the device has specific initialization process */
  56. int (*post_init_device) (struct lp55xx_chip *chip);
  57. /* access brightness register */
  58. void (*brightness_work_fn)(struct work_struct *work);
  59. /* current setting function */
  60. void (*set_led_current) (struct lp55xx_led *led, u8 led_current);
  61. /* access program memory when the firmware is loaded */
  62. void (*firmware_cb)(struct lp55xx_chip *chip);
  63. /* used for running firmware LED patterns */
  64. void (*run_engine) (struct lp55xx_chip *chip, bool start);
  65. /* additional device specific attributes */
  66. const struct attribute_group *dev_attr_group;
  67. };
  68. /*
  69. * struct lp55xx_engine
  70. * @mode : Engine mode
  71. * @led_mux : Mux bits for LED selection. Only used in LP5523
  72. */
  73. struct lp55xx_engine {
  74. enum lp55xx_engine_mode mode;
  75. u16 led_mux;
  76. };
  77. /*
  78. * struct lp55xx_chip
  79. * @cl : I2C communication for access registers
  80. * @pdata : Platform specific data
  81. * @lock : Lock for user-space interface
  82. * @num_leds : Number of registered LEDs
  83. * @cfg : Device specific configuration data
  84. * @engine_idx : Selected engine number
  85. * @engines : Engine structure for the device attribute R/W interface
  86. * @fw : Firmware data for running a LED pattern
  87. */
  88. struct lp55xx_chip {
  89. struct i2c_client *cl;
  90. struct clk *clk;
  91. struct lp55xx_platform_data *pdata;
  92. struct mutex lock; /* lock for user-space interface */
  93. int num_leds;
  94. struct lp55xx_device_config *cfg;
  95. enum lp55xx_engine_index engine_idx;
  96. struct lp55xx_engine engines[LP55XX_ENGINE_MAX];
  97. const struct firmware *fw;
  98. };
  99. /*
  100. * struct lp55xx_led
  101. * @chan_nr : Channel number
  102. * @cdev : LED class device
  103. * @led_current : Current setting at each led channel
  104. * @max_current : Maximun current at each led channel
  105. * @brightness_work : Workqueue for brightness control
  106. * @brightness : Brightness value
  107. * @chip : The lp55xx chip data
  108. */
  109. struct lp55xx_led {
  110. int chan_nr;
  111. struct led_classdev cdev;
  112. u8 led_current;
  113. u8 max_current;
  114. struct work_struct brightness_work;
  115. u8 brightness;
  116. struct lp55xx_chip *chip;
  117. };
  118. /* register access */
  119. extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val);
  120. extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val);
  121. extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg,
  122. u8 mask, u8 val);
  123. /* external clock detection */
  124. extern bool lp55xx_is_extclk_used(struct lp55xx_chip *chip);
  125. /* common device init/deinit functions */
  126. extern int lp55xx_init_device(struct lp55xx_chip *chip);
  127. extern void lp55xx_deinit_device(struct lp55xx_chip *chip);
  128. /* common LED class device functions */
  129. extern int lp55xx_register_leds(struct lp55xx_led *led,
  130. struct lp55xx_chip *chip);
  131. extern void lp55xx_unregister_leds(struct lp55xx_led *led,
  132. struct lp55xx_chip *chip);
  133. /* common device attributes functions */
  134. extern int lp55xx_register_sysfs(struct lp55xx_chip *chip);
  135. extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip);
  136. /* common device tree population function */
  137. extern int lp55xx_of_populate_pdata(struct device *dev,
  138. struct device_node *np);
  139. #endif /* _LEDS_LP55XX_COMMON_H */