leds-lp55xx-common.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * LP5521/LP5523/LP55231 Common Driver
  3. *
  4. * Copyright 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 modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * Derived from leds-lp5521.c, leds-lp5523.c
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/i2c.h>
  16. #include <linux/leds.h>
  17. #include <linux/module.h>
  18. #include <linux/platform_data/leds-lp55xx.h>
  19. #include "leds-lp55xx-common.h"
  20. int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
  21. {
  22. return i2c_smbus_write_byte_data(chip->cl, reg, val);
  23. }
  24. EXPORT_SYMBOL_GPL(lp55xx_write);
  25. int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val)
  26. {
  27. s32 ret;
  28. ret = i2c_smbus_read_byte_data(chip->cl, reg);
  29. if (ret < 0)
  30. return ret;
  31. *val = ret;
  32. return 0;
  33. }
  34. EXPORT_SYMBOL_GPL(lp55xx_read);
  35. int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, u8 mask, u8 val)
  36. {
  37. int ret;
  38. u8 tmp;
  39. ret = lp55xx_read(chip, reg, &tmp);
  40. if (ret)
  41. return ret;
  42. tmp &= ~mask;
  43. tmp |= val & mask;
  44. return lp55xx_write(chip, reg, tmp);
  45. }
  46. EXPORT_SYMBOL_GPL(lp55xx_update_bits);
  47. int lp55xx_init_device(struct lp55xx_chip *chip)
  48. {
  49. struct lp55xx_platform_data *pdata;
  50. struct device *dev = &chip->cl->dev;
  51. int ret = 0;
  52. WARN_ON(!chip);
  53. pdata = chip->pdata;
  54. if (!pdata)
  55. return -EINVAL;
  56. if (pdata->setup_resources) {
  57. ret = pdata->setup_resources();
  58. if (ret < 0) {
  59. dev_err(dev, "setup resoure err: %d\n", ret);
  60. goto err;
  61. }
  62. }
  63. if (pdata->enable) {
  64. pdata->enable(0);
  65. usleep_range(1000, 2000); /* Keep enable down at least 1ms */
  66. pdata->enable(1);
  67. usleep_range(1000, 2000); /* 500us abs min. */
  68. }
  69. err:
  70. return ret;
  71. }
  72. EXPORT_SYMBOL_GPL(lp55xx_init_device);
  73. MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
  74. MODULE_DESCRIPTION("LP55xx Common Driver");
  75. MODULE_LICENSE("GPL");