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