163d49afeSJan Glauber /*
263d49afeSJan Glauber * This file is subject to the terms and conditions of the GNU General Public
363d49afeSJan Glauber * License. See the file "COPYING" in the main directory of this archive
463d49afeSJan Glauber * for more details.
563d49afeSJan Glauber *
663d49afeSJan Glauber * Copyright (C) 2011, 2012 Cavium, Inc.
763d49afeSJan Glauber */
863d49afeSJan Glauber
963d49afeSJan Glauber #include <linux/platform_device.h>
1063d49afeSJan Glauber #include <linux/spi/spi.h>
1163d49afeSJan Glauber #include <linux/module.h>
1263d49afeSJan Glauber #include <linux/io.h>
1363d49afeSJan Glauber #include <linux/of.h>
1463d49afeSJan Glauber
1563d49afeSJan Glauber #include <asm/octeon/octeon.h>
1663d49afeSJan Glauber
1763d49afeSJan Glauber #include "spi-cavium.h"
1863d49afeSJan Glauber
octeon_spi_probe(struct platform_device * pdev)1963d49afeSJan Glauber static int octeon_spi_probe(struct platform_device *pdev)
2063d49afeSJan Glauber {
2163d49afeSJan Glauber void __iomem *reg_base;
22*d2a44ae8SYang Yingliang struct spi_controller *host;
2363d49afeSJan Glauber struct octeon_spi *p;
2463d49afeSJan Glauber int err = -ENOENT;
2563d49afeSJan Glauber
26*d2a44ae8SYang Yingliang host = spi_alloc_host(&pdev->dev, sizeof(struct octeon_spi));
27*d2a44ae8SYang Yingliang if (!host)
2863d49afeSJan Glauber return -ENOMEM;
29*d2a44ae8SYang Yingliang p = spi_controller_get_devdata(host);
30*d2a44ae8SYang Yingliang platform_set_drvdata(pdev, host);
3163d49afeSJan Glauber
32050688dcSYueHaibing reg_base = devm_platform_ioremap_resource(pdev, 0);
3363d49afeSJan Glauber if (IS_ERR(reg_base)) {
3463d49afeSJan Glauber err = PTR_ERR(reg_base);
3563d49afeSJan Glauber goto fail;
3663d49afeSJan Glauber }
3763d49afeSJan Glauber
3863d49afeSJan Glauber p->register_base = reg_base;
3963d49afeSJan Glauber p->sys_freq = octeon_get_io_clock_rate();
4063d49afeSJan Glauber
4163d49afeSJan Glauber p->regs.config = 0;
4263d49afeSJan Glauber p->regs.status = 0x08;
4363d49afeSJan Glauber p->regs.tx = 0x10;
4463d49afeSJan Glauber p->regs.data = 0x80;
4563d49afeSJan Glauber
46*d2a44ae8SYang Yingliang host->num_chipselect = 4;
47*d2a44ae8SYang Yingliang host->mode_bits = SPI_CPHA |
4863d49afeSJan Glauber SPI_CPOL |
4963d49afeSJan Glauber SPI_CS_HIGH |
5063d49afeSJan Glauber SPI_LSB_FIRST |
5163d49afeSJan Glauber SPI_3WIRE;
5263d49afeSJan Glauber
53*d2a44ae8SYang Yingliang host->transfer_one_message = octeon_spi_transfer_one_message;
54*d2a44ae8SYang Yingliang host->bits_per_word_mask = SPI_BPW_MASK(8);
55*d2a44ae8SYang Yingliang host->max_speed_hz = OCTEON_SPI_MAX_CLOCK_HZ;
5663d49afeSJan Glauber
57*d2a44ae8SYang Yingliang host->dev.of_node = pdev->dev.of_node;
58*d2a44ae8SYang Yingliang err = devm_spi_register_controller(&pdev->dev, host);
5963d49afeSJan Glauber if (err) {
60*d2a44ae8SYang Yingliang dev_err(&pdev->dev, "register host failed: %d\n", err);
6163d49afeSJan Glauber goto fail;
6263d49afeSJan Glauber }
6363d49afeSJan Glauber
6463d49afeSJan Glauber dev_info(&pdev->dev, "OCTEON SPI bus driver\n");
6563d49afeSJan Glauber
6663d49afeSJan Glauber return 0;
6763d49afeSJan Glauber fail:
68*d2a44ae8SYang Yingliang spi_controller_put(host);
6963d49afeSJan Glauber return err;
7063d49afeSJan Glauber }
7163d49afeSJan Glauber
octeon_spi_remove(struct platform_device * pdev)72f74d4b8bSUwe Kleine-König static void octeon_spi_remove(struct platform_device *pdev)
7363d49afeSJan Glauber {
74*d2a44ae8SYang Yingliang struct spi_controller *host = platform_get_drvdata(pdev);
75*d2a44ae8SYang Yingliang struct octeon_spi *p = spi_controller_get_devdata(host);
7663d49afeSJan Glauber
7763d49afeSJan Glauber /* Clear the CSENA* and put everything in a known state. */
7863d49afeSJan Glauber writeq(0, p->register_base + OCTEON_SPI_CFG(p));
7963d49afeSJan Glauber }
8063d49afeSJan Glauber
8163d49afeSJan Glauber static const struct of_device_id octeon_spi_match[] = {
8263d49afeSJan Glauber { .compatible = "cavium,octeon-3010-spi", },
8363d49afeSJan Glauber {},
8463d49afeSJan Glauber };
8563d49afeSJan Glauber MODULE_DEVICE_TABLE(of, octeon_spi_match);
8663d49afeSJan Glauber
8763d49afeSJan Glauber static struct platform_driver octeon_spi_driver = {
8863d49afeSJan Glauber .driver = {
8963d49afeSJan Glauber .name = "spi-octeon",
9063d49afeSJan Glauber .of_match_table = octeon_spi_match,
9163d49afeSJan Glauber },
9263d49afeSJan Glauber .probe = octeon_spi_probe,
93f74d4b8bSUwe Kleine-König .remove_new = octeon_spi_remove,
9463d49afeSJan Glauber };
9563d49afeSJan Glauber
9663d49afeSJan Glauber module_platform_driver(octeon_spi_driver);
9763d49afeSJan Glauber
9863d49afeSJan Glauber MODULE_DESCRIPTION("Cavium, Inc. OCTEON SPI bus driver");
9963d49afeSJan Glauber MODULE_AUTHOR("David Daney");
10063d49afeSJan Glauber MODULE_LICENSE("GPL");
101