treewide: Add SPDX license identifier for more missed files
[linux-block.git] / drivers / media / radio / radio-rtrack2.c
CommitLineData
09c434b8 1// SPDX-License-Identifier: GPL-2.0-only
8bd7ef5a
HV
2/*
3 * RadioTrack II driver
4 * Copyright 1998 Ben Pfaff
4286c6f6 5 *
1da177e4 6 * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
d9b01449 7 * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
1da177e4
LT
8 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
9 *
8bd7ef5a 10 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
32590819 11 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@kernel.org>
4ca28661
HV
12 *
13 * Fully tested with actual hardware and the v4l2-compliance tool.
1da177e4
LT
14 */
15
6e6a8b5a 16#include <linux/module.h> /* Modules */
1da177e4 17#include <linux/init.h> /* Initdata */
fb911ee8 18#include <linux/ioport.h> /* request_region */
1da177e4 19#include <linux/delay.h> /* udelay */
f8c559f8 20#include <linux/videodev2.h> /* kernel radio structs */
922c78e9 21#include <linux/mutex.h>
922c78e9 22#include <linux/io.h> /* outb, outb_p */
a875431d 23#include <linux/slab.h>
922c78e9 24#include <media/v4l2-device.h>
35ea11ff 25#include <media/v4l2-ioctl.h>
8bd7ef5a 26#include "radio-isa.h"
1da177e4 27
922c78e9
HV
28MODULE_AUTHOR("Ben Pfaff");
29MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
30MODULE_LICENSE("GPL");
8bd7ef5a 31MODULE_VERSION("0.1.99");
f8c559f8 32
1da177e4
LT
33#ifndef CONFIG_RADIO_RTRACK2_PORT
34#define CONFIG_RADIO_RTRACK2_PORT -1
35#endif
36
8bd7ef5a 37#define RTRACK2_MAX 2
1da177e4 38
8bd7ef5a
HV
39static int io[RTRACK2_MAX] = { [0] = CONFIG_RADIO_RTRACK2_PORT,
40 [1 ... (RTRACK2_MAX - 1)] = -1 };
41static int radio_nr[RTRACK2_MAX] = { [0 ... (RTRACK2_MAX - 1)] = -1 };
922c78e9 42
8bd7ef5a
HV
43module_param_array(io, int, NULL, 0444);
44MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
45module_param_array(radio_nr, int, NULL, 0444);
46MODULE_PARM_DESC(radio_nr, "Radio device numbers");
1da177e4 47
8bd7ef5a 48static struct radio_isa_card *rtrack2_alloc(void)
1da177e4 49{
8bd7ef5a 50 return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
1da177e4
LT
51}
52
8bd7ef5a 53static void zero(struct radio_isa_card *isa)
1da177e4 54{
8bd7ef5a
HV
55 outb_p(1, isa->io);
56 outb_p(3, isa->io);
57 outb_p(1, isa->io);
1da177e4
LT
58}
59
8bd7ef5a 60static void one(struct radio_isa_card *isa)
1da177e4 61{
8bd7ef5a
HV
62 outb_p(5, isa->io);
63 outb_p(7, isa->io);
64 outb_p(5, isa->io);
1da177e4
LT
65}
66
8bd7ef5a 67static int rtrack2_s_frequency(struct radio_isa_card *isa, u32 freq)
1da177e4
LT
68{
69 int i;
70
71 freq = freq / 200 + 856;
4286c6f6 72
8bd7ef5a
HV
73 outb_p(0xc8, isa->io);
74 outb_p(0xc9, isa->io);
75 outb_p(0xc9, isa->io);
1da177e4
LT
76
77 for (i = 0; i < 10; i++)
8bd7ef5a 78 zero(isa);
1da177e4
LT
79
80 for (i = 14; i >= 0; i--)
81 if (freq & (1 << i))
8bd7ef5a 82 one(isa);
1da177e4 83 else
8bd7ef5a 84 zero(isa);
25f30389 85
8bd7ef5a 86 outb_p(0xc8, isa->io);
4ca28661 87 outb_p(v4l2_ctrl_g_ctrl(isa->mute), isa->io);
25f30389
DL
88 return 0;
89}
f8c559f8 90
8bd7ef5a 91static u32 rtrack2_g_signal(struct radio_isa_card *isa)
25f30389 92{
8bd7ef5a
HV
93 /* bit set = no signal present */
94 return (inb(isa->io) & 2) ? 0 : 0xffff;
25f30389 95}
f8c559f8 96
8bd7ef5a 97static int rtrack2_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
25f30389 98{
8bd7ef5a 99 outb(mute, isa->io);
25f30389
DL
100 return 0;
101}
f8c559f8 102
8bd7ef5a
HV
103static const struct radio_isa_ops rtrack2_ops = {
104 .alloc = rtrack2_alloc,
105 .s_mute_volume = rtrack2_s_mute_volume,
106 .s_frequency = rtrack2_s_frequency,
107 .g_signal = rtrack2_g_signal,
1da177e4
LT
108};
109
8bd7ef5a
HV
110static const int rtrack2_ioports[] = { 0x20f, 0x30f };
111
112static struct radio_isa_driver rtrack2_driver = {
113 .driver = {
114 .match = radio_isa_match,
115 .probe = radio_isa_probe,
116 .remove = radio_isa_remove,
117 .driver = {
118 .name = "radio-rtrack2",
119 },
120 },
121 .io_params = io,
122 .radio_nr_params = radio_nr,
123 .io_ports = rtrack2_ioports,
124 .num_of_io_ports = ARRAY_SIZE(rtrack2_ioports),
125 .region_size = 4,
126 .card = "AIMSlab RadioTrack II",
127 .ops = &rtrack2_ops,
128 .has_stereo = true,
1da177e4
LT
129};
130
131static int __init rtrack2_init(void)
132{
8bd7ef5a 133 return isa_register_driver(&rtrack2_driver.driver, RTRACK2_MAX);
1da177e4
LT
134}
135
922c78e9 136static void __exit rtrack2_exit(void)
1da177e4 137{
8bd7ef5a 138 isa_unregister_driver(&rtrack2_driver.driver);
1da177e4
LT
139}
140
141module_init(rtrack2_init);
922c78e9 142module_exit(rtrack2_exit);