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