Skip to content

Commit

Permalink
[Inventec][D6356] Kernel upgrade and few updates
Browse files Browse the repository at this point in the history
- Upgrade kernel to 4.19
- Update SFP/QSFP platform API base on latest xcvrd
- Add auto find gpio base in swps driver

Signed-off-by: cynthia <wu.cynthia@inventec.com>
  • Loading branch information
CynthiaINV committed Aug 21, 2020
1 parent 7872b4e commit 2a84aa6
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
blacklist lpc_ich
blacklist i2c-i801
blacklist i2c_ismt
blacklist gpio_ich
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
obj-m += ucd9000.o
obj-m += i2c-mux-pca9541.o
obj-m += inv-mux-9641.o
obj-m += gpio-ich.o
obj-m += lpc_ich.o
obj-m += inv_cpld.o
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,13 @@ static int pca9541_probe(struct i2c_client *client,
* We have to lock the adapter before releasing the bus.
*/
if (detect_id == 0) {
i2c_lock_adapter(adap);
i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
pca9541_release_bus(client);
i2c_unlock_adapter(adap);
i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
} else {
i2c_lock_adapter(adap);
i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
pca9641_release_bus(client);
i2c_unlock_adapter(adap);
i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
}

/* Create mux adapter */
Expand Down Expand Up @@ -558,7 +558,7 @@ static int pca9541_remove(struct i2c_client *client)

static struct i2c_driver pca9541_driver = {
.driver = {
.name = "pca9541",
.name = "inv-mux-9641",
.of_match_table = of_match_ptr(pca9541_of_match),
},
.probe = pca9541_probe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ cpld_probe(struct i2c_client *client, const struct i2c_device_id *id)
if (status)
goto exit_free;

data->hwmon_dev = hwmon_device_register(&client->dev);
data->hwmon_dev = hwmon_device_register_with_info(&client->dev, "inv_cpld", NULL, NULL, NULL);
if (IS_ERR(data->hwmon_dev)) {
status = PTR_ERR(data->hwmon_dev);
goto exit_remove;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,35 @@ clean_cpld_4_rst_all(struct mux_obj_s *self){
return 0;
}

static int gpiochip_match_name(struct gpio_chip *chip, void *data)
{
const char *name = data;
return !strcmp(chip->label, name);
}

static struct gpio_chip *find_chip_by_name(const char *name)
{
return gpiochip_find((void *)name, gpiochip_match_name);
}

static int
_setup_muxctl_cb(struct mux_obj_s *self,
unsigned gpio){
unsigned int gpio){

char mod_dsc[32] = "ERR";

int gpio_base = 0;
struct gpio_chip *chip = NULL;

if (NULL == (chip = find_chip_by_name("gpio_ich"))) {
SWPS_ERR("find gpio name fail\n");
return -1;
}
gpio_base = chip->base;
self->gpio_num = gpio + gpio_base;

switch (gpio) {
case MUX_RST_GPIO_FORCE_RANGELEY:
self->gpio_num = gpio;
self->_pull_low = rangeley_force_pull_low;
self->_pull_high = rangeley_force_pull_high;
self->_init = init_gpio_4_force;
Expand All @@ -386,7 +405,6 @@ _setup_muxctl_cb(struct mux_obj_s *self,
goto ok_setup_muxctl_cb;

case MUX_RST_GPIO_FORCE_HEDERA:
self->gpio_num = gpio;
self->_pull_low = hedera_force_pull_low;
self->_pull_high = hedera_force_pull_high;
self->_init = init_gpio_4_force;
Expand All @@ -401,7 +419,6 @@ _setup_muxctl_cb(struct mux_obj_s *self,
case MUX_RST_GPIO_249_PCA9548:
case MUX_RST_GPIO_500_PCA9548:
case MUX_RST_GPIO_505_PCA9548:
self->gpio_num = gpio;
self->_pull_low = normal_gpio_pull_low;
self->_pull_high = normal_gpio_pull_high;
self->_init = init_gpio_4_normal;
Expand All @@ -412,7 +429,6 @@ _setup_muxctl_cb(struct mux_obj_s *self,
goto ok_setup_muxctl_cb;

case MUX_RST_CPLD_C0_A77_70_74_RST_ALL:
self->gpio_num = gpio;
self->_pull_low = cpld_rst_all_4_pull_low;
self->_pull_high = cpld_rst_all_4_pull_high;
self->_init = init_cpld_4_rst_all;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/platform_data/pca954x.h>
#include <linux/gpio/machine.h>

struct inv_i2c_board_info {
int ch;
Expand All @@ -14,6 +15,9 @@ struct inv_i2c_board_info {
};

#define bus_id(id) (id)
#define SCL_PIN 58
#define SDA_PIN 75

static struct pca954x_platform_mode pca9641_modes_1[] = {
{.adap_id = bus_id(2),},
};
Expand Down Expand Up @@ -137,49 +141,49 @@ static struct pca954x_platform_data mux_data_0_6 = {
};

static struct i2c_board_info i2c_device_info0[] __initdata = {
{"pca9641", 0, 0x76, &pca9641_data_1, 0, 0}, //PCA9641-1
{"pca9641", 0, 0x73, &pca9641_data_3, 0, 0}, //PCA9641-3
{"pca9641", 0, 0x09, &pca9641_data_4, 0, 0}, //PCA9641-4
{"pca9641", 0, 0x76, "pca9641-1", &pca9641_data_1, 0, 0}, //PCA9641-1
{"pca9641", 0, 0x73, "pca9641-2", &pca9641_data_3, 0, 0}, //PCA9641-3
{"pca9641", 0, 0x09, "pca9641-3", &pca9641_data_4, 0, 0}, //PCA9641-4
};
static struct i2c_board_info i2c_device_info1[] __initdata = {
{"pca9641", 0, 0x0A, &pca9641_data_2, 0, 0}, //PCA9641-2
{"pca9641", 0, 0x0A, "pca9641-4", &pca9641_data_2, 0, 0}, //PCA9641-2
};
static struct i2c_board_info i2c_device_info2[] __initdata = {
{"inv_cpld", 0, 0x77, 0, 0, 0}, //CPLD
{"inv_cpld", 0, 0x77, "inv_cpld", 0, 0, 0}, //CPLD
};
static struct i2c_board_info i2c_device_info3[] __initdata = {
{"tmp75", 0, 0x48, 0, 0, 0}, //CPU Board Temp
{"tmp75", 0, 0x4A, 0, 0, 0}, //Temp
{"tmp75", 0, 0x4D, 0, 0, 0}, //Temp
{"tmp75", 0, 0x4E, 0, 0, 0}, //Temp
{"tmp75", 0, 0x48, "tmp75-1", 0, 0, 0}, //CPU Board Temp
{"tmp75", 0, 0x4A, "tmp75-2", 0, 0, 0}, //Temp
{"tmp75", 0, 0x4D, "tmp75-3", 0, 0, 0}, //Temp
{"tmp75", 0, 0x4E, "tmp75-4", 0, 0, 0}, //Temp
};
static struct i2c_board_info i2c_device_info4[] __initdata = {
{"pmbus", 0, 0x5B, 0, 0, 0}, //PSU1
{"pmbus", 0, 0x5A, 0, 0, 0}, //PSU2
{"pmbus", 0, 0x5B, "pmbus-1", 0, 0, 0}, //PSU1
{"pmbus", 0, 0x5A, "pmbus-2", 0, 0, 0}, //PSU2
};
static struct i2c_board_info i2c_device_info5[] __initdata = {
{"pca9548", 0, 0x70, &mux_data_0, 0, 0}, //mux root
{"pca9548", 0, 0x70, "pca9548-1", &mux_data_0, 0, 0}, //mux root
};
static struct i2c_board_info i2c_device_info6[] __initdata = {
{"pca9548", 0, 0x72, &mux_data_0_0, 0, 0},
{"pca9548", 0, 0x72, "pca9548-2", &mux_data_0_0, 0, 0},
};
static struct i2c_board_info i2c_device_info7[] __initdata = {
{"pca9548", 0, 0x72, &mux_data_0_1, 0, 0},
{"pca9548", 0, 0x72, "pca9548-3", &mux_data_0_1, 0, 0},
};
static struct i2c_board_info i2c_device_info8[] __initdata = {
{"pca9548", 0, 0x72, &mux_data_0_2, 0, 0},
{"pca9548", 0, 0x72, "pca9548-4", &mux_data_0_2, 0, 0},
};
static struct i2c_board_info i2c_device_info9[] __initdata = {
{"pca9548", 0, 0x72, &mux_data_0_3, 0, 0},
{"pca9548", 0, 0x72, "pca9548-5", &mux_data_0_3, 0, 0},
};
static struct i2c_board_info i2c_device_info10[] __initdata = {
{"pca9548", 0, 0x72, &mux_data_0_4, 0, 0},
{"pca9548", 0, 0x72, "pca9548-6", &mux_data_0_4, 0, 0},
};
static struct i2c_board_info i2c_device_info11[] __initdata = {
{"pca9548", 0, 0x72, &mux_data_0_5, 0, 0},
{"pca9548", 0, 0x72, "pca9548-7", &mux_data_0_5, 0, 0},
};
static struct i2c_board_info i2c_device_info12[] __initdata = {
{"pca9548", 0, 0x72, &mux_data_0_6, 0, 0},
{"pca9548", 0, 0x72, "pca9548-8", &mux_data_0_6, 0, 0},
};


Expand All @@ -203,16 +207,33 @@ static struct inv_i2c_board_info i2cdev_list[] = {
static int client_list_index = 0;
static struct i2c_client *client_list[INV_PLATFORM_CLIENT_MAX_NUM] = {0};

/////////////////////////////////////////////////////////////////////////////////////////
static struct platform_device *device_i2c_gpio0;
static struct i2c_gpio_platform_data i2c_gpio_platdata0 = {
.scl_pin = 58, //494,
.sda_pin = 75, //511,
static struct gpiod_lookup_table inv_i2c_gpiod_table = {
.dev_id = "i2c-gpio.1",
.table = {
GPIO_LOOKUP_IDX("gpio_ich", SDA_PIN, NULL, 0, GPIO_OPEN_DRAIN), //I2C_SDA
GPIO_LOOKUP_IDX("gpio_ich", SCL_PIN, NULL, 1, GPIO_OPEN_DRAIN), //I2C_SCL
},
};

static struct i2c_gpio_platform_data i2c_platform_data = {
.udelay = 5, //5:100kHz
//.sda_is_open_drain = 0,
//.scl_is_open_drain = 0,
//.scl_is_output_only = 0,
};

static void i2cgpio_device_release(struct device *dev)
{
gpiod_remove_lookup_table(&inv_i2c_gpiod_table);
}

.udelay = 5, //5:100kHz
.sda_is_open_drain = 0,
.scl_is_open_drain = 0,
.scl_is_output_only = 0
static struct platform_device device_i2c_gpio0 = {
.name = "i2c-gpio",
.id = 1,
.dev = {
.platform_data = &i2c_platform_data,
.release = i2cgpio_device_release,
},
};

static int __init inv_platform_init(void)
Expand All @@ -222,7 +243,6 @@ static int __init inv_platform_init(void)
int ret = 0;
int i,j,k;

//printk("%s \n", __func__);

//use i2c-gpio
//register i2c gpio
Expand All @@ -234,18 +254,11 @@ static int __init inv_platform_init(void)
outl( inl(0x501) | (1<<7), 0x501); //BMC_HEART_BEAT (GPIO15)
outl( inl(0x503) | (1<<2)|(1<<3), 0x503); //PSOC_HEART_BEAT(26),CPLD_HEART_BEAT(27)

device_i2c_gpio0 = platform_device_alloc("i2c-gpio", 1);
if (!device_i2c_gpio0) {
printk(KERN_ERR "i2c-gpio: platform_device_alloc fail\n");
return -ENOMEM;
}
device_i2c_gpio0->name = "i2c-gpio";
device_i2c_gpio0->id = 1;
device_i2c_gpio0->dev.platform_data = &i2c_gpio_platdata0;
gpiod_add_lookup_table(&inv_i2c_gpiod_table);

ret = platform_device_add(device_i2c_gpio0);
ret = platform_device_register(&device_i2c_gpio0);
if (ret) {
printk(KERN_ERR "i2c-gpio: platform_device_add fail %d\n", ret);
printk(KERN_ERR "i2c-gpio: platform_device_register fail %d\n", ret);
}
msleep(10);

Expand Down Expand Up @@ -283,8 +296,7 @@ static void __exit inv_platform_exit(void)
for(i=client_list_index-1; i>=0; i--) {
i2c_unregister_device(client_list[i]);
}
device_i2c_gpio0->dev.platform_data = NULL;
platform_device_unregister(device_i2c_gpio0);
platform_device_unregister(&device_i2c_gpio0);
printk("inv_platform_exit done\n");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ get_swpdev_by_name(char *name){
struct device *dev = class_find_device(swp_class_p,
NULL,
name,
__swp_match);
(const void *) __swp_match);
return dev;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __init__(self, index):

self.__presence_attr = None
self.__eeprom_path = None
self.sfp_type = "QSFP"
if self.__index in range(0, self.__port_end + 1):
self.__presence_attr = "/sys/class/swps/port{}/present".format(self.__index)
self.__lpmode_attr = "/sys/class/swps/port{}/lpmod".format(self.__index)
Expand Down Expand Up @@ -321,6 +322,7 @@ def get_transceiver_info(self):

transceiver_info_dict['cable_type'] = "Unknown"
transceiver_info_dict['cable_length'] = "Unknown"
transceiver_info_dict['application_advertisement'] = "Unknown"
for key in qsfp_cable_length_tup:
if key in sfp_interface_bulk_data['data']:
transceiver_info_dict['cable_type'] = key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self, index):

self.__presence_attr = None
self.__eeprom_path = None
self.sfp_type = "SFP"
if self.__index in range(0, self.__port_end + 1):
self.__presence_attr = "/sys/class/swps/port{}/present".format(self.__index)
self.__eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom".format(self.__port_to_i2c_mapping[self.__index])
Expand Down Expand Up @@ -310,6 +311,7 @@ def get_transceiver_info(self):

transceiver_info_dict['cable_type'] = "Unknown"
transceiver_info_dict['cable_length'] = "Unknown"
transceiver_info_dict['application_advertisement'] = "Unknown"
for key in sfp_cable_length_tup:
if key in sfp_interface_bulk_data['data']:
transceiver_info_dict['cable_type'] = key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def exec_cmd(cmd, show):
'i2c-i801',
'i2c-mux',
'i2c-mux-pca954x',
'i2c-mux-pca9541',
'inv-mux-9641',
'i2c-dev',
'ucd9000',
#inv-modules
Expand All @@ -134,14 +134,8 @@ def exec_cmd(cmd, show):
def system_install():
global FORCE

#remove default drivers to avoid modprobe order conflicts
status, output = exec_cmd("rmmod i2c_ismt ", 1)
status, output = exec_cmd("rmmod i2c-i801 ", 1)
status, output = exec_cmd("rmmod gpio_ich ", 1)
status, output = exec_cmd("rmmod lpc_ich ", 1)

#insert extra module
status, output = exec_cmd("insmod /lib/modules/4.9.0-11-2-amd64/kernel/drivers/gpio/gpio-ich.ko gpiobase=0",1)
status, output = exec_cmd("modprobe gpio-ich gpiobase=0",1)

#install drivers
for i in range(0,len(drivers)):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
d6356/utils/inventec_d6356_util.py usr/local/bin
d6356/utils/sonic_platform-1.0-py2-none-any.whl usr/share/sonic/device/x86_64-inventec_d6356-r0
systemd/platform-modules-d6356.service lib/systemd/system
common/blacklist /etc/modprobe.d/

0 comments on commit 2a84aa6

Please sign in to comment.