kernel: add driver for Marvell 88E6171 switch
[openwrt.git] / target / linux / generic / files / drivers / net / phy / rtl8366_smi.c
index 4407463..699234d 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/gpio.h>
 #include <linux/spinlock.h>
 #include <linux/skbuff.h>
+#include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/of_gpio.h>
 #include <linux/rtl8366.h>
@@ -742,7 +743,7 @@ static ssize_t rtl8366_write_debugfs_reg(struct file *file,
                buf[len - 1] = '\0';
 
 
-       if (strict_strtoul(buf, 16, &data)) {
+       if (kstrtoul(buf, 16, &data)) {
                dev_err(smi->parent, "Invalid reg value %s\n", buf);
        } else {
                err = rtl8366_smi_write_reg(smi, reg, data);
@@ -1108,6 +1109,7 @@ int rtl8366_sw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val)
 
        port = &val->value.ports[0];
        for (i = 0; i < val->len; i++, port++) {
+               int pvid = 0;
                member |= BIT(port->id);
 
                if (!(port->flags & BIT(SWITCH_PORT_FLAG_TAGGED)))
@@ -1117,9 +1119,14 @@ int rtl8366_sw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val)
                 * To ensure that we have a valid MC entry for this VLAN,
                 * initialize the port VLAN ID here.
                 */
-               err = rtl8366_set_pvid(smi, port->id, val->port_vlan);
+               err = rtl8366_get_pvid(smi, port->id, &pvid);
                if (err < 0)
                        return err;
+               if (pvid == 0) {
+                       err = rtl8366_set_pvid(smi, port->id, val->port_vlan);
+                       if (err < 0)
+                               return err;
+               }
        }
 
        return rtl8366_set_vlan(smi, val->port_vlan, member, untag, 0);
@@ -1378,7 +1385,7 @@ int rtl8366_smi_probe_of(struct platform_device *pdev, struct rtl8366_smi *smi)
        int sck = of_get_named_gpio(pdev->dev.of_node, "gpio-sck", 0);
        int sda = of_get_named_gpio(pdev->dev.of_node, "gpio-sda", 0);
 
-       if (!sck || !sda) {
+       if (!gpio_is_valid(sck) || !gpio_is_valid(sda)) {
                dev_err(&pdev->dev, "gpios missing in devictree\n");
                return -EINVAL;
        }
@@ -1389,7 +1396,7 @@ int rtl8366_smi_probe_of(struct platform_device *pdev, struct rtl8366_smi *smi)
        return 0;
 }
 #else
-static inline int rtl8366_smi_probe_of(struct device_node *np, struct rtl8366_smi *smi)
+static inline int rtl8366_smi_probe_of(struct platform_device *pdev, struct rtl8366_smi *smi)
 {
        return -ENODEV;
 }