blob: 09cfbc373c92919e3259f5a5e5a1afe2a332578b [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>
Hans Verkuil4ca28662013-02-25 08:00:15 -030011 *
12 * Fully tested with actual hardware and the v4l2-compliance tool.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
14
15#include <linux/module.h> /* Modules */
16#include <linux/init.h> /* Initdata */
Peter Osterlundfb911ee2005-09-13 01:25:15 -070017#include <linux/ioport.h> /* request_region */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/delay.h> /* udelay */
Mauro Carvalho Chehabf8c559f2006-08-08 09:10:02 -030019#include <linux/videodev2.h> /* kernel radio structs */
Hans Verkuil922c78e2009-03-06 13:52:06 -030020#include <linux/mutex.h>
Hans Verkuil922c78e2009-03-06 13:52:06 -030021#include <linux/io.h> /* outb, outb_p */
Hans Verkuila8754312012-03-27 05:39:21 -030022#include <linux/slab.h>
Hans Verkuil922c78e2009-03-06 13:52:06 -030023#include <media/v4l2-device.h>
24#include <media/v4l2-ioctl.h>
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030025#include "radio-isa.h"
Mauro Carvalho Chehabf8c559f2006-08-08 09:10:02 -030026
Hans Verkuil922c78e2009-03-06 13:52:06 -030027MODULE_AUTHOR("Ben Pfaff");
28MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
29MODULE_LICENSE("GPL");
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030030MODULE_VERSION("0.1.99");
Mauro Carvalho Chehabf8c559f2006-08-08 09:10:02 -030031
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#ifndef CONFIG_RADIO_RTRACK2_PORT
33#define CONFIG_RADIO_RTRACK2_PORT -1
34#endif
35
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030036#define RTRACK2_MAX 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030038static int io[RTRACK2_MAX] = { [0] = CONFIG_RADIO_RTRACK2_PORT,
39 [1 ... (RTRACK2_MAX - 1)] = -1 };
40static int radio_nr[RTRACK2_MAX] = { [0 ... (RTRACK2_MAX - 1)] = -1 };
Hans Verkuil922c78e2009-03-06 13:52:06 -030041
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030042module_param_array(io, int, NULL, 0444);
43MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
44module_param_array(radio_nr, int, NULL, 0444);
45MODULE_PARM_DESC(radio_nr, "Radio device numbers");
46
47static struct radio_isa_card *rtrack2_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030049 return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030052static void zero(struct radio_isa_card *isa)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030054 outb_p(1, isa->io);
55 outb_p(3, isa->io);
56 outb_p(1, isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030059static void one(struct radio_isa_card *isa)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030061 outb_p(5, isa->io);
62 outb_p(7, isa->io);
63 outb_p(5, isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030066static int rtrack2_s_frequency(struct radio_isa_card *isa, u32 freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
68 int i;
69
70 freq = freq / 200 + 856;
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030071
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030072 outb_p(0xc8, isa->io);
73 outb_p(0xc9, isa->io);
74 outb_p(0xc9, isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 for (i = 0; i < 10; i++)
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030077 zero(isa);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79 for (i = 14; i >= 0; i--)
80 if (freq & (1 << i))
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030081 one(isa);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 else
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030083 zero(isa);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030085 outb_p(0xc8, isa->io);
Hans Verkuil4ca28662013-02-25 08:00:15 -030086 outb_p(v4l2_ctrl_g_ctrl(isa->mute), isa->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 return 0;
88}
89
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030090static u32 rtrack2_g_signal(struct radio_isa_card *isa)
Douglas Landgraf25f30382007-04-19 16:42:25 -030091{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -030092 /* bit set = no signal present */
93 return (inb(isa->io) & 2) ? 0 : 0xffff;
94}
95
96static int rtrack2_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
97{
98 outb(mute, isa->io);
Douglas Landgraf25f30382007-04-19 16:42:25 -030099 return 0;
100}
101
Hans Verkuil8bd7ef52012-01-16 05:24:08 -0300102static const struct radio_isa_ops rtrack2_ops = {
103 .alloc = rtrack2_alloc,
104 .s_mute_volume = rtrack2_s_mute_volume,
105 .s_frequency = rtrack2_s_frequency,
106 .g_signal = rtrack2_g_signal,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107};
108
Hans Verkuil8bd7ef52012-01-16 05:24:08 -0300109static const int rtrack2_ioports[] = { 0x20f, 0x30f };
110
111static struct radio_isa_driver rtrack2_driver = {
112 .driver = {
113 .match = radio_isa_match,
114 .probe = radio_isa_probe,
115 .remove = radio_isa_remove,
116 .driver = {
117 .name = "radio-rtrack2",
118 },
119 },
120 .io_params = io,
121 .radio_nr_params = radio_nr,
122 .io_ports = rtrack2_ioports,
123 .num_of_io_ports = ARRAY_SIZE(rtrack2_ioports),
124 .region_size = 4,
125 .card = "AIMSlab RadioTrack II",
126 .ops = &rtrack2_ops,
127 .has_stereo = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128};
129
130static int __init rtrack2_init(void)
131{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -0300132 return isa_register_driver(&rtrack2_driver.driver, RTRACK2_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
Hans Verkuil922c78e2009-03-06 13:52:06 -0300135static void __exit rtrack2_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Hans Verkuil8bd7ef52012-01-16 05:24:08 -0300137 isa_unregister_driver(&rtrack2_driver.driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138}
139
140module_init(rtrack2_init);
Hans Verkuil922c78e2009-03-06 13:52:06 -0300141module_exit(rtrack2_exit);