Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * Copyright (C) 2017-2020 Jacopo Mondi
0004  * Copyright (C) 2017-2020 Kieran Bingham
0005  * Copyright (C) 2017-2020 Laurent Pinchart
0006  * Copyright (C) 2017-2020 Niklas Söderlund
0007  * Copyright (C) 2016 Renesas Electronics Corporation
0008  * Copyright (C) 2015 Cogent Embedded, Inc.
0009  */
0010 
0011 #include <linux/i2c.h>
0012 
0013 #define MAX9271_DEFAULT_ADDR    0x40
0014 
0015 /* Register 0x02 */
0016 #define MAX9271_SPREAD_SPECT_0      (0 << 5)
0017 #define MAX9271_SPREAD_SPECT_05     (1 << 5)
0018 #define MAX9271_SPREAD_SPECT_15     (2 << 5)
0019 #define MAX9271_SPREAD_SPECT_1      (5 << 5)
0020 #define MAX9271_SPREAD_SPECT_2      (3 << 5)
0021 #define MAX9271_SPREAD_SPECT_3      (6 << 5)
0022 #define MAX9271_SPREAD_SPECT_4      (7 << 5)
0023 #define MAX9271_R02_RES         BIT(4)
0024 #define MAX9271_PCLK_AUTODETECT     (3 << 2)
0025 #define MAX9271_SERIAL_AUTODETECT   (0x03)
0026 /* Register 0x04 */
0027 #define MAX9271_SEREN           BIT(7)
0028 #define MAX9271_CLINKEN         BIT(6)
0029 #define MAX9271_PRBSEN          BIT(5)
0030 #define MAX9271_SLEEP           BIT(4)
0031 #define MAX9271_INTTYPE_I2C     (0 << 2)
0032 #define MAX9271_INTTYPE_UART        (1 << 2)
0033 #define MAX9271_INTTYPE_NONE        (2 << 2)
0034 #define MAX9271_REVCCEN         BIT(1)
0035 #define MAX9271_FWDCCEN         BIT(0)
0036 /* Register 0x07 */
0037 #define MAX9271_DBL         BIT(7)
0038 #define MAX9271_DRS         BIT(6)
0039 #define MAX9271_BWS         BIT(5)
0040 #define MAX9271_ES          BIT(4)
0041 #define MAX9271_HVEN            BIT(2)
0042 #define MAX9271_EDC_1BIT_PARITY     (0 << 0)
0043 #define MAX9271_EDC_6BIT_CRC        (1 << 0)
0044 #define MAX9271_EDC_6BIT_HAMMING    (2 << 0)
0045 /* Register 0x08 */
0046 #define MAX9271_INVVS           BIT(7)
0047 #define MAX9271_INVHS           BIT(6)
0048 #define MAX9271_REV_LOGAIN      BIT(3)
0049 #define MAX9271_REV_HIVTH       BIT(0)
0050 /* Register 0x09 */
0051 #define MAX9271_ID          0x09
0052 /* Register 0x0d */
0053 #define MAX9271_I2CLOCACK       BIT(7)
0054 #define MAX9271_I2CSLVSH_1046NS_469NS   (3 << 5)
0055 #define MAX9271_I2CSLVSH_938NS_352NS    (2 << 5)
0056 #define MAX9271_I2CSLVSH_469NS_234NS    (1 << 5)
0057 #define MAX9271_I2CSLVSH_352NS_117NS    (0 << 5)
0058 #define MAX9271_I2CMSTBT_837KBPS    (7 << 2)
0059 #define MAX9271_I2CMSTBT_533KBPS    (6 << 2)
0060 #define MAX9271_I2CMSTBT_339KBPS    (5 << 2)
0061 #define MAX9271_I2CMSTBT_173KBPS    (4 << 2)
0062 #define MAX9271_I2CMSTBT_105KBPS    (3 << 2)
0063 #define MAX9271_I2CMSTBT_84KBPS     (2 << 2)
0064 #define MAX9271_I2CMSTBT_28KBPS     (1 << 2)
0065 #define MAX9271_I2CMSTBT_8KBPS      (0 << 2)
0066 #define MAX9271_I2CSLVTO_NONE       (3 << 0)
0067 #define MAX9271_I2CSLVTO_1024US     (2 << 0)
0068 #define MAX9271_I2CSLVTO_256US      (1 << 0)
0069 #define MAX9271_I2CSLVTO_64US       (0 << 0)
0070 /* Register 0x0f */
0071 #define MAX9271_GPIO5OUT        BIT(5)
0072 #define MAX9271_GPIO4OUT        BIT(4)
0073 #define MAX9271_GPIO3OUT        BIT(3)
0074 #define MAX9271_GPIO2OUT        BIT(2)
0075 #define MAX9271_GPIO1OUT        BIT(1)
0076 #define MAX9271_GPO         BIT(0)
0077 /* Register 0x15 */
0078 #define MAX9271_PCLKDET         BIT(0)
0079 
0080 /**
0081  * struct max9271_device - max9271 device
0082  * @client: The i2c client for the max9271 instance
0083  */
0084 struct max9271_device {
0085     struct i2c_client *client;
0086 };
0087 
0088 /**
0089  * max9271_wake_up() - Wake up the serializer by issuing an i2c transaction
0090  * @dev: The max9271 device
0091  *
0092  * This function shall be called before any other interaction with the
0093  * serializer.
0094  */
0095 void max9271_wake_up(struct max9271_device *dev);
0096 
0097 /**
0098  * max9271_set_serial_link() - Enable/disable serial link
0099  * @dev: The max9271 device
0100  * @enable: Serial link enable/disable flag
0101  *
0102  * Return 0 on success or a negative error code on failure
0103  */
0104 int max9271_set_serial_link(struct max9271_device *dev, bool enable);
0105 
0106 /**
0107  * max9271_configure_i2c() - Configure I2C bus parameters
0108  * @dev: The max9271 device
0109  * @i2c_config: The I2C bus configuration bit mask
0110  *
0111  * Configure MAX9271 I2C interface. The bus configuration provided in the
0112  * @i2c_config parameter shall be assembled using bit values defined by the
0113  * MAX9271_I2C* macros.
0114  *
0115  * Return 0 on success or a negative error code on failure
0116  */
0117 int max9271_configure_i2c(struct max9271_device *dev, u8 i2c_config);
0118 
0119 /**
0120  * max9271_set_high_threshold() - Enable or disable reverse channel high
0121  *                threshold
0122  * @dev: The max9271 device
0123  * @enable: High threshold enable/disable flag
0124  *
0125  * Return 0 on success or a negative error code on failure
0126  */
0127 int max9271_set_high_threshold(struct max9271_device *dev, bool enable);
0128 
0129 /**
0130  * max9271_configure_gmsl_link() - Configure the GMSL link
0131  * @dev: The max9271 device
0132  *
0133  * FIXME: the GMSL link configuration is currently hardcoded and performed
0134  * by programming registers 0x04, 0x07 and 0x02.
0135  *
0136  * Return 0 on success or a negative error code on failure
0137  */
0138 int max9271_configure_gmsl_link(struct max9271_device *dev);
0139 
0140 /**
0141  * max9271_set_gpios() - Set gpio lines to physical high value
0142  * @dev: The max9271 device
0143  * @gpio_mask: The mask of gpio lines to set to high value
0144  *
0145  * The @gpio_mask parameter shall be assembled using the MAX9271_GP[IO|O]*
0146  * bit values.
0147  *
0148  * Return 0 on success or a negative error code on failure
0149  */
0150 int max9271_set_gpios(struct max9271_device *dev, u8 gpio_mask);
0151 
0152 /**
0153  * max9271_clear_gpios() - Set gpio lines to physical low value
0154  * @dev: The max9271 device
0155  * @gpio_mask: The mask of gpio lines to set to low value
0156  *
0157  * The @gpio_mask parameter shall be assembled using the MAX9271_GP[IO|O]*
0158  * bit values.
0159  *
0160  * Return 0 on success or a negative error code on failure
0161  */
0162 int max9271_clear_gpios(struct max9271_device *dev, u8 gpio_mask);
0163 
0164 /**
0165  * max9271_enable_gpios() - Enable gpio lines
0166  * @dev: The max9271 device
0167  * @gpio_mask: The mask of gpio lines to enable
0168  *
0169  * The @gpio_mask parameter shall be assembled using the MAX9271_GPIO*
0170  * bit values. GPO line is always enabled by default.
0171  *
0172  * Return 0 on success or a negative error code on failure
0173  */
0174 int max9271_enable_gpios(struct max9271_device *dev, u8 gpio_mask);
0175 
0176 /**
0177  * max9271_disable_gpios() - Disable gpio lines
0178  * @dev: The max9271 device
0179  * @gpio_mask: The mask of gpio lines to disable
0180  *
0181  * The @gpio_mask parameter shall be assembled using the MAX9271_GPIO*
0182  * bit values. GPO line is always enabled by default and cannot be disabled.
0183  *
0184  * Return 0 on success or a negative error code on failure
0185  */
0186 int max9271_disable_gpios(struct max9271_device *dev, u8 gpio_mask);
0187 
0188 /**
0189  * max9271_verify_id() - Read and verify MAX9271 id
0190  * @dev: The max9271 device
0191  *
0192  * Return 0 on success or a negative error code on failure
0193  */
0194 int max9271_verify_id(struct max9271_device *dev);
0195 
0196 /**
0197  * max9271_set_address() - Program a new I2C address
0198  * @dev: The max9271 device
0199  * @addr: The new I2C address in 7-bit format
0200  *
0201  * This function only takes care of programming the new I2C address @addr to
0202  * in the MAX9271 chip registers, it is responsiblity of the caller to set
0203  * the i2c address client to the @addr value to be able to communicate with
0204  * the MAX9271 chip using the I2C framework APIs after this function returns.
0205  *
0206  * Return 0 on success or a negative error code on failure
0207  */
0208 int max9271_set_address(struct max9271_device *dev, u8 addr);
0209 
0210 /**
0211  * max9271_set_deserializer_address() - Program the remote deserializer address
0212  * @dev: The max9271 device
0213  * @addr: The deserializer I2C address in 7-bit format
0214  *
0215  * Return 0 on success or a negative error code on failure
0216  */
0217 int max9271_set_deserializer_address(struct max9271_device *dev, u8 addr);
0218 
0219 /**
0220  * max9271_set_translation() - Program I2C address translation
0221  * @dev: The max9271 device
0222  * @source: The I2C source address
0223  * @dest: The I2C destination address
0224  *
0225  * Program address translation from @source to @dest. This is required to
0226  * communicate with local devices that do not support address reprogramming.
0227  *
0228  * TODO: The device supports translation of two address, this function currently
0229  * supports a single one.
0230  *
0231  * Return 0 on success or a negative error code on failure
0232  */
0233 int max9271_set_translation(struct max9271_device *dev, u8 source, u8 dest);