Linux Audio

Check our new training course

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