Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* Terratec ActiveRadio ISA Standalone card driver for Linux radio support |
| 2 | * (c) 1999 R. Offermanns (rolf@offermanns.de) |
| 3 | * based on the aimslab radio driver from M. Kirkwood |
| 4 | * many thanks to Michael Becker and Friedhelm Birth (from TerraTec) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 5 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * History: |
| 8 | * 1999-05-21 First preview release |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * Notes on the hardware: |
| 11 | * There are two "main" chips on the card: |
| 12 | * - Philips OM5610 (http://www-us.semiconductors.philips.com/acrobat/datasheets/OM5610_2.pdf) |
| 13 | * - Philips SAA6588 (http://www-us.semiconductors.philips.com/acrobat/datasheets/SAA6588_1.pdf) |
| 14 | * (you can get the datasheet at the above links) |
| 15 | * |
| 16 | * Frequency control is done digitally -- ie out(port,encodefreq(95.8)); |
| 17 | * Volume Control is done digitally |
| 18 | * |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 19 | * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com> |
Mauro Carvalho Chehab | 55ac7b6 | 2006-08-08 09:10:03 -0300 | [diff] [blame] | 20 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> /* Modules */ |
| 24 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 25 | #include <linux/ioport.h> /* request_region */ |
Mauro Carvalho Chehab | 55ac7b6 | 2006-08-08 09:10:03 -0300 | [diff] [blame] | 26 | #include <linux/videodev2.h> /* kernel radio structs */ |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 27 | #include <linux/mutex.h> |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 28 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | 9f1dfcc | 2012-02-29 05:50:27 -0300 | [diff] [blame] | 29 | #include <linux/slab.h> |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 30 | #include <media/v4l2-device.h> |
| 31 | #include <media/v4l2-ioctl.h> |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 32 | #include "radio-isa.h" |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 33 | |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 34 | MODULE_AUTHOR("R. Offermans & others"); |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 35 | MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card."); |
| 36 | MODULE_LICENSE("GPL"); |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 37 | MODULE_VERSION("0.1.99"); |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 38 | |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 39 | /* Note: there seems to be only one possible port (0x590), but without |
| 40 | hardware this is hard to verify. For now, this is the only one we will |
| 41 | support. */ |
| 42 | static int io = 0x590; |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 43 | static int radio_nr = -1; |
| 44 | |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 45 | module_param(radio_nr, int, 0444); |
| 46 | MODULE_PARM_DESC(radio_nr, "Radio device number"); |
Mauro Carvalho Chehab | 55ac7b6 | 2006-08-08 09:10:03 -0300 | [diff] [blame] | 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define WRT_DIS 0x00 |
| 49 | #define CLK_OFF 0x00 |
| 50 | #define IIC_DATA 0x01 |
| 51 | #define IIC_CLK 0x02 |
| 52 | #define DATA 0x04 |
| 53 | #define CLK_ON 0x08 |
| 54 | #define WRT_EN 0x10 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 56 | static struct radio_isa_card *terratec_alloc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 58 | return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL); |
| 59 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 61 | static int terratec_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
| 63 | int i; |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 64 | |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 65 | if (mute) |
| 66 | vol = 0; |
| 67 | vol = vol + (vol * 32); /* change both channels */ |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 68 | for (i = 0; i < 8; i++) { |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 69 | if (vol & (0x80 >> i)) |
| 70 | outb(0x80, isa->io + 1); |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 71 | else |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 72 | outb(0x00, isa->io + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | |
| 78 | /* this is the worst part in this driver */ |
| 79 | /* many more or less strange things are going on here, but hey, it works :) */ |
| 80 | |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 81 | static int terratec_s_frequency(struct radio_isa_card *isa, u32 freq) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 82 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | int i; |
| 84 | int p; |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 85 | int temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | long rest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | unsigned char buffer[25]; /* we have to bit shift 25 registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 89 | freq = freq / 160; /* convert the freq. to a nice to handle value */ |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 90 | memset(buffer, 0, sizeof(buffer)); |
| 91 | |
| 92 | rest = freq * 10 + 10700; /* I once had understood what is going on here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* maybe some wise guy (friedhelm?) can comment this stuff */ |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 94 | i = 13; |
| 95 | p = 10; |
| 96 | temp = 102400; |
| 97 | while (rest != 0) { |
| 98 | if (rest % temp == rest) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | buffer[i] = 0; |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 100 | else { |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 101 | buffer[i] = 1; |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 102 | rest = rest - temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | i--; |
| 105 | p--; |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 106 | temp = temp / 2; |
Michael Krufky | b930e1d | 2007-08-27 18:16:54 -0300 | [diff] [blame] | 107 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 109 | for (i = 24; i > -1; i--) { /* bit shift the values to the radiocard */ |
| 110 | if (buffer[i] == 1) { |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 111 | outb(WRT_EN | DATA, isa->io); |
| 112 | outb(WRT_EN | DATA | CLK_ON, isa->io); |
| 113 | outb(WRT_EN | DATA, isa->io); |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 114 | } else { |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 115 | outb(WRT_EN | 0x00, isa->io); |
| 116 | outb(WRT_EN | 0x00 | CLK_ON, isa->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | } |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 119 | outb(0x00, isa->io); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 120 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 123 | static u32 terratec_g_signal(struct radio_isa_card *isa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 125 | /* bit set = no signal present */ |
| 126 | return (inb(isa->io) & 2) ? 0 : 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 129 | static const struct radio_isa_ops terratec_ops = { |
| 130 | .alloc = terratec_alloc, |
| 131 | .s_mute_volume = terratec_s_mute_volume, |
| 132 | .s_frequency = terratec_s_frequency, |
| 133 | .g_signal = terratec_g_signal, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 136 | static const int terratec_ioports[] = { 0x590 }; |
| 137 | |
| 138 | static struct radio_isa_driver terratec_driver = { |
| 139 | .driver = { |
| 140 | .match = radio_isa_match, |
| 141 | .probe = radio_isa_probe, |
| 142 | .remove = radio_isa_remove, |
| 143 | .driver = { |
| 144 | .name = "radio-terratec", |
| 145 | }, |
| 146 | }, |
| 147 | .io_params = &io, |
| 148 | .radio_nr_params = &radio_nr, |
| 149 | .io_ports = terratec_ioports, |
| 150 | .num_of_io_ports = ARRAY_SIZE(terratec_ioports), |
| 151 | .region_size = 2, |
| 152 | .card = "TerraTec ActiveRadio", |
| 153 | .ops = &terratec_ops, |
| 154 | .has_stereo = true, |
| 155 | .max_volume = 10, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | static int __init terratec_init(void) |
| 159 | { |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 160 | return isa_register_driver(&terratec_driver.driver, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 163 | static void __exit terratec_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
Hans Verkuil | 32c5183 | 2012-01-16 05:15:09 -0300 | [diff] [blame] | 165 | isa_unregister_driver(&terratec_driver.driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | module_init(terratec_init); |
Hans Verkuil | 5ac3d5b | 2009-03-06 13:53:58 -0300 | [diff] [blame] | 169 | module_exit(terratec_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |