2 * Copyright 2018 Michal Meloun <mmel@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/kernel.h>
33 #include <sys/queue.h>
37 #include <dev/extres/phy/phy_usb.h>
38 #include <dev/extres/phy/phy_internal.h>
40 #include "phydev_if.h"
43 * USB phy controller methods.
45 static phynode_usb_method_t phynode_usb_methods[] = {
49 DEFINE_CLASS_1(phynode_usb, phynode_usb_class, phynode_usb_methods,
53 * Create and initialize phy object, but do not register it.
56 phynode_usb_create(device_t pdev, phynode_class_t phynode_class,
57 struct phynode_usb_init_def *def)
60 struct phynode *phynode;
61 struct phynode_usb_sc *sc;
63 phynode = phynode_create(pdev, phynode_class, &def->phynode_init_def);
66 sc = phynode_get_softc(phynode);
67 sc->std_param = def->std_param;
72 *phynode_usb_register(struct phynode *phynode)
75 return (phynode_register(phynode));
78 /* --------------------------------------------------------------------------
80 * Real consumers executive
85 * Set USB phy mode. (PHY_USB_MODE_*)
88 phynode_usb_set_mode(struct phynode *phynode, int usb_mode)
94 PHYNODE_XLOCK(phynode);
95 rv = PHYNODE_USB_SET_MODE(phynode, usb_mode);
96 PHYNODE_UNLOCK(phynode);
101 * Get USB phy mode. (PHY_USB_MODE_*)
104 phynode_usb_get_mode(struct phynode *phynode, int *usb_mode)
110 PHYNODE_XLOCK(phynode);
111 rv = PHYNODE_USB_GET_MODE(phynode, usb_mode);
112 PHYNODE_UNLOCK(phynode);
116 /* --------------------------------------------------------------------------
118 * USB phy consumers interface.
121 int phy_usb_set_mode(phy_t phy, int usb_mode)
124 struct phynode *phynode;
126 phynode = phy->phynode;
127 KASSERT(phynode->ref_cnt > 0,
128 ("Attempt to access unreferenced phy.\n"));
131 rv = phynode_usb_set_mode(phynode, usb_mode);
136 int phy_usb_get_mode(phy_t phy, int *usb_mode)
139 struct phynode *phynode;
141 phynode = phy->phynode;
142 KASSERT(phynode->ref_cnt > 0,
143 ("Attempt to access unreferenced phy.\n"));
146 rv = phynode_usb_get_mode(phynode, usb_mode);