blob: 8117fdf9ed4d2023be2cba06b6ceac2ddf9dc177 [file] [log] [blame]
Hans Verkuil3088fba2012-01-16 04:58:15 -03001/*
2 * radio-aztech.c - Aztech radio card driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Hans Verkuil3088fba2012-01-16 04:58:15 -03004 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@xs4all.nl>
Mauro Carvalho Chehaba4366af2006-08-08 09:10:01 -03005 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -03006 * Adapted to support the Video for Linux API by
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by:
8 *
9 * Quay Ly
10 * Donald Song
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030011 * Jason Lewis (jlewis@twilight.vtc.vsc.edu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Scott McGrath (smcgrath@twilight.vtc.vsc.edu)
13 * William McGrath (wmcgrath@twilight.vtc.vsc.edu)
14 *
Hans Verkuil3088fba2012-01-16 04:58:15 -030015 * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool.
Linus Torvalds1da177e2005-04-16 15:20:36 -070016*/
17
18#include <linux/module.h> /* Modules */
19#include <linux/init.h> /* Initdata */
Peter Osterlundfb911ee2005-09-13 01:25:15 -070020#include <linux/ioport.h> /* request_region */
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/delay.h> /* udelay */
Mauro Carvalho Chehaba4366af2006-08-08 09:10:01 -030022#include <linux/videodev2.h> /* kernel radio structs */
Hans Verkuile697e122009-03-06 13:48:18 -030023#include <linux/io.h> /* outb, outb_p */
Hans Verkuile697e122009-03-06 13:48:18 -030024#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030025#include <media/v4l2-ioctl.h>
Hans Verkuil3088fba2012-01-16 04:58:15 -030026#include <media/v4l2-ctrls.h>
27#include "radio-isa.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Hans Verkuile697e122009-03-06 13:48:18 -030029MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
30MODULE_DESCRIPTION("A driver for the Aztech radio card.");
31MODULE_LICENSE("GPL");
Hans Verkuil3088fba2012-01-16 04:58:15 -030032MODULE_VERSION("1.0.0");
Mauro Carvalho Chehaba4366af2006-08-08 09:10:01 -030033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#ifndef CONFIG_RADIO_AZTECH_PORT
36#define CONFIG_RADIO_AZTECH_PORT -1
37#endif
38
Hans Verkuil3088fba2012-01-16 04:58:15 -030039#define AZTECH_MAX 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Hans Verkuil3088fba2012-01-16 04:58:15 -030041static int io[AZTECH_MAX] = { [0] = CONFIG_RADIO_AZTECH_PORT,
42 [1 ... (AZTECH_MAX - 1)] = -1 };
43static int radio_nr[AZTECH_MAX] = { [0 ... (AZTECH_MAX - 1)] = -1 };
44static const int radio_wait_time = 1000;
Hans Verkuile697e122009-03-06 13:48:18 -030045
Hans Verkuil3088fba2012-01-16 04:58:15 -030046module_param_array(io, int, NULL, 0444);
47MODULE_PARM_DESC(io, "I/O addresses of the Aztech card (0x350 or 0x358)");
48module_param_array(radio_nr, int, NULL, 0444);
49MODULE_PARM_DESC(radio_nr, "Radio device numbers");
50
51struct aztech {
52 struct radio_isa_card isa;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 int curvol;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054};
55
Hans Verkuile697e122009-03-06 13:48:18 -030056static void send_0_byte(struct aztech *az)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
58 udelay(radio_wait_time);
Hans Verkuil3088fba2012-01-16 04:58:15 -030059 outb_p(2 + az->curvol, az->isa.io);
60 outb_p(64 + 2 + az->curvol, az->isa.io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
62
Hans Verkuile697e122009-03-06 13:48:18 -030063static void send_1_byte(struct aztech *az)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Hans Verkuil3088fba2012-01-16 04:58:15 -030065 udelay(radio_wait_time);
66 outb_p(128 + 2 + az->curvol, az->isa.io);
67 outb_p(128 + 64 + 2 + az->curvol, az->isa.io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
Hans Verkuil3088fba2012-01-16 04:58:15 -030070static struct radio_isa_card *aztech_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Hans Verkuil3088fba2012-01-16 04:58:15 -030072 struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL);
73
74 return az ? &az->isa : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76
Hans Verkuil3088fba2012-01-16 04:58:15 -030077static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Hans Verkuil3088fba2012-01-16 04:58:15 -030079 struct aztech *az = container_of(isa, struct aztech, isa);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 int i;
81
Hans Verkuil3088fba2012-01-16 04:58:15 -030082 freq += 171200; /* Add 10.7 MHz IF */
83 freq /= 800; /* Convert to 50 kHz units */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030084
Hans Verkuile697e122009-03-06 13:48:18 -030085 send_0_byte(az); /* 0: LSB of frequency */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
Hans Verkuil3088fba2012-01-16 04:58:15 -030088 if (freq & (1 << i))
Hans Verkuile697e122009-03-06 13:48:18 -030089 send_1_byte(az);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 else
Hans Verkuile697e122009-03-06 13:48:18 -030091 send_0_byte(az);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Hans Verkuile697e122009-03-06 13:48:18 -030093 send_0_byte(az); /* 14: test bit - always 0 */
94 send_0_byte(az); /* 15: test bit - always 0 */
95 send_0_byte(az); /* 16: band data 0 - always 0 */
Hans Verkuil3088fba2012-01-16 04:58:15 -030096 if (isa->stereo) /* 17: stereo (1 to enable) */
Hans Verkuile697e122009-03-06 13:48:18 -030097 send_1_byte(az);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 else
Hans Verkuile697e122009-03-06 13:48:18 -030099 send_0_byte(az);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Hans Verkuile697e122009-03-06 13:48:18 -0300101 send_1_byte(az); /* 18: band data 1 - unknown */
102 send_0_byte(az); /* 19: time base - always 0 */
103 send_0_byte(az); /* 20: spacing (0 = 25 kHz) */
104 send_1_byte(az); /* 21: spacing (1 = 25 kHz) */
105 send_0_byte(az); /* 22: spacing (0 = 25 kHz) */
106 send_1_byte(az); /* 23: AM/FM (FM = 1, always) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /* latch frequency */
109
Hans Verkuile697e122009-03-06 13:48:18 -0300110 udelay(radio_wait_time);
Hans Verkuil3088fba2012-01-16 04:58:15 -0300111 outb_p(128 + 64 + az->curvol, az->isa.io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 return 0;
114}
115
Hans Verkuil3088fba2012-01-16 04:58:15 -0300116/* thanks to Michael Dwyer for giving me a dose of clues in
117 * the signal strength department..
118 *
119 * This card has a stereo bit - bit 0 set = mono, not set = stereo
120 */
121static u32 aztech_g_rxsubchans(struct radio_isa_card *isa)
Mauro Carvalho Chehab99218fe2007-01-25 08:09:32 -0300122{
Hans Verkuil3088fba2012-01-16 04:58:15 -0300123 if (inb(isa->io) & 1)
124 return V4L2_TUNER_SUB_MONO;
125 return V4L2_TUNER_SUB_STEREO;
126}
127
128static int aztech_s_stereo(struct radio_isa_card *isa, bool stereo)
129{
130 return aztech_s_frequency(isa, isa->freq);
131}
132
133static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
134{
135 struct aztech *az = container_of(isa, struct aztech, isa);
136
137 if (mute)
138 vol = 0;
139 az->curvol = (vol & 1) + ((vol & 2) << 1);
140 outb(az->curvol, isa->io);
Mauro Carvalho Chehab99218fe2007-01-25 08:09:32 -0300141 return 0;
142}
143
Hans Verkuil3088fba2012-01-16 04:58:15 -0300144static const struct radio_isa_ops aztech_ops = {
145 .alloc = aztech_alloc,
146 .s_mute_volume = aztech_s_mute_volume,
147 .s_frequency = aztech_s_frequency,
148 .s_stereo = aztech_s_stereo,
149 .g_rxsubchans = aztech_g_rxsubchans,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150};
151
Hans Verkuil3088fba2012-01-16 04:58:15 -0300152static const int aztech_ioports[] = { 0x350, 0x358 };
153
154static struct radio_isa_driver aztech_driver = {
155 .driver = {
156 .match = radio_isa_match,
157 .probe = radio_isa_probe,
158 .remove = radio_isa_remove,
159 .driver = {
160 .name = "radio-aztech",
161 },
162 },
163 .io_params = io,
164 .radio_nr_params = radio_nr,
165 .io_ports = aztech_ioports,
166 .num_of_io_ports = ARRAY_SIZE(aztech_ioports),
167 .region_size = 2,
168 .card = "Aztech Radio",
169 .ops = &aztech_ops,
170 .has_stereo = true,
171 .max_volume = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172};
173
174static int __init aztech_init(void)
175{
Hans Verkuil3088fba2012-01-16 04:58:15 -0300176 return isa_register_driver(&aztech_driver.driver, AZTECH_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
178
Hans Verkuile697e122009-03-06 13:48:18 -0300179static void __exit aztech_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
Hans Verkuil3088fba2012-01-16 04:58:15 -0300181 isa_unregister_driver(&aztech_driver.driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182}
183
184module_init(aztech_init);
Hans Verkuile697e122009-03-06 13:48:18 -0300185module_exit(aztech_exit);