1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/ioport.h>
27#include <linux/videodev2.h>
28#include <linux/mutex.h>
29#include <linux/io.h>
30#include <linux/slab.h>
31#include <media/v4l2-device.h>
32#include <media/v4l2-ioctl.h>
33#include "radio-isa.h"
34
35MODULE_AUTHOR("R. Offermans & others");
36MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card.");
37MODULE_LICENSE("GPL");
38MODULE_VERSION("0.1.99");
39
40
41
42
43static int io = 0x590;
44static int radio_nr = -1;
45
46module_param(radio_nr, int, 0444);
47MODULE_PARM_DESC(radio_nr, "Radio device number");
48
49#define WRT_DIS 0x00
50#define CLK_OFF 0x00
51#define IIC_DATA 0x01
52#define IIC_CLK 0x02
53#define DATA 0x04
54#define CLK_ON 0x08
55#define WRT_EN 0x10
56
57static struct radio_isa_card *terratec_alloc(void)
58{
59 return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
60}
61
62static int terratec_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
63{
64 int i;
65
66 if (mute)
67 vol = 0;
68 vol = vol + (vol * 32);
69 for (i = 0; i < 8; i++) {
70 if (vol & (0x80 >> i))
71 outb(0x80, isa->io + 1);
72 else
73 outb(0x00, isa->io + 1);
74 }
75 return 0;
76}
77
78
79
80
81
82static int terratec_s_frequency(struct radio_isa_card *isa, u32 freq)
83{
84 int i;
85 int p;
86 int temp;
87 long rest;
88 unsigned char buffer[25];
89
90 freq = freq / 160;
91 memset(buffer, 0, sizeof(buffer));
92
93 rest = freq * 10 + 10700;
94
95 i = 13;
96 p = 10;
97 temp = 102400;
98 while (rest != 0) {
99 if (rest % temp == rest)
100 buffer[i] = 0;
101 else {
102 buffer[i] = 1;
103 rest = rest - temp;
104 }
105 i--;
106 p--;
107 temp = temp / 2;
108 }
109
110 for (i = 24; i > -1; i--) {
111 if (buffer[i] == 1) {
112 outb(WRT_EN | DATA, isa->io);
113 outb(WRT_EN | DATA | CLK_ON, isa->io);
114 outb(WRT_EN | DATA, isa->io);
115 } else {
116 outb(WRT_EN | 0x00, isa->io);
117 outb(WRT_EN | 0x00 | CLK_ON, isa->io);
118 }
119 }
120 outb(0x00, isa->io);
121 return 0;
122}
123
124static u32 terratec_g_signal(struct radio_isa_card *isa)
125{
126
127 return (inb(isa->io) & 2) ? 0 : 0xffff;
128}
129
130static const struct radio_isa_ops terratec_ops = {
131 .alloc = terratec_alloc,
132 .s_mute_volume = terratec_s_mute_volume,
133 .s_frequency = terratec_s_frequency,
134 .g_signal = terratec_g_signal,
135};
136
137static const int terratec_ioports[] = { 0x590 };
138
139static struct radio_isa_driver terratec_driver = {
140 .driver = {
141 .match = radio_isa_match,
142 .probe = radio_isa_probe,
143 .remove = radio_isa_remove,
144 .driver = {
145 .name = "radio-terratec",
146 },
147 },
148 .io_params = &io,
149 .radio_nr_params = &radio_nr,
150 .io_ports = terratec_ioports,
151 .num_of_io_ports = ARRAY_SIZE(terratec_ioports),
152 .region_size = 2,
153 .card = "TerraTec ActiveRadio",
154 .ops = &terratec_ops,
155 .has_stereo = true,
156 .max_volume = 10,
157};
158
159static int __init terratec_init(void)
160{
161 return isa_register_driver(&terratec_driver.driver, 1);
162}
163
164static void __exit terratec_exit(void)
165{
166 isa_unregister_driver(&terratec_driver.driver);
167}
168
169module_init(terratec_init);
170module_exit(terratec_exit);
171
172