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