Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 2 | * Device driver for the Cuda and Egret system controllers found on PowerMacs |
| 3 | * and 68k Macs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 5 | * The Cuda or Egret is a 6805 microcontroller interfaced to the 6522 VIA. |
| 6 | * This MCU controls system power, Parameter RAM, Real Time Clock and the |
| 7 | * Apple Desktop Bus (ADB) that connects to the keyboard and mouse. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * Copyright (C) 1996 Paul Mackerras. |
| 10 | */ |
| 11 | #include <stdarg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/types.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/adb.h> |
| 17 | #include <linux/cuda.h> |
| 18 | #include <linux/spinlock.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #ifdef CONFIG_PPC |
| 21 | #include <asm/prom.h> |
| 22 | #include <asm/machdep.h> |
| 23 | #else |
| 24 | #include <asm/macintosh.h> |
| 25 | #include <asm/macints.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/mac_via.h> |
| 27 | #endif |
| 28 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/init.h> |
| 30 | |
| 31 | static volatile unsigned char __iomem *via; |
| 32 | static DEFINE_SPINLOCK(cuda_lock); |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | /* VIA registers - spaced 0x200 bytes apart */ |
| 35 | #define RS 0x200 /* skip between registers */ |
| 36 | #define B 0 /* B-side data */ |
| 37 | #define A RS /* A-side data */ |
| 38 | #define DIRB (2*RS) /* B-side direction (1=output) */ |
| 39 | #define DIRA (3*RS) /* A-side direction (1=output) */ |
| 40 | #define T1CL (4*RS) /* Timer 1 ctr/latch (low 8 bits) */ |
| 41 | #define T1CH (5*RS) /* Timer 1 counter (high 8 bits) */ |
| 42 | #define T1LL (6*RS) /* Timer 1 latch (low 8 bits) */ |
| 43 | #define T1LH (7*RS) /* Timer 1 latch (high 8 bits) */ |
| 44 | #define T2CL (8*RS) /* Timer 2 ctr/latch (low 8 bits) */ |
| 45 | #define T2CH (9*RS) /* Timer 2 counter (high 8 bits) */ |
| 46 | #define SR (10*RS) /* Shift register */ |
| 47 | #define ACR (11*RS) /* Auxiliary control register */ |
| 48 | #define PCR (12*RS) /* Peripheral control register */ |
| 49 | #define IFR (13*RS) /* Interrupt flag register */ |
| 50 | #define IER (14*RS) /* Interrupt enable register */ |
| 51 | #define ANH (15*RS) /* A-side data, no handshake */ |
| 52 | |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 53 | /* |
| 54 | * When the Cuda design replaced the Egret, some signal names and |
| 55 | * logic sense changed. They all serve the same purposes, however. |
| 56 | * |
| 57 | * VIA pin | Egret pin |
| 58 | * ----------------+------------------------------------------ |
| 59 | * PB3 (input) | Transceiver session (active low) |
| 60 | * PB4 (output) | VIA full (active high) |
| 61 | * PB5 (output) | System session (active high) |
| 62 | * |
| 63 | * VIA pin | Cuda pin |
| 64 | * ----------------+------------------------------------------ |
| 65 | * PB3 (input) | Transfer request (active low) |
| 66 | * PB4 (output) | Byte acknowledge (active low) |
| 67 | * PB5 (output) | Transfer in progress (active low) |
| 68 | */ |
| 69 | |
| 70 | /* Bits in Port B data register */ |
| 71 | #define TREQ 0x08 /* Transfer request */ |
| 72 | #define TACK 0x10 /* Transfer acknowledge */ |
| 73 | #define TIP 0x20 /* Transfer in progress */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | /* Bits in ACR */ |
| 76 | #define SR_CTRL 0x1c /* Shift register control bits */ |
| 77 | #define SR_EXT 0x0c /* Shift on external clock */ |
| 78 | #define SR_OUT 0x10 /* Shift out if 1 */ |
| 79 | |
| 80 | /* Bits in IFR and IER */ |
| 81 | #define IER_SET 0x80 /* set bits in IER */ |
| 82 | #define IER_CLR 0 /* clear bits in IER */ |
| 83 | #define SR_INT 0x04 /* Shift register full/empty */ |
| 84 | |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 85 | /* Duration of byte acknowledgement pulse (us) */ |
| 86 | #define EGRET_TACK_ASSERTED_DELAY 300 |
| 87 | #define EGRET_TACK_NEGATED_DELAY 400 |
| 88 | |
| 89 | /* Interval from interrupt to start of session (us) */ |
| 90 | #define EGRET_SESSION_DELAY 450 |
| 91 | |
| 92 | #ifdef CONFIG_PPC |
| 93 | #define mcu_is_egret false |
| 94 | #else |
| 95 | static bool mcu_is_egret; |
| 96 | #endif |
| 97 | |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 98 | static inline bool TREQ_asserted(u8 portb) |
| 99 | { |
| 100 | return !(portb & TREQ); |
| 101 | } |
| 102 | |
| 103 | static inline void assert_TIP(void) |
| 104 | { |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 105 | if (mcu_is_egret) { |
| 106 | udelay(EGRET_SESSION_DELAY); |
| 107 | out_8(&via[B], in_8(&via[B]) | TIP); |
| 108 | } else |
| 109 | out_8(&via[B], in_8(&via[B]) & ~TIP); |
| 110 | } |
| 111 | |
| 112 | static inline void assert_TIP_and_TACK(void) |
| 113 | { |
| 114 | if (mcu_is_egret) { |
| 115 | udelay(EGRET_SESSION_DELAY); |
| 116 | out_8(&via[B], in_8(&via[B]) | TIP | TACK); |
| 117 | } else |
| 118 | out_8(&via[B], in_8(&via[B]) & ~(TIP | TACK)); |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static inline void assert_TACK(void) |
| 122 | { |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 123 | if (mcu_is_egret) { |
| 124 | udelay(EGRET_TACK_NEGATED_DELAY); |
| 125 | out_8(&via[B], in_8(&via[B]) | TACK); |
| 126 | } else |
| 127 | out_8(&via[B], in_8(&via[B]) & ~TACK); |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static inline void toggle_TACK(void) |
| 131 | { |
| 132 | out_8(&via[B], in_8(&via[B]) ^ TACK); |
| 133 | } |
| 134 | |
| 135 | static inline void negate_TACK(void) |
| 136 | { |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 137 | if (mcu_is_egret) { |
| 138 | udelay(EGRET_TACK_ASSERTED_DELAY); |
| 139 | out_8(&via[B], in_8(&via[B]) & ~TACK); |
| 140 | } else |
| 141 | out_8(&via[B], in_8(&via[B]) | TACK); |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static inline void negate_TIP_and_TACK(void) |
| 145 | { |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 146 | if (mcu_is_egret) { |
| 147 | udelay(EGRET_TACK_ASSERTED_DELAY); |
| 148 | out_8(&via[B], in_8(&via[B]) & ~(TIP | TACK)); |
| 149 | } else |
| 150 | out_8(&via[B], in_8(&via[B]) | TIP | TACK); |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 151 | } |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | static enum cuda_state { |
| 154 | idle, |
| 155 | sent_first_byte, |
| 156 | sending, |
| 157 | reading, |
| 158 | read_done, |
| 159 | awaiting_reply |
| 160 | } cuda_state; |
| 161 | |
| 162 | static struct adb_request *current_req; |
| 163 | static struct adb_request *last_req; |
| 164 | static unsigned char cuda_rbuf[16]; |
| 165 | static unsigned char *reply_ptr; |
| 166 | static int reading_reply; |
| 167 | static int data_index; |
Finn Thain | 0251c38 | 2007-05-01 22:33:00 +0200 | [diff] [blame] | 168 | static int cuda_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | #ifdef CONFIG_PPC |
| 170 | static struct device_node *vias; |
| 171 | #endif |
Olaf Hering | 8727585 | 2007-02-10 21:35:12 +0100 | [diff] [blame] | 172 | static int cuda_fully_inited; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
| 174 | #ifdef CONFIG_ADB |
| 175 | static int cuda_probe(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | static int cuda_send_request(struct adb_request *req, int sync); |
| 177 | static int cuda_adb_autopoll(int devs); |
| 178 | static int cuda_reset_adb_bus(void); |
| 179 | #endif /* CONFIG_ADB */ |
| 180 | |
| 181 | static int cuda_init_via(void); |
| 182 | static void cuda_start(void); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 183 | static irqreturn_t cuda_interrupt(int irq, void *arg); |
| 184 | static void cuda_input(unsigned char *buf, int nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | void cuda_poll(void); |
| 186 | static int cuda_write(struct adb_request *req); |
| 187 | |
| 188 | int cuda_request(struct adb_request *req, |
| 189 | void (*done)(struct adb_request *), int nbytes, ...); |
| 190 | |
| 191 | #ifdef CONFIG_ADB |
| 192 | struct adb_driver via_cuda_driver = { |
Finn Thain | 18814ee | 2009-11-17 20:03:05 +1100 | [diff] [blame] | 193 | .name = "CUDA", |
| 194 | .probe = cuda_probe, |
| 195 | .send_request = cuda_send_request, |
| 196 | .autopoll = cuda_adb_autopoll, |
| 197 | .poll = cuda_poll, |
| 198 | .reset_bus = cuda_reset_adb_bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | }; |
| 200 | #endif /* CONFIG_ADB */ |
| 201 | |
Finn Thain | 18814ee | 2009-11-17 20:03:05 +1100 | [diff] [blame] | 202 | #ifdef CONFIG_MAC |
| 203 | int __init find_via_cuda(void) |
| 204 | { |
| 205 | struct adb_request req; |
| 206 | int err; |
| 207 | |
Finn Thain | f74faec | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 208 | if (macintosh_config->adb_type != MAC_ADB_CUDA && |
| 209 | macintosh_config->adb_type != MAC_ADB_EGRET) |
Finn Thain | 18814ee | 2009-11-17 20:03:05 +1100 | [diff] [blame] | 210 | return 0; |
| 211 | |
| 212 | via = via1; |
| 213 | cuda_state = idle; |
Finn Thain | f74faec | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 214 | mcu_is_egret = macintosh_config->adb_type == MAC_ADB_EGRET; |
Finn Thain | 18814ee | 2009-11-17 20:03:05 +1100 | [diff] [blame] | 215 | |
| 216 | err = cuda_init_via(); |
| 217 | if (err) { |
| 218 | printk(KERN_ERR "cuda_init_via() failed\n"); |
| 219 | via = NULL; |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | /* enable autopoll */ |
| 224 | cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, 1); |
| 225 | while (!req.complete) |
| 226 | cuda_poll(); |
| 227 | |
| 228 | return 1; |
| 229 | } |
| 230 | #else |
Benjamin Herrenschmidt | 51d3082 | 2005-11-23 17:57:25 +1100 | [diff] [blame] | 231 | int __init find_via_cuda(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | struct adb_request req; |
Benjamin Herrenschmidt | 51d3082 | 2005-11-23 17:57:25 +1100 | [diff] [blame] | 234 | phys_addr_t taddr; |
Jeremy Kerr | 018a3d1 | 2006-07-12 15:40:29 +1000 | [diff] [blame] | 235 | const u32 *reg; |
Benjamin Herrenschmidt | 51d3082 | 2005-11-23 17:57:25 +1100 | [diff] [blame] | 236 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | if (vias != 0) |
| 239 | return 1; |
Benjamin Herrenschmidt | 51d3082 | 2005-11-23 17:57:25 +1100 | [diff] [blame] | 240 | vias = of_find_node_by_name(NULL, "via-cuda"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | if (vias == 0) |
| 242 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
Stephen Rothwell | 01b2726 | 2007-04-27 13:41:15 +1000 | [diff] [blame] | 244 | reg = of_get_property(vias, "reg", NULL); |
Benjamin Herrenschmidt | 51d3082 | 2005-11-23 17:57:25 +1100 | [diff] [blame] | 245 | if (reg == NULL) { |
| 246 | printk(KERN_ERR "via-cuda: No \"reg\" property !\n"); |
| 247 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
Benjamin Herrenschmidt | 51d3082 | 2005-11-23 17:57:25 +1100 | [diff] [blame] | 249 | taddr = of_translate_address(vias, reg); |
| 250 | if (taddr == 0) { |
| 251 | printk(KERN_ERR "via-cuda: Can't translate address !\n"); |
| 252 | goto fail; |
| 253 | } |
| 254 | via = ioremap(taddr, 0x2000); |
| 255 | if (via == NULL) { |
| 256 | printk(KERN_ERR "via-cuda: Can't map address !\n"); |
| 257 | goto fail; |
| 258 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
| 260 | cuda_state = idle; |
| 261 | sys_ctrler = SYS_CTRLER_CUDA; |
| 262 | |
| 263 | err = cuda_init_via(); |
| 264 | if (err) { |
| 265 | printk(KERN_ERR "cuda_init_via() failed\n"); |
| 266 | via = NULL; |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | /* Clear and enable interrupts, but only on PPC. On 68K it's done */ |
| 271 | /* for us by the main VIA driver in arch/m68k/mac/via.c */ |
| 272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | out_8(&via[IFR], 0x7f); /* clear interrupts by writing 1s */ |
| 274 | out_8(&via[IER], IER_SET|SR_INT); /* enable interrupt from SR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
| 276 | /* enable autopoll */ |
| 277 | cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, 1); |
| 278 | while (!req.complete) |
| 279 | cuda_poll(); |
| 280 | |
| 281 | return 1; |
Benjamin Herrenschmidt | 51d3082 | 2005-11-23 17:57:25 +1100 | [diff] [blame] | 282 | |
| 283 | fail: |
| 284 | of_node_put(vias); |
| 285 | vias = NULL; |
| 286 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
Finn Thain | 18814ee | 2009-11-17 20:03:05 +1100 | [diff] [blame] | 288 | #endif /* !defined CONFIG_MAC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
| 290 | static int __init via_cuda_start(void) |
| 291 | { |
| 292 | if (via == NULL) |
| 293 | return -ENODEV; |
| 294 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 295 | #ifdef CONFIG_MAC |
Finn Thain | 0251c38 | 2007-05-01 22:33:00 +0200 | [diff] [blame] | 296 | cuda_irq = IRQ_MAC_ADB; |
Finn Thain | 18814ee | 2009-11-17 20:03:05 +1100 | [diff] [blame] | 297 | #else |
Finn Thain | 0251c38 | 2007-05-01 22:33:00 +0200 | [diff] [blame] | 298 | cuda_irq = irq_of_parse_and_map(vias, 0); |
Michael Ellerman | ef24ba7 | 2016-09-06 21:53:24 +1000 | [diff] [blame] | 299 | if (!cuda_irq) { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 300 | printk(KERN_ERR "via-cuda: can't map interrupts for %s\n", |
| 301 | vias->full_name); |
| 302 | return -ENODEV; |
| 303 | } |
Finn Thain | 18814ee | 2009-11-17 20:03:05 +1100 | [diff] [blame] | 304 | #endif |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 305 | |
Finn Thain | 0251c38 | 2007-05-01 22:33:00 +0200 | [diff] [blame] | 306 | if (request_irq(cuda_irq, cuda_interrupt, 0, "ADB", cuda_interrupt)) { |
| 307 | printk(KERN_ERR "via-cuda: can't request irq %d\n", cuda_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | return -EAGAIN; |
| 309 | } |
| 310 | |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 311 | pr_info("Macintosh Cuda and Egret driver.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
| 313 | cuda_fully_inited = 1; |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | device_initcall(via_cuda_start); |
| 318 | |
| 319 | #ifdef CONFIG_ADB |
| 320 | static int |
| 321 | cuda_probe(void) |
| 322 | { |
| 323 | #ifdef CONFIG_PPC |
| 324 | if (sys_ctrler != SYS_CTRLER_CUDA) |
| 325 | return -ENODEV; |
| 326 | #else |
Finn Thain | f74faec | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 327 | if (macintosh_config->adb_type != MAC_ADB_CUDA && |
| 328 | macintosh_config->adb_type != MAC_ADB_EGRET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | if (via == NULL) |
| 332 | return -ENODEV; |
| 333 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | #endif /* CONFIG_ADB */ |
| 336 | |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 337 | static int __init sync_egret(void) |
| 338 | { |
| 339 | if (TREQ_asserted(in_8(&via[B]))) { |
| 340 | /* Complete the inbound transfer */ |
| 341 | assert_TIP_and_TACK(); |
| 342 | while (1) { |
| 343 | negate_TACK(); |
| 344 | mdelay(1); |
| 345 | (void)in_8(&via[SR]); |
| 346 | assert_TACK(); |
| 347 | if (!TREQ_asserted(in_8(&via[B]))) |
| 348 | break; |
| 349 | } |
| 350 | negate_TIP_and_TACK(); |
| 351 | } else if (in_8(&via[B]) & TIP) { |
| 352 | /* Terminate the outbound transfer */ |
| 353 | negate_TACK(); |
| 354 | assert_TACK(); |
| 355 | mdelay(1); |
| 356 | negate_TIP_and_TACK(); |
| 357 | } |
| 358 | /* Clear shift register interrupt */ |
| 359 | if (in_8(&via[IFR]) & SR_INT) |
| 360 | (void)in_8(&via[SR]); |
| 361 | return 0; |
| 362 | } |
| 363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | #define WAIT_FOR(cond, what) \ |
| 365 | do { \ |
| 366 | int x; \ |
| 367 | for (x = 1000; !(cond); --x) { \ |
| 368 | if (x == 0) { \ |
Finn Thain | 523717d | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 369 | pr_err("Timeout waiting for " what "\n"); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | return -ENXIO; \ |
| 371 | } \ |
| 372 | udelay(100); \ |
| 373 | } \ |
| 374 | } while (0) |
| 375 | |
| 376 | static int |
Geert Uytterhoeven | 330dae1 | 2013-06-30 12:03:23 +0200 | [diff] [blame] | 377 | __init cuda_init_via(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { |
Finn Thain | 0251c38 | 2007-05-01 22:33:00 +0200 | [diff] [blame] | 379 | #ifdef CONFIG_PPC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | out_8(&via[IER], 0x7f); /* disable interrupts from VIA */ |
| 381 | (void)in_8(&via[IER]); |
Finn Thain | 0251c38 | 2007-05-01 22:33:00 +0200 | [diff] [blame] | 382 | #else |
| 383 | out_8(&via[IER], SR_INT); /* disable SR interrupt from VIA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | #endif |
| 385 | |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 386 | out_8(&via[DIRB], (in_8(&via[DIRB]) | TACK | TIP) & ~TREQ); /* TACK & TIP out */ |
| 387 | out_8(&via[ACR], (in_8(&via[ACR]) & ~SR_CTRL) | SR_EXT); /* SR data in */ |
| 388 | (void)in_8(&via[SR]); /* clear any left-over data */ |
| 389 | |
| 390 | if (mcu_is_egret) |
| 391 | return sync_egret(); |
| 392 | |
| 393 | negate_TIP_and_TACK(); |
| 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | /* delay 4ms and then clear any pending interrupt */ |
| 396 | mdelay(4); |
| 397 | (void)in_8(&via[SR]); |
Finn Thain | 0251c38 | 2007-05-01 22:33:00 +0200 | [diff] [blame] | 398 | out_8(&via[IFR], SR_INT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | /* sync with the CUDA - assert TACK without TIP */ |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 401 | assert_TACK(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
| 403 | /* wait for the CUDA to assert TREQ in response */ |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 404 | WAIT_FOR(TREQ_asserted(in_8(&via[B])), "CUDA response to sync"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
| 406 | /* wait for the interrupt and then clear it */ |
| 407 | WAIT_FOR(in_8(&via[IFR]) & SR_INT, "CUDA response to sync (2)"); |
| 408 | (void)in_8(&via[SR]); |
Finn Thain | 0251c38 | 2007-05-01 22:33:00 +0200 | [diff] [blame] | 409 | out_8(&via[IFR], SR_INT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | /* finish the sync by negating TACK */ |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 412 | negate_TACK(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
| 414 | /* wait for the CUDA to negate TREQ and the corresponding interrupt */ |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 415 | WAIT_FOR(!TREQ_asserted(in_8(&via[B])), "CUDA response to sync (3)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | WAIT_FOR(in_8(&via[IFR]) & SR_INT, "CUDA response to sync (4)"); |
| 417 | (void)in_8(&via[SR]); |
Finn Thain | 0251c38 | 2007-05-01 22:33:00 +0200 | [diff] [blame] | 418 | out_8(&via[IFR], SR_INT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | #ifdef CONFIG_ADB |
| 424 | /* Send an ADB command */ |
| 425 | static int |
| 426 | cuda_send_request(struct adb_request *req, int sync) |
| 427 | { |
| 428 | int i; |
| 429 | |
| 430 | if ((via == NULL) || !cuda_fully_inited) { |
| 431 | req->complete = 1; |
| 432 | return -ENXIO; |
| 433 | } |
| 434 | |
| 435 | req->reply_expected = 1; |
| 436 | |
| 437 | i = cuda_write(req); |
| 438 | if (i) |
| 439 | return i; |
| 440 | |
| 441 | if (sync) { |
| 442 | while (!req->complete) |
| 443 | cuda_poll(); |
| 444 | } |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | |
| 449 | /* Enable/disable autopolling */ |
| 450 | static int |
| 451 | cuda_adb_autopoll(int devs) |
| 452 | { |
| 453 | struct adb_request req; |
| 454 | |
| 455 | if ((via == NULL) || !cuda_fully_inited) |
| 456 | return -ENXIO; |
| 457 | |
| 458 | cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, (devs? 1: 0)); |
| 459 | while (!req.complete) |
| 460 | cuda_poll(); |
| 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | /* Reset adb bus - how do we do this?? */ |
| 465 | static int |
| 466 | cuda_reset_adb_bus(void) |
| 467 | { |
| 468 | struct adb_request req; |
| 469 | |
| 470 | if ((via == NULL) || !cuda_fully_inited) |
| 471 | return -ENXIO; |
| 472 | |
| 473 | cuda_request(&req, NULL, 2, ADB_PACKET, 0); /* maybe? */ |
| 474 | while (!req.complete) |
| 475 | cuda_poll(); |
| 476 | return 0; |
| 477 | } |
| 478 | #endif /* CONFIG_ADB */ |
Finn Thain | 523717d | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | /* Construct and send a cuda request */ |
| 481 | int |
| 482 | cuda_request(struct adb_request *req, void (*done)(struct adb_request *), |
| 483 | int nbytes, ...) |
| 484 | { |
| 485 | va_list list; |
| 486 | int i; |
| 487 | |
| 488 | if (via == NULL) { |
| 489 | req->complete = 1; |
| 490 | return -ENXIO; |
| 491 | } |
| 492 | |
| 493 | req->nbytes = nbytes; |
| 494 | req->done = done; |
| 495 | va_start(list, nbytes); |
| 496 | for (i = 0; i < nbytes; ++i) |
| 497 | req->data[i] = va_arg(list, int); |
| 498 | va_end(list); |
| 499 | req->reply_expected = 1; |
| 500 | return cuda_write(req); |
| 501 | } |
Anton Blanchard | 4a1b08e | 2014-08-20 08:00:01 +1000 | [diff] [blame] | 502 | EXPORT_SYMBOL(cuda_request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
| 504 | static int |
| 505 | cuda_write(struct adb_request *req) |
| 506 | { |
| 507 | unsigned long flags; |
| 508 | |
| 509 | if (req->nbytes < 2 || req->data[0] > CUDA_PACKET) { |
| 510 | req->complete = 1; |
| 511 | return -EINVAL; |
| 512 | } |
| 513 | req->next = NULL; |
| 514 | req->sent = 0; |
| 515 | req->complete = 0; |
| 516 | req->reply_len = 0; |
| 517 | |
| 518 | spin_lock_irqsave(&cuda_lock, flags); |
| 519 | if (current_req != 0) { |
| 520 | last_req->next = req; |
| 521 | last_req = req; |
| 522 | } else { |
| 523 | current_req = req; |
| 524 | last_req = req; |
| 525 | if (cuda_state == idle) |
| 526 | cuda_start(); |
| 527 | } |
| 528 | spin_unlock_irqrestore(&cuda_lock, flags); |
| 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | static void |
| 534 | cuda_start(void) |
| 535 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | /* assert cuda_state == idle */ |
Finn Thain | 06d7e99 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 537 | if (current_req == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | return; |
Finn Thain | 97ced1a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 539 | data_index = 0; |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 540 | if (TREQ_asserted(in_8(&via[B]))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | return; /* a byte is coming in from the CUDA */ |
| 542 | |
| 543 | /* set the shift register to shift out and send a byte */ |
| 544 | out_8(&via[ACR], in_8(&via[ACR]) | SR_OUT); |
Finn Thain | 97ced1a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 545 | out_8(&via[SR], current_req->data[data_index++]); |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 546 | if (mcu_is_egret) |
| 547 | assert_TIP_and_TACK(); |
| 548 | else |
| 549 | assert_TIP(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | cuda_state = sent_first_byte; |
| 551 | } |
| 552 | |
| 553 | void |
| 554 | cuda_poll(void) |
| 555 | { |
Finn Thain | ac39452 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 556 | cuda_interrupt(0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } |
Anton Blanchard | 4a1b08e | 2014-08-20 08:00:01 +1000 | [diff] [blame] | 558 | EXPORT_SYMBOL(cuda_poll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | |
Finn Thain | fe73b58 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 560 | #define ARRAY_FULL(a, p) ((p) - (a) == ARRAY_SIZE(a)) |
| 561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 563 | cuda_interrupt(int irq, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | { |
Finn Thain | ac39452 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 565 | unsigned long flags; |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 566 | u8 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | struct adb_request *req = NULL; |
| 568 | unsigned char ibuf[16]; |
| 569 | int ibuf_len = 0; |
| 570 | int complete = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Finn Thain | ac39452 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 572 | spin_lock_irqsave(&cuda_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | |
Finn Thain | 18814ee | 2009-11-17 20:03:05 +1100 | [diff] [blame] | 574 | /* On powermacs, this handler is registered for the VIA IRQ. But they use |
Finn Thain | 0251c38 | 2007-05-01 22:33:00 +0200 | [diff] [blame] | 575 | * just the shift register IRQ -- other VIA interrupt sources are disabled. |
| 576 | * On m68k macs, the VIA IRQ sources are dispatched individually. Unless |
| 577 | * we are polling, the shift register IRQ flag has already been cleared. |
| 578 | */ |
| 579 | |
| 580 | #ifdef CONFIG_MAC |
| 581 | if (!arg) |
| 582 | #endif |
| 583 | { |
| 584 | if ((in_8(&via[IFR]) & SR_INT) == 0) { |
Finn Thain | ac39452 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 585 | spin_unlock_irqrestore(&cuda_lock, flags); |
Finn Thain | 0251c38 | 2007-05-01 22:33:00 +0200 | [diff] [blame] | 586 | return IRQ_NONE; |
| 587 | } else { |
| 588 | out_8(&via[IFR], SR_INT); |
| 589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 591 | |
| 592 | status = in_8(&via[B]) & (TIP | TACK | TREQ); |
| 593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | switch (cuda_state) { |
| 595 | case idle: |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 596 | /* System controller has unsolicited data for us */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | (void)in_8(&via[SR]); |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 598 | idle_state: |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 599 | assert_TIP(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | cuda_state = reading; |
| 601 | reply_ptr = cuda_rbuf; |
| 602 | reading_reply = 0; |
| 603 | break; |
| 604 | |
| 605 | case awaiting_reply: |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 606 | /* System controller has reply data for us */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | (void)in_8(&via[SR]); |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 608 | assert_TIP(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | cuda_state = reading; |
| 610 | reply_ptr = current_req->reply; |
| 611 | reading_reply = 1; |
| 612 | break; |
| 613 | |
| 614 | case sent_first_byte: |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 615 | if (TREQ_asserted(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | /* collision */ |
| 617 | out_8(&via[ACR], in_8(&via[ACR]) & ~SR_OUT); |
| 618 | (void)in_8(&via[SR]); |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 619 | negate_TIP_and_TACK(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | cuda_state = idle; |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 621 | /* Egret does not raise an "aborted" interrupt */ |
| 622 | if (mcu_is_egret) |
| 623 | goto idle_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } else { |
Finn Thain | 97ced1a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 625 | out_8(&via[SR], current_req->data[data_index++]); |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 626 | toggle_TACK(); |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 627 | if (mcu_is_egret) |
| 628 | assert_TACK(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | cuda_state = sending; |
| 630 | } |
| 631 | break; |
| 632 | |
| 633 | case sending: |
| 634 | req = current_req; |
| 635 | if (data_index >= req->nbytes) { |
| 636 | out_8(&via[ACR], in_8(&via[ACR]) & ~SR_OUT); |
| 637 | (void)in_8(&via[SR]); |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 638 | negate_TIP_and_TACK(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | req->sent = 1; |
| 640 | if (req->reply_expected) { |
| 641 | cuda_state = awaiting_reply; |
| 642 | } else { |
| 643 | current_req = req->next; |
| 644 | complete = 1; |
| 645 | /* not sure about this */ |
| 646 | cuda_state = idle; |
| 647 | cuda_start(); |
| 648 | } |
| 649 | } else { |
| 650 | out_8(&via[SR], req->data[data_index++]); |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 651 | toggle_TACK(); |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 652 | if (mcu_is_egret) |
| 653 | assert_TACK(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
| 655 | break; |
| 656 | |
| 657 | case reading: |
Finn Thain | fe73b58 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 658 | if (reading_reply ? ARRAY_FULL(current_req->reply, reply_ptr) |
| 659 | : ARRAY_FULL(cuda_rbuf, reply_ptr)) |
| 660 | (void)in_8(&via[SR]); |
| 661 | else |
| 662 | *reply_ptr++ = in_8(&via[SR]); |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 663 | if (!TREQ_asserted(status)) { |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 664 | if (mcu_is_egret) |
| 665 | assert_TACK(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | /* that's all folks */ |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 667 | negate_TIP_and_TACK(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | cuda_state = read_done; |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 669 | /* Egret does not raise a "read done" interrupt */ |
| 670 | if (mcu_is_egret) |
| 671 | goto read_done_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | } else { |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 673 | toggle_TACK(); |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 674 | if (mcu_is_egret) |
| 675 | negate_TACK(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | } |
| 677 | break; |
| 678 | |
| 679 | case read_done: |
| 680 | (void)in_8(&via[SR]); |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 681 | read_done_state: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | if (reading_reply) { |
| 683 | req = current_req; |
| 684 | req->reply_len = reply_ptr - req->reply; |
| 685 | if (req->data[0] == ADB_PACKET) { |
| 686 | /* Have to adjust the reply from ADB commands */ |
| 687 | if (req->reply_len <= 2 || (req->reply[1] & 2) != 0) { |
| 688 | /* the 0x2 bit indicates no response */ |
| 689 | req->reply_len = 0; |
| 690 | } else { |
| 691 | /* leave just the command and result bytes in the reply */ |
| 692 | req->reply_len -= 2; |
| 693 | memmove(req->reply, req->reply + 2, req->reply_len); |
| 694 | } |
| 695 | } |
| 696 | current_req = req->next; |
| 697 | complete = 1; |
Finn Thain | cfbf998 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 698 | reading_reply = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | } else { |
| 700 | /* This is tricky. We must break the spinlock to call |
| 701 | * cuda_input. However, doing so means we might get |
| 702 | * re-entered from another CPU getting an interrupt |
| 703 | * or calling cuda_poll(). I ended up using the stack |
| 704 | * (it's only for 16 bytes) and moving the actual |
| 705 | * call to cuda_input to outside of the lock. |
| 706 | */ |
| 707 | ibuf_len = reply_ptr - cuda_rbuf; |
| 708 | memcpy(ibuf, cuda_rbuf, ibuf_len); |
| 709 | } |
Finn Thain | cfbf998 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 710 | reply_ptr = cuda_rbuf; |
Finn Thain | a646624 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 711 | cuda_state = idle; |
| 712 | cuda_start(); |
| 713 | if (cuda_state == idle && TREQ_asserted(in_8(&via[B]))) { |
Finn Thain | fd7a65a | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 714 | assert_TIP(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | cuda_state = reading; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
| 717 | break; |
| 718 | |
| 719 | default: |
Finn Thain | 523717d | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 720 | pr_err("cuda_interrupt: unknown cuda_state %d?\n", cuda_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | } |
Finn Thain | ac39452 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 722 | spin_unlock_irqrestore(&cuda_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | if (complete && req) { |
| 724 | void (*done)(struct adb_request *) = req->done; |
| 725 | mb(); |
| 726 | req->complete = 1; |
| 727 | /* Here, we assume that if the request has a done member, the |
| 728 | * struct request will survive to setting req->complete to 1 |
| 729 | */ |
| 730 | if (done) |
| 731 | (*done)(req); |
| 732 | } |
| 733 | if (ibuf_len) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 734 | cuda_input(ibuf, ibuf_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | return IRQ_HANDLED; |
| 736 | } |
| 737 | |
| 738 | static void |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 739 | cuda_input(unsigned char *buf, int nb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | switch (buf[0]) { |
| 742 | case ADB_PACKET: |
| 743 | #ifdef CONFIG_XMON |
| 744 | if (nb == 5 && buf[2] == 0x2c) { |
| 745 | extern int xmon_wants_key, xmon_adb_keycode; |
| 746 | if (xmon_wants_key) { |
| 747 | xmon_adb_keycode = buf[3]; |
| 748 | return; |
| 749 | } |
| 750 | } |
| 751 | #endif /* CONFIG_XMON */ |
| 752 | #ifdef CONFIG_ADB |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 753 | adb_input(buf+2, nb-2, buf[1] & 0x40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | #endif /* CONFIG_ADB */ |
| 755 | break; |
| 756 | |
Finn Thain | d23eee8 | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 757 | case TIMER_PACKET: |
| 758 | /* Egret sends these periodically. Might be useful as a 'heartbeat' |
| 759 | * to trigger a recovery for the VIA shift register errata. |
| 760 | */ |
| 761 | break; |
| 762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | default: |
Finn Thain | 523717d | 2016-12-31 19:56:26 -0500 | [diff] [blame] | 764 | print_hex_dump(KERN_INFO, "cuda_input: ", DUMP_PREFIX_NONE, 32, 1, |
| 765 | buf, nb, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
| 767 | } |