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