blob: 2f5671f2e17e35a5497a5a0560867efc2f572068 [file] [log] [blame]
Hans Verkuil3088fba2012-01-16 04:58:15 -03001/*
2 * radio-aztech.c - Aztech radio card driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Hans Verkuil3088fba2012-01-16 04:58:15 -03004 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@xs4all.nl>
Mauro Carvalho Chehaba4366af2006-08-08 09:10:01 -03005 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -03006 * Adapted to support the Video for Linux API by
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by:
8 *
9 * Quay Ly
10 * Donald Song
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030011 * Jason Lewis (jlewis@twilight.vtc.vsc.edu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Scott McGrath (smcgrath@twilight.vtc.vsc.edu)
13 * William McGrath (wmcgrath@twilight.vtc.vsc.edu)
14 *
Hans Verkuil3088fba2012-01-16 04:58:15 -030015 * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool.
Linus Torvalds1da177e2005-04-16 15:20:36 -070016*/
17
18#include <linux/module.h> /* Modules */
19#include <linux/init.h> /* Initdata */
Peter Osterlundfb911ee2005-09-13 01:25:15 -070020#include <linux/ioport.h> /* request_region */
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/delay.h> /* udelay */
Mauro Carvalho Chehaba4366af2006-08-08 09:10:01 -030022#include <linux/videodev2.h> /* kernel radio structs */
Hans Verkuile697e122009-03-06 13:48:18 -030023#include <linux/io.h> /* outb, outb_p */
Hans Verkuil9f1dfcc2012-02-29 05:50:27 -030024#include <linux/slab.h>
Hans Verkuile697e122009-03-06 13:48:18 -030025#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030026#include <media/v4l2-ioctl.h>
Hans Verkuil3088fba2012-01-16 04:58:15 -030027#include <media/v4l2-ctrls.h>
28#include "radio-isa.h"
Ondrej Zaryeb27faf2013-07-19 13:46:17 -030029#include "lm7000.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Hans Verkuile697e122009-03-06 13:48:18 -030031MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
32MODULE_DESCRIPTION("A driver for the Aztech radio card.");
33MODULE_LICENSE("GPL");
Hans Verkuil3088fba2012-01-16 04:58:15 -030034MODULE_VERSION("1.0.0");
Mauro Carvalho Chehaba4366af2006-08-08 09:10:01 -030035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#ifndef CONFIG_RADIO_AZTECH_PORT
38#define CONFIG_RADIO_AZTECH_PORT -1
39#endif
40
Hans Verkuil3088fba2012-01-16 04:58:15 -030041#define AZTECH_MAX 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Hans Verkuil3088fba2012-01-16 04:58:15 -030043static int io[AZTECH_MAX] = { [0] = CONFIG_RADIO_AZTECH_PORT,
44 [1 ... (AZTECH_MAX - 1)] = -1 };
45static int radio_nr[AZTECH_MAX] = { [0 ... (AZTECH_MAX - 1)] = -1 };
46static const int radio_wait_time = 1000;
Hans Verkuile697e122009-03-06 13:48:18 -030047
Hans Verkuil3088fba2012-01-16 04:58:15 -030048module_param_array(io, int, NULL, 0444);
49MODULE_PARM_DESC(io, "I/O addresses of the Aztech card (0x350 or 0x358)");
50module_param_array(radio_nr, int, NULL, 0444);
51MODULE_PARM_DESC(radio_nr, "Radio device numbers");
52
53struct aztech {
54 struct radio_isa_card isa;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 int curvol;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056};
57
Ondrej Zaryeb27faf2013-07-19 13:46:17 -030058/* 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Ondrej Zaryeb27faf2013-07-19 13:46:17 -030067static void aztech_set_pins(void *handle, u8 pins)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Ondrej Zaryeb27faf2013-07-19 13:46:17 -030069 struct radio_isa_card *isa = handle;
70 struct aztech *az = container_of(isa, struct aztech, isa);
71 u8 bits = az->curvol;
72
73 if (pins & LM7000_DATA)
74 bits |= AZTECH_BIT_TUN_DATA;
75 if (pins & LM7000_CLK)
76 bits |= AZTECH_BIT_TUN_CLK;
77 if (pins & LM7000_CE)
78 bits |= AZTECH_BIT_TUN_CE;
79
80 outb_p(bits, az->isa.io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
Hans Verkuil3088fba2012-01-16 04:58:15 -030083static struct radio_isa_card *aztech_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Hans Verkuil3088fba2012-01-16 04:58:15 -030085 struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL);
86
87 return az ? &az->isa : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89
Hans Verkuil3088fba2012-01-16 04:58:15 -030090static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Ondrej Zaryeb27faf2013-07-19 13:46:17 -030092 lm7000_set_freq(freq, isa, aztech_set_pins);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 return 0;
95}
96
Hans Verkuil3088fba2012-01-16 04:58:15 -030097/* thanks to Michael Dwyer for giving me a dose of clues in
98 * the signal strength department..
99 *
100 * This card has a stereo bit - bit 0 set = mono, not set = stereo
101 */
102static u32 aztech_g_rxsubchans(struct radio_isa_card *isa)
Mauro Carvalho Chehab99218fe2007-01-25 08:09:32 -0300103{
Hans Verkuil3088fba2012-01-16 04:58:15 -0300104 if (inb(isa->io) & 1)
105 return V4L2_TUNER_SUB_MONO;
106 return V4L2_TUNER_SUB_STEREO;
107}
108
109static int aztech_s_stereo(struct radio_isa_card *isa, bool stereo)
110{
111 return aztech_s_frequency(isa, isa->freq);
112}
113
114static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
115{
116 struct aztech *az = container_of(isa, struct aztech, isa);
117
118 if (mute)
119 vol = 0;
120 az->curvol = (vol & 1) + ((vol & 2) << 1);
121 outb(az->curvol, isa->io);
Mauro Carvalho Chehab99218fe2007-01-25 08:09:32 -0300122 return 0;
123}
124
Hans Verkuil3088fba2012-01-16 04:58:15 -0300125static const struct radio_isa_ops aztech_ops = {
126 .alloc = aztech_alloc,
127 .s_mute_volume = aztech_s_mute_volume,
128 .s_frequency = aztech_s_frequency,
129 .s_stereo = aztech_s_stereo,
130 .g_rxsubchans = aztech_g_rxsubchans,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131};
132
Hans Verkuil3088fba2012-01-16 04:58:15 -0300133static const int aztech_ioports[] = { 0x350, 0x358 };
134
135static struct radio_isa_driver aztech_driver = {
136 .driver = {
137 .match = radio_isa_match,
138 .probe = radio_isa_probe,
139 .remove = radio_isa_remove,
140 .driver = {
141 .name = "radio-aztech",
142 },
143 },
144 .io_params = io,
145 .radio_nr_params = radio_nr,
146 .io_ports = aztech_ioports,
147 .num_of_io_ports = ARRAY_SIZE(aztech_ioports),
Ondrej Zaryeb27faf2013-07-19 13:46:17 -0300148 .region_size = 8,
Hans Verkuil3088fba2012-01-16 04:58:15 -0300149 .card = "Aztech Radio",
150 .ops = &aztech_ops,
151 .has_stereo = true,
152 .max_volume = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153};
154
155static int __init aztech_init(void)
156{
Hans Verkuil3088fba2012-01-16 04:58:15 -0300157 return isa_register_driver(&aztech_driver.driver, AZTECH_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158}
159
Hans Verkuile697e122009-03-06 13:48:18 -0300160static void __exit aztech_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
Hans Verkuil3088fba2012-01-16 04:58:15 -0300162 isa_unregister_driver(&aztech_driver.driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165module_init(aztech_init);
Hans Verkuile697e122009-03-06 13:48:18 -0300166module_exit(aztech_exit);