xref: /netbsd-src/sys/arch/atari/vme/leo.c (revision 2a84159ada57dac1a3a322c289d36b976db1a473)
1*2a84159aStsutsui /*	$NetBSD: leo.c,v 1.24 2023/01/06 10:28:28 tsutsui Exp $	*/
247cf1b0eSleo 
347cf1b0eSleo /*-
447cf1b0eSleo  * Copyright (c) 1997 maximum entropy <entropy@zippy.bernstein.com>
547cf1b0eSleo  * Copyright (c) 1997 The NetBSD Foundation, Inc.
647cf1b0eSleo  * All rights reserved.
747cf1b0eSleo  *
847cf1b0eSleo  * Redistribution and use in source and binary forms, with or without
947cf1b0eSleo  * modification, are permitted provided that the following conditions
1047cf1b0eSleo  * are met:
1147cf1b0eSleo  * 1. Redistributions of source code must retain the above copyright
1247cf1b0eSleo  *    notice, this list of conditions and the following disclaimer.
1347cf1b0eSleo  * 2. Redistributions in binary form must reproduce the above copyright
1447cf1b0eSleo  *    notice, this list of conditions and the following disclaimer in the
1547cf1b0eSleo  *    documentation and/or other materials provided with the distribution.
1647cf1b0eSleo  *
1747cf1b0eSleo  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1847cf1b0eSleo  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1947cf1b0eSleo  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2047cf1b0eSleo  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2147cf1b0eSleo  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2247cf1b0eSleo  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2347cf1b0eSleo  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2447cf1b0eSleo  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2547cf1b0eSleo  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2647cf1b0eSleo  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2747cf1b0eSleo  * POSSIBILITY OF SUCH DAMAGE.
2847cf1b0eSleo  */
2947cf1b0eSleo 
3047cf1b0eSleo /*
3147cf1b0eSleo  * Driver for the Circad Leonardo 1.2 from Lexicor, a 24-bit true color
3247cf1b0eSleo  * VME graphics card based on the Texas Instruments TMS34061.
3347cf1b0eSleo  *
3447cf1b0eSleo  * Written by maximum entropy <entropy@zippy.bernstein.com>, December 5, 1997.
3547cf1b0eSleo  *
3647cf1b0eSleo  * This driver was written from scratch, but I referred to several other
3747cf1b0eSleo  * drivers in the NetBSD distribution as examples.  The file I referred to
3847cf1b0eSleo  * the most was /sys/arch/atari/vme/if_le_vme.c.  Due credits:
3947cf1b0eSleo  * Copyright (c) 1997 Leo Weppelman.  All rights reserved.
4047cf1b0eSleo  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
4147cf1b0eSleo  * Copyright (c) 1992, 1993
4247cf1b0eSleo  *	The Regents of the University of California.  All rights reserved.
4347cf1b0eSleo  * This code is derived from software contributed to Berkeley by
4447cf1b0eSleo  *	Ralph Campbell and Rick Macklem.
4547cf1b0eSleo  * This product includes software developed by the University of
4647cf1b0eSleo  *	California, Berkeley and its contributors.
4747cf1b0eSleo  */
4847cf1b0eSleo 
49e803bea7Slukem #include <sys/cdefs.h>
50*2a84159aStsutsui __KERNEL_RCSID(0, "$NetBSD: leo.c,v 1.24 2023/01/06 10:28:28 tsutsui Exp $");
51e803bea7Slukem 
5247cf1b0eSleo #include <sys/param.h>
5347cf1b0eSleo #include <sys/systm.h>
5447cf1b0eSleo #include <sys/proc.h>
5547cf1b0eSleo #include <sys/errno.h>
5647cf1b0eSleo #include <sys/device.h>
5747cf1b0eSleo #include <sys/conf.h>
5847cf1b0eSleo #include <sys/ioctl.h>
5947cf1b0eSleo #include <machine/cpu.h>
60ed9977b1Sdyoung #include <sys/bus.h>
6147cf1b0eSleo #include <machine/iomap.h>
6247cf1b0eSleo #include <machine/scu.h>
6347cf1b0eSleo #include <atari/vme/vmevar.h>
6447cf1b0eSleo #include <atari/vme/leovar.h>
6547cf1b0eSleo #include <atari/vme/leoioctl.h>
6647cf1b0eSleo 
67c1acd41fStsutsui #include "ioconf.h"
68c1acd41fStsutsui 
6947cf1b0eSleo static struct leo_addresses {
7047cf1b0eSleo 	u_long reg_addr;
7147cf1b0eSleo 	u_int reg_size;
7247cf1b0eSleo 	u_long mem_addr;
7347cf1b0eSleo 	u_int mem_size;
7447cf1b0eSleo } leostd[] = {
7547cf1b0eSleo 	{ 0xfed90000, 0x100, 0xfec00000, 0x100000 }
7647cf1b0eSleo };
7747cf1b0eSleo 
7847cf1b0eSleo #define NLEOSTD (sizeof(leostd) / sizeof(leostd[0]))
7947cf1b0eSleo 
8047cf1b0eSleo struct leo_softc {
81097168d0Stsutsui 	device_t sc_dev;		/* XXX what goes here? */
8247cf1b0eSleo 	bus_space_tag_t sc_iot;
8347cf1b0eSleo 	bus_space_tag_t sc_memt;
8447cf1b0eSleo 	bus_space_handle_t sc_ioh;
8547cf1b0eSleo 	bus_space_handle_t sc_memh;
8647cf1b0eSleo 	int sc_flags;
8747cf1b0eSleo 	int sc_maddr;
8847cf1b0eSleo 	u_int sc_msize;
8947cf1b0eSleo };
9047cf1b0eSleo 
9147cf1b0eSleo #define LEO_SC_FLAGS_INUSE 1
9247cf1b0eSleo 
93097168d0Stsutsui static int leo_match(device_t, cfdata_t, void *);
94097168d0Stsutsui static void leo_attach(device_t, device_t, void *);
9502cdf4d2Sdsl static int leo_probe(bus_space_tag_t *, bus_space_tag_t *,
9647cf1b0eSleo 			  bus_space_handle_t *, bus_space_handle_t *,
9702cdf4d2Sdsl 			  u_int, u_int);
9802cdf4d2Sdsl static int leo_init(struct leo_softc *, int);
9902cdf4d2Sdsl static int leo_scroll(struct leo_softc *, int);
10047cf1b0eSleo 
101097168d0Stsutsui CFATTACH_DECL_NEW(leo, sizeof(struct leo_softc),
102c5e91d44Sthorpej     leo_match, leo_attach, NULL, NULL);
10347cf1b0eSleo 
104987d7d84Stsutsui static dev_type_open(leoopen);
105987d7d84Stsutsui static dev_type_close(leoclose);
106987d7d84Stsutsui static dev_type_read(leomove);
107987d7d84Stsutsui static dev_type_ioctl(leoioctl);
108987d7d84Stsutsui static dev_type_mmap(leommap);
10977a6b82bSgehenna 
11077a6b82bSgehenna const struct cdevsw leo_cdevsw = {
111a68f9396Sdholland 	.d_open = leoopen,
112a68f9396Sdholland 	.d_close = leoclose,
113a68f9396Sdholland 	.d_read = leomove,
114a68f9396Sdholland 	.d_write = leomove,
115a68f9396Sdholland 	.d_ioctl = leoioctl,
116a68f9396Sdholland 	.d_stop = nostop,
117a68f9396Sdholland 	.d_tty = notty,
118a68f9396Sdholland 	.d_poll = nopoll,
119a68f9396Sdholland 	.d_mmap = leommap,
120a68f9396Sdholland 	.d_kqfilter = nokqfilter,
121f9228f42Sdholland 	.d_discard = nodiscard,
122a68f9396Sdholland 	.d_flag = 0
12377a6b82bSgehenna };
12477a6b82bSgehenna 
12547cf1b0eSleo static int
leo_match(device_t parent,cfdata_t cf,void * aux)126097168d0Stsutsui leo_match(device_t parent, cfdata_t cf, void *aux)
12747cf1b0eSleo {
12847cf1b0eSleo 	struct vme_attach_args *va = aux;
12947cf1b0eSleo 	int i;
13047cf1b0eSleo 	bus_space_tag_t iot;
13147cf1b0eSleo 	bus_space_tag_t memt;
13247cf1b0eSleo 	bus_space_handle_t ioh;
13347cf1b0eSleo 	bus_space_handle_t memh;
13447cf1b0eSleo 
13547cf1b0eSleo 	/*
13647cf1b0eSleo 	 * We are passed our configuration in the attachment arguments.
13747cf1b0eSleo 	 * The configuration information may be partially unspecified.
13847cf1b0eSleo 	 * For any unspecified configuration parameters, we fill in those
13947cf1b0eSleo 	 * parameters with data for a "standard" configuration.
14047cf1b0eSleo 	 * Once we have a fully specified configuration, we try to probe
14147cf1b0eSleo 	 * a card with that configuration.
14247cf1b0eSleo 	 * The Leonardo only has one configuration and it isn't likely
14347cf1b0eSleo 	 * to change, but this routine doesn't assume that's the case.
14447cf1b0eSleo 	 */
14547cf1b0eSleo 	iot = va->va_iot;
14647cf1b0eSleo 	memt = va->va_memt;
14747cf1b0eSleo 	for (i = 0; i < NLEOSTD; i++) {
14847cf1b0eSleo 		struct leo_addresses *leo_ap = &leostd[i];
14947cf1b0eSleo 		int found = 0;
15047cf1b0eSleo 		struct vme_attach_args vat = *va;
15147cf1b0eSleo 
15247cf1b0eSleo 		if (vat.va_irq != VMECF_IRQ_DEFAULT) {
15347cf1b0eSleo 			printf("leo_match: config error: no irq support\n");
15447cf1b0eSleo 			return 0;
15547cf1b0eSleo 		}
15647cf1b0eSleo 		if (vat.va_iobase == VMECF_IOPORT_DEFAULT)
15747cf1b0eSleo 			vat.va_iobase = leo_ap->reg_addr;
15847cf1b0eSleo 		if (vat.va_maddr == VMECF_MEM_DEFAULT)
15947cf1b0eSleo 			vat.va_maddr = leo_ap->mem_addr;
16047cf1b0eSleo 		if (vat.va_iosize == VMECF_IOSIZE_DEFAULT)
16147cf1b0eSleo 			vat.va_iosize = leo_ap->reg_size;
16247cf1b0eSleo 		if (vat.va_msize == VMECF_MEMSIZ_DEFAULT)
16347cf1b0eSleo 			vat.va_msize = leo_ap->mem_size;
16447cf1b0eSleo 		if (bus_space_map(iot, vat.va_iobase, vat.va_iosize, 0, &ioh)) {
16547cf1b0eSleo 			printf("leo_match: cannot map io area\n");
16647cf1b0eSleo 			return 0;
16747cf1b0eSleo 		}
16847cf1b0eSleo 		if (bus_space_map(memt, vat.va_maddr, vat.va_msize,
16947cf1b0eSleo 				  BUS_SPACE_MAP_LINEAR|BUS_SPACE_MAP_CACHEABLE,
17047cf1b0eSleo 				  &memh)) {
171c9a30532Sleo 			bus_space_unmap(iot, ioh, vat.va_iosize);
17247cf1b0eSleo 			printf("leo_match: cannot map memory area\n");
17347cf1b0eSleo 			return 0;
17447cf1b0eSleo 		}
17547cf1b0eSleo 		found = leo_probe(&iot, &memt, &ioh, &memh,
17647cf1b0eSleo 				  vat.va_iosize, vat.va_msize);
177c9a30532Sleo 		bus_space_unmap(iot, ioh, vat.va_iosize);
178c9a30532Sleo 		bus_space_unmap(memt, memh, vat.va_msize);
17947cf1b0eSleo 		if (found) {
18047cf1b0eSleo 			*va = vat;
18147cf1b0eSleo 			return 1;
18247cf1b0eSleo 		}
18347cf1b0eSleo 	}
18447cf1b0eSleo 	return 0;
18547cf1b0eSleo }
18647cf1b0eSleo 
18747cf1b0eSleo static int
leo_probe(bus_space_tag_t * iot,bus_space_tag_t * memt,bus_space_handle_t * ioh,bus_space_handle_t * memh,u_int iosize,u_int msize)18882357f6dSdsl leo_probe(bus_space_tag_t *iot, bus_space_tag_t *memt, bus_space_handle_t *ioh, bus_space_handle_t *memh, u_int iosize, u_int msize)
18947cf1b0eSleo {
19047cf1b0eSleo 
19147cf1b0eSleo 	/* Test that our highest register is within the io range. */
19247cf1b0eSleo 	if (0xca > iosize) /* XXX */
19347cf1b0eSleo 		return 0;
19447cf1b0eSleo 	/* Test if we can peek each register. */
19547cf1b0eSleo 	if (!bus_space_peek_1(*iot, *ioh, LEO_REG_MSBSCROLL))
19647cf1b0eSleo 		return 0;
19747cf1b0eSleo 	if (!bus_space_peek_1(*iot, *ioh, LEO_REG_LSBSCROLL))
19847cf1b0eSleo 		return 0;
19947cf1b0eSleo 	/*
20047cf1b0eSleo 	 * Write a test pattern at the start and end of the memory region,
20147cf1b0eSleo 	 * and test if the pattern can be read back.  If so, the region is
20247cf1b0eSleo 	 * backed by memory (i.e. the card is present).
20347cf1b0eSleo 	 * On the Leonardo, the first byte of each longword isn't backed by
20447cf1b0eSleo 	 * physical memory, so we only compare the three low-order bytes
20547cf1b0eSleo 	 * with the test pattern.
20647cf1b0eSleo 	 */
20747cf1b0eSleo 	bus_space_write_4(*memt, *memh, 0, 0xa5a5a5a5);
20847cf1b0eSleo 	if ((bus_space_read_4(*memt, *memh, 0) & 0xffffff) != 0xa5a5a5)
20947cf1b0eSleo 		return 0;
21047cf1b0eSleo 	bus_space_write_4(*memt, *memh, msize - 4, 0xa5a5a5a5);
21147cf1b0eSleo 	if ((bus_space_read_4(*memt, *memh, msize - 4) & 0xffffff)
21247cf1b0eSleo 		!= 0xa5a5a5)
21347cf1b0eSleo 		return 0;
21447cf1b0eSleo 	return 1;
21547cf1b0eSleo }
21647cf1b0eSleo 
21747cf1b0eSleo static void
leo_attach(device_t parent,device_t self,void * aux)218097168d0Stsutsui leo_attach(device_t parent, device_t self, void *aux)
21947cf1b0eSleo {
220097168d0Stsutsui 	struct leo_softc *sc = device_private(self);
22147cf1b0eSleo 	struct vme_attach_args *va = aux;
22247cf1b0eSleo 	bus_space_handle_t ioh;
22347cf1b0eSleo 	bus_space_handle_t memh;
22447cf1b0eSleo #ifndef SET_REGION
22547cf1b0eSleo 	int i;
22647cf1b0eSleo #endif
22747cf1b0eSleo 
228097168d0Stsutsui 	sc->sc_dev = self;
229097168d0Stsutsui 
23047cf1b0eSleo 	printf("\n");
23147cf1b0eSleo 	if (bus_space_map(va->va_iot, va->va_iobase, va->va_iosize, 0, &ioh))
2320f09ed48Sprovos 		panic("leo_attach: cannot map io area");
23347cf1b0eSleo 	if (bus_space_map(va->va_memt, va->va_maddr, va->va_msize,
23447cf1b0eSleo 			  BUS_SPACE_MAP_LINEAR|BUS_SPACE_MAP_CACHEABLE, &memh))
2350f09ed48Sprovos 		panic("leo_attach: cannot map memory area");
23647cf1b0eSleo #ifdef SET_REGION /* XXX seems to be unimplemented on atari? */
23747cf1b0eSleo 	bus_space_set_region_4(va->va_memt, memh, 0, 0, va->va_msize >> 2);
23847cf1b0eSleo #else
23947cf1b0eSleo 	for (i = 0; i < (va->va_msize >> 2); i++)
24047cf1b0eSleo 		bus_space_write_4(va->va_memt, memh, i << 2, 0);
24147cf1b0eSleo #endif
24247cf1b0eSleo 	sc->sc_iot = va->va_iot;
24347cf1b0eSleo 	sc->sc_ioh = ioh;
24447cf1b0eSleo 	sc->sc_memt = va->va_memt;
24547cf1b0eSleo 	sc->sc_memh = memh;
24647cf1b0eSleo 	sc->sc_flags = 0;
24747cf1b0eSleo 	sc->sc_maddr = va->va_maddr;
24847cf1b0eSleo 	sc->sc_msize = va->va_msize;
24947cf1b0eSleo 	leo_init(sc, 512);
25047cf1b0eSleo 	leo_scroll(sc, 0);
25147cf1b0eSleo }
25247cf1b0eSleo 
25347cf1b0eSleo int
leoopen(dev_t dev,int flags,int devtype,struct lwp * l)254097168d0Stsutsui leoopen(dev_t dev, int flags, int devtype, struct lwp *l)
25547cf1b0eSleo {
25647cf1b0eSleo 	struct leo_softc *sc;
25747cf1b0eSleo 	int r;
25847cf1b0eSleo 
259947c9ab6Scegger 	sc = device_lookup_private(&leo_cd, minor(dev));
26047cf1b0eSleo 	if (!sc)
26147cf1b0eSleo 		return ENXIO;
26247cf1b0eSleo 	if (sc->sc_flags & LEO_SC_FLAGS_INUSE)
26347cf1b0eSleo 		return EBUSY;
26447cf1b0eSleo 	r = leo_init(sc, 512);
26547cf1b0eSleo 	if (r != 0)
26647cf1b0eSleo 		return r;
26747cf1b0eSleo 	r = leo_scroll(sc, 0);
26847cf1b0eSleo 	if (r != 0)
26947cf1b0eSleo 		return r;
27047cf1b0eSleo 	sc->sc_flags |= LEO_SC_FLAGS_INUSE;
27147cf1b0eSleo 	return 0;
27247cf1b0eSleo }
27347cf1b0eSleo 
27447cf1b0eSleo static int
leo_init(struct leo_softc * sc,int ysize)275454af1c0Sdsl leo_init(struct leo_softc *sc, int ysize)
27647cf1b0eSleo {
27747cf1b0eSleo 
27847cf1b0eSleo 	if ((ysize != 256) && (ysize != 384) && (ysize != 512))
27947cf1b0eSleo 		return EINVAL;
28047cf1b0eSleo 	/* XXX */
28147cf1b0eSleo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x00, 0x6);
28247cf1b0eSleo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x08, 0x0);
28347cf1b0eSleo 	if (ysize == 384)
28447cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x10, 0x10);
28547cf1b0eSleo 	else
28647cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x10, 0x11);
28747cf1b0eSleo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x18, 0x0);
28847cf1b0eSleo 	if (ysize == 384)
28947cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x20, 0x50);
29047cf1b0eSleo 	else
29147cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x20, 0x51);
29247cf1b0eSleo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x28, 0x0);
29347cf1b0eSleo 	if (ysize == 384)
29447cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x30, 0x56);
29547cf1b0eSleo 	else
29647cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x30, 0x57);
29747cf1b0eSleo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x38, 0x0);
29847cf1b0eSleo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x40, 0x6);
29947cf1b0eSleo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x48, 0x0);
30047cf1b0eSleo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x50, 0x25);
30147cf1b0eSleo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x58, 0x0);
30247cf1b0eSleo 	if (ysize == 256) {
30347cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x60, 0x1f);
30447cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x68, 0x1);
30547cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x70, 0x29);
30647cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x78, 0x1);
30747cf1b0eSleo 	} else if (ysize == 384) {
30847cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x60, 0xa5);
30947cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x68, 0x1);
31047cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x70, 0xa7);
31147cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x78, 0x1);
31247cf1b0eSleo 	} else {
31347cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x60, 0x1d);
31447cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x68, 0x2);
31547cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x70, 0x27);
31647cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x78, 0x2);
31747cf1b0eSleo 	}
31847cf1b0eSleo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0xb8, 0x10);
31947cf1b0eSleo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0xb0, 0x10);
32047cf1b0eSleo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x80, 0x4);
32147cf1b0eSleo 	if (ysize == 384)
32247cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0xc8, 0x21);
32347cf1b0eSleo 	else
32447cf1b0eSleo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0xc8, 0x20);
32547cf1b0eSleo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0xc0, 0x40);
32647cf1b0eSleo 	return 0;
32747cf1b0eSleo }
32847cf1b0eSleo 
32947cf1b0eSleo static int
leo_scroll(struct leo_softc * sc,int scroll)330454af1c0Sdsl leo_scroll(struct leo_softc *sc, int scroll)
33147cf1b0eSleo {
33247cf1b0eSleo 
33347cf1b0eSleo 	if ((scroll < 0) || (scroll > 255))
33447cf1b0eSleo 		return EINVAL;
33547cf1b0eSleo 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, LEO_REG_MSBSCROLL,
3363db65f61Schristos 			  (scroll >> 6) & 0xff);
33747cf1b0eSleo 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, LEO_REG_LSBSCROLL,
3383db65f61Schristos 			  (scroll << 2) & 0xff);
33947cf1b0eSleo 	return 0;
34047cf1b0eSleo }
34147cf1b0eSleo 
34247cf1b0eSleo int
leoclose(dev_t dev,int flags,int devtype,struct lwp * l)343097168d0Stsutsui leoclose(dev_t dev, int flags, int devtype, struct lwp *l)
34447cf1b0eSleo {
34547cf1b0eSleo 	struct leo_softc *sc;
34647cf1b0eSleo 
347947c9ab6Scegger 	sc = device_lookup_private(&leo_cd, minor(dev));
34847cf1b0eSleo 	sc->sc_flags &= ~LEO_SC_FLAGS_INUSE;
34947cf1b0eSleo 	return 0;
35047cf1b0eSleo }
35147cf1b0eSleo 
35247cf1b0eSleo #define SMALLBSIZE      32
35347cf1b0eSleo 
35477a6b82bSgehenna int
leomove(dev_t dev,struct uio * uio,int flags)355947c9ab6Scegger leomove(dev_t dev, struct uio *uio, int flags)
35647cf1b0eSleo {
35747cf1b0eSleo 	struct leo_softc *sc;
35847cf1b0eSleo 	int length, size, error;
35947cf1b0eSleo 	u_int8_t smallbuf[SMALLBSIZE];
36047cf1b0eSleo 	off_t offset;
36147cf1b0eSleo 
362947c9ab6Scegger 	sc = device_lookup_private(&leo_cd,minor(dev));
36347cf1b0eSleo 	if (uio->uio_offset > sc->sc_msize)
36447cf1b0eSleo 		return 0;
36547cf1b0eSleo 	length = sc->sc_msize - uio->uio_offset;
36647cf1b0eSleo 	if (length > uio->uio_resid)
36747cf1b0eSleo 		length = uio->uio_resid;
36847cf1b0eSleo 	while (length > 0) {
36947cf1b0eSleo 		size = length;
37047cf1b0eSleo 		if (size > SMALLBSIZE)
37147cf1b0eSleo 			size = SMALLBSIZE;
37247cf1b0eSleo 		length -= size;
37347cf1b0eSleo 		offset = uio->uio_offset;
37447cf1b0eSleo 		if (uio->uio_rw == UIO_READ)
37547cf1b0eSleo 			bus_space_read_region_1(sc->sc_memt, sc->sc_memh,
37647cf1b0eSleo 			    offset, smallbuf, size);
37753524e44Schristos 		if ((error = uiomove((void *)smallbuf, size, uio)))
37847cf1b0eSleo 			return (error);
37947cf1b0eSleo 		if (uio->uio_rw == UIO_WRITE)
38047cf1b0eSleo 			bus_space_write_region_1(sc->sc_memt, sc->sc_memh,
38147cf1b0eSleo 			    offset, smallbuf, size);
38247cf1b0eSleo 	}
38347cf1b0eSleo 	return 0;
38447cf1b0eSleo }
38547cf1b0eSleo 
38647cf1b0eSleo int
leoioctl(dev_t dev,u_long cmd,void * data,int flags,struct lwp * l)387097168d0Stsutsui leoioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
38847cf1b0eSleo {
38947cf1b0eSleo 	struct leo_softc *sc;
39047cf1b0eSleo 
391947c9ab6Scegger 	sc = device_lookup_private(&leo_cd,minor(dev));
39247cf1b0eSleo 	switch (cmd) {
39347cf1b0eSleo 	case LIOCYRES:
39447cf1b0eSleo 		return leo_init(sc, *(int *)data);
39547cf1b0eSleo 		break;
39647cf1b0eSleo 	case LIOCSCRL:
39747cf1b0eSleo 		return leo_scroll(sc, *(int *)data);
39847cf1b0eSleo 		break;
39947cf1b0eSleo 	default:
40047cf1b0eSleo 		return EINVAL;
40147cf1b0eSleo 		break;
40247cf1b0eSleo 	}
40347cf1b0eSleo }
40447cf1b0eSleo 
405889c658bSsimonb paddr_t
leommap(dev_t dev,off_t offset,int prot)406947c9ab6Scegger leommap(dev_t dev, off_t offset, int prot)
40747cf1b0eSleo {
40847cf1b0eSleo 	struct leo_softc *sc;
40947cf1b0eSleo 
410947c9ab6Scegger 	sc = device_lookup_private(&leo_cd, minor(dev));
41147cf1b0eSleo 	if (offset >= 0 && offset < sc->sc_msize)
41247cf1b0eSleo 		return m68k_btop(sc->sc_maddr + offset);
41347cf1b0eSleo 	return -1;
41447cf1b0eSleo }
415