xref: /freebsd-13-stable/sys/dev/extres/phy/phy.h (revision f8167e0404dab9ffeaca95853dd237ab7c587f82)
1 /*-
2  * Copyright 2016 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 ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef DEV_EXTRES_PHY_H
27 #define DEV_EXTRES_PHY_H
28 #include "opt_platform.h"
29 
30 #include <sys/kobj.h>
31 #ifdef FDT
32 #include <dev/ofw/ofw_bus.h>
33 #endif
34 #include "phynode_if.h"
35 
36 #define	PHY_STATUS_ENABLED	0x00000001
37 
38 typedef struct phy *phy_t;
39 
40 /* Initialization parameters. */
41 struct phynode_init_def {
42 	intptr_t		id;		/* Phy ID */
43 #ifdef FDT
44 	 phandle_t 		ofw_node;	/* OFW node of phy */
45 #endif
46 };
47 
48 /*
49  * Shorthands for constructing method tables.
50  */
51 #define	PHYNODEMETHOD		KOBJMETHOD
52 #define	PHYNODEMETHOD_END	KOBJMETHOD_END
53 #define phynode_method_t	kobj_method_t
54 #define phynode_class_t		kobj_class_t
55 DECLARE_CLASS(phynode_class);
56 
57 /*
58  * Provider interface
59  */
60 struct phynode *phynode_create(device_t pdev, phynode_class_t phynode_class,
61     struct phynode_init_def *def);
62 struct phynode *phynode_register(struct phynode *phynode);
63 void *phynode_get_softc(struct phynode *phynode);
64 device_t phynode_get_device(struct phynode *phynode);
65 intptr_t phynode_get_id(struct phynode *phynode);
66 int phynode_enable(struct phynode *phynode);
67 int phynode_disable(struct phynode *phynode);
68 int phynode_status(struct phynode *phynode, int *status);
69 #ifdef FDT
70 phandle_t phynode_get_ofw_node(struct phynode *phynode);
71 #endif
72 
73 /*
74  * Consumer interface
75  */
76 int phy_get_by_id(device_t consumer_dev, device_t provider_dev, intptr_t id,
77     phy_t *phy);
78 void phy_release(phy_t phy);
79 int phy_enable(phy_t phy);
80 int phy_disable(phy_t phy);
81 int phy_status(phy_t phy, int *value);
82 
83 #ifdef FDT
84 int phy_get_by_ofw_name(device_t consumer, phandle_t node, char *name,
85     phy_t *phy);
86 int phy_get_by_ofw_idx(device_t consumer, phandle_t node, int idx, phy_t *phy);
87 int phy_get_by_ofw_property(device_t consumer, phandle_t node, char *name,
88     phy_t *phy);
89 #endif
90 
91 #endif /* DEV_EXTRES_PHY_H */
92