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" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 30 | MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath"); |
| 31 | MODULE_DESCRIPTION("A driver for the Aztech radio card."); |
| 32 | MODULE_LICENSE("GPL"); |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 33 | MODULE_VERSION("1.0.0"); |
Mauro Carvalho Chehab | a4366af | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #ifndef CONFIG_RADIO_AZTECH_PORT |
| 37 | #define CONFIG_RADIO_AZTECH_PORT -1 |
| 38 | #endif |
| 39 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 40 | #define AZTECH_MAX 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 42 | static int io[AZTECH_MAX] = { [0] = CONFIG_RADIO_AZTECH_PORT, |
| 43 | [1 ... (AZTECH_MAX - 1)] = -1 }; |
| 44 | static int radio_nr[AZTECH_MAX] = { [0 ... (AZTECH_MAX - 1)] = -1 }; |
| 45 | static const int radio_wait_time = 1000; |
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 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 57 | static void send_0_byte(struct aztech *az) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
| 59 | udelay(radio_wait_time); |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 60 | outb_p(2 + az->curvol, az->isa.io); |
| 61 | outb_p(64 + 2 + az->curvol, az->isa.io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 64 | static void send_1_byte(struct aztech *az) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 66 | udelay(radio_wait_time); |
| 67 | outb_p(128 + 2 + az->curvol, az->isa.io); |
| 68 | outb_p(128 + 64 + 2 + az->curvol, az->isa.io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 71 | static struct radio_isa_card *aztech_alloc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 73 | struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL); |
| 74 | |
| 75 | return az ? &az->isa : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 78 | static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 80 | struct aztech *az = container_of(isa, struct aztech, isa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | int i; |
| 82 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 83 | freq += 171200; /* Add 10.7 MHz IF */ |
| 84 | freq /= 800; /* Convert to 50 kHz units */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 85 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 86 | send_0_byte(az); /* 0: LSB of frequency */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | for (i = 0; i < 13; i++) /* : frequency bits (1-13) */ |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 89 | if (freq & (1 << i)) |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 90 | send_1_byte(az); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | else |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 92 | send_0_byte(az); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 94 | send_0_byte(az); /* 14: test bit - always 0 */ |
| 95 | send_0_byte(az); /* 15: test bit - always 0 */ |
| 96 | send_0_byte(az); /* 16: band data 0 - always 0 */ |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 97 | if (isa->stereo) /* 17: stereo (1 to enable) */ |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 98 | send_1_byte(az); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | else |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 100 | send_0_byte(az); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 102 | send_1_byte(az); /* 18: band data 1 - unknown */ |
| 103 | send_0_byte(az); /* 19: time base - always 0 */ |
| 104 | send_0_byte(az); /* 20: spacing (0 = 25 kHz) */ |
| 105 | send_1_byte(az); /* 21: spacing (1 = 25 kHz) */ |
| 106 | send_0_byte(az); /* 22: spacing (0 = 25 kHz) */ |
| 107 | send_1_byte(az); /* 23: AM/FM (FM = 1, always) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | /* latch frequency */ |
| 110 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 111 | udelay(radio_wait_time); |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 112 | outb_p(128 + 64 + az->curvol, az->isa.io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 117 | /* thanks to Michael Dwyer for giving me a dose of clues in |
| 118 | * the signal strength department.. |
| 119 | * |
| 120 | * This card has a stereo bit - bit 0 set = mono, not set = stereo |
| 121 | */ |
| 122 | static u32 aztech_g_rxsubchans(struct radio_isa_card *isa) |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 123 | { |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 124 | if (inb(isa->io) & 1) |
| 125 | return V4L2_TUNER_SUB_MONO; |
| 126 | return V4L2_TUNER_SUB_STEREO; |
| 127 | } |
| 128 | |
| 129 | static int aztech_s_stereo(struct radio_isa_card *isa, bool stereo) |
| 130 | { |
| 131 | return aztech_s_frequency(isa, isa->freq); |
| 132 | } |
| 133 | |
| 134 | static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol) |
| 135 | { |
| 136 | struct aztech *az = container_of(isa, struct aztech, isa); |
| 137 | |
| 138 | if (mute) |
| 139 | vol = 0; |
| 140 | az->curvol = (vol & 1) + ((vol & 2) << 1); |
| 141 | outb(az->curvol, isa->io); |
Mauro Carvalho Chehab | 99218fe | 2007-01-25 08:09:32 -0300 | [diff] [blame] | 142 | return 0; |
| 143 | } |
| 144 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 145 | static const struct radio_isa_ops aztech_ops = { |
| 146 | .alloc = aztech_alloc, |
| 147 | .s_mute_volume = aztech_s_mute_volume, |
| 148 | .s_frequency = aztech_s_frequency, |
| 149 | .s_stereo = aztech_s_stereo, |
| 150 | .g_rxsubchans = aztech_g_rxsubchans, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 153 | static const int aztech_ioports[] = { 0x350, 0x358 }; |
| 154 | |
| 155 | static struct radio_isa_driver aztech_driver = { |
| 156 | .driver = { |
| 157 | .match = radio_isa_match, |
| 158 | .probe = radio_isa_probe, |
| 159 | .remove = radio_isa_remove, |
| 160 | .driver = { |
| 161 | .name = "radio-aztech", |
| 162 | }, |
| 163 | }, |
| 164 | .io_params = io, |
| 165 | .radio_nr_params = radio_nr, |
| 166 | .io_ports = aztech_ioports, |
| 167 | .num_of_io_ports = ARRAY_SIZE(aztech_ioports), |
| 168 | .region_size = 2, |
| 169 | .card = "Aztech Radio", |
| 170 | .ops = &aztech_ops, |
| 171 | .has_stereo = true, |
| 172 | .max_volume = 3, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | static int __init aztech_init(void) |
| 176 | { |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 177 | return isa_register_driver(&aztech_driver.driver, AZTECH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 180 | static void __exit aztech_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
Hans Verkuil | 3088fba | 2012-01-16 04:58:15 -0300 | [diff] [blame] | 182 | isa_unregister_driver(&aztech_driver.driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | module_init(aztech_init); |
Hans Verkuil | e697e12 | 2009-03-06 13:48:18 -0300 | [diff] [blame] | 186 | module_exit(aztech_exit); |