xref: /linux/drivers/net/dsa/mt7530-mmio.c (revision 25489a4f556414445d342951615178368ee45cde)
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #include <linux/mod_devicetable.h>
4 #include <linux/module.h>
5 #include <linux/platform_device.h>
6 #include <linux/regmap.h>
7 #include <linux/regulator/consumer.h>
8 #include <linux/reset.h>
9 #include <net/dsa.h>
10 
11 #include "mt7530.h"
12 
13 static const struct of_device_id mt7988_of_match[] = {
14 	{ .compatible = "airoha,an7583-switch", .data = &mt753x_table[ID_AN7583], },
15 	{ .compatible = "airoha,en7581-switch", .data = &mt753x_table[ID_EN7581], },
16 	{ .compatible = "mediatek,mt7988-switch", .data = &mt753x_table[ID_MT7988], },
17 	{ /* sentinel */ },
18 };
19 MODULE_DEVICE_TABLE(of, mt7988_of_match);
20 
21 static int
22 mt7988_probe(struct platform_device *pdev)
23 {
24 	static struct regmap_config *sw_regmap_config;
25 	struct mt7530_priv *priv;
26 	void __iomem *base_addr;
27 	int ret;
28 
29 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
30 	if (!priv)
31 		return -ENOMEM;
32 
33 	priv->bus = NULL;
34 	priv->dev = &pdev->dev;
35 
36 	ret = mt7530_probe_common(priv);
37 	if (ret)
38 		return ret;
39 
40 	priv->rstc = devm_reset_control_get(&pdev->dev, NULL);
41 	if (IS_ERR(priv->rstc)) {
42 		dev_err(&pdev->dev, "Couldn't get our reset line\n");
43 		return PTR_ERR(priv->rstc);
44 	}
45 
46 	base_addr = devm_platform_ioremap_resource(pdev, 0);
47 	if (IS_ERR(base_addr)) {
48 		dev_err(&pdev->dev, "cannot request I/O memory space\n");
49 		return -ENXIO;
50 	}
51 
52 	sw_regmap_config = devm_kzalloc(&pdev->dev, sizeof(*sw_regmap_config), GFP_KERNEL);
53 	if (!sw_regmap_config)
54 		return -ENOMEM;
55 
56 	sw_regmap_config->name = "switch";
57 	sw_regmap_config->reg_bits = 16;
58 	sw_regmap_config->val_bits = 32;
59 	sw_regmap_config->reg_stride = 4;
60 	sw_regmap_config->max_register = MT7530_CREV;
61 	priv->regmap = devm_regmap_init_mmio(&pdev->dev, base_addr, sw_regmap_config);
62 	if (IS_ERR(priv->regmap))
63 		return PTR_ERR(priv->regmap);
64 
65 	return dsa_register_switch(priv->ds);
66 }
67 
68 static void mt7988_remove(struct platform_device *pdev)
69 {
70 	struct mt7530_priv *priv = platform_get_drvdata(pdev);
71 
72 	if (priv)
73 		mt7530_remove_common(priv);
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