1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include <linux/module.h>
30#include <linux/init.h>
31#include <linux/ioport.h>
32#include <linux/delay.h>
33#include <linux/videodev2.h>
34#include <linux/io.h>
35#include <linux/slab.h>
36#include <media/v4l2-device.h>
37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-ctrls.h>
39#include "radio-isa.h"
40#include "lm7000.h"
41
42MODULE_AUTHOR("M. Kirkwood");
43MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
44MODULE_LICENSE("GPL");
45MODULE_VERSION("1.0.0");
46
47#ifndef CONFIG_RADIO_RTRACK_PORT
48#define CONFIG_RADIO_RTRACK_PORT -1
49#endif
50
51#define RTRACK_MAX 2
52
53static int io[RTRACK_MAX] = { [0] = CONFIG_RADIO_RTRACK_PORT,
54 [1 ... (RTRACK_MAX - 1)] = -1 };
55static int radio_nr[RTRACK_MAX] = { [0 ... (RTRACK_MAX - 1)] = -1 };
56
57module_param_array(io, int, NULL, 0444);
58MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
59module_param_array(radio_nr, int, NULL, 0444);
60MODULE_PARM_DESC(radio_nr, "Radio device numbers");
61
62struct rtrack {
63 struct radio_isa_card isa;
64 int curvol;
65};
66
67static struct radio_isa_card *rtrack_alloc(void)
68{
69 struct rtrack *rt = kzalloc(sizeof(struct rtrack), GFP_KERNEL);
70
71 if (rt)
72 rt->curvol = 0xff;
73 return rt ? &rt->isa : NULL;
74}
75
76#define AIMS_BIT_TUN_CE (1 << 0)
77#define AIMS_BIT_TUN_CLK (1 << 1)
78#define AIMS_BIT_TUN_DATA (1 << 2)
79#define AIMS_BIT_VOL_CE (1 << 3)
80#define AIMS_BIT_TUN_STRQ (1 << 4)
81
82#define AIMS_BIT_VOL_UP (1 << 6)
83#define AIMS_BIT_VOL_DN (1 << 7)
84
85static void rtrack_set_pins(void *handle, u8 pins)
86{
87 struct radio_isa_card *isa = handle;
88 struct rtrack *rt = container_of(isa, struct rtrack, isa);
89 u8 bits = AIMS_BIT_VOL_DN | AIMS_BIT_VOL_UP | AIMS_BIT_TUN_STRQ;
90
91 if (!v4l2_ctrl_g_ctrl(rt->isa.mute))
92 bits |= AIMS_BIT_VOL_CE;
93
94 if (pins & LM7000_DATA)
95 bits |= AIMS_BIT_TUN_DATA;
96 if (pins & LM7000_CLK)
97 bits |= AIMS_BIT_TUN_CLK;
98 if (pins & LM7000_CE)
99 bits |= AIMS_BIT_TUN_CE;
100
101 outb_p(bits, rt->isa.io);
102}
103
104static int rtrack_s_frequency(struct radio_isa_card *isa, u32 freq)
105{
106 lm7000_set_freq(freq, isa, rtrack_set_pins);
107
108 return 0;
109}
110
111static u32 rtrack_g_signal(struct radio_isa_card *isa)
112{
113
114 return 0xffff * !(inb(isa->io) & 2);
115}
116
117static int rtrack_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
118{
119 struct rtrack *rt = container_of(isa, struct rtrack, isa);
120 int curvol = rt->curvol;
121
122 if (mute) {
123 outb(0xd0, isa->io);
124 return 0;
125 }
126 if (vol == 0) {
127 outb(0x48, isa->io);
128 msleep(curvol * 3);
129 } else if (curvol < vol) {
130 outb(0x98, isa->io);
131 for (; curvol < vol; curvol++)
132 udelay(3000);
133 } else if (curvol > vol) {
134 outb(0x58, isa->io);
135 for (; curvol > vol; curvol--)
136 udelay(3000);
137 }
138 outb(0xd8, isa->io);
139 rt->curvol = vol;
140 return 0;
141}
142
143
144static int rtrack_initialize(struct radio_isa_card *isa)
145{
146
147 outb(0x90, isa->io);
148 msleep(3000);
149 outb(0xc0, isa->io);
150 return 0;
151}
152
153static const struct radio_isa_ops rtrack_ops = {
154 .alloc = rtrack_alloc,
155 .init = rtrack_initialize,
156 .s_mute_volume = rtrack_s_mute_volume,
157 .s_frequency = rtrack_s_frequency,
158 .g_signal = rtrack_g_signal,
159};
160
161static const int rtrack_ioports[] = { 0x20f, 0x30f };
162
163static struct radio_isa_driver rtrack_driver = {
164 .driver = {
165 .match = radio_isa_match,
166 .probe = radio_isa_probe,
167 .remove = radio_isa_remove,
168 .driver = {
169 .name = "radio-aimslab",
170 },
171 },
172 .io_params = io,
173 .radio_nr_params = radio_nr,
174 .io_ports = rtrack_ioports,
175 .num_of_io_ports = ARRAY_SIZE(rtrack_ioports),
176 .region_size = 2,
177 .card = "AIMSlab RadioTrack/RadioReveal",
178 .ops = &rtrack_ops,
179 .has_stereo = true,
180 .max_volume = 0xff,
181};
182
183static int __init rtrack_init(void)
184{
185 return isa_register_driver(&rtrack_driver.driver, RTRACK_MAX);
186}
187
188static void __exit rtrack_exit(void)
189{
190 isa_unregister_driver(&rtrack_driver.driver);
191}
192
193module_init(rtrack_init);
194module_exit(rtrack_exit);
195