239 lines · c
1/* SPDX-License-Identifier: GPL-2.0+ */2/*3 * Copyright (C) 2017-2020 Jacopo Mondi4 * Copyright (C) 2017-2020 Kieran Bingham5 * Copyright (C) 2017-2020 Laurent Pinchart6 * Copyright (C) 2017-2020 Niklas Söderlund7 * Copyright (C) 2016 Renesas Electronics Corporation8 * 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 0x4017 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 0x0955/* 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 device85 * @client: The i2c client for the max9271 instance86 */87struct max9271_device {88 struct i2c_client *client;89};90 91/**92 * max9271_wake_up() - Wake up the serializer by issuing an i2c transaction93 * @dev: The max9271 device94 *95 * This function shall be called before any other interaction with the96 * serializer.97 */98void max9271_wake_up(struct max9271_device *dev);99 100/**101 * max9271_set_serial_link() - Enable/disable serial link102 * @dev: The max9271 device103 * @enable: Serial link enable/disable flag104 *105 * Return 0 on success or a negative error code on failure106 */107int max9271_set_serial_link(struct max9271_device *dev, bool enable);108 109/**110 * max9271_configure_i2c() - Configure I2C bus parameters111 * @dev: The max9271 device112 * @i2c_config: The I2C bus configuration bit mask113 *114 * Configure MAX9271 I2C interface. The bus configuration provided in the115 * @i2c_config parameter shall be assembled using bit values defined by the116 * MAX9271_I2C* macros.117 *118 * Return 0 on success or a negative error code on failure119 */120int max9271_configure_i2c(struct max9271_device *dev, u8 i2c_config);121 122/**123 * max9271_set_high_threshold() - Enable or disable reverse channel high124 * threshold125 * @dev: The max9271 device126 * @enable: High threshold enable/disable flag127 *128 * Return 0 on success or a negative error code on failure129 */130int max9271_set_high_threshold(struct max9271_device *dev, bool enable);131 132/**133 * max9271_configure_gmsl_link() - Configure the GMSL link134 * @dev: The max9271 device135 *136 * FIXME: the GMSL link configuration is currently hardcoded and performed137 * by programming registers 0x04, 0x07 and 0x02.138 *139 * Return 0 on success or a negative error code on failure140 */141int max9271_configure_gmsl_link(struct max9271_device *dev);142 143/**144 * max9271_set_gpios() - Set gpio lines to physical high value145 * @dev: The max9271 device146 * @gpio_mask: The mask of gpio lines to set to high value147 *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 failure152 */153int max9271_set_gpios(struct max9271_device *dev, u8 gpio_mask);154 155/**156 * max9271_clear_gpios() - Set gpio lines to physical low value157 * @dev: The max9271 device158 * @gpio_mask: The mask of gpio lines to set to low value159 *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 failure164 */165int max9271_clear_gpios(struct max9271_device *dev, u8 gpio_mask);166 167/**168 * max9271_enable_gpios() - Enable gpio lines169 * @dev: The max9271 device170 * @gpio_mask: The mask of gpio lines to enable171 *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 failure176 */177int max9271_enable_gpios(struct max9271_device *dev, u8 gpio_mask);178 179/**180 * max9271_disable_gpios() - Disable gpio lines181 * @dev: The max9271 device182 * @gpio_mask: The mask of gpio lines to disable183 *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 failure188 */189int max9271_disable_gpios(struct max9271_device *dev, u8 gpio_mask);190 191/**192 * max9271_verify_id() - Read and verify MAX9271 id193 * @dev: The max9271 device194 *195 * Return 0 on success or a negative error code on failure196 */197int max9271_verify_id(struct max9271_device *dev);198 199/**200 * max9271_set_address() - Program a new I2C address201 * @dev: The max9271 device202 * @addr: The new I2C address in 7-bit format203 *204 * This function only takes care of programming the new I2C address @addr to205 * in the MAX9271 chip registers, it is responsiblity of the caller to set206 * the i2c address client to the @addr value to be able to communicate with207 * the MAX9271 chip using the I2C framework APIs after this function returns.208 *209 * Return 0 on success or a negative error code on failure210 */211int max9271_set_address(struct max9271_device *dev, u8 addr);212 213/**214 * max9271_set_deserializer_address() - Program the remote deserializer address215 * @dev: The max9271 device216 * @addr: The deserializer I2C address in 7-bit format217 *218 * Return 0 on success or a negative error code on failure219 */220int max9271_set_deserializer_address(struct max9271_device *dev, u8 addr);221 222/**223 * max9271_set_translation() - Program I2C address translation224 * @dev: The max9271 device225 * @source: The I2C source address226 * @dest: The I2C destination address227 *228 * Program address translation from @source to @dest. This is required to229 * communicate with local devices that do not support address reprogramming.230 *231 * TODO: The device supports translation of two address, this function currently232 * supports a single one.233 *234 * Return 0 on success or a negative error code on failure235 */236int max9271_set_translation(struct max9271_device *dev, u8 source, u8 dest);237 238#endif /* __MEDIA_I2C_MAX9271_H__ */239