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