radio-maxiradio.c 5.7 KB
Newer Older
1 2
/*
 * Guillemot Maxi Radio FM 2000 PCI radio card driver for Linux
L
Linus Torvalds 已提交
3 4 5 6 7 8
 * (C) 2001 Dimitromanolakis Apostolos <apdim@grecian.net>
 *
 * Based in the radio Maestro PCI driver. Actually it uses the same chip
 * for radio but different pci controller.
 *
 * I didn't have any specs I reversed engineered the protocol from
9
 * the windows driver (radio.dll).
L
Linus Torvalds 已提交
10 11
 *
 * The card uses the TEA5757 chip that includes a search function but it
12
 * is useless as I haven't found any way to read back the frequency. If
L
Linus Torvalds 已提交
13 14 15
 * anybody does please mail me.
 *
 * For the pdf file see:
16
 * http://www.nxp.com/acrobat_download2/expired_datasheets/TEA5757_5759_3.pdf 
L
Linus Torvalds 已提交
17 18 19 20 21 22
 *
 *
 * CHANGES:
 *   0.75b
 *     - better pci interface thanks to Francois Romieu <romieu@cogenit.fr>
 *
23
 *   0.75      Sun Feb  4 22:51:27 EET 2001
L
Linus Torvalds 已提交
24 25 26
 *     - tiding up
 *     - removed support for multiple devices as it didn't work anyway
 *
27
 * BUGS:
L
Linus Torvalds 已提交
28 29
 *   - card unmutes if you change frequency
 *
30 31 32
 * (c) 2006, 2007 by Mauro Carvalho Chehab <mchehab@infradead.org>:
 *	- Conversion to V4L2 API
 *      - Uses video_ioctl2 for parsing and to add debug support
L
Linus Torvalds 已提交
33 34 35 36 37 38 39
 */


#include <linux/module.h>
#include <linux/init.h>
#include <linux/ioport.h>
#include <linux/delay.h>
40
#include <linux/mutex.h>
L
Linus Torvalds 已提交
41
#include <linux/pci.h>
42
#include <linux/videodev2.h>
43
#include <linux/io.h>
44
#include <linux/slab.h>
45
#include <sound/tea575x-tuner.h>
46
#include <media/v4l2-device.h>
47
#include <media/v4l2-ioctl.h>
48 49 50
#include <media/v4l2-fh.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-event.h>
51

52
MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net");
53
MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000.");
54
MODULE_LICENSE("GPL");
55
MODULE_VERSION("1.0.0");
56 57

static int radio_nr = -1;
58 59
module_param(radio_nr, int, 0644);
MODULE_PARM_DESC(radio_nr, "Radio device number");
L
Linus Torvalds 已提交
60 61

/* TEA5757 pin mappings */
62
static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
L
Linus Torvalds 已提交
63

64
static atomic_t maxiradio_instance = ATOMIC_INIT(0);
L
Linus Torvalds 已提交
65

66 67
#define PCI_VENDOR_ID_GUILLEMOT 0x5046
#define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
L
Linus Torvalds 已提交
68

69
struct maxiradio
70
{
71
	struct snd_tea575x tea;
72 73
	struct v4l2_device v4l2_dev;
	struct pci_dev *pdev;
L
Linus Torvalds 已提交
74

75
	u16	io;	/* base of radio io */
76
};
L
Linus Torvalds 已提交
77

78
static inline struct maxiradio *to_maxiradio(struct v4l2_device *v4l2_dev)
L
Linus Torvalds 已提交
79
{
80
	return container_of(v4l2_dev, struct maxiradio, v4l2_dev);
L
Linus Torvalds 已提交
81 82
}

83
static void maxiradio_tea575x_set_pins(struct snd_tea575x *tea, u8 pins)
84
{
85 86
	struct maxiradio *dev = tea->private_data;
	u8 bits = 0;
87

88 89 90 91
	bits |= (pins & TEA575X_DATA) ? data : 0;
	bits |= (pins & TEA575X_CLK)  ? clk  : 0;
	bits |= (pins & TEA575X_WREN) ? wren : 0;
	bits |= power;
L
Linus Torvalds 已提交
92

93
	outb(bits, dev->io);
94 95
}

96 97 98
/* Note: this card cannot read out the data of the shift registers,
   only the mono/stereo pin works. */
static u8 maxiradio_tea575x_get_pins(struct snd_tea575x *tea)
L
Linus Torvalds 已提交
99
{
100 101
	struct maxiradio *dev = tea->private_data;
	u8 bits = inb(dev->io);
102

103 104
	return  ((bits & data) ? TEA575X_DATA : 0) |
		((bits & mo_st) ? TEA575X_MOST : 0);
105
}
106

107
static void maxiradio_tea575x_set_direction(struct snd_tea575x *tea, bool output)
108
{
109 110
}

111 112 113 114
static struct snd_tea575x_ops maxiradio_tea_ops = {
	.set_pins = maxiradio_tea575x_set_pins,
	.get_pins = maxiradio_tea575x_get_pins,
	.set_direction = maxiradio_tea575x_set_direction,
115 116
};

117
static int __devinit maxiradio_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
L
Linus Torvalds 已提交
118
{
119 120 121 122 123 124 125 126 127 128 129
	struct maxiradio *dev;
	struct v4l2_device *v4l2_dev;
	int retval = -ENOMEM;

	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
	if (dev == NULL) {
		dev_err(&pdev->dev, "not enough memory\n");
		return -ENOMEM;
	}

	v4l2_dev = &dev->v4l2_dev;
130
	v4l2_device_set_name(v4l2_dev, "maxiradio", &maxiradio_instance);
131 132 133 134 135 136

	retval = v4l2_device_register(&pdev->dev, v4l2_dev);
	if (retval < 0) {
		v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
		goto errfr;
	}
137 138 139 140 141 142 143 144 145 146 147 148
	dev->tea.private_data = dev;
	dev->tea.ops = &maxiradio_tea_ops;
	/* The data pin cannot be read. This may be a hardware limitation, or
	   we just don't know how to read it. */
	dev->tea.cannot_read_data = true;
	dev->tea.v4l2_dev = v4l2_dev;
	dev->tea.radio_nr = radio_nr;
	strlcpy(dev->tea.card, "Maxi Radio FM2000", sizeof(dev->tea.card));
	snprintf(dev->tea.bus_info, sizeof(dev->tea.bus_info),
			"PCI:%s", pci_name(pdev));

	retval = -ENODEV;
149 150

	if (!request_region(pci_resource_start(pdev, 0),
151 152 153
			   pci_resource_len(pdev, 0), v4l2_dev->name)) {
		dev_err(&pdev->dev, "can't reserve I/O ports\n");
		goto err_hdl;
L
Linus Torvalds 已提交
154 155 156
	}

	if (pci_enable_device(pdev))
157
		goto err_out_free_region;
L
Linus Torvalds 已提交
158

159
	dev->io = pci_resource_start(pdev, 0);
160
	if (snd_tea575x_init(&dev->tea, THIS_MODULE)) {
161
		printk(KERN_ERR "radio-maxiradio: Unable to detect TEA575x tuner\n");
162
		goto err_out_free_region;
L
Linus Torvalds 已提交
163 164 165 166 167
	}
	return 0;

err_out_free_region:
	release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
168
err_hdl:
169 170 171
	v4l2_device_unregister(v4l2_dev);
errfr:
	kfree(dev);
172
	return retval;
L
Linus Torvalds 已提交
173 174
}

175
static void __devexit maxiradio_remove(struct pci_dev *pdev)
L
Linus Torvalds 已提交
176
{
177 178 179
	struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
	struct maxiradio *dev = to_maxiradio(v4l2_dev);

180 181 182 183
	snd_tea575x_exit(&dev->tea);
	/* Turn off power */
	outb(0, dev->io);
	v4l2_device_unregister(v4l2_dev);
L
Linus Torvalds 已提交
184 185 186 187 188 189
	release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
}

static struct pci_device_id maxiradio_pci_tbl[] = {
	{ PCI_VENDOR_ID_GUILLEMOT, PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO,
		PCI_ANY_ID, PCI_ANY_ID, },
190
	{ 0 }
L
Linus Torvalds 已提交
191 192 193 194 195 196 197
};

MODULE_DEVICE_TABLE(pci, maxiradio_pci_tbl);

static struct pci_driver maxiradio_driver = {
	.name		= "radio-maxiradio",
	.id_table	= maxiradio_pci_tbl,
198 199
	.probe		= maxiradio_probe,
	.remove		= __devexit_p(maxiradio_remove),
L
Linus Torvalds 已提交
200 201
};

202
static int __init maxiradio_init(void)
L
Linus Torvalds 已提交
203
{
204
	return pci_register_driver(&maxiradio_driver);
L
Linus Torvalds 已提交
205 206
}

207
static void __exit maxiradio_exit(void)
L
Linus Torvalds 已提交
208 209 210 211
{
	pci_unregister_driver(&maxiradio_driver);
}

212 213
module_init(maxiradio_init);
module_exit(maxiradio_exit);