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