- mii_mgr_write(0, 31, 0x0); //select global register
- mii_mgr_write(0, 22, 0x052f); //tune TP_IDL tail and head waveform
- mii_mgr_write(0, 17, 0x0fe0); //set TX10 signal amplitude threshold to minimum
- mii_mgr_write(0, 18, 0x40ba); //set squelch amplitude to higher threshold
- mii_mgr_write(0, 14, 0x65); //longer TP_IDL tail length
- mii_mgr_write(0, 31, 0x8000); //select local register
-
- /* Port 5 Disabled */
- rt305x_sysc_wr(rt305x_sysc_rr(0x60) | (1 << 9), 0x60); //set RGMII to GPIO mode (GPIO41-GPIO50)
- rt305x_sysc_wr(0xfff, 0x674); //GPIO41-GPIO50 output mode
- rt305x_sysc_wr(0x0, 0x670); //GPIO41-GPIO50 output low
-
- /* set default vlan */
- ramips_esw_wr(0x2001, 0x50);
- ramips_esw_wr(0x5041, 0x70);
+ /* select global register */
+ rt305x_mii_write(esw, 0, 31, 0x0);
+ /* tune TP_IDL tail and head waveform */
+ rt305x_mii_write(esw, 0, 22, 0x052f);
+ /* set TX10 signal amplitude threshold to minimum */
+ rt305x_mii_write(esw, 0, 17, 0x0fe0);
+ /* set squelch amplitude to higher threshold */
+ rt305x_mii_write(esw, 0, 18, 0x40ba);
+ /* longer TP_IDL tail length */
+ rt305x_mii_write(esw, 0, 14, 0x65);
+ /* select local register */
+ rt305x_mii_write(esw, 0, 31, 0x8000);
+
+ for (i = 0; i < RT305X_ESW_NUM_VLANS; i++) {
+ rt305x_esw_set_vlan_id(esw, i, 0);
+ rt305x_esw_set_vmsc(esw, i, 0);
+ }
+
+ for (i = 0; i < RT305X_ESW_NUM_PORTS; i++)
+ rt305x_esw_set_pvid(esw, i, 1);
+
+ switch (esw->pdata->vlan_config) {
+ case RT305X_ESW_VLAN_CONFIG_NONE:
+ break;
+
+ case RT305X_ESW_VLAN_CONFIG_BYPASS:
+ /* Pass all vlan tags to all ports */
+ for (i = 0; i < RT305X_ESW_NUM_VLANS; i++) {
+ rt305x_esw_set_vlan_id(esw, i, i+1);
+ rt305x_esw_set_vmsc(esw, i, RT305X_ESW_PORTS_ALL);
+ }
+ /* Disable VLAN TAG removal, keep aging on. */
+ rt305x_esw_wr(esw,
+ RT305X_ESW_PORTS_ALL << RT305X_ESW_POC3_ENAGING_S,
+ RT305X_ESW_REG_POC3);
+ break;
+
+ case RT305X_ESW_VLAN_CONFIG_LLLLW:
+ rt305x_esw_set_vlan_id(esw, 0, 1);
+ rt305x_esw_set_vlan_id(esw, 1, 2);
+ rt305x_esw_set_pvid(esw, RT305X_ESW_PORT4, 2);
+
+ rt305x_esw_set_vmsc(esw, 0,
+ BIT(RT305X_ESW_PORT0) | BIT(RT305X_ESW_PORT1) |
+ BIT(RT305X_ESW_PORT2) | BIT(RT305X_ESW_PORT3) |
+ BIT(RT305X_ESW_PORT6));
+ rt305x_esw_set_vmsc(esw, 1,
+ BIT(RT305X_ESW_PORT4) | BIT(RT305X_ESW_PORT6));
+ break;
+
+ case RT305X_ESW_VLAN_CONFIG_WLLLL:
+ rt305x_esw_set_vlan_id(esw, 0, 1);
+ rt305x_esw_set_vlan_id(esw, 1, 2);
+ rt305x_esw_set_pvid(esw, RT305X_ESW_PORT0, 2);
+
+ rt305x_esw_set_vmsc(esw, 0,
+ BIT(RT305X_ESW_PORT1) | BIT(RT305X_ESW_PORT2) |
+ BIT(RT305X_ESW_PORT3) | BIT(RT305X_ESW_PORT4) |
+ BIT(RT305X_ESW_PORT6));
+ rt305x_esw_set_vmsc(esw, 1,
+ BIT(RT305X_ESW_PORT0) | BIT(RT305X_ESW_PORT6));
+ break;
+
+ default:
+ BUG();
+ }
+}
+
+static int
+rt305x_esw_probe(struct platform_device *pdev)
+{
+ struct rt305x_esw_platform_data *pdata;
+ struct rt305x_esw *esw;
+ struct resource *res;
+ int err;
+
+ pdata = pdev->dev.platform_data;
+ if (!pdata)
+ return -EINVAL;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res) {
+ dev_err(&pdev->dev, "no memory resource found\n");
+ return -ENOMEM;
+ }
+
+ esw = kzalloc(sizeof(struct rt305x_esw), GFP_KERNEL);
+ if (!esw) {
+ dev_err(&pdev->dev, "no memory for private data\n");
+ return -ENOMEM;
+ }
+
+ esw->base = ioremap(res->start, resource_size(res));
+ if (!esw->base) {
+ dev_err(&pdev->dev, "ioremap failed\n");
+ err = -ENOMEM;
+ goto free_esw;
+ }
+
+ platform_set_drvdata(pdev, esw);
+
+ esw->pdata = pdata;
+ spin_lock_init(&esw->reg_rw_lock);
+ rt305x_esw_hw_init(esw);
+
+ return 0;
+
+free_esw:
+ kfree(esw);
+ return err;
+}
+
+static int
+rt305x_esw_remove(struct platform_device *pdev)
+{
+ struct rt305x_esw *esw;
+
+ esw = platform_get_drvdata(pdev);
+ if (esw) {
+ platform_set_drvdata(pdev, NULL);
+ iounmap(esw->base);
+ kfree(esw);
+ }