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
6 * Copyright (C) 2011, 2012 Cavium, Inc.
9 #include <linux/platform_device.h>
10 #include <linux/spi/spi.h>
11 #include <linux/module.h>
15 #include <asm/octeon/octeon.h>
17 #include "spi-cavium.h"
19 static int octeon_spi_probe(struct platform_device
*pdev
)
21 struct resource
*res_mem
;
22 void __iomem
*reg_base
;
23 struct spi_master
*master
;
27 master
= spi_alloc_master(&pdev
->dev
, sizeof(struct octeon_spi
));
30 p
= spi_master_get_devdata(master
);
31 platform_set_drvdata(pdev
, master
);
33 res_mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
34 reg_base
= devm_ioremap_resource(&pdev
->dev
, res_mem
);
35 if (IS_ERR(reg_base
)) {
36 err
= PTR_ERR(reg_base
);
40 p
->register_base
= reg_base
;
41 p
->sys_freq
= octeon_get_io_clock_rate();
44 p
->regs
.status
= 0x08;
48 master
->num_chipselect
= 4;
49 master
->mode_bits
= SPI_CPHA
|
55 master
->transfer_one_message
= octeon_spi_transfer_one_message
;
56 master
->bits_per_word_mask
= SPI_BPW_MASK(8);
57 master
->max_speed_hz
= OCTEON_SPI_MAX_CLOCK_HZ
;
59 master
->dev
.of_node
= pdev
->dev
.of_node
;
60 err
= devm_spi_register_master(&pdev
->dev
, master
);
62 dev_err(&pdev
->dev
, "register master failed: %d\n", err
);
66 dev_info(&pdev
->dev
, "OCTEON SPI bus driver\n");
70 spi_master_put(master
);
74 static int octeon_spi_remove(struct platform_device
*pdev
)
76 struct spi_master
*master
= platform_get_drvdata(pdev
);
77 struct octeon_spi
*p
= spi_master_get_devdata(master
);
79 /* Clear the CSENA* and put everything in a known state. */
80 writeq(0, p
->register_base
+ OCTEON_SPI_CFG(p
));
85 static const struct of_device_id octeon_spi_match
[] = {
86 { .compatible
= "cavium,octeon-3010-spi", },
89 MODULE_DEVICE_TABLE(of
, octeon_spi_match
);
91 static struct platform_driver octeon_spi_driver
= {
94 .of_match_table
= octeon_spi_match
,
96 .probe
= octeon_spi_probe
,
97 .remove
= octeon_spi_remove
,
100 module_platform_driver(octeon_spi_driver
);
102 MODULE_DESCRIPTION("Cavium, Inc. OCTEON SPI bus driver");
103 MODULE_AUTHOR("David Daney");
104 MODULE_LICENSE("GPL");