blob: b275c5d0fe9ac83cdc20d54654ae5884861c48ce [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 Verkuil922c78e2009-03-06 13:52:06 -030020#include <media/v4l2-device.h>
21#include <media/v4l2-ioctl.h>
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030022#include "radio-isa.h"
Mauro Carvalho Chehabf8c559f2006-08-08 09:10:02 -030023
Hans Verkuil922c78e2009-03-06 13:52:06 -030024MODULE_AUTHOR("Ben Pfaff");
25MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
26MODULE_LICENSE("GPL");
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030027MODULE_VERSION("0.1.99");
Mauro Carvalho Chehabf8c559f2006-08-08 09:10:02 -030028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#ifndef CONFIG_RADIO_RTRACK2_PORT
30#define CONFIG_RADIO_RTRACK2_PORT -1
31#endif
32
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030033#define RTRACK2_MAX 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030035static int io[RTRACK2_MAX] = { [0] = CONFIG_RADIO_RTRACK2_PORT,
36 [1 ... (RTRACK2_MAX - 1)] = -1 };
37static int radio_nr[RTRACK2_MAX] = { [0 ... (RTRACK2_MAX - 1)] = -1 };
Hans Verkuil922c78e2009-03-06 13:52:06 -030038
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030039module_param_array(io, int, NULL, 0444);
40MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
41module_param_array(radio_nr, int, NULL, 0444);
42MODULE_PARM_DESC(radio_nr, "Radio device numbers");
43
44static struct radio_isa_card *rtrack2_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030046 return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030049static void zero(struct radio_isa_card *isa)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030051 outb_p(1, isa->io);
52 outb_p(3, isa->io);
53 outb_p(1, isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030056static void one(struct radio_isa_card *isa)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030058 outb_p(5, isa->io);
59 outb_p(7, isa->io);
60 outb_p(5, isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
62
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030063static int rtrack2_s_frequency(struct radio_isa_card *isa, u32 freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
65 int i;
66
67 freq = freq / 200 + 856;
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030068
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030069 outb_p(0xc8, isa->io);
70 outb_p(0xc9, isa->io);
71 outb_p(0xc9, isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 for (i = 0; i < 10; i++)
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030074 zero(isa);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 for (i = 14; i >= 0; i--)
77 if (freq & (1 << i))
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030078 one(isa);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 else
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030080 zero(isa);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030082 outb_p(0xc8, isa->io);
83 if (!v4l2_ctrl_g_ctrl(isa->mute))
84 outb_p(0, isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 return 0;
86}
87
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030088static u32 rtrack2_g_signal(struct radio_isa_card *isa)
Douglas Landgraf25f30382007-04-19 16:42:25 -030089{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030090 /* bit set = no signal present */
91 return (inb(isa->io) & 2) ? 0 : 0xffff;
92}
93
94static int rtrack2_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
95{
96 outb(mute, isa->io);
Douglas Landgraf25f30382007-04-19 16:42:25 -030097 return 0;
98}
99
Hans Verkuil8bd7ef52012-01-16 05:24:08 -0300100static const struct radio_isa_ops rtrack2_ops = {
101 .alloc = rtrack2_alloc,
102 .s_mute_volume = rtrack2_s_mute_volume,
103 .s_frequency = rtrack2_s_frequency,
104 .g_signal = rtrack2_g_signal,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105};
106
Hans Verkuil8bd7ef52012-01-16 05:24:08 -0300107static const int rtrack2_ioports[] = { 0x20f, 0x30f };
108
109static struct radio_isa_driver rtrack2_driver = {
110 .driver = {
111 .match = radio_isa_match,
112 .probe = radio_isa_probe,
113 .remove = radio_isa_remove,
114 .driver = {
115 .name = "radio-rtrack2",
116 },
117 },
118 .io_params = io,
119 .radio_nr_params = radio_nr,
120 .io_ports = rtrack2_ioports,
121 .num_of_io_ports = ARRAY_SIZE(rtrack2_ioports),
122 .region_size = 4,
123 .card = "AIMSlab RadioTrack II",
124 .ops = &rtrack2_ops,
125 .has_stereo = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126};
127
128static int __init rtrack2_init(void)
129{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -0300130 return isa_register_driver(&rtrack2_driver.driver, RTRACK2_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
Hans Verkuil922c78e2009-03-06 13:52:06 -0300133static void __exit rtrack2_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -0300135 isa_unregister_driver(&rtrack2_driver.driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137
138module_init(rtrack2_init);
Hans Verkuil922c78e2009-03-06 13:52:06 -0300139module_exit(rtrack2_exit);