radio-aztech.c 4.9 KB
Newer Older
1 2
/*
 * radio-aztech.c - Aztech radio card driver
L
Linus Torvalds 已提交
3
 *
4
 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@xs4all.nl>
5
 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
6
 * Adapted to support the Video for Linux API by
L
Linus Torvalds 已提交
7 8 9 10
 * Russell Kroll <rkroll@exploits.org>.  Based on original tuner code by:
 *
 * Quay Ly
 * Donald Song
11
 * Jason Lewis      (jlewis@twilight.vtc.vsc.edu)
L
Linus Torvalds 已提交
12 13 14
 * Scott McGrath    (smcgrath@twilight.vtc.vsc.edu)
 * William McGrath  (wmcgrath@twilight.vtc.vsc.edu)
 *
15
 * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool.
L
Linus Torvalds 已提交
16 17 18 19
*/

#include <linux/module.h>	/* Modules 			*/
#include <linux/init.h>		/* Initdata			*/
20
#include <linux/ioport.h>	/* request_region		*/
L
Linus Torvalds 已提交
21
#include <linux/delay.h>	/* udelay			*/
22
#include <linux/videodev2.h>	/* kernel radio structs		*/
23 24
#include <linux/io.h>		/* outb, outb_p			*/
#include <media/v4l2-device.h>
25
#include <media/v4l2-ioctl.h>
26 27
#include <media/v4l2-ctrls.h>
#include "radio-isa.h"
L
Linus Torvalds 已提交
28

29 30 31
MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
MODULE_DESCRIPTION("A driver for the Aztech radio card.");
MODULE_LICENSE("GPL");
32
MODULE_VERSION("1.0.0");
33

L
Linus Torvalds 已提交
34 35 36 37 38
/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
#ifndef CONFIG_RADIO_AZTECH_PORT
#define CONFIG_RADIO_AZTECH_PORT -1
#endif

39
#define AZTECH_MAX 2
L
Linus Torvalds 已提交
40

41 42 43 44
static int io[AZTECH_MAX] = { [0] = CONFIG_RADIO_AZTECH_PORT,
			      [1 ... (AZTECH_MAX - 1)] = -1 };
static int radio_nr[AZTECH_MAX]	= { [0 ... (AZTECH_MAX - 1)] = -1 };
static const int radio_wait_time = 1000;
45

46 47 48 49 50 51 52
module_param_array(io, int, NULL, 0444);
MODULE_PARM_DESC(io, "I/O addresses of the Aztech card (0x350 or 0x358)");
module_param_array(radio_nr, int, NULL, 0444);
MODULE_PARM_DESC(radio_nr, "Radio device numbers");

struct aztech {
	struct radio_isa_card isa;
L
Linus Torvalds 已提交
53 54 55
	int curvol;
};

56
static void send_0_byte(struct aztech *az)
L
Linus Torvalds 已提交
57 58
{
	udelay(radio_wait_time);
59 60
	outb_p(2 + az->curvol, az->isa.io);
	outb_p(64 + 2 + az->curvol, az->isa.io);
L
Linus Torvalds 已提交
61 62
}

63
static void send_1_byte(struct aztech *az)
L
Linus Torvalds 已提交
64
{
65 66 67
	udelay(radio_wait_time);
	outb_p(128 + 2 + az->curvol, az->isa.io);
	outb_p(128 + 64 + 2 + az->curvol, az->isa.io);
L
Linus Torvalds 已提交
68 69
}

70
static struct radio_isa_card *aztech_alloc(void)
L
Linus Torvalds 已提交
71
{
72
	struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL);
73

74
	return az ? &az->isa : NULL;
L
Linus Torvalds 已提交
75 76
}

77
static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq)
L
Linus Torvalds 已提交
78
{
79
	struct aztech *az = container_of(isa, struct aztech, isa);
L
Linus Torvalds 已提交
80 81
	int  i;

82 83
	freq += 171200;			/* Add 10.7 MHz IF		*/
	freq /= 800;			/* Convert to 50 kHz units	*/
84

85
	send_0_byte(az);		/*  0: LSB of frequency       */
L
Linus Torvalds 已提交
86 87

	for (i = 0; i < 13; i++)	/*   : frequency bits (1-13)  */
88
		if (freq & (1 << i))
89
			send_1_byte(az);
L
Linus Torvalds 已提交
90
		else
91
			send_0_byte(az);
L
Linus Torvalds 已提交
92

93 94 95
	send_0_byte(az);		/* 14: test bit - always 0    */
	send_0_byte(az);		/* 15: test bit - always 0    */
	send_0_byte(az);		/* 16: band data 0 - always 0 */
96
	if (isa->stereo)		/* 17: stereo (1 to enable)   */
97
		send_1_byte(az);
L
Linus Torvalds 已提交
98
	else
99
		send_0_byte(az);
L
Linus Torvalds 已提交
100

101 102 103 104 105 106
	send_1_byte(az);		/* 18: band data 1 - unknown  */
	send_0_byte(az);		/* 19: time base - always 0   */
	send_0_byte(az);		/* 20: spacing (0 = 25 kHz)   */
	send_1_byte(az);		/* 21: spacing (1 = 25 kHz)   */
	send_0_byte(az);		/* 22: spacing (0 = 25 kHz)   */
	send_1_byte(az);		/* 23: AM/FM (FM = 1, always) */
L
Linus Torvalds 已提交
107 108 109

	/* latch frequency */

110
	udelay(radio_wait_time);
111
	outb_p(128 + 64 + az->curvol, az->isa.io);
112

113 114 115
	return 0;
}

116 117 118 119 120 121
/* thanks to Michael Dwyer for giving me a dose of clues in
 * the signal strength department..
 *
 * This card has a stereo bit - bit 0 set = mono, not set = stereo
 */
static u32 aztech_g_rxsubchans(struct radio_isa_card *isa)
122
{
123 124 125
	if (inb(isa->io) & 1)
		return V4L2_TUNER_SUB_MONO;
	return V4L2_TUNER_SUB_STEREO;
126 127
}

128
static int aztech_s_stereo(struct radio_isa_card *isa, bool stereo)
129
{
130
	return aztech_s_frequency(isa, isa->freq);
131 132
}

133
static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
134
{
135
	struct aztech *az = container_of(isa, struct aztech, isa);
136

137 138 139 140
	if (mute)
		vol = 0;
	az->curvol = (vol & 1) + ((vol & 2) << 1);
	outb(az->curvol, isa->io);
141 142 143
	return 0;
}

144 145 146 147 148 149
static const struct radio_isa_ops aztech_ops = {
	.alloc = aztech_alloc,
	.s_mute_volume = aztech_s_mute_volume,
	.s_frequency = aztech_s_frequency,
	.s_stereo = aztech_s_stereo,
	.g_rxsubchans = aztech_g_rxsubchans,
L
Linus Torvalds 已提交
150 151
};

152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
static const int aztech_ioports[] = { 0x350, 0x358 };

static struct radio_isa_driver aztech_driver = {
	.driver = {
		.match		= radio_isa_match,
		.probe		= radio_isa_probe,
		.remove		= radio_isa_remove,
		.driver		= {
			.name	= "radio-aztech",
		},
	},
	.io_params = io,
	.radio_nr_params = radio_nr,
	.io_ports = aztech_ioports,
	.num_of_io_ports = ARRAY_SIZE(aztech_ioports),
	.region_size = 2,
	.card = "Aztech Radio",
	.ops = &aztech_ops,
	.has_stereo = true,
	.max_volume = 3,
L
Linus Torvalds 已提交
172 173 174 175
};

static int __init aztech_init(void)
{
176
	return isa_register_driver(&aztech_driver.driver, AZTECH_MAX);
L
Linus Torvalds 已提交
177 178
}

179
static void __exit aztech_exit(void)
L
Linus Torvalds 已提交
180
{
181
	isa_unregister_driver(&aztech_driver.driver);
L
Linus Torvalds 已提交
182 183 184
}

module_init(aztech_init);
185
module_exit(aztech_exit);