This patch includes misc changes to already present Octeon MIPS C files files, which are necessary for the upcoming ethernet support.
The changes are mostly: - DM GPIO & I2C infrastructure - Coding style cleanup while reworking of the code Signed-off-by: Stefan Roese <s...@denx.de> --- arch/mips/mach-octeon/cvmx-bootmem.c | 3 +- arch/mips/mach-octeon/cvmx-helper-cfg.c | 67 +-- arch/mips/mach-octeon/cvmx-helper-fdt.c | 645 +++++++++--------------- arch/mips/mach-octeon/cvmx-helper.c | 45 +- 4 files changed, 279 insertions(+), 481 deletions(-) diff --git a/arch/mips/mach-octeon/cvmx-bootmem.c b/arch/mips/mach-octeon/cvmx-bootmem.c index 9bd644d68bd8..52e58b4c1761 100644 --- a/arch/mips/mach-octeon/cvmx-bootmem.c +++ b/arch/mips/mach-octeon/cvmx-bootmem.c @@ -1189,7 +1189,7 @@ s64 cvmx_bootmem_phy_mem_list_init(u64 mem_size, if (mem_size > OCTEON_DDR1_SIZE) { __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, OCTEON_DDR1_SIZE, 0); __cvmx_bootmem_phy_free(OCTEON_DDR2_BASE, - mem_size - OCTEON_DDR1_SIZE, 0); + mem_size - OCTEON_DDR2_BASE, 0); } else { __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, mem_size, 0); } @@ -1349,7 +1349,6 @@ s64 cvmx_bootmem_phy_mem_list_init_multi(u8 node_mask, addr += sizeof(struct cvmx_bootmem_named_block_desc); } - // test-only: DEBUG ifdef??? cvmx_bootmem_phy_list_print(); return 1; diff --git a/arch/mips/mach-octeon/cvmx-helper-cfg.c b/arch/mips/mach-octeon/cvmx-helper-cfg.c index 494108f0cdb7..c0b17c3914c3 100644 --- a/arch/mips/mach-octeon/cvmx-helper-cfg.c +++ b/arch/mips/mach-octeon/cvmx-helper-cfg.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Copyright (C) 2020 Marvell International Ltd. + * Copyright (C) 2020-2022 Marvell International Ltd. * * Helper Functions for the Configuration Framework */ @@ -100,7 +100,6 @@ static u64 cvmx_cfg_opts[CVMX_HELPER_CFG_OPT_MAX] = { static int cvmx_cfg_max_pko_engines; /* # of PKO DMA engines allocated */ static int cvmx_pko_queue_alloc(u64 port, int count); static void cvmx_init_port_cfg(void); -static const int dbg; int __cvmx_helper_cfg_pknd(int xiface, int index) { @@ -980,8 +979,6 @@ int __cvmx_helper_init_port_valid(void) rc = __cvmx_helper_parse_bgx_dt(fdt_addr); if (!rc) rc = __cvmx_fdt_parse_vsc7224(fdt_addr); - if (!rc) - rc = __cvmx_fdt_parse_avsp5410(fdt_addr); if (!rc && octeon_has_feature(OCTEON_FEATURE_BGX_XCV)) rc = __cvmx_helper_parse_bgx_rgmii_dt(fdt_addr); @@ -1036,7 +1033,6 @@ cvmx_import_config_t cvmx_import_app_config; int __cvmx_helper_init_port_config_data_local(void) { int rv = 0; - int dbg = 0; if (!port_cfg_data_initialized) cvmx_init_port_cfg(); @@ -1061,10 +1057,12 @@ int __cvmx_helper_init_port_config_data_local(void) } } } - if (dbg) { - cvmx_helper_cfg_show_cfg(); - cvmx_pko_queue_show(); - } + +#ifdef DEBUG + cvmx_helper_cfg_show_cfg(); + cvmx_pko_queue_show(); +#endif + return rv; } @@ -1077,9 +1075,8 @@ int cvmx_pko_alloc_iport_and_queues(int interface, int port, int port_cnt, int q { int rv, p, port_start, cnt; - if (dbg) - debug("%s: intf %d/%d pcnt %d qcnt %d\n", __func__, interface, port, port_cnt, - queue_cnt); + debug("%s: intf %d/%d pcnt %d qcnt %d\n", __func__, interface, port, port_cnt, + queue_cnt); if (!port_cfg_data_initialized) cvmx_init_port_cfg(); @@ -1122,6 +1119,7 @@ static void cvmx_init_port_cfg(void) struct cvmx_srio_port_param *sr; pcfg = &cvmx_cfg_port[node][i][j]; + memset(pcfg, 0, sizeof(*pcfg)); pcfg->port_fdt_node = CVMX_HELPER_CFG_INVALID_VALUE; @@ -1188,8 +1186,7 @@ int __cvmx_helper_init_port_config_data(int node) int pknd = 0, bpid = 0; const int use_static_config = 1; - if (dbg) - printf("%s:\n", __func__); + debug("%s:\n", __func__); if (!port_cfg_data_initialized) cvmx_init_port_cfg(); @@ -1295,10 +1292,11 @@ int __cvmx_helper_init_port_config_data(int node) __cvmx_helper_cfg_init_ipd2pko_cache(); } - if (dbg) { - cvmx_helper_cfg_show_cfg(); - cvmx_pko_queue_show(); - } +#ifdef DEBUG + cvmx_helper_cfg_show_cfg(); + cvmx_pko_queue_show(); +#endif + return rv; } @@ -1336,39 +1334,6 @@ int cvmx_helper_get_port_fdt_node_offset(int xiface, int index) return cvmx_cfg_port[xi.node][xi.interface][index].port_fdt_node; } -/** - * Search for a port based on its FDT node offset - * - * @param of_offset Node offset of port to search for - * @param[out] xiface xinterface of match - * @param[out] index port index of match - * - * Return: 0 if found, -1 if not found - */ -int cvmx_helper_cfg_get_xiface_index_by_fdt_node_offset(int of_offset, int *xiface, int *index) -{ - int iface; - int i; - int node; - struct cvmx_cfg_port_param *pcfg = NULL; - *xiface = -1; - *index = -1; - - for (node = 0; node < CVMX_MAX_NODES; node++) { - for (iface = 0; iface < CVMX_HELPER_MAX_IFACE; iface++) { - for (i = 0; i < CVMX_HELPER_CFG_MAX_PORT_PER_IFACE; i++) { - pcfg = &cvmx_cfg_port[node][iface][i]; - if (pcfg->valid && pcfg->port_fdt_node == of_offset) { - *xiface = cvmx_helper_node_interface_to_xiface(node, iface); - *index = i; - return 0; - } - } - } - } - return -1; -} - /** * @INTERNAL * Store the FDT node offset in the device tree of a phy diff --git a/arch/mips/mach-octeon/cvmx-helper-fdt.c b/arch/mips/mach-octeon/cvmx-helper-fdt.c index 3177dfb6e5ae..187c7fe65ac5 100644 --- a/arch/mips/mach-octeon/cvmx-helper-fdt.c +++ b/arch/mips/mach-octeon/cvmx-helper-fdt.c @@ -1,14 +1,17 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Copyright (C) 2020 Marvell International Ltd. + * Copyright (C) 2020-2022 Marvell International Ltd. * * FDT Helper functions similar to those provided to U-Boot. */ +#include <dm.h> +#include <i2c.h> #include <log.h> #include <malloc.h> #include <net.h> #include <linux/delay.h> +#include <asm-generic/gpio.h> #include <mach/cvmx-regs.h> #include <mach/cvmx-csr.h> @@ -19,35 +22,6 @@ #include <mach/cvmx-helper-board.h> #include <mach/cvmx-helper-cfg.h> #include <mach/cvmx-helper-fdt.h> -#include <mach/cvmx-helper-gpio.h> - -/** Structure used to get type of GPIO from device tree */ -struct gpio_compat { - char *compatible; /** Compatible string */ - enum cvmx_gpio_type type; /** Type */ - int8_t size; /** (max) Number of pins */ -}; - -#define GPIO_REG_PCA953X_IN 0 -#define GPIO_REG_PCA953X_OUT 1 -#define GPIO_REG_PCA953X_INVERT 2 -#define GPIO_REG_PCA953X_DIR 3 - -#define GPIO_REG_PCA957X_IN 0 -#define GPIO_REG_PCA957X_INVERT 1 -#define GPIO_REG_PCA957X_CFG 4 -#define GPIO_REG_PCA957X_OUT 5 - -enum cvmx_i2c_mux_type { I2C_MUX, I2C_SWITCH }; - -/** Structure used to get type of GPIO from device tree */ -struct mux_compat { - char *compatible; /** Compatible string */ - enum cvmx_i2c_bus_type type; /** Mux chip type */ - enum cvmx_i2c_mux_type mux_type; /** Type of mux */ - u8 enable; /** Enable bit for mux */ - u8 size; /** (max) Number of channels */ -}; /** * Local allocator to handle both SE and U-Boot that also zeroes out memory @@ -110,6 +84,28 @@ int cvmx_fdt_lookup_phandles(const void *fdt_addr, int node, return 0; } +int cvmx_ofnode_lookup_phandles(ofnode node, const char *prop_name, int *lenp, + ofnode *nodes) +{ + const u32 *phandles; + int count; + int i; + + phandles = ofnode_get_property(node, prop_name, &count); + if (!phandles || count < 0) + return -FDT_ERR_NOTFOUND; + + count /= 4; + if (count > *lenp) + count = *lenp; + + for (i = 0; i < count; i++) + nodes[i] = ofnode_get_by_phandle(fdt32_to_cpu(phandles[i])); + + *lenp = count; + return 0; +} + /** * Given a FDT node return the CPU node number * @@ -271,10 +267,10 @@ int cvmx_sfp_set_ipd_port(struct cvmx_fdt_sfp_info *sfp, int ipd_port) * * Return: 0 for success, -1 on error */ -static int cvmx_fdt_parse_vsc7224_channels(const void *fdt_addr, int of_offset, +static int cvmx_fdt_parse_vsc7224_channels(ofnode node, struct cvmx_vsc7224 *vsc7224) { - int parent_offset = of_offset; + struct ofnode_phandle_args phandle; int err = 0; int reg; int num_chan = 0; @@ -289,35 +285,33 @@ static int cvmx_fdt_parse_vsc7224_channels(const void *fdt_addr, int of_offset, bool is_tx; bool is_qsfp; const char *mac_str; + ofnode node_chan; - debug("%s(%p, %d, %s)\n", __func__, fdt_addr, of_offset, vsc7224->name); - do { - /* Walk through all channels */ - of_offset = fdt_node_offset_by_compatible(fdt_addr, of_offset, - "vitesse,vsc7224-channel"); - if (of_offset == -FDT_ERR_NOTFOUND) { - break; - } else if (of_offset < 0) { - debug("%s: Failed finding compatible channel\n", - __func__); - err = -1; + debug("%s(%x, %s)\n", __func__, ofnode_to_offset(node), vsc7224->name); + ofnode_for_each_compatible_node(node_chan, "vitesse,vsc7224-channel") { + if (!ofnode_valid(node_chan)) { + debug("%s: Error parsing FDT node %s\n", + __func__, ofnode_get_name(node)); break; } - if (fdt_parent_offset(fdt_addr, of_offset) != parent_offset) + + if (ofnode_to_offset(ofnode_get_parent(node_chan)) != + ofnode_to_offset(node)) break; - reg = cvmx_fdt_get_int(fdt_addr, of_offset, "reg", -1); + + reg = ofnode_get_addr(node_chan); if (reg < 0 || reg > 3) { debug("%s: channel reg is either not present or out of range\n", __func__); err = -1; break; } - is_tx = cvmx_fdt_get_bool(fdt_addr, of_offset, "direction-tx"); + is_tx = ofnode_read_bool(node_chan, "direction-tx"); debug("%s(%s): Adding %cx channel %d\n", __func__, vsc7224->name, is_tx ? 't' : 'r', reg); - tap_values = (const uint32_t *)fdt_getprop(fdt_addr, of_offset, "taps", &len); + tap_values = ofnode_get_property(node_chan, "taps", &len); if (!tap_values) { debug("%s: Error: no taps defined for vsc7224 channel %d\n", __func__, reg); @@ -351,11 +345,12 @@ static int cvmx_fdt_parse_vsc7224_channels(const void *fdt_addr, int of_offset, vsc7224->channel[reg] = channel; channel->num_taps = num_taps; channel->lane = reg; - channel->of_offset = of_offset; + channel->of_offset = ofnode_to_offset(node_chan); channel->is_tx = is_tx; - channel->pretap_disable = cvmx_fdt_get_bool(fdt_addr, of_offset, "pretap-disable"); - channel->posttap_disable = - cvmx_fdt_get_bool(fdt_addr, of_offset, "posttap-disable"); + channel->pretap_disable = ofnode_read_bool(node_chan, + "pretap-disable"); + channel->posttap_disable = ofnode_read_bool(node_chan, + "posttap-disable"); channel->vsc7224 = vsc7224; /* Read all the tap values */ for (i = 0; i < num_taps; i++) { @@ -371,9 +366,9 @@ static int cvmx_fdt_parse_vsc7224_channels(const void *fdt_addr, int of_offset, channel->ipd_port = -1; mac_str = "sfp-mac"; - if (fdt_getprop(fdt_addr, of_offset, mac_str, NULL)) { + if (ofnode_get_property(node_chan, mac_str, NULL)) { is_qsfp = false; - } else if (fdt_getprop(fdt_addr, of_offset, "qsfp-mac", NULL)) { + } else if (ofnode_get_property(node_chan, "qsfp-mac", NULL)) { is_qsfp = true; mac_str = "qsfp-mac"; } else { @@ -381,52 +376,59 @@ static int cvmx_fdt_parse_vsc7224_channels(const void *fdt_addr, int of_offset, vsc7224->name, reg); return -1; } - of_mac = cvmx_fdt_lookup_phandle(fdt_addr, of_offset, mac_str); - if (of_mac < 0) { + + err = ofnode_parse_phandle_with_args(node_chan, mac_str, NULL, + 0, 0, &phandle); + if (err) { debug("%s: Error %d with MAC %s phandle for %s\n", __func__, of_mac, mac_str, vsc7224->name); return -1; } - debug("%s: Found mac at offset %d\n", __func__, of_mac); - err = cvmx_helper_cfg_get_xiface_index_by_fdt_node_offset(of_mac, &xiface, &index); - if (!err) { - channel->xiface = xiface; - channel->index = index; - channel->ipd_port = cvmx_helper_get_ipd_port(xiface, index); - - debug("%s: Found MAC, xiface: 0x%x, index: %d, ipd port: %d\n", __func__, - xiface, index, channel->ipd_port); - if (channel->ipd_port >= 0) { - cvmx_helper_cfg_set_vsc7224_chan_info(xiface, index, channel); - debug("%s: Storing config channel for xiface 0x%x, index %d\n", - __func__, xiface, index); - } - sfp_info = cvmx_helper_cfg_get_sfp_info(xiface, index); - if (!sfp_info) { - debug("%s: Warning: no (Q)SFP+ slot found for xinterface 0x%x, index %d for channel %d\n", - __func__, xiface, index, channel->lane); - continue; - } + debug("%s: Found mac at %s\n", __func__, + ofnode_get_name(phandle.node)); + + xiface = (ofnode_get_addr(ofnode_get_parent(phandle.node)) + >> 24) & 0x0f; + index = ofnode_get_addr(phandle.node); + channel->xiface = xiface; + channel->index = index; + channel->ipd_port = cvmx_helper_get_ipd_port(xiface, index); + + debug("%s: Found MAC, xiface: 0x%x, index: %d, ipd port: %d\n", __func__, + xiface, index, channel->ipd_port); + if (channel->ipd_port >= 0) { + cvmx_helper_cfg_set_vsc7224_chan_info(xiface, index, channel); + debug("%s: Storing config channel for xiface 0x%x, index %d\n", + __func__, xiface, index); + } + sfp_info = cvmx_helper_cfg_get_sfp_info(xiface, index); + if (!sfp_info) { + debug("%s: Warning: no (Q)SFP+ slot found for xinterface 0x%x, index %d for channel %d\n", + __func__, xiface, index, channel->lane); + continue; + } - /* Link it */ - channel->next = sfp_info->vsc7224_chan; - if (sfp_info->vsc7224_chan) - sfp_info->vsc7224_chan->prev = channel; - sfp_info->vsc7224_chan = channel; - sfp_info->is_vsc7224 = true; - debug("%s: Registering VSC7224 %s channel %d with SFP %s\n", __func__, - vsc7224->name, channel->lane, sfp_info->name); - if (!sfp_info->mod_abs_changed) { - debug("%s: Registering cvmx_sfp_vsc7224_mod_abs_changed at %p for xinterface 0x%x, index %d\n", - __func__, &cvmx_sfp_vsc7224_mod_abs_changed, xiface, index); - cvmx_sfp_register_mod_abs_changed( - sfp_info, - &cvmx_sfp_vsc7224_mod_abs_changed, - NULL); - } + /* Link it */ + channel->next = sfp_info->vsc7224_chan; + if (sfp_info->vsc7224_chan) + sfp_info->vsc7224_chan->prev = channel; + sfp_info->vsc7224_chan = channel; + sfp_info->is_vsc7224 = true; + debug("%s: Registering VSC7224 %s channel %d with SFP %s\n", __func__, + vsc7224->name, channel->lane, sfp_info->name); + if (!sfp_info->mod_abs_changed) { + debug("%s: Registering cvmx_sfp_vsc7224_mod_abs_changed at %p for xinterface 0x%x, index %d\n", + __func__, &cvmx_sfp_vsc7224_mod_abs_changed, xiface, index); + cvmx_sfp_register_mod_abs_changed( + sfp_info, + &cvmx_sfp_vsc7224_mod_abs_changed, + NULL); } - } while (!err && num_chan < 4); + + if (num_chan >= 4) + break; + } return err; } @@ -441,12 +443,17 @@ static int cvmx_fdt_parse_vsc7224_channels(const void *fdt_addr, int of_offset, */ int __cvmx_fdt_parse_vsc7224(const void *fdt_addr) { - int of_offset = -1; struct cvmx_vsc7224 *vsc7224 = NULL; - struct cvmx_fdt_gpio_info *gpio_info = NULL; + ofnode node; int err = 0; - int of_parent; static bool parsed; + const int *init_array; + struct udevice *dev; + u16 value; + int reg; + int len; + int ret; + int i; debug("%s(%p)\n", __func__, fdt_addr); @@ -454,30 +461,23 @@ int __cvmx_fdt_parse_vsc7224(const void *fdt_addr) debug("%s: Already parsed\n", __func__); return 0; } - do { - of_offset = fdt_node_offset_by_compatible(fdt_addr, of_offset, - "vitesse,vsc7224"); - debug("%s: of_offset: %d\n", __func__, of_offset); - if (of_offset == -FDT_ERR_NOTFOUND) { - break; - } else if (of_offset < 0) { - err = -1; - debug("%s: Error %d parsing FDT\n", - __func__, of_offset); + + ofnode_for_each_compatible_node(node, "vitesse,vsc7224") { + if (!ofnode_valid(node)) { + debug("%s: Error parsing FDT node %s\n", + __func__, ofnode_get_name(node)); break; } vsc7224 = __cvmx_fdt_alloc(sizeof(*vsc7224)); - if (!vsc7224) { debug("%s: Out of memory!\n", __func__); return -1; } - vsc7224->of_offset = of_offset; - vsc7224->i2c_addr = cvmx_fdt_get_int(fdt_addr, of_offset, - "reg", -1); - of_parent = fdt_parent_offset(fdt_addr, of_offset); - vsc7224->i2c_bus = cvmx_fdt_get_i2c_bus(fdt_addr, of_parent); + + vsc7224->of_offset = ofnode_to_offset(node); + vsc7224->i2c_addr = ofnode_get_addr(node); + vsc7224->i2c_bus = cvmx_ofnode_get_i2c_bus(ofnode_get_parent(node)); if (vsc7224->i2c_addr < 0) { debug("%s: Error: reg field missing\n", __func__); err = -1; @@ -488,168 +488,90 @@ int __cvmx_fdt_parse_vsc7224(const void *fdt_addr) err = -1; break; } - vsc7224->name = fdt_get_name(fdt_addr, of_offset, NULL); + vsc7224->name = ofnode_get_name(node); debug("%s: Adding %s\n", __func__, vsc7224->name); - if (fdt_getprop(fdt_addr, of_offset, "reset", NULL)) { - gpio_info = cvmx_fdt_gpio_get_info_phandle(fdt_addr, of_offset, "reset"); - vsc7224->reset_gpio = gpio_info; - } - if (fdt_getprop(fdt_addr, of_offset, "los", NULL)) { - gpio_info = cvmx_fdt_gpio_get_info_phandle(fdt_addr, of_offset, "los"); - vsc7224->los_gpio = gpio_info; - } - debug("%s: Parsing channels\n", __func__); - err = cvmx_fdt_parse_vsc7224_channels(fdt_addr, of_offset, vsc7224); + + err = gpio_request_by_name_nodev(node, "reset", 0, + &vsc7224->reset_gpio, + GPIOD_IS_OUT); if (err) { - debug("%s: Error parsing VSC7224 channels\n", __func__); - break; + printf("%s: reset GPIO not found in DT!\n", __func__); + return -ENODEV; } - } while (of_offset > 0); - if (err) { - debug("%s(): Error\n", __func__); - if (vsc7224) { - if (vsc7224->reset_gpio) - __cvmx_fdt_free(vsc7224->reset_gpio, sizeof(*vsc7224->reset_gpio)); - if (vsc7224->los_gpio) - __cvmx_fdt_free(vsc7224->los_gpio, sizeof(*vsc7224->los_gpio)); - if (vsc7224->i2c_bus) - cvmx_fdt_free_i2c_bus(vsc7224->i2c_bus); - __cvmx_fdt_free(vsc7224, sizeof(*vsc7224)); + err = gpio_request_by_name_nodev(node, "los", 0, + &vsc7224->los_gpio, + GPIOD_IS_IN); + if (err) { + printf("%s: los GPIO not found in DT!\n", __func__); + return -ENODEV; } - } - if (!err) - parsed = true; - - return err; -} -/** - * @INTERNAL - * Parses all instances of the Avago AVSP5410 gearbox phy - * - * @param[in] fdt_addr Address of flat device tree - * - * Return: 0 for success, error otherwise - */ -int __cvmx_fdt_parse_avsp5410(const void *fdt_addr) -{ - int of_offset = -1; - struct cvmx_avsp5410 *avsp5410 = NULL; - struct cvmx_fdt_sfp_info *sfp_info; - int err = 0; - int of_parent; - static bool parsed; - int of_mac; - int xiface, index; - bool is_qsfp; - const char *mac_str; - - debug("%s(%p)\n", __func__, fdt_addr); - - if (parsed) { - debug("%s: Already parsed\n", __func__); - return 0; - } - - do { - of_offset = fdt_node_offset_by_compatible(fdt_addr, of_offset, - "avago,avsp-5410"); - debug("%s: of_offset: %d\n", __func__, of_offset); - if (of_offset == -FDT_ERR_NOTFOUND) { - break; - } else if (of_offset < 0) { - err = -1; - debug("%s: Error %d parsing FDT\n", __func__, of_offset); - break; + /* + * This code was taken from the NIC23 board specific code + * but should be better placed here in the common code + */ + debug("%s: Putting device in reset\n", __func__); + dm_gpio_set_value(&vsc7224->reset_gpio, 1); + mdelay(10); + debug("%s: Taking device out of reset\n", __func__); + dm_gpio_set_value(&vsc7224->reset_gpio, 0); + mdelay(50); + + init_array = ofnode_get_property(node, "vitesse,reg-init", + &len); + if (!init_array) { + debug("%s: No initialization array\n", __func__); + continue; } - - avsp5410 = __cvmx_fdt_alloc(sizeof(*avsp5410)); - - if (!avsp5410) { - debug("%s: Out of memory!\n", __func__); + if ((len % 8) != 0) { + printf("%s: Error: register init string should be an array of reg number followed by value\n", + __func__); return -1; } - avsp5410->of_offset = of_offset; - avsp5410->i2c_addr = cvmx_fdt_get_int(fdt_addr, of_offset, - "reg", -1); - of_parent = fdt_parent_offset(fdt_addr, of_offset); - avsp5410->i2c_bus = cvmx_fdt_get_i2c_bus(fdt_addr, of_parent); - if (avsp5410->i2c_addr < 0) { - debug("%s: Error: reg field missing\n", __func__); - err = -1; - break; - } - if (!avsp5410->i2c_bus) { - debug("%s: Error getting i2c bus\n", __func__); - err = -1; - break; - } - avsp5410->name = fdt_get_name(fdt_addr, of_offset, NULL); - debug("%s: Adding %s\n", __func__, avsp5410->name); - /* Now find out which interface it's mapped to */ - avsp5410->ipd_port = -1; - - mac_str = "sfp-mac"; - if (fdt_getprop(fdt_addr, of_offset, mac_str, NULL)) { - is_qsfp = false; - } else if (fdt_getprop(fdt_addr, of_offset, "qsfp-mac", NULL)) { - is_qsfp = true; - mac_str = "qsfp-mac"; - } else { - debug("%s: Error: MAC not found for %s\n", __func__, avsp5410->name); - return -1; - } - of_mac = cvmx_fdt_lookup_phandle(fdt_addr, of_offset, mac_str); - if (of_mac < 0) { - debug("%s: Error %d with MAC %s phandle for %s\n", __func__, of_mac, - mac_str, avsp5410->name); + ret = i2c_get_chip(vsc7224->i2c_bus->i2c_bus, + vsc7224->i2c_addr, 1, &dev); + if (ret) { + debug("Cannot find I2C device: %d\n", ret); return -1; } - debug("%s: Found mac at offset %d\n", __func__, of_mac); - err = cvmx_helper_cfg_get_xiface_index_by_fdt_node_offset(of_mac, &xiface, &index); - if (!err) { - avsp5410->xiface = xiface; - avsp5410->index = index; - avsp5410->ipd_port = cvmx_helper_get_ipd_port(xiface, index); - - debug("%s: Found MAC, xiface: 0x%x, index: %d, ipd port: %d\n", __func__, - xiface, index, avsp5410->ipd_port); - if (avsp5410->ipd_port >= 0) { - cvmx_helper_cfg_set_avsp5410_info(xiface, index, avsp5410); - debug("%s: Storing config phy for xiface 0x%x, index %d\n", - __func__, xiface, index); - } - sfp_info = cvmx_helper_cfg_get_sfp_info(xiface, index); - if (!sfp_info) { - debug("%s: Warning: no (Q)SFP+ slot found for xinterface 0x%x, index %d\n", - __func__, xiface, index); - continue; + for (i = 0; i < len / sizeof(int); i += 2) { + u8 buffer[2]; + + reg = fdt32_to_cpu(init_array[i]); + value = fdt32_to_cpu(init_array[i + 1]); + buffer[0] = value >> 8; + buffer[1] = value & 0xff; + ret = dm_i2c_write(dev, reg, buffer, 2); + if (ret) { + debug("Cannot write I2C device: %d\n", ret); + return -1; } - sfp_info->is_avsp5410 = true; - sfp_info->avsp5410 = avsp5410; - debug("%s: Registering AVSP5410 %s with SFP %s\n", __func__, avsp5410->name, - sfp_info->name); - if (!sfp_info->mod_abs_changed) { - debug("%s: Registering cvmx_sfp_avsp5410_mod_abs_changed at %p for xinterface 0x%x, index %d\n", - __func__, &cvmx_sfp_avsp5410_mod_abs_changed, xiface, index); - cvmx_sfp_register_mod_abs_changed( - sfp_info, - &cvmx_sfp_avsp5410_mod_abs_changed, - NULL); - } + debug(" Wrote 0x%02x <= 0x%02x%02x\n", reg, + buffer[0], buffer[1]); + } + + debug("%s: Parsing channels\n", __func__); + err = cvmx_fdt_parse_vsc7224_channels(node, vsc7224); + if (err) { + debug("%s: Error parsing VSC7224 channels\n", __func__); + break; } - } while (of_offset > 0); + } if (err) { debug("%s(): Error\n", __func__); - if (avsp5410) { - if (avsp5410->i2c_bus) - cvmx_fdt_free_i2c_bus(avsp5410->i2c_bus); - __cvmx_fdt_free(avsp5410, sizeof(*avsp5410)); + if (vsc7224) { + dm_gpio_free(vsc7224->reset_gpio.dev, + &vsc7224->reset_gpio); + dm_gpio_free(vsc7224->los_gpio.dev, + &vsc7224->los_gpio); + if (vsc7224->i2c_bus) + cvmx_fdt_free_i2c_bus(vsc7224->i2c_bus); + __cvmx_fdt_free(vsc7224, sizeof(*vsc7224)); } } if (!err) @@ -658,146 +580,6 @@ int __cvmx_fdt_parse_avsp5410(const void *fdt_addr) return err; } -/** - * Parse QSFP GPIOs for SFP - * - * @param[in] fdt_addr Pointer to flat device tree - * @param of_offset Offset of QSFP node - * @param[out] sfp_info Pointer to sfp info to fill in - * - * Return: 0 for success - */ -static int cvmx_parse_qsfp(const void *fdt_addr, int of_offset, struct cvmx_fdt_sfp_info *sfp_info) -{ - sfp_info->select = cvmx_fdt_gpio_get_info_phandle(fdt_addr, of_offset, "select"); - sfp_info->mod_abs = cvmx_fdt_gpio_get_info_phandle(fdt_addr, of_offset, "mod_prs"); - sfp_info->reset = cvmx_fdt_gpio_get_info_phandle(fdt_addr, of_offset, "reset"); - sfp_info->interrupt = cvmx_fdt_gpio_get_info_phandle(fdt_addr, of_offset, "interrupt"); - sfp_info->lp_mode = cvmx_fdt_gpio_get_info_phandle(fdt_addr, of_offset, "lp_mode"); - return 0; -} - -/** - * Parse SFP GPIOs for SFP - * - * @param[in] fdt_addr Pointer to flat device tree - * @param of_offset Offset of SFP node - * @param[out] sfp_info Pointer to sfp info to fill in - * - * Return: 0 for success - */ -static int cvmx_parse_sfp(const void *fdt_addr, int of_offset, struct cvmx_fdt_sfp_info *sfp_info) -{ - sfp_info->mod_abs = cvmx_fdt_gpio_get_info_phandle(fdt_addr, of_offset, "mod_abs"); - sfp_info->rx_los = cvmx_fdt_gpio_get_info_phandle(fdt_addr, of_offset, "rx_los"); - sfp_info->tx_disable = cvmx_fdt_gpio_get_info_phandle(fdt_addr, of_offset, "tx_disable"); - sfp_info->tx_error = cvmx_fdt_gpio_get_info_phandle(fdt_addr, of_offset, "tx_error"); - return 0; -} - -/** - * Parse SFP/QSFP EEPROM and diag - * - * @param[in] fdt_addr Pointer to flat device tree - * @param of_offset Offset of SFP node - * @param[out] sfp_info Pointer to sfp info to fill in - * - * Return: 0 for success, -1 on error - */ -static int cvmx_parse_sfp_eeprom(const void *fdt_addr, int of_offset, - struct cvmx_fdt_sfp_info *sfp_info) -{ - int of_eeprom; - int of_diag; - - debug("%s(%p, %d, %s)\n", __func__, fdt_addr, of_offset, sfp_info->name); - of_eeprom = cvmx_fdt_lookup_phandle(fdt_addr, of_offset, "eeprom"); - if (of_eeprom < 0) { - debug("%s: Missing \"eeprom\" from device tree for %s\n", __func__, sfp_info->name); - return -1; - } - - sfp_info->i2c_bus = cvmx_fdt_get_i2c_bus(fdt_addr, fdt_parent_offset(fdt_addr, of_eeprom)); - sfp_info->i2c_eeprom_addr = cvmx_fdt_get_int(fdt_addr, of_eeprom, "reg", 0x50); - - debug("%s(%p, %d, %s, %d)\n", __func__, fdt_addr, of_offset, sfp_info->name, - sfp_info->i2c_eeprom_addr); - - if (!sfp_info->i2c_bus) { - debug("%s: Error: could not determine i2c bus for eeprom for %s\n", __func__, - sfp_info->name); - return -1; - } - of_diag = cvmx_fdt_lookup_phandle(fdt_addr, of_offset, "diag"); - if (of_diag >= 0) - sfp_info->i2c_diag_addr = cvmx_fdt_get_int(fdt_addr, of_diag, "reg", 0x51); - else - sfp_info->i2c_diag_addr = 0x51; - return 0; -} - -/** - * Parse SFP information from device tree - * - * @param[in] fdt_addr Address of flat device tree - * - * Return: pointer to sfp info or NULL if error - */ -struct cvmx_fdt_sfp_info *cvmx_helper_fdt_parse_sfp_info(const void *fdt_addr, int of_offset) -{ - struct cvmx_fdt_sfp_info *sfp_info = NULL; - int err = -1; - bool is_qsfp; - - if (!fdt_node_check_compatible(fdt_addr, of_offset, "ethernet,sfp-slot")) { - is_qsfp = false; - } else if (!fdt_node_check_compatible(fdt_addr, of_offset, "ethernet,qsfp-slot")) { - is_qsfp = true; - } else { - debug("%s: Error: incompatible sfp/qsfp slot, compatible=%s\n", __func__, - (char *)fdt_getprop(fdt_addr, of_offset, "compatible", NULL)); - goto error_exit; - } - - debug("%s: %ssfp module found at offset %d\n", __func__, is_qsfp ? "q" : "", of_offset); - sfp_info = __cvmx_fdt_alloc(sizeof(*sfp_info)); - if (!sfp_info) { - debug("%s: Error: out of memory\n", __func__); - goto error_exit; - } - sfp_info->name = fdt_get_name(fdt_addr, of_offset, NULL); - sfp_info->of_offset = of_offset; - sfp_info->is_qsfp = is_qsfp; - sfp_info->last_mod_abs = -1; - sfp_info->last_rx_los = -1; - - if (is_qsfp) - err = cvmx_parse_qsfp(fdt_addr, of_offset, sfp_info); - else - err = cvmx_parse_sfp(fdt_addr, of_offset, sfp_info); - if (err) { - debug("%s: Error in %s parsing %ssfp GPIO info\n", __func__, sfp_info->name, - is_qsfp ? "q" : ""); - goto error_exit; - } - debug("%s: Parsing %ssfp module eeprom\n", __func__, is_qsfp ? "q" : ""); - err = cvmx_parse_sfp_eeprom(fdt_addr, of_offset, sfp_info); - if (err) { - debug("%s: Error parsing eeprom info for %s\n", __func__, sfp_info->name); - goto error_exit; - } - - /* Register default check for mod_abs changed */ - if (!err) - cvmx_sfp_register_check_mod_abs(sfp_info, cvmx_sfp_check_mod_abs, NULL); - -error_exit: - /* Note: we don't free any data structures on error since it gets - * rather complicated with i2c buses and whatnot. - */ - return err ? NULL : sfp_info; -} - /** * @INTERNAL * Parse a slice of the Inphi/Cortina CS4343 in the device tree @@ -968,3 +750,78 @@ int cvmx_fdt_parse_cs4343(const void *fdt_addr, int of_offset, struct cvmx_phy_i return err < 0 ? -1 : 0; } + +/** + * Given the parent offset of an i2c device build up a list describing the bus + * which can contain i2c muxes and switches. + * + * @param[in] node ofnode of the parent node of a GPIO device in + * the device tree. + * + * @return pointer to list of i2c devices starting from the root which + * can include i2c muxes and switches or NULL if error. Note that + * all entries are allocated on the heap. + * + * @see cvmx_fdt_free_i2c_bus() + */ +struct cvmx_fdt_i2c_bus_info *cvmx_ofnode_get_i2c_bus(ofnode node) +{ + struct cvmx_fdt_i2c_bus_info *businfo = NULL; + struct udevice *bus; + int ret; + + businfo = __cvmx_fdt_alloc(sizeof(*businfo)); + if (!businfo) { + debug("Out of memory\n"); + return NULL; + } + + debug("%s: Found node %s\n", __func__, ofnode_get_name(node)); + businfo->of_offset = ofnode_to_offset(node); + + /* + * Get I2C bus and probe it automatically - needed for later use + */ + ret = device_get_global_by_ofnode(node, &bus); + if (!bus || ret) { + printf("Cannot find a I2C bus\n"); + return NULL; + } + + businfo->i2c_bus = bus; + + return businfo; +} + +/** + * Return the Octeon bus number for a bus descriptor + * + * @param[in] bus bus descriptor + * + * @return Octeon twsi bus number or -1 on error + */ +int cvmx_fdt_i2c_get_root_bus(const struct cvmx_fdt_i2c_bus_info *bus) +{ + if (bus->type != CVMX_I2C_BUS_OCTEON) + return -1; + return bus->channel; +} + +/** + * Frees all entries for an i2c bus descriptor + * + * @param bus bus to free + * + * @return 0 + */ +int cvmx_fdt_free_i2c_bus(struct cvmx_fdt_i2c_bus_info *bus) +{ + struct cvmx_fdt_i2c_bus_info *last; + + while (bus) { + last = bus; + bus = bus->child; + __cvmx_fdt_free(last, sizeof(*last)); + } + return 0; +} diff --git a/arch/mips/mach-octeon/cvmx-helper.c b/arch/mips/mach-octeon/cvmx-helper.c index d0620d6cda0f..c7851717c05a 100644 --- a/arch/mips/mach-octeon/cvmx-helper.c +++ b/arch/mips/mach-octeon/cvmx-helper.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Copyright (C) 2020 Marvell International Ltd. + * Copyright (C) 2020-2022 Marvell International Ltd. * * Helper functions for common, but complicated tasks. */ @@ -302,20 +302,6 @@ static const struct iface_ops iface_ops_npi = { .enable = __cvmx_helper_npi_enable, }; -/** - * @INTERNAL - * This structure specifies the interface methods used by interfaces - * configured as srio. - */ -static const struct iface_ops iface_ops_srio = { - .mode = CVMX_HELPER_INTERFACE_MODE_SRIO, - .enumerate = __cvmx_helper_srio_probe, - .probe = __cvmx_helper_srio_probe, - .enable = __cvmx_helper_srio_enable, - .link_get = __cvmx_helper_srio_link_get, - .link_set = __cvmx_helper_srio_link_set, -}; - /** * @INTERNAL * This structure specifies the interface methods used by interfaces @@ -607,7 +593,7 @@ int __cvmx_helper_early_ports_on_interface(int interface) * chip and configuration, this can be 1-16. A value of 0 * specifies that the interface doesn't exist or isn't usable. * - * @param xiface xiface to get the port count for + * @param xiface to get the port count for * * Return: Number of ports on interface. Can be Zero. */ @@ -919,15 +905,9 @@ static cvmx_helper_interface_mode_t __cvmx_get_mode_cnf75xx(int xiface) break; } } else if ((interface < 3) && OCTEON_IS_MODEL(OCTEON_CNF75XX)) { - cvmx_sriox_status_reg_t sriox_status_reg; - int srio_port = interface - 1; - - sriox_status_reg.u64 = csr_rd(CVMX_SRIOX_STATUS_REG(srio_port)); - - if (sriox_status_reg.s.srio) - iface_ops[interface] = &iface_ops_srio; - else - iface_ops[interface] = &iface_ops_dis; + /* SRIO is disabled for now */ + printf("SRIO disabled for now!\n"); + iface_ops[interface] = &iface_ops_dis; } else if (interface == 3) { /* DPI */ iface_ops[interface] = &iface_ops_npi; } else if (interface == 4) { /* LOOP */ @@ -1046,7 +1026,6 @@ static cvmx_helper_interface_mode_t __cvmx_get_mode_octeon2(int interface) (OCTEON_IS_MODEL(OCTEON_CN66XX) && interface >= 4 && interface <= 7)) { /* Only present in CN63XX & CN66XX Octeon model */ - union cvmx_sriox_status_reg sriox_status_reg; /* cn66xx pass1.0 has only 2 SRIO interfaces. */ if ((interface == 5 || interface == 7) && @@ -1059,12 +1038,9 @@ static cvmx_helper_interface_mode_t __cvmx_get_mode_octeon2(int interface) */ iface_ops[interface] = &iface_ops_dis; } else { - sriox_status_reg.u64 = - csr_rd(CVMX_SRIOX_STATUS_REG(interface - 4)); - if (sriox_status_reg.s.srio) - iface_ops[interface] = &iface_ops_srio; - else - iface_ops[interface] = &iface_ops_dis; + /* SRIO is disabled for now */ + printf("SRIO disabled for now!\n"); + iface_ops[interface] = &iface_ops_dis; } } else if (OCTEON_IS_MODEL(OCTEON_CN66XX)) { union cvmx_mio_qlmx_cfg mio_qlm_cfg; @@ -1467,7 +1443,7 @@ int __cvmx_helper_packet_hardware_enable(int xiface) if (iface_node_ops[xi.node][xi.interface]->enable) result = iface_node_ops[xi.node][xi.interface]->enable(xiface); - result |= __cvmx_helper_board_hardware_enable(xiface); + return result; } @@ -1609,7 +1585,8 @@ int cvmx_helper_initialize_packet_io_node(unsigned int node) /* Skip invalid/disabled interfaces */ if (cvmx_helper_ports_on_interface(xiface) <= 0) continue; - printf("Node %d Interface %d has %d ports (%s)\n", node, interface, + debug("Node %d Interface %d has %d ports (%s)\n", + node, interface, cvmx_helper_ports_on_interface(xiface), cvmx_helper_interface_mode_to_string( cvmx_helper_interface_get_mode(xiface))); -- 2.35.1