/* suncore.c
*
- * Generic SUN serial/kbd/ms layer. Based entirely
+ * Common SUN serial routines. Based entirely
* upon drivers/sbus/char/sunserial.c which is:
*
* Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
*
- * Port to new UART layer is:
+ * Adaptation to new UART layer is:
*
* Copyright (C) 2002 David S. Miller (davem@redhat.com)
*/
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
-#include <linux/kbd_diacr.h>
#include <linux/init.h>
-#include <linux/bootmem.h>
#include <asm/oplib.h>
int serial_console;
int stop_a_enabled = 1;
+int sunserial_current_minor = 64;
-int __init con_is_present(void)
-{
- return serial_console ? 0 : 1;
-}
-
-static void __init nop_rs_kgdb_hook(int channel)
-{ printk("Oops: nop_rs_kgdb_hook called\n"); }
-
-static void nop_rs_change_mouse_baud(int baud)
-{ printk("Oops: nop_rs_change_mouse_baud called\n"); }
-
-static int nop_rs_read_proc(char *page, char **start, off_t off, int count,
- int *eof, void *data)
-{ printk("Oops: nop_rs_read_proc called\n"); return 0; }
-
-struct sunserial_operations rs_ops = {
- 0,
- nop_rs_kgdb_hook,
- nop_rs_change_mouse_baud,
- nop_rs_read_proc
-};
-
-static int __init serial_sun_init(void)
-{
- struct sun_initfunc *init;
-
- init = rs_ops.rs_init;
- while (init) {
- (void) init->init();
- init = init->next;
- }
-
- return 0;
-}
-
-static void __exit serial_sun_exit(void)
-{
-}
-
-module_init(serial_sun_init);
-module_exit(serial_sun_exit);
-
-void __init rs_kgdb_hook(int channel)
-{ rs_ops.rs_kgdb_hook(channel); }
-
-void rs_change_mouse_baud(int baud)
-{ rs_ops.rs_change_mouse_baud(baud); }
-
-int rs_read_proc(char *page, char **start, off_t off, int count,
- int *eof, void *data)
-{ return rs_ops.rs_read_proc(page, start, off, count, eof, data); }
-
-static void nop_compute_shiftstate (void)
-{ printk("Oops: nop_compute_shiftstate called\n"); }
-
-static void nop_setledstate (struct kbd_struct *kbd, unsigned int ledstate)
-{ printk("Oops: nop_setledstate called\n"); }
-
-static unsigned char nop_getledstate (void)
-{ printk("Oops: nop_getledstate called\n"); return 0; }
-
-static int nop_setkeycode (unsigned int scancode, unsigned int keycode)
-{ printk("Oops: nop_setkeycode called\n"); return -EINVAL; }
-
-static int nop_getkeycode (unsigned int scancode)
-{ printk("Oops: nop_getkeycode called\n"); return -EINVAL; }
-
-struct sunkbd_operations kbd_ops = {
- 0,
- nop_compute_shiftstate,
- nop_setledstate,
- nop_getledstate,
- nop_setkeycode,
- nop_getkeycode
-};
-
-#ifdef CONFIG_USB
-extern void pci_compute_shiftstate(void);
-extern int pci_setkeycode(unsigned int, unsigned int);
-extern int pci_getkeycode(unsigned int);
-extern void pci_setledstate(struct kbd_struct *, unsigned int);
-extern unsigned char pci_getledstate(void);
-extern int pcikbd_init(void);
-#endif
-
-int kbd_init(void)
-{
- struct sun_initfunc *init;
- int err = -ENODEV;
-
- init = kbd_ops.kbd_init;
- while (init) {
- err = init->init();
- init = init->next;
- }
-#ifdef CONFIG_USB
- if (!serial_console &&
- kbd_ops.compute_shiftstate == nop_compute_shiftstate) {
- printk("kbd_init: Assuming USB keyboard.\n");
- kbd_ops.compute_shiftstate = pci_compute_shiftstate;
- kbd_ops.setledstate = pci_setledstate;
- kbd_ops.getledstate = pci_getledstate;
- kbd_ops.setkeycode = pci_setkeycode;
- kbd_ops.getkeycode = pci_getkeycode;
- pcikbd_init();
- }
-#endif
- return err;
-}
-
-void compute_shiftstate(void)
-{ kbd_ops.compute_shiftstate(); }
-
-void setledstate(struct kbd_struct *kbd, unsigned int ledstate)
-{ kbd_ops.setledstate(kbd, ledstate); }
-
-unsigned char getledstate(void)
-{ return kbd_ops.getledstate(); }
-
-int setkeycode(unsigned int scancode, unsigned int keycode)
-{ return kbd_ops.setkeycode(scancode, keycode); }
-
-int getkeycode(unsigned int scancode)
-{ return kbd_ops.getkeycode(scancode); }
-
-void * __init sunserial_alloc_bootmem(unsigned long size)
-{
- void *ret;
-
- ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
- if (ret != NULL)
- memset(ret, 0, size);
-
- return ret;
-}
-
-void
-sunserial_setsun_initfunc(int (*init) (void))
-{
- struct sun_initfunc *rs_initfunc;
-
- rs_initfunc = sunserial_alloc_bootmem(sizeof(*rs_initfunc));
- if (rs_initfunc == NULL) {
- prom_printf("sunserial_setsun_initfunc: Cannot alloc sun_initfunc.\n");
- prom_halt();
- }
-
- rs_initfunc->init = init;
- rs_initfunc->next = rs_ops.rs_init;
- rs_ops.rs_init = rs_initfunc;
-}
+EXPORT_SYMBOL(serial_console);
+EXPORT_SYMBOL(stop_a_enabled);
+EXPORT_SYMBOL(sunserial_current_minor);
void
sunserial_console_termios(struct console *con)
/* XXX: this is unused below. */
}
- if (prom_node_has_property(nd, cd_prop)) {
+ if (prom_node_has_property(nd, dtr_prop)) {
memset(buf, 0, sizeof(buf));
- prom_getstring(nd, cd_prop, buf, sizeof(buf));
+ prom_getstring(nd, dtr_prop, buf, sizeof(buf));
if (!strcmp(buf, "false"))
rtsdtr = 0;
con->cflag = cflag;
}
+EXPORT_SYMBOL(sunserial_console_termios);
+
void
-sunkbd_setsun_initfunc(int (*init)(void))
+sun_do_break(void)
{
- struct sun_initfunc *kbd_initfunc;
+ if (!stop_a_enabled)
+ return;
- kbd_initfunc = sunserial_alloc_bootmem(sizeof(*kbd_initfunc));
- if (kbd_initfunc == NULL) {
- prom_printf("sunkbd_setsun_initfunc: Cannot alloc sun_initfunc.\n");
- prom_halt();
- }
+ printk("\n");
+ flush_user_windows();
- kbd_initfunc->init = init;
- kbd_initfunc->next = kbd_ops.kbd_init;
- kbd_ops.kbd_init = kbd_initfunc;
+#ifndef CONFIG_SPARC64
+ if ((unsigned long)linux_dbvec >= DEBUG_FIRSTVADDR &&
+ (unsigned long)linux_dbvec <= DEBUG_LASTVADDR)
+ sp_enter_debugger();
+ else
+#endif
+ prom_cmdline();
}
-#ifdef CONFIG_PCI
-void
-sunkbd_install_keymaps(ushort **src_key_maps, unsigned int src_keymap_count,
- char *src_func_buf, char **src_func_table,
- int src_funcbufsize, int src_funcbufleft,
- struct kbdiacr *src_accent_table,
- unsigned int src_accent_table_size)
+EXPORT_SYMBOL(sun_do_break);
+
+/* Sun serial MOUSE auto baud rate detection. */
+static struct mouse_baud_cflag {
+ int baud;
+ unsigned int cflag;
+} mouse_baud_table[] = {
+ { 1200, B1200 },
+ { 2400, B2400 },
+ { 4800, B4800 },
+ { 9600, B9600 },
+ { -1, ~0 },
+ { -1, ~0 },
+};
+
+unsigned int suncore_mouse_baud_cflag_next(unsigned int cflag, int *new_baud)
{
- extern unsigned int keymap_count;
- int i, j;
-
- for (i = 0; i < MAX_NR_KEYMAPS; i++) {
- if (src_key_maps[i]) {
- if (!key_maps[i]) {
- key_maps[i] = (ushort *)
- sunserial_alloc_bootmem(NR_KEYS * sizeof(ushort));
- if (key_maps[i] == NULL) {
- prom_printf("sunkbd_install_keymaps: "
- "Cannot alloc key_map(%d).\n", i);
- prom_halt();
- }
- }
- for (j = 0; j < NR_KEYS; j++)
- key_maps[i][j] = src_key_maps[i][j];
- }
- key_maps[i] = src_key_maps[i];
- }
- keymap_count = src_keymap_count;
+ int i;
+
+ for (i = 0; mouse_baud_table[i].baud != -1; i++)
+ if (mouse_baud_table[i].cflag == (cflag & CBAUD))
+ break;
- for (i = 0; i < MAX_NR_FUNC; i++)
- func_table[i] = src_func_table[i];
- funcbufptr = src_func_buf;
- funcbufsize = src_funcbufsize;
- funcbufleft = src_funcbufleft;
+ i += 1;
+ if (mouse_baud_table[i].baud == -1)
+ i = 0;
- for (i = 0; i < MAX_DIACR; i++)
- accent_table[i] = src_accent_table[i];
- accent_table_size = src_accent_table_size;
+ *new_baud = mouse_baud_table[i].baud;
+ return mouse_baud_table[i].cflag;
}
-#endif
-extern int sunsu_probe(void);
-extern int sunzilog_probe(void);
-#ifdef CONFIG_SAB82532
-extern int sab82532_probe(void);
-#endif
-#ifdef CONFIG_PCI
-extern int ps2kbd_probe(void);
-#endif
+EXPORT_SYMBOL(suncore_mouse_baud_cflag_next);
-/* This is called by the sparc32/sparc64 MM init layer right after
- * the bootmem allocator has been setup and is ready to use.
+/* Basically, when the baud rate is wrong the mouse spits out
+ * breaks to us.
*/
-void __init sun_serial_setup(void)
+int suncore_mouse_baud_detection(unsigned char ch, int is_break)
{
- int ret = 1;
-
-#if defined(CONFIG_PCI) && !defined(CONFIG_SPARC64)
- /*
- * Probing sequence on sparc differs from sparc64.
- * Keyboard is probed ahead of su because we want su function
- * when keyboard is active. su is probed ahead of zs in order to
- * get console on MrCoffee with fine but disconnected zs.
- */
- if (!serial_console)
- ps2kbd_probe();
- if (sunsu_probe() == 0)
- return;
-#endif
-
- if (sunzilog_probe() == 0)
- return;
-
-#ifdef CONFIG_SAB82532
- ret = sab82532_probe();
-#endif
+ static int mouse_got_break = 0;
+ static int ctr = 0;
+
+ if (is_break) {
+ /* Let a few normal bytes go by before we jump the gun
+ * and say we need to try another baud rate.
+ */
+ if (mouse_got_break && ctr < 8)
+ return 1;
+
+ /* Ok, we need to try another baud. */
+ ctr = 0;
+ mouse_got_break = 1;
+ return 2;
+ }
+ if (mouse_got_break) {
+ ctr++;
+ if (c == 0x87) {
+ /* Correct baud rate determined. */
+ mouse_got_break = 0;
+ }
+ return 1;
+ }
+ return 0;
+}
-#if defined(CONFIG_PCI) && defined(CONFIG_SPARC64)
- /*
- * Keyboard serial devices.
- *
- * Well done, Sun, prom_devopen("/pci@1f,4000/ebus@1/su@14,3083f8")
- * hangs the machine if no keyboard is connected to the device...
- * All PCI PROMs seem to do this, I have seen this on the Ultra 450
- * with version 3.5 PROM, and on the Ultra/AX with 3.1.5 PROM.
- *
- * So be very careful not to probe for keyboards if we are on a
- * serial console.
- */
- if (!serial_console)
- ps2kbd_probe();
- if (sunsu_probe() == 0)
- return;
-#endif
+EXPORT_SYMBOL(suncore_mouse_baud_detection);
- if (!ret)
- return;
-
-#ifdef CONFIG_SPARC64
- { extern int this_is_starfire;
- /* Hello, Starfire. Pleased to meet you :) */
- if (this_is_starfire != 0)
- return;
- }
-#endif
+static int __init suncore_init(void)
+{
+ return 0;
+}
- prom_printf("No serial devices found, bailing out.\n");
- prom_halt();
+static void __exit suncore_exit(void)
+{
}
+
+module_init(suncore_init);
+module_exit(suncore_exit);
+
+MODULE_AUTHOR("Eddie C. Dost, David S. Miller");
+MODULE_DESCRIPTION("Sun serial common layer");
+MODULE_LICENSE("GPL");
#include <linux/config.h>
-struct sun_initfunc {
- int (*init) (void);
- struct sun_initfunc *next;
-};
-
-struct sunserial_operations {
- struct sun_initfunc *rs_init;
- void (*rs_kgdb_hook) (int);
- void (*rs_change_mouse_baud) (int);
- int (*rs_read_proc) (char *, char **, off_t, int, int *, void *);
-};
-
-struct sunkbd_operations {
- struct sun_initfunc *kbd_init;
- void (*compute_shiftstate) (void);
- void (*setledstate) (struct kbd_struct *, unsigned int);
- unsigned char (*getledstate) (void);
- int (*setkeycode) (unsigned int, unsigned int);
- int (*getkeycode) (unsigned int);
-};
-
-extern struct sunserial_operations rs_ops;
-extern struct sunkbd_operations kbd_ops;
-
-extern void sunserial_setinitfunc(int (*) (void));
-extern void sunkbd_setinitfunc(int (*) (void));
+extern void sun_do_break(void);
+
+extern unsigned int suncore_mouse_baud_cflag_next(unsigned int, int *);
+extern int suncore_mouse_baud_detection(unsigned char, int);
extern int serial_console;
extern int stop_a_enabled;
-extern void sunserial_console_termios(struct console *);
+extern int sunserial_current_minor;
-#ifdef CONFIG_PCI
-extern void sunkbd_install_keymaps(ushort **, unsigned int, char *,
- char **, int, int, struct kbdiacr *,
- unsigned int);
-#endif
+static __inline__ int con_is_present(void)
+{
+ return serial_console ? 0 : 1;
+}
+
+extern void sunserial_console_termios(struct console *);
#endif /* !(_SERIAL_SUN_H) */
+++ /dev/null
-/* keyboard.c: Sun keyboard driver.
- *
- * Copyright (C) 1995, 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
- *
- * Added vuid event generation and /dev/kbd device for SunOS
- * compatibility - Miguel (miguel@nuclecu.unam.mx)
- *
- * Added PCI 8042 controller support -DaveM
- * Added Magic SysRq support -MJ
- */
-
-#include <linux/config.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/tty.h>
-#include <linux/tty_flip.h>
-#include <linux/mm.h>
-#include <linux/ptrace.h>
-#include <linux/signal.h>
-#include <linux/string.h>
-#include <linux/fcntl.h>
-#include <linux/poll.h>
-#include <linux/random.h>
-#include <linux/delay.h>
-#include <linux/init.h>
-#include <linux/sysrq.h>
-#include <linux/spinlock.h>
-#include <linux/smp_lock.h>
-#include <linux/devfs_fs_kernel.h>
-
-#include <asm/kbio.h>
-#include <asm/vuid_event.h>
-#include <asm/bitops.h>
-#include <asm/oplib.h>
-#include <asm/uaccess.h>
-
-#include <linux/kbd_kern.h>
-#include <linux/kbd_diacr.h>
-#include <linux/vt_kern.h>
-
-#ifdef CONFIG_PCI
-#include <linux/pci.h>
-#include <asm/pbm.h>
-#include <asm/ebus.h>
-#endif
-
-#include "sunkbd.h"
-
-#define SIZE(x) (sizeof(x)/sizeof((x)[0]))
-
-/* Define this one if you are making a new frame buffer driver */
-/* it will not block the keyboard */
-/* #define CODING_NEW_DRIVER */
-
-/* KBD device number, temporal */
-#define KBD_MAJOR 11
-
-#define KBD_REPORT_ERR
-#define KBD_REPORT_UNKN
-
-#ifndef KBD_DEFMODE
-#define KBD_DEFMODE ((1 << VC_REPEAT) | (1 << VC_META))
-#endif
-
-#ifndef KBD_DEFLEDS
-/*
- * Some laptops take the 789uiojklm,. keys as number pad when NumLock
- * is on. This seems a good reason to start with NumLock off.
- */
-#define KBD_DEFLEDS 0
-#endif
-
-#ifndef KBD_DEFLOCK
-#define KBD_DEFLOCK 0
-#endif
-
-extern void poke_blanked_console(void);
-extern void ctrl_alt_del(void);
-extern void reset_vc(unsigned int new_console);
-extern void scrollback(int);
-extern void scrollfront(int);
-
-struct l1a_kbd_state l1a_state;
-
-static spinlock_t sunkbd_lock = SPIN_LOCK_UNLOCKED;
-
-/*
- * global state includes the following, and various static variables
- * in this module: prev_scancode, shift_state, diacr, npadch, dead_key_next.
- * (last_console is now a global variable)
- */
-
-/* shift state counters.. */
-static unsigned char k_down[NR_SHIFT];
-/* keyboard key bitmap */
-static unsigned long key_down[256/BITS_PER_LONG];
-
-void push_kbd (int scan);
-int kbd_redirected;
-
-static int dead_key_next;
-/*
- * In order to retrieve the shift_state (for the mouse server), either
- * the variable must be global, or a new procedure must be created to
- * return the value. I chose the former way.
- */
-#ifndef CONFIG_PCI
-int shift_state;
-struct kbd_struct kbd_table[MAX_NR_CONSOLES];
-#endif
-static int npadch = -1; /* -1 or number assembled on pad */
-static unsigned char diacr;
-static char rep; /* flag telling character repeat */
-static struct tty_struct **ttytab;
-static struct kbd_struct * kbd = kbd_table;
-static struct tty_struct * tty;
-static int compose_led_on;
-static int kbd_delay_ticks = HZ / 5;
-static int kbd_rate_ticks = HZ / 20;
-
-void sun_compute_shiftstate(void);
-
-typedef void (*k_hand)(unsigned char value, char up_flag);
-typedef void (k_handfn)(unsigned char value, char up_flag);
-
-static k_handfn
- do_self, do_fn, do_spec, do_pad, do_dead, do_cons, do_cur, do_shift,
- do_meta, do_ascii, do_lock, do_lowercase, do_ignore;
-
-static k_hand key_handler[16] = {
- do_self, do_fn, do_spec, do_pad, do_dead, do_cons, do_cur, do_shift,
- do_meta, do_ascii, do_lock, do_lowercase,
- do_ignore, do_ignore, do_ignore, do_ignore
-};
-
-typedef void (*void_fnp)(void);
-typedef void (void_fn)(void);
-
-static void_fn do_null, enter, show_ptregs, send_intr, lastcons, caps_toggle,
- num, hold, scroll_forw, scroll_back, boot_it, caps_on, compose,
- SAK, decr_console, incr_console, spawn_console, bare_num;
-
-static void_fnp spec_fn_table[] = {
- do_null, enter, show_ptregs, show_mem,
- show_state, send_intr, lastcons, caps_toggle,
- num, hold, scroll_forw, scroll_back,
- boot_it, caps_on, compose, SAK,
- decr_console, incr_console, spawn_console, bare_num
-};
-
-/* maximum values each key_handler can handle */
-#ifndef CONFIG_PCI
-const int max_vals[] = {
- 255, SIZE(func_table) - 1, SIZE(spec_fn_table) - 1, NR_PAD - 1,
- NR_DEAD - 1, 255, 3, NR_SHIFT - 1,
- 255, NR_ASCII - 1, NR_LOCK - 1, 255,
- NR_LOCK - 1
-};
-
-const int NR_TYPES = SIZE(max_vals);
-#endif
-
-static void put_queue(int);
-static unsigned char handle_diacr(unsigned char);
-
-/* pt_regs - set by keyboard_interrupt(), used by show_ptregs() */
-static struct pt_regs * pt_regs;
-
-#ifdef CONFIG_MAGIC_SYSRQ
-unsigned char sun_sysrq_xlate[128] =
- "\0\0\0\0\0\201\202\212\203\213\204\214\205\0\206\0" /* 0x00 - 0x0f */
- "\207\210\211\0\0\0\0\0\0\0\0\0\0\03312" /* 0x10 - 0x1f */
- "34567890-=`\177\0=/*" /* 0x20 - 0x2f */
- "\0\0.\0\0\011qwertyuiop" /* 0x30 - 0x3f */
- "[]\177\000789-\0\0\0\0\0asd" /* 0x40 - 0x4f */
- "fghjkl;'\\\015\0154560\0" /* 0x50 - 0x5f */
- "\0\0\0\0zxcvbnm,./\0\012" /* 0x60 - 0x6f */
- "123\0\0\0\0\0\0 \0\0\0\0\0\0"; /* 0x70 - 0x7f */
-#endif
-
-volatile unsigned char sunkbd_layout;
-volatile unsigned char sunkbd_type;
-#define SUNKBD_TYPE2 0x02
-#define SUNKBD_TYPE3 0x03
-#define SUNKBD_TYPE4 0x04
-
-#define SUNKBD_LOUT_TYP4 0x00
-#define SUNKBD_LOUT_TYP5_MASK 0x20
-
-volatile int kbd_reset_pending;
-volatile int kbd_layout_pending;
-
-/* commands */
-#define SKBDCMD_RESET 0x1
-#define SKBDCMD_GLAYOUT 0xf
-#define SKBDCMD_BELLON 0x2
-#define SKBDCMD_BELLOFF 0x3
-#define SKBDCMD_SETLED 0xe
-#define SKBDCMD_NOCLICK 0xb
-#define SKBDCMD_CLICK 0xa
-
-static unsigned char sunkbd_clickp;
-
-/* The led set commands require sending the SETLED byte then
- * a byte encoding which led's to have set. Here are the bit
- * values, a bit set = led-on.
- */
-#define LED_NLOCK 0x1 /* Num-lock */
-#define LED_CMPOSE 0x2 /* Compose */
-#define LED_SCRLCK 0x4 /* Scroll-lock */
-#define LED_CLOCK 0x8 /* Caps-lock */
-
-/* Special state characters */
-#define SKBD_RESET 0xff
-#define SKBD_ALLUP 0x7f
-#define SKBD_LYOUT 0xfe
-
-/* On the Sparc the keyboard could be one of two things.
- * It could be a real keyboard speaking over one of the
- * channels of the second zs8530 chip (other channel is
- * used by the Sun mouse). Else we have serial console
- * going, and thus the other zs8530 chip is who we speak
- * to. Either way, we communicate through the zs8530
- * driver for all our I/O.
- */
-
-#define SUNKBD_UBIT 0x80 /* If set, key went up */
-#define SUNKBD_KMASK 0x7f /* Other bits are the keycode */
-
-#define KEY_LSHIFT 0x81
-#define KEY_RSHIFT 0x82
-#define KEY_CONTROL 0x83
-#define KEY_NILL 0x84
-#define KEY_CAPSLOCK 0x85
-#define KEY_ALT 0x86
-#define KEY_L1 0x87
-
-/* Due to sun_kbd_init() being called before rs_init(), and sun_kbd_init() doing:
- *
- * tasklet_enable(&keyboard_tasklet);
- * tasklet_schedule(&keyboard_tasklet);
- *
- * this might well be called before some driver has claimed interest in
- * handling the keyboard input/output. So we need to assign an initial nop.
- */
-static void nop_kbd_put_char(unsigned char c) { }
-static void (*kbd_put_char)(unsigned char) = nop_kbd_put_char;
-
-/* Must be invoked under sunkbd_lock. */
-static inline void send_cmd(unsigned char c)
-{
- kbd_put_char(c);
-}
-
-/* kbd_bh() calls this to send the SKBDCMD_SETLED to the sun keyboard
- * with the proper bit pattern for the leds to be set. It basically
- * converts the kbd->ledflagstate values to corresponding sun kbd led
- * bit value.
- */
-static inline unsigned char vcleds_to_sunkbd(unsigned char vcleds)
-{
- unsigned char retval = 0;
-
- if(vcleds & (1<<VC_SCROLLOCK))
- retval |= LED_SCRLCK;
- if(vcleds & (1<<VC_NUMLOCK))
- retval |= LED_NLOCK;
- if(vcleds & (1<<VC_CAPSLOCK))
- retval |= LED_CLOCK;
- if(compose_led_on)
- retval |= LED_CMPOSE;
- return retval;
-}
-
-/*
- * Translation of escaped scancodes to keycodes.
- * This is now user-settable.
- * The keycodes 1-88,96-111,119 are fairly standard, and
- * should probably not be changed - changing might confuse X.
- * X also interprets scancode 0x5d (KEY_Begin).
- *
- * For 1-88 keycode equals scancode.
- */
-
-#define E0_KPENTER 96
-#define E0_RCTRL 97
-#define E0_KPSLASH 98
-#define E0_PRSCR 99
-#define E0_RALT 100
-#define E0_BREAK 101 /* (control-pause) */
-#define E0_HOME 102
-#define E0_UP 103
-#define E0_PGUP 104
-#define E0_LEFT 105
-#define E0_RIGHT 106
-#define E0_END 107
-#define E0_DOWN 108
-#define E0_PGDN 109
-#define E0_INS 110
-#define E0_DEL 111
-
-#define E1_PAUSE 119
-
-/*
- * The keycodes below are randomly located in 89-95,112-118,120-127.
- * They could be thrown away (and all occurrences below replaced by 0),
- * but that would force many users to use the `setkeycodes' utility, where
- * they needed not before. It does not matter that there are duplicates, as
- * long as no duplication occurs for any single keyboard.
- */
-#define SC_LIM 89
-
-#define FOCUS_PF1 85 /* actual code! */
-#define FOCUS_PF2 89
-#define FOCUS_PF3 90
-#define FOCUS_PF4 91
-#define FOCUS_PF5 92
-#define FOCUS_PF6 93
-#define FOCUS_PF7 94
-#define FOCUS_PF8 95
-#define FOCUS_PF9 120
-#define FOCUS_PF10 121
-#define FOCUS_PF11 122
-#define FOCUS_PF12 123
-
-#define JAP_86 124
-/* tfj@olivia.ping.dk:
- * The four keys are located over the numeric keypad, and are
- * labelled A1-A4. It's an rc930 keyboard, from
- * Regnecentralen/RC International, Now ICL.
- * Scancodes: 59, 5a, 5b, 5c.
- */
-#define RGN1 124
-#define RGN2 125
-#define RGN3 126
-#define RGN4 127
-
-static unsigned char high_keys[128 - SC_LIM] = {
- RGN1, RGN2, RGN3, RGN4, 0, 0, 0, /* 0x59-0x5f */
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60-0x67 */
- 0, 0, 0, 0, 0, FOCUS_PF11, 0, FOCUS_PF12, /* 0x68-0x6f */
- 0, 0, 0, FOCUS_PF2, FOCUS_PF9, 0, 0, FOCUS_PF3, /* 0x70-0x77 */
- FOCUS_PF4, FOCUS_PF5, FOCUS_PF6, FOCUS_PF7, /* 0x78-0x7b */
- FOCUS_PF8, JAP_86, FOCUS_PF10, 0 /* 0x7c-0x7f */
-};
-
-/* BTC */
-#define E0_MACRO 112
-/* LK450 */
-#define E0_F13 113
-#define E0_F14 114
-#define E0_HELP 115
-#define E0_DO 116
-#define E0_F17 117
-#define E0_KPMINPLUS 118
-/*
- * My OmniKey generates e0 4c for the "OMNI" key and the
- * right alt key does nada. [kkoller@nyx10.cs.du.edu]
- */
-#define E0_OK 124
-/*
- * New microsoft keyboard is rumoured to have
- * e0 5b (left window button), e0 5c (right window button),
- * e0 5d (menu button). [or: LBANNER, RBANNER, RMENU]
- * [or: Windows_L, Windows_R, TaskMan]
- */
-#define E0_MSLW 125
-#define E0_MSRW 126
-#define E0_MSTM 127
-
-static unsigned char e0_keys[128] = {
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00-0x07 */
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0x08-0x0f */
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10-0x17 */
- 0, 0, 0, 0, E0_KPENTER, E0_RCTRL, 0, 0, /* 0x18-0x1f */
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20-0x27 */
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0x28-0x2f */
- 0, 0, 0, 0, 0, E0_KPSLASH, 0, E0_PRSCR, /* 0x30-0x37 */
- E0_RALT, 0, 0, 0, 0, E0_F13, E0_F14, E0_HELP, /* 0x38-0x3f */
- E0_DO, E0_F17, 0, 0, 0, 0, E0_BREAK, E0_HOME, /* 0x40-0x47 */
- E0_UP, E0_PGUP, 0, E0_LEFT, E0_OK, E0_RIGHT, E0_KPMINPLUS, E0_END,/* 0x48-0x4f */
- E0_DOWN, E0_PGDN, E0_INS, E0_DEL, 0, 0, 0, 0, /* 0x50-0x57 */
- 0, 0, 0, E0_MSLW, E0_MSRW, E0_MSTM, 0, 0, /* 0x58-0x5f */
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60-0x67 */
- 0, 0, 0, 0, 0, 0, 0, E0_MACRO, /* 0x68-0x6f */
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70-0x77 */
- 0, 0, 0, 0, 0, 0, 0, 0 /* 0x78-0x7f */
-};
-
-/* we use this map to determine if a particular key should not be
- autorepeated. We don't autorepeat CONTROL, LSHIFT, CAPS,
- ALT, LMETA, RSHIFT, RMETA, ALTG and COMPOSE */
-static unsigned char norepeat_keys[128] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, /* 0x00-0x0f */
- 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10-0x1f */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20-0x2f */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x30-0x3f */
- 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, /* 0x40-0x4f */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50-0x5f */
- 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, /* 0x60-0x6f */
- 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, /* 0x70-0x7f */
-};
-
-
-int sun_setkeycode(unsigned int scancode, unsigned int keycode)
-{
- if (scancode < SC_LIM || scancode > 255 || keycode > 127)
- return -EINVAL;
- if (scancode < 128)
- high_keys[scancode - SC_LIM] = keycode;
- else
- e0_keys[scancode - 128] = keycode;
- return 0;
-}
-
-int sun_getkeycode(unsigned int scancode)
-{
- return
- (scancode < SC_LIM || scancode > 255) ? -EINVAL :
- (scancode < 128) ? high_keys[scancode - SC_LIM] :
- e0_keys[scancode - 128];
-}
-
-static void __sunkbd_inchar(unsigned char ch, struct pt_regs *regs);
-void sunkbd_inchar(unsigned char ch, struct pt_regs *regs);
-static void keyboard_timer (unsigned long ignored);
-
-static struct timer_list
-auto_repeat_timer = { function: keyboard_timer };
-
-/* Keeps track of the last pressed key */
-static unsigned char last_keycode;
-
-static void
-keyboard_timer (unsigned long ignored)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&sunkbd_lock, flags);
-
- /* Auto repeat: send regs = 0 to indicate autorepeat */
- __sunkbd_inchar (last_keycode, 0);
- del_timer (&auto_repeat_timer);
- if (kbd_rate_ticks) {
- auto_repeat_timer.expires = jiffies + kbd_rate_ticks;
- add_timer (&auto_repeat_timer);
- }
-
- spin_unlock_irqrestore(&sunkbd_lock, flags);
-}
-
-#ifndef CONFIG_PCI
-DECLARE_TASKLET_DISABLED(keyboard_tasklet, sun_kbd_bh, 0);
-#endif
-
-/* #define SKBD_DEBUG */
-/* This is our keyboard 'interrupt' routine.
- * Must run under sunkbd_lock.
- */
-static void __sunkbd_inchar(unsigned char ch, struct pt_regs *regs)
-{
- unsigned char keycode;
- char up_flag; /* 0 or SUNKBD_UBIT */
- char raw_mode;
-
- if(ch == SKBD_RESET) {
- kbd_reset_pending = 1;
- goto out;
- }
- if(ch == SKBD_LYOUT) {
- kbd_layout_pending = 1;
- goto out;
- }
- if(kbd_reset_pending) {
- sunkbd_type = ch;
- kbd_reset_pending = 0;
- if(ch == SUNKBD_TYPE4)
- send_cmd(SKBDCMD_GLAYOUT);
- goto out;
- } else if(kbd_layout_pending) {
- sunkbd_layout = ch;
- kbd_layout_pending = 0;
- goto out;
- } else if(ch == SKBD_ALLUP) {
- del_timer (&auto_repeat_timer);
- memset(key_down, 0, sizeof(key_down));
- sun_compute_shiftstate();
- goto out;
- }
-#ifdef SKBD_DEBUG
- if(ch == 0x7f)
- printk("KBD<ALL KEYS UP>");
- else
- printk("KBD<%x %s>", ch,
- ((ch&0x80) ? "UP" : "DOWN"));
-#endif
-
- /* Whee, a real character. */
- if(regs) {
- pt_regs = regs;
- last_keycode = keycode = ch;
- } else {
- keycode = ch;
- }
-
- do_poke_blanked_console = 1;
- schedule_console_callback();
- add_keyboard_randomness(keycode);
-
- tty = ttytab? ttytab[fg_console]: NULL;
- if (tty && (!tty->driver_data)) {
- /* This is to workaround ugly bug in tty_io.c, which
- does not do locking when it should */
- tty = NULL;
- }
- kbd = kbd_table + fg_console;
- if((raw_mode = (kbd->kbdmode == VC_RAW))) {
- if (kbd_redirected == fg_console+1)
- push_kbd (keycode);
- else
- put_queue(keycode);
- /* we do not return yet, because we want to maintain
- * the key_down array, so that we have the correct
- * values when finishing RAW mode or when changing VT's.
- */
- }
- up_flag = (keycode & SUNKBD_UBIT); /* The 'up' bit */
- keycode &= SUNKBD_KMASK; /* all the rest */
- del_timer (&auto_repeat_timer);
- if(up_flag) {
- rep = 0;
- clear_bit(keycode, key_down);
- } else {
- if (!norepeat_keys[keycode]) {
- if (kbd_rate_ticks) {
- auto_repeat_timer.expires =
- jiffies + kbd_delay_ticks;
- add_timer (&auto_repeat_timer);
- }
- }
- rep = test_and_set_bit(keycode, key_down);
- }
-
-#ifdef CONFIG_MAGIC_SYSRQ /* Handle the SysRq hack */
- if (l1a_state.l1_down) {
- if (!up_flag)
- handle_sysrq(sun_sysrq_xlate[keycode], pt_regs, tty);
- goto out;
- }
-#endif
-
- if(raw_mode)
- goto out;
-
- if(kbd->kbdmode == VC_MEDIUMRAW) {
- put_queue(keycode + up_flag);
- goto out;
- }
-
- /*
- * Small change in philosophy: earlier we defined repetition by
- * rep = keycode == prev_keycode;
- * prev_keycode = keycode;
- * but now by the fact that the depressed key was down already.
- * Does this ever make a difference? Yes.
- */
-
- /*
- * Repeat a key only if the input buffers are empty or the
- * characters get echoed locally. This makes key repeat usable
- * with slow applications and under heavy loads.
- */
- if (!rep ||
- (vc_kbd_mode(kbd,VC_REPEAT) && tty &&
- (L_ECHO(tty) || (tty->driver.chars_in_buffer(tty) == 0)))) {
- u_short keysym;
- u_char type;
-
- /* the XOR below used to be an OR */
- int shift_final = shift_state ^ kbd->lockstate ^ kbd->slockstate;
- ushort *key_map = key_maps[shift_final];
-
- if (key_map != NULL) {
- keysym = key_map[keycode];
- type = KTYP(keysym);
-
- if (type >= 0xf0) {
- type -= 0xf0;
- if (type == KT_LETTER) {
- type = KT_LATIN;
- if (vc_kbd_led(kbd, VC_CAPSLOCK)) {
- key_map = key_maps[shift_final ^ (1<<KG_SHIFT)];
- if (key_map)
- keysym = key_map[keycode];
- }
- }
- (*key_handler[type])(keysym & 0xff, up_flag);
- if (type != KT_SLOCK)
- kbd->slockstate = 0;
- }
- } else {
- /* maybe beep? */
- /* we have at least to update shift_state */
- sun_compute_shiftstate();
- }
- }
-out:
- tasklet_schedule(&keyboard_tasklet);
-}
-
-void sunkbd_inchar(unsigned char ch, struct pt_regs *regs)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&sunkbd_lock, flags);
- __sunkbd_inchar(ch, regs);
- spin_unlock_irqrestore(&sunkbd_lock, flags);
-}
-
-static void put_queue(int ch)
-{
- if (tty) {
- tty_insert_flip_char(tty, ch, 0);
- con_schedule_flip(tty);
- }
-}
-
-static void puts_queue(char *cp)
-{
- if (!tty)
- return;
-
- while (*cp) {
- tty_insert_flip_char(tty, *cp, 0);
- cp++;
- }
- con_schedule_flip(tty);
-}
-
-static void applkey(int key, char mode)
-{
- static char buf[] = { 0x1b, 'O', 0x00, 0x00 };
-
- buf[1] = (mode ? 'O' : '[');
- buf[2] = key;
- puts_queue(buf);
-}
-
-static void enter(void)
-{
- put_queue(13);
- if (vc_kbd_mode(kbd,VC_CRLF))
- put_queue(10);
-}
-
-static void caps_toggle(void)
-{
- if (rep)
- return;
- chg_vc_kbd_led(kbd, VC_CAPSLOCK);
-}
-
-static void caps_on(void)
-{
- if (rep)
- return;
- set_vc_kbd_led(kbd, VC_CAPSLOCK);
-}
-
-static void show_ptregs(void)
-{
- if (pt_regs)
- show_regs(pt_regs);
-}
-
-static void hold(void)
-{
- if (rep || !tty)
- return;
-
- /*
- * Note: SCROLLOCK will be set (cleared) by stop_tty (start_tty);
- * these routines are also activated by ^S/^Q.
- * (And SCROLLOCK can also be set by the ioctl KDSKBLED.)
- */
- if (tty->stopped)
- start_tty(tty);
- else
- stop_tty(tty);
-}
-
-static void num(void)
-{
- if (vc_kbd_mode(kbd,VC_APPLIC))
- applkey('P', 1);
- else
- bare_num();
-}
-
-/*
- * Bind this to Shift-NumLock if you work in application keypad mode
- * but want to be able to change the NumLock flag.
- * Bind this to NumLock if you prefer that the NumLock key always
- * changes the NumLock flag.
- */
-static void bare_num(void)
-{
- if (!rep)
- chg_vc_kbd_led(kbd,VC_NUMLOCK);
-}
-
-static void lastcons(void)
-{
- /* switch to the last used console, ChN */
- set_console(last_console);
-}
-
-static void decr_console(void)
-{
- int i;
-
- for (i = fg_console-1; i != fg_console; i--) {
- if (i == -1)
- i = MAX_NR_CONSOLES-1;
- if (vc_cons_allocated(i))
- break;
- }
- set_console(i);
-}
-
-static void incr_console(void)
-{
- int i;
-
- for (i = fg_console+1; i != fg_console; i++) {
- if (i == MAX_NR_CONSOLES)
- i = 0;
- if (vc_cons_allocated(i))
- break;
- }
- set_console(i);
-}
-
-static void send_intr(void)
-{
- if (!tty)
- return;
- tty_insert_flip_char(tty, 0, TTY_BREAK);
- con_schedule_flip(tty);
-}
-
-static void scroll_forw(void)
-{
- scrollfront(0);
-}
-
-static void scroll_back(void)
-{
- scrollback(0);
-}
-
-static void boot_it(void)
-{
- extern int obp_system_intr(void);
-
- if (!obp_system_intr())
- ctrl_alt_del();
- /* sigh.. attempt to prevent multiple entry */
- last_keycode=1;
- rep = 0;
-}
-
-static void compose(void)
-{
- dead_key_next = 1;
- compose_led_on = 1;
- set_leds();
-}
-
-#ifdef CONFIG_PCI
-extern int spawnpid, spawnsig;
-#else
-int spawnpid, spawnsig;
-#endif
-
-
-static void spawn_console(void)
-{
- if (spawnpid)
- if(kill_proc(spawnpid, spawnsig, 1))
- spawnpid = 0;
-}
-
-static void SAK(void)
-{
- do_SAK(tty);
-#if 0
- /*
- * Need to fix SAK handling to fix up RAW/MEDIUM_RAW and
- * vt_cons modes before we can enable RAW/MEDIUM_RAW SAK
- * handling.
- *
- * We should do this some day --- the whole point of a secure
- * attention key is that it should be guaranteed to always
- * work.
- */
- reset_vc(fg_console);
- do_unblank_screen(); /* not in interrupt routine? */
-#endif
-}
-
-static void do_ignore(unsigned char value, char up_flag)
-{
-}
-
-static void do_null()
-{
- sun_compute_shiftstate();
-}
-
-static void do_spec(unsigned char value, char up_flag)
-{
- if (up_flag)
- return;
- if (value >= SIZE(spec_fn_table))
- return;
- spec_fn_table[value]();
-}
-
-static void do_lowercase(unsigned char value, char up_flag)
-{
- printk("keyboard.c: do_lowercase was called - impossible\n");
-}
-
-static void do_self(unsigned char value, char up_flag)
-{
- if (up_flag)
- return; /* no action, if this is a key release */
-
- if (diacr) {
- value = handle_diacr(value);
- compose_led_on = 0;
- set_leds();
- }
-
- if (dead_key_next) {
- dead_key_next = 0;
- diacr = value;
- return;
- }
-
- put_queue(value);
-}
-
-#define A_GRAVE '`'
-#define A_ACUTE '\''
-#define A_CFLEX '^'
-#define A_TILDE '~'
-#define A_DIAER '"'
-#define A_CEDIL ','
-static unsigned char ret_diacr[NR_DEAD] =
- {A_GRAVE, A_ACUTE, A_CFLEX, A_TILDE, A_DIAER, A_CEDIL };
-
-/* If a dead key pressed twice, output a character corresponding to it, */
-/* otherwise just remember the dead key. */
-
-static void do_dead(unsigned char value, char up_flag)
-{
- if (up_flag)
- return;
-
- value = ret_diacr[value];
- if (diacr == value) { /* pressed twice */
- diacr = 0;
- put_queue(value);
- return;
- }
- diacr = value;
-}
-
-
-/* If space is pressed, return the character corresponding the pending */
-/* dead key, otherwise try to combine the two. */
-
-unsigned char handle_diacr(unsigned char ch)
-{
- int d = diacr;
- int i;
-
- diacr = 0;
- if (ch == ' ')
- return d;
-
- for (i = 0; i < accent_table_size; i++) {
- if (accent_table[i].diacr == d && accent_table[i].base == ch)
- return accent_table[i].result;
- }
-
- put_queue(d);
- return ch;
-}
-
-static void do_cons(unsigned char value, char up_flag)
-{
- if (up_flag)
- return;
- set_console(value);
-}
-
-static void do_fn(unsigned char value, char up_flag)
-{
- if (up_flag)
- return;
- if (value < SIZE(func_table)) {
- if (func_table[value])
- puts_queue(func_table[value]);
- } else
- printk("do_fn called with value=%d\n", value);
-}
-
-static void do_pad(unsigned char value, char up_flag)
-{
- static const char *pad_chars = "0123456789+-*/\015,.?";
- static const char *app_map = "pqrstuvwxylSRQMnn?";
-
- if (up_flag)
- return; /* no action, if this is a key release */
-
- /* kludge... shift forces cursor/number keys */
- if (vc_kbd_mode(kbd,VC_APPLIC) && !k_down[KG_SHIFT]) {
- applkey(app_map[value], 1);
- return;
- }
-
- if (!vc_kbd_led(kbd,VC_NUMLOCK))
- switch (value) {
- case KVAL(K_PCOMMA):
- case KVAL(K_PDOT):
- do_fn(KVAL(K_REMOVE), 0);
- return;
- case KVAL(K_P0):
- do_fn(KVAL(K_INSERT), 0);
- return;
- case KVAL(K_P1):
- do_fn(KVAL(K_SELECT), 0);
- return;
- case KVAL(K_P2):
- do_cur(KVAL(K_DOWN), 0);
- return;
- case KVAL(K_P3):
- do_fn(KVAL(K_PGDN), 0);
- return;
- case KVAL(K_P4):
- do_cur(KVAL(K_LEFT), 0);
- return;
- case KVAL(K_P6):
- do_cur(KVAL(K_RIGHT), 0);
- return;
- case KVAL(K_P7):
- do_fn(KVAL(K_FIND), 0);
- return;
- case KVAL(K_P8):
- do_cur(KVAL(K_UP), 0);
- return;
- case KVAL(K_P9):
- do_fn(KVAL(K_PGUP), 0);
- return;
- case KVAL(K_P5):
- applkey('G', vc_kbd_mode(kbd, VC_APPLIC));
- return;
- }
-
- put_queue(pad_chars[value]);
- if (value == KVAL(K_PENTER) && vc_kbd_mode(kbd, VC_CRLF))
- put_queue(10);
-}
-
-static void do_cur(unsigned char value, char up_flag)
-{
- static const char *cur_chars = "BDCA";
- if (up_flag)
- return;
-
- applkey(cur_chars[value], vc_kbd_mode(kbd,VC_CKMODE));
-}
-
-static void do_shift(unsigned char value, char up_flag)
-{
- int old_state = shift_state;
-
- if (rep)
- return;
-
- /* Mimic typewriter:
- a CapsShift key acts like Shift but undoes CapsLock */
- if (value == KVAL(K_CAPSSHIFT)) {
- value = KVAL(K_SHIFT);
- if (!up_flag)
- clr_vc_kbd_led(kbd, VC_CAPSLOCK);
- }
-
- if (up_flag) {
- /* handle the case that two shift or control
- keys are depressed simultaneously */
- if (k_down[value])
- k_down[value]--;
- } else
- k_down[value]++;
-
- if (k_down[value])
- shift_state |= (1 << value);
- else
- shift_state &= ~ (1 << value);
-
- /* kludge, no joke... */
- if (up_flag && shift_state != old_state && npadch != -1) {
- put_queue(npadch & 0xff);
- npadch = -1;
- }
-}
-
-/* called after returning from RAW mode or when changing consoles -
- recompute k_down[] and shift_state from key_down[] */
-/* maybe called when keymap is undefined, so that shiftkey release is seen */
-void sun_compute_shiftstate(void)
-{
- int i, j, k, sym, val;
-
- shift_state = 0;
- for(i=0; i < SIZE(k_down); i++)
- k_down[i] = 0;
-
- for(i=0; i < SIZE(key_down); i++)
- if(key_down[i]) { /* skip this word if not a single bit on */
- k = i*BITS_PER_LONG;
- for(j=0; j<BITS_PER_LONG; j++,k++)
- if(test_bit(k, key_down)) {
- sym = U(plain_map[k]);
- if(KTYP(sym) == KT_SHIFT) {
- val = KVAL(sym);
- if (val == KVAL(K_CAPSSHIFT))
- val = KVAL(K_SHIFT);
- k_down[val]++;
- shift_state |= (1<<val);
- }
- }
- }
-}
-
-static void do_meta(unsigned char value, char up_flag)
-{
- if (up_flag)
- return;
-
- if (vc_kbd_mode(kbd, VC_META)) {
- put_queue('\033');
- put_queue(value);
- } else
- put_queue(value | 0x80);
-}
-
-static void do_ascii(unsigned char value, char up_flag)
-{
- int base;
-
- if (up_flag)
- return;
-
- if (value < 10) /* decimal input of code, while Alt depressed */
- base = 10;
- else { /* hexadecimal input of code, while AltGr depressed */
- value -= 10;
- base = 16;
- }
-
- if (npadch == -1)
- npadch = value;
- else
- npadch = npadch * base + value;
-}
-
-static void do_lock(unsigned char value, char up_flag)
-{
- if (up_flag || rep)
- return;
- chg_vc_kbd_lock(kbd, value);
-}
-
-/*
- * The leds display either (i) the status of NumLock, CapsLock, ScrollLock,
- * or (ii) whatever pattern of lights people want to show using KDSETLED,
- * or (iii) specified bits of specified words in kernel memory.
- */
-
-static unsigned char ledstate = 0xff; /* undefined */
-static unsigned char ledioctl;
-
-unsigned char sun_getledstate(void) {
- return ledstate;
-}
-
-void sun_setledstate(struct kbd_struct *kbd, unsigned int led) {
- if (!(led & ~7)) {
- ledioctl = led;
- kbd->ledmode = LED_SHOW_IOCTL;
- } else
- kbd->ledmode = LED_SHOW_FLAGS;
- set_leds();
-}
-
-static struct ledptr {
- unsigned int *addr;
- unsigned int mask;
- unsigned char valid:1;
-} ledptrs[3];
-
-void register_leds(int console, unsigned int led,
- unsigned int *addr, unsigned int mask) {
- struct kbd_struct *kbd = kbd_table + console;
- if (led < 3) {
- ledptrs[led].addr = addr;
- ledptrs[led].mask = mask;
- ledptrs[led].valid = 1;
- kbd->ledmode = LED_SHOW_MEM;
- } else
- kbd->ledmode = LED_SHOW_FLAGS;
-}
-
-static inline unsigned char getleds(void){
- struct kbd_struct *kbd = kbd_table + fg_console;
- unsigned char leds;
-
- if (kbd->ledmode == LED_SHOW_IOCTL)
- return ledioctl;
- leds = kbd->ledflagstate;
- if (kbd->ledmode == LED_SHOW_MEM) {
- if (ledptrs[0].valid) {
- if (*ledptrs[0].addr & ledptrs[0].mask)
- leds |= 1;
- else
- leds &= ~1;
- }
- if (ledptrs[1].valid) {
- if (*ledptrs[1].addr & ledptrs[1].mask)
- leds |= 2;
- else
- leds &= ~2;
- }
- if (ledptrs[2].valid) {
- if (*ledptrs[2].addr & ledptrs[2].mask)
- leds |= 4;
- else
- leds &= ~4;
- }
- }
- return leds;
-}
-
-/*
- * This routine is the bottom half of the keyboard interrupt
- * routine, and runs with all interrupts enabled. It does
- * console changing, led setting and copy_to_cooked, which can
- * take a reasonably long time.
- *
- * Aside from timing (which isn't really that important for
- * keyboard interrupts as they happen often), using the software
- * interrupt routines for this thing allows us to easily mask
- * this when we don't want any of the above to happen. Not yet
- * used, but this allows for easy and efficient race-condition
- * prevention later on.
- */
-static unsigned char sunkbd_ledstate = 0xff; /* undefined */
-void sun_kbd_bh(unsigned long dummy)
-{
- unsigned long flags;
- unsigned char leds, kbd_leds;
-
- spin_lock_irqsave(&sunkbd_lock, flags);
-
- leds = getleds();
- kbd_leds = vcleds_to_sunkbd(leds);
- if (kbd_leds != sunkbd_ledstate) {
- ledstate = leds;
- sunkbd_ledstate = kbd_leds;
- send_cmd(SKBDCMD_SETLED);
- send_cmd(kbd_leds);
- }
-
- spin_unlock_irqrestore(&sunkbd_lock, flags);
-}
-
-/* Support for keyboard "beeps". */
-
-/* Timer routine to turn off the beep after the interval expires. */
-static void sunkbd_kd_nosound(unsigned long __unused)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&sunkbd_lock, flags);
- send_cmd(SKBDCMD_BELLOFF);
- spin_unlock_irqrestore(&sunkbd_lock, flags);
-}
-
-/*
- * Initiate a keyboard beep. If the frequency is zero, then we stop
- * the beep. Any other frequency will start a monotone beep. The beep
- * will be stopped by a timer after "ticks" jiffies. If ticks is 0,
- * then we do not start a timer.
- */
-static void sunkbd_kd_mksound(unsigned int hz, unsigned int ticks)
-{
- unsigned long flags;
- static struct timer_list sound_timer = { function: sunkbd_kd_nosound };
-
- spin_lock_irqsave(&sunkbd_lock, flags);
-
- del_timer(&sound_timer);
-
- if (hz) {
- send_cmd(SKBDCMD_BELLON);
- if (ticks) {
- sound_timer.expires = jiffies + ticks;
- add_timer(&sound_timer);
- }
- } else
- send_cmd(SKBDCMD_BELLOFF);
-
- spin_unlock_irqrestore(&sunkbd_lock, flags);
-}
-
-extern void (*kd_mksound)(unsigned int hz, unsigned int ticks);
-
-int __init sun_kbd_init(void)
-{
- int i, opt_node;
- struct kbd_struct kbd0;
- extern struct tty_driver console_driver;
-
- kbd0.ledflagstate = kbd0.default_ledflagstate = KBD_DEFLEDS;
- kbd0.ledmode = LED_SHOW_FLAGS;
- kbd0.lockstate = KBD_DEFLOCK;
- kbd0.slockstate = 0;
- kbd0.modeflags = KBD_DEFMODE;
- kbd0.kbdmode = VC_XLATE;
-
- for (i = 0 ; i < MAX_NR_CONSOLES ; i++)
- kbd_table[i] = kbd0;
-
- ttytab = console_driver.table;
-
- kd_mksound = sunkbd_kd_mksound;
-
- /* XXX Check keyboard-click? property in 'options' PROM node XXX */
- if(sparc_cpu_model != sun4) {
- opt_node = prom_getchild(prom_root_node);
- opt_node = prom_searchsiblings(opt_node, "options");
- i = prom_getintdefault(opt_node, "keyboard-click?", -1);
- if(i != -1)
- sunkbd_clickp = 1;
- else
- sunkbd_clickp = 0;
- } else {
- sunkbd_clickp = 0;
- }
-
- keyboard_tasklet.func = sun_kbd_bh;
-
- tasklet_enable(&keyboard_tasklet);
- tasklet_schedule(&keyboard_tasklet);
-
- return 0;
-}
-
-/* /dev/kbd support */
-
-#define KBD_QSIZE 32
-static Firm_event kbd_queue [KBD_QSIZE];
-static int kbd_head, kbd_tail;
-static spinlock_t kbd_queue_lock = SPIN_LOCK_UNLOCKED;
-char kbd_opened;
-static int kbd_active = 0;
-static DECLARE_WAIT_QUEUE_HEAD(kbd_wait);
-static struct fasync_struct *kb_fasync;
-
-void
-push_kbd (int scan)
-{
- unsigned long flags;
- int next;
-
- if (scan == KBD_IDLE)
- return;
-
- spin_lock_irqsave(&kbd_queue_lock, flags);
- next = (kbd_head + 1) % KBD_QSIZE;
- if (next != kbd_tail){
- kbd_queue [kbd_head].id = scan & KBD_KEYMASK;
- kbd_queue [kbd_head].value=scan & KBD_UP ? VKEY_UP : VKEY_DOWN;
- kbd_queue [kbd_head].time = xtime;
- kbd_head = next;
- }
- spin_unlock_irqrestore(&kbd_queue_lock, flags);
-
- kill_fasync (&kb_fasync, SIGIO, POLL_IN);
- wake_up_interruptible (&kbd_wait);
-}
-
-static ssize_t
-kbd_read (struct file *f, char *buffer, size_t count, loff_t *ppos)
-{
- DECLARE_WAITQUEUE(wait, current);
- unsigned long flags;
- char *end, *p;
-
- /* Return EWOULDBLOCK, because this is what the X server expects */
- if (kbd_head == kbd_tail){
- if (f->f_flags & O_NONBLOCK)
- return -EWOULDBLOCK;
- add_wait_queue (&kbd_wait, &wait);
-repeat:
- set_current_state(TASK_INTERRUPTIBLE);
- if (kbd_head == kbd_tail && !signal_pending(current)) {
- schedule();
- goto repeat;
- }
- current->state = TASK_RUNNING;
- remove_wait_queue (&kbd_wait, &wait);
- }
- /* There is data in the keyboard, fill the user buffer */
- end = buffer+count;
- p = buffer;
- spin_lock_irqsave(&kbd_queue_lock, flags);
- for (; p < end && kbd_head != kbd_tail;){
- Firm_event this_event = kbd_queue[kbd_tail];
-
- kbd_tail = (kbd_tail + 1) % KBD_QSIZE;
-
- spin_unlock_irqrestore(&kbd_queue_lock, flags);
-
-#ifdef CONFIG_SPARC32_COMPAT
- if (test_thread_flag(TIF_32BIT)) {
- if (copy_to_user((Firm_event *)p, &this_event,
- sizeof(Firm_event)-sizeof(struct timeval)))
- return -EFAULT;
- p += sizeof(Firm_event)-sizeof(struct timeval);
- if (__put_user(this_event.time.tv_sec, (u32 *)p))
- return -EFAULT;
- p += sizeof(u32);
- if (__put_user(this_event.time.tv_usec, (u32 *)p))
- return -EFAULT;
- p += sizeof(u32);
- } else
-#endif
- {
- if (copy_to_user((Firm_event *)p, &this_event,
- sizeof(Firm_event)))
- return -EFAULT;
- p += sizeof (Firm_event);
- }
-#ifdef KBD_DEBUG
- printk ("[%s]", this_event.value == VKEY_UP ? "UP" : "DOWN");
-#endif
-
- spin_lock_irqsave(&kbd_queue_lock, flags);
- }
-
- spin_unlock_irqrestore(&kbd_queue_lock, flags);
-
- return p-buffer;
-}
-
-/* Needed by X */
-static int kbd_fasync (int fd, struct file *filp, int on)
-{
- int retval;
-
- retval = fasync_helper (fd, filp, on, &kb_fasync);
- if (retval < 0)
- return retval;
- return 0;
-}
-
-static unsigned int kbd_poll (struct file *f, poll_table *wait)
-{
- poll_wait(f, &kbd_wait, wait);
- if (kbd_head != kbd_tail)
- return POLLIN | POLLRDNORM;
- return 0;
-}
-
-static int
-kbd_ioctl (struct inode *i, struct file *f, unsigned int cmd, unsigned long arg)
-{
- unsigned char c;
- unsigned char leds = 0;
- int value;
-
- switch (cmd){
- case KIOCTYPE: /* return keyboard type */
- if (put_user(sunkbd_type, (int *) arg))
- return -EFAULT;
- break;
- case KIOCGTRANS:
- if (put_user(TR_UNTRANS_EVENT, (int *) arg))
- return -EFAULT;
- break;
- case KIOCTRANS:
- if (get_user(value, (int *) arg))
- return -EFAULT;
- if (value != TR_UNTRANS_EVENT)
- return -EINVAL;
- break;
- case KIOCLAYOUT:
- if (put_user(sunkbd_layout, (int *) arg))
- return -EFAULT;
- break;
- case KIOCSDIRECT:
-#ifndef CODING_NEW_DRIVER
- if (get_user(value, (int *) arg))
- return -EFAULT;
- if(value)
- kbd_redirected = fg_console + 1;
- else
- kbd_redirected = 0;
- kbd_table [fg_console].kbdmode = kbd_redirected ? VC_RAW : VC_XLATE;
-#endif
- break;
- case KIOCCMD:
- if (get_user(value, (int *) arg))
- return -EFAULT;
- c = (unsigned char) value;
- switch (c) {
- case SKBDCMD_CLICK:
- case SKBDCMD_NOCLICK:
- spin_lock_irq(&sunkbd_lock);
- send_cmd(c);
- spin_unlock_irq(&sunkbd_lock);
- return 0;
- case SKBDCMD_BELLON:
- kd_mksound(1,0);
- return 0;
- case SKBDCMD_BELLOFF:
- kd_mksound(0,0);
- return 0;
- default:
- return -EINVAL;
- }
- case KIOCSLED:
- if (get_user(c, (unsigned char *) arg))
- return -EFAULT;
-
- if (c & LED_SCRLCK) leds |= (1 << VC_SCROLLOCK);
- if (c & LED_NLOCK) leds |= (1 << VC_NUMLOCK);
- if (c & LED_CLOCK) leds |= (1 << VC_CAPSLOCK);
- compose_led_on = !!(c & LED_CMPOSE);
- sun_setledstate(kbd_table + fg_console, leds);
- break;
- case KIOCGLED:
- if (put_user(vcleds_to_sunkbd(getleds()), (unsigned char *) arg))
- return -EFAULT;
- break;
- case KIOCGRATE:
- {
- struct kbd_rate rate;
-
- rate.delay = kbd_delay_ticks;
- if (kbd_rate_ticks)
- rate.rate = HZ / kbd_rate_ticks;
- else
- rate.rate = 0;
-
- if (copy_to_user((struct kbd_rate *)arg, &rate,
- sizeof(struct kbd_rate)))
- return -EFAULT;
-
- return 0;
- }
- case KIOCSRATE:
- {
- struct kbd_rate rate;
-
- if (verify_area(VERIFY_READ, (void *)arg,
- sizeof(struct kbd_rate)))
- return -EFAULT;
- copy_from_user(&rate, (struct kbd_rate *)arg,
- sizeof(struct kbd_rate));
-
- if (rate.rate > 50)
- return -EINVAL;
- if (rate.rate == 0)
- kbd_rate_ticks = 0;
- else
- kbd_rate_ticks = HZ / rate.rate;
- kbd_delay_ticks = rate.delay;
-
- return 0;
- }
- case FIONREAD: /* return number of bytes in kbd queue */
- {
- int count;
-
- count = kbd_head - kbd_tail;
- if (put_user((count < 0) ? KBD_QSIZE - count : count, (int *) arg))
- return -EFAULT;
- return 0;
- }
- default:
- printk ("Unknown Keyboard ioctl: %8.8x\n", cmd);
- return -EINVAL;
- }
- return 0;
-}
-
-static int
-kbd_open (struct inode *i, struct file *f)
-{
- spin_lock_irq(&kbd_queue_lock);
- kbd_active++;
-
- if (kbd_opened)
- goto out;
-
- kbd_opened = fg_console + 1;
-
- kbd_head = kbd_tail = 0;
-
- out:
- spin_unlock_irq(&kbd_queue_lock);
-
- return 0;
-}
-
-static int
-kbd_close (struct inode *i, struct file *f)
-{
- spin_lock_irq(&kbd_queue_lock);
- if (!--kbd_active) {
- if (kbd_redirected)
- kbd_table [kbd_redirected-1].kbdmode = VC_XLATE;
- kbd_redirected = 0;
- kbd_opened = 0;
- kbd_fasync (-1, f, 0);
- }
- spin_unlock_irq(&kbd_queue_lock);
-
- return 0;
-}
-
-static struct file_operations kbd_fops =
-{
- .read = kbd_read,
- .poll = kbd_poll,
- .ioctl = kbd_ioctl,
- .open = kbd_open,
- .release = kbd_close,
- .fasync = kbd_fasync,
-};
-
-void __init keyboard_zsinit(void (*put_char)(unsigned char))
-{
- int timeout = 0;
-
- kbd_put_char = put_char;
- if (!kbd_put_char)
- panic("keyboard_zsinit: no put_char parameter");
-
- /* Test out the leds */
- sunkbd_type = 255;
- sunkbd_layout = 0;
-
- send_cmd(SKBDCMD_RESET);
- send_cmd(SKBDCMD_RESET);
- while((sunkbd_type==255) && timeout++ < 25000) {
- udelay(100);
- barrier();
- }
-
- if(timeout>=25000) {
- printk("keyboard: not present\n");
- return;
- }
-
- if(sunkbd_type != SUNKBD_TYPE4) {
- printk("Sun TYPE %d keyboard detected ", sunkbd_type);
- } else {
- timeout=0;
- while((sunkbd_layout==0) && timeout++ < 10000) {
- udelay(100);
- barrier();
- }
- printk("Sun TYPE %d keyboard detected ",
- ((sunkbd_layout & SUNKBD_LOUT_TYP5_MASK) ? 5 : 4));
- }
- if(sunkbd_type == SUNKBD_TYPE2)
- sunkbd_clickp = 0;
-
- spin_lock_irq(&sunkbd_lock);
-
- if(sunkbd_clickp) {
- send_cmd(SKBDCMD_CLICK);
- printk("with keyclick\n");
- } else {
- send_cmd(SKBDCMD_NOCLICK);
- printk("without keyclick\n");
- }
-
- /* Dork with led lights, then turn them all off */
- send_cmd(SKBDCMD_SETLED); send_cmd(0xf); /* All on */
- send_cmd(SKBDCMD_SETLED); send_cmd(0x0); /* All off */
-
- spin_unlock_irq(&sunkbd_lock);
-
- /* Register the /dev/kbd interface */
- devfs_register (NULL, "kbd", DEVFS_FL_DEFAULT,
- KBD_MAJOR, 0,
- S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH,
- &kbd_fops, NULL);
- if (devfs_register_chrdev (KBD_MAJOR, "kbd", &kbd_fops)){
- printk ("Could not register /dev/kbd device\n");
- return;
- }
- return;
-}
+++ /dev/null
-/* $Id: sunkbd.h,v 1.4 2000/02/09 11:15:54 davem Exp $
- * sunkbd.h: Defines needed by SUN Keyboard drivers
- *
- * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
- */
-
-#ifndef _SPARC_SUNKBD_H
-#define _SPARC_SUNKBD_H 1
-
-#include <linux/config.h>
-
-/* Keyboard defines for L1-A processing... */
-#define SUNKBD_RESET 0xff
-#define SUNKBD_L1 0x01
-#define SUNKBD_UP 0x80
-#define SUNKBD_A 0x4d
-
-struct l1a_kbd_state {
- int kbd_id;
- int l1_down;
-};
-
-extern struct l1a_kbd_state l1a_state;
-
-extern void keyboard_zsinit(void (*kbd_put_char)(unsigned char));
-extern void sunkbd_inchar(unsigned char, struct pt_regs *);
-extern void batten_down_hatches(void);
-
-extern void sun_kbd_bh(unsigned long);
-extern int sun_kbd_init(void);
-extern void sun_compute_shiftstate(void);
-extern void sun_setledstate(struct kbd_struct *, unsigned int);
-extern unsigned char sun_getledstate(void);
-extern int sun_setkeycode(unsigned int, unsigned int);
-extern int sun_getkeycode(unsigned int);
-
-#ifdef CONFIG_PCI
-
-extern ushort *sun_key_maps[MAX_NR_KEYMAPS];
-extern unsigned int sun_keymap_count;
-
-extern char sun_func_buf[];
-extern char *sun_func_table[MAX_NR_FUNC];
-extern int sun_funcbufsize;
-extern int sun_funcbufleft;
-
-extern struct kbdiacr sun_accent_table[MAX_DIACR];
-extern unsigned int sun_accent_table_size;
-
-#endif /* CONFIG_PCI */
-
-#endif /* !(_SPARC_SUNKBD_H) */
+++ /dev/null
-/* sunmouse.c: Sun mouse driver for the Sparc
- *
- * Copyright (C) 1995, 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
- * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
- *
- * Parts based on the psaux.c driver written by:
- * Johan Myreen.
- *
- * Dec/19/95 Added SunOS mouse ioctls - miguel.
- * Jan/5/96 Added VUID support, sigio support - miguel.
- * Mar/5/96 Added proper mouse stream support - miguel.
- * Sep/96 Allow more than one reader -miguel.
- * Aug/97 Added PCI 8042 controller support -DaveM
- */
-
-/* The mouse is run off of one of the Zilog serial ports. On
- * that port is the mouse and the keyboard, each gets a zs channel.
- * The mouse itself is mouse-systems in nature. So the protocol is:
- *
- * Byte 1) Button state which is bit-encoded as
- * 0x4 == left-button down, else up
- * 0x2 == middle-button down, else up
- * 0x1 == right-button down, else up
- *
- * Byte 2) Delta-x
- * Byte 3) Delta-y
- * Byte 4) Delta-x again
- * Byte 5) Delta-y again
- *
- * One day this driver will have to support more than one mouse in the system.
- *
- * This driver has two modes of operation: the default VUID_NATIVE is
- * set when the device is opened and allows the application to see the
- * mouse character stream as we get it from the serial (for gpm for
- * example). The second method, VUID_FIRM_EVENT will provide cooked
- * events in Firm_event records as expected by SunOS/Solaris applications.
- *
- * FIXME: We need to support more than one mouse.
- * */
-
-#include <linux/config.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/fcntl.h>
-#include <linux/signal.h>
-#include <linux/timer.h>
-#include <linux/errno.h>
-#include <linux/miscdevice.h>
-#include <linux/mm.h>
-#include <linux/poll.h>
-#include <linux/spinlock.h>
-#include <linux/smp_lock.h>
-#include <linux/init.h>
-#include <asm/uaccess.h>
-#include <asm/system.h>
-#include <asm/vuid_event.h>
-#include <linux/random.h>
-/* The following keeps track of software state for the Sun
- * mouse.
- */
-#define STREAM_SIZE 2048
-#define EV_SIZE (STREAM_SIZE/sizeof (Firm_event))
-#define BUTTON_LEFT 4
-#define BUTTON_MIDDLE 2
-#define BUTTON_RIGHT 1
-
-struct sun_mouse {
- unsigned char transaction[5]; /* Each protocol transaction */
- unsigned char byte; /* Counter, starts at 0 */
- unsigned char button_state; /* Current button state */
- unsigned char prev_state; /* Previous button state */
- int delta_x; /* Current delta-x */
- int delta_y; /* Current delta-y */
- int active; /* set if device is open */
- int vuid_mode; /* VUID_NATIVE or VUID_FIRM_EVENT */
- wait_queue_head_t proc_list;
- struct fasync_struct *fasync;
-
- /* The event/stream queue */
- spinlock_t lock;
- unsigned int head;
- unsigned int tail;
- union {
- char stream [STREAM_SIZE];
- Firm_event ev [EV_SIZE];
- } queue;
-};
-
-static struct sun_mouse sunmouse;
-#define gen_events (sunmouse.vuid_mode != VUID_NATIVE)
-#define bstate sunmouse.button_state
-#define pstate sunmouse.prev_state
-
-extern void mouse_put_char(char ch);
-
-#undef SMOUSE_DEBUG
-
-static int
-push_event (Firm_event *ev)
-{
- unsigned long flags;
- int next, ret;
-
- spin_lock_irqsave(&sunmouse.lock, flags);
-
- next = (sunmouse.head + 1) % EV_SIZE;
- ret = 0;
- if (next != sunmouse.tail) {
- sunmouse.queue.ev [sunmouse.head] = *ev;
- sunmouse.head = next;
- ret = 1;
- }
-
- spin_unlock_irqrestore(&sunmouse.lock, flags);
-
- return ret;
-}
-
-static int
-queue_empty (void)
-{
- return sunmouse.head == sunmouse.tail;
-}
-
-/* Must be invoked under the sunmouse.lock */
-static void get_from_queue (Firm_event *p)
-{
- *p = sunmouse.queue.ev [sunmouse.tail];
- sunmouse.tail = (sunmouse.tail + 1) % EV_SIZE;
-}
-
-static void
-push_char (char c)
-{
- unsigned long flags;
- int next;
-
- spin_lock_irqsave(&sunmouse.lock, flags);
-
- next = (sunmouse.head + 1) % STREAM_SIZE;
- if (next != sunmouse.tail) {
-#ifdef SMOUSE_DEBUG
- printk("P<%02x>\n", (unsigned char)c);
-#endif
- sunmouse.queue.stream [sunmouse.head] = c;
- sunmouse.head = next;
- }
-
- spin_unlock_irqrestore(&sunmouse.lock, flags);
-
- kill_fasync (&sunmouse.fasync, SIGIO, POLL_IN);
- wake_up_interruptible (&sunmouse.proc_list);
-}
-
-/* Auto baud rate "detection". ;-) */
-static int mouse_baud = 4800; /* Initial rate set by zilog driver. */
-
-/* Change the baud rate after receiving too many "bogon bytes". */
-void sun_mouse_change_baud(void)
-{
- extern void rs_change_mouse_baud(int newbaud);
-
- if(mouse_baud == 1200)
- mouse_baud = 2400;
- else if(mouse_baud == 2400)
- mouse_baud = 4800;
- else if(mouse_baud == 4800)
- mouse_baud = 9600;
- else
- mouse_baud = 1200;
-
- rs_change_mouse_baud(mouse_baud);
-}
-
-/* This tries to monitor the mouse state so that it
- * can automatically adjust to the correct baud rate.
- * The mouse spits out BRKs when the baud rate is
- * incorrect.
- *
- * It returns non-zero if we should ignore this byte.
- */
-int mouse_baud_detection(unsigned char c, int is_break)
-{
- static int mouse_got_break = 0;
- static int ctr = 0;
-
- if (is_break) {
- /* Let a few normal bytes go by before
- * we jump the gun and say we need to
- * try another baud rate.
- */
- if (mouse_got_break && ctr < 8)
- return 1;
-
- /* OK, we need to try another baud rate. */
- sun_mouse_change_baud();
- ctr = 0;
- mouse_got_break = 1;
- return 1;
- }
- if (mouse_got_break) {
- ctr++;
- if (c == 0x87) {
- printk(KERN_INFO "sunmouse: Successfully "
- "adjusted to %d baud.\n", mouse_baud);
- mouse_got_break = 0;
- }
- return 1;
- }
-
- return 0;
-}
-
-/* You ask me, why does this cap the lower bound at -127 and not
- * -128? Because the xf86 mouse code is crap and treats -128
- * as an illegal value and resets it's protocol state machine
- * when it sees this value.
- */
-#define CLIP(__X) (((__X) > 127) ? 127 : (((__X) < -127) ? -127 : (__X)))
-
-/* The following is called from the serial driver when bytes/breaks
- * are received on the Mouse line.
- */
-void
-sun_mouse_inbyte(unsigned char byte, int is_break)
-{
- signed char mvalue;
- int d, pushed = 0;
- Firm_event ev;
-
- add_mouse_randomness (byte);
-#if 0
- {
- static int xxx = 0;
- printk("mouse(%02x:%d) ",
- byte, is_break);
- if (byte == 0x87) {
- xxx = 0;
- printk("\n");
- }
- }
-#endif
- if (mouse_baud_detection(byte, is_break))
- return;
-
- if(!sunmouse.active)
- return;
-
- /* Ignore this if it is garbage. */
- if (sunmouse.byte == 69) {
- if (byte != 0x87)
- return;
-
- /* Ok, we've begun the state machine. */
- sunmouse.byte = 0;
- }
-#if 0
- /* If the mouse sends us a byte from 0x80 to 0x87
- * we are starting at byte zero in the transaction
- * protocol.
- */
- if((byte & ~0x0f) == 0x80)
- sunmouse.byte = 0;
-#endif
-
- mvalue = (signed char) byte;
- switch(sunmouse.byte) {
- case 0:
- /* If we get a bogus button byte, just skip it.
- * When we get here the baud detection code has
- * passed, so the only other things which can
- * cause this are dropped serial characters and
- * confused mouse. We check this because otherwise
- * begin posting erroneous mouse events.
- */
- if ((byte & 0xf0) != 0x80)
- return;
-
- /* Button state */
- sunmouse.button_state = (~byte) & 0x7;
-#ifdef SMOUSE_DEBUG
- printk("B<Left %s, Middle %s, Right %s>",
- ((sunmouse.button_state & 0x4) ? "DOWN" : "UP"),
- ((sunmouse.button_state & 0x2) ? "DOWN" : "UP"),
- ((sunmouse.button_state & 0x1) ? "DOWN" : "UP"));
-#endif
- /* To deal with the Sparcbook 3 */
- if (byte & 0x8) {
- sunmouse.byte += 2;
- sunmouse.delta_y = 0;
- sunmouse.delta_x = 0;
- }
- sunmouse.byte++;
- return;
- case 1:
- /* Delta-x 1 */
-#ifdef SMOUSE_DEBUG
- printk("DX1<%d>", mvalue);
-#endif
- sunmouse.delta_x = mvalue;
- sunmouse.byte++;
- return;
- case 2:
- /* Delta-y 1 */
-#ifdef SMOUSE_DEBUG
- printk("DY1<%d>", mvalue);
-#endif
- sunmouse.delta_y = mvalue;
- sunmouse.byte++;
- return;
- case 3:
- /* Delta-x 2 */
-#ifdef SMOUSE_DEBUG
- printk("DX2<%d>", mvalue);
-#endif
- sunmouse.delta_x += mvalue;
- sunmouse.delta_x = CLIP(sunmouse.delta_x);
- sunmouse.byte++;
- return;
- case 4:
- /* Last byte, Delta-y 2 */
-#ifdef SMOUSE_DEBUG
- printk("DY2<%d>", mvalue);
-#endif
- sunmouse.delta_y += mvalue;
- sunmouse.delta_y = CLIP(sunmouse.delta_y);
- sunmouse.byte = 0; /* Back to button state */
- break;
- case 69:
- /* Until we get the (0x80 -> 0x87) value we aren't
- * in the middle of a real transaction, so just
- * return.
- */
- return;
- default:
- printk("sunmouse: bogon transaction state\n");
- sunmouse.byte = 69; /* What could cause this? */
- return;
- };
-
- if (!gen_events) {
- push_char (~sunmouse.button_state & 0x87);
- push_char (sunmouse.delta_x);
- push_char (sunmouse.delta_y);
- return;
- }
-
- d = bstate ^ pstate;
- pstate = bstate;
- if (d) {
- if (d & BUTTON_LEFT) {
- ev.id = MS_LEFT;
- ev.value = bstate & BUTTON_LEFT;
- }
- if (d & BUTTON_RIGHT) {
- ev.id = MS_RIGHT;
- ev.value = bstate & BUTTON_RIGHT;
- }
- if (d & BUTTON_MIDDLE) {
- ev.id = MS_MIDDLE;
- ev.value = bstate & BUTTON_MIDDLE;
- }
- ev.time = xtime;
- ev.value = ev.value ? VKEY_DOWN : VKEY_UP;
- pushed += push_event (&ev);
- }
- if (sunmouse.delta_x) {
- ev.id = LOC_X_DELTA;
- ev.time = xtime;
- ev.value = sunmouse.delta_x;
- pushed += push_event (&ev);
- sunmouse.delta_x = 0;
- }
- if (sunmouse.delta_y) {
- ev.id = LOC_Y_DELTA;
- ev.time = xtime;
- ev.value = sunmouse.delta_y;
- pushed += push_event (&ev);
- }
-
- if (pushed != 0) {
- /* We just completed a transaction, wake up whoever is awaiting
- * this event.
- */
- kill_fasync (&sunmouse.fasync, SIGIO, POLL_IN);
- wake_up_interruptible(&sunmouse.proc_list);
- }
- return;
-}
-
-static int
-sun_mouse_open(struct inode * inode, struct file * file)
-{
- spin_lock_irq(&sunmouse.lock);
- if (sunmouse.active++)
- goto out;
- sunmouse.delta_x = sunmouse.delta_y = 0;
- sunmouse.button_state = 0x80;
- sunmouse.vuid_mode = VUID_NATIVE;
-out:
- spin_unlock_irq(&sunmouse.lock);
- return 0;
-}
-
-static int sun_mouse_fasync (int fd, struct file *filp, int on)
-{
- int retval;
-
- retval = fasync_helper (fd, filp, on, &sunmouse.fasync);
- if (retval < 0)
- return retval;
- return 0;
-}
-
-static int
-sun_mouse_close(struct inode *inode, struct file *file)
-{
- sun_mouse_fasync (-1, file, 0);
-
- spin_lock_irq(&sunmouse.lock);
- sunmouse.active--;
- spin_unlock_irq(&sunmouse.lock);
-
- return 0;
-}
-
-static ssize_t
-sun_mouse_write(struct file *file, const char *buffer,
- size_t count, loff_t *ppos)
-{
- return -EINVAL; /* foo on you */
-}
-
-static ssize_t
-sun_mouse_read(struct file *file, char *buffer,
- size_t count, loff_t *ppos)
-{
- DECLARE_WAITQUEUE(wait, current);
- unsigned long flags;
-
- if (queue_empty ()) {
- if (file->f_flags & O_NONBLOCK)
- return -EWOULDBLOCK;
- add_wait_queue (&sunmouse.proc_list, &wait);
-repeat:
- set_current_state(TASK_INTERRUPTIBLE);
- if (queue_empty() && !signal_pending(current)) {
- schedule();
- goto repeat;
- }
- current->state = TASK_RUNNING;
- remove_wait_queue (&sunmouse.proc_list, &wait);
- }
- if (gen_events) {
- char *p = buffer, *end = buffer+count;
-
- spin_lock_irqsave(&sunmouse.lock, flags);
- while (p < end && !queue_empty ()){
- Firm_event this_event;
-
- get_from_queue(&this_event);
- spin_unlock_irqrestore(&sunmouse.lock, flags);
-
-#ifdef CONFIG_SPARC32_COMPAT
- if (test_thread_flag(TIF_32BIT)) {
- if ((end - p) <
- ((sizeof(Firm_event) - sizeof(struct timeval) +
- (sizeof(u32) * 2))))
- break;
- if (copy_to_user((Firm_event *)p, &this_event,
- sizeof(Firm_event)-sizeof(struct timeval)))
- return -EFAULT;
- p += sizeof(Firm_event)-sizeof(struct timeval);
- if (__put_user(this_event.time.tv_sec, (u32 *)p))
- return -EFAULT;
- p += sizeof(u32);
- if (__put_user(this_event.time.tv_usec, (u32 *)p))
- return -EFAULT;
- p += sizeof(u32);
- } else
-#endif
- {
- if ((end - p) < sizeof(Firm_event))
- break;
- if (copy_to_user((Firm_event *)p, &this_event,
- sizeof(Firm_event)))
- return -EFAULT;
- p += sizeof (Firm_event);
- }
- spin_lock_irqsave(&sunmouse.lock, flags);
- }
- spin_unlock_irqrestore(&sunmouse.lock, flags);
- file->f_dentry->d_inode->i_atime = CURRENT_TIME;
- return p-buffer;
- } else {
- int c, limit = 3;
-
- if (count < limit)
- limit = count;
- for (c = 0; c < limit; c++) {
- unsigned char val;
- int empty = 0;
-
- spin_lock_irqsave(&sunmouse.lock, flags);
- if (queue_empty()) {
- empty = 1;
- val = 0;
- } else {
- val = sunmouse.queue.stream[sunmouse.tail];
- sunmouse.tail = (sunmouse.tail + 1) % STREAM_SIZE;
- }
- spin_unlock_irqrestore(&sunmouse.lock, flags);
-
- if (empty)
- break;
-
- put_user(val, buffer);
- buffer++;
- }
- while (c < count) {
- if (c >= 5)
- break;
- put_user(0, buffer);
- buffer++;
- c++;
- }
- file->f_dentry->d_inode->i_atime = CURRENT_TIME;
- return c;
- }
- /* Only called if nothing was sent */
- if (signal_pending(current))
- return -ERESTARTSYS;
- return 0;
-}
-
-static unsigned int sun_mouse_poll(struct file *file, poll_table *wait)
-{
- poll_wait(file, &sunmouse.proc_list, wait);
- if(!queue_empty())
- return POLLIN | POLLRDNORM;
- return 0;
-}
-int
-sun_mouse_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
-{
- int i;
-
- switch (cmd){
- /* VUIDGFORMAT - Get input device byte stream format */
- case _IOR('v', 2, int):
- if (put_user(sunmouse.vuid_mode, (int *) arg))
- return -EFAULT;
- break;
-
- /* VUIDSFORMAT - Set input device byte stream format*/
- case _IOW('v', 1, int):
- if (get_user(i, (int *) arg))
- return -EFAULT;
- if (i == VUID_NATIVE || i == VUID_FIRM_EVENT){
- int value;
-
- if (get_user(value, (int *)arg))
- return -EFAULT;
-
- spin_lock_irq(&sunmouse.lock);
- sunmouse.vuid_mode = value;
- sunmouse.head = sunmouse.tail = 0;
- spin_unlock_irq(&sunmouse.lock);
- } else
- return -EINVAL;
- break;
-
- case 0x8024540b:
- case 0x40245408:
- /* This is a buggy application doing termios on the mouse driver */
- /* we ignore it. I keep this check here so that we will notice */
- /* future mouse vuid ioctls */
- return -ENOTTY;
-
- default:
-#ifdef DEBUG
- printk ("[MOUSE-ioctl: %8.8x]\n", cmd);
-#endif
- return -EINVAL;
- }
- return 0;
-}
-
-struct file_operations sun_mouse_fops = {
- .read = sun_mouse_read,
- .write = sun_mouse_write,
- .poll = sun_mouse_poll,
- .ioctl = sun_mouse_ioctl,
- .open = sun_mouse_open,
- .release = sun_mouse_close,
- .fasync = sun_mouse_fasync,
-};
-
-static struct miscdevice sun_mouse_mouse = {
- SUN_MOUSE_MINOR, "sunmouse", &sun_mouse_fops
-};
-
-void sun_mouse_zsinit(void)
-{
- printk("Sun Mouse-Systems mouse driver version 1.00\n");
-
- sunmouse.active = 0;
- misc_register (&sun_mouse_mouse);
- sunmouse.delta_x = sunmouse.delta_y = 0;
- sunmouse.button_state = 0x80;
- init_waitqueue_head(&sunmouse.proc_list);
- spin_lock_init(&sunmouse.lock);
- sunmouse.byte = 69;
-}
+++ /dev/null
-/* $Id: sunmouse.h,v 1.2 1999/11/19 09:56:34 davem Exp $
- * sunmouse.h: Interface to the SUN mouse driver.
- *
- * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
- */
-
-#ifndef _SPARC_SUNMOUSE_H
-#define _SPARC_SUNMOUSE_H 1
-
-extern void sun_mouse_zsinit(void);
-extern void sun_mouse_inbyte(unsigned char, int);
-
-#endif /* !(_SPARC_SUNMOUSE_H) */
static struct tty_driver serial_driver, callout_driver;
static int sab82532_refcount;
-/* number of characters left in xmit buffer before we ask for more */
-#define WAKEUP_CHARS 256
-
#undef SERIAL_PARANOIA_CHECK
#define SERIAL_DO_RESTART
int __init sab82532_console_init(void)
{
- extern int con_is_present(void);
extern int su_console_registered;
if (con_is_present() || su_console_registered)
* Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
* Copyright (C) 1998-1999 Pete Zaitcev (zaitcev@yahoo.com)
*
- * This is mainly a variation of drivers/char/serial.c,
- * credits go to authors mentioned therein.
+ * This is mainly a variation of 8250.c, credits go to authors mentioned
+ * therein. In fact this driver should be merged into the generic 8250.c
+ * infrastructure perhaps using a 8250_sparc.c module.
*
* Fixed to use tty_get_baud_rate().
* Theodore Ts'o <tytso@mit.edu>, 2001-Oct-12
+ *
+ * Converted to new 2.5.x UART layer.
+ * David S. Miller (davem@redhat.com), 2002-Jul-29
*/
-/*
- * Configuration section.
- */
-#undef SERIAL_PARANOIA_CHECK
-#define CONFIG_SERIAL_NOPAUSE_IO /* Unused on sparc */
-#define SERIAL_DO_RESTART
-
-/* Set of debugging defines */
-
-#undef SERIAL_DEBUG_INTR
-#undef SERIAL_DEBUG_OPEN
-#undef SERIAL_DEBUG_FLOW
-#undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
-#undef SERIAL_DEBUG_THROTTLE
-
-#define RS_ISR_PASS_LIMIT 256
-
-/*
- * 0x20 is sun4m thing, Dave Redman heritage.
- * See arch/sparc/kernel/irq.c.
- */
-#define IRQ_4M(n) ((n)|0x20)
-
-#if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
-#define DBG_CNT(s) \
-do { \
- printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
- kdevname(tty->device), (info->flags), serial_refcount, \
- info->count,tty->count,s); \
-} while (0)
-#else
-#define DBG_CNT(s)
-#endif
-
-/*
- * End of serial driver configuration section.
- */
-#include <linux/config.h>
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/signal.h>
-#include <linux/sched.h>
-#include <linux/interrupt.h>
-#include <linux/tty.h>
-#include <linux/tty_flip.h>
-#include <linux/serial.h>
-#include <linux/serialP.h>
-#include <linux/serial_reg.h>
-#include <linux/string.h>
-#include <linux/fcntl.h>
-#include <linux/ptrace.h>
-#include <linux/ioport.h>
-#include <linux/mm.h>
-#include <linux/slab.h>
-#include <linux/init.h>
-#include <linux/bootmem.h>
-#include <linux/delay.h>
-#ifdef CONFIG_SERIAL_CONSOLE
-#include <linux/console.h>
-#include <linux/major.h>
-#endif
-#include <linux/sysrq.h>
-
-#include <asm/system.h>
-#include <asm/oplib.h>
-#include <asm/io.h>
-#include <asm/ebus.h>
-#ifdef CONFIG_SPARC64
-#include <asm/isa.h>
+#ifdef CONFIG_SERIO
+#include <linux/serio.h>
#endif
-#include <asm/irq.h>
-#include <asm/uaccess.h>
-#include <asm/bitops.h>
-#include "sunserial.h"
+#include "suncore.h"
#include "sunkbd.h"
#include "sunmouse.h"
*/
#define BAUD_BASE (1846200 / 16)
-#ifdef CONFIG_SERIAL_CONSOLE
-extern int serial_console;
-static struct console sercons;
-int su_serial_console_init(void);
-#endif
-
enum su_type { SU_PORT_NONE, SU_PORT_MS, SU_PORT_KBD, SU_PORT_PORT };
static char *su_typev[] = { "???", "mouse", "kbd", "serial" };
-#define SU_PROPSIZE 128
-
/*
- * serial.c saves memory when it allocates async_info upon first open.
- * We have parts of state structure together because we do call startup
- * for keyboard and mouse.
+ * Here we define the default xmit fifo size used for each type of UART.
*/
-struct su_struct {
- int magic;
- unsigned long port;
- int baud_base;
- int type; /* Hardware type: e.g. 16550 */
- int irq;
- int flags;
- int line;
- int cflag;
-
- enum su_type port_type; /* Hookup type: e.g. mouse */
- int is_console;
- int port_node;
-
- char name[16];
-
- int xmit_fifo_size;
- int custom_divisor;
- unsigned short close_delay;
- unsigned short closing_wait; /* time to wait before closing */
-
- struct tty_struct *tty;
- int read_status_mask;
- int ignore_status_mask;
- int timeout;
- int quot;
- int x_char; /* xon/xoff character */
- int IER; /* Interrupt Enable Register */
- int MCR; /* Modem control register */
- unsigned long event;
- int blocked_open; /* # of blocked opens */
- long session; /* Session of opening process */
- long pgrp; /* pgrp of opening process */
- unsigned char *xmit_buf;
- int xmit_head;
- int xmit_tail;
- int xmit_cnt;
- struct tq_struct tqueue;
- wait_queue_head_t open_wait;
- wait_queue_head_t close_wait;
- wait_queue_head_t delta_msr_wait;
-
- int count;
- struct async_icount icount;
- struct termios normal_termios, callout_termios;
- unsigned long last_active; /* For async_struct, to be */
+static const struct serial_uart_config uart_config[PORT_MAX_8250+1] = {
+ { "unknown", 1, 0 },
+ { "8250", 1, 0 },
+ { "16450", 1, 0 },
+ { "16550", 1, 0 },
+ { "16550A", 16, UART_CLEAR_FIFO | UART_USE_FIFO },
+ { "Cirrus", 1, 0 },
+ { "ST16650", 1, UART_CLEAR_FIFO | UART_STARTECH },
+ { "ST16650V2", 32, UART_CLEAR_FIFO | UART_USE_FIFO | UART_STARTECH },
+ { "TI16750", 64, UART_CLEAR_FIFO | UART_USE_FIFO },
+ { "Startech", 1, 0 },
+ { "16C950/954", 128, UART_CLEAR_FIFO | UART_USE_FIFO },
+ { "ST16654", 64, UART_CLEAR_FIFO | UART_USE_FIFO | UART_STARTECH },
+ { "XR16850", 128, UART_CLEAR_FIFO | UART_USE_FIFO | UART_STARTECH },
+ { "RSA", 2048, UART_CLEAR_FIFO | UART_USE_FIFO }
};
-/*
- * Scan status structure.
- * "prop" is a local variable but it eats stack to keep it in each
- * stack frame of a recursive procedure.
- */
-struct su_probe_scan {
- int msnode, kbnode; /* PROM nodes for mouse and keyboard */
- int msx, kbx; /* minors for mouse and keyboard */
- int devices; /* scan index */
- char prop[SU_PROPSIZE];
-};
+#define _INLINE_
-static char *serial_name = "PCIO serial driver";
-static char serial_version[16];
+static _INLINE_ unsigned int serial_in(struct uart_sunsu_port *up, int offset)
+{
+ offset <<= up->port.regshift;
-static DECLARE_TASK_QUEUE(tq_serial);
+ switch (up->port.iotype) {
+ case SERIAL_IO_HUB6:
+ outb(up->port.hub6 - 1 + offset, up->port.iobase);
+ return inb(up->port.iobase + 1);
-static struct tty_driver serial_driver, callout_driver;
-static int serial_refcount;
+ case SERIAL_IO_MEM:
+ return readb(up->port.membase + offset);
-/* number of characters left in xmit buffer before we ask for more */
-#define WAKEUP_CHARS 256
+ default:
+ return inb(up->port.iobase + offset);
+ }
+}
-static void autoconfig(struct su_struct *info);
-static void change_speed(struct su_struct *info, struct termios *old);
-static void su_wait_until_sent(struct tty_struct *tty, int timeout);
+static _INLINE_ void
+serial_out(struct uart_sunsu_port *up, int offset, int value)
+{
+#ifndef CONFIG_SPARC64
+ /*
+ * MrCoffee has weird schematics: IRQ4 & P10(?) pins of SuperIO are
+ * connected with a gate then go to SlavIO. When IRQ4 goes tristated
+ * gate outputs a logical one. Since we use level triggered interrupts
+ * we have lockup and watchdog reset. We cannot mask IRQ because
+ * keyboard shares IRQ with us (Word has it as Bob Smelik's design).
+ * This problem is similar to what Alpha people suffer, see serial.c.
+ */
+ if (offset == UART_MCR)
+ value |= UART_MCR_OUT2;
+#endif
+ offset <<= up->port.regshift;
-/*
- * Here we define the default xmit fifo size used for each type of
- * UART
- */
-static struct serial_uart_config uart_config[] = {
- { "unknown", 1, 0 },
- { "8250", 1, 0 },
- { "16450", 1, 0 },
- { "16550", 1, 0 },
- { "16550A", 16, UART_CLEAR_FIFO | UART_USE_FIFO },
- { "cirrus", 1, 0 },
- { "ST16650", 1, UART_CLEAR_FIFO |UART_STARTECH },
- { "ST16650V2", 32, UART_CLEAR_FIFO | UART_USE_FIFO |
- UART_STARTECH },
- { "TI16750", 64, UART_CLEAR_FIFO | UART_USE_FIFO},
- { 0, 0}
-};
+ switch (up->port.iotype) {
+ case SERIAL_IO_HUB6:
+ outb(up->port.hub6 - 1 + offset, up->port.iobase);
+ outb(value, up->port.iobase + 1);
+ break;
+ case SERIAL_IO_MEM:
+ writeb(value, up->port.membase + offset);
+ break;
-#define NR_PORTS 4
+ default:
+ outb(value, up->port.iobase + offset);
+ }
+}
-static struct su_struct su_table[NR_PORTS];
-static struct tty_struct *serial_table[NR_PORTS];
-static struct termios *serial_termios[NR_PORTS];
-static struct termios *serial_termios_locked[NR_PORTS];
+/*
+ * We used to support using pause I/O for certain machines. We
+ * haven't supported this for a while, but just in case it's badly
+ * needed for certain old 386 machines, I've left these #define's
+ * in....
+ */
+#define serial_inp(up, offset) serial_in(up, offset)
+#define serial_outp(up, offset, value) serial_out(up, offset, value)
-#ifndef MIN
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-#endif
/*
- * tmp_buf is used as a temporary buffer by serial_write. We need to
- * lock it in case the copy_from_user blocks while swapping in a page,
- * and some other program tries to do a serial write at the same time.
- * Since the lock will only come under contention when the system is
- * swapping and available memory is low, it makes sense to share one
- * buffer across all the serial ports, since it significantly saves
- * memory if large numbers of serial ports are open.
+ * For the 16C950
*/
-static unsigned char *tmp_buf;
-static DECLARE_MUTEX(tmp_buf_sem);
-
-static inline int serial_paranoia_check(struct su_struct *info,
- kdev_t device, const char *routine)
+static void serial_icr_write(struct uart_sunsu_port *up, int offset, int value)
{
-#ifdef SERIAL_PARANOIA_CHECK
- static const char *badmagic = KERN_WARNING
- "Warning: bad magic number for serial struct (%s) in %s\n";
- static const char *badinfo = KERN_WARNING
- "Warning: null su_struct for (%s) in %s\n";
-
- if (!info) {
- printk(badinfo, kdevname(device), routine);
- return 1;
- }
- if (info->magic != SERIAL_MAGIC) {
- printk(badmagic, kdevname(device), routine);
- return 1;
- }
-#endif
- return 0;
+ serial_out(up, UART_SCR, offset);
+ serial_out(up, UART_ICR, value);
}
-static inline
-unsigned int su_inb(struct su_struct *info, unsigned long offset)
+static unsigned int serial_icr_read(struct uart_sunsu_port *up, int offset)
{
- return inb(info->port + offset);
+ unsigned int value;
+
+ serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
+ serial_out(up, UART_SCR, offset);
+ value = serial_in(up, UART_ICR);
+ serial_icr_write(up, UART_ACR, up->acr);
+
+ return value;
}
-static inline void
-su_outb(struct su_struct *info, unsigned long offset, int value)
+#ifdef CONFIG_SERIAL_8250_RSA
+/*
+ * Attempts to turn on the RSA FIFO. Returns zero on failure.
+ * We set the port uart clock rate if we succeed.
+ */
+static int __enable_rsa(struct uart_sunsu_port *up)
{
-#ifndef __sparc_v9__
- /*
- * MrCoffee has weird schematics: IRQ4 & P10(?) pins of SuperIO are
- * connected with a gate then go to SlavIO. When IRQ4 goes tristated
- * gate outputs a logical one. Since we use level triggered interrupts
- * we have lockup and watchdog reset. We cannot mask IRQ because
- * keyboard shares IRQ with us (Word has it as Bob Smelik's design).
- * This problem is similar to what Alpha people suffer, see serial.c.
- */
- if (offset == UART_MCR) value |= UART_MCR_OUT2;
-#endif
- outb(value, info->port + offset);
+ unsigned char mode;
+ int result;
+
+ mode = serial_inp(up, UART_RSA_MSR);
+ result = mode & UART_RSA_MSR_FIFO;
+
+ if (!result) {
+ serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
+ mode = serial_inp(up, UART_RSA_MSR);
+ result = mode & UART_RSA_MSR_FIFO;
+ }
+
+ if (result)
+ up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16;
+
+ return result;
}
-#define serial_in(info, off) su_inb(info, off)
-#define serial_inp(info, off) su_inb(info, off)
-#define serial_out(info, off, val) su_outb(info, off, val)
-#define serial_outp(info, off, val) su_outb(info, off, val)
+static void enable_rsa(struct uart_sunsu_port *up)
+{
+ if (up->port.type == PORT_RSA) {
+ if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
+ spin_lock_irq(&up->port.lock);
+ __enable_rsa(up);
+ spin_unlock_irq(&up->port.lock);
+ }
+ if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
+ serial_outp(up, UART_RSA_FRR, 0);
+ }
+}
/*
- * ------------------------------------------------------------
- * su_stop() and su_start()
- *
- * This routines are called before setting or resetting tty->stopped.
- * They enable or disable transmitter interrupts, as necessary.
- * ------------------------------------------------------------
+ * Attempts to turn off the RSA FIFO. Returns zero on failure.
+ * It is unknown why interrupts were disabled in here. However,
+ * the caller is expected to preserve this behaviour by grabbing
+ * the spinlock before calling this function.
*/
-static void su_stop(struct tty_struct *tty)
+static void disable_rsa(struct uart_sunsu_port *up)
{
- struct su_struct *info = (struct su_struct *)tty->driver_data;
- unsigned long flags;
+ unsigned char mode;
+ int result;
- if (serial_paranoia_check(info, tty->device, "su_stop"))
- return;
+ if (up->port.type == PORT_RSA &&
+ up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) {
+ spin_lock_irq(&up->port.lock);
+
+ mode = serial_inp(up, UART_RSA_MSR);
+ result = !(mode & UART_RSA_MSR_FIFO);
+
+ if (!result) {
+ serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
+ mode = serial_inp(up, UART_RSA_MSR);
+ result = !(mode & UART_RSA_MSR_FIFO);
+ }
- save_flags(flags); cli();
- if (info->IER & UART_IER_THRI) {
- info->IER &= ~UART_IER_THRI;
- serial_out(info, UART_IER, info->IER);
+ if (result)
+ up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
+ spin_unlock_irq(&up->port.lock);
}
- restore_flags(flags);
}
+#endif /* CONFIG_SERIAL_8250_RSA */
-static void su_start(struct tty_struct *tty)
+static void sunsu_stop_tx(struct uart_port *port, unsigned int tty_stop)
{
- struct su_struct *info = (struct su_struct *)tty->driver_data;
- unsigned long flags;
-
- if (serial_paranoia_check(info, tty->device, "su_start"))
- return;
+ struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
- save_flags(flags); cli();
- if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
- info->IER |= UART_IER_THRI;
- serial_out(info, UART_IER, info->IER);
+ if (up->ier & UART_IER_THRI) {
+ up->ier &= ~UART_IER_THRI;
+ serial_out(up, UART_IER, up->ier);
+ }
+ if (up->port.type == PORT_16C950 && tty_stop) {
+ up->acr |= UART_ACR_TXDIS;
+ serial_icr_write(up, UART_ACR, up->acr);
}
- restore_flags(flags);
}
-/*
- * ----------------------------------------------------------------------
- *
- * Here starts the interrupt handling routines. All of the following
- * subroutines are declared as inline and are folded into
- * su_interrupt(). They were separated out for readability's sake.
- *
- * Note: rs_interrupt() is a "fast" interrupt, which means that it
- * runs with interrupts turned off. People who may want to modify
- * rs_interrupt() should try to keep the interrupt handler as fast as
- * possible. After you are done making modifications, it is not a bad
- * idea to do:
- *
- * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
- *
- * and look at the resulting assemble code in serial.s.
- *
- * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
- * -----------------------------------------------------------------------
- */
-
-/*
- * This routine is used by the interrupt handler to schedule
- * processing in the software interrupt portion of the driver.
- */
-static void
-su_sched_event(struct su_struct *info, int event)
+static void sunsu_start_tx(struct uart_port *port, unsigned int tty_start)
{
- info->event |= 1 << event;
- queue_task(&info->tqueue, &tq_serial);
- mark_bh(SERIAL_BH);
+ struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
+
+ if (!(up->ier & UART_IER_THRI)) {
+ up->ier |= UART_IER_THRI;
+ serial_out(up, UART_IER, up->ier);
+ }
+ /*
+ * We only do this from uart_start
+ */
+ if (tty_start && up->port.type == PORT_16C950) {
+ up->acr &= ~UART_ACR_TXDIS;
+ serial_icr_write(up, UART_ACR, up->acr);
+ }
}
-static void
-receive_kbd_ms_chars(struct su_struct *info, struct pt_regs *regs, int is_brk)
+static void sunsu_stop_rx(struct uart_port *port)
{
- unsigned char status = 0;
- unsigned char ch;
+ struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
+ unsigned long flags;
- do {
- ch = serial_inp(info, UART_RX);
- if (info->port_type == SU_PORT_KBD) {
- if (ch == SUNKBD_RESET) {
- l1a_state.kbd_id = 1;
- l1a_state.l1_down = 0;
- } else if (l1a_state.kbd_id) {
- l1a_state.kbd_id = 0;
- } else if (ch == SUNKBD_L1) {
- l1a_state.l1_down = 1;
- } else if (ch == (SUNKBD_L1|SUNKBD_UP)) {
- l1a_state.l1_down = 0;
- } else if (ch == SUNKBD_A && l1a_state.l1_down) {
- /* whee... */
- batten_down_hatches();
- /* Continue execution... */
- l1a_state.l1_down = 0;
- l1a_state.kbd_id = 0;
- return;
- }
- sunkbd_inchar(ch, regs);
- } else {
- sun_mouse_inbyte(ch, is_brk);
- }
+ spin_lock_irqsave(&up->port.lock, flags);
+ up->ier &= ~UART_IER_RLSI;
+ up->port.read_status_mask &= ~UART_LSR_DR;
+ serial_out(up, UART_IER, up->ier);
+ spin_unlock_irqrestore(&up->port.lock, flags);
+}
+
+static void sunsu_enable_ms(struct uart_port *port)
+{
+ struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
+ unsigned long flags;
- status = su_inb(info, UART_LSR);
- } while (status & UART_LSR_DR);
+ spin_lock_irqsave(&up->port.lock, flags);
+ up->ier |= UART_IER_MSI;
+ serial_out(up, UART_IER, up->ier);
+ spin_unlock_irqrestore(&up->port.lock, flags);
}
-static void
-receive_serial_chars(struct su_struct *info, int *status, struct pt_regs *regs)
+static _INLINE_ void
+receive_chars(struct uart_sunsu_port *up, int *status, struct pt_regs *regs)
{
- struct tty_struct *tty = info->tty;
+ struct tty_struct *tty = up->port.info->tty;
unsigned char ch;
- int ignored = 0, saw_console_brk = 0;
- struct async_icount *icount;
+ int max_count = 256;
+ int saw_console_brk = 0;
- icount = &info->icount;
do {
- ch = serial_inp(info, UART_RX);
- if (info->is_console &&
- (ch == 0 || (*status &UART_LSR_BI)))
- saw_console_brk = 1;
- if (tty->flip.count >= TTY_FLIPBUF_SIZE)
- break;
+ if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
+ tty->flip.tqueue.routine((void *)tty);
+ if (tty->flip.count >= TTY_FLIPBUF_SIZE)
+ return; // if TTY_DONT_FLIP is set
+ }
+ ch = serial_inp(up, UART_RX);
*tty->flip.char_buf_ptr = ch;
- icount->rx++;
+ *tty->flip.flag_buf_ptr = TTY_NORMAL;
+ up->port.icount.rx++;
-#ifdef SERIAL_DEBUG_INTR
- printk("D%02x:%02x.", ch, *status);
-#endif
- *tty->flip.flag_buf_ptr = 0;
- if (*status & (UART_LSR_BI | UART_LSR_PE |
- UART_LSR_FE | UART_LSR_OE)) {
+ if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
+ UART_LSR_FE | UART_LSR_OE))) {
/*
* For statistics only
*/
if (*status & UART_LSR_BI) {
*status &= ~(UART_LSR_FE | UART_LSR_PE);
- icount->brk++;
+ up->port.icount.brk++;
+ if (SU_IS_CONS(up))
+ saw_console_brk = 1;
+ /*
+ * We do the SysRQ and SAK checking
+ * here because otherwise the break
+ * may get masked by ignore_status_mask
+ * or read_status_mask.
+ */
+ if (uart_handle_break(&up->port))
+ goto ignore_char;
} else if (*status & UART_LSR_PE)
- icount->parity++;
+ up->port.icount.parity++;
else if (*status & UART_LSR_FE)
- icount->frame++;
+ up->port.icount.frame++;
if (*status & UART_LSR_OE)
- icount->overrun++;
+ up->port.icount.overrun++;
/*
- * Now check to see if character should be
- * ignored, and mask off conditions which
- * should be ignored.
+ * Mask off conditions which should be ingored.
*/
- if (*status & info->ignore_status_mask) {
- if (++ignored > 100) {
-#ifdef SERIAL_DEBUG_INTR
- printk("ign100..");
-#endif
- break;
- }
- goto ignore_char;
+ *status &= up->port.read_status_mask;
+
+ if (up->port.line == up->port.cons->index) {
+ /* Recover the break flag from console xmit */
+ *status |= up->lsr_break_flag;
+ up->lsr_break_flag = 0;
}
- *status &= info->read_status_mask;
- if (*status & (UART_LSR_BI)) {
-#ifdef SERIAL_DEBUG_INTR
- printk("handling break....");
-#endif
+ if (*status & UART_LSR_BI) {
*tty->flip.flag_buf_ptr = TTY_BREAK;
- if (info->flags & ASYNC_SAK)
- do_SAK(tty);
} else if (*status & UART_LSR_PE)
*tty->flip.flag_buf_ptr = TTY_PARITY;
else if (*status & UART_LSR_FE)
*tty->flip.flag_buf_ptr = TTY_FRAME;
- if (*status & UART_LSR_OE) {
- /*
- * Overrun is special, since it's
- * reported immediately, and doesn't
- * affect the current character
- */
- if (tty->flip.count < TTY_FLIPBUF_SIZE) {
- tty->flip.count++;
- tty->flip.flag_buf_ptr++;
- tty->flip.char_buf_ptr++;
- *tty->flip.flag_buf_ptr = TTY_OVERRUN;
- }
- }
}
- tty->flip.flag_buf_ptr++;
- tty->flip.char_buf_ptr++;
- tty->flip.count++;
+ if (uart_handle_sysrq_char(&up->port, ch, regs))
+ goto ignore_char;
+ if ((*status & up->port.ignore_status_mask) == 0) {
+ tty->flip.flag_buf_ptr++;
+ tty->flip.char_buf_ptr++;
+ tty->flip.count++;
+ }
+ if ((*status & UART_LSR_OE) &&
+ tty->flip.count < TTY_FLIPBUF_SIZE) {
+ /*
+ * Overrun is special, since it's reported
+ * immediately, and doesn't affect the current
+ * character.
+ */
+ *tty->flip.flag_buf_ptr = TTY_OVERRUN;
+ tty->flip.flag_buf_ptr++;
+ tty->flip.char_buf_ptr++;
+ tty->flip.count++;
+ }
ignore_char:
- *status = serial_inp(info, UART_LSR);
- } while (*status & UART_LSR_DR);
-#ifdef SERIAL_DEBUG_INTR
- printk("E%02x.R%d", *status, tty->flip.count);
-#endif
+ *status = serial_inp(up, UART_LSR);
+ } while ((*status & UART_LSR_DR) && (max_count-- > 0));
tty_flip_buffer_push(tty);
- if (saw_console_brk != 0)
- batten_down_hatches();
+
+ if (saw_console_brk)
+ sun_do_break();
}
-static void
-transmit_chars(struct su_struct *info, int *intr_done)
+static _INLINE_ void transmit_chars(struct uart_sunsu_port *up)
{
+ struct circ_buf *xmit = &up->port.info->xmit;
int count;
- if (info->x_char) {
- serial_outp(info, UART_TX, info->x_char);
- info->icount.tx++;
- info->x_char = 0;
- if (intr_done)
- *intr_done = 0;
+ if (up->port.x_char) {
+ serial_outp(up, UART_TX, up->port.x_char);
+ up->port.icount.tx++;
+ up->port.x_char = 0;
return;
}
- if ((info->xmit_cnt <= 0) || info->tty->stopped ||
- info->tty->hw_stopped) {
- info->IER &= ~UART_IER_THRI;
- serial_out(info, UART_IER, info->IER);
+ if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
+ sunsu_stop_tx(&up->port, 0);
return;
}
- count = info->xmit_fifo_size;
+ count = up->port.fifosize;
do {
- serial_out(info, UART_TX, info->xmit_buf[info->xmit_tail++]);
- info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
- info->icount.tx++;
- if (--info->xmit_cnt <= 0)
+ serial_out(up, UART_TX, xmit->buf[xmit->tail]);
+ xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
+ up->port.icount.tx++;
+ if (uart_circ_empty(xmit))
break;
} while (--count > 0);
-
- if (info->xmit_cnt < WAKEUP_CHARS)
- su_sched_event(info, RS_EVENT_WRITE_WAKEUP);
-#ifdef SERIAL_DEBUG_INTR
- printk("T%d...", info->xmit_cnt);
-#endif
- if (intr_done)
- *intr_done = 0;
+ if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
+ uart_event(&up->port, EVT_WRITE_WAKEUP);
- if (info->xmit_cnt <= 0) {
- info->IER &= ~UART_IER_THRI;
- serial_out(info, UART_IER, info->IER);
- }
+ if (uart_circ_empty(xmit))
+ sunsu_stop_tx(&up->port, 0);
}
-static void
-check_modem_status(struct su_struct *info)
+static _INLINE_ void check_modem_status(struct uart_sunsu_port *up)
{
- int status;
- struct async_icount *icount;
-
- status = serial_in(info, UART_MSR);
-
- if (status & UART_MSR_ANY_DELTA) {
- icount = &info->icount;
- /* update input line counters */
- if (status & UART_MSR_TERI)
- icount->rng++;
- if (status & UART_MSR_DDSR)
- icount->dsr++;
- if (status & UART_MSR_DDCD) {
- icount->dcd++;
-#ifdef CONFIG_HARD_PPS
- if ((info->flags & ASYNC_HARDPPS_CD) &&
- (status & UART_MSR_DCD))
- hardpps();
-#endif
- }
- if (status & UART_MSR_DCTS)
- icount->cts++;
- wake_up_interruptible(&info->delta_msr_wait);
- }
+ int status;
- if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
-#if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
- printk("ttys%d CD now %s...", info->line,
- (status & UART_MSR_DCD) ? "on" : "off");
-#endif
- if (status & UART_MSR_DCD)
- wake_up_interruptible(&info->open_wait);
- else if (!((info->flags & ASYNC_CALLOUT_ACTIVE) &&
- (info->flags & ASYNC_CALLOUT_NOHUP))) {
-#ifdef SERIAL_DEBUG_OPEN
- printk("doing serial hangup...");
-#endif
- if (info->tty)
- tty_hangup(info->tty);
- }
- }
- if (info->flags & ASYNC_CTS_FLOW) {
- if (info->tty->hw_stopped) {
- if (status & UART_MSR_CTS) {
-#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
- printk("CTS tx start...");
-#endif
- info->tty->hw_stopped = 0;
- info->IER |= UART_IER_THRI;
- serial_out(info, UART_IER, info->IER);
- su_sched_event(info, RS_EVENT_WRITE_WAKEUP);
- return;
- }
- } else {
- if (!(status & UART_MSR_CTS)) {
-#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
- printk("CTS tx stop...");
-#endif
- info->tty->hw_stopped = 1;
- info->IER &= ~UART_IER_THRI;
- serial_out(info, UART_IER, info->IER);
- }
- }
- }
+ status = serial_in(up, UART_MSR);
+
+ if ((status & UART_MSR_ANY_DELTA) == 0)
+ return;
+
+ if (status & UART_MSR_TERI)
+ up->port.icount.rng++;
+ if (status & UART_MSR_DDSR)
+ up->port.icount.dsr++;
+ if (status & UART_MSR_DDCD)
+ uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
+ if (status & UART_MSR_DCTS)
+ uart_handle_cts_change(&up->port, status & UART_MSR_CTS);
+
+ wake_up_interruptible(&up->port.info->delta_msr_wait);
}
-/*
- * This is the kbd/mouse serial driver's interrupt routine
- */
-static void
-su_kbd_ms_interrupt(int irq, void *dev_id, struct pt_regs * regs)
+static void sunsu_serial_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
- struct su_struct *info = (struct su_struct *)dev_id;
+ struct uart_sunsu_port *up = dev_id;
+ unsigned long flags;
unsigned char status;
-#ifdef SERIAL_DEBUG_INTR
- printk("su_kbd_ms_interrupt(%s)...", __irq_itoa(irq));
-#endif
- if (!info)
- return;
-
- if (serial_in(info, UART_IIR) & UART_IIR_NO_INT)
- return;
+ spin_lock_irqsave(&up->port.lock, flags);
- status = serial_inp(info, UART_LSR);
-#ifdef SERIAL_DEBUG_INTR
- printk("status = %x...", status);
-#endif
- if ((status & UART_LSR_DR) || (status & UART_LSR_BI))
- receive_kbd_ms_chars(info, regs,
- (status & UART_LSR_BI) != 0);
+ do {
+ status = serial_inp(up, UART_LSR);
+ if (status & UART_LSR_DR)
+ receive_serial_chars(up, &status, regs);
+ check_modem_status(up);
+ if (status & UART_LSR_THRE)
+ transmit_chars(up);
+ } while (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT));
-#ifdef SERIAL_DEBUG_INTR
- printk("end.\n");
-#endif
+ spin_unlock_irqrestore(&up->port.lock, flags);
}
-/*
- * This is the serial driver's generic interrupt routine
- */
+/* Seperate interrupt handling path for keyboard/mouse ports. */
+
static void
-su_serial_interrupt(int irq, void *dev_id, struct pt_regs * regs)
+sunsu_change_speed(struct uart_port *port, unsigned int cflag,
+ unsigned int iflag, unsigned int quot);
+
+static void sunsu_change_mouse_baud(struct uart_sunsu_port *up)
{
- int status;
- struct su_struct *info;
- int pass_counter = 0;
+ unsigned int cur_cflag = up->port.cflag;
+ int quot, new_baud;
-#ifdef SERIAL_DEBUG_INTR
- printk("su_serial_interrupt(%s)...", __irq_itoa(irq));
-#endif
- info = (struct su_struct *)dev_id;
- if (!info || !info->tty) {
-#ifdef SERIAL_DEBUG_INTR
- printk("strain\n");
-#endif
- return;
- }
+ up->port.cflag &= ~CBAUD;
+ up->port.cflag |= suncore_mouse_baud_cflag_next(cur_cflag, &new_baud);
- do {
- status = serial_inp(info, UART_LSR);
-#ifdef SERIAL_DEBUG_INTR
- printk("status = %x...", status);
-#endif
- if (status & UART_LSR_DR)
- receive_serial_chars(info, &status, regs);
- check_modem_status(info);
- if (status & UART_LSR_THRE)
- transmit_chars(info, 0);
+ quot = sunsu_calc_quot(new_baud);
- if (pass_counter++ > RS_ISR_PASS_LIMIT) {
-#ifdef SERIAL_DEBUG_INTR
- printk("rs loop break");
-#endif
- break; /* Prevent infinite loops */
- }
- } while (!(serial_in(info, UART_IIR) & UART_IIR_NO_INT));
+ spin_unlock(&up->port.lock);
- info->last_active = jiffies;
+ sunsu_change_speed(up, up->port.cflag, 0, quot);
-#ifdef SERIAL_DEBUG_INTR
- printk("end.\n");
-#endif
+ spin_lock(&up->port.lock);
}
-/*
- * -------------------------------------------------------------------
- * Here ends the serial interrupt routines.
- * -------------------------------------------------------------------
- */
-
-/*
- * This routine is used to handle the "bottom half" processing for the
- * serial driver, known also the "software interrupt" processing.
- * This processing is done at the kernel interrupt level, after the
- * su_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
- * is where time-consuming activities which can not be done in the
- * interrupt driver proper are done; the interrupt driver schedules
- * them using su_sched_event(), and they get done here.
- */
-static void do_serial_bh(void)
+static void receive_kbd_ms_chars(struct uart_sunsu_port *up, struct pt_regs *regs, int is_break)
{
- run_task_queue(&tq_serial);
+ do {
+ unsigned char ch = serial_inp(up, UART_RX);
+
+ if (up->port_type == SU_PORT_KBD) {
+ if (ch == SUNKBD_RESET) {
+ up->kbd_id = 1;
+ up->l1_down = 0;
+ } else if (up->kbd_id) {
+ up->kbd_id = 0;
+ } else if (ch == SUNKBD_L1) {
+ up->l1_down = 1;
+ } else if (ch == (SUNKBD_L1|SUNKBD_UP)) {
+ up->l1_down = 0;
+ } else if (ch == SUNKBD_A && up->l1_down) {
+ /* whee... */
+ sun_do_break();
+
+ /* Continue execution... */
+ up->l1_down = 0;
+ up->kbd_id = 0;
+ return;
+ }
+ kbd_pt_regs = regs;
+#ifdef CONFIG_SERIO
+ serio_interrupt(&up->serio, ch, 0);
+#endif
+ } else if (up->port_type == SU_PORT_MS) {
+ int ret = suncore_mouse_baud_detection(ch, is_break);
+
+ switch (ret) {
+ case 2:
+ sunsu_change_mouse_baud(up);
+ /* fallthru */
+ case 1:
+ break;
+
+ case 0:
+#ifdef CONFIG_SERIO
+ serio_interrupt(&up->serio, ch, 0);
+#endif
+ break;
+ };
+ }
+ } while (serial_in(up, UART_LSR) & UART_LSR_DR);
}
-static void do_softint(void *private_)
+static void sunsu_kbd_ms_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
- struct su_struct *info = (struct su_struct *) private_;
- struct tty_struct *tty;
+ struct uart_sunsu_port *up = dev_id;
- tty = info->tty;
- if (!tty)
- return;
+ if (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT)) {
+ unsigned char status = serial_inp(up, UART_LSR);
- if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
- if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
- tty->ldisc.write_wakeup)
- (tty->ldisc.write_wakeup)(tty);
- wake_up_interruptible(&tty->write_wait);
+ if ((status & UART_LSR_DR) || (status & UART_LSR_BI))
+ receive_kbd_ms_chars(up, regs,
+ (status & UART_LSR_BI) != 0);
}
}
-/*
- * ---------------------------------------------------------------
- * Low level utility subroutines for the serial driver: routines to
- * figure out the appropriate timeout for an interrupt chain, routines
- * to initialize and startup a serial port, and routines to shutdown a
- * serial port. Useful stuff like that.
- * ---------------------------------------------------------------
- */
-
-static int
-startup(struct su_struct *info)
+static unsigned int sunsu_tx_empty(struct uart_port *port)
{
+ struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
unsigned long flags;
- int retval=0;
- unsigned long page;
+ unsigned int ret;
- save_flags(flags);
- if (info->tty) {
- page = get_free_page(GFP_KERNEL);
- if (!page)
- return -ENOMEM;
+ spin_lock_irqsave(&up->port.lock, flags);
+ ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
+ spin_unlock_irqrestore(&up->port.lock, flags);
- cli();
+ return ret;
+}
- if (info->flags & ASYNC_INITIALIZED) {
- free_page(page);
- goto errout;
- }
+static unsigned int sunsu_get_mctrl(struct uart_port *port)
+{
+ struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
+ unsigned long flags;
+ unsigned char status;
+ unsigned int ret;
- if (info->port == 0 || info->type == PORT_UNKNOWN) {
- set_bit(TTY_IO_ERROR, &info->tty->flags);
- free_page(page);
- goto errout;
- }
- if (info->xmit_buf)
- free_page(page);
- else
- info->xmit_buf = (unsigned char *) page;
- }
- cli();
+ spin_lock_irqsave(&up->port.lock, flags);
+ status = serial_in(up, UART_MSR);
+ spin_unlock_irqrestore(&up->port.lock, flags);
-#ifdef SERIAL_DEBUG_OPEN
- printk("starting up ttys%d (irq %s)...", info->line,
- __irq_itoa(info->irq));
-#endif
+ ret = 0;
+ if (status & UART_MSR_DCD)
+ ret |= TIOCM_CAR;
+ if (status & UART_MSR_RI)
+ ret |= TIOCM_RNG;
+ if (status & UART_MSR_DSR)
+ ret |= TIOCM_DSR;
+ if (status & UART_MSR_CTS)
+ ret |= TIOCM_CTS;
+ return ret;
+}
- if (uart_config[info->type].flags & UART_STARTECH) {
- /* Wake up UART */
- serial_outp(info, UART_LCR, 0xBF);
- serial_outp(info, UART_EFR, UART_EFR_ECB);
- serial_outp(info, UART_IER, 0);
- serial_outp(info, UART_EFR, 0);
- serial_outp(info, UART_LCR, 0);
- }
+static void sunsu_set_mctrl(struct uart_port *port, unsigned int mctrl)
+{
+ struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
+ unsigned char mcr = 0;
+
+ if (mctrl & TIOCM_RTS)
+ mcr |= UART_MCR_RTS;
+ if (mctrl & TIOCM_DTR)
+ mcr |= UART_MCR_DTR;
+ if (mctrl & TIOCM_OUT1)
+ mcr |= UART_MCR_OUT1;
+ if (mctrl & TIOCM_OUT2)
+ mcr |= UART_MCR_OUT2;
+ if (mctrl & TIOCM_LOOP)
+ mcr |= UART_MCR_LOOP;
+
+ serial_out(up, UART_MCR, mcr);
+}
- if (info->type == PORT_16750) {
- /* Wake up UART */
- serial_outp(info, UART_IER, 0);
- }
+static void sunsu_break_ctl(struct uart_port *port, int break_state)
+{
+ struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
+ unsigned long flags;
- /*
- * Clear the FIFO buffers and disable them
- * (they will be reenabled in change_speed())
- */
- if (uart_config[info->type].flags & UART_CLEAR_FIFO)
- serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR |
- UART_FCR_CLEAR_XMIT));
+ spin_lock_irqsave(&up->port.lock, flags);
+ if (break_state == -1)
+ up->lcr |= UART_LCR_SBC;
+ else
+ up->lcr &= ~UART_LCR_SBC;
+ serial_out(up, UART_LCR, up->lcr);
+ spin_unlock_irqrestore(&up->port.lock, flags);
+}
+static int sunsu_startup(struct uart_port *port)
+{
+ struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
+ unsigned long flags;
+ int retval;
+
+ if (up->port.type == PORT_16C950) {
+ /* Wake up and initialize UART */
+ up->acr = 0;
+ serial_outp(up, UART_LCR, 0xBF);
+ serial_outp(up, UART_EFR, UART_EFR_ECB);
+ serial_outp(up, UART_IER, 0);
+ serial_outp(up, UART_LCR, 0);
+ serial_icr_write(up, UART_CSR, 0); /* Reset the UART */
+ serial_outp(up, UART_LCR, 0xBF);
+ serial_outp(up, UART_EFR, UART_EFR_ECB);
+ serial_outp(up, UART_LCR, 0);
+ }
+
+#ifdef CONFIG_SERIAL_8250_RSA
/*
- * At this point there's no way the LSR could still be 0xFF;
- * if it is, then bail out, because there's likely no UART
- * here.
+ * If this is an RSA port, see if we can kick it up to the
+ * higher speed clock.
*/
- if (serial_inp(info, UART_LSR) == 0xff) {
- if (capable(CAP_SYS_ADMIN)) {
- if (info->tty)
- set_bit(TTY_IO_ERROR, &info->tty->flags);
- } else
- retval = -ENODEV;
- goto errout;
- }
+ enable_rsa(up);
+#endif
/*
- * Allocate the IRQ if necessary
+ * Clear the FIFO buffers and disable them.
+ * (they will be reeanbled in change_speed())
*/
- if (info->port_type != SU_PORT_PORT) {
- retval = request_irq(info->irq, su_kbd_ms_interrupt,
- SA_SHIRQ, info->name, info);
- } else {
- retval = request_irq(info->irq, su_serial_interrupt,
- SA_SHIRQ, info->name, info);
- }
- if (retval) {
- if (capable(CAP_SYS_ADMIN)) {
- if (info->tty)
- set_bit(TTY_IO_ERROR, &info->tty->flags);
- retval = 0;
- }
- goto errout;
+ if (uart_config[up->port.type].flags & UART_CLEAR_FIFO) {
+ serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
+ serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
+ UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
+ serial_outp(up, UART_FCR, 0);
}
/*
* Clear the interrupt registers.
*/
- (void) serial_inp(info, UART_RX);
- (void) serial_inp(info, UART_IIR);
- (void) serial_inp(info, UART_MSR);
+ (void) serial_inp(up, UART_LSR);
+ (void) serial_inp(up, UART_RX);
+ (void) serial_inp(up, UART_IIR);
+ (void) serial_inp(up, UART_MSR);
/*
- * Now, initialize the UART
+ * At this point, there's no way the LSR could still be 0xff;
+ * if it is, then bail out, because there's likely no UART
+ * here.
*/
- serial_outp(info, UART_LCR, UART_LCR_WLEN8); /* reset DLAB */
-
- info->MCR = 0;
- if (info->tty && info->tty->termios->c_cflag & CBAUD)
- info->MCR = UART_MCR_DTR | UART_MCR_RTS;
- if (info->irq != 0)
- info->MCR |= UART_MCR_OUT2;
- serial_outp(info, UART_MCR, info->MCR);
+ if (!(up->port.flags & ASYNC_BUGGY_UART) &&
+ (serial_inp(up, UART_LSR) == 0xff)) {
+ printk("ttyS%d: LSR safety check engaged!\n", up->port.line);
+ return -ENODEV;
+ }
/*
- * Finally, enable interrupts
+ * Now, initialize the UART
*/
- info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
- serial_outp(info, UART_IER, info->IER); /* enable interrupts */
+ serial_outp(up, UART_LCR, UART_LCR_WLEN8);
- /*
- * And clear the interrupt registers again for luck.
- */
- (void)serial_inp(info, UART_LSR);
- (void)serial_inp(info, UART_RX);
- (void)serial_inp(info, UART_IIR);
- (void)serial_inp(info, UART_MSR);
+ spin_lock_irqsave(&up->port.lock, flags);
+
+ up->port.mctrl |= TIOCM_OUT2;
- if (info->tty)
- clear_bit(TTY_IO_ERROR, &info->tty->flags);
- info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
+ sunsu_set_mctrl(&up->port, up->port.mctrl);
+ spin_unlock_irqrestore(&up->port.lock, flags);
/*
- * Set up the tty->alt_speed kludge
+ * Finally, enable interrupts. Note: Modem status interrupts
+ * are set via change_speed(), which will be occuring imminently
+ * anyway, so we don't enable them here.
*/
- if (info->tty) {
- if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
- info->tty->alt_speed = 57600;
- if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
- info->tty->alt_speed = 115200;
- if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
- info->tty->alt_speed = 230400;
- if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
- info->tty->alt_speed = 460800;
+ up->ier = UART_IER_RLSI | UART_IER_RDI;
+ serial_outp(up, UART_IER, up->ier);
+
+ if (up->port.flags & ASYNC_FOURPORT) {
+ unsigned int icp;
+ /*
+ * Enable interrupts on the AST Fourport board
+ */
+ icp = (up->port.iobase & 0xfe0) | 0x01f;
+ outb_p(0x80, icp);
+ (void) inb_p(icp);
}
/*
- * and set the speed of the serial port
+ * And clear the interrupt registers again for luck.
*/
- change_speed(info, 0);
+ (void) serial_inp(up, UART_LSR);
+ (void) serial_inp(up, UART_RX);
+ (void) serial_inp(up, UART_IIR);
+ (void) serial_inp(up, UART_MSR);
- info->flags |= ASYNC_INITIALIZED;
- restore_flags(flags);
return 0;
-
-errout:
- restore_flags(flags);
- return retval;
}
-/*
- * This routine will shutdown a serial port; interrupts are disabled, and
- * DTR is dropped if the hangup on close termio flag is on.
- */
-static void
-shutdown(struct su_struct *info)
+static void sunsu_shutdown(struct uart_port *port)
{
- unsigned long flags;
+ struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
+ unsigned long flags;
- if (!(info->flags & ASYNC_INITIALIZED))
- return;
+ /*
+ * Disable interrupts from this port
+ */
+ up->ier = 0;
+ serial_outp(up, UART_IER, 0);
+
+ spin_lock_irqsave(&up->port.lock, flags);
+ if (up->port.flags & ASYNC_FOURPORT) {
+ /* reset interrupts on the AST Fourport board */
+ inb((up->port.iobase & 0xfe0) | 0x1f);
+ up->port.mctrl |= TIOCM_OUT1;
+ } else
+ up->port.mctrl &= ~TIOCM_OUT2;
- save_flags(flags); cli(); /* Disable interrupts */
+ sunsu_set_mctrl(&up->port, up->port.mctrl);
+ spin_unlock_irqrestore(&up->port.lock, flags);
/*
- * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
- * here so the queue might never be waken up
+ * Disable break condition and FIFOs
*/
- wake_up_interruptible(&info->delta_msr_wait);
-
+ serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC);
+ serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
+ UART_FCR_CLEAR_RCVR |
+ UART_FCR_CLEAR_XMIT);
+ serial_outp(up, UART_FCR, 0);
+
+#ifdef CONFIG_SERIAL_8250_RSA
/*
- * Free the IRQ, if necessary
+ * Reset the RSA board back to 115kbps compat mode.
*/
- free_irq(info->irq, info);
-
- if (info->xmit_buf) {
- free_page((unsigned long) info->xmit_buf);
- info->xmit_buf = 0;
- }
-
- info->IER = 0;
- serial_outp(info, UART_IER, 0x00); /* disable all intrs */
- info->MCR &= ~UART_MCR_OUT2;
-
- /* disable break condition */
- serial_out(info, UART_LCR, serial_inp(info, UART_LCR) & ~UART_LCR_SBC);
-
- if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
- info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
- serial_outp(info, UART_MCR, info->MCR);
-
- /* disable FIFO's */
- serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR |
- UART_FCR_CLEAR_XMIT));
- (void)serial_in(info, UART_RX); /* read data port to reset things */
-
- if (info->tty)
- set_bit(TTY_IO_ERROR, &info->tty->flags);
-
- if (uart_config[info->type].flags & UART_STARTECH) {
- /* Arrange to enter sleep mode */
- serial_outp(info, UART_LCR, 0xBF);
- serial_outp(info, UART_EFR, UART_EFR_ECB);
- serial_outp(info, UART_IER, UART_IERX_SLEEP);
- serial_outp(info, UART_LCR, 0);
- }
- if (info->type == PORT_16750) {
- /* Arrange to enter sleep mode */
- serial_outp(info, UART_IER, UART_IERX_SLEEP);
- }
- info->flags &= ~ASYNC_INITIALIZED;
- restore_flags(flags);
-}
-
-static int
-su_get_baud_rate(struct su_struct *info)
-{
- static struct tty_struct c_tty;
- static struct termios c_termios;
-
- if (info->tty)
- return tty_get_baud_rate(info->tty);
-
- memset(&c_tty, 0, sizeof(c_tty));
- memset(&c_termios, 0, sizeof(c_termios));
- c_tty.termios = &c_termios;
- c_termios.c_cflag = info->cflag;
+ disable_rsa(up);
+#endif
- return tty_get_baud_rate(&c_tty);
+ /*
+ * Read data port to reset things.
+ */
+ (void) serial_in(up, UART_RX);
}
-/*
- * This routine is called to set the UART divisor registers to match
- * the specified baud rate for a serial port.
- */
static void
-change_speed(struct su_struct *info,
- struct termios *old_termios)
+sunsu_change_speed(struct uart_port *port, unsigned int cflag,
+ unsigned int iflag, unsigned int quot)
{
- int quot = 0, baud;
- unsigned int cval, fcr = 0;
- int bits;
- unsigned long flags;
-
- if (info->port_type == SU_PORT_PORT) {
- if (!info->tty || !info->tty->termios)
- return;
- if (!info->port)
- return;
- info->cflag = info->tty->termios->c_cflag;
- }
+ struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
+ unsigned char cval, fcr = 0;
+ unsigned long flags;
- /* byte size and parity */
- switch (info->cflag & CSIZE) {
- case CS5: cval = 0x00; bits = 7; break;
- case CS6: cval = 0x01; bits = 8; break;
- case CS7: cval = 0x02; bits = 9; break;
- case CS8: cval = 0x03; bits = 10; break;
- /* Never happens, but GCC is too dumb to figure it out */
- default: cval = 0x00; bits = 7; break;
+ switch (cflag & CSIZE) {
+ case CS5:
+ cval = 0x00;
+ break;
+ case CS6:
+ cval = 0x01;
+ break;
+ case CS7:
+ cval = 0x02;
+ break;
+ default:
+ case CS8:
+ cval = 0x03;
+ break;
}
- if (info->cflag & CSTOPB) {
+
+ if (cflag & CSTOPB)
cval |= 0x04;
- bits++;
- }
- if (info->cflag & PARENB) {
+ if (cflag & PARENB)
cval |= UART_LCR_PARITY;
- bits++;
- }
- if (!(info->cflag & PARODD))
+ if (!(cflag & PARODD))
cval |= UART_LCR_EPAR;
#ifdef CMSPAR
- if (info->cflag & CMSPAR)
+ if (cflag & CMSPAR)
cval |= UART_LCR_SPAR;
#endif
- /* Determine divisor based on baud rate */
- baud = su_get_baud_rate(info);
- if (baud == 38400 &&
- ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
- quot = info->custom_divisor;
- else {
- if (baud == 134)
- /* Special case since 134 is really 134.5 */
- quot = (2 * info->baud_base / 269);
- else if (baud)
- quot = info->baud_base / baud;
- }
- /* If the quotient is zero refuse the change */
- if (!quot && old_termios) {
- info->tty->termios->c_cflag &= ~CBAUD;
- info->tty->termios->c_cflag |= (old_termios->c_cflag & CBAUD);
- baud = tty_get_baud_rate(info->tty);
- if (!baud)
- baud = 9600;
- if (baud == 38400 &&
- ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
- quot = info->custom_divisor;
- else {
- if (baud == 134)
- /* Special case since 134 is really 134.5 */
- quot = (2*info->baud_base / 269);
- else if (baud)
- quot = info->baud_base / baud;
- }
- }
- /* As a last resort, if the quotient is zero, default to 9600 bps */
- if (!quot)
- quot = info->baud_base / 9600;
- info->timeout = ((info->xmit_fifo_size*HZ*bits*quot) / info->baud_base);
- info->timeout += HZ/50; /* Add .02 seconds of slop */
-
- /* Set up FIFO's */
- if (uart_config[info->type].flags & UART_USE_FIFO) {
- if ((info->baud_base / quot) < 9600)
+ /*
+ * Work around a bug in the Oxford Semiconductor 952 rev B
+ * chip which causes it to seriously miscalculate baud rates
+ * when DLL is 0.
+ */
+ if ((quot & 0xff) == 0 && up->port.type == PORT_16C950 &&
+ up->rev == 0x5201)
+ quot ++;
+
+ if (uart_config[up->port.type].flags & UART_USE_FIFO) {
+ if ((up->port.uartclk / quot) < (2400 * 16))
fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
+#ifdef CONFIG_SERIAL_8250_RSA
+ else if (up->port.type == PORT_RSA)
+ fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_14;
+#endif
else
fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_8;
}
- if (info->type == PORT_16750)
+ if (up->port.type == PORT_16750)
fcr |= UART_FCR7_64BYTE;
- /* CTS flow control flag and modem status interrupts */
- info->IER &= ~UART_IER_MSI;
- if (info->flags & ASYNC_HARDPPS_CD)
- info->IER |= UART_IER_MSI;
- if (info->cflag & CRTSCTS) {
- info->flags |= ASYNC_CTS_FLOW;
- info->IER |= UART_IER_MSI;
- } else
- info->flags &= ~ASYNC_CTS_FLOW;
- if (info->cflag & CLOCAL)
- info->flags &= ~ASYNC_CHECK_CD;
- else {
- info->flags |= ASYNC_CHECK_CD;
- info->IER |= UART_IER_MSI;
- }
- serial_out(info, UART_IER, info->IER);
+ up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
+ if (iflag & INPCK)
+ up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
+ if (iflag & (BRKINT | PARMRK))
+ up->port.read_status_mask |= UART_LSR_BI;
/*
- * Set up parity check flag
+ * Characteres to ignore
*/
- if (info->tty) {
-#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
-
- info->read_status_mask = UART_LSR_OE | UART_LSR_THRE |
- UART_LSR_DR;
- if (I_INPCK(info->tty))
- info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
- if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
- info->read_status_mask |= UART_LSR_BI;
-
- /*
- * Characters to ignore
- */
- info->ignore_status_mask = 0;
- if (I_IGNPAR(info->tty))
- info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
- if (I_IGNBRK(info->tty)) {
- info->ignore_status_mask |= UART_LSR_BI;
- /*
- * If we're ignore parity and break indicators, ignore
- * overruns too. (For real raw support).
- */
- if (I_IGNPAR(info->tty))
- info->ignore_status_mask |= UART_LSR_OE;
- }
+ up->port.ignore_status_mask = 0;
+ if (iflag & IGNPAR)
+ up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
+ if (iflag & IGNBRK) {
+ up->port.ignore_status_mask |= UART_LSR_BI;
/*
- * !!! ignore all characters if CREAD is not set
+ * If we're ignoring parity and break indicators,
+ * ignore overruns too (for real raw support).
*/
- if ((info->cflag & CREAD) == 0)
- info->ignore_status_mask |= UART_LSR_DR;
+ if (iflag & IGNPAR)
+ up->port.ignore_status_mask |= UART_LSR_OE;
}
- save_flags(flags); cli();
- if (uart_config[info->type].flags & UART_STARTECH) {
- serial_outp(info, UART_LCR, 0xBF);
- serial_outp(info, UART_EFR,
- (info->cflag & CRTSCTS) ? UART_EFR_CTS : 0);
- }
- serial_outp(info, UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */
- serial_outp(info, UART_DLL, quot & 0xff); /* LS of divisor */
- serial_outp(info, UART_DLM, quot >> 8); /* MS of divisor */
- if (info->type == PORT_16750)
- serial_outp(info, UART_FCR, fcr); /* set fcr */
- serial_outp(info, UART_LCR, cval); /* reset DLAB */
- if (info->type != PORT_16750)
- serial_outp(info, UART_FCR, fcr); /* set fcr */
- restore_flags(flags);
- info->quot = quot;
-}
-
-static void
-su_put_char(struct tty_struct *tty, unsigned char ch)
-{
- struct su_struct *info = (struct su_struct *)tty->driver_data;
- unsigned long flags;
-
- if (serial_paranoia_check(info, tty->device, "su_put_char"))
- return;
+ /*
+ * ignore all characters if CREAD is not set
+ */
+ if ((cflag & CREAD) == 0)
+ up->port.ignore_status_mask |= UART_LSR_DR;
- if (!tty || !info->xmit_buf)
- return;
+ /*
+ * CTS flow control flag and modem status interrupts
+ */
+ up->ier &= ~UART_IER_MSI;
+ if (UART_ENABLE_MS(&up->port, cflag))
+ up->ier |= UART_IER_MSI;
- save_flags(flags); cli();
- if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
- restore_flags(flags);
- return;
+ /*
+ * Ok, we're now changing the port state. Do it with
+ * interrupts disabled.
+ */
+ spin_lock_irqsave(&up->port.lock, flags);
+ serial_out(up, UART_IER, up->ier);
+
+ if (uart_config[up->port.type].flags & UART_STARTECH) {
+ serial_outp(up, UART_LCR, 0xBF);
+ serial_outp(up, UART_EFR, cflag & CRTSCTS ? UART_EFR_CTS :0);
+ }
+ serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */
+ serial_outp(up, UART_DLL, quot & 0xff); /* LS of divisor */
+ serial_outp(up, UART_DLM, quot >> 8); /* MS of divisor */
+ if (up->port.type == PORT_16750)
+ serial_outp(up, UART_FCR, fcr); /* set fcr */
+ serial_outp(up, UART_LCR, cval); /* reset DLAB */
+ up->lcr = cval; /* Save LCR */
+ if (up->port.type != PORT_16750) {
+ if (fcr & UART_FCR_ENABLE_FIFO) {
+ /* emulated UARTs (Lucent Venus 167x) need two steps */
+ serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
+ }
+ serial_outp(up, UART_FCR, fcr); /* set fcr */
}
-
- info->xmit_buf[info->xmit_head++] = ch;
- info->xmit_head &= SERIAL_XMIT_SIZE-1;
- info->xmit_cnt++;
- restore_flags(flags);
+ spin_unlock_irqrestore(&up->port.lock, flags);
}
-static void su_put_char_kbd(unsigned char c)
+static void sunsu_release_port(struct uart_port *port)
{
- struct su_struct *info = su_table;
- int lsr;
-
- if (info->port_type != SU_PORT_KBD)
- ++info;
- if (info->port_type != SU_PORT_KBD)
- return;
-
- do {
- lsr = serial_in(info, UART_LSR);
- } while (!(lsr & UART_LSR_THRE));
-
- /* Send the character out. */
- su_outb(info, UART_TX, c);
}
-static void
-su_change_mouse_baud(int baud)
+static int sunsu_request_port(struct uart_port *port)
{
- struct su_struct *info = su_table;
-
- if (info->port_type != SU_PORT_MS)
- ++info;
- if (info->port_type != SU_PORT_MS)
- return;
-
- info->cflag &= ~CBAUD;
- switch (baud) {
- case 1200:
- info->cflag |= B1200;
- break;
- case 2400:
- info->cflag |= B2400;
- break;
- case 4800:
- info->cflag |= B4800;
- break;
- case 9600:
- info->cflag |= B9600;
- break;
- default:
- printk("su_change_mouse_baud: unknown baud rate %d, "
- "defaulting to 1200\n", baud);
- info->cflag |= 1200;
- break;
- }
- change_speed(info, 0);
+ return 0;
}
-static void
-su_flush_chars(struct tty_struct *tty)
+static void sunsu_config_port(struct uart_port *port, int flags)
{
- struct su_struct *info = (struct su_struct *)tty->driver_data;
- unsigned long flags;
-
- if (serial_paranoia_check(info, tty->device, "su_flush_chars"))
- return;
-
- if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
- !info->xmit_buf)
- return;
-
- save_flags(flags); cli();
- info->IER |= UART_IER_THRI;
- serial_out(info, UART_IER, info->IER);
- restore_flags(flags);
}
static int
-su_write(struct tty_struct * tty, int from_user,
- const unsigned char *buf, int count)
+sunsu_verify_port(struct uart_port *port, struct serial_struct *ser)
{
- int c, ret = 0;
- struct su_struct *info = (struct su_struct *)tty->driver_data;
- unsigned long flags;
-
- if (serial_paranoia_check(info, tty->device, "su_write"))
- return 0;
-
- if (!tty || !info->xmit_buf || !tmp_buf)
- return 0;
-
- save_flags(flags);
- if (from_user) {
- down(&tmp_buf_sem);
- while (1) {
- c = MIN(count,
- MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
- SERIAL_XMIT_SIZE - info->xmit_head));
- if (c <= 0)
- break;
-
- c -= copy_from_user(tmp_buf, buf, c);
- if (!c) {
- if (!ret)
- ret = -EFAULT;
- break;
- }
- cli();
- c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
- SERIAL_XMIT_SIZE - info->xmit_head));
- memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
- info->xmit_head = ((info->xmit_head + c) &
- (SERIAL_XMIT_SIZE-1));
- info->xmit_cnt += c;
- restore_flags(flags);
- buf += c;
- count -= c;
- ret += c;
- }
- up(&tmp_buf_sem);
- } else {
- while (1) {
- cli();
- c = MIN(count,
- MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
- SERIAL_XMIT_SIZE - info->xmit_head));
- if (c <= 0) {
- restore_flags(flags);
- break;
- }
- memcpy(info->xmit_buf + info->xmit_head, buf, c);
- info->xmit_head = ((info->xmit_head + c) &
- (SERIAL_XMIT_SIZE-1));
- info->xmit_cnt += c;
- restore_flags(flags);
- buf += c;
- count -= c;
- ret += c;
- }
- }
- if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
- !(info->IER & UART_IER_THRI)) {
- info->IER |= UART_IER_THRI;
- serial_out(info, UART_IER, info->IER);
- }
- return ret;
+ return -EINVAL;
}
-static int
-su_write_room(struct tty_struct *tty)
+static const char *
+sunsu_type(struct uart_port *port)
{
- struct su_struct *info = (struct su_struct *)tty->driver_data;
- int ret;
+ int type = port->type;
- if (serial_paranoia_check(info, tty->device, "su_write_room"))
- return 0;
- ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
- if (ret < 0)
- ret = 0;
- return ret;
+ if (type >= ARRAY_SIZE(uart_config))
+ type = 0;
+ return uart_config[type].name;
}
-static int
-su_chars_in_buffer(struct tty_struct *tty)
-{
- struct su_struct *info = (struct su_struct *)tty->driver_data;
-
- if (serial_paranoia_check(info, tty->device, "su_chars_in_buffer"))
- return 0;
- return info->xmit_cnt;
-}
+static struct uart_ops sunsu_pops = {
+ .tx_empty = sunsu_tx_empty,
+ .set_mctrl = sunsu_set_mctrl,
+ .get_mctrl = sunsu_get_mctrl,
+ .stop_tx = sunsu_stop_tx,
+ .start_tx = sunsu_start_tx,
+ .stop_rx = sunsu_stop_rx,
+ .enable_ms = sunsu_enable_ms,
+ .break_ctl = sunsu_break_ctl,
+ .startup = sunsu_startup,
+ .shutdown = sunsu_shutdown,
+ .change_speed = sunsu_change_speed,
+ .pm = sunsu_pm,
+ .type = sunsu_type,
+ .release_port = sunsu_release_port,
+ .request_port = sunsu_request_port,
+ .config_port = sunsu_config_port,
+ .verify_port = sunsu_verify_port,
+};
-static void
-su_flush_buffer(struct tty_struct *tty)
-{
- struct su_struct *info = (struct su_struct *)tty->driver_data;
- unsigned long flags;
+#define UART_NR 4
- if (serial_paranoia_check(info, tty->device, "su_flush_buffer"))
- return;
- save_flags(flags); cli();
- info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
- restore_flags(flags);
- wake_up_interruptible(&tty->write_wait);
- if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
- tty->ldisc.write_wakeup)
- (tty->ldisc.write_wakeup)(tty);
-}
+static struct uart_sunsu_port sunsu_ports[UART_NR];
-/*
- * This function is used to send a high-priority XON/XOFF character to
- * the device
- */
-static void
-su_send_xchar(struct tty_struct *tty, char ch)
-{
- struct su_struct *info = (struct su_struct *)tty->driver_data;
-
- if (serial_paranoia_check(info, tty->device, "su_send_char"))
- return;
+#ifdef CONFIG_SERIO
- if (!(info->flags & ASYNC_INITIALIZED))
- return;
-
- info->x_char = ch;
- if (ch) {
- /* Make sure transmit interrupts are on */
- info->IER |= UART_IER_THRI;
- serial_out(info, UART_IER, info->IER);
- }
-}
+static spinlock_t sunsu_serio_lock = SPIN_LOCK_UNLOCKED;
-/*
- * ------------------------------------------------------------
- * su_throttle()
- *
- * This routine is called by the upper-layer tty layer to signal that
- * incoming characters should be throttled.
- * ------------------------------------------------------------
- */
-static void
-su_throttle(struct tty_struct * tty)
+static void sunsu_serio_write(struct serio *serio, unsigned char ch)
{
- struct su_struct *info = (struct su_struct *)tty->driver_data;
+ struct uart_sunsu_port *up = serio->driver;
unsigned long flags;
-#ifdef SERIAL_DEBUG_THROTTLE
- char buf[64];
-
- printk("throttle %s: %d....\n", tty_name(tty, buf),
- tty->ldisc.chars_in_buffer(tty));
-#endif
+ int lsr;
- if (serial_paranoia_check(info, tty->device, "su_throttle"))
- return;
+ spin_lock_irqsave(&sunsu_serio_lock, flags);
- if (I_IXOFF(tty))
- su_send_xchar(tty, STOP_CHAR(tty));
+ do {
+ lsr = serial_in(up, UART_LSR);
+ } while (!(lsr & UART_LSR_THRE));
- if (tty->termios->c_cflag & CRTSCTS)
- info->MCR &= ~UART_MCR_RTS;
+ /* Send the character out. */
+ sunsu_writeb(up, UART_TX, c);
- save_flags(flags); cli();
- serial_out(info, UART_MCR, info->MCR);
- restore_flags(flags);
+ spin_unlock_irqrestore(&sunsu_serio_lock, flags);
}
-static void
-su_unthrottle(struct tty_struct * tty)
+static int sunsu_serio_open(struct serio *serio)
{
- struct su_struct *info = (struct su_struct *)tty->driver_data;
unsigned long flags;
-#ifdef SERIAL_DEBUG_THROTTLE
- char buf[64];
-
- printk("unthrottle %s: %d....\n", tty_name(tty, buf),
- tty->ldisc.chars_in_buffer(tty));
-#endif
+ int ret;
- if (serial_paranoia_check(info, tty->device, "su_unthrottle"))
- return;
-
- if (I_IXOFF(tty)) {
- if (info->x_char)
- info->x_char = 0;
- else
- su_send_xchar(tty, START_CHAR(tty));
- }
- if (tty->termios->c_cflag & CRTSCTS)
- info->MCR |= UART_MCR_RTS;
- save_flags(flags); cli();
- serial_out(info, UART_MCR, info->MCR);
- restore_flags(flags);
-}
-
-/*
- * ------------------------------------------------------------
- * su_ioctl() and friends
- * ------------------------------------------------------------
- */
-
-/*
- * get_serial_info - handle TIOCGSERIAL ioctl()
- *
- * Purpose: Return standard serial struct information about
- * a serial port handled by this driver.
- *
- * Added: 11-May-2001 Lars Kellogg-Stedman <lars@larsshack.org>
- */
-static int get_serial_info(struct su_struct * info,
- struct serial_struct * retinfo)
-{
- struct serial_struct tmp;
-
- if (!retinfo)
- return -EFAULT;
- memset(&tmp, 0, sizeof(tmp));
-
- tmp.type = info->type;
- tmp.line = info->line;
- tmp.port = info->port;
- tmp.irq = info->irq;
- tmp.flags = info->flags;
- tmp.xmit_fifo_size = info->xmit_fifo_size;
- tmp.baud_base = info->baud_base;
- tmp.close_delay = info->close_delay;
- tmp.closing_wait = info->closing_wait;
- tmp.custom_divisor = info->custom_divisor;
- tmp.hub6 = 0;
-
- if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
- return -EFAULT;
+ spin_lock_irqsave(&sunsu_serio_lock, flags);
+ if (serio->private == NULL) {
+ serio->private = (void *) -1L;
+ ret = 0;
+ } else
+ ret = -EBUSY;
+ spin_unlock_irqrestore(&sunsu_serio_lock, flags);
- return 0;
+ return ret;
}
-/*
- * get_lsr_info - get line status register info
- *
- * Purpose: Let user call ioctl() to get info when the UART physically
- * is emptied. On bus types like RS485, the transmitter must
- * release the bus after transmitting. This must be done when
- * the transmit shift register is empty, not be done when the
- * transmit holding register is empty. This functionality
- * allows an RS485 driver to be written in user space.
- */
-static int
-get_lsr_info(struct su_struct * info, unsigned int *value)
+static void sunsu_serio_close(struct serio *serio)
{
- unsigned char status;
- unsigned int result;
unsigned long flags;
- save_flags(flags); cli();
- status = serial_in(info, UART_LSR);
- restore_flags(flags);
- result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
- return put_user(result,value);
+ spin_lock_irqsave(&sunsu_serio_lock, flags);
+ serio->private = NULL;
+ spin_unlock_irqrestore(&sunsu_serio_lock, flags);
}
+#endif /* CONFIG_SERIO */
-static int
-get_modem_info(struct su_struct * info, unsigned int *value)
+static void sunsu_autoconfig(struct uart_sunsu_port *up)
{
- unsigned char control, status;
- unsigned int result;
- unsigned long flags;
-
- control = info->MCR;
- save_flags(flags); cli();
- status = serial_in(info, UART_MSR);
- restore_flags(flags);
- result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
- | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
-#ifdef TIOCM_OUT1
- | ((control & UART_MCR_OUT1) ? TIOCM_OUT1 : 0)
- | ((control & UART_MCR_OUT2) ? TIOCM_OUT2 : 0)
-#endif
- | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
- | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
- | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
- | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
- return put_user(result,value);
-}
-
-static int
-set_modem_info(struct su_struct * info, unsigned int cmd, unsigned int *value)
-{
- unsigned int arg;
- unsigned long flags;
-
- if (get_user(arg, value))
- return -EFAULT;
- switch (cmd) {
- case TIOCMBIS:
- if (arg & TIOCM_RTS)
- info->MCR |= UART_MCR_RTS;
- if (arg & TIOCM_DTR)
- info->MCR |= UART_MCR_DTR;
-#ifdef TIOCM_OUT1
- if (arg & TIOCM_OUT1)
- info->MCR |= UART_MCR_OUT1;
- if (arg & TIOCM_OUT2)
- info->MCR |= UART_MCR_OUT2;
-#endif
- break;
- case TIOCMBIC:
- if (arg & TIOCM_RTS)
- info->MCR &= ~UART_MCR_RTS;
- if (arg & TIOCM_DTR)
- info->MCR &= ~UART_MCR_DTR;
-#ifdef TIOCM_OUT1
- if (arg & TIOCM_OUT1)
- info->MCR &= ~UART_MCR_OUT1;
- if (arg & TIOCM_OUT2)
- info->MCR &= ~UART_MCR_OUT2;
-#endif
- break;
- case TIOCMSET:
- info->MCR = ((info->MCR & ~(UART_MCR_RTS |
-#ifdef TIOCM_OUT1
- UART_MCR_OUT1 |
- UART_MCR_OUT2 |
+ unsigned char status1, status2, scratch, scratch2, scratch3;
+ unsigned char save_lcr, save_mcr;
+ struct linux_ebus_device *dev = 0;
+ struct linux_ebus *ebus;
+#ifdef CONFIG_SPARC64
+ struct isa_bridge *isa_br;
+ struct isa_device *isa_dev;
#endif
- UART_MCR_DTR))
- | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
-#ifdef TIOCM_OUT1
- | ((arg & TIOCM_OUT1) ? UART_MCR_OUT1 : 0)
- | ((arg & TIOCM_OUT2) ? UART_MCR_OUT2 : 0)
+#ifndef CONFIG_SPARC64
+ struct linux_prom_registers reg0;
#endif
- | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
- break;
- default:
- return -EINVAL;
- }
- save_flags(flags); cli();
- serial_out(info, UART_MCR, info->MCR);
- restore_flags(flags);
- return 0;
-}
-
-/*
- * su_break() --- routine which turns the break handling on or off
- */
-static void
-su_break(struct tty_struct *tty, int break_state)
-{
- struct su_struct * info = (struct su_struct *)tty->driver_data;
unsigned long flags;
-
- if (serial_paranoia_check(info, tty->device, "su_break"))
- return;
- if (!info->port)
+ if (!up->port_node || !up->port_type)
return;
- save_flags(flags); cli();
- if (break_state == -1)
- serial_out(info, UART_LCR,
- serial_inp(info, UART_LCR) | UART_LCR_SBC);
- else
- serial_out(info, UART_LCR,
- serial_inp(info, UART_LCR) & ~UART_LCR_SBC);
- restore_flags(flags);
-}
-
-static int
-su_ioctl(struct tty_struct *tty, struct file * file,
- unsigned int cmd, unsigned long arg)
-{
- struct su_struct * info = (struct su_struct *)tty->driver_data;
- struct async_icount cprev, cnow; /* kernel counter temps */
- struct serial_icounter_struct *p_cuser; /* user space */
-
- if (serial_paranoia_check(info, tty->device, "su_ioctl"))
- return -ENODEV;
-
- if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
- (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
- (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
- if (tty->flags & (1 << TTY_IO_ERROR))
- return -EIO;
- }
- switch (cmd) {
- case TIOCMGET:
- return get_modem_info(info, (unsigned int *) arg);
- case TIOCMBIS:
- case TIOCMBIC:
- case TIOCMSET:
- return set_modem_info(info, cmd, (unsigned int *) arg);
-
- case TIOCGSERIAL:
- return get_serial_info(info, (struct serial_struct *)arg);
-
- case TIOCSERGETLSR: /* Get line status register */
- return get_lsr_info(info, (unsigned int *) arg);
-
-#if 0
- case TIOCSERGSTRUCT:
- if (copy_to_user((struct async_struct *) arg,
- info, sizeof(struct async_struct)))
- return -EFAULT;
- return 0;
-#endif
-
- /*
- * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
- * - mask passed in arg for lines of interest
- * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
- * Caller should use TIOCGICOUNT to see which one it was
- */
- case TIOCMIWAIT:
- cli();
- /* note the counters on entry */
- cprev = info->icount;
- sti();
- while (1) {
- interruptible_sleep_on(&info->delta_msr_wait);
- /* see if a signal did it */
- if (signal_pending(current))
- return -ERESTARTSYS;
- cli();
- cnow = info->icount; /* atomic copy */
- sti();
- if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
- cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
- return -EIO; /* no change => error */
- if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
- ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
- ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
- ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
- return 0;
- }
- cprev = cnow;
+ /*
+ * First we look for Ebus-bases su's
+ */
+ for_each_ebus(ebus) {
+ for_each_ebusdev(dev, ebus) {
+ if (dev->prom_node == up->port_node) {
+ up->port.membase = (char *) dev->resource[0].start;
+ up->irq = dev->irqs[0];
+ goto ebus_done;
}
- /* NOTREACHED */
-
- /*
- * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
- * Return: write counters to the user passed counter struct
- * NB: both 1->0 and 0->1 transitions are counted except for
- * RI where only 0->1 is counted.
- */
- case TIOCGICOUNT:
- cli();
- cnow = info->icount;
- sti();
- p_cuser = (struct serial_icounter_struct *) arg;
- if (put_user(cnow.cts, &p_cuser->cts) ||
- put_user(cnow.dsr, &p_cuser->dsr) ||
- put_user(cnow.rng, &p_cuser->rng) ||
- put_user(cnow.dcd, &p_cuser->dcd))
- return -EFAULT;
- return 0;
-
- default:
- return -ENOIOCTLCMD;
}
- /* return 0; */ /* Trigger warnings if fall through by a chance. */
-}
-
-static void
-su_set_termios(struct tty_struct *tty, struct termios *old_termios)
-{
- struct su_struct *info = (struct su_struct *)tty->driver_data;
- unsigned long flags;
-
- if ( (tty->termios->c_cflag == old_termios->c_cflag)
- && ( RELEVANT_IFLAG(tty->termios->c_iflag)
- == RELEVANT_IFLAG(old_termios->c_iflag)))
- return;
-
- change_speed(info, old_termios);
-
- /* Handle transition to B0 status */
- if ((old_termios->c_cflag & CBAUD) &&
- !(tty->termios->c_cflag & CBAUD)) {
- info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
- save_flags(flags); cli();
- serial_out(info, UART_MCR, info->MCR);
- restore_flags(flags);
}
- /* Handle transition away from B0 status */
- if (!(old_termios->c_cflag & CBAUD) &&
- (tty->termios->c_cflag & CBAUD)) {
- info->MCR |= UART_MCR_DTR;
- if (!(tty->termios->c_cflag & CRTSCTS) ||
- !test_bit(TTY_THROTTLED, &tty->flags)) {
- info->MCR |= UART_MCR_RTS;
+#ifdef CONFIG_SPARC64
+ for_each_isa(isa_br) {
+ for_each_isadev(isa_dev, isa_br) {
+ if (isa_dev->prom_node == up->port_node) {
+ up->port.membase = (char *) isa_dev->resource.start;
+ up->irq = isa_dev->irq;
+ goto ebus_done;
+ }
}
- save_flags(flags); cli();
- serial_out(info, UART_MCR, info->MCR);
- restore_flags(flags);
}
-
- /* Handle turning off CRTSCTS */
- if ((old_termios->c_cflag & CRTSCTS) &&
- !(tty->termios->c_cflag & CRTSCTS)) {
- tty->hw_stopped = 0;
- su_start(tty);
- }
-
-#if 0
- /*
- * No need to wake up processes in open wait, since they
- * sample the CLOCAL flag once, and don't recheck it.
- * XXX It's not clear whether the current behavior is correct
- * or not. Hence, this may change.....
- */
- if (!(old_termios->c_cflag & CLOCAL) &&
- (tty->termios->c_cflag & CLOCAL))
- wake_up_interruptible(&info->open_wait);
#endif
-}
-/*
- * ------------------------------------------------------------
- * su_close()
- *
- * This routine is called when the serial port gets closed. First, we
- * wait for the last remaining data to be sent. Then, we unlink its
- * async structure from the interrupt chain if necessary, and we free
- * that IRQ if nothing is left in the chain.
- * ------------------------------------------------------------
- */
-static void
-su_close(struct tty_struct *tty, struct file * filp)
-{
- struct su_struct *info = (struct su_struct *)tty->driver_data;
- unsigned long flags;
-
- if (!info || serial_paranoia_check(info, tty->device, "su_close"))
- return;
-
- save_flags(flags); cli();
-
- if (tty_hung_up_p(filp)) {
- DBG_CNT("before DEC-hung");
- MOD_DEC_USE_COUNT;
- restore_flags(flags);
- return;
- }
-
-#ifdef SERIAL_DEBUG_OPEN
- printk("su_close ttys%d, count = %d\n", info->line, info->count);
-#endif
- if ((tty->count == 1) && (info->count != 1)) {
- /*
- * Uh, oh. tty->count is 1, which means that the tty
- * structure will be freed. info->count should always
- * be one in these conditions. If it's greater than
- * one, we've got real problems, since it means the
- * serial port won't be shutdown.
- */
- printk("su_close: bad serial port count; tty->count is 1, "
- "info->count is %d\n", info->count);
- info->count = 1;
- }
- if (--info->count < 0) {
- printk("su_close: bad serial port count for ttys%d: %d\n",
- info->line, info->count);
- info->count = 0;
- }
- if (info->count) {
- DBG_CNT("before DEC-2");
- MOD_DEC_USE_COUNT;
- restore_flags(flags);
- return;
- }
- info->flags |= ASYNC_CLOSING;
- /*
- * Save the termios structure, since this port may have
- * separate termios for callout and dialin.
- */
- if (info->flags & ASYNC_NORMAL_ACTIVE)
- info->normal_termios = *tty->termios;
- if (info->flags & ASYNC_CALLOUT_ACTIVE)
- info->callout_termios = *tty->termios;
+#ifdef CONFIG_SPARC64
/*
- * Now we wait for the transmit buffer to clear; and we notify
- * the line discipline to only process XON/XOFF characters.
+ * Not on Ebus, bailing.
*/
- tty->closing = 1;
- if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
- tty_wait_until_sent(tty, info->closing_wait);
+ return;
+#else
/*
- * At this point we stop accepting input. To do this, we
- * disable the receive line status interrupts, and tell the
- * interrupt driver to stop checking the data ready bit in the
- * line status register.
+ * Not on Ebus, must be OBIO.
*/
- info->IER &= ~UART_IER_RLSI;
- info->read_status_mask &= ~UART_LSR_DR;
- if (info->flags & ASYNC_INITIALIZED) {
- serial_out(info, UART_IER, info->IER);
- /*
- * Before we drop DTR, make sure the UART transmitter
- * has completely drained; this is especially
- * important if there is a transmit FIFO!
- */
- su_wait_until_sent(tty, info->timeout);
- }
- shutdown(info);
- if (tty->driver.flush_buffer)
- tty->driver.flush_buffer(tty);
- if (tty->ldisc.flush_buffer)
- tty->ldisc.flush_buffer(tty);
- tty->closing = 0;
- info->event = 0;
- info->tty = 0;
- if (info->blocked_open) {
- if (info->close_delay) {
- current->state = TASK_INTERRUPTIBLE;
- schedule_timeout(info->close_delay);
- }
- wake_up_interruptible(&info->open_wait);
+ if (prom_getproperty(up->port_node, "reg",
+ (char *)®0, sizeof(reg0)) == -1) {
+ prom_printf("sunsu: no \"reg\" property\n");
+ return;
}
- info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
- ASYNC_CLOSING);
- wake_up_interruptible(&info->close_wait);
- MOD_DEC_USE_COUNT;
- restore_flags(flags);
-}
-
-/*
- * su_wait_until_sent() --- wait until the transmitter is empty
- */
-static void
-su_wait_until_sent(struct tty_struct *tty, int timeout)
-{
- struct su_struct * info = (struct su_struct *)tty->driver_data;
- unsigned long orig_jiffies, char_time;
- int lsr;
-
- if (serial_paranoia_check(info, tty->device, "su_wait_until_sent"))
+ prom_apply_obio_ranges(®0, 1);
+ if (reg0.which_io != 0) { /* Just in case... */
+ prom_printf("sunsu: bus number nonzero: 0x%x:%x\n",
+ reg0.which_io, reg0.phys_addr);
return;
-
- if (info->type == PORT_UNKNOWN)
+ }
+ if ((up->port.membase = ioremap(reg0.phys_addr, reg0.reg_size)) == 0) {
+ prom_printf("sunsu: Cannot map registers.\n");
return;
+ }
- if (info->xmit_fifo_size == 0)
- return; /* Just in case ... */
-
- orig_jiffies = jiffies;
/*
- * Set the check interval to be 1/5 of the estimated time to
- * send a single character, and make it at least 1. The check
- * interval should also be less than the timeout.
- *
- * Note: we have to use pretty tight timings here to satisfy
- * the NIST-PCTS.
+ * 0x20 is sun4m thing, Dave Redman heritage.
+ * See arch/sparc/kernel/irq.c.
*/
- char_time = (info->timeout - HZ/50) / info->xmit_fifo_size;
- char_time = char_time / 5;
- if (char_time == 0)
- char_time = 1;
- if (timeout)
- char_time = MIN(char_time, timeout);
-#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
- printk("In su_wait_until_sent(%d) check=%lu...", timeout, char_time);
- printk("jiff=%lu...", jiffies);
-#endif
- while (!((lsr = serial_inp(info, UART_LSR)) & UART_LSR_TEMT)) {
-#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
- printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
-#endif
- current->state = TASK_INTERRUPTIBLE;
- schedule_timeout(char_time);
- if (signal_pending(current))
- break;
- if (timeout && time_after(jiffies, orig_jiffies + timeout))
- break;
- }
-#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
- printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
-#endif
-}
-
-/*
- * su_hangup() --- called by tty_hangup() when a hangup is signaled.
- */
-static void
-su_hangup(struct tty_struct *tty)
-{
- struct su_struct * info = (struct su_struct *)tty->driver_data;
-
- if (serial_paranoia_check(info, tty->device, "su_hangup"))
- return;
-
- su_flush_buffer(tty);
- shutdown(info);
- info->event = 0;
- info->count = 0;
- info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
- info->tty = 0;
- wake_up_interruptible(&info->open_wait);
-}
-
-/*
- * ------------------------------------------------------------
- * su_open() and friends
- * ------------------------------------------------------------
- */
-static int
-block_til_ready(struct tty_struct *tty, struct file * filp,
- struct su_struct *info)
-{
- DECLARE_WAITQUEUE(wait, current);
- int retval;
- int do_clocal = 0, extra_count = 0;
- unsigned long flags;
+#define IRQ_4M(n) ((n)|0x20)
/*
- * If the device is in the middle of being closed, then block
- * until it's done, and then try again.
+ * There is no intr property on MrCoffee, so hardwire it.
*/
- if (tty_hung_up_p(filp) ||
- (info->flags & ASYNC_CLOSING)) {
- if (info->flags & ASYNC_CLOSING)
- interruptible_sleep_on(&info->close_wait);
-#ifdef SERIAL_DO_RESTART
- return ((info->flags & ASYNC_HUP_NOTIFY) ?
- -EAGAIN : -ERESTARTSYS);
-#else
- return -EAGAIN;
+ up->irq = IRQ_4M(13);
#endif
- }
- /*
- * If this is a callout device, then just make sure the normal
- * device isn't being used.
- */
- if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
- if (info->flags & ASYNC_NORMAL_ACTIVE)
- return -EBUSY;
- if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
- (info->flags & ASYNC_SESSION_LOCKOUT) &&
- (info->session != current->session))
- return -EBUSY;
- if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
- (info->flags & ASYNC_PGRP_LOCKOUT) &&
- (info->pgrp != current->pgrp))
- return -EBUSY;
- info->flags |= ASYNC_CALLOUT_ACTIVE;
- return 0;
- }
+ebus_done:
- /*
- * If non-blocking mode is set, or the port is not enabled,
- * then make the check up front and then exit.
- */
- if ((filp->f_flags & O_NONBLOCK) ||
- (tty->flags & (1 << TTY_IO_ERROR))) {
- if (info->flags & ASYNC_CALLOUT_ACTIVE)
- return -EBUSY;
- info->flags |= ASYNC_NORMAL_ACTIVE;
- return 0;
- }
+ spin_lock_irqsave(&up->port.lock, flags);
- if (info->flags & ASYNC_CALLOUT_ACTIVE) {
- if (info->normal_termios.c_cflag & CLOCAL)
- do_clocal = 1;
- } else {
- if (tty->termios->c_cflag & CLOCAL)
- do_clocal = 1;
- }
-
- /*
- * Block waiting for the carrier detect and the line to become
- * free (i.e., not in use by the callout). While we are in
- * this loop, info->count is dropped by one, so that
- * su_close() knows when to free things. We restore it upon
- * exit, either normal or abnormal.
- */
- retval = 0;
- add_wait_queue(&info->open_wait, &wait);
-#ifdef SERIAL_DEBUG_OPEN
- printk("block_til_ready before block: ttys%d, count = %d\n",
- info->line, info->count);
+ if (!(up->port.flags & ASYNC_BUGGY_UART)) {
+ /*
+ * Do a simple existence test first; if we fail this, there's
+ * no point trying anything else.
+ *
+ * 0x80 is used as a nonsense port to prevent against false
+ * positives due to ISA bus float. The assumption is that
+ * 0x80 is a non-existent port; which should be safe since
+ * include/asm/io.h also makes this assumption.
+ */
+ scratch = serial_inp(up, UART_IER);
+ serial_outp(up, UART_IER, 0);
+#ifdef __i386__
+ outb(0xff, 0x080);
#endif
- save_flags(flags); cli();
- if (!tty_hung_up_p(filp)) {
- extra_count = 1;
- info->count--;
- }
- restore_flags(flags);
- info->blocked_open++;
- while (1) {
- save_flags(flags); cli();
- if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
- (tty->termios->c_cflag & CBAUD))
- serial_out(info, UART_MCR,
- serial_inp(info, UART_MCR) |
- (UART_MCR_DTR | UART_MCR_RTS));
- restore_flags(flags);
- set_current_state(TASK_INTERRUPTIBLE);
- if (tty_hung_up_p(filp) ||
- !(info->flags & ASYNC_INITIALIZED)) {
-#ifdef SERIAL_DO_RESTART
- if (info->flags & ASYNC_HUP_NOTIFY)
- retval = -EAGAIN;
- else
- retval = -ERESTARTSYS;
-#else
- retval = -EAGAIN;
+ scratch2 = serial_inp(up, UART_IER);
+ serial_outp(up, UART_IER, 0x0f);
+#ifdef __i386__
+ outb(0, 0x080);
#endif
+ scratch3 = serial_inp(up, UART_IER);
+ serial_outp(up, UART_IER, scratch);
+ if (scratch2 != 0 || scratch3 != 0x0F)
+ goto out; /* We failed; there's nothing here */
+ }
+
+ save_mcr = serial_in(up, UART_MCR);
+ save_lcr = serial_in(up, UART_LCR);
+
+ /*
+ * Check to see if a UART is really there. Certain broken
+ * internal modems based on the Rockwell chipset fail this
+ * test, because they apparently don't implement the loopback
+ * test mode. So this test is skipped on the COM 1 through
+ * COM 4 ports. This *should* be safe, since no board
+ * manufacturer would be stupid enough to design a board
+ * that conflicts with COM 1-4 --- we hope!
+ */
+ if (!(up->port.flags & ASYNC_SKIP_TEST)) {
+ serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A);
+ status1 = serial_inp(up, UART_MSR) & 0xF0;
+ serial_outp(up, UART_MCR, save_mcr);
+ if (status1 != 0x90)
+ goto out; /* We failed loopback test */
+ }
+ serial_outp(up, UART_LCR, 0xBF); /* set up for StarTech test */
+ serial_outp(up, UART_EFR, 0); /* EFR is the same as FCR */
+ serial_outp(up, UART_LCR, 0);
+ serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
+ scratch = serial_in(up, UART_IIR) >> 6;
+ switch (scratch) {
+ case 0:
+ up->port.type = PORT_16450;
break;
- }
- if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
- !(info->flags & ASYNC_CLOSING) &&
- (do_clocal || (serial_in(info, UART_MSR) &
- UART_MSR_DCD)))
+ case 1:
+ up->port.type = PORT_UNKNOWN;
+ break;
+ case 2:
+ up->port.type = PORT_16550;
break;
- if (signal_pending(current)) {
- retval = -ERESTARTSYS;
+ case 3:
+ up->port.type = PORT_16550A;
break;
+ }
+ if (up->port.type == PORT_16550A) {
+ /* Check for Startech UART's */
+ serial_outp(up, UART_LCR, UART_LCR_DLAB);
+ if (serial_in(up, UART_EFR) == 0) {
+ up->port.type = PORT_16650;
+ } else {
+ serial_outp(up, UART_LCR, 0xBF);
+ if (serial_in(up, UART_EFR) == 0)
+ up->port.type = PORT_16650V2;
}
-#ifdef SERIAL_DEBUG_OPEN
- printk("block_til_ready blocking: ttys%d, count = %d\n",
- info->line, info->count);
-#endif
- schedule();
}
- current->state = TASK_RUNNING;
- remove_wait_queue(&info->open_wait, &wait);
- if (extra_count)
- info->count++;
- info->blocked_open--;
-#ifdef SERIAL_DEBUG_OPEN
- printk("block_til_ready after blocking: ttys%d, count = %d\n",
- info->line, info->count);
-#endif
- if (retval)
- return retval;
- info->flags |= ASYNC_NORMAL_ACTIVE;
- return 0;
-}
+ if (up->port.type == PORT_16550A) {
+ /* Check for TI 16750 */
+ serial_outp(up, UART_LCR, save_lcr | UART_LCR_DLAB);
+ serial_outp(up, UART_FCR,
+ UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
+ scratch = serial_in(up, UART_IIR) >> 5;
+ if (scratch == 7) {
+ /*
+ * If this is a 16750, and not a cheap UART
+ * clone, then it should only go into 64 byte
+ * mode if the UART_FCR7_64BYTE bit was set
+ * while UART_LCR_DLAB was latched.
+ */
+ serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
+ serial_outp(up, UART_LCR, 0);
+ serial_outp(up, UART_FCR,
+ UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
+ scratch = serial_in(up, UART_IIR) >> 5;
+ if (scratch == 6)
+ up->port.type = PORT_16750;
+ }
+ serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
+ }
+ serial_outp(up, UART_LCR, scratch2);
+ if (up->port.type == PORT_16450) {
+ scratch = serial_in(up, UART_SCR);
+ serial_outp(up, UART_SCR, 0xa5);
+ status1 = serial_in(up, UART_SCR);
+ serial_outp(up, UART_SCR, 0x5a);
+ status2 = serial_in(up, UART_SCR);
+ serial_outp(up, UART_SCR, scratch);
-/*
- * This routine is called whenever a serial port is opened. It
- * enables interrupts for a serial port, linking in its async structure into
- * the IRQ chain. It also performs the serial-specific
- * initialization for the tty structure.
- */
-static int
-su_open(struct tty_struct *tty, struct file * filp)
-{
- struct su_struct *info;
- int retval, line;
- unsigned long page;
+ if ((status1 != 0xa5) || (status2 != 0x5a))
+ up->port.type = PORT_8250;
+ }
- line = minor(tty->device) - tty->driver.minor_start;
- if ((line < 0) || (line >= NR_PORTS))
- return -ENODEV;
- info = su_table + line;
- info->count++;
- tty->driver_data = info;
- info->tty = tty;
+ up->port.xmit_fifo_size = uart_config[up->port.type].dfl_xmit_fifo_size;
- if (serial_paranoia_check(info, tty->device, "su_open")) {
- info->count--;
- return -ENODEV;
- }
+ if (up->port.type == PORT_UNKNOWN)
+ goto out;
-#ifdef SERIAL_DEBUG_OPEN
- printk("su_open %s%d, count = %d\n", tty->driver.name, info->line,
- info->count);
-#endif
- info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
-
- if (!tmp_buf) {
- page = get_free_page(GFP_KERNEL);
- if (!page)
- return -ENOMEM;
- if (tmp_buf)
- free_page(page);
- else
- tmp_buf = (unsigned char *) page;
- }
+ sprintf(up->name, "su(%s)", su_typev[up->port_type]);
/*
- * If the port is the middle of closing, bail out now
- */
- if (tty_hung_up_p(filp) ||
- (info->flags & ASYNC_CLOSING)) {
- if (info->flags & ASYNC_CLOSING)
- interruptible_sleep_on(&info->close_wait);
-#ifdef SERIAL_DO_RESTART
- return ((info->flags & ASYNC_HUP_NOTIFY) ?
- -EAGAIN : -ERESTARTSYS);
-#else
- return -EAGAIN;
-#endif
- }
-
- /*
- * Start up serial port
+ * Reset the UART.
*/
- retval = startup(info);
- if (retval)
- return retval;
-
- MOD_INC_USE_COUNT;
- retval = block_til_ready(tty, filp, info);
- if (retval) {
-#ifdef SERIAL_DEBUG_OPEN
- printk("su_open returning after block_til_ready with %d\n",
- retval);
+#ifdef CONFIG_SERIAL_8250_RSA
+ if (up->port.type == PORT_RSA)
+ serial_outp(up, UART_RSA_FRR, 0);
#endif
- return retval;
- }
+ serial_outp(up, UART_MCR, save_mcr);
+ serial_outp(up, UART_FCR, (UART_FCR_ENABLE_FIFO |
+ UART_FCR_CLEAR_RCVR |
+ UART_FCR_CLEAR_XMIT));
+ serial_outp(up, UART_FCR, 0);
+ (void)serial_in(up, UART_RX);
+ serial_outp(up, UART_IER, 0);
- if ((info->count == 1) &&
- (info->flags & ASYNC_SPLIT_TERMIOS)) {
- if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
- *tty->termios = info->normal_termios;
- else
- *tty->termios = info->callout_termios;
- change_speed(info, 0);
- }
-#ifdef CONFIG_SERIAL_CONSOLE
- if (sercons.cflag && sercons.index == line) {
- tty->termios->c_cflag = sercons.cflag;
- sercons.cflag = 0;
- change_speed(info, 0);
- }
-#endif
- info->session = current->session;
- info->pgrp = current->pgrp;
+out:
+ spin_unlock_irqrestore(&up->port.lock, flags);
+}
-#ifdef SERIAL_DEBUG_OPEN
- printk("su_open ttys%d successful...", info->line);
+static struct uart_driver sunsu_reg = {
+ .owner = THIS_MODULE,
+ .driver_name = "serial",
+#ifdef CONFIG_DEVFS_FS
+ .dev_name = "tts/%d",
+#else
+ .dev_name = "ttyS",
#endif
- return 0;
-}
+ .major = TTY_MAJOR,
+};
-/*
- * /proc fs routines....
- */
-static int
-line_info(char *buf, struct su_struct *info)
+static int __init sunsu_serial_init(void)
{
- char stat_buf[30], control, status;
- int ret;
- unsigned long flags;
+ int instance, ret;
- if (info->port == 0 || info->type == PORT_UNKNOWN)
- return 0;
+ /* How many instances do we need? */
+ instance = 0;
+ for (i = 0; i < UART_NR; i++) {
+ if (up->port_type == SU_PORT_MS ||
+ up->port_type == SU_PORT_KBD)
+ continue;
- ret = sprintf(buf, "%u: uart:%s port:%lX irq:%s",
- info->line, uart_config[info->type].name,
- (unsigned long)info->port, __irq_itoa(info->irq));
+ up->port.type = PORT_UNKNOWN;
+ up->port.baud_base = BAUD_BASE;
- /*
- * Figure out the current RS-232 lines
- */
- save_flags(flags); cli();
- status = serial_in(info, UART_MSR);
- control = info ? info->MCR : serial_in(info, UART_MCR);
- restore_flags(flags);
-
- stat_buf[0] = 0;
- stat_buf[1] = 0;
- if (control & UART_MCR_RTS)
- strcat(stat_buf, "|RTS");
- if (status & UART_MSR_CTS)
- strcat(stat_buf, "|CTS");
- if (control & UART_MCR_DTR)
- strcat(stat_buf, "|DTR");
- if (status & UART_MSR_DSR)
- strcat(stat_buf, "|DSR");
- if (status & UART_MSR_DCD)
- strcat(stat_buf, "|CD");
- if (status & UART_MSR_RI)
- strcat(stat_buf, "|RI");
+ sunsu_autoconfig(up);
+ if (up->port.type == PORT_UNKNOWN)
+ continue;
- if (info->quot) {
- ret += sprintf(buf+ret, " baud:%u",
- info->baud_base / info->quot);
+ up->port.line = instance++;
+ up->port.ops = &sunsu_pops;
}
- ret += sprintf(buf+ret, " tx:%u rx:%u",
- info->icount.tx, info->icount.rx);
-
- if (info->icount.frame)
- ret += sprintf(buf+ret, " fe:%u", info->icount.frame);
-
- if (info->icount.parity)
- ret += sprintf(buf+ret, " pe:%u", info->icount.parity);
+ sunsu_reg.minor = sunserial_current_minor;
+ sunserial_current_minor += instance;
- if (info->icount.brk)
- ret += sprintf(buf+ret, " brk:%u", info->icount.brk);
+ sunsu_reg.nr = instance;
+ sunsu_reg.cons = &sunsu_console;
- if (info->icount.overrun)
- ret += sprintf(buf+ret, " oe:%u", info->icount.overrun);
-
- /*
- * Last thing is the RS-232 status lines
- */
- ret += sprintf(buf+ret, " %s\n", stat_buf+1);
- return ret;
-}
-
-int su_read_proc(char *page, char **start, off_t off, int count,
- int *eof, void *data)
-{
- int i, len = 0;
- off_t begin = 0;
-
- len += sprintf(page, "serinfo:1.0 driver:%s\n", serial_version);
- for (i = 0; i < NR_PORTS && len < 4000; i++) {
- len += line_info(page + len, &su_table[i]);
- if (len+begin > off+count)
- goto done;
- if (len+begin < off) {
- begin += len;
- len = 0;
- }
- }
- *eof = 1;
-done:
- if (off >= len+begin)
- return 0;
- *start = page + (off-begin);
- return ((count < begin+len-off) ? count : begin+len-off);
-}
-
-/*
- * ---------------------------------------------------------------------
- * su_XXX_init() and friends
- *
- * su_XXX_init() is called at boot-time to initialize the serial driver.
- * ---------------------------------------------------------------------
- */
-
-/*
- * This routine prints out the appropriate serial driver version
- * number, and identifies which options were configured into this
- * driver.
- */
-static __inline__ void __init show_su_version(void)
-{
- char *revision = "$Revision: 1.55 $";
- char *version, *p;
-
- version = strchr(revision, ' ');
- strcpy(serial_version, ++version);
- p = strchr(serial_version, ' ');
- *p = '\0';
- printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
-}
-
-/*
- * This routine is called by su_{serial|kbd_ms}_init() to initialize a specific
- * serial port. It determines what type of UART chip this serial port is
- * using: 8250, 16450, 16550, 16550A. The important question is
- * whether or not this UART is a 16550A, since this will determine
- * whether or not we can use its FIFO features.
- */
-static void
-autoconfig(struct su_struct *info)
-{
- unsigned char status1, status2, scratch, scratch2;
- struct linux_ebus_device *dev = 0;
- struct linux_ebus *ebus;
-#ifdef CONFIG_SPARC64
- struct isa_bridge *isa_br;
- struct isa_device *isa_dev;
-#endif
-#ifndef __sparc_v9__
- struct linux_prom_registers reg0;
-#endif
- unsigned long flags;
+ ret = uart_register_driver(&sunsu_reg);
+ if (ret < 0)
+ return ret;
- if (!info->port_node || !info->port_type)
- return;
+ instance = 0;
+ for (i = 0; i < UART_NR; i++) {
+ struct uart_sunsu_port *up = &sunsu_port[i];
- /*
- * First we look for Ebus-bases su's
- */
- for_each_ebus(ebus) {
- for_each_ebusdev(dev, ebus) {
- if (dev->prom_node == info->port_node) {
- info->port = dev->resource[0].start;
- info->irq = dev->irqs[0];
- goto ebus_done;
- }
- }
- }
+ /* Do not register Keyboard/Mouse lines with UART
+ * layer.
+ */
+ if (up->port_type == SU_PORT_MS ||
+ up->port_type == SU_PORT_KBD)
+ continue;
-#ifdef CONFIG_SPARC64
- for_each_isa(isa_br) {
- for_each_isadev(isa_dev, isa_br) {
- if (isa_dev->prom_node == info->port_node) {
- info->port = isa_dev->resource.start;
- info->irq = isa_dev->irq;
- goto ebus_done;
- }
- }
- }
-#endif
+ if (up->port.type == PORT_UNKNOWN)
+ continue;
-#ifdef __sparc_v9__
- /*
- * Not on Ebus, bailing.
- */
- return;
-#else
- /*
- * Not on Ebus, must be OBIO.
- */
- if (prom_getproperty(info->port_node, "reg",
- (char *)®0, sizeof(reg0)) == -1) {
- prom_printf("su: no \"reg\" property\n");
- return;
- }
- prom_apply_obio_ranges(®0, 1);
- if (reg0.which_io != 0) { /* Just in case... */
- prom_printf("su: bus number nonzero: 0x%x:%x\n",
- reg0.which_io, reg0.phys_addr);
- return;
- }
- if ((info->port = (unsigned long) ioremap(reg0.phys_addr,
- reg0.reg_size)) == 0) {
- prom_printf("su: cannot map\n");
- return;
+ uart_add_one_port(&sunsu_reg, up);
}
- /*
- * There is no intr property on MrCoffee, so hardwire it.
- */
- info->irq = IRQ_4M(13);
-#endif
+ return 0;
+}
-ebus_done:
+static int __init su_kbd_ms_init(void)
+{
+ struct uart_sunsu_port *up;
+ int i;
-#ifdef SERIAL_DEBUG_OPEN
- printk("Found 'su' at %016lx IRQ %s\n", info->port,
- __irq_itoa(info->irq));
-#endif
+ for (i = 0, up = sunsu_ports; i < 2; i++, up++) {
+ up->port.line = i;
+ up->port.type = PORT_UNKNOWN;
+ up->port.baud_base = BAUD_BASE;
- info->magic = SERIAL_MAGIC;
+ if (up->port_type == SU_PORT_KBD)
+ up->port.cflag = B1200 | CS8 | CLOCAL | CREAD;
+ else
+ up->port.cflag = B4800 | CS8 | CLOCAL | CREAD;
- save_flags(flags); cli();
+ sunsu_autoconfig(up);
+ if (up->port.type == PORT_UNKNOWN)
+ continue;
- /*
- * Do a simple existence test first; if we fail this, there's
- * no point trying anything else.
- *
- * 0x80 is used as a nonsense port to prevent against false
- * positives due to ISA bus float. The assumption is that
- * 0x80 is a non-existent port; which should be safe since
- * include/asm/io.h also makes this assumption.
- */
- scratch = serial_inp(info, UART_IER);
- serial_outp(info, UART_IER, 0);
- scratch2 = serial_inp(info, UART_IER);
- serial_outp(info, UART_IER, scratch);
- if (scratch2) {
- restore_flags(flags);
- return; /* We failed; there's nothing here */
- }
+ printk(KERN_INFO "su%d at 0x%p (irq = %s) is a %s\n",
+ i,
+ up->port.membase, __irq_itoa(up->irq),
+ sunsu_type(&up->port));
- scratch = serial_inp(info, UART_MCR);
- serial_outp(info, UART_MCR, UART_MCR_LOOP | scratch);
- serial_outp(info, UART_MCR, UART_MCR_LOOP | 0x0A);
- status1 = serial_inp(info, UART_MSR) & 0xF0;
- serial_outp(info, UART_MCR, scratch);
- if (status1 != 0x90) {
- /*
- * This code fragment used to fail, now it fixed itself.
- * We keep the printout for a case.
- */
- printk("su: loopback returned status 0x%02x\n", status1);
- restore_flags(flags);
- return;
- }
-
- scratch2 = serial_in(info, UART_LCR);
- serial_outp(info, UART_LCR, 0xBF); /* set up for StarTech test */
- serial_outp(info, UART_EFR, 0); /* EFR is the same as FCR */
- serial_outp(info, UART_LCR, 0);
- serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
- scratch = serial_in(info, UART_IIR) >> 6;
- switch (scratch) {
- case 0:
- info->type = PORT_16450;
- break;
- case 1:
- info->type = PORT_UNKNOWN;
- break;
- case 2:
- info->type = PORT_16550;
- break;
- case 3:
- info->type = PORT_16550A;
- break;
- }
- if (info->type == PORT_16550A) {
- /* Check for Startech UART's */
- serial_outp(info, UART_LCR, scratch2 | UART_LCR_DLAB);
- if (serial_in(info, UART_EFR) == 0) {
- info->type = PORT_16650;
- } else {
- serial_outp(info, UART_LCR, 0xBF);
- if (serial_in(info, UART_EFR) == 0)
- info->type = PORT_16650V2;
- }
- }
- if (info->type == PORT_16550A) {
- /* Check for TI 16750 */
- serial_outp(info, UART_LCR, scratch2 | UART_LCR_DLAB);
- serial_outp(info, UART_FCR,
- UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
- scratch = serial_in(info, UART_IIR) >> 5;
- if (scratch == 7) {
- serial_outp(info, UART_LCR, 0);
- serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
- scratch = serial_in(info, UART_IIR) >> 5;
- if (scratch == 6)
- info->type = PORT_16750;
- }
- serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
- }
- serial_outp(info, UART_LCR, scratch2);
- if (info->type == PORT_16450) {
- scratch = serial_in(info, UART_SCR);
- serial_outp(info, UART_SCR, 0xa5);
- status1 = serial_in(info, UART_SCR);
- serial_outp(info, UART_SCR, 0x5a);
- status2 = serial_in(info, UART_SCR);
- serial_outp(info, UART_SCR, scratch);
+#ifdef CONFIG_SERIO
+ memset(&up->serio, 0, sizeof(up->serio));
- if ((status1 != 0xa5) || (status2 != 0x5a))
- info->type = PORT_8250;
- }
- info->xmit_fifo_size = uart_config[info->type].dfl_xmit_fifo_size;
+ up->serio.driver = up;
- if (info->type == PORT_UNKNOWN) {
- restore_flags(flags);
- return;
- }
+ up->serio.type = SERIO_RS232;
+ if (up->port_type == SU_PORT_KBD) {
+ up->serio.type |= SERIO_SUNKBD;
+ up->serio.name = "sukbd";
+ } else {
+ up->serio.type |= SERIO_SUN;
+ up->serio.name = "sums";
+ }
+ up->phys = (i == 0 ? "su/serio0" : "su/serio1");
- sprintf(info->name, "su(%s)", su_typev[info->port_type]);
+ up->serio.write = sunsu_serio_write;
+ up->serio.open = sunsu_serio_open;
+ up->serio.close = sunsu_serio_close;
- /*
- * Reset the UART.
- */
- serial_outp(info, UART_MCR, 0x00);
- serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT));
- (void)serial_in(info, UART_RX);
- serial_outp(info, UART_IER, 0x00);
+ serio_register_port(&up->serio);
+#endif
- restore_flags(flags);
+ sunsu_startup(up);
+ }
+ return 0;
}
-/* This is used by the SAB driver to adjust where its minor
- * numbers start, we always are probed for first.
+/*
+ * ------------------------------------------------------------
+ * Serial console driver
+ * ------------------------------------------------------------
*/
-int su_num_ports = 0;
-EXPORT_SYMBOL(su_num_ports);
+
+#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
/*
- * The serial driver boot-time initialization code!
+ * Wait for transmitter & holding register to empty
*/
-int __init su_serial_init(void)
+static __inline__ void wait_for_xmitr(struct uart_sunsu_port *up)
{
- int i;
- struct su_struct *info;
+ unsigned int status, tmout = 10000;
- init_bh(SERIAL_BH, do_serial_bh);
- show_su_version();
+ /* Wait up to 10ms for the character(s) to be sent. */
+ do {
+ status = serial_in(up, UART_LSR);
- /* Initialize the tty_driver structure */
+ if (status & UART_LSR_BI)
+ up->lsr_break_flag = UART_LSR_BI;
- memset(&serial_driver, 0, sizeof(struct tty_driver));
- serial_driver.magic = TTY_DRIVER_MAGIC;
- serial_driver.driver_name = "su";
-#ifdef CONFIG_DEVFS_FS
- serial_driver.name = "tts/%d";
-#else
- serial_driver.name = "ttyS";
-#endif
- serial_driver.major = TTY_MAJOR;
- serial_driver.minor_start = 64;
- serial_driver.num = NR_PORTS;
- serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
- serial_driver.subtype = SERIAL_TYPE_NORMAL;
- serial_driver.init_termios = tty_std_termios;
- serial_driver.init_termios.c_cflag =
- B9600 | CS8 | CREAD | HUPCL | CLOCAL;
- serial_driver.flags = TTY_DRIVER_REAL_RAW;
- serial_driver.refcount = &serial_refcount;
- serial_driver.table = serial_table;
- serial_driver.termios = serial_termios;
- serial_driver.termios_locked = serial_termios_locked;
-
- serial_driver.open = su_open;
- serial_driver.close = su_close;
- serial_driver.write = su_write;
- serial_driver.put_char = su_put_char;
- serial_driver.flush_chars = su_flush_chars;
- serial_driver.write_room = su_write_room;
- serial_driver.chars_in_buffer = su_chars_in_buffer;
- serial_driver.flush_buffer = su_flush_buffer;
- serial_driver.ioctl = su_ioctl;
- serial_driver.throttle = su_throttle;
- serial_driver.unthrottle = su_unthrottle;
- serial_driver.send_xchar = su_send_xchar;
- serial_driver.set_termios = su_set_termios;
- serial_driver.stop = su_stop;
- serial_driver.start = su_start;
- serial_driver.hangup = su_hangup;
- serial_driver.break_ctl = su_break;
- serial_driver.wait_until_sent = su_wait_until_sent;
- serial_driver.read_proc = su_read_proc;
+ if (--tmout == 0)
+ break;
+ udelay(1);
+ } while ((status & BOTH_EMPTY) != BOTH_EMPTY);
+
+ /* Wait up to 1s for flow control if necessary */
+ if (up->port.flags & ASYNC_CONS_FLOW) {
+ tmout = 1000000;
+ while (--tmout &&
+ ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0))
+ udelay(1);
+ }
+}
+
+/*
+ * Print a string to the serial port trying not to disturb
+ * any possible real use of the port...
+ */
+static void sunsu_console_write(struct console *co, const char *s,
+ unsigned int count)
+{
+ struct uart_sunsu_port *up = &sunsu_ports[co->index];
+ unsigned int ier;
+ int i;
/*
- * The callout device is just like normal device except for
- * major number and the subtype code.
+ * First save the UER then disable the interrupts
*/
- callout_driver = serial_driver;
-#ifdef CONFIG_DEVFS_FS
- callout_driver.name = "cua/%d";
-#else
- callout_driver.name = "cua";
-#endif
- callout_driver.major = TTYAUX_MAJOR;
- callout_driver.subtype = SERIAL_TYPE_CALLOUT;
- callout_driver.read_proc = 0;
- callout_driver.proc_entry = 0;
-
- if (tty_register_driver(&serial_driver))
- panic("Couldn't register regular su\n");
- if (tty_register_driver(&callout_driver))
- panic("Couldn't register callout su\n");
-
- for (i = 0, info = su_table; i < NR_PORTS; i++, info++) {
- info->line = i;
- info->type = PORT_UNKNOWN;
- info->baud_base = BAUD_BASE;
- /* info->flags = 0; */
- info->custom_divisor = 0;
- info->close_delay = 5*HZ/10;
- info->closing_wait = 30*HZ;
- info->callout_termios = callout_driver.init_termios;
- info->normal_termios = serial_driver.init_termios;
- info->icount.cts = info->icount.dsr =
- info->icount.rng = info->icount.dcd = 0;
- info->icount.rx = info->icount.tx = 0;
- info->icount.frame = info->icount.parity = 0;
- info->icount.overrun = info->icount.brk = 0;
- info->tqueue.routine = do_softint;
- info->tqueue.data = info;
- info->cflag = serial_driver.init_termios.c_cflag;
- init_waitqueue_head(&info->open_wait);
- init_waitqueue_head(&info->close_wait);
- init_waitqueue_head(&info->delta_msr_wait);
-
- autoconfig(info);
- if (info->type == PORT_UNKNOWN)
- continue;
+ ier = serial_in(up, UART_IER);
+ serial_out(up, UART_IER, 0);
- printk(KERN_INFO "%s at 0x%lx (tty %d irq %s) is a %s\n",
- info->name, (long)info->port, i, __irq_itoa(info->irq),
- uart_config[info->type].name);
- }
+ /*
+ * Now, do each character
+ */
+ for (i = 0; i < count; i++, s++) {
+ wait_for_xmitr(up);
- for (i = 0, info = su_table; i < NR_PORTS; i++, info++)
- if (info->type == PORT_UNKNOWN)
- break;
+ /*
+ * Send the character out.
+ * If a LF, also do CR...
+ */
+ serial_out(up, UART_TX, *s);
+ if (*s == 10) {
+ wait_for_xmitr(up);
+ serial_out(up, UART_TX, 13);
+ }
+ }
- su_num_ports = i;
- serial_driver.num = callout_driver.num = i;
+ /*
+ * Finally, wait for transmitter to become empty
+ * and restore the IER
+ */
+ wait_for_xmitr(up);
+ serial_out(up, UART_IER, ier);
+}
- return 0;
+static kdev_t sunsu_console_device(struct console *co)
+{
+ return mk_kdev(TTY_MAJOR, 64 + co->index);
}
-int __init su_kbd_ms_init(void)
+/*
+ * Setup initial baud/bits/parity. We do two things here:
+ * - construct a cflag setting for the first su_open()
+ * - initialize the serial port
+ * Return non-zero if we didn't find a serial port.
+ */
+static int __init sunsu_console_setup(struct console *co, char *options)
{
- int i;
- struct su_struct *info;
+ struct uart_port *port;
+ int baud = 9600;
+ int bits = 8;
+ int parity = 'n';
+ int flow = 'n';
+
+ /*
+ * Check whether an invalid uart number has been specified, and
+ * if so, search for the first available port that does have
+ * console support.
+ */
+ if (co->index >= UART_NR)
+ co->index = 0;
+ port = &sunsu_ports[co->index].port;
- show_su_version();
+ /*
+ * Temporary fix.
+ */
+ spin_lock_init(&port->lock);
- for (i = 0, info = su_table; i < 2; i++, info++) {
- info->line = i;
- info->type = PORT_UNKNOWN;
- info->baud_base = BAUD_BASE;
+ if (options)
+ uart_parse_options(options, &baud, &parity, &bits, &flow);
- if (info->port_type == SU_PORT_KBD)
- info->cflag = B1200 | CS8 | CLOCAL | CREAD;
- else
- info->cflag = B4800 | CS8 | CLOCAL | CREAD;
+ return uart_set_options(port, co, baud, parity, bits, flow);
+}
- init_waitqueue_head(&info->open_wait);
- init_waitqueue_head(&info->close_wait);
- init_waitqueue_head(&info->delta_msr_wait);
+static struct console sunsu_cons = {
+ .name = "ttyS",
+ .write = sunsu_console_write,
+ .device = sunsu_console_device,
+ .setup = sunsu_console_setup,
+ .flags = CON_PRINTBUFFER,
+ .index = -1,
+};
- autoconfig(info);
- if (info->type == PORT_UNKNOWN)
- continue;
+/*
+ * Register console.
+ */
+
+static int __init sunsu_serial_console_init(void)
+{
+ int index;
- printk(KERN_INFO "%s at 0x%lx (irq = %s) is a %s\n",
- info->name, info->port, __irq_itoa(info->irq),
- uart_config[info->type].name);
+ if (con_is_present())
+ return 0;
- startup(info);
- if (info->port_type == SU_PORT_KBD)
- keyboard_zsinit(su_put_char_kbd);
- else
- sun_mouse_zsinit();
- }
+ index = serial_console - 1;
+ if (su_table[index].port == 0 || su_table[index].port_node == 0)
+ return 0;
+ sunsu_cons.index = index;
+ register_console(&sunsu_cons);
return 0;
}
return 0;
}
+#define SU_PROPSIZE 128
+
+/*
+ * Scan status structure.
+ * "prop" is a local variable but it eats stack to keep it in each
+ * stack frame of a recursive procedure.
+ */
+struct su_probe_scan {
+ int msnode, kbnode; /* PROM nodes for mouse and keyboard */
+ int msx, kbx; /* minors for mouse and keyboard */
+ int devices; /* scan index */
+ char prop[SU_PROPSIZE];
+};
+
/*
- * We got several platforms which present 'su' in different parts
- * of device tree. 'su' may be found under obio, ebus, isa and pci.
+ * We have several platforms which present 'su' in different parts
+ * of the device tree. 'su' may be found under obio, ebus, isa and pci.
* We walk over the tree and find them wherever PROM hides them.
*/
-void __init su_probe_any(struct su_probe_scan *t, int sunode)
+static void __init su_probe_any(struct su_probe_scan *t, int sunode)
{
struct su_struct *info;
int len;
- if (t->devices >= NR_PORTS) return;
+ if (t->devices >= UART_NR)
+ return;
for (; sunode != 0; sunode = prom_getsibling(sunode)) {
len = prom_getproperty(sunode, "name", t->prop, SU_PROPSIZE);
- if (len <= 1) continue; /* Broken PROM node */
+ if (len <= 1)
+ continue; /* Broken PROM node */
+
if (su_node_ok(sunode, t->prop, len)) {
info = &su_table[t->devices];
if (t->kbnode != 0 && sunode == t->kbnode) {
t->msx = t->devices;
info->port_type = SU_PORT_MS;
} else {
-#ifdef __sparc_v9__
+#ifdef CONFIG_SPARC64
/*
* Do not attempt to use the truncated
* keyboard/mouse ports as serial ports
}
}
-int __init su_probe(void)
+static int __init sunsu_probe(void)
{
int node;
int len;
node = prom_getchild(prom_root_node);
node = prom_searchsiblings(node, "aliases");
if (node != 0) {
-
- len = prom_getproperty(node, "keyboard", scan.prop,SU_PROPSIZE);
+ len = prom_getproperty(node, "keyboard", scan.prop, SU_PROPSIZE);
if (len > 0) {
scan.prop[len] = 0;
scan.kbnode = prom_finddevice(scan.prop);
* Currently if we got keyboard and mouse hooked to "su" ports
* we do not use any possible remaining "su" as a serial port.
* Thus, we ignore values of .msx and .kbx, then compact ports.
- * Those who want to address this issue need to merge
- * su_serial_init() and su_ms_kbd_init().
*/
if (scan.msx != -1 && scan.kbx != -1) {
- su_table[0].port_type = SU_PORT_MS;
- su_table[0].is_console = 0;
- su_table[0].port_node = scan.msnode;
- su_table[1].port_type = SU_PORT_KBD;
- su_table[1].is_console = 0;
- su_table[1].port_node = scan.kbnode;
-
- sunserial_setinitfunc(su_kbd_ms_init);
- rs_ops.rs_change_mouse_baud = su_change_mouse_baud;
- sunkbd_setinitfunc(sun_kbd_init);
- kbd_ops.compute_shiftstate = sun_compute_shiftstate;
- kbd_ops.setledstate = sun_setledstate;
- kbd_ops.getledstate = sun_getledstate;
- kbd_ops.setkeycode = sun_setkeycode;
- kbd_ops.getkeycode = sun_getkeycode;
-#ifdef CONFIG_PCI
- sunkbd_install_keymaps(sun_key_maps,
- sun_keymap_count, sun_func_buf, sun_func_table,
- sun_funcbufsize, sun_funcbufleft,
- sun_accent_table, sun_accent_table_size);
-#endif
+ sunsu_ports[0].port_type = SU_PORT_MS;
+ sunsu_ports[0].port_node = scan.msnode;
+ sunsu_ports[1].port_type = SU_PORT_KBD;
+ sunsu_ports[1].port_node = scan.kbnode;
+
+ sunsu_kbd_ms_init();
return 0;
}
+
if (scan.msx != -1 || scan.kbx != -1) {
- printk("su_probe: cannot match keyboard and mouse, confused\n");
+ printk("sunsu_probe: cannot match keyboard and mouse, confused\n");
return -ENODEV;
}
if (scan.devices == 0)
return -ENODEV;
-#ifdef CONFIG_SERIAL_CONSOLE
/*
* Console must be initiated after the generic initialization.
- * sunserial_setinitfunc inverts order, so call this before next one.
*/
- sunserial_setinitfunc(su_serial_console_init);
-#endif
- sunserial_setinitfunc(su_serial_init);
- return 0;
-}
-
-/*
- * ------------------------------------------------------------
- * Serial console driver
- * ------------------------------------------------------------
- */
-#ifdef CONFIG_SERIAL_CONSOLE
-
-#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
+ sunsu_reg.cons = &sunsu_cons;
+ sunsu_reg.nr = scan.devices;
-/*
- * Wait for transmitter & holding register to empty
- */
-static __inline__ void
-wait_for_xmitr(struct su_struct *info)
-{
- int lsr;
- unsigned int tmout = 1000000;
+ sunsu_serial_init();
+ sunsu_serial_console_init();
- do {
- lsr = su_inb(info, UART_LSR);
- if (--tmout == 0)
- break;
- } while ((lsr & BOTH_EMPTY) != BOTH_EMPTY);
+ return 0;
}
-/*
- * Print a string to the serial port trying not to disturb
- * any possible real use of the port...
- */
-static void
-serial_console_write(struct console *co, const char *s,
- unsigned count)
+static void __exit sunsu_exit(void)
{
- struct su_struct *info;
- int ier;
- unsigned i;
-
- info = su_table + co->index;
- /*
- * First save the IER then disable the interrupts
- */
- ier = su_inb(info, UART_IER);
- su_outb(info, UART_IER, 0x00);
+ int i, saw_uart;
- /*
- * Now, do each character
- */
- for (i = 0; i < count; i++, s++) {
- wait_for_xmitr(info);
+ saw_uart = 0;
+ for (i = 0; i < UART_NR; i++) {
+ struct uart_sunsu_port *up = &sunsu_ports[i];
- /*
- * Send the character out.
- * If a LF, also do CR...
- */
- su_outb(info, UART_TX, *s);
- if (*s == 10) {
- wait_for_xmitr(info);
- su_outb(info, UART_TX, 13);
+ if (up->port_type == SU_PORT_MS ||
+ up->port_type == SU_PORT_KBD) {
+#ifdef CONFIG_SERIO
+ serio_unregister_port(&up->serio);
+#endif
+ } else if (up->port.type != PORT_UNKNOWN) {
+ uart_remove_one_port(&sunsu_reg, up);
+ saw_uart++;
}
}
- /*
- * Finally, Wait for transmitter & holding register to empty
- * and restore the IER
- */
- wait_for_xmitr(info);
- su_outb(info, UART_IER, ier);
-}
-
-static kdev_t
-serial_console_device(struct console *c)
-{
- return mk_kdev(TTY_MAJOR, 64 + c->index);
-}
-
-/*
- * Setup initial baud/bits/parity. We do two things here:
- * - construct a cflag setting for the first su_open()
- * - initialize the serial port
- * Return non-zero if we didn't find a serial port.
- */
-static int __init serial_console_setup(struct console *co, char *options)
-{
- struct su_struct *info;
- unsigned cval;
- int baud = 9600;
- int bits = 8;
- int parity = 'n';
- int cflag = CREAD | HUPCL | CLOCAL;
- int quot = 0;
- char *s;
-
- if (options) {
- baud = simple_strtoul(options, NULL, 10);
- s = options;
- while (*s >= '0' && *s <= '9')
- s++;
- if (*s) parity = *s++;
- if (*s) bits = *s - '0';
- }
-
- /*
- * Now construct a cflag setting.
- */
- switch (baud) {
- case 1200:
- cflag |= B1200;
- break;
- case 2400:
- cflag |= B2400;
- break;
- case 4800:
- cflag |= B4800;
- break;
- case 19200:
- cflag |= B19200;
- break;
- case 38400:
- cflag |= B38400;
- break;
- case 57600:
- cflag |= B57600;
- break;
- case 115200:
- cflag |= B115200;
- break;
- case 9600:
- default:
- cflag |= B9600;
- baud = 9600;
- break;
- }
- switch (bits) {
- case 7:
- cflag |= CS7;
- break;
- default:
- case 8:
- cflag |= CS8;
- break;
- }
- switch (parity) {
- case 'o': case 'O':
- cflag |= PARODD;
- break;
- case 'e': case 'E':
- cflag |= PARENB;
- break;
- }
- co->cflag = cflag;
-
- /*
- * Divisor, bytesize and parity
- */
- info = su_table + co->index;
- quot = BAUD_BASE / baud;
- cval = cflag & (CSIZE | CSTOPB);
-#if defined(__powerpc__) || defined(__alpha__)
- cval >>= 8;
-#else /* !__powerpc__ && !__alpha__ */
- cval >>= 4;
-#endif /* !__powerpc__ && !__alpha__ */
- if (cflag & PARENB)
- cval |= UART_LCR_PARITY;
- if (!(cflag & PARODD))
- cval |= UART_LCR_EPAR;
-
- /*
- * Disable UART interrupts, set DTR and RTS high
- * and set speed.
- */
- su_outb(info, UART_IER, 0);
- su_outb(info, UART_MCR, UART_MCR_DTR | UART_MCR_RTS);
- su_outb(info, UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */
- su_outb(info, UART_DLL, quot & 0xff); /* LS of divisor */
- su_outb(info, UART_DLM, quot >> 8); /* MS of divisor */
- su_outb(info, UART_LCR, cval); /* reset DLAB */
- info->quot = quot;
-
- /*
- * If we read 0xff from the LSR, there is no UART here.
- */
- if (su_inb(info, UART_LSR) == 0xff)
- return -1;
-
- info->is_console = 1;
-
- return 0;
-}
-
-static struct console sercons = {
- .name = "ttyS",
- .write = serial_console_write,
- .device = serial_console_device,
- .setup = serial_console_setup,
- .flags = CON_PRINTBUFFER,
- .index = -1,
-};
-
-int su_console_registered = 0;
-
-/*
- * Register console.
- */
-int __init su_serial_console_init(void)
-{
- extern int con_is_present(void);
- int index;
-
- if (con_is_present())
- return 0;
- if (serial_console == 0)
- return 0;
- index = serial_console - 1;
- if (su_table[index].port == 0 || su_table[index].port_node == 0)
- return 0;
- sercons.index = index;
- register_console(&sercons);
- su_console_registered = 1;
- return 0;
+ if (saw_uart)
+ uart_unregister_driver(&sunsu_reg);
}
-#endif /* CONFIG_SERIAL_CONSOLE */
+module_init(sunsu_probe);
+module_exit(sunsu_exit);
* sunzilog.c
*
* Driver for Zilog serial chips found on Sun workstations and
- * servers. This driver could actually be made more generic
- * and anyone wanting to work on doing that should contact
- * me. -DaveM
+ * servers. This driver could actually be made more generic.
*
- * This is based on the old drivers/sbus/char/zs.c code, a lot
+ * This is based on the old drivers/sbus/char/zs.c code. A lot
* of code has been simply moved over directly from there but
* much has been rewritten. Credits therefore go out to Eddie
* C. Dost, Peter Zaitcev, Ted Ts'o and Alex Buell for their
* Copyright (C) 2002 David S. Miller (davem@redhat.com)
*/
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/errno.h>
+#include <linux/delay.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/major.h>
+#include <linux/string.h>
+#include <linux/ptrace.h>
+#include <linux/ioport.h>
+#include <linux/slab.h>
+#include <linux/circ_buf.h>
+#include <linux/serial.h>
+#include <linux/console.h>
+#include <linux/spinlock.h>
+#ifdef CONFIG_SERIO
+#include <linux/serio.h>
+#endif
+#include <linux/init.h>
+
+#include <asm/io.h>
+#include <asm/irq.h>
+
+#include <linux/serial_core.h>
+
#include "suncore.h"
#include "sunzilog.h"
* On 64-bit sparc we only need to flush single writes to ensure
* completion.
*/
-#ifndef __sparc_v9__
+#ifndef CONFIG_SPARC64
#define ZSDELAY() udelay(5)
#define ZSDELAY_LONG() udelay(20)
-#define ZS_WSYNC(channel) do { } while(0)
+#define ZS_WSYNC(channel) do { } while (0)
#else
#define ZSDELAY()
#define ZSDELAY_LONG()
sbus_readb(&((__channel)->control))
#endif
-/* Default setting is sun4/sun4c/sun4m, two chips on board. */
-static int num_sunzilog = 2;
+static int num_sunzilog;
#define NUM_SUNZILOG num_sunzilog
#define NUM_CHANNELS (NUM_SUNZILOG * 2)
+#define KEYBOARD_LINE 0x2
+#define MOUSE_LINE 0x3
+
+#define ZS_CLOCK 4915200 /* Zilog input clock rate. */
+#define ZS_CLOCK_DIVISOR 16 /* Divisor this driver uses. */
+
/*
* We wrap our port structure around the generic uart_port.
*/
#define SUNZILOG_FLAG_IS_KGDB 0x00000008
#define SUNZILOG_FLAG_MODEM_STATUS 0x00000010
#define SUNZILOG_FLAG_IS_CHANNEL_A 0x00000020
+#define SUNZILOG_FLAG_REGS_HELD 0x00000040
+#define SUNZILOG_FLAG_TX_STOPPED 0x00000080
+#define SUNZILOG_FLAG_TX_ACTIVE 0x00000100
/* L1-A keyboard break state. */
int kbd_id;
unsigned char parity_mask;
unsigned char prev_status;
+
+#ifdef CONFIG_SERIO
+ struct serio serio;
+#endif
};
#define ZILOG_CHANNEL_FROM_PORT(PORT) ((struct zilog_channel *)((PORT)->membase))
(UART_ZILOG(PORT)->curregs[REGNUM])
#define SUNZILOG_SET_CURR_REG(PORT, REGNUM, REGVAL) \
((UART_ZILOG(PORT)->curregs[REGNUM]) = (REGVAL))
-
-static unsigned char sunzilog_initregs_normal[NUM_ZSREGS] = {
- RES_EXT_INT, /* R0 */
- 0, /* R1 */
- 0, /* R2 */
- Rx8, /* R3 */
- PAR_EVEN | X16CLK | SB1, /* R4 */
- Tx8, /* R5 */
- 0, /* R6 */
- 0, /* R7 */
- 0, /* R8 */
- NV | MIE, /* R9 */
- NRZ, /* R10 */
- RCBR | TCBR, /* R11 */
- 0, 0, /* R12, R13 Baud Quotient low, high */
- BRSRC | BRENAB, /* R14 */
- DCDIE | SYNCIE | CTSIE | BRKIE, /* R15 */
-};
-
-static unsigned char sunzilog_initregs_console[NUM_ZSREGS] = {
- RES_EXT_INT, /* R0 */
- EXT_INT_ENAB | INT_ALL_Rx, /* R1 */
- 0, /* R2 */
- Rx8 | RxENAB, /* R3 */
- X16CLK, /* R4 */
- DTR | Tx8 | TxENAB, /* R5 */
- 0, /* R6 */
- 0, /* R7 */
- 0, /* R8 */
- NV | MIE, /* R9 */
- NRZ, /* R10 */
- RCBR | TCBR, /* R11 */
- 0, 0, /* R12, R13 Baud Quotient low, high */
- BRSRC | BRENAB, /* R14 */
- DCDIE | SYNCIE | CTSIE | BRKIE, /* R15 */
-};
-
-static unsigned char sunzilog_initregs_kgdb[NUM_ZSREGS] = {
- 0, 0, 0 /* R0, R1, R2 */
- Rx8 | RxENAB, /* R3 */
- PAR_EVEN | X16CLK | SB1, /* R4 */
- DTR | Tx8 | TxENAB, /* R5 */
- 0, 0, 0, /* R6, R7, R8 */
- NV, /* R9 */
- NRZ, /* R10 */
- RCBR | TCBR, /* R11 */
- 0, 0, /* R12, R13 Baud Quotient low, high */
- BRSRC | BRENAB, /* R14 */
- DCDIE, /* R15 */
-};
+#define ZS_IS_KEYB(UP) ((UP)->flags & SUNZILOG_FLAG_CONS_KEYB)
+#define ZS_IS_MOUSE(UP) ((UP)->flags & SUNZILOG_FLAG_CONS_MOUSE)
+#define ZS_IS_CONS(UP) ((UP)->flags & SUNZILOG_FLAG_IS_CONS)
+#define ZS_IS_KGDB(UP) ((UP)->flags & SUNZILOG_FLAG_IS_KGDB)
+#define ZS_WANTS_MODEM_STATUS(UP) ((UP)->flags & SUNZILOG_FLAG_MODEM_STATUS)
+#define ZS_IS_CHANNEL_A(UP) ((UP)->flags & SUNZILOG_FLAG_IS_CHANNEL_A)
+#define ZS_REGS_HELD(UP) ((UP)->flags & SUNZILOG_FLAG_REGS_HELD)
+#define ZS_TX_STOPPED(UP) ((UP)->flags & SUNZILOG_FLAG_TX_STOPPED)
+#define ZS_TX_ACTIVE(UP) ((UP)->flags & SUNZILOG_FLAG_TX_ACTIVE)
/* Reading and writing Zilog8530 registers. The delays are to make this
* driver work on the Sun4 which needs a settling delay after each chip
ZSDELAY();
}
-static void load_zsregs(struct zilog_channel *channel, unsigned char *regs,
- int is_channel_a)
+static void sunzilog_clear_fifo(struct zilog_channel *channel)
+{
+ int i;
+
+ for (i = 0; i < 32; i++) {
+ unsigned char regval;
+
+ regval = sbus_readb(&channel->control);
+ ZSDELAY();
+ if (regval & Rx_CH_AV)
+ break;
+
+ regval = read_zsreg(channel, R1);
+ sbus_readb(&channel->data);
+ ZSDELAY();
+
+ if (regval & (PAR_ERR | Rx_OVR | CRC_ERR)) {
+ sbus_writeb(ERR_RES, &channel->control);
+ ZSDELAY();
+ ZS_WSYNC(channel);
+ }
+ }
+}
+
+/* This function must only be called when the TX is not busy. The UART
+ * port lock must be held and local interrupts disabled.
+ */
+static void __load_zsregs(struct zilog_channel *channel, unsigned char *regs)
{
int i;
+ /* Let pending transmits finish. */
for (i = 0; i < 1000; i++) {
unsigned char stat = read_zsreg(channel, R1);
if (stat & ALL_SNT)
break;
udelay(100);
}
- write_zsreg(channel, R3, 0);
- ZS_CLEARSTAT(channel);
- ZS_CLEARERR(channel);
- ZS_CLEARFIFO(channel);
- if (is_channel_a)
- write_zsreg(channel, R9, CHRA);
- else
- write_zsreg(channel, R9, CHRB);
- ZSDELAY_LONG();
+ sbus_writeb(ERR_RES, &channel->control);
+ ZSDELAY();
+ ZS_WSYNC(channel);
+
+ sunzilog_clear_fifo(channel);
+ /* Disable all interrupts. */
+ write_zsreg(channel, R1,
+ regs[R1] & ~(RxINT_MASK | TxINT_ENAB | EXT_INT_ENAB));
+
+ /* Set parity, sync config, stop bits, and clock divisor. */
write_zsreg(channel, R4, regs[R4]);
+
+ /* Set misc. TX/RX control bits. */
+ write_zsreg(channel, R10, regs[R10]);
+
+ /* Set TX/RX controls sans the enable bits. */
write_zsreg(channel, R3, regs[R3] & ~RxENAB);
write_zsreg(channel, R5, regs[R5] & ~TxENAB);
- write_zsreg(channel, R9, regs[R9] & ~MIE);
- write_zsreg(channel, R10, regs[R10]);
+
+ /* Synchronous mode config. */
+ write_zsreg(channel, R6, regs[R6]);
+ write_zsreg(channel, R7, regs[R7]);
+
+ /* Don't mess with the interrupt vector (R2, unused by us) and
+ * master interrupt control (R9). We make sure this is setup
+ * properly at probe time then never touch it again.
+ */
+
+ /* Disable baud generator. */
+ write_zsreg(channel, R14, regs[R14] & ~BRENAB);
+
+ /* Clock mode control. */
write_zsreg(channel, R11, regs[R11]);
+
+ /* Lower and upper byte of baud rate generator divisor. */
write_zsreg(channel, R12, regs[R12]);
write_zsreg(channel, R13, regs[R13]);
- write_zsreg(channel, R14, regs[R14] & ~BRENAB);
+
+ /* Now rewrite R14, with BRENAB (if set). */
write_zsreg(channel, R14, regs[R14]);
- write_zsreg(channel, R14,
- (regs[R14] & ~SNRZI) | BRENAB);
- write_zsreg(channel, R3, regs[R3]);
- write_zsreg(channel, R5, regs[R5]);
+
+ /* External status interrupt control. */
write_zsreg(channel, R15, regs[R15]);
+
+ /* Reset external status interrupts. */
write_zsreg(channel, R0, RES_EXT_INT);
- write_zsreg(channel, R0, ERR_RES);
+ write_zsreg(channel, R0, RES_EXT_INT);
+
+ /* Rewrite R3/R5, this time without enables masked. */
+ write_zsreg(channel, R3, regs[R3]);
+ write_zsreg(channel, R5, regs[R5]);
+
+ /* Rewrite R1, this time without IRQ enabled masked. */
write_zsreg(channel, R1, regs[R1]);
- write_zsreg(channel, R9, regs[R9]);
}
-/* The port->lock must be held and interrupts must be disabled here. */
-static __inline__ unsigned char __sunzilog_read_channel_status(struct uart_port *port)
+/* Reprogram the Zilog channel HW registers with the copies found in the
+ * software state struct. If the transmitter is busy, we defer this update
+ * until the next TX complete interrupt. Else, we do it right now.
+ *
+ * The UART port lock must be held and local interrupts disabled.
+ */
+static void sunzilog_maybe_update_regs(struct zilog_channel *channel,
+ struct uart_sunzilog_port *up)
{
- struct zilog_channel *channel;
- unsigned char status;
-
- channel = ZILOG_CHANNEL_FROM_PORT(port);
- status = sbus_read(&channel->control);
- ZSDELAY();
-
- return status;
+ if (!ZS_REGS_HELD(up)) {
+ if (ZS_TX_ACTIVE(up)) {
+ up->flags |= SUNZILOG_FLAG_REGS_HELD;
+ } else {
+ __load_zsregs(channel, up->curregs);
+ }
+ }
}
-/* A convenient way to quickly get R0 status. The caller must _not_ hold the
- * port lock, it is acquired here. If you have the lock already invoke the
- * double-underscore variant above.
- */
-static unsigned char sunzilog_read_channel_status(struct uart_port *port)
+static void sunzilog_change_mouse_baud(struct uart_sunzilog_port *up)
{
- unsigned long flags;
- unsigned char status;
+ unsigned int cur_cflag = up->port.cflag;
+ int brg, new_baud;
- spin_lock_irqsave(&port->lock, flags);
- status = __sunzilog_read_channel_status(port);
- spin_unlock_irqrestore(&port->lock, flags);
+ up->port.cflag &= ~CBAUD;
+ up->port.cflag |= suncore_mouse_baud_cflag_next(cur_cflag, &new_baud);
- return status;
+ brg = BPS_TO_BRG(new_baud,
+ (ZS_CLOCK / ZS_CLOCK_DIVISOR));
+ up->curregs[R12] = (brg & 0xff);
+ up->curregs[R13] = (brg >> 8) & 0xff;
+ sunzilog_maybe_update_regs(ZILOG_CHANNEL_FROM_PORT(&up->port), up);
}
-/* A convenient way to set/clear bits in an arbitrary zilog register.
- * The caller must the port lock and local interrupts must be disabled.
- */
-static void __sunzilog_set_clear_bits(struct uart_port *port, int regnum,
- unsigned char set_bits,
- unsigned char clear_bits)
+static void sunzilog_kbdms_receive_chars(struct uart_sunzilog_port *up,
+ unsigned char ch, int is_break)
{
- unsigned char regval;
+ if (ZS_IS_KEYB(up)) {
+ if (ch == SUNKBD_RESET) {
+ up->kbd_id = 1;
+ up->l1_down = 0;
+ } else if (up->kbd_id) {
+ up->kbd_id = 0;
+ } else if (ch == SUNKBD_l1) {
+ up->l1_down = 1;
+ } else if (ch == (SUNKBD_l1 | SUNKBD_UP)) {
+ up->l1_down = 0;
+ } else if (ch == SUNKBD_A && up->l1_down) {
+ sun_do_break();
+ up->l1_down = 0;
+ up->kbd_id = 0;
+ return;
+ }
+#ifdef CONFIG_SERIO
+ serio_interrupt(&up->serio, ch, 0);
+#endif
+ } else if (ZS_IS_MOUSE(up)) {
+ int ret = suncore_mouse_baud_detection(ch, is_break);
+
+ switch (ret) {
+ case 2:
+ sunzilog_change_mouse_baud(up);
+ /* fallthru */
+ case 1:
+ break;
- regval = SUNZILOG_GET_CURR_REG(port, regnum);
- regval |= set_bits;
- regval &= ~clear_bits;
- SUNZILOG_SET_CURR_REG(port, regnum, regval);
- write_zsreg(ZILOG_CHANNEL_FROM_PORT(port), regnum, regval);
+ case 0:
+#ifdef CONFIG_SERIO
+ serio_interrupt(&up->serio, ch, 0);
+#endif
+ break;
+ };
+ }
}
-static void sunzilog_receive_chars(struct uart_sunzilog_port *sunzilog_port,
+static void sunzilog_receive_chars(struct uart_sunzilog_port *up,
struct sunzilog_channel *channel,
struct pt_regs *regs)
{
- struct tty_struct *tty = sunzilog_port->port.info->tty;
+ struct tty_struct *tty = up->port.info->tty;
while (1) {
unsigned char ch, r1;
ch = sbus_readb(&channel->data);
ZSDELAY();
- ch &= sunzilog_port->parity_mask;
-
- if (sunzilog_port->flags & SUNZILOG_FLAG_CONS_KEYB) {
- if (ch == SUNKBD_RESET) {
- sunzilog_port->kbd_id = 1;
- sunzilog_port->l1_down = 0;
- } else if (sunzilog_port->kbd_id) {
- sunzilog_port->kbd_id = 0;
- } else if (ch == SUNKBD_l1) {
- sunzilog_port->l1_down = 1;
- } else if (ch == (SUNKBD_l1 | SUNKBD_UP)) {
- sunzilog_port->l1_down = 0;
- } else if (ch == SUNKBD_A && sunzilog_port->l1_down) {
- sun_do_break();
- sunzilog_port->l1_down = 0;
- sunzilog_port->kbd_id = 0;
- return;
- }
- sunkbd_inchar(ch, regs);
- goto next_char;
- }
- if (sunzilog_port->flags & SUNZILOG_FLAG_CONS_MOUSE) {
- sun_mouse_inbyte(ch, 0);
+ ch &= up->parity_mask;
+
+ if (unlikely(ZS_IS_KEYB(up)) || unlikely(ZS_IS_MOUSE(up))) {
+ sunzilog_kbdms_receive_chars(up, ch, 0);
goto next_char;
}
- if ((sunzilog_port->flags & SUNZILOG_FLAG_IS_CONS) &&
- (r1 & BRK_ABRT)) {
+
+ if (ZS_IS_CONS(up) && (r1 & BRK_ABRT)) {
+ /* Wait for BREAK to deassert to avoid potentially
+ * confusing the PROM.
+ */
+ while (1) {
+ ch = sbus_readb(&channel->control);
+ ZSDELAY();
+ if (!(ch & BRK_ABRT))
+ break;
+ }
sun_do_break();
return;
}
#ifndef CONFIG_SPARC64
/* Look for kgdb 'stop' character. */
- if ((sunzilog_port->flags & SUNZILOG_FLAG_IS_KGDB) &&
- (ch == '\003')) {
+ if (ZS_IS_KGDB(up) && (ch == '\003')) {
breakpoint();
return;
}
/* A real serial line, record the character and status. */
*tty->flip.char_buf_ptr = ch;
*tty->flip.flag_buf_ptr = TTY_NORMAL;
- sunzilog_port->port.icount.rx++;
+ up->port.icount.rx++;
if (r1 & (BRK_ABRT | PAR_ERR | Rx_OVR | CRC_ERR)) {
if (r1 & BRK_ABRT) {
r1 &= ~(PAR_ERR | CRC_ERR);
- sunzilog_port->port.icount.break++;
- if (uart_handle_break(&sunzilog_port->port))
+ up->port.icount.break++;
+ if (uart_handle_break(&up->port))
goto next_char;
}
else if (r1 & PAR_ERR)
- sunzilog_port->port.icount.parity++;
+ up->port.icount.parity++;
else if (r1 & CRC_ERR)
- sunzilog_port->port.icount.frame++;
+ up->port.icount.frame++;
if (r1 & Rx_OVR)
- sunzilog_port->port.icount.overrun++;
- r1 &= sunzilog_port->port.read_status_mask;
+ up->port.icount.overrun++;
+ r1 &= up->port.read_status_mask;
if (r1 & BRK_ABRT)
*tty->flip.flag_buf_ptr = TTY_BREAK;
else if (r1 & PAR_ERR)
else if (r1 & CRC_ERR)
*tty->flip.flag_buf_ptr = TTY_FRAME;
}
- if (uart_handle_sysrq_char(&sunzilog_port->port, ch, regs))
+ if (uart_handle_sysrq_char(&up->port, ch, regs))
goto next_char;
if (up->ignore_status_mask == 0xff ||
- (r1 & sunzilog_port->port.ignore_status_mask) == 0) {
+ (r1 & up->port.ignore_status_mask) == 0) {
tty->flip.flag_buf_ptr++;
tty->flip.char_buf_ptr++;
tty->flip.count++;
tty_flip_buffer_push(tty);
}
-static void sunzilog_status_handle(struct uart_sunzilog_port *sunzilog_port,
+static void sunzilog_status_handle(struct uart_sunzilog_port *up,
struct sunzilog_channel *channel)
{
unsigned char status;
ZSDELAY();
ZS_WSYNC(channel);
- if ((status & BRK_ABRT) &&
- (sunzilog_port->flags & SUNZILOG_FLAG_CONS_MOUSE))
- sun_mouse_inbyte(0, 1);
+ if ((status & BRK_ABRT) && ZS_IS_MOUSE(up))
+ sunzilog_kbdms_receive_chars(up, 0, 1);
- if (sunzilog_port->flags & SUNZILOG_FLAG_MODEM_STATUS) {
+ if (ZS_WANTS_MODEM_STATUS(up)) {
if (status & SYNC)
- sunzilog_port->port.icount.dsr++;
+ up->port.icount.dsr++;
/* The Zilog just gives us an interrupt when DCD/CTS/etc. change.
* But it does not tell us which bit has changed, we have to keep
* track of this ourselves.
*/
- if ((status & DCD) ^ sunzilog_port->prev_status)
- uart_handle_dcd_change(&sunzilog_port->port,
- (status & DCD));
- if ((status & CTS) ^ sunzilog_port->prev_status)
- uart_handle_cts_change(&sunzilog_port->port,
+ if ((status & DCD) ^ up->prev_status)
+ uart_handle_dcd_change(&up->port,
+ (status & DCD));
+ if ((status & CTS) ^ up->prev_status)
+ uart_handle_cts_change(&up->port,
(status & CTS));
- wake_up_interruptible(&sunzilog_port->port.info->delta_msr_wait);
+ wake_up_interruptible(&up->port.info->delta_msr_wait);
}
- sunzilog_port->prev_status = status;
-}
-
-#define ZS_PUT_CHAR_MAX_DELAY 2000 /* 10 ms */
-
-static void sunzilog_put_char(struct sunzilog_channel *channel, unsigned char ch)
-{
- int loops = ZS_PUT_CHAR_MAX_DELAY;
-
- /* This is a timed polling loop so do not switch the explicit
- * udelay with ZSDELAY as that is a NOP on some platforms. -DaveM
- */
- do {
- unsigned char val = sbus_readb(&channel->control);
- if (val & Tx_BUF_EMP)
- break;
- udelay(5);
- } while (--loops);
-
- sbus_writeb(ch, &channel->data);
- ZSDELAY();
- ZS_WSYNC(channel);
+ up->prev_status = status;
}
-static void sunzilog_transmit_chars(struct uart_sunzilog_port *sunzilog_port,
+static void sunzilog_transmit_chars(struct uart_sunzilog_port *up,
struct sunzilog_channel *channel)
{
- struct circ_buf *xmit = &sunzilog_port->port.info->xmit;
- unsigned char status;
+ struct circ_buf *xmit = &up->port.info->xmit;
int count;
- status = sbus_readb(&channel->control);
- ZSDELAY();
+ if (ZS_IS_CONS(up)) {
+ unsigned char status = sbus_readb(&channel->control);
+ ZSDELAY();
- /* TX still busy? Just wait for the next TX done interrupt.
- * XXX This is a bug bug bug if it happens. It can occur because
- * XXX of how we used to do serial consoles on Sparc but we should
- * XXX transmit console writes just like we normally would for normal
- * XXX UART lines (ie. buffered and TX interrupt driven). -DaveM
- */
- if (!(status & Tx_BUF_EMP))
- return;
+ /* TX still busy? Just wait for the next TX done interrupt.
+ *
+ * It can occur because of how we do serial console writes. It would
+ * be nice to transmit console writes just like we normally would for
+ * a TTY line. (ie. buffered and TX interrupt driven). That is not
+ * easy because console writes cannot sleep. One solution might be
+ * to poll on enough port->xmit space becomming free. -DaveM
+ */
+ if (!(status & Tx_BUF_EMP))
+ return;
+ }
+
+ if (ZS_REGS_HELD(up)) {
+ __load_zsregs(channel, up->curregs);
+ up->flags &= ~SUNZILOG_FLAG_REGS_HELD;
+ }
+
+ if (ZS_TX_STOPPED(up)) {
+ up->flags &= ~SUNZILOG_FLAG_TX_STOPPED;
+ goto disable_tx_int;
+ }
- if (sunzilog_port->port.x_char) {
+ if (up->port.x_char) {
sbus_writeb(sunzilog->port.x_char, &channel->data);
ZSDELAY();
ZS_WSYNC(channel);
- sunzilog_port->port.icount.tx++;
- sunzilog_port->port.x_char = 0;
+ up->port.icount.tx++;
+ up->port.x_char = 0;
return;
}
- if (uart_circ_empty(xmit) || uart_tx_stopped(&sunzilog_port->port)) {
- sunzilog_stop_tx(&sunzilog_port->port, 0);
- return;
- }
+ if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port))
+ goto disable_tx_int;
sbus_writeb(xmit->buf[xmit->tail], &channel->data);
ZSDELAY();
ZS_WSYNC(channel);
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
- sunzilog_port->port.icount.tx++;
+ up->port.icount.tx++;
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
- uart_event(&sunzilog_port->port, EVT_WRITE_WAKEUP);
+ uart_event(&up->port, EVT_WRITE_WAKEUP);
+
+ if (!uart_circ_empty(xmit))
+ return;
- if (uart_circ_empty(xmit))
- sunzilog_stop_tx(&sunzilog_port->port, 0);
+disable_tx_int:
+ up->curregs[R5] &= ~TxENAB;
+ write_zsreg(ZILOG_CHANNEL_FROM_PORT(&up->port), R5, up->curregs[R5]);
}
static void sunzilog_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
- struct uart_sunzilog_port *sunzilog_port = dev_id;
+ struct uart_sunzilog_port *up = dev_id;
unsigned long flags;
- while (sunzilog_port) {
+ while (up) {
struct sunzilog_channel *channel
- = ZILOG_CHANNEL_FROM_PORT(&sunzilog_port.port);
- unsigned char r3;
+ = ZILOG_CHANNEL_FROM_PORT(&up->port);
+ unsigned char r3, status;
- spin_lock(&sunzilog_port->port.lock);
+ spin_lock(&up->port.lock);
r3 = read_zsreg(channel, 3);
/* Channel A */
ZS_WSYNC(channel);
if (r3 & CHARxIP)
- sunzilog_receive_chars(sunzilog_port, channel, regs);
+ sunzilog_receive_chars(up, channel, regs);
if (r3 & CHAEXT)
- sunzilog_status_handle(sunzilog_port, channel);
+ sunzilog_status_handle(up, channel);
if (r3 & CHATxIP)
- sunzilog_transmit_chars(sunzilog_port, channel);
+ sunzilog_transmit_chars(up, channel);
}
- spin_unlock(&sunzilog_port->port.lock);
+ spin_unlock(&up->port.lock);
/* Channel B */
- sunzilog_port = sunzilog_port->next;
- channel = ZILOG_CHANNEL_FROM_PORT(&sunzilog_port.port);
+ up = up->next;
+ channel = ZILOG_CHANNEL_FROM_PORT(&up.port);
- spin_lock(&sunzilog_port->port.lock);
+ spin_lock(&up->port.lock);
if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) {
sbus_writeb(RES_H_IUS, &channel->control);
ZSDELAY();
ZS_WSYNC(channel);
if (r3 & CHBRxIP)
- sunzilog_receive_chars(sunzilog_port, channel, regs);
+ sunzilog_receive_chars(up, channel, regs);
if (r3 & CHBEXT)
- sunzilog_status_handle(sunzilog_port, channel);
+ sunzilog_status_handle(up, channel);
if (r3 & CHBTxIP)
- sunzilog_transmit_chars(sunzilog_port, channel);
+ sunzilog_transmit_chars(up, channel);
}
- spin_unlock(&sunzilog_port->port.lock);
+ spin_unlock(&up->port.lock);
- sunzilog_port = sunzilog_port->next;
+ up = up->next;
}
- spin_lock_irqrestore(&sunzilog_lock, flags);
+}
+
+/* A convenient way to quickly get R0 status. The caller must _not_ hold the
+ * port lock, it is acquired here.
+ */
+static __inline__ unsigned char sunzilog_read_channel_status(struct uart_port *port)
+{
+ struct zilog_channel *channel;
+ unsigned long flags;
+ unsigned char status;
+
+ spin_lock_irqsave(&port->lock, flags);
+
+ channel = ZILOG_CHANNEL_FROM_PORT(port);
+ status = sbus_read(&channel->control);
+ ZSDELAY();
+
+ spin_unlock_irqrestore(&port->lock, flags);
+
+ return status;
}
/* The port lock is not held. */
/* The port lock is held and interrupts are disabled. */
static void sunzilog_set_mctrl(struct uart_port *port, unsigned int mctrl)
{
+ struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
+ struct sunzilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
unsigned char set_bits, clear_bits;
set_bits = clear_bits = 0;
else
clear_bits |= DTR;
- __sunzilog_set_clear_bits(port, 5, set_bits, clear_bits);
+ /* NOTE: Not subject to 'transmitter active' rule. */
+ up->curregs[R5] |= set_bits;
+ up->curregs[R5] &= ~clear_bits;
+ write_zsreg(channel, R5, up->curregs[R5]);
}
/* The port lock is held and interrupts are disabled. */
static void sunzilog_stop_tx(struct uart_port *port, unsigned int tty_stop)
{
- __sunzilog_set_clear_bits(port, 5, 0, TxENAB);
+ struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
+
+ up->flags |= SUNZILOG_FLAG_TX_STOPPED;
}
/* The port lock is held and interrupts are disabled. */
static void sunzilog_start_tx(struct uart_port *port, unsigned int tty_start)
{
struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
- struct sunzilog_channel *channel;
+ struct sunzilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
unsigned char status;
- /* Enable the transmitter. */
- __sunzilog_set_clear_bits(port, 5, TxENAB, 0);
+ up->flags |= SUNZILOG_FLAG_TX_ACTIVE;
+ up->flags &= ~SUNZILOG_FLAG_TX_STOPPED;
- channel = ZILOG_CHANNEL_FROM_PORT(port);
+ /* Enable the transmitter. */
+ if (!(up->curregs[R5] & TxENAB)) {
+ /* NOTE: Not subject to 'transmitter active' rule. */
+ up->curregs[R5] |= TxENAB;
+ write_zsreg(channel, R5, up->curregs[R5]);
+ }
status = sbus_readb(&channel->control);
ZSDELAY();
port->icount.tx++;
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
- uart_event(&sunzilog_port->port, EVT_WRITE_WAKEUP);
-
- if (uart_circ_empty(xmit))
- sunzilog_stop_tx(&sunzilog_port->port, 0);
+ uart_event(&up->port, EVT_WRITE_WAKEUP);
}
}
/* The port lock is not held. */
static void sunzilog_stop_rx(struct uart_port *port)
{
+ struct uart_sunzilog_port *up = UART_ZILOG(port);
+ struct sunzilog_channel *channel;
+ unsigned long flags;
+
+ spin_lock_irqsave(&port->lock, flags);
+
+ channel = ZILOG_CHANNEL_FROM_PORT(port);
+
+ /* Disable all RX interrupts. */
+ up->curregs[R1] &= ~RxINT_MASK;
+ sunzilog_maybe_update_regs(up, up->curregs);
+
+ spin_unlock_irqrestore(&port->lock, flags);
}
/* The port lock is not held. */
static void sunzilog_enable_ms(struct uart_port *port)
{
+ struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
+ struct sunzilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
+ unsigned char new_reg;
unsigned long flags;
spin_lock_irqsave(&port->lock, flags);
- __sunzilog_set_clear_bits(port, 15,
- (DCDIE | SYNCIE | CTSIE), 0);
+
+ new_reg = up->curregs[R15] | (DCDIE | SYNCIE | CTSIE);
+ if (new_reg != up->curregs[R15]) {
+ up->curregs[R15] = new_reg;
+
+ /* NOTE: Not subject to 'transmitter active' rule. */
+ write_zsreg(channel, R15, up->curregs[R15]);
+ }
+
spin_unlock_irqrestore(&port->lock, flags);
}
/* The port lock is not held. */
static void sunzilog_break_ctl(struct uart_port *port, int break_state)
{
- unsigned char set_bits, clear_bits;
+ struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
+ struct sunzilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
+ unsigned char set_bits, clear_bits, new_reg;
unsigned long flags;
set_bits = clear_bits = 0;
clear_bits |= SND_BRK;
spin_lock_irqsave(&port->lock, flags);
- __sunzilog_set_clear_bits(port, 5, set_bits, clear_bits);
+
+ new_reg = (up->curregs[R5] | set_bits) & ~clear_bits;
+ if (new_reg != up->curregs[R5]) {
+ up->curregs[R5] = new_reg;
+
+ /* NOTE: Not subject to 'transmitter active' rule. */
+ write_zsreg(channel, R5, up->curregs[R5]);
+ }
+
spin_unlock_irqrestore(&port->lock, flags);
}
static int sunzilog_startup(struct uart_port *port)
{
+ struct uart_sunzilog_port *up = UART_ZILOG(port);
+ struct sunzilog_channel *channel;
+ unsigned long flags;
+
+ spin_lock_irqsave(&port->lock, flags);
+
+ channel = ZILOG_CHANNEL_FROM_PORT(port);
+ up->prev_status = sbus_readb(&channel->control);
+
+ /* Enable receiver and transmitter. */
+ up->curregs[R3] |= RxENAB;
+ up->curregs[R5] |= TxENAB;
+
+ /* Enable RX and status interrupts. TX interrupts are enabled
+ * as needed.
+ */
+ up->curregs[R1] |= EXT_INT_ENAB | INT_ALL_Rx;
+ up->curregs[R9] |= MIE;
+ sunzilog_maybe_update_regs(up, up->curregs);
+
+ spin_unlock_irqrestore(&port->lock, flags);
}
static void sunzilog_shutdown(struct uart_port *port)
{
+ struct uart_sunzilog_port *up = UART_ZILOG(port);
+ struct sunzilog_channel *channel;
+ unsigned long flags;
+
+ spin_lock_irqsave(&port->lock, flags);
+
+ channel = ZILOG_CHANNEL_FROM_PORT(port);
+
+ /* Disable receiver and transmitter. */
+ up->curregs[R3] &= ~RxENAB;
+ up->curregs[R5] &= ~TxENAB;
+
+ /* Disable all interrupts and BRK assertion. */
+ up->curregs[R1] &= ~(EXT_INT_ENAB | TxINT_ENAB | RxINT_MASK);
+ up->curregs[R5] &= ~SND_BRK;
+ up->curregs[R9] &= ~MIE;
+ sunzilog_maybe_update_regs(up, up->curregs);
+
+ spin_unlock_irqrestore(&port->lock, flags);
}
-/* The port lock is not held. */
+/* Shared by TTY driver and serial console setup. The port lock is held
+ * and local interrupts are disabled.
+ */
static void
-sunzilog_change_speed(struct uart_port *port, unsigned int cflag,
- unsigned int iflag, unsigned int quot)
+sunzilog_convert_to_zs(struct uart_sunzilog_port *up, unsigned int cflag,
+ unsigned int iflag, int brg)
{
- struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
- unsigned long flags;
- spin_lock_irqsave(&up->port.lock, flags);
+ /* Don't modify MIE. */
+ up->curregs[R9] |= NV;
+
+ up->curregs[R10] = NRZ;
+ up->curregs[11] = TCBR | RCBR;
/* Program BAUD and clock source. */
up->curregs[4] &= ~XCLK_MASK;
up->curregs[4] |= X16CLK;
- up->curregs[11] = TCBR | RCBR;
- /* XXX verify this stuff XXX */
- up->curregs[12] = quot & 0xff;
- up->curregs[13] = (quot >> 8) & 0xff;
+ up->curregs[12] = brg & 0xff;
+ up->curregs[13] = (brg >> 8) & 0xff;
up->curregs[14] = BRSRC | BRENAB;
- up->curregs[15] |= RTS | DTR;
/* Character size, stop bits, and parity. */
up->curregs[3] &= ~RxN_MASK;
if ((cflag & CREAD) == 0)
up->ignore_status_mask = 0xff;
+}
+
+/* The port lock is not held. */
+static void
+sunzilog_change_speed(struct uart_port *port, unsigned int cflag,
+ unsigned int iflag, unsigned int quot)
+{
+ struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
+ unsigned long flags;
+ int baud, brg;
+
+ spin_lock_irqsave(&up->port.lock, flags);
+
+ baud = (ZILOG_CLOCK / (quot * 16));
+ brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
+
+ sunzilog_convert_to_zs(up, cflag, iflag, brg);
if (UART_ENABLE_MS(&up->port, cflag))
up->flags |= SUNZILOG_FLAG_MODEM_STATUS;
else
up->flags &= ~SUNZILOG_FLAG_MODEM_STATUS;
- load_zsregs(up, up->curregs);
+ sunzilog_maybe_update_regs(ZILOG_CHANNEL_FROM_PORT(port), up);
spin_unlock_irqrestore(&up->port.lock, flags);
}
static int sunzilog_request_port(struct uart_port *port)
{
+ return 0;
}
/* These do not need to do anything interesting either. */
{
}
+/* We do not support letting the user mess with the divisor, IRQ, etc. */
static int sunzilog_verify_port(struct uart_port *port, struct serial_struct *ser)
{
- return 0;
+ return -EINVAL;
}
static struct uart_ops sunzilog_pops = {
- tx_empty: sunzilog_tx_empty,
- set_mctrl: sunzilog_set_mctrl,
- get_mctrl: sunzilog_get_mctrl,
- stop_tx: sunzilog_stop_tx,
- start_tx: sunzilog_start_tx,
- stop_rx: sunzilog_stop_rx,
- enable_ms: sunzilog_enable_ms,
- break_ctl: sunzilog_break_ctl,
- startup: sunzilog_startup,
- shutdown: sunzilog_shutdown,
- change_speed: sunzilog_change_speed,
- type: sunzilog_type,
- release_port: sunzilog_release_port,
- request_port: sunzilog_request_port,
- config_port: sunzilog_config_port,
- verify_port: sunzilog_verify_port,
+ .tx_empty = sunzilog_tx_empty,
+ .set_mctrl = sunzilog_set_mctrl,
+ .get_mctrl = sunzilog_get_mctrl,
+ .stop_tx = sunzilog_stop_tx,
+ .start_tx = sunzilog_start_tx,
+ .stop_rx = sunzilog_stop_rx,
+ .enable_ms = sunzilog_enable_ms,
+ .break_ctl = sunzilog_break_ctl,
+ .startup = sunzilog_startup,
+ .shutdown = sunzilog_shutdown,
+ .change_speed = sunzilog_change_speed,
+ .type = sunzilog_type,
+ .release_port = sunzilog_release_port,
+ .request_port = sunzilog_request_port,
+ .config_port = sunzilog_config_port,
+ .verify_port = sunzilog_verify_port,
};
-static struct uart_sunzilog_port sunzilog_ports[UART_NR];
+static struct uart_sunzilog_port *sunzilog_port_table;
+static struct zilog_layout **sunzilog_chip_regs;
+
+static struct uart_sunzilog_port *sunzilog_irq_chain;
+static int zilog_irq = -1;
static struct uart_driver sunzilog_reg = {
- owner: THIS_MODULE,
- driver_name: "ttyS",
+ .owner = THIS_MODULE,
+ .driver_name = "ttyS",
#ifdef CONFIG_DEVFS_FS
- dev_name: "ttyS%d",
+ .dev_name = "ttyS%d",
#else
- dev_name: "ttyS",
+ .dev_name = "ttyS",
#endif
- major: TTY_MAJOR,
- minor: 64,
+ .major = TTY_MAJOR,
+ .minor = 64,
};
-static void * __init sunzilog_alloc_bootmem(unsigned long size)
+static void * __init sunzilog_alloc_one_table(unsigned long size)
{
void *ret;
- ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
+ ret = kmalloc(size, GFP_KERNEL);
if (ret != NULL)
memset(ret, 0, size);
static void __init sunzilog_alloc_tables(void)
{
- zs_chips = (struct sun_zslayout **)
- zs_alloc_bootmem(NUM_SERIAL * sizeof(struct sun_zslayout *));
- if (zs_chips == NULL)
- zs_init_alloc_failure("zs_chips");
- zs_channels = (struct sun_zschannel **)
- zs_alloc_bootmem(NUM_CHANNELS * sizeof(struct sun_zschannel *));
- if (zs_channels == NULL)
- zs_init_alloc_failure("zs_channels");
- zs_nodes = (int *)
- zs_alloc_bootmem(NUM_SERIAL * sizeof(int));
- if (zs_nodes == NULL)
- zs_init_alloc_failure("zs_nodes");
- zs_soft = (struct sun_serial *)
- zs_alloc_bootmem(NUM_CHANNELS * sizeof(struct sun_serial));
- if (zs_soft == NULL)
- zs_init_alloc_failure("zs_soft");
- zs_ttys = (struct tty_struct *)
- zs_alloc_bootmem(NUM_CHANNELS * sizeof(struct tty_struct));
- if (zs_ttys == NULL)
- zs_init_alloc_failure("zs_ttys");
- serial_table = (struct tty_struct **)
- zs_alloc_bootmem(NUM_CHANNELS * sizeof(struct tty_struct *));
- if (serial_table == NULL)
- zs_init_alloc_failure("serial_table");
- serial_termios = (struct termios **)
- zs_alloc_bootmem(NUM_CHANNELS * sizeof(struct termios *));
- if (serial_termios == NULL)
- zs_init_alloc_failure("serial_termios");
- serial_termios_locked = (struct termios **)
- zs_alloc_bootmem(NUM_CHANNELS * sizeof(struct termios *));
- if (serial_termios_locked == NULL)
- zs_init_alloc_failure("serial_termios_locked");
-}
-
-static int __init sunzilog_probe(void)
+ sunzilog_port_table = (struct uart_sunzilog_port *)
+ zs_alloc_one_table(NUM_CHANNELS * sizeof(struct uart_sunzilog_port));
+ sunzilog_chip_regs = (struct zilog_layout **)
+ zs_alloc_one_table(NUM_SUNZILOG * sizeof(struct zilog_layout *));
+ sunzilog_nodes = (int *)
+ zs_alloc_one_table(NUM_SUNZILOG * sizeof(int));
+
+ if (sunzilog_port_table == NULL ||
+ sunzilog_chip_regs == NULL ||
+ sunzilog_nodes == NULL) {
+ prom_printf("sunzilog_init: Cannot alloc SunZilog tables.\n");
+ prom_halt();
+ }
+}
+
+#ifdef CONFIG_SPARC64
+
+/* We used to attempt to use the address property of the Zilog device node
+ * but that totally is not necessary on sparc64.
+ */
+static struct zilog_layout * __init get_zs_sun4u(int chip)
+{
+ unsigned long mapped_addr;
+ unsigned int sun4u_ino;
+ int busnode, zsnode, seen;
+
+ if (central_bus)
+ busnode = central_bus->child->prom_node;
+ else
+ busnode = prom_searchsiblings(prom_getchild(prom_root_node), "sbus");
+
+ if (busnode == 0 || busnode == -1) {
+ prom_printf("SunZilog: Cannot find bus of Zilog %d in get_zs_sun4u.\n",
+ chip);
+ prom_halt();
+ }
+
+ zsnode = prom_getchild(busnode);
+ seen = 0;
+ while (zsnode) {
+ int slave;
+
+ zsnode = prom_searchsiblings(zsnode, "zs");
+ if (zsnode == 0 || zsnode == -1)
+ break;
+ slave = prom_getintdefault(zsnode, "slave", -1);
+ if ((slave == chip) || (seen == chip)) {
+ struct sbus_bus *sbus = NULL;
+ struct sbus_dev *sdev = NULL;
+ int err;
+
+ if (central_bus == NULL) {
+ for_each_sbus(sbus) {
+ for_each_sbusdev(sdev, sbus) {
+ if (sdev->prom_node == zsnode)
+ goto found;
+ }
+ }
+ }
+ found:
+ if (sdev == NULL && central_bus == NULL) {
+ prom_printf("SunZilog: sdev&¢ral == NULL for "
+ "Zilog %d in get_zs_sun4u.\n", chip);
+ prom_halt();
+ }
+ if (central_bus == NULL) {
+ mapped_addr =
+ sbus_ioremap(&sdev->resource[0], 0,
+ PAGE_SIZE,
+ "Zilog Registers");
+ } else {
+ struct linux_prom_registers zsregs[1];
+
+ err = prom_getproperty(zsnode, "reg",
+ (char *) &zsregs[0],
+ sizeof(zsregs));
+ if (err == -1) {
+ prom_printf("SunZilog: Cannot map "
+ "Zilog %d regs on "
+ "central bus.\n", chip);
+ prom_halt();
+ }
+ apply_fhc_ranges(central_bus->child,
+ &zsregs[0], 1);
+ apply_central_ranges(central_bus, &zsregs[0], 1);
+ mapped_addr =
+ (((u64)zsregs[0].which_io)<<32UL) |
+ ((u64)zsregs[0].phys_addr);
+ }
+
+ sunzilog_nodes[chip] = zsnode;
+ if (zilog_irq == -1) {
+ if (central_bus) {
+ unsigned long iclr, imap;
+
+ iclr = central_bus->child->fhc_regs.uregs
+ + FHC_UREGS_ICLR;
+ imap = central_bus->child->fhc_regs.uregs
+ + FHC_UREGS_IMAP;
+ zilog_irq = build_irq(12, 0, iclr, imap);
+ } else {
+ err = prom_getproperty(zsnode, "interrupts",
+ (char *) &sun4u_ino,
+ sizeof(sun4u_ino));
+ zilog_irq = sbus_build_irq(sbus_root, sun4u_ino);
+ }
+ }
+ break;
+ }
+ zsnode = prom_getsibling(zsnode);
+ seen++;
+ }
+
+ if (zsnode == 0 || zsnode == -1) {
+ prom_printf("SunZilog: Cannot find Zilog %d in get_zs_sun4u.\n", chip);
+ prom_halt();
+ }
+
+ return (struct zilog_layout *) mapped_addr;
+}
+#else /* CONFIG_SPARC64 */
+static struct zilog_layout * __init get_zs_sun4cmd(int chip)
+{
+ struct linux_prom_irqs irq_info[2];
+ unsigned long mapped_addr;
+ int zsnode, chipid, cpunode;
+
+ if (sparc_cpu_model == sun4d) {
+ int bbnode, walk, no;
+
+ zsnode = 0;
+ bbnode = 0;
+ no = 0;
+ for (walk = prom_getchild(prom_root_node);
+ (walk = prom_searchsiblings(walk, "cpu-unit")) != 0;
+ walk = prom_getsibling(walk)) {
+ bbnode = prom_getchild(walk);
+ if (bbnode &&
+ (bbnode = prom_searchsiblings(bbnode, "bootbus"))) {
+ if (no == (chip / 2)) {
+ cpunode = walk;
+ zsnode = prom_getchild(bbnode);
+ chipid = (chip & 1);
+ break;
+ }
+ no++;
+ }
+ }
+ if (!walk) {
+ prom_printf("SunZilog: Cannot find the %d'th bootbus on sun4d.\n",
+ (chip / 2));
+ prom_halt();
+ }
+ } else {
+ int tmp;
+
+ zsnode = prom_getchild(prom_root_node);
+ if ((tmp = prom_searchsiblings(zsnode, "obio"))) {
+ zsnode = prom_getchild(tmp);
+ if (!zsnode) {
+ prom_printf("SunZilog: Child of obio node does "
+ "not exist.\n");
+ prom_halt();
+ }
+ }
+ chipid = 0;
+ }
+
+ while (zsnode) {
+ struct linux_prom_registers zsreg[4];
+ struct resource res;
+
+ zsnode = prom_searchsiblings(zsnode, "zs");
+ if (zsnode == 0 || zsnode == -1)
+ break;
+
+ if (prom_getintdefault(zsnode, "slave", -1) != chipid) {
+ zsnode = prom_getsibling(zsnode);
+ continue;
+ }
+
+ if (sparc_cpu_model == sun4d) {
+ /* Sun4d Zilog nodes lack the address property, so just
+ * map it like a normal device.
+ */
+ if (prom_getproperty(zsnode, "reg",
+ (char *) zsreg, sizeof(zsreg)) == -1) {
+ prom_printf("SunZilog: Cannot map Zilog %d "
+ "regs on sun4c.\n", chip);
+ prom_halt();
+ }
+ prom_apply_generic_ranges(bbnode, cpunode, zsreg, 1);
+ res.start = zsreg[0].phys_addr;
+ res.end = res.start + (8 - 1);
+ res.flags = zsreg[0].which_io | IORESOURCE_IO;
+ mapped_addr = sbus_ioremap(&res, 0, 8, "Zilog Serial");
+ } else {
+ unsigned int vaddr[2];
+
+ if (prom_getproperty(zsnode, "address",
+ (void *) vaddr, sizeof(vaddr))
+ % sizeof(unsigned int)) {
+ prom_printf("SunZilog: Cannot get address property for "
+ "Zilog %d.\n", chip);
+ prom_halt();
+ }
+ mapped_addr = (unsigned long) vaddr[0];
+ }
+ sunzilog_nodes[chip] = zsnode;
+ if (prom_getproperty(zsnode, "intr",
+ (char *) irq_info, sizeof(irq_info))
+ % sizeof(struct linux_prom_irqs)) {
+ prom_printf("SunZilog: Cannot get IRQ property for "
+ "Zilog %d.\n", chip);
+ prom_halt();
+ }
+ if (zilog_irq == -1) {
+ zilog_irq = irq_info[0].pri;
+ } else if (zilog_irq != irq_info[0].pri) {
+ prom_printf("SunZilog: Inconsistent IRQ layout for Zilog %d.\n",
+ chip);
+ promt_halt();
+ }
+ break;
+ }
+ if (!zsnode) {
+ prom_printf("SunZilog: OBP node for Zilog %d not found.\n", chip);
+ prom_halt();
+ }
+
+ return (struct zilog_layout *) mapped_addr;
+}
+#endif /* !(CONFIG_SPARC64) */
+
+/* Get the address of the registers for SunZilog instance CHIP. */
+static struct zilog_layout * __init get_zs(int chip)
+{
+ if (chip < 0 || chip >= NUM_SUNZILOG) {
+ prom_printf("SunZilog: Illegal chip number %d in get_zs.\n", chip);
+ prom_halt();
+ }
+
+#ifdef CONFIG_SPARC64
+ return get_zs_sun4u(chip);
+#else
+
+ if (sparc_cpu_model == sun4) {
+ struct resource res;
+
+ /* Not probe-able, hard code it. */
+ switch (chip) {
+ case 0:
+ res.start = 0xf1000000;
+ break;
+ case 1:
+ res.start = 0xf0000000;
+ break;
+ };
+ sunzilog_nodes[chip] = 0;
+ zilog_irq = 12;
+ res.end = (res.start + (8 - 1));
+ res.flags = IORESOURCE_IO;
+ return sbus_ioremap(&res, 0, 8, "SunZilog");
+ }
+
+ return get_zs_sun4cmd(chip);
+#endif
+}
+
+#define ZS_PUT_CHAR_MAX_DELAY 2000 /* 10 ms */
+
+static void sunzilog_put_char(struct sunzilog_channel *channel, unsigned char ch)
+{
+ int loops = ZS_PUT_CHAR_MAX_DELAY;
+
+ /* This is a timed polling loop so do not switch the explicit
+ * udelay with ZSDELAY as that is a NOP on some platforms. -DaveM
+ */
+ do {
+ unsigned char val = sbus_readb(&channel->control);
+ if (val & Tx_BUF_EMP) {
+ ZSDELAY();
+ break;
+ }
+ udelay(5);
+ } while (--loops);
+
+ sbus_writeb(ch, &channel->data);
+ ZSDELAY();
+ ZS_WSYNC(channel);
+}
+
+#ifdef CONFIG_SERIO
+
+static spinlock_t sunzilog_serio_lock = SPIN_LOCK_UNLOCKED;
+
+static void sunzilog_serio_write(struct serio *serio, unsigned char ch)
+{
+ struct uart_sunzilog_port *up = serio->driver;
+ unsigned long flags;
+
+ spin_lock_irqsave(&sunzilog_serio_lock, flags);
+
+ sunzilog_put_char(channel, ch);
+
+ spin_lock_irqrestore(&sunzilog_serio_lock, flags);
+}
+
+static int sunzilog_serio_open(struct serio *serio)
+{
+ unsigned long flags;
+ int ret;
+
+ spin_lock_irqsave(&sunsu_serio_lock, flags);
+ if (serio->private == NULL) {
+ serio->private = (void *) -1L;
+ ret = 0;
+ } else
+ ret = -EBUSY;
+ spin_unlock_irqrestore(&sunsu_serio_lock, flags);
+
+ return ret;
+}
+
+static void sunzilog_serio_close(struct serio *serio)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&sunsu_serio_lock, flags);
+ serio->private = NULL;
+ spin_unlock_irqrestore(&sunsu_serio_lock, flags);
+}
+
+#endif /* CONFIG_SERIO */
+
+static void
+sunzilog_console_write(struct console *cons, const char *s, unsigned int count)
+{
+ struct uart_sunzilog_port *up = &sunzilog_port_table[con->index];
+ struct sunzilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
+ unsigned long flags;
+ int i;
+
+ spin_lock_irqsave(&up->port.lock, flags);
+ for (i = 0; i < count; i++, s++) {
+ sunzilog_put_char(channel, *s);
+ if (*s == 10)
+ sunzilog_put_char(channel, 13);
+ }
+ udelay(2);
+ spin_unlock_irqrestore(&up->port.lock, flags);
+}
+
+static kdev_t sunzilog_console_device(struct console *cons)
+{
+ return mk_kdev(TTY_MAJOR, 64 + con->index);
+}
+
+static int __init sunzilog_console_setup(struct console *cons, char *options)
+{
+ struct uart_sunzilog_port *up = &sunzilog_port_table[con->index];
+ unsigned long flags;
+ int baud, brg;
+
+ printk("Console: ttyS%d (Zilog8530)\n", con->index / 2);
+
+ /* Get firmware console settings. */
+ sunserial_console_termios(con);
+
+ /* Firmware console speed is limited to 150-->38400 baud so
+ * this hackish cflag thing is OK.
+ */
+ switch(cflag & CBAUD) {
+ case B150: baud = 150; break;
+ case B300: baud = 300; break;
+ case B600: baud = 600; break;
+ case B1200: baud = 1200; break;
+ case B2400: baud = 2400; break;
+ case B4800: baud = 4800; break;
+ default: case B9600: baud = 9600; break;
+ case B19200: baud = 19200; break;
+ case B38400: baud = 38400; break;
+ };
+
+ brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
+
+ /*
+ * Temporary fix.
+ */
+ spin_lock_init(&up->port.lock);
+
+ spin_lock_irqsave(&up->port.lock, flags);
+
+ up->curregs[R15] = BRKIE;
+
+ sunzilog_convert_to_zs(up, con->cflag, 0, brg);
+
+ spin_unlock_irqrestore(&up->port.lock, flags);
+
+ sunzilog_set_mctrl(up, TIOCM_DTR | TIOCM_RTS);
+ sunzilog_startup(up);
+}
+
+static struct console sunzilog_console = {
+ .name = "ttyS",
+ .write = sunzilog_console_write,
+ .device = sunzilog_console_device,
+ .setup = sunzilog_console_setup,
+ .flags = CON_PRINTBUFFER,
+ .index = -1,
+};
+
+static int __init sunzilog_console_init(void)
+{
+ if (con_is_present())
+ return 0;
+
+ sunzilog_console.index = serial_console - 1;
+ register_console(&sunzilog_console);
+ return 0;
+}
+
+static void __init sunzilog_prepare(void)
+{
+ struct uart_sunzilog_port *up;
+ struct zilog_layout *rp;
+ int channel, chip;
+
+ sunzilog_irq_chain = up = &sunzilog_port_table[0];
+ for (channel = 0; channel < NUM_CHANNELS - 1; channel++)
+ up[channel].next = &up[channel + 1];
+ up[channel].next = NULL;
+
+ for (chip = 0; chip < NUM_SUNZILOG; chip++) {
+ if (!sunzilog_chip_regs[chip]) {
+ sunzilog_chip_regs[chip] = rp = get_zs(chip);
+
+ up[(chip * 2) + 0].port.membase = &rp->channelA;
+ up[(chip * 2) + 1].port.membase = &rp->channelB;
+ }
+
+ /* Channel A */
+ up[(chip * 2) + 0].port.iotype = SERIAL_IO_MEM;
+ up[(chip * 2) + 0].port.irq = zilog_irq;
+ up[(chip * 2) + 0].port.uartclk = ZILOG_CLOCK;
+ up[(chip * 2) + 0].port.fifosize = 1;
+ up[(chip * 2) + 0].port.ops = &sunzilog_pops;
+ up[(chip * 2) + 0].port.flags = 0;
+ up[(chip * 2) + 0].port.line = (chip * 2) + 0;
+ up[(chip * 2) + 0].flags |= SUNZILOG_FLAG_IS_CHANNEL_A;
+
+ /* Channel B */
+ up[(chip * 2) + 1].port.iotype = SERIAL_IO_MEM;
+ up[(chip * 2) + 1].port.irq = zilog_irq;
+ up[(chip * 2) + 1].port.uartclk = ZILOG_CLOCK;
+ up[(chip * 2) + 1].port.fifosize = 1;
+ up[(chip * 2) + 1].port.ops = &sunzilog_pops;
+ up[(chip * 2) + 1].port.flags = 0;
+ up[(chip * 2) + 1].port.line = (chip * 2) + 1;
+ up[(chip * 2) + 1].flags |= 0;
+ }
+}
+
+static void __init sunzilog_init_kbdms(struct uart_sunzilog_port *up, int channel)
+{
+ int baud, brg;
+
+ if (channel == KEYBOARD_LINE) {
+ up->flags |= SUNZILOG_FLAG_CONS_KEYB;
+ up->port.cflag = B1200 | CS8 | CLOCAL | CREAD;
+ baud = 1200;
+ } else {
+ up->flags |= SUNZILOG_FLAG_CONS_MOUSE;
+ up->port.cflag = B4800 | CS8 | CLOCAL | CREAD;
+ baud = 4800;
+ }
+ printk(KERN_INFO "zs%d at 0x%p (irq = %s) is a Zilog8530\n",
+ channel, up->port.membase, __irq_itoa(zilog_irq));
+
+ up->curregs[R15] = BRKIE;
+ brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
+ sunzilog_convert_to_zs(up, up->port.cflag, 0, brg);
+
+#ifdef CONFIG_SERIO
+ memset(&up->serio, 0, sizeof(up->serio));
+
+ up->serio.driver = up;
+
+ up->serio.type = SERIO_RS232;
+ if (channel == KEYBOARD_LINE) {
+ up->serio.type |= SERIO_SUNKBD;
+ up->serio.name = "zskbd";
+ } else {
+ up->serio.type |= SERIO_SUN;
+ up->serio.name = "zsms";
+ }
+ up->phys = (channel == KEYBOARD_LINE ?
+ "zs/serio0" : "zs/serio1");
+
+ up->serio.write = sunzilog_serio_write;
+ up->serio.open = sunzilog_serio_open;
+ up->serio.close = sunzilog_serio_close;
+
+ serio_register_port(&up->serio);
+#endif
+
+ spin_unlock(&up->port.lock);
+ sunzilog_set_mctrl(up, TIOCM_DTR | TIOCM_RTS);
+ sunzilog_startup(&up->port);
+ spin_lock(&up->port.lock);
+}
+
+static void __init sunzilog_init_hw(void)
+{
+ int channel;
+
+ for (channel = 0; channel < NUM_CHANNELS; channel++) {
+ struct uart_sunzilog_port *up = &sunzilog_port_table[channel];
+ struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
+ unsigned long flags;
+ int baud, brg;
+
+ spin_lock_irqsave(&up->port.lock, flags);
+
+ if (ZS_IS_CHANNEL_A(up)) {
+ write_zsreg(channel, R9, FHWRES);
+ ZSDELAY_LONG();
+ (void) read_zsreg(channel, R0);
+ }
+
+ if (channel == KEYBOARD_LINE || channel == MOUSE_LINE) {
+ sunzilog_init_kbdms(up, channel);
+ } else if (ZS_IS_CONS(up)) {
+ /* sunzilog_console_setup takes care of this */
+ } else {
+ /* Normal serial TTY. */
+ up->parity_mask = 0xff;
+ up->curregs[R3] = RxENAB;
+ up->curregs[R5] = TxENAB;
+ up->curregs[R9] = NV | MIE;
+ up->curregs[R10] = NRZ;
+ up->curregs[R11] = TCBR | RCBR;
+ baud = 9600;
+ brg = BPS_TO_BRG(baud, (ZS_CLOCK / ZS_CLOCK_DIVISOR));
+ up->curregs[R12] = (brg & 0xff);
+ up->curregs[R13] = (brg >> 8) & 0xff;
+ up->curregs[R14] = BRSRC | BRENAB;
+ sunzilog_maybe_update_regs(channel, up->curregs);
+ }
+
+ spin_unlock_irqrestore(&up->port.lock, flags);
+ }
+}
+
+static int __init sunzilog_ports_init(void)
+{
+ int ret;
+
+ printk(KERN_INFO "Serial: Sun Zilog driver.\n");
+
+ sunzilog_prepare();
+
+ if (request_irq(zilog_irq, sunzilog_interrupt, SA_SHIRQ,
+ "SunZilog", sunzilog_irq_chain)) {
+ prom_printf("SunZilog: Unable to register zs interrupt handler.\n");
+ prom_halt();
+ }
+
+ sunzilog_init_hw();
+
+ /* We can only init this once we have probed the Zilogs
+ * in the system.
+ */
+ sunzilog_reg.nr = NUM_CHANNELS;
+
+#ifdef CONFIG_SERIAL_CONSOLE
+ sunzilog_reg.cons = &sunzilog_console;
+#else
+ sunzilog_reg.cons = NULL;
+#endif
+
+ ret = uart_register_driver(&sunzilog_reg);
+ if (ret == 0) {
+ int i;
+
+ for (i = 0; i < NUM_CHANNELS; i++) {
+ if (ZS_IS_KEYB(up) || ZS_IS_MOUSE(up))
+ continue;
+
+ uart_add_one_port(&sunzilog_reg,
+ &sunzilog_port_table[i].port);
+ }
+ }
+
+ return ret;
+}
+
+static int __init sunzilog_init(void)
{
int node;
/* Sun4 Zilog setup is hard coded, no probing to do. */
- if (sparc_cpu_model == sun4)
+ if (sparc_cpu_model == sun4) {
+ NUM_SUNZILOG = 2;
goto no_probe;
+ }
- NUM_SUNZILOG = 0;
node = prom_getchild(prom_root_node);
if (sparc_cpu_model == sun4d) {
int bbnode;
+ NUM_SUNZILOG = 0;
while (node &&
(node = prom_searchsiblings(node, "cpu-unit"))) {
bbnode = prom_getchild(node);
node = prom_getsibling(node);
}
goto no_probe;
- }
-
-#ifdef CONFIG_SPARC64
- else if (sparc_cpu_model == sun4u) {
+ } else if (sparc_cpu_model == sun4u) {
int central_node;
/* Central bus zilogs must be checked for first,
* since Enterprise boxes might have SBUSes as well.
*/
central_node = prom_finddevice("/central");
- if(central_node != 0 && central_node != -1)
+ if (central_node != 0 && central_node != -1)
node = prom_searchsiblings(prom_getchild(central_node), "fhc");
else
node = prom_searchsiblings(node, "sbus");
- if(node != 0 && node != -1)
+ if (node != 0 && node != -1)
node = prom_getchild(node);
- if(node == 0 || node == -1)
+ if (node == 0 || node == -1)
return -ENODEV;
- }
-#endif /* CONFIG_SPARC64 */
- else {
+ } else {
node = prom_searchsiblings(node, "obio");
- if(node)
+ if (node)
node = prom_getchild(node);
- NUM_SERIAL = 2;
+ NUM_SUNZILOG = 2;
goto no_probe;
}
if (!node)
return -ENODEV;
- NUM_SERIAL = 2;
+ NUM_SUNZILOG = 2;
no_probe:
- sunzilog_alloc_tables();
-}
-
-static int __init sunzilog_init(void)
-{
- int ret;
-
- printk(KERN_INFO "Serial: Sun Zilog driver.\n");
-
- /* We can only init this once we have probed the Zilogs
- * in the system.
- */
- sunzilog_reg.nr = NUM_CHANNELS;
-
- /* XXX This is probably where this needs to be setup for
- * XXX the same reason.
- */
- sunzilog_reg.cons = XXX;
-
- ret = uart_register_driver(&sunzilog_reg);
- if (ret == 0) {
- int i;
+ sunzilog_alloc_tables();
- for (i = 0; i < UART_NR; i++) {
- /* XXX For each probed Zilog do this... */
- uart_add_one_port(&sunzilog_reg,
- &sunzilog_ports[i].port);
- }
- }
+ sunzilog_ports_init();
+ sunzilog_console_init();
- return ret;
+ return 0;
}
static void __exit sunzilog_exit(void)
{
int i;
- for (i = 0; i < UART_NR; i++) {
- /* XXX For each probed Zilog do this... */
+ for (i = 0; i < NUM_CHANNELS; i++) {
+ if (ZS_IS_KEYB(up) || ZS_IS_MOUSE(up))
+ continue;
+
uart_remove_one_port(&sunzilog_reg,
- &sunzilog_ports[i].port);
+ &sunzilog_port_table[i].port);
}
uart_unregister_driver(&sunzilog_reg);