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