Commit | Line | Data |
---|---|---|
09c434b8 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
4286c6f6 MCC |
2 | /* |
3 | * Guillemot Maxi Radio FM 2000 PCI radio card driver for Linux | |
1da177e4 LT |
4 | * (C) 2001 Dimitromanolakis Apostolos <apdim@grecian.net> |
5 | * | |
6 | * Based in the radio Maestro PCI driver. Actually it uses the same chip | |
7 | * for radio but different pci controller. | |
8 | * | |
9 | * I didn't have any specs I reversed engineered the protocol from | |
4286c6f6 | 10 | * the windows driver (radio.dll). |
1da177e4 LT |
11 | * |
12 | * The card uses the TEA5757 chip that includes a search function but it | |
4286c6f6 | 13 | * is useless as I haven't found any way to read back the frequency. If |
1da177e4 LT |
14 | * anybody does please mail me. |
15 | * | |
16 | * For the pdf file see: | |
4a3fad70 | 17 | * http://www.nxp.com/acrobat_download2/expired_datasheets/TEA5757_5759_3.pdf |
1da177e4 LT |
18 | * |
19 | * | |
20 | * CHANGES: | |
21 | * 0.75b | |
22 | * - better pci interface thanks to Francois Romieu <romieu@cogenit.fr> | |
23 | * | |
e84fef6b | 24 | * 0.75 Sun Feb 4 22:51:27 EET 2001 |
1da177e4 LT |
25 | * - tiding up |
26 | * - removed support for multiple devices as it didn't work anyway | |
27 | * | |
4286c6f6 | 28 | * BUGS: |
1da177e4 LT |
29 | * - card unmutes if you change frequency |
30 | * | |
32590819 | 31 | * (c) 2006, 2007 by Mauro Carvalho Chehab <mchehab@kernel.org>: |
06470ed6 MCC |
32 | * - Conversion to V4L2 API |
33 | * - Uses video_ioctl2 for parsing and to add debug support | |
1da177e4 LT |
34 | */ |
35 | ||
36 | ||
37 | #include <linux/module.h> | |
38 | #include <linux/init.h> | |
39 | #include <linux/ioport.h> | |
40 | #include <linux/delay.h> | |
3593cab5 | 41 | #include <linux/mutex.h> |
1da177e4 | 42 | #include <linux/pci.h> |
e84fef6b | 43 | #include <linux/videodev2.h> |
2710e6aa | 44 | #include <linux/io.h> |
5a0e3ad6 | 45 | #include <linux/slab.h> |
d647f0b7 | 46 | #include <media/drv-intf/tea575x.h> |
2710e6aa | 47 | #include <media/v4l2-device.h> |
35ea11ff | 48 | #include <media/v4l2-ioctl.h> |
cfb19b0a HV |
49 | #include <media/v4l2-fh.h> |
50 | #include <media/v4l2-ctrls.h> | |
51 | #include <media/v4l2-event.h> | |
29834c1a | 52 | |
2710e6aa | 53 | MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net"); |
cfb19b0a | 54 | MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000."); |
2710e6aa | 55 | MODULE_LICENSE("GPL"); |
cfb19b0a | 56 | MODULE_VERSION("1.0.0"); |
2710e6aa HV |
57 | |
58 | static int radio_nr = -1; | |
cfb19b0a HV |
59 | module_param(radio_nr, int, 0644); |
60 | MODULE_PARM_DESC(radio_nr, "Radio device number"); | |
1da177e4 LT |
61 | |
62 | /* TEA5757 pin mappings */ | |
2710e6aa | 63 | static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16; |
1da177e4 | 64 | |
cfb19b0a | 65 | static atomic_t maxiradio_instance = ATOMIC_INIT(0); |
1da177e4 | 66 | |
cfb19b0a HV |
67 | #define PCI_VENDOR_ID_GUILLEMOT 0x5046 |
68 | #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001 | |
1da177e4 | 69 | |
2710e6aa | 70 | struct maxiradio |
3ca685aa | 71 | { |
cfb19b0a | 72 | struct snd_tea575x tea; |
2710e6aa | 73 | struct v4l2_device v4l2_dev; |
2710e6aa | 74 | struct pci_dev *pdev; |
1da177e4 | 75 | |
2710e6aa | 76 | u16 io; /* base of radio io */ |
712642b8 | 77 | }; |
1da177e4 | 78 | |
2710e6aa | 79 | static inline struct maxiradio *to_maxiradio(struct v4l2_device *v4l2_dev) |
1da177e4 | 80 | { |
2710e6aa | 81 | return container_of(v4l2_dev, struct maxiradio, v4l2_dev); |
1da177e4 LT |
82 | } |
83 | ||
cfb19b0a | 84 | static void maxiradio_tea575x_set_pins(struct snd_tea575x *tea, u8 pins) |
4286c6f6 | 85 | { |
cfb19b0a HV |
86 | struct maxiradio *dev = tea->private_data; |
87 | u8 bits = 0; | |
f1557ceb | 88 | |
cfb19b0a HV |
89 | bits |= (pins & TEA575X_DATA) ? data : 0; |
90 | bits |= (pins & TEA575X_CLK) ? clk : 0; | |
91 | bits |= (pins & TEA575X_WREN) ? wren : 0; | |
92 | bits |= power; | |
1da177e4 | 93 | |
cfb19b0a | 94 | outb(bits, dev->io); |
06470ed6 MCC |
95 | } |
96 | ||
cfb19b0a HV |
97 | /* Note: this card cannot read out the data of the shift registers, |
98 | only the mono/stereo pin works. */ | |
99 | static u8 maxiradio_tea575x_get_pins(struct snd_tea575x *tea) | |
1da177e4 | 100 | { |
cfb19b0a HV |
101 | struct maxiradio *dev = tea->private_data; |
102 | u8 bits = inb(dev->io); | |
4286c6f6 | 103 | |
cfb19b0a HV |
104 | return ((bits & data) ? TEA575X_DATA : 0) | |
105 | ((bits & mo_st) ? TEA575X_MOST : 0); | |
06470ed6 | 106 | } |
e84fef6b | 107 | |
cfb19b0a | 108 | static void maxiradio_tea575x_set_direction(struct snd_tea575x *tea, bool output) |
06470ed6 | 109 | { |
140dcc46 MCC |
110 | } |
111 | ||
22dbec26 | 112 | static const struct snd_tea575x_ops maxiradio_tea_ops = { |
cfb19b0a HV |
113 | .set_pins = maxiradio_tea575x_set_pins, |
114 | .get_pins = maxiradio_tea575x_get_pins, | |
115 | .set_direction = maxiradio_tea575x_set_direction, | |
2710e6aa HV |
116 | }; |
117 | ||
4c62e976 GKH |
118 | static int maxiradio_probe(struct pci_dev *pdev, |
119 | const struct pci_device_id *ent) | |
1da177e4 | 120 | { |
2710e6aa HV |
121 | struct maxiradio *dev; |
122 | struct v4l2_device *v4l2_dev; | |
123 | int retval = -ENOMEM; | |
124 | ||
125 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | |
126 | if (dev == NULL) { | |
127 | dev_err(&pdev->dev, "not enough memory\n"); | |
128 | return -ENOMEM; | |
129 | } | |
130 | ||
131 | v4l2_dev = &dev->v4l2_dev; | |
cfb19b0a | 132 | v4l2_device_set_name(v4l2_dev, "maxiradio", &maxiradio_instance); |
2710e6aa HV |
133 | |
134 | retval = v4l2_device_register(&pdev->dev, v4l2_dev); | |
135 | if (retval < 0) { | |
136 | v4l2_err(v4l2_dev, "Could not register v4l2_device\n"); | |
137 | goto errfr; | |
138 | } | |
cfb19b0a HV |
139 | dev->tea.private_data = dev; |
140 | dev->tea.ops = &maxiradio_tea_ops; | |
141 | /* The data pin cannot be read. This may be a hardware limitation, or | |
142 | we just don't know how to read it. */ | |
143 | dev->tea.cannot_read_data = true; | |
144 | dev->tea.v4l2_dev = v4l2_dev; | |
145 | dev->tea.radio_nr = radio_nr; | |
c0decac1 | 146 | strscpy(dev->tea.card, "Maxi Radio FM2000", sizeof(dev->tea.card)); |
cfb19b0a HV |
147 | snprintf(dev->tea.bus_info, sizeof(dev->tea.bus_info), |
148 | "PCI:%s", pci_name(pdev)); | |
149 | ||
150 | retval = -ENODEV; | |
2710e6aa HV |
151 | |
152 | if (!request_region(pci_resource_start(pdev, 0), | |
cfb19b0a HV |
153 | pci_resource_len(pdev, 0), v4l2_dev->name)) { |
154 | dev_err(&pdev->dev, "can't reserve I/O ports\n"); | |
155 | goto err_hdl; | |
1da177e4 LT |
156 | } |
157 | ||
158 | if (pci_enable_device(pdev)) | |
4286c6f6 | 159 | goto err_out_free_region; |
1da177e4 | 160 | |
2710e6aa | 161 | dev->io = pci_resource_start(pdev, 0); |
5daf53a6 | 162 | if (snd_tea575x_init(&dev->tea, THIS_MODULE)) { |
cfb19b0a | 163 | printk(KERN_ERR "radio-maxiradio: Unable to detect TEA575x tuner\n"); |
4286c6f6 | 164 | goto err_out_free_region; |
1da177e4 | 165 | } |
1da177e4 LT |
166 | return 0; |
167 | ||
168 | err_out_free_region: | |
169 | release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0)); | |
cfb19b0a | 170 | err_hdl: |
2710e6aa HV |
171 | v4l2_device_unregister(v4l2_dev); |
172 | errfr: | |
173 | kfree(dev); | |
cfb19b0a | 174 | return retval; |
1da177e4 LT |
175 | } |
176 | ||
4c62e976 | 177 | static void maxiradio_remove(struct pci_dev *pdev) |
1da177e4 | 178 | { |
2710e6aa HV |
179 | struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev); |
180 | struct maxiradio *dev = to_maxiradio(v4l2_dev); | |
181 | ||
cfb19b0a HV |
182 | snd_tea575x_exit(&dev->tea); |
183 | /* Turn off power */ | |
184 | outb(0, dev->io); | |
185 | v4l2_device_unregister(v4l2_dev); | |
1da177e4 | 186 | release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0)); |
04bc9365 | 187 | kfree(dev); |
1da177e4 LT |
188 | } |
189 | ||
c181efd2 | 190 | static const struct pci_device_id maxiradio_pci_tbl[] = { |
1da177e4 LT |
191 | { PCI_VENDOR_ID_GUILLEMOT, PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO, |
192 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2710e6aa | 193 | { 0 } |
1da177e4 LT |
194 | }; |
195 | ||
196 | MODULE_DEVICE_TABLE(pci, maxiradio_pci_tbl); | |
197 | ||
198 | static struct pci_driver maxiradio_driver = { | |
199 | .name = "radio-maxiradio", | |
200 | .id_table = maxiradio_pci_tbl, | |
cfb19b0a | 201 | .probe = maxiradio_probe, |
4c62e976 | 202 | .remove = maxiradio_remove, |
1da177e4 LT |
203 | }; |
204 | ||
725d7b71 | 205 | module_pci_driver(maxiradio_driver); |