radio-rtrack2.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * RadioTrack II driver
  3. * Copyright 1998 Ben Pfaff
  4. *
  5. * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
  6. * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
  7. * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
  8. *
  9. * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
  10. * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
  11. */
  12. #include <linux/module.h> /* Modules */
  13. #include <linux/init.h> /* Initdata */
  14. #include <linux/ioport.h> /* request_region */
  15. #include <linux/delay.h> /* udelay */
  16. #include <linux/videodev2.h> /* kernel radio structs */
  17. #include <linux/mutex.h>
  18. #include <linux/io.h> /* outb, outb_p */
  19. #include <media/v4l2-device.h>
  20. #include <media/v4l2-ioctl.h>
  21. #include "radio-isa.h"
  22. MODULE_AUTHOR("Ben Pfaff");
  23. MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
  24. MODULE_LICENSE("GPL");
  25. MODULE_VERSION("0.1.99");
  26. #ifndef CONFIG_RADIO_RTRACK2_PORT
  27. #define CONFIG_RADIO_RTRACK2_PORT -1
  28. #endif
  29. #define RTRACK2_MAX 2
  30. static int io[RTRACK2_MAX] = { [0] = CONFIG_RADIO_RTRACK2_PORT,
  31. [1 ... (RTRACK2_MAX - 1)] = -1 };
  32. static int radio_nr[RTRACK2_MAX] = { [0 ... (RTRACK2_MAX - 1)] = -1 };
  33. module_param_array(io, int, NULL, 0444);
  34. MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
  35. module_param_array(radio_nr, int, NULL, 0444);
  36. MODULE_PARM_DESC(radio_nr, "Radio device numbers");
  37. static struct radio_isa_card *rtrack2_alloc(void)
  38. {
  39. return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
  40. }
  41. static void zero(struct radio_isa_card *isa)
  42. {
  43. outb_p(1, isa->io);
  44. outb_p(3, isa->io);
  45. outb_p(1, isa->io);
  46. }
  47. static void one(struct radio_isa_card *isa)
  48. {
  49. outb_p(5, isa->io);
  50. outb_p(7, isa->io);
  51. outb_p(5, isa->io);
  52. }
  53. static int rtrack2_s_frequency(struct radio_isa_card *isa, u32 freq)
  54. {
  55. int i;
  56. freq = freq / 200 + 856;
  57. outb_p(0xc8, isa->io);
  58. outb_p(0xc9, isa->io);
  59. outb_p(0xc9, isa->io);
  60. for (i = 0; i < 10; i++)
  61. zero(isa);
  62. for (i = 14; i >= 0; i--)
  63. if (freq & (1 << i))
  64. one(isa);
  65. else
  66. zero(isa);
  67. outb_p(0xc8, isa->io);
  68. if (!v4l2_ctrl_g_ctrl(isa->mute))
  69. outb_p(0, isa->io);
  70. return 0;
  71. }
  72. static u32 rtrack2_g_signal(struct radio_isa_card *isa)
  73. {
  74. /* bit set = no signal present */
  75. return (inb(isa->io) & 2) ? 0 : 0xffff;
  76. }
  77. static int rtrack2_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
  78. {
  79. outb(mute, isa->io);
  80. return 0;
  81. }
  82. static const struct radio_isa_ops rtrack2_ops = {
  83. .alloc = rtrack2_alloc,
  84. .s_mute_volume = rtrack2_s_mute_volume,
  85. .s_frequency = rtrack2_s_frequency,
  86. .g_signal = rtrack2_g_signal,
  87. };
  88. static const int rtrack2_ioports[] = { 0x20f, 0x30f };
  89. static struct radio_isa_driver rtrack2_driver = {
  90. .driver = {
  91. .match = radio_isa_match,
  92. .probe = radio_isa_probe,
  93. .remove = radio_isa_remove,
  94. .driver = {
  95. .name = "radio-rtrack2",
  96. },
  97. },
  98. .io_params = io,
  99. .radio_nr_params = radio_nr,
  100. .io_ports = rtrack2_ioports,
  101. .num_of_io_ports = ARRAY_SIZE(rtrack2_ioports),
  102. .region_size = 4,
  103. .card = "AIMSlab RadioTrack II",
  104. .ops = &rtrack2_ops,
  105. .has_stereo = true,
  106. };
  107. static int __init rtrack2_init(void)
  108. {
  109. return isa_register_driver(&rtrack2_driver.driver, RTRACK2_MAX);
  110. }
  111. static void __exit rtrack2_exit(void)
  112. {
  113. isa_unregister_driver(&rtrack2_driver.driver);
  114. }
  115. module_init(rtrack2_init);
  116. module_exit(rtrack2_exit);