dm: powerpc: P1020: add i2c DM support
[oweals/u-boot.git] / board / freescale / common / vsc3316_3308.c
index 786856597f6f3e11f13a1d9adcfac1b297346b88..033fae020f12c01b9758674636db3905d66dec49 100644 (file)
@@ -1,23 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2012 Freescale Semiconductor, Inc.
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
  */
 
 #include "vsc3316_3308.h"
 #define INPUT_STATE_REG                0x13
 #define GLOBAL_INPUT_ISE1              0x51
 #define GLOBAL_INPUT_ISE2              0x52
+#define GLOBAL_INPUT_GAIN              0x53
 #define GLOBAL_INPUT_LOS               0x55
+#define GLOBAL_OUTPUT_PE1              0x56
+#define GLOBAL_OUTPUT_PE2              0x57
+#define GLOBAL_OUTPUT_LEVEL            0x58
+#define GLOBAL_OUTPUT_TERMINATION      0x5A
 #define GLOBAL_CORE_CNTRL              0x5D
 #define OUTPUT_MODE_PAGE               0x23
 #define CORE_CONTROL_PAGE              0x25
@@ -47,7 +35,7 @@ int vsc_if_enable(unsigned int vsc_addr)
        return i2c_write(vsc_addr, INTERFACE_MODE_REG, 1, &data, 1);
 }
 
-int vsc3316_config(unsigned int vsc_addr, const int8_t con_arr[][2],
+int vsc3316_config(unsigned int vsc_addr, int8_t con_arr[][2],
                unsigned int num_con)
 {
        unsigned int i;
@@ -108,6 +96,109 @@ int vsc3316_config(unsigned int vsc_addr, const int8_t con_arr[][2],
        return 0;
 }
 
+#ifdef CONFIG_SYS_FSL_B4860QDS_XFI_ERR
+int vsc3308_config_adjust(unsigned int vsc_addr, const int8_t con_arr[][2],
+               unsigned int num_con)
+{
+       unsigned int i;
+       u8 rev_id = 0;
+       int ret;
+
+       debug("VSC:Initializing VSC3308 at I2C address 0x%x for Tx\n",
+             vsc_addr);
+
+       ret = i2c_read(vsc_addr, REVISION_ID_REG, 1, &rev_id, 1);
+       if (ret < 0) {
+               printf("VSC:0x%x could not read REV_ID from device.\n",
+                      vsc_addr);
+               return ret;
+       }
+
+       if (rev_id != 0xab) {
+               printf("VSC: device at address 0x%x is not VSC3316/3308.\n",
+                      vsc_addr);
+               return -ENODEV;
+       }
+
+       ret = vsc_if_enable(vsc_addr);
+       if (ret) {
+               printf("VSC:0x%x could not configured for 2-wire I/F.\n",
+                      vsc_addr);
+               return ret;
+       }
+
+       /* config connections - page 0x00 */
+       i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, CONNECTION_CONFIG_PAGE);
+
+       /* Configure Global Input ISE */
+       i2c_reg_write(vsc_addr, GLOBAL_INPUT_ISE1, 0);
+       i2c_reg_write(vsc_addr, GLOBAL_INPUT_ISE2, 0);
+
+       /* Configure Tx/Rx Global Output PE1 */
+       i2c_reg_write(vsc_addr, GLOBAL_OUTPUT_PE1, 0);
+
+       /* Configure Tx/Rx Global Output PE2 */
+       i2c_reg_write(vsc_addr, GLOBAL_OUTPUT_PE2, 0);
+
+       /* Configure Tx/Rx Global Input GAIN */
+       i2c_reg_write(vsc_addr, GLOBAL_INPUT_GAIN, 0x3F);
+
+       /* Setting Global Input LOS threshold value */
+       i2c_reg_write(vsc_addr, GLOBAL_INPUT_LOS, 0xE0);
+
+       /* Setting Global output termination */
+       i2c_reg_write(vsc_addr, GLOBAL_OUTPUT_TERMINATION, 0);
+
+       /* Configure Tx/Rx Global Output level */
+       if (vsc_addr == VSC3308_TX_ADDRESS)
+               i2c_reg_write(vsc_addr, GLOBAL_OUTPUT_LEVEL, 4);
+       else
+               i2c_reg_write(vsc_addr, GLOBAL_OUTPUT_LEVEL, 2);
+
+       /* Making crosspoint connections, by connecting required
+        * input to output */
+       for (i = 0; i < num_con ; i++)
+               i2c_reg_write(vsc_addr, con_arr[i][1], con_arr[i][0]);
+
+       /* input state - page 0x13 */
+       i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, INPUT_STATE_REG);
+       /* Turning off all the required input of the switch */
+       for (i = 0; i < num_con; i++)
+               i2c_reg_write(vsc_addr, con_arr[i][0], 1);
+
+       /* only turn on specific Tx/Rx requested by the XFI erratum */
+       if (vsc_addr == VSC3308_TX_ADDRESS) {
+               i2c_reg_write(vsc_addr, 2, 0);
+               i2c_reg_write(vsc_addr, 3, 0);
+       } else {
+               i2c_reg_write(vsc_addr, 0, 0);
+               i2c_reg_write(vsc_addr, 1, 0);
+       }
+
+       /* config output mode - page 0x23 */
+       i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, OUTPUT_MODE_PAGE);
+       /* Turn off the Output driver correspond to required output*/
+       for (i = 0; i < num_con ; i++)
+               i2c_reg_write(vsc_addr,  con_arr[i][1], 1);
+
+       /* only turn on specific Tx/Rx requested by the XFI erratum */
+       if (vsc_addr == VSC3308_TX_ADDRESS) {
+               i2c_reg_write(vsc_addr, 0, 0);
+               i2c_reg_write(vsc_addr, 1, 0);
+       } else {
+               i2c_reg_write(vsc_addr, 3, 0);
+               i2c_reg_write(vsc_addr, 4, 0);
+       }
+
+       /* configure global core control register, Turn on Global core power */
+       i2c_reg_write(vsc_addr, GLOBAL_CORE_CNTRL, 0);
+
+       vsc_wp_config(vsc_addr);
+
+       return 0;
+}
+#endif
+
 int vsc3308_config(unsigned int vsc_addr, const int8_t con_arr[][2],
                unsigned int num_con)
 {