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 void __iomem
*reg_base
;
22 struct spi_master
*master
;
26 master
= spi_alloc_master(&pdev
->dev
, sizeof(struct octeon_spi
));
29 p
= spi_master_get_devdata(master
);
30 platform_set_drvdata(pdev
, master
);
32 reg_base
= devm_platform_ioremap_resource(pdev
, 0);
33 if (IS_ERR(reg_base
)) {
34 err
= PTR_ERR(reg_base
);
38 p
->register_base
= reg_base
;
39 p
->sys_freq
= octeon_get_io_clock_rate();
42 p
->regs
.status
= 0x08;
46 master
->num_chipselect
= 4;
47 master
->mode_bits
= SPI_CPHA
|
53 master
->transfer_one_message
= octeon_spi_transfer_one_message
;
54 master
->bits_per_word_mask
= SPI_BPW_MASK(8);
55 master
->max_speed_hz
= OCTEON_SPI_MAX_CLOCK_HZ
;
57 master
->dev
.of_node
= pdev
->dev
.of_node
;
58 err
= devm_spi_register_master(&pdev
->dev
, master
);
60 dev_err(&pdev
->dev
, "register master failed: %d\n", err
);
64 dev_info(&pdev
->dev
, "OCTEON SPI bus driver\n");
68 spi_master_put(master
);
72 static int octeon_spi_remove(struct platform_device
*pdev
)
74 struct spi_master
*master
= platform_get_drvdata(pdev
);
75 struct octeon_spi
*p
= spi_master_get_devdata(master
);
77 /* Clear the CSENA* and put everything in a known state. */
78 writeq(0, p
->register_base
+ OCTEON_SPI_CFG(p
));
83 static const struct of_device_id octeon_spi_match
[] = {
84 { .compatible
= "cavium,octeon-3010-spi", },
87 MODULE_DEVICE_TABLE(of
, octeon_spi_match
);
89 static struct platform_driver octeon_spi_driver
= {
92 .of_match_table
= octeon_spi_match
,
94 .probe
= octeon_spi_probe
,
95 .remove
= octeon_spi_remove
,
98 module_platform_driver(octeon_spi_driver
);
100 MODULE_DESCRIPTION("Cavium, Inc. OCTEON SPI bus driver");
101 MODULE_AUTHOR("David Daney");
102 MODULE_LICENSE("GPL");