Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v4.12 160 lines 4.3 kB view raw
1/* 2 * radio-aztech.c - Aztech radio card driver 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 7 * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by: 8 * 9 * Quay Ly 10 * Donald Song 11 * Jason Lewis (jlewis@twilight.vtc.vsc.edu) 12 * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) 13 * William McGrath (wmcgrath@twilight.vtc.vsc.edu) 14 * 15 * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool. 16*/ 17 18#include <linux/module.h> /* Modules */ 19#include <linux/init.h> /* Initdata */ 20#include <linux/ioport.h> /* request_region */ 21#include <linux/delay.h> /* udelay */ 22#include <linux/videodev2.h> /* kernel radio structs */ 23#include <linux/io.h> /* outb, outb_p */ 24#include <linux/slab.h> 25#include <media/v4l2-device.h> 26#include <media/v4l2-ioctl.h> 27#include <media/v4l2-ctrls.h> 28#include "radio-isa.h" 29#include "lm7000.h" 30 31MODULE_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"); 34MODULE_VERSION("1.0.0"); 35 36/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ 37#ifndef CONFIG_RADIO_AZTECH_PORT 38#define CONFIG_RADIO_AZTECH_PORT -1 39#endif 40 41#define AZTECH_MAX 2 42 43static 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 }; 46 47module_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; 54 int curvol; 55}; 56 57/* 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 */ 65 66static void aztech_set_pins(void *handle, u8 pins) 67{ 68 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); 80} 81 82static struct radio_isa_card *aztech_alloc(void) 83{ 84 struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL); 85 86 return az ? &az->isa : NULL; 87} 88 89static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq) 90{ 91 lm7000_set_freq(freq, isa, aztech_set_pins); 92 93 return 0; 94} 95 96static u32 aztech_g_rxsubchans(struct radio_isa_card *isa) 97{ 98 if (inb(isa->io) & AZTECH_BIT_MONO) 99 return V4L2_TUNER_SUB_MONO; 100 return V4L2_TUNER_SUB_STEREO; 101} 102 103static u32 aztech_g_signal(struct radio_isa_card *isa) 104{ 105 return (inb(isa->io) & AZTECH_BIT_NOT_TUNED) ? 0 : 0xffff; 106} 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); 116 return 0; 117} 118 119static 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, 123 .g_rxsubchans = aztech_g_rxsubchans, 124 .g_signal = aztech_g_signal, 125}; 126 127static 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), 142 .region_size = 8, 143 .card = "Aztech Radio", 144 .ops = &aztech_ops, 145 .has_stereo = true, 146 .max_volume = 3, 147}; 148 149static int __init aztech_init(void) 150{ 151 return isa_register_driver(&aztech_driver.driver, AZTECH_MAX); 152} 153 154static void __exit aztech_exit(void) 155{ 156 isa_unregister_driver(&aztech_driver.driver); 157} 158 159module_init(aztech_init); 160module_exit(aztech_exit);