1 // SPDX-License-Identifier: GPL-2.0-only
3 * radio-aztech.c - Aztech radio card driver
5 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@xs4all.nl>
6 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@kernel.org>
7 * Adapted to support the Video for Linux API by
8 * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by:
12 * Jason Lewis (jlewis@twilight.vtc.vsc.edu)
13 * Scott McGrath (smcgrath@twilight.vtc.vsc.edu)
14 * William McGrath (wmcgrath@twilight.vtc.vsc.edu)
16 * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool.
19 #include <linux/module.h> /* Modules */
20 #include <linux/init.h> /* Initdata */
21 #include <linux/ioport.h> /* request_region */
22 #include <linux/delay.h> /* udelay */
23 #include <linux/videodev2.h> /* kernel radio structs */
24 #include <linux/io.h> /* outb, outb_p */
25 #include <linux/slab.h>
26 #include <media/v4l2-device.h>
27 #include <media/v4l2-ioctl.h>
28 #include <media/v4l2-ctrls.h>
29 #include "radio-isa.h"
32 MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
33 MODULE_DESCRIPTION("A driver for the Aztech radio card.");
34 MODULE_LICENSE("GPL");
35 MODULE_VERSION("1.0.0");
37 /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
38 #ifndef CONFIG_RADIO_AZTECH_PORT
39 #define CONFIG_RADIO_AZTECH_PORT -1
44 static int io
[AZTECH_MAX
] = { [0] = CONFIG_RADIO_AZTECH_PORT
,
45 [1 ... (AZTECH_MAX
- 1)] = -1 };
46 static int radio_nr
[AZTECH_MAX
] = { [0 ... (AZTECH_MAX
- 1)] = -1 };
48 module_param_array(io
, int, NULL
, 0444);
49 MODULE_PARM_DESC(io
, "I/O addresses of the Aztech card (0x350 or 0x358)");
50 module_param_array(radio_nr
, int, NULL
, 0444);
51 MODULE_PARM_DESC(radio_nr
, "Radio device numbers");
54 struct radio_isa_card isa
;
58 /* bit definitions for register read */
59 #define AZTECH_BIT_NOT_TUNED (1 << 0)
60 #define AZTECH_BIT_MONO (1 << 1)
61 /* bit definitions for register write */
62 #define AZTECH_BIT_TUN_CE (1 << 1)
63 #define AZTECH_BIT_TUN_CLK (1 << 6)
64 #define AZTECH_BIT_TUN_DATA (1 << 7)
65 /* bits 0 and 2 are volume control, bits 3..5 are not connected */
67 static void aztech_set_pins(void *handle
, u8 pins
)
69 struct radio_isa_card
*isa
= handle
;
70 struct aztech
*az
= container_of(isa
, struct aztech
, isa
);
73 if (pins
& LM7000_DATA
)
74 bits
|= AZTECH_BIT_TUN_DATA
;
75 if (pins
& LM7000_CLK
)
76 bits
|= AZTECH_BIT_TUN_CLK
;
78 bits
|= AZTECH_BIT_TUN_CE
;
80 outb_p(bits
, az
->isa
.io
);
83 static struct radio_isa_card
*aztech_alloc(void)
85 struct aztech
*az
= kzalloc(sizeof(*az
), GFP_KERNEL
);
87 return az
? &az
->isa
: NULL
;
90 static int aztech_s_frequency(struct radio_isa_card
*isa
, u32 freq
)
92 lm7000_set_freq(freq
, isa
, aztech_set_pins
);
97 static u32
aztech_g_rxsubchans(struct radio_isa_card
*isa
)
99 if (inb(isa
->io
) & AZTECH_BIT_MONO
)
100 return V4L2_TUNER_SUB_MONO
;
101 return V4L2_TUNER_SUB_STEREO
;
104 static u32
aztech_g_signal(struct radio_isa_card
*isa
)
106 return (inb(isa
->io
) & AZTECH_BIT_NOT_TUNED
) ? 0 : 0xffff;
109 static int aztech_s_mute_volume(struct radio_isa_card
*isa
, bool mute
, int vol
)
111 struct aztech
*az
= container_of(isa
, struct aztech
, isa
);
115 az
->curvol
= (vol
& 1) + ((vol
& 2) << 1);
116 outb(az
->curvol
, isa
->io
);
120 static const struct radio_isa_ops aztech_ops
= {
121 .alloc
= aztech_alloc
,
122 .s_mute_volume
= aztech_s_mute_volume
,
123 .s_frequency
= aztech_s_frequency
,
124 .g_rxsubchans
= aztech_g_rxsubchans
,
125 .g_signal
= aztech_g_signal
,
128 static const int aztech_ioports
[] = { 0x350, 0x358 };
130 static struct radio_isa_driver aztech_driver
= {
132 .match
= radio_isa_match
,
133 .probe
= radio_isa_probe
,
134 .remove
= radio_isa_remove
,
136 .name
= "radio-aztech",
140 .radio_nr_params
= radio_nr
,
141 .io_ports
= aztech_ioports
,
142 .num_of_io_ports
= ARRAY_SIZE(aztech_ioports
),
144 .card
= "Aztech Radio",
150 static int __init
aztech_init(void)
152 return isa_register_driver(&aztech_driver
.driver
, AZTECH_MAX
);
155 static void __exit
aztech_exit(void)
157 isa_unregister_driver(&aztech_driver
.driver
);
160 module_init(aztech_init
);
161 module_exit(aztech_exit
);