Merge branch 'drm-next-3.9' of git://people.freedesktop.org/~agd5f/linux into drm...
[linux-2.6/libata-dev.git] / drivers / media / radio / radio-aztech.c
blob177bcbd7a7c1c1e72b3459e618d56fb69bba617e
1 /*
2 * radio-aztech.c - Aztech radio card driver
4 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@xs4all.nl>
5 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
6 * Adapted to support the Video for Linux API by
7 * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by:
9 * Quay Ly
10 * Donald Song
11 * Jason Lewis (jlewis@twilight.vtc.vsc.edu)
12 * Scott McGrath (smcgrath@twilight.vtc.vsc.edu)
13 * William McGrath (wmcgrath@twilight.vtc.vsc.edu)
15 * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool.
18 #include <linux/module.h> /* Modules */
19 #include <linux/init.h> /* Initdata */
20 #include <linux/ioport.h> /* request_region */
21 #include <linux/delay.h> /* udelay */
22 #include <linux/videodev2.h> /* kernel radio structs */
23 #include <linux/io.h> /* outb, outb_p */
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"
30 MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
31 MODULE_DESCRIPTION("A driver for the Aztech radio card.");
32 MODULE_LICENSE("GPL");
33 MODULE_VERSION("1.0.0");
35 /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
36 #ifndef CONFIG_RADIO_AZTECH_PORT
37 #define CONFIG_RADIO_AZTECH_PORT -1
38 #endif
40 #define AZTECH_MAX 2
42 static int io[AZTECH_MAX] = { [0] = CONFIG_RADIO_AZTECH_PORT,
43 [1 ... (AZTECH_MAX - 1)] = -1 };
44 static int radio_nr[AZTECH_MAX] = { [0 ... (AZTECH_MAX - 1)] = -1 };
45 static const int radio_wait_time = 1000;
47 module_param_array(io, int, NULL, 0444);
48 MODULE_PARM_DESC(io, "I/O addresses of the Aztech card (0x350 or 0x358)");
49 module_param_array(radio_nr, int, NULL, 0444);
50 MODULE_PARM_DESC(radio_nr, "Radio device numbers");
52 struct aztech {
53 struct radio_isa_card isa;
54 int curvol;
57 static void send_0_byte(struct aztech *az)
59 udelay(radio_wait_time);
60 outb_p(2 + az->curvol, az->isa.io);
61 outb_p(64 + 2 + az->curvol, az->isa.io);
64 static void send_1_byte(struct aztech *az)
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);
71 static struct radio_isa_card *aztech_alloc(void)
73 struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL);
75 return az ? &az->isa : NULL;
78 static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq)
80 struct aztech *az = container_of(isa, struct aztech, isa);
81 int i;
83 freq += 171200; /* Add 10.7 MHz IF */
84 freq /= 800; /* Convert to 50 kHz units */
86 send_0_byte(az); /* 0: LSB of frequency */
88 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
89 if (freq & (1 << i))
90 send_1_byte(az);
91 else
92 send_0_byte(az);
94 send_0_byte(az); /* 14: test bit - always 0 */
95 send_0_byte(az); /* 15: test bit - always 0 */
96 send_0_byte(az); /* 16: band data 0 - always 0 */
97 if (isa->stereo) /* 17: stereo (1 to enable) */
98 send_1_byte(az);
99 else
100 send_0_byte(az);
102 send_1_byte(az); /* 18: band data 1 - unknown */
103 send_0_byte(az); /* 19: time base - always 0 */
104 send_0_byte(az); /* 20: spacing (0 = 25 kHz) */
105 send_1_byte(az); /* 21: spacing (1 = 25 kHz) */
106 send_0_byte(az); /* 22: spacing (0 = 25 kHz) */
107 send_1_byte(az); /* 23: AM/FM (FM = 1, always) */
109 /* latch frequency */
111 udelay(radio_wait_time);
112 outb_p(128 + 64 + az->curvol, az->isa.io);
114 return 0;
117 /* thanks to Michael Dwyer for giving me a dose of clues in
118 * the signal strength department..
120 * This card has a stereo bit - bit 0 set = mono, not set = stereo
122 static u32 aztech_g_rxsubchans(struct radio_isa_card *isa)
124 if (inb(isa->io) & 1)
125 return V4L2_TUNER_SUB_MONO;
126 return V4L2_TUNER_SUB_STEREO;
129 static int aztech_s_stereo(struct radio_isa_card *isa, bool stereo)
131 return aztech_s_frequency(isa, isa->freq);
134 static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
136 struct aztech *az = container_of(isa, struct aztech, isa);
138 if (mute)
139 vol = 0;
140 az->curvol = (vol & 1) + ((vol & 2) << 1);
141 outb(az->curvol, isa->io);
142 return 0;
145 static 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,
153 static const int aztech_ioports[] = { 0x350, 0x358 };
155 static 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",
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,
175 static int __init aztech_init(void)
177 return isa_register_driver(&aztech_driver.driver, AZTECH_MAX);
180 static void __exit aztech_exit(void)
182 isa_unregister_driver(&aztech_driver.driver);
185 module_init(aztech_init);
186 module_exit(aztech_exit);