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 | |
| 6 | #include <common.h> |
| 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 | { |
| 19 | return PHY_INTERFACE_MODE_NONE; |
| 20 | } |
| 21 | |
| 22 | void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl) |
| 23 | { |
| 24 | phy_interface_t enet_if; |
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; |
Prabhakar Kushwaha | ef55310 | 2015-11-04 12:25:56 +0530 | [diff] [blame] | 28 | dpmac_info[dpmac_id].phy_addr = -1; |
Prabhakar Kushwaha | 316de87 | 2015-11-04 12:25:52 +0530 | [diff] [blame] | 29 | dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE; |
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); |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 32 | if (enet_if != PHY_INTERFACE_MODE_NONE) { |
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 | } |
| 37 | } |
| 38 | |
Ashish Kumar | ec455e2 | 2017-08-31 16:37:31 +0530 | [diff] [blame] | 39 | void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if) |
| 40 | { |
| 41 | dpmac_info[dpmac_id].enabled = 1; |
| 42 | dpmac_info[dpmac_id].id = dpmac_id; |
| 43 | dpmac_info[dpmac_id].phy_addr = -1; |
| 44 | dpmac_info[dpmac_id].enet_if = enet_if; |
| 45 | } |
| 46 | |
| 47 | |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 48 | /*TODO what it do */ |
| 49 | static int wriop_dpmac_to_index(int dpmac_id) |
| 50 | { |
| 51 | int i; |
| 52 | |
| 53 | for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) { |
| 54 | if (dpmac_info[i].id == dpmac_id) |
| 55 | return i; |
| 56 | } |
| 57 | |
| 58 | return -1; |
| 59 | } |
| 60 | |
| 61 | void wriop_disable_dpmac(int dpmac_id) |
| 62 | { |
| 63 | int i = wriop_dpmac_to_index(dpmac_id); |
| 64 | |
| 65 | if (i == -1) |
| 66 | return; |
| 67 | |
| 68 | dpmac_info[i].enabled = 0; |
| 69 | wriop_dpmac_disable(dpmac_id); |
| 70 | } |
| 71 | |
| 72 | void wriop_enable_dpmac(int dpmac_id) |
| 73 | { |
| 74 | int i = wriop_dpmac_to_index(dpmac_id); |
| 75 | |
| 76 | if (i == -1) |
| 77 | return; |
| 78 | |
| 79 | dpmac_info[i].enabled = 1; |
| 80 | wriop_dpmac_enable(dpmac_id); |
| 81 | } |
| 82 | |
Prabhakar Kushwaha | ef55310 | 2015-11-04 12:25:56 +0530 | [diff] [blame] | 83 | u8 wriop_is_enabled_dpmac(int dpmac_id) |
| 84 | { |
| 85 | int i = wriop_dpmac_to_index(dpmac_id); |
| 86 | |
| 87 | if (i == -1) |
| 88 | return -1; |
| 89 | |
| 90 | return dpmac_info[i].enabled; |
| 91 | } |
| 92 | |
| 93 | |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 94 | void wriop_set_mdio(int dpmac_id, struct mii_dev *bus) |
| 95 | { |
| 96 | int i = wriop_dpmac_to_index(dpmac_id); |
| 97 | |
| 98 | if (i == -1) |
| 99 | return; |
| 100 | |
| 101 | dpmac_info[i].bus = bus; |
| 102 | } |
| 103 | |
| 104 | struct mii_dev *wriop_get_mdio(int dpmac_id) |
| 105 | { |
| 106 | int i = wriop_dpmac_to_index(dpmac_id); |
| 107 | |
| 108 | if (i == -1) |
| 109 | return NULL; |
| 110 | |
| 111 | return dpmac_info[i].bus; |
| 112 | } |
| 113 | |
| 114 | void wriop_set_phy_address(int dpmac_id, int address) |
| 115 | { |
| 116 | int i = wriop_dpmac_to_index(dpmac_id); |
| 117 | |
| 118 | if (i == -1) |
| 119 | return; |
| 120 | |
| 121 | dpmac_info[i].phy_addr = address; |
| 122 | } |
| 123 | |
| 124 | int wriop_get_phy_address(int dpmac_id) |
| 125 | { |
| 126 | int i = wriop_dpmac_to_index(dpmac_id); |
| 127 | |
| 128 | if (i == -1) |
| 129 | return -1; |
| 130 | |
| 131 | return dpmac_info[i].phy_addr; |
| 132 | } |
| 133 | |
| 134 | void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev) |
| 135 | { |
| 136 | int i = wriop_dpmac_to_index(dpmac_id); |
| 137 | |
| 138 | if (i == -1) |
| 139 | return; |
| 140 | |
| 141 | dpmac_info[i].phydev = phydev; |
| 142 | } |
| 143 | |
| 144 | struct phy_device *wriop_get_phy_dev(int dpmac_id) |
| 145 | { |
| 146 | int i = wriop_dpmac_to_index(dpmac_id); |
| 147 | |
| 148 | if (i == -1) |
| 149 | return NULL; |
| 150 | |
| 151 | return dpmac_info[i].phydev; |
| 152 | } |
| 153 | |
| 154 | phy_interface_t wriop_get_enet_if(int dpmac_id) |
| 155 | { |
| 156 | int i = wriop_dpmac_to_index(dpmac_id); |
| 157 | |
| 158 | if (i == -1) |
| 159 | return PHY_INTERFACE_MODE_NONE; |
| 160 | |
| 161 | if (dpmac_info[i].enabled) |
| 162 | return dpmac_info[i].enet_if; |
| 163 | |
| 164 | return PHY_INTERFACE_MODE_NONE; |
| 165 | } |