Commit | Line | Data |
---|---|---|
3088fba8 HV |
1 | /* |
2 | * radio-aztech.c - Aztech radio card driver | |
1da177e4 | 3 | * |
3088fba8 | 4 | * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@xs4all.nl> |
a4366af4 | 5 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
4286c6f6 | 6 | * Adapted to support the Video for Linux API by |
1da177e4 LT |
7 | * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by: |
8 | * | |
9 | * Quay Ly | |
10 | * Donald Song | |
4286c6f6 | 11 | * Jason Lewis (jlewis@twilight.vtc.vsc.edu) |
1da177e4 LT |
12 | * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) |
13 | * William McGrath (wmcgrath@twilight.vtc.vsc.edu) | |
14 | * | |
3088fba8 | 15 | * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool. |
1da177e4 LT |
16 | */ |
17 | ||
18 | #include <linux/module.h> /* Modules */ | |
19 | #include <linux/init.h> /* Initdata */ | |
fb911ee8 | 20 | #include <linux/ioport.h> /* request_region */ |
1da177e4 | 21 | #include <linux/delay.h> /* udelay */ |
a4366af4 | 22 | #include <linux/videodev2.h> /* kernel radio structs */ |
e697e12e | 23 | #include <linux/io.h> /* outb, outb_p */ |
9f1dfccf | 24 | #include <linux/slab.h> |
e697e12e | 25 | #include <media/v4l2-device.h> |
35ea11ff | 26 | #include <media/v4l2-ioctl.h> |
3088fba8 HV |
27 | #include <media/v4l2-ctrls.h> |
28 | #include "radio-isa.h" | |
eb27fafe | 29 | #include "lm7000.h" |
1da177e4 | 30 | |
e697e12e HV |
31 | MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath"); |
32 | MODULE_DESCRIPTION("A driver for the Aztech radio card."); | |
33 | MODULE_LICENSE("GPL"); | |
3088fba8 | 34 | MODULE_VERSION("1.0.0"); |
a4366af4 | 35 | |
1da177e4 | 36 | /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ |
1da177e4 LT |
37 | #ifndef CONFIG_RADIO_AZTECH_PORT |
38 | #define CONFIG_RADIO_AZTECH_PORT -1 | |
39 | #endif | |
40 | ||
3088fba8 | 41 | #define AZTECH_MAX 2 |
1da177e4 | 42 | |
3088fba8 HV |
43 | static int io[AZTECH_MAX] = { [0] = CONFIG_RADIO_AZTECH_PORT, |
44 | [1 ... (AZTECH_MAX - 1)] = -1 }; | |
45 | static int radio_nr[AZTECH_MAX] = { [0 ... (AZTECH_MAX - 1)] = -1 }; | |
46 | static const int radio_wait_time = 1000; | |
e697e12e | 47 | |
3088fba8 HV |
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"); | |
52 | ||
53 | struct aztech { | |
54 | struct radio_isa_card isa; | |
1da177e4 | 55 | int curvol; |
1da177e4 LT |
56 | }; |
57 | ||
eb27fafe OZ |
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 */ | |
1da177e4 | 66 | |
eb27fafe | 67 | static void aztech_set_pins(void *handle, u8 pins) |
1da177e4 | 68 | { |
eb27fafe OZ |
69 | 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); | |
1da177e4 LT |
81 | } |
82 | ||
3088fba8 | 83 | static struct radio_isa_card *aztech_alloc(void) |
1da177e4 | 84 | { |
3088fba8 | 85 | struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL); |
e697e12e | 86 | |
3088fba8 | 87 | return az ? &az->isa : NULL; |
1da177e4 LT |
88 | } |
89 | ||
3088fba8 | 90 | static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq) |
1da177e4 | 91 | { |
eb27fafe | 92 | lm7000_set_freq(freq, isa, aztech_set_pins); |
676b0ac7 | 93 | |
a0c05ab9 MCC |
94 | return 0; |
95 | } | |
96 | ||
3088fba8 | 97 | static u32 aztech_g_rxsubchans(struct radio_isa_card *isa) |
e697e12e | 98 | { |
1c9f11ed | 99 | if (inb(isa->io) & AZTECH_BIT_MONO) |
3088fba8 HV |
100 | return V4L2_TUNER_SUB_MONO; |
101 | return V4L2_TUNER_SUB_STEREO; | |
e697e12e HV |
102 | } |
103 | ||
1c9f11ed | 104 | static u32 aztech_g_signal(struct radio_isa_card *isa) |
99218fe4 | 105 | { |
1c9f11ed | 106 | return (inb(isa->io) & AZTECH_BIT_NOT_TUNED) ? 0 : 0xffff; |
99218fe4 MCC |
107 | } |
108 | ||
3088fba8 | 109 | static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol) |
99218fe4 | 110 | { |
3088fba8 | 111 | struct aztech *az = container_of(isa, struct aztech, isa); |
99218fe4 | 112 | |
3088fba8 HV |
113 | if (mute) |
114 | vol = 0; | |
115 | az->curvol = (vol & 1) + ((vol & 2) << 1); | |
116 | outb(az->curvol, isa->io); | |
99218fe4 MCC |
117 | return 0; |
118 | } | |
119 | ||
3088fba8 HV |
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, | |
3088fba8 | 124 | .g_rxsubchans = aztech_g_rxsubchans, |
1c9f11ed | 125 | .g_signal = aztech_g_signal, |
1da177e4 LT |
126 | }; |
127 | ||
3088fba8 HV |
128 | static const int aztech_ioports[] = { 0x350, 0x358 }; |
129 | ||
130 | static struct radio_isa_driver aztech_driver = { | |
131 | .driver = { | |
132 | .match = radio_isa_match, | |
133 | .probe = radio_isa_probe, | |
134 | .remove = radio_isa_remove, | |
135 | .driver = { | |
136 | .name = "radio-aztech", | |
137 | }, | |
138 | }, | |
139 | .io_params = io, | |
140 | .radio_nr_params = radio_nr, | |
141 | .io_ports = aztech_ioports, | |
142 | .num_of_io_ports = ARRAY_SIZE(aztech_ioports), | |
eb27fafe | 143 | .region_size = 8, |
3088fba8 HV |
144 | .card = "Aztech Radio", |
145 | .ops = &aztech_ops, | |
146 | .has_stereo = true, | |
147 | .max_volume = 3, | |
1da177e4 LT |
148 | }; |
149 | ||
150 | static int __init aztech_init(void) | |
151 | { | |
3088fba8 | 152 | return isa_register_driver(&aztech_driver.driver, AZTECH_MAX); |
1da177e4 LT |
153 | } |
154 | ||
e697e12e | 155 | static void __exit aztech_exit(void) |
1da177e4 | 156 | { |
3088fba8 | 157 | isa_unregister_driver(&aztech_driver.driver); |
1da177e4 LT |
158 | } |
159 | ||
160 | module_init(aztech_init); | |
e697e12e | 161 | module_exit(aztech_exit); |