ocelot_ext.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SPDX-License-Identifier: (GPL-2.0 OR MIT)
  2. /*
  3. * Copyright 2021-2022 Innovative Advantage Inc.
  4. */
  5. #include <linux/mfd/ocelot.h>
  6. #include <linux/platform_device.h>
  7. #include <linux/regmap.h>
  8. #include <soc/mscc/ocelot.h>
  9. #include <soc/mscc/vsc7514_regs.h>
  10. #include "felix.h"
  11. #define VSC7514_NUM_PORTS 11
  12. #define OCELOT_PORT_MODE_SERDES (OCELOT_PORT_MODE_SGMII | \
  13. OCELOT_PORT_MODE_QSGMII)
  14. static const u32 vsc7512_port_modes[VSC7514_NUM_PORTS] = {
  15. OCELOT_PORT_MODE_INTERNAL,
  16. OCELOT_PORT_MODE_INTERNAL,
  17. OCELOT_PORT_MODE_INTERNAL,
  18. OCELOT_PORT_MODE_INTERNAL,
  19. OCELOT_PORT_MODE_SERDES,
  20. OCELOT_PORT_MODE_SERDES,
  21. OCELOT_PORT_MODE_SERDES,
  22. OCELOT_PORT_MODE_SERDES,
  23. OCELOT_PORT_MODE_SERDES,
  24. OCELOT_PORT_MODE_SGMII,
  25. OCELOT_PORT_MODE_SERDES,
  26. };
  27. static const struct ocelot_ops ocelot_ext_ops = {
  28. .reset = ocelot_reset,
  29. .wm_enc = ocelot_wm_enc,
  30. .wm_dec = ocelot_wm_dec,
  31. .wm_stat = ocelot_wm_stat,
  32. .port_to_netdev = felix_port_to_netdev,
  33. .netdev_to_port = felix_netdev_to_port,
  34. };
  35. static const char * const vsc7512_resource_names[TARGET_MAX] = {
  36. [SYS] = "sys",
  37. [REW] = "rew",
  38. [S0] = "s0",
  39. [S1] = "s1",
  40. [S2] = "s2",
  41. [QS] = "qs",
  42. [QSYS] = "qsys",
  43. [ANA] = "ana",
  44. };
  45. static const struct felix_info vsc7512_info = {
  46. .resource_names = vsc7512_resource_names,
  47. .regfields = vsc7514_regfields,
  48. .map = vsc7514_regmap,
  49. .ops = &ocelot_ext_ops,
  50. .vcap = vsc7514_vcap_props,
  51. .num_mact_rows = 1024,
  52. .num_ports = VSC7514_NUM_PORTS,
  53. .port_modes = vsc7512_port_modes,
  54. .phylink_mac_config = ocelot_phylink_mac_config,
  55. .configure_serdes = ocelot_port_configure_serdes,
  56. };
  57. static int ocelot_ext_probe(struct platform_device *pdev)
  58. {
  59. return felix_register_switch(&pdev->dev, 0, 1, false, false,
  60. DSA_TAG_PROTO_OCELOT, &vsc7512_info);
  61. }
  62. static void ocelot_ext_remove(struct platform_device *pdev)
  63. {
  64. struct felix *felix = dev_get_drvdata(&pdev->dev);
  65. if (!felix)
  66. return;
  67. dsa_unregister_switch(felix->ds);
  68. }
  69. static void ocelot_ext_shutdown(struct platform_device *pdev)
  70. {
  71. struct felix *felix = dev_get_drvdata(&pdev->dev);
  72. if (!felix)
  73. return;
  74. dsa_switch_shutdown(felix->ds);
  75. dev_set_drvdata(&pdev->dev, NULL);
  76. }
  77. static const struct of_device_id ocelot_ext_switch_of_match[] = {
  78. { .compatible = "mscc,vsc7512-switch" },
  79. { },
  80. };
  81. MODULE_DEVICE_TABLE(of, ocelot_ext_switch_of_match);
  82. static struct platform_driver ocelot_ext_switch_driver = {
  83. .driver = {
  84. .name = "ocelot-ext-switch",
  85. .of_match_table = ocelot_ext_switch_of_match,
  86. },
  87. .probe = ocelot_ext_probe,
  88. .remove_new = ocelot_ext_remove,
  89. .shutdown = ocelot_ext_shutdown,
  90. };
  91. module_platform_driver(ocelot_ext_switch_driver);
  92. MODULE_DESCRIPTION("External Ocelot Switch driver");
  93. MODULE_LICENSE("GPL");
  94. MODULE_IMPORT_NS(MFD_OCELOT);