xref: /openbmc/u-boot/board/gdsys/common/miiphybb.c (revision 393cb361)
1 /*
2  * (C) Copyright 2010
3  * Dirk Eibach,  Guntermann & Drunck GmbH, eibach@gdsys.de
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23 
24 #include <common.h>
25 #include <miiphy.h>
26 
27 #include <asm/io.h>
28 
29 struct io_bb_pinset {
30 	int mdio;
31 	int mdc;
32 };
33 
34 static int io_bb_mii_init(struct bb_miiphy_bus *bus)
35 {
36 	return 0;
37 }
38 
39 static int io_bb_mdio_active(struct bb_miiphy_bus *bus)
40 {
41 	struct io_bb_pinset *pins = bus->priv;
42 
43 	out_be32((void *)GPIO0_TCR,
44 		in_be32((void *)GPIO0_TCR) | pins->mdio);
45 
46 	return 0;
47 }
48 
49 static int io_bb_mdio_tristate(struct bb_miiphy_bus *bus)
50 {
51 	struct io_bb_pinset *pins = bus->priv;
52 
53 	out_be32((void *)GPIO0_TCR,
54 		in_be32((void *)GPIO0_TCR) & ~pins->mdio);
55 
56 	return 0;
57 }
58 
59 static int io_bb_set_mdio(struct bb_miiphy_bus *bus, int v)
60 {
61 	struct io_bb_pinset *pins = bus->priv;
62 
63 	if (v)
64 		out_be32((void *)GPIO0_OR,
65 			in_be32((void *)GPIO0_OR) | pins->mdio);
66 	else
67 		out_be32((void *)GPIO0_OR,
68 			in_be32((void *)GPIO0_OR) & ~pins->mdio);
69 
70 	return 0;
71 }
72 
73 static int io_bb_get_mdio(struct bb_miiphy_bus *bus, int *v)
74 {
75 	struct io_bb_pinset *pins = bus->priv;
76 
77 	*v = ((in_be32((void *)GPIO0_IR) & pins->mdio) != 0);
78 
79 	return 0;
80 }
81 
82 static int io_bb_set_mdc(struct bb_miiphy_bus *bus, int v)
83 {
84 	struct io_bb_pinset *pins = bus->priv;
85 
86 	if (v)
87 		out_be32((void *)GPIO0_OR,
88 			in_be32((void *)GPIO0_OR) | pins->mdc);
89 	else
90 		out_be32((void *)GPIO0_OR,
91 			in_be32((void *)GPIO0_OR) & ~pins->mdc);
92 
93 	return 0;
94 }
95 
96 static int io_bb_delay(struct bb_miiphy_bus *bus)
97 {
98 	udelay(1);
99 
100 	return 0;
101 }
102 
103 struct io_bb_pinset io_bb_pinsets[] = {
104 	{
105 		.mdio = CONFIG_SYS_MDIO_PIN,
106 		.mdc = CONFIG_SYS_MDC_PIN,
107 	},
108 #ifdef CONFIG_SYS_GBIT_MII1_BUSNAME
109 	{
110 		.mdio = CONFIG_SYS_MDIO1_PIN,
111 		.mdc = CONFIG_SYS_MDC1_PIN,
112 	},
113 #endif
114 };
115 
116 struct bb_miiphy_bus bb_miiphy_buses[] = {
117 	{
118 		.name = CONFIG_SYS_GBIT_MII_BUSNAME,
119 		.init = io_bb_mii_init,
120 		.mdio_active = io_bb_mdio_active,
121 		.mdio_tristate = io_bb_mdio_tristate,
122 		.set_mdio = io_bb_set_mdio,
123 		.get_mdio = io_bb_get_mdio,
124 		.set_mdc = io_bb_set_mdc,
125 		.delay = io_bb_delay,
126 		.priv = &io_bb_pinsets[0],
127 	},
128 #ifdef CONFIG_SYS_GBIT_MII1_BUSNAME
129 	{
130 		.name = CONFIG_SYS_GBIT_MII1_BUSNAME,
131 		.init = io_bb_mii_init,
132 		.mdio_active = io_bb_mdio_active,
133 		.mdio_tristate = io_bb_mdio_tristate,
134 		.set_mdio = io_bb_set_mdio,
135 		.get_mdio = io_bb_get_mdio,
136 		.set_mdc = io_bb_set_mdc,
137 		.delay = io_bb_delay,
138 		.priv = &io_bb_pinsets[1],
139 	},
140 #endif
141 };
142 
143 int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) /
144 			  sizeof(bb_miiphy_buses[0]);
145