Home | History | Annotate | Line # | Download | only in fdt
      1 /*	$NetBSD: fdt_port.h,v 1.7 2024/02/10 09:21:52 andvar 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 drm_device;
     48 
     49 struct fdt_port;
     50 struct fdt_endpoint;
     51 
     52 struct fdt_device_ports {
     53 	struct fdt_port *dp_port; /* this device's ports */
     54 	int		dp_nports; /* number of ports for this device */
     55 	device_t	dp_dev;
     56 	/* callbacks to device drivers owning endpoints */
     57 	void		(*dp_ep_connect)(device_t, struct fdt_endpoint *, bool);
     58 	int		(*dp_ep_activate)(device_t, struct fdt_endpoint *, bool);
     59 	int		(*dp_ep_enable)(device_t, struct fdt_endpoint *, bool);
     60 	void *		(*dp_ep_get_data)(device_t, struct fdt_endpoint *);
     61 	SLIST_ENTRY(fdt_device_ports) dp_list;
     62 };
     63 
     64 enum endpoint_type {
     65 	EP_OTHER = 0,
     66 	EP_CONNECTOR,
     67 	EP_PANEL,
     68 
     69 	EP_DRM_BRIDGE,		/* struct drm_bridge */
     70 	EP_DRM_CONNECTOR,	/* struct drm_connector */
     71 	EP_DRM_CRTC,		/* struct drm_crtc */
     72 	EP_DRM_ENCODER,		/* struct drm_encoder */
     73 	EP_DRM_PANEL,		/* struct drm_panel */
     74 };
     75 
     76 
     77 /*
     78  * register a device's ports and endpoints into the provided fdt_device_ports.
     79  * when and endpoint is connected to a remote endpoint, dp_ep_connect
     80  * is called for the devices associated to both endpoints
     81  */
     82 int fdt_ports_register(struct fdt_device_ports *, device_t,
     83 					int, enum endpoint_type);
     84 
     85 /* various methods to retrieve an endpoint descriptor */
     86 struct fdt_endpoint *fdt_endpoint_get_from_phandle(int);
     87 struct fdt_endpoint *fdt_endpoint_get_from_index(struct fdt_device_ports *,
     88 							int, int);
     89 struct fdt_endpoint *fdt_endpoint_remote(struct fdt_endpoint *);
     90 struct fdt_endpoint *fdt_endpoint_remote_from_index(struct fdt_device_ports *,
     91 							int, int);
     92 
     93 /*
     94  * get informations/data for a given endpoint
     95  */
     96 int fdt_endpoint_port_index(struct fdt_endpoint *);
     97 int fdt_endpoint_index(struct fdt_endpoint *);
     98 int fdt_endpoint_phandle(struct fdt_endpoint *);
     99 device_t fdt_endpoint_device(struct fdt_endpoint *);
    100 bool fdt_endpoint_is_active(struct fdt_endpoint *);
    101 bool fdt_endpoint_is_enabled(struct fdt_endpoint *);
    102 enum endpoint_type fdt_endpoint_type(struct fdt_endpoint *);
    103 /*
    104  * call dp_ep_get_data() for the endpoint. The returned pointer is
    105  * type of driver-specific.
    106  */
    107 void * fdt_endpoint_get_data(struct fdt_endpoint *);
    108 
    109 /*
    110  * Activate/deactivate an endpoint. This causes dp_ep_activate() to be
    111  * called for the remote endpoint
    112  */
    113 int fdt_endpoint_activate(struct fdt_endpoint *, bool);
    114 
    115 /*
    116  * Activate/deactivate an endpoint by direct reference.
    117  */
    118 int fdt_endpoint_activate_direct(struct fdt_endpoint *, bool);
    119 
    120 /*
    121  * Enable/disable an endpoint. This causes dp_ep_enable() to be called for
    122  * the remote endpoint
    123  */
    124 int fdt_endpoint_enable(struct fdt_endpoint *, bool);
    125 
    126 #endif /* _DEV_FDT_FDT_PORT_H */
    127