1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2019 MediaTek Inc.
3  *
4  * Author: Ryder Lee <ryder.lee@mediatek.com>
5  *         Felix Fietkau <nbd@nbd.name>
6  */
7 
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/regmap.h>
12 #include <linux/mfd/syscon.h>
13 #include <linux/of.h>
14 #include "mt7615.h"
15 
16 int mt7622_wmac_init(struct mt7615_dev *dev)
17 {
18 	struct device_node *np = dev->mt76.dev->of_node;
19 
20 	if (!is_mt7622(&dev->mt76))
21 		return 0;
22 
23 	dev->infracfg = syscon_regmap_lookup_by_phandle(np, "mediatek,infracfg");
24 	if (IS_ERR(dev->infracfg)) {
25 		dev_err(dev->mt76.dev, "Cannot find infracfg controller\n");
26 		return PTR_ERR(dev->infracfg);
27 	}
28 
29 	return 0;
30 }
31 
32 static int mt7622_wmac_probe(struct platform_device *pdev)
33 {
34 	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
35 	void __iomem *mem_base;
36 	int irq;
37 
38 	irq = platform_get_irq(pdev, 0);
39 	if (irq < 0)
40 		return irq;
41 
42 	mem_base = devm_ioremap_resource(&pdev->dev, res);
43 	if (IS_ERR(mem_base))
44 		return PTR_ERR(mem_base);
45 
46 	return mt7615_mmio_probe(&pdev->dev, mem_base, irq, mt7615e_reg_map);
47 }
48 
49 static int mt7622_wmac_remove(struct platform_device *pdev)
50 {
51 	struct mt7615_dev *dev = platform_get_drvdata(pdev);
52 
53 	mt7615_unregister_device(dev);
54 
55 	return 0;
56 }
57 
58 static const struct of_device_id mt7622_wmac_of_match[] = {
59 	{ .compatible = "mediatek,mt7622-wmac" },
60 	{},
61 };
62 
63 struct platform_driver mt7622_wmac_driver = {
64 	.driver = {
65 		.name = "mt7622-wmac",
66 		.of_match_table = mt7622_wmac_of_match,
67 	},
68 	.probe = mt7622_wmac_probe,
69 	.remove = mt7622_wmac_remove,
70 };
71 
72 MODULE_FIRMWARE(MT7622_FIRMWARE_N9);
73 MODULE_FIRMWARE(MT7622_ROM_PATCH);
74