1 /*- 2 * Copyright 2016 Michal Meloun <[email protected]> 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 40 typedef struct phy *phy_t; 41 42 /* Initialization parameters. */ 43 struct 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 57 DECLARE_CLASS(phynode_class); 58 59 /* 60 * Provider interface 61 */ 62 struct phynode *phynode_create(device_t pdev, phynode_class_t phynode_class, 63 struct phynode_init_def *def); 64 struct phynode *phynode_register(struct phynode *phynode); 65 void *phynode_get_softc(struct phynode *phynode); 66 device_t phynode_get_device(struct phynode *phynode); 67 intptr_t phynode_get_id(struct phynode *phynode); 68 int phynode_enable(struct phynode *phynode); 69 int phynode_disable(struct phynode *phynode); 70 int phynode_status(struct phynode *phynode, int *status); 71 #ifdef FDT 72 phandle_t phynode_get_ofw_node(struct phynode *phynode); 73 #endif 74 75 /* 76 * Consumer interface 77 */ 78 int phy_get_by_id(device_t consumer_dev, device_t provider_dev, intptr_t id, 79 phy_t *phy); 80 void phy_release(phy_t phy); 81 int phy_enable(phy_t phy); 82 int phy_disable(phy_t phy); 83 int phy_status(phy_t phy, int *value); 84 85 #ifdef FDT 86 int phy_get_by_ofw_name(device_t consumer, phandle_t node, char *name, 87 phy_t *phy); 88 int phy_get_by_ofw_idx(device_t consumer, phandle_t node, int idx, phy_t *phy); 89 int 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