Module Name: src
Committed By: mbalmer
Date: Mon Dec 17 20:38:01 UTC 2012
Modified Files:
src/distrib/sets/lists/man: mi
src/share/man/man4: Makefile
src/sys/arch/i386/conf: ALL GENERIC
src/sys/dev/pci: files.pci
Added Files:
src/share/man/man4: ibmcd.4
src/sys/dev/pci: ibmcd.c
Log Message:
Adding ibmcd(4), a device driver for the IBM 4810 BSP cash drawer port as
found e.g. in SurePOS 300 series point of sale terminals. The driver
provides a gpio(4) device with three pins: pin 0 to open drawer, pin 1
to read the status and pin 2 to read whether a cash drawer is connected or
not.
To generate a diff of this commit:
cvs rdiff -u -r1.1412 -r1.1413 src/distrib/sets/lists/man/mi
cvs rdiff -u -r1.593 -r1.594 src/share/man/man4/Makefile
cvs rdiff -u -r0 -r1.1 src/share/man/man4/ibmcd.4
cvs rdiff -u -r1.348 -r1.349 src/sys/arch/i386/conf/ALL
cvs rdiff -u -r1.1084 -r1.1085 src/sys/arch/i386/conf/GENERIC
cvs rdiff -u -r1.360 -r1.361 src/sys/dev/pci/files.pci
cvs rdiff -u -r0 -r1.1 src/sys/dev/pci/ibmcd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/man/mi
diff -u src/distrib/sets/lists/man/mi:1.1412 src/distrib/sets/lists/man/mi:1.1413
--- src/distrib/sets/lists/man/mi:1.1412 Sun Dec 16 20:33:43 2012
+++ src/distrib/sets/lists/man/mi Mon Dec 17 20:38:00 2012
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1412 2012/12/16 20:33:43 christos Exp $
+# $NetBSD: mi,v 1.1413 2012/12/17 20:38:00 mbalmer Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -1180,6 +1180,7 @@
./usr/share/man/cat4/i4btrc.0 man-obsolete obsolete
./usr/share/man/cat4/i915drm.0 man-sys-catman .cat
./usr/share/man/cat4/iavc.0 man-sys-catman .cat
+./usr/share/man/cat4/ibmcd.0 man-sys-catman .cat
./usr/share/man/cat4/ibmhawk.0 man-sys-catman .cat
./usr/share/man/cat4/ichlpcib.0 man-obsolete obsolete
./usr/share/man/cat4/ichsmb.0 man-sys-catman .cat
@@ -4074,6 +4075,7 @@
./usr/share/man/html4/i386/viac7temp.html man-sys-htmlman html
./usr/share/man/html4/i915drm.html man-sys-htmlman html
./usr/share/man/html4/iavc.html man-sys-htmlman html
+./usr/share/man/html4/ibmcd.html man-sys-htmlman html
./usr/share/man/html4/ibmhawk.html man-sys-htmlman html
./usr/share/man/html4/ichlpcib.html man-obsolete obsolete
./usr/share/man/html4/ichsmb.html man-sys-htmlman html
@@ -6798,6 +6800,7 @@
./usr/share/man/man4/i4btrc.4 man-obsolete obsolete
./usr/share/man/man4/i915drm.4 man-sys-man .man
./usr/share/man/man4/iavc.4 man-sys-man .man
+./usr/share/man/man4/ibmcd.4 man-sys-man .man
./usr/share/man/man4/ibmhawk.4 man-sys-man .man
./usr/share/man/man4/ichlpcib.4 man-obsolete obsolete
./usr/share/man/man4/ichsmb.4 man-sys-man .man
Index: src/share/man/man4/Makefile
diff -u src/share/man/man4/Makefile:1.593 src/share/man/man4/Makefile:1.594
--- src/share/man/man4/Makefile:1.593 Sun Dec 16 13:09:18 2012
+++ src/share/man/man4/Makefile Mon Dec 17 20:37:59 2012
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.593 2012/12/16 13:09:18 mbalmer Exp $
+# $NetBSD: Makefile,v 1.594 2012/12/17 20:37:59 mbalmer Exp $
# @(#)Makefile 8.1 (Berkeley) 6/18/93
MAN= aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -29,7 +29,7 @@ MAN= aac.4 ac97.4 acardide.4 aceride.4 a
glxtphy.4 gpib.4 gpio.4 gpiolock.4 gpiopwm.4 gpiosim.4 gre.4 \
gphyter.4 gsip.4 \
hdaudio.4 hifn.4 hme.4 hpacel.4 hpqlb.4 hptide.4 \
- ibmhawk.4 ichsmb.4 icmp.4 icp.4 icsphy.4 iee.4 ieee80211.4 \
+ ibmcd.4 ibmhawk.4 ichsmb.4 icmp.4 icp.4 icsphy.4 iee.4 ieee80211.4 \
ifmedia.4 igphy.4 igsfb.4 iha.4 ihphy.4 iic.4 inet.4 ikphy.4 inphy.4 \
intersil7170.4 \
ioasic.4 ioat.4 iop.4 iophy.4 iopsp.4 ip.4 ipkdb.4 ipmi.4 ipw.4 \
Index: src/sys/arch/i386/conf/ALL
diff -u src/sys/arch/i386/conf/ALL:1.348 src/sys/arch/i386/conf/ALL:1.349
--- src/sys/arch/i386/conf/ALL:1.348 Sun Dec 16 18:52:17 2012
+++ src/sys/arch/i386/conf/ALL Mon Dec 17 20:38:00 2012
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.348 2012/12/16 18:52:17 mbalmer Exp $
+# $NetBSD: ALL,v 1.349 2012/12/17 20:38:00 mbalmer Exp $
# From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
#
# ALL machine description file
@@ -17,7 +17,7 @@ include "arch/i386/conf/std.i386"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "ALL-$Revision: 1.348 $"
+#ident "ALL-$Revision: 1.349 $"
maxusers 64 # estimated number of users
@@ -521,6 +521,10 @@ isa0 at pcib?
ptcd0 at isa?
gpio* at ptcd?
+# IBM 4810 BSP cash drawer port
+ibmcd* at pci? dev ? function ?
+gpio* at ibmcd?
+
# PCMCIA bus support
pcmcia* at pcic? controller ? socket ?
pcmcia* at tcic? controller ? socket ?
Index: src/sys/arch/i386/conf/GENERIC
diff -u src/sys/arch/i386/conf/GENERIC:1.1084 src/sys/arch/i386/conf/GENERIC:1.1085
--- src/sys/arch/i386/conf/GENERIC:1.1084 Mon Dec 10 02:03:45 2012
+++ src/sys/arch/i386/conf/GENERIC Mon Dec 17 20:38:00 2012
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.1084 2012/12/10 02:03:45 dholland Exp $
+# $NetBSD: GENERIC,v 1.1085 2012/12/17 20:38:00 mbalmer Exp $
#
# GENERIC machine description file
#
@@ -22,7 +22,7 @@ include "arch/i386/conf/std.i386"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "GENERIC-$Revision: 1.1084 $"
+#ident "GENERIC-$Revision: 1.1085 $"
maxusers 64 # estimated number of users
@@ -477,6 +477,9 @@ puc* at pci? dev ? function ? # PCI "uni
pwdog* at pci ? dev ? function ? # QUANCOM PWDOG1
+#ibmcd* at pci ? dev ? function ? # IBM 4810 BSP cash drawer port
+#gpio* at ibmcd?
+
agp* at pchb?
Index: src/sys/dev/pci/files.pci
diff -u src/sys/dev/pci/files.pci:1.360 src/sys/dev/pci/files.pci:1.361
--- src/sys/dev/pci/files.pci:1.360 Thu Aug 2 00:17:44 2012
+++ src/sys/dev/pci/files.pci Mon Dec 17 20:37:59 2012
@@ -1,4 +1,4 @@
-# $NetBSD: files.pci,v 1.360 2012/08/02 00:17:44 macallan Exp $
+# $NetBSD: files.pci,v 1.361 2012/12/17 20:37:59 mbalmer Exp $
#
# Config file and device description for machine-independent PCI code.
# Included by ports that need it. Requires that the SCSI files be
@@ -1091,6 +1091,11 @@ device pwdog: sysmon_envsys
attach pwdog at pci
file dev/pci/pwdog.c pwdog
+# IBM 4810 BSP cash drawer port
+device ibmcd: gpiobus
+attach ibmcd at pci
+file dev/pci/ibmcd.c ibmcd
+
# SIS 315 Pro frame buffer
device sisfb: wsemuldisplaydev, rasops8, rasops15, rasops16, rasops32, vcons
attach sisfb at pci
Added files:
Index: src/share/man/man4/ibmcd.4
diff -u /dev/null src/share/man/man4/ibmcd.4:1.1
--- /dev/null Mon Dec 17 20:38:02 2012
+++ src/share/man/man4/ibmcd.4 Mon Dec 17 20:37:59 2012
@@ -0,0 +1,68 @@
+.\" $NetBSD: ibmcd.4,v 1.1 2012/12/17 20:37:59 mbalmer Exp $
+.\"
+.\" Copyright (c) 2012 Marc Balmer <[email protected]>
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+.\"
+.Dd December 17, 2012
+.Dt IBMCD 4
+.Os
+.Sh NAME
+.Nm ibmcd
+.Nd support for the IBM 4810 BSP cash drawer port
+.Sh SYNOPSIS
+.Cd "ibmcd* at at pci ? dev ? function ?"
+.Cd "gpio* at ibmcd?"
+.Sh DESCRIPTION
+The
+.Nm
+driver controls the cash drawer port of the IBM 4810 BSP PCI device found
+in IBM point of sale terminals (e.g. in the SurePOS 300 series) using the GPIO
+subsystem.
+.Pp
+.Nm
+provides a GPIO device with three pins: pin 0 is used to control the cash drawer
+while pin 1 can be used to read the current state of the sense input pin.
+A logical 0 means the cash drawer is closed, a logical 1 means the cash drawer
+is open.
+.Pp
+Pin 2 reports if a cash drawer is connected.
+A logical 0 means there is no cash drawer connected, a logical 1 means the cash drawer is connected.
+.Pp
+To open the cash drawer, set pin 0 to logical 1.
+There is no need to reset pin 0 to logical 0 afterwards as the device generates
+a oneshot impulse.
+.Sh SEE ALSO
+.Xr gpio 4 ,
+.Xr gpioctl 8 ,
+.Xr ptcd 4
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Nx 6.1 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Marc Balmer Aq [email protected] .
Index: src/sys/dev/pci/ibmcd.c
diff -u /dev/null src/sys/dev/pci/ibmcd.c:1.1
--- /dev/null Mon Dec 17 20:38:02 2012
+++ src/sys/dev/pci/ibmcd.c Mon Dec 17 20:38:00 2012
@@ -0,0 +1,238 @@
+/* $NetBSD: ibmcd.c,v 1.1 2012/12/17 20:38:00 mbalmer Exp $ */
+
+/*
+ * Copyright (c) 2012 Marc Balmer <[email protected]>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+/*
+ * Driver for the IBM 4810 BSP cash drawer port.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/gpio.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/systm.h>
+
+#include <dev/gpio/gpiovar.h>
+
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcidevs.h>
+
+/* registers */
+#define IBMCD_STATUS 0x00
+#define IBMCD_CONTROL 0x01
+
+#define IBMCD_CMD_OPEN 0x6d
+#define IBMCD_DO_OPEN 0x01
+
+#define IBMCD_CLOSED 0x80
+#define IBMCD_NOT_CONNECTED 0x40
+
+/* GPIO constants */
+#define IBMCD_NPINS 3
+#define PIN_OPEN 0
+#define PIN_STATUS 1
+#define PIN_CONNECTED 2
+
+struct ibmcd_softc {
+ bus_space_tag_t sc_iot;
+ bus_space_handle_t sc_ioh;
+ bus_size_t sc_iosize;
+
+ /* GPIO interface */
+ struct gpio_chipset_tag sc_gpio_gc;
+ gpio_pin_t sc_gpio_pins[IBMCD_NPINS];
+};
+
+static int ibmcd_match(device_t, cfdata_t, void *);
+static void ibmcd_attach(device_t, device_t, void *);
+static int ibmcd_detach(device_t, int);
+#if (__NetBSD_Version__ >= 600000000)
+static bool ibmcd_suspend(device_t, const pmf_qual_t *);
+static bool ibmcd_resume(device_t, const pmf_qual_t *);
+#endif
+int ibmcd_gpio_pin_read(void *, int);
+void ibmcd_gpio_pin_write(void *, int, int);
+void ibmcd_gpio_pin_ctl(void *, int, int);
+
+CFATTACH_DECL2_NEW(ibmcd, sizeof(struct ibmcd_softc), ibmcd_match,
+ ibmcd_attach, ibmcd_detach, NULL, NULL, NULL);
+
+static int
+ibmcd_match(device_t parent, cfdata_t match, void *aux)
+{
+ struct pci_attach_args *pa = (struct pci_attach_args *)aux;
+
+ if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_IBM &&
+ PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_IBM_4810_BSP)
+ return 1;
+ return 0;
+}
+
+void
+ibmcd_attach(device_t parent, device_t self, void *aux)
+{
+ struct ibmcd_softc *sc = device_private(self);
+ struct pci_attach_args *const pa = (struct pci_attach_args *)aux;
+ struct gpiobus_attach_args gba;
+ pcireg_t memtype;
+
+ memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START);
+ if (pci_mapreg_map(pa, PCI_MAPREG_START, memtype, 0, &sc->sc_iot,
+ &sc->sc_ioh, NULL, &sc->sc_iosize)) {
+ aprint_error("\n");
+ aprint_error_dev(self, "PCI %s region not found\n",
+ memtype == PCI_MAPREG_TYPE_IO ? "I/O" : "memory");
+ return;
+ }
+ printf(": IBM 4810 BSP cash drawer\n");
+
+#if (__NetBSD_Version__ >= 600000000)
+ pmf_device_register(self, ibmcd_suspend, ibmcd_resume);
+#endif
+ /* Initialize pins array */
+ sc->sc_gpio_pins[PIN_OPEN].pin_num = 0;
+ sc->sc_gpio_pins[PIN_OPEN].pin_caps = GPIO_PIN_OUTPUT;
+ sc->sc_gpio_pins[PIN_STATUS].pin_num = 1;
+ sc->sc_gpio_pins[PIN_STATUS].pin_caps = GPIO_PIN_INPUT;
+ sc->sc_gpio_pins[PIN_CONNECTED].pin_num = 2;
+ sc->sc_gpio_pins[PIN_CONNECTED].pin_caps = GPIO_PIN_INPUT;
+
+ /* Create controller tag */
+ sc->sc_gpio_gc.gp_cookie = sc;
+ sc->sc_gpio_gc.gp_pin_read = ibmcd_gpio_pin_read;
+ sc->sc_gpio_gc.gp_pin_write = ibmcd_gpio_pin_write;
+ sc->sc_gpio_gc.gp_pin_ctl = ibmcd_gpio_pin_ctl;
+
+ gba.gba_gc = &sc->sc_gpio_gc;
+ gba.gba_pins = sc->sc_gpio_pins;
+ gba.gba_npins = IBMCD_NPINS;
+
+ /* Attach GPIO framework */
+ config_found_ia(self, "gpiobus", &gba, gpiobus_print);
+
+}
+
+static int
+ibmcd_detach(device_t self, int flags)
+{
+ struct ibmcd_softc *sc = device_private(self);
+
+#if (__NetBSD_Version__ >= 600000000)
+ pmf_device_deregister(self);
+#endif
+ if (sc->sc_iosize)
+ bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
+ return 0;
+}
+
+#if (__NetBSD_Version__ >= 600000000)
+static bool
+ibmcd_resume(device_t self, const pmf_qual_t *qual)
+{
+ return true;
+}
+
+static bool
+ibmcd_suspend(device_t self, const pmf_qual_t *qual)
+{
+ return true;
+}
+#endif
+
+int
+ibmcd_gpio_pin_read(void *arg, int pin)
+{
+ struct ibmcd_softc *sc = arg;
+ uint8_t data;
+
+ data = bus_space_read_1(sc->sc_iot, sc->sc_ioh, IBMCD_STATUS);
+
+ switch (pin) {
+ case PIN_STATUS:
+ return data & IBMCD_CLOSED ? 0 : 1;
+ case PIN_CONNECTED:
+ return data & IBMCD_NOT_CONNECTED ? 0 : 1;
+ default:
+ return 0;
+ }
+}
+
+void
+ibmcd_gpio_pin_write(void *arg, int pin, int value)
+{
+ struct ibmcd_softc *sc = arg;
+
+ if (pin != PIN_OPEN)
+ return;
+
+ bus_space_write_1(sc->sc_iot, sc->sc_ioh, IBMCD_STATUS,
+ value ? IBMCD_DO_OPEN : 0);
+ bus_space_write_1(sc->sc_iot, sc->sc_ioh, IBMCD_CONTROL,
+ IBMCD_CMD_OPEN);
+}
+
+void
+ibmcd_gpio_pin_ctl(void *arg, int pin, int flags)
+{
+ /* We ignore pin control requests since the pin functions are fixed. */
+}
+
+MODULE(MODULE_CLASS_DRIVER, ibmcd, "pci");
+
+#ifdef _MODULE
+#include "ioconf.c"
+#endif
+
+static int
+ibmcd_modcmd(modcmd_t cmd, void *opaque)
+{
+ int error;
+
+ error = 0;
+ switch (cmd) {
+ case MODULE_CMD_INIT:
+#ifdef _MODULE
+ error = config_init_component(cfdriver_ioconf_ibmcd,
+ cfattach_ioconf_ibmcd, cfdata_ioconf_ibmcd);
+ if (error)
+ aprint_error("%s: unable to init component\n",
+ ibmcd_cd.cd_name);
+#endif
+ break;
+ case MODULE_CMD_FINI:
+#ifdef _MODULE
+ config_fini_component(cfdriver_ioconf_ibmcd,
+ cfattach_ioconf_ibmcd, cfdata_ioconf_ibmcd);
+#endif
+ break;
+ default:
+ error = ENOTTY;
+ }
+ return error;
+}