spic.c revision 111748
169873Snsayer/* 269873Snsayer * Copyright (c) 2000 Nick Sayer 369873Snsayer * All rights reserved. 469873Snsayer * 569873Snsayer * Redistribution and use in source and binary forms, with or without 669873Snsayer * modification, are permitted provided that the following conditions 769873Snsayer * are met: 869873Snsayer * 1. Redistributions of source code must retain the above copyright 969873Snsayer * notice, this list of conditions and the following disclaimer. 1069873Snsayer * 2. Redistributions in binary form must reproduce the above copyright 1169873Snsayer * notice, this list of conditions and the following disclaimer in the 1269873Snsayer * documentation and/or other materials provided with the distribution. 1369873Snsayer * 1469873Snsayer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1569873Snsayer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1669873Snsayer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1769873Snsayer * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1869873Snsayer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1969873Snsayer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2069873Snsayer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2169873Snsayer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2269873Snsayer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2369873Snsayer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2469873Snsayer * SUCH DAMAGE. 2569873Snsayer * 2669873Snsayer * spic -- the Sony Programmable I/O Controller 2769873Snsayer * 2869873Snsayer * This device exists on most recent Sony laptops. It is the means by which 2969873Snsayer * you can watch the Jog Dial and some other functions. 3069873Snsayer * 3169873Snsayer * At the moment, this driver merely tries to turn the jog dial into a 3269873Snsayer * device that moused can park on, with the intent of supplying a Z axis 3369873Snsayer * and mouse button out of the jog dial. I suspect that this device will 3469873Snsayer * end up having to support at least 2 different minor devices: One to be 3569873Snsayer * the jog wheel device for moused to camp out on and the other to perform 3669873Snsayer * all of the other miscelaneous functions of this device. But for now, 3769873Snsayer * the jog wheel is all you get. 3869873Snsayer * 3969873Snsayer * At the moment, the data sent back by the device is rather primitive. 4069873Snsayer * It sends a single character per event: 4169873Snsayer * u = up, d = down -- that's the jog button 4269873Snsayer * l = left, r = right -- that's the dial. 4369873Snsayer * "left" and "right" are rather caprecious. They actually represent 4469873Snsayer * ccw and cw, respectively 4569873Snsayer * 4669873Snsayer * What documentation exists is thanks to Andrew Tridge, and his page at 4769873Snsayer * http://samba.org/picturebook/ Special thanks also to Ian Dowse, who 4869873Snsayer * also provided sample code upon which this driver was based. 4969873Snsayer * 5069873Snsayer * $FreeBSD: head/sys/i386/isa/spic.c 111748 2003-03-02 16:54:40Z des $ 5169873Snsayer */ 5269873Snsayer 5369873Snsayer#include <sys/param.h> 5469873Snsayer#include <sys/systm.h> 5569873Snsayer#include <sys/kernel.h> 5669873Snsayer#include <sys/bus.h> 5769873Snsayer#include <machine/bus.h> 5869873Snsayer#include <sys/rman.h> 5969873Snsayer#include <machine/resource.h> 6069873Snsayer#include <isa/isavar.h> 6169873Snsayer#include <sys/poll.h> 6269873Snsayer#include <machine/pci_cfgreg.h> 6369873Snsayer#include <machine/clock.h> 6469873Snsayer#include <sys/tty.h> 6569873Snsayer#include <sys/conf.h> 6669873Snsayer#include <sys/fcntl.h> 6769873Snsayer#include <sys/malloc.h> 6869873Snsayer#include <sys/sysctl.h> 6969873Snsayer#include <sys/uio.h> 7069873Snsayer 7169873Snsayer#include <i386/isa/spicreg.h> 7269873Snsayer 7369873Snsayerstatic int spic_pollrate; 7469873Snsayer 7569873SnsayerSYSCTL_INT(_machdep, OID_AUTO, spic_pollrate, CTLFLAG_RW, &spic_pollrate, 0, "") 7669873Snsayer; 7769873Snsayer 7869873Snsayerdevclass_t spic_devclass; 7969873Snsayer 8069873Snsayerstatic d_open_t spicopen; 8169873Snsayerstatic d_close_t spicclose; 8269873Snsayerstatic d_read_t spicread; 8369873Snsayerstatic d_ioctl_t spicioctl; 8469873Snsayerstatic d_poll_t spicpoll; 8569873Snsayer 8669873Snsayerstatic struct cdevsw spic_cdevsw = { 8769873Snsayer /* open */ spicopen, 8869873Snsayer /* close */ spicclose, 8969873Snsayer /* read */ spicread, 9069873Snsayer /* write */ nowrite, 9169873Snsayer /* ioctl */ spicioctl, 9269873Snsayer /* poll */ spicpoll, 9369873Snsayer /* mmap */ nommap, 9469873Snsayer /* strategy */ nostrategy, 9569873Snsayer /* name */ "spic", 9669873Snsayer /* maj */ CDEV_MAJOR, 9769873Snsayer /* dump */ nodump, 9869873Snsayer /* psize */ nopsize, 9969873Snsayer /* flags */ 0, 10069873Snsayer}; 10169873Snsayer 10269873Snsayer#define SCBUFLEN 128 10369873Snsayer 10469873Snsayerstruct spic_softc { 10569873Snsayer u_short sc_port_addr; 10669873Snsayer u_char sc_intr; 10769873Snsayer struct resource *sc_port_res,*sc_intr_res; 10869873Snsayer int sc_port_rid,sc_intr_rid; 10969873Snsayer int sc_opened; 11069873Snsayer int sc_sleeping; 11169873Snsayer int sc_buttonlast; 11269873Snsayer struct callout_handle sc_timeout_ch; 11369873Snsayer device_t sc_dev; 11469873Snsayer struct selinfo sc_rsel; 11569873Snsayer u_char sc_buf[SCBUFLEN]; 11669873Snsayer int sc_count; 11793071Swill int sc_model; 11869873Snsayer}; 11969873Snsayer 12069873Snsayerstatic void 12169873Snsayerwrite_port1(struct spic_softc *sc, u_char val) 12269873Snsayer{ 12369873Snsayer DELAY(10); 12469873Snsayer outb(sc->sc_port_addr, val); 12569873Snsayer} 12669873Snsayer 12769873Snsayerstatic void 12869873Snsayerwrite_port2(struct spic_softc *sc, u_char val) 12969873Snsayer{ 13069873Snsayer DELAY(10); 13169873Snsayer outb(sc->sc_port_addr + 4, val); 13269873Snsayer} 13369873Snsayer 13469873Snsayerstatic u_char 13569873Snsayerread_port1(struct spic_softc *sc) 13669873Snsayer{ 13769873Snsayer DELAY(10); 13869873Snsayer return inb(sc->sc_port_addr); 13969873Snsayer} 14069873Snsayer 14169873Snsayerstatic u_char 14269873Snsayerread_port2(struct spic_softc *sc) 14369873Snsayer{ 14469873Snsayer DELAY(10); 14569873Snsayer return inb(sc->sc_port_addr + 4); 14669873Snsayer} 14769873Snsayer 14893071Swillstatic u_char 14993071Swillread_port_cst(struct spic_softc *sc) 15093071Swill{ 15193071Swill DELAY(10); 15293071Swill return inb(SPIC_CST_IOPORT); 15393071Swill} 15493071Swill 15569873Snsayerstatic void 15669873Snsayerbusy_wait(struct spic_softc *sc) 15769873Snsayer{ 15869873Snsayer int i=0; 15969873Snsayer 16069873Snsayer while(read_port2(sc) & 2) { 16169873Snsayer DELAY(10); 16269873Snsayer if (i++>10000) { 16369873Snsayer printf("spic busy wait abort\n"); 16469873Snsayer return; 16569873Snsayer } 16669873Snsayer } 16769873Snsayer} 16869873Snsayer 16993071Swillstatic void 17093071Swillbusy_wait_cst(struct spic_softc *sc, int mask) 17193071Swill{ 17293071Swill int i=0; 17393071Swill 17493071Swill while(read_port_cst(sc) & mask) { 17593071Swill DELAY(10); 17693071Swill if (i++>10000) { 17793071Swill printf("spic busy wait abort\n"); 17893071Swill return; 17993071Swill } 18093071Swill } 18193071Swill} 18293071Swill 18369873Snsayerstatic u_char 18469873Snsayerspic_call1(struct spic_softc *sc, u_char dev) { 18569873Snsayer busy_wait(sc); 18669873Snsayer write_port2(sc, dev); 18769873Snsayer read_port2(sc); 18869873Snsayer return read_port1(sc); 18969873Snsayer} 19069873Snsayer 19169873Snsayerstatic u_char 19269873Snsayerspic_call2(struct spic_softc *sc, u_char dev, u_char fn) 19369873Snsayer{ 19469873Snsayer busy_wait(sc); 19569873Snsayer write_port2(sc, dev); 19669873Snsayer busy_wait(sc); 19769873Snsayer write_port1(sc, fn); 19869873Snsayer return read_port1(sc); 19969873Snsayer} 20069873Snsayer 20193071Swillstatic void 20293071Swillspic_ecrset(struct spic_softc *sc, u_int16_t addr, u_int16_t value) 20393071Swill{ 20493071Swill busy_wait_cst(sc, 3); 20593071Swill outb(SPIC_CST_IOPORT, 0x81); 20693071Swill busy_wait_cst(sc, 2); 20793071Swill outb(SPIC_DATA_IOPORT, addr); 20893071Swill busy_wait_cst(sc, 2); 20993071Swill outb(SPIC_DATA_IOPORT, value); 21093071Swill busy_wait_cst(sc, 2); 21193071Swill} 21293071Swill 21393071Swillstatic void 21493071Swillspic_type2_srs(struct spic_softc *sc) 21593071Swill{ 21693071Swill spic_ecrset(sc, SPIC_SHIB, (sc->sc_port_addr & 0xFF00) >> 8); 21793071Swill spic_ecrset(sc, SPIC_SLOB, sc->sc_port_addr & 0x00FF); 21893071Swill spic_ecrset(sc, SPIC_SIRQ, 0x00); /* using polling mode (IRQ=0)*/ 21993071Swill DELAY(10); 22093071Swill} 22193071Swill 22269873Snsayerstatic int 22369873Snsayerspic_probe(device_t dev) 22469873Snsayer{ 22593071Swill struct spic_softc *sc; 22669873Snsayer u_char t, spic_irq; 22769873Snsayer 22893071Swill sc = device_get_softc(dev); 22969873Snsayer 23069873Snsayer /* 23169873Snsayer * We can only have 1 of these. Attempting to probe for a unit 1 23269873Snsayer * will destroy the work we did for unit 0 23369873Snsayer */ 23469873Snsayer if (device_get_unit(dev)) 23569873Snsayer return ENXIO; 23669873Snsayer 23769873Snsayer bzero(sc, sizeof(struct spic_softc)); 23869873Snsayer 23969873Snsayer if (!(sc->sc_port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, 24069873Snsayer &sc->sc_port_rid, 0, ~0, 5, RF_ACTIVE))) { 24169873Snsayer device_printf(dev,"Couldn't map I/O\n"); 24269873Snsayer return ENXIO; 24369873Snsayer } 24469873Snsayer sc->sc_port_addr = (u_short)rman_get_start(sc->sc_port_res); 24569873Snsayer 24669873Snsayer#ifdef notyet 24769873Snsayer if (!(sc->sc_intr_res = bus_alloc_resource(dev, SYS_RES_IRQ, 24869873Snsayer &sc->sc_intr_rid, 0, ~0, 1, RF_ACTIVE))) { 24969873Snsayer device_printf(dev,"Couldn't map IRQ\n"); 25069873Snsayer bus_release_resource(dev, SYS_RES_IOPORT, 25169873Snsayer sc->sc_port_rid, sc->sc_port_res); 25269873Snsayer return ENXIO; 25369873Snsayer } 25469873Snsayer sc->sc_intr = (u_short)rman_get_start(sc->sc_intr_res); 25569873Snsayer 25669873Snsayer switch (sc->sc_intr) { 25769873Snsayer case 0: spic_irq = 3; break; 25869873Snsayer case 5: spic_irq = 0; break; 25969873Snsayer case 0xa: spic_irq = 1; break; 26069873Snsayer case 0xb: spic_irq = 2; break; 26169873Snsayer default: device_printf(dev,"Invalid IRQ\n"); 26269873Snsayer bus_release_resource(dev, SYS_RES_IOPORT, 26369873Snsayer sc->sc_port_rid, sc->sc_port_res); 26469873Snsayer bus_release_resource(dev, SYS_RES_IRQ, 26569873Snsayer sc->sc_intr_rid, sc->sc_intr_res); 26669873Snsayer return ENXIO; 26769873Snsayer } 26869873Snsayer#else 26969873Snsayer spic_irq = 3; 27069873Snsayer#endif 27169873Snsayer 27269873Snsayer#if 0 27369873Snsayer if (sc->sc_port_addr != 0x10A0) { 27469873Snsayer bus_release_resource(dev, SYS_RES_IOPORT, 27569873Snsayer sc->sc_port_rid, sc->sc_port_res); 27669873Snsayer bus_release_resource(dev, SYS_RES_IRQ, 27769873Snsayer sc->sc_intr_rid, sc->sc_intr_res); 27869873Snsayer return ENXIO; 27969873Snsayer } 28069873Snsayer#endif 28169873Snsayer 28269873Snsayer /* PIIX4 chipset at least? */ 28393071Swill if (pci_cfgregread(PIIX4_BUS, PIIX4_SLOT, PIIX4_FUNC, 0, 4) == 28493071Swill PIIX4_DEVID) { 28593071Swill sc->sc_model = SPIC_DEVICE_MODEL_TYPE1; 28693071Swill } else { 28793071Swill /* For newer VAIOs (R505, SRX7, ...) */ 28893071Swill sc->sc_model = SPIC_DEVICE_MODEL_TYPE2; 28993071Swill } 29069873Snsayer 29169873Snsayer /* 29269873Snsayer * This is an ugly hack. It is necessary until ACPI works correctly. 29369873Snsayer * 29469873Snsayer * The SPIC consists of 2 registers. They are mapped onto I/O by the 29569873Snsayer * PIIX4's General Device 10 function. There is also an interrupt 29669873Snsayer * control port at a somewhat magic location, but this first pass is 29769873Snsayer * polled. 29869873Snsayer * 29969873Snsayer * So the first thing we need to do is map the G10 space in. 30069873Snsayer * 30169873Snsayer */ 30269873Snsayer 30393071Swill /* Enable ACPI mode to get Fn key events */ 30493071Swill /* XXX This may slow down your VAIO if ACPI is not supported in the kernel. 30593071Swill outb(0xb2, 0xf0); 30693071Swill */ 30769873Snsayer 30893071Swill device_printf(dev,"device model type = %d\n", sc->sc_model); 30993071Swill 31093071Swill if(sc->sc_model == SPIC_DEVICE_MODEL_TYPE1) { 31193071Swill pci_cfgregwrite(PIIX4_BUS, PIIX4_SLOT, PIIX4_FUNC, G10A, 31293071Swill sc->sc_port_addr, 2); 31393071Swill t = pci_cfgregread(PIIX4_BUS, PIIX4_SLOT, PIIX4_FUNC, G10L, 1); 31493071Swill t &= 0xf0; 31593071Swill t |= 4; 31693071Swill pci_cfgregwrite(PIIX4_BUS, PIIX4_SLOT, PIIX4_FUNC, G10L, t, 1); 31793071Swill outw(SPIC_IRQ_PORT, (inw(SPIC_IRQ_PORT) & ~(0x3 << SPIC_IRQ_SHIFT)) | (spic_irq << SPIC_IRQ_SHIFT)); 31893071Swill t = pci_cfgregread(PIIX4_BUS, PIIX4_SLOT, PIIX4_FUNC, G10L, 1); 31993071Swill t &= 0x1f; 32093071Swill t |= 0xc0; 32193071Swill pci_cfgregwrite(PIIX4_BUS, PIIX4_SLOT, PIIX4_FUNC, G10L, t, 1); 32293071Swill } else { 32393071Swill spic_type2_srs(sc); 32493071Swill } 32593071Swill 32669873Snsayer /* 32769873Snsayer * XXX: Should try and see if there's anything actually there. 32869873Snsayer */ 32969873Snsayer 33069873Snsayer device_set_desc(dev, "Sony Programmable I/O Controller"); 33169873Snsayer 33269873Snsayer return 0; 33369873Snsayer} 33469873Snsayer 33569873Snsayerstatic int 33669873Snsayerspic_attach(device_t dev) 33769873Snsayer{ 33893071Swill struct spic_softc *sc; 33969873Snsayer 34093071Swill sc = device_get_softc(dev); 34169873Snsayer 34269873Snsayer sc->sc_dev = dev; 34369873Snsayer 34469873Snsayer spic_pollrate = (hz/50); /* Every 50th of a second */ 34569873Snsayer 34669873Snsayer spic_call1(sc, 0x82); 34769873Snsayer spic_call2(sc, 0x81, 0xff); 34869873Snsayer spic_call1(sc, 0x92); 34969873Snsayer 35093071Swill /* There can be only one */ 35193071Swill make_dev(&spic_cdevsw, 0, 0, 0, 0600, "jogdial"); 35269873Snsayer 35369873Snsayer return 0; 35469873Snsayer} 35569873Snsayer 35669873Snsayerstatic void 35769873Snsayerspictimeout(void *arg) 35869873Snsayer{ 35993071Swill struct spic_softc *sc = arg; 36069873Snsayer u_char b, event, param; 36169873Snsayer int j; 36269873Snsayer 36393071Swill if (!sc->sc_opened) { 36493071Swill device_printf(sc->sc_dev, "timeout called while closed!\n"); 36593071Swill return; 36693071Swill } 36769873Snsayer 36869873Snsayer event = read_port2(sc); 36969873Snsayer param = read_port1(sc); 37069873Snsayer 37169873Snsayer if ((event != 4) && (!(event & 0x1))) 37269873Snsayer switch(event) { 37393071Swill case 0x10: /* jog wheel event (type1) */ 37493071Swill if (sc->sc_model == SPIC_DEVICE_MODEL_TYPE1) { 37593071Swill b = !!(param & 0x40); 37693071Swill if (b != sc->sc_buttonlast) { 37793071Swill sc->sc_buttonlast = b; 37869873Snsayer sc->sc_buf[sc->sc_count++] = 37993071Swill b?'d':'u'; 38069873Snsayer } 38193071Swill j = (param & 0xf) | ((param & 0x10)? ~0xf:0); 38293071Swill if (j<0) 38393071Swill while(j++!=0) { 38493071Swill sc->sc_buf[sc->sc_count++] = 38593071Swill 'l'; 38693071Swill } 38793071Swill else if (j>0) 38893071Swill while(j--!=0) { 38993071Swill sc->sc_buf[sc->sc_count++] = 39093071Swill 'r'; 39193071Swill } 39293071Swill } 39393071Swill break; 39493071Swill case 0x08: /* jog wheel event (type2) */ 39593071Swill case 0x00: 39693071Swill /* SPIC_DEVICE_MODEL_TYPE2 returns jog wheel event=0x00 */ 39793071Swill if (sc->sc_model == SPIC_DEVICE_MODEL_TYPE2) { 39893071Swill b = !!(param & 0x40); 39993071Swill if (b != sc->sc_buttonlast) { 40093071Swill sc->sc_buttonlast = b; 40169873Snsayer sc->sc_buf[sc->sc_count++] = 40293071Swill b?'d':'u'; 40369873Snsayer } 40493071Swill j = (param & 0xf) | ((param & 0x10)? ~0xf:0); 40593071Swill if (j<0) 40693071Swill while(j++!=0) { 40793071Swill sc->sc_buf[sc->sc_count++] = 40893071Swill 'l'; 40993071Swill } 41093071Swill else if (j>0) 41193071Swill while(j--!=0) { 41293071Swill sc->sc_buf[sc->sc_count++] = 41393071Swill 'r'; 41493071Swill } 41593071Swill } 41669873Snsayer break; 41769873Snsayer case 0x60: /* Capture button */ 41869873Snsayer printf("Capture button event: %x\n",param); 41969873Snsayer break; 42069873Snsayer case 0x30: /* Lid switch */ 42169873Snsayer printf("Lid switch event: %x\n",param); 42269873Snsayer break; 42393071Swill case 0x0c: /* We must ignore these type of event for C1VP... */ 42493071Swill case 0x70: /* Closing/Opening the lid on C1VP */ 42593071Swill break; 42669873Snsayer default: 42793071Swill printf("Unknown event: event %02x param %02x\n", event, param); 42869873Snsayer break; 42969873Snsayer } 43069873Snsayer else { 43169873Snsayer /* No event. Wait some more */ 43293071Swill sc->sc_timeout_ch = timeout(spictimeout, sc, spic_pollrate); 43369873Snsayer return; 43469873Snsayer } 43569873Snsayer 43669873Snsayer if (sc->sc_count) { 43769873Snsayer if (sc->sc_sleeping) { 43869873Snsayer sc->sc_sleeping = 0; 439111748Sdes wakeup( sc); 44069873Snsayer } 44169873Snsayer selwakeup(&sc->sc_rsel); 44269873Snsayer } 44369873Snsayer spic_call2(sc, 0x81, 0xff); /* Clear event */ 44469873Snsayer 44593071Swill sc->sc_timeout_ch = timeout(spictimeout, sc, spic_pollrate); 44669873Snsayer} 44769873Snsayer 44869873Snsayerstatic int 44983366Sjulianspicopen(dev_t dev, int flag, int fmt, struct thread *td) 45069873Snsayer{ 45193071Swill struct spic_softc *sc; 45269873Snsayer 45393071Swill sc = devclass_get_softc(spic_devclass, 0); 45469873Snsayer 45593071Swill if (sc->sc_opened) 45693071Swill return EBUSY; 45769873Snsayer 45869873Snsayer sc->sc_opened++; 45969873Snsayer sc->sc_count=0; 46069873Snsayer 46193071Swill /* Start the polling */ 46293071Swill timeout(spictimeout, sc, spic_pollrate); 46393071Swill return 0; 46469873Snsayer} 46569873Snsayer 46669873Snsayerstatic int 46783366Sjulianspicclose(dev_t dev, int flag, int fmt, struct thread *td) 46869873Snsayer{ 46993071Swill struct spic_softc *sc; 47069873Snsayer 47193071Swill sc = devclass_get_softc(spic_devclass, 0); 47269873Snsayer 47393071Swill /* Stop polling */ 47493071Swill untimeout(spictimeout, sc, sc->sc_timeout_ch); 47593071Swill sc->sc_opened = 0; 47693071Swill return 0; 47769873Snsayer} 47869873Snsayer 47969873Snsayerstatic int 48069873Snsayerspicread(dev_t dev, struct uio *uio, int flag) 48169873Snsayer{ 48293071Swill struct spic_softc *sc; 48369873Snsayer int l, s, error; 48469873Snsayer u_char buf[SCBUFLEN]; 48569873Snsayer 48693071Swill sc = devclass_get_softc(spic_devclass, 0); 48769873Snsayer 48869873Snsayer if (uio->uio_resid <= 0) /* What kind of a read is this?! */ 48969873Snsayer return 0; 49069873Snsayer 49169873Snsayer s = spltty(); 49269873Snsayer while (!(sc->sc_count)) { 49369873Snsayer sc->sc_sleeping=1; 494111748Sdes error = tsleep( sc, PZERO | PCATCH, "jogrea", 0); 49569873Snsayer sc->sc_sleeping=0; 49669873Snsayer if (error) { 49769873Snsayer splx(s); 49869873Snsayer return error; 49969873Snsayer } 50069873Snsayer } 50169873Snsayer splx(s); 50269873Snsayer 50369873Snsayer s = spltty(); 50469873Snsayer l = min(uio->uio_resid, sc->sc_count); 50569873Snsayer bcopy(sc->sc_buf, buf, l); 50669873Snsayer sc->sc_count -= l; 50769873Snsayer bcopy(sc->sc_buf + l, sc->sc_buf, l); 50869873Snsayer splx(s); 50969873Snsayer return uiomove(buf, l, uio); 51069873Snsayer 51169873Snsayer} 51269873Snsayer 51369873Snsayerstatic int 51483366Sjulianspicioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td) 51569873Snsayer{ 51693071Swill struct spic_softc *sc; 51769873Snsayer 51893071Swill sc = devclass_get_softc(spic_devclass, 0); 51969873Snsayer 52069873Snsayer return EIO; 52169873Snsayer} 52269873Snsayer 52369873Snsayerstatic int 52483366Sjulianspicpoll(dev_t dev, int events, struct thread *td) 52569873Snsayer{ 52693071Swill struct spic_softc *sc; 52793071Swill int revents = 0, s; 52869873Snsayer 52993071Swill sc = devclass_get_softc(spic_devclass, 0); 53093071Swill s = spltty(); 53193071Swill if (events & (POLLIN | POLLRDNORM)) { 53293071Swill if (sc->sc_count) 53393071Swill revents |= events & (POLLIN | POLLRDNORM); 53493071Swill else 53593071Swill selrecord(td, &sc->sc_rsel); /* Who shall we wake? */ 53693071Swill } 53793071Swill splx(s); 53869873Snsayer 53993071Swill return revents; 54069873Snsayer} 54169873Snsayer 54269873Snsayer 54369873Snsayerstatic device_method_t spic_methods[] = { 54469873Snsayer DEVMETHOD(device_probe, spic_probe), 54569873Snsayer DEVMETHOD(device_attach, spic_attach), 54669873Snsayer 54769873Snsayer { 0, 0 } 54869873Snsayer}; 54969873Snsayer 55069873Snsayerstatic driver_t spic_driver = { 55169873Snsayer "spic", 55269873Snsayer spic_methods, 55369873Snsayer sizeof(struct spic_softc), 55469873Snsayer}; 55569873Snsayer 55669873SnsayerDRIVER_MODULE(spic, isa, spic_driver, spic_devclass, 0, 0); 55769873Snsayer 558