radio-maxiradio.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Guillemot Maxi Radio FM 2000 PCI radio card driver for Linux
  3. * (C) 2001 Dimitromanolakis Apostolos <apdim@grecian.net>
  4. *
  5. * Based in the radio Maestro PCI driver. Actually it uses the same chip
  6. * for radio but different pci controller.
  7. *
  8. * I didn't have any specs I reversed engineered the protocol from
  9. * the windows driver (radio.dll).
  10. *
  11. * The card uses the TEA5757 chip that includes a search function but it
  12. * is useless as I haven't found any way to read back the frequency. If
  13. * anybody does please mail me.
  14. *
  15. * For the pdf file see:
  16. * http://www.nxp.com/acrobat_download2/expired_datasheets/TEA5757_5759_3.pdf
  17. *
  18. *
  19. * CHANGES:
  20. * 0.75b
  21. * - better pci interface thanks to Francois Romieu <romieu@cogenit.fr>
  22. *
  23. * 0.75 Sun Feb 4 22:51:27 EET 2001
  24. * - tiding up
  25. * - removed support for multiple devices as it didn't work anyway
  26. *
  27. * BUGS:
  28. * - card unmutes if you change frequency
  29. *
  30. * (c) 2006, 2007 by Mauro Carvalho Chehab <mchehab@infradead.org>:
  31. * - Conversion to V4L2 API
  32. * - Uses video_ioctl2 for parsing and to add debug support
  33. */
  34. #include <linux/module.h>
  35. #include <linux/init.h>
  36. #include <linux/ioport.h>
  37. #include <linux/delay.h>
  38. #include <linux/mutex.h>
  39. #include <linux/pci.h>
  40. #include <linux/videodev2.h>
  41. #include <linux/io.h>
  42. #include <linux/slab.h>
  43. #include <sound/tea575x-tuner.h>
  44. #include <media/v4l2-device.h>
  45. #include <media/v4l2-ioctl.h>
  46. #include <media/v4l2-fh.h>
  47. #include <media/v4l2-ctrls.h>
  48. #include <media/v4l2-event.h>
  49. MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net");
  50. MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000.");
  51. MODULE_LICENSE("GPL");
  52. MODULE_VERSION("1.0.0");
  53. static int radio_nr = -1;
  54. module_param(radio_nr, int, 0644);
  55. MODULE_PARM_DESC(radio_nr, "Radio device number");
  56. /* TEA5757 pin mappings */
  57. static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
  58. static atomic_t maxiradio_instance = ATOMIC_INIT(0);
  59. #define PCI_VENDOR_ID_GUILLEMOT 0x5046
  60. #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
  61. struct maxiradio
  62. {
  63. struct snd_tea575x tea;
  64. struct v4l2_device v4l2_dev;
  65. struct pci_dev *pdev;
  66. u16 io; /* base of radio io */
  67. };
  68. static inline struct maxiradio *to_maxiradio(struct v4l2_device *v4l2_dev)
  69. {
  70. return container_of(v4l2_dev, struct maxiradio, v4l2_dev);
  71. }
  72. static void maxiradio_tea575x_set_pins(struct snd_tea575x *tea, u8 pins)
  73. {
  74. struct maxiradio *dev = tea->private_data;
  75. u8 bits = 0;
  76. bits |= (pins & TEA575X_DATA) ? data : 0;
  77. bits |= (pins & TEA575X_CLK) ? clk : 0;
  78. bits |= (pins & TEA575X_WREN) ? wren : 0;
  79. bits |= power;
  80. outb(bits, dev->io);
  81. }
  82. /* Note: this card cannot read out the data of the shift registers,
  83. only the mono/stereo pin works. */
  84. static u8 maxiradio_tea575x_get_pins(struct snd_tea575x *tea)
  85. {
  86. struct maxiradio *dev = tea->private_data;
  87. u8 bits = inb(dev->io);
  88. return ((bits & data) ? TEA575X_DATA : 0) |
  89. ((bits & mo_st) ? TEA575X_MOST : 0);
  90. }
  91. static void maxiradio_tea575x_set_direction(struct snd_tea575x *tea, bool output)
  92. {
  93. }
  94. static struct snd_tea575x_ops maxiradio_tea_ops = {
  95. .set_pins = maxiradio_tea575x_set_pins,
  96. .get_pins = maxiradio_tea575x_get_pins,
  97. .set_direction = maxiradio_tea575x_set_direction,
  98. };
  99. static int __devinit maxiradio_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  100. {
  101. struct maxiradio *dev;
  102. struct v4l2_device *v4l2_dev;
  103. int retval = -ENOMEM;
  104. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  105. if (dev == NULL) {
  106. dev_err(&pdev->dev, "not enough memory\n");
  107. return -ENOMEM;
  108. }
  109. v4l2_dev = &dev->v4l2_dev;
  110. v4l2_device_set_name(v4l2_dev, "maxiradio", &maxiradio_instance);
  111. retval = v4l2_device_register(&pdev->dev, v4l2_dev);
  112. if (retval < 0) {
  113. v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
  114. goto errfr;
  115. }
  116. dev->tea.private_data = dev;
  117. dev->tea.ops = &maxiradio_tea_ops;
  118. /* The data pin cannot be read. This may be a hardware limitation, or
  119. we just don't know how to read it. */
  120. dev->tea.cannot_read_data = true;
  121. dev->tea.v4l2_dev = v4l2_dev;
  122. dev->tea.radio_nr = radio_nr;
  123. strlcpy(dev->tea.card, "Maxi Radio FM2000", sizeof(dev->tea.card));
  124. snprintf(dev->tea.bus_info, sizeof(dev->tea.bus_info),
  125. "PCI:%s", pci_name(pdev));
  126. retval = -ENODEV;
  127. if (!request_region(pci_resource_start(pdev, 0),
  128. pci_resource_len(pdev, 0), v4l2_dev->name)) {
  129. dev_err(&pdev->dev, "can't reserve I/O ports\n");
  130. goto err_hdl;
  131. }
  132. if (pci_enable_device(pdev))
  133. goto err_out_free_region;
  134. dev->io = pci_resource_start(pdev, 0);
  135. if (snd_tea575x_init(&dev->tea)) {
  136. printk(KERN_ERR "radio-maxiradio: Unable to detect TEA575x tuner\n");
  137. goto err_out_free_region;
  138. }
  139. return 0;
  140. err_out_free_region:
  141. release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
  142. err_hdl:
  143. v4l2_device_unregister(v4l2_dev);
  144. errfr:
  145. kfree(dev);
  146. return retval;
  147. }
  148. static void __devexit maxiradio_remove(struct pci_dev *pdev)
  149. {
  150. struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
  151. struct maxiradio *dev = to_maxiradio(v4l2_dev);
  152. snd_tea575x_exit(&dev->tea);
  153. /* Turn off power */
  154. outb(0, dev->io);
  155. v4l2_device_unregister(v4l2_dev);
  156. release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
  157. }
  158. static struct pci_device_id maxiradio_pci_tbl[] = {
  159. { PCI_VENDOR_ID_GUILLEMOT, PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO,
  160. PCI_ANY_ID, PCI_ANY_ID, },
  161. { 0 }
  162. };
  163. MODULE_DEVICE_TABLE(pci, maxiradio_pci_tbl);
  164. static struct pci_driver maxiradio_driver = {
  165. .name = "radio-maxiradio",
  166. .id_table = maxiradio_pci_tbl,
  167. .probe = maxiradio_probe,
  168. .remove = __devexit_p(maxiradio_remove),
  169. };
  170. static int __init maxiradio_init(void)
  171. {
  172. return pci_register_driver(&maxiradio_driver);
  173. }
  174. static void __exit maxiradio_exit(void)
  175. {
  176. pci_unregister_driver(&maxiradio_driver);
  177. }
  178. module_init(maxiradio_init);
  179. module_exit(maxiradio_exit);