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/tsc2007.h>
36 #include <linux/spi/spi.h>
37 #include <linux/spi/xilinx_spi.h>
38 #include <linux/spi/max7301.h>
39 #include <linux/spi/mc33880.h>
41 #include <media/timb_radio.h>
43 #include "timberdale.h"
45 #define DRIVER_NAME "timberdale"
47 struct timberdale_device
{
48 resource_size_t ctl_mapbase
;
49 unsigned char __iomem
*ctl_membase
;
57 /*--------------------------------------------------------------------------*/
59 static struct tsc2007_platform_data timberdale_tsc2007_platform_data
= {
64 static struct i2c_board_info timberdale_i2c_board_info
[] = {
66 I2C_BOARD_INFO("tsc2007", 0x48),
67 .platform_data
= &timberdale_tsc2007_platform_data
,
68 .irq
= IRQ_TIMBERDALE_TSC_INT
72 static __devinitdata
struct ocores_i2c_platform_data
73 timberdale_ocores_platform_data
= {
76 .devices
= timberdale_i2c_board_info
,
77 .num_devices
= ARRAY_SIZE(timberdale_i2c_board_info
)
80 const static __devinitconst
struct resource timberdale_ocores_resources
[] = {
82 .start
= OCORESOFFSET
,
84 .flags
= IORESOURCE_MEM
,
87 .start
= IRQ_TIMBERDALE_I2C
,
88 .end
= IRQ_TIMBERDALE_I2C
,
89 .flags
= IORESOURCE_IRQ
,
93 const struct max7301_platform_data timberdale_max7301_platform_data
= {
97 const struct mc33880_platform_data timberdale_mc33880_platform_data
= {
101 static struct spi_board_info timberdale_spi_16bit_board_info
[] = {
103 .modalias
= "max7301",
104 .max_speed_hz
= 26000,
107 .platform_data
= &timberdale_max7301_platform_data
111 static struct spi_board_info timberdale_spi_8bit_board_info
[] = {
113 .modalias
= "mc33880",
114 .max_speed_hz
= 4000,
117 .platform_data
= &timberdale_mc33880_platform_data
121 static __devinitdata
struct xspi_platform_data timberdale_xspi_platform_data
= {
123 .little_endian
= true,
124 /* bits per word and devices will be filled in runtime depending
129 const static __devinitconst
struct resource timberdale_spi_resources
[] = {
133 .flags
= IORESOURCE_MEM
,
136 .start
= IRQ_TIMBERDALE_SPI
,
137 .end
= IRQ_TIMBERDALE_SPI
,
138 .flags
= IORESOURCE_IRQ
,
142 const static __devinitconst
struct resource timberdale_eth_resources
[] = {
146 .flags
= IORESOURCE_MEM
,
149 .start
= IRQ_TIMBERDALE_ETHSW_IF
,
150 .end
= IRQ_TIMBERDALE_ETHSW_IF
,
151 .flags
= IORESOURCE_IRQ
,
155 static __devinitdata
struct timbgpio_platform_data
156 timberdale_gpio_platform_data
= {
158 .nr_pins
= GPIO_NR_PINS
,
162 const static __devinitconst
struct resource timberdale_gpio_resources
[] = {
166 .flags
= IORESOURCE_MEM
,
169 .start
= IRQ_TIMBERDALE_GPIO
,
170 .end
= IRQ_TIMBERDALE_GPIO
,
171 .flags
= IORESOURCE_IRQ
,
175 const static __devinitconst
struct resource timberdale_mlogicore_resources
[] = {
177 .start
= MLCOREOFFSET
,
179 .flags
= IORESOURCE_MEM
,
182 .start
= IRQ_TIMBERDALE_MLCORE
,
183 .end
= IRQ_TIMBERDALE_MLCORE
,
184 .flags
= IORESOURCE_IRQ
,
187 .start
= IRQ_TIMBERDALE_MLCORE_BUF
,
188 .end
= IRQ_TIMBERDALE_MLCORE_BUF
,
189 .flags
= IORESOURCE_IRQ
,
193 const static __devinitconst
struct resource timberdale_uart_resources
[] = {
197 .flags
= IORESOURCE_MEM
,
200 .start
= IRQ_TIMBERDALE_UART
,
201 .end
= IRQ_TIMBERDALE_UART
,
202 .flags
= IORESOURCE_IRQ
,
206 const static __devinitconst
struct resource timberdale_uartlite_resources
[] = {
208 .start
= UARTLITEOFFSET
,
210 .flags
= IORESOURCE_MEM
,
213 .start
= IRQ_TIMBERDALE_UARTLITE
,
214 .end
= IRQ_TIMBERDALE_UARTLITE
,
215 .flags
= IORESOURCE_IRQ
,
219 const static __devinitconst
struct resource timberdale_radio_resources
[] = {
223 .flags
= IORESOURCE_MEM
,
226 .start
= IRQ_TIMBERDALE_RDS
,
227 .end
= IRQ_TIMBERDALE_RDS
,
228 .flags
= IORESOURCE_IRQ
,
232 static __devinitdata
struct i2c_board_info timberdale_tef6868_i2c_board_info
= {
233 I2C_BOARD_INFO("tef6862", 0x60)
236 static __devinitdata
struct i2c_board_info timberdale_saa7706_i2c_board_info
= {
237 I2C_BOARD_INFO("saa7706h", 0x1C)
240 static __devinitdata
struct timb_radio_platform_data
241 timberdale_radio_platform_data
= {
244 .module_name
= "tef6862",
245 .info
= &timberdale_tef6868_i2c_board_info
248 .module_name
= "saa7706h",
249 .info
= &timberdale_saa7706_i2c_board_info
253 const static __devinitconst
struct resource timberdale_dma_resources
[] = {
257 .flags
= IORESOURCE_MEM
,
260 .start
= IRQ_TIMBERDALE_DMA
,
261 .end
= IRQ_TIMBERDALE_DMA
,
262 .flags
= IORESOURCE_IRQ
,
266 static __devinitdata
struct mfd_cell timberdale_cells_bar0_cfg0
[] = {
269 .num_resources
= ARRAY_SIZE(timberdale_uart_resources
),
270 .resources
= timberdale_uart_resources
,
274 .num_resources
= ARRAY_SIZE(timberdale_gpio_resources
),
275 .resources
= timberdale_gpio_resources
,
276 .platform_data
= &timberdale_gpio_platform_data
,
277 .data_size
= sizeof(timberdale_gpio_platform_data
),
280 .name
= "timb-radio",
281 .num_resources
= ARRAY_SIZE(timberdale_radio_resources
),
282 .resources
= timberdale_radio_resources
,
283 .platform_data
= &timberdale_radio_platform_data
,
284 .data_size
= sizeof(timberdale_radio_platform_data
),
287 .name
= "xilinx_spi",
288 .num_resources
= ARRAY_SIZE(timberdale_spi_resources
),
289 .resources
= timberdale_spi_resources
,
290 .platform_data
= &timberdale_xspi_platform_data
,
291 .data_size
= sizeof(timberdale_xspi_platform_data
),
295 .num_resources
= ARRAY_SIZE(timberdale_eth_resources
),
296 .resources
= timberdale_eth_resources
,
300 .num_resources
= ARRAY_SIZE(timberdale_dma_resources
),
301 .resources
= timberdale_dma_resources
,
305 static __devinitdata
struct mfd_cell timberdale_cells_bar0_cfg1
[] = {
308 .num_resources
= ARRAY_SIZE(timberdale_uart_resources
),
309 .resources
= timberdale_uart_resources
,
313 .num_resources
= ARRAY_SIZE(timberdale_uartlite_resources
),
314 .resources
= timberdale_uartlite_resources
,
318 .num_resources
= ARRAY_SIZE(timberdale_gpio_resources
),
319 .resources
= timberdale_gpio_resources
,
320 .platform_data
= &timberdale_gpio_platform_data
,
321 .data_size
= sizeof(timberdale_gpio_platform_data
),
324 .name
= "timb-mlogicore",
325 .num_resources
= ARRAY_SIZE(timberdale_mlogicore_resources
),
326 .resources
= timberdale_mlogicore_resources
,
329 .name
= "timb-radio",
330 .num_resources
= ARRAY_SIZE(timberdale_radio_resources
),
331 .resources
= timberdale_radio_resources
,
332 .platform_data
= &timberdale_radio_platform_data
,
333 .data_size
= sizeof(timberdale_radio_platform_data
),
336 .name
= "xilinx_spi",
337 .num_resources
= ARRAY_SIZE(timberdale_spi_resources
),
338 .resources
= timberdale_spi_resources
,
339 .platform_data
= &timberdale_xspi_platform_data
,
340 .data_size
= sizeof(timberdale_xspi_platform_data
),
344 .num_resources
= ARRAY_SIZE(timberdale_eth_resources
),
345 .resources
= timberdale_eth_resources
,
349 .num_resources
= ARRAY_SIZE(timberdale_dma_resources
),
350 .resources
= timberdale_dma_resources
,
354 static __devinitdata
struct mfd_cell timberdale_cells_bar0_cfg2
[] = {
357 .num_resources
= ARRAY_SIZE(timberdale_uart_resources
),
358 .resources
= timberdale_uart_resources
,
362 .num_resources
= ARRAY_SIZE(timberdale_gpio_resources
),
363 .resources
= timberdale_gpio_resources
,
364 .platform_data
= &timberdale_gpio_platform_data
,
365 .data_size
= sizeof(timberdale_gpio_platform_data
),
368 .name
= "timb-radio",
369 .num_resources
= ARRAY_SIZE(timberdale_radio_resources
),
370 .resources
= timberdale_radio_resources
,
371 .platform_data
= &timberdale_radio_platform_data
,
372 .data_size
= sizeof(timberdale_radio_platform_data
),
375 .name
= "xilinx_spi",
376 .num_resources
= ARRAY_SIZE(timberdale_spi_resources
),
377 .resources
= timberdale_spi_resources
,
378 .platform_data
= &timberdale_xspi_platform_data
,
379 .data_size
= sizeof(timberdale_xspi_platform_data
),
383 .num_resources
= ARRAY_SIZE(timberdale_dma_resources
),
384 .resources
= timberdale_dma_resources
,
388 static __devinitdata
struct mfd_cell timberdale_cells_bar0_cfg3
[] = {
391 .num_resources
= ARRAY_SIZE(timberdale_uart_resources
),
392 .resources
= timberdale_uart_resources
,
395 .name
= "ocores-i2c",
396 .num_resources
= ARRAY_SIZE(timberdale_ocores_resources
),
397 .resources
= timberdale_ocores_resources
,
398 .platform_data
= &timberdale_ocores_platform_data
,
399 .data_size
= sizeof(timberdale_ocores_platform_data
),
403 .num_resources
= ARRAY_SIZE(timberdale_gpio_resources
),
404 .resources
= timberdale_gpio_resources
,
405 .platform_data
= &timberdale_gpio_platform_data
,
406 .data_size
= sizeof(timberdale_gpio_platform_data
),
409 .name
= "timb-radio",
410 .num_resources
= ARRAY_SIZE(timberdale_radio_resources
),
411 .resources
= timberdale_radio_resources
,
412 .platform_data
= &timberdale_radio_platform_data
,
413 .data_size
= sizeof(timberdale_radio_platform_data
),
416 .name
= "xilinx_spi",
417 .num_resources
= ARRAY_SIZE(timberdale_spi_resources
),
418 .resources
= timberdale_spi_resources
,
419 .platform_data
= &timberdale_xspi_platform_data
,
420 .data_size
= sizeof(timberdale_xspi_platform_data
),
424 .num_resources
= ARRAY_SIZE(timberdale_eth_resources
),
425 .resources
= timberdale_eth_resources
,
429 .num_resources
= ARRAY_SIZE(timberdale_dma_resources
),
430 .resources
= timberdale_dma_resources
,
434 static const __devinitconst
struct resource timberdale_sdhc_resources
[] = {
435 /* located in bar 1 and bar 2 */
437 .start
= SDHC0OFFSET
,
439 .flags
= IORESOURCE_MEM
,
442 .start
= IRQ_TIMBERDALE_SDHC
,
443 .end
= IRQ_TIMBERDALE_SDHC
,
444 .flags
= IORESOURCE_IRQ
,
448 static __devinitdata
struct mfd_cell timberdale_cells_bar1
[] = {
451 .num_resources
= ARRAY_SIZE(timberdale_sdhc_resources
),
452 .resources
= timberdale_sdhc_resources
,
456 static __devinitdata
struct mfd_cell timberdale_cells_bar2
[] = {
459 .num_resources
= ARRAY_SIZE(timberdale_sdhc_resources
),
460 .resources
= timberdale_sdhc_resources
,
464 static ssize_t
show_fw_ver(struct device
*dev
, struct device_attribute
*attr
,
467 struct pci_dev
*pdev
= to_pci_dev(dev
);
468 struct timberdale_device
*priv
= pci_get_drvdata(pdev
);
470 return sprintf(buf
, "%d.%d.%d\n", priv
->fw
.major
, priv
->fw
.minor
,
474 static DEVICE_ATTR(fw_ver
, S_IRUGO
, show_fw_ver
, NULL
);
476 /*--------------------------------------------------------------------------*/
478 static int __devinit
timb_probe(struct pci_dev
*dev
,
479 const struct pci_device_id
*id
)
481 struct timberdale_device
*priv
;
483 resource_size_t mapbase
;
484 struct msix_entry
*msix_entries
= NULL
;
487 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
491 pci_set_drvdata(dev
, priv
);
493 err
= pci_enable_device(dev
);
497 mapbase
= pci_resource_start(dev
, 0);
499 dev_err(&dev
->dev
, "No resource\n");
503 /* create a resource for the PCI master register */
504 priv
->ctl_mapbase
= mapbase
+ CHIPCTLOFFSET
;
505 if (!request_mem_region(priv
->ctl_mapbase
, CHIPCTLSIZE
, "timb-ctl")) {
506 dev_err(&dev
->dev
, "Failed to request ctl mem\n");
510 priv
->ctl_membase
= ioremap(priv
->ctl_mapbase
, CHIPCTLSIZE
);
511 if (!priv
->ctl_membase
) {
512 dev_err(&dev
->dev
, "ioremap failed for ctl mem\n");
516 /* read the HW config */
517 priv
->fw
.major
= ioread32(priv
->ctl_membase
+ TIMB_REV_MAJOR
);
518 priv
->fw
.minor
= ioread32(priv
->ctl_membase
+ TIMB_REV_MINOR
);
519 priv
->fw
.config
= ioread32(priv
->ctl_membase
+ TIMB_HW_CONFIG
);
521 if (priv
->fw
.major
> TIMB_SUPPORTED_MAJOR
) {
522 dev_err(&dev
->dev
, "The driver supports an older "
523 "version of the FPGA, please update the driver to "
524 "support %d.%d\n", priv
->fw
.major
, priv
->fw
.minor
);
527 if (priv
->fw
.major
< TIMB_SUPPORTED_MAJOR
||
528 priv
->fw
.minor
< TIMB_REQUIRED_MINOR
) {
529 dev_err(&dev
->dev
, "The FPGA image is too old (%d.%d), "
530 "please upgrade the FPGA to at least: %d.%d\n",
531 priv
->fw
.major
, priv
->fw
.minor
,
532 TIMB_SUPPORTED_MAJOR
, TIMB_REQUIRED_MINOR
);
536 msix_entries
= kzalloc(TIMBERDALE_NR_IRQS
* sizeof(*msix_entries
),
541 for (i
= 0; i
< TIMBERDALE_NR_IRQS
; i
++)
542 msix_entries
[i
].entry
= i
;
544 err
= pci_enable_msix(dev
, msix_entries
, TIMBERDALE_NR_IRQS
);
547 "MSI-X init failed: %d, expected entries: %d\n",
548 err
, TIMBERDALE_NR_IRQS
);
552 err
= device_create_file(&dev
->dev
, &dev_attr_fw_ver
);
554 goto err_create_file
;
556 /* Reset all FPGA PLB peripherals */
557 iowrite32(0x1, priv
->ctl_membase
+ TIMB_SW_RST
);
559 /* update IRQ offsets in I2C board info */
560 for (i
= 0; i
< ARRAY_SIZE(timberdale_i2c_board_info
); i
++)
561 timberdale_i2c_board_info
[i
].irq
=
562 msix_entries
[timberdale_i2c_board_info
[i
].irq
].vector
;
564 /* Update the SPI configuration depending on the HW (8 or 16 bit) */
565 if (priv
->fw
.config
& TIMB_HW_CONFIG_SPI_8BIT
) {
566 timberdale_xspi_platform_data
.bits_per_word
= 8;
567 timberdale_xspi_platform_data
.devices
=
568 timberdale_spi_8bit_board_info
;
569 timberdale_xspi_platform_data
.num_devices
=
570 ARRAY_SIZE(timberdale_spi_8bit_board_info
);
572 timberdale_xspi_platform_data
.bits_per_word
= 16;
573 timberdale_xspi_platform_data
.devices
=
574 timberdale_spi_16bit_board_info
;
575 timberdale_xspi_platform_data
.num_devices
=
576 ARRAY_SIZE(timberdale_spi_16bit_board_info
);
579 ip_setup
= priv
->fw
.config
& TIMB_HW_VER_MASK
;
582 err
= mfd_add_devices(&dev
->dev
, -1,
583 timberdale_cells_bar0_cfg0
,
584 ARRAY_SIZE(timberdale_cells_bar0_cfg0
),
585 &dev
->resource
[0], msix_entries
[0].vector
);
588 err
= mfd_add_devices(&dev
->dev
, -1,
589 timberdale_cells_bar0_cfg1
,
590 ARRAY_SIZE(timberdale_cells_bar0_cfg1
),
591 &dev
->resource
[0], msix_entries
[0].vector
);
594 err
= mfd_add_devices(&dev
->dev
, -1,
595 timberdale_cells_bar0_cfg2
,
596 ARRAY_SIZE(timberdale_cells_bar0_cfg2
),
597 &dev
->resource
[0], msix_entries
[0].vector
);
600 err
= mfd_add_devices(&dev
->dev
, -1,
601 timberdale_cells_bar0_cfg3
,
602 ARRAY_SIZE(timberdale_cells_bar0_cfg3
),
603 &dev
->resource
[0], msix_entries
[0].vector
);
606 dev_err(&dev
->dev
, "Uknown IP setup: %d.%d.%d\n",
607 priv
->fw
.major
, priv
->fw
.minor
, ip_setup
);
614 dev_err(&dev
->dev
, "mfd_add_devices failed: %d\n", err
);
618 err
= mfd_add_devices(&dev
->dev
, 0,
619 timberdale_cells_bar1
, ARRAY_SIZE(timberdale_cells_bar1
),
620 &dev
->resource
[1], msix_entries
[0].vector
);
622 dev_err(&dev
->dev
, "mfd_add_devices failed: %d\n", err
);
626 /* only version 0 and 3 have the iNand routed to SDHCI */
627 if (((priv
->fw
.config
& TIMB_HW_VER_MASK
) == TIMB_HW_VER0
) ||
628 ((priv
->fw
.config
& TIMB_HW_VER_MASK
) == TIMB_HW_VER3
)) {
629 err
= mfd_add_devices(&dev
->dev
, 1, timberdale_cells_bar2
,
630 ARRAY_SIZE(timberdale_cells_bar2
),
631 &dev
->resource
[2], msix_entries
[0].vector
);
633 dev_err(&dev
->dev
, "mfd_add_devices failed: %d\n", err
);
641 "Found Timberdale Card. Rev: %d.%d, HW config: 0x%02x\n",
642 priv
->fw
.major
, priv
->fw
.minor
, priv
->fw
.config
);
647 mfd_remove_devices(&dev
->dev
);
649 device_remove_file(&dev
->dev
, &dev_attr_fw_ver
);
651 pci_disable_msix(dev
);
653 iounmap(priv
->ctl_membase
);
655 release_mem_region(priv
->ctl_mapbase
, CHIPCTLSIZE
);
657 pci_set_drvdata(dev
, NULL
);
659 pci_disable_device(dev
);
663 pci_set_drvdata(dev
, NULL
);
667 static void __devexit
timb_remove(struct pci_dev
*dev
)
669 struct timberdale_device
*priv
= pci_get_drvdata(dev
);
671 mfd_remove_devices(&dev
->dev
);
673 device_remove_file(&dev
->dev
, &dev_attr_fw_ver
);
675 iounmap(priv
->ctl_membase
);
676 release_mem_region(priv
->ctl_mapbase
, CHIPCTLSIZE
);
678 pci_disable_msix(dev
);
679 pci_disable_device(dev
);
680 pci_set_drvdata(dev
, NULL
);
684 static struct pci_device_id timberdale_pci_tbl
[] = {
685 { PCI_DEVICE(PCI_VENDOR_ID_TIMB
, PCI_DEVICE_ID_TIMB
) },
688 MODULE_DEVICE_TABLE(pci
, timberdale_pci_tbl
);
690 static struct pci_driver timberdale_pci_driver
= {
692 .id_table
= timberdale_pci_tbl
,
694 .remove
= __devexit_p(timb_remove
),
697 static int __init
timberdale_init(void)
701 err
= pci_register_driver(&timberdale_pci_driver
);
704 "Failed to register PCI driver for %s device.\n",
705 timberdale_pci_driver
.name
);
709 printk(KERN_INFO
"Driver for %s has been successfully registered.\n",
710 timberdale_pci_driver
.name
);
715 static void __exit
timberdale_exit(void)
717 pci_unregister_driver(&timberdale_pci_driver
);
719 printk(KERN_INFO
"Driver for %s has been successfully unregistered.\n",
720 timberdale_pci_driver
.name
);
723 module_init(timberdale_init
);
724 module_exit(timberdale_exit
);
726 MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
727 MODULE_VERSION(DRV_VERSION
);
728 MODULE_LICENSE("GPL v2");