staticbool hp_sdc_disabled;
module_param_named(no_hpsdc, hp_sdc_disabled, bool, 0);
MODULE_PARM_DESC(no_hpsdc, "Do not enable HP SDC driver.");
static hp_i8042_sdc hp_sdc; /* All driver state is kept in here. */
/*************** primitives for use in any context *********************/ staticinline uint8_t hp_sdc_status_in8(void)
{
uint8_t status; unsignedlong flags;
write_lock_irqsave(&hp_sdc.ibf_lock, flags);
status = sdc_readb(hp_sdc.status_io); if (!(status & HP_SDC_STATUS_IBF))
hp_sdc.ibf = 0;
write_unlock_irqrestore(&hp_sdc.ibf_lock, flags);
/* Care must be taken to only invoke hp_sdc_spin_ibf when *absolutelyneeded,orinrarelyinvokedsubroutines. *NotonlydoesitwasteCPUcycles,italsowastesbuscycles.
*/ staticinlinevoid hp_sdc_spin_ibf(void)
{ unsignedlong flags;
rwlock_t *lock;
if (hp_sdc.rqty <= 0) { /* All data has been gathered. */ if (curr->seq[curr->actidx] & HP_SDC_ACT_SEMAPHORE) if (curr->act.semaphore)
up(curr->act.semaphore);
if (curr->seq[curr->actidx] & HP_SDC_ACT_CALLBACK) if (curr->act.irqhook)
curr->act.irqhook(irq, dev_id, status, data);
curr->actidx = curr->idx;
curr->idx++; /* Return control of this transaction */
write_lock(&hp_sdc.rtq_lock);
hp_sdc.rcurr = -1;
hp_sdc.rqty = 0;
write_unlock(&hp_sdc.rtq_lock);
tasklet_schedule(&hp_sdc.task);
}
}
status = hp_sdc_status_in8(); /* Read data unconditionally to advance i8042. */
data = hp_sdc_data_in8();
/* For now we are ignoring these until we get the SDC to behave. */ if (((status & 0xf1) == 0x51) && data == 0x82) return IRQ_HANDLED;
switch (status & HP_SDC_STATUS_IRQMASK) { case0: /* This case is not documented. */ break;
case HP_SDC_STATUS_USERTIMER: case HP_SDC_STATUS_PERIODIC: case HP_SDC_STATUS_TIMER:
read_lock(&hp_sdc.hook_lock); if (hp_sdc.timer != NULL)
hp_sdc.timer(irq, dev_id, status, data);
read_unlock(&hp_sdc.hook_lock); break;
case HP_SDC_STATUS_REG:
hp_sdc_take(irq, dev_id, status, data); break;
case HP_SDC_STATUS_HILCMD: case HP_SDC_STATUS_HILDATA:
read_lock(&hp_sdc.hook_lock); if (hp_sdc.hil != NULL)
hp_sdc.hil(irq, dev_id, status, data);
read_unlock(&hp_sdc.hook_lock); break;
static irqreturn_t hp_sdc_nmisr(int irq, void *dev_id)
{ int status;
status = hp_sdc_status_in8();
printk(KERN_WARNING PREFIX "NMI !\n");
#if0 if (status & HP_SDC_NMISTATUS_FHS) {
read_lock(&hp_sdc.hook_lock); if (hp_sdc.timer != NULL)
hp_sdc.timer(irq, dev_id, status, 0);
read_unlock(&hp_sdc.hook_lock);
} else { /* TODO: pass this on to the HIL handler, or do SAK here? */
printk(KERN_WARNING PREFIX "HIL NMI\n");
} #endif
if (hp_sdc.rcurr >= 0) {
ktime_t now = ktime_get();
if (ktime_after(now, ktime_add_us(hp_sdc.rtime,
HP_SDC_MAX_REG_DELAY))) {
hp_sdc_transaction *curr;
uint8_t tmp;
curr = hp_sdc.tq[hp_sdc.rcurr]; /* If this turns out to be a normal failure mode *we'llneedtofigureoutawaytocommunicate *itbacktotheapplication.andbelessverbose.
*/
printk(KERN_WARNING PREFIX "read timeout (%lldus)!\n",
ktime_us_delta(now, hp_sdc.rtime));
curr->idx += hp_sdc.rqty;
hp_sdc.rqty = 0;
tmp = curr->seq[curr->actidx];
curr->seq[curr->actidx] |= HP_SDC_ACT_DEAD; if (tmp & HP_SDC_ACT_SEMAPHORE) if (curr->act.semaphore)
up(curr->act.semaphore);
if (tmp & HP_SDC_ACT_CALLBACK) { /* Note this means that irqhooks may be called *intasklet/bhcontext.
*/ if (curr->act.irqhook)
curr->act.irqhook(0, NULL, 0, 0);
}
unsignedlong hp_sdc_put(void)
{
hp_sdc_transaction *curr;
uint8_t act; int idx, curridx;
int limit = 0;
write_lock(&hp_sdc.lock);
/* If i8042 buffers are full, we cannot do anything that
requires output, so we skip to the administrativa. */ if (hp_sdc.ibf) {
hp_sdc_status_in8(); if (hp_sdc.ibf) goto finish;
}
anew: /* See if we are in the middle of a sequence. */ if (hp_sdc.wcurr < 0)
hp_sdc.wcurr = 0;
read_lock_irq(&hp_sdc.rtq_lock); if (hp_sdc.rcurr == hp_sdc.wcurr)
hp_sdc.wcurr++;
read_unlock_irq(&hp_sdc.rtq_lock); if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN)
hp_sdc.wcurr = 0;
curridx = hp_sdc.wcurr;
if (hp_sdc.tq[curridx] != NULL) goto start;
while (++curridx != hp_sdc.wcurr) { if (curridx >= HP_SDC_QUEUE_LEN) {
curridx = -1; /* Wrap to top */ continue;
}
read_lock_irq(&hp_sdc.rtq_lock); if (hp_sdc.rcurr == curridx) {
read_unlock_irq(&hp_sdc.rtq_lock); continue;
}
read_unlock_irq(&hp_sdc.rtq_lock); if (hp_sdc.tq[curridx] != NULL) break; /* Found one. */
} if (curridx == hp_sdc.wcurr) { /* There's nothing queued to do. */
curridx = -1;
}
hp_sdc.wcurr = curridx;
start:
/* Check to see if the interrupt mask needs to be set. */ if (hp_sdc.set_im) {
hp_sdc_status_out8(hp_sdc.im | HP_SDC_CMD_SET_IM);
hp_sdc.set_im = 0; goto finish;
}
if (hp_sdc.wcurr == -1) goto done;
curr = hp_sdc.tq[curridx];
idx = curr->actidx;
if (curr->actidx >= curr->endidx) {
hp_sdc.tq[curridx] = NULL; /* Interleave outbound data between the transactions. */
hp_sdc.wcurr++; if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN)
hp_sdc.wcurr = 0; goto finish;
}
act = curr->seq[idx];
idx++;
if (curr->idx >= curr->endidx) { if (act & HP_SDC_ACT_DEALLOC)
kfree(curr);
hp_sdc.tq[curridx] = NULL; /* Interleave outbound data between the transactions. */
hp_sdc.wcurr++; if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN)
hp_sdc.wcurr = 0; goto finish;
}
while (act & HP_SDC_ACT_PRECMD) { if (curr->idx != idx) {
idx++;
act &= ~HP_SDC_ACT_PRECMD; break;
}
hp_sdc_status_out8(curr->seq[idx]);
curr->idx++; /* act finished? */ if ((act & HP_SDC_ACT_DURING) == HP_SDC_ACT_PRECMD) goto actdone; /* skip quantity field if data-out sequence follows. */ if (act & HP_SDC_ACT_DATAOUT)
curr->idx++; goto finish;
} if (act & HP_SDC_ACT_DATAOUT) { int qty;
hp_sdc_data_out8(w7[hp_sdc.wi - 0x70]);
hp_sdc.r7[hp_sdc.wi - 0x70] = w7[hp_sdc.wi - 0x70];
hp_sdc.wi++; /* write index register autoincrements */
{ int i = 0;
while ((i < 4) && w7[i] == hp_sdc.r7[i])
i++; if (i >= 4) {
curr->idx = idx + 1; if ((act & HP_SDC_ACT_DURING) ==
HP_SDC_ACT_DATAREG) goto actdone;
}
} goto finish;
} /* We don't go any further in the command if there is a pending read,
because we don't want interleaved results. */
read_lock_irq(&hp_sdc.rtq_lock); if (hp_sdc.rcurr >= 0) {
read_unlock_irq(&hp_sdc.rtq_lock); goto finish;
}
read_unlock_irq(&hp_sdc.rtq_lock);
if (act & HP_SDC_ACT_POSTCMD) {
uint8_t postcmd;
/* curr->idx should == idx at this point. */
postcmd = curr->seq[idx];
curr->idx++; if (act & HP_SDC_ACT_DATAIN) {
/* Start a new read */
hp_sdc.rqty = curr->seq[curr->idx];
hp_sdc.rtime = ktime_get();
curr->idx++; /* Still need to lock here in case of spurious irq. */
write_lock_irq(&hp_sdc.rtq_lock);
hp_sdc.rcurr = curridx;
write_unlock_irq(&hp_sdc.rtq_lock);
hp_sdc_status_out8(postcmd); goto finish;
}
hp_sdc_status_out8(postcmd); goto actdone;
}
if (curr->idx >= curr->endidx) { /* This transaction is over. */ if (act & HP_SDC_ACT_DEALLOC)
kfree(curr);
hp_sdc.tq[curridx] = NULL;
} else {
curr->actidx = idx + 1;
curr->idx = idx + 2;
} /* Interleave outbound data between the transactions. */
hp_sdc.wcurr++; if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN)
hp_sdc.wcurr = 0;
finish: /* If by some quirk IBF has cleared and our ISR has run to
see that that has happened, do it all again. */ if (!hp_sdc.ibf && limit++ < 20) goto anew;
done: if (hp_sdc.wcurr >= 0)
tasklet_schedule(&hp_sdc.task);
write_unlock(&hp_sdc.lock);
return0;
}
/******* Functions called in either user or kernel context ****/ int __hp_sdc_enqueue_transaction(hp_sdc_transaction *this)
{ int i;
if (this == NULL) {
BUG(); return -EINVAL;
}
/* Can't have same transaction on queue twice */ for (i = 0; i < HP_SDC_QUEUE_LEN; i++) if (hp_sdc.tq[i] == this) goto fail;
this->actidx = 0; this->idx = 1;
/* Search for empty slot */ for (i = 0; i < HP_SDC_QUEUE_LEN; i++) if (hp_sdc.tq[i] == NULL) {
hp_sdc.tq[i] = this;
tasklet_schedule(&hp_sdc.task); return0;
}
printk(KERN_WARNING PREFIX "No free slot to add transaction.\n"); return -EBUSY;
int hp_sdc_release_hil_irq(hp_sdc_irqhook *callback)
{
write_lock_irq(&hp_sdc.hook_lock); if ((callback != hp_sdc.hil) ||
(hp_sdc.hil == NULL)) {
write_unlock_irq(&hp_sdc.hook_lock); return -EINVAL;
}
hp_sdc.hil = NULL; /* Disable interrupts from HIL only if there is no cooked driver. */ if(hp_sdc.cooked == NULL) {
hp_sdc.im |= (HP_SDC_IM_HIL | HP_SDC_IM_RESET);
hp_sdc.set_im = 1;
}
write_unlock_irq(&hp_sdc.hook_lock);
tasklet_schedule(&hp_sdc.task);
return0;
}
int hp_sdc_release_cooked_irq(hp_sdc_irqhook *callback)
{
write_lock_irq(&hp_sdc.hook_lock); if ((callback != hp_sdc.cooked) ||
(hp_sdc.cooked == NULL)) {
write_unlock_irq(&hp_sdc.hook_lock); return -EINVAL;
}
hp_sdc.cooked = NULL; /* Disable interrupts from HIL only if there is no raw HIL driver. */ if(hp_sdc.hil == NULL) {
hp_sdc.im |= (HP_SDC_IM_HIL | HP_SDC_IM_RESET);
hp_sdc.set_im = 1;
}
write_unlock_irq(&hp_sdc.hook_lock);
tasklet_schedule(&hp_sdc.task);
ret = hp_sdc_init(); /* after successful initialization give SDC some time to settle
* and then load the hp_sdc_mlc upper layer driver */ if (!ret)
schedule_delayed_work(&moduleloader_work,
msecs_to_jiffies(2000));
return ret;
}
#endif/* __hppa__ */
staticvoid hp_sdc_exit(void)
{ /* do nothing if we don't have a SDC */ if (!hp_sdc.dev) return;
write_lock_irq(&hp_sdc.lock);
/* Turn off all maskable "sub-function" irq's. */
hp_sdc_spin_ibf();
sdc_writeb(HP_SDC_CMD_SET_IM | HP_SDC_IM_MASK, hp_sdc.status_io);
/* Wait until we know this has been processed by the i8042 */
hp_sdc_spin_ibf();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.