max9271.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2017-2020 Jacopo Mondi
  4. * Copyright (C) 2017-2020 Kieran Bingham
  5. * Copyright (C) 2017-2020 Laurent Pinchart
  6. * Copyright (C) 2017-2020 Niklas Söderlund
  7. * Copyright (C) 2016 Renesas Electronics Corporation
  8. * Copyright (C) 2015 Cogent Embedded, Inc.
  9. */
  10. #ifndef __MEDIA_I2C_MAX9271_H__
  11. #define __MEDIA_I2C_MAX9271_H__
  12. #include <linux/i2c.h>
  13. #define MAX9271_DEFAULT_ADDR 0x40
  14. /* Register 0x02 */
  15. #define MAX9271_SPREAD_SPECT_0 (0 << 5)
  16. #define MAX9271_SPREAD_SPECT_05 (1 << 5)
  17. #define MAX9271_SPREAD_SPECT_15 (2 << 5)
  18. #define MAX9271_SPREAD_SPECT_1 (5 << 5)
  19. #define MAX9271_SPREAD_SPECT_2 (3 << 5)
  20. #define MAX9271_SPREAD_SPECT_3 (6 << 5)
  21. #define MAX9271_SPREAD_SPECT_4 (7 << 5)
  22. #define MAX9271_R02_RES BIT(4)
  23. #define MAX9271_PCLK_AUTODETECT (3 << 2)
  24. #define MAX9271_SERIAL_AUTODETECT (0x03)
  25. /* Register 0x04 */
  26. #define MAX9271_SEREN BIT(7)
  27. #define MAX9271_CLINKEN BIT(6)
  28. #define MAX9271_PRBSEN BIT(5)
  29. #define MAX9271_SLEEP BIT(4)
  30. #define MAX9271_INTTYPE_I2C (0 << 2)
  31. #define MAX9271_INTTYPE_UART (1 << 2)
  32. #define MAX9271_INTTYPE_NONE (2 << 2)
  33. #define MAX9271_REVCCEN BIT(1)
  34. #define MAX9271_FWDCCEN BIT(0)
  35. /* Register 0x07 */
  36. #define MAX9271_DBL BIT(7)
  37. #define MAX9271_DRS BIT(6)
  38. #define MAX9271_BWS BIT(5)
  39. #define MAX9271_ES BIT(4)
  40. #define MAX9271_HVEN BIT(2)
  41. #define MAX9271_EDC_1BIT_PARITY (0 << 0)
  42. #define MAX9271_EDC_6BIT_CRC (1 << 0)
  43. #define MAX9271_EDC_6BIT_HAMMING (2 << 0)
  44. /* Register 0x08 */
  45. #define MAX9271_INVVS BIT(7)
  46. #define MAX9271_INVHS BIT(6)
  47. #define MAX9271_REV_LOGAIN BIT(3)
  48. #define MAX9271_REV_HIVTH BIT(0)
  49. /* Register 0x09 */
  50. #define MAX9271_ID 0x09
  51. /* Register 0x0d */
  52. #define MAX9271_I2CLOCACK BIT(7)
  53. #define MAX9271_I2CSLVSH_1046NS_469NS (3 << 5)
  54. #define MAX9271_I2CSLVSH_938NS_352NS (2 << 5)
  55. #define MAX9271_I2CSLVSH_469NS_234NS (1 << 5)
  56. #define MAX9271_I2CSLVSH_352NS_117NS (0 << 5)
  57. #define MAX9271_I2CMSTBT_837KBPS (7 << 2)
  58. #define MAX9271_I2CMSTBT_533KBPS (6 << 2)
  59. #define MAX9271_I2CMSTBT_339KBPS (5 << 2)
  60. #define MAX9271_I2CMSTBT_173KBPS (4 << 2)
  61. #define MAX9271_I2CMSTBT_105KBPS (3 << 2)
  62. #define MAX9271_I2CMSTBT_84KBPS (2 << 2)
  63. #define MAX9271_I2CMSTBT_28KBPS (1 << 2)
  64. #define MAX9271_I2CMSTBT_8KBPS (0 << 2)
  65. #define MAX9271_I2CSLVTO_NONE (3 << 0)
  66. #define MAX9271_I2CSLVTO_1024US (2 << 0)
  67. #define MAX9271_I2CSLVTO_256US (1 << 0)
  68. #define MAX9271_I2CSLVTO_64US (0 << 0)
  69. /* Register 0x0f */
  70. #define MAX9271_GPIO5OUT BIT(5)
  71. #define MAX9271_GPIO4OUT BIT(4)
  72. #define MAX9271_GPIO3OUT BIT(3)
  73. #define MAX9271_GPIO2OUT BIT(2)
  74. #define MAX9271_GPIO1OUT BIT(1)
  75. #define MAX9271_GPO BIT(0)
  76. /* Register 0x15 */
  77. #define MAX9271_PCLKDET BIT(0)
  78. /**
  79. * struct max9271_device - max9271 device
  80. * @client: The i2c client for the max9271 instance
  81. */
  82. struct max9271_device {
  83. struct i2c_client *client;
  84. };
  85. /**
  86. * max9271_wake_up() - Wake up the serializer by issuing an i2c transaction
  87. * @dev: The max9271 device
  88. *
  89. * This function shall be called before any other interaction with the
  90. * serializer.
  91. */
  92. void max9271_wake_up(struct max9271_device *dev);
  93. /**
  94. * max9271_set_serial_link() - Enable/disable serial link
  95. * @dev: The max9271 device
  96. * @enable: Serial link enable/disable flag
  97. *
  98. * Return 0 on success or a negative error code on failure
  99. */
  100. int max9271_set_serial_link(struct max9271_device *dev, bool enable);
  101. /**
  102. * max9271_configure_i2c() - Configure I2C bus parameters
  103. * @dev: The max9271 device
  104. * @i2c_config: The I2C bus configuration bit mask
  105. *
  106. * Configure MAX9271 I2C interface. The bus configuration provided in the
  107. * @i2c_config parameter shall be assembled using bit values defined by the
  108. * MAX9271_I2C* macros.
  109. *
  110. * Return 0 on success or a negative error code on failure
  111. */
  112. int max9271_configure_i2c(struct max9271_device *dev, u8 i2c_config);
  113. /**
  114. * max9271_set_high_threshold() - Enable or disable reverse channel high
  115. * threshold
  116. * @dev: The max9271 device
  117. * @enable: High threshold enable/disable flag
  118. *
  119. * Return 0 on success or a negative error code on failure
  120. */
  121. int max9271_set_high_threshold(struct max9271_device *dev, bool enable);
  122. /**
  123. * max9271_configure_gmsl_link() - Configure the GMSL link
  124. * @dev: The max9271 device
  125. *
  126. * FIXME: the GMSL link configuration is currently hardcoded and performed
  127. * by programming registers 0x04, 0x07 and 0x02.
  128. *
  129. * Return 0 on success or a negative error code on failure
  130. */
  131. int max9271_configure_gmsl_link(struct max9271_device *dev);
  132. /**
  133. * max9271_set_gpios() - Set gpio lines to physical high value
  134. * @dev: The max9271 device
  135. * @gpio_mask: The mask of gpio lines to set to high value
  136. *
  137. * The @gpio_mask parameter shall be assembled using the MAX9271_GP[IO|O]*
  138. * bit values.
  139. *
  140. * Return 0 on success or a negative error code on failure
  141. */
  142. int max9271_set_gpios(struct max9271_device *dev, u8 gpio_mask);
  143. /**
  144. * max9271_clear_gpios() - Set gpio lines to physical low value
  145. * @dev: The max9271 device
  146. * @gpio_mask: The mask of gpio lines to set to low value
  147. *
  148. * The @gpio_mask parameter shall be assembled using the MAX9271_GP[IO|O]*
  149. * bit values.
  150. *
  151. * Return 0 on success or a negative error code on failure
  152. */
  153. int max9271_clear_gpios(struct max9271_device *dev, u8 gpio_mask);
  154. /**
  155. * max9271_enable_gpios() - Enable gpio lines
  156. * @dev: The max9271 device
  157. * @gpio_mask: The mask of gpio lines to enable
  158. *
  159. * The @gpio_mask parameter shall be assembled using the MAX9271_GPIO*
  160. * bit values. GPO line is always enabled by default.
  161. *
  162. * Return 0 on success or a negative error code on failure
  163. */
  164. int max9271_enable_gpios(struct max9271_device *dev, u8 gpio_mask);
  165. /**
  166. * max9271_disable_gpios() - Disable gpio lines
  167. * @dev: The max9271 device
  168. * @gpio_mask: The mask of gpio lines to disable
  169. *
  170. * The @gpio_mask parameter shall be assembled using the MAX9271_GPIO*
  171. * bit values. GPO line is always enabled by default and cannot be disabled.
  172. *
  173. * Return 0 on success or a negative error code on failure
  174. */
  175. int max9271_disable_gpios(struct max9271_device *dev, u8 gpio_mask);
  176. /**
  177. * max9271_verify_id() - Read and verify MAX9271 id
  178. * @dev: The max9271 device
  179. *
  180. * Return 0 on success or a negative error code on failure
  181. */
  182. int max9271_verify_id(struct max9271_device *dev);
  183. /**
  184. * max9271_set_address() - Program a new I2C address
  185. * @dev: The max9271 device
  186. * @addr: The new I2C address in 7-bit format
  187. *
  188. * This function only takes care of programming the new I2C address @addr to
  189. * in the MAX9271 chip registers, it is responsiblity of the caller to set
  190. * the i2c address client to the @addr value to be able to communicate with
  191. * the MAX9271 chip using the I2C framework APIs after this function returns.
  192. *
  193. * Return 0 on success or a negative error code on failure
  194. */
  195. int max9271_set_address(struct max9271_device *dev, u8 addr);
  196. /**
  197. * max9271_set_deserializer_address() - Program the remote deserializer address
  198. * @dev: The max9271 device
  199. * @addr: The deserializer I2C address in 7-bit format
  200. *
  201. * Return 0 on success or a negative error code on failure
  202. */
  203. int max9271_set_deserializer_address(struct max9271_device *dev, u8 addr);
  204. /**
  205. * max9271_set_translation() - Program I2C address translation
  206. * @dev: The max9271 device
  207. * @source: The I2C source address
  208. * @dest: The I2C destination address
  209. *
  210. * Program address translation from @source to @dest. This is required to
  211. * communicate with local devices that do not support address reprogramming.
  212. *
  213. * TODO: The device supports translation of two address, this function currently
  214. * supports a single one.
  215. *
  216. * Return 0 on success or a negative error code on failure
  217. */
  218. int max9271_set_translation(struct max9271_device *dev, u8 source, u8 dest);
  219. #endif /* __MEDIA_I2C_MAX9271_H__ */