xref: /openbmc/linux/drivers/soc/lantiq/fpi-bus.c (revision 806b5228)
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 regmap *rcu_regmap;
32 	void __iomem *xbar_membase;
33 	u32 rcu_ahb_endianness_reg_offset;
34 	int ret;
35 
36 	xbar_membase = devm_platform_ioremap_resource(pdev, 0);
37 	if (IS_ERR(xbar_membase))
38 		return PTR_ERR(xbar_membase);
39 
40 	/* RCU configuration is optional */
41 	rcu_regmap = syscon_regmap_lookup_by_phandle(np, "lantiq,rcu");
42 	if (IS_ERR(rcu_regmap))
43 		return PTR_ERR(rcu_regmap);
44 
45 	ret = device_property_read_u32(dev, "lantiq,offset-endianness",
46 				       &rcu_ahb_endianness_reg_offset);
47 	if (ret) {
48 		dev_err(&pdev->dev, "Failed to get RCU reg offset\n");
49 		return ret;
50 	}
51 
52 	ret = regmap_update_bits(rcu_regmap, rcu_ahb_endianness_reg_offset,
53 				 RCU_VR9_BE_AHB1S, RCU_VR9_BE_AHB1S);
54 	if (ret) {
55 		dev_warn(&pdev->dev,
56 			 "Failed to configure RCU AHB endianness\n");
57 		return ret;
58 	}
59 
60 	/* disable fpi burst */
61 	ltq_w32_mask(XBAR_FPI_BURST_EN, 0, xbar_membase + XBAR_ALWAYS_LAST);
62 
63 	return of_platform_populate(dev->of_node, NULL, NULL, dev);
64 }
65 
66 static const struct of_device_id ltq_fpi_match[] = {
67 	{ .compatible = "lantiq,xrx200-fpi" },
68 	{},
69 };
70 MODULE_DEVICE_TABLE(of, ltq_fpi_match);
71 
72 static struct platform_driver ltq_fpi_driver = {
73 	.probe = ltq_fpi_probe,
74 	.driver = {
75 		.name = "fpi-xway",
76 		.of_match_table = ltq_fpi_match,
77 	},
78 };
79 
80 module_platform_driver(ltq_fpi_driver);
81 
82 MODULE_DESCRIPTION("Lantiq FPI bus driver");
83 MODULE_LICENSE("GPL");
84