go7007-loader.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (C) 2008 Sensoray Company Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License (Version 2) as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/slab.h>
  15. #include <linux/usb.h>
  16. #include <linux/firmware.h>
  17. #include <cypress_firmware.h>
  18. struct fw_config {
  19. u16 vendor;
  20. u16 product;
  21. const char * const fw_name1;
  22. const char * const fw_name2;
  23. };
  24. static struct fw_config fw_configs[] = {
  25. { 0x1943, 0xa250, "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/" },
  26. { 0x093b, 0xa002, "/*(DEBLOBBED)*/", NULL },
  27. { 0x093b, 0xa004, "/*(DEBLOBBED)*/", NULL },
  28. { 0x0eb1, 0x6666, "/*(DEBLOBBED)*/", NULL },
  29. { 0x0eb1, 0x6668, "/*(DEBLOBBED)*/", NULL },
  30. { 0, 0, NULL, NULL }
  31. };
  32. /*(DEBLOBBED)*/
  33. static int go7007_loader_probe(struct usb_interface *interface,
  34. const struct usb_device_id *id)
  35. {
  36. struct usb_device *usbdev;
  37. const struct firmware *fw;
  38. u16 vendor, product;
  39. const char *fw1, *fw2;
  40. int ret;
  41. int i;
  42. usbdev = usb_get_dev(interface_to_usbdev(interface));
  43. if (!usbdev)
  44. goto failed2;
  45. if (usbdev->descriptor.bNumConfigurations != 1) {
  46. dev_err(&interface->dev, "can't handle multiple config\n");
  47. goto failed2;
  48. }
  49. vendor = le16_to_cpu(usbdev->descriptor.idVendor);
  50. product = le16_to_cpu(usbdev->descriptor.idProduct);
  51. for (i = 0; fw_configs[i].fw_name1; i++)
  52. if (fw_configs[i].vendor == vendor &&
  53. fw_configs[i].product == product)
  54. break;
  55. /* Should never happen */
  56. if (fw_configs[i].fw_name1 == NULL)
  57. goto failed2;
  58. fw1 = fw_configs[i].fw_name1;
  59. fw2 = fw_configs[i].fw_name2;
  60. dev_info(&interface->dev, "loading firmware %s\n", fw1);
  61. if (reject_firmware(&fw, fw1, &usbdev->dev)) {
  62. dev_err(&interface->dev,
  63. "unable to load firmware from file \"%s\"\n", fw1);
  64. goto failed2;
  65. }
  66. ret = cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
  67. release_firmware(fw);
  68. if (0 != ret) {
  69. dev_err(&interface->dev, "loader download failed\n");
  70. goto failed2;
  71. }
  72. if (fw2 == NULL)
  73. return 0;
  74. if (reject_firmware(&fw, fw2, &usbdev->dev)) {
  75. dev_err(&interface->dev,
  76. "unable to load firmware from file \"%s\"\n", fw2);
  77. goto failed2;
  78. }
  79. ret = cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
  80. release_firmware(fw);
  81. if (0 != ret) {
  82. dev_err(&interface->dev, "firmware download failed\n");
  83. goto failed2;
  84. }
  85. return 0;
  86. failed2:
  87. usb_put_dev(usbdev);
  88. dev_err(&interface->dev, "probe failed\n");
  89. return -ENODEV;
  90. }
  91. static void go7007_loader_disconnect(struct usb_interface *interface)
  92. {
  93. dev_info(&interface->dev, "disconnect\n");
  94. usb_put_dev(interface_to_usbdev(interface));
  95. usb_set_intfdata(interface, NULL);
  96. }
  97. static const struct usb_device_id go7007_loader_ids[] = {
  98. { USB_DEVICE(0x1943, 0xa250) },
  99. { USB_DEVICE(0x093b, 0xa002) },
  100. { USB_DEVICE(0x093b, 0xa004) },
  101. { USB_DEVICE(0x0eb1, 0x6666) },
  102. { USB_DEVICE(0x0eb1, 0x6668) },
  103. {} /* Terminating entry */
  104. };
  105. MODULE_DEVICE_TABLE(usb, go7007_loader_ids);
  106. static struct usb_driver go7007_loader_driver = {
  107. .name = "go7007-loader",
  108. .probe = go7007_loader_probe,
  109. .disconnect = go7007_loader_disconnect,
  110. .id_table = go7007_loader_ids,
  111. };
  112. module_usb_driver(go7007_loader_driver);
  113. MODULE_AUTHOR("");
  114. MODULE_DESCRIPTION("firmware loader for go7007-usb");
  115. MODULE_LICENSE("GPL v2");