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