提交 ffd51f46 编写于 作者: H Helge Deller 提交者: Dmitry Torokhov

Input: HIL - cleanup coding style

Signed-off-by: NHelge Deller <deller@gmx.de>
Signed-off-by: NDmitry Torokhov <dtor@mail.ru>
上级 3acaf540
...@@ -94,10 +94,12 @@ static void hil_kbd_process_record(struct hil_kbd *kbd) ...@@ -94,10 +94,12 @@ static void hil_kbd_process_record(struct hil_kbd *kbd)
idx = kbd->idx4/4; idx = kbd->idx4/4;
p = data[idx - 1]; p = data[idx - 1];
if ((p & ~HIL_CMDCT_POL) == if ((p & ~HIL_CMDCT_POL) ==
(HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL)) goto report; (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL))
if ((p & ~HIL_CMDCT_RPL) == goto report;
(HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_RPL)) 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. */ /* Not a poll response. See if we are loading config records. */
switch (p & HIL_PKT_DATA_MASK) { switch (p & HIL_PKT_DATA_MASK) {
...@@ -107,27 +109,32 @@ static void hil_kbd_process_record(struct hil_kbd *kbd) ...@@ -107,27 +109,32 @@ static void hil_kbd_process_record(struct hil_kbd *kbd)
for (; i < HIL_KBD_MAX_LENGTH; i++) for (; i < HIL_KBD_MAX_LENGTH; i++)
kbd->idd[i] = 0; kbd->idd[i] = 0;
break; break;
case HIL_CMD_RSC: case HIL_CMD_RSC:
for (i = 0; i < idx; i++) for (i = 0; i < idx; i++)
kbd->rsc[i] = kbd->data[i] & HIL_PKT_DATA_MASK; kbd->rsc[i] = kbd->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_KBD_MAX_LENGTH; i++) for (; i < HIL_KBD_MAX_LENGTH; i++)
kbd->rsc[i] = 0; kbd->rsc[i] = 0;
break; break;
case HIL_CMD_EXD: case HIL_CMD_EXD:
for (i = 0; i < idx; i++) for (i = 0; i < idx; i++)
kbd->exd[i] = kbd->data[i] & HIL_PKT_DATA_MASK; kbd->exd[i] = kbd->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_KBD_MAX_LENGTH; i++) for (; i < HIL_KBD_MAX_LENGTH; i++)
kbd->exd[i] = 0; kbd->exd[i] = 0;
break; break;
case HIL_CMD_RNM: case HIL_CMD_RNM:
for (i = 0; i < idx; i++) for (i = 0; i < idx; i++)
kbd->rnm[i] = kbd->data[i] & HIL_PKT_DATA_MASK; kbd->rnm[i] = kbd->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_KBD_MAX_LENGTH + 1; i++) for (; i < HIL_KBD_MAX_LENGTH + 1; i++)
kbd->rnm[i] = '\0'; kbd->rnm[i] = '\0';
break; break;
default: default:
/* These occur when device isn't present */ /* These occur when device isn't present */
if (p == (HIL_ERR_INT | HIL_PKT_CMD)) break; if (p == (HIL_ERR_INT | HIL_PKT_CMD))
break;
/* Anything else we'd like to know about. */ /* Anything else we'd like to know about. */
printk(KERN_WARNING PREFIX "Device sent unknown record %x\n", p); printk(KERN_WARNING PREFIX "Device sent unknown record %x\n", p);
break; break;
...@@ -139,16 +146,19 @@ static void hil_kbd_process_record(struct hil_kbd *kbd) ...@@ -139,16 +146,19 @@ static void hil_kbd_process_record(struct hil_kbd *kbd)
switch (kbd->data[0] & HIL_POL_CHARTYPE_MASK) { switch (kbd->data[0] & HIL_POL_CHARTYPE_MASK) {
case HIL_POL_CHARTYPE_NONE: case HIL_POL_CHARTYPE_NONE:
break; break;
case HIL_POL_CHARTYPE_ASCII: case HIL_POL_CHARTYPE_ASCII:
while (cnt < idx - 1) while (cnt < idx - 1)
input_report_key(dev, kbd->data[cnt++] & 0x7f, 1); input_report_key(dev, kbd->data[cnt++] & 0x7f, 1);
break; break;
case HIL_POL_CHARTYPE_RSVD1: case HIL_POL_CHARTYPE_RSVD1:
case HIL_POL_CHARTYPE_RSVD2: case HIL_POL_CHARTYPE_RSVD2:
case HIL_POL_CHARTYPE_BINARY: case HIL_POL_CHARTYPE_BINARY:
while (cnt < idx - 1) while (cnt < idx - 1)
input_report_key(dev, kbd->data[cnt++], 1); input_report_key(dev, kbd->data[cnt++], 1);
break; break;
case HIL_POL_CHARTYPE_SET1: case HIL_POL_CHARTYPE_SET1:
while (cnt < idx - 1) { while (cnt < idx - 1) {
unsigned int key; unsigned int key;
...@@ -161,6 +171,7 @@ static void hil_kbd_process_record(struct hil_kbd *kbd) ...@@ -161,6 +171,7 @@ static void hil_kbd_process_record(struct hil_kbd *kbd)
input_report_key(dev, key, !up); input_report_key(dev, key, !up);
} }
break; break;
case HIL_POL_CHARTYPE_SET2: case HIL_POL_CHARTYPE_SET2:
while (cnt < idx - 1) { while (cnt < idx - 1) {
unsigned int key; unsigned int key;
...@@ -173,6 +184,7 @@ static void hil_kbd_process_record(struct hil_kbd *kbd) ...@@ -173,6 +184,7 @@ static void hil_kbd_process_record(struct hil_kbd *kbd)
input_report_key(dev, key, !up); input_report_key(dev, key, !up);
} }
break; break;
case HIL_POL_CHARTYPE_SET3: case HIL_POL_CHARTYPE_SET3:
while (cnt < idx - 1) { while (cnt < idx - 1) {
unsigned int key; unsigned int key;
...@@ -191,42 +203,43 @@ static void hil_kbd_process_record(struct hil_kbd *kbd) ...@@ -191,42 +203,43 @@ static void hil_kbd_process_record(struct hil_kbd *kbd)
up(&kbd->sem); up(&kbd->sem);
} }
static void hil_kbd_process_err(struct hil_kbd *kbd) { static void hil_kbd_process_err(struct hil_kbd *kbd)
{
printk(KERN_WARNING PREFIX "errored HIL packet\n"); printk(KERN_WARNING PREFIX "errored HIL packet\n");
kbd->idx4 = 0; kbd->idx4 = 0;
up(&kbd->sem); up(&kbd->sem);
} }
static irqreturn_t hil_kbd_interrupt(struct serio *serio, static irqreturn_t hil_kbd_interrupt(struct serio *serio,
unsigned char data, unsigned int flags) unsigned char data, unsigned int flags)
{ {
struct hil_kbd *kbd; struct hil_kbd *kbd;
hil_packet packet; hil_packet packet;
int idx; int idx;
kbd = serio_get_drvdata(serio); kbd = serio_get_drvdata(serio);
if (kbd == NULL) { BUG_ON(kbd == NULL);
BUG();
return IRQ_HANDLED;
}
if (kbd->idx4 >= (HIL_KBD_MAX_LENGTH * sizeof(hil_packet))) { if (kbd->idx4 >= (HIL_KBD_MAX_LENGTH * sizeof(hil_packet))) {
hil_kbd_process_err(kbd); hil_kbd_process_err(kbd);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
idx = kbd->idx4/4; idx = kbd->idx4/4;
if (!(kbd->idx4 % 4)) kbd->data[idx] = 0; if (!(kbd->idx4 % 4))
kbd->data[idx] = 0;
packet = kbd->data[idx]; packet = kbd->data[idx];
packet |= ((hil_packet)data) << ((3 - (kbd->idx4 % 4)) * 8); packet |= ((hil_packet)data) << ((3 - (kbd->idx4 % 4)) * 8);
kbd->data[idx] = packet; kbd->data[idx] = packet;
/* Records of N 4-byte hil_packets must terminate with a command. */ /* Records of N 4-byte hil_packets must terminate with a command. */
if ((++(kbd->idx4)) % 4) return IRQ_HANDLED; if ((++(kbd->idx4)) % 4)
return IRQ_HANDLED;
if ((packet & 0xffff0000) != HIL_ERR_INT) { if ((packet & 0xffff0000) != HIL_ERR_INT) {
hil_kbd_process_err(kbd); hil_kbd_process_err(kbd);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
if (packet & HIL_PKT_CMD) hil_kbd_process_record(kbd); if (packet & HIL_PKT_CMD)
hil_kbd_process_record(kbd);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -235,10 +248,7 @@ static void hil_kbd_disconnect(struct serio *serio) ...@@ -235,10 +248,7 @@ static void hil_kbd_disconnect(struct serio *serio)
struct hil_kbd *kbd; struct hil_kbd *kbd;
kbd = serio_get_drvdata(serio); kbd = serio_get_drvdata(serio);
if (kbd == NULL) { BUG_ON(kbd == NULL);
BUG();
return;
}
serio_close(serio); serio_close(serio);
input_unregister_device(kbd->dev); input_unregister_device(kbd->dev);
...@@ -267,34 +277,34 @@ static int hil_kbd_connect(struct serio *serio, struct serio_driver *drv) ...@@ -267,34 +277,34 @@ static int hil_kbd_connect(struct serio *serio, struct serio_driver *drv)
serio_set_drvdata(serio, kbd); serio_set_drvdata(serio, kbd);
kbd->serio = serio; kbd->serio = serio;
init_MUTEX_LOCKED(&(kbd->sem)); init_MUTEX_LOCKED(&kbd->sem);
/* Get device info. MLC driver supplies devid/status/etc. */ /* Get device info. MLC driver supplies devid/status/etc. */
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8); serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_IDD); serio->write(serio, HIL_CMD_IDD);
down(&(kbd->sem)); down(&kbd->sem);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8); serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_RSC); serio->write(serio, HIL_CMD_RSC);
down(&(kbd->sem)); down(&kbd->sem);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8); serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_RNM); serio->write(serio, HIL_CMD_RNM);
down(&(kbd->sem)); down(&kbd->sem);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8); serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_EXD); serio->write(serio, HIL_CMD_EXD);
down(&(kbd->sem)); down(&kbd->sem);
up(&(kbd->sem)); up(&kbd->sem);
did = kbd->idd[0]; did = kbd->idd[0];
idd = kbd->idd + 1; idd = kbd->idd + 1;
...@@ -310,12 +320,11 @@ static int hil_kbd_connect(struct serio *serio, struct serio_driver *drv) ...@@ -310,12 +320,11 @@ static int hil_kbd_connect(struct serio *serio, struct serio_driver *drv)
goto bail2; goto bail2;
} }
if(HIL_IDD_NUM_BUTTONS(idd) || HIL_IDD_NUM_AXES_PER_SET(*idd)) { if (HIL_IDD_NUM_BUTTONS(idd) || HIL_IDD_NUM_AXES_PER_SET(*idd)) {
printk(KERN_INFO PREFIX "keyboards only, no combo devices supported.\n"); printk(KERN_INFO PREFIX "keyboards only, no combo devices supported.\n");
goto bail2; goto bail2;
} }
kbd->dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 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->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL);
kbd->dev->keycodemax = HIL_KEYCODES_SET1_TBLSIZE; kbd->dev->keycodemax = HIL_KEYCODES_SET1_TBLSIZE;
...@@ -344,8 +353,8 @@ static int hil_kbd_connect(struct serio *serio, struct serio_driver *drv) ...@@ -344,8 +353,8 @@ static int hil_kbd_connect(struct serio *serio, struct serio_driver *drv)
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8); serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_EK1); /* Enable Keyswitch Autorepeat 1 */ serio->write(serio, HIL_CMD_EK1); /* Enable Keyswitch Autorepeat 1 */
down(&(kbd->sem)); down(&kbd->sem);
up(&(kbd->sem)); up(&kbd->sem);
return 0; return 0;
bail2: bail2:
...@@ -374,20 +383,20 @@ static struct serio_driver hil_kbd_serio_drv = { ...@@ -374,20 +383,20 @@ static struct serio_driver hil_kbd_serio_drv = {
}, },
.description = "HP HIL keyboard driver", .description = "HP HIL keyboard driver",
.id_table = hil_kbd_ids, .id_table = hil_kbd_ids,
.connect = hil_kbd_connect, .connect = hil_kbd_connect,
.disconnect = hil_kbd_disconnect, .disconnect = hil_kbd_disconnect,
.interrupt = hil_kbd_interrupt .interrupt = hil_kbd_interrupt
}; };
static int __init hil_kbd_init(void) static int __init hil_kbd_init(void)
{ {
return serio_register_driver(&hil_kbd_serio_drv); return serio_register_driver(&hil_kbd_serio_drv);
} }
static void __exit hil_kbd_exit(void) static void __exit hil_kbd_exit(void)
{ {
serio_unregister_driver(&hil_kbd_serio_drv); serio_unregister_driver(&hil_kbd_serio_drv);
} }
module_init(hil_kbd_init); module_init(hil_kbd_init);
module_exit(hil_kbd_exit); module_exit(hil_kbd_exit);
...@@ -88,10 +88,12 @@ static void hil_ptr_process_record(struct hil_ptr *ptr) ...@@ -88,10 +88,12 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
idx = ptr->idx4/4; idx = ptr->idx4/4;
p = data[idx - 1]; p = data[idx - 1];
if ((p & ~HIL_CMDCT_POL) == if ((p & ~HIL_CMDCT_POL) ==
(HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL)) goto report; (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL))
if ((p & ~HIL_CMDCT_RPL) == goto report;
(HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_RPL)) 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. */ /* Not a poll response. See if we are loading config records. */
switch (p & HIL_PKT_DATA_MASK) { switch (p & HIL_PKT_DATA_MASK) {
...@@ -101,27 +103,32 @@ static void hil_ptr_process_record(struct hil_ptr *ptr) ...@@ -101,27 +103,32 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
for (; i < HIL_PTR_MAX_LENGTH; i++) for (; i < HIL_PTR_MAX_LENGTH; i++)
ptr->idd[i] = 0; ptr->idd[i] = 0;
break; break;
case HIL_CMD_RSC: case HIL_CMD_RSC:
for (i = 0; i < idx; i++) for (i = 0; i < idx; i++)
ptr->rsc[i] = ptr->data[i] & HIL_PKT_DATA_MASK; ptr->rsc[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_PTR_MAX_LENGTH; i++) for (; i < HIL_PTR_MAX_LENGTH; i++)
ptr->rsc[i] = 0; ptr->rsc[i] = 0;
break; break;
case HIL_CMD_EXD: case HIL_CMD_EXD:
for (i = 0; i < idx; i++) for (i = 0; i < idx; i++)
ptr->exd[i] = ptr->data[i] & HIL_PKT_DATA_MASK; ptr->exd[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_PTR_MAX_LENGTH; i++) for (; i < HIL_PTR_MAX_LENGTH; i++)
ptr->exd[i] = 0; ptr->exd[i] = 0;
break; break;
case HIL_CMD_RNM: case HIL_CMD_RNM:
for (i = 0; i < idx; i++) for (i = 0; i < idx; i++)
ptr->rnm[i] = ptr->data[i] & HIL_PKT_DATA_MASK; ptr->rnm[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
for (; i < HIL_PTR_MAX_LENGTH + 1; i++) for (; i < HIL_PTR_MAX_LENGTH + 1; i++)
ptr->rnm[i] = '\0'; ptr->rnm[i] = 0;
break; break;
default: default:
/* These occur when device isn't present */ /* These occur when device isn't present */
if (p == (HIL_ERR_INT | HIL_PKT_CMD)) break; if (p == (HIL_ERR_INT | HIL_PKT_CMD))
break;
/* Anything else we'd like to know about. */ /* Anything else we'd like to know about. */
printk(KERN_WARNING PREFIX "Device sent unknown record %x\n", p); printk(KERN_WARNING PREFIX "Device sent unknown record %x\n", p);
break; break;
...@@ -130,7 +137,8 @@ static void hil_ptr_process_record(struct hil_ptr *ptr) ...@@ -130,7 +137,8 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
report: report:
if ((p & HIL_CMDCT_POL) != idx - 1) { if ((p & HIL_CMDCT_POL) != idx - 1) {
printk(KERN_WARNING PREFIX "Malformed poll packet %x (idx = %i)\n", p, idx); printk(KERN_WARNING PREFIX
"Malformed poll packet %x (idx = %i)\n", p, idx);
goto out; goto out;
} }
...@@ -139,7 +147,7 @@ static void hil_ptr_process_record(struct hil_ptr *ptr) ...@@ -139,7 +147,7 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
laxis += i; laxis += i;
ax16 = ptr->idd[1] & HIL_IDD_HEADER_16BIT; /* 8 or 16bit resolution */ ax16 = ptr->idd[1] & HIL_IDD_HEADER_16BIT; /* 8 or 16bit resolution */
absdev = ptr->idd[1] & HIL_IDD_HEADER_ABS; absdev = ptr->idd[1] & HIL_IDD_HEADER_ABS;
for (cnt = 1; i < laxis; i++) { for (cnt = 1; i < laxis; i++) {
unsigned int lo,hi,val; unsigned int lo,hi,val;
...@@ -157,7 +165,8 @@ static void hil_ptr_process_record(struct hil_ptr *ptr) ...@@ -157,7 +165,8 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
input_report_abs(dev, ABS_X + i, val); input_report_abs(dev, ABS_X + i, val);
} else { } else {
val = (int) (((int8_t)lo) | ((int8_t)hi<<8)); val = (int) (((int8_t)lo) | ((int8_t)hi<<8));
if (i%3) val *= -1; if (i%3)
val *= -1;
input_report_rel(dev, REL_X + i, val); input_report_rel(dev, REL_X + i, val);
} }
} }
...@@ -168,10 +177,11 @@ static void hil_ptr_process_record(struct hil_ptr *ptr) ...@@ -168,10 +177,11 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
btn = ptr->data[cnt++]; btn = ptr->data[cnt++];
up = btn & 1; up = btn & 1;
btn &= 0xfe; btn &= 0xfe;
if (btn == 0x8e) { if (btn == 0x8e)
continue; /* TODO: proximity == touch? */ continue; /* TODO: proximity == touch? */
} else
else if ((btn > 0x8c) || (btn < 0x80)) continue; if ((btn > 0x8c) || (btn < 0x80))
continue;
btn = (btn - 0x80) >> 1; btn = (btn - 0x80) >> 1;
btn = ptr->btnmap[btn]; btn = ptr->btnmap[btn];
input_report_key(dev, btn, !up); input_report_key(dev, btn, !up);
...@@ -182,14 +192,14 @@ static void hil_ptr_process_record(struct hil_ptr *ptr) ...@@ -182,14 +192,14 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
up(&ptr->sem); up(&ptr->sem);
} }
static void hil_ptr_process_err(struct hil_ptr *ptr) { static void hil_ptr_process_err(struct hil_ptr *ptr)
{
printk(KERN_WARNING PREFIX "errored HIL packet\n"); printk(KERN_WARNING PREFIX "errored HIL packet\n");
ptr->idx4 = 0; ptr->idx4 = 0;
up(&ptr->sem); up(&ptr->sem);
return;
} }
static irqreturn_t hil_ptr_interrupt(struct serio *serio, static irqreturn_t hil_ptr_interrupt(struct serio *serio,
unsigned char data, unsigned int flags) unsigned char data, unsigned int flags)
{ {
struct hil_ptr *ptr; struct hil_ptr *ptr;
...@@ -197,29 +207,29 @@ static irqreturn_t hil_ptr_interrupt(struct serio *serio, ...@@ -197,29 +207,29 @@ static irqreturn_t hil_ptr_interrupt(struct serio *serio,
int idx; int idx;
ptr = serio_get_drvdata(serio); ptr = serio_get_drvdata(serio);
if (ptr == NULL) { BUG_ON(ptr == NULL);
BUG();
return IRQ_HANDLED;
}
if (ptr->idx4 >= (HIL_PTR_MAX_LENGTH * sizeof(hil_packet))) { if (ptr->idx4 >= (HIL_PTR_MAX_LENGTH * sizeof(hil_packet))) {
hil_ptr_process_err(ptr); hil_ptr_process_err(ptr);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
idx = ptr->idx4/4; idx = ptr->idx4/4;
if (!(ptr->idx4 % 4)) ptr->data[idx] = 0; if (!(ptr->idx4 % 4))
ptr->data[idx] = 0;
packet = ptr->data[idx]; packet = ptr->data[idx];
packet |= ((hil_packet)data) << ((3 - (ptr->idx4 % 4)) * 8); packet |= ((hil_packet)data) << ((3 - (ptr->idx4 % 4)) * 8);
ptr->data[idx] = packet; ptr->data[idx] = packet;
/* Records of N 4-byte hil_packets must terminate with a command. */ /* Records of N 4-byte hil_packets must terminate with a command. */
if ((++(ptr->idx4)) % 4) return IRQ_HANDLED; if ((++(ptr->idx4)) % 4)
return IRQ_HANDLED;
if ((packet & 0xffff0000) != HIL_ERR_INT) { if ((packet & 0xffff0000) != HIL_ERR_INT) {
hil_ptr_process_err(ptr); hil_ptr_process_err(ptr);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
if (packet & HIL_PKT_CMD) if (packet & HIL_PKT_CMD)
hil_ptr_process_record(ptr); hil_ptr_process_record(ptr);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -228,10 +238,7 @@ static void hil_ptr_disconnect(struct serio *serio) ...@@ -228,10 +238,7 @@ static void hil_ptr_disconnect(struct serio *serio)
struct hil_ptr *ptr; struct hil_ptr *ptr;
ptr = serio_get_drvdata(serio); ptr = serio_get_drvdata(serio);
if (ptr == NULL) { BUG_ON(ptr == NULL);
BUG();
return;
}
serio_close(serio); serio_close(serio);
input_unregister_device(ptr->dev); input_unregister_device(ptr->dev);
...@@ -241,7 +248,7 @@ static void hil_ptr_disconnect(struct serio *serio) ...@@ -241,7 +248,7 @@ static void hil_ptr_disconnect(struct serio *serio)
static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver) static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
{ {
struct hil_ptr *ptr; struct hil_ptr *ptr;
char *txt; const char *txt;
unsigned int i, naxsets, btntype; unsigned int i, naxsets, btntype;
uint8_t did, *idd; uint8_t did, *idd;
...@@ -260,34 +267,34 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver) ...@@ -260,34 +267,34 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
serio_set_drvdata(serio, ptr); serio_set_drvdata(serio, ptr);
ptr->serio = serio; ptr->serio = serio;
init_MUTEX_LOCKED(&(ptr->sem)); init_MUTEX_LOCKED(&ptr->sem);
/* Get device info. MLC driver supplies devid/status/etc. */ /* Get device info. MLC driver supplies devid/status/etc. */
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8); serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_IDD); serio->write(serio, HIL_CMD_IDD);
down(&(ptr->sem)); down(&ptr->sem);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8); serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_RSC); serio->write(serio, HIL_CMD_RSC);
down(&(ptr->sem)); down(&ptr->sem);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8); serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_RNM); serio->write(serio, HIL_CMD_RNM);
down(&(ptr->sem)); down(&ptr->sem);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, 0); serio->write(serio, 0);
serio->write(serio, HIL_PKT_CMD >> 8); serio->write(serio, HIL_PKT_CMD >> 8);
serio->write(serio, HIL_CMD_EXD); serio->write(serio, HIL_CMD_EXD);
down(&(ptr->sem)); down(&ptr->sem);
up(&(ptr->sem)); up(&ptr->sem);
did = ptr->idd[0]; did = ptr->idd[0];
idd = ptr->idd + 1; idd = ptr->idd + 1;
...@@ -301,12 +308,12 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver) ...@@ -301,12 +308,12 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
ptr->dev->evbit[0] = BIT(EV_ABS); ptr->dev->evbit[0] = BIT(EV_ABS);
txt = "absolute"; txt = "absolute";
} }
if (!ptr->dev->evbit[0]) { if (!ptr->dev->evbit[0])
goto bail2; goto bail2;
}
ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd); ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd);
if (ptr->nbtn) ptr->dev->evbit[0] |= BIT(EV_KEY); if (ptr->nbtn)
ptr->dev->evbit[0] |= BIT(EV_KEY);
naxsets = HIL_IDD_NUM_AXSETS(*idd); naxsets = HIL_IDD_NUM_AXSETS(*idd);
ptr->naxes = HIL_IDD_NUM_AXES_PER_SET(*idd); ptr->naxes = HIL_IDD_NUM_AXES_PER_SET(*idd);
...@@ -315,7 +322,7 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver) ...@@ -315,7 +322,7 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
did, txt); did, txt);
printk(KERN_INFO PREFIX "HIL pointer has %i buttons and %i sets of %i axes\n", printk(KERN_INFO PREFIX "HIL pointer has %i buttons and %i sets of %i axes\n",
ptr->nbtn, naxsets, ptr->naxes); ptr->nbtn, naxsets, ptr->naxes);
btntype = BTN_MISC; btntype = BTN_MISC;
if ((did & HIL_IDD_DID_ABS_TABLET_MASK) == HIL_IDD_DID_ABS_TABLET) if ((did & HIL_IDD_DID_ABS_TABLET_MASK) == HIL_IDD_DID_ABS_TABLET)
#ifdef TABLET_SIMULATES_MOUSE #ifdef TABLET_SIMULATES_MOUSE
...@@ -325,7 +332,7 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver) ...@@ -325,7 +332,7 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
#endif #endif
if ((did & HIL_IDD_DID_ABS_TSCREEN_MASK) == HIL_IDD_DID_ABS_TSCREEN) if ((did & HIL_IDD_DID_ABS_TSCREEN_MASK) == HIL_IDD_DID_ABS_TSCREEN)
btntype = BTN_TOUCH; btntype = BTN_TOUCH;
if ((did & HIL_IDD_DID_REL_MOUSE_MASK) == HIL_IDD_DID_REL_MOUSE) if ((did & HIL_IDD_DID_REL_MOUSE_MASK) == HIL_IDD_DID_REL_MOUSE)
btntype = BTN_MOUSE; btntype = BTN_MOUSE;
...@@ -341,12 +348,10 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver) ...@@ -341,12 +348,10 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
} }
if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) { if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) {
for (i = 0; i < ptr->naxes; i++) { for (i = 0; i < ptr->naxes; i++)
set_bit(REL_X + i, ptr->dev->relbit); set_bit(REL_X + i, ptr->dev->relbit);
} for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++)
for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++) {
set_bit(REL_X + i, ptr->dev->relbit); set_bit(REL_X + i, ptr->dev->relbit);
}
} else { } else {
for (i = 0; i < ptr->naxes; i++) { for (i = 0; i < ptr->naxes; i++) {
set_bit(ABS_X + i, ptr->dev->absbit); set_bit(ABS_X + i, ptr->dev->absbit);
...@@ -419,11 +424,11 @@ static int __init hil_ptr_init(void) ...@@ -419,11 +424,11 @@ static int __init hil_ptr_init(void)
{ {
return serio_register_driver(&hil_ptr_serio_driver); return serio_register_driver(&hil_ptr_serio_driver);
} }
static void __exit hil_ptr_exit(void) static void __exit hil_ptr_exit(void)
{ {
serio_unregister_driver(&hil_ptr_serio_driver); serio_unregister_driver(&hil_ptr_serio_driver);
} }
module_init(hil_ptr_init); module_init(hil_ptr_init);
module_exit(hil_ptr_exit); module_exit(hil_ptr_exit);
...@@ -32,11 +32,11 @@ ...@@ -32,11 +32,11 @@
* *
* Driver theory of operation: * Driver theory of operation:
* *
* Some access methods and an ISR is defined by the sub-driver * 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 * (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, * few bits of logic in addition to raw access to the HIL MLC,
* specifically, the ISR, which is entirely registered by the * specifically, the ISR, which is entirely registered by the
* sub-driver and invoked directly, must check for record * sub-driver and invoked directly, must check for record
* termination or packet match, at which point a semaphore must * termination or packet match, at which point a semaphore must
* be cleared and then the hil_mlcs_tasklet must be scheduled. * be cleared and then the hil_mlcs_tasklet must be scheduled.
* *
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
* itself if output is pending. (This rescheduling should be replaced * itself if output is pending. (This rescheduling should be replaced
* at some point with a sub-driver-specific mechanism.) * at some point with a sub-driver-specific mechanism.)
* *
* A timer task prods the tasklet once per second to prevent * A timer task prods the tasklet once per second to prevent
* hangups when attached devices do not return expected data * hangups when attached devices do not return expected data
* and to initiate probes of the loop for new devices. * and to initiate probes of the loop for new devices.
*/ */
...@@ -83,69 +83,85 @@ DECLARE_TASKLET_DISABLED(hil_mlcs_tasklet, hil_mlcs_process, 0); ...@@ -83,69 +83,85 @@ DECLARE_TASKLET_DISABLED(hil_mlcs_tasklet, hil_mlcs_process, 0);
/********************** Device info/instance management **********************/ /********************** Device info/instance management **********************/
static void hil_mlc_clear_di_map (hil_mlc *mlc, int val) { static void hil_mlc_clear_di_map(hil_mlc *mlc, int val)
{
int j; int j;
for (j = val; j < 7 ; j++) {
for (j = val; j < 7 ; j++)
mlc->di_map[j] = -1; mlc->di_map[j] = -1;
}
} }
static void hil_mlc_clear_di_scratch (hil_mlc *mlc) { static void hil_mlc_clear_di_scratch(hil_mlc *mlc)
memset(&(mlc->di_scratch), 0, sizeof(mlc->di_scratch)); {
memset(&mlc->di_scratch, 0, sizeof(mlc->di_scratch));
} }
static void hil_mlc_copy_di_scratch (hil_mlc *mlc, int idx) { static void hil_mlc_copy_di_scratch(hil_mlc *mlc, int idx)
memcpy(&(mlc->di[idx]), &(mlc->di_scratch), sizeof(mlc->di_scratch)); {
memcpy(&mlc->di[idx], &mlc->di_scratch, sizeof(mlc->di_scratch));
} }
static int hil_mlc_match_di_scratch (hil_mlc *mlc) { static int hil_mlc_match_di_scratch(hil_mlc *mlc)
{
int idx; int idx;
for (idx = 0; idx < HIL_MLC_DEVMEM; idx++) { for (idx = 0; idx < HIL_MLC_DEVMEM; idx++) {
int j, found; int j, found = 0;
/* In-use slots are not eligible. */ /* In-use slots are not eligible. */
found = 0; for (j = 0; j < 7 ; j++)
for (j = 0; j < 7 ; j++) { if (mlc->di_map[j] == idx)
if (mlc->di_map[j] == idx) found++; found++;
}
if (found) continue; if (found)
if (!memcmp(mlc->di + idx, continue;
&(mlc->di_scratch),
sizeof(mlc->di_scratch))) break; if (!memcmp(mlc->di + idx, &mlc->di_scratch,
sizeof(mlc->di_scratch)))
break;
} }
return((idx >= HIL_MLC_DEVMEM) ? -1 : idx); return idx >= HIL_MLC_DEVMEM ? -1 : idx;
} }
static int hil_mlc_find_free_di(hil_mlc *mlc) { static int hil_mlc_find_free_di(hil_mlc *mlc)
{
int idx; int idx;
/* TODO: Pick all-zero slots first, failing that,
* randomize the slot picked among those eligible. /* TODO: Pick all-zero slots first, failing that,
* randomize the slot picked among those eligible.
*/ */
for (idx = 0; idx < HIL_MLC_DEVMEM; idx++) { for (idx = 0; idx < HIL_MLC_DEVMEM; idx++) {
int j, found; int j, found = 0;
found = 0;
for (j = 0; j < 7 ; j++) { for (j = 0; j < 7 ; j++)
if (mlc->di_map[j] == idx) found++; if (mlc->di_map[j] == idx)
} found++;
if (!found) break;
if (!found)
break;
} }
return(idx); /* Note: It is guaranteed at least one above will match */
return idx; /* Note: It is guaranteed at least one above will match */
} }
static inline void hil_mlc_clean_serio_map(hil_mlc *mlc) { static inline void hil_mlc_clean_serio_map(hil_mlc *mlc)
{
int idx; int idx;
for (idx = 0; idx < HIL_MLC_DEVMEM; idx++) { for (idx = 0; idx < HIL_MLC_DEVMEM; idx++) {
int j, found; int j, found = 0;
found = 0;
for (j = 0; j < 7 ; j++) { for (j = 0; j < 7 ; j++)
if (mlc->di_map[j] == idx) found++; if (mlc->di_map[j] == idx)
} found++;
if (!found) mlc->serio_map[idx].di_revmap = -1;
if (!found)
mlc->serio_map[idx].di_revmap = -1;
} }
} }
static void hil_mlc_send_polls(hil_mlc *mlc) { static void hil_mlc_send_polls(hil_mlc *mlc)
{
int did, i, cnt; int did, i, cnt;
struct serio *serio; struct serio *serio;
struct serio_driver *drv; struct serio_driver *drv;
...@@ -157,26 +173,31 @@ static void hil_mlc_send_polls(hil_mlc *mlc) { ...@@ -157,26 +173,31 @@ static void hil_mlc_send_polls(hil_mlc *mlc) {
while (mlc->icount < 15 - i) { while (mlc->icount < 15 - i) {
hil_packet p; hil_packet p;
p = mlc->ipacket[i]; p = mlc->ipacket[i];
if (did != (p & HIL_PKT_ADDR_MASK) >> 8) { if (did != (p & HIL_PKT_ADDR_MASK) >> 8) {
if (drv == NULL || drv->interrupt == NULL) goto skip; if (drv && drv->interrupt) {
drv->interrupt(serio, 0, 0);
drv->interrupt(serio, HIL_ERR_INT >> 16, 0);
drv->interrupt(serio, HIL_PKT_CMD >> 8, 0);
drv->interrupt(serio, HIL_CMD_POL + cnt, 0);
}
drv->interrupt(serio, 0, 0);
drv->interrupt(serio, HIL_ERR_INT >> 16, 0);
drv->interrupt(serio, HIL_PKT_CMD >> 8, 0);
drv->interrupt(serio, HIL_CMD_POL + cnt, 0);
skip:
did = (p & HIL_PKT_ADDR_MASK) >> 8; did = (p & HIL_PKT_ADDR_MASK) >> 8;
serio = did ? mlc->serio[mlc->di_map[did-1]] : NULL; serio = did ? mlc->serio[mlc->di_map[did-1]] : NULL;
drv = (serio != NULL) ? serio->drv : NULL; drv = (serio != NULL) ? serio->drv : NULL;
cnt = 0; cnt = 0;
} }
cnt++; i++;
if (drv == NULL || drv->interrupt == NULL) continue; cnt++;
drv->interrupt(serio, (p >> 24), 0); i++;
drv->interrupt(serio, (p >> 16) & 0xff, 0);
drv->interrupt(serio, (p >> 8) & ~HIL_PKT_ADDR_MASK, 0); if (drv && drv->interrupt) {
drv->interrupt(serio, p & 0xff, 0); drv->interrupt(serio, (p >> 24), 0);
drv->interrupt(serio, (p >> 16) & 0xff, 0);
drv->interrupt(serio, (p >> 8) & ~HIL_PKT_ADDR_MASK, 0);
drv->interrupt(serio, p & 0xff, 0);
}
} }
} }
...@@ -215,12 +236,16 @@ static void hil_mlc_send_polls(hil_mlc *mlc) { ...@@ -215,12 +236,16 @@ static void hil_mlc_send_polls(hil_mlc *mlc) {
#define HILSEN_DOZE (HILSEN_SAME | HILSEN_SCHED | HILSEN_BREAK) #define HILSEN_DOZE (HILSEN_SAME | HILSEN_SCHED | HILSEN_BREAK)
#define HILSEN_SLEEP (HILSEN_SAME | HILSEN_BREAK) #define HILSEN_SLEEP (HILSEN_SAME | HILSEN_BREAK)
static int hilse_match(hil_mlc *mlc, int unused) { static int hilse_match(hil_mlc *mlc, int unused)
{
int rc; int rc;
rc = hil_mlc_match_di_scratch(mlc); rc = hil_mlc_match_di_scratch(mlc);
if (rc == -1) { if (rc == -1) {
rc = hil_mlc_find_free_di(mlc); rc = hil_mlc_find_free_di(mlc);
if (rc == -1) goto err; if (rc == -1)
goto err;
#ifdef HIL_MLC_DEBUG #ifdef HIL_MLC_DEBUG
printk(KERN_DEBUG PREFIX "new in slot %i\n", rc); printk(KERN_DEBUG PREFIX "new in slot %i\n", rc);
#endif #endif
...@@ -231,6 +256,7 @@ static int hilse_match(hil_mlc *mlc, int unused) { ...@@ -231,6 +256,7 @@ static int hilse_match(hil_mlc *mlc, int unused) {
serio_rescan(mlc->serio[rc]); serio_rescan(mlc->serio[rc]);
return -1; return -1;
} }
mlc->di_map[mlc->ddi] = rc; mlc->di_map[mlc->ddi] = rc;
#ifdef HIL_MLC_DEBUG #ifdef HIL_MLC_DEBUG
printk(KERN_DEBUG PREFIX "same in slot %i\n", rc); printk(KERN_DEBUG PREFIX "same in slot %i\n", rc);
...@@ -238,152 +264,177 @@ static int hilse_match(hil_mlc *mlc, int unused) { ...@@ -238,152 +264,177 @@ static int hilse_match(hil_mlc *mlc, int unused) {
mlc->serio_map[rc].di_revmap = mlc->ddi; mlc->serio_map[rc].di_revmap = mlc->ddi;
hil_mlc_clean_serio_map(mlc); hil_mlc_clean_serio_map(mlc);
return 0; return 0;
err: err:
printk(KERN_ERR PREFIX "Residual device slots exhausted, close some serios!\n"); printk(KERN_ERR PREFIX "Residual device slots exhausted, close some serios!\n");
return 1; return 1;
} }
/* An LCV used to prevent runaway loops, forces 5 second sleep when reset. */ /* An LCV used to prevent runaway loops, forces 5 second sleep when reset. */
static int hilse_init_lcv(hil_mlc *mlc, int unused) { static int hilse_init_lcv(hil_mlc *mlc, int unused)
{
struct timeval tv; struct timeval tv;
do_gettimeofday(&tv); do_gettimeofday(&tv);
if(mlc->lcv == 0) goto restart; /* First init, no need to dally */ if (mlc->lcv && (tv.tv_sec - mlc->lcv_tv.tv_sec) < 5)
if(tv.tv_sec - mlc->lcv_tv.tv_sec < 5) return -1; return -1;
restart:
mlc->lcv_tv = tv; mlc->lcv_tv = tv;
mlc->lcv = 0; mlc->lcv = 0;
return 0; return 0;
} }
static int hilse_inc_lcv(hil_mlc *mlc, int lim) { static int hilse_inc_lcv(hil_mlc *mlc, int lim)
if (mlc->lcv++ >= lim) return -1; {
return 0; return mlc->lcv++ >= lim ? -1 : 0;
} }
#if 0 #if 0
static int hilse_set_lcv(hil_mlc *mlc, int val) { static int hilse_set_lcv(hil_mlc *mlc, int val)
{
mlc->lcv = val; mlc->lcv = val;
return 0; return 0;
} }
#endif #endif
/* Management of the discovered device index (zero based, -1 means no devs) */ /* Management of the discovered device index (zero based, -1 means no devs) */
static int hilse_set_ddi(hil_mlc *mlc, int val) { static int hilse_set_ddi(hil_mlc *mlc, int val)
{
mlc->ddi = val; mlc->ddi = val;
hil_mlc_clear_di_map(mlc, val + 1); hil_mlc_clear_di_map(mlc, val + 1);
return 0; return 0;
} }
static int hilse_dec_ddi(hil_mlc *mlc, int unused) { static int hilse_dec_ddi(hil_mlc *mlc, int unused)
{
mlc->ddi--; mlc->ddi--;
if (mlc->ddi <= -1) { if (mlc->ddi <= -1) {
mlc->ddi = -1; mlc->ddi = -1;
hil_mlc_clear_di_map(mlc, 0); hil_mlc_clear_di_map(mlc, 0);
return -1; return -1;
} }
hil_mlc_clear_di_map(mlc, mlc->ddi + 1); hil_mlc_clear_di_map(mlc, mlc->ddi + 1);
return 0; return 0;
} }
static int hilse_inc_ddi(hil_mlc *mlc, int unused) { static int hilse_inc_ddi(hil_mlc *mlc, int unused)
if (mlc->ddi >= 6) { {
BUG(); BUG_ON(mlc->ddi >= 6);
return -1;
}
mlc->ddi++; mlc->ddi++;
return 0; return 0;
} }
static int hilse_take_idd(hil_mlc *mlc, int unused) { static int hilse_take_idd(hil_mlc *mlc, int unused)
{
int i; int i;
/* Help the state engine: /* Help the state engine:
* Is this a real IDD response or just an echo? * Is this a real IDD response or just an echo?
* *
* Real IDD response does not start with a command. * Real IDD response does not start with a command.
*/ */
if (mlc->ipacket[0] & HIL_PKT_CMD) goto bail; if (mlc->ipacket[0] & HIL_PKT_CMD)
goto bail;
/* Should have the command echoed further down. */ /* Should have the command echoed further down. */
for (i = 1; i < 16; i++) { for (i = 1; i < 16; i++) {
if (((mlc->ipacket[i] & HIL_PKT_ADDR_MASK) == if (((mlc->ipacket[i] & HIL_PKT_ADDR_MASK) ==
(mlc->ipacket[0] & HIL_PKT_ADDR_MASK)) && (mlc->ipacket[0] & HIL_PKT_ADDR_MASK)) &&
(mlc->ipacket[i] & HIL_PKT_CMD) && (mlc->ipacket[i] & HIL_PKT_CMD) &&
((mlc->ipacket[i] & HIL_PKT_DATA_MASK) == HIL_CMD_IDD)) ((mlc->ipacket[i] & HIL_PKT_DATA_MASK) == HIL_CMD_IDD))
break; break;
} }
if (i > 15) goto bail; if (i > 15)
goto bail;
/* And the rest of the packets should still be clear. */ /* And the rest of the packets should still be clear. */
while (++i < 16) { while (++i < 16)
if (mlc->ipacket[i]) break; if (mlc->ipacket[i])
} break;
if (i < 16) goto bail;
for (i = 0; i < 16; i++) { if (i < 16)
mlc->di_scratch.idd[i] = goto bail;
for (i = 0; i < 16; i++)
mlc->di_scratch.idd[i] =
mlc->ipacket[i] & HIL_PKT_DATA_MASK; mlc->ipacket[i] & HIL_PKT_DATA_MASK;
}
/* Next step is to see if RSC supported */ /* Next step is to see if RSC supported */
if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_RSC) if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_RSC)
return HILSEN_NEXT; return HILSEN_NEXT;
if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_EXD)
if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_EXD)
return HILSEN_DOWN | 4; return HILSEN_DOWN | 4;
return 0; return 0;
bail: bail:
mlc->ddi--; mlc->ddi--;
return -1; /* This should send us off to ACF */ return -1; /* This should send us off to ACF */
} }
static int hilse_take_rsc(hil_mlc *mlc, int unused) { static int hilse_take_rsc(hil_mlc *mlc, int unused)
{
int i; int i;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++)
mlc->di_scratch.rsc[i] = mlc->di_scratch.rsc[i] =
mlc->ipacket[i] & HIL_PKT_DATA_MASK; mlc->ipacket[i] & HIL_PKT_DATA_MASK;
}
/* Next step is to see if EXD supported (IDD has already been read) */ /* Next step is to see if EXD supported (IDD has already been read) */
if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_EXD) if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_EXD)
return HILSEN_NEXT; return HILSEN_NEXT;
return 0; return 0;
} }
static int hilse_take_exd(hil_mlc *mlc, int unused) { static int hilse_take_exd(hil_mlc *mlc, int unused)
{
int i; int i;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++)
mlc->di_scratch.exd[i] = mlc->di_scratch.exd[i] =
mlc->ipacket[i] & HIL_PKT_DATA_MASK; mlc->ipacket[i] & HIL_PKT_DATA_MASK;
}
/* Next step is to see if RNM supported. */ /* Next step is to see if RNM supported. */
if (mlc->di_scratch.exd[0] & HIL_EXD_HEADER_RNM) if (mlc->di_scratch.exd[0] & HIL_EXD_HEADER_RNM)
return HILSEN_NEXT; return HILSEN_NEXT;
return 0; return 0;
} }
static int hilse_take_rnm(hil_mlc *mlc, int unused) { static int hilse_take_rnm(hil_mlc *mlc, int unused)
{
int i; int i;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++)
mlc->di_scratch.rnm[i] = mlc->di_scratch.rnm[i] =
mlc->ipacket[i] & HIL_PKT_DATA_MASK; mlc->ipacket[i] & HIL_PKT_DATA_MASK;
}
do { printk(KERN_INFO PREFIX "Device name gotten: %16s\n",
char nam[17]; mlc->di_scratch.rnm);
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; return 0;
} }
static int hilse_operate(hil_mlc *mlc, int repoll) { static int hilse_operate(hil_mlc *mlc, int repoll)
{
if (mlc->opercnt == 0) hil_mlcs_probe = 0; if (mlc->opercnt == 0)
hil_mlcs_probe = 0;
mlc->opercnt = 1; mlc->opercnt = 1;
hil_mlc_send_polls(mlc); hil_mlc_send_polls(mlc);
if (!hil_mlcs_probe) return 0; if (!hil_mlcs_probe)
return 0;
hil_mlcs_probe = 0; hil_mlcs_probe = 0;
mlc->opercnt = 0; mlc->opercnt = 0;
return 1; return 1;
...@@ -428,7 +479,7 @@ const struct hilse_node hil_mlc_se[HILSEN_END] = { ...@@ -428,7 +479,7 @@ const struct hilse_node hil_mlc_se[HILSEN_END] = {
EXPECT(HIL_ERR_INT | TEST_PACKET(0xa), EXPECT(HIL_ERR_INT | TEST_PACKET(0xa),
2000, HILSEN_NEXT, HILSEN_RESTART, HILSEN_RESTART) 2000, HILSEN_NEXT, HILSEN_RESTART, HILSEN_RESTART)
OUT(HIL_CTRL_ONLY | 0) /* Disable test mode */ OUT(HIL_CTRL_ONLY | 0) /* Disable test mode */
/* 9 HILSEN_DHR */ /* 9 HILSEN_DHR */
FUNC(hilse_init_lcv, 0, HILSEN_NEXT, HILSEN_SLEEP, 0) FUNC(hilse_init_lcv, 0, HILSEN_NEXT, HILSEN_SLEEP, 0)
...@@ -439,7 +490,7 @@ const struct hilse_node hil_mlc_se[HILSEN_END] = { ...@@ -439,7 +490,7 @@ const struct hilse_node hil_mlc_se[HILSEN_END] = {
IN(300000, HILSEN_DHR2, HILSEN_DHR2, HILSEN_NEXT) IN(300000, HILSEN_DHR2, HILSEN_DHR2, HILSEN_NEXT)
/* 14 HILSEN_IFC */ /* 14 HILSEN_IFC */
OUT(HIL_PKT_CMD | HIL_CMD_IFC) OUT(HIL_PKT_CMD | HIL_CMD_IFC)
EXPECT(HIL_PKT_CMD | HIL_CMD_IFC | HIL_ERR_INT, EXPECT(HIL_PKT_CMD | HIL_CMD_IFC | HIL_ERR_INT,
20000, HILSEN_DISC, HILSEN_DHR2, HILSEN_NEXT ) 20000, HILSEN_DISC, HILSEN_DHR2, HILSEN_NEXT )
...@@ -455,7 +506,7 @@ const struct hilse_node hil_mlc_se[HILSEN_END] = { ...@@ -455,7 +506,7 @@ const struct hilse_node hil_mlc_se[HILSEN_END] = {
/* 18 HILSEN_HEAL */ /* 18 HILSEN_HEAL */
OUT_LAST(HIL_CMD_ELB) OUT_LAST(HIL_CMD_ELB)
EXPECT_LAST(HIL_CMD_ELB | HIL_ERR_INT, EXPECT_LAST(HIL_CMD_ELB | HIL_ERR_INT,
20000, HILSEN_REPOLL, HILSEN_DSR, HILSEN_NEXT) 20000, HILSEN_REPOLL, HILSEN_DSR, HILSEN_NEXT)
FUNC(hilse_dec_ddi, 0, HILSEN_HEAL, HILSEN_NEXT, 0) FUNC(hilse_dec_ddi, 0, HILSEN_HEAL, HILSEN_NEXT, 0)
...@@ -503,7 +554,7 @@ const struct hilse_node hil_mlc_se[HILSEN_END] = { ...@@ -503,7 +554,7 @@ const struct hilse_node hil_mlc_se[HILSEN_END] = {
/* 44 HILSEN_PROBE */ /* 44 HILSEN_PROBE */
OUT_LAST(HIL_PKT_CMD | HIL_CMD_EPT) OUT_LAST(HIL_PKT_CMD | HIL_CMD_EPT)
IN(10000, HILSEN_DISC, HILSEN_DSR, HILSEN_NEXT) IN(10000, HILSEN_DISC, HILSEN_DSR, HILSEN_NEXT)
OUT_DISC(HIL_PKT_CMD | HIL_CMD_ELB) OUT_DISC(HIL_PKT_CMD | HIL_CMD_ELB)
IN(10000, HILSEN_DISC, HILSEN_DSR, HILSEN_NEXT) IN(10000, HILSEN_DISC, HILSEN_DSR, HILSEN_NEXT)
OUT(HIL_PKT_CMD | HIL_CMD_ACF | 1) OUT(HIL_PKT_CMD | HIL_CMD_ACF | 1)
...@@ -514,7 +565,7 @@ const struct hilse_node hil_mlc_se[HILSEN_END] = { ...@@ -514,7 +565,7 @@ const struct hilse_node hil_mlc_se[HILSEN_END] = {
/* 52 HILSEN_DSR */ /* 52 HILSEN_DSR */
FUNC(hilse_set_ddi, -1, HILSEN_NEXT, 0, 0) FUNC(hilse_set_ddi, -1, HILSEN_NEXT, 0, 0)
OUT(HIL_PKT_CMD | HIL_CMD_DSR) OUT(HIL_PKT_CMD | HIL_CMD_DSR)
IN(20000, HILSEN_DHR, HILSEN_DHR, HILSEN_IFC) IN(20000, HILSEN_DHR, HILSEN_DHR, HILSEN_IFC)
/* 55 HILSEN_REPOLL */ /* 55 HILSEN_REPOLL */
OUT(HIL_PKT_CMD | HIL_CMD_RPL) OUT(HIL_PKT_CMD | HIL_CMD_RPL)
...@@ -523,14 +574,15 @@ const struct hilse_node hil_mlc_se[HILSEN_END] = { ...@@ -523,14 +574,15 @@ const struct hilse_node hil_mlc_se[HILSEN_END] = {
FUNC(hilse_operate, 1, HILSEN_OPERATE, HILSEN_IFC, HILSEN_PROBE) FUNC(hilse_operate, 1, HILSEN_OPERATE, HILSEN_IFC, HILSEN_PROBE)
/* 58 HILSEN_IFCACF */ /* 58 HILSEN_IFCACF */
OUT(HIL_PKT_CMD | HIL_CMD_IFC) OUT(HIL_PKT_CMD | HIL_CMD_IFC)
EXPECT(HIL_PKT_CMD | HIL_CMD_IFC | HIL_ERR_INT, EXPECT(HIL_PKT_CMD | HIL_CMD_IFC | HIL_ERR_INT,
20000, HILSEN_ACF2, HILSEN_DHR2, HILSEN_HEAL) 20000, HILSEN_ACF2, HILSEN_DHR2, HILSEN_HEAL)
/* 60 HILSEN_END */ /* 60 HILSEN_END */
}; };
static inline void hilse_setup_input(hil_mlc *mlc, const struct hilse_node *node) { static inline void hilse_setup_input(hil_mlc *mlc, const struct hilse_node *node)
{
switch (node->act) { switch (node->act) {
case HILSE_EXPECT_DISC: case HILSE_EXPECT_DISC:
...@@ -555,25 +607,25 @@ static inline void hilse_setup_input(hil_mlc *mlc, const struct hilse_node *node ...@@ -555,25 +607,25 @@ static inline void hilse_setup_input(hil_mlc *mlc, const struct hilse_node *node
do_gettimeofday(&(mlc->instart)); do_gettimeofday(&(mlc->instart));
mlc->icount = 15; mlc->icount = 15;
memset(mlc->ipacket, 0, 16 * sizeof(hil_packet)); memset(mlc->ipacket, 0, 16 * sizeof(hil_packet));
BUG_ON(down_trylock(&(mlc->isem))); BUG_ON(down_trylock(&mlc->isem));
return;
} }
#ifdef HIL_MLC_DEBUG #ifdef HIL_MLC_DEBUG
static int doze = 0; static int doze;
static int seidx; /* For debug */ static int seidx; /* For debug */
#endif #endif
static int hilse_donode (hil_mlc *mlc) { static int hilse_donode(hil_mlc *mlc)
{
const struct hilse_node *node; const struct hilse_node *node;
int nextidx = 0; int nextidx = 0;
int sched_long = 0; int sched_long = 0;
unsigned long flags; unsigned long flags;
#ifdef HIL_MLC_DEBUG #ifdef HIL_MLC_DEBUG
if (mlc->seidx && (mlc->seidx != seidx) && mlc->seidx != 41 && mlc->seidx != 42 && mlc->seidx != 43) { if (mlc->seidx && mlc->seidx != seidx &&
printk(KERN_DEBUG PREFIX "z%i \n {%i}", doze, mlc->seidx); mlc->seidx != 41 && mlc->seidx != 42 && mlc->seidx != 43) {
printk(KERN_DEBUG PREFIX "z%i \n {%i}", doze, mlc->seidx);
doze = 0; doze = 0;
} }
...@@ -588,50 +640,59 @@ static int hilse_donode (hil_mlc *mlc) { ...@@ -588,50 +640,59 @@ static int hilse_donode (hil_mlc *mlc) {
case HILSE_FUNC: case HILSE_FUNC:
BUG_ON(node->object.func == NULL); BUG_ON(node->object.func == NULL);
rc = node->object.func(mlc, node->arg); rc = node->object.func(mlc, node->arg);
nextidx = (rc > 0) ? node->ugly : nextidx = (rc > 0) ? node->ugly :
((rc < 0) ? node->bad : node->good); ((rc < 0) ? node->bad : node->good);
if (nextidx == HILSEN_FOLLOW) nextidx = rc; if (nextidx == HILSEN_FOLLOW)
nextidx = rc;
break; break;
case HILSE_EXPECT_LAST: case HILSE_EXPECT_LAST:
case HILSE_EXPECT_DISC: case HILSE_EXPECT_DISC:
case HILSE_EXPECT: case HILSE_EXPECT:
case HILSE_IN: case HILSE_IN:
/* Already set up from previous HILSE_OUT_* */ /* Already set up from previous HILSE_OUT_* */
write_lock_irqsave(&(mlc->lock), flags); write_lock_irqsave(&mlc->lock, flags);
rc = mlc->in(mlc, node->arg); rc = mlc->in(mlc, node->arg);
if (rc == 2) { if (rc == 2) {
nextidx = HILSEN_DOZE; nextidx = HILSEN_DOZE;
sched_long = 1; sched_long = 1;
write_unlock_irqrestore(&(mlc->lock), flags); write_unlock_irqrestore(&mlc->lock, flags);
break; break;
} }
if (rc == 1) nextidx = node->ugly; if (rc == 1)
else if (rc == 0) nextidx = node->good; nextidx = node->ugly;
else nextidx = node->bad; else if (rc == 0)
nextidx = node->good;
else
nextidx = node->bad;
mlc->istarted = 0; mlc->istarted = 0;
write_unlock_irqrestore(&(mlc->lock), flags); write_unlock_irqrestore(&mlc->lock, flags);
break; break;
case HILSE_OUT_LAST: case HILSE_OUT_LAST:
write_lock_irqsave(&(mlc->lock), flags); write_lock_irqsave(&mlc->lock, flags);
pack = node->object.packet; pack = node->object.packet;
pack |= ((mlc->ddi + 1) << HIL_PKT_ADDR_SHIFT); pack |= ((mlc->ddi + 1) << HIL_PKT_ADDR_SHIFT);
goto out; goto out;
case HILSE_OUT_DISC: case HILSE_OUT_DISC:
write_lock_irqsave(&(mlc->lock), flags); write_lock_irqsave(&mlc->lock, flags);
pack = node->object.packet; pack = node->object.packet;
pack |= ((mlc->ddi + 2) << HIL_PKT_ADDR_SHIFT); pack |= ((mlc->ddi + 2) << HIL_PKT_ADDR_SHIFT);
goto out; goto out;
case HILSE_OUT: case HILSE_OUT:
write_lock_irqsave(&(mlc->lock), flags); write_lock_irqsave(&mlc->lock, flags);
pack = node->object.packet; pack = node->object.packet;
out: out:
if (mlc->istarted) goto out2; if (mlc->istarted)
goto out2;
/* Prepare to receive input */ /* Prepare to receive input */
if ((node + 1)->act & HILSE_IN) if ((node + 1)->act & HILSE_IN)
hilse_setup_input(mlc, node + 1); hilse_setup_input(mlc, node + 1);
out2: out2:
write_unlock_irqrestore(&(mlc->lock), flags); write_unlock_irqrestore(&mlc->lock, flags);
if (down_trylock(&mlc->osem)) { if (down_trylock(&mlc->osem)) {
nextidx = HILSEN_DOZE; nextidx = HILSEN_DOZE;
...@@ -639,37 +700,39 @@ static int hilse_donode (hil_mlc *mlc) { ...@@ -639,37 +700,39 @@ static int hilse_donode (hil_mlc *mlc) {
} }
up(&mlc->osem); up(&mlc->osem);
write_lock_irqsave(&(mlc->lock), flags); write_lock_irqsave(&mlc->lock, flags);
if (!(mlc->ostarted)) { if (!mlc->ostarted) {
mlc->ostarted = 1; mlc->ostarted = 1;
mlc->opacket = pack; mlc->opacket = pack;
mlc->out(mlc); mlc->out(mlc);
nextidx = HILSEN_DOZE; nextidx = HILSEN_DOZE;
write_unlock_irqrestore(&(mlc->lock), flags); write_unlock_irqrestore(&mlc->lock, flags);
break; break;
} }
mlc->ostarted = 0; mlc->ostarted = 0;
do_gettimeofday(&(mlc->instart)); do_gettimeofday(&(mlc->instart));
write_unlock_irqrestore(&(mlc->lock), flags); write_unlock_irqrestore(&mlc->lock, flags);
nextidx = HILSEN_NEXT; nextidx = HILSEN_NEXT;
break; break;
case HILSE_CTS: case HILSE_CTS:
nextidx = mlc->cts(mlc) ? node->bad : node->good; nextidx = mlc->cts(mlc) ? node->bad : node->good;
break; break;
default: default:
BUG(); BUG();
nextidx = 0;
break;
} }
#ifdef HIL_MLC_DEBUG #ifdef HIL_MLC_DEBUG
if (nextidx == HILSEN_DOZE) doze++; if (nextidx == HILSEN_DOZE)
doze++;
#endif #endif
while (nextidx & HILSEN_SCHED) { while (nextidx & HILSEN_SCHED) {
struct timeval tv; struct timeval tv;
if (!sched_long) goto sched; if (!sched_long)
goto sched;
do_gettimeofday(&tv); do_gettimeofday(&tv);
tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec); tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec);
...@@ -682,17 +745,24 @@ static int hilse_donode (hil_mlc *mlc) { ...@@ -682,17 +745,24 @@ static int hilse_donode (hil_mlc *mlc) {
sched: sched:
tasklet_schedule(&hil_mlcs_tasklet); tasklet_schedule(&hil_mlcs_tasklet);
break; break;
} }
if (nextidx & HILSEN_DOWN) mlc->seidx += nextidx & HILSEN_MASK;
else if (nextidx & HILSEN_UP) mlc->seidx -= nextidx & HILSEN_MASK; if (nextidx & HILSEN_DOWN)
else mlc->seidx = nextidx & HILSEN_MASK; 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;
if (nextidx & HILSEN_BREAK) return 1;
return 0; return 0;
} }
/******************** tasklet context functions **************************/ /******************** tasklet context functions **************************/
static void hil_mlcs_process(unsigned long unused) { static void hil_mlcs_process(unsigned long unused)
{
struct list_head *tmp; struct list_head *tmp;
read_lock(&hil_mlcs_lock); read_lock(&hil_mlcs_lock);
...@@ -700,19 +770,20 @@ static void hil_mlcs_process(unsigned long unused) { ...@@ -700,19 +770,20 @@ static void hil_mlcs_process(unsigned long unused) {
struct hil_mlc *mlc = list_entry(tmp, hil_mlc, list); struct hil_mlc *mlc = list_entry(tmp, hil_mlc, list);
while (hilse_donode(mlc) == 0) { while (hilse_donode(mlc) == 0) {
#ifdef HIL_MLC_DEBUG #ifdef HIL_MLC_DEBUG
if (mlc->seidx != 41 && if (mlc->seidx != 41 &&
mlc->seidx != 42 && mlc->seidx != 42 &&
mlc->seidx != 43) mlc->seidx != 43)
printk(KERN_DEBUG PREFIX " + "); printk(KERN_DEBUG PREFIX " + ");
#endif #endif
}; }
} }
read_unlock(&hil_mlcs_lock); read_unlock(&hil_mlcs_lock);
} }
/************************* Keepalive timer task *********************/ /************************* Keepalive timer task *********************/
void hil_mlcs_timer (unsigned long data) { void hil_mlcs_timer(unsigned long data)
{
hil_mlcs_probe = 1; hil_mlcs_probe = 1;
tasklet_schedule(&hil_mlcs_tasklet); tasklet_schedule(&hil_mlcs_tasklet);
/* Re-insert the periodic task. */ /* Re-insert the periodic task. */
...@@ -722,28 +793,25 @@ void hil_mlcs_timer (unsigned long data) { ...@@ -722,28 +793,25 @@ void hil_mlcs_timer (unsigned long data) {
/******************** user/kernel context functions **********************/ /******************** user/kernel context functions **********************/
static int hil_mlc_serio_write(struct serio *serio, unsigned char c) { static int hil_mlc_serio_write(struct serio *serio, unsigned char c)
{
struct hil_mlc_serio_map *map; struct hil_mlc_serio_map *map;
struct hil_mlc *mlc; struct hil_mlc *mlc;
struct serio_driver *drv; struct serio_driver *drv;
uint8_t *idx, *last; uint8_t *idx, *last;
map = serio->port_data; map = serio->port_data;
if (map == NULL) { BUG_ON(map == NULL);
BUG();
return -EIO;
}
mlc = map->mlc; mlc = map->mlc;
if (mlc == NULL) { BUG_ON(mlc == NULL);
BUG();
return -EIO; mlc->serio_opacket[map->didx] |=
}
mlc->serio_opacket[map->didx] |=
((hil_packet)c) << (8 * (3 - mlc->serio_oidx[map->didx])); ((hil_packet)c) << (8 * (3 - mlc->serio_oidx[map->didx]));
if (mlc->serio_oidx[map->didx] >= 3) { if (mlc->serio_oidx[map->didx] >= 3) {
/* for now only commands */ /* for now only commands */
if (!(mlc->serio_opacket[map->didx] & HIL_PKT_CMD)) if (!(mlc->serio_opacket[map->didx] & HIL_PKT_CMD))
return -EIO; return -EIO;
switch (mlc->serio_opacket[map->didx] & HIL_PKT_DATA_MASK) { switch (mlc->serio_opacket[map->didx] & HIL_PKT_DATA_MASK) {
case HIL_CMD_IDD: case HIL_CMD_IDD:
...@@ -769,12 +837,11 @@ static int hil_mlc_serio_write(struct serio *serio, unsigned char c) { ...@@ -769,12 +837,11 @@ static int hil_mlc_serio_write(struct serio *serio, unsigned char c) {
return -EIO; return -EIO;
emu: emu:
drv = serio->drv; drv = serio->drv;
if (drv == NULL) { BUG_ON(drv == NULL);
BUG();
return -EIO;
}
last = idx + 15; last = idx + 15;
while ((last != idx) && (*last == 0)) last--; while ((last != idx) && (*last == 0))
last--;
while (idx != last) { while (idx != last) {
drv->interrupt(serio, 0, 0); drv->interrupt(serio, 0, 0);
...@@ -787,14 +854,15 @@ static int hil_mlc_serio_write(struct serio *serio, unsigned char c) { ...@@ -787,14 +854,15 @@ static int hil_mlc_serio_write(struct serio *serio, unsigned char c) {
drv->interrupt(serio, HIL_ERR_INT >> 16, 0); drv->interrupt(serio, HIL_ERR_INT >> 16, 0);
drv->interrupt(serio, HIL_PKT_CMD >> 8, 0); drv->interrupt(serio, HIL_PKT_CMD >> 8, 0);
drv->interrupt(serio, *idx, 0); drv->interrupt(serio, *idx, 0);
mlc->serio_oidx[map->didx] = 0; mlc->serio_oidx[map->didx] = 0;
mlc->serio_opacket[map->didx] = 0; mlc->serio_opacket[map->didx] = 0;
return 0; return 0;
} }
static int hil_mlc_serio_open(struct serio *serio) { static int hil_mlc_serio_open(struct serio *serio)
{
struct hil_mlc_serio_map *map; struct hil_mlc_serio_map *map;
struct hil_mlc *mlc; struct hil_mlc *mlc;
...@@ -802,33 +870,24 @@ static int hil_mlc_serio_open(struct serio *serio) { ...@@ -802,33 +870,24 @@ static int hil_mlc_serio_open(struct serio *serio) {
return -EBUSY; return -EBUSY;
map = serio->port_data; map = serio->port_data;
if (map == NULL) { BUG_ON(map == NULL);
BUG();
return -ENODEV;
}
mlc = map->mlc; mlc = map->mlc;
if (mlc == NULL) { BUG_ON(mlc == NULL);
BUG();
return -ENODEV;
}
return 0; return 0;
} }
static void hil_mlc_serio_close(struct serio *serio) { static void hil_mlc_serio_close(struct serio *serio)
{
struct hil_mlc_serio_map *map; struct hil_mlc_serio_map *map;
struct hil_mlc *mlc; struct hil_mlc *mlc;
map = serio->port_data; map = serio->port_data;
if (map == NULL) { BUG_ON(map == NULL);
BUG();
return;
}
mlc = map->mlc; mlc = map->mlc;
if (mlc == NULL) { BUG_ON(mlc == NULL);
BUG();
return;
}
serio_set_drvdata(serio, NULL); serio_set_drvdata(serio, NULL);
serio->drv = NULL; serio->drv = NULL;
...@@ -842,27 +901,26 @@ static const struct serio_device_id hil_mlc_serio_id = { ...@@ -842,27 +901,26 @@ static const struct serio_device_id hil_mlc_serio_id = {
.id = SERIO_ANY, .id = SERIO_ANY,
}; };
int hil_mlc_register(hil_mlc *mlc) { int hil_mlc_register(hil_mlc *mlc)
{
int i; int i;
unsigned long flags; unsigned long flags;
if (mlc == NULL) { BUG_ON(mlc == NULL);
return -EINVAL;
}
mlc->istarted = 0; mlc->istarted = 0;
mlc->ostarted = 0; mlc->ostarted = 0;
rwlock_init(&mlc->lock); rwlock_init(&mlc->lock);
init_MUTEX(&(mlc->osem)); init_MUTEX(&mlc->osem);
init_MUTEX(&(mlc->isem)); init_MUTEX(&mlc->isem);
mlc->icount = -1; mlc->icount = -1;
mlc->imatch = 0; mlc->imatch = 0;
mlc->opercnt = 0; mlc->opercnt = 0;
init_MUTEX_LOCKED(&(mlc->csem)); init_MUTEX_LOCKED(&(mlc->csem));
hil_mlc_clear_di_scratch(mlc); hil_mlc_clear_di_scratch(mlc);
hil_mlc_clear_di_map(mlc, 0); hil_mlc_clear_di_map(mlc, 0);
...@@ -897,19 +955,18 @@ int hil_mlc_register(hil_mlc *mlc) { ...@@ -897,19 +955,18 @@ int hil_mlc_register(hil_mlc *mlc) {
return 0; return 0;
} }
int hil_mlc_unregister(hil_mlc *mlc) { int hil_mlc_unregister(hil_mlc *mlc)
{
struct list_head *tmp; struct list_head *tmp;
unsigned long flags; unsigned long flags;
int i; int i;
if (mlc == NULL) BUG_ON(mlc == NULL);
return -EINVAL;
write_lock_irqsave(&hil_mlcs_lock, flags); write_lock_irqsave(&hil_mlcs_lock, flags);
list_for_each(tmp, &hil_mlcs) { list_for_each(tmp, &hil_mlcs)
if (list_entry(tmp, hil_mlc, list) == mlc) if (list_entry(tmp, hil_mlc, list) == mlc)
goto found; goto found;
}
/* not found in list */ /* not found in list */
write_unlock_irqrestore(&hil_mlcs_lock, flags); write_unlock_irqrestore(&hil_mlcs_lock, flags);
...@@ -918,7 +975,7 @@ int hil_mlc_unregister(hil_mlc *mlc) { ...@@ -918,7 +975,7 @@ int hil_mlc_unregister(hil_mlc *mlc) {
found: found:
list_del(tmp); list_del(tmp);
write_unlock_irqrestore(&hil_mlcs_lock, flags); write_unlock_irqrestore(&hil_mlcs_lock, flags);
for (i = 0; i < HIL_MLC_DEVMEM; i++) { for (i = 0; i < HIL_MLC_DEVMEM; i++) {
serio_unregister_port(mlc->serio[i]); serio_unregister_port(mlc->serio[i]);
...@@ -942,7 +999,7 @@ static int __init hil_mlc_init(void) ...@@ -942,7 +999,7 @@ static int __init hil_mlc_init(void)
return 0; return 0;
} }
static void __exit hil_mlc_exit(void) static void __exit hil_mlc_exit(void)
{ {
del_timer(&hil_mlcs_kicker); del_timer(&hil_mlcs_kicker);
...@@ -950,6 +1007,6 @@ static void __exit hil_mlc_exit(void) ...@@ -950,6 +1007,6 @@ static void __exit hil_mlc_exit(void)
tasklet_disable(&hil_mlcs_tasklet); tasklet_disable(&hil_mlcs_tasklet);
tasklet_kill(&hil_mlcs_tasklet); tasklet_kill(&hil_mlcs_tasklet);
} }
module_init(hil_mlc_init); module_init(hil_mlc_init);
module_exit(hil_mlc_exit); module_exit(hil_mlc_exit);
...@@ -34,27 +34,27 @@ ...@@ -34,27 +34,27 @@
* *
* Driver theory of operation: * Driver theory of operation:
* *
* hp_sdc_put does all writing to the SDC. ISR can run on a different * 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 * 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. * (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 * 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. * 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 * 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, * 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, * but if used with HIL devices that support the multibyte transfer command,
* keeping outbound throughput flowing at the 6500KBps that the HIL is * keeping outbound throughput flowing at the 6500KBps that the HIL is
* capable of is more than can be done at HZ=100. * 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 * 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 * 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 * 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 * 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. * 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 * 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, * 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 * 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. * 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 * A timer task schedules the tasklet once per second just to make
...@@ -106,33 +106,39 @@ EXPORT_SYMBOL(hp_sdc_dequeue_transaction); ...@@ -106,33 +106,39 @@ EXPORT_SYMBOL(hp_sdc_dequeue_transaction);
static hp_i8042_sdc hp_sdc; /* All driver state is kept in here. */ static hp_i8042_sdc hp_sdc; /* All driver state is kept in here. */
/*************** primitives for use in any context *********************/ /*************** primitives for use in any context *********************/
static inline uint8_t hp_sdc_status_in8 (void) { static inline uint8_t hp_sdc_status_in8(void)
{
uint8_t status; uint8_t status;
unsigned long flags; unsigned long flags;
write_lock_irqsave(&hp_sdc.ibf_lock, flags); write_lock_irqsave(&hp_sdc.ibf_lock, flags);
status = sdc_readb(hp_sdc.status_io); status = sdc_readb(hp_sdc.status_io);
if (!(status & HP_SDC_STATUS_IBF)) hp_sdc.ibf = 0; if (!(status & HP_SDC_STATUS_IBF))
hp_sdc.ibf = 0;
write_unlock_irqrestore(&hp_sdc.ibf_lock, flags); write_unlock_irqrestore(&hp_sdc.ibf_lock, flags);
return status; return status;
} }
static inline uint8_t hp_sdc_data_in8 (void) { static inline uint8_t hp_sdc_data_in8(void)
return sdc_readb(hp_sdc.data_io); {
return sdc_readb(hp_sdc.data_io);
} }
static inline void hp_sdc_status_out8 (uint8_t val) { static inline void hp_sdc_status_out8(uint8_t val)
{
unsigned long flags; unsigned long flags;
write_lock_irqsave(&hp_sdc.ibf_lock, flags); write_lock_irqsave(&hp_sdc.ibf_lock, flags);
hp_sdc.ibf = 1; hp_sdc.ibf = 1;
if ((val & 0xf0) == 0xe0) hp_sdc.wi = 0xff; if ((val & 0xf0) == 0xe0)
hp_sdc.wi = 0xff;
sdc_writeb(val, hp_sdc.status_io); sdc_writeb(val, hp_sdc.status_io);
write_unlock_irqrestore(&hp_sdc.ibf_lock, flags); write_unlock_irqrestore(&hp_sdc.ibf_lock, flags);
} }
static inline void hp_sdc_data_out8 (uint8_t val) { static inline void hp_sdc_data_out8(uint8_t val)
{
unsigned long flags; unsigned long flags;
write_lock_irqsave(&hp_sdc.ibf_lock, flags); write_lock_irqsave(&hp_sdc.ibf_lock, flags);
...@@ -141,11 +147,12 @@ static inline void hp_sdc_data_out8 (uint8_t val) { ...@@ -141,11 +147,12 @@ static inline void hp_sdc_data_out8 (uint8_t val) {
write_unlock_irqrestore(&hp_sdc.ibf_lock, flags); write_unlock_irqrestore(&hp_sdc.ibf_lock, flags);
} }
/* Care must be taken to only invoke hp_sdc_spin_ibf when /* Care must be taken to only invoke hp_sdc_spin_ibf when
* absolutely needed, or in rarely invoked subroutines. * absolutely needed, or in rarely invoked subroutines.
* Not only does it waste CPU cycles, it also wastes bus cycles. * Not only does it waste CPU cycles, it also wastes bus cycles.
*/ */
static inline void hp_sdc_spin_ibf(void) { static inline void hp_sdc_spin_ibf(void)
{
unsigned long flags; unsigned long flags;
rwlock_t *lock; rwlock_t *lock;
...@@ -158,19 +165,21 @@ static inline void hp_sdc_spin_ibf(void) { ...@@ -158,19 +165,21 @@ static inline void hp_sdc_spin_ibf(void) {
} }
read_unlock(lock); read_unlock(lock);
write_lock(lock); write_lock(lock);
while (sdc_readb(hp_sdc.status_io) & HP_SDC_STATUS_IBF) {}; while (sdc_readb(hp_sdc.status_io) & HP_SDC_STATUS_IBF)
{ }
hp_sdc.ibf = 0; hp_sdc.ibf = 0;
write_unlock_irqrestore(lock, flags); write_unlock_irqrestore(lock, flags);
} }
/************************ Interrupt context functions ************************/ /************************ Interrupt context functions ************************/
static void hp_sdc_take (int irq, void *dev_id, uint8_t status, uint8_t data) { static void hp_sdc_take(int irq, void *dev_id, uint8_t status, uint8_t data)
{
hp_sdc_transaction *curr; hp_sdc_transaction *curr;
read_lock(&hp_sdc.rtq_lock); read_lock(&hp_sdc.rtq_lock);
if (hp_sdc.rcurr < 0) { if (hp_sdc.rcurr < 0) {
read_unlock(&hp_sdc.rtq_lock); read_unlock(&hp_sdc.rtq_lock);
return; return;
} }
curr = hp_sdc.tq[hp_sdc.rcurr]; curr = hp_sdc.tq[hp_sdc.rcurr];
...@@ -183,25 +192,27 @@ static void hp_sdc_take (int irq, void *dev_id, uint8_t status, uint8_t data) { ...@@ -183,25 +192,27 @@ static void hp_sdc_take (int irq, void *dev_id, uint8_t status, uint8_t data) {
if (hp_sdc.rqty <= 0) { if (hp_sdc.rqty <= 0) {
/* All data has been gathered. */ /* All data has been gathered. */
if(curr->seq[curr->actidx] & HP_SDC_ACT_SEMAPHORE) { if (curr->seq[curr->actidx] & HP_SDC_ACT_SEMAPHORE)
if (curr->act.semaphore) up(curr->act.semaphore); if (curr->act.semaphore)
} up(curr->act.semaphore);
if(curr->seq[curr->actidx] & HP_SDC_ACT_CALLBACK) {
if (curr->seq[curr->actidx] & HP_SDC_ACT_CALLBACK)
if (curr->act.irqhook) if (curr->act.irqhook)
curr->act.irqhook(irq, dev_id, status, data); curr->act.irqhook(irq, dev_id, status, data);
}
curr->actidx = curr->idx; curr->actidx = curr->idx;
curr->idx++; curr->idx++;
/* Return control of this transaction */ /* Return control of this transaction */
write_lock(&hp_sdc.rtq_lock); write_lock(&hp_sdc.rtq_lock);
hp_sdc.rcurr = -1; hp_sdc.rcurr = -1;
hp_sdc.rqty = 0; hp_sdc.rqty = 0;
write_unlock(&hp_sdc.rtq_lock); write_unlock(&hp_sdc.rtq_lock);
tasklet_schedule(&hp_sdc.task); tasklet_schedule(&hp_sdc.task);
} }
} }
static irqreturn_t hp_sdc_isr(int irq, void *dev_id) { static irqreturn_t hp_sdc_isr(int irq, void *dev_id)
{
uint8_t status, data; uint8_t status, data;
status = hp_sdc_status_in8(); status = hp_sdc_status_in8();
...@@ -209,67 +220,74 @@ static irqreturn_t hp_sdc_isr(int irq, void *dev_id) { ...@@ -209,67 +220,74 @@ static irqreturn_t hp_sdc_isr(int irq, void *dev_id) {
data = hp_sdc_data_in8(); data = hp_sdc_data_in8();
/* For now we are ignoring these until we get the SDC to behave. */ /* For now we are ignoring these until we get the SDC to behave. */
if (((status & 0xf1) == 0x51) && data == 0x82) { if (((status & 0xf1) == 0x51) && data == 0x82)
return IRQ_HANDLED; return IRQ_HANDLED;
}
switch(status & HP_SDC_STATUS_IRQMASK) { switch (status & HP_SDC_STATUS_IRQMASK) {
case 0: /* This case is not documented. */ case 0: /* This case is not documented. */
break; break;
case HP_SDC_STATUS_USERTIMER:
case HP_SDC_STATUS_PERIODIC: case HP_SDC_STATUS_USERTIMER:
case HP_SDC_STATUS_TIMER: case HP_SDC_STATUS_PERIODIC:
case HP_SDC_STATUS_TIMER:
read_lock(&hp_sdc.hook_lock); read_lock(&hp_sdc.hook_lock);
if (hp_sdc.timer != NULL) if (hp_sdc.timer != NULL)
hp_sdc.timer(irq, dev_id, status, data); hp_sdc.timer(irq, dev_id, status, data);
read_unlock(&hp_sdc.hook_lock); read_unlock(&hp_sdc.hook_lock);
break; break;
case HP_SDC_STATUS_REG:
case HP_SDC_STATUS_REG:
hp_sdc_take(irq, dev_id, status, data); hp_sdc_take(irq, dev_id, status, data);
break; break;
case HP_SDC_STATUS_HILCMD:
case HP_SDC_STATUS_HILDATA: case HP_SDC_STATUS_HILCMD:
case HP_SDC_STATUS_HILDATA:
read_lock(&hp_sdc.hook_lock); read_lock(&hp_sdc.hook_lock);
if (hp_sdc.hil != NULL) if (hp_sdc.hil != NULL)
hp_sdc.hil(irq, dev_id, status, data); hp_sdc.hil(irq, dev_id, status, data);
read_unlock(&hp_sdc.hook_lock); read_unlock(&hp_sdc.hook_lock);
break; break;
case HP_SDC_STATUS_PUP:
case HP_SDC_STATUS_PUP:
read_lock(&hp_sdc.hook_lock); read_lock(&hp_sdc.hook_lock);
if (hp_sdc.pup != NULL) if (hp_sdc.pup != NULL)
hp_sdc.pup(irq, dev_id, status, data); hp_sdc.pup(irq, dev_id, status, data);
else printk(KERN_INFO PREFIX "HP SDC reports successful PUP.\n"); else
printk(KERN_INFO PREFIX "HP SDC reports successful PUP.\n");
read_unlock(&hp_sdc.hook_lock); read_unlock(&hp_sdc.hook_lock);
break; break;
default:
default:
read_lock(&hp_sdc.hook_lock); read_lock(&hp_sdc.hook_lock);
if (hp_sdc.cooked != NULL) if (hp_sdc.cooked != NULL)
hp_sdc.cooked(irq, dev_id, status, data); hp_sdc.cooked(irq, dev_id, status, data);
read_unlock(&hp_sdc.hook_lock); read_unlock(&hp_sdc.hook_lock);
break; break;
} }
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static irqreturn_t hp_sdc_nmisr(int irq, void *dev_id) { static irqreturn_t hp_sdc_nmisr(int irq, void *dev_id)
{
int status; int status;
status = hp_sdc_status_in8(); status = hp_sdc_status_in8();
printk(KERN_WARNING PREFIX "NMI !\n"); printk(KERN_WARNING PREFIX "NMI !\n");
#if 0 #if 0
if (status & HP_SDC_NMISTATUS_FHS) { if (status & HP_SDC_NMISTATUS_FHS) {
read_lock(&hp_sdc.hook_lock); read_lock(&hp_sdc.hook_lock);
if (hp_sdc.timer != NULL) if (hp_sdc.timer != NULL)
hp_sdc.timer(irq, dev_id, status, 0); hp_sdc.timer(irq, dev_id, status, 0);
read_unlock(&hp_sdc.hook_lock); read_unlock(&hp_sdc.hook_lock);
} } else {
else {
/* TODO: pass this on to the HIL handler, or do SAK here? */ /* TODO: pass this on to the HIL handler, or do SAK here? */
printk(KERN_WARNING PREFIX "HIL NMI\n"); printk(KERN_WARNING PREFIX "HIL NMI\n");
} }
#endif #endif
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -278,13 +296,17 @@ static irqreturn_t hp_sdc_nmisr(int irq, void *dev_id) { ...@@ -278,13 +296,17 @@ static irqreturn_t hp_sdc_nmisr(int irq, void *dev_id) {
unsigned long hp_sdc_put(void); unsigned long hp_sdc_put(void);
static void hp_sdc_tasklet(unsigned long foo) { static void hp_sdc_tasklet(unsigned long foo)
{
write_lock_irq(&hp_sdc.rtq_lock); write_lock_irq(&hp_sdc.rtq_lock);
if (hp_sdc.rcurr >= 0) { if (hp_sdc.rcurr >= 0) {
struct timeval tv; struct timeval tv;
do_gettimeofday(&tv); do_gettimeofday(&tv);
if (tv.tv_sec > hp_sdc.rtv.tv_sec) tv.tv_usec += 1000000; if (tv.tv_sec > hp_sdc.rtv.tv_sec)
tv.tv_usec += USEC_PER_SEC;
if (tv.tv_usec - hp_sdc.rtv.tv_usec > HP_SDC_MAX_REG_DELAY) { if (tv.tv_usec - hp_sdc.rtv.tv_usec > HP_SDC_MAX_REG_DELAY) {
hp_sdc_transaction *curr; hp_sdc_transaction *curr;
uint8_t tmp; uint8_t tmp;
...@@ -300,27 +322,29 @@ static void hp_sdc_tasklet(unsigned long foo) { ...@@ -300,27 +322,29 @@ static void hp_sdc_tasklet(unsigned long foo) {
hp_sdc.rqty = 0; hp_sdc.rqty = 0;
tmp = curr->seq[curr->actidx]; tmp = curr->seq[curr->actidx];
curr->seq[curr->actidx] |= HP_SDC_ACT_DEAD; curr->seq[curr->actidx] |= HP_SDC_ACT_DEAD;
if(tmp & HP_SDC_ACT_SEMAPHORE) { if (tmp & HP_SDC_ACT_SEMAPHORE)
if (curr->act.semaphore) if (curr->act.semaphore)
up(curr->act.semaphore); up(curr->act.semaphore);
}
if(tmp & HP_SDC_ACT_CALLBACK) { if (tmp & HP_SDC_ACT_CALLBACK) {
/* Note this means that irqhooks may be called /* Note this means that irqhooks may be called
* in tasklet/bh context. * in tasklet/bh context.
*/ */
if (curr->act.irqhook) if (curr->act.irqhook)
curr->act.irqhook(0, NULL, 0, 0); curr->act.irqhook(0, NULL, 0, 0);
} }
curr->actidx = curr->idx; curr->actidx = curr->idx;
curr->idx++; curr->idx++;
hp_sdc.rcurr = -1; hp_sdc.rcurr = -1;
} }
} }
write_unlock_irq(&hp_sdc.rtq_lock); write_unlock_irq(&hp_sdc.rtq_lock);
hp_sdc_put(); hp_sdc_put();
} }
unsigned long hp_sdc_put(void) { unsigned long hp_sdc_put(void)
{
hp_sdc_transaction *curr; hp_sdc_transaction *curr;
uint8_t act; uint8_t act;
int idx, curridx; int idx, curridx;
...@@ -333,19 +357,24 @@ unsigned long hp_sdc_put(void) { ...@@ -333,19 +357,24 @@ unsigned long hp_sdc_put(void) {
requires output, so we skip to the administrativa. */ requires output, so we skip to the administrativa. */
if (hp_sdc.ibf) { if (hp_sdc.ibf) {
hp_sdc_status_in8(); hp_sdc_status_in8();
if (hp_sdc.ibf) goto finish; if (hp_sdc.ibf)
goto finish;
} }
anew: anew:
/* See if we are in the middle of a sequence. */ /* See if we are in the middle of a sequence. */
if (hp_sdc.wcurr < 0) hp_sdc.wcurr = 0; if (hp_sdc.wcurr < 0)
hp_sdc.wcurr = 0;
read_lock_irq(&hp_sdc.rtq_lock); read_lock_irq(&hp_sdc.rtq_lock);
if (hp_sdc.rcurr == hp_sdc.wcurr) hp_sdc.wcurr++; if (hp_sdc.rcurr == hp_sdc.wcurr)
hp_sdc.wcurr++;
read_unlock_irq(&hp_sdc.rtq_lock); read_unlock_irq(&hp_sdc.rtq_lock);
if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0; if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN)
hp_sdc.wcurr = 0;
curridx = hp_sdc.wcurr; curridx = hp_sdc.wcurr;
if (hp_sdc.tq[curridx] != NULL) goto start; if (hp_sdc.tq[curridx] != NULL)
goto start;
while (++curridx != hp_sdc.wcurr) { while (++curridx != hp_sdc.wcurr) {
if (curridx >= HP_SDC_QUEUE_LEN) { if (curridx >= HP_SDC_QUEUE_LEN) {
...@@ -358,7 +387,8 @@ unsigned long hp_sdc_put(void) { ...@@ -358,7 +387,8 @@ unsigned long hp_sdc_put(void) {
continue; continue;
} }
read_unlock_irq(&hp_sdc.rtq_lock); read_unlock_irq(&hp_sdc.rtq_lock);
if (hp_sdc.tq[curridx] != NULL) break; /* Found one. */ if (hp_sdc.tq[curridx] != NULL)
break; /* Found one. */
} }
if (curridx == hp_sdc.wcurr) { /* There's nothing queued to do. */ if (curridx == hp_sdc.wcurr) { /* There's nothing queued to do. */
curridx = -1; curridx = -1;
...@@ -374,7 +404,8 @@ unsigned long hp_sdc_put(void) { ...@@ -374,7 +404,8 @@ unsigned long hp_sdc_put(void) {
goto finish; goto finish;
} }
if (hp_sdc.wcurr == -1) goto done; if (hp_sdc.wcurr == -1)
goto done;
curr = hp_sdc.tq[curridx]; curr = hp_sdc.tq[curridx];
idx = curr->actidx; idx = curr->actidx;
...@@ -383,20 +414,23 @@ unsigned long hp_sdc_put(void) { ...@@ -383,20 +414,23 @@ unsigned long hp_sdc_put(void) {
hp_sdc.tq[curridx] = NULL; hp_sdc.tq[curridx] = NULL;
/* Interleave outbound data between the transactions. */ /* Interleave outbound data between the transactions. */
hp_sdc.wcurr++; hp_sdc.wcurr++;
if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0; if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN)
goto finish; hp_sdc.wcurr = 0;
goto finish;
} }
act = curr->seq[idx]; act = curr->seq[idx];
idx++; idx++;
if (curr->idx >= curr->endidx) { if (curr->idx >= curr->endidx) {
if (act & HP_SDC_ACT_DEALLOC) kfree(curr); if (act & HP_SDC_ACT_DEALLOC)
kfree(curr);
hp_sdc.tq[curridx] = NULL; hp_sdc.tq[curridx] = NULL;
/* Interleave outbound data between the transactions. */ /* Interleave outbound data between the transactions. */
hp_sdc.wcurr++; hp_sdc.wcurr++;
if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0; if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN)
goto finish; hp_sdc.wcurr = 0;
goto finish;
} }
while (act & HP_SDC_ACT_PRECMD) { while (act & HP_SDC_ACT_PRECMD) {
...@@ -409,9 +443,10 @@ unsigned long hp_sdc_put(void) { ...@@ -409,9 +443,10 @@ unsigned long hp_sdc_put(void) {
curr->idx++; curr->idx++;
/* act finished? */ /* act finished? */
if ((act & HP_SDC_ACT_DURING) == HP_SDC_ACT_PRECMD) if ((act & HP_SDC_ACT_DURING) == HP_SDC_ACT_PRECMD)
goto actdone; goto actdone;
/* skip quantity field if data-out sequence follows. */ /* skip quantity field if data-out sequence follows. */
if (act & HP_SDC_ACT_DATAOUT) curr->idx++; if (act & HP_SDC_ACT_DATAOUT)
curr->idx++;
goto finish; goto finish;
} }
if (act & HP_SDC_ACT_DATAOUT) { if (act & HP_SDC_ACT_DATAOUT) {
...@@ -423,15 +458,15 @@ unsigned long hp_sdc_put(void) { ...@@ -423,15 +458,15 @@ unsigned long hp_sdc_put(void) {
hp_sdc_data_out8(curr->seq[curr->idx]); hp_sdc_data_out8(curr->seq[curr->idx]);
curr->idx++; curr->idx++;
/* act finished? */ /* act finished? */
if ((curr->idx - idx >= qty) && if (curr->idx - idx >= qty &&
((act & HP_SDC_ACT_DURING) == HP_SDC_ACT_DATAOUT)) (act & HP_SDC_ACT_DURING) == HP_SDC_ACT_DATAOUT)
goto actdone; goto actdone;
goto finish; goto finish;
} }
idx += qty; idx += qty;
act &= ~HP_SDC_ACT_DATAOUT; act &= ~HP_SDC_ACT_DATAOUT;
} } else
else while (act & HP_SDC_ACT_DATAREG) { while (act & HP_SDC_ACT_DATAREG) {
int mask; int mask;
uint8_t w7[4]; uint8_t w7[4];
...@@ -445,26 +480,30 @@ unsigned long hp_sdc_put(void) { ...@@ -445,26 +480,30 @@ unsigned long hp_sdc_put(void) {
act &= ~HP_SDC_ACT_DATAREG; act &= ~HP_SDC_ACT_DATAREG;
break; break;
} }
w7[0] = (mask & 1) ? curr->seq[++idx] : hp_sdc.r7[0]; w7[0] = (mask & 1) ? curr->seq[++idx] : hp_sdc.r7[0];
w7[1] = (mask & 2) ? curr->seq[++idx] : hp_sdc.r7[1]; w7[1] = (mask & 2) ? curr->seq[++idx] : hp_sdc.r7[1];
w7[2] = (mask & 4) ? curr->seq[++idx] : hp_sdc.r7[2]; w7[2] = (mask & 4) ? curr->seq[++idx] : hp_sdc.r7[2];
w7[3] = (mask & 8) ? curr->seq[++idx] : hp_sdc.r7[3]; w7[3] = (mask & 8) ? curr->seq[++idx] : hp_sdc.r7[3];
if (hp_sdc.wi > 0x73 || hp_sdc.wi < 0x70 || if (hp_sdc.wi > 0x73 || hp_sdc.wi < 0x70 ||
w7[hp_sdc.wi-0x70] == hp_sdc.r7[hp_sdc.wi-0x70]) { w7[hp_sdc.wi - 0x70] == hp_sdc.r7[hp_sdc.wi - 0x70]) {
int i = 0; int i = 0;
/* Need to point the write index register */ /* Need to point the write index register */
while ((i < 4) && w7[i] == hp_sdc.r7[i]) i++; while (i < 4 && w7[i] == hp_sdc.r7[i])
i++;
if (i < 4) { if (i < 4) {
hp_sdc_status_out8(HP_SDC_CMD_SET_D0 + i); hp_sdc_status_out8(HP_SDC_CMD_SET_D0 + i);
hp_sdc.wi = 0x70 + i; hp_sdc.wi = 0x70 + i;
goto finish; goto finish;
} }
idx++; idx++;
if ((act & HP_SDC_ACT_DURING) == HP_SDC_ACT_DATAREG) if ((act & HP_SDC_ACT_DURING) == HP_SDC_ACT_DATAREG)
goto actdone; goto actdone;
curr->idx = idx; curr->idx = idx;
act &= ~HP_SDC_ACT_DATAREG; act &= ~HP_SDC_ACT_DATAREG;
break; break;
...@@ -476,12 +515,13 @@ unsigned long hp_sdc_put(void) { ...@@ -476,12 +515,13 @@ unsigned long hp_sdc_put(void) {
{ {
int i = 0; int i = 0;
while ((i < 4) && w7[i] == hp_sdc.r7[i]) i++; while ((i < 4) && w7[i] == hp_sdc.r7[i])
i++;
if (i >= 4) { if (i >= 4) {
curr->idx = idx + 1; curr->idx = idx + 1;
if ((act & HP_SDC_ACT_DURING) == if ((act & HP_SDC_ACT_DURING) ==
HP_SDC_ACT_DATAREG) HP_SDC_ACT_DATAREG)
goto actdone; goto actdone;
} }
} }
goto finish; goto finish;
...@@ -497,7 +537,7 @@ unsigned long hp_sdc_put(void) { ...@@ -497,7 +537,7 @@ unsigned long hp_sdc_put(void) {
if (act & HP_SDC_ACT_POSTCMD) { if (act & HP_SDC_ACT_POSTCMD) {
uint8_t postcmd; uint8_t postcmd;
/* curr->idx should == idx at this point. */ /* curr->idx should == idx at this point. */
postcmd = curr->seq[idx]; postcmd = curr->seq[idx];
...@@ -505,12 +545,12 @@ unsigned long hp_sdc_put(void) { ...@@ -505,12 +545,12 @@ unsigned long hp_sdc_put(void) {
if (act & HP_SDC_ACT_DATAIN) { if (act & HP_SDC_ACT_DATAIN) {
/* Start a new read */ /* Start a new read */
hp_sdc.rqty = curr->seq[curr->idx]; hp_sdc.rqty = curr->seq[curr->idx];
do_gettimeofday(&hp_sdc.rtv); do_gettimeofday(&hp_sdc.rtv);
curr->idx++; curr->idx++;
/* Still need to lock here in case of spurious irq. */ /* Still need to lock here in case of spurious irq. */
write_lock_irq(&hp_sdc.rtq_lock); write_lock_irq(&hp_sdc.rtq_lock);
hp_sdc.rcurr = curridx; hp_sdc.rcurr = curridx;
write_unlock_irq(&hp_sdc.rtq_lock); write_unlock_irq(&hp_sdc.rtq_lock);
hp_sdc_status_out8(postcmd); hp_sdc_status_out8(postcmd);
goto finish; goto finish;
...@@ -519,64 +559,69 @@ unsigned long hp_sdc_put(void) { ...@@ -519,64 +559,69 @@ unsigned long hp_sdc_put(void) {
goto actdone; goto actdone;
} }
actdone: actdone:
if (act & HP_SDC_ACT_SEMAPHORE) { if (act & HP_SDC_ACT_SEMAPHORE)
up(curr->act.semaphore); up(curr->act.semaphore);
} else if (act & HP_SDC_ACT_CALLBACK)
else if (act & HP_SDC_ACT_CALLBACK) {
curr->act.irqhook(0,NULL,0,0); curr->act.irqhook(0,NULL,0,0);
}
if (curr->idx >= curr->endidx) { /* This transaction is over. */ if (curr->idx >= curr->endidx) { /* This transaction is over. */
if (act & HP_SDC_ACT_DEALLOC) kfree(curr); if (act & HP_SDC_ACT_DEALLOC)
kfree(curr);
hp_sdc.tq[curridx] = NULL; hp_sdc.tq[curridx] = NULL;
} } else {
else {
curr->actidx = idx + 1; curr->actidx = idx + 1;
curr->idx = idx + 2; curr->idx = idx + 2;
} }
/* Interleave outbound data between the transactions. */ /* Interleave outbound data between the transactions. */
hp_sdc.wcurr++; hp_sdc.wcurr++;
if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0; if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN)
hp_sdc.wcurr = 0;
finish: finish:
/* If by some quirk IBF has cleared and our ISR has run to /* If by some quirk IBF has cleared and our ISR has run to
see that that has happened, do it all again. */ see that that has happened, do it all again. */
if (!hp_sdc.ibf && limit++ < 20) goto anew; if (!hp_sdc.ibf && limit++ < 20)
goto anew;
done: done:
if (hp_sdc.wcurr >= 0) tasklet_schedule(&hp_sdc.task); if (hp_sdc.wcurr >= 0)
tasklet_schedule(&hp_sdc.task);
write_unlock(&hp_sdc.lock); write_unlock(&hp_sdc.lock);
return 0; return 0;
} }
/******* Functions called in either user or kernel context ****/ /******* Functions called in either user or kernel context ****/
int hp_sdc_enqueue_transaction(hp_sdc_transaction *this) { int hp_sdc_enqueue_transaction(hp_sdc_transaction *this)
{
unsigned long flags; unsigned long flags;
int i; int i;
if (this == NULL) { if (this == NULL) {
tasklet_schedule(&hp_sdc.task); tasklet_schedule(&hp_sdc.task);
return -EINVAL; return -EINVAL;
}; }
write_lock_irqsave(&hp_sdc.lock, flags); write_lock_irqsave(&hp_sdc.lock, flags);
/* Can't have same transaction on queue twice */ /* Can't have same transaction on queue twice */
for (i=0; i < HP_SDC_QUEUE_LEN; i++) for (i = 0; i < HP_SDC_QUEUE_LEN; i++)
if (hp_sdc.tq[i] == this) goto fail; if (hp_sdc.tq[i] == this)
goto fail;
this->actidx = 0; this->actidx = 0;
this->idx = 1; this->idx = 1;
/* Search for empty slot */ /* Search for empty slot */
for (i=0; i < HP_SDC_QUEUE_LEN; i++) { for (i = 0; i < HP_SDC_QUEUE_LEN; i++)
if (hp_sdc.tq[i] == NULL) { if (hp_sdc.tq[i] == NULL) {
hp_sdc.tq[i] = this; hp_sdc.tq[i] = this;
write_unlock_irqrestore(&hp_sdc.lock, flags); write_unlock_irqrestore(&hp_sdc.lock, flags);
tasklet_schedule(&hp_sdc.task); tasklet_schedule(&hp_sdc.task);
return 0; return 0;
} }
}
write_unlock_irqrestore(&hp_sdc.lock, flags); write_unlock_irqrestore(&hp_sdc.lock, flags);
printk(KERN_WARNING PREFIX "No free slot to add transaction.\n"); printk(KERN_WARNING PREFIX "No free slot to add transaction.\n");
return -EBUSY; return -EBUSY;
...@@ -587,7 +632,8 @@ int hp_sdc_enqueue_transaction(hp_sdc_transaction *this) { ...@@ -587,7 +632,8 @@ int hp_sdc_enqueue_transaction(hp_sdc_transaction *this) {
return -EINVAL; return -EINVAL;
} }
int hp_sdc_dequeue_transaction(hp_sdc_transaction *this) { int hp_sdc_dequeue_transaction(hp_sdc_transaction *this)
{
unsigned long flags; unsigned long flags;
int i; int i;
...@@ -595,8 +641,9 @@ int hp_sdc_dequeue_transaction(hp_sdc_transaction *this) { ...@@ -595,8 +641,9 @@ int hp_sdc_dequeue_transaction(hp_sdc_transaction *this) {
/* TODO: don't remove it if it's not done. */ /* TODO: don't remove it if it's not done. */
for (i=0; i < HP_SDC_QUEUE_LEN; i++) for (i = 0; i < HP_SDC_QUEUE_LEN; i++)
if (hp_sdc.tq[i] == this) hp_sdc.tq[i] = NULL; if (hp_sdc.tq[i] == this)
hp_sdc.tq[i] = NULL;
write_unlock_irqrestore(&hp_sdc.lock, flags); write_unlock_irqrestore(&hp_sdc.lock, flags);
return 0; return 0;
...@@ -605,11 +652,11 @@ int hp_sdc_dequeue_transaction(hp_sdc_transaction *this) { ...@@ -605,11 +652,11 @@ int hp_sdc_dequeue_transaction(hp_sdc_transaction *this) {
/********************** User context functions **************************/ /********************** User context functions **************************/
int hp_sdc_request_timer_irq(hp_sdc_irqhook *callback) { int hp_sdc_request_timer_irq(hp_sdc_irqhook *callback)
{
if (callback == NULL || hp_sdc.dev == NULL) { if (callback == NULL || hp_sdc.dev == NULL)
return -EINVAL; return -EINVAL;
}
write_lock_irq(&hp_sdc.hook_lock); write_lock_irq(&hp_sdc.hook_lock);
if (hp_sdc.timer != NULL) { if (hp_sdc.timer != NULL) {
write_unlock_irq(&hp_sdc.hook_lock); write_unlock_irq(&hp_sdc.hook_lock);
...@@ -629,11 +676,11 @@ int hp_sdc_request_timer_irq(hp_sdc_irqhook *callback) { ...@@ -629,11 +676,11 @@ int hp_sdc_request_timer_irq(hp_sdc_irqhook *callback) {
return 0; return 0;
} }
int hp_sdc_request_hil_irq(hp_sdc_irqhook *callback) { int hp_sdc_request_hil_irq(hp_sdc_irqhook *callback)
{
if (callback == NULL || hp_sdc.dev == NULL) { if (callback == NULL || hp_sdc.dev == NULL)
return -EINVAL; return -EINVAL;
}
write_lock_irq(&hp_sdc.hook_lock); write_lock_irq(&hp_sdc.hook_lock);
if (hp_sdc.hil != NULL) { if (hp_sdc.hil != NULL) {
write_unlock_irq(&hp_sdc.hook_lock); write_unlock_irq(&hp_sdc.hook_lock);
...@@ -650,11 +697,11 @@ int hp_sdc_request_hil_irq(hp_sdc_irqhook *callback) { ...@@ -650,11 +697,11 @@ int hp_sdc_request_hil_irq(hp_sdc_irqhook *callback) {
return 0; return 0;
} }
int hp_sdc_request_cooked_irq(hp_sdc_irqhook *callback) { int hp_sdc_request_cooked_irq(hp_sdc_irqhook *callback)
{
if (callback == NULL || hp_sdc.dev == NULL) { if (callback == NULL || hp_sdc.dev == NULL)
return -EINVAL; return -EINVAL;
}
write_lock_irq(&hp_sdc.hook_lock); write_lock_irq(&hp_sdc.hook_lock);
if (hp_sdc.cooked != NULL) { if (hp_sdc.cooked != NULL) {
write_unlock_irq(&hp_sdc.hook_lock); write_unlock_irq(&hp_sdc.hook_lock);
...@@ -672,9 +719,8 @@ int hp_sdc_request_cooked_irq(hp_sdc_irqhook *callback) { ...@@ -672,9 +719,8 @@ int hp_sdc_request_cooked_irq(hp_sdc_irqhook *callback) {
return 0; return 0;
} }
int hp_sdc_release_timer_irq(hp_sdc_irqhook *callback) { int hp_sdc_release_timer_irq(hp_sdc_irqhook *callback)
{
write_lock_irq(&hp_sdc.hook_lock); write_lock_irq(&hp_sdc.hook_lock);
if ((callback != hp_sdc.timer) || if ((callback != hp_sdc.timer) ||
(hp_sdc.timer == NULL)) { (hp_sdc.timer == NULL)) {
...@@ -694,8 +740,8 @@ int hp_sdc_release_timer_irq(hp_sdc_irqhook *callback) { ...@@ -694,8 +740,8 @@ int hp_sdc_release_timer_irq(hp_sdc_irqhook *callback) {
return 0; return 0;
} }
int hp_sdc_release_hil_irq(hp_sdc_irqhook *callback) { int hp_sdc_release_hil_irq(hp_sdc_irqhook *callback)
{
write_lock_irq(&hp_sdc.hook_lock); write_lock_irq(&hp_sdc.hook_lock);
if ((callback != hp_sdc.hil) || if ((callback != hp_sdc.hil) ||
(hp_sdc.hil == NULL)) { (hp_sdc.hil == NULL)) {
...@@ -715,8 +761,8 @@ int hp_sdc_release_hil_irq(hp_sdc_irqhook *callback) { ...@@ -715,8 +761,8 @@ int hp_sdc_release_hil_irq(hp_sdc_irqhook *callback) {
return 0; return 0;
} }
int hp_sdc_release_cooked_irq(hp_sdc_irqhook *callback) { int hp_sdc_release_cooked_irq(hp_sdc_irqhook *callback)
{
write_lock_irq(&hp_sdc.hook_lock); write_lock_irq(&hp_sdc.hook_lock);
if ((callback != hp_sdc.cooked) || if ((callback != hp_sdc.cooked) ||
(hp_sdc.cooked == NULL)) { (hp_sdc.cooked == NULL)) {
...@@ -738,7 +784,8 @@ int hp_sdc_release_cooked_irq(hp_sdc_irqhook *callback) { ...@@ -738,7 +784,8 @@ int hp_sdc_release_cooked_irq(hp_sdc_irqhook *callback) {
/************************* Keepalive timer task *********************/ /************************* Keepalive timer task *********************/
void hp_sdc_kicker (unsigned long data) { void hp_sdc_kicker (unsigned long data)
{
tasklet_schedule(&hp_sdc.task); tasklet_schedule(&hp_sdc.task);
/* Re-insert the periodic task. */ /* Re-insert the periodic task. */
mod_timer(&hp_sdc.kicker, jiffies + HZ); mod_timer(&hp_sdc.kicker, jiffies + HZ);
...@@ -750,10 +797,10 @@ void hp_sdc_kicker (unsigned long data) { ...@@ -750,10 +797,10 @@ void hp_sdc_kicker (unsigned long data) {
static const struct parisc_device_id hp_sdc_tbl[] = { static const struct parisc_device_id hp_sdc_tbl[] = {
{ {
.hw_type = HPHW_FIO, .hw_type = HPHW_FIO,
.hversion_rev = HVERSION_REV_ANY_ID, .hversion_rev = HVERSION_REV_ANY_ID,
.hversion = HVERSION_ANY_ID, .hversion = HVERSION_ANY_ID,
.sversion = 0x73, .sversion = 0x73,
}, },
{ 0, } { 0, }
}; };
...@@ -772,16 +819,15 @@ static struct parisc_driver hp_sdc_driver = { ...@@ -772,16 +819,15 @@ static struct parisc_driver hp_sdc_driver = {
static int __init hp_sdc_init(void) static int __init hp_sdc_init(void)
{ {
int i;
char *errstr; char *errstr;
hp_sdc_transaction t_sync; hp_sdc_transaction t_sync;
uint8_t ts_sync[6]; uint8_t ts_sync[6];
struct semaphore s_sync; struct semaphore s_sync;
rwlock_init(&hp_sdc.lock); rwlock_init(&hp_sdc.lock);
rwlock_init(&hp_sdc.ibf_lock); rwlock_init(&hp_sdc.ibf_lock);
rwlock_init(&hp_sdc.rtq_lock); rwlock_init(&hp_sdc.rtq_lock);
rwlock_init(&hp_sdc.hook_lock); rwlock_init(&hp_sdc.hook_lock);
hp_sdc.timer = NULL; hp_sdc.timer = NULL;
hp_sdc.hil = NULL; hp_sdc.hil = NULL;
...@@ -796,7 +842,8 @@ static int __init hp_sdc_init(void) ...@@ -796,7 +842,8 @@ static int __init hp_sdc_init(void)
hp_sdc.r7[3] = 0xff; hp_sdc.r7[3] = 0xff;
hp_sdc.ibf = 1; hp_sdc.ibf = 1;
for (i = 0; i < HP_SDC_QUEUE_LEN; i++) hp_sdc.tq[i] = NULL; memset(&hp_sdc.tq, 0, sizeof(hp_sdc.tq));
hp_sdc.wcurr = -1; hp_sdc.wcurr = -1;
hp_sdc.rcurr = -1; hp_sdc.rcurr = -1;
hp_sdc.rqty = 0; hp_sdc.rqty = 0;
...@@ -804,27 +851,32 @@ static int __init hp_sdc_init(void) ...@@ -804,27 +851,32 @@ static int __init hp_sdc_init(void)
hp_sdc.dev_err = -ENODEV; hp_sdc.dev_err = -ENODEV;
errstr = "IO not found for"; errstr = "IO not found for";
if (!hp_sdc.base_io) goto err0; if (!hp_sdc.base_io)
goto err0;
errstr = "IRQ not found for"; errstr = "IRQ not found for";
if (!hp_sdc.irq) goto err0; if (!hp_sdc.irq)
goto err0;
hp_sdc.dev_err = -EBUSY; hp_sdc.dev_err = -EBUSY;
#if defined(__hppa__) #if defined(__hppa__)
errstr = "IO not available for"; errstr = "IO not available for";
if (request_region(hp_sdc.data_io, 2, hp_sdc_driver.name)) goto err0; if (request_region(hp_sdc.data_io, 2, hp_sdc_driver.name))
#endif goto err0;
#endif
errstr = "IRQ not available for"; errstr = "IRQ not available for";
if (request_irq(hp_sdc.irq, &hp_sdc_isr, IRQF_SHARED|IRQF_SAMPLE_RANDOM, if (request_irq(hp_sdc.irq, &hp_sdc_isr, IRQF_SHARED|IRQF_SAMPLE_RANDOM,
"HP SDC", &hp_sdc)) goto err1; "HP SDC", &hp_sdc))
goto err1;
errstr = "NMI not available for"; errstr = "NMI not available for";
if (request_irq(hp_sdc.nmi, &hp_sdc_nmisr, IRQF_SHARED, if (request_irq(hp_sdc.nmi, &hp_sdc_nmisr, IRQF_SHARED,
"HP SDC NMI", &hp_sdc)) goto err2; "HP SDC NMI", &hp_sdc))
goto err2;
printk(KERN_INFO PREFIX "HP SDC at 0x%p, IRQ %d (NMI IRQ %d)\n", 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); (void *)hp_sdc.base_io, hp_sdc.irq, hp_sdc.nmi);
hp_sdc_status_in8(); hp_sdc_status_in8();
...@@ -858,9 +910,10 @@ static int __init hp_sdc_init(void) ...@@ -858,9 +910,10 @@ static int __init hp_sdc_init(void)
err1: err1:
release_region(hp_sdc.data_io, 2); release_region(hp_sdc.data_io, 2);
err0: err0:
printk(KERN_WARNING PREFIX ": %s SDC IO=0x%p IRQ=0x%x NMI=0x%x\n", 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); errstr, (void *)hp_sdc.base_io, hp_sdc.irq, hp_sdc.nmi);
hp_sdc.dev = NULL; hp_sdc.dev = NULL;
return hp_sdc.dev_err; return hp_sdc.dev_err;
} }
...@@ -868,8 +921,10 @@ static int __init hp_sdc_init(void) ...@@ -868,8 +921,10 @@ static int __init hp_sdc_init(void)
static int __init hp_sdc_init_hppa(struct parisc_device *d) static int __init hp_sdc_init_hppa(struct parisc_device *d)
{ {
if (!d) return 1; if (!d)
if (hp_sdc.dev != NULL) return 1; /* We only expect one SDC */ return 1;
if (hp_sdc.dev != NULL)
return 1; /* We only expect one SDC */
hp_sdc.dev = d; hp_sdc.dev = d;
hp_sdc.irq = d->irq; hp_sdc.irq = d->irq;
...@@ -906,10 +961,8 @@ static void hp_sdc_exit(void) ...@@ -906,10 +961,8 @@ static void hp_sdc_exit(void)
tasklet_kill(&hp_sdc.task); tasklet_kill(&hp_sdc.task);
/* release_region(hp_sdc.data_io, 2); */
#if defined(__hppa__) #if defined(__hppa__)
if (unregister_parisc_driver(&hp_sdc_driver)) if (unregister_parisc_driver(&hp_sdc_driver))
printk(KERN_WARNING PREFIX "Error unregistering HP SDC"); printk(KERN_WARNING PREFIX "Error unregistering HP SDC");
#endif #endif
} }
...@@ -923,7 +976,7 @@ static int __init hp_sdc_register(void) ...@@ -923,7 +976,7 @@ static int __init hp_sdc_register(void)
mm_segment_t fs; mm_segment_t fs;
unsigned char i; unsigned char i;
#endif #endif
hp_sdc.dev = NULL; hp_sdc.dev = NULL;
hp_sdc.dev_err = 0; hp_sdc.dev_err = 0;
#if defined(__hppa__) #if defined(__hppa__)
...@@ -960,8 +1013,8 @@ static int __init hp_sdc_register(void) ...@@ -960,8 +1013,8 @@ static int __init hp_sdc_register(void)
tq_init.seq = tq_init_seq; tq_init.seq = tq_init_seq;
tq_init.act.semaphore = &tq_init_sem; tq_init.act.semaphore = &tq_init_sem;
tq_init_seq[0] = tq_init_seq[0] =
HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN | HP_SDC_ACT_SEMAPHORE; HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN | HP_SDC_ACT_SEMAPHORE;
tq_init_seq[1] = HP_SDC_CMD_READ_KCC; tq_init_seq[1] = HP_SDC_CMD_READ_KCC;
tq_init_seq[2] = 1; tq_init_seq[2] = 1;
tq_init_seq[3] = 0; tq_init_seq[3] = 0;
...@@ -979,13 +1032,13 @@ static int __init hp_sdc_register(void) ...@@ -979,13 +1032,13 @@ static int __init hp_sdc_register(void)
} }
hp_sdc.r11 = tq_init_seq[4]; hp_sdc.r11 = tq_init_seq[4];
if (hp_sdc.r11 & HP_SDC_CFG_NEW) { if (hp_sdc.r11 & HP_SDC_CFG_NEW) {
char *str; const char *str;
printk(KERN_INFO PREFIX "New style SDC\n"); printk(KERN_INFO PREFIX "New style SDC\n");
tq_init_seq[1] = HP_SDC_CMD_READ_XTD; tq_init_seq[1] = HP_SDC_CMD_READ_XTD;
tq_init.actidx = 0; tq_init.actidx = 0;
tq_init.idx = 1; tq_init.idx = 1;
down(&tq_init_sem); down(&tq_init_sem);
hp_sdc_enqueue_transaction(&tq_init); hp_sdc_enqueue_transaction(&tq_init);
down(&tq_init_sem); down(&tq_init_sem);
up(&tq_init_sem); up(&tq_init_sem);
if ((tq_init_seq[0] & HP_SDC_ACT_DEAD) == HP_SDC_ACT_DEAD) { if ((tq_init_seq[0] & HP_SDC_ACT_DEAD) == HP_SDC_ACT_DEAD) {
...@@ -995,15 +1048,13 @@ static int __init hp_sdc_register(void) ...@@ -995,15 +1048,13 @@ static int __init hp_sdc_register(void)
hp_sdc.r7e = tq_init_seq[4]; hp_sdc.r7e = tq_init_seq[4];
HP_SDC_XTD_REV_STRINGS(hp_sdc.r7e & HP_SDC_XTD_REV, str) HP_SDC_XTD_REV_STRINGS(hp_sdc.r7e & HP_SDC_XTD_REV, str)
printk(KERN_INFO PREFIX "Revision: %s\n", str); printk(KERN_INFO PREFIX "Revision: %s\n", str);
if (hp_sdc.r7e & HP_SDC_XTD_BEEPER) { if (hp_sdc.r7e & HP_SDC_XTD_BEEPER)
printk(KERN_INFO PREFIX "TI SN76494 beeper present\n"); printk(KERN_INFO PREFIX "TI SN76494 beeper present\n");
} if (hp_sdc.r7e & HP_SDC_XTD_BBRTC)
if (hp_sdc.r7e & HP_SDC_XTD_BBRTC) {
printk(KERN_INFO PREFIX "OKI MSM-58321 BBRTC present\n"); printk(KERN_INFO PREFIX "OKI MSM-58321 BBRTC present\n");
}
printk(KERN_INFO PREFIX "Spunking the self test register to force PUP " printk(KERN_INFO PREFIX "Spunking the self test register to force PUP "
"on next firmware reset.\n"); "on next firmware reset.\n");
tq_init_seq[0] = HP_SDC_ACT_PRECMD | tq_init_seq[0] = HP_SDC_ACT_PRECMD |
HP_SDC_ACT_DATAOUT | HP_SDC_ACT_SEMAPHORE; HP_SDC_ACT_DATAOUT | HP_SDC_ACT_SEMAPHORE;
tq_init_seq[1] = HP_SDC_CMD_SET_STR; tq_init_seq[1] = HP_SDC_CMD_SET_STR;
tq_init_seq[2] = 1; tq_init_seq[2] = 1;
...@@ -1012,14 +1063,12 @@ static int __init hp_sdc_register(void) ...@@ -1012,14 +1063,12 @@ static int __init hp_sdc_register(void)
tq_init.idx = 1; tq_init.idx = 1;
tq_init.endidx = 4; tq_init.endidx = 4;
down(&tq_init_sem); down(&tq_init_sem);
hp_sdc_enqueue_transaction(&tq_init); hp_sdc_enqueue_transaction(&tq_init);
down(&tq_init_sem); down(&tq_init_sem);
up(&tq_init_sem); up(&tq_init_sem);
} } else
else { printk(KERN_INFO PREFIX "Old style SDC (1820-%s).\n",
printk(KERN_INFO PREFIX "Old style SDC (1820-%s).\n",
(hp_sdc.r11 & HP_SDC_CFG_REV) ? "3300" : "2564/3087"); (hp_sdc.r11 & HP_SDC_CFG_REV) ? "3300" : "2564/3087");
}
return 0; return 0;
} }
...@@ -1027,13 +1076,13 @@ static int __init hp_sdc_register(void) ...@@ -1027,13 +1076,13 @@ static int __init hp_sdc_register(void)
module_init(hp_sdc_register); module_init(hp_sdc_register);
module_exit(hp_sdc_exit); module_exit(hp_sdc_exit);
/* Timing notes: These measurements taken on my 64MHz 7100-LC (715/64) /* Timing notes: These measurements taken on my 64MHz 7100-LC (715/64)
* cycles cycles-adj time * cycles cycles-adj time
* between two consecutive mfctl(16)'s: 4 n/a 63ns * between two consecutive mfctl(16)'s: 4 n/a 63ns
* hp_sdc_spin_ibf when idle: 119 115 1.7us * hp_sdc_spin_ibf when idle: 119 115 1.7us
* gsc_writeb status register: 83 79 1.2us * gsc_writeb status register: 83 79 1.2us
* IBF to clear after sending SET_IM: 6204 6006 93us * 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 LOAD_RT: 4467 4352 68us
* IBF to clear after sending two LOAD_RTs: 18974 18859 295us * IBF to clear after sending two LOAD_RTs: 18974 18859 295us
* READ_T1, read status/data, IRQ, call handler: 35564 n/a 556us * 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 * cmd to ~IBF READ_T1 2nd time right after: 5158403 n/a 81ms
......
...@@ -58,12 +58,13 @@ struct hp_sdc_mlc_priv_s { ...@@ -58,12 +58,13 @@ struct hp_sdc_mlc_priv_s {
} hp_sdc_mlc_priv; } hp_sdc_mlc_priv;
/************************* Interrupt context ******************************/ /************************* Interrupt context ******************************/
static void hp_sdc_mlc_isr (int irq, void *dev_id, static void hp_sdc_mlc_isr (int irq, void *dev_id,
uint8_t status, uint8_t data) { uint8_t status, uint8_t data)
int idx; {
int idx;
hil_mlc *mlc = &hp_sdc_mlc; hil_mlc *mlc = &hp_sdc_mlc;
write_lock(&(mlc->lock)); write_lock(&mlc->lock);
if (mlc->icount < 0) { if (mlc->icount < 0) {
printk(KERN_WARNING PREFIX "HIL Overflow!\n"); printk(KERN_WARNING PREFIX "HIL Overflow!\n");
up(&mlc->isem); up(&mlc->isem);
...@@ -73,239 +74,247 @@ static void hp_sdc_mlc_isr (int irq, void *dev_id, ...@@ -73,239 +74,247 @@ static void hp_sdc_mlc_isr (int irq, void *dev_id,
if ((status & HP_SDC_STATUS_IRQMASK) == HP_SDC_STATUS_HILDATA) { if ((status & HP_SDC_STATUS_IRQMASK) == HP_SDC_STATUS_HILDATA) {
mlc->ipacket[idx] |= data | HIL_ERR_INT; mlc->ipacket[idx] |= data | HIL_ERR_INT;
mlc->icount--; mlc->icount--;
if (hp_sdc_mlc_priv.got5x) goto check; if (hp_sdc_mlc_priv.got5x || !idx)
if (!idx) goto check; goto check;
if ((mlc->ipacket[idx-1] & HIL_PKT_ADDR_MASK) != 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] &= ~HIL_PKT_ADDR_MASK; mlc->ipacket[idx] &= ~HIL_PKT_ADDR_MASK;
mlc->ipacket[idx] |= (mlc->ipacket[idx-1] mlc->ipacket[idx] |= (mlc->ipacket[idx - 1]
& HIL_PKT_ADDR_MASK); & HIL_PKT_ADDR_MASK);
} }
goto check; goto check;
} }
/* We know status is 5X */ /* We know status is 5X */
if (data & HP_SDC_HIL_ISERR) goto err; if (data & HP_SDC_HIL_ISERR)
mlc->ipacket[idx] = goto err;
mlc->ipacket[idx] =
(data & HP_SDC_HIL_R1MASK) << HIL_PKT_ADDR_SHIFT; (data & HP_SDC_HIL_R1MASK) << HIL_PKT_ADDR_SHIFT;
hp_sdc_mlc_priv.got5x = 1; hp_sdc_mlc_priv.got5x = 1;
goto out; goto out;
check: check:
hp_sdc_mlc_priv.got5x = 0; hp_sdc_mlc_priv.got5x = 0;
if (mlc->imatch == 0) goto done; if (mlc->imatch == 0)
if ((mlc->imatch == (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL)) goto done;
&& (mlc->ipacket[idx] == (mlc->imatch | idx))) goto done; if ((mlc->imatch == (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL))
if (mlc->ipacket[idx] == mlc->imatch) goto done; && (mlc->ipacket[idx] == (mlc->imatch | idx)))
goto done;
if (mlc->ipacket[idx] == mlc->imatch)
goto done;
goto out; goto out;
err: err:
printk(KERN_DEBUG PREFIX "err code %x\n", data); printk(KERN_DEBUG PREFIX "err code %x\n", data);
switch (data) { switch (data) {
case HP_SDC_HIL_RC_DONE: case HP_SDC_HIL_RC_DONE:
printk(KERN_WARNING PREFIX "Bastard SDC reconfigured loop!\n"); printk(KERN_WARNING PREFIX "Bastard SDC reconfigured loop!\n");
break; break;
case HP_SDC_HIL_ERR: case HP_SDC_HIL_ERR:
mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_PERR | mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_PERR |
HIL_ERR_FERR | HIL_ERR_FOF; HIL_ERR_FERR | HIL_ERR_FOF;
break; break;
case HP_SDC_HIL_TO: case HP_SDC_HIL_TO:
mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_LERR; mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_LERR;
break; break;
case HP_SDC_HIL_RC: case HP_SDC_HIL_RC:
printk(KERN_WARNING PREFIX "Bastard SDC decided to reconfigure loop!\n"); printk(KERN_WARNING PREFIX "Bastard SDC decided to reconfigure loop!\n");
break; break;
default: default:
printk(KERN_WARNING PREFIX "Unkown HIL Error status (%x)!\n", data); printk(KERN_WARNING PREFIX "Unkown HIL Error status (%x)!\n", data);
break; break;
} }
/* No more data will be coming due to an error. */ /* No more data will be coming due to an error. */
done: done:
tasklet_schedule(mlc->tasklet); tasklet_schedule(mlc->tasklet);
up(&(mlc->isem)); up(&mlc->isem);
out: out:
write_unlock(&(mlc->lock)); write_unlock(&mlc->lock);
} }
/******************** Tasklet or userspace context functions ****************/ /******************** Tasklet or userspace context functions ****************/
static int hp_sdc_mlc_in (hil_mlc *mlc, suseconds_t timeout) { static int hp_sdc_mlc_in(hil_mlc *mlc, suseconds_t timeout)
{
unsigned long flags; unsigned long flags;
struct hp_sdc_mlc_priv_s *priv; struct hp_sdc_mlc_priv_s *priv;
int rc = 2; int rc = 2;
priv = mlc->priv; priv = mlc->priv;
write_lock_irqsave(&(mlc->lock), flags); write_lock_irqsave(&mlc->lock, flags);
/* Try to down the semaphore */ /* Try to down the semaphore */
if (down_trylock(&(mlc->isem))) { if (down_trylock(&mlc->isem)) {
struct timeval tv; struct timeval tv;
if (priv->emtestmode) { if (priv->emtestmode) {
mlc->ipacket[0] = mlc->ipacket[0] =
HIL_ERR_INT | (mlc->opacket & HIL_ERR_INT | (mlc->opacket &
(HIL_PKT_CMD | (HIL_PKT_CMD |
HIL_PKT_ADDR_MASK | HIL_PKT_ADDR_MASK |
HIL_PKT_DATA_MASK)); HIL_PKT_DATA_MASK));
mlc->icount = 14; mlc->icount = 14;
/* printk(KERN_DEBUG PREFIX ">[%x]\n", mlc->ipacket[0]); */ /* printk(KERN_DEBUG PREFIX ">[%x]\n", mlc->ipacket[0]); */
goto wasup; goto wasup;
} }
do_gettimeofday(&tv); do_gettimeofday(&tv);
tv.tv_usec += 1000000 * (tv.tv_sec - mlc->instart.tv_sec); tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec);
if (tv.tv_usec - mlc->instart.tv_usec > mlc->intimeout) { if (tv.tv_usec - mlc->instart.tv_usec > mlc->intimeout) {
/* printk("!%i %i", /* printk("!%i %i",
tv.tv_usec - mlc->instart.tv_usec, tv.tv_usec - mlc->instart.tv_usec,
mlc->intimeout); mlc->intimeout);
*/ */
rc = 1; rc = 1;
up(&(mlc->isem)); up(&mlc->isem);
} }
goto done; goto done;
} }
wasup: wasup:
up(&(mlc->isem)); up(&mlc->isem);
rc = 0; rc = 0;
goto done; goto done;
done: done:
write_unlock_irqrestore(&(mlc->lock), flags); write_unlock_irqrestore(&mlc->lock, flags);
return rc; return rc;
} }
static int hp_sdc_mlc_cts (hil_mlc *mlc) { static int hp_sdc_mlc_cts(hil_mlc *mlc)
{
struct hp_sdc_mlc_priv_s *priv; struct hp_sdc_mlc_priv_s *priv;
unsigned long flags; unsigned long flags;
priv = mlc->priv; priv = mlc->priv;
write_lock_irqsave(&(mlc->lock), flags); write_lock_irqsave(&mlc->lock, flags);
/* Try to down the semaphores -- they should be up. */ /* Try to down the semaphores -- they should be up. */
if (down_trylock(&(mlc->isem))) { BUG_ON(down_trylock(&mlc->isem));
BUG(); BUG_ON(down_trylock(&mlc->osem));
goto busy;
}
if (down_trylock(&(mlc->osem))) {
BUG();
up(&(mlc->isem));
goto busy;
}
up(&(mlc->isem));
up(&(mlc->osem));
if (down_trylock(&(mlc->csem))) { up(&mlc->isem);
if (priv->trans.act.semaphore != &(mlc->csem)) goto poll; up(&mlc->osem);
goto busy;
if (down_trylock(&mlc->csem)) {
if (priv->trans.act.semaphore != &mlc->csem)
goto poll;
else
goto busy;
} }
if (!(priv->tseq[4] & HP_SDC_USE_LOOP)) goto done;
if (!(priv->tseq[4] & HP_SDC_USE_LOOP))
goto done;
poll: poll:
priv->trans.act.semaphore = &(mlc->csem); priv->trans.act.semaphore = &mlc->csem;
priv->trans.actidx = 0; priv->trans.actidx = 0;
priv->trans.idx = 1; priv->trans.idx = 1;
priv->trans.endidx = 5; priv->trans.endidx = 5;
priv->tseq[0] = priv->tseq[0] =
HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN | HP_SDC_ACT_SEMAPHORE; HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN | HP_SDC_ACT_SEMAPHORE;
priv->tseq[1] = HP_SDC_CMD_READ_USE; priv->tseq[1] = HP_SDC_CMD_READ_USE;
priv->tseq[2] = 1; priv->tseq[2] = 1;
priv->tseq[3] = 0; priv->tseq[3] = 0;
priv->tseq[4] = 0; priv->tseq[4] = 0;
hp_sdc_enqueue_transaction(&(priv->trans)); hp_sdc_enqueue_transaction(&priv->trans);
busy: busy:
write_unlock_irqrestore(&(mlc->lock), flags); write_unlock_irqrestore(&mlc->lock, flags);
return 1; return 1;
done: done:
priv->trans.act.semaphore = &(mlc->osem); priv->trans.act.semaphore = &mlc->osem;
up(&(mlc->csem)); up(&mlc->csem);
write_unlock_irqrestore(&(mlc->lock), flags); write_unlock_irqrestore(&mlc->lock, flags);
return 0; return 0;
} }
static void hp_sdc_mlc_out (hil_mlc *mlc) { static void hp_sdc_mlc_out(hil_mlc *mlc)
{
struct hp_sdc_mlc_priv_s *priv; struct hp_sdc_mlc_priv_s *priv;
unsigned long flags; unsigned long flags;
priv = mlc->priv; priv = mlc->priv;
write_lock_irqsave(&(mlc->lock), flags); write_lock_irqsave(&mlc->lock, flags);
/* Try to down the semaphore -- it should be up. */ /* Try to down the semaphore -- it should be up. */
if (down_trylock(&(mlc->osem))) { BUG_ON(down_trylock(&mlc->osem));
BUG();
goto done;
}
if (mlc->opacket & HIL_DO_ALTER_CTRL) goto do_control; if (mlc->opacket & HIL_DO_ALTER_CTRL)
goto do_control;
do_data: do_data:
if (priv->emtestmode) { if (priv->emtestmode) {
up(&(mlc->osem)); up(&mlc->osem);
goto done; goto done;
} }
/* Shouldn't be sending commands when loop may be busy */ /* Shouldn't be sending commands when loop may be busy */
if (down_trylock(&(mlc->csem))) { BUG_ON(down_trylock(&mlc->csem));
BUG(); up(&mlc->csem);
goto done;
}
up(&(mlc->csem));
priv->trans.actidx = 0; priv->trans.actidx = 0;
priv->trans.idx = 1; priv->trans.idx = 1;
priv->trans.act.semaphore = &(mlc->osem); priv->trans.act.semaphore = &mlc->osem;
priv->trans.endidx = 6; priv->trans.endidx = 6;
priv->tseq[0] = priv->tseq[0] =
HP_SDC_ACT_DATAREG | HP_SDC_ACT_POSTCMD | HP_SDC_ACT_SEMAPHORE; HP_SDC_ACT_DATAREG | HP_SDC_ACT_POSTCMD | HP_SDC_ACT_SEMAPHORE;
priv->tseq[1] = 0x7; priv->tseq[1] = 0x7;
priv->tseq[2] = priv->tseq[2] =
(mlc->opacket & (mlc->opacket &
(HIL_PKT_ADDR_MASK | HIL_PKT_CMD)) (HIL_PKT_ADDR_MASK | HIL_PKT_CMD))
>> HIL_PKT_ADDR_SHIFT; >> HIL_PKT_ADDR_SHIFT;
priv->tseq[3] = priv->tseq[3] =
(mlc->opacket & HIL_PKT_DATA_MASK) (mlc->opacket & HIL_PKT_DATA_MASK)
>> HIL_PKT_DATA_SHIFT; >> HIL_PKT_DATA_SHIFT;
priv->tseq[4] = 0; /* No timeout */ priv->tseq[4] = 0; /* No timeout */
if (priv->tseq[3] == HIL_CMD_DHR) priv->tseq[4] = 1; if (priv->tseq[3] == HIL_CMD_DHR)
priv->tseq[4] = 1;
priv->tseq[5] = HP_SDC_CMD_DO_HIL; priv->tseq[5] = HP_SDC_CMD_DO_HIL;
goto enqueue; goto enqueue;
do_control: do_control:
priv->emtestmode = mlc->opacket & HIL_CTRL_TEST; priv->emtestmode = mlc->opacket & HIL_CTRL_TEST;
/* we cannot emulate this, it should not be used. */ /* we cannot emulate this, it should not be used. */
BUG_ON((mlc->opacket & (HIL_CTRL_APE | HIL_CTRL_IPF)) == HIL_CTRL_APE); BUG_ON((mlc->opacket & (HIL_CTRL_APE | HIL_CTRL_IPF)) == HIL_CTRL_APE);
if ((mlc->opacket & HIL_CTRL_ONLY) == HIL_CTRL_ONLY) goto control_only; if ((mlc->opacket & HIL_CTRL_ONLY) == HIL_CTRL_ONLY)
if (mlc->opacket & HIL_CTRL_APE) { goto control_only;
BUG(); /* Should not send command/data after engaging APE */
goto done; /* Should not send command/data after engaging APE */
} BUG_ON(mlc->opacket & HIL_CTRL_APE);
/* Disengaging APE this way would not be valid either since
/* Disengaging APE this way would not be valid either since
* the loop must be allowed to idle. * the loop must be allowed to idle.
* *
* So, it works out that we really never actually send control * So, it works out that we really never actually send control
* and data when using SDC, we just send the data. * and data when using SDC, we just send the data.
*/ */
goto do_data; goto do_data;
control_only: control_only:
priv->trans.actidx = 0; priv->trans.actidx = 0;
priv->trans.idx = 1; priv->trans.idx = 1;
priv->trans.act.semaphore = &(mlc->osem); priv->trans.act.semaphore = &mlc->osem;
priv->trans.endidx = 4; priv->trans.endidx = 4;
priv->tseq[0] = priv->tseq[0] =
HP_SDC_ACT_PRECMD | HP_SDC_ACT_DATAOUT | HP_SDC_ACT_SEMAPHORE; HP_SDC_ACT_PRECMD | HP_SDC_ACT_DATAOUT | HP_SDC_ACT_SEMAPHORE;
priv->tseq[1] = HP_SDC_CMD_SET_LPC; priv->tseq[1] = HP_SDC_CMD_SET_LPC;
priv->tseq[2] = 1; priv->tseq[2] = 1;
// priv->tseq[3] = (mlc->ddc + 1) | HP_SDC_LPS_ACSUCC; /* priv->tseq[3] = (mlc->ddc + 1) | HP_SDC_LPS_ACSUCC; */
priv->tseq[3] = 0; priv->tseq[3] = 0;
if (mlc->opacket & HIL_CTRL_APE) { if (mlc->opacket & HIL_CTRL_APE) {
priv->tseq[3] |= HP_SDC_LPC_APE_IPF; priv->tseq[3] |= HP_SDC_LPC_APE_IPF;
down_trylock(&(mlc->csem)); down_trylock(&mlc->csem);
} }
enqueue: enqueue:
hp_sdc_enqueue_transaction(&(priv->trans)); hp_sdc_enqueue_transaction(&priv->trans);
done: done:
write_unlock_irqrestore(&(mlc->lock), flags); write_unlock_irqrestore(&mlc->lock, flags);
} }
static int __init hp_sdc_mlc_init(void) static int __init hp_sdc_mlc_init(void)
...@@ -316,14 +325,13 @@ static int __init hp_sdc_mlc_init(void) ...@@ -316,14 +325,13 @@ static int __init hp_sdc_mlc_init(void)
hp_sdc_mlc_priv.emtestmode = 0; hp_sdc_mlc_priv.emtestmode = 0;
hp_sdc_mlc_priv.trans.seq = hp_sdc_mlc_priv.tseq; hp_sdc_mlc_priv.trans.seq = hp_sdc_mlc_priv.tseq;
hp_sdc_mlc_priv.trans.act.semaphore = &(mlc->osem); hp_sdc_mlc_priv.trans.act.semaphore = &mlc->osem;
hp_sdc_mlc_priv.got5x = 0; hp_sdc_mlc_priv.got5x = 0;
mlc->cts = &hp_sdc_mlc_cts; mlc->cts = &hp_sdc_mlc_cts;
mlc->in = &hp_sdc_mlc_in; mlc->in = &hp_sdc_mlc_in;
mlc->out = &hp_sdc_mlc_out; mlc->out = &hp_sdc_mlc_out;
mlc->priv = &hp_sdc_mlc_priv;
mlc->priv = &hp_sdc_mlc_priv;
if (hil_mlc_register(mlc)) { if (hil_mlc_register(mlc)) {
printk(KERN_WARNING PREFIX "Failed to register MLC structure with hil_mlc\n"); printk(KERN_WARNING PREFIX "Failed to register MLC structure with hil_mlc\n");
...@@ -336,10 +344,9 @@ static int __init hp_sdc_mlc_init(void) ...@@ -336,10 +344,9 @@ static int __init hp_sdc_mlc_init(void)
} }
return 0; return 0;
err1: err1:
if (hil_mlc_unregister(mlc)) { if (hil_mlc_unregister(mlc))
printk(KERN_ERR PREFIX "Failed to unregister MLC structure with hil_mlc.\n" printk(KERN_ERR PREFIX "Failed to unregister MLC structure with hil_mlc.\n"
"This is bad. Could cause an oops.\n"); "This is bad. Could cause an oops.\n");
}
err0: err0:
return -EBUSY; return -EBUSY;
} }
...@@ -347,14 +354,14 @@ static int __init hp_sdc_mlc_init(void) ...@@ -347,14 +354,14 @@ static int __init hp_sdc_mlc_init(void)
static void __exit hp_sdc_mlc_exit(void) static void __exit hp_sdc_mlc_exit(void)
{ {
hil_mlc *mlc = &hp_sdc_mlc; hil_mlc *mlc = &hp_sdc_mlc;
if (hp_sdc_release_hil_irq(&hp_sdc_mlc_isr)) {
if (hp_sdc_release_hil_irq(&hp_sdc_mlc_isr))
printk(KERN_ERR PREFIX "Failed to release the raw HIL ISR hook.\n" printk(KERN_ERR PREFIX "Failed to release the raw HIL ISR hook.\n"
"This is bad. Could cause an oops.\n"); "This is bad. Could cause an oops.\n");
}
if (hil_mlc_unregister(mlc)) { if (hil_mlc_unregister(mlc))
printk(KERN_ERR PREFIX "Failed to unregister MLC structure with hil_mlc.\n" printk(KERN_ERR PREFIX "Failed to unregister MLC structure with hil_mlc.\n"
"This is bad. Could cause an oops.\n"); "This is bad. Could cause an oops.\n");
}
} }
module_init(hp_sdc_mlc_init); module_init(hp_sdc_mlc_init);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册