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 * $FreeBSD$
26 */
27
28#ifndef DEV_EXTRES_PHY_H
29#define DEV_EXTRES_PHY_H
30#include "opt_platform.h"
31
32#include <sys/kobj.h>
33#ifdef FDT
34#include <dev/ofw/ofw_bus.h>
35#endif
36#include "phynode_if.h"
37
38#define	PHY_STATUS_ENABLED	0x00000001
39
40typedef struct phy *phy_t;
41
42/* Initialization parameters. */
43struct phynode_init_def {
44	intptr_t		id;		/* Phy ID */
45#ifdef FDT
46	 phandle_t 		ofw_node;	/* OFW node of phy */
47#endif
48};
49
50/*
51 * Shorthands for constructing method tables.
52 */
53#define	PHYNODEMETHOD		KOBJMETHOD
54#define	PHYNODEMETHOD_END	KOBJMETHOD_END
55#define phynode_method_t	kobj_method_t
56#define phynode_class_t		kobj_class_t
57DECLARE_CLASS(phynode_class);
58
59/*
60 * Provider interface
61 */
62struct phynode *phynode_create(device_t pdev, phynode_class_t phynode_class,
63    struct phynode_init_def *def);
64struct phynode *phynode_register(struct phynode *phynode);
65void *phynode_get_softc(struct phynode *phynode);
66device_t phynode_get_device(struct phynode *phynode);
67intptr_t phynode_get_id(struct phynode *phynode);
68int phynode_enable(struct phynode *phynode);
69int phynode_disable(struct phynode *phynode);
70int phynode_status(struct phynode *phynode, int *status);
71#ifdef FDT
72phandle_t phynode_get_ofw_node(struct phynode *phynode);
73#endif
74
75/*
76 * Consumer interface
77 */
78int phy_get_by_id(device_t consumer_dev, device_t provider_dev, intptr_t id,
79    phy_t *phy);
80void phy_release(phy_t phy);
81int phy_enable(phy_t phy);
82int phy_disable(phy_t phy);
83int phy_status(phy_t phy, int *value);
84
85#ifdef FDT
86int phy_get_by_ofw_name(device_t consumer, phandle_t node, char *name,
87    phy_t *phy);
88int phy_get_by_ofw_idx(device_t consumer, phandle_t node, int idx, phy_t *phy);
89int phy_get_by_ofw_property(device_t consumer, phandle_t node, char *name,
90    phy_t *phy);
91#endif
92
93#endif /* DEV_EXTRES_PHY_H */
94