1 // SPDX-License-Identifier: GPL-2.0-only
3 * Zoltrix Radio Plus driver
4 * Copyright 1998 C. van Schaik <carl@leg.uct.ac.za>
7 * Due to the inconsistency in reading from the signal flags
8 * it is difficult to get an accurate tuned signal.
10 * It seems that the card is not linear to 0 volume. It cuts off
11 * at a low volume, and it is not possible (at least I have not found)
12 * to get fine volume control over the low volume range.
14 * Some code derived from code by Romolo Manfredini
17 * 1999-05-06 - (C. van Schaik)
18 * - Make signal strength and stereo scans
19 * kinder to cpu while in delay
20 * 1999-01-05 - (C. van Schaik)
21 * - Changed tuning to 1/160Mhz accuracy
22 * - Added stereo support
23 * (card defaults to stereo)
24 * (can explicitly force mono on the card)
25 * (can detect if station is in stereo)
26 * - Added unmute function
27 * - Reworked ioctl functions
28 * 2002-07-15 - Fix Stereo typo
30 * 2006-07-24 - Converted to V4L2 API
31 * by Mauro Carvalho Chehab <mchehab@kernel.org>
33 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
35 * Note that this is the driver for the Zoltrix Radio Plus.
36 * This driver does not work for the Zoltrix Radio Plus 108 or the
37 * Zoltrix Radio Plus for Windows.
39 * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool.
42 #include <linux/module.h> /* Modules */
43 #include <linux/init.h> /* Initdata */
44 #include <linux/ioport.h> /* request_region */
45 #include <linux/delay.h> /* udelay, msleep */
46 #include <linux/videodev2.h> /* kernel radio structs */
47 #include <linux/mutex.h>
48 #include <linux/io.h> /* outb, outb_p */
49 #include <linux/slab.h>
50 #include <media/v4l2-device.h>
51 #include <media/v4l2-ioctl.h>
52 #include "radio-isa.h"
54 MODULE_AUTHOR("C. van Schaik");
55 MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
56 MODULE_LICENSE("GPL");
57 MODULE_VERSION("0.1.99");
59 #ifndef CONFIG_RADIO_ZOLTRIX_PORT
60 #define CONFIG_RADIO_ZOLTRIX_PORT -1
65 static int io
[ZOLTRIX_MAX
] = { [0] = CONFIG_RADIO_ZOLTRIX_PORT
,
66 [1 ... (ZOLTRIX_MAX
- 1)] = -1 };
67 static int radio_nr
[ZOLTRIX_MAX
] = { [0 ... (ZOLTRIX_MAX
- 1)] = -1 };
69 module_param_array(io
, int, NULL
, 0444);
70 MODULE_PARM_DESC(io
, "I/O addresses of the Zoltrix Radio Plus card (0x20c or 0x30c)");
71 module_param_array(radio_nr
, int, NULL
, 0444);
72 MODULE_PARM_DESC(radio_nr
, "Radio device numbers");
75 struct radio_isa_card isa
;
80 static struct radio_isa_card
*zoltrix_alloc(void)
82 struct zoltrix
*zol
= kzalloc(sizeof(*zol
), GFP_KERNEL
);
84 return zol
? &zol
->isa
: NULL
;
87 static int zoltrix_s_mute_volume(struct radio_isa_card
*isa
, bool mute
, int vol
)
89 struct zoltrix
*zol
= container_of(isa
, struct zoltrix
, isa
);
93 if (mute
|| vol
== 0) {
96 inb(isa
->io
+ 3); /* Zoltrix needs to be read to confirm */
100 outb(vol
- 1, isa
->io
);
106 /* tunes the radio to the desired frequency */
107 static int zoltrix_s_frequency(struct radio_isa_card
*isa
, u32 freq
)
109 struct zoltrix
*zol
= container_of(isa
, struct zoltrix
, isa
);
110 struct v4l2_device
*v4l2_dev
= &isa
->v4l2_dev
;
111 unsigned long long bitmask
, f
, m
;
112 bool stereo
= isa
->stereo
;
116 v4l2_warn(v4l2_dev
, "cannot set a frequency of 0.\n");
120 m
= (freq
/ 160 - 8800) * 2;
121 f
= (unsigned long long)m
+ 0x4d1c;
123 bitmask
= 0xc480402c10080000ull
;
128 inb(isa
->io
+ 3); /* Zoltrix needs to be read to confirm */
133 bitmask
= (bitmask
^ ((f
& 0xff) << 47) ^ ((f
& 0xff00) << 30) ^ (stereo
<< 31));
135 if ((bitmask
& 0x8000000000000000ull
) != 0) {
152 /* termination sequence */
160 return zoltrix_s_mute_volume(isa
, zol
->muted
, zol
->curvol
);
163 /* Get signal strength */
164 static u32
zoltrix_g_rxsubchans(struct radio_isa_card
*isa
)
166 struct zoltrix
*zol
= container_of(isa
, struct zoltrix
, isa
);
169 outb(0x00, isa
->io
); /* This stuff I found to do nothing */
170 outb(zol
->curvol
, isa
->io
);
177 return (a
== b
&& a
== 0xcf) ?
178 V4L2_TUNER_SUB_STEREO
: V4L2_TUNER_SUB_MONO
;
181 static u32
zoltrix_g_signal(struct radio_isa_card
*isa
)
183 struct zoltrix
*zol
= container_of(isa
, struct zoltrix
, isa
);
186 outb(0x00, isa
->io
); /* This stuff I found to do nothing */
187 outb(zol
->curvol
, isa
->io
);
197 /* I found this out by playing with a binary scanner on the card io */
198 return (a
== 0xcf || a
== 0xdf || a
== 0xef) ? 0xffff : 0;
201 static int zoltrix_s_stereo(struct radio_isa_card
*isa
, bool stereo
)
203 return zoltrix_s_frequency(isa
, isa
->freq
);
206 static const struct radio_isa_ops zoltrix_ops
= {
207 .alloc
= zoltrix_alloc
,
208 .s_mute_volume
= zoltrix_s_mute_volume
,
209 .s_frequency
= zoltrix_s_frequency
,
210 .s_stereo
= zoltrix_s_stereo
,
211 .g_rxsubchans
= zoltrix_g_rxsubchans
,
212 .g_signal
= zoltrix_g_signal
,
215 static const int zoltrix_ioports
[] = { 0x20c, 0x30c };
217 static struct radio_isa_driver zoltrix_driver
= {
219 .match
= radio_isa_match
,
220 .probe
= radio_isa_probe
,
221 .remove
= radio_isa_remove
,
223 .name
= "radio-zoltrix",
227 .radio_nr_params
= radio_nr
,
228 .io_ports
= zoltrix_ioports
,
229 .num_of_io_ports
= ARRAY_SIZE(zoltrix_ioports
),
231 .card
= "Zoltrix Radio Plus",
237 static int __init
zoltrix_init(void)
239 return isa_register_driver(&zoltrix_driver
.driver
, ZOLTRIX_MAX
);
242 static void __exit
zoltrix_exit(void)
244 isa_unregister_driver(&zoltrix_driver
.driver
);
247 module_init(zoltrix_init
);
248 module_exit(zoltrix_exit
);