1*3d7316acSColin Foster // SPDX-License-Identifier: (GPL-2.0 OR MIT) 2*3d7316acSColin Foster /* 3*3d7316acSColin Foster * Copyright 2021-2022 Innovative Advantage Inc. 4*3d7316acSColin Foster */ 5*3d7316acSColin Foster 6*3d7316acSColin Foster #include <linux/mfd/ocelot.h> 7*3d7316acSColin Foster #include <linux/phylink.h> 8*3d7316acSColin Foster #include <linux/platform_device.h> 9*3d7316acSColin Foster #include <linux/regmap.h> 10*3d7316acSColin Foster #include <soc/mscc/ocelot.h> 11*3d7316acSColin Foster #include <soc/mscc/vsc7514_regs.h> 12*3d7316acSColin Foster #include "felix.h" 13*3d7316acSColin Foster 14*3d7316acSColin Foster #define VSC7514_NUM_PORTS 11 15*3d7316acSColin Foster 16*3d7316acSColin Foster #define OCELOT_PORT_MODE_SERDES (OCELOT_PORT_MODE_SGMII | \ 17*3d7316acSColin Foster OCELOT_PORT_MODE_QSGMII) 18*3d7316acSColin Foster 19*3d7316acSColin Foster static const u32 vsc7512_port_modes[VSC7514_NUM_PORTS] = { 20*3d7316acSColin Foster OCELOT_PORT_MODE_INTERNAL, 21*3d7316acSColin Foster OCELOT_PORT_MODE_INTERNAL, 22*3d7316acSColin Foster OCELOT_PORT_MODE_INTERNAL, 23*3d7316acSColin Foster OCELOT_PORT_MODE_INTERNAL, 24*3d7316acSColin Foster OCELOT_PORT_MODE_NONE, 25*3d7316acSColin Foster OCELOT_PORT_MODE_NONE, 26*3d7316acSColin Foster OCELOT_PORT_MODE_NONE, 27*3d7316acSColin Foster OCELOT_PORT_MODE_NONE, 28*3d7316acSColin Foster OCELOT_PORT_MODE_NONE, 29*3d7316acSColin Foster OCELOT_PORT_MODE_NONE, 30*3d7316acSColin Foster OCELOT_PORT_MODE_NONE, 31*3d7316acSColin Foster }; 32*3d7316acSColin Foster 33*3d7316acSColin Foster static const struct ocelot_ops ocelot_ext_ops = { 34*3d7316acSColin Foster .reset = ocelot_reset, 35*3d7316acSColin Foster .wm_enc = ocelot_wm_enc, 36*3d7316acSColin Foster .wm_dec = ocelot_wm_dec, 37*3d7316acSColin Foster .wm_stat = ocelot_wm_stat, 38*3d7316acSColin Foster .port_to_netdev = felix_port_to_netdev, 39*3d7316acSColin Foster .netdev_to_port = felix_netdev_to_port, 40*3d7316acSColin Foster }; 41*3d7316acSColin Foster 42*3d7316acSColin Foster static const char * const vsc7512_resource_names[TARGET_MAX] = { 43*3d7316acSColin Foster [SYS] = "sys", 44*3d7316acSColin Foster [REW] = "rew", 45*3d7316acSColin Foster [S0] = "s0", 46*3d7316acSColin Foster [S1] = "s1", 47*3d7316acSColin Foster [S2] = "s2", 48*3d7316acSColin Foster [QS] = "qs", 49*3d7316acSColin Foster [QSYS] = "qsys", 50*3d7316acSColin Foster [ANA] = "ana", 51*3d7316acSColin Foster }; 52*3d7316acSColin Foster 53*3d7316acSColin Foster static const struct felix_info vsc7512_info = { 54*3d7316acSColin Foster .resource_names = vsc7512_resource_names, 55*3d7316acSColin Foster .regfields = vsc7514_regfields, 56*3d7316acSColin Foster .map = vsc7514_regmap, 57*3d7316acSColin Foster .ops = &ocelot_ext_ops, 58*3d7316acSColin Foster .vcap = vsc7514_vcap_props, 59*3d7316acSColin Foster .num_mact_rows = 1024, 60*3d7316acSColin Foster .num_ports = VSC7514_NUM_PORTS, 61*3d7316acSColin Foster .num_tx_queues = OCELOT_NUM_TC, 62*3d7316acSColin Foster .port_modes = vsc7512_port_modes, 63*3d7316acSColin Foster }; 64*3d7316acSColin Foster 65*3d7316acSColin Foster static int ocelot_ext_probe(struct platform_device *pdev) 66*3d7316acSColin Foster { 67*3d7316acSColin Foster struct device *dev = &pdev->dev; 68*3d7316acSColin Foster struct dsa_switch *ds; 69*3d7316acSColin Foster struct ocelot *ocelot; 70*3d7316acSColin Foster struct felix *felix; 71*3d7316acSColin Foster int err; 72*3d7316acSColin Foster 73*3d7316acSColin Foster felix = kzalloc(sizeof(*felix), GFP_KERNEL); 74*3d7316acSColin Foster if (!felix) 75*3d7316acSColin Foster return -ENOMEM; 76*3d7316acSColin Foster 77*3d7316acSColin Foster dev_set_drvdata(dev, felix); 78*3d7316acSColin Foster 79*3d7316acSColin Foster ocelot = &felix->ocelot; 80*3d7316acSColin Foster ocelot->dev = dev; 81*3d7316acSColin Foster 82*3d7316acSColin Foster ocelot->num_flooding_pgids = 1; 83*3d7316acSColin Foster 84*3d7316acSColin Foster felix->info = &vsc7512_info; 85*3d7316acSColin Foster 86*3d7316acSColin Foster ds = kzalloc(sizeof(*ds), GFP_KERNEL); 87*3d7316acSColin Foster if (!ds) { 88*3d7316acSColin Foster err = -ENOMEM; 89*3d7316acSColin Foster dev_err_probe(dev, err, "Failed to allocate DSA switch\n"); 90*3d7316acSColin Foster goto err_free_felix; 91*3d7316acSColin Foster } 92*3d7316acSColin Foster 93*3d7316acSColin Foster ds->dev = dev; 94*3d7316acSColin Foster ds->num_ports = felix->info->num_ports; 95*3d7316acSColin Foster ds->num_tx_queues = felix->info->num_tx_queues; 96*3d7316acSColin Foster 97*3d7316acSColin Foster ds->ops = &felix_switch_ops; 98*3d7316acSColin Foster ds->priv = ocelot; 99*3d7316acSColin Foster felix->ds = ds; 100*3d7316acSColin Foster felix->tag_proto = DSA_TAG_PROTO_OCELOT; 101*3d7316acSColin Foster 102*3d7316acSColin Foster err = dsa_register_switch(ds); 103*3d7316acSColin Foster if (err) { 104*3d7316acSColin Foster dev_err_probe(dev, err, "Failed to register DSA switch\n"); 105*3d7316acSColin Foster goto err_free_ds; 106*3d7316acSColin Foster } 107*3d7316acSColin Foster 108*3d7316acSColin Foster return 0; 109*3d7316acSColin Foster 110*3d7316acSColin Foster err_free_ds: 111*3d7316acSColin Foster kfree(ds); 112*3d7316acSColin Foster err_free_felix: 113*3d7316acSColin Foster kfree(felix); 114*3d7316acSColin Foster return err; 115*3d7316acSColin Foster } 116*3d7316acSColin Foster 117*3d7316acSColin Foster static int ocelot_ext_remove(struct platform_device *pdev) 118*3d7316acSColin Foster { 119*3d7316acSColin Foster struct felix *felix = dev_get_drvdata(&pdev->dev); 120*3d7316acSColin Foster 121*3d7316acSColin Foster if (!felix) 122*3d7316acSColin Foster return 0; 123*3d7316acSColin Foster 124*3d7316acSColin Foster dsa_unregister_switch(felix->ds); 125*3d7316acSColin Foster 126*3d7316acSColin Foster kfree(felix->ds); 127*3d7316acSColin Foster kfree(felix); 128*3d7316acSColin Foster 129*3d7316acSColin Foster return 0; 130*3d7316acSColin Foster } 131*3d7316acSColin Foster 132*3d7316acSColin Foster static void ocelot_ext_shutdown(struct platform_device *pdev) 133*3d7316acSColin Foster { 134*3d7316acSColin Foster struct felix *felix = dev_get_drvdata(&pdev->dev); 135*3d7316acSColin Foster 136*3d7316acSColin Foster if (!felix) 137*3d7316acSColin Foster return; 138*3d7316acSColin Foster 139*3d7316acSColin Foster dsa_switch_shutdown(felix->ds); 140*3d7316acSColin Foster 141*3d7316acSColin Foster dev_set_drvdata(&pdev->dev, NULL); 142*3d7316acSColin Foster } 143*3d7316acSColin Foster 144*3d7316acSColin Foster static const struct of_device_id ocelot_ext_switch_of_match[] = { 145*3d7316acSColin Foster { .compatible = "mscc,vsc7512-switch" }, 146*3d7316acSColin Foster { }, 147*3d7316acSColin Foster }; 148*3d7316acSColin Foster MODULE_DEVICE_TABLE(of, ocelot_ext_switch_of_match); 149*3d7316acSColin Foster 150*3d7316acSColin Foster static struct platform_driver ocelot_ext_switch_driver = { 151*3d7316acSColin Foster .driver = { 152*3d7316acSColin Foster .name = "ocelot-switch", 153*3d7316acSColin Foster .of_match_table = of_match_ptr(ocelot_ext_switch_of_match), 154*3d7316acSColin Foster }, 155*3d7316acSColin Foster .probe = ocelot_ext_probe, 156*3d7316acSColin Foster .remove = ocelot_ext_remove, 157*3d7316acSColin Foster .shutdown = ocelot_ext_shutdown, 158*3d7316acSColin Foster }; 159*3d7316acSColin Foster module_platform_driver(ocelot_ext_switch_driver); 160*3d7316acSColin Foster 161*3d7316acSColin Foster MODULE_DESCRIPTION("External Ocelot Switch driver"); 162*3d7316acSColin Foster MODULE_LICENSE("GPL"); 163*3d7316acSColin Foster MODULE_IMPORT_NS(MFD_OCELOT); 164