xref: /openbmc/linux/drivers/soc/lantiq/fpi-bus.c (revision 8795a739)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *
4  *  Copyright (C) 2011-2015 John Crispin <blogic@phrozen.org>
5  *  Copyright (C) 2015 Martin Blumenstingl <martin.blumenstingl@googlemail.com>
6  *  Copyright (C) 2017 Hauke Mehrtens <hauke@hauke-m.de>
7  */
8 
9 #include <linux/device.h>
10 #include <linux/err.h>
11 #include <linux/mfd/syscon.h>
12 #include <linux/module.h>
13 #include <linux/of.h>
14 #include <linux/of_platform.h>
15 #include <linux/platform_device.h>
16 #include <linux/property.h>
17 #include <linux/regmap.h>
18 
19 #include <lantiq_soc.h>
20 
21 #define XBAR_ALWAYS_LAST	0x430
22 #define XBAR_FPI_BURST_EN	BIT(1)
23 #define XBAR_AHB_BURST_EN	BIT(2)
24 
25 #define RCU_VR9_BE_AHB1S	0x00000008
26 
27 static int ltq_fpi_probe(struct platform_device *pdev)
28 {
29 	struct device *dev = &pdev->dev;
30 	struct device_node *np = dev->of_node;
31 	struct resource *res_xbar;
32 	struct regmap *rcu_regmap;
33 	void __iomem *xbar_membase;
34 	u32 rcu_ahb_endianness_reg_offset;
35 	int ret;
36 
37 	res_xbar = platform_get_resource(pdev, IORESOURCE_MEM, 0);
38 	xbar_membase = devm_ioremap_resource(dev, res_xbar);
39 	if (IS_ERR(xbar_membase))
40 		return PTR_ERR(xbar_membase);
41 
42 	/* RCU configuration is optional */
43 	rcu_regmap = syscon_regmap_lookup_by_phandle(np, "lantiq,rcu");
44 	if (IS_ERR(rcu_regmap))
45 		return PTR_ERR(rcu_regmap);
46 
47 	ret = device_property_read_u32(dev, "lantiq,offset-endianness",
48 				       &rcu_ahb_endianness_reg_offset);
49 	if (ret) {
50 		dev_err(&pdev->dev, "Failed to get RCU reg offset\n");
51 		return ret;
52 	}
53 
54 	ret = regmap_update_bits(rcu_regmap, rcu_ahb_endianness_reg_offset,
55 				 RCU_VR9_BE_AHB1S, RCU_VR9_BE_AHB1S);
56 	if (ret) {
57 		dev_warn(&pdev->dev,
58 			 "Failed to configure RCU AHB endianness\n");
59 		return ret;
60 	}
61 
62 	/* disable fpi burst */
63 	ltq_w32_mask(XBAR_FPI_BURST_EN, 0, xbar_membase + XBAR_ALWAYS_LAST);
64 
65 	return of_platform_populate(dev->of_node, NULL, NULL, dev);
66 }
67 
68 static const struct of_device_id ltq_fpi_match[] = {
69 	{ .compatible = "lantiq,xrx200-fpi" },
70 	{},
71 };
72 MODULE_DEVICE_TABLE(of, ltq_fpi_match);
73 
74 static struct platform_driver ltq_fpi_driver = {
75 	.probe = ltq_fpi_probe,
76 	.driver = {
77 		.name = "fpi-xway",
78 		.of_match_table = ltq_fpi_match,
79 	},
80 };
81 
82 module_platform_driver(ltq_fpi_driver);
83 
84 MODULE_DESCRIPTION("Lantiq FPI bus driver");
85 MODULE_LICENSE("GPL");
86