diff options
author | Kenji Aoyama <aoyama@cvs.openbsd.org> | 2007-01-29 14:18:01 +0000 |
---|---|---|
committer | Kenji Aoyama <aoyama@cvs.openbsd.org> | 2007-01-29 14:18:01 +0000 |
commit | 6306aef59f4a6f6202699665489bfeb95ff5c51c (patch) | |
tree | fb1e902898a3b2cd427c82abf7da80b2c7c2f9ed /sys/arch/luna88k | |
parent | 4f0a489d0850dbd3f4699dffd349aa86a223e221 (diff) |
LCD device driver support for luna88k, first step.
ok miod@
Diffstat (limited to 'sys/arch/luna88k')
-rw-r--r-- | sys/arch/luna88k/dev/lcd.c | 168 | ||||
-rw-r--r-- | sys/arch/luna88k/include/conf.h | 11 | ||||
-rw-r--r-- | sys/arch/luna88k/include/lcd.h | 65 | ||||
-rw-r--r-- | sys/arch/luna88k/luna88k/conf.c | 4 |
4 files changed, 235 insertions, 13 deletions
diff --git a/sys/arch/luna88k/dev/lcd.c b/sys/arch/luna88k/dev/lcd.c index cfba031871c..8e0720552b1 100644 --- a/sys/arch/luna88k/dev/lcd.c +++ b/sys/arch/luna88k/dev/lcd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lcd.c,v 1.1 2004/04/21 15:23:52 aoyama Exp $ */ +/* $OpenBSD: lcd.c,v 1.2 2007/01/29 14:18:00 aoyama Exp $ */ /* $NetBSD: lcd.c,v 1.2 2000/01/07 05:13:08 nisimura Exp $ */ /*- @@ -37,17 +37,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/* Taken from NetBSD/luna68k */ - -/* - * XXX - * Following code segments are subject to change. - * XXX - */ - #include <sys/param.h> #include <sys/systm.h> #include <sys/device.h> +#include <sys/ioctl.h> +#include <sys/fcntl.h> + +#include <machine/conf.h> +#include <machine/lcd.h> #define PIO1_MODE_OUTPUT 0x84 #define PIO1_MODE_INPUT 0x94 @@ -69,6 +66,8 @@ #define LCD_HOME 0x02 #define LCD_LOCATE(X, Y) (((Y) & 1 ? 0xc0 : 0x80) | ((X) & 0x0f)) +#define LCD_MAXBUFLEN 80 + struct pio { volatile u_int8_t portA; volatile unsigned : 24; @@ -80,15 +79,164 @@ struct pio { volatile unsigned : 24; }; +/* Internal prototypes */ void lcdbusywait(void); void lcdput(int); void lcdctrl(int); void lcdshow(const char *); void greeting(void); - /* "1234567890123456" */ + +/* Internal variables */ +int lcd_opened = 0; + /* "1234567890123456" */ static const char lcd_boot_message1[] = "OpenBSD/luna88k "; static const char lcd_boot_message2[] = " SX-9100/DT "; +/* + * open/close/write/ioctl + */ + +int +lcdopen(dev, flags, fmt, p) + dev_t dev; + int flags, fmt; + struct proc *p; +{ + if (minor(dev) != 0) + return ENXIO; + if (lcd_opened) + return EBUSY; + lcd_opened = 1; + + return 0; +} + +int +lcdclose(dev, flags, fmt, p) + dev_t dev; + int flags, fmt; + struct proc *p; +{ + lcd_opened = 0; + + return 0; +} + +int +lcdwrite(dev, uio, flag) + dev_t dev; + struct uio *uio; + int flag; +{ + int error, len; + int i, n; + char buf[LCD_MAXBUFLEN]; + + len = n = uio->uio_resid; + + if ((len < 0) || (len > LCD_MAXBUFLEN)) + return EIO; + + while (n > 0) { + error = uiomove(buf, n, uio); + if (error) + return EIO; + n = uio->uio_resid; + } + + for(i = 0; i < len; i++) { + lcdput((int)buf[i]); + } + + return 0; +} + +int +lcdioctl(dev, cmd, addr, flag, p) + dev_t dev; + u_long cmd; + caddr_t addr; + int flag; + struct proc *p; +{ + int val; + + /* check if the device opened with write mode */ + switch(cmd) { + case LCDCLS: + case LCDHOME: + case LCDMODE: + case LCDDISP: + case LCDMOVE: + case LCDSEEK: + case LCDRESTORE: + if ((flag & FWRITE) == 0) + return EACCES; + break; + } + + switch(cmd) { + case LCDCLS: + lcdctrl(LCD_CLS); + break; + + case LCDHOME: + lcdctrl(LCD_HOME); + break; + + case LCDMODE: + val = *(int *)addr; + switch (val) { + case LCDMODE_C_LEFT: + case LCDMODE_C_RIGHT: + case LCDMODE_D_LEFT: + case LCDMODE_D_RIGHT: + lcdctrl(val); + break; + default: + return EINVAL; + } + break; + + case LCDDISP: + val = *(int *)addr; + if ((val & 0x7) != val) + return EINVAL; + lcdctrl(val | 0x8); + break; + + case LCDMOVE: + val = *(int *)addr; + switch (val) { + case LCDMOVE_C_LEFT: + case LCDMOVE_C_RIGHT: + case LCDMOVE_D_LEFT: + case LCDMOVE_D_RIGHT: + lcdctrl(val); + break; + default: + return EINVAL; + } + break; + + case LCDSEEK: + val = *(int *)addr & 0x7f; + lcdctrl(val | 0x80); + break; + + case LCDRESTORE: + greeting(); + break; + + default: + return ENOTTY; + } + return 0; +} + +/* + * Internal functions + */ void lcdbusywait() { diff --git a/sys/arch/luna88k/include/conf.h b/sys/arch/luna88k/include/conf.h index df90e73a09f..27dd8083330 100644 --- a/sys/arch/luna88k/include/conf.h +++ b/sys/arch/luna88k/include/conf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.h,v 1.1 2004/05/07 15:08:25 aoyama Exp $ */ +/* $OpenBSD: conf.h,v 1.2 2007/01/29 14:18:00 aoyama Exp $ */ /* * Copyright (c) 2004, Miodrag Vallat. * All rights reserved. @@ -34,3 +34,12 @@ cdev_decl(mm); cdev_decl(sio); + +cdev_decl(lcd); + +/* open, close, write, ioctl */ +#define cdev_lcd_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), \ + (dev_type_read((*))) enodev, dev_init(c,n,write), \ + dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ + 0, seltrue, (dev_type_mmap((*))) enodev } diff --git a/sys/arch/luna88k/include/lcd.h b/sys/arch/luna88k/include/lcd.h new file mode 100644 index 00000000000..3620a88c9af --- /dev/null +++ b/sys/arch/luna88k/include/lcd.h @@ -0,0 +1,65 @@ +/* $OpenBSD: lcd.h,v 1.1 2007/01/29 14:18:00 aoyama Exp $ */ + +/* + * Copyright (c) 2007 Kenji AOYAMA <aoyama@nk-home.net> + * 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 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 AUTHOR 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. + */ + +#ifndef _LUNA88K_LCD_H_ +#define _LUNA88K_LCD_H_ + +/* + * OpenBSD/luna88k LCD driver + */ + +/* The ioctl defines */ + +#define LCDCLS _IO('L', 1) /* Clear LCD screen */ +#define LCDHOME _IO('L', 2) /* Move the cursor to left-upper */ +#define LCDMODE _IOW('L', 3, int) /* Set the data entry mode */ +#define LCDDISP _IOW('L', 4, int) /* Blink, cursor, and display on/off */ +#define LCDMOVE _IOW('L', 5, int) /* Move cursor / shift display area */ +#define LCDSEEK _IOW('L', 6, int) /* Move the cursor to specified position */ +#define LCDRESTORE _IO('L', 7) /* Restore boot-time LCD message */ + +/* argument value for each ioctl */ + +/* LCDMODE; when a character data is written, then ... */ +#define LCDMODE_C_LEFT 0x04 /* cursor moves left */ +#define LCDMODE_C_RIGHT 0x06 /* cursor moves right */ +#define LCDMODE_D_LEFT 0x05 /* display area shifts to left */ +#define LCDMODE_D_RIGHT 0x07 /* display area shifts to right */ + +/* LCDDISP; you can use these values or'ed */ +#define LCD_DISPLAY 0x04 /* LCD display on */ +#define LCD_CURSOR 0x02 /* Cursor on */ +#define LCD_BLINK 0x01 /* Blink on */ + +/* LCDMOVE; just move the cursor or shift the display area */ +#define LCDMOVE_C_LEFT 0x10 /* cursor moves left */ +#define LCDMOVE_C_RIGHT 0x14 /* cursor moves right */ +#define LCDMOVE_D_LEFT 0x18 /* display area shifts to left */ +#define LCDMOVE_D_RIGHT 0x1c /* display area shifts to right */ + +#endif /* _LUNA88K_LCD_H_ */ diff --git a/sys/arch/luna88k/luna88k/conf.c b/sys/arch/luna88k/luna88k/conf.c index 22be67388f3..85c48c71fe5 100644 --- a/sys/arch/luna88k/luna88k/conf.c +++ b/sys/arch/luna88k/luna88k/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.2 2004/05/07 15:08:25 aoyama Exp $ */ +/* $OpenBSD: conf.c,v 1.3 2007/01/29 14:18:00 aoyama Exp $ */ /*- * Copyright (c) 1991 The Regents of the University of California. @@ -105,7 +105,7 @@ struct cdevsw cdevsw[] = cdev_notdef(), /* 7: */ cdev_disk_init(NSD,sd), /* 8: SCSI disk */ cdev_disk_init(NCD,cd), /* 9: SCSI CD-ROM */ - cdev_notdef(), /* 10 */ + cdev_lcd_init(1, lcd), /* 10: /dev/lcd */ cdev_notdef(), /* 11 */ cdev_tty_init(NSIOTTY,sio), /* 12: on-board UART (ttya) */ cdev_wsdisplay_init(NWSDISPLAY, /* 13: frame buffers, etc. */ |