2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-05-23 09:12:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015-2016 Marvell International Ltd.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Stefan Roese <sr@denx.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <fdtdec.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <asm/io.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2016-05-23 09:12:05 +00:00
|
|
|
#include <linux/errno.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <linux/libfdt.h>
|
2016-05-23 09:12:05 +00:00
|
|
|
|
2018-08-17 10:58:51 +00:00
|
|
|
#include "comphy_core.h"
|
2016-05-23 09:12:05 +00:00
|
|
|
|
|
|
|
#define COMPHY_MAX_CHIP 4
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2018-04-24 15:21:28 +00:00
|
|
|
static const char *get_speed_string(u32 speed)
|
2016-05-23 09:12:05 +00:00
|
|
|
{
|
2018-04-24 15:21:28 +00:00
|
|
|
static const char * const speed_strings[] = {
|
|
|
|
"1.25 Gbps", "1.5 Gbps", "2.5 Gbps",
|
2017-04-26 14:20:47 +00:00
|
|
|
"3.0 Gbps", "3.125 Gbps", "5 Gbps",
|
|
|
|
"5.125 Gpbs", "6 Gbps", "6.25 Gbps",
|
|
|
|
"10.3125 Gbps"
|
2018-04-24 15:21:28 +00:00
|
|
|
};
|
2016-05-23 09:12:05 +00:00
|
|
|
|
2017-04-26 12:40:00 +00:00
|
|
|
if (speed < 0 || speed > COMPHY_SPEED_MAX)
|
2016-05-23 09:12:05 +00:00
|
|
|
return "invalid";
|
|
|
|
|
|
|
|
return speed_strings[speed];
|
|
|
|
}
|
|
|
|
|
2018-04-24 15:21:28 +00:00
|
|
|
static const char *get_type_string(u32 type)
|
2016-05-23 09:12:05 +00:00
|
|
|
{
|
2018-04-24 15:21:28 +00:00
|
|
|
static const char * const type_strings[] = {
|
|
|
|
"UNCONNECTED", "PEX0", "PEX1", "PEX2", "PEX3",
|
|
|
|
"SATA0", "SATA1", "SATA2", "SATA3", "SGMII0",
|
2017-04-24 07:51:03 +00:00
|
|
|
"SGMII1", "SGMII2", "SGMII3", "QSGMII", "USB3"
|
2018-04-24 15:21:28 +00:00
|
|
|
"USB3_HOST0", "USB3_HOST1", "USB3_DEVICE",
|
|
|
|
"XAUI0", "XAUI1", "XAUI2", "XAUI3",
|
|
|
|
"RXAUI0", "RXAUI1", "SFI", "IGNORE"
|
|
|
|
};
|
2016-05-23 09:12:05 +00:00
|
|
|
|
2017-04-26 12:40:00 +00:00
|
|
|
if (type < 0 || type > COMPHY_TYPE_MAX)
|
2016-05-23 09:12:05 +00:00
|
|
|
return "invalid";
|
|
|
|
|
|
|
|
return type_strings[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
void comphy_print(struct chip_serdes_phy_config *chip_cfg,
|
|
|
|
struct comphy_map *comphy_map_data)
|
|
|
|
{
|
|
|
|
u32 lane;
|
|
|
|
|
|
|
|
for (lane = 0; lane < chip_cfg->comphy_lanes_count;
|
|
|
|
lane++, comphy_map_data++) {
|
2017-04-26 12:40:00 +00:00
|
|
|
if (comphy_map_data->speed == COMPHY_SPEED_INVALID) {
|
2016-05-23 09:12:05 +00:00
|
|
|
printf("Comphy-%d: %-13s\n", lane,
|
|
|
|
get_type_string(comphy_map_data->type));
|
|
|
|
} else {
|
|
|
|
printf("Comphy-%d: %-13s %-10s\n", lane,
|
|
|
|
get_type_string(comphy_map_data->type),
|
|
|
|
get_speed_string(comphy_map_data->speed));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-23 10:57:57 +00:00
|
|
|
int comphy_rx_training(struct udevice *dev, u32 lane)
|
|
|
|
{
|
|
|
|
struct chip_serdes_phy_config *chip_cfg = dev_get_priv(dev);
|
|
|
|
|
|
|
|
if (chip_cfg->rx_training)
|
|
|
|
return chip_cfg->rx_training(chip_cfg, lane);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-17 10:58:51 +00:00
|
|
|
__weak int comphy_update_map(struct comphy_map *serdes_map, int count)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-23 09:12:05 +00:00
|
|
|
static int comphy_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
const void *blob = gd->fdt_blob;
|
2017-01-17 23:52:55 +00:00
|
|
|
int node = dev_of_offset(dev);
|
2016-05-23 09:12:05 +00:00
|
|
|
struct chip_serdes_phy_config *chip_cfg = dev_get_priv(dev);
|
|
|
|
int subnode;
|
|
|
|
int lane;
|
2016-10-25 16:16:25 +00:00
|
|
|
int last_idx = 0;
|
2017-04-19 10:37:59 +00:00
|
|
|
static int current_idx;
|
2018-08-17 10:58:51 +00:00
|
|
|
int res;
|
2016-05-23 09:12:05 +00:00
|
|
|
|
|
|
|
/* Save base addresses for later use */
|
2017-05-17 23:18:05 +00:00
|
|
|
chip_cfg->comphy_base_addr = (void *)devfdt_get_addr_index(dev, 0);
|
2016-05-23 09:12:05 +00:00
|
|
|
if (IS_ERR(chip_cfg->comphy_base_addr))
|
|
|
|
return PTR_ERR(chip_cfg->comphy_base_addr);
|
|
|
|
|
2017-05-17 23:18:05 +00:00
|
|
|
chip_cfg->hpipe3_base_addr = (void *)devfdt_get_addr_index(dev, 1);
|
2016-05-23 09:12:05 +00:00
|
|
|
if (IS_ERR(chip_cfg->hpipe3_base_addr))
|
|
|
|
return PTR_ERR(chip_cfg->hpipe3_base_addr);
|
|
|
|
|
|
|
|
chip_cfg->comphy_lanes_count = fdtdec_get_int(blob, node,
|
|
|
|
"max-lanes", 0);
|
|
|
|
if (chip_cfg->comphy_lanes_count <= 0) {
|
2020-09-15 14:45:02 +00:00
|
|
|
dev_err(dev, "comphy max lanes is wrong\n");
|
2016-05-23 09:12:05 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
chip_cfg->comphy_mux_bitcount = fdtdec_get_int(blob, node,
|
|
|
|
"mux-bitcount", 0);
|
|
|
|
if (chip_cfg->comphy_mux_bitcount <= 0) {
|
2020-09-15 14:45:02 +00:00
|
|
|
dev_err(dev, "comphy mux bit count is wrong\n");
|
2016-05-23 09:12:05 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-04-24 15:21:21 +00:00
|
|
|
chip_cfg->comphy_mux_lane_order =
|
|
|
|
fdtdec_locate_array(blob, node, "mux-lane-order",
|
|
|
|
chip_cfg->comphy_lanes_count);
|
|
|
|
|
2021-03-23 10:57:57 +00:00
|
|
|
if (device_is_compatible(dev, "marvell,comphy-armada-3700")) {
|
2016-05-23 09:12:05 +00:00
|
|
|
chip_cfg->ptr_comphy_chip_init = comphy_a3700_init;
|
2021-03-23 10:57:57 +00:00
|
|
|
chip_cfg->rx_training = NULL;
|
|
|
|
}
|
2016-05-23 09:12:05 +00:00
|
|
|
|
2021-03-23 10:57:57 +00:00
|
|
|
if (device_is_compatible(dev, "marvell,comphy-cp110")) {
|
2016-08-30 14:48:20 +00:00
|
|
|
chip_cfg->ptr_comphy_chip_init = comphy_cp110_init;
|
2021-03-23 10:57:57 +00:00
|
|
|
chip_cfg->rx_training = comphy_cp110_sfi_rx_training;
|
|
|
|
}
|
2016-08-30 14:48:20 +00:00
|
|
|
|
2016-05-23 09:12:05 +00:00
|
|
|
/*
|
|
|
|
* Bail out if no chip_init function is defined, e.g. no
|
|
|
|
* compatible node is found
|
|
|
|
*/
|
|
|
|
if (!chip_cfg->ptr_comphy_chip_init) {
|
2020-09-15 14:45:02 +00:00
|
|
|
dev_err(dev, "comphy: No compatible DT node found\n");
|
2016-05-23 09:12:05 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
lane = 0;
|
2016-10-02 23:59:29 +00:00
|
|
|
fdt_for_each_subnode(subnode, blob, node) {
|
2016-05-23 09:12:05 +00:00
|
|
|
/* Skip disabled ports */
|
|
|
|
if (!fdtdec_get_is_enabled(blob, subnode))
|
|
|
|
continue;
|
|
|
|
|
2017-08-21 13:58:21 +00:00
|
|
|
chip_cfg->comphy_map_data[lane].type =
|
2017-08-22 08:14:22 +00:00
|
|
|
fdtdec_get_int(blob, subnode, "phy-type",
|
|
|
|
COMPHY_TYPE_INVALID);
|
|
|
|
|
2017-08-21 13:58:21 +00:00
|
|
|
if (chip_cfg->comphy_map_data[lane].type ==
|
|
|
|
COMPHY_TYPE_INVALID) {
|
2016-05-23 09:12:05 +00:00
|
|
|
printf("no phy type for lane %d, setting lane as unconnected\n",
|
|
|
|
lane + 1);
|
2017-08-22 08:14:22 +00:00
|
|
|
continue;
|
2016-05-23 09:12:05 +00:00
|
|
|
}
|
|
|
|
|
2017-08-21 13:58:21 +00:00
|
|
|
chip_cfg->comphy_map_data[lane].speed =
|
2017-08-22 08:14:22 +00:00
|
|
|
fdtdec_get_int(blob, subnode, "phy-speed",
|
|
|
|
COMPHY_SPEED_INVALID);
|
|
|
|
|
2017-08-21 13:58:21 +00:00
|
|
|
chip_cfg->comphy_map_data[lane].invert =
|
2017-08-22 08:14:22 +00:00
|
|
|
fdtdec_get_int(blob, subnode, "phy-invert",
|
|
|
|
COMPHY_POLARITY_NO_INVERT);
|
|
|
|
|
2017-08-21 13:58:21 +00:00
|
|
|
chip_cfg->comphy_map_data[lane].clk_src =
|
2017-08-22 08:14:22 +00:00
|
|
|
fdtdec_get_bool(blob, subnode, "clk-src");
|
|
|
|
|
2017-08-21 13:58:21 +00:00
|
|
|
chip_cfg->comphy_map_data[lane].end_point =
|
2017-08-22 08:14:22 +00:00
|
|
|
fdtdec_get_bool(blob, subnode, "end_point");
|
|
|
|
|
2016-05-23 09:12:05 +00:00
|
|
|
lane++;
|
|
|
|
}
|
|
|
|
|
2017-08-21 13:58:21 +00:00
|
|
|
res = comphy_update_map(chip_cfg->comphy_map_data, chip_cfg->comphy_lanes_count);
|
2018-08-17 10:58:51 +00:00
|
|
|
if (res < 0)
|
|
|
|
return res;
|
|
|
|
|
2017-04-24 15:45:32 +00:00
|
|
|
/* Save CP index for MultiCP devices (A8K) */
|
|
|
|
chip_cfg->cp_index = current_idx++;
|
2016-05-23 09:12:05 +00:00
|
|
|
/* PHY power UP sequence */
|
2017-08-21 13:58:21 +00:00
|
|
|
chip_cfg->ptr_comphy_chip_init(chip_cfg, chip_cfg->comphy_map_data);
|
2016-05-23 09:12:05 +00:00
|
|
|
/* PHY print SerDes status */
|
2017-12-03 13:13:08 +00:00
|
|
|
printf("Comphy chip #%d:\n", chip_cfg->cp_index);
|
2017-08-21 13:58:21 +00:00
|
|
|
comphy_print(chip_cfg, chip_cfg->comphy_map_data);
|
2016-05-23 09:12:05 +00:00
|
|
|
|
2016-10-25 16:16:25 +00:00
|
|
|
/*
|
|
|
|
* Only run the dedicated PHY init code once, in the last PHY init call
|
|
|
|
*/
|
|
|
|
if (of_machine_is_compatible("marvell,armada8040"))
|
|
|
|
last_idx = 1;
|
|
|
|
|
2017-04-24 15:45:32 +00:00
|
|
|
if (chip_cfg->cp_index == last_idx) {
|
2016-10-25 16:16:25 +00:00
|
|
|
/* Initialize dedicated PHYs (not muxed SerDes lanes) */
|
|
|
|
comphy_dedicated_phys_init();
|
|
|
|
}
|
2016-05-23 09:12:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id comphy_ids[] = {
|
|
|
|
{ .compatible = "marvell,mvebu-comphy" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(mvebu_comphy) = {
|
|
|
|
.name = "mvebu_comphy",
|
|
|
|
.id = UCLASS_MISC,
|
|
|
|
.of_match = comphy_ids,
|
|
|
|
.probe = comphy_probe,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct chip_serdes_phy_config),
|
2016-05-23 09:12:05 +00:00
|
|
|
};
|