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