1*950a6087SEmmanuel Vadot /*- 2*950a6087SEmmanuel Vadot * Copyright 2016 Michal Meloun <mmel@FreeBSD.org> 3*950a6087SEmmanuel Vadot * 4*950a6087SEmmanuel Vadot * Redistribution and use in source and binary forms, with or without 5*950a6087SEmmanuel Vadot * modification, are permitted provided that the following conditions 6*950a6087SEmmanuel Vadot * are met: 7*950a6087SEmmanuel Vadot * 1. Redistributions of source code must retain the above copyright 8*950a6087SEmmanuel Vadot * notice, this list of conditions and the following disclaimer. 9*950a6087SEmmanuel Vadot * 2. Redistributions in binary form must reproduce the above copyright 10*950a6087SEmmanuel Vadot * notice, this list of conditions and the following disclaimer in the 11*950a6087SEmmanuel Vadot * documentation and/or other materials provided with the distribution. 12*950a6087SEmmanuel Vadot * 13*950a6087SEmmanuel Vadot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14*950a6087SEmmanuel Vadot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15*950a6087SEmmanuel Vadot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16*950a6087SEmmanuel Vadot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17*950a6087SEmmanuel Vadot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18*950a6087SEmmanuel Vadot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19*950a6087SEmmanuel Vadot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20*950a6087SEmmanuel Vadot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21*950a6087SEmmanuel Vadot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22*950a6087SEmmanuel Vadot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23*950a6087SEmmanuel Vadot * 24*950a6087SEmmanuel Vadot */ 25*950a6087SEmmanuel Vadot 26*950a6087SEmmanuel Vadot #ifndef _DEV_PHY_H_ 27*950a6087SEmmanuel Vadot #define _DEV_PHY_H_ 28*950a6087SEmmanuel Vadot 29*950a6087SEmmanuel Vadot #include "opt_platform.h" 30*950a6087SEmmanuel Vadot 31*950a6087SEmmanuel Vadot #include <sys/kobj.h> 32*950a6087SEmmanuel Vadot #ifdef FDT 33*950a6087SEmmanuel Vadot #include <dev/ofw/ofw_bus.h> 34*950a6087SEmmanuel Vadot #endif 35*950a6087SEmmanuel Vadot 36*950a6087SEmmanuel Vadot #define PHY_STATUS_ENABLED 0x00000001 37*950a6087SEmmanuel Vadot 38*950a6087SEmmanuel Vadot typedef enum phy_mode { 39*950a6087SEmmanuel Vadot PHY_MODE_INVALID, 40*950a6087SEmmanuel Vadot PHY_MODE_USB_HOST, 41*950a6087SEmmanuel Vadot PHY_MODE_USB_DEVICE, 42*950a6087SEmmanuel Vadot PHY_MODE_USB_OTG, 43*950a6087SEmmanuel Vadot PHY_MODE_UFS, 44*950a6087SEmmanuel Vadot PHY_MODE_PCIE, 45*950a6087SEmmanuel Vadot PHY_MODE_ETHERNET, 46*950a6087SEmmanuel Vadot PHY_MODE_MIPI_DPHY, 47*950a6087SEmmanuel Vadot PHY_MODE_SATA, 48*950a6087SEmmanuel Vadot PHY_MODE_LVDS, 49*950a6087SEmmanuel Vadot PHY_MODE_DP 50*950a6087SEmmanuel Vadot } phy_mode_t ; 51*950a6087SEmmanuel Vadot 52*950a6087SEmmanuel Vadot typedef enum phy_submode { 53*950a6087SEmmanuel Vadot /* Common */ 54*950a6087SEmmanuel Vadot PHY_SUBMODE_NA = 0, /* Not applicable */ 55*950a6087SEmmanuel Vadot PHY_SUBMODE_INTERNAL, 56*950a6087SEmmanuel Vadot 57*950a6087SEmmanuel Vadot /* Ethernet */ 58*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_MII = 1000, 59*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_GMII, 60*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_SGMII, 61*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_TBI, 62*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_REVMII, 63*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_RMII, 64*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_RGMII, 65*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_RGMII_ID, 66*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_RGMII_RXID, 67*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_RGMII_TXID, 68*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_RTBI, 69*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_SMII, 70*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_XGMII, 71*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_XLGMII, 72*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_MOCA, 73*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_QSGMII, 74*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_TRGMII, 75*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_1000BASEX, 76*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_2500BASEX, 77*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_RXAUI, 78*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_XAUI, 79*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_10GBASER, 80*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_USXGMII, 81*950a6087SEmmanuel Vadot PHY_SUBMODE_ETH_10GKR, 82*950a6087SEmmanuel Vadot 83*950a6087SEmmanuel Vadot /* USB */ 84*950a6087SEmmanuel Vadot PHY_SUBMODE_USB_LS = 2000, 85*950a6087SEmmanuel Vadot PHY_SUBMODE_USB_FS, 86*950a6087SEmmanuel Vadot PHY_SUBMODE_USB_HS, 87*950a6087SEmmanuel Vadot PHY_SUBMODE_USB_SS, 88*950a6087SEmmanuel Vadot 89*950a6087SEmmanuel Vadot /* UFS */ 90*950a6087SEmmanuel Vadot PHY_SUBMODE_UFS_HS_A = 3000, 91*950a6087SEmmanuel Vadot PHY_SUBMODE_UFS_HS_B, 92*950a6087SEmmanuel Vadot 93*950a6087SEmmanuel Vadot } phy_submode_t; 94*950a6087SEmmanuel Vadot 95*950a6087SEmmanuel Vadot typedef struct phy *phy_t; 96*950a6087SEmmanuel Vadot 97*950a6087SEmmanuel Vadot /* Initialization parameters. */ 98*950a6087SEmmanuel Vadot struct phynode_init_def { 99*950a6087SEmmanuel Vadot intptr_t id; /* Phy ID */ 100*950a6087SEmmanuel Vadot #ifdef FDT 101*950a6087SEmmanuel Vadot phandle_t ofw_node; /* OFW node of phy */ 102*950a6087SEmmanuel Vadot #endif 103*950a6087SEmmanuel Vadot }; 104*950a6087SEmmanuel Vadot 105*950a6087SEmmanuel Vadot #include "phynode_if.h" 106*950a6087SEmmanuel Vadot 107*950a6087SEmmanuel Vadot /* 108*950a6087SEmmanuel Vadot * Shorthands for constructing method tables. 109*950a6087SEmmanuel Vadot */ 110*950a6087SEmmanuel Vadot #define PHYNODEMETHOD KOBJMETHOD 111*950a6087SEmmanuel Vadot #define PHYNODEMETHOD_END KOBJMETHOD_END 112*950a6087SEmmanuel Vadot #define phynode_method_t kobj_method_t 113*950a6087SEmmanuel Vadot #define phynode_class_t kobj_class_t 114*950a6087SEmmanuel Vadot DECLARE_CLASS(phynode_class); 115*950a6087SEmmanuel Vadot 116*950a6087SEmmanuel Vadot /* 117*950a6087SEmmanuel Vadot * Provider interface 118*950a6087SEmmanuel Vadot */ 119*950a6087SEmmanuel Vadot struct phynode *phynode_create(device_t pdev, phynode_class_t phynode_class, 120*950a6087SEmmanuel Vadot struct phynode_init_def *def); 121*950a6087SEmmanuel Vadot struct phynode *phynode_register(struct phynode *phynode); 122*950a6087SEmmanuel Vadot void *phynode_get_softc(struct phynode *phynode); 123*950a6087SEmmanuel Vadot device_t phynode_get_device(struct phynode *phynode); 124*950a6087SEmmanuel Vadot intptr_t phynode_get_id(struct phynode *phynode); 125*950a6087SEmmanuel Vadot int phynode_enable(struct phynode *phynode); 126*950a6087SEmmanuel Vadot int phynode_disable(struct phynode *phynode); 127*950a6087SEmmanuel Vadot int phynode_set_mode(struct phynode *phynode, phy_mode_t mode, 128*950a6087SEmmanuel Vadot phy_submode_t submode); 129*950a6087SEmmanuel Vadot int phynode_status(struct phynode *phynode, int *status); 130*950a6087SEmmanuel Vadot #ifdef FDT 131*950a6087SEmmanuel Vadot phandle_t phynode_get_ofw_node(struct phynode *phynode); 132*950a6087SEmmanuel Vadot #endif 133*950a6087SEmmanuel Vadot 134*950a6087SEmmanuel Vadot /* 135*950a6087SEmmanuel Vadot * Consumer interface 136*950a6087SEmmanuel Vadot */ 137*950a6087SEmmanuel Vadot int phy_get_by_id(device_t consumer_dev, device_t provider_dev, intptr_t id, 138*950a6087SEmmanuel Vadot phy_t *phy); 139*950a6087SEmmanuel Vadot void phy_release(phy_t phy); 140*950a6087SEmmanuel Vadot int phy_enable(phy_t phy); 141*950a6087SEmmanuel Vadot int phy_disable(phy_t phy); 142*950a6087SEmmanuel Vadot int phy_set_mode(phy_t phy, phy_mode_t mode, phy_submode_t submode); 143*950a6087SEmmanuel Vadot int phy_status(phy_t phy, int *value); 144*950a6087SEmmanuel Vadot #ifdef FDT 145*950a6087SEmmanuel Vadot int phy_get_by_ofw_name(device_t consumer, phandle_t node, char *name, 146*950a6087SEmmanuel Vadot phy_t *phy); 147*950a6087SEmmanuel Vadot int phy_get_by_ofw_idx(device_t consumer, phandle_t node, int idx, phy_t *phy); 148*950a6087SEmmanuel Vadot int phy_get_by_ofw_property(device_t consumer, phandle_t node, char *name, 149*950a6087SEmmanuel Vadot phy_t *phy); 150*950a6087SEmmanuel Vadot #endif 151*950a6087SEmmanuel Vadot 152*950a6087SEmmanuel Vadot #endif /* _DEV_PHY_H_ */ 153