Linux 4.9.243
[linux/fpc-iii.git] / drivers / media / radio / radio-rtrack2.c
blob09cfbc373c92919e3259f5a5e5a1afe2a332578b
1 /*
2 * RadioTrack II driver
3 * Copyright 1998 Ben Pfaff
5 * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
6 * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
7 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
9 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
10 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
12 * Fully tested with actual hardware and the v4l2-compliance tool.
15 #include <linux/module.h> /* Modules */
16 #include <linux/init.h> /* Initdata */
17 #include <linux/ioport.h> /* request_region */
18 #include <linux/delay.h> /* udelay */
19 #include <linux/videodev2.h> /* kernel radio structs */
20 #include <linux/mutex.h>
21 #include <linux/io.h> /* outb, outb_p */
22 #include <linux/slab.h>
23 #include <media/v4l2-device.h>
24 #include <media/v4l2-ioctl.h>
25 #include "radio-isa.h"
27 MODULE_AUTHOR("Ben Pfaff");
28 MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
29 MODULE_LICENSE("GPL");
30 MODULE_VERSION("0.1.99");
32 #ifndef CONFIG_RADIO_RTRACK2_PORT
33 #define CONFIG_RADIO_RTRACK2_PORT -1
34 #endif
36 #define RTRACK2_MAX 2
38 static int io[RTRACK2_MAX] = { [0] = CONFIG_RADIO_RTRACK2_PORT,
39 [1 ... (RTRACK2_MAX - 1)] = -1 };
40 static int radio_nr[RTRACK2_MAX] = { [0 ... (RTRACK2_MAX - 1)] = -1 };
42 module_param_array(io, int, NULL, 0444);
43 MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
44 module_param_array(radio_nr, int, NULL, 0444);
45 MODULE_PARM_DESC(radio_nr, "Radio device numbers");
47 static struct radio_isa_card *rtrack2_alloc(void)
49 return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
52 static void zero(struct radio_isa_card *isa)
54 outb_p(1, isa->io);
55 outb_p(3, isa->io);
56 outb_p(1, isa->io);
59 static void one(struct radio_isa_card *isa)
61 outb_p(5, isa->io);
62 outb_p(7, isa->io);
63 outb_p(5, isa->io);
66 static int rtrack2_s_frequency(struct radio_isa_card *isa, u32 freq)
68 int i;
70 freq = freq / 200 + 856;
72 outb_p(0xc8, isa->io);
73 outb_p(0xc9, isa->io);
74 outb_p(0xc9, isa->io);
76 for (i = 0; i < 10; i++)
77 zero(isa);
79 for (i = 14; i >= 0; i--)
80 if (freq & (1 << i))
81 one(isa);
82 else
83 zero(isa);
85 outb_p(0xc8, isa->io);
86 outb_p(v4l2_ctrl_g_ctrl(isa->mute), isa->io);
87 return 0;
90 static u32 rtrack2_g_signal(struct radio_isa_card *isa)
92 /* bit set = no signal present */
93 return (inb(isa->io) & 2) ? 0 : 0xffff;
96 static int rtrack2_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
98 outb(mute, isa->io);
99 return 0;
102 static 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,
109 static const int rtrack2_ioports[] = { 0x20f, 0x30f };
111 static 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",
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,
130 static int __init rtrack2_init(void)
132 return isa_register_driver(&rtrack2_driver.driver, RTRACK2_MAX);
135 static void __exit rtrack2_exit(void)
137 isa_unregister_driver(&rtrack2_driver.driver);
140 module_init(rtrack2_init);
141 module_exit(rtrack2_exit);