radio-maxiradio.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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@kernel.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 <media/drv-intf/tea575x.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 const 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 maxiradio_probe(struct pci_dev *pdev,
  100. const struct pci_device_id *ent)
  101. {
  102. struct maxiradio *dev;
  103. struct v4l2_device *v4l2_dev;
  104. int retval = -ENOMEM;
  105. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  106. if (dev == NULL) {
  107. dev_err(&pdev->dev, "not enough memory\n");
  108. return -ENOMEM;
  109. }
  110. v4l2_dev = &dev->v4l2_dev;
  111. v4l2_device_set_name(v4l2_dev, "maxiradio", &maxiradio_instance);
  112. retval = v4l2_device_register(&pdev->dev, v4l2_dev);
  113. if (retval < 0) {
  114. v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
  115. goto errfr;
  116. }
  117. dev->tea.private_data = dev;
  118. dev->tea.ops = &maxiradio_tea_ops;
  119. /* The data pin cannot be read. This may be a hardware limitation, or
  120. we just don't know how to read it. */
  121. dev->tea.cannot_read_data = true;
  122. dev->tea.v4l2_dev = v4l2_dev;
  123. dev->tea.radio_nr = radio_nr;
  124. strlcpy(dev->tea.card, "Maxi Radio FM2000", sizeof(dev->tea.card));
  125. snprintf(dev->tea.bus_info, sizeof(dev->tea.bus_info),
  126. "PCI:%s", pci_name(pdev));
  127. retval = -ENODEV;
  128. if (!request_region(pci_resource_start(pdev, 0),
  129. pci_resource_len(pdev, 0), v4l2_dev->name)) {
  130. dev_err(&pdev->dev, "can't reserve I/O ports\n");
  131. goto err_hdl;
  132. }
  133. if (pci_enable_device(pdev))
  134. goto err_out_free_region;
  135. dev->io = pci_resource_start(pdev, 0);
  136. if (snd_tea575x_init(&dev->tea, THIS_MODULE)) {
  137. printk(KERN_ERR "radio-maxiradio: Unable to detect TEA575x tuner\n");
  138. goto err_out_free_region;
  139. }
  140. return 0;
  141. err_out_free_region:
  142. release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
  143. err_hdl:
  144. v4l2_device_unregister(v4l2_dev);
  145. errfr:
  146. kfree(dev);
  147. return retval;
  148. }
  149. static void maxiradio_remove(struct pci_dev *pdev)
  150. {
  151. struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
  152. struct maxiradio *dev = to_maxiradio(v4l2_dev);
  153. snd_tea575x_exit(&dev->tea);
  154. /* Turn off power */
  155. outb(0, dev->io);
  156. v4l2_device_unregister(v4l2_dev);
  157. release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
  158. kfree(dev);
  159. }
  160. static const struct pci_device_id maxiradio_pci_tbl[] = {
  161. { PCI_VENDOR_ID_GUILLEMOT, PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO,
  162. PCI_ANY_ID, PCI_ANY_ID, },
  163. { 0 }
  164. };
  165. MODULE_DEVICE_TABLE(pci, maxiradio_pci_tbl);
  166. static struct pci_driver maxiradio_driver = {
  167. .name = "radio-maxiradio",
  168. .id_table = maxiradio_pci_tbl,
  169. .probe = maxiradio_probe,
  170. .remove = maxiradio_remove,
  171. };
  172. module_pci_driver(maxiradio_driver);