afe440x.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * AFE440X Heart Rate Monitors and Low-Cost Pulse Oximeters
  3. *
  4. * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
  5. * Andrew F. Davis <afd@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. */
  16. #ifndef _AFE440X_H
  17. #define _AFE440X_H
  18. /* AFE440X registers */
  19. #define AFE440X_CONTROL0 0x00
  20. #define AFE440X_LED2STC 0x01
  21. #define AFE440X_LED2ENDC 0x02
  22. #define AFE440X_LED1LEDSTC 0x03
  23. #define AFE440X_LED1LEDENDC 0x04
  24. #define AFE440X_ALED2STC 0x05
  25. #define AFE440X_ALED2ENDC 0x06
  26. #define AFE440X_LED1STC 0x07
  27. #define AFE440X_LED1ENDC 0x08
  28. #define AFE440X_LED2LEDSTC 0x09
  29. #define AFE440X_LED2LEDENDC 0x0a
  30. #define AFE440X_ALED1STC 0x0b
  31. #define AFE440X_ALED1ENDC 0x0c
  32. #define AFE440X_LED2CONVST 0x0d
  33. #define AFE440X_LED2CONVEND 0x0e
  34. #define AFE440X_ALED2CONVST 0x0f
  35. #define AFE440X_ALED2CONVEND 0x10
  36. #define AFE440X_LED1CONVST 0x11
  37. #define AFE440X_LED1CONVEND 0x12
  38. #define AFE440X_ALED1CONVST 0x13
  39. #define AFE440X_ALED1CONVEND 0x14
  40. #define AFE440X_ADCRSTSTCT0 0x15
  41. #define AFE440X_ADCRSTENDCT0 0x16
  42. #define AFE440X_ADCRSTSTCT1 0x17
  43. #define AFE440X_ADCRSTENDCT1 0x18
  44. #define AFE440X_ADCRSTSTCT2 0x19
  45. #define AFE440X_ADCRSTENDCT2 0x1a
  46. #define AFE440X_ADCRSTSTCT3 0x1b
  47. #define AFE440X_ADCRSTENDCT3 0x1c
  48. #define AFE440X_PRPCOUNT 0x1d
  49. #define AFE440X_CONTROL1 0x1e
  50. #define AFE440X_LEDCNTRL 0x22
  51. #define AFE440X_CONTROL2 0x23
  52. #define AFE440X_ALARM 0x29
  53. #define AFE440X_LED2VAL 0x2a
  54. #define AFE440X_ALED2VAL 0x2b
  55. #define AFE440X_LED1VAL 0x2c
  56. #define AFE440X_ALED1VAL 0x2d
  57. #define AFE440X_LED2_ALED2VAL 0x2e
  58. #define AFE440X_LED1_ALED1VAL 0x2f
  59. #define AFE440X_CONTROL3 0x31
  60. #define AFE440X_PDNCYCLESTC 0x32
  61. #define AFE440X_PDNCYCLEENDC 0x33
  62. /* CONTROL0 register fields */
  63. #define AFE440X_CONTROL0_REG_READ BIT(0)
  64. #define AFE440X_CONTROL0_TM_COUNT_RST BIT(1)
  65. #define AFE440X_CONTROL0_SW_RESET BIT(3)
  66. /* CONTROL1 register fields */
  67. #define AFE440X_CONTROL1_TIMEREN BIT(8)
  68. /* TIAGAIN register fields */
  69. #define AFE440X_TIAGAIN_ENSEPGAIN BIT(15)
  70. /* CONTROL2 register fields */
  71. #define AFE440X_CONTROL2_PDN_AFE BIT(0)
  72. #define AFE440X_CONTROL2_PDN_RX BIT(1)
  73. #define AFE440X_CONTROL2_DYNAMIC4 BIT(3)
  74. #define AFE440X_CONTROL2_DYNAMIC3 BIT(4)
  75. #define AFE440X_CONTROL2_DYNAMIC2 BIT(14)
  76. #define AFE440X_CONTROL2_DYNAMIC1 BIT(20)
  77. /* CONTROL3 register fields */
  78. #define AFE440X_CONTROL3_CLKDIV GENMASK(2, 0)
  79. /* CONTROL0 values */
  80. #define AFE440X_CONTROL0_WRITE 0x0
  81. #define AFE440X_CONTROL0_READ 0x1
  82. #define AFE440X_INTENSITY_CHAN(_index, _mask) \
  83. { \
  84. .type = IIO_INTENSITY, \
  85. .channel = _index, \
  86. .address = _index, \
  87. .scan_index = _index, \
  88. .scan_type = { \
  89. .sign = 's', \
  90. .realbits = 24, \
  91. .storagebits = 32, \
  92. .endianness = IIO_CPU, \
  93. }, \
  94. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
  95. _mask, \
  96. .indexed = true, \
  97. }
  98. #define AFE440X_CURRENT_CHAN(_index) \
  99. { \
  100. .type = IIO_CURRENT, \
  101. .channel = _index, \
  102. .address = _index, \
  103. .scan_index = -1, \
  104. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
  105. BIT(IIO_CHAN_INFO_SCALE), \
  106. .indexed = true, \
  107. .output = true, \
  108. }
  109. struct afe440x_val_table {
  110. int integer;
  111. int fract;
  112. };
  113. #define AFE440X_TABLE_ATTR(_name, _table) \
  114. static ssize_t _name ## _show(struct device *dev, \
  115. struct device_attribute *attr, char *buf) \
  116. { \
  117. ssize_t len = 0; \
  118. int i; \
  119. \
  120. for (i = 0; i < ARRAY_SIZE(_table); i++) \
  121. len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06u ", \
  122. _table[i].integer, \
  123. _table[i].fract); \
  124. \
  125. buf[len - 1] = '\n'; \
  126. \
  127. return len; \
  128. } \
  129. static DEVICE_ATTR_RO(_name)
  130. struct afe440x_attr {
  131. struct device_attribute dev_attr;
  132. unsigned int field;
  133. const struct afe440x_val_table *val_table;
  134. unsigned int table_size;
  135. };
  136. #define to_afe440x_attr(_dev_attr) \
  137. container_of(_dev_attr, struct afe440x_attr, dev_attr)
  138. #define AFE440X_ATTR(_name, _field, _table) \
  139. struct afe440x_attr afe440x_attr_##_name = { \
  140. .dev_attr = __ATTR(_name, (S_IRUGO | S_IWUSR), \
  141. afe440x_show_register, \
  142. afe440x_store_register), \
  143. .field = _field, \
  144. .val_table = _table, \
  145. .table_size = ARRAY_SIZE(_table), \
  146. }
  147. #endif /* _AFE440X_H */