Merge tag 'dmaengine-4.8-rc1' of git://git.infradead.org/users/vkoul/slave-dma
[deliverable/linux.git] / drivers / media / radio / radio-rtrack2.c
CommitLineData
8bd7ef5a
HV
1/*
2 * RadioTrack II driver
3 * Copyright 1998 Ben Pfaff
4286c6f6 4 *
1da177e4 5 * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
d9b01449 6 * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
1da177e4
LT
7 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
8 *
8bd7ef5a 9 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
f8c559f8 10 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
4ca28661
HV
11 *
12 * Fully tested with actual hardware and the v4l2-compliance tool.
1da177e4
LT
13 */
14
15#include <linux/module.h> /* Modules */
16#include <linux/init.h> /* Initdata */
fb911ee8 17#include <linux/ioport.h> /* request_region */
1da177e4 18#include <linux/delay.h> /* udelay */
f8c559f8 19#include <linux/videodev2.h> /* kernel radio structs */
922c78e9 20#include <linux/mutex.h>
922c78e9 21#include <linux/io.h> /* outb, outb_p */
a875431d 22#include <linux/slab.h>
922c78e9 23#include <media/v4l2-device.h>
35ea11ff 24#include <media/v4l2-ioctl.h>
8bd7ef5a 25#include "radio-isa.h"
1da177e4 26
922c78e9
HV
27MODULE_AUTHOR("Ben Pfaff");
28MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
29MODULE_LICENSE("GPL");
8bd7ef5a 30MODULE_VERSION("0.1.99");
f8c559f8 31
1da177e4
LT
32#ifndef CONFIG_RADIO_RTRACK2_PORT
33#define CONFIG_RADIO_RTRACK2_PORT -1
34#endif
35
8bd7ef5a 36#define RTRACK2_MAX 2
1da177e4 37
8bd7ef5a
HV
38static 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 };
922c78e9 41
8bd7ef5a
HV
42module_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");
1da177e4 46
8bd7ef5a 47static struct radio_isa_card *rtrack2_alloc(void)
1da177e4 48{
8bd7ef5a 49 return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
1da177e4
LT
50}
51
8bd7ef5a 52static void zero(struct radio_isa_card *isa)
1da177e4 53{
8bd7ef5a
HV
54 outb_p(1, isa->io);
55 outb_p(3, isa->io);
56 outb_p(1, isa->io);
1da177e4
LT
57}
58
8bd7ef5a 59static void one(struct radio_isa_card *isa)
1da177e4 60{
8bd7ef5a
HV
61 outb_p(5, isa->io);
62 outb_p(7, isa->io);
63 outb_p(5, isa->io);
1da177e4
LT
64}
65
8bd7ef5a 66static int rtrack2_s_frequency(struct radio_isa_card *isa, u32 freq)
1da177e4
LT
67{
68 int i;
69
70 freq = freq / 200 + 856;
4286c6f6 71
8bd7ef5a
HV
72 outb_p(0xc8, isa->io);
73 outb_p(0xc9, isa->io);
74 outb_p(0xc9, isa->io);
1da177e4
LT
75
76 for (i = 0; i < 10; i++)
8bd7ef5a 77 zero(isa);
1da177e4
LT
78
79 for (i = 14; i >= 0; i--)
80 if (freq & (1 << i))
8bd7ef5a 81 one(isa);
1da177e4 82 else
8bd7ef5a 83 zero(isa);
25f30389 84
8bd7ef5a 85 outb_p(0xc8, isa->io);
4ca28661 86 outb_p(v4l2_ctrl_g_ctrl(isa->mute), isa->io);
25f30389
DL
87 return 0;
88}
f8c559f8 89
8bd7ef5a 90static u32 rtrack2_g_signal(struct radio_isa_card *isa)
25f30389 91{
8bd7ef5a
HV
92 /* bit set = no signal present */
93 return (inb(isa->io) & 2) ? 0 : 0xffff;
25f30389 94}
f8c559f8 95
8bd7ef5a 96static int rtrack2_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
25f30389 97{
8bd7ef5a 98 outb(mute, isa->io);
25f30389
DL
99 return 0;
100}
f8c559f8 101
8bd7ef5a
HV
102static 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,
1da177e4
LT
107};
108
8bd7ef5a
HV
109static 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,
1da177e4
LT
128};
129
130static int __init rtrack2_init(void)
131{
8bd7ef5a 132 return isa_register_driver(&rtrack2_driver.driver, RTRACK2_MAX);
1da177e4
LT
133}
134
922c78e9 135static void __exit rtrack2_exit(void)
1da177e4 136{
8bd7ef5a 137 isa_unregister_driver(&rtrack2_driver.driver);
1da177e4
LT
138}
139
140module_init(rtrack2_init);
922c78e9 141module_exit(rtrack2_exit);
This page took 0.9064 seconds and 5 git commands to generate.