radio-terratec.c 4.4 KB

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