radio-sf16fmr2.c (b29e2679d0da91c60d3ac190d9c3bd65ac2f68c5) | radio-sf16fmr2.c (3491a88ea0499cb10024cf7ec4d2d261634fa2b7) |
---|---|
1/* SF16-FMR2 radio driver for Linux | 1/* SF16-FMR2 and SF16-FMD2 radio driver for Linux |
2 * Copyright (c) 2011 Ondrej Zary 3 * 4 * Original driver was (c) 2000-2002 Ziglio Frediano, freddy77@angelfire.com 5 * but almost nothing remained here after conversion to generic TEA575x 6 * implementation 7 */ 8 9#include <linux/delay.h> 10#include <linux/module.h> /* Modules */ 11#include <linux/init.h> /* Initdata */ 12#include <linux/slab.h> 13#include <linux/ioport.h> /* request_region */ 14#include <linux/io.h> /* outb, outb_p */ 15#include <linux/isa.h> | 2 * Copyright (c) 2011 Ondrej Zary 3 * 4 * Original driver was (c) 2000-2002 Ziglio Frediano, freddy77@angelfire.com 5 * but almost nothing remained here after conversion to generic TEA575x 6 * implementation 7 */ 8 9#include <linux/delay.h> 10#include <linux/module.h> /* Modules */ 11#include <linux/init.h> /* Initdata */ 12#include <linux/slab.h> 13#include <linux/ioport.h> /* request_region */ 14#include <linux/io.h> /* outb, outb_p */ 15#include <linux/isa.h> |
16#include <linux/pnp.h> |
|
16#include <sound/tea575x-tuner.h> 17 18MODULE_AUTHOR("Ondrej Zary"); | 17#include <sound/tea575x-tuner.h> 18 19MODULE_AUTHOR("Ondrej Zary"); |
19MODULE_DESCRIPTION("MediaForte SF16-FMR2 FM radio card driver"); | 20MODULE_DESCRIPTION("MediaForte SF16-FMR2 and SF16-FMD2 FM radio card driver"); |
20MODULE_LICENSE("GPL"); 21 | 21MODULE_LICENSE("GPL"); 22 |
22static int radio_nr = -1; 23module_param(radio_nr, int, 0444); 24MODULE_PARM_DESC(radio_nr, "Radio device number"); | 23/* these cards can only use two different ports (0x384 and 0x284) */ 24#define FMR2_MAX 2 |
25 | 25 |
26static int radio_nr[FMR2_MAX] = { [0 ... (FMR2_MAX - 1)] = -1 }; 27module_param_array(radio_nr, int, NULL, 0444); 28MODULE_PARM_DESC(radio_nr, "Radio device numbers"); 29 |
|
26struct fmr2 { 27 int io; 28 struct v4l2_device v4l2_dev; 29 struct snd_tea575x tea; 30 struct v4l2_ctrl *volume; 31 struct v4l2_ctrl *balance; | 30struct fmr2 { 31 int io; 32 struct v4l2_device v4l2_dev; 33 struct snd_tea575x tea; 34 struct v4l2_ctrl *volume; 35 struct v4l2_ctrl *balance; |
36 bool is_fmd2; |
|
32}; 33 | 37}; 38 |
34/* the port is hardwired so no need to support multiple cards */ | 39static int num_fmr2_cards; 40static struct fmr2 *fmr2_cards[FMR2_MAX]; 41static bool isa_registered; 42static bool pnp_registered; 43 44/* the port is hardwired on SF16-FMR2 */ |
35#define FMR2_PORT 0x384 36 37/* TEA575x tuner pins */ 38#define STR_DATA (1 << 0) 39#define STR_CLK (1 << 1) 40#define STR_WREN (1 << 2) 41#define STR_MOST (1 << 3) 42/* PT2254A/TC9154A volume control pins */ --- 126 unchanged lines hidden (view full) --- 169static const struct v4l2_ctrl_ops fmr2_ctrl_ops = { 170 .s_ctrl = fmr2_s_ctrl, 171}; 172 173static int fmr2_tea_ext_init(struct snd_tea575x *tea) 174{ 175 struct fmr2 *fmr2 = tea->private_data; 176 | 45#define FMR2_PORT 0x384 46 47/* TEA575x tuner pins */ 48#define STR_DATA (1 << 0) 49#define STR_CLK (1 << 1) 50#define STR_WREN (1 << 2) 51#define STR_MOST (1 << 3) 52/* PT2254A/TC9154A volume control pins */ --- 126 unchanged lines hidden (view full) --- 179static const struct v4l2_ctrl_ops fmr2_ctrl_ops = { 180 .s_ctrl = fmr2_s_ctrl, 181}; 182 183static int fmr2_tea_ext_init(struct snd_tea575x *tea) 184{ 185 struct fmr2 *fmr2 = tea->private_data; 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); 179 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) { 181 printk(KERN_ERR "radio-sf16fmr2: can't initialize controls\n"); 182 return tea->ctrl_handler.error; 183 } 184 } 185 186 return 0; 187} 188 | 189 fmr2->volume = v4l2_ctrl_new_std(&tea->ctrl_handler, &fmr2_ctrl_ops, V4L2_CID_AUDIO_VOLUME, 0, 68, 2, 56); 190 fmr2->balance = v4l2_ctrl_new_std(&tea->ctrl_handler, &fmr2_ctrl_ops, V4L2_CID_AUDIO_BALANCE, -68, 68, 2, 0); 191 if (tea->ctrl_handler.error) { 192 printk(KERN_ERR "radio-sf16fmr2: can't initialize controls\n"); 193 return tea->ctrl_handler.error; 194 } 195 } 196 197 return 0; 198} 199 |
189static int __devinit fmr2_probe(struct device *pdev, unsigned int dev) | 200static struct pnp_device_id fmr2_pnp_ids[] __devinitdata = { 201 { .id = "MFRad13" }, /* tuner subdevice of SF16-FMD2 */ 202 { .id = "" } 203}; 204MODULE_DEVICE_TABLE(pnp, fmr2_pnp_ids); 205 206static int __devinit fmr2_probe(struct fmr2 *fmr2, struct device *pdev, int io) |
190{ | 207{ |
191 struct fmr2 *fmr2; 192 int err; | 208 int err, i; 209 char *card_name = fmr2->is_fmd2 ? "SF16-FMD2" : "SF16-FMR2"; |
193 | 210 |
194 fmr2 = kzalloc(sizeof(*fmr2), GFP_KERNEL); 195 if (fmr2 == NULL) 196 return -ENOMEM; | 211 /* avoid errors if a card was already registered at given port */ 212 for (i = 0; i < num_fmr2_cards; i++) 213 if (io == fmr2_cards[i]->io) 214 return -EBUSY; |
197 | 215 |
198 strlcpy(fmr2->v4l2_dev.name, dev_name(pdev), 199 sizeof(fmr2->v4l2_dev.name)); 200 fmr2->io = FMR2_PORT; | 216 strlcpy(fmr2->v4l2_dev.name, "radio-sf16fmr2", 217 sizeof(fmr2->v4l2_dev.name)), 218 fmr2->io = io; |
201 202 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); | 219 220 if (!request_region(fmr2->io, 2, fmr2->v4l2_dev.name)) { 221 printk(KERN_ERR "radio-sf16fmr2: I/O port 0x%x already in use\n", fmr2->io); |
204 kfree(fmr2); | |
205 return -EBUSY; 206 } 207 208 dev_set_drvdata(pdev, fmr2); 209 err = v4l2_device_register(pdev, &fmr2->v4l2_dev); 210 if (err < 0) { 211 v4l2_err(&fmr2->v4l2_dev, "Could not register v4l2_device\n"); 212 release_region(fmr2->io, 2); | 222 return -EBUSY; 223 } 224 225 dev_set_drvdata(pdev, fmr2); 226 err = v4l2_device_register(pdev, &fmr2->v4l2_dev); 227 if (err < 0) { 228 v4l2_err(&fmr2->v4l2_dev, "Could not register v4l2_device\n"); 229 release_region(fmr2->io, 2); |
213 kfree(fmr2); | |
214 return err; 215 } 216 fmr2->tea.v4l2_dev = &fmr2->v4l2_dev; 217 fmr2->tea.private_data = fmr2; | 230 return err; 231 } 232 fmr2->tea.v4l2_dev = &fmr2->v4l2_dev; 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; 220 fmr2->tea.ext_init = fmr2_tea_ext_init; | 235 fmr2->tea.ops = &fmr2_tea_ops; 236 fmr2->tea.ext_init = fmr2_tea_ext_init; |
221 strlcpy(fmr2->tea.card, "SF16-FMR2", sizeof(fmr2->tea.card)); 222 snprintf(fmr2->tea.bus_info, sizeof(fmr2->tea.bus_info), "ISA:%s", 223 fmr2->v4l2_dev.name); | 237 strlcpy(fmr2->tea.card, card_name, sizeof(fmr2->tea.card)); 238 snprintf(fmr2->tea.bus_info, sizeof(fmr2->tea.bus_info), "%s:%s", 239 fmr2->is_fmd2 ? "PnP" : "ISA", dev_name(pdev)); |
224 225 if (snd_tea575x_init(&fmr2->tea)) { 226 printk(KERN_ERR "radio-sf16fmr2: Unable to detect TEA575x tuner\n"); 227 release_region(fmr2->io, 2); | 240 241 if (snd_tea575x_init(&fmr2->tea)) { 242 printk(KERN_ERR "radio-sf16fmr2: Unable to detect TEA575x tuner\n"); 243 release_region(fmr2->io, 2); |
228 kfree(fmr2); | |
229 return -ENODEV; 230 } 231 | 244 return -ENODEV; 245 } 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; 234} 235 | 249 return 0; 250} 251 |
236static int __exit fmr2_remove(struct device *pdev, unsigned int dev) | 252static int __devinit fmr2_isa_match(struct device *pdev, unsigned int ndev) |
237{ | 253{ |
238 struct fmr2 *fmr2 = dev_get_drvdata(pdev); | 254 struct fmr2 *fmr2 = kzalloc(sizeof(*fmr2), GFP_KERNEL); 255 if (!fmr2) 256 return 0; |
239 | 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 268static int __devinit fmr2_pnp_probe(struct pnp_dev *pdev, 269 const struct pnp_device_id *id) 270{ 271 int ret; 272 struct fmr2 *fmr2 = kzalloc(sizeof(*fmr2), GFP_KERNEL); 273 if (!fmr2) 274 return -ENOMEM; 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 288static void __devexit fmr2_remove(struct fmr2 *fmr2) 289{ |
|
240 snd_tea575x_exit(&fmr2->tea); 241 release_region(fmr2->io, 2); 242 v4l2_device_unregister(&fmr2->v4l2_dev); 243 kfree(fmr2); | 290 snd_tea575x_exit(&fmr2->tea); 291 release_region(fmr2->io, 2); 292 v4l2_device_unregister(&fmr2->v4l2_dev); 293 kfree(fmr2); |
294} 295 296static 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; 245} 246 | 301 return 0; 302} 303 |
247struct isa_driver fmr2_driver = { 248 .probe = fmr2_probe, 249 .remove = fmr2_remove, | 304static void __devexit fmr2_pnp_remove(struct pnp_dev *pdev) 305{ 306 fmr2_remove(pnp_get_drvdata(pdev)); 307 pnp_set_drvdata(pdev, NULL); 308} 309 310struct isa_driver fmr2_isa_driver = { 311 .match = fmr2_isa_match, 312 .remove = __devexit_p(fmr2_isa_remove), |
250 .driver = { 251 .name = "radio-sf16fmr2", 252 }, 253}; 254 | 313 .driver = { 314 .name = "radio-sf16fmr2", 315 }, 316}; 317 |
318struct 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 |
|
255static int __init fmr2_init(void) 256{ | 325static int __init fmr2_init(void) 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} 259 260static void __exit fmr2_exit(void) 261{ | 337} 338 339static void __exit fmr2_exit(void) 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} 264 265module_init(fmr2_init); 266module_exit(fmr2_exit); | 345} 346 347module_init(fmr2_init); 348module_exit(fmr2_exit); |