1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/ioport.h>
21#include <linux/delay.h>
22#include <linux/videodev2.h>
23#include <linux/io.h>
24#include <linux/slab.h>
25#include <media/v4l2-device.h>
26#include <media/v4l2-ioctl.h>
27#include <media/v4l2-ctrls.h>
28#include "radio-isa.h"
29
30MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
31MODULE_DESCRIPTION("A driver for the Aztech radio card.");
32MODULE_LICENSE("GPL");
33MODULE_VERSION("1.0.0");
34
35
36#ifndef CONFIG_RADIO_AZTECH_PORT
37#define CONFIG_RADIO_AZTECH_PORT -1
38#endif
39
40#define AZTECH_MAX 2
41
42static int io[AZTECH_MAX] = { [0] = CONFIG_RADIO_AZTECH_PORT,
43 [1 ... (AZTECH_MAX - 1)] = -1 };
44static int radio_nr[AZTECH_MAX] = { [0 ... (AZTECH_MAX - 1)] = -1 };
45static const int radio_wait_time = 1000;
46
47module_param_array(io, int, NULL, 0444);
48MODULE_PARM_DESC(io, "I/O addresses of the Aztech card (0x350 or 0x358)");
49module_param_array(radio_nr, int, NULL, 0444);
50MODULE_PARM_DESC(radio_nr, "Radio device numbers");
51
52struct aztech {
53 struct radio_isa_card isa;
54 int curvol;
55};
56
57static void send_0_byte(struct aztech *az)
58{
59 udelay(radio_wait_time);
60 outb_p(2 + az->curvol, az->isa.io);
61 outb_p(64 + 2 + az->curvol, az->isa.io);
62}
63
64static void send_1_byte(struct aztech *az)
65{
66 udelay(radio_wait_time);
67 outb_p(128 + 2 + az->curvol, az->isa.io);
68 outb_p(128 + 64 + 2 + az->curvol, az->isa.io);
69}
70
71static struct radio_isa_card *aztech_alloc(void)
72{
73 struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL);
74
75 return az ? &az->isa : NULL;
76}
77
78static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq)
79{
80 struct aztech *az = container_of(isa, struct aztech, isa);
81 int i;
82
83 freq += 171200;
84 freq /= 800;
85
86 send_0_byte(az);
87
88 for (i = 0; i < 13; i++)
89 if (freq & (1 << i))
90 send_1_byte(az);
91 else
92 send_0_byte(az);
93
94 send_0_byte(az);
95 send_0_byte(az);
96 send_0_byte(az);
97 if (isa->stereo)
98 send_1_byte(az);
99 else
100 send_0_byte(az);
101
102 send_1_byte(az);
103 send_0_byte(az);
104 send_0_byte(az);
105 send_1_byte(az);
106 send_0_byte(az);
107 send_1_byte(az);
108
109
110
111 udelay(radio_wait_time);
112 outb_p(128 + 64 + az->curvol, az->isa.io);
113
114 return 0;
115}
116
117
118
119
120
121
122static u32 aztech_g_rxsubchans(struct radio_isa_card *isa)
123{
124 if (inb(isa->io) & 1)
125 return V4L2_TUNER_SUB_MONO;
126 return V4L2_TUNER_SUB_STEREO;
127}
128
129static int aztech_s_stereo(struct radio_isa_card *isa, bool stereo)
130{
131 return aztech_s_frequency(isa, isa->freq);
132}
133
134static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
135{
136 struct aztech *az = container_of(isa, struct aztech, isa);
137
138 if (mute)
139 vol = 0;
140 az->curvol = (vol & 1) + ((vol & 2) << 1);
141 outb(az->curvol, isa->io);
142 return 0;
143}
144
145static const struct radio_isa_ops aztech_ops = {
146 .alloc = aztech_alloc,
147 .s_mute_volume = aztech_s_mute_volume,
148 .s_frequency = aztech_s_frequency,
149 .s_stereo = aztech_s_stereo,
150 .g_rxsubchans = aztech_g_rxsubchans,
151};
152
153static const int aztech_ioports[] = { 0x350, 0x358 };
154
155static struct radio_isa_driver aztech_driver = {
156 .driver = {
157 .match = radio_isa_match,
158 .probe = radio_isa_probe,
159 .remove = radio_isa_remove,
160 .driver = {
161 .name = "radio-aztech",
162 },
163 },
164 .io_params = io,
165 .radio_nr_params = radio_nr,
166 .io_ports = aztech_ioports,
167 .num_of_io_ports = ARRAY_SIZE(aztech_ioports),
168 .region_size = 2,
169 .card = "Aztech Radio",
170 .ops = &aztech_ops,
171 .has_stereo = true,
172 .max_volume = 3,
173};
174
175static int __init aztech_init(void)
176{
177 return isa_register_driver(&aztech_driver.driver, AZTECH_MAX);
178}
179
180static void __exit aztech_exit(void)
181{
182 isa_unregister_driver(&aztech_driver.driver);
183}
184
185module_init(aztech_init);
186module_exit(aztech_exit);
187