2 * Copyright 2012 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
7 #include "vsc3316_3308.h"
9 #define REVISION_ID_REG 0x7E
10 #define INTERFACE_MODE_REG 0x79
11 #define CURRENT_PAGE_REGISTER 0x7F
12 #define CONNECTION_CONFIG_PAGE 0x00
13 #define INPUT_STATE_REG 0x13
14 #define GLOBAL_INPUT_ISE1 0x51
15 #define GLOBAL_INPUT_ISE2 0x52
16 #define GLOBAL_INPUT_LOS 0x55
17 #define GLOBAL_CORE_CNTRL 0x5D
18 #define OUTPUT_MODE_PAGE 0x23
19 #define CORE_CONTROL_PAGE 0x25
20 #define CORE_CONFIG_REG 0x75
22 int vsc_if_enable(unsigned int vsc_addr)
26 debug("VSC:Configuring VSC at I2C address 0x%2x"
27 " for 2-wire interface\n", vsc_addr);
29 /* enable 2-wire Serial InterFace (I2C) */
31 return i2c_write(vsc_addr, INTERFACE_MODE_REG, 1, &data, 1);
34 int vsc3316_config(unsigned int vsc_addr, int8_t con_arr[][2],
41 debug("VSC:Initializing VSC3316 at I2C address 0x%2x"
42 " for Tx\n", vsc_addr);
44 ret = i2c_read(vsc_addr, REVISION_ID_REG, 1, &rev_id, 1);
46 printf("VSC:0x%x could not read REV_ID from device.\n",
52 printf("VSC: device at address 0x%x is not VSC3316/3308.\n",
57 ret = vsc_if_enable(vsc_addr);
59 printf("VSC:0x%x could not configured for 2-wire I/F.\n",
64 /* config connections - page 0x00 */
65 i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, CONNECTION_CONFIG_PAGE);
67 /* Making crosspoint connections, by connecting required
69 for (i = 0; i < num_con ; i++)
70 i2c_reg_write(vsc_addr, con_arr[i][1], con_arr[i][0]);
72 /* input state - page 0x13 */
73 i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, INPUT_STATE_REG);
74 /* Configuring the required input of the switch */
75 for (i = 0; i < num_con ; i++)
76 i2c_reg_write(vsc_addr, con_arr[i][0], 0x80);
78 /* Setting Global Input LOS threshold value */
79 i2c_reg_write(vsc_addr, GLOBAL_INPUT_LOS, 0x60);
81 /* config output mode - page 0x23 */
82 i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, OUTPUT_MODE_PAGE);
83 /* Turn ON the Output driver correspond to required output*/
84 for (i = 0; i < num_con ; i++)
85 i2c_reg_write(vsc_addr, con_arr[i][1], 0);
87 /* configure global core control register, Turn on Global core power */
88 i2c_reg_write(vsc_addr, GLOBAL_CORE_CNTRL, 0);
90 vsc_wp_config(vsc_addr);
95 int vsc3308_config(unsigned int vsc_addr, const int8_t con_arr[][2],
102 debug("VSC:Initializing VSC3308 at I2C address 0x%x"
103 " for Tx\n", vsc_addr);
105 ret = i2c_read(vsc_addr, REVISION_ID_REG, 1, &rev_id, 1);
107 printf("VSC:0x%x could not read REV_ID from device.\n",
112 if (rev_id != 0xab) {
113 printf("VSC: device at address 0x%x is not VSC3316/3308.\n",
118 ret = vsc_if_enable(vsc_addr);
120 printf("VSC:0x%x could not configured for 2-wire I/F.\n",
125 /* config connections - page 0x00 */
126 i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, CONNECTION_CONFIG_PAGE);
128 /* Making crosspoint connections, by connecting required
130 for (i = 0; i < num_con ; i++)
131 i2c_reg_write(vsc_addr, con_arr[i][1], con_arr[i][0]);
133 /*Configure Global Input ISE and gain */
134 i2c_reg_write(vsc_addr, GLOBAL_INPUT_ISE1, 0x12);
135 i2c_reg_write(vsc_addr, GLOBAL_INPUT_ISE2, 0x12);
137 /* input state - page 0x13 */
138 i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, INPUT_STATE_REG);
139 /* Turning ON the required input of the switch */
140 for (i = 0; i < num_con ; i++)
141 i2c_reg_write(vsc_addr, con_arr[i][0], 0);
143 /* Setting Global Input LOS threshold value */
144 i2c_reg_write(vsc_addr, GLOBAL_INPUT_LOS, 0x60);
146 /* config output mode - page 0x23 */
147 i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, OUTPUT_MODE_PAGE);
148 /* Turn ON the Output driver correspond to required output*/
149 for (i = 0; i < num_con ; i++)
150 i2c_reg_write(vsc_addr, con_arr[i][1], 0);
152 /* configure global core control register, Turn on Global core power */
153 i2c_reg_write(vsc_addr, GLOBAL_CORE_CNTRL, 0);
155 vsc_wp_config(vsc_addr);
160 void vsc_wp_config(unsigned int vsc_addr)
162 debug("VSC:Configuring VSC at address:0x%x for WP\n", vsc_addr);
164 /* For new crosspoint configuration to occur, WP bit of
165 * CORE_CONFIG_REG should be set 1 and then reset to 0 */
166 i2c_reg_write(vsc_addr, CORE_CONFIG_REG, 0x01);
167 i2c_reg_write(vsc_addr, CORE_CONFIG_REG, 0x0);