109c434b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
23491a88eSOndrej Zary /* SF16-FMR2 and SF16-FMD2 radio driver for Linux
39e8fa0e6SOndrej Zary  * Copyright (c) 2011 Ondrej Zary
41da177e4SLinus Torvalds  *
59e8fa0e6SOndrej Zary  * Original driver was (c) 2000-2002 Ziglio Frediano, freddy77@angelfire.com
69e8fa0e6SOndrej Zary  * but almost nothing remained here after conversion to generic TEA575x
79e8fa0e6SOndrej Zary  * implementation
81da177e4SLinus Torvalds  */
91da177e4SLinus Torvalds 
109e8fa0e6SOndrej Zary #include <linux/delay.h>
111da177e4SLinus Torvalds #include <linux/module.h>	/* Modules			*/
121da177e4SLinus Torvalds #include <linux/init.h>		/* Initdata			*/
13d4ecc83bSHans Verkuil #include <linux/slab.h>
14fb911ee8SPeter Osterlund #include <linux/ioport.h>	/* request_region		*/
15c32a9d71SHans Verkuil #include <linux/io.h>		/* outb, outb_p			*/
16d4ecc83bSHans Verkuil #include <linux/isa.h>
173491a88eSOndrej Zary #include <linux/pnp.h>
18d647f0b7SMauro Carvalho Chehab #include <media/drv-intf/tea575x.h>
19c32a9d71SHans Verkuil 
209e8fa0e6SOndrej Zary MODULE_AUTHOR("Ondrej Zary");
213491a88eSOndrej Zary MODULE_DESCRIPTION("MediaForte SF16-FMR2 and SF16-FMD2 FM radio card driver");
22c32a9d71SHans Verkuil MODULE_LICENSE("GPL");
23c32a9d71SHans Verkuil 
243491a88eSOndrej Zary /* these cards can only use two different ports (0x384 and 0x284) */
253491a88eSOndrej Zary #define FMR2_MAX 2
263491a88eSOndrej Zary 
273491a88eSOndrej Zary static int radio_nr[FMR2_MAX] = { [0 ... (FMR2_MAX - 1)] = -1 };
283491a88eSOndrej Zary module_param_array(radio_nr, int, NULL, 0444);
293491a88eSOndrej Zary MODULE_PARM_DESC(radio_nr, "Radio device numbers");
30d4ecc83bSHans Verkuil 
319e8fa0e6SOndrej Zary struct fmr2 {
32c32a9d71SHans Verkuil 	int io;
33d4ecc83bSHans Verkuil 	struct v4l2_device v4l2_dev;
349e8fa0e6SOndrej Zary 	struct snd_tea575x tea;
359e8fa0e6SOndrej Zary 	struct v4l2_ctrl *volume;
369e8fa0e6SOndrej Zary 	struct v4l2_ctrl *balance;
373491a88eSOndrej Zary 	bool is_fmd2;
381da177e4SLinus Torvalds };
391da177e4SLinus Torvalds 
403491a88eSOndrej Zary static int num_fmr2_cards;
413491a88eSOndrej Zary static struct fmr2 *fmr2_cards[FMR2_MAX];
423491a88eSOndrej Zary static bool isa_registered;
433491a88eSOndrej Zary static bool pnp_registered;
443491a88eSOndrej Zary 
453491a88eSOndrej Zary /* the port is hardwired on SF16-FMR2 */
469e8fa0e6SOndrej Zary #define FMR2_PORT	0x384
471da177e4SLinus Torvalds 
489e8fa0e6SOndrej Zary /* TEA575x tuner pins */
499e8fa0e6SOndrej Zary #define STR_DATA	(1 << 0)
509e8fa0e6SOndrej Zary #define STR_CLK		(1 << 1)
519e8fa0e6SOndrej Zary #define STR_WREN	(1 << 2)
529e8fa0e6SOndrej Zary #define STR_MOST	(1 << 3)
539e8fa0e6SOndrej Zary /* PT2254A/TC9154A volume control pins */
549e8fa0e6SOndrej Zary #define PT_ST		(1 << 4)
559e8fa0e6SOndrej Zary #define PT_CK		(1 << 5)
569e8fa0e6SOndrej Zary #define PT_DATA		(1 << 6)
579e8fa0e6SOndrej Zary /* volume control presence pin */
589e8fa0e6SOndrej Zary #define FMR2_HASVOL	(1 << 7)
591da177e4SLinus Torvalds 
fmr2_tea575x_set_pins(struct snd_tea575x * tea,u8 pins)609e8fa0e6SOndrej Zary static void fmr2_tea575x_set_pins(struct snd_tea575x *tea, u8 pins)
611da177e4SLinus Torvalds {
629e8fa0e6SOndrej Zary 	struct fmr2 *fmr2 = tea->private_data;
639e8fa0e6SOndrej Zary 	u8 bits = 0;
649e8fa0e6SOndrej Zary 
659e8fa0e6SOndrej Zary 	bits |= (pins & TEA575X_DATA) ? STR_DATA : 0;
669e8fa0e6SOndrej Zary 	bits |= (pins & TEA575X_CLK)  ? STR_CLK  : 0;
679e8fa0e6SOndrej Zary 	/* WRITE_ENABLE is inverted, DATA must be high during read */
689e8fa0e6SOndrej Zary 	bits |= (pins & TEA575X_WREN) ? 0 : STR_WREN | STR_DATA;
699e8fa0e6SOndrej Zary 
709e8fa0e6SOndrej Zary 	outb(bits, fmr2->io);
711da177e4SLinus Torvalds }
721da177e4SLinus Torvalds 
fmr2_tea575x_get_pins(struct snd_tea575x * tea)739e8fa0e6SOndrej Zary static u8 fmr2_tea575x_get_pins(struct snd_tea575x *tea)
741da177e4SLinus Torvalds {
759e8fa0e6SOndrej Zary 	struct fmr2 *fmr2 = tea->private_data;
769e8fa0e6SOndrej Zary 	u8 bits = inb(fmr2->io);
77c32a9d71SHans Verkuil 
78b5c2e0abSDan Carpenter 	return  ((bits & STR_DATA) ? TEA575X_DATA : 0) |
79b5c2e0abSDan Carpenter 		((bits & STR_MOST) ? TEA575X_MOST : 0);
801da177e4SLinus Torvalds }
811da177e4SLinus Torvalds 
fmr2_tea575x_set_direction(struct snd_tea575x * tea,bool output)829e8fa0e6SOndrej Zary static void fmr2_tea575x_set_direction(struct snd_tea575x *tea, bool output)
831da177e4SLinus Torvalds {
841da177e4SLinus Torvalds }
851da177e4SLinus Torvalds 
8622dbec26SJulia Lawall static const struct snd_tea575x_ops fmr2_tea_ops = {
879e8fa0e6SOndrej Zary 	.set_pins = fmr2_tea575x_set_pins,
889e8fa0e6SOndrej Zary 	.get_pins = fmr2_tea575x_get_pins,
899e8fa0e6SOndrej Zary 	.set_direction = fmr2_tea575x_set_direction,
909e8fa0e6SOndrej Zary };
919e8fa0e6SOndrej Zary 
929e8fa0e6SOndrej Zary /* TC9154A/PT2254A volume control */
939e8fa0e6SOndrej Zary 
949e8fa0e6SOndrej Zary /* 18-bit shift register bit definitions */
959e8fa0e6SOndrej Zary #define TC9154A_ATT_MAJ_0DB	(1 << 0)
969e8fa0e6SOndrej Zary #define TC9154A_ATT_MAJ_10DB	(1 << 1)
979e8fa0e6SOndrej Zary #define TC9154A_ATT_MAJ_20DB	(1 << 2)
989e8fa0e6SOndrej Zary #define TC9154A_ATT_MAJ_30DB	(1 << 3)
999e8fa0e6SOndrej Zary #define TC9154A_ATT_MAJ_40DB	(1 << 4)
1009e8fa0e6SOndrej Zary #define TC9154A_ATT_MAJ_50DB	(1 << 5)
1019e8fa0e6SOndrej Zary #define TC9154A_ATT_MAJ_60DB	(1 << 6)
1029e8fa0e6SOndrej Zary 
1039e8fa0e6SOndrej Zary #define TC9154A_ATT_MIN_0DB	(1 << 7)
1049e8fa0e6SOndrej Zary #define TC9154A_ATT_MIN_2DB	(1 << 8)
1059e8fa0e6SOndrej Zary #define TC9154A_ATT_MIN_4DB	(1 << 9)
1069e8fa0e6SOndrej Zary #define TC9154A_ATT_MIN_6DB	(1 << 10)
1079e8fa0e6SOndrej Zary #define TC9154A_ATT_MIN_8DB	(1 << 11)
1089e8fa0e6SOndrej Zary /* bit 12 is ignored */
1099e8fa0e6SOndrej Zary #define TC9154A_CHANNEL_LEFT	(1 << 13)
1109e8fa0e6SOndrej Zary #define TC9154A_CHANNEL_RIGHT	(1 << 14)
1119e8fa0e6SOndrej Zary /* bits 15, 16, 17 must be 0 */
1129e8fa0e6SOndrej Zary 
1139e8fa0e6SOndrej Zary #define	TC9154A_ATT_MAJ(x)	(1 << x)
1149e8fa0e6SOndrej Zary #define TC9154A_ATT_MIN(x)	(1 << (7 + x))
1159e8fa0e6SOndrej Zary 
tc9154a_set_pins(struct fmr2 * fmr2,u8 pins)1169e8fa0e6SOndrej Zary static void tc9154a_set_pins(struct fmr2 *fmr2, u8 pins)
1171da177e4SLinus Torvalds {
1189e8fa0e6SOndrej Zary 	if (!fmr2->tea.mute)
1199e8fa0e6SOndrej Zary 		pins |= STR_WREN;
1209e8fa0e6SOndrej Zary 
1219e8fa0e6SOndrej Zary 	outb(pins, fmr2->io);
1221da177e4SLinus Torvalds }
1231da177e4SLinus Torvalds 
tc9154a_set_attenuation(struct fmr2 * fmr2,int att,u32 channel)1249e8fa0e6SOndrej Zary static void tc9154a_set_attenuation(struct fmr2 *fmr2, int att, u32 channel)
1251da177e4SLinus Torvalds {
1269e8fa0e6SOndrej Zary 	int i;
1279e8fa0e6SOndrej Zary 	u32 reg;
1289e8fa0e6SOndrej Zary 	u8 bit;
129c32a9d71SHans Verkuil 
1309e8fa0e6SOndrej Zary 	reg = TC9154A_ATT_MAJ(att / 10) | TC9154A_ATT_MIN((att % 10) / 2);
1319e8fa0e6SOndrej Zary 	reg |= channel;
1329e8fa0e6SOndrej Zary 	/* write 18-bit shift register, LSB first */
1339e8fa0e6SOndrej Zary 	for (i = 0; i < 18; i++) {
1349e8fa0e6SOndrej Zary 		bit = reg & (1 << i) ? PT_DATA : 0;
1359e8fa0e6SOndrej Zary 		tc9154a_set_pins(fmr2, bit);
1369e8fa0e6SOndrej Zary 		udelay(5);
1379e8fa0e6SOndrej Zary 		tc9154a_set_pins(fmr2, bit | PT_CK);
1389e8fa0e6SOndrej Zary 		udelay(5);
1399e8fa0e6SOndrej Zary 		tc9154a_set_pins(fmr2, bit);
1401da177e4SLinus Torvalds 	}
1411da177e4SLinus Torvalds 
1429e8fa0e6SOndrej Zary 	/* latch register data */
1439e8fa0e6SOndrej Zary 	udelay(5);
1449e8fa0e6SOndrej Zary 	tc9154a_set_pins(fmr2, PT_ST);
1459e8fa0e6SOndrej Zary 	udelay(5);
1469e8fa0e6SOndrej Zary 	tc9154a_set_pins(fmr2, 0);
1479e8fa0e6SOndrej Zary }
1489e8fa0e6SOndrej Zary 
fmr2_s_ctrl(struct v4l2_ctrl * ctrl)1499e8fa0e6SOndrej Zary static int fmr2_s_ctrl(struct v4l2_ctrl *ctrl)
1501da177e4SLinus Torvalds {
1519e8fa0e6SOndrej Zary 	struct snd_tea575x *tea = container_of(ctrl->handler, struct snd_tea575x, ctrl_handler);
1529e8fa0e6SOndrej Zary 	struct fmr2 *fmr2 = tea->private_data;
1539e8fa0e6SOndrej Zary 	int volume, balance, left, right;
154acda0e71SMauro Carvalho Chehab 
155acda0e71SMauro Carvalho Chehab 	switch (ctrl->id) {
156acda0e71SMauro Carvalho Chehab 	case V4L2_CID_AUDIO_VOLUME:
1579e8fa0e6SOndrej Zary 		volume = ctrl->val;
1589e8fa0e6SOndrej Zary 		balance = fmr2->balance->cur.val;
159acda0e71SMauro Carvalho Chehab 		break;
1609e8fa0e6SOndrej Zary 	case V4L2_CID_AUDIO_BALANCE:
1619e8fa0e6SOndrej Zary 		balance = ctrl->val;
1629e8fa0e6SOndrej Zary 		volume = fmr2->volume->cur.val;
163acda0e71SMauro Carvalho Chehab 		break;
164acda0e71SMauro Carvalho Chehab 	default:
165acda0e71SMauro Carvalho Chehab 		return -EINVAL;
166acda0e71SMauro Carvalho Chehab 	}
16734ab962dSDouglas Landgraf 
1689e8fa0e6SOndrej Zary 	left = right = volume;
1699e8fa0e6SOndrej Zary 	if (balance < 0)
1709e8fa0e6SOndrej Zary 		right = max(0, right + balance);
1719e8fa0e6SOndrej Zary 	if (balance > 0)
1729e8fa0e6SOndrej Zary 		left = max(0, left - balance);
17334ab962dSDouglas Landgraf 
1749e8fa0e6SOndrej Zary 	tc9154a_set_attenuation(fmr2, abs(left - 68), TC9154A_CHANNEL_LEFT);
1759e8fa0e6SOndrej Zary 	tc9154a_set_attenuation(fmr2, abs(right - 68), TC9154A_CHANNEL_RIGHT);
1769e8fa0e6SOndrej Zary 
17734ab962dSDouglas Landgraf 	return 0;
17834ab962dSDouglas Landgraf }
17934ab962dSDouglas Landgraf 
1809e8fa0e6SOndrej Zary static const struct v4l2_ctrl_ops fmr2_ctrl_ops = {
1819e8fa0e6SOndrej Zary 	.s_ctrl = fmr2_s_ctrl,
1821da177e4SLinus Torvalds };
1831da177e4SLinus Torvalds 
fmr2_tea_ext_init(struct snd_tea575x * tea)1849e8fa0e6SOndrej Zary static int fmr2_tea_ext_init(struct snd_tea575x *tea)
1859e8fa0e6SOndrej Zary {
1869e8fa0e6SOndrej Zary 	struct fmr2 *fmr2 = tea->private_data;
1879e8fa0e6SOndrej Zary 
1883491a88eSOndrej Zary 	/* FMR2 can have volume control, FMD2 can't (uses SB16 mixer) */
1893491a88eSOndrej Zary 	if (!fmr2->is_fmd2 && inb(fmr2->io) & FMR2_HASVOL) {
1909e8fa0e6SOndrej Zary 		fmr2->volume = v4l2_ctrl_new_std(&tea->ctrl_handler, &fmr2_ctrl_ops, V4L2_CID_AUDIO_VOLUME, 0, 68, 2, 56);
1919e8fa0e6SOndrej Zary 		fmr2->balance = v4l2_ctrl_new_std(&tea->ctrl_handler, &fmr2_ctrl_ops, V4L2_CID_AUDIO_BALANCE, -68, 68, 2, 0);
1929e8fa0e6SOndrej Zary 		if (tea->ctrl_handler.error) {
193bdb2c41fSMasanari Iida 			printk(KERN_ERR "radio-sf16fmr2: can't initialize controls\n");
1949e8fa0e6SOndrej Zary 			return tea->ctrl_handler.error;
1959e8fa0e6SOndrej Zary 		}
1969e8fa0e6SOndrej Zary 	}
1979e8fa0e6SOndrej Zary 
1989e8fa0e6SOndrej Zary 	return 0;
1999e8fa0e6SOndrej Zary }
2001da177e4SLinus Torvalds 
201db4a8505SArvind Yadav static const struct pnp_device_id fmr2_pnp_ids[] = {
2023491a88eSOndrej Zary 	{ .id = "MFRad13" }, /* tuner subdevice of SF16-FMD2 */
2033491a88eSOndrej Zary 	{ .id = "" }
2043491a88eSOndrej Zary };
2053491a88eSOndrej Zary MODULE_DEVICE_TABLE(pnp, fmr2_pnp_ids);
2063491a88eSOndrej Zary 
fmr2_probe(struct fmr2 * fmr2,struct device * pdev,int io)2074c62e976SGreg Kroah-Hartman static int fmr2_probe(struct fmr2 *fmr2, struct device *pdev, int io)
2081da177e4SLinus Torvalds {
2093491a88eSOndrej Zary 	int err, i;
2103491a88eSOndrej Zary 	char *card_name = fmr2->is_fmd2 ? "SF16-FMD2" : "SF16-FMR2";
2111da177e4SLinus Torvalds 
2123491a88eSOndrej Zary 	/* avoid errors if a card was already registered at given port */
2133491a88eSOndrej Zary 	for (i = 0; i < num_fmr2_cards; i++)
2143491a88eSOndrej Zary 		if (io == fmr2_cards[i]->io)
2153491a88eSOndrej Zary 			return -EBUSY;
216d4ecc83bSHans Verkuil 
217c0decac1SMauro Carvalho Chehab 	strscpy(fmr2->v4l2_dev.name, "radio-sf16fmr2",
2180fcd8d89SJulia Lawall 		sizeof(fmr2->v4l2_dev.name));
2193491a88eSOndrej Zary 	fmr2->io = io;
2201da177e4SLinus Torvalds 
221d4ecc83bSHans Verkuil 	if (!request_region(fmr2->io, 2, fmr2->v4l2_dev.name)) {
2229e8fa0e6SOndrej Zary 		printk(KERN_ERR "radio-sf16fmr2: I/O port 0x%x already in use\n", fmr2->io);
2231da177e4SLinus Torvalds 		return -EBUSY;
2241da177e4SLinus Torvalds 	}
2251da177e4SLinus Torvalds 
226d4ecc83bSHans Verkuil 	dev_set_drvdata(pdev, fmr2);
227d4ecc83bSHans Verkuil 	err = v4l2_device_register(pdev, &fmr2->v4l2_dev);
228d4ecc83bSHans Verkuil 	if (err < 0) {
229d4ecc83bSHans Verkuil 		v4l2_err(&fmr2->v4l2_dev, "Could not register v4l2_device\n");
230d4ecc83bSHans Verkuil 		release_region(fmr2->io, 2);
231d4ecc83bSHans Verkuil 		return err;
232d4ecc83bSHans Verkuil 	}
233d4ecc83bSHans Verkuil 	fmr2->tea.v4l2_dev = &fmr2->v4l2_dev;
2349e8fa0e6SOndrej Zary 	fmr2->tea.private_data = fmr2;
2353491a88eSOndrej Zary 	fmr2->tea.radio_nr = radio_nr[num_fmr2_cards];
2369e8fa0e6SOndrej Zary 	fmr2->tea.ops = &fmr2_tea_ops;
2379e8fa0e6SOndrej Zary 	fmr2->tea.ext_init = fmr2_tea_ext_init;
238c0decac1SMauro Carvalho Chehab 	strscpy(fmr2->tea.card, card_name, sizeof(fmr2->tea.card));
2393491a88eSOndrej Zary 	snprintf(fmr2->tea.bus_info, sizeof(fmr2->tea.bus_info), "%s:%s",
2403491a88eSOndrej Zary 			fmr2->is_fmd2 ? "PnP" : "ISA", dev_name(pdev));
2419e8fa0e6SOndrej Zary 
2425daf53a6SHans de Goede 	if (snd_tea575x_init(&fmr2->tea, THIS_MODULE)) {
2439e8fa0e6SOndrej Zary 		printk(KERN_ERR "radio-sf16fmr2: Unable to detect TEA575x tuner\n");
244c32a9d71SHans Verkuil 		release_region(fmr2->io, 2);
2459e8fa0e6SOndrej Zary 		return -ENODEV;
246c32a9d71SHans Verkuil 	}
247c32a9d71SHans Verkuil 
2483491a88eSOndrej Zary 	printk(KERN_INFO "radio-sf16fmr2: %s radio card at 0x%x.\n",
2493491a88eSOndrej Zary 			card_name, fmr2->io);
2501da177e4SLinus Torvalds 	return 0;
2511da177e4SLinus Torvalds }
2521da177e4SLinus Torvalds 
fmr2_isa_match(struct device * pdev,unsigned int ndev)2534c62e976SGreg Kroah-Hartman static int fmr2_isa_match(struct device *pdev, unsigned int ndev)
2541da177e4SLinus Torvalds {
2553491a88eSOndrej Zary 	struct fmr2 *fmr2 = kzalloc(sizeof(*fmr2), GFP_KERNEL);
2563491a88eSOndrej Zary 	if (!fmr2)
2573491a88eSOndrej Zary 		return 0;
258c32a9d71SHans Verkuil 
2593491a88eSOndrej Zary 	if (fmr2_probe(fmr2, pdev, FMR2_PORT)) {
2603491a88eSOndrej Zary 		kfree(fmr2);
2613491a88eSOndrej Zary 		return 0;
2623491a88eSOndrej Zary 	}
2633491a88eSOndrej Zary 	dev_set_drvdata(pdev, fmr2);
2643491a88eSOndrej Zary 	fmr2_cards[num_fmr2_cards++] = fmr2;
2653491a88eSOndrej Zary 
2663491a88eSOndrej Zary 	return 1;
2673491a88eSOndrej Zary }
2683491a88eSOndrej Zary 
fmr2_pnp_probe(struct pnp_dev * pdev,const struct pnp_device_id * id)2694c62e976SGreg Kroah-Hartman static int fmr2_pnp_probe(struct pnp_dev *pdev, const struct pnp_device_id *id)
2703491a88eSOndrej Zary {
2713491a88eSOndrej Zary 	int ret;
2723491a88eSOndrej Zary 	struct fmr2 *fmr2 = kzalloc(sizeof(*fmr2), GFP_KERNEL);
2733491a88eSOndrej Zary 	if (!fmr2)
2743491a88eSOndrej Zary 		return -ENOMEM;
2753491a88eSOndrej Zary 
2763491a88eSOndrej Zary 	fmr2->is_fmd2 = true;
2773491a88eSOndrej Zary 	ret = fmr2_probe(fmr2, &pdev->dev, pnp_port_start(pdev, 0));
2783491a88eSOndrej Zary 	if (ret) {
2793491a88eSOndrej Zary 		kfree(fmr2);
2803491a88eSOndrej Zary 		return ret;
2813491a88eSOndrej Zary 	}
2823491a88eSOndrej Zary 	pnp_set_drvdata(pdev, fmr2);
2833491a88eSOndrej Zary 	fmr2_cards[num_fmr2_cards++] = fmr2;
2843491a88eSOndrej Zary 
2853491a88eSOndrej Zary 	return 0;
2863491a88eSOndrej Zary }
2873491a88eSOndrej Zary 
fmr2_remove(struct fmr2 * fmr2)2884c62e976SGreg Kroah-Hartman static void fmr2_remove(struct fmr2 *fmr2)
2893491a88eSOndrej Zary {
2909e8fa0e6SOndrej Zary 	snd_tea575x_exit(&fmr2->tea);
291c32a9d71SHans Verkuil 	release_region(fmr2->io, 2);
292d4ecc83bSHans Verkuil 	v4l2_device_unregister(&fmr2->v4l2_dev);
293d4ecc83bSHans Verkuil 	kfree(fmr2);
2943491a88eSOndrej Zary }
2953491a88eSOndrej Zary 
fmr2_isa_remove(struct device * pdev,unsigned int ndev)296*30e88d01SUwe Kleine-König static void fmr2_isa_remove(struct device *pdev, unsigned int ndev)
2973491a88eSOndrej Zary {
2983491a88eSOndrej Zary 	fmr2_remove(dev_get_drvdata(pdev));
299d4ecc83bSHans Verkuil }
300d4ecc83bSHans Verkuil 
fmr2_pnp_remove(struct pnp_dev * pdev)3014c62e976SGreg Kroah-Hartman static void fmr2_pnp_remove(struct pnp_dev *pdev)
3023491a88eSOndrej Zary {
3033491a88eSOndrej Zary 	fmr2_remove(pnp_get_drvdata(pdev));
3043491a88eSOndrej Zary 	pnp_set_drvdata(pdev, NULL);
3053491a88eSOndrej Zary }
3063491a88eSOndrej Zary 
30725fb62b6SMauro Carvalho Chehab static struct isa_driver fmr2_isa_driver = {
3083491a88eSOndrej Zary 	.match		= fmr2_isa_match,
3094c62e976SGreg Kroah-Hartman 	.remove		= fmr2_isa_remove,
310d4ecc83bSHans Verkuil 	.driver		= {
311d4ecc83bSHans Verkuil 		.name	= "radio-sf16fmr2",
312d4ecc83bSHans Verkuil 	},
313d4ecc83bSHans Verkuil };
314d4ecc83bSHans Verkuil 
31525fb62b6SMauro Carvalho Chehab static struct pnp_driver fmr2_pnp_driver = {
3163491a88eSOndrej Zary 	.name		= "radio-sf16fmr2",
3173491a88eSOndrej Zary 	.id_table	= fmr2_pnp_ids,
3183491a88eSOndrej Zary 	.probe		= fmr2_pnp_probe,
3194c62e976SGreg Kroah-Hartman 	.remove		= fmr2_pnp_remove,
3203491a88eSOndrej Zary };
3213491a88eSOndrej Zary 
fmr2_init(void)322d4ecc83bSHans Verkuil static int __init fmr2_init(void)
323d4ecc83bSHans Verkuil {
3243491a88eSOndrej Zary 	int ret;
3253491a88eSOndrej Zary 
3263491a88eSOndrej Zary 	ret = pnp_register_driver(&fmr2_pnp_driver);
3273491a88eSOndrej Zary 	if (!ret)
3283491a88eSOndrej Zary 		pnp_registered = true;
3293491a88eSOndrej Zary 	ret = isa_register_driver(&fmr2_isa_driver, 1);
3303491a88eSOndrej Zary 	if (!ret)
3313491a88eSOndrej Zary 		isa_registered = true;
3323491a88eSOndrej Zary 
3333491a88eSOndrej Zary 	return (pnp_registered || isa_registered) ? 0 : ret;
334d4ecc83bSHans Verkuil }
335d4ecc83bSHans Verkuil 
fmr2_exit(void)336d4ecc83bSHans Verkuil static void __exit fmr2_exit(void)
337d4ecc83bSHans Verkuil {
3383491a88eSOndrej Zary 	if (pnp_registered)
3393491a88eSOndrej Zary 		pnp_unregister_driver(&fmr2_pnp_driver);
3403491a88eSOndrej Zary 	if (isa_registered)
3413491a88eSOndrej Zary 		isa_unregister_driver(&fmr2_isa_driver);
3421da177e4SLinus Torvalds }
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds module_init(fmr2_init);
345c32a9d71SHans Verkuil module_exit(fmr2_exit);
346