ati_remote2.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*
  2. * ati_remote2 - ATI/Philips USB RF remote driver
  3. *
  4. * Copyright (C) 2005-2008 Ville Syrjala <syrjala@sci.fi>
  5. * Copyright (C) 2007-2008 Peter Stokes <linux@dadeos.co.uk>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2
  9. * as published by the Free Software Foundation.
  10. */
  11. #include <linux/usb/input.h>
  12. #define DRIVER_DESC "ATI/Philips USB RF remote driver"
  13. #define DRIVER_VERSION "0.3"
  14. MODULE_DESCRIPTION(DRIVER_DESC);
  15. MODULE_VERSION(DRIVER_VERSION);
  16. MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
  17. MODULE_LICENSE("GPL");
  18. /*
  19. * ATI Remote Wonder II Channel Configuration
  20. *
  21. * The remote control can by assigned one of sixteen "channels" in order to facilitate
  22. * the use of multiple remote controls within range of each other.
  23. * A remote's "channel" may be altered by pressing and holding the "PC" button for
  24. * approximately 3 seconds, after which the button will slowly flash the count of the
  25. * currently configured "channel", using the numeric keypad enter a number between 1 and
  26. * 16 and then press the "PC" button again, the button will slowly flash the count of the
  27. * newly configured "channel".
  28. */
  29. static unsigned int channel_mask = 0xFFFF;
  30. module_param(channel_mask, uint, 0644);
  31. MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
  32. static unsigned int mode_mask = 0x1F;
  33. module_param(mode_mask, uint, 0644);
  34. MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
  35. static struct usb_device_id ati_remote2_id_table[] = {
  36. { USB_DEVICE(0x0471, 0x0602) }, /* ATI Remote Wonder II */
  37. { }
  38. };
  39. MODULE_DEVICE_TABLE(usb, ati_remote2_id_table);
  40. static DEFINE_MUTEX(ati_remote2_mutex);
  41. enum {
  42. ATI_REMOTE2_OPENED = 0x1,
  43. ATI_REMOTE2_SUSPENDED = 0x2,
  44. };
  45. enum {
  46. ATI_REMOTE2_AUX1,
  47. ATI_REMOTE2_AUX2,
  48. ATI_REMOTE2_AUX3,
  49. ATI_REMOTE2_AUX4,
  50. ATI_REMOTE2_PC,
  51. ATI_REMOTE2_MODES,
  52. };
  53. static const struct {
  54. u8 hw_code;
  55. u16 keycode;
  56. } ati_remote2_key_table[] = {
  57. { 0x00, KEY_0 },
  58. { 0x01, KEY_1 },
  59. { 0x02, KEY_2 },
  60. { 0x03, KEY_3 },
  61. { 0x04, KEY_4 },
  62. { 0x05, KEY_5 },
  63. { 0x06, KEY_6 },
  64. { 0x07, KEY_7 },
  65. { 0x08, KEY_8 },
  66. { 0x09, KEY_9 },
  67. { 0x0c, KEY_POWER },
  68. { 0x0d, KEY_MUTE },
  69. { 0x10, KEY_VOLUMEUP },
  70. { 0x11, KEY_VOLUMEDOWN },
  71. { 0x20, KEY_CHANNELUP },
  72. { 0x21, KEY_CHANNELDOWN },
  73. { 0x28, KEY_FORWARD },
  74. { 0x29, KEY_REWIND },
  75. { 0x2c, KEY_PLAY },
  76. { 0x30, KEY_PAUSE },
  77. { 0x31, KEY_STOP },
  78. { 0x37, KEY_RECORD },
  79. { 0x38, KEY_DVD },
  80. { 0x39, KEY_TV },
  81. { 0x3f, KEY_PROG1 }, /* AUX1-AUX4 and PC */
  82. { 0x54, KEY_MENU },
  83. { 0x58, KEY_UP },
  84. { 0x59, KEY_DOWN },
  85. { 0x5a, KEY_LEFT },
  86. { 0x5b, KEY_RIGHT },
  87. { 0x5c, KEY_OK },
  88. { 0x78, KEY_A },
  89. { 0x79, KEY_B },
  90. { 0x7a, KEY_C },
  91. { 0x7b, KEY_D },
  92. { 0x7c, KEY_E },
  93. { 0x7d, KEY_F },
  94. { 0x82, KEY_ENTER },
  95. { 0x8e, KEY_VENDOR },
  96. { 0x96, KEY_COFFEE },
  97. { 0xa9, BTN_LEFT },
  98. { 0xaa, BTN_RIGHT },
  99. { 0xbe, KEY_QUESTION },
  100. { 0xd0, KEY_EDIT },
  101. { 0xd5, KEY_FRONT },
  102. { 0xf9, KEY_INFO },
  103. };
  104. struct ati_remote2 {
  105. struct input_dev *idev;
  106. struct usb_device *udev;
  107. struct usb_interface *intf[2];
  108. struct usb_endpoint_descriptor *ep[2];
  109. struct urb *urb[2];
  110. void *buf[2];
  111. dma_addr_t buf_dma[2];
  112. unsigned long jiffies;
  113. int mode;
  114. char name[64];
  115. char phys[64];
  116. /* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
  117. u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)];
  118. unsigned int flags;
  119. };
  120. static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id);
  121. static void ati_remote2_disconnect(struct usb_interface *interface);
  122. static int ati_remote2_suspend(struct usb_interface *interface, pm_message_t message);
  123. static int ati_remote2_resume(struct usb_interface *interface);
  124. static struct usb_driver ati_remote2_driver = {
  125. .name = "ati_remote2",
  126. .probe = ati_remote2_probe,
  127. .disconnect = ati_remote2_disconnect,
  128. .id_table = ati_remote2_id_table,
  129. .suspend = ati_remote2_suspend,
  130. .resume = ati_remote2_resume,
  131. .supports_autosuspend = 1,
  132. };
  133. static int ati_remote2_submit_urbs(struct ati_remote2 *ar2)
  134. {
  135. int r;
  136. r = usb_submit_urb(ar2->urb[0], GFP_KERNEL);
  137. if (r) {
  138. dev_err(&ar2->intf[0]->dev,
  139. "%s(): usb_submit_urb() = %d\n", __func__, r);
  140. return r;
  141. }
  142. r = usb_submit_urb(ar2->urb[1], GFP_KERNEL);
  143. if (r) {
  144. usb_kill_urb(ar2->urb[0]);
  145. dev_err(&ar2->intf[1]->dev,
  146. "%s(): usb_submit_urb() = %d\n", __func__, r);
  147. return r;
  148. }
  149. return 0;
  150. }
  151. static void ati_remote2_kill_urbs(struct ati_remote2 *ar2)
  152. {
  153. usb_kill_urb(ar2->urb[1]);
  154. usb_kill_urb(ar2->urb[0]);
  155. }
  156. static int ati_remote2_open(struct input_dev *idev)
  157. {
  158. struct ati_remote2 *ar2 = input_get_drvdata(idev);
  159. int r;
  160. dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
  161. r = usb_autopm_get_interface(ar2->intf[0]);
  162. if (r) {
  163. dev_err(&ar2->intf[0]->dev,
  164. "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
  165. goto fail1;
  166. }
  167. mutex_lock(&ati_remote2_mutex);
  168. if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) {
  169. r = ati_remote2_submit_urbs(ar2);
  170. if (r)
  171. goto fail2;
  172. }
  173. ar2->flags |= ATI_REMOTE2_OPENED;
  174. mutex_unlock(&ati_remote2_mutex);
  175. usb_autopm_put_interface(ar2->intf[0]);
  176. return 0;
  177. fail2:
  178. mutex_unlock(&ati_remote2_mutex);
  179. usb_autopm_put_interface(ar2->intf[0]);
  180. fail1:
  181. return r;
  182. }
  183. static void ati_remote2_close(struct input_dev *idev)
  184. {
  185. struct ati_remote2 *ar2 = input_get_drvdata(idev);
  186. dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
  187. mutex_lock(&ati_remote2_mutex);
  188. if (!(ar2->flags & ATI_REMOTE2_SUSPENDED))
  189. ati_remote2_kill_urbs(ar2);
  190. ar2->flags &= ~ATI_REMOTE2_OPENED;
  191. mutex_unlock(&ati_remote2_mutex);
  192. }
  193. static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
  194. {
  195. struct input_dev *idev = ar2->idev;
  196. u8 *data = ar2->buf[0];
  197. int channel, mode;
  198. channel = data[0] >> 4;
  199. if (!((1 << channel) & channel_mask))
  200. return;
  201. mode = data[0] & 0x0F;
  202. if (mode > ATI_REMOTE2_PC) {
  203. dev_err(&ar2->intf[0]->dev,
  204. "Unknown mode byte (%02x %02x %02x %02x)\n",
  205. data[3], data[2], data[1], data[0]);
  206. return;
  207. }
  208. if (!((1 << mode) & mode_mask))
  209. return;
  210. input_event(idev, EV_REL, REL_X, (s8) data[1]);
  211. input_event(idev, EV_REL, REL_Y, (s8) data[2]);
  212. input_sync(idev);
  213. }
  214. static int ati_remote2_lookup(unsigned int hw_code)
  215. {
  216. int i;
  217. for (i = 0; i < ARRAY_SIZE(ati_remote2_key_table); i++)
  218. if (ati_remote2_key_table[i].hw_code == hw_code)
  219. return i;
  220. return -1;
  221. }
  222. static void ati_remote2_input_key(struct ati_remote2 *ar2)
  223. {
  224. struct input_dev *idev = ar2->idev;
  225. u8 *data = ar2->buf[1];
  226. int channel, mode, hw_code, index;
  227. channel = data[0] >> 4;
  228. if (!((1 << channel) & channel_mask))
  229. return;
  230. mode = data[0] & 0x0F;
  231. if (mode > ATI_REMOTE2_PC) {
  232. dev_err(&ar2->intf[1]->dev,
  233. "Unknown mode byte (%02x %02x %02x %02x)\n",
  234. data[3], data[2], data[1], data[0]);
  235. return;
  236. }
  237. hw_code = data[2];
  238. if (hw_code == 0x3f) {
  239. /*
  240. * For some incomprehensible reason the mouse pad generates
  241. * events which look identical to the events from the last
  242. * pressed mode key. Naturally we don't want to generate key
  243. * events for the mouse pad so we filter out any subsequent
  244. * events from the same mode key.
  245. */
  246. if (ar2->mode == mode)
  247. return;
  248. if (data[1] == 0)
  249. ar2->mode = mode;
  250. }
  251. if (!((1 << mode) & mode_mask))
  252. return;
  253. index = ati_remote2_lookup(hw_code);
  254. if (index < 0) {
  255. dev_err(&ar2->intf[1]->dev,
  256. "Unknown code byte (%02x %02x %02x %02x)\n",
  257. data[3], data[2], data[1], data[0]);
  258. return;
  259. }
  260. switch (data[1]) {
  261. case 0: /* release */
  262. break;
  263. case 1: /* press */
  264. ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_DELAY]);
  265. break;
  266. case 2: /* repeat */
  267. /* No repeat for mouse buttons. */
  268. if (ar2->keycode[mode][index] == BTN_LEFT ||
  269. ar2->keycode[mode][index] == BTN_RIGHT)
  270. return;
  271. if (!time_after_eq(jiffies, ar2->jiffies))
  272. return;
  273. ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_PERIOD]);
  274. break;
  275. default:
  276. dev_err(&ar2->intf[1]->dev,
  277. "Unknown state byte (%02x %02x %02x %02x)\n",
  278. data[3], data[2], data[1], data[0]);
  279. return;
  280. }
  281. input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]);
  282. input_sync(idev);
  283. }
  284. static void ati_remote2_complete_mouse(struct urb *urb)
  285. {
  286. struct ati_remote2 *ar2 = urb->context;
  287. int r;
  288. switch (urb->status) {
  289. case 0:
  290. usb_mark_last_busy(ar2->udev);
  291. ati_remote2_input_mouse(ar2);
  292. break;
  293. case -ENOENT:
  294. case -EILSEQ:
  295. case -ECONNRESET:
  296. case -ESHUTDOWN:
  297. dev_dbg(&ar2->intf[0]->dev,
  298. "%s(): urb status = %d\n", __func__, urb->status);
  299. return;
  300. default:
  301. usb_mark_last_busy(ar2->udev);
  302. dev_err(&ar2->intf[0]->dev,
  303. "%s(): urb status = %d\n", __func__, urb->status);
  304. }
  305. r = usb_submit_urb(urb, GFP_ATOMIC);
  306. if (r)
  307. dev_err(&ar2->intf[0]->dev,
  308. "%s(): usb_submit_urb() = %d\n", __func__, r);
  309. }
  310. static void ati_remote2_complete_key(struct urb *urb)
  311. {
  312. struct ati_remote2 *ar2 = urb->context;
  313. int r;
  314. switch (urb->status) {
  315. case 0:
  316. usb_mark_last_busy(ar2->udev);
  317. ati_remote2_input_key(ar2);
  318. break;
  319. case -ENOENT:
  320. case -EILSEQ:
  321. case -ECONNRESET:
  322. case -ESHUTDOWN:
  323. dev_dbg(&ar2->intf[1]->dev,
  324. "%s(): urb status = %d\n", __func__, urb->status);
  325. return;
  326. default:
  327. usb_mark_last_busy(ar2->udev);
  328. dev_err(&ar2->intf[1]->dev,
  329. "%s(): urb status = %d\n", __func__, urb->status);
  330. }
  331. r = usb_submit_urb(urb, GFP_ATOMIC);
  332. if (r)
  333. dev_err(&ar2->intf[1]->dev,
  334. "%s(): usb_submit_urb() = %d\n", __func__, r);
  335. }
  336. static int ati_remote2_getkeycode(struct input_dev *idev,
  337. int scancode, int *keycode)
  338. {
  339. struct ati_remote2 *ar2 = input_get_drvdata(idev);
  340. int index, mode;
  341. mode = scancode >> 8;
  342. if (mode > ATI_REMOTE2_PC || !((1 << mode) & mode_mask))
  343. return -EINVAL;
  344. index = ati_remote2_lookup(scancode & 0xFF);
  345. if (index < 0)
  346. return -EINVAL;
  347. *keycode = ar2->keycode[mode][index];
  348. return 0;
  349. }
  350. static int ati_remote2_setkeycode(struct input_dev *idev, int scancode, int keycode)
  351. {
  352. struct ati_remote2 *ar2 = input_get_drvdata(idev);
  353. int index, mode, old_keycode;
  354. mode = scancode >> 8;
  355. if (mode > ATI_REMOTE2_PC || !((1 << mode) & mode_mask))
  356. return -EINVAL;
  357. index = ati_remote2_lookup(scancode & 0xFF);
  358. if (index < 0)
  359. return -EINVAL;
  360. if (keycode < KEY_RESERVED || keycode > KEY_MAX)
  361. return -EINVAL;
  362. old_keycode = ar2->keycode[mode][index];
  363. ar2->keycode[mode][index] = keycode;
  364. set_bit(keycode, idev->keybit);
  365. for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
  366. for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
  367. if (ar2->keycode[mode][index] == old_keycode)
  368. return 0;
  369. }
  370. }
  371. clear_bit(old_keycode, idev->keybit);
  372. return 0;
  373. }
  374. static int ati_remote2_input_init(struct ati_remote2 *ar2)
  375. {
  376. struct input_dev *idev;
  377. int index, mode, retval;
  378. idev = input_allocate_device();
  379. if (!idev)
  380. return -ENOMEM;
  381. ar2->idev = idev;
  382. input_set_drvdata(idev, ar2);
  383. idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL);
  384. idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
  385. BIT_MASK(BTN_RIGHT);
  386. idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  387. for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
  388. for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
  389. ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode;
  390. set_bit(ar2->keycode[mode][index], idev->keybit);
  391. }
  392. }
  393. /* AUX1-AUX4 and PC generate the same scancode. */
  394. index = ati_remote2_lookup(0x3f);
  395. ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1;
  396. ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2;
  397. ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3;
  398. ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4;
  399. ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC;
  400. set_bit(KEY_PROG1, idev->keybit);
  401. set_bit(KEY_PROG2, idev->keybit);
  402. set_bit(KEY_PROG3, idev->keybit);
  403. set_bit(KEY_PROG4, idev->keybit);
  404. set_bit(KEY_PC, idev->keybit);
  405. idev->rep[REP_DELAY] = 250;
  406. idev->rep[REP_PERIOD] = 33;
  407. idev->open = ati_remote2_open;
  408. idev->close = ati_remote2_close;
  409. idev->getkeycode = ati_remote2_getkeycode;
  410. idev->setkeycode = ati_remote2_setkeycode;
  411. idev->name = ar2->name;
  412. idev->phys = ar2->phys;
  413. usb_to_input_id(ar2->udev, &idev->id);
  414. idev->dev.parent = &ar2->udev->dev;
  415. retval = input_register_device(idev);
  416. if (retval)
  417. input_free_device(idev);
  418. return retval;
  419. }
  420. static int ati_remote2_urb_init(struct ati_remote2 *ar2)
  421. {
  422. struct usb_device *udev = ar2->udev;
  423. int i, pipe, maxp;
  424. for (i = 0; i < 2; i++) {
  425. ar2->buf[i] = usb_buffer_alloc(udev, 4, GFP_KERNEL, &ar2->buf_dma[i]);
  426. if (!ar2->buf[i])
  427. return -ENOMEM;
  428. ar2->urb[i] = usb_alloc_urb(0, GFP_KERNEL);
  429. if (!ar2->urb[i])
  430. return -ENOMEM;
  431. pipe = usb_rcvintpipe(udev, ar2->ep[i]->bEndpointAddress);
  432. maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
  433. maxp = maxp > 4 ? 4 : maxp;
  434. usb_fill_int_urb(ar2->urb[i], udev, pipe, ar2->buf[i], maxp,
  435. i ? ati_remote2_complete_key : ati_remote2_complete_mouse,
  436. ar2, ar2->ep[i]->bInterval);
  437. ar2->urb[i]->transfer_dma = ar2->buf_dma[i];
  438. ar2->urb[i]->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  439. }
  440. return 0;
  441. }
  442. static void ati_remote2_urb_cleanup(struct ati_remote2 *ar2)
  443. {
  444. int i;
  445. for (i = 0; i < 2; i++) {
  446. usb_free_urb(ar2->urb[i]);
  447. usb_buffer_free(ar2->udev, 4, ar2->buf[i], ar2->buf_dma[i]);
  448. }
  449. }
  450. static int ati_remote2_setup(struct ati_remote2 *ar2)
  451. {
  452. int r, i, channel;
  453. /*
  454. * Configure receiver to only accept input from remote "channel"
  455. * channel == 0 -> Accept input from any remote channel
  456. * channel == 1 -> Only accept input from remote channel 1
  457. * channel == 2 -> Only accept input from remote channel 2
  458. * ...
  459. * channel == 16 -> Only accept input from remote channel 16
  460. */
  461. channel = 0;
  462. for (i = 0; i < 16; i++) {
  463. if ((1 << i) & channel_mask) {
  464. if (!(~(1 << i) & 0xFFFF & channel_mask))
  465. channel = i + 1;
  466. break;
  467. }
  468. }
  469. r = usb_control_msg(ar2->udev, usb_sndctrlpipe(ar2->udev, 0),
  470. 0x20,
  471. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  472. channel, 0x0, NULL, 0, USB_CTRL_SET_TIMEOUT);
  473. if (r) {
  474. dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d\n",
  475. __func__, r);
  476. return r;
  477. }
  478. return 0;
  479. }
  480. static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id)
  481. {
  482. struct usb_device *udev = interface_to_usbdev(interface);
  483. struct usb_host_interface *alt = interface->cur_altsetting;
  484. struct ati_remote2 *ar2;
  485. int r;
  486. if (alt->desc.bInterfaceNumber)
  487. return -ENODEV;
  488. ar2 = kzalloc(sizeof (struct ati_remote2), GFP_KERNEL);
  489. if (!ar2)
  490. return -ENOMEM;
  491. ar2->udev = udev;
  492. ar2->intf[0] = interface;
  493. ar2->ep[0] = &alt->endpoint[0].desc;
  494. ar2->intf[1] = usb_ifnum_to_if(udev, 1);
  495. r = usb_driver_claim_interface(&ati_remote2_driver, ar2->intf[1], ar2);
  496. if (r)
  497. goto fail1;
  498. alt = ar2->intf[1]->cur_altsetting;
  499. ar2->ep[1] = &alt->endpoint[0].desc;
  500. r = ati_remote2_urb_init(ar2);
  501. if (r)
  502. goto fail2;
  503. r = ati_remote2_setup(ar2);
  504. if (r)
  505. goto fail2;
  506. usb_make_path(udev, ar2->phys, sizeof(ar2->phys));
  507. strlcat(ar2->phys, "/input0", sizeof(ar2->phys));
  508. strlcat(ar2->name, "ATI Remote Wonder II", sizeof(ar2->name));
  509. r = ati_remote2_input_init(ar2);
  510. if (r)
  511. goto fail2;
  512. usb_set_intfdata(interface, ar2);
  513. interface->needs_remote_wakeup = 1;
  514. return 0;
  515. fail2:
  516. ati_remote2_urb_cleanup(ar2);
  517. usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
  518. fail1:
  519. kfree(ar2);
  520. return r;
  521. }
  522. static void ati_remote2_disconnect(struct usb_interface *interface)
  523. {
  524. struct ati_remote2 *ar2;
  525. struct usb_host_interface *alt = interface->cur_altsetting;
  526. if (alt->desc.bInterfaceNumber)
  527. return;
  528. ar2 = usb_get_intfdata(interface);
  529. usb_set_intfdata(interface, NULL);
  530. input_unregister_device(ar2->idev);
  531. ati_remote2_urb_cleanup(ar2);
  532. usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
  533. kfree(ar2);
  534. }
  535. static int ati_remote2_suspend(struct usb_interface *interface,
  536. pm_message_t message)
  537. {
  538. struct ati_remote2 *ar2;
  539. struct usb_host_interface *alt = interface->cur_altsetting;
  540. if (alt->desc.bInterfaceNumber)
  541. return 0;
  542. ar2 = usb_get_intfdata(interface);
  543. dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
  544. mutex_lock(&ati_remote2_mutex);
  545. if (ar2->flags & ATI_REMOTE2_OPENED)
  546. ati_remote2_kill_urbs(ar2);
  547. ar2->flags |= ATI_REMOTE2_SUSPENDED;
  548. mutex_unlock(&ati_remote2_mutex);
  549. return 0;
  550. }
  551. static int ati_remote2_resume(struct usb_interface *interface)
  552. {
  553. struct ati_remote2 *ar2;
  554. struct usb_host_interface *alt = interface->cur_altsetting;
  555. int r = 0;
  556. if (alt->desc.bInterfaceNumber)
  557. return 0;
  558. ar2 = usb_get_intfdata(interface);
  559. dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
  560. mutex_lock(&ati_remote2_mutex);
  561. if (ar2->flags & ATI_REMOTE2_OPENED)
  562. r = ati_remote2_submit_urbs(ar2);
  563. if (!r)
  564. ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
  565. mutex_unlock(&ati_remote2_mutex);
  566. return r;
  567. }
  568. static int __init ati_remote2_init(void)
  569. {
  570. int r;
  571. r = usb_register(&ati_remote2_driver);
  572. if (r)
  573. printk(KERN_ERR "ati_remote2: usb_register() = %d\n", r);
  574. else
  575. printk(KERN_INFO "ati_remote2: " DRIVER_DESC " " DRIVER_VERSION "\n");
  576. return r;
  577. }
  578. static void __exit ati_remote2_exit(void)
  579. {
  580. usb_deregister(&ati_remote2_driver);
  581. }
  582. module_init(ati_remote2_init);
  583. module_exit(ati_remote2_exit);