mt7530-mmio.c 2.4 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,an7583-switch", .data = &mt753x_table[ID_AN7583], },
  12. { .compatible = "airoha,en7581-switch", .data = &mt753x_table[ID_EN7581], },
  13. { .compatible = "mediatek,mt7988-switch", .data = &mt753x_table[ID_MT7988], },
  14. { /* sentinel */ },
  15. };
  16. MODULE_DEVICE_TABLE(of, mt7988_of_match);
  17. static const struct regmap_config sw_regmap_config = {
  18. .name = "switch",
  19. .reg_bits = 16,
  20. .val_bits = 32,
  21. .reg_stride = 4,
  22. .max_register = MT7530_CREV,
  23. };
  24. static int
  25. mt7988_probe(struct platform_device *pdev)
  26. {
  27. struct mt7530_priv *priv;
  28. void __iomem *base_addr;
  29. int ret;
  30. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  31. if (!priv)
  32. return -ENOMEM;
  33. priv->bus = NULL;
  34. priv->dev = &pdev->dev;
  35. ret = mt7530_probe_common(priv);
  36. if (ret)
  37. return ret;
  38. priv->rstc = devm_reset_control_get(&pdev->dev, NULL);
  39. if (IS_ERR(priv->rstc)) {
  40. dev_err(&pdev->dev, "Couldn't get our reset line\n");
  41. return PTR_ERR(priv->rstc);
  42. }
  43. base_addr = devm_platform_ioremap_resource(pdev, 0);
  44. if (IS_ERR(base_addr)) {
  45. dev_err(&pdev->dev, "cannot request I/O memory space\n");
  46. return -ENXIO;
  47. }
  48. priv->regmap = devm_regmap_init_mmio(&pdev->dev, base_addr,
  49. &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 = 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");