diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/modules/builds/delta_ak7448_platform.c b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/modules/builds/delta_ak7448_platform.c new file mode 100644 index 00000000..cdd078ac --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/modules/builds/delta_ak7448_platform.c @@ -0,0 +1,1439 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CPLD_A_REG 0x33 +#define CPLD_B_REG 0x32 +#define BUS3_MUX_REG 0x11 +#define BUS8_MUX_REG 0x19 + +#define QSFP_P0_VAL 0x04 +#define QSFP_P1_VAL 0x03 +#define QSFP_P2_VAL 0x02 +#define QSFP_P3_VAL 0x00 + +#define SFP_PRESENCE_1 0x02 +#define SFP_PRESENCE_2 0x03 +#define SFP_PRESENCE_3 0x04 +#define SFP_PRESENCE_4 0x05 +#define SFP_PRESENCE_5 0x06 +#define SFP_PRESENCE_6 0x07 +#define QSFP_PRESENCE_1 0x0d +#define QSFP_LP_MODE_1 0x0c +#define QSFP_RESET_1 0x0e + +#define DEFAULT_DISABLE 0x00 +#define QSFP_DEFAULT_DISABLE 0x01 + +#define BUS3_DEV_NUM 4 +#define BUS8_DEV_NUM 48 +#define DEFAULT_NUM 1 +#define BUS3_BASE_NUM 20 +#define BUS8_BASE_NUM 30 + +#define ak7448_i2c_device_num(NUM){ \ + .name = "delta-ak7448-i2c-device", \ + .id = NUM, \ + .dev = { \ + .platform_data = &ak7448_i2c_device_platform_data[NUM], \ + .release = device_release, \ + }, \ +} + +/* Check cpld read results */ +#define VALIDATED_READ(_buf, _rv, _read, _invert) \ + do { \ + _rv = _read; \ + if (_rv < 0) { \ + return sprintf(_buf, "READ ERROR\n"); \ + } \ + if (_invert) { \ + _rv = ~_rv; \ + } \ + _rv &= 0xFF; \ + } while(0) \ + + +/*Define struct to get client of i2c_new_deivce */ +struct i2c_client * i2c_client_9548; + +enum{ + BUS0 = 0, + BUS1, + BUS2, + BUS3, + BUS4, + BUS5, + BUS6, + BUS7, + BUS8, +}; + +long sfp_port_data = 0; + +static LIST_HEAD(cpld_client_list); + +struct cpld_client_node +{ + struct i2c_client *client; + struct list_head list; +}; + +int i2c_cpld_read(int bus, unsigned short cpld_addr, u8 reg) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EPERM; + + list_for_each(list_node, &cpld_client_list){ + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if ((cpld_node->client->adapter->nr == bus) && (cpld_node->client->addr == cpld_addr) ){ + ret = i2c_smbus_read_byte_data(cpld_node->client, reg); + break; + } + } + return ret; +} +EXPORT_SYMBOL(i2c_cpld_read); + +int i2c_cpld_write(int bus, unsigned short cpld_addr, u8 reg, u8 value) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EIO; + + list_for_each(list_node, &cpld_client_list){ + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if ((cpld_node->client->adapter->nr == bus) && (cpld_node->client->addr == cpld_addr) ){ + ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value); + break; + } + } + + return ret; +} +EXPORT_SYMBOL(i2c_cpld_write); + +/*---------------- I2C device - start ------------- */ +static void device_release(struct device *dev) +{ + return; +} + +struct i2c_device_platform_data { + int parent; + struct i2c_board_info info; + struct i2c_client *client; +}; + +static struct i2c_device_platform_data ak7448_i2c_device_platform_data[] = { + { + /* qsfp 1 (0x50) */ + .parent = 20, + .info = { .type = "optoe1", .addr = 0x50 }, + .client = NULL, + }, + { + /* qsfp 2 (0x50) */ + .parent = 21, + .info = { .type = "optoe1", .addr = 0x50 }, + .client = NULL, + }, + { + /* qsfp 3 (0x50) */ + .parent = 22, + .info = { .type = "optoe1", .addr = 0x50 }, + .client = NULL, + }, + { + /* qsfp 4 (0x50) */ + .parent = 23, + .info = { .type = "optoe1", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 1 (0x50) */ + .parent = 30, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 2 (0x50) */ + .parent = 31, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 3 (0x50) */ + .parent = 32, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 4 (0x50) */ + .parent = 33, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 5 (0x50) */ + .parent = 34, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 6 (0x50) */ + .parent = 35, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 7 (0x50) */ + .parent = 36, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 8 (0x50) */ + .parent = 37, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 9 (0x50) */ + .parent = 38, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 10 (0x50) */ + .parent = 39, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 11 (0x50) */ + .parent = 40, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 12 (0x50) */ + .parent = 41, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 13 (0x50) */ + .parent = 42, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 14 (0x50) */ + .parent = 43, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 15 (0x50) */ + .parent = 44, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 16 (0x50) */ + .parent = 45, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 17 (0x50) */ + .parent = 46, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 18 (0x50) */ + .parent = 47, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 19 (0x50) */ + .parent = 48, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 20 (0x50) */ + .parent = 49, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 21 (0x50) */ + .parent = 50, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 22 (0x50) */ + .parent = 51, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 23 (0x50) */ + .parent = 52, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 24 (0x50) */ + .parent = 53, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 25 (0x50) */ + .parent = 54, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 26 (0x50) */ + .parent = 55, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 27 (0x50) */ + .parent = 56, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 28 (0x50) */ + .parent = 57, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 29 (0x50) */ + .parent = 58, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 30 (0x50) */ + .parent = 59, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 31 (0x50) */ + .parent = 60, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 32 (0x50) */ + .parent = 61, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 33 (0x50) */ + .parent = 62, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 34 (0x50) */ + .parent = 63, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 35 (0x50) */ + .parent = 64, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 36 (0x50) */ + .parent = 65, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 37 (0x50) */ + .parent = 66, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 38 (0x50) */ + .parent = 67, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 39 (0x50) */ + .parent = 68, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 40 (0x50) */ + .parent = 69, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 41 (0x50) */ + .parent = 70, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 42 (0x50) */ + .parent = 71, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 43 (0x50) */ + .parent = 72, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 44 (0x50) */ + .parent = 73, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 45 (0x50) */ + .parent = 74, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 46 (0x50) */ + .parent = 75, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 47 (0x50) */ + .parent = 76, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, + { + /* sfp 48 (0x50) */ + .parent = 77, + .info = { .type = "optoe2", .addr = 0x50 }, + .client = NULL, + }, +}; + + +static struct platform_device ak7448_i2c_device[] = { + ak7448_i2c_device_num(0), + ak7448_i2c_device_num(1), + ak7448_i2c_device_num(2), + ak7448_i2c_device_num(3), + ak7448_i2c_device_num(4), + ak7448_i2c_device_num(5), + ak7448_i2c_device_num(6), + ak7448_i2c_device_num(7), + ak7448_i2c_device_num(8), + ak7448_i2c_device_num(9), + ak7448_i2c_device_num(10), + ak7448_i2c_device_num(11), + ak7448_i2c_device_num(12), + ak7448_i2c_device_num(13), + ak7448_i2c_device_num(14), + ak7448_i2c_device_num(15), + ak7448_i2c_device_num(16), + ak7448_i2c_device_num(17), + ak7448_i2c_device_num(18), + ak7448_i2c_device_num(19), + ak7448_i2c_device_num(20), + ak7448_i2c_device_num(21), + ak7448_i2c_device_num(22), + ak7448_i2c_device_num(23), + ak7448_i2c_device_num(24), + ak7448_i2c_device_num(25), + ak7448_i2c_device_num(26), + ak7448_i2c_device_num(27), + ak7448_i2c_device_num(28), + ak7448_i2c_device_num(29), + ak7448_i2c_device_num(30), + ak7448_i2c_device_num(31), + ak7448_i2c_device_num(32), + ak7448_i2c_device_num(33), + ak7448_i2c_device_num(34), + ak7448_i2c_device_num(35), + ak7448_i2c_device_num(36), + ak7448_i2c_device_num(37), + ak7448_i2c_device_num(38), + ak7448_i2c_device_num(39), + ak7448_i2c_device_num(40), + ak7448_i2c_device_num(41), + ak7448_i2c_device_num(42), + ak7448_i2c_device_num(43), + ak7448_i2c_device_num(44), + ak7448_i2c_device_num(45), + ak7448_i2c_device_num(46), + ak7448_i2c_device_num(47), + ak7448_i2c_device_num(48), + ak7448_i2c_device_num(49), + ak7448_i2c_device_num(50), + ak7448_i2c_device_num(51), +}; + +/*---------------- I2C device - end ------------- */ + +/*---------------- I2C driver - start ------------- */ +static int __init i2c_device_probe(struct platform_device *pdev) +{ + struct i2c_device_platform_data *pdata; + struct i2c_adapter *parent; + + pdata = pdev->dev.platform_data; + if (!pdata) { + dev_err(&pdev->dev, "Missing platform data\n"); + return -ENODEV; + } + + parent = i2c_get_adapter(pdata->parent); + if (!parent) { + dev_err(&pdev->dev, "Parent adapter (%d) not found\n", + pdata->parent); + return -ENODEV; + } + + pdata->client = i2c_new_device(parent, &pdata->info); + if (!pdata->client) { + dev_err(&pdev->dev, "Failed to create i2c client %s at %d\n", + pdata->info.type, pdata->parent); + return -ENODEV; + } + + return 0; +} + +static int __exit i2c_deivce_remove(struct platform_device *pdev) +{ + struct i2c_adapter *parent; + struct i2c_device_platform_data *pdata; + + pdata = pdev->dev.platform_data; + if (!pdata) { + dev_err(&pdev->dev, "Missing platform data\n"); + return -ENODEV; + } + + if (pdata->client) { + parent = i2c_get_adapter(pdata->parent); + i2c_unregister_device(pdata->client); + i2c_put_adapter(parent); + } + + return 0; +} +static struct platform_driver i2c_device_driver = { + .probe = i2c_device_probe, + .remove = __exit_p(i2c_deivce_remove), + .driver = { + .owner = THIS_MODULE, + .name = "delta-ak7448-i2c-device", + } +}; + +/*---------------- I2C driver - end ------------- */ + +/*---------------- CPLD - start ------------- */ + +/* CPLD -- device */ + +enum cpld_type { + cpld_a, + cpld_b, +}; + +struct cpld_platform_data { + int reg_addr; + struct i2c_client *client; +}; + +static struct cpld_platform_data ak7448_cpld_platform_data[] = { + [cpld_a] = { + .reg_addr = CPLD_A_REG, + }, + [cpld_b] = { + .reg_addr = CPLD_B_REG, + }, +}; + +static struct platform_device ak7448_cpld = { + .name = "delta-ak7448-cpld", + .id = 0, + .dev = { + .platform_data = ak7448_cpld_platform_data, + .release = device_release + }, +}; + +static ssize_t for_status(struct device *dev, struct device_attribute *dev_attr, char *buf); + +enum ak7448_sfp_sysfs_attributes +{ + SFP_SELECT_PORT, + SFP_IS_PRESENT, + SFP_IS_PRESENT_ALL, + SFP_LP_MODE, + SFP_RESET, + ADDR, + DATA, +}; + +static struct kobject *kobj_swpld; + +static ssize_t set_w_port_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); + struct device *i2cdev = kobj_to_dev(kobj_swpld); + struct cpld_platform_data *pdata = i2cdev->platform_data; + long data; + int error; + long port_t = 0; + u8 reg_t = 0x00; + + error = kstrtol(buf, 10, &data); + if(error) + return error; + + /* Disable SFP channel */ + if (i2c_smbus_write_byte_data(pdata[cpld_b].client, BUS8_MUX_REG, (u8)DEFAULT_DISABLE) < 0) { + return -EIO; + } + + /* Disable QSFP channel */ + if (i2c_smbus_write_byte_data(pdata[cpld_b].client, BUS3_MUX_REG, (u8)QSFP_DEFAULT_DISABLE) < 0) { + return -EIO; + } + + sfp_port_data = data; + return count; +} + +static ssize_t for_r_port_data(struct device *dev, struct device_attribute *dev_attr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); + struct device *i2cdev = kobj_to_dev(kobj_swpld); + struct cpld_platform_data *pdata = i2cdev->platform_data; + + if (sfp_port_data == DEFAULT_DISABLE) + { + /* Disable SFP channel */ + if (i2c_smbus_write_byte_data(pdata[cpld_b].client, BUS8_MUX_REG, (u8)DEFAULT_DISABLE) < 0) { + return -EIO; + } + + /* Disable QSFP channel */ + if (i2c_smbus_write_byte_data(pdata[cpld_b].client, BUS3_MUX_REG, (u8)QSFP_DEFAULT_DISABLE) < 0) { + return -EIO; + } + } + + return sprintf(buf, "%d\n", sfp_port_data); + +} + +static ssize_t set_w_lp_mode_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); + struct device *i2cdev = kobj_to_dev(kobj_swpld); + struct cpld_platform_data *pdata = i2cdev->platform_data; + long data; + int error; + long port_t = 0; + int bit_t = 0x00; + int values = 0x00; + + error = kstrtol(buf, 10, &data); + if (error) + return error; + + port_t = sfp_port_data; + + if (port_t > 48 && port_t < 53) + { /* QSFP Port 48-53 */ + values = i2c_smbus_read_byte_data(pdata[cpld_b].client, QSFP_LP_MODE_1); + if (values < 0) + return -EIO; + + /* Indicate the module is in LP mode or not + * 0 = Disable + * 1 = Enable + */ + if (data == 0) + { + bit_t = ~(1 << ((port_t - 1) % 8)); + values = values & bit_t; + } + else if (data == 1) + { + bit_t = 1 << ((port_t - 1) % 8); + values = values | bit_t; + } + else + { + return -EINVAL; + } + + if (i2c_smbus_write_byte_data(pdata[cpld_b].client, QSFP_LP_MODE_1, (u8)values) < 0) + { + return -EIO; + } + } + + return count; +} + +static ssize_t set_w_reset_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); + struct device *i2cdev = kobj_to_dev(kobj_swpld); + struct cpld_platform_data *pdata = i2cdev->platform_data; + long data; + int error; + long port_t = 0; + int bit_t = 0x00; + int values = 0x00; + + error = kstrtol(buf, 10, &data); + if (error) + return error; + + port_t = sfp_port_data; + + if (port_t > 48 && port_t < 53) + { /* QSFP Port 48-53 */ + values = i2c_smbus_read_byte_data(pdata[cpld_b].client, QSFP_RESET_1); + if (values < 0) + return -EIO; + + /* Indicate the module Reset or not + * 0 = Reset + * 1 = Normal + */ + if (data == 0) + { + bit_t = ~(1 << ((port_t - 1) % 8)); + values = values & bit_t; + } + else if (data == 1) + { + bit_t = 1 << ((port_t - 1) % 8); + values = values | bit_t; + } + else + { + return -EINVAL; + } + + if (i2c_smbus_write_byte_data(pdata[cpld_b].client, QSFP_RESET_1, (u8)values) < 0) + { + return -EIO; + } + } + + return count; +} + +static ssize_t for_status(struct device *dev, struct device_attribute *dev_attr, char *buf){ + struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); + struct device *i2cdev = kobj_to_dev(kobj_swpld); + struct cpld_platform_data *pdata = i2cdev->platform_data; + long port_t = 0; + u8 reg_t = 0x00; + u8 cpld_addr_t = 0x00; + int values[7] = {'\0'}; + int bit_t = 0x00; + + switch (attr->index) { + case SFP_IS_PRESENT: + port_t = sfp_port_data; + + if (port_t > 0 && port_t < 9) { /* SFP Port 1-8 */ + reg_t = SFP_PRESENCE_1; + } else if (port_t > 8 && port_t < 17) { /* SFP Port 9-16 */ + reg_t = SFP_PRESENCE_2; + } else if (port_t > 16 && port_t < 25) { /* SFP Port 17-24 */ + reg_t = SFP_PRESENCE_3; + } else if (port_t > 24 && port_t < 33) { /* SFP Port 25-32 */ + reg_t = SFP_PRESENCE_4; + } else if (port_t > 32 && port_t < 41) { /* SFP Port 33-40 */ + reg_t = SFP_PRESENCE_5; + } else if (port_t > 40 && port_t < 49) { /* SFP Port 41-48 */ + reg_t = SFP_PRESENCE_6; + } else if (port_t > 48 && port_t < 53) { /* QSFP Port 49-54 */ + reg_t = QSFP_PRESENCE_1; + } else { + values[0] = 1; /* return 1, module NOT present */ + return sprintf(buf, "%d\n", values[0]); + } + + if(port_t > 48 && port_t < 53){ + VALIDATED_READ(buf, values[0], i2c_smbus_read_byte_data(pdata[cpld_b].client, reg_t), 0); + } + else{ + VALIDATED_READ(buf, values[0], i2c_smbus_read_byte_data(pdata[cpld_a].client, reg_t), 0); + } + + /* SWPLD QSFP module respond */ + bit_t = 1 << ((port_t - 1) % 8); + values[0] = values[0] & bit_t; + values[0] = values[0] / bit_t; + + /* sfp_is_present value + * return 0 is module present + * return 1 is module NOT present*/ + return sprintf(buf, "%d\n", values[0]); + + case SFP_IS_PRESENT_ALL: + /* + * Report the SFP ALL PRESENCE status + * This data information form CPLD.*/ + + /* SFP_PRESENT Ports 1-8 */ + VALIDATED_READ(buf, values[0], + i2c_smbus_read_byte_data(pdata[cpld_a].client, SFP_PRESENCE_1), 0); + /* SFP_PRESENT Ports 9-16 */ + VALIDATED_READ(buf, values[1], + i2c_smbus_read_byte_data(pdata[cpld_a].client, SFP_PRESENCE_2), 0); + /* SFP_PRESENT Ports 17-24 */ + VALIDATED_READ(buf, values[2], + i2c_smbus_read_byte_data(pdata[cpld_a].client, SFP_PRESENCE_3), 0); + /* SFP_PRESENT Ports 25-32 */ + VALIDATED_READ(buf, values[3], + i2c_smbus_read_byte_data(pdata[cpld_a].client, SFP_PRESENCE_4), 0); + /* SFP_PRESENT Ports 33-40 */ + VALIDATED_READ(buf, values[4], + i2c_smbus_read_byte_data(pdata[cpld_a].client, SFP_PRESENCE_5), 0); + /* SFP_PRESENT Ports 41-48 */ + VALIDATED_READ(buf, values[5], + i2c_smbus_read_byte_data(pdata[cpld_a].client, SFP_PRESENCE_6), 0); + /* QSFP_PRESENT Ports 49-52 */ + VALIDATED_READ(buf, values[6], + i2c_smbus_read_byte_data(pdata[cpld_b].client, QSFP_PRESENCE_1), 0); + + + /* sfp_is_present_all value + * return 0 is module present + * return 1 is module NOT present + */ + return sprintf(buf, "%02X %02X %02X %02X %02X %02X %02X \n",values[0], values[1], values[2],values[3], values[4], values[5],values[6]); + case SFP_LP_MODE: + port_t = sfp_port_data; + if (port_t > 48 && port_t < 53) { + /* QSFP Port 49-52 */ + VALIDATED_READ(buf, values[0], i2c_smbus_read_byte_data(pdata[cpld_b].client, QSFP_LP_MODE_1), 0); + } else { + /* In AK7448 only QSFP support control LP MODE */ + values[0] = 0; + return sprintf(buf, "%d\n", values[0]); + } + + bit_t = 1 << ((port_t - 1) % 8); + values[0] = values[0] & bit_t; + values[0] = values[0] / bit_t; + + /* sfp_lp_mode value + * return 0 is module NOT in LP mode + * return 1 is module in LP mode + */ + + return sprintf(buf, "%d\n", values[0]); + + case SFP_RESET: + port_t = sfp_port_data; + if (port_t > 48 && port_t < 53) { + /* QSFP Port 49-54 */ + VALIDATED_READ(buf, values[0], i2c_smbus_read_byte_data(pdata[cpld_b].client, QSFP_RESET_1), 0); + } else { + /* In AK7448 only QSFP support control RESET MODE */ + values[0] = 1; + return sprintf(buf, "%d\n", values[0]); + } + + /* SWPLD QSFP module respond */ + bit_t = 1 << ((port_t - 1) % 8); + values[0] = values[0] & bit_t; + values[0] = values[0] / bit_t; + + /* sfp_reset value + * return 0 is module Reset + * return 1 is module Normal*/ + return sprintf(buf, "%d\n", values[0]); + + default: + return sprintf(buf, "%d not found", attr->index); + } +} + +static unsigned char swpld_reg_addr; + +static ssize_t +get_cpld_data(struct device *dev, struct device_attribute *attr, char *buf) +{ + int ret; + struct cpld_platform_data *pdata = dev->platform_data; + + ret = sprintf(buf, "0x%x\n",i2c_smbus_read_byte_data(pdata[cpld_b].client, swpld_reg_addr)); + return ret; +} + +static ssize_t +set_cpld_data(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct cpld_platform_data *pdata = dev->platform_data; + unsigned int val; + char *endp; + char ret = -1; + + val = simple_strtoul(buf, &endp, 16); + if (isspace(*endp)){ + endp++; + } + + if (endp - buf != count){ + return -1; + } + + if (val > 255){ + return -1; + } + + ret = i2c_smbus_write_byte_data(pdata[cpld_b].client, swpld_reg_addr, val); + + return count; +} + +static ssize_t get_cpld_reg(struct device *dev, struct device_attribute *attr, + char *buf) +{ + int len; + len = sprintf(buf, "0x%x\n", swpld_reg_addr); + return len; +} + +static ssize_t +set_cpld_reg(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned int val; + char *endp; + + val = simple_strtoul(buf, &endp, 16); + if (isspace(*endp)){ + endp++; + } + + if (endp - buf != count){ + return -1; + } + + if (val > 255) + { + return -1; + } + swpld_reg_addr = val; + return count; +} + + +static SENSOR_DEVICE_ATTR(sfp_select_port, S_IWUSR | S_IRUGO, for_r_port_data, set_w_port_data, SFP_SELECT_PORT); +static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, for_status, NULL, SFP_IS_PRESENT); +static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, for_status, NULL, SFP_IS_PRESENT_ALL); +static SENSOR_DEVICE_ATTR(sfp_lp_mode, S_IWUSR | S_IRUGO, for_status, set_w_lp_mode_data, SFP_LP_MODE); +static SENSOR_DEVICE_ATTR(sfp_reset, S_IWUSR | S_IRUGO, for_status, set_w_reset_data, SFP_RESET); +static SENSOR_DEVICE_ATTR(data, S_IWUSR | S_IRUGO, get_cpld_data, set_cpld_data, DATA); +static SENSOR_DEVICE_ATTR(addr, S_IWUSR | S_IRUGO, get_cpld_reg, set_cpld_reg, ADDR); + + +static struct attribute *ak7448_cpld_attrs[] = { + &sensor_dev_attr_sfp_select_port.dev_attr.attr, + &sensor_dev_attr_sfp_is_present.dev_attr.attr, + &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, + &sensor_dev_attr_sfp_lp_mode.dev_attr.attr, + &sensor_dev_attr_sfp_reset.dev_attr.attr, + &sensor_dev_attr_data.dev_attr.attr, + &sensor_dev_attr_addr.dev_attr.attr, + NULL, +}; + +static struct attribute_group ak7448_cpld_attr_grp = { + .attrs = ak7448_cpld_attrs, +}; + + +/* CPLD -- driver */ +static int __init cpld_probe(struct platform_device *pdev) +{ + struct cpld_platform_data *pdata; + struct i2c_adapter *parent; + int ret,i; + + pdata = pdev->dev.platform_data; + if (!pdata) { + dev_err(&pdev->dev, "CPLD platform data not found\n"); + return -ENODEV; + } + + parent = i2c_get_adapter(BUS5); + if (!parent) { + printk(KERN_WARNING "Parent adapter (%d) not found\n",BUS5); + return -ENODEV; + } + + for (i = 0; i < ARRAY_SIZE(ak7448_cpld_platform_data); i++) { + pdata[i].client = i2c_new_dummy(parent, pdata[i].reg_addr); + if (!pdata[i].client) { + printk(KERN_WARNING "Fail to create dummy i2c client for addr %d\n", pdata[i].reg_addr); + goto error; + } + } + + kobj_swpld = &pdev->dev.kobj; + ret = sysfs_create_group(&pdev->dev.kobj, &ak7448_cpld_attr_grp); + if (ret) { + printk(KERN_WARNING "Fail to create cpld attribute group"); + goto error; + } + + return 0; + +error: + kobject_put(kobj_swpld); + i--; + for (; i >= 0; i--) { + if (pdata[i].client) { + i2c_unregister_device(pdata[i].client); + } + } + i2c_put_adapter(parent); + + return -ENODEV; +} + +static int __exit cpld_remove(struct platform_device *pdev) +{ + struct i2c_adapter *parent = NULL; + struct cpld_platform_data *pdata = pdev->dev.platform_data; + int i; + sysfs_remove_group(&pdev->dev.kobj, &ak7448_cpld_attr_grp); + + if (!pdata) { + dev_err(&pdev->dev, "Missing platform data\n"); + } + else { + kobject_put(kobj_swpld); + for (i = 0; i < ARRAY_SIZE(ak7448_cpld_platform_data); i++) { + if (pdata[i].client) { + if (!parent) { + parent = (pdata[i].client)->adapter; + } + i2c_unregister_device(pdata[i].client); + } + } + } + + i2c_put_adapter(parent); + + return 0; +} + +static struct platform_driver cpld_driver = { + .probe = cpld_probe, + .remove = __exit_p(cpld_remove), + .driver = { + .owner = THIS_MODULE, + .name = "delta-ak7448-cpld", + }, +}; + +/*---------------- CPLD - end ------------- */ + +/*---------------- MUX - start ------------- */ + +struct swpld_mux_platform_data { + int parent; + int base_nr; + int reg_addr; + struct i2c_client *cpld; +}; + +struct swpld_mux { + struct i2c_adapter *parent; + struct i2c_adapter **child; + struct swpld_mux_platform_data data; +}; + +static struct swpld_mux_platform_data ak7448_swpld_mux_platform_data[] = { + { + .parent = BUS3, + .base_nr = BUS3_BASE_NUM, + .cpld = NULL, + .reg_addr = BUS3_MUX_REG , + }, + { + .parent = BUS8, + .base_nr = BUS8_BASE_NUM, + .cpld = NULL, + .reg_addr = BUS8_MUX_REG , + }, +}; + + +static struct platform_device ak7448_swpld_mux[] = { + { + .name = "delta-ak7448-swpld-mux", + .id = 0, + .dev = { + .platform_data = &ak7448_swpld_mux_platform_data[0], + .release = device_release, + }, + }, + { + .name = "delta-ak7448-swpld-mux", + .id = 1, + .dev = { + .platform_data = &ak7448_swpld_mux_platform_data[1], + .release = device_release, + }, + }, +}; + + +static int cpld_reg_write_byte(struct i2c_client *client, u8 regaddr, u8 val) +{ + union i2c_smbus_data data; + + data.byte = val; + return client->adapter->algo->smbus_xfer(client->adapter, client->addr, + client->flags, + I2C_SMBUS_WRITE, + regaddr, I2C_SMBUS_BYTE_DATA, &data); +} + +static int swpld_mux_select(struct i2c_adapter *adap, void *data, u8 chan) +{ + struct swpld_mux *mux = data; + u8 swpld_mux_val=0; + if ( mux->data.base_nr == BUS3_BASE_NUM ) + { + switch (chan) { + case 0: + swpld_mux_val = QSFP_P0_VAL; + break; + case 1: + swpld_mux_val = QSFP_P1_VAL; + break; + case 2: + swpld_mux_val = QSFP_P2_VAL; + break; + case 3: + swpld_mux_val = QSFP_P3_VAL; + break; + } + } + else if ( mux->data.base_nr == BUS8_BASE_NUM ){ + if (chan < 16){ + swpld_mux_val = (u8)(chan); + } + else if (15 < chan && chan < 32){ + swpld_mux_val = (u8)(chan - 16) + 0x10; + } + else if (31 < chan && chan < 48){ + swpld_mux_val = (u8)(chan - 32) + 0x20; + } + else{ + swpld_mux_val = 0x00; + } + } + else + { + swpld_mux_val = 0x00; + } + swpld_mux_val=swpld_mux_val & (u8)0x3F; + + return cpld_reg_write_byte(mux->data.cpld, mux->data.reg_addr, (u8)(swpld_mux_val & 0xff)); +} + +static int __init swpld_mux_probe(struct platform_device *pdev) +{ + struct swpld_mux *mux; + struct swpld_mux_platform_data *pdata; + struct i2c_adapter *parent; + int i, ret, dev_num; + + pdata = pdev->dev.platform_data; + if (!pdata) { + dev_err(&pdev->dev, "SWPLD platform data not found\n"); + return -ENODEV; + } + + parent = i2c_get_adapter(pdata->parent); + if (!parent) { + dev_err(&pdev->dev, "Parent adapter (%d) not found\n", pdata->parent); + return -ENODEV; + } + + /* Judge bus number to decide how many devices*/ + switch (pdata->parent) { + case BUS3: + dev_num = BUS3_DEV_NUM; + break; + case BUS8: + dev_num = BUS8_DEV_NUM; + break; + default : + dev_num = DEFAULT_NUM; + break; + } + + mux = kzalloc(sizeof(*mux), GFP_KERNEL); + if (!mux) { + ret = -ENOMEM; + printk(KERN_ERR "Failed to allocate memory for mux\n"); + goto alloc_failed; + } + + mux->parent = parent; + mux->data = *pdata; + mux->child = kzalloc(sizeof(struct i2c_adapter *) * dev_num, GFP_KERNEL); + if (!mux->child) { + ret = -ENOMEM; + printk(KERN_ERR "Failed to allocate memory for device on mux\n"); + goto alloc_failed2; + } + + for (i = 0; i < dev_num; i++) { + int nr = pdata->base_nr + i; + unsigned int class = 0; + + mux->child[i] = i2c_add_mux_adapter(parent, &pdev->dev, mux, + nr, i, class, + swpld_mux_select, NULL); + if (!mux->child[i]) { + ret = -ENODEV; + dev_err(&pdev->dev, "Failed to add adapter %d\n", i); + goto add_adapter_failed; + } + } + + platform_set_drvdata(pdev, mux); + return 0; + +add_adapter_failed: + for (; i > 0; i--) + i2c_del_mux_adapter(mux->child[i - 1]); + kfree(mux->child); +alloc_failed2: + kfree(mux); +alloc_failed: + i2c_put_adapter(parent); + + return ret; +} + + +static int __exit swpld_mux_remove(struct platform_device *pdev) +{ + int i; + struct swpld_mux *mux = platform_get_drvdata(pdev); + struct swpld_mux_platform_data *pdata; + struct i2c_adapter *parent; + int dev_num; + + pdata = pdev->dev.platform_data; + if (!pdata) { + dev_err(&pdev->dev, "SWPLD platform data not found\n"); + return -ENODEV; + } + + parent = i2c_get_adapter(pdata->parent); + if (!parent) { + dev_err(&pdev->dev, "Parent adapter (%d) not found\n", + pdata->parent); + return -ENODEV; + } + switch (pdata->parent) { + case BUS3: + dev_num = BUS3_DEV_NUM; + break; + case BUS8: + dev_num = BUS8_DEV_NUM; + break; + default : + dev_num = DEFAULT_NUM; + break; + } + + for (i = 0; i < dev_num; i++) + i2c_del_mux_adapter(mux->child[i]); + + platform_set_drvdata(pdev, NULL); + i2c_put_adapter(mux->parent); + kfree(mux->child); + kfree(mux); + + return 0; +} + +static struct platform_driver swpld_mux_driver = { + .probe = swpld_mux_probe, + .remove = __exit_p(swpld_mux_remove), /* TODO */ + .driver = { + .owner = THIS_MODULE, + .name = "delta-ak7448-swpld-mux", + }, +}; +/*---------------- MUX - end ------------- */ + + +/*---------------- module initialization ------------- */ +static void __init delta_ak7448_platform_init(void) +{ + struct i2c_client *client; + struct i2c_adapter *adapter; + struct cpld_platform_data *cpld_pdata; + struct swpld_mux_platform_data *swpld_pdata; + int ret,i = 0; + + // set the CPLD prob and remove + ret = platform_driver_register(&cpld_driver); + if (ret) { + printk(KERN_WARNING "Fail to register cpld driver\n"); + goto error_cpld_driver; + } + + // register the mux prob which call the CPLD + ret = platform_driver_register(&swpld_mux_driver); + if (ret) { + printk(KERN_WARNING "Fail to register swpld mux driver\n"); + goto error_swpld_mux_driver; + } + + // register the i2c devices + ret = platform_driver_register(&i2c_device_driver); + if (ret) { + printk(KERN_WARNING "Fail to register i2c device driver\n"); + goto error_i2c_device_driver; + } + + // register the CPLD + ret = platform_device_register(&ak7448_cpld); + if (ret) { + printk(KERN_WARNING "Fail to create cpld device\n"); + goto error_ak7448_cpld; + } + // link the CPLD and the Mux + cpld_pdata = ak7448_cpld.dev.platform_data; + + for (i = 0; i < ARRAY_SIZE(ak7448_swpld_mux); i++){ + swpld_pdata = ak7448_swpld_mux[i].dev.platform_data; + swpld_pdata->cpld = cpld_pdata[cpld_b].client; + ret = platform_device_register(&ak7448_swpld_mux[i]); + if (ret) { + printk(KERN_WARNING "Fail to create swpld mux %d\n", i); + goto error_ak7448_swpld_mux; + } + } + + for (i = 0; i < ARRAY_SIZE(ak7448_i2c_device); i++) + { + ret = platform_device_register(&ak7448_i2c_device[i]); + if (ret) { + printk(KERN_WARNING "Fail to create i2c device %d\n", i); + goto error_ak7448_i2c_device; + } + } + + if (ret) + goto error_ak7448_swpld_mux; + + return 0; + +error_ak7448_i2c_device: + i--; + for (; i >= 0; i--) { + platform_device_unregister(&ak7448_i2c_device[i]); + } + i = ARRAY_SIZE(ak7448_swpld_mux); +error_ak7448_swpld_mux: + i--; + for (; i >= 0; i--) { + platform_device_unregister(&ak7448_swpld_mux[i]); + } + platform_driver_unregister(&ak7448_cpld); +error_ak7448_cpld: + platform_driver_unregister(&i2c_device_driver); +error_i2c_device_driver: + platform_driver_unregister(&swpld_mux_driver); +error_swpld_mux_driver: + platform_driver_unregister(&cpld_driver); +error_cpld_driver: + return ret; +} + +static void __exit delta_ak7448_platform_exit(void) +{ + int i = 0; + + for ( i = 0; i < ARRAY_SIZE(ak7448_i2c_device); i++ ) { + platform_device_unregister(&ak7448_i2c_device[i]); + } + + for (i = 0; i < ARRAY_SIZE(ak7448_swpld_mux); i++) { + platform_device_unregister(&ak7448_swpld_mux[i]); + } + + platform_device_unregister(&ak7448_cpld); + platform_driver_unregister(&i2c_device_driver); + platform_driver_unregister(&cpld_driver); + platform_driver_unregister(&swpld_mux_driver); + +} + +module_init(delta_ak7448_platform_init); +module_exit(delta_ak7448_platform_exit); + +MODULE_DESCRIPTION("DNI ak7448 Platform Support"); +MODULE_AUTHOR("Johnson Lu "); +MODULE_LICENSE("GPL"); diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/modules/builds/dni_ak7448_psu.c b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/modules/builds/dni_ak7448_psu.c index a01354e4..1960e9ff 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/modules/builds/dni_ak7448_psu.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/modules/builds/dni_ak7448_psu.c @@ -131,10 +131,9 @@ static ssize_t set_fan_duty_cycle(struct device *dev, struct device_attribute \ return -EINVAL; /* Select SWPLD PSU offset */ - i2c_cpld_write(SWPLD_BUS, SWPLD_REG, - SWPLD_PSU_MUX_REG, SELECT_PSU2_EEPROM); mutex_lock(&data->update_lock); + i2c_cpld_write(SWPLD_BUS, SWPLD_REG,SWPLD_PSU_MUX_REG, SELECT_PSU2_EEPROM); data->fan_duty_cycle[nr] = speed; dps_800ab_16_d_write_word(client, 0x3B + nr, data->fan_duty_cycle[nr]); mutex_unlock(&data->update_lock); diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/modules/builds/dni_ak7448_sfp.c b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/modules/builds/dni_ak7448_sfp.c deleted file mode 100755 index 1c69ed28..00000000 --- a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/modules/builds/dni_ak7448_sfp.c +++ /dev/null @@ -1,698 +0,0 @@ -/* - * An hwmon driver for agema ak7448 qsfp - * - * Copyright (C) 2017 Delta Networks, Inc. - * - * DNI - * - * Based on ad7414.c - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#define I2C_BUS_5 5 -#define SWPLD_U21 0x30 -#define SWPLD_A 0x33 -#define SWPLD_B 0x32 - -#define SFP_PRESENCE_1 0x02 -#define SFP_PRESENCE_2 0x03 -#define SFP_PRESENCE_3 0x04 -#define SFP_PRESENCE_4 0x05 -#define SFP_PRESENCE_5 0x06 -#define SFP_PRESENCE_6 0x07 -#define QSFP_PRESENCE_1 0x0d -#define QSFP_LP_MODE_1 0x0c -#define QSFP_RESET_1 0x0e - -#define DEFAULT_DISABLE 0x00 -#define QSFP_DEFAULT_DISABLE 0x01 -#define QSFP_SEL_I2C_MUX 0x11 -#define SFP_SEL_I2C_MUX 0x19 - - -/* Check cpld read results */ -#define VALIDATED_READ(_buf, _rv, _read, _invert) \ - do { \ - _rv = _read; \ - if (_rv < 0) { \ - return sprintf(_buf, "READ ERROR\n"); \ - } \ - if (_invert) { \ - _rv = ~_rv; \ - } \ - _rv &= 0xFF; \ - } while(0) \ - - -long sfp_port_data = 0; - -static const u8 cpld_to_port_table[] = { - 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, - 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, - 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, - 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, - 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, - 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, - 0x2f, 0x04, 0x03, 0x02, 0x00}; - -/* Addresses scanned */ -static const unsigned short normal_i2c[] = { 0x50, I2C_CLIENT_END }; - -/* Each client has this additional data */ -struct ak7448_sfp_data -{ - struct device *hwmon_dev; - struct mutex update_lock; - char valid; - unsigned long last_updated; - int port; - char eeprom[256]; -}; - -static ssize_t for_eeprom(struct device *dev, struct device_attribute *dev_attr,char *buf); -static int ak7448_sfp_read_block(struct i2c_client *client, u8 command,u8 *data, int data_len); -static struct ak7448_sfp_data *ak7448_sfp_update_device(struct device *dev); -static ssize_t for_status(struct device *dev, struct device_attribute *dev_attr, char *buf); -static ssize_t set_w_port_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count); -static ssize_t for_r_port_data(struct device *dev, struct device_attribute *dev_attr, char *buf); -static ssize_t set_w_lp_mode_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count); -static ssize_t set_w_reset_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count); - -extern int i2c_cpld_read(int bus, unsigned short cpld_addr, u8 reg); -extern int i2c_cpld_write(int bus, unsigned short cpld_addr, u8 reg, u8 value); - -enum ak7448_sfp_sysfs_attributes -{ - SFP_EEPROM, - SFP_SELECT_PORT, - SFP_IS_PRESENT, - SFP_IS_PRESENT_ALL, - SFP_LP_MODE, - SFP_RESET -}; - -static ssize_t set_w_port_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count) -{ - long data; - int error; - long port_t = 0; - u8 reg_t = 0x00; - - error = kstrtol(buf, 10, &data); - if(error) - return error; - - port_t = data; - - if(port_t > 0 && port_t < 9) - { /* SFP Port 1-8 */ - reg_t = SFP_SEL_I2C_MUX; - } - else if (port_t > 8 && port_t < 17) - { /* SFP Port 9-16 */ - reg_t = SFP_SEL_I2C_MUX; - } - else if (port_t > 16 && port_t < 25) - { /* SFP Port 17-24 */ - reg_t = SFP_SEL_I2C_MUX; - } - else if (port_t > 24 && port_t < 33) - { /* SFP Port 25-32 */ - reg_t = SFP_SEL_I2C_MUX; - } - else if (port_t > 32 && port_t < 37) - { /* SFP Port 33-36 */ - reg_t = SFP_SEL_I2C_MUX; - } - else if (port_t > 36 && port_t < 45) - { /* SFP Port 37-44 */ - reg_t = SFP_SEL_I2C_MUX; - } - else if (port_t > 44 && port_t < 49) - { /* SFP Port 45-48 */ - reg_t = SFP_SEL_I2C_MUX; - } - else if (port_t > 48 && port_t < 53) - { /* QSFP Port 49-52 */ - reg_t = QSFP_SEL_I2C_MUX; - } - else - { - /* Disable SFP channel */ - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, SFP_SEL_I2C_MUX, - DEFAULT_DISABLE) < 0) { - return -EIO; - } - - /* Disable QSFP channel */ - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, QSFP_SEL_I2C_MUX, - QSFP_DEFAULT_DISABLE) < 0) { - return -EIO; - } - - goto exit; - - } - - /* Disable SFP channel */ - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, SFP_SEL_I2C_MUX, - DEFAULT_DISABLE) < 0) { - return -EIO; - } - - /* Disable QSFP channel */ - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, QSFP_SEL_I2C_MUX, - QSFP_DEFAULT_DISABLE) < 0) { - return -EIO; - } - - /* Select SFP or QSFP port channel */ - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, reg_t, - cpld_to_port_table[port_t]) < 0) { - return -EIO; - } - -exit: - sfp_port_data = data; - return count; -} - -static ssize_t for_r_port_data(struct device *dev, struct device_attribute *dev_attr, char *buf) -{ - if (sfp_port_data == DEFAULT_DISABLE) - { - /* Disable SFP channel */ - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, - SFP_SEL_I2C_MUX, DEFAULT_DISABLE) < 0) { - return -EIO; - } - - /* Disable QSFP channel */ - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, - QSFP_SEL_I2C_MUX, QSFP_DEFAULT_DISABLE) < 0) { - return -EIO; - } - } - - return sprintf(buf, "%d\n", sfp_port_data); - -} - -static ssize_t set_w_lp_mode_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count) -{ - long data; - int error; - long port_t = 0; - int bit_t = 0x00; - int values = 0x00; - - error = kstrtol(buf, 10, &data); - if (error) - return error; - - port_t = sfp_port_data; - - if (port_t > 48 && port_t < 53) - { /* QSFP Port 48-53 */ - values = i2c_cpld_read(I2C_BUS_5, SWPLD_B, QSFP_LP_MODE_1); - if (values < 0) - return -EIO; - - /* Indicate the module is in LP mode or not - * 0 = Disable - * 1 = Enable - */ - if (data == 0) - { - bit_t = ~(1 << ((port_t - 1) % 8)); - values = values & bit_t; - } - else if (data == 1) - { - bit_t = 1 << ((port_t - 1) % 8); - values = values | bit_t; - } - else - { - return -EINVAL; - } - - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, QSFP_LP_MODE_1, - values) < 0) - { - return -EIO; - } - } - - return count; -} - -static ssize_t set_w_reset_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count) -{ - long data; - int error; - long port_t = 0; - int bit_t = 0x00; - int values = 0x00; - - error = kstrtol(buf, 10, &data); - if (error) - return error; - - port_t = sfp_port_data; - - if (port_t > 48 && port_t < 53) - { /* QSFP Port 48-53 */ - values = i2c_cpld_read(I2C_BUS_5, SWPLD_B, QSFP_RESET_1); - if (values < 0) - return -EIO; - - /* Indicate the module Reset or not - * 0 = Reset - * 1 = Normal - */ - if (data == 0) - { - bit_t = ~(1 << ((port_t - 1) % 8)); - values = values & bit_t; - } - else if (data == 1) - { - bit_t = 1 << ((port_t - 1) % 8); - values = values | bit_t; - } - else - { - return -EINVAL; - } - - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, QSFP_RESET_1, - values) < 0) - { - return -EIO; - } - } - - return count; -} - -static ssize_t for_status(struct device *dev, struct device_attribute *dev_attr, char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); - long port_t = 0; - u8 reg_t = 0x00; - u8 cpld_addr_t = 0x00; - int values[7] = {'\0'}; - int bit_t = 0x00; - - switch (attr->index) - { - case SFP_IS_PRESENT: - port_t = sfp_port_data; - - if (port_t > 0 && port_t < 9) { /* SFP Port 1-8 */ - cpld_addr_t = SWPLD_A; - reg_t = SFP_PRESENCE_1; - } else if (port_t > 8 && port_t < 17) { /* SFP Port 9-16 */ - cpld_addr_t = SWPLD_A; - reg_t = SFP_PRESENCE_2; - } else if (port_t > 16 && port_t < 25) { /* SFP Port 17-24 */ - cpld_addr_t = SWPLD_A; - reg_t = SFP_PRESENCE_3; - } else if (port_t > 24 && port_t < 33) { /* SFP Port 25-32 */ - cpld_addr_t = SWPLD_A; - reg_t = SFP_PRESENCE_4; - } else if (port_t > 32 && port_t < 41) { /* SFP Port 33-40 */ - cpld_addr_t = SWPLD_A; - reg_t = SFP_PRESENCE_5; - } else if (port_t > 40 && port_t < 49) { /* SFP Port 41-48 */ - cpld_addr_t = SWPLD_A; - reg_t = SFP_PRESENCE_6; - } else if (port_t > 48 && port_t < 53) { /* QSFP Port 49-54 */ - cpld_addr_t = SWPLD_B; - reg_t = QSFP_PRESENCE_1; - } else { - values[0] = 1; /* return 1, module NOT present */ - return sprintf(buf, "%d\n", values[0]); - } - - VALIDATED_READ(buf, values[0], i2c_cpld_read(I2C_BUS_5, - cpld_addr_t, reg_t), 0); - - - /* SWPLD QSFP module respond */ - bit_t = 1 << ((port_t - 1) % 8); - values[0] = values[0] & bit_t; - values[0] = values[0] / bit_t; - - /* sfp_is_present value - * return 0 is module present - * return 1 is module NOT present*/ - return sprintf(buf, "%d\n", values[0]); - - case SFP_IS_PRESENT_ALL: - /* - * Report the SFP ALL PRESENCE status - * This data information form CPLD. - */ - - /* SFP_PRESENT Ports 1-8 */ - VALIDATED_READ(buf, values[0], - i2c_cpld_read(I2C_BUS_5, SWPLD_A, SFP_PRESENCE_1), 0); - /* SFP_PRESENT Ports 9-16 */ - VALIDATED_READ(buf, values[1], - i2c_cpld_read(I2C_BUS_5, SWPLD_A, SFP_PRESENCE_2), 0); - /* SFP_PRESENT Ports 17-24 */ - VALIDATED_READ(buf, values[2], - i2c_cpld_read(I2C_BUS_5, SWPLD_A, SFP_PRESENCE_3), 0); - /* SFP_PRESENT Ports 25-32 */ - VALIDATED_READ(buf, values[3], - i2c_cpld_read(I2C_BUS_5, SWPLD_A, SFP_PRESENCE_4), 0); - /* SFP_PRESENT Ports 33-40 */ - VALIDATED_READ(buf, values[4], - i2c_cpld_read(I2C_BUS_5, SWPLD_A, SFP_PRESENCE_5), 0); - /* SFP_PRESENT Ports 41-48 */ - VALIDATED_READ(buf, values[5], - i2c_cpld_read(I2C_BUS_5, SWPLD_A, SFP_PRESENCE_6), 0); - /* QSFP_PRESENT Ports 49-52 */ - VALIDATED_READ(buf, values[6], - i2c_cpld_read(I2C_BUS_5, SWPLD_B, QSFP_PRESENCE_1), 0); - - - /* sfp_is_present_all value - * return 0 is module present - * return 1 is module NOT present - */ - return sprintf(buf, "%02X %02X %02X %02X %02X %02X %02X \n",values[0], values[1], values[2],values[3], values[4], values[5],values[6]); - - case SFP_LP_MODE: - - port_t = sfp_port_data; - if (port_t > 48 && port_t < 53) { - /* QSFP Port 49-52 */ - VALIDATED_READ(buf, values[0], i2c_cpld_read(I2C_BUS_5, - SWPLD_B, QSFP_LP_MODE_1), 0); - } else { - /* In AK7448 only QSFP support control LP MODE */ - values[0] = 0; - return sprintf(buf, "%d\n", values[0]); - } - - bit_t = 1 << ((port_t - 1) % 8); - values[0] = values[0] & bit_t; - values[0] = values[0] / bit_t; - - /* sfp_lp_mode value - * return 0 is module NOT in LP mode - * return 1 is module in LP mode - */ - - return sprintf(buf, "%d\n", values[0]); - - case SFP_RESET: - port_t = sfp_port_data; - if (port_t > 48 && port_t < 53) { - /* QSFP Port 49-54 */ - VALIDATED_READ(buf, values[0], i2c_cpld_read(I2C_BUS_5, - SWPLD_B, QSFP_RESET_1), 0); - } else { - /* In AK7448 only QSFP support control RESET MODE */ - values[0] = 1; - return sprintf(buf, "%d\n", values[0]); - } - - /* SWPLD QSFP module respond */ - bit_t = 1 << ((port_t - 1) % 8); - values[0] = values[0] & bit_t; - values[0] = values[0] / bit_t; - - /* sfp_reset value - * return 0 is module Reset - * return 1 is module Normal*/ - return sprintf(buf, "%d\n", values[0]); - - default: - return (attr->index); - } -} - -static ssize_t for_eeprom(struct device *dev, struct device_attribute *dev_attr,char *buf) -{ - struct ak7448_sfp_data *data = ak7448_sfp_update_device(dev); - if (!data->valid) - { - return 0; - } - memcpy(buf, data->eeprom, sizeof(data->eeprom)); - return sizeof(data->eeprom); -} - -static int ak7448_sfp_read_block(struct i2c_client *client, u8 command, u8 *data, int data_len) -{ - int result = i2c_smbus_read_i2c_block_data(client, command, data_len,data); - if (unlikely(result < 0)) - goto abort; - if (unlikely(result != data_len)) - { - result = -EIO; - goto abort; - } - result = 0; - -abort: - return result; -} - -static struct ak7448_sfp_data *ak7448_sfp_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct ak7448_sfp_data *data = i2c_get_clientdata(client); - long port_t = 0; - u8 reg_t = 0x00; - - port_t = sfp_port_data; - - - if (port_t > 0 && port_t < 9) { /* SFP Port 1-8 */ - reg_t = SFP_SEL_I2C_MUX; - } else if (port_t > 8 && port_t < 17) { /* SFP Port 9-16 */ - reg_t = SFP_SEL_I2C_MUX; - } else if (port_t > 16 && port_t < 25) { /* SFP Port 17-24 */ - reg_t = SFP_SEL_I2C_MUX; - } else if (port_t > 24 && port_t < 33) { /* SFP Port 25-32 */ - reg_t = SFP_SEL_I2C_MUX; - } else if (port_t > 32 && port_t < 41) { /* SFP Port 33-40 */ - reg_t = SFP_SEL_I2C_MUX; - } else if (port_t > 40 && port_t < 49) { /* SFP Port 41-48 */ - reg_t = SFP_SEL_I2C_MUX; - } else if (port_t > 48 && port_t < 53) { /* QSFP Port 49-52 */ - reg_t = QSFP_SEL_I2C_MUX; - } else { - memset(data->eeprom, 0, sizeof(data->eeprom)); - - /* Disable SFP channel */ - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, SFP_SEL_I2C_MUX, - DEFAULT_DISABLE) < 0) { - goto exit; - } - - /* Disable QSFP channel */ - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, QSFP_SEL_I2C_MUX, - QSFP_DEFAULT_DISABLE) < 0) { - goto exit; - } - - goto exit; - } - - /* Disable SFP channel */ - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, SFP_SEL_I2C_MUX, - DEFAULT_DISABLE) < 0) { - memset(data->eeprom, 0, sizeof(data->eeprom)); - goto exit; - } - - /* Disable QSFP channel */ - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, QSFP_SEL_I2C_MUX, - QSFP_DEFAULT_DISABLE) < 0) { - memset(data->eeprom, 0, sizeof(data->eeprom)); - goto exit; - } - - /* Select SFP or QSFP port channel */ - if (i2c_cpld_write(I2C_BUS_5, SWPLD_B, reg_t, - cpld_to_port_table[port_t]) < 0) { - memset(data->eeprom, 0, sizeof(data->eeprom)); - goto exit; - } - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated) || !data->valid) - { - int status = -1; - int i = 0; - data->valid = 0; - memset(data->eeprom, 0, sizeof(data->eeprom)); - - for (i = 0; i < sizeof(data->eeprom)/I2C_SMBUS_BLOCK_MAX; i++) - { - status = ak7448_sfp_read_block(client,i * I2C_SMBUS_BLOCK_MAX,data->eeprom + (i * I2C_SMBUS_BLOCK_MAX),I2C_SMBUS_BLOCK_MAX); - if (status < 0) - { - printk(KERN_INFO "status = %d\n", status); - dev_dbg(&client->dev,"unable to read eeprom from port(%d)\n", data->port); - - goto exit; - } - } - data->last_updated = jiffies; - data->valid = 1; - } - -exit: - mutex_unlock(&data->update_lock); - return data; -} - -/* sysfs attributes for hwmon */ -static SENSOR_DEVICE_ATTR(sfp_eeprom,S_IRUGO, for_eeprom, NULL,SFP_EEPROM); -static SENSOR_DEVICE_ATTR(sfp_select_port, S_IWUSR | S_IRUGO, for_r_port_data, set_w_port_data, SFP_SELECT_PORT); -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, for_status, NULL, SFP_IS_PRESENT); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, for_status, NULL, SFP_IS_PRESENT_ALL); -static SENSOR_DEVICE_ATTR(sfp_lp_mode,S_IWUSR | S_IRUGO, for_status, set_w_lp_mode_data, SFP_LP_MODE); -static SENSOR_DEVICE_ATTR(sfp_reset, S_IWUSR | S_IRUGO, for_status, set_w_reset_data, SFP_RESET); - -static struct attribute *ak7448_sfp_attributes[] = { - &sensor_dev_attr_sfp_eeprom.dev_attr.attr, - &sensor_dev_attr_sfp_select_port.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_lp_mode.dev_attr.attr, - &sensor_dev_attr_sfp_reset.dev_attr.attr, - NULL -}; - -static const struct attribute_group ak7448_sfp_group = { - .attrs = ak7448_sfp_attributes, -}; - -static int ak7448_sfp_probe(struct i2c_client *client, const struct i2c_device_id *id) -{ - struct ak7448_sfp_data *data; - int status; - - if (!i2c_check_functionality(client->adapter,I2C_FUNC_SMBUS_I2C_BLOCK)) - { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct ak7448_sfp_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - mutex_init(&data->update_lock); - data->port = id->driver_data; - i2c_set_clientdata(client, data); - - dev_info(&client->dev, "chip found\n"); - - status = sysfs_create_group(&client->dev.kobj, &ak7448_sfp_group); - if (status) - goto exit_sysfs_create_group; - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) - { - status = PTR_ERR(data->hwmon_dev); - goto exit_hwmon_device_register; - } - - dev_info(&client->dev, "%s: sfp '%s'\n", dev_name(data->hwmon_dev),client->name); - - return 0; - -exit_hwmon_device_register: - sysfs_remove_group(&client->dev.kobj, &ak7448_sfp_group); -exit_sysfs_create_group: - kfree(data); -exit: - return status; -} - -static int ak7448_sfp_remove(struct i2c_client *client) -{ - struct ak7448_sfp_data *data = i2c_get_clientdata(client); - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &ak7448_sfp_group); - kfree(data); - return 0; -} - -enum id_name -{ - dni_ak7448_sfp -}; - -static const struct i2c_device_id ak7448_sfp_id[] = { - { "dni_ak7448_sfp", dni_ak7448_sfp }, - {} -}; -MODULE_DEVICE_TABLE(i2c, ak7448_sfp_id); - - -static struct i2c_driver ak7448_sfp_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "dni_ak7448_sfp", - }, - .probe = ak7448_sfp_probe, - .remove = ak7448_sfp_remove, - .id_table = ak7448_sfp_id, - .address_list = normal_i2c, -}; - -static int __init ak7448_sfp_init(void) -{ - return i2c_add_driver(&ak7448_sfp_driver); -} - -static void __exit ak7448_sfp_exit(void) -{ - i2c_del_driver(&ak7448_sfp_driver); -} - -MODULE_AUTHOR("Aries Lin "); -MODULE_DESCRIPTION("ak7448 SFP Driver"); -MODULE_LICENSE("GPL"); - -module_init(ak7448_sfp_init); -module_exit(ak7448_sfp_exit); diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/fani.c b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/fani.c index dd670ef2..f484ce78 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/fani.c @@ -96,16 +96,13 @@ dni_fani_info_get_fan(int local_id, onlp_fan_info_t* info) mux_info_t mux_info; dev_info_t dev_info; - mux_info.bus = I2C_BUS_5; - mux_info.addr = CPLD_B; mux_info.offset = FAN_I2C_MUX_SEL_REG; mux_info.channel = FAN_I2C_SEL_FAN_CTRL; - mux_info.flags = DEFAULT_FLAG; dev_info.bus = I2C_BUS_7; dev_info.addr = FAN_IO_CTL; dev_info.offset = 0x00; - dev_info.flags = DEFAULT_FLAG; + dev_info.flags = ONLP_I2C_F_FORCE; sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].speed); rpm = dni_i2c_lock_read_attribute(&mux_info, fullpath); @@ -160,11 +157,8 @@ dni_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info) dev_info_t dev_info; mux_info_t mux_info; - mux_info.bus = I2C_BUS_5; - mux_info.addr = CPLD_B; mux_info.offset = PSU_I2C_MUX_SEL_REG; mux_info.channel = PSU_I2C_SEL_PSU_EEPROM; - mux_info.flags = DEFAULT_FLAG; dev_info.bus = I2C_BUS_4; dev_info.addr = PSU_EEPROM; @@ -291,11 +285,8 @@ onlp_fani_rpm_set(onlp_oid_t id, int rpm) } sprintf(data, "%d", rpm); - mux_info.bus = I2C_BUS_5; - mux_info.addr = CPLD_B; mux_info.offset = FAN_I2C_MUX_SEL_REG; mux_info.channel = FAN_I2C_SEL_FAN_CTRL; - mux_info.flags = DEFAULT_FLAG; ret = dni_i2c_lock_write_attribute(&mux_info, data, fullpath); if(ret == -1){ @@ -321,10 +312,6 @@ onlp_fani_percentage_set(onlp_oid_t id, int percentage) char fullpath[70] = {0}; mux_info_t mux_info; - mux_info.bus = I2C_BUS_5; - mux_info.addr = CPLD_B; - mux_info.flags = DEFAULT_FLAG; - VALIDATE(id); local_id = ONLP_OID_ID_GET(id); diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/ledi.c b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/ledi.c index 8a5fbf7d..98d0c2cb 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/ledi.c @@ -101,13 +101,10 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) dev_info.offset = 0x00; dev_info.flags = DEFAULT_FLAG; - mux_info.bus = I2C_BUS_5; - mux_info.addr = CPLD_B; mux_info.offset = FAN_I2C_MUX_SEL_REG; - mux_info.flags = DEFAULT_FLAG; /* Set front panel's mode of leds */ - r_data = dni_lock_cpld_read_attribute(CPLD_B_PATH,LED_REG); + r_data = dni_lock_cpld_read_attribute(CPLD_B_PLATFORM_PATH,LED_REG); if(r_data == -1){ AIM_LOG_ERROR("Unable to read front panel led status from reg\r\n"); return ONLP_STATUS_E_INTERNAL; @@ -149,7 +146,7 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) case LED_REAR_FAN_TRAY_1: dev_info.addr = FAN_TRAY; mux_info.channel = 0x02; - r_data = dni_lock_cpld_read_attribute(CPLD_B_PATH,FAN_TRAY_LED_REG); + r_data = dni_lock_cpld_read_attribute(CPLD_B_PLATFORM_PATH,FAN_TRAY_LED_REG); if(r_data == -1){ AIM_LOG_ERROR("Unable to read fan tray 1 led status from reg\r\n"); return ONLP_STATUS_E_INTERNAL; @@ -171,7 +168,7 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) case LED_REAR_FAN_TRAY_2: dev_info.addr = FAN_TRAY; mux_info.channel = 0x01; - r_data = dni_lock_cpld_read_attribute(CPLD_B_PATH,FAN_TRAY_LED_REG); + r_data = dni_lock_cpld_read_attribute(CPLD_B_PLATFORM_PATH,FAN_TRAY_LED_REG); if(r_data == -1){ AIM_LOG_ERROR("Unable to read fan tray 2 led status from reg\r\n"); return ONLP_STATUS_E_INTERNAL; @@ -194,7 +191,7 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) case LED_REAR_FAN_TRAY_3: dev_info.addr = FAN_TRAY; mux_info.channel = 0x00; - r_data = dni_lock_cpld_read_attribute(CPLD_B_PATH,FAN_TRAY_LED_REG); + r_data = dni_lock_cpld_read_attribute(CPLD_B_PLATFORM_PATH,FAN_TRAY_LED_REG); if(r_data == -1){ AIM_LOG_ERROR("Unable to read fan tray 3 led status from reg\r\n"); return ONLP_STATUS_E_INTERNAL; @@ -261,7 +258,7 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) switch(local_id) { case LED_FRONT_FAN: - front_panel_led_value = dni_lock_cpld_read_attribute(CPLD_B_PATH,LED_REG); + front_panel_led_value = dni_lock_cpld_read_attribute(CPLD_B_PLATFORM_PATH,LED_REG); if(front_panel_led_value == -1 ){ AIM_LOG_ERROR("Unable to read led(%d) status from reg\r\n",local_id); return ONLP_STATUS_E_INTERNAL; @@ -278,7 +275,7 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) front_panel_led_value = front_panel_led_value; } - if(dni_lock_cpld_write_attribute(CPLD_B_PATH,LED_REG,front_panel_led_value) != 0){ + if(dni_lock_cpld_write_attribute(CPLD_B_PLATFORM_PATH,LED_REG,front_panel_led_value) != 0){ AIM_LOG_ERROR("Unable to set led(%d) status\r\n",local_id); return ONLP_STATUS_E_INTERNAL; } @@ -286,7 +283,7 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) break; case LED_FRONT_SYS: - front_panel_led_value = dni_lock_cpld_read_attribute(CPLD_B_PATH,LED_REG); + front_panel_led_value = dni_lock_cpld_read_attribute(CPLD_B_PLATFORM_PATH,LED_REG); if(front_panel_led_value == -1 ){ AIM_LOG_ERROR("Unable to read led(%d) status from reg\r\n",local_id); return ONLP_STATUS_E_INTERNAL; @@ -306,7 +303,7 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) front_panel_led_value = front_panel_led_value; } - if(dni_lock_cpld_write_attribute(CPLD_B_PATH,LED_REG,front_panel_led_value) != 0){ + if(dni_lock_cpld_write_attribute(CPLD_B_PLATFORM_PATH,LED_REG,front_panel_led_value) != 0){ AIM_LOG_ERROR("Unable to set led(%d) status\r\n",local_id); return ONLP_STATUS_E_INTERNAL; } @@ -314,7 +311,7 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) break; case LED_FRONT_PWR: - front_panel_led_value = dni_lock_cpld_read_attribute(CPLD_B_PATH,LED_REG); + front_panel_led_value = dni_lock_cpld_read_attribute(CPLD_B_PLATFORM_PATH,LED_REG); if(front_panel_led_value == -1 ){ AIM_LOG_ERROR("Unable to read led(%d) status from reg\r\n",local_id); return ONLP_STATUS_E_INTERNAL; @@ -334,7 +331,7 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) front_panel_led_value = front_panel_led_value; } - if(dni_lock_cpld_write_attribute(CPLD_B_PATH,LED_REG,front_panel_led_value) != 0){ + if(dni_lock_cpld_write_attribute(CPLD_B_PLATFORM_PATH,LED_REG,front_panel_led_value) != 0){ AIM_LOG_ERROR("Unable to set led(%d) status\r\n",local_id); return ONLP_STATUS_E_INTERNAL; } @@ -342,7 +339,7 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) break; case LED_REAR_FAN_TRAY_1: - fan_tray_led_reg_value = dni_lock_cpld_read_attribute(CPLD_B_PATH,FAN_TRAY_LED_REG); + fan_tray_led_reg_value = dni_lock_cpld_read_attribute(CPLD_B_PLATFORM_PATH,FAN_TRAY_LED_REG); if(fan_tray_led_reg_value == -1 ){ AIM_LOG_ERROR("Unable to read led(%d) status from reg\r\n",local_id); return ONLP_STATUS_E_INTERNAL; @@ -359,7 +356,7 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) fan_tray_led_reg_value = fan_tray_led_reg_value; } - if(dni_lock_cpld_write_attribute(CPLD_B_PATH,FAN_TRAY_LED_REG,fan_tray_led_reg_value) != 0){ + if(dni_lock_cpld_write_attribute(CPLD_B_PLATFORM_PATH,FAN_TRAY_LED_REG,fan_tray_led_reg_value) != 0){ AIM_LOG_ERROR("Unable to set led(%d) status\r\n",local_id); return ONLP_STATUS_E_INTERNAL; } @@ -367,7 +364,7 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) break; case LED_REAR_FAN_TRAY_2: - fan_tray_led_reg_value = dni_lock_cpld_read_attribute(CPLD_B_PATH,FAN_TRAY_LED_REG); + fan_tray_led_reg_value = dni_lock_cpld_read_attribute(CPLD_B_PLATFORM_PATH,FAN_TRAY_LED_REG); if(fan_tray_led_reg_value == -1 ){ AIM_LOG_ERROR("Unable to read led(%d) status from reg\r\n",local_id); return ONLP_STATUS_E_INTERNAL; @@ -384,7 +381,7 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) fan_tray_led_reg_value = fan_tray_led_reg_value; } - if(dni_lock_cpld_write_attribute(CPLD_B_PATH,FAN_TRAY_LED_REG,fan_tray_led_reg_value) != 0){ + if(dni_lock_cpld_write_attribute(CPLD_B_PLATFORM_PATH,FAN_TRAY_LED_REG,fan_tray_led_reg_value) != 0){ AIM_LOG_ERROR("Unable to set led(%d) status\r\n",local_id); return ONLP_STATUS_E_INTERNAL; } @@ -392,7 +389,7 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) break; case LED_REAR_FAN_TRAY_3: - fan_tray_led_reg_value = dni_lock_cpld_read_attribute(CPLD_B_PATH,FAN_TRAY_LED_REG); + fan_tray_led_reg_value = dni_lock_cpld_read_attribute(CPLD_B_PLATFORM_PATH,FAN_TRAY_LED_REG); if(fan_tray_led_reg_value == -1 ){ AIM_LOG_ERROR("Unable to read led(%d) status from reg\r\n",local_id); return ONLP_STATUS_E_INTERNAL; @@ -409,7 +406,7 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) fan_tray_led_reg_value = fan_tray_led_reg_value; } - if(dni_lock_cpld_write_attribute(CPLD_B_PATH,FAN_TRAY_LED_REG,fan_tray_led_reg_value) != 0){ + if(dni_lock_cpld_write_attribute(CPLD_B_PLATFORM_PATH,FAN_TRAY_LED_REG,fan_tray_led_reg_value) != 0){ AIM_LOG_ERROR("Unable to set led(%d) status\r\n",local_id); return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/platform_lib.c index f2d663db..ac8e1bf0 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/platform_lib.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/platform_lib.c @@ -41,29 +41,24 @@ int dni_i2c_read_attribute_binary(char *filename, char *buffer, int buf_size, in int fd; int len; - if ((buffer == NULL) || (buf_size < 0)) - { + if ((buffer == NULL) || (buf_size < 0)) { return -1; } - if ((fd = open(filename, O_RDONLY)) == -1) - { + if ((fd = open(filename, O_RDONLY)) == -1) { return -1; } - if ((len = read(fd, buffer, buf_size)) < 0) - { + if ((len = read(fd, buffer, buf_size)) < 0) { close(fd); return -1; } - if ((close(fd) == -1)) - { + if ((close(fd) == -1)) { return -1; } - if ((len > buf_size) || (data_len != 0 && len != data_len)) - { + if ((len > buf_size) || (data_len != 0 && len != data_len)) { return -1; } @@ -93,10 +88,9 @@ int dni_i2c_lock_read( mux_info_t * mux_info, dev_info_t * dev_info) int r_data=0; pthread_mutex_lock(&mutex); - if(mux_info != NULL) - { + if(mux_info != NULL){ char cpld_path[100] = {0}; - sprintf(cpld_path, "%s/%d-%04x", PREFIX_PATH, mux_info->bus, mux_info->addr); + sprintf(cpld_path, "%s", CPLD_B_PLATFORM_PATH); dni_lock_cpld_write_attribute(cpld_path, mux_info->offset, mux_info->channel); } if(dev_info->size == 1) @@ -111,19 +105,23 @@ int dni_i2c_lock_read( mux_info_t * mux_info, dev_info_t * dev_info) int dni_i2c_lock_write( mux_info_t * mux_info, dev_info_t * dev_info) { pthread_mutex_lock(&mutex); - if(mux_info != NULL) - { + int ret; + if(mux_info != NULL){ char cpld_path[100] = {0}; - sprintf(cpld_path, "%s/%d-%04x", PREFIX_PATH, mux_info->bus, mux_info->addr); + sprintf(cpld_path, "%s", CPLD_B_PLATFORM_PATH); dni_lock_cpld_write_attribute(cpld_path, mux_info->offset, mux_info->channel); } /* Write size */ if(dev_info->size == 1) - onlp_i2c_write(dev_info->bus, dev_info->addr, dev_info->offset, 1, &dev_info->data_8, dev_info->flags); + ret = onlp_i2c_write(dev_info->bus, dev_info->addr, dev_info->offset, 1, &dev_info->data_8, dev_info->flags); else - onlp_i2c_writew(dev_info->bus, dev_info->addr, dev_info->offset, dev_info->data_16, dev_info->flags); + ret = onlp_i2c_writew(dev_info->bus, dev_info->addr, dev_info->offset, dev_info->data_16, dev_info->flags); pthread_mutex_unlock(&mutex); + if (ret != 0) + { + return -1; + } return 0; } @@ -133,18 +131,15 @@ int dni_i2c_lock_read_attribute(mux_info_t * mux_info, char * fullpath) char r_data[10] = {0}; pthread_mutex_lock(&mutex); - if(mux_info != NULL) - { + if(mux_info != NULL){ char cpld_path[100] = {0}; - sprintf(cpld_path, "%s/%d-%04x", PREFIX_PATH, mux_info->bus, mux_info->addr); + sprintf(cpld_path, "%s", CPLD_B_PLATFORM_PATH); dni_lock_cpld_write_attribute(cpld_path, mux_info->offset, mux_info->channel); } - if ((fd = open(fullpath, O_RDONLY)) == -1) - { + if ((fd = open(fullpath, O_RDONLY)) == -1){ goto ERROR; } - if ((len = read(fd, r_data, nbytes)) <= 0) - { + if ((len = read(fd, r_data, nbytes)) <= 0){ goto ERROR; } close(fd); @@ -160,21 +155,18 @@ int dni_i2c_lock_write_attribute(mux_info_t * mux_info, char * data,char * fullp { int fd, len, nbytes = 10; pthread_mutex_lock(&mutex); - if(mux_info!=NULL) - { + if(mux_info!=NULL){ char cpld_path[100] = {0}; - sprintf(cpld_path, "%s/%d-%04x", PREFIX_PATH, mux_info->bus, mux_info->addr); + sprintf(cpld_path, "%s", CPLD_B_PLATFORM_PATH); dni_lock_cpld_write_attribute(cpld_path, mux_info->offset, mux_info->channel); } /* Create output file descriptor */ fd = open(fullpath, O_WRONLY, 0644); - if (fd == -1) - { + if (fd == -1){ goto ERROR; } len = write (fd, data, (ssize_t) nbytes); - if (len != nbytes) - { + if (len != nbytes){ goto ERROR; } close(fd); @@ -201,26 +193,22 @@ int dni_lock_cpld_read_attribute(char *cpld_path, int addr) pthread_mutex_lock(&mutex1); /* Create output file descriptor */ - fd = open(cpld_addr_path, O_WRONLY, 0644); - if (fd == -1) - { + fd = open(cpld_addr_path, O_WRONLY, 0644); + if (fd == -1){ goto ERR_HANDLE; } len = write (fd, address, 2); - if (len <= 0) - { + if (len <= 0){ goto ERR_HANDLE; } close(fd); - if ((fd = open(cpld_data_path, O_RDONLY)) == -1) - { + if ((fd = open(cpld_data_path, O_RDONLY, 0644)) == -1){ goto ERR_HANDLE; } - if ((len = read(fd, r_data, nbytes)) <= 0) - { + if ((len = read(fd, r_data, nbytes)) <= 0){ goto ERR_HANDLE; } close(fd); @@ -229,7 +217,7 @@ int dni_lock_cpld_read_attribute(char *cpld_path, int addr) sscanf(r_data, "%x", &data); return data; - ERR_HANDLE: +ERR_HANDLE: close(fd); pthread_mutex_unlock(&mutex1); return -1; @@ -250,26 +238,22 @@ int dni_lock_cpld_write_attribute(char *cpld_path, int addr, int data) pthread_mutex_lock(&mutex1); /* Create output file descriptor */ fd = open(cpld_addr_path, O_WRONLY, 0644); - if (fd == -1) - { + if (fd == -1){ goto ERR_HANDLE; } len = write(fd, address, 2); - if(len <= 0) - { + if(len <= 0){ goto ERR_HANDLE; } close(fd); fd = open(cpld_data_path, O_WRONLY, 0644); - if (fd == -1) - { + if (fd == -1){ goto ERR_HANDLE; } sprintf(address, "%02x", data); len = write (fd, address, 2); - if(len <= 0) - { + if(len <= 0){ goto ERR_HANDLE; } close(fd); @@ -277,7 +261,7 @@ int dni_lock_cpld_write_attribute(char *cpld_path, int addr, int data) return 0; - ERR_HANDLE: +ERR_HANDLE: close(fd); pthread_mutex_unlock(&mutex1); return -1; @@ -288,11 +272,9 @@ int dni_fan_speed_good() { int rpm = 0, rpm1 = 0, speed_good = 0; mux_info_t mux_info; - mux_info.bus = I2C_BUS_5; - mux_info.addr = CPLD_B; + mux_info.offset = FAN_I2C_MUX_SEL_REG; mux_info.channel = FAN_I2C_SEL_FAN_CTRL; - mux_info.flags = DEFAULT_FLAG; rpm = dni_i2c_lock_read_attribute(&mux_info, FAN1_FRONT); rpm1 = dni_i2c_lock_read_attribute(&mux_info, FAN1_REAR); diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/platform_lib.h index cf0ef7a8..ddc08b92 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/platform_lib.h @@ -45,9 +45,6 @@ #define NUM_OF_PORT NUM_OF_SFP + NUM_OF_QSFP #define PREFIX_PATH "/sys/bus/i2c/devices" -#define SYS_CPLD_PATH PREFIX_PATH "/2-0031" -#define CPLD_A_PATH PREFIX_PATH "/5-0033" -#define CPLD_B_PATH PREFIX_PATH "/5-0032" #define PSU_AC_PMBUS_PREFIX PREFIX_PATH "/4-0058/" #define PSU_AC_PMBUS_NODE(node) PSU_AC_PMBUS_PREFIX#node @@ -60,16 +57,14 @@ #define FAN3_REAR PREFIX_PATH "/7-002d/fan1_input" #define IDPROM_PATH "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/i2c-2/2-0053/eeprom" -#define SFP_SELECT_PORT_PATH PREFIX_PATH "/8-0050/sfp_select_port" -#define SFP_IS_PRESENT_PATH PREFIX_PATH "/8-0050/sfp_is_present" -#define SFP_IS_PRESENT_ALL_PATH PREFIX_PATH "/8-0050/sfp_is_present_all" -#define SFP_EEPROM_PATH PREFIX_PATH "/8-0050/sfp_eeprom" +#define CPLD_B_PLATFORM_PATH "/sys/devices/platform/delta-ak7448-cpld.0" +#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" +#define SFP_SELECT_PORT_PATH "/sys/devices/platform/delta-ak7448-cpld.0/sfp_select_port" +#define SFP_IS_PRESENT_PATH "/sys/devices/platform/delta-ak7448-cpld.0/sfp_is_present" +#define SFP_IS_PRESENT_ALL_PATH "/sys/devices/platform/delta-ak7448-cpld.0/sfp_is_present_all" -#define QSFP_SELECT_PORT_PATH PREFIX_PATH "/3-0050/sfp_select_port" -#define QSFP_IS_PRESENT_PATH PREFIX_PATH "/3-0050/sfp_is_present" -#define QSFP_EEPROM_PATH PREFIX_PATH "/3-0050/sfp_eeprom" -#define QSFP_RESET_PATH PREFIX_PATH "/3-0050/sfp_reset" -#define QSFP_LP_MODE_PATH PREFIX_PATH "/3-0050/sfp_lp_mode" +#define QSFP_RESET_PATH "/sys/devices/platform/delta-ak7448-cpld.0/sfp_reset" +#define QSFP_LP_MODE_PATH "/sys/devices/platform/delta-ak7448-cpld.0/sfp_lp_mode" /* BUS define */ #define I2C_BUS_0 (0) @@ -96,7 +91,6 @@ #define QSFP_RESPOND_REG (0x0b) #define SYS_CPLD (0x31) #define CPLD_A (0x33) -#define CPLD_B (0x32) #define SYS_VERSION_REG (0x01) #define CPLD_A_VERSION_REG (0x00) #define CPLD_B_VERSION_REG (0x01) diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/psui.c b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/psui.c index ecae9b60..e894fafe 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/psui.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/psui.c @@ -151,11 +151,8 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) memset(info, 0, sizeof(onlp_psu_info_t)); *info = pinfo[index]; - mux_info.bus = I2C_BUS_5; - mux_info.addr = CPLD_B; mux_info.offset = PSU_I2C_MUX_SEL_REG; mux_info.channel = PSU_I2C_SEL_PSU_EEPROM; - mux_info.flags = DEFAULT_FLAG; dev_info.bus = I2C_BUS_4; dev_info.offset = 0x00; /* In EEPROM address 0x00 */ diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/sfpi.c b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/sfpi.c index 4c0a8dc1..cda73127 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/sfpi.c @@ -30,10 +30,18 @@ #include #include #include +#include #include #include "platform_lib.h" /******************* Utility Function *****************************************/ +int sfp_map_bus[] ={30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 72, 73, 74, 75, 76, 77, 20, 21, + 22, 23}; + int ak7448_get_respond_val(int port){ int respond_default = 0xff; @@ -65,6 +73,14 @@ onlp_sfpi_init(void){ return ONLP_STATUS_OK; } +int +onlp_sfpi_map_bus_index(int port) +{ + if(port < 0 || port > 52) + return ONLP_STATUS_E_INTERNAL; + return sfp_map_bus[port-1]; +} + int onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap){ /*Ports {1, 52}*/ @@ -82,35 +98,20 @@ onlp_sfpi_is_present(int port){ char port_data[2]; int present, present_bit; - if(port > 0 && port < 49) - { - /* Select QSFP port */ + if(port > 0 && port < 53) + { + /* Select QSFP/SFP port */ sprintf(port_data, "%d", port ); if(dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH) < 0){ AIM_LOG_ERROR("Unable to select port(%d)\r\n", port); } - /* Read SFP MODULE is present or not */ + /* Read QSFP/SFP MODULE is present or not */ present_bit = dni_i2c_lock_read_attribute(NULL, SFP_IS_PRESENT_PATH); if(present_bit < 0){ AIM_LOG_ERROR("Unable to read present or not from port(%d)\r\n", port); } } - else if(port > 48 && port < 53) - { - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, QSFP_SELECT_PORT_PATH) < 0){ - AIM_LOG_ERROR("Unable to select port(%d)\r\n", port); - } - - /* Read SFP MODULE is present or not */ - present_bit = dni_i2c_lock_read_attribute(NULL, QSFP_IS_PRESENT_PATH); - if(present_bit < 0){ - AIM_LOG_ERROR("Unable to read present or not from port(%d)\r\n", port); - } - - } /* From sfp_is_present value, * return 0 = The module is preset @@ -180,9 +181,9 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) int onlp_sfpi_eeprom_read(int port, uint8_t data[256]) { - char port_data[2]; int sfp_respond_reg; int sfp_respond_val; + int size = 0; /* Get respond register if port have it */ @@ -190,49 +191,22 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) /* Set respond val */ sfp_respond_val = ak7448_get_respond_val(port); - dni_lock_cpld_write_attribute(CPLD_B_PATH, sfp_respond_reg, sfp_respond_val); + dni_lock_cpld_write_attribute(CPLD_B_PLATFORM_PATH, sfp_respond_reg, sfp_respond_val); - if(port > 0 && port < 49) - { - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH) < 0){ - AIM_LOG_INFO("Unable to select port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } + memset(data, 0, 256); + if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, onlp_sfpi_map_bus_index(port)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; } - else if(port > 48 && port < 53) - { - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, QSFP_SELECT_PORT_PATH) < 0 ){ - AIM_LOG_INFO("Unable to select port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - } - - memset(data, 0 ,256); - /* Read eeprom information into data[] */ - if(port > 0 && port < 49) - { - if(dni_i2c_read_attribute_binary(SFP_EEPROM_PATH, (char *)data, 256, 256) != 0) - { - AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - } - else if(port > 48 && port < 53) - { - if(dni_i2c_read_attribute_binary(QSFP_EEPROM_PATH, (char *)data, 256, 256) != 0) - { - AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } + if (size != 256) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", port); + return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; + } int onlp_sfpi_port_map(int port, int* rport) @@ -248,7 +222,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) int value_t; char port_data[2]; - if(port > 0 && port < 49) + if(port > 0 && port < 53) { /* Select QSFP port */ sprintf(port_data, "%d", port ); @@ -256,17 +230,6 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) AIM_LOG_INFO("Unable to select port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } - - } - else if(port > 48 && port < 53) - { - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, QSFP_SELECT_PORT_PATH) < 0){ - AIM_LOG_INFO("Unable to select port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - } switch (control) { @@ -315,7 +278,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) int value_t; char port_data[2]; - if(port > 0 && port < 49) + if(port > 0 && port < 53) { /* Select QSFP port */ sprintf(port_data, "%d", port ); @@ -323,19 +286,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) AIM_LOG_INFO("Unable to select port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } - } - else if(port > 48 && port < 53) - { - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, QSFP_SELECT_PORT_PATH) < 0){ - AIM_LOG_INFO("Unable to select port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - - } - switch (control) { case ONLP_SFP_CONTROL_RESET_STATE: @@ -370,186 +321,51 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) int onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) { - char port_data[2]; - int sfp_respond_reg, sfp_respond_val; - dev_info_t dev_info; - - /* Get respond register if port have it */ - sfp_respond_reg = ak7448_get_respond_reg(port); - - /* Set respond val */ - sfp_respond_val = ak7448_get_respond_val(port); - dni_lock_cpld_write_attribute(CPLD_B_PATH, sfp_respond_reg, sfp_respond_val); - - if(port > 0 && port < 49) - { - dev_info.bus = I2C_BUS_8; - - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH) < 0){ - AIM_LOG_INFO("Unable to select port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - + int bus; + + bus = onlp_sfpi_map_bus_index(port); + if(devaddr == 0x51){ + addr += 256; } - else if(port > 48 && port < 53) - { - dev_info.bus = I2C_BUS_3; - - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, QSFP_SELECT_PORT_PATH) < 0){ - AIM_LOG_INFO("Unable to select port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - - } - - dev_info.addr = PORT_ADDR; - dev_info.offset = addr; - dev_info.flags = ONLP_I2C_F_FORCE; - dev_info.size = 1; /* Read 1 byte */ - - return dni_i2c_lock_read(NULL, &dev_info); + return onlp_i2c_readb(bus, devaddr, addr, ONLP_I2C_F_FORCE); } int onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) { - char port_data[2]; - int sfp_respond_reg, sfp_respond_val; - dev_info_t dev_info; + int bus; - /* Get respond register if port have it */ - sfp_respond_reg = ak7448_get_respond_reg(port); - - /* Set respond val */ - sfp_respond_val = ak7448_get_respond_val(port); - dni_lock_cpld_write_attribute(CPLD_B_PATH, sfp_respond_reg, sfp_respond_val); - - if(port > 0 && port < 49) - { - dev_info.bus = I2C_BUS_8; - - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH) < 0){ - AIM_LOG_INFO("Unable to select port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } + bus = onlp_sfpi_map_bus_index(port); + if(devaddr == 0x51){ + addr += 256; } - else if(port > 48 && port < 53) - { - dev_info.bus = I2C_BUS_3; - - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, QSFP_SELECT_PORT_PATH) < 0){ - AIM_LOG_INFO("Unable to select port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - } - - dev_info.addr = PORT_ADDR; - dev_info.offset = addr; - dev_info.flags = ONLP_I2C_F_FORCE; - dev_info.size = 1; /* Write 1 byte */ - dev_info.data_8 = value; - - return dni_i2c_lock_write(NULL, &dev_info); + + return onlp_i2c_writeb(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); + } int onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) { - char port_data[2]; - int sfp_respond_reg, sfp_respond_val; - dev_info_t dev_info; - - /* Get respond register if port have it */ - sfp_respond_reg = ak7448_get_respond_reg(port); - - /* Set respond val */ - sfp_respond_val = ak7448_get_respond_val(port); - dni_lock_cpld_write_attribute(CPLD_B_PATH, sfp_respond_reg, sfp_respond_val); - - if(port > 0 && port < 49) - { - dev_info.bus = I2C_BUS_8; - - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH) < 0){ - AIM_LOG_INFO("Unable to select port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } + int bus; + bus = onlp_sfpi_map_bus_index(port); + if(devaddr == 0x51){ + addr += 256; } - else if(port > 48 && port < 53) - { - dev_info.bus = I2C_BUS_3; - - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, QSFP_SELECT_PORT_PATH) < 0){ - AIM_LOG_INFO("Unable to select port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - } - - dev_info.addr = PORT_ADDR; - dev_info.offset = addr; - dev_info.flags = ONLP_I2C_F_FORCE; - dev_info.size = 2; /* Read 1 byte */ - - return dni_i2c_lock_read(NULL, &dev_info); + return onlp_i2c_readw(bus, devaddr, addr, ONLP_I2C_F_FORCE); } int onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value) { - char port_data[2]; - int sfp_respond_reg, sfp_respond_val; - dev_info_t dev_info; - - /* Get respond register if port have it */ - sfp_respond_reg = ak7448_get_respond_reg(port); - - /* Set respond val */ - sfp_respond_val = ak7448_get_respond_val(port); - dni_lock_cpld_write_attribute(CPLD_B_PATH, sfp_respond_reg, sfp_respond_val); - - if(port > 0 && port < 49) - { - dev_info.bus = I2C_BUS_8; - - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH) < 0){ - AIM_LOG_INFO("Unable to select port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } + int bus; + + bus = onlp_sfpi_map_bus_index(port); + if(devaddr == 0x51){ + addr += 256; } - else if(port > 48 && port < 53) - { - dev_info.bus = I2C_BUS_3; - - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, QSFP_SELECT_PORT_PATH) < 0){ - AIM_LOG_INFO("Unable to select port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - } - - dev_info.addr = PORT_ADDR; - dev_info.offset = addr; - dev_info.flags = ONLP_I2C_F_FORCE; - dev_info.size = 2; /* Write 2 byte */ - dev_info.data_16 = value; - - return dni_i2c_lock_write(NULL, &dev_info); + return onlp_i2c_writew(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); } int @@ -557,7 +373,7 @@ onlp_sfpi_control_supported(int port, onlp_sfp_control_t control, int* rv) { char port_data[2] ; - if(port > 0 && port < 49) + if(port > 0 && port < 53) { /* Select QSFP port */ sprintf(port_data, "%d", port ); @@ -566,15 +382,6 @@ onlp_sfpi_control_supported(int port, onlp_sfp_control_t control, int* rv) return ONLP_STATUS_E_INTERNAL; } } - else if(port > 48 && port < 53) - { - /* Select QSFP port */ - sprintf(port_data, "%d", port ); - if(dni_i2c_lock_write_attribute(NULL, port_data, QSFP_SELECT_PORT_PATH) < 0){ - AIM_LOG_INFO("Unable to select port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - } switch (control) { case ONLP_SFP_CONTROL_RESET_STATE: @@ -605,8 +412,6 @@ onlp_sfpi_control_supported(int port, onlp_sfp_control_t control, int* rv) return ONLP_STATUS_OK; } - - int onlp_sfpi_denit(void) { @@ -622,7 +427,30 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) int onlp_sfpi_dom_read(int port, uint8_t data[256]) { - return ONLP_STATUS_E_UNSUPPORTED; + FILE* fp; + char file[64] = {0}; + + sprintf(file, PORT_EEPROM_FORMAT, onlp_sfpi_map_bus_index(port)); + fp = fopen(file, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + if (fseek(fp, 256, SEEK_CUR) != 0) { + fclose(fp); + AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + int ret = fread(data, 1, 256, fp); + fclose(fp); + if (ret != 256) { + AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; } int diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/sysi.c b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/sysi.c index 22d687ba..a363554d 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/sysi.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/sysi.c @@ -55,33 +55,27 @@ decide_percentage(int *percentage, int temper) { int level; - if(temper <= 50) - { + if(temper <= 50){ *percentage = 50; level = 1; } - else if(temper > 50 && temper <= 55) - { + else if(temper > 50 && temper <= 55){ *percentage = 58; level = 2; } - else if(temper > 55 && temper <= 60) - { + else if(temper > 55 && temper <= 60){ *percentage = 65; level = 3; } - else if(temper > 60 && temper <= 65) - { + else if(temper > 60 && temper <= 65){ *percentage = 80; level = 4; } - else if(temper > 65) - { + else if(temper > 65){ *percentage = 100; level = 5; } - else - { + else{ *percentage = 100; level = 6; } @@ -117,11 +111,24 @@ onlp_sysi_onie_data_free(uint8_t* data) int onlp_sysi_platform_info_get(onlp_platform_info_t* pi) { + dev_info_t dev_info; int sys_cpld_version = 0, cpld_a_version = 0, cpld_b_version = 0; - sys_cpld_version = dni_lock_cpld_read_attribute(SYS_CPLD_PATH,SYS_VERSION_REG); - cpld_a_version = dni_lock_cpld_read_attribute(CPLD_A_PATH,CPLD_A_VERSION_REG); - cpld_b_version = (dni_lock_cpld_read_attribute(CPLD_B_PATH,CPLD_B_VERSION_REG) & 0x7); + dev_info.bus = I2C_BUS_5; + dev_info.addr = CPLD_A; + dev_info.offset = CPLD_A_VERSION_REG; + dev_info.size = 1; + dev_info.flags = ONLP_I2C_F_FORCE; + cpld_a_version = dni_i2c_lock_read(NULL, &dev_info); + + dev_info.bus = I2C_BUS_2; + dev_info.addr = SYS_CPLD; + dev_info.offset = SYS_VERSION_REG; + dev_info.size = 1; + dev_info.flags = DEFAULT_FLAG; + sys_cpld_version = dni_i2c_lock_read(NULL, &dev_info); + + cpld_b_version = (dni_lock_cpld_read_attribute(CPLD_B_PLATFORM_PATH,CPLD_B_VERSION_REG) & 0x7); pi->cpld_versions = aim_fstrdup("SYSTEM-CPLD = %d, CPLD-A = %d, CPLD-B = %d", sys_cpld_version, cpld_a_version, cpld_b_version); @@ -245,10 +252,7 @@ onlp_sysi_platform_manage_leds(void) mux_info_t mux_info; dev_info_t dev_info; - mux_info.bus = I2C_BUS_5; - mux_info.addr = CPLD_B; mux_info.offset = FAN_I2C_MUX_SEL_REG; - mux_info.flags = DEFAULT_FLAG; dev_info.bus = I2C_BUS_7; dev_info.offset = 0x00; @@ -343,11 +347,8 @@ onlp_sysi_platform_manage_leds(void) } /* Set front light of PWR */ - mux_info.bus = I2C_BUS_5; - mux_info.addr = CPLD_B; mux_info.offset = PSU_I2C_MUX_SEL_REG; mux_info.channel = PSU_I2C_SEL_PSU_EEPROM; - mux_info.flags = DEFAULT_FLAG; dev_info.bus = I2C_BUS_4; dev_info.offset = 0x00; diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/thermali.c b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/thermali.c index fdf24864..5e4494be 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/thermali.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/onlp/builds/src/module/src/thermali.c @@ -154,11 +154,8 @@ onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) return ONLP_STATUS_E_INVALID; } - mux_info.bus = I2C_BUS_5; - mux_info.addr = CPLD_B; mux_info.offset = offset; mux_info.channel = channel; - mux_info.flags = DEFAULT_FLAG; sprintf(fullpath, "%s%s", PREFIX_PATH, last_path[local_id]); diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/platform-config/r0/src/python/x86_64_delta_ak7448_r0/__init__.py b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/platform-config/r0/src/python/x86_64_delta_ak7448_r0/__init__.py index 82527b9d..ff2bdfb6 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-ak7448/platform-config/r0/src/python/x86_64_delta_ak7448_r0/__init__.py +++ b/packages/platforms/delta/x86-64/x86-64-delta-ak7448/platform-config/r0/src/python/x86_64_delta_ak7448_r0/__init__.py @@ -11,25 +11,22 @@ class OnlPlatform_x86_64_delta_ak7448_r0(OnlPlatformDelta, #PCA9548 modulize self.new_i2c_device('pca9547', 0x71, 1) - #Insert cpld module - self.insmod('i2c_cpld') - self.new_i2c_device('cpld', 0x31, 2) - self.new_i2c_device('cpld', 0x33, 5) - self.new_i2c_device('cpld', 0x32, 5) + self.insmod('optoe') + self.insmod('delta_ak7448_platform') #IDEEPROM modulize self.new_i2c_device('24c02', 0x53, 2) #Insert psu module self.insmod('dni_ak7448_psu') - os.system("echo 0x04 > /sys/bus/i2c/devices/5-0032/addr") - os.system("echo 0x02 > /sys/bus/i2c/devices/5-0032/data") + os.system("echo 0x04 > /sys/devices/platform/delta-ak7448-cpld.0/addr") + os.system("echo 0x02 > /sys/devices/platform/delta-ak7448-cpld.0/data") self.new_i2c_device('dni_ak7448_psu', 0x58, 4) #Insert fan module self.insmod('dni_emc2305') - os.system("echo 0x0a > /sys/bus/i2c/devices/5-0032/addr") - os.system("echo 0x05 > /sys/bus/i2c/devices/5-0032/data") + os.system("echo 0x0a > /sys/devices/platform/delta-ak7448-cpld.0/addr") + os.system("echo 0x05 > /sys/devices/platform/delta-ak7448-cpld.0/data") self.new_i2c_device('emc2305', 0x2c, 7) self.new_i2c_device('emc2305', 0x2d, 7) @@ -38,23 +35,27 @@ class OnlPlatform_x86_64_delta_ak7448_r0(OnlPlatformDelta, self.new_i2c_device('tmp75', 0x4c, 6) self.new_i2c_device('tmp75', 0x4d, 6) self.new_i2c_device('tmp75', 0x4e, 6) - os.system("echo 0x0a > /sys/bus/i2c/devices/5-0032/addr") - os.system("echo 0x06 > /sys/bus/i2c/devices/5-0032/data") + os.system("echo 0x0a > /sys/devices/platform/delta-ak7448-cpld.0/addr") + os.system("echo 0x06 > /sys/devices/platform/delta-ak7448-cpld.0/data") self.new_i2c_device('tmp75', 0x4f, 7) - #Insert sfp module - self.insmod('dni_ak7448_sfp') - self.new_i2c_device('dni_ak7448_sfp', 0x50, 3) - self.new_i2c_device('dni_ak7448_sfp', 0x50, 8) - #Set front panel sys light - os.system("echo 0x09 > /sys/bus/i2c/devices/5-0032/addr") - os.system("echo 0x03 > /sys/bus/i2c/devices/5-0032/data") + os.system("echo 0x09 > /sys/devices/platform/delta-ak7448-cpld.0/addr") + os.system("echo 0x03 > /sys/devices/platform/delta-ak7448-cpld.0/data") #Set thermal Thigh & Tlow os.system("echo 80000 > /sys/class/hwmon/hwmon6/temp1_max") os.system("echo 75000 > /sys/class/hwmon/hwmon6/temp1_max_hyst") + #Set SFP port name + for port in range(1, 49): + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+29), shell=True) + + #Set QSFP port name + for port in range(49, 53): + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port-29), shell=True) + + return True