mt7530-mmio.c 2.5 KB

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