blob: b1f844c64fdeddad89a8c58e47b63d3d91936a4c [file] [log] [blame]
Hans Verkuil8bd7ef52012-01-16 05:24:08 -03001/*
2 * RadioTrack II driver
3 * Copyright 1998 Ben Pfaff
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -03004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
Alan Coxd9b01442008-10-27 15:13:47 -03006 * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
8 *
Hans Verkuil8bd7ef52012-01-16 05:24:08 -03009 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
Mauro Carvalho Chehabf8c559f2006-08-08 09:10:02 -030010 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
12
13#include <linux/module.h> /* Modules */
14#include <linux/init.h> /* Initdata */
Peter Osterlundfb911ee2005-09-13 01:25:15 -070015#include <linux/ioport.h> /* request_region */
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/delay.h> /* udelay */
Mauro Carvalho Chehabf8c559f2006-08-08 09:10:02 -030017#include <linux/videodev2.h> /* kernel radio structs */
Hans Verkuil922c78e2009-03-06 13:52:06 -030018#include <linux/mutex.h>
Hans Verkuil922c78e2009-03-06 13:52:06 -030019#include <linux/io.h> /* outb, outb_p */
Hans Verkuila8754312012-03-27 05:39:21 -030020#include <linux/slab.h>
Hans Verkuil922c78e2009-03-06 13:52:06 -030021#include <media/v4l2-device.h>
22#include <media/v4l2-ioctl.h>
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030023#include "radio-isa.h"
Mauro Carvalho Chehabf8c559f2006-08-08 09:10:02 -030024
Hans Verkuil922c78e2009-03-06 13:52:06 -030025MODULE_AUTHOR("Ben Pfaff");
26MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
27MODULE_LICENSE("GPL");
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030028MODULE_VERSION("0.1.99");
Mauro Carvalho Chehabf8c559f2006-08-08 09:10:02 -030029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#ifndef CONFIG_RADIO_RTRACK2_PORT
31#define CONFIG_RADIO_RTRACK2_PORT -1
32#endif
33
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030034#define RTRACK2_MAX 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030036static int io[RTRACK2_MAX] = { [0] = CONFIG_RADIO_RTRACK2_PORT,
37 [1 ... (RTRACK2_MAX - 1)] = -1 };
38static int radio_nr[RTRACK2_MAX] = { [0 ... (RTRACK2_MAX - 1)] = -1 };
Hans Verkuil922c78e2009-03-06 13:52:06 -030039
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030040module_param_array(io, int, NULL, 0444);
41MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
42module_param_array(radio_nr, int, NULL, 0444);
43MODULE_PARM_DESC(radio_nr, "Radio device numbers");
44
45static struct radio_isa_card *rtrack2_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030047 return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030050static void zero(struct radio_isa_card *isa)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030052 outb_p(1, isa->io);
53 outb_p(3, isa->io);
54 outb_p(1, isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030057static void one(struct radio_isa_card *isa)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030059 outb_p(5, isa->io);
60 outb_p(7, isa->io);
61 outb_p(5, isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030064static int rtrack2_s_frequency(struct radio_isa_card *isa, u32 freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
66 int i;
67
68 freq = freq / 200 + 856;
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030069
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030070 outb_p(0xc8, isa->io);
71 outb_p(0xc9, isa->io);
72 outb_p(0xc9, isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74 for (i = 0; i < 10; i++)
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030075 zero(isa);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 for (i = 14; i >= 0; i--)
78 if (freq & (1 << i))
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030079 one(isa);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 else
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030081 zero(isa);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030083 outb_p(0xc8, isa->io);
84 if (!v4l2_ctrl_g_ctrl(isa->mute))
85 outb_p(0, isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 return 0;
87}
88
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030089static u32 rtrack2_g_signal(struct radio_isa_card *isa)
Douglas Landgraf25f30382007-04-19 16:42:25 -030090{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030091 /* bit set = no signal present */
92 return (inb(isa->io) & 2) ? 0 : 0xffff;
93}
94
95static int rtrack2_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
96{
97 outb(mute, isa->io);
Douglas Landgraf25f30382007-04-19 16:42:25 -030098 return 0;
99}
100
Hans Verkuil8bd7ef52012-01-16 05:24:08 -0300101static const struct radio_isa_ops rtrack2_ops = {
102 .alloc = rtrack2_alloc,
103 .s_mute_volume = rtrack2_s_mute_volume,
104 .s_frequency = rtrack2_s_frequency,
105 .g_signal = rtrack2_g_signal,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106};
107
Hans Verkuil8bd7ef52012-01-16 05:24:08 -0300108static const int rtrack2_ioports[] = { 0x20f, 0x30f };
109
110static struct radio_isa_driver rtrack2_driver = {
111 .driver = {
112 .match = radio_isa_match,
113 .probe = radio_isa_probe,
114 .remove = radio_isa_remove,
115 .driver = {
116 .name = "radio-rtrack2",
117 },
118 },
119 .io_params = io,
120 .radio_nr_params = radio_nr,
121 .io_ports = rtrack2_ioports,
122 .num_of_io_ports = ARRAY_SIZE(rtrack2_ioports),
123 .region_size = 4,
124 .card = "AIMSlab RadioTrack II",
125 .ops = &rtrack2_ops,
126 .has_stereo = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127};
128
129static int __init rtrack2_init(void)
130{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -0300131 return isa_register_driver(&rtrack2_driver.driver, RTRACK2_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
Hans Verkuil922c78e2009-03-06 13:52:06 -0300134static void __exit rtrack2_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -0300136 isa_unregister_driver(&rtrack2_driver.driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
139module_init(rtrack2_init);
Hans Verkuil922c78e2009-03-06 13:52:06 -0300140module_exit(rtrack2_exit);