2 * Access to HP-HIL MLC through HP System Device Controller.
4 * Copyright (c) 2001 Brian S. Julin
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * Alternatively, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL").
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * HP-HIL Technical Reference Manual. Hewlett Packard Product No. 45918A
31 * System Device Controller Microprocessor Firmware Theory of Operation
32 * for Part Number 1820-4784 Revision B. Dwg No. A-1820-4784-2
36 #include <linux/hil_mlc.h>
37 #include <linux/hp_sdc.h>
38 #include <linux/errno.h>
39 #include <linux/kernel.h>
40 #include <linux/module.h>
41 #include <linux/init.h>
42 #include <linux/string.h>
43 #include <linux/semaphore.h>
45 #define PREFIX "HP SDC MLC: "
47 static hil_mlc hp_sdc_mlc;
49 MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
50 MODULE_DESCRIPTION("Glue for onboard HIL MLC in HP-PARISC machines");
51 MODULE_LICENSE("Dual BSD/GPL");
53 struct hp_sdc_mlc_priv_s {
55 hp_sdc_transaction trans;
60 /************************* Interrupt context ******************************/
61 static void hp_sdc_mlc_isr (int irq, void *dev_id,
62 uint8_t status, uint8_t data)
65 hil_mlc *mlc = &hp_sdc_mlc;
67 write_lock(&mlc->lock);
68 if (mlc->icount < 0) {
69 printk(KERN_WARNING PREFIX "HIL Overflow!\n");
73 idx = 15 - mlc->icount;
74 if ((status & HP_SDC_STATUS_IRQMASK) == HP_SDC_STATUS_HILDATA) {
75 mlc->ipacket[idx] |= data | HIL_ERR_INT;
77 if (hp_sdc_mlc_priv.got5x || !idx)
79 if ((mlc->ipacket[idx - 1] & HIL_PKT_ADDR_MASK) !=
80 (mlc->ipacket[idx] & HIL_PKT_ADDR_MASK)) {
81 mlc->ipacket[idx] &= ~HIL_PKT_ADDR_MASK;
82 mlc->ipacket[idx] |= (mlc->ipacket[idx - 1]
87 /* We know status is 5X */
88 if (data & HP_SDC_HIL_ISERR)
91 (data & HP_SDC_HIL_R1MASK) << HIL_PKT_ADDR_SHIFT;
92 hp_sdc_mlc_priv.got5x = 1;
96 hp_sdc_mlc_priv.got5x = 0;
99 if ((mlc->imatch == (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL))
100 && (mlc->ipacket[idx] == (mlc->imatch | idx)))
102 if (mlc->ipacket[idx] == mlc->imatch)
107 printk(KERN_DEBUG PREFIX "err code %x\n", data);
110 case HP_SDC_HIL_RC_DONE:
111 printk(KERN_WARNING PREFIX "Bastard SDC reconfigured loop!\n");
115 mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_PERR |
116 HIL_ERR_FERR | HIL_ERR_FOF;
120 mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_LERR;
124 printk(KERN_WARNING PREFIX "Bastard SDC decided to reconfigure loop!\n");
128 printk(KERN_WARNING PREFIX "Unkown HIL Error status (%x)!\n", data);
132 /* No more data will be coming due to an error. */
134 tasklet_schedule(mlc->tasklet);
137 write_unlock(&mlc->lock);
141 /******************** Tasklet or userspace context functions ****************/
143 static int hp_sdc_mlc_in(hil_mlc *mlc, suseconds_t timeout)
145 struct hp_sdc_mlc_priv_s *priv;
150 /* Try to down the semaphore */
151 if (down_trylock(&mlc->isem)) {
153 if (priv->emtestmode) {
155 HIL_ERR_INT | (mlc->opacket &
160 /* printk(KERN_DEBUG PREFIX ">[%x]\n", mlc->ipacket[0]); */
163 do_gettimeofday(&tv);
164 tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec);
165 if (tv.tv_usec - mlc->instart.tv_usec > mlc->intimeout) {
167 tv.tv_usec - mlc->instart.tv_usec,
182 static int hp_sdc_mlc_cts(hil_mlc *mlc)
184 struct hp_sdc_mlc_priv_s *priv;
188 /* Try to down the semaphores -- they should be up. */
189 BUG_ON(down_trylock(&mlc->isem));
190 BUG_ON(down_trylock(&mlc->osem));
195 if (down_trylock(&mlc->csem)) {
196 if (priv->trans.act.semaphore != &mlc->csem)
202 if (!(priv->tseq[4] & HP_SDC_USE_LOOP))
206 priv->trans.act.semaphore = &mlc->csem;
207 priv->trans.actidx = 0;
209 priv->trans.endidx = 5;
211 HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN | HP_SDC_ACT_SEMAPHORE;
212 priv->tseq[1] = HP_SDC_CMD_READ_USE;
216 __hp_sdc_enqueue_transaction(&priv->trans);
220 priv->trans.act.semaphore = &mlc->osem;
225 static void hp_sdc_mlc_out(hil_mlc *mlc)
227 struct hp_sdc_mlc_priv_s *priv;
231 /* Try to down the semaphore -- it should be up. */
232 BUG_ON(down_trylock(&mlc->osem));
234 if (mlc->opacket & HIL_DO_ALTER_CTRL)
238 if (priv->emtestmode) {
242 /* Shouldn't be sending commands when loop may be busy */
243 BUG_ON(down_trylock(&mlc->csem));
246 priv->trans.actidx = 0;
248 priv->trans.act.semaphore = &mlc->osem;
249 priv->trans.endidx = 6;
251 HP_SDC_ACT_DATAREG | HP_SDC_ACT_POSTCMD | HP_SDC_ACT_SEMAPHORE;
255 (HIL_PKT_ADDR_MASK | HIL_PKT_CMD))
256 >> HIL_PKT_ADDR_SHIFT;
258 (mlc->opacket & HIL_PKT_DATA_MASK)
259 >> HIL_PKT_DATA_SHIFT;
260 priv->tseq[4] = 0; /* No timeout */
261 if (priv->tseq[3] == HIL_CMD_DHR)
263 priv->tseq[5] = HP_SDC_CMD_DO_HIL;
267 priv->emtestmode = mlc->opacket & HIL_CTRL_TEST;
269 /* we cannot emulate this, it should not be used. */
270 BUG_ON((mlc->opacket & (HIL_CTRL_APE | HIL_CTRL_IPF)) == HIL_CTRL_APE);
272 if ((mlc->opacket & HIL_CTRL_ONLY) == HIL_CTRL_ONLY)
275 /* Should not send command/data after engaging APE */
276 BUG_ON(mlc->opacket & HIL_CTRL_APE);
278 /* Disengaging APE this way would not be valid either since
279 * the loop must be allowed to idle.
281 * So, it works out that we really never actually send control
282 * and data when using SDC, we just send the data.
287 priv->trans.actidx = 0;
289 priv->trans.act.semaphore = &mlc->osem;
290 priv->trans.endidx = 4;
292 HP_SDC_ACT_PRECMD | HP_SDC_ACT_DATAOUT | HP_SDC_ACT_SEMAPHORE;
293 priv->tseq[1] = HP_SDC_CMD_SET_LPC;
295 /* priv->tseq[3] = (mlc->ddc + 1) | HP_SDC_LPS_ACSUCC; */
297 if (mlc->opacket & HIL_CTRL_APE) {
298 priv->tseq[3] |= HP_SDC_LPC_APE_IPF;
299 down_trylock(&mlc->csem);
302 hp_sdc_enqueue_transaction(&priv->trans);
305 static int __init hp_sdc_mlc_init(void)
307 hil_mlc *mlc = &hp_sdc_mlc;
309 printk(KERN_INFO PREFIX "Registering the System Domain Controller's HIL MLC.\n");
311 hp_sdc_mlc_priv.emtestmode = 0;
312 hp_sdc_mlc_priv.trans.seq = hp_sdc_mlc_priv.tseq;
313 hp_sdc_mlc_priv.trans.act.semaphore = &mlc->osem;
314 hp_sdc_mlc_priv.got5x = 0;
316 mlc->cts = &hp_sdc_mlc_cts;
317 mlc->in = &hp_sdc_mlc_in;
318 mlc->out = &hp_sdc_mlc_out;
319 mlc->priv = &hp_sdc_mlc_priv;
321 if (hil_mlc_register(mlc)) {
322 printk(KERN_WARNING PREFIX "Failed to register MLC structure with hil_mlc\n");
326 if (hp_sdc_request_hil_irq(&hp_sdc_mlc_isr)) {
327 printk(KERN_WARNING PREFIX "Request for raw HIL ISR hook denied\n");
332 if (hil_mlc_unregister(mlc))
333 printk(KERN_ERR PREFIX "Failed to unregister MLC structure with hil_mlc.\n"
334 "This is bad. Could cause an oops.\n");
339 static void __exit hp_sdc_mlc_exit(void)
341 hil_mlc *mlc = &hp_sdc_mlc;
343 if (hp_sdc_release_hil_irq(&hp_sdc_mlc_isr))
344 printk(KERN_ERR PREFIX "Failed to release the raw HIL ISR hook.\n"
345 "This is bad. Could cause an oops.\n");
347 if (hil_mlc_unregister(mlc))
348 printk(KERN_ERR PREFIX "Failed to unregister MLC structure with hil_mlc.\n"
349 "This is bad. Could cause an oops.\n");
352 module_init(hp_sdc_mlc_init);
353 module_exit(hp_sdc_mlc_exit);