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