radio-aztech.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
  29. MODULE_DESCRIPTION("A driver for the Aztech radio card.");
  30. MODULE_LICENSE("GPL");
  31. MODULE_VERSION("1.0.0");
  32. /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
  33. #ifndef CONFIG_RADIO_AZTECH_PORT
  34. #define CONFIG_RADIO_AZTECH_PORT -1
  35. #endif
  36. #define AZTECH_MAX 2
  37. static int io[AZTECH_MAX] = { [0] = CONFIG_RADIO_AZTECH_PORT,
  38. [1 ... (AZTECH_MAX - 1)] = -1 };
  39. static int radio_nr[AZTECH_MAX] = { [0 ... (AZTECH_MAX - 1)] = -1 };
  40. static const int radio_wait_time = 1000;
  41. module_param_array(io, int, NULL, 0444);
  42. MODULE_PARM_DESC(io, "I/O addresses of the Aztech card (0x350 or 0x358)");
  43. module_param_array(radio_nr, int, NULL, 0444);
  44. MODULE_PARM_DESC(radio_nr, "Radio device numbers");
  45. struct aztech {
  46. struct radio_isa_card isa;
  47. int curvol;
  48. };
  49. static void send_0_byte(struct aztech *az)
  50. {
  51. udelay(radio_wait_time);
  52. outb_p(2 + az->curvol, az->isa.io);
  53. outb_p(64 + 2 + az->curvol, az->isa.io);
  54. }
  55. static void send_1_byte(struct aztech *az)
  56. {
  57. udelay(radio_wait_time);
  58. outb_p(128 + 2 + az->curvol, az->isa.io);
  59. outb_p(128 + 64 + 2 + az->curvol, az->isa.io);
  60. }
  61. static struct radio_isa_card *aztech_alloc(void)
  62. {
  63. struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL);
  64. return az ? &az->isa : NULL;
  65. }
  66. static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq)
  67. {
  68. struct aztech *az = container_of(isa, struct aztech, isa);
  69. int i;
  70. freq += 171200; /* Add 10.7 MHz IF */
  71. freq /= 800; /* Convert to 50 kHz units */
  72. send_0_byte(az); /* 0: LSB of frequency */
  73. for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
  74. if (freq & (1 << i))
  75. send_1_byte(az);
  76. else
  77. send_0_byte(az);
  78. send_0_byte(az); /* 14: test bit - always 0 */
  79. send_0_byte(az); /* 15: test bit - always 0 */
  80. send_0_byte(az); /* 16: band data 0 - always 0 */
  81. if (isa->stereo) /* 17: stereo (1 to enable) */
  82. send_1_byte(az);
  83. else
  84. send_0_byte(az);
  85. send_1_byte(az); /* 18: band data 1 - unknown */
  86. send_0_byte(az); /* 19: time base - always 0 */
  87. send_0_byte(az); /* 20: spacing (0 = 25 kHz) */
  88. send_1_byte(az); /* 21: spacing (1 = 25 kHz) */
  89. send_0_byte(az); /* 22: spacing (0 = 25 kHz) */
  90. send_1_byte(az); /* 23: AM/FM (FM = 1, always) */
  91. /* latch frequency */
  92. udelay(radio_wait_time);
  93. outb_p(128 + 64 + az->curvol, az->isa.io);
  94. return 0;
  95. }
  96. /* thanks to Michael Dwyer for giving me a dose of clues in
  97. * the signal strength department..
  98. *
  99. * This card has a stereo bit - bit 0 set = mono, not set = stereo
  100. */
  101. static u32 aztech_g_rxsubchans(struct radio_isa_card *isa)
  102. {
  103. if (inb(isa->io) & 1)
  104. return V4L2_TUNER_SUB_MONO;
  105. return V4L2_TUNER_SUB_STEREO;
  106. }
  107. static int aztech_s_stereo(struct radio_isa_card *isa, bool stereo)
  108. {
  109. return aztech_s_frequency(isa, isa->freq);
  110. }
  111. static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
  112. {
  113. struct aztech *az = container_of(isa, struct aztech, isa);
  114. if (mute)
  115. vol = 0;
  116. az->curvol = (vol & 1) + ((vol & 2) << 1);
  117. outb(az->curvol, isa->io);
  118. return 0;
  119. }
  120. static const struct radio_isa_ops aztech_ops = {
  121. .alloc = aztech_alloc,
  122. .s_mute_volume = aztech_s_mute_volume,
  123. .s_frequency = aztech_s_frequency,
  124. .s_stereo = aztech_s_stereo,
  125. .g_rxsubchans = aztech_g_rxsubchans,
  126. };
  127. static const int aztech_ioports[] = { 0x350, 0x358 };
  128. static struct radio_isa_driver aztech_driver = {
  129. .driver = {
  130. .match = radio_isa_match,
  131. .probe = radio_isa_probe,
  132. .remove = radio_isa_remove,
  133. .driver = {
  134. .name = "radio-aztech",
  135. },
  136. },
  137. .io_params = io,
  138. .radio_nr_params = radio_nr,
  139. .io_ports = aztech_ioports,
  140. .num_of_io_ports = ARRAY_SIZE(aztech_ioports),
  141. .region_size = 2,
  142. .card = "Aztech Radio",
  143. .ops = &aztech_ops,
  144. .has_stereo = true,
  145. .max_volume = 3,
  146. };
  147. static int __init aztech_init(void)
  148. {
  149. return isa_register_driver(&aztech_driver.driver, AZTECH_MAX);
  150. }
  151. static void __exit aztech_exit(void)
  152. {
  153. isa_unregister_driver(&aztech_driver.driver);
  154. }
  155. module_init(aztech_init);
  156. module_exit(aztech_exit);