Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Freescale Semiconductor |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 6 | #include <common.h> |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 7 | #include <asm/io.h> |
| 8 | #include <asm/types.h> |
| 9 | #include <malloc.h> |
| 10 | #include <net.h> |
| 11 | #include <linux/compat.h> |
| 12 | #include <asm/arch/fsl_serdes.h> |
| 13 | #include <fsl-mc/ldpaa_wriop.h> |
| 14 | |
| 15 | struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS]; |
| 16 | |
| 17 | __weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc) |
| 18 | { |
Marek Behún | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 19 | return PHY_INTERFACE_MODE_NA; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl) |
| 23 | { |
| 24 | phy_interface_t enet_if; |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 25 | int phy_num; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 26 | |
Prabhakar Kushwaha | 316de87 | 2015-11-04 12:25:52 +0530 | [diff] [blame] | 27 | dpmac_info[dpmac_id].enabled = 0; |
| 28 | dpmac_info[dpmac_id].id = 0; |
Marek Behún | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 29 | dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NA; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 30 | |
Prabhakar Kushwaha | 316de87 | 2015-11-04 12:25:52 +0530 | [diff] [blame] | 31 | enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl); |
Marek Behún | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 32 | if (enet_if != PHY_INTERFACE_MODE_NA) { |
Prabhakar Kushwaha | 316de87 | 2015-11-04 12:25:52 +0530 | [diff] [blame] | 33 | dpmac_info[dpmac_id].enabled = 1; |
| 34 | dpmac_info[dpmac_id].id = dpmac_id; |
| 35 | dpmac_info[dpmac_id].enet_if = enet_if; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 36 | } |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 37 | for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) { |
| 38 | dpmac_info[dpmac_id].phydev[phy_num] = NULL; |
| 39 | dpmac_info[dpmac_id].phy_addr[phy_num] = -1; |
| 40 | } |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Ashish Kumar | ec455e2 | 2017-08-31 16:37:31 +0530 | [diff] [blame] | 43 | void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if) |
| 44 | { |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 45 | int phy_num; |
| 46 | |
Ashish Kumar | ec455e2 | 2017-08-31 16:37:31 +0530 | [diff] [blame] | 47 | dpmac_info[dpmac_id].enabled = 1; |
| 48 | dpmac_info[dpmac_id].id = dpmac_id; |
Ashish Kumar | ec455e2 | 2017-08-31 16:37:31 +0530 | [diff] [blame] | 49 | dpmac_info[dpmac_id].enet_if = enet_if; |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 50 | for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) { |
| 51 | dpmac_info[dpmac_id].phydev[phy_num] = NULL; |
| 52 | dpmac_info[dpmac_id].phy_addr[phy_num] = -1; |
| 53 | } |
Ashish Kumar | ec455e2 | 2017-08-31 16:37:31 +0530 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 57 | /*TODO what it do */ |
| 58 | static int wriop_dpmac_to_index(int dpmac_id) |
| 59 | { |
| 60 | int i; |
| 61 | |
| 62 | for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) { |
| 63 | if (dpmac_info[i].id == dpmac_id) |
| 64 | return i; |
| 65 | } |
| 66 | |
| 67 | return -1; |
| 68 | } |
| 69 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 70 | int wriop_disable_dpmac(int dpmac_id) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 71 | { |
| 72 | int i = wriop_dpmac_to_index(dpmac_id); |
| 73 | |
| 74 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 75 | return -ENODEV; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 76 | |
| 77 | dpmac_info[i].enabled = 0; |
| 78 | wriop_dpmac_disable(dpmac_id); |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 79 | |
| 80 | return 0; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 83 | int wriop_enable_dpmac(int dpmac_id) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 84 | { |
| 85 | int i = wriop_dpmac_to_index(dpmac_id); |
| 86 | |
| 87 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 88 | return -ENODEV; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 89 | |
| 90 | dpmac_info[i].enabled = 1; |
| 91 | wriop_dpmac_enable(dpmac_id); |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 92 | |
| 93 | return 0; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 96 | int wriop_is_enabled_dpmac(int dpmac_id) |
Prabhakar Kushwaha | ef55310 | 2015-11-04 12:25:56 +0530 | [diff] [blame] | 97 | { |
| 98 | int i = wriop_dpmac_to_index(dpmac_id); |
| 99 | |
| 100 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 101 | return -ENODEV; |
Prabhakar Kushwaha | ef55310 | 2015-11-04 12:25:56 +0530 | [diff] [blame] | 102 | |
| 103 | return dpmac_info[i].enabled; |
| 104 | } |
| 105 | |
| 106 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 107 | int wriop_set_mdio(int dpmac_id, struct mii_dev *bus) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 108 | { |
| 109 | int i = wriop_dpmac_to_index(dpmac_id); |
| 110 | |
| 111 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 112 | return -ENODEV; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 113 | |
| 114 | dpmac_info[i].bus = bus; |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 115 | |
| 116 | return 0; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | struct mii_dev *wriop_get_mdio(int dpmac_id) |
| 120 | { |
| 121 | int i = wriop_dpmac_to_index(dpmac_id); |
| 122 | |
| 123 | if (i == -1) |
| 124 | return NULL; |
| 125 | |
| 126 | return dpmac_info[i].bus; |
| 127 | } |
| 128 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 129 | int wriop_set_phy_address(int dpmac_id, int phy_num, int address) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 130 | { |
| 131 | int i = wriop_dpmac_to_index(dpmac_id); |
| 132 | |
| 133 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 134 | return -ENODEV; |
| 135 | if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM) |
| 136 | return -EINVAL; |
| 137 | |
| 138 | dpmac_info[i].phy_addr[phy_num] = address; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 139 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 140 | return 0; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 143 | int wriop_get_phy_address(int dpmac_id, int phy_num) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 144 | { |
| 145 | int i = wriop_dpmac_to_index(dpmac_id); |
| 146 | |
| 147 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 148 | return -ENODEV; |
| 149 | if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM) |
| 150 | return -EINVAL; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 151 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 152 | return dpmac_info[i].phy_addr[phy_num]; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 155 | int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 156 | { |
| 157 | int i = wriop_dpmac_to_index(dpmac_id); |
| 158 | |
| 159 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 160 | return -ENODEV; |
| 161 | if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM) |
| 162 | return -EINVAL; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 163 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 164 | dpmac_info[i].phydev[phy_num] = phydev; |
| 165 | |
| 166 | return 0; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 169 | struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 170 | { |
| 171 | int i = wriop_dpmac_to_index(dpmac_id); |
| 172 | |
| 173 | if (i == -1) |
| 174 | return NULL; |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 175 | if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM) |
| 176 | return NULL; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 177 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 178 | return dpmac_info[i].phydev[phy_num]; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | phy_interface_t wriop_get_enet_if(int dpmac_id) |
| 182 | { |
| 183 | int i = wriop_dpmac_to_index(dpmac_id); |
| 184 | |
| 185 | if (i == -1) |
Marek Behún | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 186 | return PHY_INTERFACE_MODE_NA; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 187 | |
| 188 | if (dpmac_info[i].enabled) |
| 189 | return dpmac_info[i].enet_if; |
| 190 | |
Marek Behún | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 191 | return PHY_INTERFACE_MODE_NA; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 192 | } |