Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 1 | /* |
| 2 | * radio-aztech.c - Aztech radio card driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 4 | * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@xs4all.nl> |
Mauro Carvalho Chehab | a4366af | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 5 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 6 | * Adapted to support the Video for Linux API by |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by: |
| 8 | * |
| 9 | * Quay Ly |
| 10 | * Donald Song |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 11 | * Jason Lewis (jlewis@twilight.vtc.vsc.edu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) |
| 13 | * William McGrath (wmcgrath@twilight.vtc.vsc.edu) |
| 14 | * |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 15 | * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> /* Modules */ |
| 19 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 20 | #include <linux/ioport.h> /* request_region */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/delay.h> /* udelay */ |
Mauro Carvalho Chehab | a4366af | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 22 | #include <linux/videodev2.h> /* kernel radio structs */ |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 23 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | 9f1dfcc | 2012-02-29 05:50:27 -0300 | [diff] [blame] | 24 | #include <linux/slab.h> |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 25 | #include <media/v4l2-device.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 26 | #include <media/v4l2-ioctl.h> |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 27 | #include <media/v4l2-ctrls.h> |
| 28 | #include "radio-isa.h" |
Ondrej Zary | eb27faf | 2013-07-19 13:46:17 -0300 | [diff] [blame] | 29 | #include "lm7000.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 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"); |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 34 | MODULE_VERSION("1.0.0"); |
Mauro Carvalho Chehab | a4366af | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #ifndef CONFIG_RADIO_AZTECH_PORT |
| 38 | #define CONFIG_RADIO_AZTECH_PORT -1 |
| 39 | #endif |
| 40 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 41 | #define AZTECH_MAX 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 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 }; |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 46 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 47 | module_param_array(io, int, NULL, 0444); |
| 48 | MODULE_PARM_DESC(io, "I/O addresses of the Aztech card (0x350 or 0x358)"); |
| 49 | module_param_array(radio_nr, int, NULL, 0444); |
| 50 | MODULE_PARM_DESC(radio_nr, "Radio device numbers"); |
| 51 | |
| 52 | struct aztech { |
| 53 | struct radio_isa_card isa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | int curvol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
Ondrej Zary | eb27faf | 2013-07-19 13:46:17 -0300 | [diff] [blame] | 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 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Ondrej Zary | eb27faf | 2013-07-19 13:46:17 -0300 | [diff] [blame] | 66 | static void aztech_set_pins(void *handle, u8 pins) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Ondrej Zary | eb27faf | 2013-07-19 13:46:17 -0300 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 82 | static struct radio_isa_card *aztech_alloc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 84 | struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL); |
| 85 | |
| 86 | return az ? &az->isa : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 89 | static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
Ondrej Zary | eb27faf | 2013-07-19 13:46:17 -0300 | [diff] [blame] | 91 | lm7000_set_freq(freq, isa, aztech_set_pins); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 96 | static u32 aztech_g_rxsubchans(struct radio_isa_card *isa) |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 97 | { |
Ondrej Zary | 1c9f11e | 2013-07-19 13:46:18 -0300 | [diff] [blame] | 98 | if (inb(isa->io) & AZTECH_BIT_MONO) |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 99 | return V4L2_TUNER_SUB_MONO; |
| 100 | return V4L2_TUNER_SUB_STEREO; |
| 101 | } |
| 102 | |
Ondrej Zary | 1c9f11e | 2013-07-19 13:46:18 -0300 | [diff] [blame] | 103 | static u32 aztech_g_signal(struct radio_isa_card *isa) |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 104 | { |
Ondrej Zary | 1c9f11e | 2013-07-19 13:46:18 -0300 | [diff] [blame] | 105 | return (inb(isa->io) & AZTECH_BIT_NOT_TUNED) ? 0 : 0xffff; |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static 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 Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 116 | return 0; |
| 117 | } |
| 118 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 119 | static 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 Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 123 | .g_rxsubchans = aztech_g_rxsubchans, |
Ondrej Zary | 1c9f11e | 2013-07-19 13:46:18 -0300 | [diff] [blame] | 124 | .g_signal = aztech_g_signal, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 127 | static const int aztech_ioports[] = { 0x350, 0x358 }; |
| 128 | |
| 129 | static 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 Zary | eb27faf | 2013-07-19 13:46:17 -0300 | [diff] [blame] | 142 | .region_size = 8, |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 143 | .card = "Aztech Radio", |
| 144 | .ops = &aztech_ops, |
| 145 | .has_stereo = true, |
| 146 | .max_volume = 3, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | static int __init aztech_init(void) |
| 150 | { |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 151 | return isa_register_driver(&aztech_driver.driver, AZTECH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 154 | static void __exit aztech_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 156 | isa_unregister_driver(&aztech_driver.driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | module_init(aztech_init); |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 160 | module_exit(aztech_exit); |