Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/fdt Add connector and panel drivers (panel supports ...



details:   https://anonhg.NetBSD.org/src/rev/4411116f0e34
branches:  trunk
changeset: 831514:4411116f0e34
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Tue Apr 03 12:40:20 2018 +0000

description:
Add connector and panel drivers (panel supports only panel-lvds and
panel-dual-lvds at this time, but can easily be extended to other types
of panels).
Add an API for ports/endpoints.
Proposed on tech-kern@ a few days ago, ok jmcneill@

diffstat:

 sys/dev/fdt/connector_fdt.c |  129 +++++++++++++++
 sys/dev/fdt/connector_fdt.h |   41 ++++
 sys/dev/fdt/fdt_port.c      |  370 ++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/fdt/fdt_port.h      |  108 ++++++++++++
 sys/dev/fdt/files.fdt       |   12 +-
 sys/dev/fdt/panel_fdt.c     |  192 ++++++++++++++++++++++
 sys/dev/fdt/panel_fdt.h     |   62 +++++++
 7 files changed, 913 insertions(+), 1 deletions(-)

diffs (truncated from 952 to 300 lines):

diff -r 7331c0e77853 -r 4411116f0e34 sys/dev/fdt/connector_fdt.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/fdt/connector_fdt.c       Tue Apr 03 12:40:20 2018 +0000
@@ -0,0 +1,129 @@
+/*     $NetBSD: connector_fdt.c,v 1.1 2018/04/03 12:40:20 bouyer Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Manuel Bouyer.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * connector driver.
+ * specified in linux/Documentation/devicetree/bindings/display/connector/
+ * basically it only register its endpoint.
+ */
+
+#include <sys/cdefs.h>
+
+__KERNEL_RCSID(1, "$NetBSD: connector_fdt.c,v 1.1 2018/04/03 12:40:20 bouyer Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/bus.h>
+#include <sys/kmem.h>
+
+#include <dev/fdt/fdtvar.h>
+#include <dev/fdt/fdt_port.h>
+#include <dev/fdt/connector_fdt.h>
+
+static int fdt_connector_match(device_t, cfdata_t, void *);
+static void fdt_connector_attach(device_t, device_t, void *);
+static void *fdt_connector_get_data(device_t, struct fdt_endpoint *);
+
+SLIST_HEAD(, fdt_connector_softc) fdt_connectors =
+    SLIST_HEAD_INITIALIZER(&fdt_connectors);
+
+struct fdt_connector_softc {
+       device_t sc_dev;
+       int sc_phandle;
+       struct fdt_connector sc_con;
+       SLIST_ENTRY(fdt_connector_softc) sc_list;
+       struct fdt_device_ports sc_ports;
+};
+
+#define sc_type sc_con.con_type
+
+CFATTACH_DECL_NEW(fdt_connector, sizeof(struct fdt_connector_softc),
+    fdt_connector_match, fdt_connector_attach, NULL, NULL);
+
+static const struct of_compat_data compat_data[] = {
+       {"composite-video-connector", CON_TV},
+       {"dvi-connector", CON_DVI},
+       {"hdmi-connector", CON_HDMI},
+       {"vga-connector", CON_VGA},
+       { NULL }
+};
+
+static int
+fdt_connector_match(device_t parent, cfdata_t cf, void *aux)
+{
+       const struct fdt_attach_args *faa = aux;
+
+       return of_match_compat_data(faa->faa_phandle, compat_data);
+}
+
+static void
+fdt_connector_attach(device_t parent, device_t self, void *aux)
+{
+       struct fdt_connector_softc *sc = device_private(self);
+       const struct fdt_attach_args * const faa = aux;
+       const int phandle = faa->faa_phandle;
+
+       sc->sc_dev = self;
+       sc->sc_phandle = phandle;
+       sc->sc_type = of_search_compatible(phandle, compat_data)->data;
+
+       SLIST_INSERT_HEAD(&fdt_connectors, sc, sc_list);
+
+       aprint_naive("\n");
+       switch(sc->sc_type) {
+       case CON_VGA:
+               aprint_normal(": VGA");
+               break;
+       case CON_DVI:
+               aprint_normal(": DVI");
+               break;
+       case CON_HDMI:
+               aprint_normal(": HDMI");
+               break;
+       case CON_TV:
+               aprint_normal(": composite");
+               break;
+       default:
+               panic("unknown connector type %d\n", sc->sc_type);
+       }
+       aprint_normal(" connector\n");
+       sc->sc_ports.dp_ep_get_data = fdt_connector_get_data;
+       fdt_ports_register(&sc->sc_ports, self, phandle, EP_CONNECTOR);
+}
+
+static void *
+fdt_connector_get_data(device_t dev, struct fdt_endpoint *ep)
+{
+       struct fdt_connector_softc *sc = device_private(dev);
+
+       return &sc->sc_con;
+}
diff -r 7331c0e77853 -r 4411116f0e34 sys/dev/fdt/connector_fdt.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/fdt/connector_fdt.h       Tue Apr 03 12:40:20 2018 +0000
@@ -0,0 +1,41 @@
+/*     $NetBSD: connector_fdt.h,v 1.1 2018/04/03 12:40:20 bouyer Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Manuel Bouyer.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+enum connector_type {
+       CON_VGA,
+       CON_DVI,
+       CON_HDMI,
+       CON_TV,
+};
+
+struct fdt_connector {
+       enum connector_type con_type;
+};
diff -r 7331c0e77853 -r 4411116f0e34 sys/dev/fdt/fdt_port.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/fdt/fdt_port.c    Tue Apr 03 12:40:20 2018 +0000
@@ -0,0 +1,370 @@
+/*     $NetBSD: fdt_port.c,v 1.1 2018/04/03 12:40:20 bouyer Exp $      */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Manuel Bouyer.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * ports and endpoints management. from
+ * linux/Documentation/devicetree/bindings/graph.txt
+ * Given a device and its node, it enumerates all ports and endpoints for this
+ * device, and register connections with the remote endpoints.
+ */
+
+#include <sys/cdefs.h>
+
+__KERNEL_RCSID(1, "$NetBSD: fdt_port.c,v 1.1 2018/04/03 12:40:20 bouyer Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/bus.h>
+#include <sys/kmem.h>
+
+#include <dev/fdt/fdtvar.h>
+#include <dev/fdt/fdt_port.h>
+
+struct fdt_endpoint;
+
+struct fdt_port {
+       int     port_id;
+       int     port_phandle; /* port's node */
+       struct fdt_endpoint *port_ep; /* this port's endpoints */
+       int     port_nep; /* number of endpoints for this port */
+       struct fdt_device_ports *port_dp; /* this port's device */
+};
+
+struct fdt_endpoint {
+       int             ep_id;
+       enum endpoint_type ep_type;
+       int             ep_phandle;
+       struct fdt_port *ep_port; /* parent of this endpoint */
+       int             ep_rphandle; /* report endpoint */
+       struct fdt_endpoint *ep_rep;
+       bool            ep_active;
+       bool            ep_enabled;
+};
+
+SLIST_HEAD(, fdt_device_ports) fdt_port_devices =
+    SLIST_HEAD_INITIALIZER(&fdt_port_devices);
+
+static void fdt_endpoints_register(int, struct fdt_port *, enum endpoint_type);
+static const char *ep_name(struct fdt_endpoint *, char *, int);
+
+struct fdt_endpoint *
+fdt_endpoint_get_from_phandle(int rphandle)
+{
+       struct fdt_device_ports *ports;
+       int p, e;
+
+       if (rphandle < 0)
+               return NULL;
+
+       SLIST_FOREACH(ports, &fdt_port_devices, dp_list) {
+               for (p = 0; p < ports->dp_nports; p++) {
+                       struct fdt_port *port = &ports->dp_port[p];
+                       for (e = 0; e < port->port_nep; e++) {
+                               struct fdt_endpoint *ep = &port->port_ep[e];
+                               if (ep->ep_phandle == rphandle)
+                                       return ep;
+                       }
+               }
+       }
+       return NULL;
+
+}
+
+struct fdt_endpoint *
+fdt_endpoint_get_from_index(struct fdt_device_ports *device_ports,
+    int port_index, int ep_index)
+{
+       int p, e;
+       for (p = 0; p < device_ports->dp_nports; p++) {
+               struct fdt_port *port = &device_ports->dp_port[p];
+               if (port->port_id != port_index)
+                       continue;
+               for (e = 0; e < port->port_nep; e++) {
+                       struct fdt_endpoint *ep = &port->port_ep[e];
+                       if (ep->ep_id == ep_index) {
+                               return ep;
+                       }
+               }
+       }
+       return NULL;



Home | Main Index | Thread Index | Old Index