Path: blob/master/drivers/input/serio/hp_sdc_mlc.c
15112 views
/*1* Access to HP-HIL MLC through HP System Device Controller.2*3* Copyright (c) 2001 Brian S. Julin4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions, and the following disclaimer,11* without modification.12* 2. The name of the author may not be used to endorse or promote products13* derived from this software without specific prior written permission.14*15* Alternatively, this software may be distributed under the terms of the16* GNU General Public License ("GPL").17*18* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR22* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27*28* References:29* HP-HIL Technical Reference Manual. Hewlett Packard Product No. 45918A30* System Device Controller Microprocessor Firmware Theory of Operation31* for Part Number 1820-4784 Revision B. Dwg No. A-1820-4784-232*33*/3435#include <linux/hil_mlc.h>36#include <linux/hp_sdc.h>37#include <linux/errno.h>38#include <linux/kernel.h>39#include <linux/module.h>40#include <linux/init.h>41#include <linux/string.h>42#include <linux/semaphore.h>4344#define PREFIX "HP SDC MLC: "4546static hil_mlc hp_sdc_mlc;4748MODULE_AUTHOR("Brian S. Julin <[email protected]>");49MODULE_DESCRIPTION("Glue for onboard HIL MLC in HP-PARISC machines");50MODULE_LICENSE("Dual BSD/GPL");5152static struct hp_sdc_mlc_priv_s {53int emtestmode;54hp_sdc_transaction trans;55u8 tseq[16];56int got5x;57} hp_sdc_mlc_priv;5859/************************* Interrupt context ******************************/60static void hp_sdc_mlc_isr (int irq, void *dev_id,61uint8_t status, uint8_t data)62{63int idx;64hil_mlc *mlc = &hp_sdc_mlc;6566write_lock(&mlc->lock);67if (mlc->icount < 0) {68printk(KERN_WARNING PREFIX "HIL Overflow!\n");69up(&mlc->isem);70goto out;71}72idx = 15 - mlc->icount;73if ((status & HP_SDC_STATUS_IRQMASK) == HP_SDC_STATUS_HILDATA) {74mlc->ipacket[idx] |= data | HIL_ERR_INT;75mlc->icount--;76if (hp_sdc_mlc_priv.got5x || !idx)77goto check;78if ((mlc->ipacket[idx - 1] & HIL_PKT_ADDR_MASK) !=79(mlc->ipacket[idx] & HIL_PKT_ADDR_MASK)) {80mlc->ipacket[idx] &= ~HIL_PKT_ADDR_MASK;81mlc->ipacket[idx] |= (mlc->ipacket[idx - 1]82& HIL_PKT_ADDR_MASK);83}84goto check;85}86/* We know status is 5X */87if (data & HP_SDC_HIL_ISERR)88goto err;89mlc->ipacket[idx] =90(data & HP_SDC_HIL_R1MASK) << HIL_PKT_ADDR_SHIFT;91hp_sdc_mlc_priv.got5x = 1;92goto out;9394check:95hp_sdc_mlc_priv.got5x = 0;96if (mlc->imatch == 0)97goto done;98if ((mlc->imatch == (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL))99&& (mlc->ipacket[idx] == (mlc->imatch | idx)))100goto done;101if (mlc->ipacket[idx] == mlc->imatch)102goto done;103goto out;104105err:106printk(KERN_DEBUG PREFIX "err code %x\n", data);107108switch (data) {109case HP_SDC_HIL_RC_DONE:110printk(KERN_WARNING PREFIX "Bastard SDC reconfigured loop!\n");111break;112113case HP_SDC_HIL_ERR:114mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_PERR |115HIL_ERR_FERR | HIL_ERR_FOF;116break;117118case HP_SDC_HIL_TO:119mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_LERR;120break;121122case HP_SDC_HIL_RC:123printk(KERN_WARNING PREFIX "Bastard SDC decided to reconfigure loop!\n");124break;125126default:127printk(KERN_WARNING PREFIX "Unknown HIL Error status (%x)!\n", data);128break;129}130131/* No more data will be coming due to an error. */132done:133tasklet_schedule(mlc->tasklet);134up(&mlc->isem);135out:136write_unlock(&mlc->lock);137}138139140/******************** Tasklet or userspace context functions ****************/141142static int hp_sdc_mlc_in(hil_mlc *mlc, suseconds_t timeout)143{144struct hp_sdc_mlc_priv_s *priv;145int rc = 2;146147priv = mlc->priv;148149/* Try to down the semaphore */150if (down_trylock(&mlc->isem)) {151struct timeval tv;152if (priv->emtestmode) {153mlc->ipacket[0] =154HIL_ERR_INT | (mlc->opacket &155(HIL_PKT_CMD |156HIL_PKT_ADDR_MASK |157HIL_PKT_DATA_MASK));158mlc->icount = 14;159/* printk(KERN_DEBUG PREFIX ">[%x]\n", mlc->ipacket[0]); */160goto wasup;161}162do_gettimeofday(&tv);163tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec);164if (tv.tv_usec - mlc->instart.tv_usec > mlc->intimeout) {165/* printk("!%i %i",166tv.tv_usec - mlc->instart.tv_usec,167mlc->intimeout);168*/169rc = 1;170up(&mlc->isem);171}172goto done;173}174wasup:175up(&mlc->isem);176rc = 0;177done:178return rc;179}180181static int hp_sdc_mlc_cts(hil_mlc *mlc)182{183struct hp_sdc_mlc_priv_s *priv;184185priv = mlc->priv;186187/* Try to down the semaphores -- they should be up. */188BUG_ON(down_trylock(&mlc->isem));189BUG_ON(down_trylock(&mlc->osem));190191up(&mlc->isem);192up(&mlc->osem);193194if (down_trylock(&mlc->csem)) {195if (priv->trans.act.semaphore != &mlc->csem)196goto poll;197else198goto busy;199}200201if (!(priv->tseq[4] & HP_SDC_USE_LOOP))202goto done;203204poll:205priv->trans.act.semaphore = &mlc->csem;206priv->trans.actidx = 0;207priv->trans.idx = 1;208priv->trans.endidx = 5;209priv->tseq[0] =210HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN | HP_SDC_ACT_SEMAPHORE;211priv->tseq[1] = HP_SDC_CMD_READ_USE;212priv->tseq[2] = 1;213priv->tseq[3] = 0;214priv->tseq[4] = 0;215__hp_sdc_enqueue_transaction(&priv->trans);216busy:217return 1;218done:219priv->trans.act.semaphore = &mlc->osem;220up(&mlc->csem);221return 0;222}223224static void hp_sdc_mlc_out(hil_mlc *mlc)225{226struct hp_sdc_mlc_priv_s *priv;227228priv = mlc->priv;229230/* Try to down the semaphore -- it should be up. */231BUG_ON(down_trylock(&mlc->osem));232233if (mlc->opacket & HIL_DO_ALTER_CTRL)234goto do_control;235236do_data:237if (priv->emtestmode) {238up(&mlc->osem);239return;240}241/* Shouldn't be sending commands when loop may be busy */242BUG_ON(down_trylock(&mlc->csem));243up(&mlc->csem);244245priv->trans.actidx = 0;246priv->trans.idx = 1;247priv->trans.act.semaphore = &mlc->osem;248priv->trans.endidx = 6;249priv->tseq[0] =250HP_SDC_ACT_DATAREG | HP_SDC_ACT_POSTCMD | HP_SDC_ACT_SEMAPHORE;251priv->tseq[1] = 0x7;252priv->tseq[2] =253(mlc->opacket &254(HIL_PKT_ADDR_MASK | HIL_PKT_CMD))255>> HIL_PKT_ADDR_SHIFT;256priv->tseq[3] =257(mlc->opacket & HIL_PKT_DATA_MASK)258>> HIL_PKT_DATA_SHIFT;259priv->tseq[4] = 0; /* No timeout */260if (priv->tseq[3] == HIL_CMD_DHR)261priv->tseq[4] = 1;262priv->tseq[5] = HP_SDC_CMD_DO_HIL;263goto enqueue;264265do_control:266priv->emtestmode = mlc->opacket & HIL_CTRL_TEST;267268/* we cannot emulate this, it should not be used. */269BUG_ON((mlc->opacket & (HIL_CTRL_APE | HIL_CTRL_IPF)) == HIL_CTRL_APE);270271if ((mlc->opacket & HIL_CTRL_ONLY) == HIL_CTRL_ONLY)272goto control_only;273274/* Should not send command/data after engaging APE */275BUG_ON(mlc->opacket & HIL_CTRL_APE);276277/* Disengaging APE this way would not be valid either since278* the loop must be allowed to idle.279*280* So, it works out that we really never actually send control281* and data when using SDC, we just send the data.282*/283goto do_data;284285control_only:286priv->trans.actidx = 0;287priv->trans.idx = 1;288priv->trans.act.semaphore = &mlc->osem;289priv->trans.endidx = 4;290priv->tseq[0] =291HP_SDC_ACT_PRECMD | HP_SDC_ACT_DATAOUT | HP_SDC_ACT_SEMAPHORE;292priv->tseq[1] = HP_SDC_CMD_SET_LPC;293priv->tseq[2] = 1;294/* priv->tseq[3] = (mlc->ddc + 1) | HP_SDC_LPS_ACSUCC; */295priv->tseq[3] = 0;296if (mlc->opacket & HIL_CTRL_APE) {297priv->tseq[3] |= HP_SDC_LPC_APE_IPF;298BUG_ON(down_trylock(&mlc->csem));299}300enqueue:301hp_sdc_enqueue_transaction(&priv->trans);302}303304static int __init hp_sdc_mlc_init(void)305{306hil_mlc *mlc = &hp_sdc_mlc;307int err;308309#ifdef __mc68000__310if (!MACH_IS_HP300)311return -ENODEV;312#endif313314printk(KERN_INFO PREFIX "Registering the System Domain Controller's HIL MLC.\n");315316hp_sdc_mlc_priv.emtestmode = 0;317hp_sdc_mlc_priv.trans.seq = hp_sdc_mlc_priv.tseq;318hp_sdc_mlc_priv.trans.act.semaphore = &mlc->osem;319hp_sdc_mlc_priv.got5x = 0;320321mlc->cts = &hp_sdc_mlc_cts;322mlc->in = &hp_sdc_mlc_in;323mlc->out = &hp_sdc_mlc_out;324mlc->priv = &hp_sdc_mlc_priv;325326err = hil_mlc_register(mlc);327if (err) {328printk(KERN_WARNING PREFIX "Failed to register MLC structure with hil_mlc\n");329return err;330}331332if (hp_sdc_request_hil_irq(&hp_sdc_mlc_isr)) {333printk(KERN_WARNING PREFIX "Request for raw HIL ISR hook denied\n");334if (hil_mlc_unregister(mlc))335printk(KERN_ERR PREFIX "Failed to unregister MLC structure with hil_mlc.\n"336"This is bad. Could cause an oops.\n");337return -EBUSY;338}339340return 0;341}342343static void __exit hp_sdc_mlc_exit(void)344{345hil_mlc *mlc = &hp_sdc_mlc;346347if (hp_sdc_release_hil_irq(&hp_sdc_mlc_isr))348printk(KERN_ERR PREFIX "Failed to release the raw HIL ISR hook.\n"349"This is bad. Could cause an oops.\n");350351if (hil_mlc_unregister(mlc))352printk(KERN_ERR PREFIX "Failed to unregister MLC structure with hil_mlc.\n"353"This is bad. Could cause an oops.\n");354}355356module_init(hp_sdc_mlc_init);357module_exit(hp_sdc_mlc_exit);358359360