blob: 46f1a1ecbb4f706b7c604a10c82f260b08cb208f [file] [log] [blame]
Dirk Eibacha605ea72010-10-21 10:50:05 +02001/*
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
Dirk Eibach255ef4d2011-10-20 11:12:55 +020029struct io_bb_pinset {
30 int mdio;
31 int mdc;
32};
33
Dirk Eibacha605ea72010-10-21 10:50:05 +020034static int io_bb_mii_init(struct bb_miiphy_bus *bus)
35{
36 return 0;
37}
38
39static int io_bb_mdio_active(struct bb_miiphy_bus *bus)
40{
Dirk Eibach255ef4d2011-10-20 11:12:55 +020041 struct io_bb_pinset *pins = bus->priv;
42
Dirk Eibacha605ea72010-10-21 10:50:05 +020043 out_be32((void *)GPIO0_TCR,
Dirk Eibach255ef4d2011-10-20 11:12:55 +020044 in_be32((void *)GPIO0_TCR) | pins->mdio);
Dirk Eibacha605ea72010-10-21 10:50:05 +020045
46 return 0;
47}
48
49static int io_bb_mdio_tristate(struct bb_miiphy_bus *bus)
50{
Dirk Eibach255ef4d2011-10-20 11:12:55 +020051 struct io_bb_pinset *pins = bus->priv;
52
Dirk Eibacha605ea72010-10-21 10:50:05 +020053 out_be32((void *)GPIO0_TCR,
Dirk Eibach255ef4d2011-10-20 11:12:55 +020054 in_be32((void *)GPIO0_TCR) & ~pins->mdio);
Dirk Eibacha605ea72010-10-21 10:50:05 +020055
56 return 0;
57}
58
59static int io_bb_set_mdio(struct bb_miiphy_bus *bus, int v)
60{
Dirk Eibach255ef4d2011-10-20 11:12:55 +020061 struct io_bb_pinset *pins = bus->priv;
62
Dirk Eibacha605ea72010-10-21 10:50:05 +020063 if (v)
64 out_be32((void *)GPIO0_OR,
Dirk Eibach255ef4d2011-10-20 11:12:55 +020065 in_be32((void *)GPIO0_OR) | pins->mdio);
Dirk Eibacha605ea72010-10-21 10:50:05 +020066 else
67 out_be32((void *)GPIO0_OR,
Dirk Eibach255ef4d2011-10-20 11:12:55 +020068 in_be32((void *)GPIO0_OR) & ~pins->mdio);
Dirk Eibacha605ea72010-10-21 10:50:05 +020069
70 return 0;
71}
72
73static int io_bb_get_mdio(struct bb_miiphy_bus *bus, int *v)
74{
Dirk Eibach255ef4d2011-10-20 11:12:55 +020075 struct io_bb_pinset *pins = bus->priv;
76
77 *v = ((in_be32((void *)GPIO0_IR) & pins->mdio) != 0);
Dirk Eibacha605ea72010-10-21 10:50:05 +020078
79 return 0;
80}
81
82static int io_bb_set_mdc(struct bb_miiphy_bus *bus, int v)
83{
Dirk Eibach255ef4d2011-10-20 11:12:55 +020084 struct io_bb_pinset *pins = bus->priv;
85
Dirk Eibacha605ea72010-10-21 10:50:05 +020086 if (v)
87 out_be32((void *)GPIO0_OR,
Dirk Eibach255ef4d2011-10-20 11:12:55 +020088 in_be32((void *)GPIO0_OR) | pins->mdc);
Dirk Eibacha605ea72010-10-21 10:50:05 +020089 else
90 out_be32((void *)GPIO0_OR,
Dirk Eibach255ef4d2011-10-20 11:12:55 +020091 in_be32((void *)GPIO0_OR) & ~pins->mdc);
Dirk Eibacha605ea72010-10-21 10:50:05 +020092
93 return 0;
94}
95
96static int io_bb_delay(struct bb_miiphy_bus *bus)
97{
98 udelay(1);
99
100 return 0;
101}
102
Dirk Eibach255ef4d2011-10-20 11:12:55 +0200103struct 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
Dirk Eibacha605ea72010-10-21 10:50:05 +0200116struct 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,
Dirk Eibach255ef4d2011-10-20 11:12:55 +0200126 .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
Dirk Eibacha605ea72010-10-21 10:50:05 +0200141};
142
143int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) /
144 sizeof(bb_miiphy_buses[0]);