radio-terratec.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* Terratec ActiveRadio ISA Standalone card driver for Linux radio support
  2. * (c) 1999 R. Offermanns (rolf@offermanns.de)
  3. * based on the aimslab radio driver from M. Kirkwood
  4. * many thanks to Michael Becker and Friedhelm Birth (from TerraTec)
  5. *
  6. *
  7. * History:
  8. * 1999-05-21 First preview release
  9. *
  10. * Notes on the hardware:
  11. * There are two "main" chips on the card:
  12. * - Philips OM5610 (http://www-us.semiconductors.philips.com/acrobat/datasheets/OM5610_2.pdf)
  13. * - Philips SAA6588 (http://www-us.semiconductors.philips.com/acrobat/datasheets/SAA6588_1.pdf)
  14. * (you can get the datasheet at the above links)
  15. *
  16. * Frequency control is done digitally -- ie out(port,encodefreq(95.8));
  17. * Volume Control is done digitally
  18. *
  19. * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
  20. * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
  21. */
  22. #include <linux/module.h> /* Modules */
  23. #include <linux/init.h> /* Initdata */
  24. #include <linux/ioport.h> /* request_region */
  25. #include <linux/videodev2.h> /* kernel radio structs */
  26. #include <linux/mutex.h>
  27. #include <linux/io.h> /* outb, outb_p */
  28. #include <linux/slab.h>
  29. #include <media/v4l2-device.h>
  30. #include <media/v4l2-ioctl.h>
  31. #include "radio-isa.h"
  32. MODULE_AUTHOR("R. Offermans & others");
  33. MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card.");
  34. MODULE_LICENSE("GPL");
  35. MODULE_VERSION("0.1.99");
  36. /* Note: there seems to be only one possible port (0x590), but without
  37. hardware this is hard to verify. For now, this is the only one we will
  38. support. */
  39. static int io = 0x590;
  40. static int radio_nr = -1;
  41. module_param(radio_nr, int, 0444);
  42. MODULE_PARM_DESC(radio_nr, "Radio device number");
  43. #define WRT_DIS 0x00
  44. #define CLK_OFF 0x00
  45. #define IIC_DATA 0x01
  46. #define IIC_CLK 0x02
  47. #define DATA 0x04
  48. #define CLK_ON 0x08
  49. #define WRT_EN 0x10
  50. static struct radio_isa_card *terratec_alloc(void)
  51. {
  52. return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
  53. }
  54. static int terratec_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
  55. {
  56. int i;
  57. if (mute)
  58. vol = 0;
  59. vol = vol + (vol * 32); /* change both channels */
  60. for (i = 0; i < 8; i++) {
  61. if (vol & (0x80 >> i))
  62. outb(0x80, isa->io + 1);
  63. else
  64. outb(0x00, isa->io + 1);
  65. }
  66. return 0;
  67. }
  68. /* this is the worst part in this driver */
  69. /* many more or less strange things are going on here, but hey, it works :) */
  70. static int terratec_s_frequency(struct radio_isa_card *isa, u32 freq)
  71. {
  72. int i;
  73. int p;
  74. int temp;
  75. long rest;
  76. unsigned char buffer[25]; /* we have to bit shift 25 registers */
  77. freq = freq / 160; /* convert the freq. to a nice to handle value */
  78. memset(buffer, 0, sizeof(buffer));
  79. rest = freq * 10 + 10700; /* I once had understood what is going on here */
  80. /* maybe some wise guy (friedhelm?) can comment this stuff */
  81. i = 13;
  82. p = 10;
  83. temp = 102400;
  84. while (rest != 0) {
  85. if (rest % temp == rest)
  86. buffer[i] = 0;
  87. else {
  88. buffer[i] = 1;
  89. rest = rest - temp;
  90. }
  91. i--;
  92. p--;
  93. temp = temp / 2;
  94. }
  95. for (i = 24; i > -1; i--) { /* bit shift the values to the radiocard */
  96. if (buffer[i] == 1) {
  97. outb(WRT_EN | DATA, isa->io);
  98. outb(WRT_EN | DATA | CLK_ON, isa->io);
  99. outb(WRT_EN | DATA, isa->io);
  100. } else {
  101. outb(WRT_EN | 0x00, isa->io);
  102. outb(WRT_EN | 0x00 | CLK_ON, isa->io);
  103. }
  104. }
  105. outb(0x00, isa->io);
  106. return 0;
  107. }
  108. static u32 terratec_g_signal(struct radio_isa_card *isa)
  109. {
  110. /* bit set = no signal present */
  111. return (inb(isa->io) & 2) ? 0 : 0xffff;
  112. }
  113. static const struct radio_isa_ops terratec_ops = {
  114. .alloc = terratec_alloc,
  115. .s_mute_volume = terratec_s_mute_volume,
  116. .s_frequency = terratec_s_frequency,
  117. .g_signal = terratec_g_signal,
  118. };
  119. static const int terratec_ioports[] = { 0x590 };
  120. static struct radio_isa_driver terratec_driver = {
  121. .driver = {
  122. .match = radio_isa_match,
  123. .probe = radio_isa_probe,
  124. .remove = radio_isa_remove,
  125. .driver = {
  126. .name = "radio-terratec",
  127. },
  128. },
  129. .io_params = &io,
  130. .radio_nr_params = &radio_nr,
  131. .io_ports = terratec_ioports,
  132. .num_of_io_ports = ARRAY_SIZE(terratec_ioports),
  133. .region_size = 2,
  134. .card = "TerraTec ActiveRadio",
  135. .ops = &terratec_ops,
  136. .has_stereo = true,
  137. .max_volume = 10,
  138. };
  139. static int __init terratec_init(void)
  140. {
  141. return isa_register_driver(&terratec_driver.driver, 1);
  142. }
  143. static void __exit terratec_exit(void)
  144. {
  145. isa_unregister_driver(&terratec_driver.driver);
  146. }
  147. module_init(terratec_init);
  148. module_exit(terratec_exit);