blob: 042835d6af6dedefc34ce78e3bc05d27d34671a5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dirk Eibach9a13d812010-10-21 10:50:05 +02002/*
3 * (C) Copyright 2010
Mario Sixb4893582018-03-06 08:04:58 +01004 * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
Dirk Eibach9a13d812010-10-21 10:50:05 +02005 */
6
7#include <common.h>
8#include <miiphy.h>
9
10#include <asm/io.h>
11
Dirk Eibach6fabe552011-10-20 11:12:55 +020012struct io_bb_pinset {
13 int mdio;
14 int mdc;
15};
16
Dirk Eibach9a13d812010-10-21 10:50:05 +020017static int io_bb_mii_init(struct bb_miiphy_bus *bus)
18{
19 return 0;
20}
21
22static int io_bb_mdio_active(struct bb_miiphy_bus *bus)
23{
Dirk Eibach6fabe552011-10-20 11:12:55 +020024 struct io_bb_pinset *pins = bus->priv;
25
Dirk Eibach9a13d812010-10-21 10:50:05 +020026 out_be32((void *)GPIO0_TCR,
Dirk Eibach6fabe552011-10-20 11:12:55 +020027 in_be32((void *)GPIO0_TCR) | pins->mdio);
Dirk Eibach9a13d812010-10-21 10:50:05 +020028
29 return 0;
30}
31
32static int io_bb_mdio_tristate(struct bb_miiphy_bus *bus)
33{
Dirk Eibach6fabe552011-10-20 11:12:55 +020034 struct io_bb_pinset *pins = bus->priv;
35
Dirk Eibach9a13d812010-10-21 10:50:05 +020036 out_be32((void *)GPIO0_TCR,
Dirk Eibach6fabe552011-10-20 11:12:55 +020037 in_be32((void *)GPIO0_TCR) & ~pins->mdio);
Dirk Eibach9a13d812010-10-21 10:50:05 +020038
39 return 0;
40}
41
42static int io_bb_set_mdio(struct bb_miiphy_bus *bus, int v)
43{
Dirk Eibach6fabe552011-10-20 11:12:55 +020044 struct io_bb_pinset *pins = bus->priv;
45
Dirk Eibach9a13d812010-10-21 10:50:05 +020046 if (v)
47 out_be32((void *)GPIO0_OR,
Dirk Eibach6fabe552011-10-20 11:12:55 +020048 in_be32((void *)GPIO0_OR) | pins->mdio);
Dirk Eibach9a13d812010-10-21 10:50:05 +020049 else
50 out_be32((void *)GPIO0_OR,
Dirk Eibach6fabe552011-10-20 11:12:55 +020051 in_be32((void *)GPIO0_OR) & ~pins->mdio);
Dirk Eibach9a13d812010-10-21 10:50:05 +020052
53 return 0;
54}
55
56static int io_bb_get_mdio(struct bb_miiphy_bus *bus, int *v)
57{
Dirk Eibach6fabe552011-10-20 11:12:55 +020058 struct io_bb_pinset *pins = bus->priv;
59
60 *v = ((in_be32((void *)GPIO0_IR) & pins->mdio) != 0);
Dirk Eibach9a13d812010-10-21 10:50:05 +020061
62 return 0;
63}
64
65static int io_bb_set_mdc(struct bb_miiphy_bus *bus, int v)
66{
Dirk Eibach6fabe552011-10-20 11:12:55 +020067 struct io_bb_pinset *pins = bus->priv;
68
Dirk Eibach9a13d812010-10-21 10:50:05 +020069 if (v)
70 out_be32((void *)GPIO0_OR,
Dirk Eibach6fabe552011-10-20 11:12:55 +020071 in_be32((void *)GPIO0_OR) | pins->mdc);
Dirk Eibach9a13d812010-10-21 10:50:05 +020072 else
73 out_be32((void *)GPIO0_OR,
Dirk Eibach6fabe552011-10-20 11:12:55 +020074 in_be32((void *)GPIO0_OR) & ~pins->mdc);
Dirk Eibach9a13d812010-10-21 10:50:05 +020075
76 return 0;
77}
78
79static int io_bb_delay(struct bb_miiphy_bus *bus)
80{
81 udelay(1);
82
83 return 0;
84}
85
Dirk Eibach6fabe552011-10-20 11:12:55 +020086struct io_bb_pinset io_bb_pinsets[] = {
87 {
88 .mdio = CONFIG_SYS_MDIO_PIN,
89 .mdc = CONFIG_SYS_MDC_PIN,
90 },
91#ifdef CONFIG_SYS_GBIT_MII1_BUSNAME
92 {
93 .mdio = CONFIG_SYS_MDIO1_PIN,
94 .mdc = CONFIG_SYS_MDC1_PIN,
95 },
96#endif
97};
98
Dirk Eibach9a13d812010-10-21 10:50:05 +020099struct bb_miiphy_bus bb_miiphy_buses[] = {
100 {
101 .name = CONFIG_SYS_GBIT_MII_BUSNAME,
102 .init = io_bb_mii_init,
103 .mdio_active = io_bb_mdio_active,
104 .mdio_tristate = io_bb_mdio_tristate,
105 .set_mdio = io_bb_set_mdio,
106 .get_mdio = io_bb_get_mdio,
107 .set_mdc = io_bb_set_mdc,
108 .delay = io_bb_delay,
Dirk Eibach6fabe552011-10-20 11:12:55 +0200109 .priv = &io_bb_pinsets[0],
110 },
111#ifdef CONFIG_SYS_GBIT_MII1_BUSNAME
112 {
113 .name = CONFIG_SYS_GBIT_MII1_BUSNAME,
114 .init = io_bb_mii_init,
115 .mdio_active = io_bb_mdio_active,
116 .mdio_tristate = io_bb_mdio_tristate,
117 .set_mdio = io_bb_set_mdio,
118 .get_mdio = io_bb_get_mdio,
119 .set_mdc = io_bb_set_mdc,
120 .delay = io_bb_delay,
121 .priv = &io_bb_pinsets[1],
122 },
123#endif
Dirk Eibach9a13d812010-10-21 10:50:05 +0200124};
125
126int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) /
127 sizeof(bb_miiphy_buses[0]);