blob: 926057a8ad54684fe1cc60a3e1bda6c77057a8a0 [file] [log] [blame]
Prabhakar Kushwaha2dd335f2015-03-20 19:28:22 -07001/*
2 * Copyright (C) 2015 Freescale Semiconductor
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <asm/types.h>
10#include <malloc.h>
11#include <net.h>
12#include <linux/compat.h>
13#include <asm/arch/fsl_serdes.h>
14#include <fsl-mc/ldpaa_wriop.h>
15
16struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];
17
18__weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
19{
20 return PHY_INTERFACE_MODE_NONE;
21}
22
23void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
24{
25 phy_interface_t enet_if;
26 int index = dpmac_id + sd * 8;
27
28 dpmac_info[index].enabled = 0;
29 dpmac_info[index].id = 0;
30 dpmac_info[index].enet_if = PHY_INTERFACE_MODE_NONE;
31
32 enet_if = wriop_dpmac_enet_if(index, lane_prtcl);
33 if (enet_if != PHY_INTERFACE_MODE_NONE) {
34 dpmac_info[index].enabled = 1;
35 dpmac_info[index].id = index;
36 dpmac_info[index].enet_if = enet_if;
37 }
38}
39
40/*TODO what it do */
41static int wriop_dpmac_to_index(int dpmac_id)
42{
43 int i;
44
45 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
46 if (dpmac_info[i].id == dpmac_id)
47 return i;
48 }
49
50 return -1;
51}
52
53void wriop_disable_dpmac(int dpmac_id)
54{
55 int i = wriop_dpmac_to_index(dpmac_id);
56
57 if (i == -1)
58 return;
59
60 dpmac_info[i].enabled = 0;
61 wriop_dpmac_disable(dpmac_id);
62}
63
64void wriop_enable_dpmac(int dpmac_id)
65{
66 int i = wriop_dpmac_to_index(dpmac_id);
67
68 if (i == -1)
69 return;
70
71 dpmac_info[i].enabled = 1;
72 wriop_dpmac_enable(dpmac_id);
73}
74
75void wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
76{
77 int i = wriop_dpmac_to_index(dpmac_id);
78
79 if (i == -1)
80 return;
81
82 dpmac_info[i].bus = bus;
83}
84
85struct mii_dev *wriop_get_mdio(int dpmac_id)
86{
87 int i = wriop_dpmac_to_index(dpmac_id);
88
89 if (i == -1)
90 return NULL;
91
92 return dpmac_info[i].bus;
93}
94
95void wriop_set_phy_address(int dpmac_id, int address)
96{
97 int i = wriop_dpmac_to_index(dpmac_id);
98
99 if (i == -1)
100 return;
101
102 dpmac_info[i].phy_addr = address;
103}
104
105int wriop_get_phy_address(int dpmac_id)
106{
107 int i = wriop_dpmac_to_index(dpmac_id);
108
109 if (i == -1)
110 return -1;
111
112 return dpmac_info[i].phy_addr;
113}
114
115void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
116{
117 int i = wriop_dpmac_to_index(dpmac_id);
118
119 if (i == -1)
120 return;
121
122 dpmac_info[i].phydev = phydev;
123}
124
125struct phy_device *wriop_get_phy_dev(int dpmac_id)
126{
127 int i = wriop_dpmac_to_index(dpmac_id);
128
129 if (i == -1)
130 return NULL;
131
132 return dpmac_info[i].phydev;
133}
134
135phy_interface_t wriop_get_enet_if(int dpmac_id)
136{
137 int i = wriop_dpmac_to_index(dpmac_id);
138
139 if (i == -1)
140 return PHY_INTERFACE_MODE_NONE;
141
142 if (dpmac_info[i].enabled)
143 return dpmac_info[i].enet_if;
144
145 return PHY_INTERFACE_MODE_NONE;
146}