From a9a182b7b404507b2638406073b5f4a4396c756c Mon Sep 17 00:00:00 2001 From: Fuzail Khan Date: Thu, 16 Dec 2021 00:12:03 -0800 Subject: [PATCH 1/3] Update PDDF kernel modules with 5.10 kernel and fix some compilation warnings --- platform/pddf/i2c/Makefile | 2 +- platform/pddf/i2c/debian/rules | 8 +- platform/pddf/i2c/modules/Makefile | 2 +- platform/pddf/i2c/modules/cpld/Makefile | 6 +- .../modules/cpld/driver/pddf_cpld_driver.c | 61 +++- .../pddf/i2c/modules/cpld/pddf_cpld_module.c | 19 +- platform/pddf/i2c/modules/cpldmux/Makefile | 6 +- .../cpldmux/driver/pddf_cpldmux_driver.c | 1 - platform/pddf/i2c/modules/fan/Makefile | 6 +- .../i2c/modules/fan/driver/pddf_fan_api.c | 49 ++- .../i2c/modules/fan/driver/pddf_fan_driver.c | 2 +- .../pddf/i2c/modules/fan/pddf_fan_module.c | 4 +- platform/pddf/i2c/modules/gpio/Makefile | 2 +- .../pddf/i2c/modules/gpio/pddf_gpio_module.c | 4 +- .../pddf/i2c/modules/include/pddf_cpld_defs.h | 1 + .../pddf/i2c/modules/include/pddf_mux_defs.h | 2 - .../pddf/i2c/modules/include/pddf_xcvr_defs.h | 4 +- platform/pddf/i2c/modules/led/Makefile | 2 +- platform/pddf/i2c/modules/mux/Makefile | 2 +- .../pddf/i2c/modules/mux/pddf_mux_module.c | 83 ++--- platform/pddf/i2c/modules/psu/Makefile | 6 +- .../i2c/modules/psu/driver/pddf_psu_api.c | 12 +- .../i2c/modules/psu/driver/pddf_psu_driver.c | 2 +- .../pddf/i2c/modules/psu/pddf_psu_module.c | 4 +- platform/pddf/i2c/modules/sysstatus/Makefile | 2 +- platform/pddf/i2c/modules/xcvr/Makefile | 6 +- .../i2c/modules/xcvr/driver/pddf_xcvr_api.c | 311 ++++++++---------- .../modules/xcvr/driver/pddf_xcvr_driver.c | 2 +- .../pddf/i2c/modules/xcvr/pddf_xcvr_module.c | 8 +- 29 files changed, 315 insertions(+), 304 deletions(-) diff --git a/platform/pddf/i2c/Makefile b/platform/pddf/i2c/Makefile index 1486370b5005..092c11539723 100644 --- a/platform/pddf/i2c/Makefile +++ b/platform/pddf/i2c/Makefile @@ -1 +1 @@ -subdir-m := modules +obj-m := modules/ diff --git a/platform/pddf/i2c/debian/rules b/platform/pddf/i2c/debian/rules index 45a58fb9b570..0afdb8667d08 100755 --- a/platform/pddf/i2c/debian/rules +++ b/platform/pddf/i2c/debian/rules @@ -18,7 +18,7 @@ PACKAGE_PRE_NAME := sonic-platform-pddf KVERSION ?= $(shell uname -r) KERNEL_SRC := /lib/modules/$(KVERSION) MOD_SRC_DIR:= $(shell pwd) -MODULE_DIRS:= client cpld cpld/driver cpldmux cpldmux/driver fan fan/driver fan/vendor_api mux gpio led psu psu/driver sysstatus xcvr xcvr/driver +MODULE_DIRS:= client cpld cpld/driver cpldmux cpldmux/driver fan fan/driver mux gpio led psu psu/driver sysstatus xcvr xcvr/driver MODULE_DIR:= modules UTILS_DIR := utils SERVICE_DIR := service @@ -35,8 +35,10 @@ clean: make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR) clean build: + set -e; \ make modules -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR); \ $(PYTHON) $(MOD_SRC_DIR)/setup.py build; \ + set +e binary: binary-arch binary-indep # Nothing to do @@ -50,11 +52,13 @@ binary-indep: dh_installdirs -p$(PACKAGE_PRE_NAME) $(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ dh_installdirs -p$(PACKAGE_PRE_NAME) usr/local/bin; \ # Custom package commands + set -e; \ (for mod in $(MODULE_DIRS); do \ cp $(MOD_SRC_DIR)/$(MODULE_DIR)/$${mod}/*.ko debian/$(PACKAGE_PRE_NAME)/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ done) ; \ cp -r $(MOD_SRC_DIR)/$(UTILS_DIR)/* debian/$(PACKAGE_PRE_NAME)/usr/local/bin/; \ - $(PYTHON) $(MOD_SRC_DIR)/setup.py install --root=$(MOD_SRC_DIR)/debian/$(PACKAGE_PRE_NAME) --install-layout=deb; + $(PYTHON) $(MOD_SRC_DIR)/setup.py install --root=$(MOD_SRC_DIR)/debian/$(PACKAGE_PRE_NAME) --install-layout=deb; \ + set +e # Resuming debhelper scripts dh_testroot diff --git a/platform/pddf/i2c/modules/Makefile b/platform/pddf/i2c/modules/Makefile index 67d3726c3202..ebfce193c273 100644 --- a/platform/pddf/i2c/modules/Makefile +++ b/platform/pddf/i2c/modules/Makefile @@ -1 +1 @@ -subdir-m := client cpld cpldmux xcvr mux gpio psu fan led sysstatus +obj-m := client/ cpld/ cpldmux/ xcvr/ mux/ gpio/ psu/ fan/ led/ sysstatus/ diff --git a/platform/pddf/i2c/modules/cpld/Makefile b/platform/pddf/i2c/modules/cpld/Makefile index c6182ef4f93d..2ed1697c8e24 100644 --- a/platform/pddf/i2c/modules/cpld/Makefile +++ b/platform/pddf/i2c/modules/cpld/Makefile @@ -1,4 +1,4 @@ -subdir-m := driver -obj-m := pddf_cpld_module.o +obj-m := driver/ +obj-m += pddf_cpld_module.o -CFLAGS_$(obj-m):= -I$(M)/modules/include +ccflags-y:= -I$(M)/modules/include diff --git a/platform/pddf/i2c/modules/cpld/driver/pddf_cpld_driver.c b/platform/pddf/i2c/modules/cpld/driver/pddf_cpld_driver.c index a34c370b9af1..dabc8f9d8f9c 100755 --- a/platform/pddf/i2c/modules/cpld/driver/pddf_cpld_driver.c +++ b/platform/pddf/i2c/modules/cpld/driver/pddf_cpld_driver.c @@ -30,9 +30,58 @@ static struct mutex list_lock; struct cpld_client_node { struct i2c_client *client; + char name[CPLD_CLIENT_NAME_LEN]; struct list_head list; }; +int board_i2c_cpld_read_new(unsigned short cpld_addr, char *name, u8 reg) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EPERM; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if ((cpld_node->client->addr == cpld_addr) && (strncmp(cpld_node->name, name, strlen(name)) == 0)) { + ret = i2c_smbus_read_byte_data(cpld_node->client, reg); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(board_i2c_cpld_read_new); + +int board_i2c_cpld_write_new(unsigned short cpld_addr, char *name, u8 reg, u8 value) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EIO; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if ((cpld_node->client->addr == cpld_addr) && (strncmp(cpld_node->name, name, strlen(name)) == 0)){ + ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(board_i2c_cpld_write_new); + int board_i2c_cpld_read(unsigned short cpld_addr, u8 reg) { struct list_head *list_node = NULL; @@ -128,7 +177,9 @@ static void board_i2c_cpld_add_client(struct i2c_client *client) } node->client = client; - + strcpy(node->name, (char *)client->dev.platform_data); + dev_dbg(&client->dev, "Adding %s to the cpld client list\n", node->name); + mutex_lock(&list_lock); list_add(&node->list, &cpld_client_list); mutex_unlock(&list_lock); @@ -188,8 +239,14 @@ static int board_i2c_cpld_probe(struct i2c_client *client, static int board_i2c_cpld_remove(struct i2c_client *client) { - sysfs_remove_group(&client->dev.kobj, &cpld_attribute_group); + /* Platform data is just a char string */ + char *platdata = (char *)client->dev.platform_data; + sysfs_remove_group(&client->dev.kobj, &cpld_attribute_group); board_i2c_cpld_remove_client(client); + if (platdata) + { + kfree(platdata); + } return 0; } diff --git a/platform/pddf/i2c/modules/cpld/pddf_cpld_module.c b/platform/pddf/i2c/modules/cpld/pddf_cpld_module.c index 156ab9644c6c..4a933069e6d8 100644 --- a/platform/pddf/i2c/modules/cpld/pddf_cpld_module.c +++ b/platform/pddf/i2c/modules/cpld/pddf_cpld_module.c @@ -37,7 +37,7 @@ EXPORT_SYMBOL(pddf_cpld_data); static ssize_t do_device_operation(struct device *dev, struct device_attribute *da, const char *buf, size_t count); static ssize_t store_pddf_cpld_data(struct device *dev, struct device_attribute *da, const char *buf, size_t count); -ssize_t show_pddf_cpld_data(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t show_pddf_cpld_data(struct device *dev, struct device_attribute *da, char *buf); extern void *get_device_table(char *name); extern void delete_device_table(char *name); @@ -77,9 +77,8 @@ static ssize_t store_pddf_cpld_data(struct device *dev, struct device_attribute return count; } -EXPORT_SYMBOL(store_pddf_cpld_data); -ssize_t show_pddf_cpld_data(struct device *dev, struct device_attribute *da, char *buf) +static ssize_t show_pddf_cpld_data(struct device *dev, struct device_attribute *da, char *buf) { int ret = 0; PDDF_ATTR *ptr = (PDDF_ATTR *)da; @@ -91,7 +90,6 @@ ssize_t show_pddf_cpld_data(struct device *dev, struct device_attribute *da, cha return ret; } -EXPORT_SYMBOL(show_pddf_cpld_data); static ssize_t do_device_operation(struct device *dev, struct device_attribute *da, const char *buf, size_t count) { @@ -100,6 +98,7 @@ static ssize_t do_device_operation(struct device *dev, struct device_attribute * struct i2c_adapter *adapter; static struct i2c_board_info board_info; struct i2c_client *client_ptr; + char *pddf_cpld_name = NULL; if (strncmp(buf, "add", strlen(buf)-1)==0) { @@ -107,17 +106,19 @@ static ssize_t do_device_operation(struct device *dev, struct device_attribute * if (strncmp(device_ptr->dev_type, "i2c_cpld", strlen("i2c_cpld"))==0) { + pddf_cpld_name = (char *)kzalloc(CPLD_CLIENT_NAME_LEN, GFP_KERNEL); + if (pddf_cpld_name != NULL) strcpy(pddf_cpld_name, device_ptr->i2c_name); + board_info = (struct i2c_board_info) { - .platform_data = (void *)NULL, + .platform_data = (void *)pddf_cpld_name, }; board_info.addr = device_ptr->dev_addr; strcpy(board_info.type, device_ptr->dev_type); - /*pddf_dbg(KERN_ERR "Creating a client %s on 0x%x, platform_data 0x%x\n", board_info.type, board_info.addr, board_info.platform_data);*/ client_ptr = i2c_new_client_device(adapter, &board_info); - if (client_ptr != NULL) { + if (!IS_ERR(client_ptr)) { i2c_put_adapter(adapter); pddf_dbg(CPLD, KERN_ERR "Created %s client: 0x%p\n", device_ptr->i2c_name, (void *)client_ptr); add_device_table(device_ptr->i2c_name, (void*)client_ptr); @@ -152,8 +153,12 @@ static ssize_t do_device_operation(struct device *dev, struct device_attribute * { printk(KERN_ERR "PDDF_ERROR: %s: Invalid value for dev_ops %s", __FUNCTION__, buf); } + goto clear_data; free_data: + if (board_info.platform_data) + kfree(board_info.platform_data); +clear_data: /*TODO: free the device_ptr->data is dynamically allocated*/ memset(device_ptr, 0 , sizeof(NEW_DEV_ATTR)); diff --git a/platform/pddf/i2c/modules/cpldmux/Makefile b/platform/pddf/i2c/modules/cpldmux/Makefile index 53816b98f750..518f225fdd3a 100644 --- a/platform/pddf/i2c/modules/cpldmux/Makefile +++ b/platform/pddf/i2c/modules/cpldmux/Makefile @@ -1,4 +1,4 @@ -subdir-m := driver -obj-m := pddf_cpldmux_module.o +obj-m := driver/ +obj-m += pddf_cpldmux_module.o -CFLAGS_$(obj-m):= -I$(M)/modules/include +ccflags-y:= -I$(M)/modules/include diff --git a/platform/pddf/i2c/modules/cpldmux/driver/pddf_cpldmux_driver.c b/platform/pddf/i2c/modules/cpldmux/driver/pddf_cpldmux_driver.c index c9df1a60c1af..2c914b92b1b0 100755 --- a/platform/pddf/i2c/modules/cpldmux/driver/pddf_cpldmux_driver.c +++ b/platform/pddf/i2c/modules/cpldmux/driver/pddf_cpldmux_driver.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include "pddf_client_defs.h" diff --git a/platform/pddf/i2c/modules/fan/Makefile b/platform/pddf/i2c/modules/fan/Makefile index 94b6b146c51d..acd0bf5f411b 100644 --- a/platform/pddf/i2c/modules/fan/Makefile +++ b/platform/pddf/i2c/modules/fan/Makefile @@ -1,4 +1,4 @@ -subdir-m := driver -obj-m := pddf_fan_module.o +obj-m := driver/ +obj-m += pddf_fan_module.o -CFLAGS_$(obj-m):= -I$(M)/modules/include +ccflags-y:= -I$(M)/modules/include diff --git a/platform/pddf/i2c/modules/fan/driver/pddf_fan_api.c b/platform/pddf/i2c/modules/fan/driver/pddf_fan_api.c index 167b0e183315..0fecee963ed2 100644 --- a/platform/pddf/i2c/modules/fan/driver/pddf_fan_api.c +++ b/platform/pddf/i2c/modules/fan/driver/pddf_fan_api.c @@ -64,20 +64,20 @@ int fan_update_hw(struct device *dev, struct fan_attr_info *info, FAN_DATA_ATTR { status = (sysfs_attr_data->pre_set)(client, udata, info); if (status!=0) - printk(KERN_ERR "%s: pre_set function fails for %s attribute\n", __FUNCTION__, udata->aname); + dev_warn(&client->dev, "%s: pre_set function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status); } if (sysfs_attr_data->do_set != NULL) { status = (sysfs_attr_data->do_set)(client, udata, info); if (status!=0) - printk(KERN_ERR "%s: do_set function fails for %s attribute\n", __FUNCTION__, udata->aname); + dev_warn(&client->dev, "%s: do_set function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status); } if (sysfs_attr_data->post_set != NULL) { status = (sysfs_attr_data->post_set)(client, udata, info); if (status!=0) - printk(KERN_ERR "%s: post_set function fails for %s attribute\n", __FUNCTION__, udata->aname); + dev_warn(&client->dev, "%s: post_set function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status); } mutex_unlock(&info->update_lock); @@ -104,20 +104,20 @@ int fan_update_attr(struct device *dev, struct fan_attr_info *info, FAN_DATA_ATT { status = (sysfs_attr_data->pre_get)(client, udata, info); if (status!=0) - printk(KERN_ERR "%s: pre_get function fails for %s attribute\n", __FUNCTION__, udata->aname); + dev_warn(&client->dev, "%s: pre_get function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status); } if (sysfs_attr_data->do_get != NULL) { status = (sysfs_attr_data->do_get)(client, udata, info); if (status!=0) - printk(KERN_ERR "%s: do_get function fails for %s attribute\n", __FUNCTION__, udata->aname); + dev_warn(&client->dev, "%s: do_get function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status); } if (sysfs_attr_data->post_get != NULL) { status = (sysfs_attr_data->post_get)(client, udata, info); if (status!=0) - printk(KERN_ERR "%s: post_get function fails for %s attribute\n", __FUNCTION__, udata->aname); + dev_warn(&client->dev, "%s: post_get function fails for %s attribute.ret %d\n", __FUNCTION__, udata->aname, status); } @@ -346,7 +346,10 @@ int sonic_i2c_get_fan_present_default(void *client, FAN_DATA_ATTR *udata, void * val = i2c_smbus_read_byte_data((struct i2c_client *)client, udata->offset); } - painfo->val.intval = ((val & udata->mask) == udata->cmpval); + if (val < 0) + status = val; + else + painfo->val.intval = ((val & udata->mask) == udata->cmpval); return status; @@ -355,7 +358,7 @@ int sonic_i2c_get_fan_present_default(void *client, FAN_DATA_ATTR *udata, void * int sonic_i2c_get_fan_rpm_default(void *client, FAN_DATA_ATTR *udata, void *info) { int status = 0; - uint32_t val = 0; + int val = 0; struct fan_attr_info *painfo = (struct fan_attr_info *)info; if (strcmp(udata->devtype, "cpld") == 0) @@ -375,10 +378,15 @@ int sonic_i2c_get_fan_rpm_default(void *client, FAN_DATA_ATTR *udata, void *info } } - if (udata->is_divisor) - painfo->val.intval = udata->mult / (val >> 3); + if (val < 0) + status = val; else - painfo->val.intval = udata->mult * val; + { + if (udata->is_divisor) + painfo->val.intval = udata->mult / (val >> 3); + else + painfo->val.intval = udata->mult * val; + } return status; } @@ -471,7 +479,7 @@ int sonic_i2c_set_fan_pwm_default(struct i2c_client *client, FAN_DATA_ATTR *udat int sonic_i2c_get_fan_pwm_default(void *client, FAN_DATA_ATTR *udata, void *info) { int status = 0; - uint32_t val = 0; + int val = 0; struct fan_attr_info *painfo = (struct fan_attr_info *)info; if (strcmp(udata->devtype, "cpld") == 0) @@ -491,15 +499,20 @@ int sonic_i2c_get_fan_pwm_default(void *client, FAN_DATA_ATTR *udata, void *info } } - val = val & udata->mask; - painfo->val.intval = val; + if (val < 0) + status = val; + else + { + val = val & udata->mask; + painfo->val.intval = val; + } return status; } int sonic_i2c_get_fan_fault_default(void *client, FAN_DATA_ATTR *udata, void *info) { int status = 0; - uint32_t val = 0; + int val = 0; struct fan_attr_info *painfo = (struct fan_attr_info *)info; /*Assuming fan fault to be denoted by 1 byte only*/ @@ -512,8 +525,10 @@ int sonic_i2c_get_fan_fault_default(void *client, FAN_DATA_ATTR *udata, void *in val = i2c_smbus_read_byte_data((struct i2c_client *)client, udata->offset); } - val = val & udata->mask; - painfo->val.intval = val; + if (val < 0) + status = val; + else + painfo->val.intval = ((val & udata->mask) == udata->cmpval); return status; } diff --git a/platform/pddf/i2c/modules/fan/driver/pddf_fan_driver.c b/platform/pddf/i2c/modules/fan/driver/pddf_fan_driver.c index da8275fccd64..45105f8707a9 100644 --- a/platform/pddf/i2c/modules/fan/driver/pddf_fan_driver.c +++ b/platform/pddf/i2c/modules/fan/driver/pddf_fan_driver.c @@ -357,7 +357,7 @@ static int pddf_fan_probe(struct i2c_client *client, goto exit_free; } - data->hwmon_dev = hwmon_device_register(&client->dev); + data->hwmon_dev = hwmon_device_register_with_info(&client->dev, client->name, NULL, NULL, NULL); if (IS_ERR(data->hwmon_dev)) { status = PTR_ERR(data->hwmon_dev); goto exit_remove; diff --git a/platform/pddf/i2c/modules/fan/pddf_fan_module.c b/platform/pddf/i2c/modules/fan/pddf_fan_module.c index b910d6b4a351..1c31fb920c04 100644 --- a/platform/pddf/i2c/modules/fan/pddf_fan_module.c +++ b/platform/pddf/i2c/modules/fan/pddf_fan_module.c @@ -159,9 +159,9 @@ static ssize_t do_device_operation(struct device *dev, struct device_attribute * board_info = i2c_get_fan_board_info(fdata, cdata); /* Populate the platform data for fan */ - client_ptr = i2c_new_device(adapter, board_info); + client_ptr = i2c_new_client_device(adapter, board_info); - if(client_ptr != NULL) + if(!IS_ERR(client_ptr)) { i2c_put_adapter(adapter); pddf_dbg(FAN, KERN_ERR "Created a %s client: 0x%p\n", cdata->i2c_name, (void *)client_ptr); diff --git a/platform/pddf/i2c/modules/gpio/Makefile b/platform/pddf/i2c/modules/gpio/Makefile index 6d48c5884731..c5e69ac7c1ff 100644 --- a/platform/pddf/i2c/modules/gpio/Makefile +++ b/platform/pddf/i2c/modules/gpio/Makefile @@ -1,4 +1,4 @@ obj-m := pddf_gpio_module.o -CFLAGS_$(obj-m):= -I$(M)/modules/include +ccflags-y := -I$(M)/modules/include diff --git a/platform/pddf/i2c/modules/gpio/pddf_gpio_module.c b/platform/pddf/i2c/modules/gpio/pddf_gpio_module.c index afd37c3927df..30eec5f185f4 100644 --- a/platform/pddf/i2c/modules/gpio/pddf_gpio_module.c +++ b/platform/pddf/i2c/modules/gpio/pddf_gpio_module.c @@ -119,10 +119,10 @@ static ssize_t do_device_operation(struct device *dev, struct device_attribute * board_info = i2c_get_gpio_board_info(gpio_ptr, device_ptr); /*pddf_dbg(KERN_ERR "Creating a client %s on 0x%x, platform_data 0x%x\n", board_info->type, board_info->addr, board_info->platform_data);*/ - client_ptr = i2c_new_device(adapter, board_info); + client_ptr = i2c_new_client_device(adapter, board_info); i2c_put_adapter(adapter); - if (client_ptr != NULL) + if (!IS_ERR(client_ptr)) { pddf_dbg(GPIO, KERN_ERR "Created %s client: 0x%p\n", device_ptr->i2c_name, (void *)client_ptr); add_device_table(device_ptr->i2c_name, (void*)client_ptr); diff --git a/platform/pddf/i2c/modules/include/pddf_cpld_defs.h b/platform/pddf/i2c/modules/include/pddf_cpld_defs.h index c312f3277f75..23b8505e666a 100644 --- a/platform/pddf/i2c/modules/include/pddf_cpld_defs.h +++ b/platform/pddf/i2c/modules/include/pddf_cpld_defs.h @@ -20,6 +20,7 @@ #ifndef __PDDF_CPLD_DEFS_H__ #define __PDDF_CPLD_DEFS_H__ +#define CPLD_CLIENT_NAME_LEN 32 /* CPLD DATA - DATA FOR CPLD CLIENT READ/WRITE*/ typedef struct CPLD_DATA { diff --git a/platform/pddf/i2c/modules/include/pddf_mux_defs.h b/platform/pddf/i2c/modules/include/pddf_mux_defs.h index c58a00e972c6..f10cb25e50c4 100644 --- a/platform/pddf/i2c/modules/include/pddf_mux_defs.h +++ b/platform/pddf/i2c/modules/include/pddf_mux_defs.h @@ -20,8 +20,6 @@ #ifndef __PAL_MUX_DEFS_H__ #define __PAL_MUX_DEFS_H__ -#include - /* MUX CLIENT DATA - PLATFORM DATA FOR PSU CLIENT */ typedef struct MUX_DATA { diff --git a/platform/pddf/i2c/modules/include/pddf_xcvr_defs.h b/platform/pddf/i2c/modules/include/pddf_xcvr_defs.h index 63de2eeae0c2..585ce8cc7334 100644 --- a/platform/pddf/i2c/modules/include/pddf_xcvr_defs.h +++ b/platform/pddf/i2c/modules/include/pddf_xcvr_defs.h @@ -115,7 +115,7 @@ enum xcvr_sysfs_attributes { XCVR_ATTR_MAX }; -extern int board_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int board_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); +extern int board_i2c_cpld_read_new(unsigned short cpld_addr, char *name, u8 reg); +extern int board_i2c_cpld_write_new(unsigned short cpld_addr, char *name, u8 reg, u8 value); #endif diff --git a/platform/pddf/i2c/modules/led/Makefile b/platform/pddf/i2c/modules/led/Makefile index 0c450ec70b4c..4bb36f9b5311 100644 --- a/platform/pddf/i2c/modules/led/Makefile +++ b/platform/pddf/i2c/modules/led/Makefile @@ -1,4 +1,4 @@ TARGET := pddf_led_module obj-m := $(TARGET).o -CFLAGS_$(obj-m):= -I$(M)/modules/include +ccflags-y := -I$(M)/modules/include diff --git a/platform/pddf/i2c/modules/mux/Makefile b/platform/pddf/i2c/modules/mux/Makefile index 486e7033435f..85502608cbdd 100644 --- a/platform/pddf/i2c/modules/mux/Makefile +++ b/platform/pddf/i2c/modules/mux/Makefile @@ -1,4 +1,4 @@ obj-m := pddf_mux_module.o -CFLAGS_$(obj-m):= -I$(M)/modules/include +ccflags-y := -I$(M)/modules/include diff --git a/platform/pddf/i2c/modules/mux/pddf_mux_module.c b/platform/pddf/i2c/modules/mux/pddf_mux_module.c index b0cd9e761ca7..b1daff2b7224 100644 --- a/platform/pddf/i2c/modules/mux/pddf_mux_module.c +++ b/platform/pddf/i2c/modules/mux/pddf_mux_module.c @@ -56,72 +56,49 @@ static const struct attribute_group pddf_mux_client_data_group = { .attrs = mux_attributes, }; -struct i2c_board_info *i2c_get_mux_board_info(MUX_DATA* mdata, NEW_DEV_ATTR *device_data) -{ - static struct i2c_board_info board_info; - static struct pca954x_platform_mode platform_modes[8]; - static struct pca954x_platform_data mux_platform_data; - int num_modes, i; - - if (strncmp(device_data->dev_type, "pca9548", strlen("pca9548")) == 0) - num_modes = 8; - else if (strncmp(device_data->dev_type, "pca9546", strlen("pca9546")) == 0) - num_modes = 6; - else - { - printk(KERN_ERR "%s: Unknown type of mux device\n", __FUNCTION__); - return NULL; - } - - for(i = 0; i < num_modes; i++) { - platform_modes[i] = (struct pca954x_platform_mode) { - .adap_id = (mdata->virt_bus + i), - .deselect_on_exit = 1, - }; - } - - mux_platform_data = (struct pca954x_platform_data) { - .modes = platform_modes, - .num_modes = num_modes, - }; - - board_info = (struct i2c_board_info) { - .platform_data = &mux_platform_data, - }; - - board_info.addr = device_data->dev_addr; - strcpy(board_info.type, device_data->dev_type); - - return &board_info; -} - - static ssize_t do_device_operation(struct device *dev, struct device_attribute *da, const char *buf, size_t count) { PDDF_ATTR *ptr = (PDDF_ATTR *)da; MUX_DATA *mux_ptr = (MUX_DATA *)(ptr->addr); NEW_DEV_ATTR *device_ptr = (NEW_DEV_ATTR *)(ptr->data); struct i2c_adapter *adapter; - struct i2c_board_info *board_info; + static struct i2c_board_info board_info; struct i2c_client *client_ptr; if (strncmp(buf, "add", strlen(buf)-1)==0) { - adapter = i2c_get_adapter(device_ptr->parent_bus); - board_info = i2c_get_mux_board_info(mux_ptr, device_ptr); - - client_ptr = i2c_new_device(adapter, board_info); - - if (client_ptr != NULL) + /* Supported types are pca_9540, pca_9542, pca_9543, pca_9544, pca_9545, pca_9546, pca_9547, pca_9548, + * pca_9846, pca_9847, pca_9848, pca_9849 + */ + if ( (strncmp(device_ptr->dev_type, "pca954", 6) == 0) || + (strncmp(device_ptr->dev_type, "pca984", 6) == 0) ) { - i2c_put_adapter(adapter); - pddf_dbg(MUX, KERN_ERR "Created %s client: 0x%p\n", device_ptr->i2c_name, (void *)client_ptr); - add_device_table(device_ptr->i2c_name, (void*)client_ptr); + adapter = i2c_get_adapter(device_ptr->parent_bus); + board_info = (struct i2c_board_info) { + .platform_data = NULL, + }; + + board_info.addr = device_ptr->dev_addr; + strcpy(board_info.type, device_ptr->dev_type); + + + client_ptr = i2c_new_client_device(adapter, &board_info); + + if (!IS_ERR(client_ptr)) + { + i2c_put_adapter(adapter); + pddf_dbg(MUX, KERN_ERR "Created %s client: 0x%p\n", device_ptr->i2c_name, (void *)client_ptr); + add_device_table(device_ptr->i2c_name, (void*)client_ptr); + } + else + { + i2c_put_adapter(adapter); + goto free_data; + } } - else + else { - i2c_put_adapter(adapter); - goto free_data; + printk(KERN_ERR "%s: Unknown type of mux device %s\n", __FUNCTION__, device_ptr->dev_type); } } else if (strncmp(buf, "delete", strlen(buf)-1)==0) diff --git a/platform/pddf/i2c/modules/psu/Makefile b/platform/pddf/i2c/modules/psu/Makefile index 04db30dfb48b..354c5ae2ed06 100644 --- a/platform/pddf/i2c/modules/psu/Makefile +++ b/platform/pddf/i2c/modules/psu/Makefile @@ -1,4 +1,4 @@ -subdir-m := driver -obj-m := pddf_psu_module.o +obj-m := driver/ +obj-m += pddf_psu_module.o -CFLAGS_$(obj-m):= -I$(M)/modules/include +ccflags-y:= -I$(M)/modules/include diff --git a/platform/pddf/i2c/modules/psu/driver/pddf_psu_api.c b/platform/pddf/i2c/modules/psu/driver/pddf_psu_api.c index b6b5e306a000..b358370f800e 100644 --- a/platform/pddf/i2c/modules/psu/driver/pddf_psu_api.c +++ b/platform/pddf/i2c/modules/psu/driver/pddf_psu_api.c @@ -89,20 +89,20 @@ int psu_update_hw(struct device *dev, struct psu_attr_info *info, PSU_DATA_ATTR { status = (sysfs_attr_data->pre_set)(client, udata, info); if (status!=0) - printk(KERN_ERR "%s: pre_set function fails for %s attribute\n", __FUNCTION__, udata->aname); + dev_warn(&client->dev, "%s: pre_set function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status); } if (sysfs_attr_data->do_set != NULL) { status = (sysfs_attr_data->do_set)(client, udata, info); if (status!=0) - printk(KERN_ERR "%s: do_set function fails for %s attribute\n", __FUNCTION__, udata->aname); + dev_warn(&client->dev, "%s: do_set function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status); } if (sysfs_attr_data->post_set != NULL) { status = (sysfs_attr_data->post_set)(client, udata, info); if (status!=0) - printk(KERN_ERR "%s: post_set function fails for %s attribute\n", __FUNCTION__, udata->aname); + dev_warn(&client->dev, "%s: post_set function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status); } mutex_unlock(&info->update_lock); @@ -128,20 +128,20 @@ int psu_update_attr(struct device *dev, struct psu_attr_info *data, PSU_DATA_ATT { status = (sysfs_attr_data->pre_get)(client, udata, data); if (status!=0) - printk(KERN_ERR "%s: pre_get function fails for %s attribute\n", __FUNCTION__, udata->aname); + dev_warn(&client->dev, "%s: pre_get function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status); } if (sysfs_attr_data->do_get != NULL) { status = (sysfs_attr_data->do_get)(client, udata, data); if (status!=0) - printk(KERN_ERR "%s: do_get function fails for %s attribute\n", __FUNCTION__, udata->aname); + dev_warn(&client->dev, "%s: do_get function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status); } if (sysfs_attr_data->post_get != NULL) { status = (sysfs_attr_data->post_get)(client, udata, data); if (status!=0) - printk(KERN_ERR "%s: post_get function fails for %s attribute\n", __FUNCTION__, udata->aname); + dev_warn(&client->dev, "%s: post_get function fails for %s attribute. ret %d\n", __FUNCTION__, udata->aname, status); } data->last_updated = jiffies; diff --git a/platform/pddf/i2c/modules/psu/driver/pddf_psu_driver.c b/platform/pddf/i2c/modules/psu/driver/pddf_psu_driver.c index ad71e45eca20..dc7edb92a3ad 100644 --- a/platform/pddf/i2c/modules/psu/driver/pddf_psu_driver.c +++ b/platform/pddf/i2c/modules/psu/driver/pddf_psu_driver.c @@ -224,7 +224,7 @@ static int psu_probe(struct i2c_client *client, goto exit_free; } - data->hwmon_dev = hwmon_device_register(&client->dev); + data->hwmon_dev = hwmon_device_register_with_info(&client->dev, client->name, NULL, NULL, NULL); if (IS_ERR(data->hwmon_dev)) { status = PTR_ERR(data->hwmon_dev); goto exit_remove; diff --git a/platform/pddf/i2c/modules/psu/pddf_psu_module.c b/platform/pddf/i2c/modules/psu/pddf_psu_module.c index cf9713b407cd..41ceea7cca3d 100644 --- a/platform/pddf/i2c/modules/psu/pddf_psu_module.c +++ b/platform/pddf/i2c/modules/psu/pddf_psu_module.c @@ -160,9 +160,9 @@ static ssize_t do_device_operation(struct device *dev, struct device_attribute * board_info = i2c_get_psu_board_info(pdata, cdata); /* Populate the platform data for psu */ - client_ptr = i2c_new_device(adapter, board_info); + client_ptr = i2c_new_client_device(adapter, board_info); - if(client_ptr != NULL) + if(!IS_ERR(client_ptr)) { i2c_put_adapter(adapter); pddf_dbg(PSU, KERN_ERR "Created a %s client: 0x%p\n", cdata->i2c_name , (void *)client_ptr); diff --git a/platform/pddf/i2c/modules/sysstatus/Makefile b/platform/pddf/i2c/modules/sysstatus/Makefile index 150d160eae15..fc2e6261975e 100644 --- a/platform/pddf/i2c/modules/sysstatus/Makefile +++ b/platform/pddf/i2c/modules/sysstatus/Makefile @@ -1,4 +1,4 @@ TARGET := pddf_sysstatus_module obj-m := $(TARGET).o -CFLAGS_$(obj-m):= -I$(M)/modules/include +ccflags-y := -I$(M)/modules/include diff --git a/platform/pddf/i2c/modules/xcvr/Makefile b/platform/pddf/i2c/modules/xcvr/Makefile index e72ad6b44233..433a8630a2e8 100644 --- a/platform/pddf/i2c/modules/xcvr/Makefile +++ b/platform/pddf/i2c/modules/xcvr/Makefile @@ -1,4 +1,4 @@ -subdir-m := driver -obj-m := pddf_xcvr_module.o +obj-m := driver/ +obj-m += pddf_xcvr_module.o -CFLAGS_$(obj-m):= -I$(M)/modules/include +ccflags-y:= -I$(M)/modules/include diff --git a/platform/pddf/i2c/modules/xcvr/driver/pddf_xcvr_api.c b/platform/pddf/i2c/modules/xcvr/driver/pddf_xcvr_api.c index ddb7a1b3a2b3..a18b4ac93af5 100644 --- a/platform/pddf/i2c/modules/xcvr/driver/pddf_xcvr_api.c +++ b/platform/pddf/i2c/modules/xcvr/driver/pddf_xcvr_api.c @@ -47,36 +47,106 @@ int get_xcvr_module_attr_data(struct i2c_client *client, struct device *dev, int xcvr_i2c_cpld_read(XCVR_ATTR *info) { int status = -1; + int retry = 10; if (info!=NULL) { - if (info->len==1) - { - status = board_i2c_cpld_read(info->devaddr , info->offset); - } - else + /* Get the I2C client for the CPLD */ + struct i2c_client *client_ptr=NULL; + client_ptr = (struct i2c_client *)get_device_table(info->devname); + if (client_ptr) { - /* Get the I2C client for the CPLD */ - struct i2c_client *client_ptr=NULL; - client_ptr = (struct i2c_client *)get_device_table(info->devname); - if (client_ptr) + if (info->len==1) + { + while (retry) + { + status = board_i2c_cpld_read_new(info->devaddr, info->devname, info->offset); + if (unlikely(status < 0)) + { + msleep(60); + retry--; + continue; + } + break; + } + } + else if (info->len==2) { - if (info->len==2) - { + while(retry) + { status = i2c_smbus_read_word_swapped(client_ptr, info->offset); + if (unlikely(status < 0)) + { + msleep(60); + retry--; + continue; + } + break; } - else - printk(KERN_ERR "PDDF_XCVR: Doesn't support block CPLD read yet"); } else - printk(KERN_ERR "Unable to get the client handle for %s\n", info->devname); + printk(KERN_ERR "PDDF_XCVR: Doesn't support block CPLD read yet"); } + else + printk(KERN_ERR "Unable to get the client handle for %s\n", info->devname); + } + + return status; +} + +int xcvr_i2c_cpld_write(XCVR_ATTR *info, uint32_t val) +{ + int status = 0; + unsigned int val_mask = 0, dnd_value = 0; + uint32_t reg; + struct i2c_client *client_ptr=NULL; + val_mask = BIT_INDEX(info->mask); + /* Get the I2C client for the CPLD */ + client_ptr = (struct i2c_client *)get_device_table(info->devname); + + if (client_ptr) + { + if (info->len == 1) + status = board_i2c_cpld_read_new(info->devaddr, info->devname, info->offset); + else if (info->len == 2) + status = i2c_smbus_read_word_swapped(client_ptr, info->offset); + else + { + printk(KERN_ERR "PDDF_XCVR: Doesn't support block CPLD read yet"); + status = -1; + } + } + else + { + printk(KERN_ERR "Unable to get the client handle for %s\n", info->devname); + status = -1; } + if (status < 0) + return status; + else + { + msleep(60); + dnd_value = status & ~val_mask; + if (((val == 1) && (info->cmpval != 0)) || ((val == 0) && (info->cmpval == 0))) + reg = dnd_value | val_mask; + else + reg = dnd_value; + if (info->len == 1) + status = board_i2c_cpld_write_new(info->devaddr, info->devname, info->offset, (uint8_t)reg); + else if (info->len == 2) + status = i2c_smbus_write_word_swapped(client_ptr, info->offset, (uint16_t)reg); + else + { + printk(KERN_ERR "PDDF_XCVR: Doesn't support block CPLD write yet"); + status = -1; + } + } return status; } + int sonic_i2c_get_mod_pres(struct i2c_client *client, XCVR_ATTR *info, struct xcvr_data *data) { int status = 0; @@ -143,7 +213,7 @@ int sonic_i2c_get_mod_intr_status(struct i2c_client *client, XCVR_ATTR *info, st mod_intr = ((status & BIT_INDEX(info->mask)) == info->cmpval) ? 1 : 0; sfp_dbg(KERN_INFO "\nModule Interrupt :0x%x, reg_value = 0x%x\n", mod_intr, status); } - } + } else if(strcmp(info->devtype, "eeprom") == 0) { /* get client client for eeprom - Not Applicable */ @@ -247,54 +317,15 @@ int sonic_i2c_get_mod_txfault(struct i2c_client *client, XCVR_ATTR *info, struct int sonic_i2c_set_mod_reset(struct i2c_client *client, XCVR_ATTR *info, struct xcvr_data *data) { int status = 0; - unsigned int val_mask = 0, dnd_value = 0; - uint32_t reg; - struct i2c_client *client_ptr=NULL; if (strcmp(info->devtype, "cpld") == 0) { - val_mask = BIT_INDEX(info->mask); - /* Get the I2C client for the CPLD */ - client_ptr = (struct i2c_client *)get_device_table(info->devname); - - if (client_ptr) - { - if (info->len == 1) - status = board_i2c_cpld_read(info->devaddr , info->offset); - else if (info->len == 2) - status = i2c_smbus_read_word_data(client_ptr, info->offset); - else - { - printk(KERN_ERR "PDDF_XCVR: Doesn't support block CPLD read yet"); - status = -1; - } - } - else - { - printk(KERN_ERR "Unable to get the client handle for %s\n", info->devname); - status = -1; - } - /*printk(KERN_ERR "sonic_i2c_set_mod_reset:client_ptr=0x%x, status=0x%x, offset=0x%x, len=%d\n", client_ptr, status, info->offset, info->len);*/ - - if (status < 0) - return status; - else - { - dnd_value = status & ~val_mask; - if (((data->reset == 1) && (info->cmpval != 0)) || ((data->reset == 0) && (info->cmpval == 0))) - reg = dnd_value | val_mask; - else - reg = dnd_value; - if (info->len == 1) - status = board_i2c_cpld_write(info->devaddr, info->offset, (uint8_t)reg); - else if (info->len == 2) - status = i2c_smbus_write_word_swapped(client_ptr, info->offset, (uint16_t)reg); - else - { - printk(KERN_ERR "PDDF_XCVR: Doesn't support block CPLD write yet"); - status = -1; - } - } + status = xcvr_i2c_cpld_write(info, data->reset); + } + else + { + printk(KERN_ERR "Error: Invalid device type (%s) to set xcvr reset\n", info->devtype); + status = -1; } return status; @@ -303,53 +334,15 @@ int sonic_i2c_set_mod_reset(struct i2c_client *client, XCVR_ATTR *info, struct x int sonic_i2c_set_mod_lpmode(struct i2c_client *client, XCVR_ATTR *info, struct xcvr_data *data) { int status = 0; - unsigned int val_mask = 0, dnd_value = 0; - uint32_t reg; - struct i2c_client *client_ptr=NULL; if (strcmp(info->devtype, "cpld") == 0) { - val_mask = BIT_INDEX(info->mask); - /* Get the I2C client for the CPLD */ - client_ptr = (struct i2c_client *)get_device_table(info->devname); - - if (client_ptr) - { - if (info->len == 1) - status = board_i2c_cpld_read(info->devaddr , info->offset); - else if (info->len == 2) - status = i2c_smbus_read_word_data(client_ptr, info->offset); - else - { - printk(KERN_ERR "PDDF_XCVR: Doesn't support block CPLD read yet"); - status = -1; - } - } - else - { - printk(KERN_ERR "Unable to get the client handle for %s\n", info->devname); - status = -1; - } - - if (status < 0) - return status; - else - { - dnd_value = status & ~val_mask; - if (((data->lpmode == 1) && (info->cmpval != 0)) || ((data->lpmode == 0) && (info->cmpval == 0))) - reg = dnd_value | val_mask; - else - reg = dnd_value; - if (info->len == 1) - status = board_i2c_cpld_write(info->devaddr, info->offset, (uint8_t)reg); - else if (info->len == 2) - status = i2c_smbus_write_word_swapped(client_ptr, info->offset, (uint16_t)reg); - else - { - printk(KERN_ERR "PDDF_XCVR: Doesn't support block CPLD write yet"); - status = -1; - } - } + status = xcvr_i2c_cpld_write(info, data->lpmode); + } + else + { + printk(KERN_ERR "Error: Invalid device type (%s) to set xcvr lpmode\n", info->devtype); + status = -1; } return status; @@ -358,53 +351,15 @@ int sonic_i2c_set_mod_lpmode(struct i2c_client *client, XCVR_ATTR *info, struct int sonic_i2c_set_mod_txdisable(struct i2c_client *client, XCVR_ATTR *info, struct xcvr_data *data) { int status = 0; - unsigned int val_mask = 0, dnd_value = 0; - uint32_t reg; - struct i2c_client *client_ptr=NULL; if (strcmp(info->devtype, "cpld") == 0) { - val_mask = BIT_INDEX(info->mask); - /* Get the I2C client for the CPLD */ - client_ptr = (struct i2c_client *)get_device_table(info->devname); - - if (client_ptr) - { - if (info->len == 1) - status = board_i2c_cpld_read(info->devaddr , info->offset); - else if (info->len == 2) - status = i2c_smbus_read_word_data(client_ptr, info->offset); - else - { - printk(KERN_ERR "PDDF_XCVR: Doesn't support block CPLD read yet"); - status = -1; - } - } - else - { - printk(KERN_ERR "Unable to get the client handle for %s\n", info->devname); - status = -1; - } - - if (status < 0) - return status; - else - { - dnd_value = status & ~val_mask; - if (((data->txdisable == 1) && (info->cmpval != 0)) || ((data->txdisable == 0) && (info->cmpval == 0))) - reg = dnd_value | val_mask; - else - reg = dnd_value; - if (info->len == 1) - status = board_i2c_cpld_write(info->devaddr, info->offset, (uint8_t)reg); - else if (info->len == 2) - status = i2c_smbus_write_word_swapped(client_ptr, info->offset, (uint16_t)reg); - else - { - printk(KERN_ERR "PDDF_XCVR: Doesn't support block CPLD write yet"); - status = -1; - } - } + status = xcvr_i2c_cpld_write(info, data->txdisable); + } + else + { + printk(KERN_ERR "Error: Invalid device type (%s) to set xcvr txdisable\n", info->devtype); + status = -1; } return status; @@ -433,20 +388,20 @@ ssize_t get_module_presence(struct device *dev, struct device_attribute *da, { status = (attr_ops->pre_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: pre_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: pre_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->do_get != NULL) { status = (attr_ops->do_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: do_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); + dev_warn(&client->dev, "%s: do_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->post_get != NULL) { status = (attr_ops->post_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: post_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: post_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } mutex_unlock(&data->update_lock); return sprintf(buf, "%d\n", data->modpres); @@ -478,20 +433,20 @@ ssize_t get_module_reset(struct device *dev, struct device_attribute *da, { status = (attr_ops->pre_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: pre_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: pre_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); } if (attr_ops->do_get != NULL) { status = (attr_ops->do_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: do_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: do_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); } if (attr_ops->post_get != NULL) { status = (attr_ops->post_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: post_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: post_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); } mutex_unlock(&data->update_lock); @@ -533,20 +488,20 @@ ssize_t set_module_reset(struct device *dev, struct device_attribute *da, const { status = (attr_ops->pre_set)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: pre_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: pre_set function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->do_set != NULL) { status = (attr_ops->do_set)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: do_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: do_set function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->post_set != NULL) { status = (attr_ops->post_set)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: post_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: post_set function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } mutex_unlock(&data->update_lock); @@ -579,20 +534,20 @@ ssize_t get_module_intr_status(struct device *dev, struct device_attribute *da, { status = (attr_ops->pre_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: pre_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: pre_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->do_get != NULL) { status = (attr_ops->do_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: do_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: do_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->post_get != NULL) { status = (attr_ops->post_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: post_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: post_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } mutex_unlock(&data->update_lock); @@ -645,20 +600,20 @@ ssize_t get_module_lpmode(struct device *dev, struct device_attribute *da, char { status = (attr_ops->pre_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: pre_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: pre_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->do_get != NULL) { status = (attr_ops->do_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: do_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: do_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->post_get != NULL) { status = (attr_ops->post_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: post_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: post_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } mutex_unlock(&data->update_lock); return sprintf(buf, "%d\n", data->lpmode); @@ -699,20 +654,20 @@ ssize_t set_module_lpmode(struct device *dev, struct device_attribute *da, const { status = (attr_ops->pre_set)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: pre_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: pre_set function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->do_set != NULL) { status = (attr_ops->do_set)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: do_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: do_set function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->post_set != NULL) { status = (attr_ops->post_set)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: post_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: post_set function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } mutex_unlock(&data->update_lock); } @@ -743,20 +698,20 @@ ssize_t get_module_rxlos(struct device *dev, struct device_attribute *da, { status = (attr_ops->pre_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: pre_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: pre_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->do_get != NULL) { status = (attr_ops->do_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: do_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: do_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->post_get != NULL) { status = (attr_ops->post_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: post_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: post_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } mutex_unlock(&data->update_lock); return sprintf(buf, "%d\n", data->rxlos); @@ -789,20 +744,20 @@ ssize_t get_module_txdisable(struct device *dev, struct device_attribute *da, { status = (attr_ops->pre_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: pre_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: pre_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->do_get != NULL) { status = (attr_ops->do_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: do_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: do_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->post_get != NULL) { status = (attr_ops->post_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: post_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: post_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } mutex_unlock(&data->update_lock); return sprintf(buf, "%d\n", data->txdisable); @@ -843,20 +798,20 @@ ssize_t set_module_txdisable(struct device *dev, struct device_attribute *da, co { status = (attr_ops->pre_set)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: pre_set function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: pre_set function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->do_set != NULL) { status = (attr_ops->do_set)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: do_set function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: do_set function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->post_set != NULL) { status = (attr_ops->post_set)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: post_set function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: post_set function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } mutex_unlock(&data->update_lock); } @@ -887,20 +842,20 @@ ssize_t get_module_txfault(struct device *dev, struct device_attribute *da, { status = (attr_ops->pre_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: pre_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: pre_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->do_get != NULL) { status = (attr_ops->do_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: do_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: do_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } if (attr_ops->post_get != NULL) { status = (attr_ops->post_get)(client, attr_data, data); if (status!=0) - printk(KERN_ERR "%s: post_get function fails for %s attribute\n", __FUNCTION__, attr_data->aname); + dev_warn(&client->dev, "%s: post_get function fails for %s attribute. ret %d\n", __FUNCTION__, attr_data->aname, status); } mutex_unlock(&data->update_lock); return sprintf(buf, "%d\n", data->txfault); diff --git a/platform/pddf/i2c/modules/xcvr/driver/pddf_xcvr_driver.c b/platform/pddf/i2c/modules/xcvr/driver/pddf_xcvr_driver.c index 142d38a2ff2b..7ce1bca94b71 100644 --- a/platform/pddf/i2c/modules/xcvr/driver/pddf_xcvr_driver.c +++ b/platform/pddf/i2c/modules/xcvr/driver/pddf_xcvr_driver.c @@ -159,7 +159,7 @@ static int xcvr_probe(struct i2c_client *client, goto exit_free; } - data->xdev = hwmon_device_register(&client->dev); + data->xdev = hwmon_device_register_with_info(&client->dev, client->name, NULL, NULL, NULL); if (IS_ERR(data->xdev)) { status = PTR_ERR(data->xdev); goto exit_remove; diff --git a/platform/pddf/i2c/modules/xcvr/pddf_xcvr_module.c b/platform/pddf/i2c/modules/xcvr/pddf_xcvr_module.c index 65c555b742a2..43c41954c71f 100644 --- a/platform/pddf/i2c/modules/xcvr/pddf_xcvr_module.c +++ b/platform/pddf/i2c/modules/xcvr/pddf_xcvr_module.c @@ -129,8 +129,8 @@ static ssize_t do_device_operation(struct device *dev, struct device_attribute * board_info.addr = cdata->dev_addr; strcpy(board_info.type, cdata->dev_type); - client_ptr = i2c_new_device(adapter, &board_info); - if (client_ptr != NULL) { + client_ptr = i2c_new_client_device(adapter, &board_info); + if (!IS_ERR(client_ptr)) { i2c_put_adapter(adapter); pddf_dbg(XCVR, KERN_ERR "Created a %s client: 0x%p\n", cdata->i2c_name, (void *)client_ptr); add_device_table(cdata->i2c_name, (void*)client_ptr); @@ -152,8 +152,8 @@ static ssize_t do_device_operation(struct device *dev, struct device_attribute * board_info.addr = cdata->dev_addr; strcpy(board_info.type, cdata->dev_type); - client_ptr = i2c_new_device(adapter, &board_info); - if(client_ptr != NULL) { + client_ptr = i2c_new_client_device(adapter, &board_info); + if(!IS_ERR(client_ptr)) { i2c_put_adapter(adapter); pddf_dbg(XCVR, KERN_ERR "Created %s, type:%s client: 0x%p\n", cdata->i2c_name, cdata->dev_type, (void *)client_ptr); add_device_table(cdata->i2c_name, (void*)client_ptr); From f6c136c0cf2a2d13bbf09ef2d1ebe5fecf544be5 Mon Sep 17 00:00:00 2001 From: Fuzail Khan Date: Tue, 21 Dec 2021 00:35:08 -0800 Subject: [PATCH 2/3] Small change to re-run the checks --- platform/pddf/i2c/modules/xcvr/driver/pddf_xcvr_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/pddf/i2c/modules/xcvr/driver/pddf_xcvr_api.c b/platform/pddf/i2c/modules/xcvr/driver/pddf_xcvr_api.c index a18b4ac93af5..a7be64328cab 100644 --- a/platform/pddf/i2c/modules/xcvr/driver/pddf_xcvr_api.c +++ b/platform/pddf/i2c/modules/xcvr/driver/pddf_xcvr_api.c @@ -48,11 +48,11 @@ int xcvr_i2c_cpld_read(XCVR_ATTR *info) { int status = -1; int retry = 10; + struct i2c_client *client_ptr=NULL; if (info!=NULL) { /* Get the I2C client for the CPLD */ - struct i2c_client *client_ptr=NULL; client_ptr = (struct i2c_client *)get_device_table(info->devname); if (client_ptr) { From 525c5b081efa43abc5da4d22a75298c81f0e8031 Mon Sep 17 00:00:00 2001 From: Fuzail Khan Date: Tue, 28 Dec 2021 22:40:41 -0800 Subject: [PATCH 3/3] Taking a backup of synvers file required for compilation of various ODMs modules --- platform/pddf/i2c/debian/rules | 2 ++ 1 file changed, 2 insertions(+) diff --git a/platform/pddf/i2c/debian/rules b/platform/pddf/i2c/debian/rules index 0afdb8667d08..edca93ee06a8 100755 --- a/platform/pddf/i2c/debian/rules +++ b/platform/pddf/i2c/debian/rules @@ -56,6 +56,8 @@ binary-indep: (for mod in $(MODULE_DIRS); do \ cp $(MOD_SRC_DIR)/$(MODULE_DIR)/$${mod}/*.ko debian/$(PACKAGE_PRE_NAME)/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ done) ; \ + # Need to take a backup of symvers file for compilation of custom modules in various platforms + cp $(MOD_SRC_DIR)/Module.symvers $(MOD_SRC_DIR)/Module.symvers.PDDF; \ cp -r $(MOD_SRC_DIR)/$(UTILS_DIR)/* debian/$(PACKAGE_PRE_NAME)/usr/local/bin/; \ $(PYTHON) $(MOD_SRC_DIR)/setup.py install --root=$(MOD_SRC_DIR)/debian/$(PACKAGE_PRE_NAME) --install-layout=deb; \ set +e