split dev_queue
[cor.git] / drivers / media / radio / radio-rtrack2.c
blob73d2c187f1227fdd32e3507d94cddc1b667423da
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * RadioTrack II driver
4 * Copyright 1998 Ben Pfaff
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>
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>
13 * Fully tested with actual hardware and the v4l2-compliance tool.
16 #include <linux/module.h> /* Modules */
17 #include <linux/init.h> /* Initdata */
18 #include <linux/ioport.h> /* request_region */
19 #include <linux/delay.h> /* udelay */
20 #include <linux/videodev2.h> /* kernel radio structs */
21 #include <linux/mutex.h>
22 #include <linux/io.h> /* outb, outb_p */
23 #include <linux/slab.h>
24 #include <media/v4l2-device.h>
25 #include <media/v4l2-ioctl.h>
26 #include "radio-isa.h"
28 MODULE_AUTHOR("Ben Pfaff");
29 MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
30 MODULE_LICENSE("GPL");
31 MODULE_VERSION("0.1.99");
33 #ifndef CONFIG_RADIO_RTRACK2_PORT
34 #define CONFIG_RADIO_RTRACK2_PORT -1
35 #endif
37 #define RTRACK2_MAX 2
39 static int io[RTRACK2_MAX] = { [0] = CONFIG_RADIO_RTRACK2_PORT,
40 [1 ... (RTRACK2_MAX - 1)] = -1 };
41 static int radio_nr[RTRACK2_MAX] = { [0 ... (RTRACK2_MAX - 1)] = -1 };
43 module_param_array(io, int, NULL, 0444);
44 MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
45 module_param_array(radio_nr, int, NULL, 0444);
46 MODULE_PARM_DESC(radio_nr, "Radio device numbers");
48 static struct radio_isa_card *rtrack2_alloc(void)
50 return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
53 static void zero(struct radio_isa_card *isa)
55 outb_p(1, isa->io);
56 outb_p(3, isa->io);
57 outb_p(1, isa->io);
60 static void one(struct radio_isa_card *isa)
62 outb_p(5, isa->io);
63 outb_p(7, isa->io);
64 outb_p(5, isa->io);
67 static int rtrack2_s_frequency(struct radio_isa_card *isa, u32 freq)
69 int i;
71 freq = freq / 200 + 856;
73 outb_p(0xc8, isa->io);
74 outb_p(0xc9, isa->io);
75 outb_p(0xc9, isa->io);
77 for (i = 0; i < 10; i++)
78 zero(isa);
80 for (i = 14; i >= 0; i--)
81 if (freq & (1 << i))
82 one(isa);
83 else
84 zero(isa);
86 outb_p(0xc8, isa->io);
87 outb_p(v4l2_ctrl_g_ctrl(isa->mute), isa->io);
88 return 0;
91 static u32 rtrack2_g_signal(struct radio_isa_card *isa)
93 /* bit set = no signal present */
94 return (inb(isa->io) & 2) ? 0 : 0xffff;
97 static int rtrack2_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
99 outb(mute, isa->io);
100 return 0;
103 static const struct radio_isa_ops rtrack2_ops = {
104 .alloc = rtrack2_alloc,
105 .s_mute_volume = rtrack2_s_mute_volume,
106 .s_frequency = rtrack2_s_frequency,
107 .g_signal = rtrack2_g_signal,
110 static const int rtrack2_ioports[] = { 0x20f, 0x30f };
112 static struct radio_isa_driver rtrack2_driver = {
113 .driver = {
114 .match = radio_isa_match,
115 .probe = radio_isa_probe,
116 .remove = radio_isa_remove,
117 .driver = {
118 .name = "radio-rtrack2",
121 .io_params = io,
122 .radio_nr_params = radio_nr,
123 .io_ports = rtrack2_ioports,
124 .num_of_io_ports = ARRAY_SIZE(rtrack2_ioports),
125 .region_size = 4,
126 .card = "AIMSlab RadioTrack II",
127 .ops = &rtrack2_ops,
128 .has_stereo = true,
131 static int __init rtrack2_init(void)
133 return isa_register_driver(&rtrack2_driver.driver, RTRACK2_MAX);
136 static void __exit rtrack2_exit(void)
138 isa_unregister_driver(&rtrack2_driver.driver);
141 module_init(rtrack2_init);
142 module_exit(rtrack2_exit);