1 /* $NetBSD: fdt_port.h,v 1.1 2018/04/03 12:40:20 bouyer Exp $ */ 2 3 /*- 4 * Copyright (c) 2018 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Manuel Bouyer. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * ports and endpoints management. from 34 * linux/Documentation/devicetree/bindings/graph.txt 35 * 2 endpoints can be connected together in the device tree. In this case 36 * an endpoint will have a remote endpoint. 37 * A pair of connected endpoints can be activated by a driver; when it choose 38 * to use this path. 39 * A pair of active endpoints can be enabled; when a driver starts to send 40 * a signal. Disabling a pair of endpoints can cause appropriate actions 41 * to save power (stop clocks, disable output buffers, turn on/off power, ...) 42 */ 43 44 #ifndef _DEV_FDT_FDT_PORT_H_ 45 #define _DEV_FDT_FDT_PORT_H_ 46 47 struct fdt_port; 48 struct fdt_endpoint; 49 50 struct fdt_device_ports { 51 struct fdt_port *dp_port; /* this device's ports */ 52 int dp_nports; /* number of ports for this device */ 53 device_t dp_dev; 54 /* callbacks to device drivers owning endpoints */ 55 void (*dp_ep_connect)(device_t, struct fdt_endpoint *, bool); 56 int (*dp_ep_activate)(device_t, struct fdt_endpoint *, bool); 57 int (*dp_ep_enable)(device_t, struct fdt_endpoint *, bool); 58 void * (*dp_ep_get_data)(device_t, struct fdt_endpoint *); 59 SLIST_ENTRY(fdt_device_ports) dp_list; 60 }; 61 62 enum endpoint_type { 63 EP_OTHER = 0, 64 EP_CONNECTOR, 65 EP_PANEL, 66 }; 67 68 69 /* 70 * register a device's ports and enpoints into the provided fdt_device_ports. 71 * when and endpoint is connected to a remote endpoint, dp_ep_connect 72 * is called for the devices associated to both endpoints 73 */ 74 int fdt_ports_register(struct fdt_device_ports *, device_t, 75 int, enum endpoint_type); 76 77 /* various methods to retrive an enpoint descriptor */ 78 struct fdt_endpoint *fdt_endpoint_get_from_phandle(int); 79 struct fdt_endpoint *fdt_endpoint_get_from_index(struct fdt_device_ports *, 80 int, int); 81 struct fdt_endpoint *fdt_endpoint_remote(struct fdt_endpoint *); 82 83 /* 84 * get informations/data for a given endpoint 85 */ 86 int fdt_endpoint_port_index(struct fdt_endpoint *); 87 int fdt_endpoint_index(struct fdt_endpoint *); 88 device_t fdt_endpoint_device(struct fdt_endpoint *); 89 bool fdt_endpoint_is_active(struct fdt_endpoint *); 90 bool fdt_endpoint_is_enabled(struct fdt_endpoint *); 91 /* 92 * call dp_ep_get_data() for the endpoint. The returned pointer is 93 * type of driver-specific. 94 */ 95 void * fdt_endpoint_get_data(struct fdt_endpoint *); 96 97 /* 98 * Activate/deactivate an endpoint. This causes dp_ep_activate() to be 99 * called for the remote endpoint 100 */ 101 int fdt_endpoint_activate(struct fdt_endpoint *, bool); 102 /* 103 * Enable/disable an endpoint. This causes dp_ep_enable() to be called for 104 * the remote endpoint 105 */ 106 int fdt_endpoint_enable(struct fdt_endpoint *, bool); 107 108 #endif /* _DEV_FDT_FDT_PORT_H_ */ 109