leds-lp55xx-common.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. };
  22. struct lp55xx_led;
  23. struct lp55xx_chip;
  24. /*
  25. * struct lp55xx_reg
  26. * @addr : Register address
  27. * @val : Register value
  28. */
  29. struct lp55xx_reg {
  30. u8 addr;
  31. u8 val;
  32. };
  33. /*
  34. * struct lp55xx_device_config
  35. * @reset : Chip specific reset command
  36. * @enable : Chip specific enable command
  37. * @max_channel : Maximum number of channels
  38. * @post_init_device : Chip specific initialization code
  39. * @brightness_work_fn : Brightness work function
  40. * @set_led_current : LED current set function
  41. * @firmware_cb : Call function when the firmware is loaded
  42. * @run_engine : Run internal engine for pattern
  43. * @dev_attr_group : Device specific attributes
  44. */
  45. struct lp55xx_device_config {
  46. const struct lp55xx_reg reset;
  47. const struct lp55xx_reg enable;
  48. const int max_channel;
  49. /* define if the device has specific initialization process */
  50. int (*post_init_device) (struct lp55xx_chip *chip);
  51. /* access brightness register */
  52. void (*brightness_work_fn)(struct work_struct *work);
  53. /* current setting function */
  54. void (*set_led_current) (struct lp55xx_led *led, u8 led_current);
  55. /* access program memory when the firmware is loaded */
  56. void (*firmware_cb)(struct lp55xx_chip *chip);
  57. /* used for running firmware LED patterns */
  58. void (*run_engine) (struct lp55xx_chip *chip, bool start);
  59. /* additional device specific attributes */
  60. const struct attribute_group *dev_attr_group;
  61. };
  62. /*
  63. * struct lp55xx_chip
  64. * @cl : I2C communication for access registers
  65. * @pdata : Platform specific data
  66. * @lock : Lock for user-space interface
  67. * @num_leds : Number of registered LEDs
  68. * @cfg : Device specific configuration data
  69. * @engine_idx : Selected engine number
  70. * @fw : Firmware data for running a LED pattern
  71. */
  72. struct lp55xx_chip {
  73. struct i2c_client *cl;
  74. struct lp55xx_platform_data *pdata;
  75. struct mutex lock; /* lock for user-space interface */
  76. int num_leds;
  77. struct lp55xx_device_config *cfg;
  78. enum lp55xx_engine_index engine_idx;
  79. const struct firmware *fw;
  80. };
  81. /*
  82. * struct lp55xx_led
  83. * @chan_nr : Channel number
  84. * @cdev : LED class device
  85. * @led_current : Current setting at each led channel
  86. * @max_current : Maximun current at each led channel
  87. * @brightness_work : Workqueue for brightness control
  88. * @brightness : Brightness value
  89. * @chip : The lp55xx chip data
  90. */
  91. struct lp55xx_led {
  92. int chan_nr;
  93. struct led_classdev cdev;
  94. u8 led_current;
  95. u8 max_current;
  96. struct work_struct brightness_work;
  97. u8 brightness;
  98. struct lp55xx_chip *chip;
  99. };
  100. /* register access */
  101. extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val);
  102. extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val);
  103. extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg,
  104. u8 mask, u8 val);
  105. /* common device init/deinit functions */
  106. extern int lp55xx_init_device(struct lp55xx_chip *chip);
  107. extern void lp55xx_deinit_device(struct lp55xx_chip *chip);
  108. /* common LED class device functions */
  109. extern int lp55xx_register_leds(struct lp55xx_led *led,
  110. struct lp55xx_chip *chip);
  111. extern void lp55xx_unregister_leds(struct lp55xx_led *led,
  112. struct lp55xx_chip *chip);
  113. /* common device attributes functions */
  114. extern int lp55xx_register_sysfs(struct lp55xx_chip *chip);
  115. extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip);
  116. #endif /* _LEDS_LP55XX_COMMON_H */