Debian Codegraph @

drivers/spi/spi-cavium-octeon.c

raw
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2011, 2012 Cavium, Inc.
7 */
8
9 #include <linux/platform_device.h>
10 #include <linux/spi/spi.h>
11 #include <linux/module.h>
12 #include <linux/io.h>
13 #include <linux/of.h>
14
15 #include <asm/octeon/octeon.h>
16
17 #include "spi-cavium.h"
18
19 static int octeon_spi_probe(struct platform_device *pdev)
20 {
21 void __iomem *reg_base;
22 struct spi_controller *host;
23 struct octeon_spi *p;
24 int err = -ENOENT;
25
26 host = spi_alloc_host(&pdev->dev, sizeof(struct octeon_spi));
27 if (!host)
28 return -ENOMEM;
29 p = spi_controller_get_devdata(host);
30 platform_set_drvdata(pdev, host);
31
32 reg_base = devm_platform_ioremap_resource(pdev, 0);
33 if (IS_ERR(reg_base)) {
34 err = PTR_ERR(reg_base);
35 goto fail;
36 }
37
38 p->register_base = reg_base;
39 p->sys_freq = octeon_get_io_clock_rate();
40
41 p->regs.config = 0;
42 p->regs.status = 0x08;
43 p->regs.tx = 0x10;
44 p->regs.data = 0x80;
45
46 host->num_chipselect = 4;
47 host->mode_bits = SPI_CPHA |
48 SPI_CPOL |
49 SPI_CS_HIGH |
50 SPI_LSB_FIRST |
51 SPI_3WIRE;
52
53 host->transfer_one_message = octeon_spi_transfer_one_message;
54 host->bits_per_word_mask = SPI_BPW_MASK(8);
55 host->max_speed_hz = OCTEON_SPI_MAX_CLOCK_HZ;
56
57 err = spi_register_controller(host);
58 if (err) {
59 dev_err(&pdev->dev, "register host failed: %d\n", err);
60 goto fail;
61 }
62
63 dev_info(&pdev->dev, "OCTEON SPI bus driver\n");
64
65 return 0;
66 fail:
67 spi_controller_put(host);
68 return err;
69 }
70
71 static void octeon_spi_remove(struct platform_device *pdev)
72 {
73 struct spi_controller *host = platform_get_drvdata(pdev);
74 struct octeon_spi *p = spi_controller_get_devdata(host);
75
76 spi_controller_get(host);
77
78 spi_unregister_controller(host);
79
80 /* Clear the CSENA* and put everything in a known state. */
81 writeq(0, p->register_base + OCTEON_SPI_CFG(p));
82
83 spi_controller_put(host);
84 }
85
86 static const struct of_device_id octeon_spi_match[] = {
87 { .compatible = "cavium,octeon-3010-spi", },
88 {},
89 };
90 MODULE_DEVICE_TABLE(of, octeon_spi_match);
91
92 static struct platform_driver octeon_spi_driver = {
93 .driver = {
94 .name = "spi-octeon",
95 .of_match_table = octeon_spi_match,
96 },
97 .probe = octeon_spi_probe,
98 .remove = octeon_spi_remove,
99 };
100
101 module_platform_driver(octeon_spi_driver);
102
103 MODULE_DESCRIPTION("Cavium, Inc. OCTEON SPI bus driver");
104 MODULE_AUTHOR("David Daney");
105 MODULE_LICENSE("GPL");