blob: ca5040ed8d409f695154c4fb42ba8f75e230c8b5 [file] [log] [blame]
wdenk214ec6b2001-10-08 19:18:17 +00001/*----------------------------------------------------------------------------+
Josh Boyer471573b2009-08-07 13:53:20 -04002| This source code is dual-licensed. You may use it under the terms of the
3| GNU General Public License version 2, or under the license below.
wdenk214ec6b2001-10-08 19:18:17 +00004|
wdenk5256def2003-09-18 10:45:21 +00005| This source code has been made available to you by IBM on an AS-IS
6| basis. Anyone receiving this source is licensed under IBM
7| copyrights to use it in any way he or she deems fit, including
8| copying it, modifying it, compiling it, and redistributing it either
9| with or without modifications. No license under IBM patents or
10| patent applications is to be implied by the copyright license.
wdenk214ec6b2001-10-08 19:18:17 +000011|
wdenk5256def2003-09-18 10:45:21 +000012| Any user of this software should understand that IBM cannot provide
13| technical support for this software and will not be responsible for
14| any consequences resulting from the use of this software.
wdenk214ec6b2001-10-08 19:18:17 +000015|
wdenk5256def2003-09-18 10:45:21 +000016| Any person who transfers this source code or any derivative work
17| must include the IBM copyright notice, this paragraph, and the
18| preceding two paragraphs in the transferred software.
wdenk214ec6b2001-10-08 19:18:17 +000019|
wdenk5256def2003-09-18 10:45:21 +000020| COPYRIGHT I B M CORPORATION 1999
21| LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
Luigi 'Comio' Mantellini466827e2009-10-10 12:42:20 +020022|
23| Additions (C) Copyright 2009 Industrie Dial Face S.p.A.
wdenk214ec6b2001-10-08 19:18:17 +000024+----------------------------------------------------------------------------*/
25/*----------------------------------------------------------------------------+
26|
wdenk5256def2003-09-18 10:45:21 +000027| File Name: miiphy.h
wdenk214ec6b2001-10-08 19:18:17 +000028|
wdenk5256def2003-09-18 10:45:21 +000029| Function: Include file defining PHY registers.
wdenk214ec6b2001-10-08 19:18:17 +000030|
wdenk5256def2003-09-18 10:45:21 +000031| Author: Mark Wisner
wdenk214ec6b2001-10-08 19:18:17 +000032|
wdenk214ec6b2001-10-08 19:18:17 +000033+----------------------------------------------------------------------------*/
34#ifndef _miiphy_h_
35#define _miiphy_h_
36
Andy Flemingaecf6fc2011-04-08 02:10:27 -050037#include <common.h>
Mike Frysingerd63ee712010-12-23 15:40:12 -050038#include <linux/mii.h>
Andy Flemingaecf6fc2011-04-08 02:10:27 -050039#include <linux/list.h>
Marian Balakowiczaab8c492005-10-28 22:30:33 +020040#include <net.h>
Andy Flemingaecf6fc2011-04-08 02:10:27 -050041#include <phy.h>
42
43struct legacy_mii_dev {
44 int (*read)(const char *devname, unsigned char addr,
Wolfgang Denk934fcb62011-12-07 08:35:14 +010045 unsigned char reg, unsigned short *value);
Andy Flemingaecf6fc2011-04-08 02:10:27 -050046 int (*write)(const char *devname, unsigned char addr,
Wolfgang Denk934fcb62011-12-07 08:35:14 +010047 unsigned char reg, unsigned short value);
Andy Flemingaecf6fc2011-04-08 02:10:27 -050048};
wdenk214ec6b2001-10-08 19:18:17 +000049
Wolfgang Denk934fcb62011-12-07 08:35:14 +010050int miiphy_read(const char *devname, unsigned char addr, unsigned char reg,
Larry Johnson81b974b2007-10-31 11:21:29 -050051 unsigned short *value);
Wolfgang Denk934fcb62011-12-07 08:35:14 +010052int miiphy_write(const char *devname, unsigned char addr, unsigned char reg,
Larry Johnson81b974b2007-10-31 11:21:29 -050053 unsigned short value);
Andy Flemingaea0c3e2011-04-07 14:38:35 -050054int miiphy_info(const char *devname, unsigned char addr, unsigned int *oui,
Larry Johnson81b974b2007-10-31 11:21:29 -050055 unsigned char *model, unsigned char *rev);
Andy Flemingaea0c3e2011-04-07 14:38:35 -050056int miiphy_reset(const char *devname, unsigned char addr);
57int miiphy_speed(const char *devname, unsigned char addr);
58int miiphy_duplex(const char *devname, unsigned char addr);
59int miiphy_is_1000base_x(const char *devname, unsigned char addr);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020060#ifdef CONFIG_SYS_FAULT_ECHO_LINK_DOWN
Andy Flemingaea0c3e2011-04-07 14:38:35 -050061int miiphy_link(const char *devname, unsigned char addr);
wdenk49c3f672003-10-08 22:33:00 +000062#endif
wdenk214ec6b2001-10-08 19:18:17 +000063
Andy Flemingaea0c3e2011-04-07 14:38:35 -050064void miiphy_init(void);
Marian Balakowiczcbdd1c82005-11-30 18:06:04 +010065
Andy Flemingaea0c3e2011-04-07 14:38:35 -050066void miiphy_register(const char *devname,
67 int (*read)(const char *devname, unsigned char addr,
Wolfgang Denk934fcb62011-12-07 08:35:14 +010068 unsigned char reg, unsigned short *value),
Andy Flemingaea0c3e2011-04-07 14:38:35 -050069 int (*write)(const char *devname, unsigned char addr,
Wolfgang Denk934fcb62011-12-07 08:35:14 +010070 unsigned char reg, unsigned short value));
Marian Balakowiczaab8c492005-10-28 22:30:33 +020071
Andy Flemingaea0c3e2011-04-07 14:38:35 -050072int miiphy_set_current_dev(const char *devname);
73const char *miiphy_get_current_dev(void);
Andy Flemingaecf6fc2011-04-08 02:10:27 -050074struct mii_dev *mdio_get_current_dev(void);
75struct mii_dev *miiphy_get_dev_by_name(const char *devname);
76struct phy_device *mdio_phydev_for_ethname(const char *devname);
Marian Balakowiczaab8c492005-10-28 22:30:33 +020077
Andy Flemingaea0c3e2011-04-07 14:38:35 -050078void miiphy_listdev(void);
Marian Balakowiczaab8c492005-10-28 22:30:33 +020079
Andy Flemingaecf6fc2011-04-08 02:10:27 -050080struct mii_dev *mdio_alloc(void);
81int mdio_register(struct mii_dev *bus);
82void mdio_list_devices(void);
83
Luigi 'Comio' Mantellini466827e2009-10-10 12:42:20 +020084#ifdef CONFIG_BITBANGMII
85
86#define BB_MII_DEVNAME "bb_miiphy"
87
88struct bb_miiphy_bus {
Mike Frysinger6b300dc2011-11-10 14:11:04 +000089 char name[16];
Luigi 'Comio' Mantellini466827e2009-10-10 12:42:20 +020090 int (*init)(struct bb_miiphy_bus *bus);
91 int (*mdio_active)(struct bb_miiphy_bus *bus);
92 int (*mdio_tristate)(struct bb_miiphy_bus *bus);
93 int (*set_mdio)(struct bb_miiphy_bus *bus, int v);
94 int (*get_mdio)(struct bb_miiphy_bus *bus, int *v);
95 int (*set_mdc)(struct bb_miiphy_bus *bus, int v);
96 int (*delay)(struct bb_miiphy_bus *bus);
97#ifdef CONFIG_BITBANGMII_MULTI
98 void *priv;
99#endif
100};
101
102extern struct bb_miiphy_bus bb_miiphy_buses[];
103extern int bb_miiphy_buses_num;
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200104
Andy Flemingaea0c3e2011-04-07 14:38:35 -0500105void bb_miiphy_init(void);
106int bb_miiphy_read(const char *devname, unsigned char addr,
Larry Johnson81b974b2007-10-31 11:21:29 -0500107 unsigned char reg, unsigned short *value);
Andy Flemingaea0c3e2011-04-07 14:38:35 -0500108int bb_miiphy_write(const char *devname, unsigned char addr,
Larry Johnson81b974b2007-10-31 11:21:29 -0500109 unsigned char reg, unsigned short value);
Luigi 'Comio' Mantellini466827e2009-10-10 12:42:20 +0200110#endif
wdenk214ec6b2001-10-08 19:18:17 +0000111
112/* phy seed setup */
wdenk5256def2003-09-18 10:45:21 +0000113#define AUTO 99
Larry Johnson81b974b2007-10-31 11:21:29 -0500114#define _1000BASET 1000
wdenk5256def2003-09-18 10:45:21 +0000115#define _100BASET 100
116#define _10BASET 10
117#define HALF 22
118#define FULL 44
wdenk214ec6b2001-10-08 19:18:17 +0000119
120/* phy register offsets */
Mike Frysingerd63ee712010-12-23 15:40:12 -0500121#define MII_MIPSCR 0x11
wdenk214ec6b2001-10-08 19:18:17 +0000122
Mike Frysingerd63ee712010-12-23 15:40:12 -0500123/* MII_LPA */
Larry Johnson81b974b2007-10-31 11:21:29 -0500124#define PHY_ANLPAR_PSB_802_3 0x0001
125#define PHY_ANLPAR_PSB_802_9 0x0002
wdenk656140b2004-04-25 13:18:40 +0000126
Mike Frysingerd63ee712010-12-23 15:40:12 -0500127/* MII_CTRL1000 masks */
Larry Johnson966a80b2007-11-01 08:46:50 -0500128#define PHY_1000BTCR_1000FD 0x0200
129#define PHY_1000BTCR_1000HD 0x0100
130
Mike Frysingerd63ee712010-12-23 15:40:12 -0500131/* MII_STAT1000 masks */
Larry Johnson81b974b2007-10-31 11:21:29 -0500132#define PHY_1000BTSR_MSCF 0x8000
133#define PHY_1000BTSR_MSCR 0x4000
134#define PHY_1000BTSR_LRS 0x2000
135#define PHY_1000BTSR_RRS 0x1000
136#define PHY_1000BTSR_1000FD 0x0800
137#define PHY_1000BTSR_1000HD 0x0400
wdenked2ac4b2004-03-14 18:23:55 +0000138
Larry Johnson966a80b2007-11-01 08:46:50 -0500139/* phy EXSR */
Mike Frysingerd63ee712010-12-23 15:40:12 -0500140#define ESTATUS_1000XF 0x8000
141#define ESTATUS_1000XH 0x4000
Larry Johnson966a80b2007-11-01 08:46:50 -0500142
wdenk214ec6b2001-10-08 19:18:17 +0000143#endif