Commit 8ea0d85c authored by Helge Deller's avatar Helge Deller Committed by Vojtech Pavlik

input: HP HIL support (from PARISC Linux tree).

From: Helge Deller <deller@gmx.de>
Signed-off-by: default avatarVojtech Pavlik <vojtech@suse.cz>
parent 388e6f0d
...@@ -30,6 +30,44 @@ config KEYBOARD_ATKBD ...@@ -30,6 +30,44 @@ config KEYBOARD_ATKBD
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called atkbd. module will be called atkbd.
config KEYBOARD_ATKBD_HP_KEYCODES
bool "Use HP keyboard scancodes"
depends on PARISC && KEYBOARD_ATKBD
default y
help
Say Y here if you have a PA-RISC machine and want to use an AT or
PS/2 keyboard, and your keyboard uses keycodes that are specific to
PA-RISC keyboards.
Say N if you use a standard keyboard.
config KEYBOARD_ATKBD_RDI_KEYCODES
bool "Use PrecisionBook keyboard scancodes"
depends on KEYBOARD_ATKBD_HP_KEYCODES
default n
help
If you have an RDI PrecisionBook, say Y here if you want to use its
built-in keyboard (as opposed to an external keyboard).
The PrecisionBook has five keys that conflict with those used by most
AT and PS/2 keyboards. These are as follows:
PrecisionBook Standard AT or PS/2
F1 F12
Left Ctrl Left Alt
Caps Lock Left Ctrl
Right Ctrl Caps Lock
Left 102nd key (the key to the right of Left Shift)
If you say N here, and use the PrecisionBook keyboard, then each key
in the left-hand column will be interpreted as the corresponding key
in the right-hand column.
If you say Y here, and use an external keyboard, then each key in the
right-hand column will be interpreted as the key shown in the
left-hand column.
config KEYBOARD_SUNKBD config KEYBOARD_SUNKBD
tristate "Sun Type 4 and Type 5 keyboard" tristate "Sun Type 4 and Type 5 keyboard"
select SERIO select SERIO
...@@ -105,4 +143,34 @@ config KEYBOARD_AMIGA ...@@ -105,4 +143,34 @@ config KEYBOARD_AMIGA
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called amikbd. module will be called amikbd.
config KEYBOARD_HIL_OLD
tristate "HP HIL keyboard support (simple driver)"
depends on GSC
default y
help
The "Human Interface Loop" is a older, 8-channel USB-like
controller used in several Hewlett Packard models. This driver
was adapted from the one written for m68k/hp300, and implements
support for a keyboard attached to the HIL port, but not for
any other types of HIL input devices like mice or tablets.
However, it has been thoroughly tested and is stable.
If you want full HIL support including support for multiple
keyboards, mices and tablets, you have to enable the
"HP System Device Controller i8042 Support" in the input/serio
submenu.
config KEYBOARD_HIL
tristate "HP HIL keyboard support"
depends on GSC
default y
select HP_SDC
select HIL_MLC
select SERIO
help
The "Human Interface Loop" is a older, 8-channel USB-like
controller used in several Hewlett Packard models.
This driver implements support for HIL-keyboards attached
to your machine, so normally you should say Y here.
endif endif
...@@ -13,3 +13,6 @@ obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o ...@@ -13,3 +13,6 @@ obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o
obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o
obj-$(CONFIG_KEYBOARD_98KBD) += 98kbd.o obj-$(CONFIG_KEYBOARD_98KBD) += 98kbd.o
obj-$(CONFIG_KEYBOARD_CORGI) += corgikbd.o obj-$(CONFIG_KEYBOARD_CORGI) += corgikbd.o
obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o
obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o
...@@ -71,12 +71,15 @@ __obsolete_setup("atkbd_softrepeat="); ...@@ -71,12 +71,15 @@ __obsolete_setup("atkbd_softrepeat=");
* are loadable via an userland utility. * are loadable via an userland utility.
*/ */
#if defined(__hppa__)
#include "hpps2atkbd.h"
#else
static unsigned char atkbd_set2_keycode[512] = { static unsigned char atkbd_set2_keycode[512] = {
#ifdef CONFIG_KEYBOARD_ATKBD_HP_KEYCODES
/* XXX: need a more general approach */
#include "hpps2atkbd.h" /* include the keyboard scancodes */
#else
0, 67, 65, 63, 61, 59, 60, 88, 0, 68, 66, 64, 62, 15, 41,117, 0, 67, 65, 63, 61, 59, 60, 88, 0, 68, 66, 64, 62, 15, 41,117,
0, 56, 42, 93, 29, 16, 2, 0, 0, 0, 44, 31, 30, 17, 3, 0, 0, 56, 42, 93, 29, 16, 2, 0, 0, 0, 44, 31, 30, 17, 3, 0,
0, 46, 45, 32, 18, 5, 4, 95, 0, 57, 47, 33, 20, 19, 6,183, 0, 46, 45, 32, 18, 5, 4, 95, 0, 57, 47, 33, 20, 19, 6,183,
...@@ -96,9 +99,8 @@ static unsigned char atkbd_set2_keycode[512] = { ...@@ -96,9 +99,8 @@ static unsigned char atkbd_set2_keycode[512] = {
110,111,108,112,106,103, 0,119, 0,118,109, 0, 99,104,119, 0, 110,111,108,112,106,103, 0,119, 0,118,109, 0, 99,104,119, 0,
0, 0, 0, 65, 99, 0, 0, 0, 65, 99,
};
#endif #endif
};
static unsigned char atkbd_set3_keycode[512] = { static unsigned char atkbd_set3_keycode[512] = {
......
/*
* Generic linux-input device driver for keyboard devices
*
* Copyright (c) 2001 Brian S. Julin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL").
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
*
* References:
* HP-HIL Technical Reference Manual. Hewlett Packard Product No. 45918A
*
*/
#include <linux/hil.h>
#include <linux/input.h>
#include <linux/serio.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/pci_ids.h>
#define PREFIX "HIL KEYB: "
#define HIL_GENERIC_NAME "HIL keyboard"
MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
MODULE_DESCRIPTION(HIL_GENERIC_NAME " driver");
MODULE_LICENSE("Dual BSD/GPL");
#define HIL_KBD_MAX_LENGTH 16
#define HIL_KBD_SET1_UPBIT 0x01
#define HIL_KBD_SET1_SHIFT 1
static unsigned int hil_kbd_set1[HIL_KEYCODES_SET1_TBLSIZE] =
{ HIL_KEYCODES_SET1 };
#define HIL_KBD_SET2_UPBIT 0x01
#define HIL_KBD_SET2_SHIFT 1
/* Set2 is user defined */
#define HIL_KBD_SET3_UPBIT 0x80
#define HIL_KBD_SET3_SHIFT 0
static unsigned int hil_kbd_set3[HIL_KEYCODES_SET3_TBLSIZE] =
{ HIL_KEYCODES_SET3 };
static char hil_language[][16] = { HIL_LOCALE_MAP };
struct hil_kbd {
struct input_dev dev;
struct serio *serio;
/* Input buffer and index for packets from HIL bus. */
hil_packet data[HIL_KBD_MAX_LENGTH];
int idx4; /* four counts per packet */
/* Raw device info records from HIL bus, see hil.h for fields. */
char idd[HIL_KBD_MAX_LENGTH]; /* DID byte and IDD record */
char rsc[HIL_KBD_MAX_LENGTH]; /* RSC record */
char exd[HIL_KBD_MAX_LENGTH]; /* EXD record */
char rnm[HIL_KBD_MAX_LENGTH + 1]; /* RNM record + NULL term. */
/* Something to sleep around with. */
struct semaphore sem;
};
/* Process a complete packet after transfer from the HIL */
static void hil_kbd_process_record(struct hil_kbd *kbd)
{
struct input_dev *dev = &kbd->dev;
hil_packet *data = kbd->data;
hil_packet p;
int idx, i, cnt;
idx = kbd->idx4/4;
p = data[idx - 1];
if ((p & ~HIL_CMDCT_POL) ==
(HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL)) goto report;
if ((p & ~HIL_CMDCT_RPL) ==
(HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_RPL)) goto report;
/* Not a poll response. See if we are loading config records. */
switch (p & HIL_PKT_DATA_MASK) {
case HIL_CMD_IDD:
for (i = 0; i < idx; i++)
kbd->idd[i] = kbd->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_KBD_MAX_LENGTH; i++)
kbd->idd[i] = 0;
break;
case HIL_CMD_RSC:
for (i = 0; i < idx; i++)
kbd->rsc[i] = kbd->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_KBD_MAX_LENGTH; i++)
kbd->rsc[i] = 0;
break;
case HIL_CMD_EXD:
for (i = 0; i < idx; i++)
kbd->exd[i] = kbd->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_KBD_MAX_LENGTH; i++)
kbd->exd[i] = 0;
break;
case HIL_CMD_RNM:
for (i = 0; i < idx; i++)
kbd->rnm[i] = kbd->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_KBD_MAX_LENGTH + 1; i++)
kbd->rnm[i] = '\0';
break;
default:
/* These occur when device isn't present */
if (p == (HIL_ERR_INT | HIL_PKT_CMD)) break;
/* Anything else we'd like to know about. */
printk(KERN_WARNING PREFIX "Device sent unknown record %x\n", p);
break;
}
goto out;
report:
cnt = 1;
switch (kbd->data[0] & HIL_POL_CHARTYPE_MASK) {
case HIL_POL_CHARTYPE_NONE:
break;
case HIL_POL_CHARTYPE_ASCII:
while (cnt < idx - 1)
input_report_key(dev, kbd->data[cnt++] & 0x7f, 1);
break;
case HIL_POL_CHARTYPE_RSVD1:
case HIL_POL_CHARTYPE_RSVD2:
case HIL_POL_CHARTYPE_BINARY:
while (cnt < idx - 1)
input_report_key(dev, kbd->data[cnt++], 1);
break;
case HIL_POL_CHARTYPE_SET1:
while (cnt < idx - 1) {
unsigned int key;
int up;
key = kbd->data[cnt++];
up = key & HIL_KBD_SET1_UPBIT;
key &= (~HIL_KBD_SET1_UPBIT & 0xff);
key = hil_kbd_set1[key >> HIL_KBD_SET1_SHIFT];
if (key != KEY_RESERVED)
input_report_key(dev, key, !up);
}
break;
case HIL_POL_CHARTYPE_SET2:
while (cnt < idx - 1) {
unsigned int key;
int up;
key = kbd->data[cnt++];
up = key & HIL_KBD_SET2_UPBIT;
key &= (~HIL_KBD_SET1_UPBIT & 0xff);
key = key >> HIL_KBD_SET2_SHIFT;
if (key != KEY_RESERVED)
input_report_key(dev, key, !up);
}
break;
case HIL_POL_CHARTYPE_SET3:
while (cnt < idx - 1) {
unsigned int key;
int up;
key = kbd->data[cnt++];
up = key & HIL_KBD_SET3_UPBIT;
key &= (~HIL_KBD_SET1_UPBIT & 0xff);
key = hil_kbd_set3[key >> HIL_KBD_SET3_SHIFT];
if (key != KEY_RESERVED)
input_report_key(dev, key, !up);
}
break;
}
out:
kbd->idx4 = 0;
up(&kbd->sem);
}
static void hil_kbd_process_err(struct hil_kbd *kbd) {
printk(KERN_WARNING PREFIX "errored HIL packet\n");
kbd->idx4 = 0;
up(&kbd->sem);
}
static irqreturn_t hil_kbd_interrupt(struct serio *serio,
unsigned char data, unsigned int flags, struct pt_regs *regs)
{
struct hil_kbd *kbd;
hil_packet packet;
int idx;
kbd = (struct hil_kbd *)serio->private;
if (kbd == NULL) {
BUG();
return IRQ_HANDLED;
}
if (kbd->idx4 >= (HIL_KBD_MAX_LENGTH * sizeof(hil_packet))) {
hil_kbd_process_err(kbd);
return IRQ_HANDLED;
}
idx = kbd->idx4/4;
if (!(kbd->idx4 % 4)) kbd->data[idx] = 0;
packet = kbd->data[idx];
packet |= ((hil_packet)data) << ((3 - (kbd->idx4 % 4)) * 8);
kbd->data[idx] = packet;
/* Records of N 4-byte hil_packets must terminate with a command. */
if ((++(kbd->idx4)) % 4) return IRQ_HANDLED;
if ((packet & 0xffff0000) != HIL_ERR_INT) {
hil_kbd_process_err(kbd);
return IRQ_HANDLED;
}
if (packet & HIL_PKT_CMD) hil_kbd_process_record(kbd);
return IRQ_HANDLED;
}
static void hil_kbd_disconnect(struct serio *serio)
{
struct hil_kbd *kbd;
kbd = (struct hil_kbd *)serio->private;
if (kbd == NULL) {
BUG();
return;
}
input_unregister_device(&kbd->dev);
serio_close(serio);
kfree(kbd);
}
static void hil_kbd_connect(struct serio *serio, struct serio_driver *drv)
{
struct hil_kbd *kbd;
uint8_t did, *idd;
int i;
if (serio->type != (SERIO_HIL_MLC | SERIO_HIL)) return;
if (!(kbd = kmalloc(sizeof(struct hil_kbd), GFP_KERNEL))) return;
memset(kbd, 0, sizeof(struct hil_kbd));
if (serio_open(serio, drv)) goto bail0;
serio->private = kbd;
kbd->serio = serio;
kbd->dev.private = kbd;
init_MUTEX_LOCKED(&(kbd->sem));
/* Get device info. MLC driver supplies devid/status/etc. */
serio->write(serio, 0);
serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_IDD);
down(&(kbd->sem));
serio->write(serio, 0);
serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_RSC);
down(&(kbd->sem));
serio->write(serio, 0);
serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_RNM);
down(&(kbd->sem));
serio->write(serio, 0);
serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_EXD);
down(&(kbd->sem));
up(&(kbd->sem));
did = kbd->idd[0];
idd = kbd->idd + 1;
switch (did & HIL_IDD_DID_TYPE_MASK) {
case HIL_IDD_DID_TYPE_KB_INTEGRAL:
case HIL_IDD_DID_TYPE_KB_ITF:
case HIL_IDD_DID_TYPE_KB_RSVD:
case HIL_IDD_DID_TYPE_CHAR:
printk(KERN_INFO PREFIX "HIL keyboard found (did = 0x%02x, lang = %s)\n",
did, hil_language[did & HIL_IDD_DID_TYPE_KB_LANG_MASK]);
break;
default:
goto bail1;
}
if(HIL_IDD_NUM_BUTTONS(idd) || HIL_IDD_NUM_AXES_PER_SET(*idd)) {
printk(KERN_INFO PREFIX "keyboards only, no combo devices supported.\n");
goto bail1;
}
kbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
kbd->dev.ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL);
kbd->dev.keycodemax = HIL_KEYCODES_SET1_TBLSIZE;
kbd->dev.keycodesize = sizeof(hil_kbd_set1[0]);
kbd->dev.keycode = hil_kbd_set1;
kbd->dev.name = strlen(kbd->rnm) ? kbd->rnm : HIL_GENERIC_NAME;
kbd->dev.phys = "hpkbd/input0"; /* XXX */
kbd->dev.id.bustype = BUS_HIL;
kbd->dev.id.vendor = PCI_VENDOR_ID_HP;
kbd->dev.id.product = 0x0001; /* TODO: get from kbd->rsc */
kbd->dev.id.version = 0x0100; /* TODO: get from kbd->rsc */
kbd->dev.dev = &serio->dev;
for (i = 0; i < 128; i++) {
set_bit(hil_kbd_set1[i], kbd->dev.keybit);
set_bit(hil_kbd_set3[i], kbd->dev.keybit);
}
clear_bit(0, kbd->dev.keybit);
input_register_device(&kbd->dev);
printk(KERN_INFO "input: %s, ID: %d\n",
kbd->dev.name, did);
serio->write(serio, 0);
serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_EK1); /* Enable Keyswitch Autorepeat 1 */
down(&(kbd->sem));
up(&(kbd->sem));
return;
bail1:
serio_close(serio);
bail0:
kfree(kbd);
}
struct serio_driver hil_kbd_serio_drv = {
.driver = {
.name = "hil_kbd",
},
.description = "HP HIL keyboard driver",
.connect = hil_kbd_connect,
.disconnect = hil_kbd_disconnect,
.interrupt = hil_kbd_interrupt
};
static int __init hil_kbd_init(void)
{
serio_register_driver(&hil_kbd_serio_drv);
return 0;
}
static void __exit hil_kbd_exit(void)
{
serio_unregister_driver(&hil_kbd_serio_drv);
}
module_init(hil_kbd_init);
module_exit(hil_kbd_exit);
/*
* linux/drivers/hil/hilkbd.c
*
* Copyright (C) 1998 Philip Blundell <philb@gnu.org>
* Copyright (C) 1999 Matthew Wilcox <willy@bofh.ai>
* Copyright (C) 1999-2003 Helge Deller <deller@gmx.de>
*
* Very basic HP Human Interface Loop (HIL) driver.
* This driver handles the keyboard on HP300 (m68k) and on some
* HP700 (parisc) series machines.
*
*
* This file is subject to the terms and conditions of the GNU General Public
* License version 2. See the file COPYING in the main directory of this
* archive for more details.
*/
#include <linux/pci_ids.h>
#include <linux/ioport.h>
#include <linux/module.h>
#include <linux/config.h>
#include <linux/errno.h>
#include <linux/input.h>
#include <linux/init.h>
#include <linux/irq.h>
#include <linux/hil.h>
#include <linux/spinlock.h>
MODULE_AUTHOR("Philip Blundell, Matthew Wilcox, Helge Deller");
MODULE_DESCRIPTION("HIL keyboard driver (basic functionality)");
MODULE_LICENSE("GPL v2");
#if defined(CONFIG_PARISC)
#include <asm/io.h>
#include <asm/hardware.h>
#include <asm/parisc-device.h>
static unsigned long hil_base; /* HPA for the HIL device */
static unsigned int hil_irq;
#define HILBASE hil_base /* HPPA (parisc) port address */
#define HIL_DATA 0x800
#define HIL_CMD 0x801
#define HIL_IRQ hil_irq
#define hil_readb(p) gsc_readb(p)
#define hil_writeb(v,p) gsc_writeb((v),(p))
#elif defined(CONFIG_HP300)
#define HILBASE 0xf0428000 /* HP300 (m86k) port address */
#define HIL_DATA 0x1
#define HIL_CMD 0x3
#define HIL_IRQ 2
#define hil_readb(p) readb(p)
#define hil_writeb(v,p) writeb((v),(p))
#else
#error "HIL is not supported on this platform"
#endif
/* HIL helper functions */
#define hil_busy() (hil_readb(HILBASE + HIL_CMD) & HIL_BUSY)
#define hil_data_available() (hil_readb(HILBASE + HIL_CMD) & HIL_DATA_RDY)
#define hil_status() (hil_readb(HILBASE + HIL_CMD))
#define hil_command(x) do { hil_writeb((x), HILBASE + HIL_CMD); } while (0)
#define hil_read_data() (hil_readb(HILBASE + HIL_DATA))
#define hil_write_data(x) do { hil_writeb((x), HILBASE + HIL_DATA); } while (0)
/* HIL constants */
#define HIL_BUSY 0x02
#define HIL_DATA_RDY 0x01
#define HIL_SETARD 0xA0 /* set auto-repeat delay */
#define HIL_SETARR 0xA2 /* set auto-repeat rate */
#define HIL_SETTONE 0xA3 /* set tone generator */
#define HIL_CNMT 0xB2 /* clear nmi */
#define HIL_INTON 0x5C /* Turn on interrupts. */
#define HIL_INTOFF 0x5D /* Turn off interrupts. */
#define HIL_READKBDSADR 0xF9
#define HIL_WRITEKBDSADR 0xE9
static unsigned int hphilkeyb_keycode[HIL_KEYCODES_SET1_TBLSIZE] =
{ HIL_KEYCODES_SET1 };
/* HIL structure */
static struct {
struct input_dev dev;
unsigned int curdev;
unsigned char s;
unsigned char c;
int valid;
unsigned char data[16];
unsigned int ptr;
spinlock_t lock;
void *dev_id; /* native bus device */
} hil_dev;
static void poll_finished(void)
{
int down;
int key;
unsigned char scode;
switch (hil_dev.data[0]) {
case 0x40:
down = (hil_dev.data[1] & 1) == 0;
scode = hil_dev.data[1] >> 1;
key = hphilkeyb_keycode[scode];
input_report_key(&hil_dev.dev, key, down);
break;
}
hil_dev.curdev = 0;
}
static inline void handle_status(unsigned char s, unsigned char c)
{
if (c & 0x8) {
/* End of block */
if (c & 0x10)
poll_finished();
} else {
if (c & 0x10) {
if (hil_dev.curdev)
poll_finished(); /* just in case */
hil_dev.curdev = c & 7;
hil_dev.ptr = 0;
}
}
}
static inline void handle_data(unsigned char s, unsigned char c)
{
if (hil_dev.curdev) {
hil_dev.data[hil_dev.ptr++] = c;
hil_dev.ptr &= 15;
}
}
/*
* Handle HIL interrupts.
*/
static irqreturn_t hil_interrupt(int irq, void *handle, struct pt_regs *regs)
{
unsigned char s, c;
s = hil_status();
c = hil_read_data();
switch (s >> 4) {
case 0x5:
handle_status(s, c);
break;
case 0x6:
handle_data(s, c);
break;
case 0x4:
hil_dev.s = s;
hil_dev.c = c;
mb();
hil_dev.valid = 1;
break;
}
return IRQ_HANDLED;
}
/*
* Send a command to the HIL
*/
static void hil_do(unsigned char cmd, unsigned char *data, unsigned int len)
{
unsigned long flags;
spin_lock_irqsave(&hil_dev.lock, flags);
while (hil_busy())
/* wait */;
hil_command(cmd);
while (len--) {
while (hil_busy())
/* wait */;
hil_write_data(*(data++));
}
spin_unlock_irqrestore(&hil_dev.lock, flags);
}
/*
* Initialise HIL.
*/
static int __init
hil_keyb_init(void)
{
unsigned char c;
unsigned int i, kbid;
wait_queue_head_t hil_wait;
if (hil_dev.dev.id.bustype) {
return -ENODEV; /* already initialized */
}
#if defined(CONFIG_HP300)
if (!hwreg_present((void *)(HILBASE + HIL_DATA)))
return -ENODEV;
request_region(HILBASE+HIL_DATA, 2, "hil");
#endif
request_irq(HIL_IRQ, hil_interrupt, 0, "hil", hil_dev.dev_id);
/* Turn on interrupts */
hil_do(HIL_INTON, NULL, 0);
/* Look for keyboards */
hil_dev.valid = 0; /* clear any pending data */
hil_do(HIL_READKBDSADR, NULL, 0);
init_waitqueue_head(&hil_wait);
wait_event_interruptible_timeout(hil_wait, hil_dev.valid, 3*HZ);
if (!hil_dev.valid) {
printk(KERN_WARNING "HIL: timed out, assuming no keyboard present.\n");
}
c = hil_dev.c;
hil_dev.valid = 0;
if (c == 0) {
kbid = -1;
printk(KERN_WARNING "HIL: no keyboard present.\n");
} else {
kbid = ffz(~c);
/* printk(KERN_INFO "HIL: keyboard found at id %d\n", kbid); */
}
/* set it to raw mode */
c = 0;
hil_do(HIL_WRITEKBDSADR, &c, 1);
init_input_dev(&hil_dev.dev);
for (i = 0; i < HIL_KEYCODES_SET1_TBLSIZE; i++)
if (hphilkeyb_keycode[i] != KEY_RESERVED)
set_bit(hphilkeyb_keycode[i], hil_dev.dev.keybit);
hil_dev.dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
hil_dev.dev.ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL);
hil_dev.dev.keycodemax = HIL_KEYCODES_SET1_TBLSIZE;
hil_dev.dev.keycodesize = sizeof(hphilkeyb_keycode[0]);
hil_dev.dev.keycode = hphilkeyb_keycode;
hil_dev.dev.name = "HIL keyboard";
hil_dev.dev.phys = "hpkbd/input0";
hil_dev.dev.id.bustype = BUS_HIL;
hil_dev.dev.id.vendor = PCI_VENDOR_ID_HP;
hil_dev.dev.id.product = 0x0001;
hil_dev.dev.id.version = 0x0010;
input_register_device(&hil_dev.dev);
printk(KERN_INFO "input: %s, ID %d at 0x%08lx (irq %d) found and attached\n",
hil_dev.dev.name, kbid, HILBASE, HIL_IRQ);
return 0;
}
#if defined(CONFIG_PARISC)
static int __init
hil_init_chip(struct parisc_device *dev)
{
if (!dev->irq) {
printk(KERN_WARNING "HIL: IRQ not found for HIL bus at 0x%08lx\n", dev->hpa);
return -ENODEV;
}
hil_base = dev->hpa;
hil_irq = dev->irq;
hil_dev.dev_id = dev;
printk(KERN_INFO "Found HIL bus at 0x%08lx, IRQ %d\n", hil_base, hil_irq);
return hil_keyb_init();
}
static struct parisc_device_id hil_tbl[] = {
{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00073 },
{ 0, }
};
MODULE_DEVICE_TABLE(parisc, hil_tbl);
static struct parisc_driver hil_driver = {
.name = "HIL",
.id_table = hil_tbl,
.probe = hil_init_chip,
};
#endif /* CONFIG_PARISC */
static int __init hil_init(void)
{
#if defined(CONFIG_PARISC)
return register_parisc_driver(&hil_driver);
#else
return hil_keyb_init();
#endif
}
static void __exit hil_exit(void)
{
if (HIL_IRQ) {
disable_irq(HIL_IRQ);
free_irq(HIL_IRQ, hil_dev.dev_id);
}
/* Turn off interrupts */
hil_do(HIL_INTOFF, NULL, 0);
input_unregister_device(&hil_dev.dev);
#if defined(CONFIG_PARISC)
unregister_parisc_driver(&hil_driver);
#else
release_region(HILBASE+HIL_DATA, 2);
#endif
}
module_init(hil_init);
module_exit(hil_exit);
...@@ -14,10 +14,8 @@ ...@@ -14,10 +14,8 @@
*/ */
/* undefine if you have a RDI PRECISIONBOOK */ /* Is the keyboard an RDI PrecisionBook? */
#define STANDARD_KEYBOARD #ifndef CONFIG_KEYBOARD_ATKBD_RDI_KEYCODES
#if defined(STANDARD_KEYBOARD)
# define CONFLICT(x,y) x # define CONFLICT(x,y) x
#else #else
# define CONFLICT(x,y) y # define CONFLICT(x,y) y
...@@ -50,10 +48,10 @@ ...@@ -50,10 +48,10 @@
/* 60 */ KEY_DOWN, C_61, KEY_PAUSE, KEY_UP, KEY_DELETE, KEY_END, KEY_BACKSPACE, KEY_INSERT, /* 60 */ KEY_DOWN, C_61, KEY_PAUSE, KEY_UP, KEY_DELETE, KEY_END, KEY_BACKSPACE, KEY_INSERT,
/* 68 */ KEY_RESERVED, KEY_KP1, KEY_RIGHT, KEY_KP4, KEY_KP7, KEY_PAGEDOWN, KEY_HOME, KEY_PAGEUP, /* 68 */ KEY_RESERVED, KEY_KP1, KEY_RIGHT, KEY_KP4, KEY_KP7, KEY_PAGEDOWN, KEY_HOME, KEY_PAGEUP,
/* 70 */ KEY_KP0, KEY_KPDOT, KEY_KP2, KEY_KP5, KEY_KP6, KEY_KP8, KEY_ESC, KEY_NUMLOCK, /* 70 */ KEY_KP0, KEY_KPDOT, KEY_KP2, KEY_KP5, KEY_KP6, KEY_KP8, KEY_ESC, KEY_NUMLOCK,
/* 78 */ KEY_F11, KEY_KPPLUS, KEY_KP3, KEY_KPMINUS, KEY_KPASTERISK,KEY_KP9, KEY_SCROLLLOCK,KEY_103RD, /* 78 */ KEY_F11, KEY_KPPLUS, KEY_KP3, KEY_KPMINUS, KEY_KPASTERISK,KEY_KP9, KEY_SCROLLLOCK,KEY_102ND,
/* 80 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, /* 80 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED,
/* 88 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, /* 88 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED,
/* 90 */ KEY_RESERVED, KEY_RIGHTALT, KEY_SYSRQ, KEY_RESERVED, KEY_RIGHTCTRL, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, /* 90 */ KEY_RESERVED, KEY_RIGHTALT, 255, KEY_RESERVED, KEY_RIGHTCTRL, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED,
/* 98 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_CAPSLOCK, KEY_RESERVED, KEY_LEFTMETA, /* 98 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_CAPSLOCK, KEY_RESERVED, KEY_LEFTMETA,
/* a0 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RIGHTMETA, /* a0 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RIGHTMETA,
/* a8 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_COMPOSE, /* a8 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_COMPOSE,
...@@ -103,7 +101,6 @@ ...@@ -103,7 +101,6 @@
/* f0 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, /* f0 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED,
/* f8 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED /* f8 */ KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED
#undef STANDARD_KEYBOARD
#undef CONFLICT #undef CONFLICT
#undef C_07 #undef C_07
#undef C_11 #undef C_11
......
...@@ -49,4 +49,12 @@ config INPUT_UINPUT ...@@ -49,4 +49,12 @@ config INPUT_UINPUT
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called uinput. module will be called uinput.
config HP_SDC_RTC
tristate "HP SDC Real Time Clock"
depends on GSC
select HP_SDC
help
Say Y here if you want to support the built-in real time clock
of the HP SDC controller.
endif endif
...@@ -9,3 +9,4 @@ obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o ...@@ -9,3 +9,4 @@ obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o
obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o
obj-$(CONFIG_INPUT_98SPKR) += 98spkr.o obj-$(CONFIG_INPUT_98SPKR) += 98spkr.o
obj-$(CONFIG_INPUT_UINPUT) += uinput.o obj-$(CONFIG_INPUT_UINPUT) += uinput.o
obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o
/*
* HP i8042 SDC + MSM-58321 BBRTC driver.
*
* Copyright (c) 2001 Brian S. Julin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL").
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
*
* References:
* System Device Controller Microprocessor Firmware Theory of Operation
* for Part Number 1820-4784 Revision B. Dwg No. A-1820-4784-2
* efirtc.c by Stephane Eranian/Hewlett Packard
*
*/
#include <linux/hp_sdc.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/time.h>
#include <linux/miscdevice.h>
#include <linux/proc_fs.h>
#include <linux/poll.h>
#include <linux/rtc.h>
MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
MODULE_DESCRIPTION("HP i8042 SDC + MSM-58321 RTC Driver");
MODULE_LICENSE("Dual BSD/GPL");
#define RTC_VERSION "1.10d"
static unsigned long epoch = 2000;
static struct semaphore i8042tregs;
static hp_sdc_irqhook hp_sdc_rtc_isr;
static struct fasync_struct *hp_sdc_rtc_async_queue;
static DECLARE_WAIT_QUEUE_HEAD(hp_sdc_rtc_wait);
static loff_t hp_sdc_rtc_llseek(struct file *file, loff_t offset, int origin);
static ssize_t hp_sdc_rtc_read(struct file *file, char *buf,
size_t count, loff_t *ppos);
static int hp_sdc_rtc_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg);
static unsigned int hp_sdc_rtc_poll(struct file *file, poll_table *wait);
static int hp_sdc_rtc_open(struct inode *inode, struct file *file);
static int hp_sdc_rtc_release(struct inode *inode, struct file *file);
static int hp_sdc_rtc_fasync (int fd, struct file *filp, int on);
static int hp_sdc_rtc_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data);
static void hp_sdc_rtc_isr (int irq, void *dev_id,
uint8_t status, uint8_t data)
{
return;
}
static int hp_sdc_rtc_do_read_bbrtc (struct rtc_time *rtctm)
{
struct semaphore tsem;
hp_sdc_transaction t;
uint8_t tseq[91];
int i;
i = 0;
while (i < 91) {
tseq[i++] = HP_SDC_ACT_DATAREG |
HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN;
tseq[i++] = 0x01; /* write i8042[0x70] */
tseq[i] = i / 7; /* BBRTC reg address */
i++;
tseq[i++] = HP_SDC_CMD_DO_RTCR; /* Trigger command */
tseq[i++] = 2; /* expect 1 stat/dat pair back. */
i++; i++; /* buffer for stat/dat pair */
}
tseq[84] |= HP_SDC_ACT_SEMAPHORE;
t.endidx = 91;
t.seq = tseq;
t.act.semaphore = &tsem;
init_MUTEX_LOCKED(&tsem);
if (hp_sdc_enqueue_transaction(&t)) return -1;
down_interruptible(&tsem); /* Put ourselves to sleep for results. */
/* Check for nonpresence of BBRTC */
if (!((tseq[83] | tseq[90] | tseq[69] | tseq[76] |
tseq[55] | tseq[62] | tseq[34] | tseq[41] |
tseq[20] | tseq[27] | tseq[6] | tseq[13]) & 0x0f))
return -1;
memset(rtctm, 0, sizeof(struct rtc_time));
rtctm->tm_year = (tseq[83] & 0x0f) + (tseq[90] & 0x0f) * 10;
rtctm->tm_mon = (tseq[69] & 0x0f) + (tseq[76] & 0x0f) * 10;
rtctm->tm_mday = (tseq[55] & 0x0f) + (tseq[62] & 0x0f) * 10;
rtctm->tm_wday = (tseq[48] & 0x0f);
rtctm->tm_hour = (tseq[34] & 0x0f) + (tseq[41] & 0x0f) * 10;
rtctm->tm_min = (tseq[20] & 0x0f) + (tseq[27] & 0x0f) * 10;
rtctm->tm_sec = (tseq[6] & 0x0f) + (tseq[13] & 0x0f) * 10;
return 0;
}
static int hp_sdc_rtc_read_bbrtc (struct rtc_time *rtctm)
{
struct rtc_time tm, tm_last;
int i = 0;
/* MSM-58321 has no read latch, so must read twice and compare. */
if (hp_sdc_rtc_do_read_bbrtc(&tm_last)) return -1;
if (hp_sdc_rtc_do_read_bbrtc(&tm)) return -1;
while (memcmp(&tm, &tm_last, sizeof(struct rtc_time))) {
if (i++ > 4) return -1;
memcpy(&tm_last, &tm, sizeof(struct rtc_time));
if (hp_sdc_rtc_do_read_bbrtc(&tm)) return -1;
}
memcpy(rtctm, &tm, sizeof(struct rtc_time));
return 0;
}
static int64_t hp_sdc_rtc_read_i8042timer (uint8_t loadcmd, int numreg)
{
hp_sdc_transaction t;
uint8_t tseq[26] = {
HP_SDC_ACT_PRECMD | HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN,
0,
HP_SDC_CMD_READ_T1, 2, 0, 0,
HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN,
HP_SDC_CMD_READ_T2, 2, 0, 0,
HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN,
HP_SDC_CMD_READ_T3, 2, 0, 0,
HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN,
HP_SDC_CMD_READ_T4, 2, 0, 0,
HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN,
HP_SDC_CMD_READ_T5, 2, 0, 0
};
t.endidx = numreg * 5;
tseq[1] = loadcmd;
tseq[t.endidx - 4] |= HP_SDC_ACT_SEMAPHORE; /* numreg assumed > 1 */
t.seq = tseq;
t.act.semaphore = &i8042tregs;
down_interruptible(&i8042tregs); /* Sleep if output regs in use. */
if (hp_sdc_enqueue_transaction(&t)) return -1;
down_interruptible(&i8042tregs); /* Sleep until results come back. */
up(&i8042tregs);
return (tseq[5] |
((uint64_t)(tseq[10]) << 8) | ((uint64_t)(tseq[15]) << 16) |
((uint64_t)(tseq[20]) << 24) | ((uint64_t)(tseq[25]) << 32));
}
/* Read the i8042 real-time clock */
static inline int hp_sdc_rtc_read_rt(struct timeval *res) {
int64_t raw;
uint32_t tenms;
unsigned int days;
raw = hp_sdc_rtc_read_i8042timer(HP_SDC_CMD_LOAD_RT, 5);
if (raw < 0) return -1;
tenms = (uint32_t)raw & 0xffffff;
days = (unsigned int)(raw >> 24) & 0xffff;
res->tv_usec = (suseconds_t)(tenms % 100) * 10000;
res->tv_sec = (time_t)(tenms / 100) + days * 86400;
return 0;
}
/* Read the i8042 fast handshake timer */
static inline int hp_sdc_rtc_read_fhs(struct timeval *res) {
uint64_t raw;
unsigned int tenms;
raw = hp_sdc_rtc_read_i8042timer(HP_SDC_CMD_LOAD_FHS, 2);
if (raw < 0) return -1;
tenms = (unsigned int)raw & 0xffff;
res->tv_usec = (suseconds_t)(tenms % 100) * 10000;
res->tv_sec = (time_t)(tenms / 100);
return 0;
}
/* Read the i8042 match timer (a.k.a. alarm) */
static inline int hp_sdc_rtc_read_mt(struct timeval *res) {
int64_t raw;
uint32_t tenms;
raw = hp_sdc_rtc_read_i8042timer(HP_SDC_CMD_LOAD_MT, 3);
if (raw < 0) return -1;
tenms = (uint32_t)raw & 0xffffff;
res->tv_usec = (suseconds_t)(tenms % 100) * 10000;
res->tv_sec = (time_t)(tenms / 100);
return 0;
}
/* Read the i8042 delay timer */
static inline int hp_sdc_rtc_read_dt(struct timeval *res) {
int64_t raw;
uint32_t tenms;
raw = hp_sdc_rtc_read_i8042timer(HP_SDC_CMD_LOAD_DT, 3);
if (raw < 0) return -1;
tenms = (uint32_t)raw & 0xffffff;
res->tv_usec = (suseconds_t)(tenms % 100) * 10000;
res->tv_sec = (time_t)(tenms / 100);
return 0;
}
/* Read the i8042 cycle timer (a.k.a. periodic) */
static inline int hp_sdc_rtc_read_ct(struct timeval *res) {
int64_t raw;
uint32_t tenms;
raw = hp_sdc_rtc_read_i8042timer(HP_SDC_CMD_LOAD_CT, 3);
if (raw < 0) return -1;
tenms = (uint32_t)raw & 0xffffff;
res->tv_usec = (suseconds_t)(tenms % 100) * 10000;
res->tv_sec = (time_t)(tenms / 100);
return 0;
}
/* Set the i8042 real-time clock */
static int hp_sdc_rtc_set_rt (struct timeval *setto)
{
uint32_t tenms;
unsigned int days;
hp_sdc_transaction t;
uint8_t tseq[11] = {
HP_SDC_ACT_PRECMD | HP_SDC_ACT_DATAOUT,
HP_SDC_CMD_SET_RTMS, 3, 0, 0, 0,
HP_SDC_ACT_PRECMD | HP_SDC_ACT_DATAOUT,
HP_SDC_CMD_SET_RTD, 2, 0, 0
};
t.endidx = 10;
if (0xffff < setto->tv_sec / 86400) return -1;
days = setto->tv_sec / 86400;
if (0xffff < setto->tv_usec / 1000000 / 86400) return -1;
days += ((setto->tv_sec % 86400) + setto->tv_usec / 1000000) / 86400;
if (days > 0xffff) return -1;
if (0xffffff < setto->tv_sec) return -1;
tenms = setto->tv_sec * 100;
if (0xffffff < setto->tv_usec / 10000) return -1;
tenms += setto->tv_usec / 10000;
if (tenms > 0xffffff) return -1;
tseq[3] = (uint8_t)(tenms & 0xff);
tseq[4] = (uint8_t)((tenms >> 8) & 0xff);
tseq[5] = (uint8_t)((tenms >> 16) & 0xff);
tseq[9] = (uint8_t)(days & 0xff);
tseq[10] = (uint8_t)((days >> 8) & 0xff);
t.seq = tseq;
if (hp_sdc_enqueue_transaction(&t)) return -1;
return 0;
}
/* Set the i8042 fast handshake timer */
static int hp_sdc_rtc_set_fhs (struct timeval *setto)
{
uint32_t tenms;
hp_sdc_transaction t;
uint8_t tseq[5] = {
HP_SDC_ACT_PRECMD | HP_SDC_ACT_DATAOUT,
HP_SDC_CMD_SET_FHS, 2, 0, 0
};
t.endidx = 4;
if (0xffff < setto->tv_sec) return -1;
tenms = setto->tv_sec * 100;
if (0xffff < setto->tv_usec / 10000) return -1;
tenms += setto->tv_usec / 10000;
if (tenms > 0xffff) return -1;
tseq[3] = (uint8_t)(tenms & 0xff);
tseq[4] = (uint8_t)((tenms >> 8) & 0xff);
t.seq = tseq;
if (hp_sdc_enqueue_transaction(&t)) return -1;
return 0;
}
/* Set the i8042 match timer (a.k.a. alarm) */
#define hp_sdc_rtc_set_mt (setto) \
hp_sdc_rtc_set_i8042timer(setto, HP_SDC_CMD_SET_MT)
/* Set the i8042 delay timer */
#define hp_sdc_rtc_set_dt (setto) \
hp_sdc_rtc_set_i8042timer(setto, HP_SDC_CMD_SET_DT)
/* Set the i8042 cycle timer (a.k.a. periodic) */
#define hp_sdc_rtc_set_ct (setto) \
hp_sdc_rtc_set_i8042timer(setto, HP_SDC_CMD_SET_CT)
/* Set one of the i8042 3-byte wide timers */
static int hp_sdc_rtc_set_i8042timer (struct timeval *setto, uint8_t setcmd)
{
uint32_t tenms;
hp_sdc_transaction t;
uint8_t tseq[6] = {
HP_SDC_ACT_PRECMD | HP_SDC_ACT_DATAOUT,
0, 3, 0, 0, 0
};
t.endidx = 6;
if (0xffffff < setto->tv_sec) return -1;
tenms = setto->tv_sec * 100;
if (0xffffff < setto->tv_usec / 10000) return -1;
tenms += setto->tv_usec / 10000;
if (tenms > 0xffffff) return -1;
tseq[1] = setcmd;
tseq[3] = (uint8_t)(tenms & 0xff);
tseq[4] = (uint8_t)((tenms >> 8) & 0xff);
tseq[5] = (uint8_t)((tenms >> 16) & 0xff);
t.seq = tseq;
if (hp_sdc_enqueue_transaction(&t)) {
return -1;
}
return 0;
}
static loff_t hp_sdc_rtc_llseek(struct file *file, loff_t offset, int origin)
{
return -ESPIPE;
}
static ssize_t hp_sdc_rtc_read(struct file *file, char *buf,
size_t count, loff_t *ppos) {
ssize_t retval;
if (count < sizeof(unsigned long))
return -EINVAL;
retval = put_user(68, (unsigned long *)buf);
return retval;
}
static unsigned int hp_sdc_rtc_poll(struct file *file, poll_table *wait)
{
unsigned long l;
l = 0;
if (l != 0)
return POLLIN | POLLRDNORM;
return 0;
}
static int hp_sdc_rtc_open(struct inode *inode, struct file *file)
{
return 0;
}
static int hp_sdc_rtc_release(struct inode *inode, struct file *file)
{
/* Turn off interrupts? */
if (file->f_flags & FASYNC) {
hp_sdc_rtc_fasync (-1, file, 0);
}
return 0;
}
static int hp_sdc_rtc_fasync (int fd, struct file *filp, int on)
{
return fasync_helper (fd, filp, on, &hp_sdc_rtc_async_queue);
}
static int hp_sdc_rtc_proc_output (char *buf)
{
#define YN(bit) ("no")
#define NY(bit) ("yes")
char *p;
struct rtc_time tm;
struct timeval tv;
memset(&tm, 0, sizeof(struct rtc_time));
p = buf;
if (hp_sdc_rtc_read_bbrtc(&tm)) {
p += sprintf(p, "BBRTC\t\t: READ FAILED!\n");
} else {
p += sprintf(p,
"rtc_time\t: %02d:%02d:%02d\n"
"rtc_date\t: %04d-%02d-%02d\n"
"rtc_epoch\t: %04lu\n",
tm.tm_hour, tm.tm_min, tm.tm_sec,
tm.tm_year + 1900, tm.tm_mon + 1,
tm.tm_mday, epoch);
}
if (hp_sdc_rtc_read_rt(&tv)) {
p += sprintf(p, "i8042 rtc\t: READ FAILED!\n");
} else {
p += sprintf(p, "i8042 rtc\t: %ld.%02d seconds\n",
tv.tv_sec, tv.tv_usec/1000);
}
if (hp_sdc_rtc_read_fhs(&tv)) {
p += sprintf(p, "handshake\t: READ FAILED!\n");
} else {
p += sprintf(p, "handshake\t: %ld.%02d seconds\n",
tv.tv_sec, tv.tv_usec/1000);
}
if (hp_sdc_rtc_read_mt(&tv)) {
p += sprintf(p, "alarm\t\t: READ FAILED!\n");
} else {
p += sprintf(p, "alarm\t\t: %ld.%02d seconds\n",
tv.tv_sec, tv.tv_usec/1000);
}
if (hp_sdc_rtc_read_dt(&tv)) {
p += sprintf(p, "delay\t\t: READ FAILED!\n");
} else {
p += sprintf(p, "delay\t\t: %ld.%02d seconds\n",
tv.tv_sec, tv.tv_usec/1000);
}
if (hp_sdc_rtc_read_ct(&tv)) {
p += sprintf(p, "periodic\t: READ FAILED!\n");
} else {
p += sprintf(p, "periodic\t: %ld.%02d seconds\n",
tv.tv_sec, tv.tv_usec/1000);
}
p += sprintf(p,
"DST_enable\t: %s\n"
"BCD\t\t: %s\n"
"24hr\t\t: %s\n"
"square_wave\t: %s\n"
"alarm_IRQ\t: %s\n"
"update_IRQ\t: %s\n"
"periodic_IRQ\t: %s\n"
"periodic_freq\t: %ld\n"
"batt_status\t: %s\n",
YN(RTC_DST_EN),
NY(RTC_DM_BINARY),
YN(RTC_24H),
YN(RTC_SQWE),
YN(RTC_AIE),
YN(RTC_UIE),
YN(RTC_PIE),
1UL,
1 ? "okay" : "dead");
return p - buf;
#undef YN
#undef NY
}
static int hp_sdc_rtc_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int len = hp_sdc_rtc_proc_output (page);
if (len <= off+count) *eof = 1;
*start = page + off;
len -= off;
if (len>count) len = count;
if (len<0) len = 0;
return len;
}
static int hp_sdc_rtc_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
#if 1
return -EINVAL;
#else
struct rtc_time wtime;
struct timeval ttime;
int use_wtime = 0;
/* This needs major work. */
switch (cmd) {
case RTC_AIE_OFF: /* Mask alarm int. enab. bit */
case RTC_AIE_ON: /* Allow alarm interrupts. */
case RTC_PIE_OFF: /* Mask periodic int. enab. bit */
case RTC_PIE_ON: /* Allow periodic ints */
case RTC_UIE_ON: /* Allow ints for RTC updates. */
case RTC_UIE_OFF: /* Allow ints for RTC updates. */
{
/* We cannot mask individual user timers and we
cannot tell them apart when they occur, so it
would be disingenuous to succeed these IOCTLs */
return -EINVAL;
}
case RTC_ALM_READ: /* Read the present alarm time */
{
if (hp_sdc_rtc_read_mt(&ttime)) return -EFAULT;
if (hp_sdc_rtc_read_bbrtc(&wtime)) return -EFAULT;
wtime.tm_hour = ttime.tv_sec / 3600; ttime.tv_sec %= 3600;
wtime.tm_min = ttime.tv_sec / 60; ttime.tv_sec %= 60;
wtime.tm_sec = ttime.tv_sec;
break;
}
case RTC_IRQP_READ: /* Read the periodic IRQ rate. */
{
return put_user(hp_sdc_rtc_freq, (unsigned long *)arg);
}
case RTC_IRQP_SET: /* Set periodic IRQ rate. */
{
/*
* The max we can do is 100Hz.
*/
if ((arg < 1) || (arg > 100)) return -EINVAL;
ttime.tv_sec = 0;
ttime.tv_usec = 1000000 / arg;
if (hp_sdc_rtc_set_ct(&ttime)) return -EFAULT;
hp_sdc_rtc_freq = arg;
return 0;
}
case RTC_ALM_SET: /* Store a time into the alarm */
{
/*
* This expects a struct hp_sdc_rtc_time. Writing 0xff means
* "don't care" or "match all" for PC timers. The HP SDC
* does not support that perk, but it could be emulated fairly
* easily. Only the tm_hour, tm_min and tm_sec are used.
* We could do it with 10ms accuracy with the HP SDC, if the
* rtc interface left us a way to do that.
*/
struct hp_sdc_rtc_time alm_tm;
if (copy_from_user(&alm_tm, (struct hp_sdc_rtc_time*)arg,
sizeof(struct hp_sdc_rtc_time)))
return -EFAULT;
if (alm_tm.tm_hour > 23) return -EINVAL;
if (alm_tm.tm_min > 59) return -EINVAL;
if (alm_tm.tm_sec > 59) return -EINVAL;
ttime.sec = alm_tm.tm_hour * 3600 +
alm_tm.tm_min * 60 + alm_tm.tm_sec;
ttime.usec = 0;
if (hp_sdc_rtc_set_mt(&ttime)) return -EFAULT;
return 0;
}
case RTC_RD_TIME: /* Read the time/date from RTC */
{
if (hp_sdc_rtc_read_bbrtc(&wtime)) return -EFAULT;
break;
}
case RTC_SET_TIME: /* Set the RTC */
{
struct rtc_time hp_sdc_rtc_tm;
unsigned char mon, day, hrs, min, sec, leap_yr;
unsigned int yrs;
if (!capable(CAP_SYS_TIME))
return -EACCES;
if (copy_from_user(&hp_sdc_rtc_tm, (struct rtc_time *)arg,
sizeof(struct rtc_time)))
return -EFAULT;
yrs = hp_sdc_rtc_tm.tm_year + 1900;
mon = hp_sdc_rtc_tm.tm_mon + 1; /* tm_mon starts at zero */
day = hp_sdc_rtc_tm.tm_mday;
hrs = hp_sdc_rtc_tm.tm_hour;
min = hp_sdc_rtc_tm.tm_min;
sec = hp_sdc_rtc_tm.tm_sec;
if (yrs < 1970)
return -EINVAL;
leap_yr = ((!(yrs % 4) && (yrs % 100)) || !(yrs % 400));
if ((mon > 12) || (day == 0))
return -EINVAL;
if (day > (days_in_mo[mon] + ((mon == 2) && leap_yr)))
return -EINVAL;
if ((hrs >= 24) || (min >= 60) || (sec >= 60))
return -EINVAL;
if ((yrs -= eH) > 255) /* They are unsigned */
return -EINVAL;
return 0;
}
case RTC_EPOCH_READ: /* Read the epoch. */
{
return put_user (epoch, (unsigned long *)arg);
}
case RTC_EPOCH_SET: /* Set the epoch. */
{
/*
* There were no RTC clocks before 1900.
*/
if (arg < 1900)
return -EINVAL;
if (!capable(CAP_SYS_TIME))
return -EACCES;
epoch = arg;
return 0;
}
default:
return -EINVAL;
}
return copy_to_user((void *)arg, &wtime, sizeof wtime) ? -EFAULT : 0;
#endif
}
static struct file_operations hp_sdc_rtc_fops = {
.owner = THIS_MODULE,
.llseek = hp_sdc_rtc_llseek,
.read = hp_sdc_rtc_read,
.poll = hp_sdc_rtc_poll,
.ioctl = hp_sdc_rtc_ioctl,
.open = hp_sdc_rtc_open,
.release = hp_sdc_rtc_release,
.fasync = hp_sdc_rtc_fasync,
};
static struct miscdevice hp_sdc_rtc_dev = {
.minor = RTC_MINOR,
.name = "rtc_HIL",
.fops = &hp_sdc_rtc_fops
};
static int __init hp_sdc_rtc_init(void)
{
int ret;
init_MUTEX(&i8042tregs);
if ((ret = hp_sdc_request_timer_irq(&hp_sdc_rtc_isr)))
return ret;
misc_register(&hp_sdc_rtc_dev);
create_proc_read_entry ("driver/rtc", 0, 0,
hp_sdc_rtc_read_proc, NULL);
printk(KERN_INFO "HP i8042 SDC + MSM-58321 RTC support loaded "
"(RTC v " RTC_VERSION ")\n");
return 0;
}
static void __exit hp_sdc_rtc_exit(void)
{
remove_proc_entry ("driver/rtc", NULL);
misc_deregister(&hp_sdc_rtc_dev);
hp_sdc_release_timer_irq(hp_sdc_rtc_isr);
printk(KERN_INFO "HP i8042 SDC + MSM-58321 RTC support unloaded\n");
}
module_init(hp_sdc_rtc_init);
module_exit(hp_sdc_rtc_exit);
...@@ -127,4 +127,12 @@ config MOUSE_VSXXXAA ...@@ -127,4 +127,12 @@ config MOUSE_VSXXXAA
described in the source file). This driver also works with the described in the source file). This driver also works with the
digitizer (VSXXX-AB) DEC produced. digitizer (VSXXX-AB) DEC produced.
config MOUSE_HIL
tristate "HIL pointers (mice etc)."
depends on GSC
select HP_SDC
select HIL_MLC
help
Say Y here to support HIL pointers.
endif endif
...@@ -12,6 +12,7 @@ obj-$(CONFIG_MOUSE_MAPLE) += maplemouse.o ...@@ -12,6 +12,7 @@ obj-$(CONFIG_MOUSE_MAPLE) += maplemouse.o
obj-$(CONFIG_MOUSE_PC110PAD) += pc110pad.o obj-$(CONFIG_MOUSE_PC110PAD) += pc110pad.o
obj-$(CONFIG_MOUSE_PS2) += psmouse.o obj-$(CONFIG_MOUSE_PS2) += psmouse.o
obj-$(CONFIG_MOUSE_SERIAL) += sermouse.o obj-$(CONFIG_MOUSE_SERIAL) += sermouse.o
obj-$(CONFIG_MOUSE_HIL) += hil_ptr.o
obj-$(CONFIG_MOUSE_VSXXXAA) += vsxxxaa.o obj-$(CONFIG_MOUSE_VSXXXAA) += vsxxxaa.o
psmouse-objs := psmouse-base.o alps.o logips2pp.o synaptics.o psmouse-objs := psmouse-base.o alps.o logips2pp.o synaptics.o
/*
* Generic linux-input device driver for axis-bearing devices
*
* Copyright (c) 2001 Brian S. Julin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL").
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
*
* References:
* HP-HIL Technical Reference Manual. Hewlett Packard Product No. 45918A
*
*/
#include <linux/hil.h>
#include <linux/input.h>
#include <linux/serio.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/pci_ids.h>
#define PREFIX "HIL PTR: "
#define HIL_GENERIC_NAME "HIL pointer device"
MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
MODULE_DESCRIPTION(HIL_GENERIC_NAME " driver");
MODULE_LICENSE("Dual BSD/GPL");
#define TABLET_SIMULATES_MOUSE /* allow tablet to be used as mouse */
#undef TABLET_AUTOADJUST /* auto-adjust valid tablet ranges */
#define HIL_PTR_MAX_LENGTH 16
struct hil_ptr {
struct input_dev dev;
struct serio *serio;
/* Input buffer and index for packets from HIL bus. */
hil_packet data[HIL_PTR_MAX_LENGTH];
int idx4; /* four counts per packet */
/* Raw device info records from HIL bus, see hil.h for fields. */
char idd[HIL_PTR_MAX_LENGTH]; /* DID byte and IDD record */
char rsc[HIL_PTR_MAX_LENGTH]; /* RSC record */
char exd[HIL_PTR_MAX_LENGTH]; /* EXD record */
char rnm[HIL_PTR_MAX_LENGTH + 1]; /* RNM record + NULL term. */
/* Extra device details not contained in struct input_dev. */
unsigned int nbtn, naxes;
unsigned int btnmap[7];
/* Something to sleep around with. */
struct semaphore sem;
};
/* Process a complete packet after transfer from the HIL */
static void hil_ptr_process_record(struct hil_ptr *ptr)
{
struct input_dev *dev = &ptr->dev;
hil_packet *data = ptr->data;
hil_packet p;
int idx, i, cnt, laxis;
int ax16, absdev;
idx = ptr->idx4/4;
p = data[idx - 1];
if ((p & ~HIL_CMDCT_POL) ==
(HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL)) goto report;
if ((p & ~HIL_CMDCT_RPL) ==
(HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_RPL)) goto report;
/* Not a poll response. See if we are loading config records. */
switch (p & HIL_PKT_DATA_MASK) {
case HIL_CMD_IDD:
for (i = 0; i < idx; i++)
ptr->idd[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_PTR_MAX_LENGTH; i++)
ptr->idd[i] = 0;
break;
case HIL_CMD_RSC:
for (i = 0; i < idx; i++)
ptr->rsc[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_PTR_MAX_LENGTH; i++)
ptr->rsc[i] = 0;
break;
case HIL_CMD_EXD:
for (i = 0; i < idx; i++)
ptr->exd[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_PTR_MAX_LENGTH; i++)
ptr->exd[i] = 0;
break;
case HIL_CMD_RNM:
for (i = 0; i < idx; i++)
ptr->rnm[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_PTR_MAX_LENGTH + 1; i++)
ptr->rnm[i] = '\0';
break;
default:
/* These occur when device isn't present */
if (p == (HIL_ERR_INT | HIL_PKT_CMD)) break;
/* Anything else we'd like to know about. */
printk(KERN_WARNING PREFIX "Device sent unknown record %x\n", p);
break;
}
goto out;
report:
if ((p & HIL_CMDCT_POL) != idx - 1) {
printk(KERN_WARNING PREFIX "Malformed poll packet %x (idx = %i)\n", p, idx);
goto out;
}
i = (ptr->data[0] & HIL_POL_AXIS_ALT) ? 3 : 0;
laxis = ptr->data[0] & HIL_POL_NUM_AXES_MASK;
laxis += i;
ax16 = ptr->idd[1] & HIL_IDD_HEADER_16BIT; /* 8 or 16bit resolution */
absdev = ptr->idd[1] & HIL_IDD_HEADER_ABS;
for (cnt = 1; i < laxis; i++) {
unsigned int lo,hi,val;
lo = ptr->data[cnt++] & HIL_PKT_DATA_MASK;
hi = ax16 ? (ptr->data[cnt++] & HIL_PKT_DATA_MASK) : 0;
if (absdev) {
val = lo + (hi<<8);
#ifdef TABLET_AUTOADJUST
if (val < ptr->dev.absmin[ABS_X + i])
ptr->dev.absmin[ABS_X + i] = val;
if (val > ptr->dev.absmax[ABS_X + i])
ptr->dev.absmax[ABS_X + i] = val;
#endif
if (i%3) val = ptr->dev.absmax[ABS_X + i] - val;
input_report_abs(dev, ABS_X + i, val);
} else {
val = (int) (((int8_t)lo) | ((int8_t)hi<<8));
if (i%3) val *= -1;
input_report_rel(dev, REL_X + i, val);
}
}
while (cnt < idx - 1) {
unsigned int btn;
int up;
btn = ptr->data[cnt++];
up = btn & 1;
btn &= 0xfe;
if (btn == 0x8e) {
continue; /* TODO: proximity == touch? */
}
else if ((btn > 0x8c) || (btn < 0x80)) continue;
btn = (btn - 0x80) >> 1;
btn = ptr->btnmap[btn];
input_report_key(dev, btn, !up);
}
input_sync(dev);
out:
ptr->idx4 = 0;
up(&ptr->sem);
}
static void hil_ptr_process_err(struct hil_ptr *ptr) {
printk(KERN_WARNING PREFIX "errored HIL packet\n");
ptr->idx4 = 0;
up(&ptr->sem);
return;
}
static irqreturn_t hil_ptr_interrupt(struct serio *serio,
unsigned char data, unsigned int flags, struct pt_regs *regs)
{
struct hil_ptr *ptr;
hil_packet packet;
int idx;
ptr = (struct hil_ptr *)serio->private;
if (ptr == NULL) {
BUG();
return IRQ_HANDLED;
}
if (ptr->idx4 >= (HIL_PTR_MAX_LENGTH * sizeof(hil_packet))) {
hil_ptr_process_err(ptr);
return IRQ_HANDLED;
}
idx = ptr->idx4/4;
if (!(ptr->idx4 % 4)) ptr->data[idx] = 0;
packet = ptr->data[idx];
packet |= ((hil_packet)data) << ((3 - (ptr->idx4 % 4)) * 8);
ptr->data[idx] = packet;
/* Records of N 4-byte hil_packets must terminate with a command. */
if ((++(ptr->idx4)) % 4) return IRQ_HANDLED;
if ((packet & 0xffff0000) != HIL_ERR_INT) {
hil_ptr_process_err(ptr);
return IRQ_HANDLED;
}
if (packet & HIL_PKT_CMD)
hil_ptr_process_record(ptr);
return IRQ_HANDLED;
}
static void hil_ptr_disconnect(struct serio *serio)
{
struct hil_ptr *ptr;
ptr = (struct hil_ptr *)serio->private;
if (ptr == NULL) {
BUG();
return;
}
input_unregister_device(&ptr->dev);
serio_close(serio);
kfree(ptr);
}
static void hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
{
struct hil_ptr *ptr;
char *txt;
unsigned int i, naxsets, btntype;
uint8_t did, *idd;
if (serio->type != (SERIO_HIL_MLC | SERIO_HIL)) return;
if (!(ptr = kmalloc(sizeof(struct hil_ptr), GFP_KERNEL))) return;
memset(ptr, 0, sizeof(struct hil_ptr));
if (serio_open(serio, driver)) goto bail0;
serio->private = ptr;
ptr->serio = serio;
ptr->dev.private = ptr;
init_MUTEX_LOCKED(&(ptr->sem));
/* Get device info. MLC driver supplies devid/status/etc. */
serio->write(serio, 0);
serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_IDD);
down(&(ptr->sem));
serio->write(serio, 0);
serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_RSC);
down(&(ptr->sem));
serio->write(serio, 0);
serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_RNM);
down(&(ptr->sem));
serio->write(serio, 0);
serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_EXD);
down(&(ptr->sem));
up(&(ptr->sem));
init_input_dev(&ptr->dev);
did = ptr->idd[0];
idd = ptr->idd + 1;
txt = "unknown";
if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) {
ptr->dev.evbit[0] = BIT(EV_REL);
txt = "relative";
}
if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_ABS) {
ptr->dev.evbit[0] = BIT(EV_ABS);
txt = "absolute";
}
if (!ptr->dev.evbit[0]) {
goto bail1;
}
ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd);
if (ptr->nbtn) ptr->dev.evbit[0] |= BIT(EV_KEY);
naxsets = HIL_IDD_NUM_AXSETS(*idd);
ptr->naxes = HIL_IDD_NUM_AXES_PER_SET(*idd);
printk(KERN_INFO PREFIX "HIL pointer device found (did: 0x%02x, axis: %s)\n",
did, txt);
printk(KERN_INFO PREFIX "HIL pointer has %i buttons and %i sets of %i axes\n",
ptr->nbtn, naxsets, ptr->naxes);
btntype = BTN_MISC;
if ((did & HIL_IDD_DID_ABS_TABLET_MASK) == HIL_IDD_DID_ABS_TABLET)
#ifdef TABLET_SIMULATES_MOUSE
btntype = BTN_TOUCH;
#else
btntype = BTN_DIGI;
#endif
if ((did & HIL_IDD_DID_ABS_TSCREEN_MASK) == HIL_IDD_DID_ABS_TSCREEN)
btntype = BTN_TOUCH;
if ((did & HIL_IDD_DID_REL_MOUSE_MASK) == HIL_IDD_DID_REL_MOUSE)
btntype = BTN_MOUSE;
for (i = 0; i < ptr->nbtn; i++) {
set_bit(btntype | i, ptr->dev.keybit);
ptr->btnmap[i] = btntype | i;
}
if (btntype == BTN_MOUSE) {
/* Swap buttons 2 and 3 */
ptr->btnmap[1] = BTN_MIDDLE;
ptr->btnmap[2] = BTN_RIGHT;
}
if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) {
for (i = 0; i < ptr->naxes; i++) {
set_bit(REL_X + i, ptr->dev.relbit);
}
for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++) {
set_bit(REL_X + i, ptr->dev.relbit);
}
} else {
for (i = 0; i < ptr->naxes; i++) {
set_bit(ABS_X + i, ptr->dev.absbit);
ptr->dev.absmin[ABS_X + i] = 0;
ptr->dev.absmax[ABS_X + i] =
HIL_IDD_AXIS_MAX((ptr->idd + 1), i);
}
for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++) {
set_bit(ABS_X + i, ptr->dev.absbit);
ptr->dev.absmin[ABS_X + i] = 0;
ptr->dev.absmax[ABS_X + i] =
HIL_IDD_AXIS_MAX((ptr->idd + 1), (i - 3));
}
#ifdef TABLET_AUTOADJUST
for (i = 0; i < ABS_MAX; i++) {
int diff = ptr->dev.absmax[ABS_X + i] / 10;
ptr->dev.absmin[ABS_X + i] += diff;
ptr->dev.absmax[ABS_X + i] -= diff;
}
#endif
}
ptr->dev.name = strlen(ptr->rnm) ? ptr->rnm : HIL_GENERIC_NAME;
ptr->dev.id.bustype = BUS_HIL;
ptr->dev.id.vendor = PCI_VENDOR_ID_HP;
ptr->dev.id.product = 0x0001; /* TODO: get from ptr->rsc */
ptr->dev.id.version = 0x0100; /* TODO: get from ptr->rsc */
ptr->dev.dev = &serio->dev;
input_register_device(&ptr->dev);
printk(KERN_INFO "input: %s (%s), ID: %d\n",
ptr->dev.name,
(btntype == BTN_MOUSE) ? "HIL mouse":"HIL tablet or touchpad",
did);
return;
bail1:
serio_close(serio);
bail0:
kfree(ptr);
return;
}
static struct serio_driver hil_ptr_serio_driver = {
.driver = {
.name = "hil_ptr",
},
.description = "HP HIL mouse/tablet driver",
.connect = hil_ptr_connect,
.disconnect = hil_ptr_disconnect,
.interrupt = hil_ptr_interrupt
};
static int __init hil_ptr_init(void)
{
serio_register_driver(&hil_ptr_serio_driver);
return 0;
}
static void __exit hil_ptr_exit(void)
{
serio_unregister_driver(&hil_ptr_serio_driver);
}
module_init(hil_ptr_init);
module_exit(hil_ptr_exit);
...@@ -48,7 +48,7 @@ config SERIO_SERPORT ...@@ -48,7 +48,7 @@ config SERIO_SERPORT
config SERIO_CT82C710 config SERIO_CT82C710
tristate "ct82c710 Aux port controller" tristate "ct82c710 Aux port controller"
depends on !PARISC depends on X86
---help--- ---help---
Say Y here if you have a Texas Instruments TravelMate notebook Say Y here if you have a Texas Instruments TravelMate notebook
equipped with the ct82c710 chip and want to use a mouse connected equipped with the ct82c710 chip and want to use a mouse connected
...@@ -110,6 +110,32 @@ config SERIO_GSCPS2 ...@@ -110,6 +110,32 @@ config SERIO_GSCPS2
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called gscps2. module will be called gscps2.
config HP_SDC
tristate "HP System Device Controller i8042 Support"
depends on GSC && SERIO
default y
---help---
This option enables supports for the the "System Device
Controller", an i8042 carrying microcode to manage a
few miscellanous devices on some Hewlett Packard systems.
The SDC itself contains a 10ms resolution timer/clock capable
of delivering interrupts on a periodic and one-shot basis.
The SDC may also be connected to a battery-backed real-time
clock, a basic audio waveform generator, and an HP-HIL Master
Link Controller serving up to seven input devices.
By itself this option is rather useless, but enabling it will
enable selection of drivers for the abovementioned devices.
It is, however, incompatible with the old, reliable HIL keyboard
driver, and the new HIL driver is experimental, so if you plan
to use a HIL keyboard as your primary keyboard, you may wish
to keep using that driver until the new HIL drivers have had
more testing.
config HIL_MLC
tristate "HIL MLC Support (needed for HIL input devices)"
depends on HP_SDC
config SERIO_PCIPS2 config SERIO_PCIPS2
tristate "PCI PS/2 keyboard and PS/2 mouse controller" tristate "PCI PS/2 keyboard and PS/2 mouse controller"
depends on PCI depends on PCI
......
...@@ -15,6 +15,8 @@ obj-$(CONFIG_SERIO_AMBAKMI) += ambakmi.o ...@@ -15,6 +15,8 @@ obj-$(CONFIG_SERIO_AMBAKMI) += ambakmi.o
obj-$(CONFIG_SERIO_Q40KBD) += q40kbd.o obj-$(CONFIG_SERIO_Q40KBD) += q40kbd.o
obj-$(CONFIG_SERIO_98KBD) += 98kbd-io.o obj-$(CONFIG_SERIO_98KBD) += 98kbd-io.o
obj-$(CONFIG_SERIO_GSCPS2) += gscps2.o obj-$(CONFIG_SERIO_GSCPS2) += gscps2.o
obj-$(CONFIG_HP_SDC) += hp_sdc.o
obj-$(CONFIG_HIL_MLC) += hp_sdc_mlc.o hil_mlc.o
obj-$(CONFIG_SERIO_PCIPS2) += pcips2.o obj-$(CONFIG_SERIO_PCIPS2) += pcips2.o
obj-$(CONFIG_SERIO_MACEPS2) += maceps2.o obj-$(CONFIG_SERIO_MACEPS2) += maceps2.o
obj-$(CONFIG_SERIO_LIBPS2) += libps2.o obj-$(CONFIG_SERIO_LIBPS2) += libps2.o
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include <asm/parisc-device.h> #include <asm/parisc-device.h>
MODULE_AUTHOR("Laurent Canet <canetl@esiee.fr>, Thibaut Varene <varenet@esiee.fr>, Helge Deller <deller@gmx.de>"); MODULE_AUTHOR("Laurent Canet <canetl@esiee.fr>, Thibaut Varene <varenet@esiee.fr>, Helge Deller <deller@gmx.de>");
MODULE_DESCRIPTION("HP GSC PS/2 port driver"); MODULE_DESCRIPTION("HP GSC PS2 port driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_DEVICE_TABLE(parisc, gscps2_device_tbl); MODULE_DEVICE_TABLE(parisc, gscps2_device_tbl);
...@@ -444,7 +444,7 @@ static struct parisc_device_id gscps2_device_tbl[] = { ...@@ -444,7 +444,7 @@ static struct parisc_device_id gscps2_device_tbl[] = {
}; };
static struct parisc_driver parisc_ps2_driver = { static struct parisc_driver parisc_ps2_driver = {
.name = "GSC PS/2", .name = "GSC PS2",
.id_table = gscps2_device_tbl, .id_table = gscps2_device_tbl,
.probe = gscps2_probe, .probe = gscps2_probe,
.remove = gscps2_remove, .remove = gscps2_remove,
......
/*
* HIL MLC state machine and serio interface driver
*
* Copyright (c) 2001 Brian S. Julin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL").
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
*
* References:
* HP-HIL Technical Reference Manual. Hewlett Packard Product No. 45918A
*
*
* Driver theory of operation:
*
* Some access methods and an ISR is defined by the sub-driver
* (e.g. hp_sdc_mlc.c). These methods are expected to provide a
* few bits of logic in addition to raw access to the HIL MLC,
* specifically, the ISR, which is entirely registered by the
* sub-driver and invoked directly, must check for record
* termination or packet match, at which point a semaphore must
* be cleared and then the hil_mlcs_tasklet must be scheduled.
*
* The hil_mlcs_tasklet processes the state machine for all MLCs
* each time it runs, checking each MLC's progress at the current
* node in the state machine, and moving the MLC to subsequent nodes
* in the state machine when appropriate. It will reschedule
* itself if output is pending. (This rescheduling should be replaced
* at some point with a sub-driver-specific mechanism.)
*
* A timer task prods the tasklet once per second to prevent
* hangups when attached devices do not return expected data
* and to initiate probes of the loop for new devices.
*/
#include <linux/hil_mlc.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/timer.h>
#include <linux/sched.h>
#include <linux/list.h>
MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
MODULE_DESCRIPTION("HIL MLC serio");
MODULE_LICENSE("Dual BSD/GPL");
EXPORT_SYMBOL(hil_mlc_register);
EXPORT_SYMBOL(hil_mlc_unregister);
#define PREFIX "HIL MLC: "
static LIST_HEAD(hil_mlcs);
static rwlock_t hil_mlcs_lock = RW_LOCK_UNLOCKED;
static struct timer_list hil_mlcs_kicker;
static int hil_mlcs_probe;
static void hil_mlcs_process(unsigned long unused);
DECLARE_TASKLET_DISABLED(hil_mlcs_tasklet, hil_mlcs_process, 0);
/* #define HIL_MLC_DEBUG */
/********************** Device info/instance management **********************/
static void hil_mlc_clear_di_map (hil_mlc *mlc, int val) {
int j;
for (j = val; j < 7 ; j++) {
mlc->di_map[j] = -1;
}
}
static void hil_mlc_clear_di_scratch (hil_mlc *mlc) {
memset(&(mlc->di_scratch), 0, sizeof(mlc->di_scratch));
}
static void hil_mlc_copy_di_scratch (hil_mlc *mlc, int idx) {
memcpy(&(mlc->di[idx]), &(mlc->di_scratch), sizeof(mlc->di_scratch));
}
static int hil_mlc_match_di_scratch (hil_mlc *mlc) {
int idx;
for (idx = 0; idx < HIL_MLC_DEVMEM; idx++) {
int j, found;
/* In-use slots are not eligible. */
found = 0;
for (j = 0; j < 7 ; j++) {
if (mlc->di_map[j] == idx) found++;
}
if (found) continue;
if (!memcmp(mlc->di + idx,
&(mlc->di_scratch),
sizeof(mlc->di_scratch))) break;
}
return((idx >= HIL_MLC_DEVMEM) ? -1 : idx);
}
static int hil_mlc_find_free_di(hil_mlc *mlc) {
int idx;
/* TODO: Pick all-zero slots first, failing that,
* randomize the slot picked among those eligible.
*/
for (idx = 0; idx < HIL_MLC_DEVMEM; idx++) {
int j, found;
found = 0;
for (j = 0; j < 7 ; j++) {
if (mlc->di_map[j] == idx) found++;
}
if (!found) break;
}
return(idx); /* Note: It is guaranteed at least one above will match */
}
static inline void hil_mlc_clean_serio_map(hil_mlc *mlc) {
int idx;
for (idx = 0; idx < HIL_MLC_DEVMEM; idx++) {
int j, found;
found = 0;
for (j = 0; j < 7 ; j++) {
if (mlc->di_map[j] == idx) found++;
}
if (!found) mlc->serio_map[idx].di_revmap = -1;
}
}
static void hil_mlc_send_polls(hil_mlc *mlc) {
int did, i, cnt;
struct serio *serio;
struct serio_driver *drv;
i = cnt = 0;
did = (mlc->ipacket[0] & HIL_PKT_ADDR_MASK) >> 8;
serio = did ? mlc->serio[mlc->di_map[did - 1]] : NULL;
drv = (serio != NULL) ? serio->drv : NULL;
while (mlc->icount < 15 - i) {
hil_packet p;
p = mlc->ipacket[i];
if (did != (p & HIL_PKT_ADDR_MASK) >> 8) {
if (drv == NULL || drv->interrupt == NULL) goto skip;
drv->interrupt(serio, 0, 0, NULL);
drv->interrupt(serio, HIL_ERR_INT >> 16, 0, NULL);
drv->interrupt(serio, HIL_PKT_CMD >> 8, 0, NULL);
drv->interrupt(serio, HIL_CMD_POL + cnt, 0, NULL);
skip:
did = (p & HIL_PKT_ADDR_MASK) >> 8;
serio = did ? mlc->serio[mlc->di_map[did-1]] : NULL;
drv = (serio != NULL) ? serio->drv : NULL;
cnt = 0;
}
cnt++; i++;
if (drv == NULL || drv->interrupt == NULL) continue;
drv->interrupt(serio, (p >> 24), 0, NULL);
drv->interrupt(serio, (p >> 16) & 0xff, 0, NULL);
drv->interrupt(serio, (p >> 8) & ~HIL_PKT_ADDR_MASK, 0, NULL);
drv->interrupt(serio, p & 0xff, 0, NULL);
}
}
/*************************** State engine *********************************/
#define HILSEN_SCHED 0x000100 /* Schedule the tasklet */
#define HILSEN_BREAK 0x000200 /* Wait until next pass */
#define HILSEN_UP 0x000400 /* relative node#, decrement */
#define HILSEN_DOWN 0x000800 /* relative node#, increment */
#define HILSEN_FOLLOW 0x001000 /* use retval as next node# */
#define HILSEN_MASK 0x0000ff
#define HILSEN_START 0
#define HILSEN_RESTART 1
#define HILSEN_DHR 9
#define HILSEN_DHR2 10
#define HILSEN_IFC 14
#define HILSEN_HEAL0 16
#define HILSEN_HEAL 18
#define HILSEN_ACF 21
#define HILSEN_ACF2 22
#define HILSEN_DISC0 25
#define HILSEN_DISC 27
#define HILSEN_MATCH 40
#define HILSEN_OPERATE 41
#define HILSEN_PROBE 44
#define HILSEN_DSR 52
#define HILSEN_REPOLL 55
#define HILSEN_IFCACF 58
#define HILSEN_END 60
#define HILSEN_NEXT (HILSEN_DOWN | 1)
#define HILSEN_SAME (HILSEN_DOWN | 0)
#define HILSEN_LAST (HILSEN_UP | 1)
#define HILSEN_DOZE (HILSEN_SAME | HILSEN_SCHED | HILSEN_BREAK)
#define HILSEN_SLEEP (HILSEN_SAME | HILSEN_BREAK)
static int hilse_match(hil_mlc *mlc, int unused) {
int rc;
rc = hil_mlc_match_di_scratch(mlc);
if (rc == -1) {
rc = hil_mlc_find_free_di(mlc);
if (rc == -1) goto err;
#ifdef HIL_MLC_DEBUG
printk(KERN_DEBUG PREFIX "new in slot %i\n", rc);
#endif
hil_mlc_copy_di_scratch(mlc, rc);
mlc->di_map[mlc->ddi] = rc;
mlc->serio_map[rc].di_revmap = mlc->ddi;
hil_mlc_clean_serio_map(mlc);
serio_rescan(mlc->serio[rc]);
return -1;
}
mlc->di_map[mlc->ddi] = rc;
#ifdef HIL_MLC_DEBUG
printk(KERN_DEBUG PREFIX "same in slot %i\n", rc);
#endif
mlc->serio_map[rc].di_revmap = mlc->ddi;
hil_mlc_clean_serio_map(mlc);
return 0;
err:
printk(KERN_ERR PREFIX "Residual device slots exhausted, close some serios!\n");
return 1;
}
/* An LCV used to prevent runaway loops, forces 5 second sleep when reset. */
static int hilse_init_lcv(hil_mlc *mlc, int unused) {
struct timeval tv;
do_gettimeofday(&tv);
if(mlc->lcv == 0) goto restart; /* First init, no need to dally */
if(tv.tv_sec - mlc->lcv_tv.tv_sec < 5) return -1;
restart:
mlc->lcv_tv = tv;
mlc->lcv = 0;
return 0;
}
static int hilse_inc_lcv(hil_mlc *mlc, int lim) {
if (mlc->lcv++ >= lim) return -1;
return 0;
}
#if 0
static int hilse_set_lcv(hil_mlc *mlc, int val) {
mlc->lcv = val;
return 0;
}
#endif
/* Management of the discovered device index (zero based, -1 means no devs) */
static int hilse_set_ddi(hil_mlc *mlc, int val) {
mlc->ddi = val;
hil_mlc_clear_di_map(mlc, val + 1);
return 0;
}
static int hilse_dec_ddi(hil_mlc *mlc, int unused) {
mlc->ddi--;
if (mlc->ddi <= -1) {
mlc->ddi = -1;
hil_mlc_clear_di_map(mlc, 0);
return -1;
}
hil_mlc_clear_di_map(mlc, mlc->ddi + 1);
return 0;
}
static int hilse_inc_ddi(hil_mlc *mlc, int unused) {
if (mlc->ddi >= 6) {
BUG();
return -1;
}
mlc->ddi++;
return 0;
}
static int hilse_take_idd(hil_mlc *mlc, int unused) {
int i;
/* Help the state engine:
* Is this a real IDD response or just an echo?
*
* Real IDD response does not start with a command.
*/
if (mlc->ipacket[0] & HIL_PKT_CMD) goto bail;
/* Should have the command echoed further down. */
for (i = 1; i < 16; i++) {
if (((mlc->ipacket[i] & HIL_PKT_ADDR_MASK) ==
(mlc->ipacket[0] & HIL_PKT_ADDR_MASK)) &&
(mlc->ipacket[i] & HIL_PKT_CMD) &&
((mlc->ipacket[i] & HIL_PKT_DATA_MASK) == HIL_CMD_IDD))
break;
}
if (i > 15) goto bail;
/* And the rest of the packets should still be clear. */
while (++i < 16) {
if (mlc->ipacket[i]) break;
}
if (i < 16) goto bail;
for (i = 0; i < 16; i++) {
mlc->di_scratch.idd[i] =
mlc->ipacket[i] & HIL_PKT_DATA_MASK;
}
/* Next step is to see if RSC supported */
if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_RSC)
return HILSEN_NEXT;
if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_EXD)
return HILSEN_DOWN | 4;
return 0;
bail:
mlc->ddi--;
return -1; /* This should send us off to ACF */
}
static int hilse_take_rsc(hil_mlc *mlc, int unused) {
int i;
for (i = 0; i < 16; i++) {
mlc->di_scratch.rsc[i] =
mlc->ipacket[i] & HIL_PKT_DATA_MASK;
}
/* Next step is to see if EXD supported (IDD has already been read) */
if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_EXD)
return HILSEN_NEXT;
return 0;
}
static int hilse_take_exd(hil_mlc *mlc, int unused) {
int i;
for (i = 0; i < 16; i++) {
mlc->di_scratch.exd[i] =
mlc->ipacket[i] & HIL_PKT_DATA_MASK;
}
/* Next step is to see if RNM supported. */
if (mlc->di_scratch.exd[0] & HIL_EXD_HEADER_RNM)
return HILSEN_NEXT;
return 0;
}
static int hilse_take_rnm(hil_mlc *mlc, int unused) {
int i;
for (i = 0; i < 16; i++) {
mlc->di_scratch.rnm[i] =
mlc->ipacket[i] & HIL_PKT_DATA_MASK;
}
do {
char nam[17];
snprintf(nam, 16, "%s", mlc->di_scratch.rnm);
nam[16] = '\0';
printk(KERN_INFO PREFIX "Device name gotten: %s\n", nam);
} while (0);
return 0;
}
static int hilse_operate(hil_mlc *mlc, int repoll) {
if (mlc->opercnt == 0) hil_mlcs_probe = 0;
mlc->opercnt = 1;
hil_mlc_send_polls(mlc);
if (!hil_mlcs_probe) return 0;
hil_mlcs_probe = 0;
mlc->opercnt = 0;
return 1;
}
#define FUNC(funct, funct_arg, zero_rc, neg_rc, pos_rc) \
{ HILSE_FUNC, { func: &funct }, funct_arg, zero_rc, neg_rc, pos_rc },
#define OUT(pack) \
{ HILSE_OUT, { packet: pack }, 0, HILSEN_NEXT, HILSEN_DOZE, 0 },
#define CTS \
{ HILSE_CTS, { packet: 0 }, 0, HILSEN_NEXT | HILSEN_SCHED | HILSEN_BREAK, HILSEN_DOZE, 0 },
#define EXPECT(comp, to, got, got_wrong, timed_out) \
{ HILSE_EXPECT, { packet: comp }, to, got, got_wrong, timed_out },
#define EXPECT_LAST(comp, to, got, got_wrong, timed_out) \
{ HILSE_EXPECT_LAST, { packet: comp }, to, got, got_wrong, timed_out },
#define EXPECT_DISC(comp, to, got, got_wrong, timed_out) \
{ HILSE_EXPECT_DISC, { packet: comp }, to, got, got_wrong, timed_out },
#define IN(to, got, got_error, timed_out) \
{ HILSE_IN, { packet: 0 }, to, got, got_error, timed_out },
#define OUT_DISC(pack) \
{ HILSE_OUT_DISC, { packet: pack }, 0, 0, 0, 0 },
#define OUT_LAST(pack) \
{ HILSE_OUT_LAST, { packet: pack }, 0, 0, 0, 0 },
struct hilse_node hil_mlc_se[HILSEN_END] = {
/* 0 HILSEN_START */
FUNC(hilse_init_lcv, 0, HILSEN_NEXT, HILSEN_SLEEP, 0)
/* 1 HILSEN_RESTART */
FUNC(hilse_inc_lcv, 10, HILSEN_NEXT, HILSEN_START, 0)
OUT(HIL_CTRL_ONLY) /* Disable APE */
CTS
#define TEST_PACKET(x) \
(HIL_PKT_CMD | (x << HIL_PKT_ADDR_SHIFT) | x << 4 | x)
OUT(HIL_DO_ALTER_CTRL | HIL_CTRL_TEST | TEST_PACKET(0x5))
EXPECT(HIL_ERR_INT | TEST_PACKET(0x5),
2000, HILSEN_NEXT, HILSEN_RESTART, HILSEN_RESTART)
OUT(HIL_DO_ALTER_CTRL | HIL_CTRL_TEST | TEST_PACKET(0xa))
EXPECT(HIL_ERR_INT | TEST_PACKET(0xa),
2000, HILSEN_NEXT, HILSEN_RESTART, HILSEN_RESTART)
OUT(HIL_CTRL_ONLY | 0) /* Disable test mode */
/* 9 HILSEN_DHR */
FUNC(hilse_init_lcv, 0, HILSEN_NEXT, HILSEN_SLEEP, 0)
/* 10 HILSEN_DHR2 */
FUNC(hilse_inc_lcv, 10, HILSEN_NEXT, HILSEN_START, 0)
FUNC(hilse_set_ddi, -1, HILSEN_NEXT, 0, 0)
OUT(HIL_PKT_CMD | HIL_CMD_DHR)
IN(300000, HILSEN_DHR2, HILSEN_DHR2, HILSEN_NEXT)
/* 14 HILSEN_IFC */
OUT(HIL_PKT_CMD | HIL_CMD_IFC)
EXPECT(HIL_PKT_CMD | HIL_CMD_IFC | HIL_ERR_INT,
20000, HILSEN_DISC, HILSEN_DHR2, HILSEN_NEXT )
/* If devices are there, they weren't in PUP or other loopback mode.
* We're more concerned at this point with restoring operation
* to devices than discovering new ones, so we try to salvage
* the loop configuration by closing off the loop.
*/
/* 16 HILSEN_HEAL0 */
FUNC(hilse_dec_ddi, 0, HILSEN_NEXT, HILSEN_ACF, 0)
FUNC(hilse_inc_ddi, 0, HILSEN_NEXT, 0, 0)
/* 18 HILSEN_HEAL */
OUT_LAST(HIL_CMD_ELB)
EXPECT_LAST(HIL_CMD_ELB | HIL_ERR_INT,
20000, HILSEN_REPOLL, HILSEN_DSR, HILSEN_NEXT)
FUNC(hilse_dec_ddi, 0, HILSEN_HEAL, HILSEN_NEXT, 0)
/* 21 HILSEN_ACF */
FUNC(hilse_init_lcv, 0, HILSEN_NEXT, HILSEN_DOZE, 0)
/* 22 HILSEN_ACF2 */
FUNC(hilse_inc_lcv, 10, HILSEN_NEXT, HILSEN_START, 0)
OUT(HIL_PKT_CMD | HIL_CMD_ACF | 1)
IN(20000, HILSEN_NEXT, HILSEN_DSR, HILSEN_NEXT)
/* 25 HILSEN_DISC0 */
OUT_DISC(HIL_PKT_CMD | HIL_CMD_ELB)
EXPECT_DISC(HIL_PKT_CMD | HIL_CMD_ELB | HIL_ERR_INT,
20000, HILSEN_NEXT, HILSEN_DSR, HILSEN_DSR)
/* Only enter here if response just received */
/* 27 HILSEN_DISC */
OUT_DISC(HIL_PKT_CMD | HIL_CMD_IDD)
EXPECT_DISC(HIL_PKT_CMD | HIL_CMD_IDD | HIL_ERR_INT,
20000, HILSEN_NEXT, HILSEN_DSR, HILSEN_START)
FUNC(hilse_inc_ddi, 0, HILSEN_NEXT, HILSEN_START, 0)
FUNC(hilse_take_idd, 0, HILSEN_MATCH, HILSEN_IFCACF, HILSEN_FOLLOW)
OUT_LAST(HIL_PKT_CMD | HIL_CMD_RSC)
EXPECT_LAST(HIL_PKT_CMD | HIL_CMD_RSC | HIL_ERR_INT,
30000, HILSEN_NEXT, HILSEN_DSR, HILSEN_DSR)
FUNC(hilse_take_rsc, 0, HILSEN_MATCH, 0, HILSEN_FOLLOW)
OUT_LAST(HIL_PKT_CMD | HIL_CMD_EXD)
EXPECT_LAST(HIL_PKT_CMD | HIL_CMD_EXD | HIL_ERR_INT,
30000, HILSEN_NEXT, HILSEN_DSR, HILSEN_DSR)
FUNC(hilse_take_exd, 0, HILSEN_MATCH, 0, HILSEN_FOLLOW)
OUT_LAST(HIL_PKT_CMD | HIL_CMD_RNM)
EXPECT_LAST(HIL_PKT_CMD | HIL_CMD_RNM | HIL_ERR_INT,
30000, HILSEN_NEXT, HILSEN_DSR, HILSEN_DSR)
FUNC(hilse_take_rnm, 0, HILSEN_MATCH, 0, 0)
/* 40 HILSEN_MATCH */
FUNC(hilse_match, 0, HILSEN_NEXT, HILSEN_NEXT, /* TODO */ 0)
/* 41 HILSEN_OPERATE */
OUT(HIL_PKT_CMD | HIL_CMD_POL)
EXPECT(HIL_PKT_CMD | HIL_CMD_POL | HIL_ERR_INT,
20000, HILSEN_NEXT, HILSEN_DSR, HILSEN_NEXT)
FUNC(hilse_operate, 0, HILSEN_OPERATE, HILSEN_IFC, HILSEN_NEXT)
/* 44 HILSEN_PROBE */
OUT_LAST(HIL_PKT_CMD | HIL_CMD_EPT)
IN(10000, HILSEN_DISC, HILSEN_DSR, HILSEN_NEXT)
OUT_DISC(HIL_PKT_CMD | HIL_CMD_ELB)
IN(10000, HILSEN_DISC, HILSEN_DSR, HILSEN_NEXT)
OUT(HIL_PKT_CMD | HIL_CMD_ACF | 1)
IN(10000, HILSEN_DISC0, HILSEN_DSR, HILSEN_NEXT)
OUT_LAST(HIL_PKT_CMD | HIL_CMD_ELB)
IN(10000, HILSEN_OPERATE, HILSEN_DSR, HILSEN_DSR)
/* 52 HILSEN_DSR */
FUNC(hilse_set_ddi, -1, HILSEN_NEXT, 0, 0)
OUT(HIL_PKT_CMD | HIL_CMD_DSR)
IN(20000, HILSEN_DHR, HILSEN_DHR, HILSEN_IFC)
/* 55 HILSEN_REPOLL */
OUT(HIL_PKT_CMD | HIL_CMD_RPL)
EXPECT(HIL_PKT_CMD | HIL_CMD_RPL | HIL_ERR_INT,
20000, HILSEN_NEXT, HILSEN_DSR, HILSEN_NEXT)
FUNC(hilse_operate, 1, HILSEN_OPERATE, HILSEN_IFC, HILSEN_PROBE)
/* 58 HILSEN_IFCACF */
OUT(HIL_PKT_CMD | HIL_CMD_IFC)
EXPECT(HIL_PKT_CMD | HIL_CMD_IFC | HIL_ERR_INT,
20000, HILSEN_ACF2, HILSEN_DHR2, HILSEN_HEAL)
/* 60 HILSEN_END */
};
static inline void hilse_setup_input(hil_mlc *mlc, struct hilse_node *node) {
switch (node->act) {
case HILSE_EXPECT_DISC:
mlc->imatch = node->object.packet;
mlc->imatch |= ((mlc->ddi + 2) << HIL_PKT_ADDR_SHIFT);
break;
case HILSE_EXPECT_LAST:
mlc->imatch = node->object.packet;
mlc->imatch |= ((mlc->ddi + 1) << HIL_PKT_ADDR_SHIFT);
break;
case HILSE_EXPECT:
mlc->imatch = node->object.packet;
break;
case HILSE_IN:
mlc->imatch = 0;
break;
default:
BUG();
}
mlc->istarted = 1;
mlc->intimeout = node->arg;
do_gettimeofday(&(mlc->instart));
mlc->icount = 15;
memset(mlc->ipacket, 0, 16 * sizeof(hil_packet));
if (down_trylock(&(mlc->isem))) BUG();
return;
}
#ifdef HIL_MLC_DEBUG
static int doze = 0;
static int seidx; /* For debug */
static int kick = 1;
#endif
static int hilse_donode (hil_mlc *mlc) {
struct hilse_node *node;
int nextidx = 0;
int sched_long = 0;
unsigned long flags;
#ifdef HIL_MLC_DEBUG
if (mlc->seidx && (mlc->seidx != seidx) && mlc->seidx != 41 && mlc->seidx != 42 && mlc->seidx != 43) {
printk(KERN_DEBUG PREFIX "z%i \n%s {%i}", doze, kick ? "K" : "", mlc->seidx);
doze = 0;
}
kick = 0;
seidx = mlc->seidx;
#endif
node = hil_mlc_se + mlc->seidx;
switch (node->act) {
int rc;
hil_packet pack;
case HILSE_FUNC:
if (node->object.func == NULL) break;
rc = node->object.func(mlc, node->arg);
nextidx = (rc > 0) ? node->ugly :
((rc < 0) ? node->bad : node->good);
if (nextidx == HILSEN_FOLLOW) nextidx = rc;
break;
case HILSE_EXPECT_LAST:
case HILSE_EXPECT_DISC:
case HILSE_EXPECT:
case HILSE_IN:
/* Already set up from previous HILSE_OUT_* */
write_lock_irqsave(&(mlc->lock), flags);
rc = mlc->in(mlc, node->arg);
if (rc == 2) {
nextidx = HILSEN_DOZE;
sched_long = 1;
write_unlock_irqrestore(&(mlc->lock), flags);
break;
}
if (rc == 1) nextidx = node->ugly;
else if (rc == 0) nextidx = node->good;
else nextidx = node->bad;
mlc->istarted = 0;
write_unlock_irqrestore(&(mlc->lock), flags);
break;
case HILSE_OUT_LAST:
write_lock_irqsave(&(mlc->lock), flags);
pack = node->object.packet;
pack |= ((mlc->ddi + 1) << HIL_PKT_ADDR_SHIFT);
goto out;
case HILSE_OUT_DISC:
write_lock_irqsave(&(mlc->lock), flags);
pack = node->object.packet;
pack |= ((mlc->ddi + 2) << HIL_PKT_ADDR_SHIFT);
goto out;
case HILSE_OUT:
write_lock_irqsave(&(mlc->lock), flags);
pack = node->object.packet;
out:
if (mlc->istarted) goto out2;
/* Prepare to receive input */
if ((node + 1)->act & HILSE_IN)
hilse_setup_input(mlc, node + 1);
out2:
write_unlock_irqrestore(&(mlc->lock), flags);
if (down_trylock(&mlc->osem)) {
nextidx = HILSEN_DOZE;
break;
}
up(&mlc->osem);
write_lock_irqsave(&(mlc->lock), flags);
if (!(mlc->ostarted)) {
mlc->ostarted = 1;
mlc->opacket = pack;
mlc->out(mlc);
nextidx = HILSEN_DOZE;
write_unlock_irqrestore(&(mlc->lock), flags);
break;
}
mlc->ostarted = 0;
do_gettimeofday(&(mlc->instart));
write_unlock_irqrestore(&(mlc->lock), flags);
nextidx = HILSEN_NEXT;
break;
case HILSE_CTS:
nextidx = mlc->cts(mlc) ? node->bad : node->good;
break;
default:
BUG();
nextidx = 0;
break;
}
#ifdef HIL_MLC_DEBUG
if (nextidx == HILSEN_DOZE) doze++;
#endif
while (nextidx & HILSEN_SCHED) {
struct timeval tv;
if (!sched_long) goto sched;
do_gettimeofday(&tv);
tv.tv_usec += 1000000 * (tv.tv_sec - mlc->instart.tv_sec);
tv.tv_usec -= mlc->instart.tv_usec;
if (tv.tv_usec >= mlc->intimeout) goto sched;
tv.tv_usec = (mlc->intimeout - tv.tv_usec) * HZ / 1000000;
if (!tv.tv_usec) goto sched;
mod_timer(&hil_mlcs_kicker, jiffies + tv.tv_usec);
break;
sched:
tasklet_schedule(&hil_mlcs_tasklet);
break;
}
if (nextidx & HILSEN_DOWN) mlc->seidx += nextidx & HILSEN_MASK;
else if (nextidx & HILSEN_UP) mlc->seidx -= nextidx & HILSEN_MASK;
else mlc->seidx = nextidx & HILSEN_MASK;
if (nextidx & HILSEN_BREAK) return 1;
return 0;
}
/******************** tasklet context functions **************************/
static void hil_mlcs_process(unsigned long unused) {
struct list_head *tmp;
read_lock(&hil_mlcs_lock);
list_for_each(tmp, &hil_mlcs) {
struct hil_mlc *mlc = list_entry(tmp, hil_mlc, list);
while (hilse_donode(mlc) == 0) {
#ifdef HIL_MLC_DEBUG
if (mlc->seidx != 41 &&
mlc->seidx != 42 &&
mlc->seidx != 43)
printk(KERN_DEBUG PREFIX " + ");
#endif
};
}
read_unlock(&hil_mlcs_lock);
}
/************************* Keepalive timer task *********************/
void hil_mlcs_timer (unsigned long data) {
hil_mlcs_probe = 1;
tasklet_schedule(&hil_mlcs_tasklet);
/* Re-insert the periodic task. */
if (!timer_pending(&hil_mlcs_kicker))
mod_timer(&hil_mlcs_kicker, jiffies + HZ);
}
/******************** user/kernel context functions **********************/
static int hil_mlc_serio_write(struct serio *serio, unsigned char c) {
struct hil_mlc_serio_map *map;
struct hil_mlc *mlc;
struct serio_driver *drv;
uint8_t *idx, *last;
map = serio->port_data;
if (map == NULL) {
BUG();
return -EIO;
}
mlc = map->mlc;
if (mlc == NULL) {
BUG();
return -EIO;
}
mlc->serio_opacket[map->didx] |=
((hil_packet)c) << (8 * (3 - mlc->serio_oidx[map->didx]));
if (mlc->serio_oidx[map->didx] >= 3) {
/* for now only commands */
if (!(mlc->serio_opacket[map->didx] & HIL_PKT_CMD))
return -EIO;
switch (mlc->serio_opacket[map->didx] & HIL_PKT_DATA_MASK) {
case HIL_CMD_IDD:
idx = mlc->di[map->didx].idd;
goto emu;
case HIL_CMD_RSC:
idx = mlc->di[map->didx].rsc;
goto emu;
case HIL_CMD_EXD:
idx = mlc->di[map->didx].exd;
goto emu;
case HIL_CMD_RNM:
idx = mlc->di[map->didx].rnm;
goto emu;
default:
break;
}
mlc->serio_oidx[map->didx] = 0;
mlc->serio_opacket[map->didx] = 0;
}
mlc->serio_oidx[map->didx]++;
return -EIO;
emu:
drv = serio->drv;
if (drv == NULL) {
BUG();
return -EIO;
}
last = idx + 15;
while ((last != idx) && (*last == 0)) last--;
while (idx != last) {
drv->interrupt(serio, 0, 0, NULL);
drv->interrupt(serio, HIL_ERR_INT >> 16, 0, NULL);
drv->interrupt(serio, 0, 0, NULL);
drv->interrupt(serio, *idx, 0, NULL);
idx++;
}
drv->interrupt(serio, 0, 0, NULL);
drv->interrupt(serio, HIL_ERR_INT >> 16, 0, NULL);
drv->interrupt(serio, HIL_PKT_CMD >> 8, 0, NULL);
drv->interrupt(serio, *idx, 0, NULL);
mlc->serio_oidx[map->didx] = 0;
mlc->serio_opacket[map->didx] = 0;
return 0;
}
static int hil_mlc_serio_open(struct serio *serio) {
struct hil_mlc_serio_map *map;
struct hil_mlc *mlc;
if (serio->private != NULL) return -EBUSY;
map = serio->port_data;
if (map == NULL) {
BUG();
return -ENODEV;
}
mlc = map->mlc;
if (mlc == NULL) {
BUG();
return -ENODEV;
}
return 0;
}
static void hil_mlc_serio_close(struct serio *serio) {
struct hil_mlc_serio_map *map;
struct hil_mlc *mlc;
map = serio->port_data;
if (map == NULL) {
BUG();
return;
}
mlc = map->mlc;
if (mlc == NULL) {
BUG();
return;
}
serio->private = NULL;
serio->drv = NULL;
/* TODO wake up interruptable */
}
int hil_mlc_register(hil_mlc *mlc) {
int i;
unsigned long flags;
if (mlc == NULL) {
return -EINVAL;
}
mlc->istarted = 0;
mlc->ostarted = 0;
mlc->lock = RW_LOCK_UNLOCKED;
init_MUTEX(&(mlc->osem));
init_MUTEX(&(mlc->isem));
mlc->icount = -1;
mlc->imatch = 0;
mlc->opercnt = 0;
init_MUTEX_LOCKED(&(mlc->csem));
hil_mlc_clear_di_scratch(mlc);
hil_mlc_clear_di_map(mlc, 0);
for (i = 0; i < HIL_MLC_DEVMEM; i++) {
struct serio *mlc_serio;
hil_mlc_copy_di_scratch(mlc, i);
mlc_serio = kmalloc(sizeof(*mlc_serio), GFP_KERNEL);
mlc->serio[i] = mlc_serio;
memset(mlc_serio, 0, sizeof(*mlc_serio));
mlc_serio->type = SERIO_HIL | SERIO_HIL_MLC;
mlc_serio->write = hil_mlc_serio_write;
mlc_serio->open = hil_mlc_serio_open;
mlc_serio->close = hil_mlc_serio_close;
mlc_serio->port_data = &(mlc->serio_map[i]);
mlc->serio_map[i].mlc = mlc;
mlc->serio_map[i].didx = i;
mlc->serio_map[i].di_revmap = -1;
mlc->serio_opacket[i] = 0;
mlc->serio_oidx[i] = 0;
serio_register_port(mlc_serio);
}
mlc->tasklet = &hil_mlcs_tasklet;
write_lock_irqsave(&hil_mlcs_lock, flags);
list_add_tail(&mlc->list, &hil_mlcs);
mlc->seidx = HILSEN_START;
write_unlock_irqrestore(&hil_mlcs_lock, flags);
tasklet_schedule(&hil_mlcs_tasklet);
return 0;
}
int hil_mlc_unregister(hil_mlc *mlc) {
struct list_head *tmp;
unsigned long flags;
int i;
if (mlc == NULL)
return -EINVAL;
write_lock_irqsave(&hil_mlcs_lock, flags);
list_for_each(tmp, &hil_mlcs) {
if (list_entry(tmp, hil_mlc, list) == mlc)
goto found;
}
/* not found in list */
write_unlock_irqrestore(&hil_mlcs_lock, flags);
tasklet_schedule(&hil_mlcs_tasklet);
return -ENODEV;
found:
list_del(tmp);
write_unlock_irqrestore(&hil_mlcs_lock, flags);
for (i = 0; i < HIL_MLC_DEVMEM; i++) {
serio_unregister_port(mlc->serio[i]);
mlc->serio[i] = NULL;
}
tasklet_schedule(&hil_mlcs_tasklet);
return 0;
}
/**************************** Module interface *************************/
static int __init hil_mlc_init(void)
{
init_timer(&hil_mlcs_kicker);
hil_mlcs_kicker.expires = jiffies + HZ;
hil_mlcs_kicker.function = &hil_mlcs_timer;
add_timer(&hil_mlcs_kicker);
tasklet_enable(&hil_mlcs_tasklet);
return 0;
}
static void __exit hil_mlc_exit(void)
{
del_timer(&hil_mlcs_kicker);
tasklet_disable(&hil_mlcs_tasklet);
tasklet_kill(&hil_mlcs_tasklet);
}
module_init(hil_mlc_init);
module_exit(hil_mlc_exit);
/*
* HP i8042-based System Device Controller driver.
*
* Copyright (c) 2001 Brian S. Julin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL").
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
*
* References:
* System Device Controller Microprocessor Firmware Theory of Operation
* for Part Number 1820-4784 Revision B. Dwg No. A-1820-4784-2
* Helge Deller's original hilkbd.c port for PA-RISC.
*
*
* Driver theory of operation:
*
* hp_sdc_put does all writing to the SDC. ISR can run on a different
* CPU than hp_sdc_put, but only one CPU runs hp_sdc_put at a time
* (it cannot really benefit from SMP anyway.) A tasket fit this perfectly.
*
* All data coming back from the SDC is sent via interrupt and can be read
* fully in the ISR, so there are no latency/throughput problems there.
* The problem is with output, due to the slow clock speed of the SDC
* compared to the CPU. This should not be too horrible most of the time,
* but if used with HIL devices that support the multibyte transfer command,
* keeping outbound throughput flowing at the 6500KBps that the HIL is
* capable of is more than can be done at HZ=100.
*
* Busy polling for IBF clear wastes CPU cycles and bus cycles. hp_sdc.ibf
* is set to 0 when the IBF flag in the status register has cleared. ISR
* may do this, and may also access the parts of queued transactions related
* to reading data back from the SDC, but otherwise will not touch the
* hp_sdc state. Whenever a register is written hp_sdc.ibf is set to 1.
*
* The i8042 write index and the values in the 4-byte input buffer
* starting at 0x70 are kept track of in hp_sdc.wi, and .r7[], respectively,
* to minimize the amount of IO needed to the SDC. However these values
* do not need to be locked since they are only ever accessed by hp_sdc_put.
*
* A timer task schedules the tasklet once per second just to make
* sure it doesn't freeze up and to allow for bad reads to time out.
*/
#include <linux/hp_sdc.h>
#include <linux/sched.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/ioport.h>
#include <linux/time.h>
#include <linux/slab.h>
#include <linux/hil.h>
#include <asm/io.h>
#include <asm/system.h>
/* Machine-specific abstraction */
#if defined(__hppa__)
# include <asm/parisc-device.h>
# define sdc_readb(p) gsc_readb(p)
# define sdc_writeb(v,p) gsc_writeb((v),(p))
#elif defined(__mc68000__)
# include <asm/uaccess.h>
# define sdc_readb(p) in_8(p)
# define sdc_writeb(v,p) out_8((p),(v))
#else
# error "HIL is not supported on this platform"
#endif
#define PREFIX "HP SDC: "
MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
MODULE_DESCRIPTION("HP i8042-based SDC Driver");
MODULE_LICENSE("Dual BSD/GPL");
EXPORT_SYMBOL(hp_sdc_request_timer_irq);
EXPORT_SYMBOL(hp_sdc_request_hil_irq);
EXPORT_SYMBOL(hp_sdc_request_cooked_irq);
EXPORT_SYMBOL(hp_sdc_release_timer_irq);
EXPORT_SYMBOL(hp_sdc_release_hil_irq);
EXPORT_SYMBOL(hp_sdc_release_cooked_irq);
EXPORT_SYMBOL(hp_sdc_enqueue_transaction);
EXPORT_SYMBOL(hp_sdc_dequeue_transaction);
static hp_i8042_sdc hp_sdc; /* All driver state is kept in here. */
/*************** primitives for use in any context *********************/
static inline uint8_t hp_sdc_status_in8 (void) {
uint8_t status;
unsigned long flags;
write_lock_irqsave(&hp_sdc.ibf_lock, flags);
status = sdc_readb(hp_sdc.status_io);
if (!(status & HP_SDC_STATUS_IBF)) hp_sdc.ibf = 0;
write_unlock_irqrestore(&hp_sdc.ibf_lock, flags);
return status;
}
static inline uint8_t hp_sdc_data_in8 (void) {
return sdc_readb(hp_sdc.data_io);
}
static inline void hp_sdc_status_out8 (uint8_t val) {
unsigned long flags;
write_lock_irqsave(&hp_sdc.ibf_lock, flags);
hp_sdc.ibf = 1;
if ((val & 0xf0) == 0xe0) hp_sdc.wi = 0xff;
sdc_writeb(val, hp_sdc.status_io);
write_unlock_irqrestore(&hp_sdc.ibf_lock, flags);
}
static inline void hp_sdc_data_out8 (uint8_t val) {
unsigned long flags;
write_lock_irqsave(&hp_sdc.ibf_lock, flags);
hp_sdc.ibf = 1;
sdc_writeb(val, hp_sdc.data_io);
write_unlock_irqrestore(&hp_sdc.ibf_lock, flags);
}
/* Care must be taken to only invoke hp_sdc_spin_ibf when
* absolutely needed, or in rarely invoked subroutines.
* Not only does it waste CPU cycles, it also wastes bus cycles.
*/
static inline void hp_sdc_spin_ibf(void) {
unsigned long flags;
rwlock_t *lock;
lock = &hp_sdc.ibf_lock;
read_lock_irqsave(lock, flags);
if (!hp_sdc.ibf) {
read_unlock_irqrestore(lock, flags);
return;
}
read_unlock(lock);
write_lock(lock);
while (sdc_readb(hp_sdc.status_io) & HP_SDC_STATUS_IBF) {};
hp_sdc.ibf = 0;
write_unlock_irqrestore(lock, flags);
}
/************************ Interrupt context functions ************************/
static void hp_sdc_take (int irq, void *dev_id, uint8_t status, uint8_t data) {
hp_sdc_transaction *curr;
read_lock(&hp_sdc.rtq_lock);
if (hp_sdc.rcurr < 0) {
read_unlock(&hp_sdc.rtq_lock);
return;
}
curr = hp_sdc.tq[hp_sdc.rcurr];
read_unlock(&hp_sdc.rtq_lock);
curr->seq[curr->idx++] = status;
curr->seq[curr->idx++] = data;
hp_sdc.rqty -= 2;
do_gettimeofday(&hp_sdc.rtv);
if (hp_sdc.rqty <= 0) {
/* All data has been gathered. */
if(curr->seq[curr->actidx] & HP_SDC_ACT_SEMAPHORE) {
if (curr->act.semaphore) up(curr->act.semaphore);
}
if(curr->seq[curr->actidx] & HP_SDC_ACT_CALLBACK) {
if (curr->act.irqhook)
curr->act.irqhook(irq, dev_id, status, data);
}
curr->actidx = curr->idx;
curr->idx++;
/* Return control of this transaction */
write_lock(&hp_sdc.rtq_lock);
hp_sdc.rcurr = -1;
hp_sdc.rqty = 0;
write_unlock(&hp_sdc.rtq_lock);
tasklet_schedule(&hp_sdc.task);
}
}
static irqreturn_t hp_sdc_isr(int irq, void *dev_id, struct pt_regs * regs) {
uint8_t status, data;
status = hp_sdc_status_in8();
/* Read data unconditionally to advance i8042. */
data = hp_sdc_data_in8();
/* For now we are ignoring these until we get the SDC to behave. */
if (((status & 0xf1) == 0x51) && data == 0x82) {
return IRQ_HANDLED;
}
switch(status & HP_SDC_STATUS_IRQMASK) {
case 0: /* This case is not documented. */
break;
case HP_SDC_STATUS_USERTIMER:
case HP_SDC_STATUS_PERIODIC:
case HP_SDC_STATUS_TIMER:
read_lock(&hp_sdc.hook_lock);
if (hp_sdc.timer != NULL)
hp_sdc.timer(irq, dev_id, status, data);
read_unlock(&hp_sdc.hook_lock);
break;
case HP_SDC_STATUS_REG:
hp_sdc_take(irq, dev_id, status, data);
break;
case HP_SDC_STATUS_HILCMD:
case HP_SDC_STATUS_HILDATA:
read_lock(&hp_sdc.hook_lock);
if (hp_sdc.hil != NULL)
hp_sdc.hil(irq, dev_id, status, data);
read_unlock(&hp_sdc.hook_lock);
break;
case HP_SDC_STATUS_PUP:
read_lock(&hp_sdc.hook_lock);
if (hp_sdc.pup != NULL)
hp_sdc.pup(irq, dev_id, status, data);
else printk(KERN_INFO PREFIX "HP SDC reports successful PUP.\n");
read_unlock(&hp_sdc.hook_lock);
break;
default:
read_lock(&hp_sdc.hook_lock);
if (hp_sdc.cooked != NULL)
hp_sdc.cooked(irq, dev_id, status, data);
read_unlock(&hp_sdc.hook_lock);
break;
}
return IRQ_HANDLED;
}
static irqreturn_t hp_sdc_nmisr(int irq, void *dev_id, struct pt_regs * regs) {
int status;
status = hp_sdc_status_in8();
printk(KERN_WARNING PREFIX "NMI !\n");
#if 0
if (status & HP_SDC_NMISTATUS_FHS) {
read_lock(&hp_sdc.hook_lock);
if (hp_sdc.timer != NULL)
hp_sdc.timer(irq, dev_id, status, 0);
read_unlock(&hp_sdc.hook_lock);
}
else {
/* TODO: pass this on to the HIL handler, or do SAK here? */
printk(KERN_WARNING PREFIX "HIL NMI\n");
}
#endif
return IRQ_HANDLED;
}
/***************** Kernel (tasklet) context functions ****************/
unsigned long hp_sdc_put(void);
static void hp_sdc_tasklet(unsigned long foo) {
write_lock_irq(&hp_sdc.rtq_lock);
if (hp_sdc.rcurr >= 0) {
struct timeval tv;
do_gettimeofday(&tv);
if (tv.tv_sec > hp_sdc.rtv.tv_sec) tv.tv_usec += 1000000;
if (tv.tv_usec - hp_sdc.rtv.tv_usec > HP_SDC_MAX_REG_DELAY) {
hp_sdc_transaction *curr;
uint8_t tmp;
curr = hp_sdc.tq[hp_sdc.rcurr];
/* If this turns out to be a normal failure mode
* we'll need to figure out a way to communicate
* it back to the application. and be less verbose.
*/
printk(KERN_WARNING PREFIX "read timeout (%ius)!\n",
tv.tv_usec - hp_sdc.rtv.tv_usec);
curr->idx += hp_sdc.rqty;
hp_sdc.rqty = 0;
tmp = curr->seq[curr->actidx];
curr->seq[curr->actidx] |= HP_SDC_ACT_DEAD;
if(tmp & HP_SDC_ACT_SEMAPHORE) {
if (curr->act.semaphore)
up(curr->act.semaphore);
}
if(tmp & HP_SDC_ACT_CALLBACK) {
/* Note this means that irqhooks may be called
* in tasklet/bh context.
*/
if (curr->act.irqhook)
curr->act.irqhook(0, 0, 0, 0);
}
curr->actidx = curr->idx;
curr->idx++;
hp_sdc.rcurr = -1;
}
}
write_unlock_irq(&hp_sdc.rtq_lock);
hp_sdc_put();
}
unsigned long hp_sdc_put(void) {
hp_sdc_transaction *curr;
uint8_t act;
int idx, curridx;
int limit = 0;
write_lock(&hp_sdc.lock);
/* If i8042 buffers are full, we cannot do anything that
requires output, so we skip to the administrativa. */
if (hp_sdc.ibf) {
hp_sdc_status_in8();
if (hp_sdc.ibf) goto finish;
}
anew:
/* See if we are in the middle of a sequence. */
if (hp_sdc.wcurr < 0) hp_sdc.wcurr = 0;
read_lock_irq(&hp_sdc.rtq_lock);
if (hp_sdc.rcurr == hp_sdc.wcurr) hp_sdc.wcurr++;
read_unlock_irq(&hp_sdc.rtq_lock);
if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0;
curridx = hp_sdc.wcurr;
if (hp_sdc.tq[curridx] != NULL) goto start;
while (++curridx != hp_sdc.wcurr) {
if (curridx >= HP_SDC_QUEUE_LEN) {
curridx = -1; /* Wrap to top */
continue;
}
read_lock_irq(&hp_sdc.rtq_lock);
if (hp_sdc.rcurr == curridx) {
read_unlock_irq(&hp_sdc.rtq_lock);
continue;
}
read_unlock_irq(&hp_sdc.rtq_lock);
if (hp_sdc.tq[curridx] != NULL) break; /* Found one. */
}
if (curridx == hp_sdc.wcurr) { /* There's nothing queued to do. */
curridx = -1;
}
hp_sdc.wcurr = curridx;
start:
/* Check to see if the interrupt mask needs to be set. */
if (hp_sdc.set_im) {
hp_sdc_status_out8(hp_sdc.im | HP_SDC_CMD_SET_IM);
hp_sdc.set_im = 0;
goto finish;
}
if (hp_sdc.wcurr == -1) goto done;
curr = hp_sdc.tq[curridx];
idx = curr->actidx;
if (curr->actidx >= curr->endidx) {
hp_sdc.tq[curridx] = NULL;
/* Interleave outbound data between the transactions. */
hp_sdc.wcurr++;
if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0;
goto finish;
}
act = curr->seq[idx];
idx++;
if (curr->idx >= curr->endidx) {
if (act & HP_SDC_ACT_DEALLOC) kfree(curr);
hp_sdc.tq[curridx] = NULL;
/* Interleave outbound data between the transactions. */
hp_sdc.wcurr++;
if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0;
goto finish;
}
while (act & HP_SDC_ACT_PRECMD) {
if (curr->idx != idx) {
idx++;
act &= ~HP_SDC_ACT_PRECMD;
break;
}
hp_sdc_status_out8(curr->seq[idx]);
curr->idx++;
/* act finished? */
if ((act & HP_SDC_ACT_DURING) == HP_SDC_ACT_PRECMD)
goto actdone;
/* skip quantity field if data-out sequence follows. */
if (act & HP_SDC_ACT_DATAOUT) curr->idx++;
goto finish;
}
if (act & HP_SDC_ACT_DATAOUT) {
int qty;
qty = curr->seq[idx];
idx++;
if (curr->idx - idx < qty) {
hp_sdc_data_out8(curr->seq[curr->idx]);
curr->idx++;
/* act finished? */
if ((curr->idx - idx >= qty) &&
((act & HP_SDC_ACT_DURING) == HP_SDC_ACT_DATAOUT))
goto actdone;
goto finish;
}
idx += qty;
act &= ~HP_SDC_ACT_DATAOUT;
}
else while (act & HP_SDC_ACT_DATAREG) {
int mask;
uint8_t w7[4];
mask = curr->seq[idx];
if (idx != curr->idx) {
idx++;
idx += !!(mask & 1);
idx += !!(mask & 2);
idx += !!(mask & 4);
idx += !!(mask & 8);
act &= ~HP_SDC_ACT_DATAREG;
break;
}
w7[0] = (mask & 1) ? curr->seq[++idx] : hp_sdc.r7[0];
w7[1] = (mask & 2) ? curr->seq[++idx] : hp_sdc.r7[1];
w7[2] = (mask & 4) ? curr->seq[++idx] : hp_sdc.r7[2];
w7[3] = (mask & 8) ? curr->seq[++idx] : hp_sdc.r7[3];
if (hp_sdc.wi > 0x73 || hp_sdc.wi < 0x70 ||
w7[hp_sdc.wi-0x70] == hp_sdc.r7[hp_sdc.wi-0x70]) {
int i = 0;
/* Need to point the write index register */
while ((i < 4) && w7[i] == hp_sdc.r7[i]) i++;
if (i < 4) {
hp_sdc_status_out8(HP_SDC_CMD_SET_D0 + i);
hp_sdc.wi = 0x70 + i;
goto finish;
}
idx++;
if ((act & HP_SDC_ACT_DURING) == HP_SDC_ACT_DATAREG)
goto actdone;
curr->idx = idx;
act &= ~HP_SDC_ACT_DATAREG;
break;
}
hp_sdc_data_out8(w7[hp_sdc.wi - 0x70]);
hp_sdc.r7[hp_sdc.wi - 0x70] = w7[hp_sdc.wi - 0x70];
hp_sdc.wi++; /* write index register autoincrements */
{
int i = 0;
while ((i < 4) && w7[i] == hp_sdc.r7[i]) i++;
if (i >= 4) {
curr->idx = idx + 1;
if ((act & HP_SDC_ACT_DURING) ==
HP_SDC_ACT_DATAREG)
goto actdone;
}
}
goto finish;
}
/* We don't go any further in the command if there is a pending read,
because we don't want interleaved results. */
read_lock_irq(&hp_sdc.rtq_lock);
if (hp_sdc.rcurr >= 0) {
read_unlock_irq(&hp_sdc.rtq_lock);
goto finish;
}
read_unlock_irq(&hp_sdc.rtq_lock);
if (act & HP_SDC_ACT_POSTCMD) {
uint8_t postcmd;
/* curr->idx should == idx at this point. */
postcmd = curr->seq[idx];
curr->idx++;
if (act & HP_SDC_ACT_DATAIN) {
/* Start a new read */
hp_sdc.rqty = curr->seq[curr->idx];
do_gettimeofday(&hp_sdc.rtv);
curr->idx++;
/* Still need to lock here in case of spurious irq. */
write_lock_irq(&hp_sdc.rtq_lock);
hp_sdc.rcurr = curridx;
write_unlock_irq(&hp_sdc.rtq_lock);
hp_sdc_status_out8(postcmd);
goto finish;
}
hp_sdc_status_out8(postcmd);
goto actdone;
}
actdone:
if (act & HP_SDC_ACT_SEMAPHORE) {
up(curr->act.semaphore);
}
else if (act & HP_SDC_ACT_CALLBACK) {
curr->act.irqhook(0,0,0,0);
}
if (curr->idx >= curr->endidx) { /* This transaction is over. */
if (act & HP_SDC_ACT_DEALLOC) kfree(curr);
hp_sdc.tq[curridx] = NULL;
}
else {
curr->actidx = idx + 1;
curr->idx = idx + 2;
}
/* Interleave outbound data between the transactions. */
hp_sdc.wcurr++;
if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0;
finish:
/* If by some quirk IBF has cleared and our ISR has run to
see that that has happened, do it all again. */
if (!hp_sdc.ibf && limit++ < 20) goto anew;
done:
if (hp_sdc.wcurr >= 0) tasklet_schedule(&hp_sdc.task);
write_unlock(&hp_sdc.lock);
return 0;
}
/******* Functions called in either user or kernel context ****/
int hp_sdc_enqueue_transaction(hp_sdc_transaction *this) {
unsigned long flags;
int i;
if (this == NULL) {
tasklet_schedule(&hp_sdc.task);
return -EINVAL;
};
write_lock_irqsave(&hp_sdc.lock, flags);
/* Can't have same transaction on queue twice */
for (i=0; i < HP_SDC_QUEUE_LEN; i++)
if (hp_sdc.tq[i] == this) goto fail;
this->actidx = 0;
this->idx = 1;
/* Search for empty slot */
for (i=0; i < HP_SDC_QUEUE_LEN; i++) {
if (hp_sdc.tq[i] == NULL) {
hp_sdc.tq[i] = this;
write_unlock_irqrestore(&hp_sdc.lock, flags);
tasklet_schedule(&hp_sdc.task);
return 0;
}
}
write_unlock_irqrestore(&hp_sdc.lock, flags);
printk(KERN_WARNING PREFIX "No free slot to add transaction.\n");
return -EBUSY;
fail:
write_unlock_irqrestore(&hp_sdc.lock,flags);
printk(KERN_WARNING PREFIX "Transaction add failed: transaction already queued?\n");
return -EINVAL;
}
int hp_sdc_dequeue_transaction(hp_sdc_transaction *this) {
unsigned long flags;
int i;
write_lock_irqsave(&hp_sdc.lock, flags);
/* TODO: don't remove it if it's not done. */
for (i=0; i < HP_SDC_QUEUE_LEN; i++)
if (hp_sdc.tq[i] == this) hp_sdc.tq[i] = NULL;
write_unlock_irqrestore(&hp_sdc.lock, flags);
return 0;
}
/********************** User context functions **************************/
int hp_sdc_request_timer_irq(hp_sdc_irqhook *callback) {
if (callback == NULL || hp_sdc.dev == NULL) {
return -EINVAL;
}
write_lock_irq(&hp_sdc.hook_lock);
if (hp_sdc.timer != NULL) {
write_unlock_irq(&hp_sdc.hook_lock);
return -EBUSY;
}
hp_sdc.timer = callback;
/* Enable interrupts from the timers */
hp_sdc.im &= ~HP_SDC_IM_FH;
hp_sdc.im &= ~HP_SDC_IM_PT;
hp_sdc.im &= ~HP_SDC_IM_TIMERS;
hp_sdc.set_im = 1;
write_unlock_irq(&hp_sdc.hook_lock);
tasklet_schedule(&hp_sdc.task);
return 0;
}
int hp_sdc_request_hil_irq(hp_sdc_irqhook *callback) {
if (callback == NULL || hp_sdc.dev == NULL) {
return -EINVAL;
}
write_lock_irq(&hp_sdc.hook_lock);
if (hp_sdc.hil != NULL) {
write_unlock_irq(&hp_sdc.hook_lock);
return -EBUSY;
}
hp_sdc.hil = callback;
hp_sdc.im &= ~(HP_SDC_IM_HIL | HP_SDC_IM_RESET);
hp_sdc.set_im = 1;
write_unlock_irq(&hp_sdc.hook_lock);
tasklet_schedule(&hp_sdc.task);
return 0;
}
int hp_sdc_request_cooked_irq(hp_sdc_irqhook *callback) {
if (callback == NULL || hp_sdc.dev == NULL) {
return -EINVAL;
}
write_lock_irq(&hp_sdc.hook_lock);
if (hp_sdc.cooked != NULL) {
write_unlock_irq(&hp_sdc.hook_lock);
return -EBUSY;
}
/* Enable interrupts from the HIL MLC */
hp_sdc.cooked = callback;
hp_sdc.im &= ~(HP_SDC_IM_HIL | HP_SDC_IM_RESET);
hp_sdc.set_im = 1;
write_unlock_irq(&hp_sdc.hook_lock);
tasklet_schedule(&hp_sdc.task);
return 0;
}
int hp_sdc_release_timer_irq(hp_sdc_irqhook *callback) {
write_lock_irq(&hp_sdc.hook_lock);
if ((callback != hp_sdc.timer) ||
(hp_sdc.timer == NULL)) {
write_unlock_irq(&hp_sdc.hook_lock);
return -EINVAL;
}
/* Disable interrupts from the timers */
hp_sdc.timer = NULL;
hp_sdc.im |= HP_SDC_IM_TIMERS;
hp_sdc.im |= HP_SDC_IM_FH;
hp_sdc.im |= HP_SDC_IM_PT;
hp_sdc.set_im = 1;
write_unlock_irq(&hp_sdc.hook_lock);
tasklet_schedule(&hp_sdc.task);
return 0;
}
int hp_sdc_release_hil_irq(hp_sdc_irqhook *callback) {
write_lock_irq(&hp_sdc.hook_lock);
if ((callback != hp_sdc.hil) ||
(hp_sdc.hil == NULL)) {
write_unlock_irq(&hp_sdc.hook_lock);
return -EINVAL;
}
hp_sdc.hil = NULL;
/* Disable interrupts from HIL only if there is no cooked driver. */
if(hp_sdc.cooked == NULL) {
hp_sdc.im |= (HP_SDC_IM_HIL | HP_SDC_IM_RESET);
hp_sdc.set_im = 1;
}
write_unlock_irq(&hp_sdc.hook_lock);
tasklet_schedule(&hp_sdc.task);
return 0;
}
int hp_sdc_release_cooked_irq(hp_sdc_irqhook *callback) {
write_lock_irq(&hp_sdc.hook_lock);
if ((callback != hp_sdc.cooked) ||
(hp_sdc.cooked == NULL)) {
write_unlock_irq(&hp_sdc.hook_lock);
return -EINVAL;
}
hp_sdc.cooked = NULL;
/* Disable interrupts from HIL only if there is no raw HIL driver. */
if(hp_sdc.hil == NULL) {
hp_sdc.im |= (HP_SDC_IM_HIL | HP_SDC_IM_RESET);
hp_sdc.set_im = 1;
}
write_unlock_irq(&hp_sdc.hook_lock);
tasklet_schedule(&hp_sdc.task);
return 0;
}
/************************* Keepalive timer task *********************/
void hp_sdc_kicker (unsigned long data) {
tasklet_schedule(&hp_sdc.task);
/* Re-insert the periodic task. */
mod_timer(&hp_sdc.kicker, jiffies + HZ);
}
/************************** Module Initialization ***************************/
#if defined(__hppa__)
static struct parisc_device_id hp_sdc_tbl[] = {
{
.hw_type = HPHW_FIO,
.hversion_rev = HVERSION_REV_ANY_ID,
.hversion = HVERSION_ANY_ID,
.sversion = 0x73,
},
{ 0, }
};
MODULE_DEVICE_TABLE(parisc, hp_sdc_tbl);
static int __init hp_sdc_init_hppa(struct parisc_device *d);
static struct parisc_driver hp_sdc_driver = {
.name = "HP SDC",
.id_table = hp_sdc_tbl,
.probe = hp_sdc_init_hppa,
};
#endif /* __hppa__ */
static int __init hp_sdc_init(void)
{
int i;
char *errstr;
hp_sdc_transaction t_sync;
uint8_t ts_sync[6];
struct semaphore s_sync;
hp_sdc.lock = RW_LOCK_UNLOCKED;
hp_sdc.ibf_lock = RW_LOCK_UNLOCKED;
hp_sdc.rtq_lock = RW_LOCK_UNLOCKED;
hp_sdc.hook_lock = RW_LOCK_UNLOCKED;
hp_sdc.timer = NULL;
hp_sdc.hil = NULL;
hp_sdc.pup = NULL;
hp_sdc.cooked = NULL;
hp_sdc.im = HP_SDC_IM_MASK; /* Mask maskable irqs */
hp_sdc.set_im = 1;
hp_sdc.wi = 0xff;
hp_sdc.r7[0] = 0xff;
hp_sdc.r7[1] = 0xff;
hp_sdc.r7[2] = 0xff;
hp_sdc.r7[3] = 0xff;
hp_sdc.ibf = 1;
for (i = 0; i < HP_SDC_QUEUE_LEN; i++) hp_sdc.tq[i] = NULL;
hp_sdc.wcurr = -1;
hp_sdc.rcurr = -1;
hp_sdc.rqty = 0;
hp_sdc.dev_err = -ENODEV;
errstr = "IO not found for";
if (!hp_sdc.base_io) goto err0;
errstr = "IRQ not found for";
if (!hp_sdc.irq) goto err0;
hp_sdc.dev_err = -EBUSY;
#if defined(__hppa__)
errstr = "IO not available for";
if (request_region(hp_sdc.data_io, 2, hp_sdc_driver.name)) goto err0;
#endif
errstr = "IRQ not available for";
if(request_irq(hp_sdc.irq, &hp_sdc_isr, 0, "HP SDC",
(void *) hp_sdc.base_io)) goto err1;
errstr = "NMI not available for";
if (request_irq(hp_sdc.nmi, &hp_sdc_nmisr, 0, "HP SDC NMI",
(void *) hp_sdc.base_io)) goto err2;
printk(KERN_INFO PREFIX "HP SDC at 0x%p, IRQ %d (NMI IRQ %d)\n",
(void *)hp_sdc.base_io, hp_sdc.irq, hp_sdc.nmi);
hp_sdc_status_in8();
hp_sdc_data_in8();
tasklet_init(&hp_sdc.task, hp_sdc_tasklet, 0);
/* Sync the output buffer registers, thus scheduling hp_sdc_tasklet. */
t_sync.actidx = 0;
t_sync.idx = 1;
t_sync.endidx = 6;
t_sync.seq = ts_sync;
ts_sync[0] = HP_SDC_ACT_DATAREG | HP_SDC_ACT_SEMAPHORE;
ts_sync[1] = 0x0f;
ts_sync[2] = ts_sync[3] = ts_sync[4] = ts_sync[5] = 0;
t_sync.act.semaphore = &s_sync;
init_MUTEX_LOCKED(&s_sync);
hp_sdc_enqueue_transaction(&t_sync);
down(&s_sync); /* Wait for t_sync to complete */
/* Create the keepalive task */
init_timer(&hp_sdc.kicker);
hp_sdc.kicker.expires = jiffies + HZ;
hp_sdc.kicker.function = &hp_sdc_kicker;
add_timer(&hp_sdc.kicker);
hp_sdc.dev_err = 0;
return 0;
err2:
free_irq(hp_sdc.irq, NULL);
err1:
release_region(hp_sdc.data_io, 2);
err0:
printk(KERN_WARNING PREFIX ": %s SDC IO=0x%p IRQ=0x%x NMI=0x%x\n",
errstr, (void *)hp_sdc.base_io, hp_sdc.irq, hp_sdc.nmi);
hp_sdc.dev = NULL;
return hp_sdc.dev_err;
}
#if defined(__hppa__)
static int __init hp_sdc_init_hppa(struct parisc_device *d)
{
if (!d) return 1;
if (hp_sdc.dev != NULL) return 1; /* We only expect one SDC */
hp_sdc.dev = d;
hp_sdc.irq = d->irq;
/* TODO: Is NMI == IRQ - 1 all cases, or is there a way to query? */
hp_sdc.nmi = d->irq - 1;
hp_sdc.base_io = (unsigned long) d->hpa;
hp_sdc.data_io = (unsigned long) d->hpa + 0x800;
hp_sdc.status_io = (unsigned long) d->hpa + 0x801;
return hp_sdc_init();
}
#endif /* __hppa__ */
#if !defined(__mc68000__) /* Link error on m68k! */
static void __exit hp_sdc_exit(void)
#else
static void hp_sdc_exit(void)
#endif
{
write_lock_irq(&hp_sdc.lock);
/* Turn off all maskable "sub-function" irq's. */
hp_sdc_spin_ibf();
sdc_writeb(HP_SDC_CMD_SET_IM | HP_SDC_IM_MASK, hp_sdc.status_io);
/* Wait until we know this has been processed by the i8042 */
hp_sdc_spin_ibf();
free_irq(hp_sdc.nmi, NULL);
free_irq(hp_sdc.irq, NULL);
write_unlock_irq(&hp_sdc.lock);
del_timer(&hp_sdc.kicker);
tasklet_kill(&hp_sdc.task);
/* release_region(hp_sdc.data_io, 2); */
#if defined(__hppa__)
if (unregister_parisc_driver(&hp_sdc_driver))
printk(KERN_WARNING PREFIX "Error unregistering HP SDC");
#endif
}
static int __init hp_sdc_register(void)
{
hp_sdc_transaction tq_init;
uint8_t tq_init_seq[5];
struct semaphore tq_init_sem;
#if defined(__mc68000__)
mm_segment_t fs;
unsigned char i;
#endif
hp_sdc.dev = NULL;
hp_sdc.dev_err = 0;
#if defined(__hppa__)
if (register_parisc_driver(&hp_sdc_driver)) {
printk(KERN_WARNING PREFIX "Error registering SDC with system bus tree.\n");
return -ENODEV;
}
#elif defined(__mc68000__)
if (!MACH_IS_HP300)
return -ENODEV;
hp_sdc.irq = 1;
hp_sdc.nmi = 7;
hp_sdc.base_io = (unsigned long) 0xf0428000;
hp_sdc.data_io = (unsigned long) hp_sdc.base_io + 1;
hp_sdc.status_io = (unsigned long) hp_sdc.base_io + 3;
fs = get_fs();
set_fs(KERNEL_DS);
if (!get_user(i, (unsigned char *)hp_sdc.data_io))
hp_sdc.dev = (void *)1;
set_fs(fs);
hp_sdc.dev_err = hp_sdc_init();
#endif
if (hp_sdc.dev == NULL) {
printk(KERN_WARNING PREFIX "No SDC found.\n");
return hp_sdc.dev_err;
}
init_MUTEX_LOCKED(&tq_init_sem);
tq_init.actidx = 0;
tq_init.idx = 1;
tq_init.endidx = 5;
tq_init.seq = tq_init_seq;
tq_init.act.semaphore = &tq_init_sem;
tq_init_seq[0] =
HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN | HP_SDC_ACT_SEMAPHORE;
tq_init_seq[1] = HP_SDC_CMD_READ_KCC;
tq_init_seq[2] = 1;
tq_init_seq[3] = 0;
tq_init_seq[4] = 0;
hp_sdc_enqueue_transaction(&tq_init);
down(&tq_init_sem);
up(&tq_init_sem);
if ((tq_init_seq[0] & HP_SDC_ACT_DEAD) == HP_SDC_ACT_DEAD) {
printk(KERN_WARNING PREFIX "Error reading config byte.\n");
hp_sdc_exit();
return -ENODEV;
}
hp_sdc.r11 = tq_init_seq[4];
if (hp_sdc.r11 & HP_SDC_CFG_NEW) {
char *str;
printk(KERN_INFO PREFIX "New style SDC\n");
tq_init_seq[1] = HP_SDC_CMD_READ_XTD;
tq_init.actidx = 0;
tq_init.idx = 1;
down(&tq_init_sem);
hp_sdc_enqueue_transaction(&tq_init);
down(&tq_init_sem);
up(&tq_init_sem);
if ((tq_init_seq[0] & HP_SDC_ACT_DEAD) == HP_SDC_ACT_DEAD) {
printk(KERN_WARNING PREFIX "Error reading extended config byte.\n");
return -ENODEV;
}
hp_sdc.r7e = tq_init_seq[4];
HP_SDC_XTD_REV_STRINGS(hp_sdc.r7e & HP_SDC_XTD_REV, str)
printk(KERN_INFO PREFIX "Revision: %s\n", str);
if (hp_sdc.r7e & HP_SDC_XTD_BEEPER) {
printk(KERN_INFO PREFIX "TI SN76494 beeper present\n");
}
if (hp_sdc.r7e & HP_SDC_XTD_BBRTC) {
printk(KERN_INFO PREFIX "OKI MSM-58321 BBRTC present\n");
}
printk(KERN_INFO PREFIX "Spunking the self test register to force PUP "
"on next firmware reset.\n");
tq_init_seq[0] = HP_SDC_ACT_PRECMD |
HP_SDC_ACT_DATAOUT | HP_SDC_ACT_SEMAPHORE;
tq_init_seq[1] = HP_SDC_CMD_SET_STR;
tq_init_seq[2] = 1;
tq_init_seq[3] = 0;
tq_init.actidx = 0;
tq_init.idx = 1;
tq_init.endidx = 4;
down(&tq_init_sem);
hp_sdc_enqueue_transaction(&tq_init);
down(&tq_init_sem);
up(&tq_init_sem);
}
else {
printk(KERN_INFO PREFIX "Old style SDC (1820-%s).\n",
(hp_sdc.r11 & HP_SDC_CFG_REV) ? "3300" : "2564/3087");
}
return 0;
}
module_init(hp_sdc_register);
module_exit(hp_sdc_exit);
/* Timing notes: These measurements taken on my 64MHz 7100-LC (715/64)
* cycles cycles-adj time
* between two consecutive mfctl(16)'s: 4 n/a 63ns
* hp_sdc_spin_ibf when idle: 119 115 1.7us
* gsc_writeb status register: 83 79 1.2us
* IBF to clear after sending SET_IM: 6204 6006 93us
* IBF to clear after sending LOAD_RT: 4467 4352 68us
* IBF to clear after sending two LOAD_RTs: 18974 18859 295us
* READ_T1, read status/data, IRQ, call handler: 35564 n/a 556us
* cmd to ~IBF READ_T1 2nd time right after: 5158403 n/a 81ms
* between IRQ received and ~IBF for above: 2578877 n/a 40ms
*
* Performance stats after a run of this module configuring HIL and
* receiving a few mouse events:
*
* status in8 282508 cycles 7128 calls
* status out8 8404 cycles 341 calls
* data out8 1734 cycles 78 calls
* isr 174324 cycles 617 calls (includes take)
* take 1241 cycles 2 calls
* put 1411504 cycles 6937 calls
* task 1655209 cycles 6937 calls (includes put)
*
*/
/*
* Access to HP-HIL MLC through HP System Device Controller.
*
* Copyright (c) 2001 Brian S. Julin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL").
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
*
* References:
* HP-HIL Technical Reference Manual. Hewlett Packard Product No. 45918A
* System Device Controller Microprocessor Firmware Theory of Operation
* for Part Number 1820-4784 Revision B. Dwg No. A-1820-4784-2
*
*/
#include <linux/hil_mlc.h>
#include <linux/hp_sdc.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/string.h>
#define PREFIX "HP SDC MLC: "
static hil_mlc hp_sdc_mlc;
MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
MODULE_DESCRIPTION("Glue for onboard HIL MLC in HP-PARISC machines");
MODULE_LICENSE("Dual BSD/GPL");
struct hp_sdc_mlc_priv_s {
int emtestmode;
hp_sdc_transaction trans;
u8 tseq[16];
int got5x;
} hp_sdc_mlc_priv;
/************************* Interrupt context ******************************/
static void hp_sdc_mlc_isr (int irq, void *dev_id,
uint8_t status, uint8_t data) {
int idx;
hil_mlc *mlc = &hp_sdc_mlc;
write_lock(&(mlc->lock));
if (mlc->icount < 0) {
printk(KERN_WARNING PREFIX "HIL Overflow!\n");
up(&mlc->isem);
goto out;
}
idx = 15 - mlc->icount;
if ((status & HP_SDC_STATUS_IRQMASK) == HP_SDC_STATUS_HILDATA) {
mlc->ipacket[idx] |= data | HIL_ERR_INT;
mlc->icount--;
if (hp_sdc_mlc_priv.got5x) goto check;
if (!idx) goto check;
if ((mlc->ipacket[idx-1] & HIL_PKT_ADDR_MASK) !=
(mlc->ipacket[idx] & HIL_PKT_ADDR_MASK)) {
mlc->ipacket[idx] &= ~HIL_PKT_ADDR_MASK;
mlc->ipacket[idx] |= (mlc->ipacket[idx-1]
& HIL_PKT_ADDR_MASK);
}
goto check;
}
/* We know status is 5X */
if (data & HP_SDC_HIL_ISERR) goto err;
mlc->ipacket[idx] =
(data & HP_SDC_HIL_R1MASK) << HIL_PKT_ADDR_SHIFT;
hp_sdc_mlc_priv.got5x = 1;
goto out;
check:
hp_sdc_mlc_priv.got5x = 0;
if (mlc->imatch == 0) goto done;
if ((mlc->imatch == (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL))
&& (mlc->ipacket[idx] == (mlc->imatch | idx))) goto done;
if (mlc->ipacket[idx] == mlc->imatch) goto done;
goto out;
err:
printk(KERN_DEBUG PREFIX "err code %x\n", data);
switch (data) {
case HP_SDC_HIL_RC_DONE:
printk(KERN_WARNING PREFIX "Bastard SDC reconfigured loop!\n");
break;
case HP_SDC_HIL_ERR:
mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_PERR |
HIL_ERR_FERR | HIL_ERR_FOF;
break;
case HP_SDC_HIL_TO:
mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_LERR;
break;
case HP_SDC_HIL_RC:
printk(KERN_WARNING PREFIX "Bastard SDC decided to reconfigure loop!\n");
break;
default:
printk(KERN_WARNING PREFIX "Unkown HIL Error status (%x)!\n", data);
break;
}
/* No more data will be coming due to an error. */
done:
tasklet_schedule(mlc->tasklet);
up(&(mlc->isem));
out:
write_unlock(&(mlc->lock));
}
/******************** Tasklet or userspace context functions ****************/
static int hp_sdc_mlc_in (hil_mlc *mlc, suseconds_t timeout) {
unsigned long flags;
struct hp_sdc_mlc_priv_s *priv;
int rc = 2;
priv = mlc->priv;
write_lock_irqsave(&(mlc->lock), flags);
/* Try to down the semaphore */
if (down_trylock(&(mlc->isem))) {
struct timeval tv;
if (priv->emtestmode) {
mlc->ipacket[0] =
HIL_ERR_INT | (mlc->opacket &
(HIL_PKT_CMD |
HIL_PKT_ADDR_MASK |
HIL_PKT_DATA_MASK));
mlc->icount = 14;
/* printk(KERN_DEBUG PREFIX ">[%x]\n", mlc->ipacket[0]); */
goto wasup;
}
do_gettimeofday(&tv);
tv.tv_usec += 1000000 * (tv.tv_sec - mlc->instart.tv_sec);
if (tv.tv_usec - mlc->instart.tv_usec > mlc->intimeout) {
/* printk("!%i %i",
tv.tv_usec - mlc->instart.tv_usec,
mlc->intimeout);
*/
rc = 1;
up(&(mlc->isem));
}
goto done;
}
wasup:
up(&(mlc->isem));
rc = 0;
goto done;
done:
write_unlock_irqrestore(&(mlc->lock), flags);
return rc;
}
static int hp_sdc_mlc_cts (hil_mlc *mlc) {
struct hp_sdc_mlc_priv_s *priv;
unsigned long flags;
priv = mlc->priv;
write_lock_irqsave(&(mlc->lock), flags);
/* Try to down the semaphores -- they should be up. */
if (down_trylock(&(mlc->isem))) {
BUG();
goto busy;
}
if (down_trylock(&(mlc->osem))) {
BUG();
up(&(mlc->isem));
goto busy;
}
up(&(mlc->isem));
up(&(mlc->osem));
if (down_trylock(&(mlc->csem))) {
if (priv->trans.act.semaphore != &(mlc->csem)) goto poll;
goto busy;
}
if (!(priv->tseq[4] & HP_SDC_USE_LOOP)) goto done;
poll:
priv->trans.act.semaphore = &(mlc->csem);
priv->trans.actidx = 0;
priv->trans.idx = 1;
priv->trans.endidx = 5;
priv->tseq[0] =
HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN | HP_SDC_ACT_SEMAPHORE;
priv->tseq[1] = HP_SDC_CMD_READ_USE;
priv->tseq[2] = 1;
priv->tseq[3] = 0;
priv->tseq[4] = 0;
hp_sdc_enqueue_transaction(&(priv->trans));
busy:
write_unlock_irqrestore(&(mlc->lock), flags);
return 1;
done:
priv->trans.act.semaphore = &(mlc->osem);
up(&(mlc->csem));
write_unlock_irqrestore(&(mlc->lock), flags);
return 0;
}
static void hp_sdc_mlc_out (hil_mlc *mlc) {
struct hp_sdc_mlc_priv_s *priv;
unsigned long flags;
priv = mlc->priv;
write_lock_irqsave(&(mlc->lock), flags);
/* Try to down the semaphore -- it should be up. */
if (down_trylock(&(mlc->osem))) {
BUG();
goto done;
}
if (mlc->opacket & HIL_DO_ALTER_CTRL) goto do_control;
do_data:
if (priv->emtestmode) {
up(&(mlc->osem));
goto done;
}
/* Shouldn't be sending commands when loop may be busy */
if (down_trylock(&(mlc->csem))) {
BUG();
goto done;
}
up(&(mlc->csem));
priv->trans.actidx = 0;
priv->trans.idx = 1;
priv->trans.act.semaphore = &(mlc->osem);
priv->trans.endidx = 6;
priv->tseq[0] =
HP_SDC_ACT_DATAREG | HP_SDC_ACT_POSTCMD | HP_SDC_ACT_SEMAPHORE;
priv->tseq[1] = 0x7;
priv->tseq[2] =
(mlc->opacket &
(HIL_PKT_ADDR_MASK | HIL_PKT_CMD))
>> HIL_PKT_ADDR_SHIFT;
priv->tseq[3] =
(mlc->opacket & HIL_PKT_DATA_MASK)
>> HIL_PKT_DATA_SHIFT;
priv->tseq[4] = 0; /* No timeout */
if (priv->tseq[3] == HIL_CMD_DHR) priv->tseq[4] = 1;
priv->tseq[5] = HP_SDC_CMD_DO_HIL;
goto enqueue;
do_control:
priv->emtestmode = mlc->opacket & HIL_CTRL_TEST;
if ((mlc->opacket & (HIL_CTRL_APE | HIL_CTRL_IPF)) == HIL_CTRL_APE) {
BUG(); /* we cannot emulate this, it should not be used. */
}
if ((mlc->opacket & HIL_CTRL_ONLY) == HIL_CTRL_ONLY) goto control_only;
if (mlc->opacket & HIL_CTRL_APE) {
BUG(); /* Should not send command/data after engaging APE */
goto done;
}
/* Disengaging APE this way would not be valid either since
* the loop must be allowed to idle.
*
* So, it works out that we really never actually send control
* and data when using SDC, we just send the data.
*/
goto do_data;
control_only:
priv->trans.actidx = 0;
priv->trans.idx = 1;
priv->trans.act.semaphore = &(mlc->osem);
priv->trans.endidx = 4;
priv->tseq[0] =
HP_SDC_ACT_PRECMD | HP_SDC_ACT_DATAOUT | HP_SDC_ACT_SEMAPHORE;
priv->tseq[1] = HP_SDC_CMD_SET_LPC;
priv->tseq[2] = 1;
// priv->tseq[3] = (mlc->ddc + 1) | HP_SDC_LPS_ACSUCC;
priv->tseq[3] = 0;
if (mlc->opacket & HIL_CTRL_APE) {
priv->tseq[3] |= HP_SDC_LPC_APE_IPF;
down_trylock(&(mlc->csem));
}
enqueue:
hp_sdc_enqueue_transaction(&(priv->trans));
done:
write_unlock_irqrestore(&(mlc->lock), flags);
}
static int __init hp_sdc_mlc_init(void)
{
hil_mlc *mlc = &hp_sdc_mlc;
printk(KERN_INFO PREFIX "Registering the System Domain Controller's HIL MLC.\n");
hp_sdc_mlc_priv.emtestmode = 0;
hp_sdc_mlc_priv.trans.seq = hp_sdc_mlc_priv.tseq;
hp_sdc_mlc_priv.trans.act.semaphore = &(mlc->osem);
hp_sdc_mlc_priv.got5x = 0;
mlc->cts = &hp_sdc_mlc_cts;
mlc->in = &hp_sdc_mlc_in;
mlc->out = &hp_sdc_mlc_out;
if (hil_mlc_register(mlc)) {
printk(KERN_WARNING PREFIX "Failed to register MLC structure with hil_mlc\n");
goto err0;
}
mlc->priv = &hp_sdc_mlc_priv;
if (hp_sdc_request_hil_irq(&hp_sdc_mlc_isr)) {
printk(KERN_WARNING PREFIX "Request for raw HIL ISR hook denied\n");
goto err1;
}
return 0;
err1:
if (hil_mlc_unregister(mlc)) {
printk(KERN_ERR PREFIX "Failed to unregister MLC structure with hil_mlc.\n"
"This is bad. Could cause an oops.\n");
}
err0:
return -EBUSY;
}
static void __exit hp_sdc_mlc_exit(void)
{
hil_mlc *mlc = &hp_sdc_mlc;
if (hp_sdc_release_hil_irq(&hp_sdc_mlc_isr)) {
printk(KERN_ERR PREFIX "Failed to release the raw HIL ISR hook.\n"
"This is bad. Could cause an oops.\n");
}
if (hil_mlc_unregister(mlc)) {
printk(KERN_ERR PREFIX "Failed to unregister MLC structure with hil_mlc.\n"
"This is bad. Could cause an oops.\n");
}
}
module_init(hp_sdc_mlc_init);
module_exit(hp_sdc_mlc_exit);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment