blob: e56e966509cd62d2a17dc4fffd863bfd91e80efb [file] [log] [blame]
Dirk Eibach9a13d812010-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
29static int io_bb_mii_init(struct bb_miiphy_bus *bus)
30{
31 return 0;
32}
33
34static int io_bb_mdio_active(struct bb_miiphy_bus *bus)
35{
36 out_be32((void *)GPIO0_TCR,
37 in_be32((void *)GPIO0_TCR) | CONFIG_SYS_MDIO_PIN);
38
39 return 0;
40}
41
42static int io_bb_mdio_tristate(struct bb_miiphy_bus *bus)
43{
44 out_be32((void *)GPIO0_TCR,
45 in_be32((void *)GPIO0_TCR) & ~CONFIG_SYS_MDIO_PIN);
46
47 return 0;
48}
49
50static int io_bb_set_mdio(struct bb_miiphy_bus *bus, int v)
51{
52 if (v)
53 out_be32((void *)GPIO0_OR,
54 in_be32((void *)GPIO0_OR) | CONFIG_SYS_MDIO_PIN);
55 else
56 out_be32((void *)GPIO0_OR,
57 in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_MDIO_PIN);
58
59 return 0;
60}
61
62static int io_bb_get_mdio(struct bb_miiphy_bus *bus, int *v)
63{
64 *v = ((in_be32((void *)GPIO0_IR) & CONFIG_SYS_MDIO_PIN) != 0);
65
66 return 0;
67}
68
69static int io_bb_set_mdc(struct bb_miiphy_bus *bus, int v)
70{
71 if (v)
72 out_be32((void *)GPIO0_OR,
73 in_be32((void *)GPIO0_OR) | CONFIG_SYS_MDC_PIN);
74 else
75 out_be32((void *)GPIO0_OR,
76 in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_MDC_PIN);
77
78 return 0;
79}
80
81static int io_bb_delay(struct bb_miiphy_bus *bus)
82{
83 udelay(1);
84
85 return 0;
86}
87
88struct bb_miiphy_bus bb_miiphy_buses[] = {
89 {
90 .name = CONFIG_SYS_GBIT_MII_BUSNAME,
91 .init = io_bb_mii_init,
92 .mdio_active = io_bb_mdio_active,
93 .mdio_tristate = io_bb_mdio_tristate,
94 .set_mdio = io_bb_set_mdio,
95 .get_mdio = io_bb_get_mdio,
96 .set_mdc = io_bb_set_mdc,
97 .delay = io_bb_delay,
98 }
99};
100
101int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) /
102 sizeof(bb_miiphy_buses[0]);