11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * HP i8042-based System Device Controller driver. 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (c) 2001 Brian S. Julin 51da177e4SLinus Torvalds * All rights reserved. 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or without 81da177e4SLinus Torvalds * modification, are permitted provided that the following conditions 91da177e4SLinus Torvalds * are met: 101da177e4SLinus Torvalds * 1. Redistributions of source code must retain the above copyright 111da177e4SLinus Torvalds * notice, this list of conditions, and the following disclaimer, 121da177e4SLinus Torvalds * without modification. 131da177e4SLinus Torvalds * 2. The name of the author may not be used to endorse or promote products 141da177e4SLinus Torvalds * derived from this software without specific prior written permission. 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * Alternatively, this software may be distributed under the terms of the 171da177e4SLinus Torvalds * GNU General Public License ("GPL"). 181da177e4SLinus Torvalds * 191da177e4SLinus Torvalds * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 201da177e4SLinus Torvalds * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 211da177e4SLinus Torvalds * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 221da177e4SLinus Torvalds * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 231da177e4SLinus Torvalds * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 241da177e4SLinus Torvalds * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 251da177e4SLinus Torvalds * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 261da177e4SLinus Torvalds * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 271da177e4SLinus Torvalds * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 281da177e4SLinus Torvalds * 291da177e4SLinus Torvalds * References: 301da177e4SLinus Torvalds * System Device Controller Microprocessor Firmware Theory of Operation 311da177e4SLinus Torvalds * for Part Number 1820-4784 Revision B. Dwg No. A-1820-4784-2 321da177e4SLinus Torvalds * Helge Deller's original hilkbd.c port for PA-RISC. 331da177e4SLinus Torvalds * 341da177e4SLinus Torvalds * 351da177e4SLinus Torvalds * Driver theory of operation: 361da177e4SLinus Torvalds * 371da177e4SLinus Torvalds * hp_sdc_put does all writing to the SDC. ISR can run on a different 381da177e4SLinus Torvalds * CPU than hp_sdc_put, but only one CPU runs hp_sdc_put at a time 391da177e4SLinus Torvalds * (it cannot really benefit from SMP anyway.) A tasket fit this perfectly. 401da177e4SLinus Torvalds * 411da177e4SLinus Torvalds * All data coming back from the SDC is sent via interrupt and can be read 421da177e4SLinus Torvalds * fully in the ISR, so there are no latency/throughput problems there. 431da177e4SLinus Torvalds * The problem is with output, due to the slow clock speed of the SDC 441da177e4SLinus Torvalds * compared to the CPU. This should not be too horrible most of the time, 451da177e4SLinus Torvalds * but if used with HIL devices that support the multibyte transfer command, 461da177e4SLinus Torvalds * keeping outbound throughput flowing at the 6500KBps that the HIL is 471da177e4SLinus Torvalds * capable of is more than can be done at HZ=100. 481da177e4SLinus Torvalds * 491da177e4SLinus Torvalds * Busy polling for IBF clear wastes CPU cycles and bus cycles. hp_sdc.ibf 501da177e4SLinus Torvalds * is set to 0 when the IBF flag in the status register has cleared. ISR 511da177e4SLinus Torvalds * may do this, and may also access the parts of queued transactions related 521da177e4SLinus Torvalds * to reading data back from the SDC, but otherwise will not touch the 531da177e4SLinus Torvalds * hp_sdc state. Whenever a register is written hp_sdc.ibf is set to 1. 541da177e4SLinus Torvalds * 551da177e4SLinus Torvalds * The i8042 write index and the values in the 4-byte input buffer 561da177e4SLinus Torvalds * starting at 0x70 are kept track of in hp_sdc.wi, and .r7[], respectively, 571da177e4SLinus Torvalds * to minimize the amount of IO needed to the SDC. However these values 581da177e4SLinus Torvalds * do not need to be locked since they are only ever accessed by hp_sdc_put. 591da177e4SLinus Torvalds * 601da177e4SLinus Torvalds * A timer task schedules the tasklet once per second just to make 611da177e4SLinus Torvalds * sure it doesn't freeze up and to allow for bad reads to time out. 621da177e4SLinus Torvalds */ 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds #include <linux/hp_sdc.h> 651da177e4SLinus Torvalds #include <linux/sched.h> 661da177e4SLinus Torvalds #include <linux/errno.h> 671da177e4SLinus Torvalds #include <linux/init.h> 681da177e4SLinus Torvalds #include <linux/module.h> 691da177e4SLinus Torvalds #include <linux/ioport.h> 701da177e4SLinus Torvalds #include <linux/time.h> 711da177e4SLinus Torvalds #include <linux/slab.h> 721da177e4SLinus Torvalds #include <linux/hil.h> 731da177e4SLinus Torvalds #include <asm/io.h> 741da177e4SLinus Torvalds #include <asm/system.h> 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds /* Machine-specific abstraction */ 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds #if defined(__hppa__) 791da177e4SLinus Torvalds # include <asm/parisc-device.h> 801da177e4SLinus Torvalds # define sdc_readb(p) gsc_readb(p) 811da177e4SLinus Torvalds # define sdc_writeb(v,p) gsc_writeb((v),(p)) 821da177e4SLinus Torvalds #elif defined(__mc68000__) 831da177e4SLinus Torvalds # include <asm/uaccess.h> 841da177e4SLinus Torvalds # define sdc_readb(p) in_8(p) 851da177e4SLinus Torvalds # define sdc_writeb(v,p) out_8((p),(v)) 861da177e4SLinus Torvalds #else 871da177e4SLinus Torvalds # error "HIL is not supported on this platform" 881da177e4SLinus Torvalds #endif 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds #define PREFIX "HP SDC: " 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>"); 931da177e4SLinus Torvalds MODULE_DESCRIPTION("HP i8042-based SDC Driver"); 941da177e4SLinus Torvalds MODULE_LICENSE("Dual BSD/GPL"); 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds EXPORT_SYMBOL(hp_sdc_request_timer_irq); 971da177e4SLinus Torvalds EXPORT_SYMBOL(hp_sdc_request_hil_irq); 981da177e4SLinus Torvalds EXPORT_SYMBOL(hp_sdc_request_cooked_irq); 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds EXPORT_SYMBOL(hp_sdc_release_timer_irq); 1011da177e4SLinus Torvalds EXPORT_SYMBOL(hp_sdc_release_hil_irq); 1021da177e4SLinus Torvalds EXPORT_SYMBOL(hp_sdc_release_cooked_irq); 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds EXPORT_SYMBOL(hp_sdc_enqueue_transaction); 1051da177e4SLinus Torvalds EXPORT_SYMBOL(hp_sdc_dequeue_transaction); 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds static hp_i8042_sdc hp_sdc; /* All driver state is kept in here. */ 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds /*************** primitives for use in any context *********************/ 1101da177e4SLinus Torvalds static inline uint8_t hp_sdc_status_in8 (void) { 1111da177e4SLinus Torvalds uint8_t status; 1121da177e4SLinus Torvalds unsigned long flags; 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds write_lock_irqsave(&hp_sdc.ibf_lock, flags); 1151da177e4SLinus Torvalds status = sdc_readb(hp_sdc.status_io); 1161da177e4SLinus Torvalds if (!(status & HP_SDC_STATUS_IBF)) hp_sdc.ibf = 0; 1171da177e4SLinus Torvalds write_unlock_irqrestore(&hp_sdc.ibf_lock, flags); 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds return status; 1201da177e4SLinus Torvalds } 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds static inline uint8_t hp_sdc_data_in8 (void) { 1231da177e4SLinus Torvalds return sdc_readb(hp_sdc.data_io); 1241da177e4SLinus Torvalds } 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds static inline void hp_sdc_status_out8 (uint8_t val) { 1271da177e4SLinus Torvalds unsigned long flags; 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds write_lock_irqsave(&hp_sdc.ibf_lock, flags); 1301da177e4SLinus Torvalds hp_sdc.ibf = 1; 1311da177e4SLinus Torvalds if ((val & 0xf0) == 0xe0) hp_sdc.wi = 0xff; 1321da177e4SLinus Torvalds sdc_writeb(val, hp_sdc.status_io); 1331da177e4SLinus Torvalds write_unlock_irqrestore(&hp_sdc.ibf_lock, flags); 1341da177e4SLinus Torvalds } 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds static inline void hp_sdc_data_out8 (uint8_t val) { 1371da177e4SLinus Torvalds unsigned long flags; 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds write_lock_irqsave(&hp_sdc.ibf_lock, flags); 1401da177e4SLinus Torvalds hp_sdc.ibf = 1; 1411da177e4SLinus Torvalds sdc_writeb(val, hp_sdc.data_io); 1421da177e4SLinus Torvalds write_unlock_irqrestore(&hp_sdc.ibf_lock, flags); 1431da177e4SLinus Torvalds } 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds /* Care must be taken to only invoke hp_sdc_spin_ibf when 1461da177e4SLinus Torvalds * absolutely needed, or in rarely invoked subroutines. 1471da177e4SLinus Torvalds * Not only does it waste CPU cycles, it also wastes bus cycles. 1481da177e4SLinus Torvalds */ 1491da177e4SLinus Torvalds static inline void hp_sdc_spin_ibf(void) { 1501da177e4SLinus Torvalds unsigned long flags; 1511da177e4SLinus Torvalds rwlock_t *lock; 1521da177e4SLinus Torvalds 1531da177e4SLinus Torvalds lock = &hp_sdc.ibf_lock; 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds read_lock_irqsave(lock, flags); 1561da177e4SLinus Torvalds if (!hp_sdc.ibf) { 1571da177e4SLinus Torvalds read_unlock_irqrestore(lock, flags); 1581da177e4SLinus Torvalds return; 1591da177e4SLinus Torvalds } 1601da177e4SLinus Torvalds read_unlock(lock); 1611da177e4SLinus Torvalds write_lock(lock); 1621da177e4SLinus Torvalds while (sdc_readb(hp_sdc.status_io) & HP_SDC_STATUS_IBF) {}; 1631da177e4SLinus Torvalds hp_sdc.ibf = 0; 1641da177e4SLinus Torvalds write_unlock_irqrestore(lock, flags); 1651da177e4SLinus Torvalds } 1661da177e4SLinus Torvalds 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds /************************ Interrupt context functions ************************/ 1691da177e4SLinus Torvalds static void hp_sdc_take (int irq, void *dev_id, uint8_t status, uint8_t data) { 1701da177e4SLinus Torvalds hp_sdc_transaction *curr; 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds read_lock(&hp_sdc.rtq_lock); 1731da177e4SLinus Torvalds if (hp_sdc.rcurr < 0) { 1741da177e4SLinus Torvalds read_unlock(&hp_sdc.rtq_lock); 1751da177e4SLinus Torvalds return; 1761da177e4SLinus Torvalds } 1771da177e4SLinus Torvalds curr = hp_sdc.tq[hp_sdc.rcurr]; 1781da177e4SLinus Torvalds read_unlock(&hp_sdc.rtq_lock); 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds curr->seq[curr->idx++] = status; 1811da177e4SLinus Torvalds curr->seq[curr->idx++] = data; 1821da177e4SLinus Torvalds hp_sdc.rqty -= 2; 1831da177e4SLinus Torvalds do_gettimeofday(&hp_sdc.rtv); 1841da177e4SLinus Torvalds 1851da177e4SLinus Torvalds if (hp_sdc.rqty <= 0) { 1861da177e4SLinus Torvalds /* All data has been gathered. */ 1871da177e4SLinus Torvalds if(curr->seq[curr->actidx] & HP_SDC_ACT_SEMAPHORE) { 1881da177e4SLinus Torvalds if (curr->act.semaphore) up(curr->act.semaphore); 1891da177e4SLinus Torvalds } 1901da177e4SLinus Torvalds if(curr->seq[curr->actidx] & HP_SDC_ACT_CALLBACK) { 1911da177e4SLinus Torvalds if (curr->act.irqhook) 1921da177e4SLinus Torvalds curr->act.irqhook(irq, dev_id, status, data); 1931da177e4SLinus Torvalds } 1941da177e4SLinus Torvalds curr->actidx = curr->idx; 1951da177e4SLinus Torvalds curr->idx++; 1961da177e4SLinus Torvalds /* Return control of this transaction */ 1971da177e4SLinus Torvalds write_lock(&hp_sdc.rtq_lock); 1981da177e4SLinus Torvalds hp_sdc.rcurr = -1; 1991da177e4SLinus Torvalds hp_sdc.rqty = 0; 2001da177e4SLinus Torvalds write_unlock(&hp_sdc.rtq_lock); 2011da177e4SLinus Torvalds tasklet_schedule(&hp_sdc.task); 2021da177e4SLinus Torvalds } 2031da177e4SLinus Torvalds } 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds static irqreturn_t hp_sdc_isr(int irq, void *dev_id, struct pt_regs * regs) { 2061da177e4SLinus Torvalds uint8_t status, data; 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds status = hp_sdc_status_in8(); 2091da177e4SLinus Torvalds /* Read data unconditionally to advance i8042. */ 2101da177e4SLinus Torvalds data = hp_sdc_data_in8(); 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds /* For now we are ignoring these until we get the SDC to behave. */ 2131da177e4SLinus Torvalds if (((status & 0xf1) == 0x51) && data == 0x82) { 2141da177e4SLinus Torvalds return IRQ_HANDLED; 2151da177e4SLinus Torvalds } 2161da177e4SLinus Torvalds 2171da177e4SLinus Torvalds switch(status & HP_SDC_STATUS_IRQMASK) { 2181da177e4SLinus Torvalds case 0: /* This case is not documented. */ 2191da177e4SLinus Torvalds break; 2201da177e4SLinus Torvalds case HP_SDC_STATUS_USERTIMER: 2211da177e4SLinus Torvalds case HP_SDC_STATUS_PERIODIC: 2221da177e4SLinus Torvalds case HP_SDC_STATUS_TIMER: 2231da177e4SLinus Torvalds read_lock(&hp_sdc.hook_lock); 2241da177e4SLinus Torvalds if (hp_sdc.timer != NULL) 2251da177e4SLinus Torvalds hp_sdc.timer(irq, dev_id, status, data); 2261da177e4SLinus Torvalds read_unlock(&hp_sdc.hook_lock); 2271da177e4SLinus Torvalds break; 2281da177e4SLinus Torvalds case HP_SDC_STATUS_REG: 2291da177e4SLinus Torvalds hp_sdc_take(irq, dev_id, status, data); 2301da177e4SLinus Torvalds break; 2311da177e4SLinus Torvalds case HP_SDC_STATUS_HILCMD: 2321da177e4SLinus Torvalds case HP_SDC_STATUS_HILDATA: 2331da177e4SLinus Torvalds read_lock(&hp_sdc.hook_lock); 2341da177e4SLinus Torvalds if (hp_sdc.hil != NULL) 2351da177e4SLinus Torvalds hp_sdc.hil(irq, dev_id, status, data); 2361da177e4SLinus Torvalds read_unlock(&hp_sdc.hook_lock); 2371da177e4SLinus Torvalds break; 2381da177e4SLinus Torvalds case HP_SDC_STATUS_PUP: 2391da177e4SLinus Torvalds read_lock(&hp_sdc.hook_lock); 2401da177e4SLinus Torvalds if (hp_sdc.pup != NULL) 2411da177e4SLinus Torvalds hp_sdc.pup(irq, dev_id, status, data); 2421da177e4SLinus Torvalds else printk(KERN_INFO PREFIX "HP SDC reports successful PUP.\n"); 2431da177e4SLinus Torvalds read_unlock(&hp_sdc.hook_lock); 2441da177e4SLinus Torvalds break; 2451da177e4SLinus Torvalds default: 2461da177e4SLinus Torvalds read_lock(&hp_sdc.hook_lock); 2471da177e4SLinus Torvalds if (hp_sdc.cooked != NULL) 2481da177e4SLinus Torvalds hp_sdc.cooked(irq, dev_id, status, data); 2491da177e4SLinus Torvalds read_unlock(&hp_sdc.hook_lock); 2501da177e4SLinus Torvalds break; 2511da177e4SLinus Torvalds } 2521da177e4SLinus Torvalds return IRQ_HANDLED; 2531da177e4SLinus Torvalds } 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds 2561da177e4SLinus Torvalds static irqreturn_t hp_sdc_nmisr(int irq, void *dev_id, struct pt_regs * regs) { 2571da177e4SLinus Torvalds int status; 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds status = hp_sdc_status_in8(); 2601da177e4SLinus Torvalds printk(KERN_WARNING PREFIX "NMI !\n"); 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvalds #if 0 2631da177e4SLinus Torvalds if (status & HP_SDC_NMISTATUS_FHS) { 2641da177e4SLinus Torvalds read_lock(&hp_sdc.hook_lock); 2651da177e4SLinus Torvalds if (hp_sdc.timer != NULL) 2661da177e4SLinus Torvalds hp_sdc.timer(irq, dev_id, status, 0); 2671da177e4SLinus Torvalds read_unlock(&hp_sdc.hook_lock); 2681da177e4SLinus Torvalds } 2691da177e4SLinus Torvalds else { 2701da177e4SLinus Torvalds /* TODO: pass this on to the HIL handler, or do SAK here? */ 2711da177e4SLinus Torvalds printk(KERN_WARNING PREFIX "HIL NMI\n"); 2721da177e4SLinus Torvalds } 2731da177e4SLinus Torvalds #endif 2741da177e4SLinus Torvalds return IRQ_HANDLED; 2751da177e4SLinus Torvalds } 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvalds /***************** Kernel (tasklet) context functions ****************/ 2791da177e4SLinus Torvalds 2801da177e4SLinus Torvalds unsigned long hp_sdc_put(void); 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvalds static void hp_sdc_tasklet(unsigned long foo) { 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvalds write_lock_irq(&hp_sdc.rtq_lock); 2851da177e4SLinus Torvalds if (hp_sdc.rcurr >= 0) { 2861da177e4SLinus Torvalds struct timeval tv; 2871da177e4SLinus Torvalds do_gettimeofday(&tv); 2881da177e4SLinus Torvalds if (tv.tv_sec > hp_sdc.rtv.tv_sec) tv.tv_usec += 1000000; 2891da177e4SLinus Torvalds if (tv.tv_usec - hp_sdc.rtv.tv_usec > HP_SDC_MAX_REG_DELAY) { 2901da177e4SLinus Torvalds hp_sdc_transaction *curr; 2911da177e4SLinus Torvalds uint8_t tmp; 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds curr = hp_sdc.tq[hp_sdc.rcurr]; 2941da177e4SLinus Torvalds /* If this turns out to be a normal failure mode 2951da177e4SLinus Torvalds * we'll need to figure out a way to communicate 2961da177e4SLinus Torvalds * it back to the application. and be less verbose. 2971da177e4SLinus Torvalds */ 2981da177e4SLinus Torvalds printk(KERN_WARNING PREFIX "read timeout (%ius)!\n", 2991da177e4SLinus Torvalds tv.tv_usec - hp_sdc.rtv.tv_usec); 3001da177e4SLinus Torvalds curr->idx += hp_sdc.rqty; 3011da177e4SLinus Torvalds hp_sdc.rqty = 0; 3021da177e4SLinus Torvalds tmp = curr->seq[curr->actidx]; 3031da177e4SLinus Torvalds curr->seq[curr->actidx] |= HP_SDC_ACT_DEAD; 3041da177e4SLinus Torvalds if(tmp & HP_SDC_ACT_SEMAPHORE) { 3051da177e4SLinus Torvalds if (curr->act.semaphore) 3061da177e4SLinus Torvalds up(curr->act.semaphore); 3071da177e4SLinus Torvalds } 3081da177e4SLinus Torvalds if(tmp & HP_SDC_ACT_CALLBACK) { 3091da177e4SLinus Torvalds /* Note this means that irqhooks may be called 3101da177e4SLinus Torvalds * in tasklet/bh context. 3111da177e4SLinus Torvalds */ 3121da177e4SLinus Torvalds if (curr->act.irqhook) 3131da177e4SLinus Torvalds curr->act.irqhook(0, 0, 0, 0); 3141da177e4SLinus Torvalds } 3151da177e4SLinus Torvalds curr->actidx = curr->idx; 3161da177e4SLinus Torvalds curr->idx++; 3171da177e4SLinus Torvalds hp_sdc.rcurr = -1; 3181da177e4SLinus Torvalds } 3191da177e4SLinus Torvalds } 3201da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.rtq_lock); 3211da177e4SLinus Torvalds hp_sdc_put(); 3221da177e4SLinus Torvalds } 3231da177e4SLinus Torvalds 3241da177e4SLinus Torvalds unsigned long hp_sdc_put(void) { 3251da177e4SLinus Torvalds hp_sdc_transaction *curr; 3261da177e4SLinus Torvalds uint8_t act; 3271da177e4SLinus Torvalds int idx, curridx; 3281da177e4SLinus Torvalds 3291da177e4SLinus Torvalds int limit = 0; 3301da177e4SLinus Torvalds 3311da177e4SLinus Torvalds write_lock(&hp_sdc.lock); 3321da177e4SLinus Torvalds 3331da177e4SLinus Torvalds /* If i8042 buffers are full, we cannot do anything that 3341da177e4SLinus Torvalds requires output, so we skip to the administrativa. */ 3351da177e4SLinus Torvalds if (hp_sdc.ibf) { 3361da177e4SLinus Torvalds hp_sdc_status_in8(); 3371da177e4SLinus Torvalds if (hp_sdc.ibf) goto finish; 3381da177e4SLinus Torvalds } 3391da177e4SLinus Torvalds 3401da177e4SLinus Torvalds anew: 3411da177e4SLinus Torvalds /* See if we are in the middle of a sequence. */ 3421da177e4SLinus Torvalds if (hp_sdc.wcurr < 0) hp_sdc.wcurr = 0; 3431da177e4SLinus Torvalds read_lock_irq(&hp_sdc.rtq_lock); 3441da177e4SLinus Torvalds if (hp_sdc.rcurr == hp_sdc.wcurr) hp_sdc.wcurr++; 3451da177e4SLinus Torvalds read_unlock_irq(&hp_sdc.rtq_lock); 3461da177e4SLinus Torvalds if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0; 3471da177e4SLinus Torvalds curridx = hp_sdc.wcurr; 3481da177e4SLinus Torvalds 3491da177e4SLinus Torvalds if (hp_sdc.tq[curridx] != NULL) goto start; 3501da177e4SLinus Torvalds 3511da177e4SLinus Torvalds while (++curridx != hp_sdc.wcurr) { 3521da177e4SLinus Torvalds if (curridx >= HP_SDC_QUEUE_LEN) { 3531da177e4SLinus Torvalds curridx = -1; /* Wrap to top */ 3541da177e4SLinus Torvalds continue; 3551da177e4SLinus Torvalds } 3561da177e4SLinus Torvalds read_lock_irq(&hp_sdc.rtq_lock); 3571da177e4SLinus Torvalds if (hp_sdc.rcurr == curridx) { 3581da177e4SLinus Torvalds read_unlock_irq(&hp_sdc.rtq_lock); 3591da177e4SLinus Torvalds continue; 3601da177e4SLinus Torvalds } 3611da177e4SLinus Torvalds read_unlock_irq(&hp_sdc.rtq_lock); 3621da177e4SLinus Torvalds if (hp_sdc.tq[curridx] != NULL) break; /* Found one. */ 3631da177e4SLinus Torvalds } 3641da177e4SLinus Torvalds if (curridx == hp_sdc.wcurr) { /* There's nothing queued to do. */ 3651da177e4SLinus Torvalds curridx = -1; 3661da177e4SLinus Torvalds } 3671da177e4SLinus Torvalds hp_sdc.wcurr = curridx; 3681da177e4SLinus Torvalds 3691da177e4SLinus Torvalds start: 3701da177e4SLinus Torvalds 3711da177e4SLinus Torvalds /* Check to see if the interrupt mask needs to be set. */ 3721da177e4SLinus Torvalds if (hp_sdc.set_im) { 3731da177e4SLinus Torvalds hp_sdc_status_out8(hp_sdc.im | HP_SDC_CMD_SET_IM); 3741da177e4SLinus Torvalds hp_sdc.set_im = 0; 3751da177e4SLinus Torvalds goto finish; 3761da177e4SLinus Torvalds } 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds if (hp_sdc.wcurr == -1) goto done; 3791da177e4SLinus Torvalds 3801da177e4SLinus Torvalds curr = hp_sdc.tq[curridx]; 3811da177e4SLinus Torvalds idx = curr->actidx; 3821da177e4SLinus Torvalds 3831da177e4SLinus Torvalds if (curr->actidx >= curr->endidx) { 3841da177e4SLinus Torvalds hp_sdc.tq[curridx] = NULL; 3851da177e4SLinus Torvalds /* Interleave outbound data between the transactions. */ 3861da177e4SLinus Torvalds hp_sdc.wcurr++; 3871da177e4SLinus Torvalds if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0; 3881da177e4SLinus Torvalds goto finish; 3891da177e4SLinus Torvalds } 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds act = curr->seq[idx]; 3921da177e4SLinus Torvalds idx++; 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds if (curr->idx >= curr->endidx) { 3951da177e4SLinus Torvalds if (act & HP_SDC_ACT_DEALLOC) kfree(curr); 3961da177e4SLinus Torvalds hp_sdc.tq[curridx] = NULL; 3971da177e4SLinus Torvalds /* Interleave outbound data between the transactions. */ 3981da177e4SLinus Torvalds hp_sdc.wcurr++; 3991da177e4SLinus Torvalds if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0; 4001da177e4SLinus Torvalds goto finish; 4011da177e4SLinus Torvalds } 4021da177e4SLinus Torvalds 4031da177e4SLinus Torvalds while (act & HP_SDC_ACT_PRECMD) { 4041da177e4SLinus Torvalds if (curr->idx != idx) { 4051da177e4SLinus Torvalds idx++; 4061da177e4SLinus Torvalds act &= ~HP_SDC_ACT_PRECMD; 4071da177e4SLinus Torvalds break; 4081da177e4SLinus Torvalds } 4091da177e4SLinus Torvalds hp_sdc_status_out8(curr->seq[idx]); 4101da177e4SLinus Torvalds curr->idx++; 4111da177e4SLinus Torvalds /* act finished? */ 4121da177e4SLinus Torvalds if ((act & HP_SDC_ACT_DURING) == HP_SDC_ACT_PRECMD) 4131da177e4SLinus Torvalds goto actdone; 4141da177e4SLinus Torvalds /* skip quantity field if data-out sequence follows. */ 4151da177e4SLinus Torvalds if (act & HP_SDC_ACT_DATAOUT) curr->idx++; 4161da177e4SLinus Torvalds goto finish; 4171da177e4SLinus Torvalds } 4181da177e4SLinus Torvalds if (act & HP_SDC_ACT_DATAOUT) { 4191da177e4SLinus Torvalds int qty; 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvalds qty = curr->seq[idx]; 4221da177e4SLinus Torvalds idx++; 4231da177e4SLinus Torvalds if (curr->idx - idx < qty) { 4241da177e4SLinus Torvalds hp_sdc_data_out8(curr->seq[curr->idx]); 4251da177e4SLinus Torvalds curr->idx++; 4261da177e4SLinus Torvalds /* act finished? */ 4271da177e4SLinus Torvalds if ((curr->idx - idx >= qty) && 4281da177e4SLinus Torvalds ((act & HP_SDC_ACT_DURING) == HP_SDC_ACT_DATAOUT)) 4291da177e4SLinus Torvalds goto actdone; 4301da177e4SLinus Torvalds goto finish; 4311da177e4SLinus Torvalds } 4321da177e4SLinus Torvalds idx += qty; 4331da177e4SLinus Torvalds act &= ~HP_SDC_ACT_DATAOUT; 4341da177e4SLinus Torvalds } 4351da177e4SLinus Torvalds else while (act & HP_SDC_ACT_DATAREG) { 4361da177e4SLinus Torvalds int mask; 4371da177e4SLinus Torvalds uint8_t w7[4]; 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds mask = curr->seq[idx]; 4401da177e4SLinus Torvalds if (idx != curr->idx) { 4411da177e4SLinus Torvalds idx++; 4421da177e4SLinus Torvalds idx += !!(mask & 1); 4431da177e4SLinus Torvalds idx += !!(mask & 2); 4441da177e4SLinus Torvalds idx += !!(mask & 4); 4451da177e4SLinus Torvalds idx += !!(mask & 8); 4461da177e4SLinus Torvalds act &= ~HP_SDC_ACT_DATAREG; 4471da177e4SLinus Torvalds break; 4481da177e4SLinus Torvalds } 4491da177e4SLinus Torvalds 4501da177e4SLinus Torvalds w7[0] = (mask & 1) ? curr->seq[++idx] : hp_sdc.r7[0]; 4511da177e4SLinus Torvalds w7[1] = (mask & 2) ? curr->seq[++idx] : hp_sdc.r7[1]; 4521da177e4SLinus Torvalds w7[2] = (mask & 4) ? curr->seq[++idx] : hp_sdc.r7[2]; 4531da177e4SLinus Torvalds w7[3] = (mask & 8) ? curr->seq[++idx] : hp_sdc.r7[3]; 4541da177e4SLinus Torvalds 4551da177e4SLinus Torvalds if (hp_sdc.wi > 0x73 || hp_sdc.wi < 0x70 || 4561da177e4SLinus Torvalds w7[hp_sdc.wi-0x70] == hp_sdc.r7[hp_sdc.wi-0x70]) { 4571da177e4SLinus Torvalds int i = 0; 4581da177e4SLinus Torvalds 4591da177e4SLinus Torvalds /* Need to point the write index register */ 4601da177e4SLinus Torvalds while ((i < 4) && w7[i] == hp_sdc.r7[i]) i++; 4611da177e4SLinus Torvalds if (i < 4) { 4621da177e4SLinus Torvalds hp_sdc_status_out8(HP_SDC_CMD_SET_D0 + i); 4631da177e4SLinus Torvalds hp_sdc.wi = 0x70 + i; 4641da177e4SLinus Torvalds goto finish; 4651da177e4SLinus Torvalds } 4661da177e4SLinus Torvalds idx++; 4671da177e4SLinus Torvalds if ((act & HP_SDC_ACT_DURING) == HP_SDC_ACT_DATAREG) 4681da177e4SLinus Torvalds goto actdone; 4691da177e4SLinus Torvalds curr->idx = idx; 4701da177e4SLinus Torvalds act &= ~HP_SDC_ACT_DATAREG; 4711da177e4SLinus Torvalds break; 4721da177e4SLinus Torvalds } 4731da177e4SLinus Torvalds 4741da177e4SLinus Torvalds hp_sdc_data_out8(w7[hp_sdc.wi - 0x70]); 4751da177e4SLinus Torvalds hp_sdc.r7[hp_sdc.wi - 0x70] = w7[hp_sdc.wi - 0x70]; 4761da177e4SLinus Torvalds hp_sdc.wi++; /* write index register autoincrements */ 4771da177e4SLinus Torvalds { 4781da177e4SLinus Torvalds int i = 0; 4791da177e4SLinus Torvalds 4801da177e4SLinus Torvalds while ((i < 4) && w7[i] == hp_sdc.r7[i]) i++; 4811da177e4SLinus Torvalds if (i >= 4) { 4821da177e4SLinus Torvalds curr->idx = idx + 1; 4831da177e4SLinus Torvalds if ((act & HP_SDC_ACT_DURING) == 4841da177e4SLinus Torvalds HP_SDC_ACT_DATAREG) 4851da177e4SLinus Torvalds goto actdone; 4861da177e4SLinus Torvalds } 4871da177e4SLinus Torvalds } 4881da177e4SLinus Torvalds goto finish; 4891da177e4SLinus Torvalds } 4901da177e4SLinus Torvalds /* We don't go any further in the command if there is a pending read, 4911da177e4SLinus Torvalds because we don't want interleaved results. */ 4921da177e4SLinus Torvalds read_lock_irq(&hp_sdc.rtq_lock); 4931da177e4SLinus Torvalds if (hp_sdc.rcurr >= 0) { 4941da177e4SLinus Torvalds read_unlock_irq(&hp_sdc.rtq_lock); 4951da177e4SLinus Torvalds goto finish; 4961da177e4SLinus Torvalds } 4971da177e4SLinus Torvalds read_unlock_irq(&hp_sdc.rtq_lock); 4981da177e4SLinus Torvalds 4991da177e4SLinus Torvalds 5001da177e4SLinus Torvalds if (act & HP_SDC_ACT_POSTCMD) { 5011da177e4SLinus Torvalds uint8_t postcmd; 5021da177e4SLinus Torvalds 5031da177e4SLinus Torvalds /* curr->idx should == idx at this point. */ 5041da177e4SLinus Torvalds postcmd = curr->seq[idx]; 5051da177e4SLinus Torvalds curr->idx++; 5061da177e4SLinus Torvalds if (act & HP_SDC_ACT_DATAIN) { 5071da177e4SLinus Torvalds 5081da177e4SLinus Torvalds /* Start a new read */ 5091da177e4SLinus Torvalds hp_sdc.rqty = curr->seq[curr->idx]; 5101da177e4SLinus Torvalds do_gettimeofday(&hp_sdc.rtv); 5111da177e4SLinus Torvalds curr->idx++; 5121da177e4SLinus Torvalds /* Still need to lock here in case of spurious irq. */ 5131da177e4SLinus Torvalds write_lock_irq(&hp_sdc.rtq_lock); 5141da177e4SLinus Torvalds hp_sdc.rcurr = curridx; 5151da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.rtq_lock); 5161da177e4SLinus Torvalds hp_sdc_status_out8(postcmd); 5171da177e4SLinus Torvalds goto finish; 5181da177e4SLinus Torvalds } 5191da177e4SLinus Torvalds hp_sdc_status_out8(postcmd); 5201da177e4SLinus Torvalds goto actdone; 5211da177e4SLinus Torvalds } 5221da177e4SLinus Torvalds 5231da177e4SLinus Torvalds actdone: 5241da177e4SLinus Torvalds if (act & HP_SDC_ACT_SEMAPHORE) { 5251da177e4SLinus Torvalds up(curr->act.semaphore); 5261da177e4SLinus Torvalds } 5271da177e4SLinus Torvalds else if (act & HP_SDC_ACT_CALLBACK) { 5281da177e4SLinus Torvalds curr->act.irqhook(0,0,0,0); 5291da177e4SLinus Torvalds } 5301da177e4SLinus Torvalds if (curr->idx >= curr->endidx) { /* This transaction is over. */ 5311da177e4SLinus Torvalds if (act & HP_SDC_ACT_DEALLOC) kfree(curr); 5321da177e4SLinus Torvalds hp_sdc.tq[curridx] = NULL; 5331da177e4SLinus Torvalds } 5341da177e4SLinus Torvalds else { 5351da177e4SLinus Torvalds curr->actidx = idx + 1; 5361da177e4SLinus Torvalds curr->idx = idx + 2; 5371da177e4SLinus Torvalds } 5381da177e4SLinus Torvalds /* Interleave outbound data between the transactions. */ 5391da177e4SLinus Torvalds hp_sdc.wcurr++; 5401da177e4SLinus Torvalds if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0; 5411da177e4SLinus Torvalds 5421da177e4SLinus Torvalds finish: 5431da177e4SLinus Torvalds /* If by some quirk IBF has cleared and our ISR has run to 5441da177e4SLinus Torvalds see that that has happened, do it all again. */ 5451da177e4SLinus Torvalds if (!hp_sdc.ibf && limit++ < 20) goto anew; 5461da177e4SLinus Torvalds 5471da177e4SLinus Torvalds done: 5481da177e4SLinus Torvalds if (hp_sdc.wcurr >= 0) tasklet_schedule(&hp_sdc.task); 5491da177e4SLinus Torvalds write_unlock(&hp_sdc.lock); 5501da177e4SLinus Torvalds return 0; 5511da177e4SLinus Torvalds } 5521da177e4SLinus Torvalds 5531da177e4SLinus Torvalds /******* Functions called in either user or kernel context ****/ 5541da177e4SLinus Torvalds int hp_sdc_enqueue_transaction(hp_sdc_transaction *this) { 5551da177e4SLinus Torvalds unsigned long flags; 5561da177e4SLinus Torvalds int i; 5571da177e4SLinus Torvalds 5581da177e4SLinus Torvalds if (this == NULL) { 5591da177e4SLinus Torvalds tasklet_schedule(&hp_sdc.task); 5601da177e4SLinus Torvalds return -EINVAL; 5611da177e4SLinus Torvalds }; 5621da177e4SLinus Torvalds 5631da177e4SLinus Torvalds write_lock_irqsave(&hp_sdc.lock, flags); 5641da177e4SLinus Torvalds 5651da177e4SLinus Torvalds /* Can't have same transaction on queue twice */ 5661da177e4SLinus Torvalds for (i=0; i < HP_SDC_QUEUE_LEN; i++) 5671da177e4SLinus Torvalds if (hp_sdc.tq[i] == this) goto fail; 5681da177e4SLinus Torvalds 5691da177e4SLinus Torvalds this->actidx = 0; 5701da177e4SLinus Torvalds this->idx = 1; 5711da177e4SLinus Torvalds 5721da177e4SLinus Torvalds /* Search for empty slot */ 5731da177e4SLinus Torvalds for (i=0; i < HP_SDC_QUEUE_LEN; i++) { 5741da177e4SLinus Torvalds if (hp_sdc.tq[i] == NULL) { 5751da177e4SLinus Torvalds hp_sdc.tq[i] = this; 5761da177e4SLinus Torvalds write_unlock_irqrestore(&hp_sdc.lock, flags); 5771da177e4SLinus Torvalds tasklet_schedule(&hp_sdc.task); 5781da177e4SLinus Torvalds return 0; 5791da177e4SLinus Torvalds } 5801da177e4SLinus Torvalds } 5811da177e4SLinus Torvalds write_unlock_irqrestore(&hp_sdc.lock, flags); 5821da177e4SLinus Torvalds printk(KERN_WARNING PREFIX "No free slot to add transaction.\n"); 5831da177e4SLinus Torvalds return -EBUSY; 5841da177e4SLinus Torvalds 5851da177e4SLinus Torvalds fail: 5861da177e4SLinus Torvalds write_unlock_irqrestore(&hp_sdc.lock,flags); 5871da177e4SLinus Torvalds printk(KERN_WARNING PREFIX "Transaction add failed: transaction already queued?\n"); 5881da177e4SLinus Torvalds return -EINVAL; 5891da177e4SLinus Torvalds } 5901da177e4SLinus Torvalds 5911da177e4SLinus Torvalds int hp_sdc_dequeue_transaction(hp_sdc_transaction *this) { 5921da177e4SLinus Torvalds unsigned long flags; 5931da177e4SLinus Torvalds int i; 5941da177e4SLinus Torvalds 5951da177e4SLinus Torvalds write_lock_irqsave(&hp_sdc.lock, flags); 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds /* TODO: don't remove it if it's not done. */ 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds for (i=0; i < HP_SDC_QUEUE_LEN; i++) 6001da177e4SLinus Torvalds if (hp_sdc.tq[i] == this) hp_sdc.tq[i] = NULL; 6011da177e4SLinus Torvalds 6021da177e4SLinus Torvalds write_unlock_irqrestore(&hp_sdc.lock, flags); 6031da177e4SLinus Torvalds return 0; 6041da177e4SLinus Torvalds } 6051da177e4SLinus Torvalds 6061da177e4SLinus Torvalds 6071da177e4SLinus Torvalds 6081da177e4SLinus Torvalds /********************** User context functions **************************/ 6091da177e4SLinus Torvalds int hp_sdc_request_timer_irq(hp_sdc_irqhook *callback) { 6101da177e4SLinus Torvalds 6111da177e4SLinus Torvalds if (callback == NULL || hp_sdc.dev == NULL) { 6121da177e4SLinus Torvalds return -EINVAL; 6131da177e4SLinus Torvalds } 6141da177e4SLinus Torvalds write_lock_irq(&hp_sdc.hook_lock); 6151da177e4SLinus Torvalds if (hp_sdc.timer != NULL) { 6161da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.hook_lock); 6171da177e4SLinus Torvalds return -EBUSY; 6181da177e4SLinus Torvalds } 6191da177e4SLinus Torvalds 6201da177e4SLinus Torvalds hp_sdc.timer = callback; 6211da177e4SLinus Torvalds /* Enable interrupts from the timers */ 6221da177e4SLinus Torvalds hp_sdc.im &= ~HP_SDC_IM_FH; 6231da177e4SLinus Torvalds hp_sdc.im &= ~HP_SDC_IM_PT; 6241da177e4SLinus Torvalds hp_sdc.im &= ~HP_SDC_IM_TIMERS; 6251da177e4SLinus Torvalds hp_sdc.set_im = 1; 6261da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.hook_lock); 6271da177e4SLinus Torvalds 6281da177e4SLinus Torvalds tasklet_schedule(&hp_sdc.task); 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds return 0; 6311da177e4SLinus Torvalds } 6321da177e4SLinus Torvalds 6331da177e4SLinus Torvalds int hp_sdc_request_hil_irq(hp_sdc_irqhook *callback) { 6341da177e4SLinus Torvalds 6351da177e4SLinus Torvalds if (callback == NULL || hp_sdc.dev == NULL) { 6361da177e4SLinus Torvalds return -EINVAL; 6371da177e4SLinus Torvalds } 6381da177e4SLinus Torvalds write_lock_irq(&hp_sdc.hook_lock); 6391da177e4SLinus Torvalds if (hp_sdc.hil != NULL) { 6401da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.hook_lock); 6411da177e4SLinus Torvalds return -EBUSY; 6421da177e4SLinus Torvalds } 6431da177e4SLinus Torvalds 6441da177e4SLinus Torvalds hp_sdc.hil = callback; 6451da177e4SLinus Torvalds hp_sdc.im &= ~(HP_SDC_IM_HIL | HP_SDC_IM_RESET); 6461da177e4SLinus Torvalds hp_sdc.set_im = 1; 6471da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.hook_lock); 6481da177e4SLinus Torvalds 6491da177e4SLinus Torvalds tasklet_schedule(&hp_sdc.task); 6501da177e4SLinus Torvalds 6511da177e4SLinus Torvalds return 0; 6521da177e4SLinus Torvalds } 6531da177e4SLinus Torvalds 6541da177e4SLinus Torvalds int hp_sdc_request_cooked_irq(hp_sdc_irqhook *callback) { 6551da177e4SLinus Torvalds 6561da177e4SLinus Torvalds if (callback == NULL || hp_sdc.dev == NULL) { 6571da177e4SLinus Torvalds return -EINVAL; 6581da177e4SLinus Torvalds } 6591da177e4SLinus Torvalds write_lock_irq(&hp_sdc.hook_lock); 6601da177e4SLinus Torvalds if (hp_sdc.cooked != NULL) { 6611da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.hook_lock); 6621da177e4SLinus Torvalds return -EBUSY; 6631da177e4SLinus Torvalds } 6641da177e4SLinus Torvalds 6651da177e4SLinus Torvalds /* Enable interrupts from the HIL MLC */ 6661da177e4SLinus Torvalds hp_sdc.cooked = callback; 6671da177e4SLinus Torvalds hp_sdc.im &= ~(HP_SDC_IM_HIL | HP_SDC_IM_RESET); 6681da177e4SLinus Torvalds hp_sdc.set_im = 1; 6691da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.hook_lock); 6701da177e4SLinus Torvalds 6711da177e4SLinus Torvalds tasklet_schedule(&hp_sdc.task); 6721da177e4SLinus Torvalds 6731da177e4SLinus Torvalds return 0; 6741da177e4SLinus Torvalds } 6751da177e4SLinus Torvalds 6761da177e4SLinus Torvalds int hp_sdc_release_timer_irq(hp_sdc_irqhook *callback) { 6771da177e4SLinus Torvalds 6781da177e4SLinus Torvalds 6791da177e4SLinus Torvalds write_lock_irq(&hp_sdc.hook_lock); 6801da177e4SLinus Torvalds if ((callback != hp_sdc.timer) || 6811da177e4SLinus Torvalds (hp_sdc.timer == NULL)) { 6821da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.hook_lock); 6831da177e4SLinus Torvalds return -EINVAL; 6841da177e4SLinus Torvalds } 6851da177e4SLinus Torvalds 6861da177e4SLinus Torvalds /* Disable interrupts from the timers */ 6871da177e4SLinus Torvalds hp_sdc.timer = NULL; 6881da177e4SLinus Torvalds hp_sdc.im |= HP_SDC_IM_TIMERS; 6891da177e4SLinus Torvalds hp_sdc.im |= HP_SDC_IM_FH; 6901da177e4SLinus Torvalds hp_sdc.im |= HP_SDC_IM_PT; 6911da177e4SLinus Torvalds hp_sdc.set_im = 1; 6921da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.hook_lock); 6931da177e4SLinus Torvalds tasklet_schedule(&hp_sdc.task); 6941da177e4SLinus Torvalds 6951da177e4SLinus Torvalds return 0; 6961da177e4SLinus Torvalds } 6971da177e4SLinus Torvalds 6981da177e4SLinus Torvalds int hp_sdc_release_hil_irq(hp_sdc_irqhook *callback) { 6991da177e4SLinus Torvalds 7001da177e4SLinus Torvalds write_lock_irq(&hp_sdc.hook_lock); 7011da177e4SLinus Torvalds if ((callback != hp_sdc.hil) || 7021da177e4SLinus Torvalds (hp_sdc.hil == NULL)) { 7031da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.hook_lock); 7041da177e4SLinus Torvalds return -EINVAL; 7051da177e4SLinus Torvalds } 7061da177e4SLinus Torvalds 7071da177e4SLinus Torvalds hp_sdc.hil = NULL; 7081da177e4SLinus Torvalds /* Disable interrupts from HIL only if there is no cooked driver. */ 7091da177e4SLinus Torvalds if(hp_sdc.cooked == NULL) { 7101da177e4SLinus Torvalds hp_sdc.im |= (HP_SDC_IM_HIL | HP_SDC_IM_RESET); 7111da177e4SLinus Torvalds hp_sdc.set_im = 1; 7121da177e4SLinus Torvalds } 7131da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.hook_lock); 7141da177e4SLinus Torvalds tasklet_schedule(&hp_sdc.task); 7151da177e4SLinus Torvalds 7161da177e4SLinus Torvalds return 0; 7171da177e4SLinus Torvalds } 7181da177e4SLinus Torvalds 7191da177e4SLinus Torvalds int hp_sdc_release_cooked_irq(hp_sdc_irqhook *callback) { 7201da177e4SLinus Torvalds 7211da177e4SLinus Torvalds write_lock_irq(&hp_sdc.hook_lock); 7221da177e4SLinus Torvalds if ((callback != hp_sdc.cooked) || 7231da177e4SLinus Torvalds (hp_sdc.cooked == NULL)) { 7241da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.hook_lock); 7251da177e4SLinus Torvalds return -EINVAL; 7261da177e4SLinus Torvalds } 7271da177e4SLinus Torvalds 7281da177e4SLinus Torvalds hp_sdc.cooked = NULL; 7291da177e4SLinus Torvalds /* Disable interrupts from HIL only if there is no raw HIL driver. */ 7301da177e4SLinus Torvalds if(hp_sdc.hil == NULL) { 7311da177e4SLinus Torvalds hp_sdc.im |= (HP_SDC_IM_HIL | HP_SDC_IM_RESET); 7321da177e4SLinus Torvalds hp_sdc.set_im = 1; 7331da177e4SLinus Torvalds } 7341da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.hook_lock); 7351da177e4SLinus Torvalds tasklet_schedule(&hp_sdc.task); 7361da177e4SLinus Torvalds 7371da177e4SLinus Torvalds return 0; 7381da177e4SLinus Torvalds } 7391da177e4SLinus Torvalds 7401da177e4SLinus Torvalds /************************* Keepalive timer task *********************/ 7411da177e4SLinus Torvalds 7421da177e4SLinus Torvalds void hp_sdc_kicker (unsigned long data) { 7431da177e4SLinus Torvalds tasklet_schedule(&hp_sdc.task); 7441da177e4SLinus Torvalds /* Re-insert the periodic task. */ 7451da177e4SLinus Torvalds mod_timer(&hp_sdc.kicker, jiffies + HZ); 7461da177e4SLinus Torvalds } 7471da177e4SLinus Torvalds 7481da177e4SLinus Torvalds /************************** Module Initialization ***************************/ 7491da177e4SLinus Torvalds 7501da177e4SLinus Torvalds #if defined(__hppa__) 7511da177e4SLinus Torvalds 7521da177e4SLinus Torvalds static struct parisc_device_id hp_sdc_tbl[] = { 7531da177e4SLinus Torvalds { 7541da177e4SLinus Torvalds .hw_type = HPHW_FIO, 7551da177e4SLinus Torvalds .hversion_rev = HVERSION_REV_ANY_ID, 7561da177e4SLinus Torvalds .hversion = HVERSION_ANY_ID, 7571da177e4SLinus Torvalds .sversion = 0x73, 7581da177e4SLinus Torvalds }, 7591da177e4SLinus Torvalds { 0, } 7601da177e4SLinus Torvalds }; 7611da177e4SLinus Torvalds 7621da177e4SLinus Torvalds MODULE_DEVICE_TABLE(parisc, hp_sdc_tbl); 7631da177e4SLinus Torvalds 7641da177e4SLinus Torvalds static int __init hp_sdc_init_hppa(struct parisc_device *d); 7651da177e4SLinus Torvalds 7661da177e4SLinus Torvalds static struct parisc_driver hp_sdc_driver = { 767*bdad1f83SMatthew Wilcox .name = "hp_sdc", 7681da177e4SLinus Torvalds .id_table = hp_sdc_tbl, 7691da177e4SLinus Torvalds .probe = hp_sdc_init_hppa, 7701da177e4SLinus Torvalds }; 7711da177e4SLinus Torvalds 7721da177e4SLinus Torvalds #endif /* __hppa__ */ 7731da177e4SLinus Torvalds 7741da177e4SLinus Torvalds static int __init hp_sdc_init(void) 7751da177e4SLinus Torvalds { 7761da177e4SLinus Torvalds int i; 7771da177e4SLinus Torvalds char *errstr; 7781da177e4SLinus Torvalds hp_sdc_transaction t_sync; 7791da177e4SLinus Torvalds uint8_t ts_sync[6]; 7801da177e4SLinus Torvalds struct semaphore s_sync; 7811da177e4SLinus Torvalds 7821da177e4SLinus Torvalds rwlock_init(&hp_sdc.lock); 7831da177e4SLinus Torvalds rwlock_init(&hp_sdc.ibf_lock); 7841da177e4SLinus Torvalds rwlock_init(&hp_sdc.rtq_lock); 7851da177e4SLinus Torvalds rwlock_init(&hp_sdc.hook_lock); 7861da177e4SLinus Torvalds 7871da177e4SLinus Torvalds hp_sdc.timer = NULL; 7881da177e4SLinus Torvalds hp_sdc.hil = NULL; 7891da177e4SLinus Torvalds hp_sdc.pup = NULL; 7901da177e4SLinus Torvalds hp_sdc.cooked = NULL; 7911da177e4SLinus Torvalds hp_sdc.im = HP_SDC_IM_MASK; /* Mask maskable irqs */ 7921da177e4SLinus Torvalds hp_sdc.set_im = 1; 7931da177e4SLinus Torvalds hp_sdc.wi = 0xff; 7941da177e4SLinus Torvalds hp_sdc.r7[0] = 0xff; 7951da177e4SLinus Torvalds hp_sdc.r7[1] = 0xff; 7961da177e4SLinus Torvalds hp_sdc.r7[2] = 0xff; 7971da177e4SLinus Torvalds hp_sdc.r7[3] = 0xff; 7981da177e4SLinus Torvalds hp_sdc.ibf = 1; 7991da177e4SLinus Torvalds 8001da177e4SLinus Torvalds for (i = 0; i < HP_SDC_QUEUE_LEN; i++) hp_sdc.tq[i] = NULL; 8011da177e4SLinus Torvalds hp_sdc.wcurr = -1; 8021da177e4SLinus Torvalds hp_sdc.rcurr = -1; 8031da177e4SLinus Torvalds hp_sdc.rqty = 0; 8041da177e4SLinus Torvalds 8051da177e4SLinus Torvalds hp_sdc.dev_err = -ENODEV; 8061da177e4SLinus Torvalds 8071da177e4SLinus Torvalds errstr = "IO not found for"; 8081da177e4SLinus Torvalds if (!hp_sdc.base_io) goto err0; 8091da177e4SLinus Torvalds 8101da177e4SLinus Torvalds errstr = "IRQ not found for"; 8111da177e4SLinus Torvalds if (!hp_sdc.irq) goto err0; 8121da177e4SLinus Torvalds 8131da177e4SLinus Torvalds hp_sdc.dev_err = -EBUSY; 8141da177e4SLinus Torvalds 8151da177e4SLinus Torvalds #if defined(__hppa__) 8161da177e4SLinus Torvalds errstr = "IO not available for"; 8171da177e4SLinus Torvalds if (request_region(hp_sdc.data_io, 2, hp_sdc_driver.name)) goto err0; 8181da177e4SLinus Torvalds #endif 8191da177e4SLinus Torvalds 8201da177e4SLinus Torvalds errstr = "IRQ not available for"; 8211da177e4SLinus Torvalds if(request_irq(hp_sdc.irq, &hp_sdc_isr, 0, "HP SDC", 8221da177e4SLinus Torvalds (void *) hp_sdc.base_io)) goto err1; 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds errstr = "NMI not available for"; 8251da177e4SLinus Torvalds if (request_irq(hp_sdc.nmi, &hp_sdc_nmisr, 0, "HP SDC NMI", 8261da177e4SLinus Torvalds (void *) hp_sdc.base_io)) goto err2; 8271da177e4SLinus Torvalds 8281da177e4SLinus Torvalds printk(KERN_INFO PREFIX "HP SDC at 0x%p, IRQ %d (NMI IRQ %d)\n", 8291da177e4SLinus Torvalds (void *)hp_sdc.base_io, hp_sdc.irq, hp_sdc.nmi); 8301da177e4SLinus Torvalds 8311da177e4SLinus Torvalds hp_sdc_status_in8(); 8321da177e4SLinus Torvalds hp_sdc_data_in8(); 8331da177e4SLinus Torvalds 8341da177e4SLinus Torvalds tasklet_init(&hp_sdc.task, hp_sdc_tasklet, 0); 8351da177e4SLinus Torvalds 8361da177e4SLinus Torvalds /* Sync the output buffer registers, thus scheduling hp_sdc_tasklet. */ 8371da177e4SLinus Torvalds t_sync.actidx = 0; 8381da177e4SLinus Torvalds t_sync.idx = 1; 8391da177e4SLinus Torvalds t_sync.endidx = 6; 8401da177e4SLinus Torvalds t_sync.seq = ts_sync; 8411da177e4SLinus Torvalds ts_sync[0] = HP_SDC_ACT_DATAREG | HP_SDC_ACT_SEMAPHORE; 8421da177e4SLinus Torvalds ts_sync[1] = 0x0f; 8431da177e4SLinus Torvalds ts_sync[2] = ts_sync[3] = ts_sync[4] = ts_sync[5] = 0; 8441da177e4SLinus Torvalds t_sync.act.semaphore = &s_sync; 8451da177e4SLinus Torvalds init_MUTEX_LOCKED(&s_sync); 8461da177e4SLinus Torvalds hp_sdc_enqueue_transaction(&t_sync); 8471da177e4SLinus Torvalds down(&s_sync); /* Wait for t_sync to complete */ 8481da177e4SLinus Torvalds 8491da177e4SLinus Torvalds /* Create the keepalive task */ 8501da177e4SLinus Torvalds init_timer(&hp_sdc.kicker); 8511da177e4SLinus Torvalds hp_sdc.kicker.expires = jiffies + HZ; 8521da177e4SLinus Torvalds hp_sdc.kicker.function = &hp_sdc_kicker; 8531da177e4SLinus Torvalds add_timer(&hp_sdc.kicker); 8541da177e4SLinus Torvalds 8551da177e4SLinus Torvalds hp_sdc.dev_err = 0; 8561da177e4SLinus Torvalds return 0; 8571da177e4SLinus Torvalds err2: 8581da177e4SLinus Torvalds free_irq(hp_sdc.irq, NULL); 8591da177e4SLinus Torvalds err1: 8601da177e4SLinus Torvalds release_region(hp_sdc.data_io, 2); 8611da177e4SLinus Torvalds err0: 8621da177e4SLinus Torvalds printk(KERN_WARNING PREFIX ": %s SDC IO=0x%p IRQ=0x%x NMI=0x%x\n", 8631da177e4SLinus Torvalds errstr, (void *)hp_sdc.base_io, hp_sdc.irq, hp_sdc.nmi); 8641da177e4SLinus Torvalds hp_sdc.dev = NULL; 8651da177e4SLinus Torvalds return hp_sdc.dev_err; 8661da177e4SLinus Torvalds } 8671da177e4SLinus Torvalds 8681da177e4SLinus Torvalds #if defined(__hppa__) 8691da177e4SLinus Torvalds 8701da177e4SLinus Torvalds static int __init hp_sdc_init_hppa(struct parisc_device *d) 8711da177e4SLinus Torvalds { 8721da177e4SLinus Torvalds if (!d) return 1; 8731da177e4SLinus Torvalds if (hp_sdc.dev != NULL) return 1; /* We only expect one SDC */ 8741da177e4SLinus Torvalds 8751da177e4SLinus Torvalds hp_sdc.dev = d; 8761da177e4SLinus Torvalds hp_sdc.irq = d->irq; 8771da177e4SLinus Torvalds hp_sdc.nmi = d->aux_irq; 8781da177e4SLinus Torvalds hp_sdc.base_io = d->hpa; 8791da177e4SLinus Torvalds hp_sdc.data_io = d->hpa + 0x800; 8801da177e4SLinus Torvalds hp_sdc.status_io = d->hpa + 0x801; 8811da177e4SLinus Torvalds 8821da177e4SLinus Torvalds return hp_sdc_init(); 8831da177e4SLinus Torvalds } 8841da177e4SLinus Torvalds 8851da177e4SLinus Torvalds #endif /* __hppa__ */ 8861da177e4SLinus Torvalds 8871da177e4SLinus Torvalds #if !defined(__mc68000__) /* Link error on m68k! */ 8881da177e4SLinus Torvalds static void __exit hp_sdc_exit(void) 8891da177e4SLinus Torvalds #else 8901da177e4SLinus Torvalds static void hp_sdc_exit(void) 8911da177e4SLinus Torvalds #endif 8921da177e4SLinus Torvalds { 8931da177e4SLinus Torvalds write_lock_irq(&hp_sdc.lock); 8941da177e4SLinus Torvalds 8951da177e4SLinus Torvalds /* Turn off all maskable "sub-function" irq's. */ 8961da177e4SLinus Torvalds hp_sdc_spin_ibf(); 8971da177e4SLinus Torvalds sdc_writeb(HP_SDC_CMD_SET_IM | HP_SDC_IM_MASK, hp_sdc.status_io); 8981da177e4SLinus Torvalds 8991da177e4SLinus Torvalds /* Wait until we know this has been processed by the i8042 */ 9001da177e4SLinus Torvalds hp_sdc_spin_ibf(); 9011da177e4SLinus Torvalds 9021da177e4SLinus Torvalds free_irq(hp_sdc.nmi, NULL); 9031da177e4SLinus Torvalds free_irq(hp_sdc.irq, NULL); 9041da177e4SLinus Torvalds write_unlock_irq(&hp_sdc.lock); 9051da177e4SLinus Torvalds 9061da177e4SLinus Torvalds del_timer(&hp_sdc.kicker); 9071da177e4SLinus Torvalds 9081da177e4SLinus Torvalds tasklet_kill(&hp_sdc.task); 9091da177e4SLinus Torvalds 9101da177e4SLinus Torvalds /* release_region(hp_sdc.data_io, 2); */ 9111da177e4SLinus Torvalds 9121da177e4SLinus Torvalds #if defined(__hppa__) 9131da177e4SLinus Torvalds if (unregister_parisc_driver(&hp_sdc_driver)) 9141da177e4SLinus Torvalds printk(KERN_WARNING PREFIX "Error unregistering HP SDC"); 9151da177e4SLinus Torvalds #endif 9161da177e4SLinus Torvalds } 9171da177e4SLinus Torvalds 9181da177e4SLinus Torvalds static int __init hp_sdc_register(void) 9191da177e4SLinus Torvalds { 9201da177e4SLinus Torvalds hp_sdc_transaction tq_init; 9211da177e4SLinus Torvalds uint8_t tq_init_seq[5]; 9221da177e4SLinus Torvalds struct semaphore tq_init_sem; 9231da177e4SLinus Torvalds #if defined(__mc68000__) 9241da177e4SLinus Torvalds mm_segment_t fs; 9251da177e4SLinus Torvalds unsigned char i; 9261da177e4SLinus Torvalds #endif 9271da177e4SLinus Torvalds 9281da177e4SLinus Torvalds hp_sdc.dev = NULL; 9291da177e4SLinus Torvalds hp_sdc.dev_err = 0; 9301da177e4SLinus Torvalds #if defined(__hppa__) 9311da177e4SLinus Torvalds if (register_parisc_driver(&hp_sdc_driver)) { 9321da177e4SLinus Torvalds printk(KERN_WARNING PREFIX "Error registering SDC with system bus tree.\n"); 9331da177e4SLinus Torvalds return -ENODEV; 9341da177e4SLinus Torvalds } 9351da177e4SLinus Torvalds #elif defined(__mc68000__) 9361da177e4SLinus Torvalds if (!MACH_IS_HP300) 9371da177e4SLinus Torvalds return -ENODEV; 9381da177e4SLinus Torvalds 9391da177e4SLinus Torvalds hp_sdc.irq = 1; 9401da177e4SLinus Torvalds hp_sdc.nmi = 7; 9411da177e4SLinus Torvalds hp_sdc.base_io = (unsigned long) 0xf0428000; 9421da177e4SLinus Torvalds hp_sdc.data_io = (unsigned long) hp_sdc.base_io + 1; 9431da177e4SLinus Torvalds hp_sdc.status_io = (unsigned long) hp_sdc.base_io + 3; 9441da177e4SLinus Torvalds fs = get_fs(); 9451da177e4SLinus Torvalds set_fs(KERNEL_DS); 9461da177e4SLinus Torvalds if (!get_user(i, (unsigned char *)hp_sdc.data_io)) 9471da177e4SLinus Torvalds hp_sdc.dev = (void *)1; 9481da177e4SLinus Torvalds set_fs(fs); 9491da177e4SLinus Torvalds hp_sdc.dev_err = hp_sdc_init(); 9501da177e4SLinus Torvalds #endif 9511da177e4SLinus Torvalds if (hp_sdc.dev == NULL) { 9521da177e4SLinus Torvalds printk(KERN_WARNING PREFIX "No SDC found.\n"); 9531da177e4SLinus Torvalds return hp_sdc.dev_err; 9541da177e4SLinus Torvalds } 9551da177e4SLinus Torvalds 9561da177e4SLinus Torvalds init_MUTEX_LOCKED(&tq_init_sem); 9571da177e4SLinus Torvalds 9581da177e4SLinus Torvalds tq_init.actidx = 0; 9591da177e4SLinus Torvalds tq_init.idx = 1; 9601da177e4SLinus Torvalds tq_init.endidx = 5; 9611da177e4SLinus Torvalds tq_init.seq = tq_init_seq; 9621da177e4SLinus Torvalds tq_init.act.semaphore = &tq_init_sem; 9631da177e4SLinus Torvalds 9641da177e4SLinus Torvalds tq_init_seq[0] = 9651da177e4SLinus Torvalds HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN | HP_SDC_ACT_SEMAPHORE; 9661da177e4SLinus Torvalds tq_init_seq[1] = HP_SDC_CMD_READ_KCC; 9671da177e4SLinus Torvalds tq_init_seq[2] = 1; 9681da177e4SLinus Torvalds tq_init_seq[3] = 0; 9691da177e4SLinus Torvalds tq_init_seq[4] = 0; 9701da177e4SLinus Torvalds 9711da177e4SLinus Torvalds hp_sdc_enqueue_transaction(&tq_init); 9721da177e4SLinus Torvalds 9731da177e4SLinus Torvalds down(&tq_init_sem); 9741da177e4SLinus Torvalds up(&tq_init_sem); 9751da177e4SLinus Torvalds 9761da177e4SLinus Torvalds if ((tq_init_seq[0] & HP_SDC_ACT_DEAD) == HP_SDC_ACT_DEAD) { 9771da177e4SLinus Torvalds printk(KERN_WARNING PREFIX "Error reading config byte.\n"); 9781da177e4SLinus Torvalds hp_sdc_exit(); 9791da177e4SLinus Torvalds return -ENODEV; 9801da177e4SLinus Torvalds } 9811da177e4SLinus Torvalds hp_sdc.r11 = tq_init_seq[4]; 9821da177e4SLinus Torvalds if (hp_sdc.r11 & HP_SDC_CFG_NEW) { 9831da177e4SLinus Torvalds char *str; 9841da177e4SLinus Torvalds printk(KERN_INFO PREFIX "New style SDC\n"); 9851da177e4SLinus Torvalds tq_init_seq[1] = HP_SDC_CMD_READ_XTD; 9861da177e4SLinus Torvalds tq_init.actidx = 0; 9871da177e4SLinus Torvalds tq_init.idx = 1; 9881da177e4SLinus Torvalds down(&tq_init_sem); 9891da177e4SLinus Torvalds hp_sdc_enqueue_transaction(&tq_init); 9901da177e4SLinus Torvalds down(&tq_init_sem); 9911da177e4SLinus Torvalds up(&tq_init_sem); 9921da177e4SLinus Torvalds if ((tq_init_seq[0] & HP_SDC_ACT_DEAD) == HP_SDC_ACT_DEAD) { 9931da177e4SLinus Torvalds printk(KERN_WARNING PREFIX "Error reading extended config byte.\n"); 9941da177e4SLinus Torvalds return -ENODEV; 9951da177e4SLinus Torvalds } 9961da177e4SLinus Torvalds hp_sdc.r7e = tq_init_seq[4]; 9971da177e4SLinus Torvalds HP_SDC_XTD_REV_STRINGS(hp_sdc.r7e & HP_SDC_XTD_REV, str) 9981da177e4SLinus Torvalds printk(KERN_INFO PREFIX "Revision: %s\n", str); 9991da177e4SLinus Torvalds if (hp_sdc.r7e & HP_SDC_XTD_BEEPER) { 10001da177e4SLinus Torvalds printk(KERN_INFO PREFIX "TI SN76494 beeper present\n"); 10011da177e4SLinus Torvalds } 10021da177e4SLinus Torvalds if (hp_sdc.r7e & HP_SDC_XTD_BBRTC) { 10031da177e4SLinus Torvalds printk(KERN_INFO PREFIX "OKI MSM-58321 BBRTC present\n"); 10041da177e4SLinus Torvalds } 10051da177e4SLinus Torvalds printk(KERN_INFO PREFIX "Spunking the self test register to force PUP " 10061da177e4SLinus Torvalds "on next firmware reset.\n"); 10071da177e4SLinus Torvalds tq_init_seq[0] = HP_SDC_ACT_PRECMD | 10081da177e4SLinus Torvalds HP_SDC_ACT_DATAOUT | HP_SDC_ACT_SEMAPHORE; 10091da177e4SLinus Torvalds tq_init_seq[1] = HP_SDC_CMD_SET_STR; 10101da177e4SLinus Torvalds tq_init_seq[2] = 1; 10111da177e4SLinus Torvalds tq_init_seq[3] = 0; 10121da177e4SLinus Torvalds tq_init.actidx = 0; 10131da177e4SLinus Torvalds tq_init.idx = 1; 10141da177e4SLinus Torvalds tq_init.endidx = 4; 10151da177e4SLinus Torvalds down(&tq_init_sem); 10161da177e4SLinus Torvalds hp_sdc_enqueue_transaction(&tq_init); 10171da177e4SLinus Torvalds down(&tq_init_sem); 10181da177e4SLinus Torvalds up(&tq_init_sem); 10191da177e4SLinus Torvalds } 10201da177e4SLinus Torvalds else { 10211da177e4SLinus Torvalds printk(KERN_INFO PREFIX "Old style SDC (1820-%s).\n", 10221da177e4SLinus Torvalds (hp_sdc.r11 & HP_SDC_CFG_REV) ? "3300" : "2564/3087"); 10231da177e4SLinus Torvalds } 10241da177e4SLinus Torvalds 10251da177e4SLinus Torvalds return 0; 10261da177e4SLinus Torvalds } 10271da177e4SLinus Torvalds 10281da177e4SLinus Torvalds module_init(hp_sdc_register); 10291da177e4SLinus Torvalds module_exit(hp_sdc_exit); 10301da177e4SLinus Torvalds 10311da177e4SLinus Torvalds /* Timing notes: These measurements taken on my 64MHz 7100-LC (715/64) 10321da177e4SLinus Torvalds * cycles cycles-adj time 10331da177e4SLinus Torvalds * between two consecutive mfctl(16)'s: 4 n/a 63ns 10341da177e4SLinus Torvalds * hp_sdc_spin_ibf when idle: 119 115 1.7us 10351da177e4SLinus Torvalds * gsc_writeb status register: 83 79 1.2us 10361da177e4SLinus Torvalds * IBF to clear after sending SET_IM: 6204 6006 93us 10371da177e4SLinus Torvalds * IBF to clear after sending LOAD_RT: 4467 4352 68us 10381da177e4SLinus Torvalds * IBF to clear after sending two LOAD_RTs: 18974 18859 295us 10391da177e4SLinus Torvalds * READ_T1, read status/data, IRQ, call handler: 35564 n/a 556us 10401da177e4SLinus Torvalds * cmd to ~IBF READ_T1 2nd time right after: 5158403 n/a 81ms 10411da177e4SLinus Torvalds * between IRQ received and ~IBF for above: 2578877 n/a 40ms 10421da177e4SLinus Torvalds * 10431da177e4SLinus Torvalds * Performance stats after a run of this module configuring HIL and 10441da177e4SLinus Torvalds * receiving a few mouse events: 10451da177e4SLinus Torvalds * 10461da177e4SLinus Torvalds * status in8 282508 cycles 7128 calls 10471da177e4SLinus Torvalds * status out8 8404 cycles 341 calls 10481da177e4SLinus Torvalds * data out8 1734 cycles 78 calls 10491da177e4SLinus Torvalds * isr 174324 cycles 617 calls (includes take) 10501da177e4SLinus Torvalds * take 1241 cycles 2 calls 10511da177e4SLinus Torvalds * put 1411504 cycles 6937 calls 10521da177e4SLinus Torvalds * task 1655209 cycles 6937 calls (includes put) 10531da177e4SLinus Torvalds * 10541da177e4SLinus Torvalds */ 1055