funsoft.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Funsoft Serial USB driver
  3. *
  4. * Copyright (C) 2006 Greg Kroah-Hartman <gregkh@suse.de>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/tty.h>
  13. #include <linux/module.h>
  14. #include <linux/usb.h>
  15. #include <linux/usb/serial.h>
  16. #include <asm/uaccess.h>
  17. static int debug;
  18. static struct usb_device_id id_table [] = {
  19. { USB_DEVICE(0x1404, 0xcddc) },
  20. { },
  21. };
  22. MODULE_DEVICE_TABLE(usb, id_table);
  23. static int funsoft_ioctl(struct usb_serial_port *port, struct file *file,
  24. unsigned int cmd, unsigned long arg)
  25. {
  26. struct termios t;
  27. dbg("%s - port %d, cmd 0x%04x", __FUNCTION__, port->number, cmd);
  28. if (cmd == TCSETSF) {
  29. if (user_termios_to_kernel_termios(&t, (void __user *)arg))
  30. return -EFAULT;
  31. dbg("%s - iflag:%x oflag:%x cflag:%x lflag:%x", __FUNCTION__,
  32. t.c_iflag, t.c_oflag, t.c_cflag, t.c_lflag);
  33. if (!(t.c_lflag & ICANON))
  34. return -EINVAL;
  35. }
  36. return -ENOIOCTLCMD;
  37. }
  38. static struct usb_driver funsoft_driver = {
  39. .name = "funsoft",
  40. .probe = usb_serial_probe,
  41. .disconnect = usb_serial_disconnect,
  42. .id_table = id_table,
  43. .no_dynamic_id = 1,
  44. };
  45. static struct usb_serial_driver funsoft_device = {
  46. .driver = {
  47. .owner = THIS_MODULE,
  48. .name = "funsoft",
  49. },
  50. .id_table = id_table,
  51. .num_interrupt_in = NUM_DONT_CARE,
  52. .num_bulk_in = NUM_DONT_CARE,
  53. .num_bulk_out = NUM_DONT_CARE,
  54. .num_ports = 1,
  55. .ioctl = funsoft_ioctl,
  56. };
  57. static int __init funsoft_init(void)
  58. {
  59. int retval;
  60. retval = usb_serial_register(&funsoft_device);
  61. if (retval)
  62. return retval;
  63. retval = usb_register(&funsoft_driver);
  64. if (retval)
  65. usb_serial_deregister(&funsoft_device);
  66. return retval;
  67. }
  68. static void __exit funsoft_exit(void)
  69. {
  70. usb_deregister(&funsoft_driver);
  71. usb_serial_deregister(&funsoft_device);
  72. }
  73. module_init(funsoft_init);
  74. module_exit(funsoft_exit);
  75. MODULE_LICENSE("GPL");
  76. module_param(debug, bool, S_IRUGO | S_IWUSR);
  77. MODULE_PARM_DESC(debug, "Debug enabled or not");