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> |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 27 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/pci.h> |
Mauro Carvalho Chehab | b6055d7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 29 | #include <linux/videodev2.h> |
Mauro Carvalho Chehab | 5e87efa | 2006-06-05 10:26:32 -0300 | [diff] [blame] | 30 | #include <media/v4l2-common.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 | |
| 78 | static int radio_ioctl(struct inode *inode, struct file *file, |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 79 | unsigned int cmd, unsigned long arg); |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 80 | static int maestro_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
| 81 | static void maestro_remove(struct pci_dev *pdev); |
| 82 | |
| 83 | static struct pci_device_id maestro_r_pci_tbl[] = { |
| 84 | { PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1968), |
| 85 | .class = PCI_CLASS_MULTIMEDIA_AUDIO << 8, |
| 86 | .class_mask = 0xffff00 }, |
| 87 | { PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1978), |
| 88 | .class = PCI_CLASS_MULTIMEDIA_AUDIO << 8, |
| 89 | .class_mask = 0xffff00 }, |
| 90 | { 0 } |
| 91 | }; |
| 92 | MODULE_DEVICE_TABLE(pci, maestro_r_pci_tbl); |
| 93 | |
| 94 | static struct pci_driver maestro_r_driver = { |
| 95 | .name = "maestro_radio", |
| 96 | .id_table = maestro_r_pci_tbl, |
| 97 | .probe = maestro_probe, |
| 98 | .remove = __devexit_p(maestro_remove), |
| 99 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 101 | static const struct file_operations maestro_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | .owner = THIS_MODULE, |
| 103 | .open = video_exclusive_open, |
| 104 | .release = video_exclusive_release, |
| 105 | .ioctl = radio_ioctl, |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 106 | .compat_ioctl = v4l_compat_ioctl32, |
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 | static struct video_device maestro_radio = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | .name = "Maestro radio", |
| 112 | .type = VID_TYPE_TUNER, |
Mauro Carvalho Chehab | b6055d7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 113 | .hardware = 0, |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 114 | .fops = &maestro_fops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 117 | struct radio_device { |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 118 | u16 io, /* base of Maestro card radio io (GPIO_DATA)*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | muted, /* VIDEO_AUDIO_MUTE */ |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 120 | stereo, /* VIDEO_TUNER_STEREO_ON */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | tuned; /* signal strength (0 or 0xffff) */ |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 122 | struct mutex lock; |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 123 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 125 | static u32 radio_bits_get(struct radio_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 127 | register u16 io=dev->io, l, rdata; |
| 128 | register u32 data=0; |
| 129 | u16 omask; |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | omask = inw(io + IO_MASK); |
| 132 | outw(~(STR_CLK | STR_WREN), io + IO_MASK); |
| 133 | outw(0, io); |
| 134 | udelay(16); |
| 135 | |
| 136 | for (l=24;l--;) { |
| 137 | outw(STR_CLK, io); /* HI state */ |
| 138 | udelay(2); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 139 | if(!l) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | dev->tuned = inw(io) & STR_MOST ? 0 : 0xffff; |
| 141 | outw(0, io); /* LO state */ |
| 142 | udelay(2); |
| 143 | data <<= 1; /* shift data */ |
| 144 | rdata = inw(io); |
| 145 | if(!l) |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 146 | dev->stereo = rdata & STR_MOST ? |
Mauro Carvalho Chehab | b6055d7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 147 | 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | else |
| 149 | if(rdata & STR_DATA) |
| 150 | data++; |
| 151 | udelay(2); |
| 152 | } |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | if(dev->muted) |
| 155 | outw(STR_WREN, io); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | udelay(4); |
| 158 | outw(omask, io + IO_MASK); |
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 | return data & 0x3ffe; |
| 161 | } |
| 162 | |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 163 | static void radio_bits_set(struct radio_device *dev, u32 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 165 | register u16 io=dev->io, l, bits; |
| 166 | u16 omask, odir; |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | omask = inw(io + IO_MASK); |
| 169 | odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN); |
| 170 | outw(odir | STR_DATA, io + IO_DIR); |
| 171 | outw(~(STR_DATA | STR_CLK | STR_WREN), io + IO_MASK); |
| 172 | udelay(16); |
| 173 | for (l=25;l;l--) { |
| 174 | bits = ((data >> 18) & STR_DATA) | STR_WREN ; |
| 175 | data <<= 1; /* shift data */ |
| 176 | outw(bits, io); /* start strobe */ |
| 177 | udelay(2); |
| 178 | outw(bits | STR_CLK, io); /* HI level */ |
| 179 | udelay(2); |
| 180 | outw(bits, io); /* LO level */ |
| 181 | udelay(4); |
| 182 | } |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | if(!dev->muted) |
| 185 | outw(0, io); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | udelay(4); |
| 188 | outw(omask, io + IO_MASK); |
| 189 | outw(odir, io + IO_DIR); |
| 190 | msleep(125); |
| 191 | } |
| 192 | |
Jesper Juhl | 77933d7 | 2005-07-27 11:46:09 -0700 | [diff] [blame] | 193 | static inline int radio_function(struct inode *inode, struct file *file, |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 194 | unsigned int cmd, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
| 196 | struct video_device *dev = video_devdata(file); |
Jiri Slaby | f86e776 | 2006-01-09 20:52:50 -0800 | [diff] [blame] | 197 | struct radio_device *card = video_get_drvdata(dev); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 198 | |
| 199 | switch (cmd) { |
Mauro Carvalho Chehab | b6055d7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 200 | case VIDIOC_QUERYCAP: |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 201 | { |
Mauro Carvalho Chehab | b6055d7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 202 | struct v4l2_capability *v = arg; |
| 203 | memset(v,0,sizeof(*v)); |
| 204 | strlcpy(v->driver, "radio-maestro", sizeof (v->driver)); |
| 205 | strlcpy(v->card, "Maestro Radio", sizeof (v->card)); |
| 206 | sprintf(v->bus_info,"PCI"); |
| 207 | v->version = RADIO_VERSION; |
| 208 | v->capabilities = V4L2_CAP_TUNER; |
| 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | return 0; |
| 211 | } |
Mauro Carvalho Chehab | b6055d7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 212 | case VIDIOC_G_TUNER: |
| 213 | { |
| 214 | struct v4l2_tuner *v = arg; |
| 215 | |
| 216 | if (v->index > 0) |
| 217 | return -EINVAL; |
| 218 | |
| 219 | (void)radio_bits_get(card); |
| 220 | |
| 221 | memset(v,0,sizeof(*v)); |
| 222 | strcpy(v->name, "FM"); |
| 223 | v->type = V4L2_TUNER_RADIO; |
| 224 | |
| 225 | v->rangelow = FREQ_LO; |
| 226 | v->rangehigh = FREQ_HI; |
| 227 | v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO; |
| 228 | v->capability=V4L2_TUNER_CAP_LOW; |
| 229 | if(card->stereo) |
| 230 | v->audmode = V4L2_TUNER_MODE_STEREO; |
| 231 | else |
| 232 | v->audmode = V4L2_TUNER_MODE_MONO; |
| 233 | v->signal=card->tuned; |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | case VIDIOC_S_TUNER: |
| 238 | { |
| 239 | struct v4l2_tuner *v = arg; |
| 240 | |
| 241 | if (v->index > 0) |
| 242 | return -EINVAL; |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | case VIDIOC_S_FREQUENCY: |
| 247 | { |
| 248 | struct v4l2_frequency *f = arg; |
| 249 | |
| 250 | if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) |
| 251 | return -EINVAL; |
| 252 | radio_bits_set(card, FREQ2BITS(f->frequency)); |
| 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | case VIDIOC_G_FREQUENCY: |
| 257 | { |
| 258 | struct v4l2_frequency *f = arg; |
| 259 | |
| 260 | f->type = V4L2_TUNER_RADIO; |
| 261 | f->frequency = BITS2FREQ(radio_bits_get(card)); |
| 262 | |
| 263 | return 0; |
| 264 | } |
| 265 | case VIDIOC_QUERYCTRL: |
| 266 | { |
| 267 | struct v4l2_queryctrl *qc = arg; |
| 268 | int i; |
| 269 | |
| 270 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { |
| 271 | if (qc->id && qc->id == radio_qctrl[i].id) { |
| 272 | memcpy(qc, &(radio_qctrl[i]), |
| 273 | sizeof(*qc)); |
| 274 | return (0); |
| 275 | } |
| 276 | } |
| 277 | return -EINVAL; |
| 278 | } |
| 279 | case VIDIOC_G_CTRL: |
| 280 | { |
| 281 | struct v4l2_control *ctrl= arg; |
| 282 | |
| 283 | switch (ctrl->id) { |
| 284 | case V4L2_CID_AUDIO_MUTE: |
| 285 | ctrl->value=card->muted; |
| 286 | return (0); |
| 287 | } |
| 288 | return -EINVAL; |
| 289 | } |
| 290 | case VIDIOC_S_CTRL: |
| 291 | { |
| 292 | struct v4l2_control *ctrl= arg; |
| 293 | |
| 294 | switch (ctrl->id) { |
| 295 | case V4L2_CID_AUDIO_MUTE: |
| 296 | { |
| 297 | register u16 io = card->io; |
| 298 | register u16 omask = inw(io + IO_MASK); |
| 299 | outw(~STR_WREN, io + IO_MASK); |
| 300 | outw((card->muted = ctrl->value ) ? |
| 301 | STR_WREN : 0, io); |
| 302 | udelay(4); |
| 303 | outw(omask, io + IO_MASK); |
| 304 | msleep(125); |
| 305 | |
| 306 | return (0); |
| 307 | } |
| 308 | } |
| 309 | return -EINVAL; |
| 310 | } |
| 311 | default: |
| 312 | return v4l_compat_translate_ioctl(inode,file,cmd,arg, |
| 313 | radio_function); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
| 317 | static int radio_ioctl(struct inode *inode, struct file *file, |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 318 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { |
| 320 | struct video_device *dev = video_devdata(file); |
Jiri Slaby | f86e776 | 2006-01-09 20:52:50 -0800 | [diff] [blame] | 321 | struct radio_device *card = video_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | int ret; |
| 323 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 324 | mutex_lock(&card->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | ret = video_usercopy(inode, file, cmd, arg, radio_function); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 326 | mutex_unlock(&card->lock); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | return ret; |
| 329 | } |
| 330 | |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 331 | static u16 __devinit radio_power_on(struct radio_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | { |
Jiri Slaby | 0eaa21f | 2006-01-09 20:52:49 -0800 | [diff] [blame] | 333 | register u16 io = dev->io; |
| 334 | register u32 ofreq; |
| 335 | u16 omask, odir; |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | omask = inw(io + IO_MASK); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 338 | odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | outw(odir & ~STR_WREN, io + IO_DIR); |
Mauro Carvalho Chehab | b6055d7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 340 | dev->muted = inw(io) & STR_WREN ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | outw(odir, io + IO_DIR); |
| 342 | outw(~(STR_WREN | STR_CLK), io + IO_MASK); |
| 343 | outw(dev->muted ? 0 : STR_WREN, io); |
| 344 | udelay(16); |
| 345 | outw(omask, io + IO_MASK); |
| 346 | ofreq = radio_bits_get(dev); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 347 | |
| 348 | if ((ofreq < FREQ2BITS(FREQ_LO)) || (ofreq > FREQ2BITS(FREQ_HI))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | ofreq = FREQ2BITS(FREQ_LO); |
| 350 | radio_bits_set(dev, ofreq); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | return (ofreq == radio_bits_get(dev)); |
| 353 | } |
| 354 | |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 355 | static int __devinit maestro_probe(struct pci_dev *pdev, |
| 356 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 358 | struct radio_device *radio_unit; |
| 359 | struct video_device *maestro_radio_inst; |
| 360 | int retval; |
| 361 | |
| 362 | retval = pci_enable_device(pdev); |
| 363 | if (retval) { |
| 364 | dev_err(&pdev->dev, "enabling pci device failed!\n"); |
| 365 | goto err; |
| 366 | } |
| 367 | |
| 368 | retval = -ENOMEM; |
| 369 | |
| 370 | radio_unit = kzalloc(sizeof(*radio_unit), GFP_KERNEL); |
| 371 | if (radio_unit == NULL) { |
| 372 | dev_err(&pdev->dev, "not enough memory\n"); |
| 373 | goto err; |
| 374 | } |
| 375 | |
| 376 | radio_unit->io = pci_resource_start(pdev, 0) + GPIO_DATA; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 377 | mutex_init(&radio_unit->lock); |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 378 | |
| 379 | maestro_radio_inst = video_device_alloc(); |
| 380 | if (maestro_radio_inst == NULL) { |
| 381 | dev_err(&pdev->dev, "not enough memory\n"); |
| 382 | goto errfr; |
| 383 | } |
| 384 | |
| 385 | memcpy(maestro_radio_inst, &maestro_radio, sizeof(maestro_radio)); |
| 386 | video_set_drvdata(maestro_radio_inst, radio_unit); |
| 387 | pci_set_drvdata(pdev, maestro_radio_inst); |
| 388 | |
| 389 | retval = video_register_device(maestro_radio_inst, VFL_TYPE_RADIO, |
| 390 | radio_nr); |
| 391 | if (retval) { |
| 392 | printk(KERN_ERR "can't register video device!\n"); |
| 393 | goto errfr1; |
| 394 | } |
| 395 | |
| 396 | if (!radio_power_on(radio_unit)) { |
| 397 | retval = -EIO; |
| 398 | goto errunr; |
| 399 | } |
| 400 | |
| 401 | dev_info(&pdev->dev, "version " DRIVER_VERSION " time " __TIME__ " " |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 402 | __DATE__ "\n"); |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 403 | dev_info(&pdev->dev, "radio chip initialized\n"); |
| 404 | |
| 405 | return 0; |
| 406 | errunr: |
| 407 | video_unregister_device(maestro_radio_inst); |
| 408 | errfr1: |
| 409 | kfree(maestro_radio_inst); |
| 410 | errfr: |
| 411 | kfree(radio_unit); |
| 412 | err: |
| 413 | return retval; |
| 414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 417 | static void __devexit maestro_remove(struct pci_dev *pdev) |
| 418 | { |
| 419 | struct video_device *vdev = pci_get_drvdata(pdev); |
| 420 | |
| 421 | video_unregister_device(vdev); |
| 422 | } |
| 423 | |
Jiri Slaby | 89dad8f | 2006-01-09 20:52:47 -0800 | [diff] [blame] | 424 | static int __init maestro_radio_init(void) |
| 425 | { |
| 426 | int retval = pci_register_driver(&maestro_r_driver); |
| 427 | |
| 428 | if (retval) |
| 429 | printk(KERN_ERR "error during registration pci driver\n"); |
| 430 | |
| 431 | return retval; |
| 432 | } |
| 433 | |
| 434 | static void __exit maestro_radio_exit(void) |
| 435 | { |
| 436 | pci_unregister_driver(&maestro_r_driver); |
| 437 | } |
| 438 | |
| 439 | module_init(maestro_radio_init); |
| 440 | module_exit(maestro_radio_exit); |
Jiri Slaby | 6a2cf8e | 2006-01-09 20:52:48 -0800 | [diff] [blame] | 441 | |
| 442 | MODULE_AUTHOR("Adam Tlalka, atlka@pg.gda.pl"); |
| 443 | MODULE_DESCRIPTION("Radio driver for the Maestro PCI sound card radio."); |
| 444 | MODULE_LICENSE("GPL"); |