1 // SPDX-License-Identifier: GPL-2.0-only
3 * timberdale.c timberdale FPGA MFD driver
4 * Copyright (c) 2009 Intel Corporation
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/pci.h>
14 #include <linux/mfd/core.h>
15 #include <linux/slab.h>
17 #include <linux/timb_gpio.h>
19 #include <linux/i2c.h>
20 #include <linux/platform_data/i2c-ocores.h>
21 #include <linux/platform_data/i2c-xiic.h>
23 #include <linux/spi/spi.h>
24 #include <linux/spi/xilinx_spi.h>
25 #include <linux/spi/max7301.h>
26 #include <linux/spi/mc33880.h>
28 #include <linux/platform_data/tsc2007.h>
29 #include <linux/platform_data/media/timb_radio.h>
30 #include <linux/platform_data/media/timb_video.h>
32 #include <linux/timb_dma.h>
34 #include <linux/ks8842.h>
36 #include "timberdale.h"
38 #define DRIVER_NAME "timberdale"
40 struct timberdale_device {
41 resource_size_t ctl_mapbase;
42 unsigned char __iomem *ctl_membase;
50 /*--------------------------------------------------------------------------*/
52 static struct tsc2007_platform_data timberdale_tsc2007_platform_data = {
57 static struct i2c_board_info timberdale_i2c_board_info[] = {
59 I2C_BOARD_INFO("tsc2007", 0x48),
60 .platform_data = &timberdale_tsc2007_platform_data,
61 .irq = IRQ_TIMBERDALE_TSC_INT
65 static struct xiic_i2c_platform_data
66 timberdale_xiic_platform_data = {
67 .devices = timberdale_i2c_board_info,
68 .num_devices = ARRAY_SIZE(timberdale_i2c_board_info)
71 static struct ocores_i2c_platform_data
72 timberdale_ocores_platform_data = {
75 .devices = timberdale_i2c_board_info,
76 .num_devices = ARRAY_SIZE(timberdale_i2c_board_info)
79 static const struct resource timberdale_xiic_resources[] = {
83 .flags = IORESOURCE_MEM,
86 .start = IRQ_TIMBERDALE_I2C,
87 .end = IRQ_TIMBERDALE_I2C,
88 .flags = IORESOURCE_IRQ,
92 static const struct resource timberdale_ocores_resources[] = {
94 .start = OCORESOFFSET,
96 .flags = IORESOURCE_MEM,
99 .start = IRQ_TIMBERDALE_I2C,
100 .end = IRQ_TIMBERDALE_I2C,
101 .flags = IORESOURCE_IRQ,
105 static const struct max7301_platform_data timberdale_max7301_platform_data = {
109 static const struct mc33880_platform_data timberdale_mc33880_platform_data = {
113 static struct spi_board_info timberdale_spi_16bit_board_info[] = {
115 .modalias = "max7301",
116 .max_speed_hz = 26000,
119 .platform_data = &timberdale_max7301_platform_data
123 static struct spi_board_info timberdale_spi_8bit_board_info[] = {
125 .modalias = "mc33880",
126 .max_speed_hz = 4000,
129 .platform_data = &timberdale_mc33880_platform_data
133 static struct xspi_platform_data timberdale_xspi_platform_data = {
135 /* bits per word and devices will be filled in runtime depending
140 static const struct resource timberdale_spi_resources[] = {
144 .flags = IORESOURCE_MEM,
147 .start = IRQ_TIMBERDALE_SPI,
148 .end = IRQ_TIMBERDALE_SPI,
149 .flags = IORESOURCE_IRQ,
153 static struct ks8842_platform_data
154 timberdale_ks8842_platform_data = {
155 .rx_dma_channel = DMA_ETH_RX,
156 .tx_dma_channel = DMA_ETH_TX
159 static const struct resource timberdale_eth_resources[] = {
163 .flags = IORESOURCE_MEM,
166 .start = IRQ_TIMBERDALE_ETHSW_IF,
167 .end = IRQ_TIMBERDALE_ETHSW_IF,
168 .flags = IORESOURCE_IRQ,
172 static struct timbgpio_platform_data
173 timberdale_gpio_platform_data = {
175 .nr_pins = GPIO_NR_PINS,
179 static const struct resource timberdale_gpio_resources[] = {
183 .flags = IORESOURCE_MEM,
186 .start = IRQ_TIMBERDALE_GPIO,
187 .end = IRQ_TIMBERDALE_GPIO,
188 .flags = IORESOURCE_IRQ,
192 static const struct resource timberdale_mlogicore_resources[] = {
194 .start = MLCOREOFFSET,
196 .flags = IORESOURCE_MEM,
199 .start = IRQ_TIMBERDALE_MLCORE,
200 .end = IRQ_TIMBERDALE_MLCORE,
201 .flags = IORESOURCE_IRQ,
204 .start = IRQ_TIMBERDALE_MLCORE_BUF,
205 .end = IRQ_TIMBERDALE_MLCORE_BUF,
206 .flags = IORESOURCE_IRQ,
210 static const struct resource timberdale_uart_resources[] = {
214 .flags = IORESOURCE_MEM,
217 .start = IRQ_TIMBERDALE_UART,
218 .end = IRQ_TIMBERDALE_UART,
219 .flags = IORESOURCE_IRQ,
223 static const struct resource timberdale_uartlite_resources[] = {
225 .start = UARTLITEOFFSET,
227 .flags = IORESOURCE_MEM,
230 .start = IRQ_TIMBERDALE_UARTLITE,
231 .end = IRQ_TIMBERDALE_UARTLITE,
232 .flags = IORESOURCE_IRQ,
236 static struct i2c_board_info timberdale_adv7180_i2c_board_info = {
237 /* Requires jumper JP9 to be off */
238 I2C_BOARD_INFO("adv7180", 0x42 >> 1),
239 .irq = IRQ_TIMBERDALE_ADV7180
242 static struct timb_video_platform_data
243 timberdale_video_platform_data = {
244 .dma_channel = DMA_VIDEO_RX,
247 .info = &timberdale_adv7180_i2c_board_info
251 static const struct resource
252 timberdale_radio_resources[] = {
256 .flags = IORESOURCE_MEM,
259 .start = IRQ_TIMBERDALE_RDS,
260 .end = IRQ_TIMBERDALE_RDS,
261 .flags = IORESOURCE_IRQ,
265 static struct i2c_board_info timberdale_tef6868_i2c_board_info = {
266 I2C_BOARD_INFO("tef6862", 0x60)
269 static struct i2c_board_info timberdale_saa7706_i2c_board_info = {
270 I2C_BOARD_INFO("saa7706h", 0x1C)
273 static struct timb_radio_platform_data
274 timberdale_radio_platform_data = {
276 .tuner = &timberdale_tef6868_i2c_board_info,
277 .dsp = &timberdale_saa7706_i2c_board_info
280 static const struct resource timberdale_video_resources[] = {
282 .start = LOGIWOFFSET,
284 .flags = IORESOURCE_MEM,
287 note that the "frame buffer" is located in DMA area
288 starting at 0x1200000
292 static struct timb_dma_platform_data timb_dma_platform_data = {
299 .descriptor_elements = 1
305 .descriptor_elements = 1
311 .descriptor_elements = 1
317 .descriptor_elements = 1
322 .bytes_per_line = 1440,
324 .descriptor_elements = 16
327 /* Video framedrop */
340 .descriptor_elements = 1
346 .descriptor_elements = 1
351 static const struct resource timberdale_dma_resources[] = {
355 .flags = IORESOURCE_MEM,
358 .start = IRQ_TIMBERDALE_DMA,
359 .end = IRQ_TIMBERDALE_DMA,
360 .flags = IORESOURCE_IRQ,
364 static const struct mfd_cell timberdale_cells_bar0_cfg0[] = {
367 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
368 .resources = timberdale_dma_resources,
369 .platform_data = &timb_dma_platform_data,
370 .pdata_size = sizeof(timb_dma_platform_data),
374 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
375 .resources = timberdale_uart_resources,
379 .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
380 .resources = timberdale_xiic_resources,
381 .platform_data = &timberdale_xiic_platform_data,
382 .pdata_size = sizeof(timberdale_xiic_platform_data),
386 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
387 .resources = timberdale_gpio_resources,
388 .platform_data = &timberdale_gpio_platform_data,
389 .pdata_size = sizeof(timberdale_gpio_platform_data),
392 .name = "timb-video",
393 .num_resources = ARRAY_SIZE(timberdale_video_resources),
394 .resources = timberdale_video_resources,
395 .platform_data = &timberdale_video_platform_data,
396 .pdata_size = sizeof(timberdale_video_platform_data),
399 .name = "timb-radio",
400 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
401 .resources = timberdale_radio_resources,
402 .platform_data = &timberdale_radio_platform_data,
403 .pdata_size = sizeof(timberdale_radio_platform_data),
406 .name = "xilinx_spi",
407 .num_resources = ARRAY_SIZE(timberdale_spi_resources),
408 .resources = timberdale_spi_resources,
409 .platform_data = &timberdale_xspi_platform_data,
410 .pdata_size = sizeof(timberdale_xspi_platform_data),
414 .num_resources = ARRAY_SIZE(timberdale_eth_resources),
415 .resources = timberdale_eth_resources,
416 .platform_data = &timberdale_ks8842_platform_data,
417 .pdata_size = sizeof(timberdale_ks8842_platform_data),
421 static const struct mfd_cell timberdale_cells_bar0_cfg1[] = {
424 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
425 .resources = timberdale_dma_resources,
426 .platform_data = &timb_dma_platform_data,
427 .pdata_size = sizeof(timb_dma_platform_data),
431 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
432 .resources = timberdale_uart_resources,
436 .num_resources = ARRAY_SIZE(timberdale_uartlite_resources),
437 .resources = timberdale_uartlite_resources,
441 .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
442 .resources = timberdale_xiic_resources,
443 .platform_data = &timberdale_xiic_platform_data,
444 .pdata_size = sizeof(timberdale_xiic_platform_data),
448 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
449 .resources = timberdale_gpio_resources,
450 .platform_data = &timberdale_gpio_platform_data,
451 .pdata_size = sizeof(timberdale_gpio_platform_data),
454 .name = "timb-mlogicore",
455 .num_resources = ARRAY_SIZE(timberdale_mlogicore_resources),
456 .resources = timberdale_mlogicore_resources,
459 .name = "timb-video",
460 .num_resources = ARRAY_SIZE(timberdale_video_resources),
461 .resources = timberdale_video_resources,
462 .platform_data = &timberdale_video_platform_data,
463 .pdata_size = sizeof(timberdale_video_platform_data),
466 .name = "timb-radio",
467 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
468 .resources = timberdale_radio_resources,
469 .platform_data = &timberdale_radio_platform_data,
470 .pdata_size = sizeof(timberdale_radio_platform_data),
473 .name = "xilinx_spi",
474 .num_resources = ARRAY_SIZE(timberdale_spi_resources),
475 .resources = timberdale_spi_resources,
476 .platform_data = &timberdale_xspi_platform_data,
477 .pdata_size = sizeof(timberdale_xspi_platform_data),
481 .num_resources = ARRAY_SIZE(timberdale_eth_resources),
482 .resources = timberdale_eth_resources,
483 .platform_data = &timberdale_ks8842_platform_data,
484 .pdata_size = sizeof(timberdale_ks8842_platform_data),
488 static const struct mfd_cell timberdale_cells_bar0_cfg2[] = {
491 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
492 .resources = timberdale_dma_resources,
493 .platform_data = &timb_dma_platform_data,
494 .pdata_size = sizeof(timb_dma_platform_data),
498 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
499 .resources = timberdale_uart_resources,
503 .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
504 .resources = timberdale_xiic_resources,
505 .platform_data = &timberdale_xiic_platform_data,
506 .pdata_size = sizeof(timberdale_xiic_platform_data),
510 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
511 .resources = timberdale_gpio_resources,
512 .platform_data = &timberdale_gpio_platform_data,
513 .pdata_size = sizeof(timberdale_gpio_platform_data),
516 .name = "timb-video",
517 .num_resources = ARRAY_SIZE(timberdale_video_resources),
518 .resources = timberdale_video_resources,
519 .platform_data = &timberdale_video_platform_data,
520 .pdata_size = sizeof(timberdale_video_platform_data),
523 .name = "timb-radio",
524 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
525 .resources = timberdale_radio_resources,
526 .platform_data = &timberdale_radio_platform_data,
527 .pdata_size = sizeof(timberdale_radio_platform_data),
530 .name = "xilinx_spi",
531 .num_resources = ARRAY_SIZE(timberdale_spi_resources),
532 .resources = timberdale_spi_resources,
533 .platform_data = &timberdale_xspi_platform_data,
534 .pdata_size = sizeof(timberdale_xspi_platform_data),
538 static const struct mfd_cell timberdale_cells_bar0_cfg3[] = {
541 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
542 .resources = timberdale_dma_resources,
543 .platform_data = &timb_dma_platform_data,
544 .pdata_size = sizeof(timb_dma_platform_data),
548 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
549 .resources = timberdale_uart_resources,
552 .name = "ocores-i2c",
553 .num_resources = ARRAY_SIZE(timberdale_ocores_resources),
554 .resources = timberdale_ocores_resources,
555 .platform_data = &timberdale_ocores_platform_data,
556 .pdata_size = sizeof(timberdale_ocores_platform_data),
560 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
561 .resources = timberdale_gpio_resources,
562 .platform_data = &timberdale_gpio_platform_data,
563 .pdata_size = sizeof(timberdale_gpio_platform_data),
566 .name = "timb-video",
567 .num_resources = ARRAY_SIZE(timberdale_video_resources),
568 .resources = timberdale_video_resources,
569 .platform_data = &timberdale_video_platform_data,
570 .pdata_size = sizeof(timberdale_video_platform_data),
573 .name = "timb-radio",
574 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
575 .resources = timberdale_radio_resources,
576 .platform_data = &timberdale_radio_platform_data,
577 .pdata_size = sizeof(timberdale_radio_platform_data),
580 .name = "xilinx_spi",
581 .num_resources = ARRAY_SIZE(timberdale_spi_resources),
582 .resources = timberdale_spi_resources,
583 .platform_data = &timberdale_xspi_platform_data,
584 .pdata_size = sizeof(timberdale_xspi_platform_data),
588 .num_resources = ARRAY_SIZE(timberdale_eth_resources),
589 .resources = timberdale_eth_resources,
590 .platform_data = &timberdale_ks8842_platform_data,
591 .pdata_size = sizeof(timberdale_ks8842_platform_data),
595 static const struct resource timberdale_sdhc_resources[] = {
596 /* located in bar 1 and bar 2 */
598 .start = SDHC0OFFSET,
600 .flags = IORESOURCE_MEM,
603 .start = IRQ_TIMBERDALE_SDHC,
604 .end = IRQ_TIMBERDALE_SDHC,
605 .flags = IORESOURCE_IRQ,
609 static const struct mfd_cell timberdale_cells_bar1[] = {
612 .num_resources = ARRAY_SIZE(timberdale_sdhc_resources),
613 .resources = timberdale_sdhc_resources,
617 static const struct mfd_cell timberdale_cells_bar2[] = {
620 .num_resources = ARRAY_SIZE(timberdale_sdhc_resources),
621 .resources = timberdale_sdhc_resources,
625 static ssize_t fw_ver_show(struct device *dev,
626 struct device_attribute *attr, char *buf)
628 struct timberdale_device *priv = dev_get_drvdata(dev);
630 return sprintf(buf, "%d.%d.%d\n", priv->fw.major, priv->fw.minor,
634 static DEVICE_ATTR_RO(fw_ver);
636 /*--------------------------------------------------------------------------*/
638 static int timb_probe(struct pci_dev *dev,
639 const struct pci_device_id *id)
641 struct timberdale_device *priv;
643 resource_size_t mapbase;
644 struct msix_entry *msix_entries = NULL;
647 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
651 pci_set_drvdata(dev, priv);
653 err = pci_enable_device(dev);
657 mapbase = pci_resource_start(dev, 0);
659 dev_err(&dev->dev, "No resource\n");
663 /* create a resource for the PCI master register */
664 priv->ctl_mapbase = mapbase + CHIPCTLOFFSET;
665 if (!request_mem_region(priv->ctl_mapbase, CHIPCTLSIZE, "timb-ctl")) {
666 dev_err(&dev->dev, "Failed to request ctl mem\n");
670 priv->ctl_membase = ioremap(priv->ctl_mapbase, CHIPCTLSIZE);
671 if (!priv->ctl_membase) {
672 dev_err(&dev->dev, "ioremap failed for ctl mem\n");
676 /* read the HW config */
677 priv->fw.major = ioread32(priv->ctl_membase + TIMB_REV_MAJOR);
678 priv->fw.minor = ioread32(priv->ctl_membase + TIMB_REV_MINOR);
679 priv->fw.config = ioread32(priv->ctl_membase + TIMB_HW_CONFIG);
681 if (priv->fw.major > TIMB_SUPPORTED_MAJOR) {
682 dev_err(&dev->dev, "The driver supports an older "
683 "version of the FPGA, please update the driver to "
684 "support %d.%d\n", priv->fw.major, priv->fw.minor);
687 if (priv->fw.major < TIMB_SUPPORTED_MAJOR ||
688 priv->fw.minor < TIMB_REQUIRED_MINOR) {
689 dev_err(&dev->dev, "The FPGA image is too old (%d.%d), "
690 "please upgrade the FPGA to at least: %d.%d\n",
691 priv->fw.major, priv->fw.minor,
692 TIMB_SUPPORTED_MAJOR, TIMB_REQUIRED_MINOR);
696 msix_entries = kcalloc(TIMBERDALE_NR_IRQS, sizeof(*msix_entries),
701 for (i = 0; i < TIMBERDALE_NR_IRQS; i++)
702 msix_entries[i].entry = i;
704 err = pci_enable_msix_exact(dev, msix_entries, TIMBERDALE_NR_IRQS);
707 "MSI-X init failed: %d, expected entries: %d\n",
708 err, TIMBERDALE_NR_IRQS);
712 err = device_create_file(&dev->dev, &dev_attr_fw_ver);
714 goto err_create_file;
716 /* Reset all FPGA PLB peripherals */
717 iowrite32(0x1, priv->ctl_membase + TIMB_SW_RST);
719 /* update IRQ offsets in I2C board info */
720 for (i = 0; i < ARRAY_SIZE(timberdale_i2c_board_info); i++)
721 timberdale_i2c_board_info[i].irq =
722 msix_entries[timberdale_i2c_board_info[i].irq].vector;
724 /* Update the SPI configuration depending on the HW (8 or 16 bit) */
725 if (priv->fw.config & TIMB_HW_CONFIG_SPI_8BIT) {
726 timberdale_xspi_platform_data.bits_per_word = 8;
727 timberdale_xspi_platform_data.devices =
728 timberdale_spi_8bit_board_info;
729 timberdale_xspi_platform_data.num_devices =
730 ARRAY_SIZE(timberdale_spi_8bit_board_info);
732 timberdale_xspi_platform_data.bits_per_word = 16;
733 timberdale_xspi_platform_data.devices =
734 timberdale_spi_16bit_board_info;
735 timberdale_xspi_platform_data.num_devices =
736 ARRAY_SIZE(timberdale_spi_16bit_board_info);
739 ip_setup = priv->fw.config & TIMB_HW_VER_MASK;
742 err = mfd_add_devices(&dev->dev, -1,
743 timberdale_cells_bar0_cfg0,
744 ARRAY_SIZE(timberdale_cells_bar0_cfg0),
745 &dev->resource[0], msix_entries[0].vector, NULL);
748 err = mfd_add_devices(&dev->dev, -1,
749 timberdale_cells_bar0_cfg1,
750 ARRAY_SIZE(timberdale_cells_bar0_cfg1),
751 &dev->resource[0], msix_entries[0].vector, NULL);
754 err = mfd_add_devices(&dev->dev, -1,
755 timberdale_cells_bar0_cfg2,
756 ARRAY_SIZE(timberdale_cells_bar0_cfg2),
757 &dev->resource[0], msix_entries[0].vector, NULL);
760 err = mfd_add_devices(&dev->dev, -1,
761 timberdale_cells_bar0_cfg3,
762 ARRAY_SIZE(timberdale_cells_bar0_cfg3),
763 &dev->resource[0], msix_entries[0].vector, NULL);
766 dev_err(&dev->dev, "Unknown IP setup: %d.%d.%d\n",
767 priv->fw.major, priv->fw.minor, ip_setup);
773 dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
777 err = mfd_add_devices(&dev->dev, 0,
778 timberdale_cells_bar1, ARRAY_SIZE(timberdale_cells_bar1),
779 &dev->resource[1], msix_entries[0].vector, NULL);
781 dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
785 /* only version 0 and 3 have the iNand routed to SDHCI */
786 if (((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER0) ||
787 ((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER3)) {
788 err = mfd_add_devices(&dev->dev, 1, timberdale_cells_bar2,
789 ARRAY_SIZE(timberdale_cells_bar2),
790 &dev->resource[2], msix_entries[0].vector, NULL);
792 dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
800 "Found Timberdale Card. Rev: %d.%d, HW config: 0x%02x\n",
801 priv->fw.major, priv->fw.minor, priv->fw.config);
806 mfd_remove_devices(&dev->dev);
808 device_remove_file(&dev->dev, &dev_attr_fw_ver);
810 pci_disable_msix(dev);
814 iounmap(priv->ctl_membase);
816 release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE);
818 pci_disable_device(dev);
824 static void timb_remove(struct pci_dev *dev)
826 struct timberdale_device *priv = pci_get_drvdata(dev);
828 mfd_remove_devices(&dev->dev);
830 device_remove_file(&dev->dev, &dev_attr_fw_ver);
832 iounmap(priv->ctl_membase);
833 release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE);
835 pci_disable_msix(dev);
836 pci_disable_device(dev);
840 static const struct pci_device_id timberdale_pci_tbl[] = {
841 { PCI_DEVICE(PCI_VENDOR_ID_TIMB, PCI_DEVICE_ID_TIMB) },
844 MODULE_DEVICE_TABLE(pci, timberdale_pci_tbl);
846 static struct pci_driver timberdale_pci_driver = {
848 .id_table = timberdale_pci_tbl,
850 .remove = timb_remove,
853 module_pci_driver(timberdale_pci_driver);
855 MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
856 MODULE_VERSION(DRV_VERSION);
857 MODULE_LICENSE("GPL v2");