radio-maxiradio.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Guillemot Maxi Radio FM 2000 PCI radio card driver for Linux
  4. * (C) 2001 Dimitromanolakis Apostolos <[email protected]>
  5. *
  6. * Based in the radio Maestro PCI driver. Actually it uses the same chip
  7. * for radio but different pci controller.
  8. *
  9. * I didn't have any specs I reversed engineered the protocol from
  10. * the windows driver (radio.dll).
  11. *
  12. * The card uses the TEA5757 chip that includes a search function but it
  13. * is useless as I haven't found any way to read back the frequency. If
  14. * anybody does please mail me.
  15. *
  16. * For the pdf file see:
  17. * http://www.nxp.com/acrobat_download2/expired_datasheets/TEA5757_5759_3.pdf
  18. *
  19. *
  20. * CHANGES:
  21. * 0.75b
  22. * - better pci interface thanks to Francois Romieu <[email protected]>
  23. *
  24. * 0.75 Sun Feb 4 22:51:27 EET 2001
  25. * - tiding up
  26. * - removed support for multiple devices as it didn't work anyway
  27. *
  28. * BUGS:
  29. * - card unmutes if you change frequency
  30. *
  31. * (c) 2006, 2007 by Mauro Carvalho Chehab <[email protected]>:
  32. * - Conversion to V4L2 API
  33. * - Uses video_ioctl2 for parsing and to add debug support
  34. */
  35. #include <linux/module.h>
  36. #include <linux/init.h>
  37. #include <linux/ioport.h>
  38. #include <linux/delay.h>
  39. #include <linux/mutex.h>
  40. #include <linux/pci.h>
  41. #include <linux/videodev2.h>
  42. #include <linux/io.h>
  43. #include <linux/slab.h>
  44. #include <media/drv-intf/tea575x.h>
  45. #include <media/v4l2-device.h>
  46. #include <media/v4l2-ioctl.h>
  47. #include <media/v4l2-fh.h>
  48. #include <media/v4l2-ctrls.h>
  49. #include <media/v4l2-event.h>
  50. MODULE_AUTHOR("Dimitromanolakis Apostolos, [email protected]");
  51. MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000.");
  52. MODULE_LICENSE("GPL");
  53. MODULE_VERSION("1.0.0");
  54. static int radio_nr = -1;
  55. module_param(radio_nr, int, 0644);
  56. MODULE_PARM_DESC(radio_nr, "Radio device number");
  57. /* TEA5757 pin mappings */
  58. static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
  59. static atomic_t maxiradio_instance = ATOMIC_INIT(0);
  60. #define PCI_VENDOR_ID_GUILLEMOT 0x5046
  61. #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
  62. struct maxiradio
  63. {
  64. struct snd_tea575x tea;
  65. struct v4l2_device v4l2_dev;
  66. struct pci_dev *pdev;
  67. u16 io; /* base of radio io */
  68. };
  69. static inline struct maxiradio *to_maxiradio(struct v4l2_device *v4l2_dev)
  70. {
  71. return container_of(v4l2_dev, struct maxiradio, v4l2_dev);
  72. }
  73. static void maxiradio_tea575x_set_pins(struct snd_tea575x *tea, u8 pins)
  74. {
  75. struct maxiradio *dev = tea->private_data;
  76. u8 bits = 0;
  77. bits |= (pins & TEA575X_DATA) ? data : 0;
  78. bits |= (pins & TEA575X_CLK) ? clk : 0;
  79. bits |= (pins & TEA575X_WREN) ? wren : 0;
  80. bits |= power;
  81. outb(bits, dev->io);
  82. }
  83. /* Note: this card cannot read out the data of the shift registers,
  84. only the mono/stereo pin works. */
  85. static u8 maxiradio_tea575x_get_pins(struct snd_tea575x *tea)
  86. {
  87. struct maxiradio *dev = tea->private_data;
  88. u8 bits = inb(dev->io);
  89. return ((bits & data) ? TEA575X_DATA : 0) |
  90. ((bits & mo_st) ? TEA575X_MOST : 0);
  91. }
  92. static void maxiradio_tea575x_set_direction(struct snd_tea575x *tea, bool output)
  93. {
  94. }
  95. static const struct snd_tea575x_ops maxiradio_tea_ops = {
  96. .set_pins = maxiradio_tea575x_set_pins,
  97. .get_pins = maxiradio_tea575x_get_pins,
  98. .set_direction = maxiradio_tea575x_set_direction,
  99. };
  100. static int maxiradio_probe(struct pci_dev *pdev,
  101. const struct pci_device_id *ent)
  102. {
  103. struct maxiradio *dev;
  104. struct v4l2_device *v4l2_dev;
  105. int retval = -ENOMEM;
  106. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  107. if (dev == NULL) {
  108. dev_err(&pdev->dev, "not enough memory\n");
  109. return -ENOMEM;
  110. }
  111. v4l2_dev = &dev->v4l2_dev;
  112. v4l2_device_set_name(v4l2_dev, "maxiradio", &maxiradio_instance);
  113. retval = v4l2_device_register(&pdev->dev, v4l2_dev);
  114. if (retval < 0) {
  115. v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
  116. goto errfr;
  117. }
  118. dev->tea.private_data = dev;
  119. dev->tea.ops = &maxiradio_tea_ops;
  120. /* The data pin cannot be read. This may be a hardware limitation, or
  121. we just don't know how to read it. */
  122. dev->tea.cannot_read_data = true;
  123. dev->tea.v4l2_dev = v4l2_dev;
  124. dev->tea.radio_nr = radio_nr;
  125. strscpy(dev->tea.card, "Maxi Radio FM2000", sizeof(dev->tea.card));
  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, THIS_MODULE)) {
  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 maxiradio_remove(struct pci_dev *pdev)
  149. {
  150. struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
  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. kfree(dev);
  158. }
  159. static const struct pci_device_id maxiradio_pci_tbl[] = {
  160. { PCI_VENDOR_ID_GUILLEMOT, PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO,
  161. PCI_ANY_ID, PCI_ANY_ID, },
  162. { 0 }
  163. };
  164. MODULE_DEVICE_TABLE(pci, maxiradio_pci_tbl);
  165. static struct pci_driver maxiradio_driver = {
  166. .name = "radio-maxiradio",
  167. .id_table = maxiradio_pci_tbl,
  168. .probe = maxiradio_probe,
  169. .remove = maxiradio_remove,
  170. };
  171. module_pci_driver(maxiradio_driver);