xref: /openbmc/linux/drivers/net/dsa/mt7530-mmio.c (revision 726ccdba)
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #include <linux/module.h>
4 #include <linux/of_platform.h>
5 #include <linux/regmap.h>
6 #include <linux/regulator/consumer.h>
7 #include <linux/reset.h>
8 #include <net/dsa.h>
9 
10 #include "mt7530.h"
11 
12 static const struct of_device_id mt7988_of_match[] = {
13 	{ .compatible = "mediatek,mt7988-switch", .data = &mt753x_table[ID_MT7988], },
14 	{ /* sentinel */ },
15 };
16 MODULE_DEVICE_TABLE(of, mt7988_of_match);
17 
18 static int
19 mt7988_probe(struct platform_device *pdev)
20 {
21 	static struct regmap_config *sw_regmap_config;
22 	struct mt7530_priv *priv;
23 	void __iomem *base_addr;
24 	int ret;
25 
26 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
27 	if (!priv)
28 		return -ENOMEM;
29 
30 	priv->bus = NULL;
31 	priv->dev = &pdev->dev;
32 
33 	ret = mt7530_probe_common(priv);
34 	if (ret)
35 		return ret;
36 
37 	priv->rstc = devm_reset_control_get(&pdev->dev, NULL);
38 	if (IS_ERR(priv->rstc)) {
39 		dev_err(&pdev->dev, "Couldn't get our reset line\n");
40 		return PTR_ERR(priv->rstc);
41 	}
42 
43 	base_addr = devm_platform_ioremap_resource(pdev, 0);
44 	if (IS_ERR(base_addr)) {
45 		dev_err(&pdev->dev, "cannot request I/O memory space\n");
46 		return -ENXIO;
47 	}
48 
49 	sw_regmap_config = devm_kzalloc(&pdev->dev, sizeof(*sw_regmap_config), GFP_KERNEL);
50 	if (!sw_regmap_config)
51 		return -ENOMEM;
52 
53 	sw_regmap_config->name = "switch";
54 	sw_regmap_config->reg_bits = 16;
55 	sw_regmap_config->val_bits = 32;
56 	sw_regmap_config->reg_stride = 4;
57 	sw_regmap_config->max_register = MT7530_CREV;
58 	priv->regmap = devm_regmap_init_mmio(&pdev->dev, base_addr, sw_regmap_config);
59 	if (IS_ERR(priv->regmap))
60 		return PTR_ERR(priv->regmap);
61 
62 	return dsa_register_switch(priv->ds);
63 }
64 
65 static int
66 mt7988_remove(struct platform_device *pdev)
67 {
68 	struct mt7530_priv *priv = platform_get_drvdata(pdev);
69 
70 	if (priv)
71 		mt7530_remove_common(priv);
72 
73 	return 0;
74 }
75 
76 static void mt7988_shutdown(struct platform_device *pdev)
77 {
78 	struct mt7530_priv *priv = platform_get_drvdata(pdev);
79 
80 	if (!priv)
81 		return;
82 
83 	dsa_switch_shutdown(priv->ds);
84 
85 	dev_set_drvdata(&pdev->dev, NULL);
86 }
87 
88 static struct platform_driver mt7988_platform_driver = {
89 	.probe  = mt7988_probe,
90 	.remove = mt7988_remove,
91 	.shutdown = mt7988_shutdown,
92 	.driver = {
93 		.name = "mt7530-mmio",
94 		.of_match_table = mt7988_of_match,
95 	},
96 };
97 module_platform_driver(mt7988_platform_driver);
98 
99 MODULE_AUTHOR("Daniel Golle <daniel@makrotopia.org>");
100 MODULE_DESCRIPTION("Driver for Mediatek MT7530 Switch (MMIO)");
101 MODULE_LICENSE("GPL");
102