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