radio-rtrack2.c 3.4 KB

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