1/* 2 * @TAG(OTHER_GPL) 3 */ 4/* SPDX-License-Identifier: GPL-2.0 OR IBM-pibs */ 5/* 6 * Additions (C) Copyright 2009 Industrie Dial Face S.p.A. 7 */ 8/*----------------------------------------------------------------------------+ 9| 10| File Name: miiphy.h 11| 12| Function: Include file defining PHY registers. 13| 14| Author: Mark Wisner 15| 16+----------------------------------------------------------------------------*/ 17#pragma once 18 19#include "common.h" 20#include "mii.h" 21#include "list.h" 22#include "phy.h" 23 24int miiphy_read(const char *devname, unsigned char addr, unsigned char reg, 25 unsigned short *value); 26int miiphy_write(const char *devname, unsigned char addr, unsigned char reg, 27 unsigned short value); 28int miiphy_info(const char *devname, unsigned char addr, unsigned int *oui, 29 unsigned char *model, unsigned char *rev); 30int miiphy_reset(const char *devname, unsigned char addr); 31int miiphy_speed(const char *devname, unsigned char addr); 32int miiphy_duplex(const char *devname, unsigned char addr); 33int miiphy_is_1000base_x(const char *devname, unsigned char addr); 34#ifdef CONFIG_SYS_FAULT_ECHO_LINK_DOWN 35int miiphy_link(const char *devname, unsigned char addr); 36#endif 37 38void miiphy_init(void); 39 40int miiphy_set_current_dev(const char *devname); 41const char *miiphy_get_current_dev(void); 42struct mii_dev *mdio_get_current_dev(void); 43struct list_head *mdio_get_list_head(void); 44struct mii_dev *miiphy_get_dev_by_name(const char *devname); 45struct phy_device *mdio_phydev_for_ethname(const char *devname); 46 47void miiphy_listdev(void); 48 49struct mii_dev *mdio_alloc(void); 50void mdio_free(struct mii_dev *bus); 51int mdio_register(struct mii_dev *bus); 52 53/** 54 * mdio_register_seq - Register mdio bus with sequence number 55 * @bus: mii device structure 56 * @seq: sequence number 57 * 58 * Return: 0 if success, negative value if error 59 */ 60int mdio_register_seq(struct mii_dev *bus, int seq); 61int mdio_unregister(struct mii_dev *bus); 62void mdio_list_devices(void); 63 64#ifdef CONFIG_BITBANGMII 65 66#define BB_MII_DEVNAME "bb_miiphy" 67 68struct bb_miiphy_bus { 69 char name[16]; 70 int (*init)(struct bb_miiphy_bus *bus); 71 int (*mdio_active)(struct bb_miiphy_bus *bus); 72 int (*mdio_tristate)(struct bb_miiphy_bus *bus); 73 int (*set_mdio)(struct bb_miiphy_bus *bus, int v); 74 int (*get_mdio)(struct bb_miiphy_bus *bus, int *v); 75 int (*set_mdc)(struct bb_miiphy_bus *bus, int v); 76 int (*delay)(struct bb_miiphy_bus *bus); 77#ifdef CONFIG_BITBANGMII_MULTI 78 void *priv; 79#endif 80}; 81 82extern struct bb_miiphy_bus bb_miiphy_buses[]; 83extern int bb_miiphy_buses_num; 84 85void bb_miiphy_init(void); 86int bb_miiphy_read(struct mii_dev *miidev, int addr, int devad, int reg); 87int bb_miiphy_write(struct mii_dev *miidev, int addr, int devad, int reg, 88 u16 value); 89#endif 90 91/* phy seed setup */ 92#define AUTO 99 93#define _1000BASET 1000 94#define _100BASET 100 95#define _10BASET 10 96#define HALF 22 97#define FULL 44 98 99/* phy register offsets */ 100#define MII_MIPSCR 0x11 101 102/* MII_LPA */ 103#define PHY_ANLPAR_PSB_802_3 0x0001 104#define PHY_ANLPAR_PSB_802_9 0x0002 105 106/* MII_CTRL1000 masks */ 107#define PHY_1000BTCR_1000FD 0x0200 108#define PHY_1000BTCR_1000HD 0x0100 109 110/* MII_STAT1000 masks */ 111#define PHY_1000BTSR_MSCF 0x8000 112#define PHY_1000BTSR_MSCR 0x4000 113#define PHY_1000BTSR_LRS 0x2000 114#define PHY_1000BTSR_RRS 0x1000 115#define PHY_1000BTSR_1000FD 0x0800 116#define PHY_1000BTSR_1000HD 0x0400 117 118/* phy EXSR */ 119#define ESTATUS_1000XF 0x8000 120#define ESTATUS_1000XH 0x4000 121 122#ifdef CONFIG_DM_MDIO 123 124/** 125 * struct mdio_perdev_priv - Per-device class data for MDIO DM 126 * 127 * @mii_bus: Supporting MII legacy bus 128 */ 129struct mdio_perdev_priv { 130 struct mii_dev *mii_bus; 131}; 132 133/** 134 * struct mdio_ops - MDIO bus operations 135 * 136 * @read: Read from a PHY register 137 * @write: Write to a PHY register 138 * @reset: Reset the MDIO bus, NULL if not supported 139 */ 140struct mdio_ops { 141 int (*read)(struct udevice *mdio_dev, int addr, int devad, int reg); 142 int (*write)(struct udevice *mdio_dev, int addr, int devad, int reg, 143 u16 val); 144 int (*reset)(struct udevice *mdio_dev); 145}; 146 147#define mdio_get_ops(dev) ((struct mdio_ops *)(dev)->driver->ops) 148 149/** 150 * dm_mdio_probe_devices - Call probe on all MII devices, currently used for 151 * MDIO console commands. 152 */ 153void dm_mdio_probe_devices(void); 154 155/** 156 * dm_mdio_phy_connect - Wrapper over phy_connect for DM MDIO 157 * 158 * @dev: mdio dev 159 * @addr: PHY address on MDIO bus 160 * @ethdev: ethernet device to connect to the PHY 161 * @interface: MAC-PHY protocol 162 * 163 * @return pointer to phy_device, or 0 on error 164 */ 165struct phy_device *dm_mdio_phy_connect(struct udevice *dev, int addr, 166 struct udevice *ethdev, 167 phy_interface_t interface); 168 169#endif 170 171#ifdef CONFIG_DM_MDIO_MUX 172 173/* indicates none of the child buses is selected */ 174#define MDIO_MUX_SELECT_NONE -1 175 176/** 177 * struct mdio_mux_ops - MDIO MUX operations 178 * 179 * @select: Selects a child bus 180 * @deselect: Clean up selection. Optional, can be NULL 181 */ 182struct mdio_mux_ops { 183 int (*select)(struct udevice *mux, int cur, int sel); 184 int (*deselect)(struct udevice *mux, int sel); 185}; 186 187#define mdio_mux_get_ops(dev) ((struct mdio_mux_ops *)(dev)->driver->ops) 188 189#endif 190