max5478.c (3233B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * All Rights Reserved.$ 7 * 8 * BCM56xx I2C Device Driver for Maxim 5478 Digital Potentiometer 9 * The Maxim 5478 digital potentiometer is used to adjust the voltage 10 * divider in SDK baseboards. See the Maxim 5478 datasheet for more info. 11 */ 12 #include <sal/types.h> 13 #include <soc/debug.h> 14 #include <soc/drv.h> 15 #include <soc/error.h> 16 #include <soc/i2c.h> 17 #include <sal/core/libc.h> 18 #include <shared/bsl.h> 19 /* Command byte - see Max5478, Table 2 */ 20 #define MAX5478_CMD_WIPER_A_VREG 0x11 21 #define MAX5478_CMD_WIPER_A_VREG_X_NVREG 0x51 22 #define MAX5478_CMD_WIPER_B_CMD 0x12 23 #define MAX5478_CMD_WIPER_B_VREG_X_NVREG 0x52 24 25 STATIC int 26 max5478_read(int unit, int devno, 27 uint16 addr, uint8* data, uint32* len) 28 { 29 COMPILER_REFERENCE(unit); 30 COMPILER_REFERENCE(devno); 31 COMPILER_REFERENCE(addr); 32 COMPILER_REFERENCE(data); 33 COMPILER_REFERENCE(len); 34 35 return SOC_E_NONE; 36 } 37 38 STATIC int 39 max5478_write(int unit, int devno, 40 uint16 addr, uint8* data, uint32 len) 41 { 42 int rv = SOC_E_NONE; 43 return rv; 44 } 45 46 STATIC int 47 max5478_ioctl(int unit, int devno, 48 int request, void* data, int len) 49 { 50 int rv = SOC_E_NONE; 51 uint16 msg0; 52 uint8 msg1; 53 max5478_t *params; 54 55 switch (request) { 56 case I2C_POT_IOC_SET: 57 params = (max5478_t *)data; 58 switch (params->wiper) { 59 case I2C_POT_MSG_WIPER_A: 60 msg0 = MAX5478_CMD_WIPER_A_VREG; 61 msg1 = MAX5478_CMD_WIPER_A_VREG_X_NVREG; 62 break; 63 64 case I2C_POT_MSG_WIPER_B: 65 msg0 = MAX5478_CMD_WIPER_B_CMD; 66 msg1 = MAX5478_CMD_WIPER_B_VREG_X_NVREG; 67 break; 68 69 default: 70 LOG_VERBOSE(BSL_LS_SOC_COMMON, 71 (BSL_META_U(unit, 72 "POT%d: invalid wiper %d\n"), 73 devno, params->wiper)); 74 return SOC_E_PARAM; 75 } 76 77 /* Command byte VREG + data byte */ 78 msg0 = (msg0 << 8) | params->value; 79 rv = soc_i2c_write_word(unit, soc_i2c_addr(unit, devno), msg0); 80 if (rv == SOC_E_NONE) { 81 soc_i2c_device(unit, devno)->tbyte +=2; 82 } 83 84 /* Transfer VREG to NVREG */ 85 rv = soc_i2c_write_byte(unit, soc_i2c_addr(unit, devno), msg1); 86 if (rv == SOC_E_NONE) { 87 soc_i2c_device(unit, devno)->tbyte++; 88 } 89 90 break; 91 92 default: 93 LOG_VERBOSE(BSL_LS_SOC_COMMON, 94 (BSL_META_U(unit, 95 "POT%d: invalid request %d\n"), 96 devno, request)); 97 return SOC_E_PARAM; 98 } 99 return rv; 100 } 101 102 STATIC int 103 max5478_init(int unit, int devno, 104 void* data, int len) 105 { 106 soc_i2c_devdesc_set(unit, devno, "Maxim 5478 Digital Potentiometer"); 107 108 return SOC_E_NONE; 109 } 110 111 /* MAX5478 Clock Chip Driver callout */ 112 i2c_driver_t _soc_i2c_max5478_driver = { 113 0x0, 0x0, /* System assigned bytes */ 114 MAX5478_DEVICE_TYPE, 115 max5478_read, 116 max5478_write, 117 max5478_ioctl, 118 max5478_init, 119 NULL, 120 };