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
13static const struct of_device_id mt7988_of_match[] = {
14 { .compatible = "mediatek,mt7988-switch", .data = &mt753x_table[ID_MT7988], },
15 { /* sentinel */ },
16};
17MODULE_DEVICE_TABLE(of, mt7988_of_match);
18
19static int
20mt7988_probe(struct platform_device *pdev)
21{
22 static struct regmap_config *sw_regmap_config;
23 struct mt7530_priv *priv;
24 void __iomem *base_addr;
25 int ret;
26
27 priv = devm_kzalloc(dev: &pdev->dev, size: sizeof(*priv), GFP_KERNEL);
28 if (!priv)
29 return -ENOMEM;
30
31 priv->bus = NULL;
32 priv->dev = &pdev->dev;
33
34 ret = mt7530_probe_common(priv);
35 if (ret)
36 return ret;
37
38 priv->rstc = devm_reset_control_get(dev: &pdev->dev, NULL);
39 if (IS_ERR(ptr: priv->rstc)) {
40 dev_err(&pdev->dev, "Couldn't get our reset line\n");
41 return PTR_ERR(ptr: priv->rstc);
42 }
43
44 base_addr = devm_platform_ioremap_resource(pdev, index: 0);
45 if (IS_ERR(ptr: base_addr)) {
46 dev_err(&pdev->dev, "cannot request I/O memory space\n");
47 return -ENXIO;
48 }
49
50 sw_regmap_config = devm_kzalloc(dev: &pdev->dev, size: sizeof(*sw_regmap_config), GFP_KERNEL);
51 if (!sw_regmap_config)
52 return -ENOMEM;
53
54 sw_regmap_config->name = "switch";
55 sw_regmap_config->reg_bits = 16;
56 sw_regmap_config->val_bits = 32;
57 sw_regmap_config->reg_stride = 4;
58 sw_regmap_config->max_register = MT7530_CREV;
59 priv->regmap = devm_regmap_init_mmio(&pdev->dev, base_addr, sw_regmap_config);
60 if (IS_ERR(ptr: priv->regmap))
61 return PTR_ERR(ptr: priv->regmap);
62
63 return dsa_register_switch(ds: priv->ds);
64}
65
66static void 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
74static void mt7988_shutdown(struct platform_device *pdev)
75{
76 struct mt7530_priv *priv = platform_get_drvdata(pdev);
77
78 if (!priv)
79 return;
80
81 dsa_switch_shutdown(ds: priv->ds);
82
83 dev_set_drvdata(dev: &pdev->dev, NULL);
84}
85
86static struct platform_driver mt7988_platform_driver = {
87 .probe = mt7988_probe,
88 .remove_new = mt7988_remove,
89 .shutdown = mt7988_shutdown,
90 .driver = {
91 .name = "mt7530-mmio",
92 .of_match_table = mt7988_of_match,
93 },
94};
95module_platform_driver(mt7988_platform_driver);
96
97MODULE_AUTHOR("Daniel Golle <daniel@makrotopia.org>");
98MODULE_DESCRIPTION("Driver for Mediatek MT7530 Switch (MMIO)");
99MODULE_LICENSE("GPL");
100

source code of linux/drivers/net/dsa/mt7530-mmio.c