blob: 177bcbd7a7c1c1e72b3459e618d56fb69bba617e [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 Verkuil9f1dfcc2012-02-29 05:50:27 -030024#include <linux/slab.h>
Hans Verkuile697e122009-03-06 13:48:18 -030025#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030026#include <media/v4l2-ioctl.h>
Hans Verkuil3088fba2012-01-16 04:58:15 -030027#include <media/v4l2-ctrls.h>
28#include "radio-isa.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Hans Verkuile697e122009-03-06 13:48:18 -030030MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
31MODULE_DESCRIPTION("A driver for the Aztech radio card.");
32MODULE_LICENSE("GPL");
Hans Verkuil3088fba2012-01-16 04:58:15 -030033MODULE_VERSION("1.0.0");
Mauro Carvalho Chehaba4366af2006-08-08 09:10:01 -030034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#ifndef CONFIG_RADIO_AZTECH_PORT
37#define CONFIG_RADIO_AZTECH_PORT -1
38#endif
39
Hans Verkuil3088fba2012-01-16 04:58:15 -030040#define AZTECH_MAX 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Hans Verkuil3088fba2012-01-16 04:58:15 -030042static int io[AZTECH_MAX] = { [0] = CONFIG_RADIO_AZTECH_PORT,
43 [1 ... (AZTECH_MAX - 1)] = -1 };
44static int radio_nr[AZTECH_MAX] = { [0 ... (AZTECH_MAX - 1)] = -1 };
45static const int radio_wait_time = 1000;
Hans Verkuile697e122009-03-06 13:48:18 -030046
Hans Verkuil3088fba2012-01-16 04:58:15 -030047module_param_array(io, int, NULL, 0444);
48MODULE_PARM_DESC(io, "I/O addresses of the Aztech card (0x350 or 0x358)");
49module_param_array(radio_nr, int, NULL, 0444);
50MODULE_PARM_DESC(radio_nr, "Radio device numbers");
51
52struct aztech {
53 struct radio_isa_card isa;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 int curvol;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055};
56
Hans Verkuile697e122009-03-06 13:48:18 -030057static void send_0_byte(struct aztech *az)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 udelay(radio_wait_time);
Hans Verkuil3088fba2012-01-16 04:58:15 -030060 outb_p(2 + az->curvol, az->isa.io);
61 outb_p(64 + 2 + az->curvol, az->isa.io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
Hans Verkuile697e122009-03-06 13:48:18 -030064static void send_1_byte(struct aztech *az)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Hans Verkuil3088fba2012-01-16 04:58:15 -030066 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
Hans Verkuil3088fba2012-01-16 04:58:15 -030071static struct radio_isa_card *aztech_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
Hans Verkuil3088fba2012-01-16 04:58:15 -030073 struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL);
74
75 return az ? &az->isa : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
Hans Verkuil3088fba2012-01-16 04:58:15 -030078static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
Hans Verkuil3088fba2012-01-16 04:58:15 -030080 struct aztech *az = container_of(isa, struct aztech, isa);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 int i;
82
Hans Verkuil3088fba2012-01-16 04:58:15 -030083 freq += 171200; /* Add 10.7 MHz IF */
84 freq /= 800; /* Convert to 50 kHz units */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030085
Hans Verkuile697e122009-03-06 13:48:18 -030086 send_0_byte(az); /* 0: LSB of frequency */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
Hans Verkuil3088fba2012-01-16 04:58:15 -030089 if (freq & (1 << i))
Hans Verkuile697e122009-03-06 13:48:18 -030090 send_1_byte(az);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 else
Hans Verkuile697e122009-03-06 13:48:18 -030092 send_0_byte(az);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Hans Verkuile697e122009-03-06 13:48:18 -030094 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 */
Hans Verkuil3088fba2012-01-16 04:58:15 -030097 if (isa->stereo) /* 17: stereo (1 to enable) */
Hans Verkuile697e122009-03-06 13:48:18 -030098 send_1_byte(az);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 else
Hans Verkuile697e122009-03-06 13:48:18 -0300100 send_0_byte(az);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Hans Verkuile697e122009-03-06 13:48:18 -0300102 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) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109 /* latch frequency */
110
Hans Verkuile697e122009-03-06 13:48:18 -0300111 udelay(radio_wait_time);
Hans Verkuil3088fba2012-01-16 04:58:15 -0300112 outb_p(128 + 64 + az->curvol, az->isa.io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 return 0;
115}
116
Hans Verkuil3088fba2012-01-16 04:58:15 -0300117/* thanks to Michael Dwyer for giving me a dose of clues in
118 * the signal strength department..
119 *
120 * This card has a stereo bit - bit 0 set = mono, not set = stereo
121 */
122static u32 aztech_g_rxsubchans(struct radio_isa_card *isa)
Mauro Carvalho Chehab99218fe2007-01-25 08:09:32 -0300123{
Hans Verkuil3088fba2012-01-16 04:58:15 -0300124 if (inb(isa->io) & 1)
125 return V4L2_TUNER_SUB_MONO;
126 return V4L2_TUNER_SUB_STEREO;
127}
128
129static int aztech_s_stereo(struct radio_isa_card *isa, bool stereo)
130{
131 return aztech_s_frequency(isa, isa->freq);
132}
133
134static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
135{
136 struct aztech *az = container_of(isa, struct aztech, isa);
137
138 if (mute)
139 vol = 0;
140 az->curvol = (vol & 1) + ((vol & 2) << 1);
141 outb(az->curvol, isa->io);
Mauro Carvalho Chehab99218fe2007-01-25 08:09:32 -0300142 return 0;
143}
144
Hans Verkuil3088fba2012-01-16 04:58:15 -0300145static 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,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151};
152
Hans Verkuil3088fba2012-01-16 04:58:15 -0300153static const int aztech_ioports[] = { 0x350, 0x358 };
154
155static 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",
162 },
163 },
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,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173};
174
175static int __init aztech_init(void)
176{
Hans Verkuil3088fba2012-01-16 04:58:15 -0300177 return isa_register_driver(&aztech_driver.driver, AZTECH_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
Hans Verkuile697e122009-03-06 13:48:18 -0300180static void __exit aztech_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
Hans Verkuil3088fba2012-01-16 04:58:15 -0300182 isa_unregister_driver(&aztech_driver.driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183}
184
185module_init(aztech_init);
Hans Verkuile697e122009-03-06 13:48:18 -0300186module_exit(aztech_exit);