2 * Atheros AR71xx built-in ethernet mac driver
4 * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7 * Based on Atheros' AG7100 driver
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
16 static unsigned char *ag71xx_speed_str(struct ag71xx
*ag
)
30 #define AR71XX_PLL_VAL_1000 0x00110000
31 #define AR71XX_PLL_VAL_100 0x00001099
32 #define AR71XX_PLL_VAL_10 0x00991099
34 #define AR91XX_PLL_VAL_1000 0x1a000000
35 #define AR91XX_PLL_VAL_100 0x13000a44
36 #define AR91XX_PLL_VAL_10 0x00441099
38 static void ag71xx_phy_link_update(struct ag71xx
*ag
)
40 struct ag71xx_platform_data
*pdata
= ag71xx_get_pdata(ag
);
48 netif_carrier_off(ag
->dev
);
49 if (netif_msg_link(ag
))
50 printk(KERN_INFO
"%s: link down\n", ag
->dev
->name
);
54 cfg2
= ag71xx_rr(ag
, AG71XX_REG_MAC_CFG2
);
55 cfg2
&= ~(MAC_CFG2_IF_1000
| MAC_CFG2_IF_10_100
| MAC_CFG2_FDX
);
56 cfg2
|= (ag
->duplex
) ? MAC_CFG2_FDX
: 0;
58 ifctl
= ag71xx_rr(ag
, AG71XX_REG_MAC_IFCTL
);
59 ifctl
&= ~(MAC_IFCTL_SPEED
);
61 fifo5
= ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG5
);
62 fifo5
&= ~FIFO_CFG5_BM
;
66 mii_speed
= MII_CTRL_SPEED_1000
;
67 cfg2
|= MAC_CFG2_IF_1000
;
68 pll
= pdata
->is_ar91xx
? AR91XX_PLL_VAL_1000
69 : AR71XX_PLL_VAL_1000
;
70 fifo5
|= FIFO_CFG5_BM
;
73 mii_speed
= MII_CTRL_SPEED_100
;
74 cfg2
|= MAC_CFG2_IF_10_100
;
75 ifctl
|= MAC_IFCTL_SPEED
;
76 pll
= pdata
->is_ar91xx
? AR91XX_PLL_VAL_100
80 mii_speed
= MII_CTRL_SPEED_10
;
81 cfg2
|= MAC_CFG2_IF_10_100
;
82 pll
= pdata
->is_ar91xx
? AR91XX_PLL_VAL_10
90 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG3
,
91 pdata
->is_ar91xx
? 0x780fff : 0x008001ff);
93 ag71xx_mii_ctrl_set_speed(ag
, mii_speed
);
95 ag71xx_wr(ag
, AG71XX_REG_MAC_CFG2
, cfg2
);
96 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG5
, fifo5
);
97 ag71xx_wr(ag
, AG71XX_REG_MAC_IFCTL
, ifctl
);
99 netif_carrier_on(ag
->dev
);
100 if (netif_msg_link(ag
))
101 printk(KERN_INFO
"%s: link up (%sMbps/%s duplex)\n",
103 ag71xx_speed_str(ag
),
104 (DUPLEX_FULL
== ag
->duplex
) ? "Full" : "Half");
106 DBG("%s: fifo_cfg0=%#x, fifo_cfg1=%#x, fifo_cfg2=%#x\n",
108 ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG0
),
109 ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG1
),
110 ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG2
));
112 DBG("%s: fifo_cfg3=%#x, fifo_cfg4=%#x, fifo_cfg5=%#x\n",
114 ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG3
),
115 ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG4
),
116 ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG5
));
118 DBG("%s: mac_cfg2=%#x, mac_ifctl=%#x, mii_ctrl=%#x\n",
120 ag71xx_rr(ag
, AG71XX_REG_MAC_CFG2
),
121 ag71xx_rr(ag
, AG71XX_REG_MAC_IFCTL
),
122 ag71xx_mii_ctrl_rr(ag
));
125 static void ag71xx_phy_link_adjust(struct net_device
*dev
)
127 struct ag71xx
*ag
= netdev_priv(dev
);
128 struct phy_device
*phydev
= ag
->phy_dev
;
130 int status_change
= 0;
132 spin_lock_irqsave(&ag
->lock
, flags
);
135 if (ag
->duplex
!= phydev
->duplex
136 || ag
->speed
!= phydev
->speed
) {
141 if (phydev
->link
!= ag
->link
) {
148 ag
->link
= phydev
->link
;
149 ag
->duplex
= phydev
->duplex
;
150 ag
->speed
= phydev
->speed
;
153 ag71xx_phy_link_update(ag
);
155 spin_unlock_irqrestore(&ag
->lock
, flags
);
158 void ag71xx_phy_start(struct ag71xx
*ag
)
161 phy_start(ag
->phy_dev
);
163 struct ag71xx_platform_data
*pdata
= ag71xx_get_pdata(ag
);
165 ag
->duplex
= pdata
->duplex
;
166 ag
->speed
= pdata
->speed
;
168 ag71xx_phy_link_update(ag
);
172 void ag71xx_phy_stop(struct ag71xx
*ag
)
175 phy_stop(ag
->phy_dev
);
180 ag71xx_phy_link_update(ag
);
184 int ag71xx_phy_connect(struct ag71xx
*ag
)
186 struct net_device
*dev
= ag
->dev
;
187 struct ag71xx_platform_data
*pdata
= ag71xx_get_pdata(ag
);
188 struct phy_device
*phydev
= NULL
;
192 if (ag
->mii_bus
&& pdata
->phy_mask
) {
193 /* TODO: use mutex of the mdio bus? */
194 for (phy_addr
= 0; phy_addr
< PHY_MAX_ADDR
; phy_addr
++) {
195 if (!(pdata
->phy_mask
& (1 << phy_addr
)))
198 if (ag
->mii_bus
->phy_map
[phy_addr
] == NULL
)
201 DBG("%s: PHY found at %s, uid=%08x\n",
203 ag
->mii_bus
->phy_map
[phy_addr
]->dev
.bus_id
,
204 ag
->mii_bus
->phy_map
[phy_addr
]->phy_id
);
207 phydev
= ag
->mii_bus
->phy_map
[phy_addr
];
215 ag
->phy_dev
= phy_connect(dev
, phydev
->dev
.bus_id
,
216 &ag71xx_phy_link_adjust
, 0, pdata
->phy_if_mode
);
218 if (IS_ERR(ag
->phy_dev
)) {
219 printk(KERN_ERR
"%s: could not connect to PHY at %s\n",
220 dev
->name
, phydev
->dev
.bus_id
);
221 return PTR_ERR(ag
->phy_dev
);
224 /* mask with MAC supported features */
226 phydev
->supported
&= PHY_GBIT_FEATURES
;
228 phydev
->supported
&= PHY_BASIC_FEATURES
;
230 phydev
->advertising
= phydev
->supported
;
232 printk(KERN_DEBUG
"%s: connected to PHY at %s "
233 "[uid=%08x, driver=%s]\n",
234 dev
->name
, phydev
->dev
.bus_id
,
235 phydev
->phy_id
, phydev
->drv
->name
);
243 switch (pdata
->speed
) {
249 printk(KERN_ERR
"%s: invalid speed specified\n",
255 printk(KERN_DEBUG
"%s: connected to %d PHYs\n",
256 dev
->name
, phy_count
);
263 void ag71xx_phy_disconnect(struct ag71xx
*ag
)
266 phy_disconnect(ag
->phy_dev
);
This page took 0.062327 seconds and 5 git commands to generate.