radio-aztech.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * radio-aztech.c - Aztech radio card driver
  3. *
  4. * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@xs4all.nl>
  5. * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
  6. * Adapted to support the Video for Linux API by
  7. * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by:
  8. *
  9. * Quay Ly
  10. * Donald Song
  11. * Jason Lewis (jlewis@twilight.vtc.vsc.edu)
  12. * Scott McGrath (smcgrath@twilight.vtc.vsc.edu)
  13. * William McGrath (wmcgrath@twilight.vtc.vsc.edu)
  14. *
  15. * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool.
  16. */
  17. #include <linux/module.h> /* Modules */
  18. #include <linux/init.h> /* Initdata */
  19. #include <linux/ioport.h> /* request_region */
  20. #include <linux/delay.h> /* udelay */
  21. #include <linux/videodev2.h> /* kernel radio structs */
  22. #include <linux/io.h> /* outb, outb_p */
  23. #include <linux/slab.h>
  24. #include <media/v4l2-device.h>
  25. #include <media/v4l2-ioctl.h>
  26. #include <media/v4l2-ctrls.h>
  27. #include "radio-isa.h"
  28. #include "lm7000.h"
  29. MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
  30. MODULE_DESCRIPTION("A driver for the Aztech radio card.");
  31. MODULE_LICENSE("GPL");
  32. MODULE_VERSION("1.0.0");
  33. /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
  34. #ifndef CONFIG_RADIO_AZTECH_PORT
  35. #define CONFIG_RADIO_AZTECH_PORT -1
  36. #endif
  37. #define AZTECH_MAX 2
  38. static int io[AZTECH_MAX] = { [0] = CONFIG_RADIO_AZTECH_PORT,
  39. [1 ... (AZTECH_MAX - 1)] = -1 };
  40. static int radio_nr[AZTECH_MAX] = { [0 ... (AZTECH_MAX - 1)] = -1 };
  41. static const int radio_wait_time = 1000;
  42. module_param_array(io, int, NULL, 0444);
  43. MODULE_PARM_DESC(io, "I/O addresses of the Aztech card (0x350 or 0x358)");
  44. module_param_array(radio_nr, int, NULL, 0444);
  45. MODULE_PARM_DESC(radio_nr, "Radio device numbers");
  46. struct aztech {
  47. struct radio_isa_card isa;
  48. int curvol;
  49. };
  50. /* bit definitions for register read */
  51. #define AZTECH_BIT_NOT_TUNED (1 << 0)
  52. #define AZTECH_BIT_MONO (1 << 1)
  53. /* bit definitions for register write */
  54. #define AZTECH_BIT_TUN_CE (1 << 1)
  55. #define AZTECH_BIT_TUN_CLK (1 << 6)
  56. #define AZTECH_BIT_TUN_DATA (1 << 7)
  57. /* bits 0 and 2 are volume control, bits 3..5 are not connected */
  58. static void aztech_set_pins(void *handle, u8 pins)
  59. {
  60. struct radio_isa_card *isa = handle;
  61. struct aztech *az = container_of(isa, struct aztech, isa);
  62. u8 bits = az->curvol;
  63. if (pins & LM7000_DATA)
  64. bits |= AZTECH_BIT_TUN_DATA;
  65. if (pins & LM7000_CLK)
  66. bits |= AZTECH_BIT_TUN_CLK;
  67. if (pins & LM7000_CE)
  68. bits |= AZTECH_BIT_TUN_CE;
  69. outb_p(bits, az->isa.io);
  70. }
  71. static struct radio_isa_card *aztech_alloc(void)
  72. {
  73. struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL);
  74. return az ? &az->isa : NULL;
  75. }
  76. static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq)
  77. {
  78. lm7000_set_freq(freq, isa, aztech_set_pins);
  79. return 0;
  80. }
  81. static u32 aztech_g_rxsubchans(struct radio_isa_card *isa)
  82. {
  83. if (inb(isa->io) & AZTECH_BIT_MONO)
  84. return V4L2_TUNER_SUB_MONO;
  85. return V4L2_TUNER_SUB_STEREO;
  86. }
  87. static u32 aztech_g_signal(struct radio_isa_card *isa)
  88. {
  89. return (inb(isa->io) & AZTECH_BIT_NOT_TUNED) ? 0 : 0xffff;
  90. }
  91. static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
  92. {
  93. struct aztech *az = container_of(isa, struct aztech, isa);
  94. if (mute)
  95. vol = 0;
  96. az->curvol = (vol & 1) + ((vol & 2) << 1);
  97. outb(az->curvol, isa->io);
  98. return 0;
  99. }
  100. static const struct radio_isa_ops aztech_ops = {
  101. .alloc = aztech_alloc,
  102. .s_mute_volume = aztech_s_mute_volume,
  103. .s_frequency = aztech_s_frequency,
  104. .g_rxsubchans = aztech_g_rxsubchans,
  105. .g_signal = aztech_g_signal,
  106. };
  107. static const int aztech_ioports[] = { 0x350, 0x358 };
  108. static struct radio_isa_driver aztech_driver = {
  109. .driver = {
  110. .match = radio_isa_match,
  111. .probe = radio_isa_probe,
  112. .remove = radio_isa_remove,
  113. .driver = {
  114. .name = "radio-aztech",
  115. },
  116. },
  117. .io_params = io,
  118. .radio_nr_params = radio_nr,
  119. .io_ports = aztech_ioports,
  120. .num_of_io_ports = ARRAY_SIZE(aztech_ioports),
  121. .region_size = 8,
  122. .card = "Aztech Radio",
  123. .ops = &aztech_ops,
  124. .has_stereo = true,
  125. .max_volume = 3,
  126. };
  127. static int __init aztech_init(void)
  128. {
  129. return isa_register_driver(&aztech_driver.driver, AZTECH_MAX);
  130. }
  131. static void __exit aztech_exit(void)
  132. {
  133. isa_unregister_driver(&aztech_driver.driver);
  134. }
  135. module_init(aztech_init);
  136. module_exit(aztech_exit);