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>
29 #include <linux/timb_gpio.h>
31 #include <linux/i2c.h>
32 #include <linux/i2c-ocores.h>
33 #include <linux/i2c/tsc2007.h>
35 #include <linux/spi/spi.h>
36 #include <linux/spi/xilinx_spi.h>
37 #include <linux/spi/max7301.h>
38 #include <linux/spi/mc33880.h>
40 #include <media/timb_radio.h>
42 #include "timberdale.h"
44 #define DRIVER_NAME "timberdale"
46 struct timberdale_device
{
47 resource_size_t ctl_mapbase
;
48 unsigned char __iomem
*ctl_membase
;
56 /*--------------------------------------------------------------------------*/
58 static struct tsc2007_platform_data timberdale_tsc2007_platform_data
= {
63 static struct i2c_board_info timberdale_i2c_board_info
[] = {
65 I2C_BOARD_INFO("tsc2007", 0x48),
66 .platform_data
= &timberdale_tsc2007_platform_data
,
67 .irq
= IRQ_TIMBERDALE_TSC_INT
71 static __devinitdata
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 const static __devinitconst
struct resource timberdale_ocores_resources
[] = {
81 .start
= OCORESOFFSET
,
83 .flags
= IORESOURCE_MEM
,
86 .start
= IRQ_TIMBERDALE_I2C
,
87 .end
= IRQ_TIMBERDALE_I2C
,
88 .flags
= IORESOURCE_IRQ
,
92 const struct max7301_platform_data timberdale_max7301_platform_data
= {
96 const struct mc33880_platform_data timberdale_mc33880_platform_data
= {
100 static struct spi_board_info timberdale_spi_16bit_board_info
[] = {
102 .modalias
= "max7301",
103 .max_speed_hz
= 26000,
106 .platform_data
= &timberdale_max7301_platform_data
110 static struct spi_board_info timberdale_spi_8bit_board_info
[] = {
112 .modalias
= "mc33880",
113 .max_speed_hz
= 4000,
116 .platform_data
= &timberdale_mc33880_platform_data
120 static __devinitdata
struct xspi_platform_data timberdale_xspi_platform_data
= {
122 .little_endian
= true,
123 /* bits per word and devices will be filled in runtime depending
128 const static __devinitconst
struct resource timberdale_spi_resources
[] = {
132 .flags
= IORESOURCE_MEM
,
135 .start
= IRQ_TIMBERDALE_SPI
,
136 .end
= IRQ_TIMBERDALE_SPI
,
137 .flags
= IORESOURCE_IRQ
,
141 const static __devinitconst
struct resource timberdale_eth_resources
[] = {
145 .flags
= IORESOURCE_MEM
,
148 .start
= IRQ_TIMBERDALE_ETHSW_IF
,
149 .end
= IRQ_TIMBERDALE_ETHSW_IF
,
150 .flags
= IORESOURCE_IRQ
,
154 static __devinitdata
struct timbgpio_platform_data
155 timberdale_gpio_platform_data
= {
157 .nr_pins
= GPIO_NR_PINS
,
161 const static __devinitconst
struct resource timberdale_gpio_resources
[] = {
165 .flags
= IORESOURCE_MEM
,
168 .start
= IRQ_TIMBERDALE_GPIO
,
169 .end
= IRQ_TIMBERDALE_GPIO
,
170 .flags
= IORESOURCE_IRQ
,
174 const static __devinitconst
struct resource timberdale_mlogicore_resources
[] = {
176 .start
= MLCOREOFFSET
,
178 .flags
= IORESOURCE_MEM
,
181 .start
= IRQ_TIMBERDALE_MLCORE
,
182 .end
= IRQ_TIMBERDALE_MLCORE
,
183 .flags
= IORESOURCE_IRQ
,
186 .start
= IRQ_TIMBERDALE_MLCORE_BUF
,
187 .end
= IRQ_TIMBERDALE_MLCORE_BUF
,
188 .flags
= IORESOURCE_IRQ
,
192 const static __devinitconst
struct resource timberdale_uart_resources
[] = {
196 .flags
= IORESOURCE_MEM
,
199 .start
= IRQ_TIMBERDALE_UART
,
200 .end
= IRQ_TIMBERDALE_UART
,
201 .flags
= IORESOURCE_IRQ
,
205 const static __devinitconst
struct resource timberdale_uartlite_resources
[] = {
207 .start
= UARTLITEOFFSET
,
209 .flags
= IORESOURCE_MEM
,
212 .start
= IRQ_TIMBERDALE_UARTLITE
,
213 .end
= IRQ_TIMBERDALE_UARTLITE
,
214 .flags
= IORESOURCE_IRQ
,
218 const static __devinitconst
struct resource timberdale_radio_resources
[] = {
222 .flags
= IORESOURCE_MEM
,
225 .start
= IRQ_TIMBERDALE_RDS
,
226 .end
= IRQ_TIMBERDALE_RDS
,
227 .flags
= IORESOURCE_IRQ
,
231 static __devinitdata
struct i2c_board_info timberdale_tef6868_i2c_board_info
= {
232 I2C_BOARD_INFO("tef6862", 0x60)
235 static __devinitdata
struct i2c_board_info timberdale_saa7706_i2c_board_info
= {
236 I2C_BOARD_INFO("saa7706h", 0x1C)
239 static __devinitdata
struct timb_radio_platform_data
240 timberdale_radio_platform_data
= {
243 .module_name
= "tef6862",
244 .info
= &timberdale_tef6868_i2c_board_info
247 .module_name
= "saa7706h",
248 .info
= &timberdale_saa7706_i2c_board_info
252 const static __devinitconst
struct resource timberdale_dma_resources
[] = {
256 .flags
= IORESOURCE_MEM
,
259 .start
= IRQ_TIMBERDALE_DMA
,
260 .end
= IRQ_TIMBERDALE_DMA
,
261 .flags
= IORESOURCE_IRQ
,
265 static __devinitdata
struct mfd_cell timberdale_cells_bar0_cfg0
[] = {
268 .num_resources
= ARRAY_SIZE(timberdale_uart_resources
),
269 .resources
= timberdale_uart_resources
,
273 .num_resources
= ARRAY_SIZE(timberdale_gpio_resources
),
274 .resources
= timberdale_gpio_resources
,
275 .platform_data
= &timberdale_gpio_platform_data
,
276 .data_size
= sizeof(timberdale_gpio_platform_data
),
279 .name
= "timb-radio",
280 .num_resources
= ARRAY_SIZE(timberdale_radio_resources
),
281 .resources
= timberdale_radio_resources
,
282 .platform_data
= &timberdale_radio_platform_data
,
283 .data_size
= sizeof(timberdale_radio_platform_data
),
286 .name
= "xilinx_spi",
287 .num_resources
= ARRAY_SIZE(timberdale_spi_resources
),
288 .resources
= timberdale_spi_resources
,
289 .platform_data
= &timberdale_xspi_platform_data
,
290 .data_size
= sizeof(timberdale_xspi_platform_data
),
294 .num_resources
= ARRAY_SIZE(timberdale_eth_resources
),
295 .resources
= timberdale_eth_resources
,
299 .num_resources
= ARRAY_SIZE(timberdale_dma_resources
),
300 .resources
= timberdale_dma_resources
,
304 static __devinitdata
struct mfd_cell timberdale_cells_bar0_cfg1
[] = {
307 .num_resources
= ARRAY_SIZE(timberdale_uart_resources
),
308 .resources
= timberdale_uart_resources
,
312 .num_resources
= ARRAY_SIZE(timberdale_uartlite_resources
),
313 .resources
= timberdale_uartlite_resources
,
317 .num_resources
= ARRAY_SIZE(timberdale_gpio_resources
),
318 .resources
= timberdale_gpio_resources
,
319 .platform_data
= &timberdale_gpio_platform_data
,
320 .data_size
= sizeof(timberdale_gpio_platform_data
),
323 .name
= "timb-mlogicore",
324 .num_resources
= ARRAY_SIZE(timberdale_mlogicore_resources
),
325 .resources
= timberdale_mlogicore_resources
,
328 .name
= "timb-radio",
329 .num_resources
= ARRAY_SIZE(timberdale_radio_resources
),
330 .resources
= timberdale_radio_resources
,
331 .platform_data
= &timberdale_radio_platform_data
,
332 .data_size
= sizeof(timberdale_radio_platform_data
),
335 .name
= "xilinx_spi",
336 .num_resources
= ARRAY_SIZE(timberdale_spi_resources
),
337 .resources
= timberdale_spi_resources
,
338 .platform_data
= &timberdale_xspi_platform_data
,
339 .data_size
= sizeof(timberdale_xspi_platform_data
),
343 .num_resources
= ARRAY_SIZE(timberdale_eth_resources
),
344 .resources
= timberdale_eth_resources
,
348 .num_resources
= ARRAY_SIZE(timberdale_dma_resources
),
349 .resources
= timberdale_dma_resources
,
353 static __devinitdata
struct mfd_cell timberdale_cells_bar0_cfg2
[] = {
356 .num_resources
= ARRAY_SIZE(timberdale_uart_resources
),
357 .resources
= timberdale_uart_resources
,
361 .num_resources
= ARRAY_SIZE(timberdale_gpio_resources
),
362 .resources
= timberdale_gpio_resources
,
363 .platform_data
= &timberdale_gpio_platform_data
,
364 .data_size
= sizeof(timberdale_gpio_platform_data
),
367 .name
= "timb-radio",
368 .num_resources
= ARRAY_SIZE(timberdale_radio_resources
),
369 .resources
= timberdale_radio_resources
,
370 .platform_data
= &timberdale_radio_platform_data
,
371 .data_size
= sizeof(timberdale_radio_platform_data
),
374 .name
= "xilinx_spi",
375 .num_resources
= ARRAY_SIZE(timberdale_spi_resources
),
376 .resources
= timberdale_spi_resources
,
377 .platform_data
= &timberdale_xspi_platform_data
,
378 .data_size
= sizeof(timberdale_xspi_platform_data
),
382 .num_resources
= ARRAY_SIZE(timberdale_dma_resources
),
383 .resources
= timberdale_dma_resources
,
387 static __devinitdata
struct mfd_cell timberdale_cells_bar0_cfg3
[] = {
390 .num_resources
= ARRAY_SIZE(timberdale_uart_resources
),
391 .resources
= timberdale_uart_resources
,
394 .name
= "ocores-i2c",
395 .num_resources
= ARRAY_SIZE(timberdale_ocores_resources
),
396 .resources
= timberdale_ocores_resources
,
397 .platform_data
= &timberdale_ocores_platform_data
,
398 .data_size
= sizeof(timberdale_ocores_platform_data
),
402 .num_resources
= ARRAY_SIZE(timberdale_gpio_resources
),
403 .resources
= timberdale_gpio_resources
,
404 .platform_data
= &timberdale_gpio_platform_data
,
405 .data_size
= sizeof(timberdale_gpio_platform_data
),
408 .name
= "timb-radio",
409 .num_resources
= ARRAY_SIZE(timberdale_radio_resources
),
410 .resources
= timberdale_radio_resources
,
411 .platform_data
= &timberdale_radio_platform_data
,
412 .data_size
= sizeof(timberdale_radio_platform_data
),
415 .name
= "xilinx_spi",
416 .num_resources
= ARRAY_SIZE(timberdale_spi_resources
),
417 .resources
= timberdale_spi_resources
,
418 .platform_data
= &timberdale_xspi_platform_data
,
419 .data_size
= sizeof(timberdale_xspi_platform_data
),
423 .num_resources
= ARRAY_SIZE(timberdale_eth_resources
),
424 .resources
= timberdale_eth_resources
,
428 .num_resources
= ARRAY_SIZE(timberdale_dma_resources
),
429 .resources
= timberdale_dma_resources
,
433 static const __devinitconst
struct resource timberdale_sdhc_resources
[] = {
434 /* located in bar 1 and bar 2 */
436 .start
= SDHC0OFFSET
,
438 .flags
= IORESOURCE_MEM
,
441 .start
= IRQ_TIMBERDALE_SDHC
,
442 .end
= IRQ_TIMBERDALE_SDHC
,
443 .flags
= IORESOURCE_IRQ
,
447 static __devinitdata
struct mfd_cell timberdale_cells_bar1
[] = {
450 .num_resources
= ARRAY_SIZE(timberdale_sdhc_resources
),
451 .resources
= timberdale_sdhc_resources
,
455 static __devinitdata
struct mfd_cell timberdale_cells_bar2
[] = {
458 .num_resources
= ARRAY_SIZE(timberdale_sdhc_resources
),
459 .resources
= timberdale_sdhc_resources
,
463 static ssize_t
show_fw_ver(struct device
*dev
, struct device_attribute
*attr
,
466 struct pci_dev
*pdev
= to_pci_dev(dev
);
467 struct timberdale_device
*priv
= pci_get_drvdata(pdev
);
469 return sprintf(buf
, "%d.%d.%d\n", priv
->fw
.major
, priv
->fw
.minor
,
473 static DEVICE_ATTR(fw_ver
, S_IRUGO
, show_fw_ver
, NULL
);
475 /*--------------------------------------------------------------------------*/
477 static int __devinit
timb_probe(struct pci_dev
*dev
,
478 const struct pci_device_id
*id
)
480 struct timberdale_device
*priv
;
482 resource_size_t mapbase
;
483 struct msix_entry
*msix_entries
= NULL
;
486 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
490 pci_set_drvdata(dev
, priv
);
492 err
= pci_enable_device(dev
);
496 mapbase
= pci_resource_start(dev
, 0);
498 dev_err(&dev
->dev
, "No resource\n");
502 /* create a resource for the PCI master register */
503 priv
->ctl_mapbase
= mapbase
+ CHIPCTLOFFSET
;
504 if (!request_mem_region(priv
->ctl_mapbase
, CHIPCTLSIZE
, "timb-ctl")) {
505 dev_err(&dev
->dev
, "Failed to request ctl mem\n");
509 priv
->ctl_membase
= ioremap(priv
->ctl_mapbase
, CHIPCTLSIZE
);
510 if (!priv
->ctl_membase
) {
511 dev_err(&dev
->dev
, "ioremap failed for ctl mem\n");
515 /* read the HW config */
516 priv
->fw
.major
= ioread32(priv
->ctl_membase
+ TIMB_REV_MAJOR
);
517 priv
->fw
.minor
= ioread32(priv
->ctl_membase
+ TIMB_REV_MINOR
);
518 priv
->fw
.config
= ioread32(priv
->ctl_membase
+ TIMB_HW_CONFIG
);
520 if (priv
->fw
.major
> TIMB_SUPPORTED_MAJOR
) {
521 dev_err(&dev
->dev
, "The driver supports an older "
522 "version of the FPGA, please update the driver to "
523 "support %d.%d\n", priv
->fw
.major
, priv
->fw
.minor
);
526 if (priv
->fw
.major
< TIMB_SUPPORTED_MAJOR
||
527 priv
->fw
.minor
< TIMB_REQUIRED_MINOR
) {
528 dev_err(&dev
->dev
, "The FPGA image is too old (%d.%d), "
529 "please upgrade the FPGA to at least: %d.%d\n",
530 priv
->fw
.major
, priv
->fw
.minor
,
531 TIMB_SUPPORTED_MAJOR
, TIMB_REQUIRED_MINOR
);
535 msix_entries
= kzalloc(TIMBERDALE_NR_IRQS
* sizeof(*msix_entries
),
540 for (i
= 0; i
< TIMBERDALE_NR_IRQS
; i
++)
541 msix_entries
[i
].entry
= i
;
543 err
= pci_enable_msix(dev
, msix_entries
, TIMBERDALE_NR_IRQS
);
546 "MSI-X init failed: %d, expected entries: %d\n",
547 err
, TIMBERDALE_NR_IRQS
);
551 err
= device_create_file(&dev
->dev
, &dev_attr_fw_ver
);
553 goto err_create_file
;
555 /* Reset all FPGA PLB peripherals */
556 iowrite32(0x1, priv
->ctl_membase
+ TIMB_SW_RST
);
558 /* update IRQ offsets in I2C board info */
559 for (i
= 0; i
< ARRAY_SIZE(timberdale_i2c_board_info
); i
++)
560 timberdale_i2c_board_info
[i
].irq
=
561 msix_entries
[timberdale_i2c_board_info
[i
].irq
].vector
;
563 /* Update the SPI configuration depending on the HW (8 or 16 bit) */
564 if (priv
->fw
.config
& TIMB_HW_CONFIG_SPI_8BIT
) {
565 timberdale_xspi_platform_data
.bits_per_word
= 8;
566 timberdale_xspi_platform_data
.devices
=
567 timberdale_spi_8bit_board_info
;
568 timberdale_xspi_platform_data
.num_devices
=
569 ARRAY_SIZE(timberdale_spi_8bit_board_info
);
571 timberdale_xspi_platform_data
.bits_per_word
= 16;
572 timberdale_xspi_platform_data
.devices
=
573 timberdale_spi_16bit_board_info
;
574 timberdale_xspi_platform_data
.num_devices
=
575 ARRAY_SIZE(timberdale_spi_16bit_board_info
);
578 ip_setup
= priv
->fw
.config
& TIMB_HW_VER_MASK
;
581 err
= mfd_add_devices(&dev
->dev
, -1,
582 timberdale_cells_bar0_cfg0
,
583 ARRAY_SIZE(timberdale_cells_bar0_cfg0
),
584 &dev
->resource
[0], msix_entries
[0].vector
);
587 err
= mfd_add_devices(&dev
->dev
, -1,
588 timberdale_cells_bar0_cfg1
,
589 ARRAY_SIZE(timberdale_cells_bar0_cfg1
),
590 &dev
->resource
[0], msix_entries
[0].vector
);
593 err
= mfd_add_devices(&dev
->dev
, -1,
594 timberdale_cells_bar0_cfg2
,
595 ARRAY_SIZE(timberdale_cells_bar0_cfg2
),
596 &dev
->resource
[0], msix_entries
[0].vector
);
599 err
= mfd_add_devices(&dev
->dev
, -1,
600 timberdale_cells_bar0_cfg3
,
601 ARRAY_SIZE(timberdale_cells_bar0_cfg3
),
602 &dev
->resource
[0], msix_entries
[0].vector
);
605 dev_err(&dev
->dev
, "Uknown IP setup: %d.%d.%d\n",
606 priv
->fw
.major
, priv
->fw
.minor
, ip_setup
);
613 dev_err(&dev
->dev
, "mfd_add_devices failed: %d\n", err
);
617 err
= mfd_add_devices(&dev
->dev
, 0,
618 timberdale_cells_bar1
, ARRAY_SIZE(timberdale_cells_bar1
),
619 &dev
->resource
[1], msix_entries
[0].vector
);
621 dev_err(&dev
->dev
, "mfd_add_devices failed: %d\n", err
);
625 /* only version 0 and 3 have the iNand routed to SDHCI */
626 if (((priv
->fw
.config
& TIMB_HW_VER_MASK
) == TIMB_HW_VER0
) ||
627 ((priv
->fw
.config
& TIMB_HW_VER_MASK
) == TIMB_HW_VER3
)) {
628 err
= mfd_add_devices(&dev
->dev
, 1, timberdale_cells_bar2
,
629 ARRAY_SIZE(timberdale_cells_bar2
),
630 &dev
->resource
[2], msix_entries
[0].vector
);
632 dev_err(&dev
->dev
, "mfd_add_devices failed: %d\n", err
);
640 "Found Timberdale Card. Rev: %d.%d, HW config: 0x%02x\n",
641 priv
->fw
.major
, priv
->fw
.minor
, priv
->fw
.config
);
646 mfd_remove_devices(&dev
->dev
);
648 device_remove_file(&dev
->dev
, &dev_attr_fw_ver
);
650 pci_disable_msix(dev
);
652 iounmap(priv
->ctl_membase
);
654 release_mem_region(priv
->ctl_mapbase
, CHIPCTLSIZE
);
656 pci_set_drvdata(dev
, NULL
);
658 pci_disable_device(dev
);
662 pci_set_drvdata(dev
, NULL
);
666 static void __devexit
timb_remove(struct pci_dev
*dev
)
668 struct timberdale_device
*priv
= pci_get_drvdata(dev
);
670 mfd_remove_devices(&dev
->dev
);
672 device_remove_file(&dev
->dev
, &dev_attr_fw_ver
);
674 iounmap(priv
->ctl_membase
);
675 release_mem_region(priv
->ctl_mapbase
, CHIPCTLSIZE
);
677 pci_disable_msix(dev
);
678 pci_disable_device(dev
);
679 pci_set_drvdata(dev
, NULL
);
683 static struct pci_device_id timberdale_pci_tbl
[] = {
684 { PCI_DEVICE(PCI_VENDOR_ID_TIMB
, PCI_DEVICE_ID_TIMB
) },
687 MODULE_DEVICE_TABLE(pci
, timberdale_pci_tbl
);
689 static struct pci_driver timberdale_pci_driver
= {
691 .id_table
= timberdale_pci_tbl
,
693 .remove
= __devexit_p(timb_remove
),
696 static int __init
timberdale_init(void)
700 err
= pci_register_driver(&timberdale_pci_driver
);
703 "Failed to register PCI driver for %s device.\n",
704 timberdale_pci_driver
.name
);
708 printk(KERN_INFO
"Driver for %s has been successfully registered.\n",
709 timberdale_pci_driver
.name
);
714 static void __exit
timberdale_exit(void)
716 pci_unregister_driver(&timberdale_pci_driver
);
718 printk(KERN_INFO
"Driver for %s has been successfully unregistered.\n",
719 timberdale_pci_driver
.name
);
722 module_init(timberdale_init
);
723 module_exit(timberdale_exit
);
725 MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
726 MODULE_VERSION(DRV_VERSION
);
727 MODULE_LICENSE("GPL v2");