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