2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-03-21 02:28:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Freescale Semiconductor
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/types.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <net.h>
|
|
|
|
#include <linux/compat.h>
|
|
|
|
#include <asm/arch/fsl_serdes.h>
|
|
|
|
#include <fsl-mc/ldpaa_wriop.h>
|
|
|
|
|
|
|
|
struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];
|
|
|
|
|
|
|
|
__weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
|
|
|
|
{
|
2022-04-06 22:33:03 +00:00
|
|
|
return PHY_INTERFACE_MODE_NA;
|
2015-03-21 02:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
|
|
|
|
{
|
|
|
|
phy_interface_t enet_if;
|
2018-10-10 08:38:34 +00:00
|
|
|
int phy_num;
|
2015-03-21 02:28:22 +00:00
|
|
|
|
2015-11-04 06:55:52 +00:00
|
|
|
dpmac_info[dpmac_id].enabled = 0;
|
|
|
|
dpmac_info[dpmac_id].id = 0;
|
2022-04-06 22:33:03 +00:00
|
|
|
dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NA;
|
2015-03-21 02:28:22 +00:00
|
|
|
|
2015-11-04 06:55:52 +00:00
|
|
|
enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
|
2022-04-06 22:33:03 +00:00
|
|
|
if (enet_if != PHY_INTERFACE_MODE_NA) {
|
2015-11-04 06:55:52 +00:00
|
|
|
dpmac_info[dpmac_id].enabled = 1;
|
|
|
|
dpmac_info[dpmac_id].id = dpmac_id;
|
|
|
|
dpmac_info[dpmac_id].enet_if = enet_if;
|
2015-03-21 02:28:22 +00:00
|
|
|
}
|
2018-10-10 08:38:34 +00:00
|
|
|
for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
|
|
|
|
dpmac_info[dpmac_id].phydev[phy_num] = NULL;
|
|
|
|
dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
|
|
|
|
}
|
2015-03-21 02:28:22 +00:00
|
|
|
}
|
|
|
|
|
2017-08-31 11:07:31 +00:00
|
|
|
void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
|
|
|
|
{
|
2018-10-10 08:38:34 +00:00
|
|
|
int phy_num;
|
|
|
|
|
2017-08-31 11:07:31 +00:00
|
|
|
dpmac_info[dpmac_id].enabled = 1;
|
|
|
|
dpmac_info[dpmac_id].id = dpmac_id;
|
|
|
|
dpmac_info[dpmac_id].enet_if = enet_if;
|
2018-10-10 08:38:34 +00:00
|
|
|
for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
|
|
|
|
dpmac_info[dpmac_id].phydev[phy_num] = NULL;
|
|
|
|
dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
|
|
|
|
}
|
2017-08-31 11:07:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-21 02:28:22 +00:00
|
|
|
/*TODO what it do */
|
|
|
|
static int wriop_dpmac_to_index(int dpmac_id)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
|
|
|
|
if (dpmac_info[i].id == dpmac_id)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-10-10 08:38:34 +00:00
|
|
|
int wriop_disable_dpmac(int dpmac_id)
|
2015-03-21 02:28:22 +00:00
|
|
|
{
|
|
|
|
int i = wriop_dpmac_to_index(dpmac_id);
|
|
|
|
|
|
|
|
if (i == -1)
|
2018-10-10 08:38:34 +00:00
|
|
|
return -ENODEV;
|
2015-03-21 02:28:22 +00:00
|
|
|
|
|
|
|
dpmac_info[i].enabled = 0;
|
|
|
|
wriop_dpmac_disable(dpmac_id);
|
2018-10-10 08:38:34 +00:00
|
|
|
|
|
|
|
return 0;
|
2015-03-21 02:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 08:38:34 +00:00
|
|
|
int wriop_enable_dpmac(int dpmac_id)
|
2015-03-21 02:28:22 +00:00
|
|
|
{
|
|
|
|
int i = wriop_dpmac_to_index(dpmac_id);
|
|
|
|
|
|
|
|
if (i == -1)
|
2018-10-10 08:38:34 +00:00
|
|
|
return -ENODEV;
|
2015-03-21 02:28:22 +00:00
|
|
|
|
|
|
|
dpmac_info[i].enabled = 1;
|
|
|
|
wriop_dpmac_enable(dpmac_id);
|
2018-10-10 08:38:34 +00:00
|
|
|
|
|
|
|
return 0;
|
2015-03-21 02:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 08:38:34 +00:00
|
|
|
int wriop_is_enabled_dpmac(int dpmac_id)
|
2015-11-04 06:55:56 +00:00
|
|
|
{
|
|
|
|
int i = wriop_dpmac_to_index(dpmac_id);
|
|
|
|
|
|
|
|
if (i == -1)
|
2018-10-10 08:38:34 +00:00
|
|
|
return -ENODEV;
|
2015-11-04 06:55:56 +00:00
|
|
|
|
|
|
|
return dpmac_info[i].enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-10 08:38:34 +00:00
|
|
|
int wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
|
2015-03-21 02:28:22 +00:00
|
|
|
{
|
|
|
|
int i = wriop_dpmac_to_index(dpmac_id);
|
|
|
|
|
|
|
|
if (i == -1)
|
2018-10-10 08:38:34 +00:00
|
|
|
return -ENODEV;
|
2015-03-21 02:28:22 +00:00
|
|
|
|
|
|
|
dpmac_info[i].bus = bus;
|
2018-10-10 08:38:34 +00:00
|
|
|
|
|
|
|
return 0;
|
2015-03-21 02:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct mii_dev *wriop_get_mdio(int dpmac_id)
|
|
|
|
{
|
|
|
|
int i = wriop_dpmac_to_index(dpmac_id);
|
|
|
|
|
|
|
|
if (i == -1)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return dpmac_info[i].bus;
|
|
|
|
}
|
|
|
|
|
2018-10-10 08:38:34 +00:00
|
|
|
int wriop_set_phy_address(int dpmac_id, int phy_num, int address)
|
2015-03-21 02:28:22 +00:00
|
|
|
{
|
|
|
|
int i = wriop_dpmac_to_index(dpmac_id);
|
|
|
|
|
|
|
|
if (i == -1)
|
2018-10-10 08:38:34 +00:00
|
|
|
return -ENODEV;
|
|
|
|
if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
dpmac_info[i].phy_addr[phy_num] = address;
|
2015-03-21 02:28:22 +00:00
|
|
|
|
2018-10-10 08:38:34 +00:00
|
|
|
return 0;
|
2015-03-21 02:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 08:38:34 +00:00
|
|
|
int wriop_get_phy_address(int dpmac_id, int phy_num)
|
2015-03-21 02:28:22 +00:00
|
|
|
{
|
|
|
|
int i = wriop_dpmac_to_index(dpmac_id);
|
|
|
|
|
|
|
|
if (i == -1)
|
2018-10-10 08:38:34 +00:00
|
|
|
return -ENODEV;
|
|
|
|
if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
|
|
|
|
return -EINVAL;
|
2015-03-21 02:28:22 +00:00
|
|
|
|
2018-10-10 08:38:34 +00:00
|
|
|
return dpmac_info[i].phy_addr[phy_num];
|
2015-03-21 02:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 08:38:34 +00:00
|
|
|
int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev)
|
2015-03-21 02:28:22 +00:00
|
|
|
{
|
|
|
|
int i = wriop_dpmac_to_index(dpmac_id);
|
|
|
|
|
|
|
|
if (i == -1)
|
2018-10-10 08:38:34 +00:00
|
|
|
return -ENODEV;
|
|
|
|
if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
|
|
|
|
return -EINVAL;
|
2015-03-21 02:28:22 +00:00
|
|
|
|
2018-10-10 08:38:34 +00:00
|
|
|
dpmac_info[i].phydev[phy_num] = phydev;
|
|
|
|
|
|
|
|
return 0;
|
2015-03-21 02:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 08:38:34 +00:00
|
|
|
struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
|
2015-03-21 02:28:22 +00:00
|
|
|
{
|
|
|
|
int i = wriop_dpmac_to_index(dpmac_id);
|
|
|
|
|
|
|
|
if (i == -1)
|
|
|
|
return NULL;
|
2018-10-10 08:38:34 +00:00
|
|
|
if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
|
|
|
|
return NULL;
|
2015-03-21 02:28:22 +00:00
|
|
|
|
2018-10-10 08:38:34 +00:00
|
|
|
return dpmac_info[i].phydev[phy_num];
|
2015-03-21 02:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
phy_interface_t wriop_get_enet_if(int dpmac_id)
|
|
|
|
{
|
|
|
|
int i = wriop_dpmac_to_index(dpmac_id);
|
|
|
|
|
|
|
|
if (i == -1)
|
2022-04-06 22:33:03 +00:00
|
|
|
return PHY_INTERFACE_MODE_NA;
|
2015-03-21 02:28:22 +00:00
|
|
|
|
|
|
|
if (dpmac_info[i].enabled)
|
|
|
|
return dpmac_info[i].enet_if;
|
|
|
|
|
2022-04-06 22:33:03 +00:00
|
|
|
return PHY_INTERFACE_MODE_NA;
|
2015-03-21 02:28:22 +00:00
|
|
|
}
|