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