svn commit: r331402 - in stable/11/sys/arm: conf versatile

Oleksandr Tymoshenko gonzo at FreeBSD.org
Fri Mar 23 01:37:33 UTC 2018


Author: gonzo
Date: Fri Mar 23 01:37:31 2018
New Revision: 331402
URL: https://svnweb.freebsd.org/changeset/base/331402

Log:
  MFC r316370-r316371
  
  r316370:
  [versatilepb] Convert VERSATILEPB kernel to INTRNG and switch to upstream DTB
  
  Scope of this change is somewhat larger than just converting to INTRNG.
  The reason for this is that INTRNG support required switching from custom
  to upstream DTS because custom DTS didn't have interrup routing information.
  This switch caused rewrite of PCI and CLCD drivers and adding SCM module.
  List of changes in this commit:
  
  - Enable INTRNG and switch to versatile-pb.dts
  
  - Add SCM driver that controls various peripheral devices like LCD or
    PCI controller. Previously registers required for power-up and
    configuring peripherals were part of their respective nodes. Upstream
    DTS has dedicated node for SCM
  
  - Convert PL190 driver to INTRNG
  
  - Convert Versatile SIC (secondary interrupt controller) to INTRNG
  
  - Refactor CLCD driver to use SCM API to power up and configuration
  
  - Refactor PCI driver to use SCM API to enable controller
  
  - Refactor PCI driver to use interrupt map provided in DTS for
    interrupt routing. As a result it fixes broken IRQ routing and
    it's no longer required to run QEMU with "-global versatile_pci.broken-irq-mapping=1"
    command-line arguments
  
  r316371:
  [versatilepb] Fix keyboard driver after switching to upstream DTS
  
  FreeBSD's DTS contained only one PL050 node and driver considered it to
  be PS/2 keyboard. In reality PL050 is a PS/2 port that pushes bytes to/from
  the periphers connected to it. New DTS contains two nodes and QEMU emulates
  keyboard connected to port #0 and mouse connected to port #1. Since there
  is no way to say what's connected to port by checking DTS we hardcode
  this knowledge in the driver: it assumes keyboard on port #0 and ignores
  port #1 altogether.
  
  Also QEMU defaults emulated keyboard to scan code set 2 while driver used
  to work with scan code set 1 so when initializing driver make sure keyboard
  is switched to scan code set 1

Added:
  stable/11/sys/arm/versatile/versatile_scm.c
     - copied unchanged from r316371, head/sys/arm/versatile/versatile_scm.c
  stable/11/sys/arm/versatile/versatile_scm.h
     - copied unchanged from r316371, head/sys/arm/versatile/versatile_scm.h
Modified:
  stable/11/sys/arm/conf/VERSATILEPB
  stable/11/sys/arm/versatile/files.versatile
  stable/11/sys/arm/versatile/pl050.c
  stable/11/sys/arm/versatile/versatile_clcd.c
  stable/11/sys/arm/versatile/versatile_pci.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/arm/conf/VERSATILEPB
==============================================================================
--- stable/11/sys/arm/conf/VERSATILEPB	Fri Mar 23 00:40:08 2018	(r331401)
+++ stable/11/sys/arm/conf/VERSATILEPB	Fri Mar 23 01:37:31 2018	(r331402)
@@ -68,7 +68,9 @@ makeoptions	SC_DFLT_FONT=cp437
 device		md
 device		random			# Entropy device
 
+options 	INTRNG
+
 # Flattened Device Tree
 options 	FDT			# Configure using FDT/DTB data
 options 	FDT_DTB_STATIC
-makeoptions	FDT_DTS_FILE=versatilepb.dts
+makeoptions	FDT_DTS_FILE=versatile-pb.dts

Modified: stable/11/sys/arm/versatile/files.versatile
==============================================================================
--- stable/11/sys/arm/versatile/files.versatile	Fri Mar 23 00:40:08 2018	(r331401)
+++ stable/11/sys/arm/versatile/files.versatile	Fri Mar 23 01:37:31 2018	(r331402)
@@ -6,6 +6,7 @@ arm/versatile/versatile_machdep.c		standard
 arm/versatile/versatile_clcd.c			optional sc
 arm/versatile/versatile_common.c		standard
 arm/versatile/versatile_pci.c			optional pci
+arm/versatile/versatile_scm.c			standard
 arm/versatile/versatile_sic.c			standard
 arm/versatile/versatile_timer.c			standard
 

Modified: stable/11/sys/arm/versatile/pl050.c
==============================================================================
--- stable/11/sys/arm/versatile/pl050.c	Fri Mar 23 00:40:08 2018	(r331401)
+++ stable/11/sys/arm/versatile/pl050.c	Fri Mar 23 01:37:31 2018	(r331402)
@@ -109,7 +109,10 @@ __FBSDID("$FreeBSD$");
 #define	KMI_DRIVER_NAME          "kmi"
 #define	KMI_NFKEY        (sizeof(fkey_tab)/sizeof(fkey_tab[0]))	/* units */
 
+#define	SET_SCANCODE_SET	0xf0
+
 struct kmi_softc {
+	device_t sc_dev;
 	keyboard_t sc_kbd;
 	keymap_t sc_keymap;
 	accentmap_t sc_accmap;
@@ -145,6 +148,8 @@ static int	kmi_ioctl(keyboard_t *, u_long, caddr_t);
 static int	kmi_enable(keyboard_t *);
 static int	kmi_disable(keyboard_t *);
 
+static int	kmi_attached = 0;
+
 /* early keyboard probe, not supported */
 static int
 kmi_configure(int flags)
@@ -483,7 +488,6 @@ kmi_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
 	}
 }
 
-
 /* clear the internal state of the keyboard */
 static void
 kmi_clear_state(keyboard_t *kbd)
@@ -613,6 +617,17 @@ pl050_kmi_probe(device_t dev)
 	if (!ofw_bus_status_okay(dev))
 		return (ENXIO);
 
+	/*
+	 * PL050 is plain PS2 port that pushes bytes to/from computer
+	 * VersatilePB has two such ports and QEMU simulates keyboard
+	 * connected to port #0 and mouse connected to port #1. This
+	 * information can't be obtained from device tree so we just
+	 * hardcode this knowledge here. We attach keyboard driver to
+	 * port #0 and ignore port #1
+	 */
+	if (kmi_attached)
+		return (ENXIO);
+
 	if (ofw_bus_is_compatible(dev, "arm,pl050")) {
 		device_set_desc(dev, "PL050 Keyboard/Mouse Interface");
 		return (BUS_PROBE_DEFAULT);
@@ -628,7 +643,9 @@ pl050_kmi_attach(device_t dev)
 	keyboard_t *kbd;
 	int rid;
 	int i;
+	uint32_t ack;
 
+	sc->sc_dev = dev;
 	kbd = &sc->sc_kbd;
 	rid = 0;
 
@@ -657,6 +674,16 @@ pl050_kmi_attach(device_t dev)
 
 	/* TODO: clock & divisor */
 
+	pl050_kmi_write_4(sc, KMICR, KMICR_EN);
+
+	pl050_kmi_write_4(sc, KMIDATA, SET_SCANCODE_SET);
+	/* read out ACK */
+	ack = pl050_kmi_read_4(sc, KMIDATA);
+	/* Set Scan Code set 1 (XT) */
+	pl050_kmi_write_4(sc, KMIDATA, 1);
+	/* read out ACK */
+	ack = pl050_kmi_read_4(sc, KMIDATA);
+
 	pl050_kmi_write_4(sc, KMICR, KMICR_EN | KMICR_RXINTREN);
 
 	kbd_init_struct(kbd, KMI_DRIVER_NAME, KB_OTHER, 
@@ -692,6 +719,7 @@ pl050_kmi_attach(device_t dev)
 	if (bootverbose) {
 		genkbd_diag(kbd, bootverbose);
 	}
+	kmi_attached = 1;
 	return (0);
 
 detach:

Modified: stable/11/sys/arm/versatile/versatile_clcd.c
==============================================================================
--- stable/11/sys/arm/versatile/versatile_clcd.c	Fri Mar 23 00:40:08 2018	(r331401)
+++ stable/11/sys/arm/versatile/versatile_clcd.c	Fri Mar 23 01:37:31 2018	(r331402)
@@ -1,7 +1,7 @@
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
- * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo at freebsd.org>
+ * Copyright (c) 2012-2017 Oleksandr Tymoshenko <gonzo at freebsd.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -52,22 +52,12 @@ __FBSDID("$FreeBSD$");
 #include <dev/fb/fbreg.h>
 #include <dev/syscons/syscons.h>
 
+#include <arm/versatile/versatile_scm.h>
+
 #include <machine/bus.h>
 
 #define	PL110_VENDOR_ARM926PXP	1
 
-#define	MEM_SYS		0
-#define	MEM_CLCD	1
-#define MEM_REGIONS	2
-
-#define	SYS_CLCD		0x00
-#define		SYS_CLCD_CLCDID_SHIFT	0x08
-#define		SYS_CLCD_CLCDID_MASK	0x1f
-#define		SYS_CLCD_PWR3V5VSWITCH	(1 << 4)
-#define		SYS_CLCD_VDDPOSSWITCH 	(1 << 3)
-#define		SYS_CLCD_NLCDIOON  	(1 << 2)
-#define		SYS_CLCD_LCD_MODE_MASK	0x03
-
 #define	CLCD_MODE_RGB888	0x0
 #define	CLCD_MODE_RGB555	0x01
 #define	CLCD_MODE_RBG565	0x02
@@ -122,18 +112,13 @@ __FBSDID("$FreeBSD$");
 #define dprintf(fmt, args...)
 #endif
 
-#define	versatile_clcdc_sys_read_4(sc, reg)	\
-	bus_read_4((sc)->mem_res[MEM_SYS], (reg))
-#define	versatile_clcdc_sys_write_4(sc, reg, val)	\
-	bus_write_4((sc)->mem_res[MEM_SYS], (reg), (val))
-
 #define	versatile_clcdc_read_4(sc, reg)	\
-	bus_read_4((sc)->mem_res[MEM_CLCD], (reg))
+	bus_read_4((sc)->mem_res, (reg))
 #define	versatile_clcdc_write_4(sc, reg, val)	\
-	bus_write_4((sc)->mem_res[MEM_CLCD], (reg), (val))
+	bus_write_4((sc)->mem_res, (reg), (val))
 
 struct versatile_clcdc_softc {
-	struct resource*	mem_res[MEM_REGIONS];
+	struct resource*	mem_res;
 
 	struct mtx		mtx;
 
@@ -208,12 +193,6 @@ static u_char mouse_pointer[16] = {
 
 static struct video_adapter_softc va_softc;
 
-static struct resource_spec versatile_clcdc_mem_spec[] = {
-	{ SYS_RES_MEMORY, 0, RF_ACTIVE },
-	{ SYS_RES_MEMORY, 1, RF_ACTIVE },
-	{ -1, 0, 0 }
-};
-
 static int versatilefb_configure(int);
 static void versatilefb_update_margins(video_adapter_t *adp);
 
@@ -249,21 +228,25 @@ versatile_clcdc_attach(device_t dev)
 {
 	struct versatile_clcdc_softc *sc = device_get_softc(dev);
 	struct video_adapter_softc *va_sc = &va_softc;
-	int err;
+	int err, rid;
 	uint32_t reg;
 	int clcdid;
 	int dma_size;
 
 	/* Request memory resources */
-	err = bus_alloc_resources(dev, versatile_clcdc_mem_spec,
-		sc->mem_res);
-	if (err) {
-		device_printf(dev, "Error: could not allocate memory resources\n");
+	rid = 0;
+	sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
+	if (sc->mem_res == NULL) {
+		device_printf(dev, "could not allocate memory resources\n");
 		return (ENXIO);
 	}
 
-	reg = versatile_clcdc_sys_read_4(sc, SYS_CLCD);
-	clcdid = (reg >> SYS_CLCD_CLCDID_SHIFT) & SYS_CLCD_CLCDID_MASK;
+	err = versatile_scm_reg_read_4(SCM_CLCD, &reg);
+	if (err) {
+		device_printf(dev, "failed to read SCM register\n");
+		goto fail;
+	}
+	clcdid = (reg >> SCM_CLCD_CLCDID_SHIFT) & SCM_CLCD_CLCDID_MASK;
 	switch (clcdid) {
 		case 31:
 			device_printf(dev, "QEMU VGA 640x480\n");
@@ -275,17 +258,17 @@ versatile_clcdc_attach(device_t dev)
 			goto fail;
 	}
 
-	reg &= ~SYS_CLCD_LCD_MODE_MASK;
+	reg &= ~SCM_CLCD_LCD_MODE_MASK;
 	reg |= CLCD_MODE_RGB565;
 	sc->mode = CLCD_MODE_RGB565;
-	versatile_clcdc_sys_write_4(sc, SYS_CLCD, reg);
-	dma_size = sc->width*sc->height*2;
-
-	/*
+	versatile_scm_reg_write_4(SCM_CLCD, reg);
+ 	dma_size = sc->width*sc->height*2;
+ 
+ 	/*
 	 * Power on LCD
 	 */
-	reg |= SYS_CLCD_PWR3V5VSWITCH | SYS_CLCD_NLCDIOON;
-	versatile_clcdc_sys_write_4(sc, SYS_CLCD, reg);
+	reg |= SCM_CLCD_PWR3V5VSWITCH | SCM_CLCD_NLCDIOON;
+	versatile_scm_reg_write_4(SCM_CLCD, reg);
 
 	/*
 	 * XXX: hardcoded timing for VGA. For other modes/panels
@@ -657,7 +640,6 @@ versatilefb_init(int unit, video_adapter_t *adp, int f
 
 	sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
 	sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
-
 
 	adp->va_window = (vm_offset_t) versatilefb_static_window;
 	adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */;

Modified: stable/11/sys/arm/versatile/versatile_pci.c
==============================================================================
--- stable/11/sys/arm/versatile/versatile_pci.c	Fri Mar 23 00:40:08 2018	(r331401)
+++ stable/11/sys/arm/versatile/versatile_pci.c	Fri Mar 23 01:37:31 2018	(r331402)
@@ -1,7 +1,7 @@
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
- * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo at freebsd.org>
+ * Copyright (c) 2012-2017 Oleksandr Tymoshenko <gonzo at freebsd.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -55,18 +55,18 @@ __FBSDID("$FreeBSD$");
 #include <dev/ofw/openfirm.h>
 #include <dev/ofw/ofw_bus.h>
 #include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
 
+#include <arm/versatile/versatile_scm.h>
+
 #include <machine/bus.h>
 #include <machine/fdt.h>
 
-#define	MEM_SYS		0
-#define	MEM_CORE	1
-#define	MEM_BASE	2
-#define	MEM_CONF_BASE	3
-#define MEM_REGIONS	4
+#define	MEM_CORE	0
+#define	MEM_BASE	1
+#define	MEM_CONF_BASE	2
+#define MEM_REGIONS	3
 
-#define	SYS_PCICTL		0x00
-
 #define	PCI_CORE_IMAP0		0x00
 #define	PCI_CORE_IMAP1		0x04
 #define	PCI_CORE_IMAP2		0x08
@@ -95,12 +95,6 @@ __FBSDID("$FreeBSD$");
 #define dprintf(fmt, args...)
 #endif
 
-
-#define	versatile_pci_sys_read_4(reg)	\
-	bus_read_4(sc->mem_res[MEM_SYS], (reg))
-#define	versatile_pci_sys_write_4(reg, val)	\
-	bus_write_4(sc->mem_res[MEM_SYS], (reg), (val))
-
 #define	versatile_pci_core_read_4(reg)	\
 	bus_read_4(sc->mem_res[MEM_CORE], (reg))
 #define	versatile_pci_core_write_4(reg, val)	\
@@ -134,13 +128,13 @@ struct versatile_pci_softc {
 	struct rman		mem_rman;
 
 	struct mtx		mtx;
+	struct ofw_bus_iinfo	pci_iinfo;
 };
 
 static struct resource_spec versatile_pci_mem_spec[] = {
 	{ SYS_RES_MEMORY, 0, RF_ACTIVE },
 	{ SYS_RES_MEMORY, 1, RF_ACTIVE },
 	{ SYS_RES_MEMORY, 2, RF_ACTIVE },
-	{ SYS_RES_MEMORY, 3, RF_ACTIVE },
 	{ -1, 0, 0 }
 };
 
@@ -151,7 +145,7 @@ versatile_pci_probe(device_t dev)
 	if (!ofw_bus_status_okay(dev))
 		return (ENXIO);
 
-	if (ofw_bus_is_compatible(dev, "versatile,pci")) {
+	if (ofw_bus_is_compatible(dev, "arm,versatile-pci")) {
 		device_set_desc(dev, "Versatile PCI controller");
 		return (BUS_PROBE_DEFAULT);
 	}
@@ -167,7 +161,10 @@ versatile_pci_attach(device_t dev)
 	int slot;
 	uint32_t vendordev_id, class_id;
 	uint32_t val;
+	phandle_t node;
 
+	node = ofw_bus_get_node(dev);
+
 	/* Request memory resources */
 	err = bus_alloc_resources(dev, versatile_pci_mem_spec,
 		sc->mem_res);
@@ -191,7 +188,7 @@ versatile_pci_attach(device_t dev)
 	versatile_pci_core_write_4(PCI_CORE_SMAP1, (PCI_NPREFETCH_WINDOW >> 28));
 	versatile_pci_core_write_4(PCI_CORE_SMAP2, (PCI_NPREFETCH_WINDOW >> 28));
 
-	versatile_pci_sys_write_4(SYS_PCICTL, 1);
+	versatile_scm_reg_write_4(SCM_PCICTL, 1);
 
 	for (slot = 0; slot <= PCI_SLOTMAX; slot++) {
 		vendordev_id = versatile_pci_read_4((slot << 11) + PCIR_DEVVENDOR);
@@ -268,6 +265,8 @@ versatile_pci_attach(device_t dev)
 		versatile_pci_conf_write_4((slot << 11) + PCIR_COMMAND, val);
 	}
 
+	ofw_bus_setup_iinfo(node, &sc->pci_iinfo, sizeof(cell_t));
+
 	device_add_child(dev, "pci", -1);
 	return (bus_generic_attach(dev));
 }
@@ -321,7 +320,7 @@ versatile_pci_alloc_resource(device_t bus, device_t ch
 		rm = &sc->io_rman;
 		break;
 	case SYS_RES_IRQ:
-		rm = &sc->irq_rman;
+		rm = NULL;
 		break;
 	case SYS_RES_MEMORY:
 		rm = &sc->mem_rman;
@@ -330,8 +329,11 @@ versatile_pci_alloc_resource(device_t bus, device_t ch
 		return (NULL);
 	}
 
-	rv = rman_reserve_resource(rm, start, end, count, flags, child);
+	if (rm == NULL)
+		return (BUS_ALLOC_RESOURCE(device_get_parent(bus),
+		    child, type, rid, start, end, count, flags));
 
+	rv = rman_reserve_resource(rm, start, end, count, flags, child);
 	if (rv == NULL)
 		return (NULL);
 
@@ -392,8 +394,6 @@ versatile_pci_teardown_intr(device_t dev, device_t chi
 	return BUS_TEARDOWN_INTR(device_get_parent(dev), dev, ires, cookie);
 }
 
-
-
 static int
 versatile_pci_maxslots(device_t dev)
 {
@@ -402,10 +402,33 @@ versatile_pci_maxslots(device_t dev)
 }
 
 static int
-versatile_pci_route_interrupt(device_t pcib, device_t device, int pin)
+versatile_pci_route_interrupt(device_t bus, device_t dev, int pin)
 {
+	struct versatile_pci_softc *sc;
+	struct ofw_pci_register reg;
+	uint32_t pintr, mintr[4];
+	phandle_t iparent;
+	int intrcells;
 
-	return (27 + ((pci_get_slot(device) + pin - 1) & 3));
+	sc = device_get_softc(bus);
+	pintr = pin;
+
+	bzero(&reg, sizeof(reg));
+	reg.phys_hi = (pci_get_bus(dev) << OFW_PCI_PHYS_HI_BUSSHIFT) |
+	    (pci_get_slot(dev) << OFW_PCI_PHYS_HI_DEVICESHIFT) |
+	    (pci_get_function(dev) << OFW_PCI_PHYS_HI_FUNCTIONSHIFT);
+
+	intrcells = ofw_bus_lookup_imap(ofw_bus_get_node(dev),
+	    &sc->pci_iinfo, &reg, sizeof(reg), &pintr, sizeof(pintr),
+	    mintr, sizeof(mintr), &iparent);
+	if (intrcells) {
+		pintr = ofw_bus_map_intr(dev, iparent, intrcells, mintr);
+		return (pintr);
+	}
+
+	device_printf(bus, "could not route pin %d for device %d.%d\n",
+	    pin, pci_get_slot(dev), pci_get_function(dev));
+	return (PCI_INVALID_IRQ);
 }
 
 static uint32_t

Copied: stable/11/sys/arm/versatile/versatile_scm.c (from r316371, head/sys/arm/versatile/versatile_scm.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/sys/arm/versatile/versatile_scm.c	Fri Mar 23 01:37:31 2018	(r331402, copy of r316371, head/sys/arm/versatile/versatile_scm.c)
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2017 Oleksandr Tymoshenko <gonzo at freebsd.org>
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by Ben Gray.
+ * 4. The name of the company nor the name of the author may be used to
+ *    endorse or promote products derived from this software without specific
+ *    prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BEN GRAY ``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 BEN GRAY 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.
+ */
+
+/*
+ * SCM - System Control Module
+ */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/bus.h>
+#include <sys/resource.h>
+#include <sys/rman.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+
+#include <machine/bus.h>
+#include <machine/resource.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+
+#include "versatile_scm.h"
+
+struct versatile_scm_softc {
+	device_t		sc_dev;
+	struct resource *	sc_mem_res;
+};
+
+static struct versatile_scm_softc *versatile_scm_sc;
+
+#define	versatile_scm_read_4(sc, reg)		\
+    bus_read_4((sc)->sc_mem_res, (reg))
+#define	versatile_scm_write_4(sc, reg, val)		\
+    bus_write_4((sc)->sc_mem_res, (reg), (val))
+
+static int
+versatile_scm_probe(device_t dev)
+{
+	if (!ofw_bus_status_okay(dev))
+		return (ENXIO);
+
+	if (!ofw_bus_is_compatible(dev, "syscon"))
+		return (ENXIO);
+
+	if (versatile_scm_sc) {
+		return (EEXIST);
+	}
+
+	device_set_desc(dev, "Versatile Control Module");
+	return (BUS_PROBE_DEFAULT);
+}
+
+static int
+versatile_scm_attach(device_t dev)
+{
+	struct versatile_scm_softc *sc;
+	int rid;
+
+	sc = device_get_softc(dev);
+	sc->sc_dev = dev;
+
+	rid = 0;
+	sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
+
+	if (sc->sc_mem_res == NULL) {
+		device_printf(dev, "could not allocate memory resources\n");
+		return (ENXIO);
+	}
+
+	versatile_scm_sc = sc;
+
+	return (0);
+}
+
+int
+versatile_scm_reg_read_4(uint32_t reg, uint32_t *val)
+{
+	if (!versatile_scm_sc)
+		return (ENXIO);
+
+	*val = versatile_scm_read_4(versatile_scm_sc, reg);
+	return (0);
+}
+
+int
+versatile_scm_reg_write_4(uint32_t reg, uint32_t val)
+{
+	if (!versatile_scm_sc)
+		return (ENXIO);
+
+	versatile_scm_write_4(versatile_scm_sc, reg, val);
+	return (0);
+}
+
+static device_method_t versatile_scm_methods[] = {
+	DEVMETHOD(device_probe,		versatile_scm_probe),
+	DEVMETHOD(device_attach,	versatile_scm_attach),
+
+	DEVMETHOD_END
+};
+
+static driver_t versatile_scm_driver = {
+	"scm",
+	versatile_scm_methods,
+	sizeof(struct versatile_scm_softc),
+};
+
+static devclass_t versatile_scm_devclass;
+
+EARLY_DRIVER_MODULE(versatile_scm, simplebus, versatile_scm_driver, versatile_scm_devclass, 0, 0,
+    BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);

Copied: stable/11/sys/arm/versatile/versatile_scm.h (from r316371, head/sys/arm/versatile/versatile_scm.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/sys/arm/versatile/versatile_scm.h	Fri Mar 23 01:37:31 2018	(r331402, copy of r316371, head/sys/arm/versatile/versatile_scm.h)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2017 Oleksandr Tymoshenko <gonzo at freebsd.org>
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by Ben Gray.
+ * 4. The name of the company nor the name of the author may be used to
+ *    endorse or promote products derived from this software without specific
+ *    prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BEN GRAY ``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 BEN GRAY 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _VERSATILE_SCM_H_
+#define _VERSATILE_SCM_H_
+
+#define	SCM_PCICTL		0x44
+#define	SCM_CLCD		0x50
+#define	 SCM_CLCD_CLCDID_SHIFT		0x08
+#define	 SCM_CLCD_CLCDID_MASK		0x1f
+#define	 SCM_CLCD_PWR3V5VSWITCH		(1 << 4)
+#define	 SCM_CLCD_VDDPOSSWITCH 		(1 << 3)
+#define	 SCM_CLCD_NLCDIOON  		(1 << 2)
+#define	 SCM_CLCD_LCD_MODE_MASK		0x03
+
+int versatile_scm_reg_read_4(uint32_t reg, uint32_t *val);
+int versatile_scm_reg_write_4(uint32_t reg, uint32_t val);
+
+#endif /* _VERSATILE_SCM_H_ */


More information about the svn-src-all mailing list