Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | *************************************************************************** |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * radio-gemtek-pci.c - Gemtek PCI Radio driver |
| 5 | * (C) 2001 Vladimir Shebordaev <vshebordaev@mail.ru> |
| 6 | * |
| 7 | *************************************************************************** |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public |
| 20 | * License along with this program; if not, write to the Free |
| 21 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, |
| 22 | * USA. |
| 23 | * |
| 24 | *************************************************************************** |
| 25 | * |
| 26 | * Gemtek Corp still silently refuses to release any specifications |
| 27 | * of their multimedia devices, so the protocol still has to be |
| 28 | * reverse engineered. |
| 29 | * |
| 30 | * The v4l code was inspired by Jonas Munsin's Gemtek serial line |
| 31 | * radio device driver. |
| 32 | * |
| 33 | * Please, let me know if this piece of code was useful :) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 34 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | * TODO: multiple device support and portability were not tested |
| 36 | * |
Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 37 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
| 38 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | *************************************************************************** |
| 40 | */ |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/types.h> |
| 43 | #include <linux/list.h> |
| 44 | #include <linux/module.h> |
| 45 | #include <linux/init.h> |
| 46 | #include <linux/pci.h> |
Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 47 | #include <linux/videodev2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/errno.h> |
Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 49 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 50 | #include <linux/io.h> |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 51 | #include <media/v4l2-device.h> |
| 52 | #include <media/v4l2-ioctl.h> |
Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 53 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 54 | MODULE_AUTHOR("Vladimir Shebordaev <vshebordaev@mail.ru>"); |
| 55 | MODULE_DESCRIPTION("The video4linux driver for the Gemtek PCI Radio Card"); |
| 56 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 52afbc2 | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 57 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 58 | static int nr_radio = -1; |
| 59 | static int mx = 1; |
| 60 | |
| 61 | module_param(mx, bool, 0); |
| 62 | MODULE_PARM_DESC(mx, "single digit: 1 - turn off the turner upon module exit (default), 0 - do not"); |
| 63 | module_param(nr_radio, int, 0); |
| 64 | MODULE_PARM_DESC(nr_radio, "video4linux device number to use"); |
| 65 | |
| 66 | #define RADIO_VERSION KERNEL_VERSION(0, 0, 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #ifndef PCI_VENDOR_ID_GEMTEK |
| 69 | #define PCI_VENDOR_ID_GEMTEK 0x5046 |
| 70 | #endif |
| 71 | |
| 72 | #ifndef PCI_DEVICE_ID_GEMTEK_PR103 |
| 73 | #define PCI_DEVICE_ID_GEMTEK_PR103 0x1001 |
| 74 | #endif |
| 75 | |
| 76 | #ifndef GEMTEK_PCI_RANGE_LOW |
| 77 | #define GEMTEK_PCI_RANGE_LOW (87*16000) |
| 78 | #endif |
| 79 | |
| 80 | #ifndef GEMTEK_PCI_RANGE_HIGH |
| 81 | #define GEMTEK_PCI_RANGE_HIGH (108*16000) |
| 82 | #endif |
| 83 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 84 | struct gemtek_pci { |
| 85 | struct v4l2_device v4l2_dev; |
| 86 | struct video_device vdev; |
| 87 | struct mutex lock; |
| 88 | struct pci_dev *pdev; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | u32 iobase; |
| 91 | u32 length; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | u32 current_frequency; |
| 94 | u8 mute; |
| 95 | }; |
| 96 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 97 | static inline struct gemtek_pci *to_gemtek_pci(struct v4l2_device *v4l2_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 99 | return container_of(v4l2_dev, struct gemtek_pci, v4l2_dev); |
| 100 | } |
| 101 | |
| 102 | static inline u8 gemtek_pci_out(u16 value, u32 port) |
| 103 | { |
| 104 | outw(value, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | return (u8)value; |
| 107 | } |
| 108 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 109 | #define _b0(v) (*((u8 *)&v)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 111 | static void __gemtek_pci_cmd(u16 value, u32 port, u8 *last_byte, int keep) |
| 112 | { |
| 113 | u8 byte = *last_byte; |
| 114 | |
| 115 | if (!value) { |
| 116 | if (!keep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | value = (u16)port; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 118 | byte &= 0xfd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } else |
| 120 | byte |= 2; |
| 121 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 122 | _b0(value) = byte; |
| 123 | outw(value, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | byte |= 1; |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 125 | _b0(value) = byte; |
| 126 | outw(value, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | byte &= 0xfe; |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 128 | _b0(value) = byte; |
| 129 | outw(value, port); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | *last_byte = byte; |
| 132 | } |
| 133 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 134 | static inline void gemtek_pci_nil(u32 port, u8 *last_byte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 136 | __gemtek_pci_cmd(0x00, port, last_byte, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 139 | static inline void gemtek_pci_cmd(u16 cmd, u32 port, u8 *last_byte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 141 | __gemtek_pci_cmd(cmd, port, last_byte, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 144 | static void gemtek_pci_setfrequency(struct gemtek_pci *card, unsigned long frequency) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 146 | int i; |
| 147 | u32 value = frequency / 200 + 856; |
| 148 | u16 mask = 0x8000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | u8 last_byte; |
| 150 | u32 port = card->iobase; |
| 151 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 152 | mutex_lock(&card->lock); |
| 153 | card->current_frequency = frequency; |
| 154 | last_byte = gemtek_pci_out(0x06, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | i = 0; |
| 157 | do { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 158 | gemtek_pci_nil(port, &last_byte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | i++; |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 160 | } while (i < 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | i = 0; |
| 163 | do { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 164 | gemtek_pci_cmd(value & mask, port, &last_byte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | mask >>= 1; |
| 166 | i++; |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 167 | } while (i < 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 169 | outw(0x10, port); |
| 170 | mutex_unlock(&card->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 174 | static void gemtek_pci_mute(struct gemtek_pci *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 176 | mutex_lock(&card->lock); |
| 177 | outb(0x1f, card->iobase); |
Richard Knutsson | fd4bc44 | 2007-02-06 21:55:07 -0300 | [diff] [blame] | 178 | card->mute = true; |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 179 | mutex_unlock(&card->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 182 | static void gemtek_pci_unmute(struct gemtek_pci *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 184 | mutex_lock(&card->lock); |
| 185 | if (card->mute) { |
| 186 | gemtek_pci_setfrequency(card, card->current_frequency); |
Richard Knutsson | fd4bc44 | 2007-02-06 21:55:07 -0300 | [diff] [blame] | 187 | card->mute = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 189 | mutex_unlock(&card->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 192 | static int gemtek_pci_getsignal(struct gemtek_pci *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 194 | int sig; |
| 195 | |
| 196 | mutex_lock(&card->lock); |
| 197 | sig = (inb(card->iobase) & 0x08) ? 0 : 1; |
| 198 | mutex_unlock(&card->lock); |
| 199 | return sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 202 | static int vidioc_querycap(struct file *file, void *priv, |
| 203 | struct v4l2_capability *v) |
| 204 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 205 | struct gemtek_pci *card = video_drvdata(file); |
| 206 | |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 207 | strlcpy(v->driver, "radio-gemtek-pci", sizeof(v->driver)); |
| 208 | strlcpy(v->card, "GemTek PCI Radio", sizeof(v->card)); |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 209 | snprintf(v->bus_info, sizeof(v->bus_info), "PCI:%s", pci_name(card->pdev)); |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 210 | v->version = RADIO_VERSION; |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 211 | v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 216 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 218 | struct gemtek_pci *card = video_drvdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 220 | if (v->index > 0) |
| 221 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 223 | strlcpy(v->name, "FM", sizeof(v->name)); |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 224 | v->type = V4L2_TUNER_RADIO; |
| 225 | v->rangelow = GEMTEK_PCI_RANGE_LOW; |
| 226 | v->rangehigh = GEMTEK_PCI_RANGE_HIGH; |
| 227 | v->rxsubchans = V4L2_TUNER_SUB_MONO; |
| 228 | v->capability = V4L2_TUNER_CAP_LOW; |
| 229 | v->audmode = V4L2_TUNER_MODE_MONO; |
| 230 | v->signal = 0xffff * gemtek_pci_getsignal(card); |
| 231 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 234 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 235 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 237 | return v->index ? -EINVAL : 0; |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 241 | struct v4l2_frequency *f) |
| 242 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 243 | struct gemtek_pci *card = video_drvdata(file); |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 244 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 245 | if (f->frequency < GEMTEK_PCI_RANGE_LOW || |
| 246 | f->frequency > GEMTEK_PCI_RANGE_HIGH) |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 247 | return -EINVAL; |
| 248 | gemtek_pci_setfrequency(card, f->frequency); |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 249 | card->mute = false; |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 254 | struct v4l2_frequency *f) |
| 255 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 256 | struct gemtek_pci *card = video_drvdata(file); |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 257 | |
| 258 | f->type = V4L2_TUNER_RADIO; |
| 259 | f->frequency = card->current_frequency; |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 264 | struct v4l2_queryctrl *qc) |
| 265 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 266 | switch (qc->id) { |
| 267 | case V4L2_CID_AUDIO_MUTE: |
| 268 | return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1); |
| 269 | case V4L2_CID_AUDIO_VOLUME: |
| 270 | return v4l2_ctrl_query_fill(qc, 0, 65535, 65535, 65535); |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 271 | } |
| 272 | return -EINVAL; |
| 273 | } |
| 274 | |
| 275 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 276 | struct v4l2_control *ctrl) |
| 277 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 278 | struct gemtek_pci *card = video_drvdata(file); |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 279 | |
| 280 | switch (ctrl->id) { |
| 281 | case V4L2_CID_AUDIO_MUTE: |
| 282 | ctrl->value = card->mute; |
| 283 | return 0; |
| 284 | case V4L2_CID_AUDIO_VOLUME: |
| 285 | if (card->mute) |
| 286 | ctrl->value = 0; |
| 287 | else |
| 288 | ctrl->value = 65535; |
| 289 | return 0; |
| 290 | } |
| 291 | return -EINVAL; |
| 292 | } |
| 293 | |
| 294 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 295 | struct v4l2_control *ctrl) |
| 296 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 297 | struct gemtek_pci *card = video_drvdata(file); |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 298 | |
| 299 | switch (ctrl->id) { |
| 300 | case V4L2_CID_AUDIO_MUTE: |
| 301 | if (ctrl->value) |
| 302 | gemtek_pci_mute(card); |
| 303 | else |
| 304 | gemtek_pci_unmute(card); |
| 305 | return 0; |
| 306 | case V4L2_CID_AUDIO_VOLUME: |
| 307 | if (ctrl->value) |
| 308 | gemtek_pci_unmute(card); |
| 309 | else |
| 310 | gemtek_pci_mute(card); |
| 311 | return 0; |
| 312 | } |
| 313 | return -EINVAL; |
| 314 | } |
| 315 | |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 316 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 317 | { |
| 318 | *i = 0; |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 323 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 324 | return i ? -EINVAL : 0; |
| 325 | } |
| 326 | |
| 327 | static int vidioc_g_audio(struct file *file, void *priv, |
| 328 | struct v4l2_audio *a) |
| 329 | { |
| 330 | a->index = 0; |
| 331 | strlcpy(a->name, "Radio", sizeof(a->name)); |
| 332 | a->capability = V4L2_AUDCAP_STEREO; |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | static int vidioc_s_audio(struct file *file, void *priv, |
| 337 | struct v4l2_audio *a) |
| 338 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 339 | return a->index ? -EINVAL : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | enum { |
| 343 | GEMTEK_PR103 |
| 344 | }; |
| 345 | |
| 346 | static char *card_names[] __devinitdata = { |
| 347 | "GEMTEK_PR103" |
| 348 | }; |
| 349 | |
| 350 | static struct pci_device_id gemtek_pci_id[] = |
| 351 | { |
| 352 | { PCI_VENDOR_ID_GEMTEK, PCI_DEVICE_ID_GEMTEK_PR103, |
| 353 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, GEMTEK_PR103 }, |
| 354 | { 0 } |
| 355 | }; |
| 356 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 357 | MODULE_DEVICE_TABLE(pci, gemtek_pci_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 359 | static const struct v4l2_file_operations gemtek_pci_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | .owner = THIS_MODULE, |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 361 | .ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | }; |
| 363 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 364 | static const struct v4l2_ioctl_ops gemtek_pci_ioctl_ops = { |
Douglas Landgraf | 6f66446 | 2007-04-26 10:42:12 -0300 | [diff] [blame] | 365 | .vidioc_querycap = vidioc_querycap, |
| 366 | .vidioc_g_tuner = vidioc_g_tuner, |
| 367 | .vidioc_s_tuner = vidioc_s_tuner, |
| 368 | .vidioc_g_audio = vidioc_g_audio, |
| 369 | .vidioc_s_audio = vidioc_s_audio, |
| 370 | .vidioc_g_input = vidioc_g_input, |
| 371 | .vidioc_s_input = vidioc_s_input, |
| 372 | .vidioc_g_frequency = vidioc_g_frequency, |
| 373 | .vidioc_s_frequency = vidioc_s_frequency, |
| 374 | .vidioc_queryctrl = vidioc_queryctrl, |
| 375 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 376 | .vidioc_s_ctrl = vidioc_s_ctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | }; |
| 378 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 379 | static int __devinit gemtek_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 381 | struct gemtek_pci *card; |
| 382 | struct v4l2_device *v4l2_dev; |
| 383 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 385 | card = kzalloc(sizeof(struct gemtek_pci), GFP_KERNEL); |
| 386 | if (card == NULL) { |
| 387 | dev_err(&pdev->dev, "out of memory\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | return -ENOMEM; |
| 389 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 391 | v4l2_dev = &card->v4l2_dev; |
| 392 | mutex_init(&card->lock); |
| 393 | card->pdev = pdev; |
| 394 | |
| 395 | strlcpy(v4l2_dev->name, "gemtek_pci", sizeof(v4l2_dev->name)); |
| 396 | |
| 397 | res = v4l2_device_register(&pdev->dev, v4l2_dev); |
| 398 | if (res < 0) { |
| 399 | v4l2_err(v4l2_dev, "Could not register v4l2_device\n"); |
| 400 | kfree(card); |
| 401 | return res; |
| 402 | } |
| 403 | |
| 404 | if (pci_enable_device(pdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | goto err_pci; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 406 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 407 | card->iobase = pci_resource_start(pdev, 0); |
| 408 | card->length = pci_resource_len(pdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 410 | if (request_region(card->iobase, card->length, card_names[pci_id->driver_data]) == NULL) { |
| 411 | v4l2_err(v4l2_dev, "i/o port already in use\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | goto err_pci; |
| 413 | } |
| 414 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 415 | strlcpy(card->vdev.name, v4l2_dev->name, sizeof(card->vdev.name)); |
| 416 | card->vdev.v4l2_dev = v4l2_dev; |
| 417 | card->vdev.fops = &gemtek_pci_fops; |
| 418 | card->vdev.ioctl_ops = &gemtek_pci_ioctl_ops; |
| 419 | card->vdev.release = video_device_release_empty; |
| 420 | video_set_drvdata(&card->vdev, card); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 421 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 422 | if (video_register_device(&card->vdev, VFL_TYPE_RADIO, nr_radio) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | goto err_video; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 425 | gemtek_pci_mute(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 427 | v4l2_info(v4l2_dev, "Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n", |
| 428 | pdev->revision, card->iobase, card->iobase + card->length - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
| 430 | return 0; |
| 431 | |
| 432 | err_video: |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 433 | release_region(card->iobase, card->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | err_pci: |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 436 | v4l2_device_unregister(v4l2_dev); |
| 437 | kfree(card); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 438 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 441 | static void __devexit gemtek_pci_remove(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 443 | struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev); |
| 444 | struct gemtek_pci *card = to_gemtek_pci(v4l2_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 446 | video_unregister_device(&card->vdev); |
| 447 | v4l2_device_unregister(v4l2_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 449 | release_region(card->iobase, card->length); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 450 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 451 | if (mx) |
| 452 | gemtek_pci_mute(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 454 | kfree(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 457 | static struct pci_driver gemtek_pci_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | .name = "gemtek_pci", |
| 459 | .id_table = gemtek_pci_id, |
| 460 | .probe = gemtek_pci_probe, |
| 461 | .remove = __devexit_p(gemtek_pci_remove), |
| 462 | }; |
| 463 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 464 | static int __init gemtek_pci_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | { |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 466 | return pci_register_driver(&gemtek_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 469 | static void __exit gemtek_pci_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | { |
Tobias Klauser | 1396275 | 2006-10-04 08:09:10 -0300 | [diff] [blame] | 471 | pci_unregister_driver(&gemtek_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Hans Verkuil | 79f9487 | 2009-03-06 13:50:07 -0300 | [diff] [blame] | 474 | module_init(gemtek_pci_init); |
| 475 | module_exit(gemtek_pci_exit); |