2 * timberdale.c timberdale FPGA MFD driver
3 * Copyright (c) 2009 Intel Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/pci.h>
26 #include <linux/msi.h>
27 #include <linux/mfd/core.h>
28 #include <linux/slab.h>
30 #include <linux/timb_gpio.h>
32 #include <linux/i2c.h>
33 #include <linux/i2c-ocores.h>
34 #include <linux/i2c-xiic.h>
35 #include <linux/i2c/tsc2007.h>
37 #include <linux/spi/spi.h>
38 #include <linux/spi/xilinx_spi.h>
39 #include <linux/spi/max7301.h>
40 #include <linux/spi/mc33880.h>
42 #include <media/timb_radio.h>
44 #include <linux/timb_dma.h>
46 #include "timberdale.h"
48 #define DRIVER_NAME "timberdale"
50 struct timberdale_device {
51 resource_size_t ctl_mapbase;
52 unsigned char __iomem *ctl_membase;
60 /*--------------------------------------------------------------------------*/
62 static struct tsc2007_platform_data timberdale_tsc2007_platform_data = {
67 static struct i2c_board_info timberdale_i2c_board_info[] = {
69 I2C_BOARD_INFO("tsc2007", 0x48),
70 .platform_data = &timberdale_tsc2007_platform_data,
71 .irq = IRQ_TIMBERDALE_TSC_INT
75 static __devinitdata struct xiic_i2c_platform_data
76 timberdale_xiic_platform_data = {
77 .devices = timberdale_i2c_board_info,
78 .num_devices = ARRAY_SIZE(timberdale_i2c_board_info)
81 static __devinitdata struct ocores_i2c_platform_data
82 timberdale_ocores_platform_data = {
85 .devices = timberdale_i2c_board_info,
86 .num_devices = ARRAY_SIZE(timberdale_i2c_board_info)
89 static const __devinitconst struct resource timberdale_xiic_resources[] = {
93 .flags = IORESOURCE_MEM,
96 .start = IRQ_TIMBERDALE_I2C,
97 .end = IRQ_TIMBERDALE_I2C,
98 .flags = IORESOURCE_IRQ,
102 static const __devinitconst struct resource timberdale_ocores_resources[] = {
104 .start = OCORESOFFSET,
106 .flags = IORESOURCE_MEM,
109 .start = IRQ_TIMBERDALE_I2C,
110 .end = IRQ_TIMBERDALE_I2C,
111 .flags = IORESOURCE_IRQ,
115 const struct max7301_platform_data timberdale_max7301_platform_data = {
119 const struct mc33880_platform_data timberdale_mc33880_platform_data = {
123 static struct spi_board_info timberdale_spi_16bit_board_info[] = {
125 .modalias = "max7301",
126 .max_speed_hz = 26000,
129 .platform_data = &timberdale_max7301_platform_data
133 static struct spi_board_info timberdale_spi_8bit_board_info[] = {
135 .modalias = "mc33880",
136 .max_speed_hz = 4000,
139 .platform_data = &timberdale_mc33880_platform_data
143 static __devinitdata struct xspi_platform_data timberdale_xspi_platform_data = {
145 .little_endian = true,
146 /* bits per word and devices will be filled in runtime depending
151 static const __devinitconst struct resource timberdale_spi_resources[] = {
155 .flags = IORESOURCE_MEM,
158 .start = IRQ_TIMBERDALE_SPI,
159 .end = IRQ_TIMBERDALE_SPI,
160 .flags = IORESOURCE_IRQ,
164 static const __devinitconst struct resource timberdale_eth_resources[] = {
168 .flags = IORESOURCE_MEM,
171 .start = IRQ_TIMBERDALE_ETHSW_IF,
172 .end = IRQ_TIMBERDALE_ETHSW_IF,
173 .flags = IORESOURCE_IRQ,
177 static __devinitdata struct timbgpio_platform_data
178 timberdale_gpio_platform_data = {
180 .nr_pins = GPIO_NR_PINS,
184 static const __devinitconst struct resource timberdale_gpio_resources[] = {
188 .flags = IORESOURCE_MEM,
191 .start = IRQ_TIMBERDALE_GPIO,
192 .end = IRQ_TIMBERDALE_GPIO,
193 .flags = IORESOURCE_IRQ,
197 static const __devinitconst struct resource timberdale_mlogicore_resources[] = {
199 .start = MLCOREOFFSET,
201 .flags = IORESOURCE_MEM,
204 .start = IRQ_TIMBERDALE_MLCORE,
205 .end = IRQ_TIMBERDALE_MLCORE,
206 .flags = IORESOURCE_IRQ,
209 .start = IRQ_TIMBERDALE_MLCORE_BUF,
210 .end = IRQ_TIMBERDALE_MLCORE_BUF,
211 .flags = IORESOURCE_IRQ,
215 static const __devinitconst struct resource timberdale_uart_resources[] = {
219 .flags = IORESOURCE_MEM,
222 .start = IRQ_TIMBERDALE_UART,
223 .end = IRQ_TIMBERDALE_UART,
224 .flags = IORESOURCE_IRQ,
228 static const __devinitconst struct resource timberdale_uartlite_resources[] = {
230 .start = UARTLITEOFFSET,
232 .flags = IORESOURCE_MEM,
235 .start = IRQ_TIMBERDALE_UARTLITE,
236 .end = IRQ_TIMBERDALE_UARTLITE,
237 .flags = IORESOURCE_IRQ,
241 static const __devinitconst struct resource timberdale_radio_resources[] = {
245 .flags = IORESOURCE_MEM,
248 .start = IRQ_TIMBERDALE_RDS,
249 .end = IRQ_TIMBERDALE_RDS,
250 .flags = IORESOURCE_IRQ,
254 static __devinitdata struct i2c_board_info timberdale_tef6868_i2c_board_info = {
255 I2C_BOARD_INFO("tef6862", 0x60)
258 static __devinitdata struct i2c_board_info timberdale_saa7706_i2c_board_info = {
259 I2C_BOARD_INFO("saa7706h", 0x1C)
262 static __devinitdata struct timb_radio_platform_data
263 timberdale_radio_platform_data = {
266 .module_name = "tef6862",
267 .info = &timberdale_tef6868_i2c_board_info
270 .module_name = "saa7706h",
271 .info = &timberdale_saa7706_i2c_board_info
275 static __devinitdata struct timb_dma_platform_data timb_dma_platform_data = {
282 .descriptor_elements = 1
288 .descriptor_elements = 1
294 .descriptor_elements = 1
300 .descriptor_elements = 1
305 .bytes_per_line = 1440,
307 .descriptor_elements = 16
310 /* Video framedrop */
323 .descriptor_elements = 1
329 .descriptor_elements = 1
334 static const __devinitconst struct resource timberdale_dma_resources[] = {
338 .flags = IORESOURCE_MEM,
341 .start = IRQ_TIMBERDALE_DMA,
342 .end = IRQ_TIMBERDALE_DMA,
343 .flags = IORESOURCE_IRQ,
347 static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg0[] = {
350 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
351 .resources = timberdale_dma_resources,
352 .platform_data = &timb_dma_platform_data,
353 .data_size = sizeof(timb_dma_platform_data),
357 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
358 .resources = timberdale_uart_resources,
362 .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
363 .resources = timberdale_xiic_resources,
364 .platform_data = &timberdale_xiic_platform_data,
365 .data_size = sizeof(timberdale_xiic_platform_data),
369 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
370 .resources = timberdale_gpio_resources,
371 .platform_data = &timberdale_gpio_platform_data,
372 .data_size = sizeof(timberdale_gpio_platform_data),
375 .name = "timb-radio",
376 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
377 .resources = timberdale_radio_resources,
378 .platform_data = &timberdale_radio_platform_data,
379 .data_size = sizeof(timberdale_radio_platform_data),
382 .name = "xilinx_spi",
383 .num_resources = ARRAY_SIZE(timberdale_spi_resources),
384 .resources = timberdale_spi_resources,
385 .platform_data = &timberdale_xspi_platform_data,
386 .data_size = sizeof(timberdale_xspi_platform_data),
390 .num_resources = ARRAY_SIZE(timberdale_eth_resources),
391 .resources = timberdale_eth_resources,
395 static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg1[] = {
398 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
399 .resources = timberdale_dma_resources,
400 .platform_data = &timb_dma_platform_data,
401 .data_size = sizeof(timb_dma_platform_data),
405 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
406 .resources = timberdale_uart_resources,
410 .num_resources = ARRAY_SIZE(timberdale_uartlite_resources),
411 .resources = timberdale_uartlite_resources,
415 .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
416 .resources = timberdale_xiic_resources,
417 .platform_data = &timberdale_xiic_platform_data,
418 .data_size = sizeof(timberdale_xiic_platform_data),
422 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
423 .resources = timberdale_gpio_resources,
424 .platform_data = &timberdale_gpio_platform_data,
425 .data_size = sizeof(timberdale_gpio_platform_data),
428 .name = "timb-mlogicore",
429 .num_resources = ARRAY_SIZE(timberdale_mlogicore_resources),
430 .resources = timberdale_mlogicore_resources,
433 .name = "timb-radio",
434 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
435 .resources = timberdale_radio_resources,
436 .platform_data = &timberdale_radio_platform_data,
437 .data_size = sizeof(timberdale_radio_platform_data),
440 .name = "xilinx_spi",
441 .num_resources = ARRAY_SIZE(timberdale_spi_resources),
442 .resources = timberdale_spi_resources,
443 .platform_data = &timberdale_xspi_platform_data,
444 .data_size = sizeof(timberdale_xspi_platform_data),
448 .num_resources = ARRAY_SIZE(timberdale_eth_resources),
449 .resources = timberdale_eth_resources,
453 static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg2[] = {
456 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
457 .resources = timberdale_dma_resources,
458 .platform_data = &timb_dma_platform_data,
459 .data_size = sizeof(timb_dma_platform_data),
463 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
464 .resources = timberdale_uart_resources,
468 .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
469 .resources = timberdale_xiic_resources,
470 .platform_data = &timberdale_xiic_platform_data,
471 .data_size = sizeof(timberdale_xiic_platform_data),
475 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
476 .resources = timberdale_gpio_resources,
477 .platform_data = &timberdale_gpio_platform_data,
478 .data_size = sizeof(timberdale_gpio_platform_data),
481 .name = "timb-radio",
482 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
483 .resources = timberdale_radio_resources,
484 .platform_data = &timberdale_radio_platform_data,
485 .data_size = sizeof(timberdale_radio_platform_data),
488 .name = "xilinx_spi",
489 .num_resources = ARRAY_SIZE(timberdale_spi_resources),
490 .resources = timberdale_spi_resources,
491 .platform_data = &timberdale_xspi_platform_data,
492 .data_size = sizeof(timberdale_xspi_platform_data),
496 static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg3[] = {
499 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
500 .resources = timberdale_dma_resources,
501 .platform_data = &timb_dma_platform_data,
502 .data_size = sizeof(timb_dma_platform_data),
506 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
507 .resources = timberdale_uart_resources,
510 .name = "ocores-i2c",
511 .num_resources = ARRAY_SIZE(timberdale_ocores_resources),
512 .resources = timberdale_ocores_resources,
513 .platform_data = &timberdale_ocores_platform_data,
514 .data_size = sizeof(timberdale_ocores_platform_data),
518 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
519 .resources = timberdale_gpio_resources,
520 .platform_data = &timberdale_gpio_platform_data,
521 .data_size = sizeof(timberdale_gpio_platform_data),
524 .name = "timb-radio",
525 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
526 .resources = timberdale_radio_resources,
527 .platform_data = &timberdale_radio_platform_data,
528 .data_size = sizeof(timberdale_radio_platform_data),
531 .name = "xilinx_spi",
532 .num_resources = ARRAY_SIZE(timberdale_spi_resources),
533 .resources = timberdale_spi_resources,
534 .platform_data = &timberdale_xspi_platform_data,
535 .data_size = sizeof(timberdale_xspi_platform_data),
539 .num_resources = ARRAY_SIZE(timberdale_eth_resources),
540 .resources = timberdale_eth_resources,
544 static const __devinitconst struct resource timberdale_sdhc_resources[] = {
545 /* located in bar 1 and bar 2 */
547 .start = SDHC0OFFSET,
549 .flags = IORESOURCE_MEM,
552 .start = IRQ_TIMBERDALE_SDHC,
553 .end = IRQ_TIMBERDALE_SDHC,
554 .flags = IORESOURCE_IRQ,
558 static __devinitdata struct mfd_cell timberdale_cells_bar1[] = {
561 .num_resources = ARRAY_SIZE(timberdale_sdhc_resources),
562 .resources = timberdale_sdhc_resources,
566 static __devinitdata struct mfd_cell timberdale_cells_bar2[] = {
569 .num_resources = ARRAY_SIZE(timberdale_sdhc_resources),
570 .resources = timberdale_sdhc_resources,
574 static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr,
577 struct pci_dev *pdev = to_pci_dev(dev);
578 struct timberdale_device *priv = pci_get_drvdata(pdev);
580 return sprintf(buf, "%d.%d.%d\n", priv->fw.major, priv->fw.minor,
584 static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
586 /*--------------------------------------------------------------------------*/
588 static int __devinit timb_probe(struct pci_dev *dev,
589 const struct pci_device_id *id)
591 struct timberdale_device *priv;
593 resource_size_t mapbase;
594 struct msix_entry *msix_entries = NULL;
597 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
601 pci_set_drvdata(dev, priv);
603 err = pci_enable_device(dev);
607 mapbase = pci_resource_start(dev, 0);
609 dev_err(&dev->dev, "No resource\n");
613 /* create a resource for the PCI master register */
614 priv->ctl_mapbase = mapbase + CHIPCTLOFFSET;
615 if (!request_mem_region(priv->ctl_mapbase, CHIPCTLSIZE, "timb-ctl")) {
616 dev_err(&dev->dev, "Failed to request ctl mem\n");
620 priv->ctl_membase = ioremap(priv->ctl_mapbase, CHIPCTLSIZE);
621 if (!priv->ctl_membase) {
622 dev_err(&dev->dev, "ioremap failed for ctl mem\n");
626 /* read the HW config */
627 priv->fw.major = ioread32(priv->ctl_membase + TIMB_REV_MAJOR);
628 priv->fw.minor = ioread32(priv->ctl_membase + TIMB_REV_MINOR);
629 priv->fw.config = ioread32(priv->ctl_membase + TIMB_HW_CONFIG);
631 if (priv->fw.major > TIMB_SUPPORTED_MAJOR) {
632 dev_err(&dev->dev, "The driver supports an older "
633 "version of the FPGA, please update the driver to "
634 "support %d.%d\n", priv->fw.major, priv->fw.minor);
637 if (priv->fw.major < TIMB_SUPPORTED_MAJOR ||
638 priv->fw.minor < TIMB_REQUIRED_MINOR) {
639 dev_err(&dev->dev, "The FPGA image is too old (%d.%d), "
640 "please upgrade the FPGA to at least: %d.%d\n",
641 priv->fw.major, priv->fw.minor,
642 TIMB_SUPPORTED_MAJOR, TIMB_REQUIRED_MINOR);
646 msix_entries = kzalloc(TIMBERDALE_NR_IRQS * sizeof(*msix_entries),
651 for (i = 0; i < TIMBERDALE_NR_IRQS; i++)
652 msix_entries[i].entry = i;
654 err = pci_enable_msix(dev, msix_entries, TIMBERDALE_NR_IRQS);
657 "MSI-X init failed: %d, expected entries: %d\n",
658 err, TIMBERDALE_NR_IRQS);
662 err = device_create_file(&dev->dev, &dev_attr_fw_ver);
664 goto err_create_file;
666 /* Reset all FPGA PLB peripherals */
667 iowrite32(0x1, priv->ctl_membase + TIMB_SW_RST);
669 /* update IRQ offsets in I2C board info */
670 for (i = 0; i < ARRAY_SIZE(timberdale_i2c_board_info); i++)
671 timberdale_i2c_board_info[i].irq =
672 msix_entries[timberdale_i2c_board_info[i].irq].vector;
674 /* Update the SPI configuration depending on the HW (8 or 16 bit) */
675 if (priv->fw.config & TIMB_HW_CONFIG_SPI_8BIT) {
676 timberdale_xspi_platform_data.bits_per_word = 8;
677 timberdale_xspi_platform_data.devices =
678 timberdale_spi_8bit_board_info;
679 timberdale_xspi_platform_data.num_devices =
680 ARRAY_SIZE(timberdale_spi_8bit_board_info);
682 timberdale_xspi_platform_data.bits_per_word = 16;
683 timberdale_xspi_platform_data.devices =
684 timberdale_spi_16bit_board_info;
685 timberdale_xspi_platform_data.num_devices =
686 ARRAY_SIZE(timberdale_spi_16bit_board_info);
689 ip_setup = priv->fw.config & TIMB_HW_VER_MASK;
692 err = mfd_add_devices(&dev->dev, -1,
693 timberdale_cells_bar0_cfg0,
694 ARRAY_SIZE(timberdale_cells_bar0_cfg0),
695 &dev->resource[0], msix_entries[0].vector);
698 err = mfd_add_devices(&dev->dev, -1,
699 timberdale_cells_bar0_cfg1,
700 ARRAY_SIZE(timberdale_cells_bar0_cfg1),
701 &dev->resource[0], msix_entries[0].vector);
704 err = mfd_add_devices(&dev->dev, -1,
705 timberdale_cells_bar0_cfg2,
706 ARRAY_SIZE(timberdale_cells_bar0_cfg2),
707 &dev->resource[0], msix_entries[0].vector);
710 err = mfd_add_devices(&dev->dev, -1,
711 timberdale_cells_bar0_cfg3,
712 ARRAY_SIZE(timberdale_cells_bar0_cfg3),
713 &dev->resource[0], msix_entries[0].vector);
716 dev_err(&dev->dev, "Uknown IP setup: %d.%d.%d\n",
717 priv->fw.major, priv->fw.minor, ip_setup);
724 dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
728 err = mfd_add_devices(&dev->dev, 0,
729 timberdale_cells_bar1, ARRAY_SIZE(timberdale_cells_bar1),
730 &dev->resource[1], msix_entries[0].vector);
732 dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
736 /* only version 0 and 3 have the iNand routed to SDHCI */
737 if (((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER0) ||
738 ((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER3)) {
739 err = mfd_add_devices(&dev->dev, 1, timberdale_cells_bar2,
740 ARRAY_SIZE(timberdale_cells_bar2),
741 &dev->resource[2], msix_entries[0].vector);
743 dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
751 "Found Timberdale Card. Rev: %d.%d, HW config: 0x%02x\n",
752 priv->fw.major, priv->fw.minor, priv->fw.config);
757 mfd_remove_devices(&dev->dev);
759 device_remove_file(&dev->dev, &dev_attr_fw_ver);
761 pci_disable_msix(dev);
763 iounmap(priv->ctl_membase);
765 release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE);
767 pci_set_drvdata(dev, NULL);
769 pci_disable_device(dev);
773 pci_set_drvdata(dev, NULL);
777 static void __devexit timb_remove(struct pci_dev *dev)
779 struct timberdale_device *priv = pci_get_drvdata(dev);
781 mfd_remove_devices(&dev->dev);
783 device_remove_file(&dev->dev, &dev_attr_fw_ver);
785 iounmap(priv->ctl_membase);
786 release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE);
788 pci_disable_msix(dev);
789 pci_disable_device(dev);
790 pci_set_drvdata(dev, NULL);
794 static struct pci_device_id timberdale_pci_tbl[] = {
795 { PCI_DEVICE(PCI_VENDOR_ID_TIMB, PCI_DEVICE_ID_TIMB) },
798 MODULE_DEVICE_TABLE(pci, timberdale_pci_tbl);
800 static struct pci_driver timberdale_pci_driver = {
802 .id_table = timberdale_pci_tbl,
804 .remove = __devexit_p(timb_remove),
807 static int __init timberdale_init(void)
811 err = pci_register_driver(&timberdale_pci_driver);
814 "Failed to register PCI driver for %s device.\n",
815 timberdale_pci_driver.name);
819 printk(KERN_INFO "Driver for %s has been successfully registered.\n",
820 timberdale_pci_driver.name);
825 static void __exit timberdale_exit(void)
827 pci_unregister_driver(&timberdale_pci_driver);
829 printk(KERN_INFO "Driver for %s has been successfully unregistered.\n",
830 timberdale_pci_driver.name);
833 module_init(timberdale_init);
834 module_exit(timberdale_exit);
836 MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
837 MODULE_VERSION(DRV_VERSION);
838 MODULE_LICENSE("GPL v2");