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. 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. /* bit definitions for register read */
  50. #define AZTECH_BIT_NOT_TUNED (1 << 0)
  51. #define AZTECH_BIT_MONO (1 << 1)
  52. /* bit definitions for register write */
  53. #define AZTECH_BIT_TUN_CE (1 << 1)
  54. #define AZTECH_BIT_TUN_CLK (1 << 6)
  55. #define AZTECH_BIT_TUN_DATA (1 << 7)
  56. /* bits 0 and 2 are volume control, bits 3..5 are not connected */
  57. static void aztech_set_pins(void *handle, u8 pins)
  58. {
  59. struct radio_isa_card *isa = handle;
  60. struct aztech *az = container_of(isa, struct aztech, isa);
  61. u8 bits = az->curvol;
  62. if (pins & LM7000_DATA)
  63. bits |= AZTECH_BIT_TUN_DATA;
  64. if (pins & LM7000_CLK)
  65. bits |= AZTECH_BIT_TUN_CLK;
  66. if (pins & LM7000_CE)
  67. bits |= AZTECH_BIT_TUN_CE;
  68. outb_p(bits, az->isa.io);
  69. }
  70. static struct radio_isa_card *aztech_alloc(void)
  71. {
  72. struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL);
  73. return az ? &az->isa : NULL;
  74. }
  75. static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq)
  76. {
  77. lm7000_set_freq(freq, isa, aztech_set_pins);
  78. return 0;
  79. }
  80. static u32 aztech_g_rxsubchans(struct radio_isa_card *isa)
  81. {
  82. if (inb(isa->io) & AZTECH_BIT_MONO)
  83. return V4L2_TUNER_SUB_MONO;
  84. return V4L2_TUNER_SUB_STEREO;
  85. }
  86. static u32 aztech_g_signal(struct radio_isa_card *isa)
  87. {
  88. return (inb(isa->io) & AZTECH_BIT_NOT_TUNED) ? 0 : 0xffff;
  89. }
  90. static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
  91. {
  92. struct aztech *az = container_of(isa, struct aztech, isa);
  93. if (mute)
  94. vol = 0;
  95. az->curvol = (vol & 1) + ((vol & 2) << 1);
  96. outb(az->curvol, isa->io);
  97. return 0;
  98. }
  99. static const struct radio_isa_ops aztech_ops = {
  100. .alloc = aztech_alloc,
  101. .s_mute_volume = aztech_s_mute_volume,
  102. .s_frequency = aztech_s_frequency,
  103. .g_rxsubchans = aztech_g_rxsubchans,
  104. .g_signal = aztech_g_signal,
  105. };
  106. static const int aztech_ioports[] = { 0x350, 0x358 };
  107. static struct radio_isa_driver aztech_driver = {
  108. .driver = {
  109. .match = radio_isa_match,
  110. .probe = radio_isa_probe,
  111. .remove = radio_isa_remove,
  112. .driver = {
  113. .name = "radio-aztech",
  114. },
  115. },
  116. .io_params = io,
  117. .radio_nr_params = radio_nr,
  118. .io_ports = aztech_ioports,
  119. .num_of_io_ports = ARRAY_SIZE(aztech_ioports),
  120. .region_size = 8,
  121. .card = "Aztech Radio",
  122. .ops = &aztech_ops,
  123. .has_stereo = true,
  124. .max_volume = 3,
  125. };
  126. static int __init aztech_init(void)
  127. {
  128. return isa_register_driver(&aztech_driver.driver, AZTECH_MAX);
  129. }
  130. static void __exit aztech_exit(void)
  131. {
  132. isa_unregister_driver(&aztech_driver.driver);
  133. }
  134. module_init(aztech_init);
  135. module_exit(aztech_exit);