Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Device driver for the Apple Desktop Bus |
| 3 | * and the /dev/adb device on macintoshes. |
| 4 | * |
| 5 | * Copyright (C) 1996 Paul Mackerras. |
| 6 | * |
| 7 | * Modified to declare controllers as structures, added |
| 8 | * client notification of bus reset and handles PowerBook |
| 9 | * sleep, by Benjamin Herrenschmidt. |
| 10 | * |
| 11 | * To do: |
| 12 | * |
| 13 | * - /sys/bus/adb to list the devices and infos |
| 14 | * - more /dev/adb to allow userland to receive the |
| 15 | * flow of auto-polling datas from a given device. |
| 16 | * - move bus probe to a kernel thread |
| 17 | */ |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/types.h> |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/fs.h> |
| 25 | #include <linux/mm.h> |
| 26 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/adb.h> |
| 28 | #include <linux/cuda.h> |
| 29 | #include <linux/pmu.h> |
| 30 | #include <linux/notifier.h> |
| 31 | #include <linux/wait.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/delay.h> |
| 34 | #include <linux/spinlock.h> |
| 35 | #include <linux/completion.h> |
| 36 | #include <linux/device.h> |
Paul Mackerras | c61dace | 2007-12-13 15:11:22 +1100 | [diff] [blame] | 37 | #include <linux/kthread.h> |
Geert Uytterhoeven | fe2528b | 2008-02-03 16:49:09 +0100 | [diff] [blame] | 38 | #include <linux/platform_device.h> |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 39 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Brandon Stewart | 74e7cd43 | 2014-01-27 19:43:17 -0600 | [diff] [blame^] | 41 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #ifdef CONFIG_PPC |
| 43 | #include <asm/prom.h> |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 44 | #include <asm/machdep.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #endif |
| 46 | |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | EXPORT_SYMBOL(adb_client_list); |
| 49 | |
| 50 | extern struct adb_driver via_macii_driver; |
| 51 | extern struct adb_driver via_maciisi_driver; |
| 52 | extern struct adb_driver via_cuda_driver; |
| 53 | extern struct adb_driver adb_iop_driver; |
| 54 | extern struct adb_driver via_pmu_driver; |
| 55 | extern struct adb_driver macio_adb_driver; |
| 56 | |
Arnd Bergmann | d851b6e | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 57 | static DEFINE_MUTEX(adb_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | static struct adb_driver *adb_driver_list[] = { |
| 59 | #ifdef CONFIG_ADB_MACII |
| 60 | &via_macii_driver, |
| 61 | #endif |
| 62 | #ifdef CONFIG_ADB_MACIISI |
| 63 | &via_maciisi_driver, |
| 64 | #endif |
| 65 | #ifdef CONFIG_ADB_CUDA |
| 66 | &via_cuda_driver, |
| 67 | #endif |
| 68 | #ifdef CONFIG_ADB_IOP |
| 69 | &adb_iop_driver, |
| 70 | #endif |
| 71 | #if defined(CONFIG_ADB_PMU) || defined(CONFIG_ADB_PMU68K) |
| 72 | &via_pmu_driver, |
| 73 | #endif |
| 74 | #ifdef CONFIG_ADB_MACIO |
| 75 | &macio_adb_driver, |
| 76 | #endif |
| 77 | NULL |
| 78 | }; |
| 79 | |
gregkh@suse.de | 56b2293 | 2005-03-23 10:01:41 -0800 | [diff] [blame] | 80 | static struct class *adb_dev_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Adrian Bunk | 9b4a8dd | 2008-06-24 03:46:57 +1000 | [diff] [blame] | 82 | static struct adb_driver *adb_controller; |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 83 | BLOCKING_NOTIFIER_HEAD(adb_client_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | static int adb_got_sleep; |
| 85 | static int adb_inited; |
Thomas Gleixner | 8192b1f | 2010-09-07 14:33:40 +0000 | [diff] [blame] | 86 | static DEFINE_SEMAPHORE(adb_probe_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | static int sleepy_trackpad; |
| 88 | static int autopoll_devs; |
| 89 | int __adb_probe_sync; |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | static int adb_scan_bus(void); |
| 92 | static int do_adb_reset_bus(void); |
| 93 | static void adbdev_init(void); |
| 94 | static int try_handler_change(int, int); |
| 95 | |
| 96 | static struct adb_handler { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 97 | void (*handler)(unsigned char *, int, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | int original_address; |
| 99 | int handler_id; |
| 100 | int busy; |
| 101 | } adb_handler[16]; |
| 102 | |
| 103 | /* |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 104 | * The adb_handler_mutex mutex protects all accesses to the original_address |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | * and handler_id fields of adb_handler[i] for all i, and changes to the |
| 106 | * handler field. |
| 107 | * Accesses to the handler field are protected by the adb_handler_lock |
| 108 | * rwlock. It is held across all calls to any handler, so that by the |
| 109 | * time adb_unregister returns, we know that the old handler isn't being |
| 110 | * called. |
| 111 | */ |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 112 | static DEFINE_MUTEX(adb_handler_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | static DEFINE_RWLOCK(adb_handler_lock); |
| 114 | |
| 115 | #if 0 |
| 116 | static void printADBreply(struct adb_request *req) |
| 117 | { |
| 118 | int i; |
| 119 | |
| 120 | printk("adb reply (%d)", req->reply_len); |
| 121 | for(i = 0; i < req->reply_len; i++) |
| 122 | printk(" %x", req->reply[i]); |
| 123 | printk("\n"); |
| 124 | |
| 125 | } |
| 126 | #endif |
| 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | static int adb_scan_bus(void) |
| 129 | { |
| 130 | int i, highFree=0, noMovement; |
| 131 | int devmask = 0; |
| 132 | struct adb_request req; |
| 133 | |
| 134 | /* assumes adb_handler[] is all zeroes at this point */ |
| 135 | for (i = 1; i < 16; i++) { |
| 136 | /* see if there is anything at address i */ |
| 137 | adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1, |
| 138 | (i << 4) | 0xf); |
| 139 | if (req.reply_len > 1) |
| 140 | /* one or more devices at this address */ |
| 141 | adb_handler[i].original_address = i; |
| 142 | else if (i > highFree) |
| 143 | highFree = i; |
| 144 | } |
| 145 | |
| 146 | /* Note we reset noMovement to 0 each time we move a device */ |
| 147 | for (noMovement = 1; noMovement < 2 && highFree > 0; noMovement++) { |
| 148 | for (i = 1; i < 16; i++) { |
| 149 | if (adb_handler[i].original_address == 0) |
| 150 | continue; |
| 151 | /* |
| 152 | * Send a "talk register 3" command to address i |
| 153 | * to provoke a collision if there is more than |
| 154 | * one device at this address. |
| 155 | */ |
| 156 | adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1, |
| 157 | (i << 4) | 0xf); |
| 158 | /* |
| 159 | * Move the device(s) which didn't detect a |
| 160 | * collision to address `highFree'. Hopefully |
| 161 | * this only moves one device. |
| 162 | */ |
| 163 | adb_request(&req, NULL, ADBREQ_SYNC, 3, |
| 164 | (i<< 4) | 0xb, (highFree | 0x60), 0xfe); |
| 165 | /* |
| 166 | * See if anybody actually moved. This is suggested |
| 167 | * by HW TechNote 01: |
| 168 | * |
| 169 | * http://developer.apple.com/technotes/hw/hw_01.html |
| 170 | */ |
| 171 | adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1, |
| 172 | (highFree << 4) | 0xf); |
| 173 | if (req.reply_len <= 1) continue; |
| 174 | /* |
| 175 | * Test whether there are any device(s) left |
| 176 | * at address i. |
| 177 | */ |
| 178 | adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1, |
| 179 | (i << 4) | 0xf); |
| 180 | if (req.reply_len > 1) { |
| 181 | /* |
| 182 | * There are still one or more devices |
| 183 | * left at address i. Register the one(s) |
| 184 | * we moved to `highFree', and find a new |
| 185 | * value for highFree. |
| 186 | */ |
| 187 | adb_handler[highFree].original_address = |
| 188 | adb_handler[i].original_address; |
| 189 | while (highFree > 0 && |
| 190 | adb_handler[highFree].original_address) |
| 191 | highFree--; |
| 192 | if (highFree <= 0) |
| 193 | break; |
| 194 | |
| 195 | noMovement = 0; |
Brandon Stewart | 74e7cd43 | 2014-01-27 19:43:17 -0600 | [diff] [blame^] | 196 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | /* |
| 198 | * No devices left at address i; move the |
| 199 | * one(s) we moved to `highFree' back to i. |
| 200 | */ |
| 201 | adb_request(&req, NULL, ADBREQ_SYNC, 3, |
| 202 | (highFree << 4) | 0xb, |
| 203 | (i | 0x60), 0xfe); |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | /* Now fill in the handler_id field of the adb_handler entries. */ |
| 209 | printk(KERN_DEBUG "adb devices:"); |
| 210 | for (i = 1; i < 16; i++) { |
| 211 | if (adb_handler[i].original_address == 0) |
| 212 | continue; |
| 213 | adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1, |
| 214 | (i << 4) | 0xf); |
| 215 | adb_handler[i].handler_id = req.reply[2]; |
| 216 | printk(" [%d]: %d %x", i, adb_handler[i].original_address, |
| 217 | adb_handler[i].handler_id); |
| 218 | devmask |= 1 << i; |
| 219 | } |
| 220 | printk("\n"); |
| 221 | return devmask; |
| 222 | } |
| 223 | |
| 224 | /* |
| 225 | * This kernel task handles ADB probing. It dies once probing is |
| 226 | * completed. |
| 227 | */ |
| 228 | static int |
| 229 | adb_probe_task(void *x) |
| 230 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | printk(KERN_INFO "adb: starting probe task...\n"); |
| 232 | do_adb_reset_bus(); |
| 233 | printk(KERN_INFO "adb: finished probe task...\n"); |
Oleg Nesterov | 1b6dd9b | 2007-07-15 23:41:29 -0700 | [diff] [blame] | 234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | up(&adb_probe_mutex); |
Oleg Nesterov | 1b6dd9b | 2007-07-15 23:41:29 -0700 | [diff] [blame] | 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | static void |
Al Viro | 3e577a8 | 2006-12-06 18:41:45 +0000 | [diff] [blame] | 241 | __adb_probe_task(struct work_struct *bullshit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
Paul Mackerras | c61dace | 2007-12-13 15:11:22 +1100 | [diff] [blame] | 243 | kthread_run(adb_probe_task, NULL, "kadbprobe"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Al Viro | 3e577a8 | 2006-12-06 18:41:45 +0000 | [diff] [blame] | 246 | static DECLARE_WORK(adb_reset_work, __adb_probe_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | int |
| 249 | adb_reset_bus(void) |
| 250 | { |
| 251 | if (__adb_probe_sync) { |
| 252 | do_adb_reset_bus(); |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | down(&adb_probe_mutex); |
| 257 | schedule_work(&adb_reset_work); |
| 258 | return 0; |
| 259 | } |
| 260 | |
Johannes Berg | c9f6d3d | 2007-12-12 01:21:25 +1100 | [diff] [blame] | 261 | #ifdef CONFIG_PM |
| 262 | /* |
| 263 | * notify clients before sleep |
| 264 | */ |
| 265 | static int adb_suspend(struct platform_device *dev, pm_message_t state) |
| 266 | { |
| 267 | adb_got_sleep = 1; |
| 268 | /* We need to get a lock on the probe thread */ |
| 269 | down(&adb_probe_mutex); |
| 270 | /* Stop autopoll */ |
| 271 | if (adb_controller->autopoll) |
| 272 | adb_controller->autopoll(0); |
| 273 | blocking_notifier_call_chain(&adb_client_list, ADB_MSG_POWERDOWN, NULL); |
| 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | * reset bus after sleep |
| 280 | */ |
| 281 | static int adb_resume(struct platform_device *dev) |
| 282 | { |
| 283 | adb_got_sleep = 0; |
| 284 | up(&adb_probe_mutex); |
| 285 | adb_reset_bus(); |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | #endif /* CONFIG_PM */ |
| 290 | |
Adrian Bunk | 9b4a8dd | 2008-06-24 03:46:57 +1000 | [diff] [blame] | 291 | static int __init adb_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
| 293 | struct adb_driver *driver; |
| 294 | int i; |
| 295 | |
| 296 | #ifdef CONFIG_PPC32 |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 297 | if (!machine_is(chrp) && !machine_is(powermac)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | return 0; |
| 299 | #endif |
| 300 | #ifdef CONFIG_MAC |
| 301 | if (!MACH_IS_MAC) |
| 302 | return 0; |
| 303 | #endif |
| 304 | |
| 305 | /* xmon may do early-init */ |
| 306 | if (adb_inited) |
| 307 | return 0; |
| 308 | adb_inited = 1; |
| 309 | |
| 310 | adb_controller = NULL; |
| 311 | |
| 312 | i = 0; |
| 313 | while ((driver = adb_driver_list[i++]) != NULL) { |
| 314 | if (!driver->probe()) { |
| 315 | adb_controller = driver; |
| 316 | break; |
| 317 | } |
| 318 | } |
Finn Thain | 18814ee | 2009-11-17 20:03:05 +1100 | [diff] [blame] | 319 | if (adb_controller != NULL && adb_controller->init && |
| 320 | adb_controller->init()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | adb_controller = NULL; |
Finn Thain | 18814ee | 2009-11-17 20:03:05 +1100 | [diff] [blame] | 322 | if (adb_controller == NULL) { |
| 323 | printk(KERN_WARNING "Warning: no ADB interface detected\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | #ifdef CONFIG_PPC |
Grant Likely | 71a157e | 2010-02-01 21:34:14 -0700 | [diff] [blame] | 326 | if (of_machine_is_compatible("AAPL,PowerBook1998") || |
| 327 | of_machine_is_compatible("PowerBook1,1")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | sleepy_trackpad = 1; |
| 329 | #endif /* CONFIG_PPC */ |
Johannes Berg | c9f6d3d | 2007-12-12 01:21:25 +1100 | [diff] [blame] | 330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | adbdev_init(); |
| 332 | adb_reset_bus(); |
| 333 | } |
| 334 | return 0; |
| 335 | } |
| 336 | |
Robert P. J. Day | faa5b9d | 2008-05-15 09:12:53 +1000 | [diff] [blame] | 337 | device_initcall(adb_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | static int |
| 340 | do_adb_reset_bus(void) |
| 341 | { |
Johannes Berg | 70b52b3 | 2007-03-19 11:53:55 +0100 | [diff] [blame] | 342 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
| 344 | if (adb_controller == NULL) |
| 345 | return -ENXIO; |
| 346 | |
| 347 | if (adb_controller->autopoll) |
| 348 | adb_controller->autopoll(0); |
| 349 | |
Johannes Berg | 70b52b3 | 2007-03-19 11:53:55 +0100 | [diff] [blame] | 350 | blocking_notifier_call_chain(&adb_client_list, |
| 351 | ADB_MSG_PRE_RESET, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
| 353 | if (sleepy_trackpad) { |
| 354 | /* Let the trackpad settle down */ |
Paul Mackerras | c61dace | 2007-12-13 15:11:22 +1100 | [diff] [blame] | 355 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 358 | mutex_lock(&adb_handler_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | write_lock_irq(&adb_handler_lock); |
| 360 | memset(adb_handler, 0, sizeof(adb_handler)); |
| 361 | write_unlock_irq(&adb_handler_lock); |
| 362 | |
| 363 | /* That one is still a bit synchronous, oh well... */ |
| 364 | if (adb_controller->reset_bus) |
| 365 | ret = adb_controller->reset_bus(); |
| 366 | else |
| 367 | ret = 0; |
| 368 | |
| 369 | if (sleepy_trackpad) { |
| 370 | /* Let the trackpad settle down */ |
Paul Mackerras | c61dace | 2007-12-13 15:11:22 +1100 | [diff] [blame] | 371 | msleep(1500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | if (!ret) { |
| 375 | autopoll_devs = adb_scan_bus(); |
| 376 | if (adb_controller->autopoll) |
| 377 | adb_controller->autopoll(autopoll_devs); |
| 378 | } |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 379 | mutex_unlock(&adb_handler_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
Johannes Berg | 70b52b3 | 2007-03-19 11:53:55 +0100 | [diff] [blame] | 381 | blocking_notifier_call_chain(&adb_client_list, |
| 382 | ADB_MSG_POST_RESET, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
| 384 | return ret; |
| 385 | } |
| 386 | |
| 387 | void |
| 388 | adb_poll(void) |
| 389 | { |
| 390 | if ((adb_controller == NULL)||(adb_controller->poll == NULL)) |
| 391 | return; |
| 392 | adb_controller->poll(); |
| 393 | } |
| 394 | |
Paul Mackerras | c61dace | 2007-12-13 15:11:22 +1100 | [diff] [blame] | 395 | static void adb_sync_req_done(struct adb_request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | { |
Paul Mackerras | c61dace | 2007-12-13 15:11:22 +1100 | [diff] [blame] | 397 | struct completion *comp = req->arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
Paul Mackerras | c61dace | 2007-12-13 15:11:22 +1100 | [diff] [blame] | 399 | complete(comp); |
| 400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
| 402 | int |
| 403 | adb_request(struct adb_request *req, void (*done)(struct adb_request *), |
| 404 | int flags, int nbytes, ...) |
| 405 | { |
| 406 | va_list list; |
Paul Mackerras | c61dace | 2007-12-13 15:11:22 +1100 | [diff] [blame] | 407 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | int rc; |
Paul Mackerras | c61dace | 2007-12-13 15:11:22 +1100 | [diff] [blame] | 409 | struct completion comp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | if ((adb_controller == NULL) || (adb_controller->send_request == NULL)) |
| 412 | return -ENXIO; |
| 413 | if (nbytes < 1) |
| 414 | return -EINVAL; |
Paul Mackerras | c61dace | 2007-12-13 15:11:22 +1100 | [diff] [blame] | 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | req->nbytes = nbytes+1; |
| 417 | req->done = done; |
| 418 | req->reply_expected = flags & ADBREQ_REPLY; |
| 419 | req->data[0] = ADB_PACKET; |
| 420 | va_start(list, nbytes); |
| 421 | for (i = 0; i < nbytes; ++i) |
| 422 | req->data[i+1] = va_arg(list, int); |
| 423 | va_end(list); |
| 424 | |
| 425 | if (flags & ADBREQ_NOSEND) |
| 426 | return 0; |
| 427 | |
Paul Mackerras | c61dace | 2007-12-13 15:11:22 +1100 | [diff] [blame] | 428 | /* Synchronous requests block using an on-stack completion */ |
| 429 | if (flags & ADBREQ_SYNC) { |
| 430 | WARN_ON(done); |
| 431 | req->done = adb_sync_req_done; |
| 432 | req->arg = ∁ |
| 433 | init_completion(&comp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Paul Mackerras | c61dace | 2007-12-13 15:11:22 +1100 | [diff] [blame] | 436 | rc = adb_controller->send_request(req, 0); |
| 437 | |
| 438 | if ((flags & ADBREQ_SYNC) && !rc && !req->complete) |
| 439 | wait_for_completion(&comp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | return rc; |
| 442 | } |
| 443 | |
| 444 | /* Ultimately this should return the number of devices with |
| 445 | the given default id. |
| 446 | And it does it now ! Note: changed behaviour: This function |
| 447 | will now register if default_id _and_ handler_id both match |
| 448 | but handler_id can be left to 0 to match with default_id only. |
| 449 | When handler_id is set, this function will try to adjust |
| 450 | the handler_id id it doesn't match. */ |
| 451 | int |
| 452 | adb_register(int default_id, int handler_id, struct adb_ids *ids, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 453 | void (*handler)(unsigned char *, int, int)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | { |
| 455 | int i; |
| 456 | |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 457 | mutex_lock(&adb_handler_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | ids->nids = 0; |
| 459 | for (i = 1; i < 16; i++) { |
| 460 | if ((adb_handler[i].original_address == default_id) && |
| 461 | (!handler_id || (handler_id == adb_handler[i].handler_id) || |
| 462 | try_handler_change(i, handler_id))) { |
| 463 | if (adb_handler[i].handler != 0) { |
| 464 | printk(KERN_ERR |
| 465 | "Two handlers for ADB device %d\n", |
| 466 | default_id); |
| 467 | continue; |
| 468 | } |
| 469 | write_lock_irq(&adb_handler_lock); |
| 470 | adb_handler[i].handler = handler; |
| 471 | write_unlock_irq(&adb_handler_lock); |
| 472 | ids->id[ids->nids++] = i; |
| 473 | } |
| 474 | } |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 475 | mutex_unlock(&adb_handler_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | return ids->nids; |
| 477 | } |
| 478 | |
| 479 | int |
| 480 | adb_unregister(int index) |
| 481 | { |
| 482 | int ret = -ENODEV; |
| 483 | |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 484 | mutex_lock(&adb_handler_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | write_lock_irq(&adb_handler_lock); |
| 486 | if (adb_handler[index].handler) { |
| 487 | while(adb_handler[index].busy) { |
| 488 | write_unlock_irq(&adb_handler_lock); |
| 489 | yield(); |
| 490 | write_lock_irq(&adb_handler_lock); |
| 491 | } |
| 492 | ret = 0; |
| 493 | adb_handler[index].handler = NULL; |
| 494 | } |
| 495 | write_unlock_irq(&adb_handler_lock); |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 496 | mutex_unlock(&adb_handler_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | return ret; |
| 498 | } |
| 499 | |
| 500 | void |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 501 | adb_input(unsigned char *buf, int nb, int autopoll) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | { |
| 503 | int i, id; |
Brandon Stewart | 74e7cd43 | 2014-01-27 19:43:17 -0600 | [diff] [blame^] | 504 | static int dump_adb_input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | unsigned long flags; |
| 506 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 507 | void (*handler)(unsigned char *, int, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | /* We skip keystrokes and mouse moves when the sleep process |
| 510 | * has been started. We stop autopoll, but this is another security |
| 511 | */ |
| 512 | if (adb_got_sleep) |
| 513 | return; |
| 514 | |
| 515 | id = buf[0] >> 4; |
| 516 | if (dump_adb_input) { |
| 517 | printk(KERN_INFO "adb packet: "); |
| 518 | for (i = 0; i < nb; ++i) |
| 519 | printk(" %x", buf[i]); |
| 520 | printk(", id = %d\n", id); |
| 521 | } |
| 522 | write_lock_irqsave(&adb_handler_lock, flags); |
| 523 | handler = adb_handler[id].handler; |
| 524 | if (handler != NULL) |
| 525 | adb_handler[id].busy = 1; |
| 526 | write_unlock_irqrestore(&adb_handler_lock, flags); |
| 527 | if (handler != NULL) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 528 | (*handler)(buf, nb, autopoll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | wmb(); |
| 530 | adb_handler[id].busy = 0; |
| 531 | } |
| 532 | |
| 533 | } |
| 534 | |
| 535 | /* Try to change handler to new_id. Will return 1 if successful. */ |
| 536 | static int try_handler_change(int address, int new_id) |
| 537 | { |
| 538 | struct adb_request req; |
| 539 | |
| 540 | if (adb_handler[address].handler_id == new_id) |
| 541 | return 1; |
| 542 | adb_request(&req, NULL, ADBREQ_SYNC, 3, |
| 543 | ADB_WRITEREG(address, 3), address | 0x20, new_id); |
| 544 | adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1, |
| 545 | ADB_READREG(address, 3)); |
| 546 | if (req.reply_len < 2) |
| 547 | return 0; |
| 548 | if (req.reply[2] != new_id) |
| 549 | return 0; |
| 550 | adb_handler[address].handler_id = req.reply[2]; |
| 551 | |
| 552 | return 1; |
| 553 | } |
| 554 | |
| 555 | int |
| 556 | adb_try_handler_change(int address, int new_id) |
| 557 | { |
| 558 | int ret; |
| 559 | |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 560 | mutex_lock(&adb_handler_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | ret = try_handler_change(address, new_id); |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 562 | mutex_unlock(&adb_handler_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | return ret; |
| 564 | } |
| 565 | |
| 566 | int |
| 567 | adb_get_infos(int address, int *original_address, int *handler_id) |
| 568 | { |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 569 | mutex_lock(&adb_handler_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | *original_address = adb_handler[address].original_address; |
| 571 | *handler_id = adb_handler[address].handler_id; |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 572 | mutex_unlock(&adb_handler_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | |
| 574 | return (*original_address != 0); |
| 575 | } |
| 576 | |
| 577 | |
| 578 | /* |
| 579 | * /dev/adb device driver. |
| 580 | */ |
| 581 | |
| 582 | #define ADB_MAJOR 56 /* major number for /dev/adb */ |
| 583 | |
| 584 | struct adbdev_state { |
| 585 | spinlock_t lock; |
| 586 | atomic_t n_pending; |
| 587 | struct adb_request *completed; |
| 588 | wait_queue_head_t wait_queue; |
| 589 | int inuse; |
| 590 | }; |
| 591 | |
| 592 | static void adb_write_done(struct adb_request *req) |
| 593 | { |
| 594 | struct adbdev_state *state = (struct adbdev_state *) req->arg; |
| 595 | unsigned long flags; |
| 596 | |
| 597 | if (!req->complete) { |
| 598 | req->reply_len = 0; |
| 599 | req->complete = 1; |
| 600 | } |
| 601 | spin_lock_irqsave(&state->lock, flags); |
| 602 | atomic_dec(&state->n_pending); |
| 603 | if (!state->inuse) { |
| 604 | kfree(req); |
| 605 | if (atomic_read(&state->n_pending) == 0) { |
| 606 | spin_unlock_irqrestore(&state->lock, flags); |
| 607 | kfree(state); |
| 608 | return; |
| 609 | } |
| 610 | } else { |
| 611 | struct adb_request **ap = &state->completed; |
| 612 | while (*ap != NULL) |
| 613 | ap = &(*ap)->next; |
| 614 | req->next = NULL; |
| 615 | *ap = req; |
| 616 | wake_up_interruptible(&state->wait_queue); |
| 617 | } |
| 618 | spin_unlock_irqrestore(&state->lock, flags); |
| 619 | } |
| 620 | |
| 621 | static int |
| 622 | do_adb_query(struct adb_request *req) |
| 623 | { |
| 624 | int ret = -EINVAL; |
| 625 | |
Brandon Stewart | 74e7cd43 | 2014-01-27 19:43:17 -0600 | [diff] [blame^] | 626 | switch(req->data[1]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | case ADB_QUERY_GETDEVINFO: |
| 628 | if (req->nbytes < 3) |
| 629 | break; |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 630 | mutex_lock(&adb_handler_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | req->reply[0] = adb_handler[req->data[2]].original_address; |
| 632 | req->reply[1] = adb_handler[req->data[2]].handler_id; |
Daniel Walker | af3ce51 | 2008-05-03 06:34:03 +1000 | [diff] [blame] | 633 | mutex_unlock(&adb_handler_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | req->complete = 1; |
| 635 | req->reply_len = 2; |
| 636 | adb_write_done(req); |
| 637 | ret = 0; |
| 638 | break; |
| 639 | } |
| 640 | return ret; |
| 641 | } |
| 642 | |
| 643 | static int adb_open(struct inode *inode, struct file *file) |
| 644 | { |
| 645 | struct adbdev_state *state; |
Jonathan Corbet | 26ce4f0 | 2008-05-16 14:19:56 -0600 | [diff] [blame] | 646 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Arnd Bergmann | d851b6e | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 648 | mutex_lock(&adb_mutex); |
Jonathan Corbet | 26ce4f0 | 2008-05-16 14:19:56 -0600 | [diff] [blame] | 649 | if (iminor(inode) > 0 || adb_controller == NULL) { |
| 650 | ret = -ENXIO; |
| 651 | goto out; |
| 652 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | state = kmalloc(sizeof(struct adbdev_state), GFP_KERNEL); |
Jonathan Corbet | 26ce4f0 | 2008-05-16 14:19:56 -0600 | [diff] [blame] | 654 | if (state == 0) { |
| 655 | ret = -ENOMEM; |
| 656 | goto out; |
| 657 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | file->private_data = state; |
| 659 | spin_lock_init(&state->lock); |
| 660 | atomic_set(&state->n_pending, 0); |
| 661 | state->completed = NULL; |
| 662 | init_waitqueue_head(&state->wait_queue); |
| 663 | state->inuse = 1; |
| 664 | |
Jonathan Corbet | 26ce4f0 | 2008-05-16 14:19:56 -0600 | [diff] [blame] | 665 | out: |
Arnd Bergmann | d851b6e | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 666 | mutex_unlock(&adb_mutex); |
Jonathan Corbet | 26ce4f0 | 2008-05-16 14:19:56 -0600 | [diff] [blame] | 667 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static int adb_release(struct inode *inode, struct file *file) |
| 671 | { |
| 672 | struct adbdev_state *state = file->private_data; |
| 673 | unsigned long flags; |
| 674 | |
Arnd Bergmann | d851b6e | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 675 | mutex_lock(&adb_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | if (state) { |
| 677 | file->private_data = NULL; |
| 678 | spin_lock_irqsave(&state->lock, flags); |
| 679 | if (atomic_read(&state->n_pending) == 0 |
| 680 | && state->completed == NULL) { |
| 681 | spin_unlock_irqrestore(&state->lock, flags); |
| 682 | kfree(state); |
| 683 | } else { |
| 684 | state->inuse = 0; |
| 685 | spin_unlock_irqrestore(&state->lock, flags); |
| 686 | } |
| 687 | } |
Arnd Bergmann | d851b6e | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 688 | mutex_unlock(&adb_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | return 0; |
| 690 | } |
| 691 | |
| 692 | static ssize_t adb_read(struct file *file, char __user *buf, |
| 693 | size_t count, loff_t *ppos) |
| 694 | { |
| 695 | int ret = 0; |
| 696 | struct adbdev_state *state = file->private_data; |
| 697 | struct adb_request *req; |
Brandon Stewart | 74e7cd43 | 2014-01-27 19:43:17 -0600 | [diff] [blame^] | 698 | DECLARE_WAITQUEUE(wait, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | unsigned long flags; |
| 700 | |
| 701 | if (count < 2) |
| 702 | return -EINVAL; |
| 703 | if (count > sizeof(req->reply)) |
| 704 | count = sizeof(req->reply); |
| 705 | if (!access_ok(VERIFY_WRITE, buf, count)) |
| 706 | return -EFAULT; |
| 707 | |
| 708 | req = NULL; |
| 709 | spin_lock_irqsave(&state->lock, flags); |
| 710 | add_wait_queue(&state->wait_queue, &wait); |
majianpeng | 64f8c135 | 2012-02-03 14:35:59 +0000 | [diff] [blame] | 711 | set_current_state(TASK_INTERRUPTIBLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
| 713 | for (;;) { |
| 714 | req = state->completed; |
| 715 | if (req != NULL) |
| 716 | state->completed = req->next; |
| 717 | else if (atomic_read(&state->n_pending) == 0) |
| 718 | ret = -EIO; |
| 719 | if (req != NULL || ret != 0) |
| 720 | break; |
| 721 | |
| 722 | if (file->f_flags & O_NONBLOCK) { |
| 723 | ret = -EAGAIN; |
| 724 | break; |
| 725 | } |
| 726 | if (signal_pending(current)) { |
| 727 | ret = -ERESTARTSYS; |
| 728 | break; |
| 729 | } |
| 730 | spin_unlock_irqrestore(&state->lock, flags); |
| 731 | schedule(); |
| 732 | spin_lock_irqsave(&state->lock, flags); |
| 733 | } |
| 734 | |
majianpeng | 64f8c135 | 2012-02-03 14:35:59 +0000 | [diff] [blame] | 735 | set_current_state(TASK_RUNNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | remove_wait_queue(&state->wait_queue, &wait); |
| 737 | spin_unlock_irqrestore(&state->lock, flags); |
| 738 | |
| 739 | if (ret) |
| 740 | return ret; |
| 741 | |
| 742 | ret = req->reply_len; |
| 743 | if (ret > count) |
| 744 | ret = count; |
| 745 | if (ret > 0 && copy_to_user(buf, req->reply, ret)) |
| 746 | ret = -EFAULT; |
| 747 | |
| 748 | kfree(req); |
| 749 | return ret; |
| 750 | } |
| 751 | |
| 752 | static ssize_t adb_write(struct file *file, const char __user *buf, |
| 753 | size_t count, loff_t *ppos) |
| 754 | { |
| 755 | int ret/*, i*/; |
| 756 | struct adbdev_state *state = file->private_data; |
| 757 | struct adb_request *req; |
| 758 | |
| 759 | if (count < 2 || count > sizeof(req->data)) |
| 760 | return -EINVAL; |
| 761 | if (adb_controller == NULL) |
| 762 | return -ENXIO; |
| 763 | if (!access_ok(VERIFY_READ, buf, count)) |
| 764 | return -EFAULT; |
| 765 | |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 766 | req = kmalloc(sizeof(struct adb_request), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | GFP_KERNEL); |
| 768 | if (req == NULL) |
| 769 | return -ENOMEM; |
| 770 | |
| 771 | req->nbytes = count; |
| 772 | req->done = adb_write_done; |
| 773 | req->arg = (void *) state; |
| 774 | req->complete = 0; |
| 775 | |
| 776 | ret = -EFAULT; |
| 777 | if (copy_from_user(req->data, buf, count)) |
| 778 | goto out; |
| 779 | |
| 780 | atomic_inc(&state->n_pending); |
| 781 | |
| 782 | /* If a probe is in progress or we are sleeping, wait for it to complete */ |
| 783 | down(&adb_probe_mutex); |
| 784 | |
| 785 | /* Queries are special requests sent to the ADB driver itself */ |
| 786 | if (req->data[0] == ADB_QUERY) { |
| 787 | if (count > 1) |
| 788 | ret = do_adb_query(req); |
| 789 | else |
| 790 | ret = -EINVAL; |
| 791 | up(&adb_probe_mutex); |
| 792 | } |
| 793 | /* Special case for ADB_BUSRESET request, all others are sent to |
| 794 | the controller */ |
Brandon Stewart | 74e7cd43 | 2014-01-27 19:43:17 -0600 | [diff] [blame^] | 795 | else if ((req->data[0] == ADB_PACKET) && (count > 1) |
| 796 | && (req->data[1] == ADB_BUSRESET)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | ret = do_adb_reset_bus(); |
| 798 | up(&adb_probe_mutex); |
| 799 | atomic_dec(&state->n_pending); |
| 800 | if (ret == 0) |
| 801 | ret = count; |
| 802 | goto out; |
| 803 | } else { |
| 804 | req->reply_expected = ((req->data[1] & 0xc) == 0xc); |
| 805 | if (adb_controller && adb_controller->send_request) |
| 806 | ret = adb_controller->send_request(req, 0); |
| 807 | else |
| 808 | ret = -ENXIO; |
| 809 | up(&adb_probe_mutex); |
| 810 | } |
| 811 | |
| 812 | if (ret != 0) { |
| 813 | atomic_dec(&state->n_pending); |
| 814 | goto out; |
| 815 | } |
| 816 | return count; |
| 817 | |
| 818 | out: |
| 819 | kfree(req); |
| 820 | return ret; |
| 821 | } |
| 822 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 823 | static const struct file_operations adb_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | .owner = THIS_MODULE, |
| 825 | .llseek = no_llseek, |
| 826 | .read = adb_read, |
| 827 | .write = adb_write, |
| 828 | .open = adb_open, |
| 829 | .release = adb_release, |
| 830 | }; |
| 831 | |
Johannes Berg | c9f6d3d | 2007-12-12 01:21:25 +1100 | [diff] [blame] | 832 | static struct platform_driver adb_pfdrv = { |
| 833 | .driver = { |
| 834 | .name = "adb", |
| 835 | }, |
| 836 | #ifdef CONFIG_PM |
| 837 | .suspend = adb_suspend, |
| 838 | .resume = adb_resume, |
| 839 | #endif |
| 840 | }; |
| 841 | |
| 842 | static struct platform_device adb_pfdev = { |
| 843 | .name = "adb", |
| 844 | }; |
| 845 | |
| 846 | static int __init |
| 847 | adb_dummy_probe(struct platform_device *dev) |
| 848 | { |
| 849 | if (dev == &adb_pfdev) |
| 850 | return 0; |
| 851 | return -ENODEV; |
| 852 | } |
| 853 | |
| 854 | static void __init |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | adbdev_init(void) |
| 856 | { |
| 857 | if (register_chrdev(ADB_MAJOR, "adb", &adb_fops)) { |
| 858 | printk(KERN_ERR "adb: unable to get major %d\n", ADB_MAJOR); |
| 859 | return; |
| 860 | } |
| 861 | |
gregkh@suse.de | 56b2293 | 2005-03-23 10:01:41 -0800 | [diff] [blame] | 862 | adb_dev_class = class_create(THIS_MODULE, "adb"); |
| 863 | if (IS_ERR(adb_dev_class)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | return; |
Greg Kroah-Hartman | a9b1261 | 2008-07-21 20:03:34 -0700 | [diff] [blame] | 865 | device_create(adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), NULL, "adb"); |
Johannes Berg | c9f6d3d | 2007-12-12 01:21:25 +1100 | [diff] [blame] | 866 | |
| 867 | platform_device_register(&adb_pfdev); |
| 868 | platform_driver_probe(&adb_pfdrv, adb_dummy_probe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | } |