Restartable sequences: wire up ARM 32 system call
[deliverable/linux.git] / drivers / media / radio / radio-zoltrix.c
CommitLineData
6b39246c
HV
1/*
2 * Zoltrix Radio Plus driver
3 * Copyright 1998 C. van Schaik <carl@leg.uct.ac.za>
1da177e4 4 *
4286c6f6 5 * BUGS
1da177e4
LT
6 * Due to the inconsistency in reading from the signal flags
7 * it is difficult to get an accurate tuned signal.
8 *
9 * It seems that the card is not linear to 0 volume. It cuts off
10 * at a low volume, and it is not possible (at least I have not found)
11 * to get fine volume control over the low volume range.
12 *
13 * Some code derived from code by Romolo Manfredini
14 * romolo@bicnet.it
15 *
16 * 1999-05-06 - (C. van Schaik)
17 * - Make signal strength and stereo scans
4286c6f6 18 * kinder to cpu while in delay
1da177e4
LT
19 * 1999-01-05 - (C. van Schaik)
20 * - Changed tuning to 1/160Mhz accuracy
21 * - Added stereo support
22 * (card defaults to stereo)
23 * (can explicitly force mono on the card)
24 * (can detect if station is in stereo)
25 * - Added unmute function
26 * - Reworked ioctl functions
27 * 2002-07-15 - Fix Stereo typo
2ab65299
MCC
28 *
29 * 2006-07-24 - Converted to V4L2 API
30 * by Mauro Carvalho Chehab <mchehab@infradead.org>
6b39246c
HV
31 *
32 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
33 *
34 * Note that this is the driver for the Zoltrix Radio Plus.
35 * This driver does not work for the Zoltrix Radio Plus 108 or the
36 * Zoltrix Radio Plus for Windows.
37 *
38 * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool.
1da177e4
LT
39 */
40
41#include <linux/module.h> /* Modules */
42#include <linux/init.h> /* Initdata */
fb911ee8 43#include <linux/ioport.h> /* request_region */
1da177e4 44#include <linux/delay.h> /* udelay, msleep */
2ab65299 45#include <linux/videodev2.h> /* kernel radio structs */
ec632c8a 46#include <linux/mutex.h>
ec632c8a 47#include <linux/io.h> /* outb, outb_p */
9f1dfccf 48#include <linux/slab.h>
ec632c8a 49#include <media/v4l2-device.h>
35ea11ff 50#include <media/v4l2-ioctl.h>
6b39246c 51#include "radio-isa.h"
1da177e4 52
6b39246c 53MODULE_AUTHOR("C. van Schaik");
ec632c8a
HV
54MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
55MODULE_LICENSE("GPL");
6b39246c 56MODULE_VERSION("0.1.99");
2ab65299 57
1da177e4
LT
58#ifndef CONFIG_RADIO_ZOLTRIX_PORT
59#define CONFIG_RADIO_ZOLTRIX_PORT -1
60#endif
61
6b39246c
HV
62#define ZOLTRIX_MAX 2
63
64static int io[ZOLTRIX_MAX] = { [0] = CONFIG_RADIO_ZOLTRIX_PORT,
65 [1 ... (ZOLTRIX_MAX - 1)] = -1 };
66static int radio_nr[ZOLTRIX_MAX] = { [0 ... (ZOLTRIX_MAX - 1)] = -1 };
1da177e4 67
6b39246c
HV
68module_param_array(io, int, NULL, 0444);
69MODULE_PARM_DESC(io, "I/O addresses of the Zoltrix Radio Plus card (0x20c or 0x30c)");
70module_param_array(radio_nr, int, NULL, 0444);
71MODULE_PARM_DESC(radio_nr, "Radio device numbers");
ec632c8a 72
ec632c8a 73struct zoltrix {
6b39246c 74 struct radio_isa_card isa;
1da177e4 75 int curvol;
6b39246c 76 bool muted;
1da177e4
LT
77};
78
6b39246c
HV
79static struct radio_isa_card *zoltrix_alloc(void)
80{
81 struct zoltrix *zol = kzalloc(sizeof(*zol), GFP_KERNEL);
82
83 return zol ? &zol->isa : NULL;
84}
ec632c8a 85
6b39246c 86static int zoltrix_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
1da177e4 87{
6b39246c 88 struct zoltrix *zol = container_of(isa, struct zoltrix, isa);
1da177e4 89
6b39246c
HV
90 zol->curvol = vol;
91 zol->muted = mute;
92 if (mute || vol == 0) {
93 outb(0, isa->io);
94 outb(0, isa->io);
95 inb(isa->io + 3); /* Zoltrix needs to be read to confirm */
1da177e4
LT
96 return 0;
97 }
98
6b39246c 99 outb(vol - 1, isa->io);
1da177e4 100 msleep(10);
6b39246c 101 inb(isa->io + 2);
1da177e4
LT
102 return 0;
103}
104
6b39246c
HV
105/* tunes the radio to the desired frequency */
106static int zoltrix_s_frequency(struct radio_isa_card *isa, u32 freq)
1da177e4 107{
6b39246c
HV
108 struct zoltrix *zol = container_of(isa, struct zoltrix, isa);
109 struct v4l2_device *v4l2_dev = &isa->v4l2_dev;
1da177e4 110 unsigned long long bitmask, f, m;
6b39246c 111 bool stereo = isa->stereo;
1da177e4
LT
112 int i;
113
b4be2048 114 if (freq == 0) {
ec632c8a 115 v4l2_warn(v4l2_dev, "cannot set a frequency of 0.\n");
b4be2048
AK
116 return -EINVAL;
117 }
118
1da177e4 119 m = (freq / 160 - 8800) * 2;
ec632c8a 120 f = (unsigned long long)m + 0x4d1c;
1da177e4
LT
121
122 bitmask = 0xc480402c10080000ull;
123 i = 45;
124
6b39246c
HV
125 outb(0, isa->io);
126 outb(0, isa->io);
127 inb(isa->io + 3); /* Zoltrix needs to be read to confirm */
1da177e4 128
6b39246c
HV
129 outb(0x40, isa->io);
130 outb(0xc0, isa->io);
ec632c8a
HV
131
132 bitmask = (bitmask ^ ((f & 0xff) << 47) ^ ((f & 0xff00) << 30) ^ (stereo << 31));
1da177e4
LT
133 while (i--) {
134 if ((bitmask & 0x8000000000000000ull) != 0) {
6b39246c 135 outb(0x80, isa->io);
1da177e4 136 udelay(50);
6b39246c 137 outb(0x00, isa->io);
1da177e4 138 udelay(50);
6b39246c 139 outb(0x80, isa->io);
1da177e4
LT
140 udelay(50);
141 } else {
6b39246c 142 outb(0xc0, isa->io);
1da177e4 143 udelay(50);
6b39246c 144 outb(0x40, isa->io);
1da177e4 145 udelay(50);
6b39246c 146 outb(0xc0, isa->io);
1da177e4
LT
147 udelay(50);
148 }
149 bitmask *= 2;
150 }
151 /* termination sequence */
6b39246c
HV
152 outb(0x80, isa->io);
153 outb(0xc0, isa->io);
154 outb(0x40, isa->io);
1da177e4 155 udelay(1000);
6b39246c 156 inb(isa->io + 2);
4286c6f6
MCC
157 udelay(1000);
158
6b39246c 159 return zoltrix_s_mute_volume(isa, zol->muted, zol->curvol);
1da177e4
LT
160}
161
162/* Get signal strength */
6b39246c 163static u32 zoltrix_g_rxsubchans(struct radio_isa_card *isa)
1da177e4 164{
6b39246c 165 struct zoltrix *zol = container_of(isa, struct zoltrix, isa);
1da177e4
LT
166 int a, b;
167
6b39246c
HV
168 outb(0x00, isa->io); /* This stuff I found to do nothing */
169 outb(zol->curvol, isa->io);
1da177e4
LT
170 msleep(20);
171
6b39246c 172 a = inb(isa->io);
1da177e4 173 msleep(10);
6b39246c 174 b = inb(isa->io);
1da177e4 175
6b39246c
HV
176 return (a == b && a == 0xcf) ?
177 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
1da177e4
LT
178}
179
6b39246c 180static u32 zoltrix_g_signal(struct radio_isa_card *isa)
1da177e4 181{
6b39246c
HV
182 struct zoltrix *zol = container_of(isa, struct zoltrix, isa);
183 int a, b;
4286c6f6 184
6b39246c
HV
185 outb(0x00, isa->io); /* This stuff I found to do nothing */
186 outb(zol->curvol, isa->io);
1da177e4
LT
187 msleep(20);
188
6b39246c 189 a = inb(isa->io);
1da177e4 190 msleep(10);
6b39246c 191 b = inb(isa->io);
a1314b1a 192
6b39246c 193 if (a != b)
a1314b1a 194 return 0;
a1314b1a 195
6b39246c
HV
196 /* I found this out by playing with a binary scanner on the card io */
197 return (a == 0xcf || a == 0xdf || a == 0xef) ? 0xffff : 0;
1da177e4
LT
198}
199
6b39246c 200static int zoltrix_s_stereo(struct radio_isa_card *isa, bool stereo)
ec632c8a 201{
6b39246c 202 return zoltrix_s_frequency(isa, isa->freq);
ec632c8a 203}
1da177e4 204
6b39246c
HV
205static const struct radio_isa_ops zoltrix_ops = {
206 .alloc = zoltrix_alloc,
207 .s_mute_volume = zoltrix_s_mute_volume,
208 .s_frequency = zoltrix_s_frequency,
209 .s_stereo = zoltrix_s_stereo,
210 .g_rxsubchans = zoltrix_g_rxsubchans,
211 .g_signal = zoltrix_g_signal,
1da177e4
LT
212};
213
6b39246c
HV
214static const int zoltrix_ioports[] = { 0x20c, 0x30c };
215
216static struct radio_isa_driver zoltrix_driver = {
217 .driver = {
218 .match = radio_isa_match,
219 .probe = radio_isa_probe,
220 .remove = radio_isa_remove,
221 .driver = {
222 .name = "radio-zoltrix",
223 },
224 },
225 .io_params = io,
226 .radio_nr_params = radio_nr,
227 .io_ports = zoltrix_ioports,
228 .num_of_io_ports = ARRAY_SIZE(zoltrix_ioports),
229 .region_size = 2,
230 .card = "Zoltrix Radio Plus",
231 .ops = &zoltrix_ops,
232 .has_stereo = true,
233 .max_volume = 15,
1da177e4
LT
234};
235
236static int __init zoltrix_init(void)
237{
6b39246c 238 return isa_register_driver(&zoltrix_driver.driver, ZOLTRIX_MAX);
1da177e4
LT
239}
240
ec632c8a 241static void __exit zoltrix_exit(void)
1da177e4 242{
6b39246c 243 isa_unregister_driver(&zoltrix_driver.driver);
1da177e4
LT
244}
245
246module_init(zoltrix_init);
ec632c8a 247module_exit(zoltrix_exit);
1da177e4 248
This page took 1.094126 seconds and 5 git commands to generate.