Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 1 | /* |
| 2 | * RadioTrack II driver |
| 3 | * Copyright 1998 Ben Pfaff |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood |
Alan Cox | d9b0144 | 2008-10-27 15:13:47 -0300 | [diff] [blame] | 6 | * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org> |
| 8 | * |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 9 | * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com> |
Mauro Carvalho Chehab | f8c559f | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 10 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> /* Modules */ |
| 14 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 15 | #include <linux/ioport.h> /* request_region */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/delay.h> /* udelay */ |
Mauro Carvalho Chehab | f8c559f | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 17 | #include <linux/videodev2.h> /* kernel radio structs */ |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 18 | #include <linux/mutex.h> |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 19 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 20 | #include <media/v4l2-device.h> |
| 21 | #include <media/v4l2-ioctl.h> |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 22 | #include "radio-isa.h" |
Mauro Carvalho Chehab | f8c559f | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 23 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 24 | MODULE_AUTHOR("Ben Pfaff"); |
| 25 | MODULE_DESCRIPTION("A driver for the RadioTrack II radio card."); |
| 26 | MODULE_LICENSE("GPL"); |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 27 | MODULE_VERSION("0.1.99"); |
Mauro Carvalho Chehab | f8c559f | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #ifndef CONFIG_RADIO_RTRACK2_PORT |
| 30 | #define CONFIG_RADIO_RTRACK2_PORT -1 |
| 31 | #endif |
| 32 | |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 33 | #define RTRACK2_MAX 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 35 | static int io[RTRACK2_MAX] = { [0] = CONFIG_RADIO_RTRACK2_PORT, |
| 36 | [1 ... (RTRACK2_MAX - 1)] = -1 }; |
| 37 | static int radio_nr[RTRACK2_MAX] = { [0 ... (RTRACK2_MAX - 1)] = -1 }; |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 38 | |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 39 | module_param_array(io, int, NULL, 0444); |
| 40 | MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)"); |
| 41 | module_param_array(radio_nr, int, NULL, 0444); |
| 42 | MODULE_PARM_DESC(radio_nr, "Radio device numbers"); |
| 43 | |
| 44 | static struct radio_isa_card *rtrack2_alloc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 46 | return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 49 | static void zero(struct radio_isa_card *isa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 51 | outb_p(1, isa->io); |
| 52 | outb_p(3, isa->io); |
| 53 | outb_p(1, isa->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 56 | static void one(struct radio_isa_card *isa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 58 | outb_p(5, isa->io); |
| 59 | outb_p(7, isa->io); |
| 60 | outb_p(5, isa->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 63 | static int rtrack2_s_frequency(struct radio_isa_card *isa, u32 freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
| 65 | int i; |
| 66 | |
| 67 | freq = freq / 200 + 856; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 68 | |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 69 | outb_p(0xc8, isa->io); |
| 70 | outb_p(0xc9, isa->io); |
| 71 | outb_p(0xc9, isa->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | for (i = 0; i < 10; i++) |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 74 | zero(isa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | for (i = 14; i >= 0; i--) |
| 77 | if (freq & (1 << i)) |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 78 | one(isa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | else |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 80 | zero(isa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 82 | outb_p(0xc8, isa->io); |
| 83 | if (!v4l2_ctrl_g_ctrl(isa->mute)) |
| 84 | outb_p(0, isa->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 88 | static u32 rtrack2_g_signal(struct radio_isa_card *isa) |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 89 | { |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 90 | /* bit set = no signal present */ |
| 91 | return (inb(isa->io) & 2) ? 0 : 0xffff; |
| 92 | } |
| 93 | |
| 94 | static int rtrack2_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol) |
| 95 | { |
| 96 | outb(mute, isa->io); |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 97 | return 0; |
| 98 | } |
| 99 | |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 100 | static const struct radio_isa_ops rtrack2_ops = { |
| 101 | .alloc = rtrack2_alloc, |
| 102 | .s_mute_volume = rtrack2_s_mute_volume, |
| 103 | .s_frequency = rtrack2_s_frequency, |
| 104 | .g_signal = rtrack2_g_signal, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 107 | static const int rtrack2_ioports[] = { 0x20f, 0x30f }; |
| 108 | |
| 109 | static struct radio_isa_driver rtrack2_driver = { |
| 110 | .driver = { |
| 111 | .match = radio_isa_match, |
| 112 | .probe = radio_isa_probe, |
| 113 | .remove = radio_isa_remove, |
| 114 | .driver = { |
| 115 | .name = "radio-rtrack2", |
| 116 | }, |
| 117 | }, |
| 118 | .io_params = io, |
| 119 | .radio_nr_params = radio_nr, |
| 120 | .io_ports = rtrack2_ioports, |
| 121 | .num_of_io_ports = ARRAY_SIZE(rtrack2_ioports), |
| 122 | .region_size = 4, |
| 123 | .card = "AIMSlab RadioTrack II", |
| 124 | .ops = &rtrack2_ops, |
| 125 | .has_stereo = true, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | static int __init rtrack2_init(void) |
| 129 | { |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 130 | return isa_register_driver(&rtrack2_driver.driver, RTRACK2_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 133 | static void __exit rtrack2_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Hans Verkuil | 8bd7ef5 | 2012-01-16 05:24:08 -0300 | [diff] [blame] | 135 | isa_unregister_driver(&rtrack2_driver.driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | module_init(rtrack2_init); |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 139 | module_exit(rtrack2_exit); |