diff options
author | Ondrej Zary <linux@rainbow-software.org> | 2012-05-17 03:55:01 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-05-20 12:16:00 -0400 |
commit | 3491a88ea0499cb10024cf7ec4d2d261634fa2b7 (patch) | |
tree | f79bdaf08f655bf8ab2500b26d69770cd69f9897 /drivers/media | |
parent | 06b491fb9a8a13225d6c9fd798b5feb92f26d126 (diff) |
[media] [resend] radio-sf16fmr2: add PnP support for SF16-FMD2
Add PnP support to radio-sf16fmr2 driver to support SF16-FMD2 card (SB16 +
TEA5757). The driver can now handle two cards (FMR2 is hardwired to 0x384,
FMD2 can be put at 0x384 or 0x284 by PnP).
Tested with both SF16-FMR2 and SF16-FMD2 (the can work at the same time by
using kernel parameter "pnp_reserve_io=0x384,2" so the FMD2 is put at 0x284).
Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/radio/Kconfig | 2 | ||||
-rw-r--r-- | drivers/media/radio/radio-sf16fmr2.c | 144 |
2 files changed, 114 insertions, 32 deletions
diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig index 8db2d7f4b52a..270f7b7e813b 100644 --- a/drivers/media/radio/Kconfig +++ b/drivers/media/radio/Kconfig | |||
@@ -329,7 +329,7 @@ config RADIO_SF16FMI | |||
329 | module will be called radio-sf16fmi. | 329 | module will be called radio-sf16fmi. |
330 | 330 | ||
331 | config RADIO_SF16FMR2 | 331 | config RADIO_SF16FMR2 |
332 | tristate "SF16FMR2 Radio" | 332 | tristate "SF16-FMR2/SF16-FMD2 Radio" |
333 | depends on ISA && VIDEO_V4L2 && SND | 333 | depends on ISA && VIDEO_V4L2 && SND |
334 | ---help--- | 334 | ---help--- |
335 | Choose Y here if you have one of these FM radio cards. | 335 | Choose Y here if you have one of these FM radio cards. |
diff --git a/drivers/media/radio/radio-sf16fmr2.c b/drivers/media/radio/radio-sf16fmr2.c index 7c69214334bf..52b8011f1b23 100644 --- a/drivers/media/radio/radio-sf16fmr2.c +++ b/drivers/media/radio/radio-sf16fmr2.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* SF16-FMR2 radio driver for Linux | 1 | /* SF16-FMR2 and SF16-FMD2 radio driver for Linux |
2 | * Copyright (c) 2011 Ondrej Zary | 2 | * Copyright (c) 2011 Ondrej Zary |
3 | * | 3 | * |
4 | * Original driver was (c) 2000-2002 Ziglio Frediano, freddy77@angelfire.com | 4 | * Original driver was (c) 2000-2002 Ziglio Frediano, freddy77@angelfire.com |
@@ -13,15 +13,19 @@ | |||
13 | #include <linux/ioport.h> /* request_region */ | 13 | #include <linux/ioport.h> /* request_region */ |
14 | #include <linux/io.h> /* outb, outb_p */ | 14 | #include <linux/io.h> /* outb, outb_p */ |
15 | #include <linux/isa.h> | 15 | #include <linux/isa.h> |
16 | #include <linux/pnp.h> | ||
16 | #include <sound/tea575x-tuner.h> | 17 | #include <sound/tea575x-tuner.h> |
17 | 18 | ||
18 | MODULE_AUTHOR("Ondrej Zary"); | 19 | MODULE_AUTHOR("Ondrej Zary"); |
19 | MODULE_DESCRIPTION("MediaForte SF16-FMR2 FM radio card driver"); | 20 | MODULE_DESCRIPTION("MediaForte SF16-FMR2 and SF16-FMD2 FM radio card driver"); |
20 | MODULE_LICENSE("GPL"); | 21 | MODULE_LICENSE("GPL"); |
21 | 22 | ||
22 | static int radio_nr = -1; | 23 | /* these cards can only use two different ports (0x384 and 0x284) */ |
23 | module_param(radio_nr, int, 0444); | 24 | #define FMR2_MAX 2 |
24 | MODULE_PARM_DESC(radio_nr, "Radio device number"); | 25 | |
26 | static int radio_nr[FMR2_MAX] = { [0 ... (FMR2_MAX - 1)] = -1 }; | ||
27 | module_param_array(radio_nr, int, NULL, 0444); | ||
28 | MODULE_PARM_DESC(radio_nr, "Radio device numbers"); | ||
25 | 29 | ||
26 | struct fmr2 { | 30 | struct fmr2 { |
27 | int io; | 31 | int io; |
@@ -29,9 +33,15 @@ struct fmr2 { | |||
29 | struct snd_tea575x tea; | 33 | struct snd_tea575x tea; |
30 | struct v4l2_ctrl *volume; | 34 | struct v4l2_ctrl *volume; |
31 | struct v4l2_ctrl *balance; | 35 | struct v4l2_ctrl *balance; |
36 | bool is_fmd2; | ||
32 | }; | 37 | }; |
33 | 38 | ||
34 | /* the port is hardwired so no need to support multiple cards */ | 39 | static int num_fmr2_cards; |
40 | static struct fmr2 *fmr2_cards[FMR2_MAX]; | ||
41 | static bool isa_registered; | ||
42 | static bool pnp_registered; | ||
43 | |||
44 | /* the port is hardwired on SF16-FMR2 */ | ||
35 | #define FMR2_PORT 0x384 | 45 | #define FMR2_PORT 0x384 |
36 | 46 | ||
37 | /* TEA575x tuner pins */ | 47 | /* TEA575x tuner pins */ |
@@ -174,7 +184,8 @@ static int fmr2_tea_ext_init(struct snd_tea575x *tea) | |||
174 | { | 184 | { |
175 | struct fmr2 *fmr2 = tea->private_data; | 185 | struct fmr2 *fmr2 = tea->private_data; |
176 | 186 | ||
177 | if (inb(fmr2->io) & FMR2_HASVOL) { | 187 | /* FMR2 can have volume control, FMD2 can't (uses SB16 mixer) */ |
188 | if (!fmr2->is_fmd2 && inb(fmr2->io) & FMR2_HASVOL) { | ||
178 | fmr2->volume = v4l2_ctrl_new_std(&tea->ctrl_handler, &fmr2_ctrl_ops, V4L2_CID_AUDIO_VOLUME, 0, 68, 2, 56); | 189 | fmr2->volume = v4l2_ctrl_new_std(&tea->ctrl_handler, &fmr2_ctrl_ops, V4L2_CID_AUDIO_VOLUME, 0, 68, 2, 56); |
179 | fmr2->balance = v4l2_ctrl_new_std(&tea->ctrl_handler, &fmr2_ctrl_ops, V4L2_CID_AUDIO_BALANCE, -68, 68, 2, 0); | 190 | fmr2->balance = v4l2_ctrl_new_std(&tea->ctrl_handler, &fmr2_ctrl_ops, V4L2_CID_AUDIO_BALANCE, -68, 68, 2, 0); |
180 | if (tea->ctrl_handler.error) { | 191 | if (tea->ctrl_handler.error) { |
@@ -186,22 +197,28 @@ static int fmr2_tea_ext_init(struct snd_tea575x *tea) | |||
186 | return 0; | 197 | return 0; |
187 | } | 198 | } |
188 | 199 | ||
189 | static int __devinit fmr2_probe(struct device *pdev, unsigned int dev) | 200 | static struct pnp_device_id fmr2_pnp_ids[] __devinitdata = { |
201 | { .id = "MFRad13" }, /* tuner subdevice of SF16-FMD2 */ | ||
202 | { .id = "" } | ||
203 | }; | ||
204 | MODULE_DEVICE_TABLE(pnp, fmr2_pnp_ids); | ||
205 | |||
206 | static int __devinit fmr2_probe(struct fmr2 *fmr2, struct device *pdev, int io) | ||
190 | { | 207 | { |
191 | struct fmr2 *fmr2; | 208 | int err, i; |
192 | int err; | 209 | char *card_name = fmr2->is_fmd2 ? "SF16-FMD2" : "SF16-FMR2"; |
193 | 210 | ||
194 | fmr2 = kzalloc(sizeof(*fmr2), GFP_KERNEL); | 211 | /* avoid errors if a card was already registered at given port */ |
195 | if (fmr2 == NULL) | 212 | for (i = 0; i < num_fmr2_cards; i++) |
196 | return -ENOMEM; | 213 | if (io == fmr2_cards[i]->io) |
214 | return -EBUSY; | ||
197 | 215 | ||
198 | strlcpy(fmr2->v4l2_dev.name, dev_name(pdev), | 216 | strlcpy(fmr2->v4l2_dev.name, "radio-sf16fmr2", |
199 | sizeof(fmr2->v4l2_dev.name)); | 217 | sizeof(fmr2->v4l2_dev.name)), |
200 | fmr2->io = FMR2_PORT; | 218 | fmr2->io = io; |
201 | 219 | ||
202 | if (!request_region(fmr2->io, 2, fmr2->v4l2_dev.name)) { | 220 | if (!request_region(fmr2->io, 2, fmr2->v4l2_dev.name)) { |
203 | printk(KERN_ERR "radio-sf16fmr2: I/O port 0x%x already in use\n", fmr2->io); | 221 | printk(KERN_ERR "radio-sf16fmr2: I/O port 0x%x already in use\n", fmr2->io); |
204 | kfree(fmr2); | ||
205 | return -EBUSY; | 222 | return -EBUSY; |
206 | } | 223 | } |
207 | 224 | ||
@@ -210,56 +227,121 @@ static int __devinit fmr2_probe(struct device *pdev, unsigned int dev) | |||
210 | if (err < 0) { | 227 | if (err < 0) { |
211 | v4l2_err(&fmr2->v4l2_dev, "Could not register v4l2_device\n"); | 228 | v4l2_err(&fmr2->v4l2_dev, "Could not register v4l2_device\n"); |
212 | release_region(fmr2->io, 2); | 229 | release_region(fmr2->io, 2); |
213 | kfree(fmr2); | ||
214 | return err; | 230 | return err; |
215 | } | 231 | } |
216 | fmr2->tea.v4l2_dev = &fmr2->v4l2_dev; | 232 | fmr2->tea.v4l2_dev = &fmr2->v4l2_dev; |
217 | fmr2->tea.private_data = fmr2; | 233 | fmr2->tea.private_data = fmr2; |
218 | fmr2->tea.radio_nr = radio_nr; | 234 | fmr2->tea.radio_nr = radio_nr[num_fmr2_cards]; |
219 | fmr2->tea.ops = &fmr2_tea_ops; | 235 | fmr2->tea.ops = &fmr2_tea_ops; |
220 | fmr2->tea.ext_init = fmr2_tea_ext_init; | 236 | fmr2->tea.ext_init = fmr2_tea_ext_init; |
221 | strlcpy(fmr2->tea.card, "SF16-FMR2", sizeof(fmr2->tea.card)); | 237 | strlcpy(fmr2->tea.card, card_name, sizeof(fmr2->tea.card)); |
222 | snprintf(fmr2->tea.bus_info, sizeof(fmr2->tea.bus_info), "ISA:%s", | 238 | snprintf(fmr2->tea.bus_info, sizeof(fmr2->tea.bus_info), "%s:%s", |
223 | fmr2->v4l2_dev.name); | 239 | fmr2->is_fmd2 ? "PnP" : "ISA", dev_name(pdev)); |
224 | 240 | ||
225 | if (snd_tea575x_init(&fmr2->tea)) { | 241 | if (snd_tea575x_init(&fmr2->tea)) { |
226 | printk(KERN_ERR "radio-sf16fmr2: Unable to detect TEA575x tuner\n"); | 242 | printk(KERN_ERR "radio-sf16fmr2: Unable to detect TEA575x tuner\n"); |
227 | release_region(fmr2->io, 2); | 243 | release_region(fmr2->io, 2); |
228 | kfree(fmr2); | ||
229 | return -ENODEV; | 244 | return -ENODEV; |
230 | } | 245 | } |
231 | 246 | ||
232 | printk(KERN_INFO "radio-sf16fmr2: SF16-FMR2 radio card at 0x%x.\n", fmr2->io); | 247 | printk(KERN_INFO "radio-sf16fmr2: %s radio card at 0x%x.\n", |
248 | card_name, fmr2->io); | ||
233 | return 0; | 249 | return 0; |
234 | } | 250 | } |
235 | 251 | ||
236 | static int __exit fmr2_remove(struct device *pdev, unsigned int dev) | 252 | static int __devinit fmr2_isa_match(struct device *pdev, unsigned int ndev) |
253 | { | ||
254 | struct fmr2 *fmr2 = kzalloc(sizeof(*fmr2), GFP_KERNEL); | ||
255 | if (!fmr2) | ||
256 | return 0; | ||
257 | |||
258 | if (fmr2_probe(fmr2, pdev, FMR2_PORT)) { | ||
259 | kfree(fmr2); | ||
260 | return 0; | ||
261 | } | ||
262 | dev_set_drvdata(pdev, fmr2); | ||
263 | fmr2_cards[num_fmr2_cards++] = fmr2; | ||
264 | |||
265 | return 1; | ||
266 | } | ||
267 | |||
268 | static int __devinit fmr2_pnp_probe(struct pnp_dev *pdev, | ||
269 | const struct pnp_device_id *id) | ||
237 | { | 270 | { |
238 | struct fmr2 *fmr2 = dev_get_drvdata(pdev); | 271 | int ret; |
272 | struct fmr2 *fmr2 = kzalloc(sizeof(*fmr2), GFP_KERNEL); | ||
273 | if (!fmr2) | ||
274 | return -ENOMEM; | ||
239 | 275 | ||
276 | fmr2->is_fmd2 = true; | ||
277 | ret = fmr2_probe(fmr2, &pdev->dev, pnp_port_start(pdev, 0)); | ||
278 | if (ret) { | ||
279 | kfree(fmr2); | ||
280 | return ret; | ||
281 | } | ||
282 | pnp_set_drvdata(pdev, fmr2); | ||
283 | fmr2_cards[num_fmr2_cards++] = fmr2; | ||
284 | |||
285 | return 0; | ||
286 | } | ||
287 | |||
288 | static void __devexit fmr2_remove(struct fmr2 *fmr2) | ||
289 | { | ||
240 | snd_tea575x_exit(&fmr2->tea); | 290 | snd_tea575x_exit(&fmr2->tea); |
241 | release_region(fmr2->io, 2); | 291 | release_region(fmr2->io, 2); |
242 | v4l2_device_unregister(&fmr2->v4l2_dev); | 292 | v4l2_device_unregister(&fmr2->v4l2_dev); |
243 | kfree(fmr2); | 293 | kfree(fmr2); |
294 | } | ||
295 | |||
296 | static int __devexit fmr2_isa_remove(struct device *pdev, unsigned int ndev) | ||
297 | { | ||
298 | fmr2_remove(dev_get_drvdata(pdev)); | ||
299 | dev_set_drvdata(pdev, NULL); | ||
300 | |||
244 | return 0; | 301 | return 0; |
245 | } | 302 | } |
246 | 303 | ||
247 | struct isa_driver fmr2_driver = { | 304 | static void __devexit fmr2_pnp_remove(struct pnp_dev *pdev) |
248 | .probe = fmr2_probe, | 305 | { |
249 | .remove = fmr2_remove, | 306 | fmr2_remove(pnp_get_drvdata(pdev)); |
307 | pnp_set_drvdata(pdev, NULL); | ||
308 | } | ||
309 | |||
310 | struct isa_driver fmr2_isa_driver = { | ||
311 | .match = fmr2_isa_match, | ||
312 | .remove = __devexit_p(fmr2_isa_remove), | ||
250 | .driver = { | 313 | .driver = { |
251 | .name = "radio-sf16fmr2", | 314 | .name = "radio-sf16fmr2", |
252 | }, | 315 | }, |
253 | }; | 316 | }; |
254 | 317 | ||
318 | struct pnp_driver fmr2_pnp_driver = { | ||
319 | .name = "radio-sf16fmr2", | ||
320 | .id_table = fmr2_pnp_ids, | ||
321 | .probe = fmr2_pnp_probe, | ||
322 | .remove = __devexit_p(fmr2_pnp_remove), | ||
323 | }; | ||
324 | |||
255 | static int __init fmr2_init(void) | 325 | static int __init fmr2_init(void) |
256 | { | 326 | { |
257 | return isa_register_driver(&fmr2_driver, 1); | 327 | int ret; |
328 | |||
329 | ret = pnp_register_driver(&fmr2_pnp_driver); | ||
330 | if (!ret) | ||
331 | pnp_registered = true; | ||
332 | ret = isa_register_driver(&fmr2_isa_driver, 1); | ||
333 | if (!ret) | ||
334 | isa_registered = true; | ||
335 | |||
336 | return (pnp_registered || isa_registered) ? 0 : ret; | ||
258 | } | 337 | } |
259 | 338 | ||
260 | static void __exit fmr2_exit(void) | 339 | static void __exit fmr2_exit(void) |
261 | { | 340 | { |
262 | isa_unregister_driver(&fmr2_driver); | 341 | if (pnp_registered) |
342 | pnp_unregister_driver(&fmr2_pnp_driver); | ||
343 | if (isa_registered) | ||
344 | isa_unregister_driver(&fmr2_isa_driver); | ||
263 | } | 345 | } |
264 | 346 | ||
265 | module_init(fmr2_init); | 347 | module_init(fmr2_init); |