From patchwork Thu May 11 13:29:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 9721513 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 736B460364 for ; Thu, 11 May 2017 13:30:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6495228609 for ; Thu, 11 May 2017 13:30:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5935728663; Thu, 11 May 2017 13:30:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BA6B728609 for ; Thu, 11 May 2017 13:30:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=j4EmfwEZqDWvcP55962DulY5g+hPYuyLx+WrRvMD8c0=; b=IeSpR3FbJYSA+O cGWO99roEsOFTkcM9O+iypr2xfDdvFyujt+3C4w77MVh+23oar4hlTb0+7Ut2T8mQ2PxYuutzZcUp gx5NdclVLa7Cj48/OOy1tX8brleGu8f7em53LR3GXGRUj6yrN6u5mFeiJ5waRXdSdXzUKYjh+bKB5 UuQFD+JYvkrM4aJwuXRN+nlpW/I3DNhp3xxFIikPYlGUhI9N/+sjMPM9YxEOqVoYYQdcn2PjxRuSD R7vW8D7hI8YkDBVBlngvehUrwvvtvn6NLeyEx2l/ij9AYuqTN+QFAETKR54gcHODVgkBpniFFfwLT cCzodTR3+jf5S7sQ6/WA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d8oAz-0005Q6-Oy; Thu, 11 May 2017 13:30:41 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d8oAR-0003P4-2o for linux-arm-kernel@lists.infradead.org; Thu, 11 May 2017 13:30:09 +0000 Received: by mail-wm0-x242.google.com with SMTP id d127so7033425wmf.1 for ; Thu, 11 May 2017 06:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3/UsXgsDesdlKUEIyUjk6nWccAAtw7dhKl/B658POCQ=; b=MeNysqnh4uYqnLjfUkzJtYyhJHmio/lYdkmXZJmaThBWCXHZgGQfS2IS9vKtdya6wl AUD1hRNA4JPW5BKdQxcQUX8IOT/yrdBxIPZwFi/md8dssIMqGopg+V1cFja8bunDY3d8 fp5obhwAfGWu+C3QygmdZgRzbxGvNGMBVFSKC9bBWckW36hFbD0d8DEBb/8ofObR6ojk o3a1E6hqYc/3r7TbX/m4cthGFCKZ50PZj3gK4/0axOWAp6Yu2zu5/JxBd9Rmjynzb7p2 4PBq6fto9Eq1n+wYXcCDq+Kr6dk3+ZF+cWgwmQfuj4+RkrwEEIVSWVN6g3xkYGVCe9pd 8oYg== 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:mime-version:content-transfer-encoding; bh=3/UsXgsDesdlKUEIyUjk6nWccAAtw7dhKl/B658POCQ=; b=bjTlVUqHONsLFVzd5omJ4Luod41N3Sj9O6D4ojygM8T8s04GIgj6k7RBLWix1tnSB0 lIZZeta0waXdhBGpqehE63bernuPrHw1kcq+8Gc242KzRJ5FO/kqVF9AebsaOADO5GGN 5xej5Cewfom/YBgyaoeLbOqzifP5I8joQI7bx2gcmk5aRzwO73BPbyfQzgjg5ncr+wvY VitfXNgBcWyJr4Y1yXGnVtOrq/T4MpPFq6CkV4QIGt3cjbkC4gf/U6uuvFnhUcnexIAR QOcwVKtRwvW/u24bosr3MNa+8t+K97ReqgOQZoRblVHPCkaidtTFWglfxudiVvjNXYFD TFrA== X-Gm-Message-State: AODbwcBfDhoGcU+Ah96/zkW1cJKopV8PDgMYfJloWvMAJ96qXD1qKweP FDy4k9Ir35ek7A== X-Received: by 10.25.80.71 with SMTP id z7mr106220lfj.131.1494509385329; Thu, 11 May 2017 06:29:45 -0700 (PDT) Received: from linux-samsung.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id i18sm31725ljd.28.2017.05.11.06.29.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 May 2017 06:29:44 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Kishon Vijay Abraham I Subject: [PATCH 2/5] phy: bcm-ns-usb3: use pointer for PHY writing function Date: Thu, 11 May 2017 15:29:22 +0200 Message-Id: <20170511132925.14564-3-zajec5@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170511132925.14564-1-zajec5@gmail.com> References: <20170511132925.14564-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170511_063007_446732_D93806DA X-CRM114-Status: GOOD ( 16.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Florian Fainelli , Jon Mason , linux-kernel@vger.kernel.org, Yendapally Reddy Dhananjaya Reddy , bcm-kernel-feedback-list@broadcom.com, =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rafał Miłecki Our current writing function accesses PHY directly bypassing MDIO layer. The aim is to extend this module to also behave as MDIO driver. This will require using different writing function which can be handled cleanly by having an extra pointer like this. Signed-off-by: Rafał Miłecki --- drivers/phy/phy-bcm-ns-usb3.c | 98 ++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 42 deletions(-) diff --git a/drivers/phy/phy-bcm-ns-usb3.c b/drivers/phy/phy-bcm-ns-usb3.c index 5e89326886dc..3d0fe5728029 100644 --- a/drivers/phy/phy-bcm-ns-usb3.c +++ b/drivers/phy/phy-bcm-ns-usb3.c @@ -53,6 +53,8 @@ struct bcm_ns_usb3 { void __iomem *dmp; void __iomem *ccb_mii; struct phy *phy; + + int (*phy_write)(struct bcm_ns_usb3 *usb3, u16 reg, u16 value); }; static const struct of_device_id bcm_ns_usb3_id_table[] = { @@ -68,51 +70,10 @@ static const struct of_device_id bcm_ns_usb3_id_table[] = { }; MODULE_DEVICE_TABLE(of, bcm_ns_usb3_id_table); -static int bcm_ns_usb3_wait_reg(struct bcm_ns_usb3 *usb3, void __iomem *addr, - u32 mask, u32 value, unsigned long timeout) -{ - unsigned long deadline = jiffies + timeout; - u32 val; - - do { - val = readl(addr); - if ((val & mask) == value) - return 0; - cpu_relax(); - udelay(10); - } while (!time_after_eq(jiffies, deadline)); - - dev_err(usb3->dev, "Timeout waiting for register %p\n", addr); - - return -EBUSY; -} - -static inline int bcm_ns_usb3_mii_mng_wait_idle(struct bcm_ns_usb3 *usb3) -{ - return bcm_ns_usb3_wait_reg(usb3, usb3->ccb_mii + BCMA_CCB_MII_MNG_CTL, - 0x0100, 0x0000, - usecs_to_jiffies(BCM_NS_USB3_MII_MNG_TIMEOUT_US)); -} - static int bcm_ns_usb3_mdio_phy_write(struct bcm_ns_usb3 *usb3, u16 reg, u16 value) { - u32 tmp = 0; - int err; - - err = bcm_ns_usb3_mii_mng_wait_idle(usb3); - if (err < 0) { - dev_err(usb3->dev, "Couldn't write 0x%08x value\n", value); - return err; - } - - /* TODO: Use a proper MDIO bus layer */ - tmp |= 0x58020000; /* Magic value for MDIO PHY write */ - tmp |= reg << 18; - tmp |= value; - writel(tmp, usb3->ccb_mii + BCMA_CCB_MII_MNG_CMD_DATA); - - return bcm_ns_usb3_mii_mng_wait_idle(usb3); + return usb3->phy_write(usb3, reg, value); } static int bcm_ns_usb3_phy_init_ns_bx(struct bcm_ns_usb3 *usb3) @@ -233,6 +194,57 @@ static const struct phy_ops ops = { .owner = THIS_MODULE, }; +/************************************************** + * Platform driver code + **************************************************/ + +static int bcm_ns_usb3_wait_reg(struct bcm_ns_usb3 *usb3, void __iomem *addr, + u32 mask, u32 value, unsigned long timeout) +{ + unsigned long deadline = jiffies + timeout; + u32 val; + + do { + val = readl(addr); + if ((val & mask) == value) + return 0; + cpu_relax(); + udelay(10); + } while (!time_after_eq(jiffies, deadline)); + + dev_err(usb3->dev, "Timeout waiting for register %p\n", addr); + + return -EBUSY; +} + +static inline int bcm_ns_usb3_mii_mng_wait_idle(struct bcm_ns_usb3 *usb3) +{ + return bcm_ns_usb3_wait_reg(usb3, usb3->ccb_mii + BCMA_CCB_MII_MNG_CTL, + 0x0100, 0x0000, + usecs_to_jiffies(BCM_NS_USB3_MII_MNG_TIMEOUT_US)); +} + +static int bcm_ns_usb3_platform_phy_write(struct bcm_ns_usb3 *usb3, u16 reg, + u16 value) +{ + u32 tmp = 0; + int err; + + err = bcm_ns_usb3_mii_mng_wait_idle(usb3); + if (err < 0) { + dev_err(usb3->dev, "Couldn't write 0x%08x value\n", value); + return err; + } + + /* TODO: Use a proper MDIO bus layer */ + tmp |= 0x58020000; /* Magic value for MDIO PHY write */ + tmp |= reg << 18; + tmp |= value; + writel(tmp, usb3->ccb_mii + BCMA_CCB_MII_MNG_CMD_DATA); + + return bcm_ns_usb3_mii_mng_wait_idle(usb3); +} + static int bcm_ns_usb3_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -266,6 +278,8 @@ static int bcm_ns_usb3_probe(struct platform_device *pdev) return PTR_ERR(usb3->ccb_mii); } + usb3->phy_write = bcm_ns_usb3_platform_phy_write; + usb3->phy = devm_phy_create(dev, NULL, &ops); if (IS_ERR(usb3->phy)) { dev_err(dev, "Failed to create PHY\n");