xref: /openbmc/linux/drivers/ata/ahci_octeon.c (revision 046b212a)
1 /*
2  * SATA glue for Cavium Octeon III SOCs.
3  *
4  *
5  * This file is subject to the terms and conditions of the GNU General Public
6  * License.  See the file "COPYING" in the main directory of this archive
7  * for more details.
8  *
9  * Copyright (C) 2010-2015 Cavium Networks
10  *
11  */
12 
13 #include <linux/module.h>
14 #include <linux/dma-mapping.h>
15 #include <linux/platform_device.h>
16 #include <linux/of_platform.h>
17 
18 #include <asm/octeon/octeon.h>
19 
20 #define CVMX_SATA_UCTL_SHIM_CFG		0xE8
21 
22 #define SATA_UCTL_ENDIAN_MODE_BIG	1
23 #define SATA_UCTL_ENDIAN_MODE_LITTLE	0
24 #define SATA_UCTL_ENDIAN_MODE_MASK	3
25 
26 #define SATA_UCTL_DMA_ENDIAN_MODE_SHIFT	8
27 #define SATA_UCTL_CSR_ENDIAN_MODE_SHIFT	0
28 #define SATA_UCTL_DMA_READ_CMD_SHIFT	12
29 
30 static int ahci_octeon_probe(struct platform_device *pdev)
31 {
32 	struct device *dev = &pdev->dev;
33 	struct device_node *node = dev->of_node;
34 	void __iomem *base;
35 	u64 cfg;
36 	int ret;
37 
38 	base = devm_platform_ioremap_resource(pdev, 0);
39 	if (IS_ERR(base))
40 		return PTR_ERR(base);
41 
42 	cfg = cvmx_readq_csr(base + CVMX_SATA_UCTL_SHIM_CFG);
43 
44 	cfg &= ~(SATA_UCTL_ENDIAN_MODE_MASK << SATA_UCTL_DMA_ENDIAN_MODE_SHIFT);
45 	cfg &= ~(SATA_UCTL_ENDIAN_MODE_MASK << SATA_UCTL_CSR_ENDIAN_MODE_SHIFT);
46 
47 #ifdef __BIG_ENDIAN
48 	cfg |= SATA_UCTL_ENDIAN_MODE_BIG << SATA_UCTL_DMA_ENDIAN_MODE_SHIFT;
49 	cfg |= SATA_UCTL_ENDIAN_MODE_BIG << SATA_UCTL_CSR_ENDIAN_MODE_SHIFT;
50 #else
51 	cfg |= SATA_UCTL_ENDIAN_MODE_LITTLE << SATA_UCTL_DMA_ENDIAN_MODE_SHIFT;
52 	cfg |= SATA_UCTL_ENDIAN_MODE_LITTLE << SATA_UCTL_CSR_ENDIAN_MODE_SHIFT;
53 #endif
54 
55 	cfg |= 1 << SATA_UCTL_DMA_READ_CMD_SHIFT;
56 
57 	cvmx_writeq_csr(base + CVMX_SATA_UCTL_SHIM_CFG, cfg);
58 
59 	if (!node) {
60 		dev_err(dev, "no device node, failed to add octeon sata\n");
61 		return -ENODEV;
62 	}
63 
64 	ret = of_platform_populate(node, NULL, NULL, dev);
65 	if (ret) {
66 		dev_err(dev, "failed to add ahci-platform core\n");
67 		return ret;
68 	}
69 
70 	return 0;
71 }
72 
73 static const struct of_device_id octeon_ahci_match[] = {
74 	{ .compatible = "cavium,octeon-7130-sata-uctl", },
75 	{ /* sentinel */ }
76 };
77 MODULE_DEVICE_TABLE(of, octeon_ahci_match);
78 
79 static struct platform_driver ahci_octeon_driver = {
80 	.probe          = ahci_octeon_probe,
81 	.driver         = {
82 		.name   = "octeon-ahci",
83 		.of_match_table = octeon_ahci_match,
84 	},
85 };
86 
87 module_platform_driver(ahci_octeon_driver);
88 
89 MODULE_LICENSE("GPL");
90 MODULE_AUTHOR("Cavium, Inc. <support@cavium.com>");
91 MODULE_DESCRIPTION("Cavium Inc. sata config.");
92