Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* Maestro PCI sound card radio driver for Linux support |
| 2 | * (c) 2000 A. Tlalka, atlka@pg.gda.pl |
| 3 | * Notes on the hardware |
| 4 | * |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 5 | * + Frequency control is done digitally |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * + No volume control - only mute/unmute - you have to use Aux line volume |
| 7 | * control on Maestro card to set the volume |
| 8 | * + Radio status (tuned/not_tuned and stereo/mono) is valid some time after |
| 9 | * frequency setting (>100ms) and only when the radio is unmuted. |
| 10 | * version 0.02 |
| 11 | * + io port is automatically detected - only the first radio is used |
| 12 | * version 0.03 |
| 13 | * + thread access locking additions |
| 14 | * version 0.04 |
| 15 | * + code improvements |
| 16 | * + VIDEO_TUNER_LOW is permanent |
Mauro Carvalho Chehab | b6055d7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 17 | * |
| 18 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/ioport.h> |
| 24 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/io.h> |
| 26 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/pci.h> |
Mauro Carvalho Chehab | b6055d7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 28 | #include <linux/videodev2.h> |
Mauro Carvalho Chehab | 5e87efa | 2006-06-05 10:26:32 -0300 | [diff] [blame] | 29 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 30 | #include <media/v4l2-ioctl.h> |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 31 | |
Mauro Carvalho Chehab | b6055d7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 32 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ |
| 33 | #define RADIO_VERSION KERNEL_VERSION(0,0,6) |
| 34 | #define DRIVER_VERSION "0.06" |
| 35 | |
| 36 | static struct v4l2_queryctrl radio_qctrl[] = { |
| 37 | { |
| 38 | .id = V4L2_CID_AUDIO_MUTE, |
| 39 | .name = "Mute", |
| 40 | .minimum = 0, |
| 41 | .maximum = 1, |
| 42 | .default_value = 1, |
| 43 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 44 | } |
| 45 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 47 | #define GPIO_DATA 0x60 /* port offset from ESS_IO_BASE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define IO_MASK 4 /* mask register offset from GPIO_DATA |
| 50 | bits 1=unmask write to given bit */ |
| 51 | #define IO_DIR 8 /* direction register offset from GPIO_DATA |
| 52 | bits 0/1=read/write direction */ |
| 53 | |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 54 | #define GPIO6 0x0040 /* mask bits for GPIO lines */ |
| 55 | #define GPIO7 0x0080 |
| 56 | #define GPIO8 0x0100 |
| 57 | #define GPIO9 0x0200 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 59 | #define STR_DATA GPIO6 /* radio TEA5757 pins and GPIO bits */ |
| 60 | #define STR_CLK GPIO7 |
| 61 | #define STR_WREN GPIO8 |
| 62 | #define STR_MOST GPIO9 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | #define FREQ_LO 50*16000 |
| 65 | #define FREQ_HI 150*16000 |
| 66 | |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 67 | #define FREQ_IF 171200 /* 10.7*16000 */ |
| 68 | #define FREQ_STEP 200 /* 12.5*16 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | #define FREQ2BITS(x) ((((unsigned int)(x)+FREQ_IF+(FREQ_STEP<<1))\ |
| 71 | /(FREQ_STEP<<2))<<2) /* (x==fmhz*16*1000) -> bits */ |
| 72 | |
| 73 | #define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF) |
| 74 | |
| 75 | static int radio_nr = -1; |
| 76 | module_param(radio_nr, int, 0); |
| 77 | |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 78 | static int maestro_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
| 79 | static void maestro_remove(struct pci_dev *pdev); |
| 80 | |
| 81 | static struct pci_device_id maestro_r_pci_tbl[] = { |
| 82 | { PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1968), |
| 83 | .class = PCI_CLASS_MULTIMEDIA_AUDIO << 8, |
| 84 | .class_mask = 0xffff00 }, |
| 85 | { PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1978), |
| 86 | .class = PCI_CLASS_MULTIMEDIA_AUDIO << 8, |
| 87 | .class_mask = 0xffff00 }, |
| 88 | { 0 } |
| 89 | }; |
| 90 | MODULE_DEVICE_TABLE(pci, maestro_r_pci_tbl); |
| 91 | |
| 92 | static struct pci_driver maestro_r_driver = { |
| 93 | .name = "maestro_radio", |
| 94 | .id_table = maestro_r_pci_tbl, |
| 95 | .probe = maestro_probe, |
| 96 | .remove = __devexit_p(maestro_remove), |
| 97 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 99 | static const struct file_operations maestro_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | .owner = THIS_MODULE, |
| 101 | .open = video_exclusive_open, |
| 102 | .release = video_exclusive_release, |
Douglas Landgraf | d455cf5 | 2007-04-26 16:44:55 -0300 | [diff] [blame] | 103 | .ioctl = video_ioctl2, |
Douglas Schilling Landgraf | 078ff79 | 2008-04-22 14:46:11 -0300 | [diff] [blame] | 104 | #ifdef CONFIG_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 105 | .compat_ioctl = v4l_compat_ioctl32, |
Douglas Schilling Landgraf | 078ff79 | 2008-04-22 14:46:11 -0300 | [diff] [blame] | 106 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | .llseek = no_llseek, |
| 108 | }; |
| 109 | |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 110 | struct radio_device { |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 111 | u16 io, /* base of Maestro card radio io (GPIO_DATA)*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | muted, /* VIDEO_AUDIO_MUTE */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 113 | stereo, /* VIDEO_TUNER_STEREO_ON */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | tuned; /* signal strength (0 or 0xffff) */ |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 115 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 117 | static u32 radio_bits_get(struct radio_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 119 | register u16 io=dev->io, l, rdata; |
| 120 | register u32 data=0; |
| 121 | u16 omask; |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | omask = inw(io + IO_MASK); |
| 124 | outw(~(STR_CLK | STR_WREN), io + IO_MASK); |
| 125 | outw(0, io); |
| 126 | udelay(16); |
| 127 | |
| 128 | for (l=24;l--;) { |
| 129 | outw(STR_CLK, io); /* HI state */ |
| 130 | udelay(2); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 131 | if(!l) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | dev->tuned = inw(io) & STR_MOST ? 0 : 0xffff; |
| 133 | outw(0, io); /* LO state */ |
| 134 | udelay(2); |
| 135 | data <<= 1; /* shift data */ |
| 136 | rdata = inw(io); |
| 137 | if(!l) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 138 | dev->stereo = rdata & STR_MOST ? |
Mauro Carvalho Chehab | b6055d7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 139 | 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | else |
| 141 | if(rdata & STR_DATA) |
| 142 | data++; |
| 143 | udelay(2); |
| 144 | } |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | if(dev->muted) |
| 147 | outw(STR_WREN, io); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | udelay(4); |
| 150 | outw(omask, io + IO_MASK); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | return data & 0x3ffe; |
| 153 | } |
| 154 | |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 155 | static void radio_bits_set(struct radio_device *dev, u32 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 157 | register u16 io=dev->io, l, bits; |
| 158 | u16 omask, odir; |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | omask = inw(io + IO_MASK); |
| 161 | odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN); |
| 162 | outw(odir | STR_DATA, io + IO_DIR); |
| 163 | outw(~(STR_DATA | STR_CLK | STR_WREN), io + IO_MASK); |
| 164 | udelay(16); |
| 165 | for (l=25;l;l--) { |
| 166 | bits = ((data >> 18) & STR_DATA) | STR_WREN ; |
| 167 | data <<= 1; /* shift data */ |
| 168 | outw(bits, io); /* start strobe */ |
| 169 | udelay(2); |
| 170 | outw(bits | STR_CLK, io); /* HI level */ |
| 171 | udelay(2); |
| 172 | outw(bits, io); /* LO level */ |
| 173 | udelay(4); |
| 174 | } |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | if(!dev->muted) |
| 177 | outw(0, io); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | udelay(4); |
| 180 | outw(omask, io + IO_MASK); |
| 181 | outw(odir, io + IO_DIR); |
| 182 | msleep(125); |
| 183 | } |
| 184 | |
Douglas Landgraf | d455cf5 | 2007-04-26 16:44:55 -0300 | [diff] [blame] | 185 | static int vidioc_querycap(struct file *file, void *priv, |
| 186 | struct v4l2_capability *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
Douglas Landgraf | d455cf5 | 2007-04-26 16:44:55 -0300 | [diff] [blame] | 188 | strlcpy(v->driver, "radio-maestro", sizeof(v->driver)); |
| 189 | strlcpy(v->card, "Maestro Radio", sizeof(v->card)); |
| 190 | sprintf(v->bus_info, "PCI"); |
| 191 | v->version = RADIO_VERSION; |
| 192 | v->capabilities = V4L2_CAP_TUNER; |
| 193 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Douglas Landgraf | d455cf5 | 2007-04-26 16:44:55 -0300 | [diff] [blame] | 196 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 197 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
| 199 | struct video_device *dev = video_devdata(file); |
Jiri Slaby | f86e776 | 2006-01-09 20:52:50 -0800 | [diff] [blame] | 200 | struct radio_device *card = video_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Douglas Landgraf | d455cf5 | 2007-04-26 16:44:55 -0300 | [diff] [blame] | 202 | if (v->index > 0) |
| 203 | return -EINVAL; |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 204 | |
Douglas Landgraf | d455cf5 | 2007-04-26 16:44:55 -0300 | [diff] [blame] | 205 | (void)radio_bits_get(card); |
| 206 | |
| 207 | strcpy(v->name, "FM"); |
| 208 | v->type = V4L2_TUNER_RADIO; |
| 209 | v->rangelow = FREQ_LO; |
| 210 | v->rangehigh = FREQ_HI; |
| 211 | v->rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO; |
| 212 | v->capability = V4L2_TUNER_CAP_LOW; |
| 213 | if(card->stereo) |
| 214 | v->audmode = V4L2_TUNER_MODE_STEREO; |
| 215 | else |
| 216 | v->audmode = V4L2_TUNER_MODE_MONO; |
| 217 | v->signal = card->tuned; |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 222 | struct v4l2_tuner *v) |
| 223 | { |
| 224 | if (v->index > 0) |
| 225 | return -EINVAL; |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 230 | struct v4l2_frequency *f) |
| 231 | { |
| 232 | struct video_device *dev = video_devdata(file); |
| 233 | struct radio_device *card = video_get_drvdata(dev); |
| 234 | |
| 235 | if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) |
| 236 | return -EINVAL; |
| 237 | radio_bits_set(card, FREQ2BITS(f->frequency)); |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 242 | struct v4l2_frequency *f) |
| 243 | { |
| 244 | struct video_device *dev = video_devdata(file); |
| 245 | struct radio_device *card = video_get_drvdata(dev); |
| 246 | |
| 247 | f->type = V4L2_TUNER_RADIO; |
| 248 | f->frequency = BITS2FREQ(radio_bits_get(card)); |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 253 | struct v4l2_queryctrl *qc) |
| 254 | { |
| 255 | int i; |
| 256 | |
| 257 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { |
| 258 | if (qc->id && qc->id == radio_qctrl[i].id) { |
| 259 | memcpy(qc, &(radio_qctrl[i]), |
| 260 | sizeof(*qc)); |
| 261 | return 0; |
| 262 | } |
| 263 | } |
| 264 | return -EINVAL; |
| 265 | } |
| 266 | |
| 267 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 268 | struct v4l2_control *ctrl) |
| 269 | { |
| 270 | struct video_device *dev = video_devdata(file); |
| 271 | struct radio_device *card = video_get_drvdata(dev); |
| 272 | |
| 273 | switch (ctrl->id) { |
| 274 | case V4L2_CID_AUDIO_MUTE: |
| 275 | ctrl->value = card->muted; |
| 276 | return 0; |
| 277 | } |
| 278 | return -EINVAL; |
| 279 | } |
| 280 | |
| 281 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 282 | struct v4l2_control *ctrl) |
| 283 | { |
| 284 | struct video_device *dev = video_devdata(file); |
| 285 | struct radio_device *card = video_get_drvdata(dev); |
| 286 | register u16 io = card->io; |
| 287 | register u16 omask = inw(io + IO_MASK); |
| 288 | |
| 289 | switch (ctrl->id) { |
| 290 | case V4L2_CID_AUDIO_MUTE: |
| 291 | outw(~STR_WREN, io + IO_MASK); |
| 292 | outw((card->muted = ctrl->value ) ? |
| 293 | STR_WREN : 0, io); |
| 294 | udelay(4); |
| 295 | outw(omask, io + IO_MASK); |
| 296 | msleep(125); |
| 297 | return 0; |
| 298 | } |
| 299 | return -EINVAL; |
| 300 | } |
| 301 | |
| 302 | static int vidioc_g_audio(struct file *file, void *priv, |
| 303 | struct v4l2_audio *a) |
| 304 | { |
| 305 | if (a->index > 1) |
| 306 | return -EINVAL; |
| 307 | |
| 308 | strcpy(a->name, "Radio"); |
| 309 | a->capability = V4L2_AUDCAP_STEREO; |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 314 | { |
| 315 | *i = 0; |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 320 | { |
| 321 | if (i != 0) |
| 322 | return -EINVAL; |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | static int vidioc_s_audio(struct file *file, void *priv, |
| 327 | struct v4l2_audio *a) |
| 328 | { |
| 329 | if (a->index != 0) |
| 330 | return -EINVAL; |
| 331 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 334 | static u16 __devinit radio_power_on(struct radio_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 336 | register u16 io = dev->io; |
| 337 | register u32 ofreq; |
| 338 | u16 omask, odir; |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | omask = inw(io + IO_MASK); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 341 | odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | outw(odir & ~STR_WREN, io + IO_DIR); |
Mauro Carvalho Chehab | b6055d7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 343 | dev->muted = inw(io) & STR_WREN ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | outw(odir, io + IO_DIR); |
| 345 | outw(~(STR_WREN | STR_CLK), io + IO_MASK); |
| 346 | outw(dev->muted ? 0 : STR_WREN, io); |
| 347 | udelay(16); |
| 348 | outw(omask, io + IO_MASK); |
| 349 | ofreq = radio_bits_get(dev); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 350 | |
| 351 | if ((ofreq < FREQ2BITS(FREQ_LO)) || (ofreq > FREQ2BITS(FREQ_HI))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | ofreq = FREQ2BITS(FREQ_LO); |
| 353 | radio_bits_set(dev, ofreq); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | return (ofreq == radio_bits_get(dev)); |
| 356 | } |
| 357 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 358 | static const struct v4l2_ioctl_ops maestro_ioctl_ops = { |
Douglas Landgraf | d455cf5 | 2007-04-26 16:44:55 -0300 | [diff] [blame] | 359 | .vidioc_querycap = vidioc_querycap, |
| 360 | .vidioc_g_tuner = vidioc_g_tuner, |
| 361 | .vidioc_s_tuner = vidioc_s_tuner, |
| 362 | .vidioc_g_audio = vidioc_g_audio, |
| 363 | .vidioc_s_audio = vidioc_s_audio, |
| 364 | .vidioc_g_input = vidioc_g_input, |
| 365 | .vidioc_s_input = vidioc_s_input, |
| 366 | .vidioc_g_frequency = vidioc_g_frequency, |
| 367 | .vidioc_s_frequency = vidioc_s_frequency, |
| 368 | .vidioc_queryctrl = vidioc_queryctrl, |
| 369 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 370 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 371 | }; |
| 372 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 373 | static struct video_device maestro_radio = { |
| 374 | .name = "Maestro radio", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 375 | .fops = &maestro_fops, |
| 376 | .ioctl_ops = &maestro_ioctl_ops, |
| 377 | }; |
| 378 | |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 379 | static int __devinit maestro_probe(struct pci_dev *pdev, |
| 380 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 382 | struct radio_device *radio_unit; |
| 383 | struct video_device *maestro_radio_inst; |
| 384 | int retval; |
| 385 | |
| 386 | retval = pci_enable_device(pdev); |
| 387 | if (retval) { |
| 388 | dev_err(&pdev->dev, "enabling pci device failed!\n"); |
| 389 | goto err; |
| 390 | } |
| 391 | |
| 392 | retval = -ENOMEM; |
| 393 | |
| 394 | radio_unit = kzalloc(sizeof(*radio_unit), GFP_KERNEL); |
| 395 | if (radio_unit == NULL) { |
| 396 | dev_err(&pdev->dev, "not enough memory\n"); |
| 397 | goto err; |
| 398 | } |
| 399 | |
| 400 | radio_unit->io = pci_resource_start(pdev, 0) + GPIO_DATA; |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 401 | |
| 402 | maestro_radio_inst = video_device_alloc(); |
| 403 | if (maestro_radio_inst == NULL) { |
| 404 | dev_err(&pdev->dev, "not enough memory\n"); |
| 405 | goto errfr; |
| 406 | } |
| 407 | |
| 408 | memcpy(maestro_radio_inst, &maestro_radio, sizeof(maestro_radio)); |
| 409 | video_set_drvdata(maestro_radio_inst, radio_unit); |
| 410 | pci_set_drvdata(pdev, maestro_radio_inst); |
| 411 | |
Hans Verkuil | cba99ae | 2008-09-03 17:11:58 -0300 | [diff] [blame] | 412 | retval = video_register_device(maestro_radio_inst, VFL_TYPE_RADIO, radio_nr); |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 413 | if (retval) { |
| 414 | printk(KERN_ERR "can't register video device!\n"); |
| 415 | goto errfr1; |
| 416 | } |
| 417 | |
| 418 | if (!radio_power_on(radio_unit)) { |
| 419 | retval = -EIO; |
| 420 | goto errunr; |
| 421 | } |
| 422 | |
| 423 | dev_info(&pdev->dev, "version " DRIVER_VERSION " time " __TIME__ " " |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 424 | __DATE__ "\n"); |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 425 | dev_info(&pdev->dev, "radio chip initialized\n"); |
| 426 | |
| 427 | return 0; |
| 428 | errunr: |
| 429 | video_unregister_device(maestro_radio_inst); |
| 430 | errfr1: |
Julia Lawall | f37fdf3 | 2008-01-01 18:08:10 -0300 | [diff] [blame] | 431 | video_device_release(maestro_radio_inst); |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 432 | errfr: |
| 433 | kfree(radio_unit); |
| 434 | err: |
| 435 | return retval; |
| 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 439 | static void __devexit maestro_remove(struct pci_dev *pdev) |
| 440 | { |
| 441 | struct video_device *vdev = pci_get_drvdata(pdev); |
| 442 | |
| 443 | video_unregister_device(vdev); |
| 444 | } |
| 445 | |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 446 | static int __init maestro_radio_init(void) |
| 447 | { |
| 448 | int retval = pci_register_driver(&maestro_r_driver); |
| 449 | |
| 450 | if (retval) |
| 451 | printk(KERN_ERR "error during registration pci driver\n"); |
| 452 | |
| 453 | return retval; |
| 454 | } |
| 455 | |
| 456 | static void __exit maestro_radio_exit(void) |
| 457 | { |
| 458 | pci_unregister_driver(&maestro_r_driver); |
| 459 | } |
| 460 | |
| 461 | module_init(maestro_radio_init); |
| 462 | module_exit(maestro_radio_exit); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 463 | |
| 464 | MODULE_AUTHOR("Adam Tlalka, atlka@pg.gda.pl"); |
| 465 | MODULE_DESCRIPTION("Radio driver for the Maestro PCI sound card radio."); |
| 466 | MODULE_LICENSE("GPL"); |