1 /*-
2 * Copyright 2018 Michal Meloun <mmel@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/lock.h>
34 #include <sys/queue.h>
35 #include <sys/sx.h>
36
37
38 #include <dev/extres/phy/phy_usb.h>
39 #include <dev/extres/phy/phy_internal.h>
40
41 /*
42 * USB phy controller methods.
43 */
44 static phynode_usb_method_t phynode_usb_methods[] = {
45
46 PHYNODEUSBMETHOD_END
47 };
48 DEFINE_CLASS_1(phynode_usb, phynode_usb_class, phynode_usb_methods,
49 0, phynode_class);
50
51 /*
52 * Create and initialize phy object, but do not register it.
53 */
54 struct phynode *
55 phynode_usb_create(device_t pdev, phynode_class_t phynode_class,
56 struct phynode_usb_init_def *def)
57
58 {
59 struct phynode *phynode;
60 struct phynode_usb_sc *sc;
61
62 phynode = phynode_create(pdev, phynode_class, &def->phynode_init_def);
63 if (phynode == NULL)
64 return (NULL);
65 sc = phynode_get_softc(phynode);
66 sc->std_param = def->std_param;
67 return (phynode);
68 }
69
70 struct phynode
71 *phynode_usb_register(struct phynode *phynode)
72 {
73
74 return (phynode_register(phynode));
75 }
76
77 /* --------------------------------------------------------------------------
78 *
79 * Real consumers executive
80 *
81 */
82
83 /*
84 * Set USB phy mode. (PHY_USB_MODE_*)
85 */
86 int
87 phynode_usb_set_mode(struct phynode *phynode, int usb_mode)
88 {
89 int rv;
90
91 PHY_TOPO_ASSERT();
92
93 PHYNODE_XLOCK(phynode);
94 rv = PHYNODE_USB_SET_MODE(phynode, usb_mode);
95 PHYNODE_UNLOCK(phynode);
96 return (rv);
97 }
98
99 /*
100 * Get USB phy mode. (PHY_USB_MODE_*)
101 */
102 int
103 phynode_usb_get_mode(struct phynode *phynode, int *usb_mode)
104 {
105 int rv;
106
107 PHY_TOPO_ASSERT();
108
109 PHYNODE_XLOCK(phynode);
110 rv = PHYNODE_USB_GET_MODE(phynode, usb_mode);
111 PHYNODE_UNLOCK(phynode);
112 return (rv);
113 }
114
115 /* --------------------------------------------------------------------------
116 *
117 * USB phy consumers interface.
118 *
119 */
120 int phy_usb_set_mode(phy_t phy, int usb_mode)
121 {
122 int rv;
123 struct phynode *phynode;
124
125 phynode = phy->phynode;
126 KASSERT(phynode->ref_cnt > 0,
127 ("Attempt to access unreferenced phy.\n"));
128
129 PHY_TOPO_SLOCK();
130 rv = phynode_usb_set_mode(phynode, usb_mode);
131 PHY_TOPO_UNLOCK();
132 return (rv);
133 }
134
135 int phy_usb_get_mode(phy_t phy, int *usb_mode)
136 {
137 int rv;
138 struct phynode *phynode;
139
140 phynode = phy->phynode;
141 KASSERT(phynode->ref_cnt > 0,
142 ("Attempt to access unreferenced phy.\n"));
143
144 PHY_TOPO_SLOCK();
145 rv = phynode_usb_get_mode(phynode, usb_mode);
146 PHY_TOPO_UNLOCK();
147 return (rv);
148 }
Cache object: 4485a7011973c85210f44897e42cca69
|