core.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * da9055 declarations for DA9055 PMICs.
  3. *
  4. * Copyright(c) 2012 Dialog Semiconductor Ltd.
  5. *
  6. * Author: David Dajun Chen <dchen@diasemi.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 as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. */
  23. #ifndef __DA9055_CORE_H
  24. #define __DA9055_CORE_H
  25. #include <linux/interrupt.h>
  26. #include <linux/regmap.h>
  27. /*
  28. * PMIC IRQ
  29. */
  30. #define DA9055_IRQ_ALARM 0x01
  31. #define DA9055_IRQ_TICK 0x02
  32. #define DA9055_IRQ_NONKEY 0x00
  33. #define DA9055_IRQ_REGULATOR 0x0B
  34. #define DA9055_IRQ_HWMON 0x03
  35. struct da9055_pdata;
  36. struct da9055 {
  37. struct regmap *regmap;
  38. struct regmap_irq_chip_data *irq_data;
  39. struct device *dev;
  40. struct i2c_client *i2c_client;
  41. int irq_base;
  42. int chip_irq;
  43. };
  44. /* Device I/O */
  45. static inline int da9055_reg_read(struct da9055 *da9055, unsigned char reg)
  46. {
  47. int val, ret;
  48. ret = regmap_read(da9055->regmap, reg, &val);
  49. if (ret < 0)
  50. return ret;
  51. return val;
  52. }
  53. static inline int da9055_reg_write(struct da9055 *da9055, unsigned char reg,
  54. unsigned char val)
  55. {
  56. return regmap_write(da9055->regmap, reg, val);
  57. }
  58. static inline int da9055_group_read(struct da9055 *da9055, unsigned char reg,
  59. unsigned reg_cnt, unsigned char *val)
  60. {
  61. return regmap_bulk_read(da9055->regmap, reg, val, reg_cnt);
  62. }
  63. static inline int da9055_group_write(struct da9055 *da9055, unsigned char reg,
  64. unsigned reg_cnt, unsigned char *val)
  65. {
  66. return regmap_raw_write(da9055->regmap, reg, val, reg_cnt);
  67. }
  68. static inline int da9055_reg_update(struct da9055 *da9055, unsigned char reg,
  69. unsigned char bit_mask,
  70. unsigned char reg_val)
  71. {
  72. return regmap_update_bits(da9055->regmap, reg, bit_mask, reg_val);
  73. }
  74. /* Generic Device API */
  75. int da9055_device_init(struct da9055 *da9055);
  76. void da9055_device_exit(struct da9055 *da9055);
  77. extern struct regmap_config da9055_regmap_config;
  78. #endif /* __DA9055_CORE_H */