pca9548.c (2013B)
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 * 7 * BCM56xx I2C Device Driver for Phillips PCA9548 i2c switch 8 */ 9 10 #include <sal/types.h> 11 #include <soc/debug.h> 12 #include <soc/drv.h> 13 #include <soc/error.h> 14 #include <soc/i2c.h> 15 #include <shared/bsl.h> 16 17 STATIC int 18 pca9548_read(int unit, int devno, uint16 addr, uint8* data, uint32* len) 19 { 20 21 int rv; 22 uint8 saddr = soc_i2c_addr(unit, devno); 23 24 rv = soc_i2c_read_byte(unit, saddr, data); 25 *len = 1; /* Byte device */ 26 /* LOG_CLI((BSL_META_U(unit, 27 "sw%d: read 0x%x from sw at 0x%x\n"), devno, *data, saddr)); */ 28 soc_i2c_device(unit, devno)->rbyte++; 29 return rv; 30 } 31 32 /* 33 * The data is what gets actually written to the channel selection 34 * register. The channel must be converted to the appropriate bit 35 * by the caller. 36 */ 37 STATIC int 38 pca9548_write(int unit, int devno, uint16 addr, uint8* data, uint32 len) 39 { 40 int rv; 41 uint8 saddr = soc_i2c_addr(unit, devno); 42 43 rv = soc_i2c_write_byte(unit, saddr, *data); 44 /* LOG_CLI((BSL_META_U(unit, 45 "sw%d: wrote 0x%x to sw at 0x%x\n"), devno, *data, saddr)); */ 46 soc_i2c_device(unit, devno)->tbyte++; 47 return rv; 48 } 49 50 51 52 STATIC int 53 pca9548_ioctl(int unit, int devno, int opcode, void* data, int len) 54 { 55 return SOC_E_NONE; 56 } 57 58 STATIC int 59 pca9548_init(int unit, int devno, void* data, int len) 60 { 61 62 soc_i2c_devdesc_set(unit, devno, "PCA9548 i2c Switch"); 63 if (!SOC_IS_SHADOW(unit)) { 64 /* enable channel 0 by default */ 65 return soc_i2c_write_byte(unit, soc_i2c_addr(unit, devno), 1); 66 } 67 return SOC_E_NONE; 68 } 69 70 71 /* PCA9548 Clock Chip Driver callout */ 72 i2c_driver_t _soc_i2c_pca9548_driver = { 73 0x0, 0x0, /* System assigned bytes */ 74 PCA9548_DEVICE_TYPE, 75 pca9548_read, 76 pca9548_write, 77 pca9548_ioctl, 78 pca9548_init, 79 NULL, 80 }; 81