From patchwork Mon Mar 23 10:14:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 222053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4E1EC54FCE for ; Mon, 23 Mar 2020 10:14:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 735A720409 for ; Mon, 23 Mar 2020 10:14:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20150623.gappssmtp.com header.i=@waldekranz-com.20150623.gappssmtp.com header.b="Hn5nTimc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727891AbgCWKOd (ORCPT ); Mon, 23 Mar 2020 06:14:33 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:37727 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727806AbgCWKOd (ORCPT ); Mon, 23 Mar 2020 06:14:33 -0400 Received: by mail-lj1-f195.google.com with SMTP id r24so13907034ljd.4 for ; Mon, 23 Mar 2020 03:14:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :organization; bh=IAvJijwLW8Q8zsqVUdB+kE0W6IMg7X+fpSu2ixoUG7E=; b=Hn5nTimc/Sg+3odUs1dEYPMdwYxvaBs4k/Bo5xq1Cx2s479j/KeBGsnBSQri4mQKTC RMlMEW984JnLdPNSu+03R9OGvlpVZFBR/bG8/MGfvuoiDyy03VHlpCT7ky511XBT+YFz +FKAhQ4KmCB/muhuOpXGdhzNIqfmLKsCk6LeK2JND/Ebha0mdRcmjuM2x6ERaCNE1hZG K1rz3RdAgRi4RLbBX6el7lr69iUK6Y4W4cEA3We7jzVATZJF9ByJcRebKmOeb2WHiedW OnPGjJbh0nfU4uxh+KYsjJA4btbimmQqA8HtfuZiD7+4cCsQpRNOsF25I3vi6ZlW5cGk a7uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:organization; bh=IAvJijwLW8Q8zsqVUdB+kE0W6IMg7X+fpSu2ixoUG7E=; b=NtQvLnfwRy6/1n0ixqCOgYBbukV4zaJU6vWtAyV8JtEP9rstL+qKFBEhIOdHuPostw P0ZE9VyKTri3mkxjOYTSC6LeyCN+HNCqM3meuO7m2eIe6IzR3s1qR6g7bcX1JW9lO6n8 D+CinMXLy3p0opSs548EZqbws91OHzjQsAUS7linQYkjO+BZchmzj/PXuzxXs5UAoHoP MCWzTQXh1qaJp8Ige6LeIZXI07xqmY4wFPiZ3Rc3F/grLY5NEFQRHRFE8FLYXloXm5a7 c+lc9VmQNnyLxhh+B3XbB+44rr9eCVRtNHrc9DctBMB3VbQGZieE/UhYd/hBZ3IXQ+EZ MpDw== X-Gm-Message-State: ANhLgQ3ZzjRpFyBB5ys5EqucoeX4X7bhqblkByMhOeyKhOoPsT2O83Ln RMwNyYpjR2Qv8mK3AWXa0l0AUTLqMScjhw== X-Google-Smtp-Source: ADFU+vumi0Q6B9ROyV2rWGNsIgRLK0sMCuu4oAgV1mU/xdbLbfbYN090eQnb5aKEQ7kYY8oDWxUMGg== X-Received: by 2002:a2e:9d98:: with SMTP id c24mr2988221ljj.137.1584958470986; Mon, 23 Mar 2020 03:14:30 -0700 (PDT) Received: from veiron.westermo.com (static-193-12-47-89.cust.tele2.se. [193.12.47.89]) by smtp.gmail.com with ESMTPSA id 28sm367434lfp.8.2020.03.23.03.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 03:14:30 -0700 (PDT) From: Tobias Waldekranz To: davem@davemloft.net Cc: netdev@vger.kernel.org, andrew@lunn.ch, f.fainelli@gmail.com, hkallweit1@gmail.com Subject: [PATCH net-next v4 1/2] dt-bindings: net: add marvell usb to mdio bindings Date: Mon, 23 Mar 2020 11:14:13 +0100 Message-Id: <20200323101414.11505-2-tobias@waldekranz.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200323101414.11505-1-tobias@waldekranz.com> References: <20200323101414.11505-1-tobias@waldekranz.com> Organization: Westermo Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Describe how the USB to MDIO controller can optionally use device tree bindings to reference attached devices such as switches. Signed-off-by: Tobias Waldekranz Reviewed-by: Andrew Lunn Reviewed-by: Florian Fainelli --- .../bindings/net/marvell,mvusb.yaml | 65 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/marvell,mvusb.yaml diff --git a/Documentation/devicetree/bindings/net/marvell,mvusb.yaml b/Documentation/devicetree/bindings/net/marvell,mvusb.yaml new file mode 100644 index 000000000000..9458f6659be1 --- /dev/null +++ b/Documentation/devicetree/bindings/net/marvell,mvusb.yaml @@ -0,0 +1,65 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/marvell,mvusb.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Marvell USB to MDIO Controller + +maintainers: + - Tobias Waldekranz + +description: |+ + This controller is mounted on development boards for Marvell's Link Street + family of Ethernet switches. It allows you to configure the switch's registers + using the standard MDIO interface. + + Since the device is connected over USB, there is no strict requirement of + having a device tree representation of the device. But in order to use it with + the mv88e6xxx driver, you need a device tree node in which to place the switch + definition. + +allOf: + - $ref: "mdio.yaml#" + +properties: + compatible: + const: usb1286,1fa4 + reg: + maxItems: 1 + description: The USB port number on the host controller + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +examples: + - | + /* USB host controller */ + &usb1 { + mvusb: mdio@1 { + compatible = "usb1286,1fa4"; + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + }; + }; + + /* MV88E6390X devboard */ + &mvusb { + switch@0 { + compatible = "marvell,mv88e6190"; + status = "ok"; + reg = <0x0>; + + ports { + /* Port definitions */ + }; + + mdio { + /* PHY definitions */ + }; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 97dce264bc7c..ff35669f8712 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10101,6 +10101,12 @@ M: Nicolas Pitre S: Odd Fixes F: drivers/mmc/host/mvsdio.* +MARVELL USB MDIO CONTROLLER DRIVER +M: Tobias Waldekranz +L: netdev@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/net/marvell,mvusb.yaml + MARVELL XENON MMC/SD/SDIO HOST CONTROLLER DRIVER M: Hu Ziji L: linux-mmc@vger.kernel.org From patchwork Mon Mar 23 10:14:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 222052 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A405C4332E for ; Mon, 23 Mar 2020 10:14:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 446B120409 for ; Mon, 23 Mar 2020 10:14:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20150623.gappssmtp.com header.i=@waldekranz-com.20150623.gappssmtp.com header.b="Z7HLWCF8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727906AbgCWKOg (ORCPT ); Mon, 23 Mar 2020 06:14:36 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:37729 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727879AbgCWKOe (ORCPT ); Mon, 23 Mar 2020 06:14:34 -0400 Received: by mail-lj1-f196.google.com with SMTP id r24so13907084ljd.4 for ; Mon, 23 Mar 2020 03:14:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :organization; bh=AwucaSojyVDcW1oL0/BLNJyhObj7yjHZoejZLugLWjY=; b=Z7HLWCF8TAU4EvnFhxKEG6TgJZR3urUi6EBeJAfg3x7tA3Or94oS6nnb7dRX7fdDiN qjlNwsaS5EYhfW3z/1bC3iUh+FyAwA8mT94fVJqGdRsxK5XgQ5egqpzp1bUC9uEV9Noi 23ykMCUAl4LF2suG319GQ6VqW515/ycMHZ6helgEx1fDcoFEb5rxGHy4+O8Vb9I2aWv1 +i0yhzofQs/r/1LpzY4mLq33x/1QMMUuYlhQNdwj8zAH6m7Tjmyhg8Rvk19EsEMWPVAr HNkAmy2KHcgCc8R+5inxCdhm78VfPTbuwx9Dvzo81yKAaDvKlFFdYXQhrpMSfvSN78sh l4FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:organization; bh=AwucaSojyVDcW1oL0/BLNJyhObj7yjHZoejZLugLWjY=; b=NxkJTMYw+l0/zy9H16ZNpUNPLtXG7THWrW/cQrigPRN24/x/I23RdyJeIO3yJyF/hA 8amLNRV2bkkzGVkwStQOIQj0BKIKwaYQCVjo+49v0/g/0qUP9ZnaEUP/38rq06kB77aT DkKKpe95gR+y7jqMRNrt9exbol/3vLty+DkimlTppXtu/EG6d2S4hDUYZLF/iL4fZ/ln 3gWvTzIQXy2xZal09F6n1NMshKOVwlnu+dxhFIkmfWjBM9knwbDC+PUpy6GDtn+B58zF lKc7iILAZUq4AI7GPjuUZ5mVxYmNPV8Oda09i3VAwmS2Ju1nvOxw64iC5cUcp+3izk4t rs5w== X-Gm-Message-State: ANhLgQ0fMYWAkAEMwLxgSGbxnPr3vrU4NpLXR8f8iNnYUoWIENTaZNzc dfDgQ7SqQ2zgDMl1W0t/zLH3+Q== X-Google-Smtp-Source: ADFU+vvhc8pGZbnPR2BORoTOMMM9hRe2ps9MnXy7Zz2kwD6QI1puwcWzjLfh8mwZsTQSFsNA/jeFiA== X-Received: by 2002:a2e:b804:: with SMTP id u4mr3899029ljo.159.1584958471937; Mon, 23 Mar 2020 03:14:31 -0700 (PDT) Received: from veiron.westermo.com (static-193-12-47-89.cust.tele2.se. [193.12.47.89]) by smtp.gmail.com with ESMTPSA id 28sm367434lfp.8.2020.03.23.03.14.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 03:14:31 -0700 (PDT) From: Tobias Waldekranz To: davem@davemloft.net Cc: netdev@vger.kernel.org, andrew@lunn.ch, f.fainelli@gmail.com, hkallweit1@gmail.com Subject: [PATCH net-next v4 2/2] net: phy: add marvell usb to mdio controller Date: Mon, 23 Mar 2020 11:14:14 +0100 Message-Id: <20200323101414.11505-3-tobias@waldekranz.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200323101414.11505-1-tobias@waldekranz.com> References: <20200323101414.11505-1-tobias@waldekranz.com> Organization: Westermo Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org An MDIO controller present on development boards for Marvell switches from the Link Street (88E6xxx) family. Using this module, you can use the following setup as a development platform for switchdev and DSA related work. .-------. .-----------------. | USB----USB | | SoC | | 88E6390X-DB ETH1-10 | ETH----ETH0 | '-------' '-----------------' Signed-off-by: Tobias Waldekranz Reviewed-by: Greg Kroah-Hartman Reviewed-by: Andrew Lunn Reviewed-by: Florian Fainelli --- MAINTAINERS | 1 + drivers/net/phy/Kconfig | 7 ++ drivers/net/phy/Makefile | 1 + drivers/net/phy/mdio-mvusb.c | 120 +++++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 drivers/net/phy/mdio-mvusb.c diff --git a/MAINTAINERS b/MAINTAINERS index ff35669f8712..f36023d4ee44 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10105,6 +10105,7 @@ MARVELL USB MDIO CONTROLLER DRIVER M: Tobias Waldekranz L: netdev@vger.kernel.org S: Maintained +F: drivers/net/phy/mdio-mvusb.c F: Documentation/devicetree/bindings/net/marvell,mvusb.yaml MARVELL XENON MMC/SD/SDIO HOST CONTROLLER DRIVER diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index cc7f1df855da..3fa33d27eeba 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -179,6 +179,13 @@ config MDIO_MSCC_MIIM This driver supports the MIIM (MDIO) interface found in the network switches of the Microsemi SoCs +config MDIO_MVUSB + tristate "Marvell USB to MDIO Adapter" + depends on USB + help + A USB to MDIO converter present on development boards for + Marvell's Link Street family of Ethernet switches. + config MDIO_OCTEON tristate "Octeon and some ThunderX SOCs MDIO buses" depends on (64BIT && OF_MDIO) || COMPILE_TEST diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index 70774ab474e6..2f5c7093a65b 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -40,6 +40,7 @@ obj-$(CONFIG_MDIO_I2C) += mdio-i2c.o obj-$(CONFIG_MDIO_IPQ8064) += mdio-ipq8064.o obj-$(CONFIG_MDIO_MOXART) += mdio-moxart.o obj-$(CONFIG_MDIO_MSCC_MIIM) += mdio-mscc-miim.o +obj-$(CONFIG_MDIO_MVUSB) += mdio-mvusb.o obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o obj-$(CONFIG_MDIO_SUN4I) += mdio-sun4i.o obj-$(CONFIG_MDIO_THUNDER) += mdio-thunder.o diff --git a/drivers/net/phy/mdio-mvusb.c b/drivers/net/phy/mdio-mvusb.c new file mode 100644 index 000000000000..d5eabddfdf51 --- /dev/null +++ b/drivers/net/phy/mdio-mvusb.c @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include + +#define USB_MARVELL_VID 0x1286 + +static const struct usb_device_id mvusb_mdio_table[] = { + { USB_DEVICE(USB_MARVELL_VID, 0x1fa4) }, + + {} +}; +MODULE_DEVICE_TABLE(usb, mvusb_mdio_table); + +enum { + MVUSB_CMD_PREAMBLE0, + MVUSB_CMD_PREAMBLE1, + MVUSB_CMD_ADDR, + MVUSB_CMD_VAL, +}; + +struct mvusb_mdio { + struct usb_device *udev; + struct mii_bus *mdio; + + __le16 buf[4]; +}; + +static int mvusb_mdio_read(struct mii_bus *mdio, int dev, int reg) +{ + struct mvusb_mdio *mvusb = mdio->priv; + int err, alen; + + if (dev & MII_ADDR_C45) + return -EOPNOTSUPP; + + mvusb->buf[MVUSB_CMD_ADDR] = cpu_to_le16(0xa400 | (dev << 5) | reg); + + err = usb_bulk_msg(mvusb->udev, usb_sndbulkpipe(mvusb->udev, 2), + mvusb->buf, 6, &alen, 100); + if (err) + return err; + + err = usb_bulk_msg(mvusb->udev, usb_rcvbulkpipe(mvusb->udev, 6), + &mvusb->buf[MVUSB_CMD_VAL], 2, &alen, 100); + if (err) + return err; + + return le16_to_cpu(mvusb->buf[MVUSB_CMD_VAL]); +} + +static int mvusb_mdio_write(struct mii_bus *mdio, int dev, int reg, u16 val) +{ + struct mvusb_mdio *mvusb = mdio->priv; + int alen; + + if (dev & MII_ADDR_C45) + return -EOPNOTSUPP; + + mvusb->buf[MVUSB_CMD_ADDR] = cpu_to_le16(0x8000 | (dev << 5) | reg); + mvusb->buf[MVUSB_CMD_VAL] = cpu_to_le16(val); + + return usb_bulk_msg(mvusb->udev, usb_sndbulkpipe(mvusb->udev, 2), + mvusb->buf, 8, &alen, 100); +} + +static int mvusb_mdio_probe(struct usb_interface *interface, + const struct usb_device_id *id) +{ + struct device *dev = &interface->dev; + struct mvusb_mdio *mvusb; + struct mii_bus *mdio; + + mdio = devm_mdiobus_alloc_size(dev, sizeof(*mvusb)); + if (!mdio) + return -ENOMEM; + + mvusb = mdio->priv; + mvusb->mdio = mdio; + mvusb->udev = usb_get_dev(interface_to_usbdev(interface)); + + /* Reversed from USB PCAPs, no idea what these mean. */ + mvusb->buf[MVUSB_CMD_PREAMBLE0] = cpu_to_le16(0xe800); + mvusb->buf[MVUSB_CMD_PREAMBLE1] = cpu_to_le16(0x0001); + + snprintf(mdio->id, MII_BUS_ID_SIZE, "mvusb-%s", dev_name(dev)); + mdio->name = mdio->id; + mdio->parent = dev; + mdio->read = mvusb_mdio_read; + mdio->write = mvusb_mdio_write; + + usb_set_intfdata(interface, mvusb); + return of_mdiobus_register(mdio, dev->of_node); +} + +static void mvusb_mdio_disconnect(struct usb_interface *interface) +{ + struct mvusb_mdio *mvusb = usb_get_intfdata(interface); + struct usb_device *udev = mvusb->udev; + + mdiobus_unregister(mvusb->mdio); + usb_set_intfdata(interface, NULL); + usb_put_dev(udev); +} + +static struct usb_driver mvusb_mdio_driver = { + .name = "mvusb_mdio", + .id_table = mvusb_mdio_table, + .probe = mvusb_mdio_probe, + .disconnect = mvusb_mdio_disconnect, +}; + +module_usb_driver(mvusb_mdio_driver); + +MODULE_AUTHOR("Tobias Waldekranz "); +MODULE_DESCRIPTION("Marvell USB MDIO Adapter"); +MODULE_LICENSE("GPL");