blob: f445327f282d8364d1ce75f1e93d84c9928e34e7 [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 };
Hans Verkuile697e122009-03-06 13:48:18 -030046
Hans Verkuil3088fba2012-01-16 04:58:15 -030047module_param_array(io, int, NULL, 0444);
48MODULE_PARM_DESC(io, "I/O addresses of the Aztech card (0x350 or 0x358)");
49module_param_array(radio_nr, int, NULL, 0444);
50MODULE_PARM_DESC(radio_nr, "Radio device numbers");
51
52struct aztech {
53 struct radio_isa_card isa;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 int curvol;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055};
56
Ondrej Zaryeb27faf2013-07-19 13:46:17 -030057/* bit definitions for register read */
58#define AZTECH_BIT_NOT_TUNED (1 << 0)
59#define AZTECH_BIT_MONO (1 << 1)
60/* bit definitions for register write */
61#define AZTECH_BIT_TUN_CE (1 << 1)
62#define AZTECH_BIT_TUN_CLK (1 << 6)
63#define AZTECH_BIT_TUN_DATA (1 << 7)
64/* bits 0 and 2 are volume control, bits 3..5 are not connected */
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Ondrej Zaryeb27faf2013-07-19 13:46:17 -030066static void aztech_set_pins(void *handle, u8 pins)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Ondrej Zaryeb27faf2013-07-19 13:46:17 -030068 struct radio_isa_card *isa = handle;
69 struct aztech *az = container_of(isa, struct aztech, isa);
70 u8 bits = az->curvol;
71
72 if (pins & LM7000_DATA)
73 bits |= AZTECH_BIT_TUN_DATA;
74 if (pins & LM7000_CLK)
75 bits |= AZTECH_BIT_TUN_CLK;
76 if (pins & LM7000_CE)
77 bits |= AZTECH_BIT_TUN_CE;
78
79 outb_p(bits, az->isa.io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
Hans Verkuil3088fba2012-01-16 04:58:15 -030082static struct radio_isa_card *aztech_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Hans Verkuil3088fba2012-01-16 04:58:15 -030084 struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL);
85
86 return az ? &az->isa : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
Hans Verkuil3088fba2012-01-16 04:58:15 -030089static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
Ondrej Zaryeb27faf2013-07-19 13:46:17 -030091 lm7000_set_freq(freq, isa, aztech_set_pins);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 return 0;
94}
95
Hans Verkuil3088fba2012-01-16 04:58:15 -030096static u32 aztech_g_rxsubchans(struct radio_isa_card *isa)
Mauro Carvalho Chehab99218fe2007-01-25 08:09:32 -030097{
Ondrej Zary1c9f11e2013-07-19 13:46:18 -030098 if (inb(isa->io) & AZTECH_BIT_MONO)
Hans Verkuil3088fba2012-01-16 04:58:15 -030099 return V4L2_TUNER_SUB_MONO;
100 return V4L2_TUNER_SUB_STEREO;
101}
102
Ondrej Zary1c9f11e2013-07-19 13:46:18 -0300103static u32 aztech_g_signal(struct radio_isa_card *isa)
Hans Verkuil3088fba2012-01-16 04:58:15 -0300104{
Ondrej Zary1c9f11e2013-07-19 13:46:18 -0300105 return (inb(isa->io) & AZTECH_BIT_NOT_TUNED) ? 0 : 0xffff;
Hans Verkuil3088fba2012-01-16 04:58:15 -0300106}
107
108static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
109{
110 struct aztech *az = container_of(isa, struct aztech, isa);
111
112 if (mute)
113 vol = 0;
114 az->curvol = (vol & 1) + ((vol & 2) << 1);
115 outb(az->curvol, isa->io);
Mauro Carvalho Chehab99218fe2007-01-25 08:09:32 -0300116 return 0;
117}
118
Hans Verkuil3088fba2012-01-16 04:58:15 -0300119static const struct radio_isa_ops aztech_ops = {
120 .alloc = aztech_alloc,
121 .s_mute_volume = aztech_s_mute_volume,
122 .s_frequency = aztech_s_frequency,
Hans Verkuil3088fba2012-01-16 04:58:15 -0300123 .g_rxsubchans = aztech_g_rxsubchans,
Ondrej Zary1c9f11e2013-07-19 13:46:18 -0300124 .g_signal = aztech_g_signal,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125};
126
Hans Verkuil3088fba2012-01-16 04:58:15 -0300127static const int aztech_ioports[] = { 0x350, 0x358 };
128
129static struct radio_isa_driver aztech_driver = {
130 .driver = {
131 .match = radio_isa_match,
132 .probe = radio_isa_probe,
133 .remove = radio_isa_remove,
134 .driver = {
135 .name = "radio-aztech",
136 },
137 },
138 .io_params = io,
139 .radio_nr_params = radio_nr,
140 .io_ports = aztech_ioports,
141 .num_of_io_ports = ARRAY_SIZE(aztech_ioports),
Ondrej Zaryeb27faf2013-07-19 13:46:17 -0300142 .region_size = 8,
Hans Verkuil3088fba2012-01-16 04:58:15 -0300143 .card = "Aztech Radio",
144 .ops = &aztech_ops,
145 .has_stereo = true,
146 .max_volume = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147};
148
149static int __init aztech_init(void)
150{
Hans Verkuil3088fba2012-01-16 04:58:15 -0300151 return isa_register_driver(&aztech_driver.driver, AZTECH_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
Hans Verkuile697e122009-03-06 13:48:18 -0300154static void __exit aztech_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Hans Verkuil3088fba2012-01-16 04:58:15 -0300156 isa_unregister_driver(&aztech_driver.driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158
159module_init(aztech_init);
Hans Verkuile697e122009-03-06 13:48:18 -0300160module_exit(aztech_exit);