radio-rtrack2.c 3.4 KB

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