From patchwork Tue Oct 4 10:43:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Gautam X-Patchwork-Id: 678012 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3spFrw44n8z9s65 for ; Tue, 4 Oct 2016 21:44:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=codeaurora.org header.i=@codeaurora.org header.b=R9/T+fq1; dkim=fail reason="signature verification failed" (1024-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b=N/Mzi+ni; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752352AbcJDKn7 (ORCPT ); Tue, 4 Oct 2016 06:43:59 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:53903 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750908AbcJDKn5 (ORCPT ); Tue, 4 Oct 2016 06:43:57 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id DF21861691; Tue, 4 Oct 2016 10:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1475577836; bh=95R7jkACslXOzyyb3nzt3fhS3MiPkXR0cGXaTo4Raks=; h=From:To:Cc:Subject:Date:From; b=R9/T+fq1lIQMoYfCz+SIxbJvbZ/GpIBkNaedhqwAkGnDkA7f6PuAizc9t6t/uW3FE wxzNPWDKGrscTjuQ6dmBNjPmL7MvJ4JkPKaJWjwUijW7ZOTHGP4u5GxZBtKxkGcIb+ jUbLTtsd+go6oz00MyMEfpC5VHy1Ci6dsLFJp4sY= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,SPF_PASS,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from blr-ubuntu-41.ap.qualcomm.com (unknown [202.46.23.61]) (using TLSv1.1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek.gautam@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id D604561691; Tue, 4 Oct 2016 10:43:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1475577835; bh=95R7jkACslXOzyyb3nzt3fhS3MiPkXR0cGXaTo4Raks=; h=From:To:Cc:Subject:Date:From; b=N/Mzi+ni8Gp8R/EgPQxcODC7U/6SZUQB8kAhjEoG1gaeqK3qj64lvHCme6dzMtuGq 2u/ZHmihxHc9nkUWFSm8cfwKLz0xfDOTTHJqIPWVK87vMEzE/D08Frl6rIB1jsvV7i 3yxkp7qGaXHRVAVFBiEZBaHVgJzKW52hpnCIMPpU= DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org D604561691 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=pass smtp.mailfrom=vivek.gautam@codeaurora.org From: Vivek Gautam To: kishon@ti.com Cc: robh+dt@kernel.org, mark.rutland@arm.com, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, vivek.gautam@codeaurora.org, Felipe Balbi Subject: [PATCH] phy: nop: Add a new phy driver for No-Op transceiver Date: Tue, 4 Oct 2016 16:13:37 +0530 Message-Id: <1475577817-28500-1-git-send-email-vivek.gautam@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org No-Op phy transceiver can be used on platforms that have controllers which themselves provide PHY functionality and there's no separate PHY controller available. This driver provides a basic skeleton for a nop-phy driver. This can be further extended to add required features. Inspired by phy-generic driver in drivers/usb/phy. Signed-off-by: Vivek Gautam Cc: Kishon Vijay Abraham I Cc: Felipe Balbi --- Hi Kishon, Felipe, This patch has been lying in my tree for sometime. This introduces a skeletal nop-phy driver based on generic phy framework. I mainly use this driver when I have only one phy driver available for testing for a controller that uses more than one phy. But this can be further extended to add any feature support for controllers that don't have a separate PHY controller and that themselves provide the PHY functionality, a purpose similar to what drivers/usb/phy/phy-generic.c driver serves. Do you think we have a requirement for such a driver in the generic phy layer? I hope this driver can do some good. Let me know your comments on this. Thanks Vivek Documentation/devicetree/bindings/phy/phy-nop.txt | 22 +++ drivers/phy/Kconfig | 10 ++ drivers/phy/Makefile | 1 + drivers/phy/phy-nop.c | 193 ++++++++++++++++++++++ 4 files changed, 226 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/phy-nop.txt create mode 100644 drivers/phy/phy-nop.c diff --git a/Documentation/devicetree/bindings/phy/phy-nop.txt b/Documentation/devicetree/bindings/phy/phy-nop.txt new file mode 100644 index 0000000..6cb6779 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/phy-nop.txt @@ -0,0 +1,22 @@ +Generic No-Op PHY +----------------- + +Required properties: + - compatible: compatible list, contains "phy-nop". + - #phy-cells: must be 0. + +Optional properties: + - clocks: a list of phandles and clock-specifier pairs, + one for each entry in clock-names. + - clock-names: must be "main_clk" for phy core clock, + "ref_clk" for phy reference clk. + - resets: a list of phandles and reset controller specifier pairs, + one for each entry in reset-names. + - reset-names: must be "phy" for reset of phy block. + - vdd-supply: Phandle to a regulator supply to PHY core block. + +Example: + phy_nop: phy_nop { + compatible = "phy-nop"; + #phy-cells = <0>; + }; diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index fe00f91..1923c4f 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -489,4 +489,14 @@ config PHY_NS2_PCIE help Enable this to support the Broadcom Northstar2 PCIe PHY. If unsure, say N. + +config PHY_NOP + tristate "No-Operation PHY transceiver driver" + depends on OF || COMPILE_TEST + select GENERIC_PHY + help + Enable this to support the generic no-operation PHY + transeiver. This driver can be used with consumers + requiring a no-op phy for few of the handlers. + endmenu diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index a534cf5..d6e0e60 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile @@ -60,3 +60,4 @@ obj-$(CONFIG_PHY_PISTACHIO_USB) += phy-pistachio-usb.o obj-$(CONFIG_PHY_CYGNUS_PCIE) += phy-bcm-cygnus-pcie.o obj-$(CONFIG_ARCH_TEGRA) += tegra/ obj-$(CONFIG_PHY_NS2_PCIE) += phy-bcm-ns2-pcie.o +obj-$(CONFIG_PHY_NOP) += phy-nop.o diff --git a/drivers/phy/phy-nop.c b/drivers/phy/phy-nop.c new file mode 100644 index 0000000..cab01a1 --- /dev/null +++ b/drivers/phy/phy-nop.c @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2016, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include +#include +#include +#include + +/** + * struct phy_nop:- structure holding NOP PHY attributes. + * + * @dev: pointer to device. + * @phy: pointer to generic phy. + * @clk: pointer to phy clock. + * @refclk: pointer to phy reference clock. + * @vdd: vdd supply to the phy core block. + * @rst: pointer to reset controller for the phy block. + */ +struct phy_nop { + struct device *dev; + struct phy *phy; + struct clk *clk; + struct clk *refclk; + struct regulator *vdd; + struct reset_control *rst; +}; + +static int phy_nop_poweron(struct phy *generic_phy) +{ + struct phy_nop *phy = phy_get_drvdata(generic_phy); + int ret = 0; + + if (phy->vdd) { + ret = regulator_enable(phy->vdd); + if (ret) { + dev_err(phy->dev, "vdd enable failed: %d\n", ret); + return ret; + } + } + + if (phy->clk) { + ret = clk_prepare_enable(phy->clk); + if (ret) { + dev_err(phy->dev, "main clk enable failed: %d\n", ret); + goto err_clk; + } + } + + if (phy->refclk) { + ret = clk_prepare_enable(phy->refclk); + if (ret) { + dev_err(phy->dev, "ref clk enable failed: %d\n", ret); + goto err_refclk; + } + } + + if (phy->rst) { + ret = reset_control_deassert(phy->rst); + if (ret) { + dev_err(phy->dev, "phy reset deassert failed\n"); + goto err_rst; + } + } + + return 0; + +err_rst: + clk_disable_unprepare(phy->refclk); +err_refclk: + clk_disable_unprepare(phy->clk); +err_clk: + regulator_disable(phy->vdd); + return ret; +} + +static int phy_nop_poweroff(struct phy *generic_phy) +{ + struct phy_nop *phy = phy_get_drvdata(generic_phy); + + if (phy->rst) + reset_control_assert(phy->rst); + + if (phy->clk) + clk_disable_unprepare(phy->clk); + if (phy->refclk) + clk_disable_unprepare(phy->refclk); + + if (phy->vdd) + regulator_disable(phy->vdd); + + return 0; +} + +static const struct phy_ops phy_nop_gen_ops = { + .power_on = phy_nop_poweron, + .power_off = phy_nop_poweroff, + .owner = THIS_MODULE, +}; + +static int phy_nop_probe(struct platform_device *pdev) +{ + struct phy_nop *phy; + struct phy *generic_phy; + struct device *dev = &pdev->dev; + struct phy_provider *phy_provider; + int ret = 0; + + phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + if (!phy) + return -ENOMEM; + phy->dev = dev; + + /* XXX: Do we need to request any clocks ? */ + phy->clk = devm_clk_get(dev, "main_clk"); + if (IS_ERR(phy->clk)) { + dev_dbg(dev, "failed to get main_clk: %ld\n", + PTR_ERR(phy->clk)); + phy->clk = NULL; + } + phy->refclk = devm_clk_get(dev, "ref_clk"); + if (IS_ERR(phy->refclk)) { + dev_dbg(dev, "failed to get ref_clk: %ld\n", + PTR_ERR(phy->refclk)); + phy->refclk = NULL; + } + + /* XXX: Do we need to request any regulators ? */ + phy->vdd = devm_regulator_get(dev, "vdd"); + if (IS_ERR(phy->vdd)) { + dev_dbg(dev, "failed to get vdd for phy: %ld\n", + PTR_ERR(phy->vdd)); + phy->vdd = NULL; + } + + /* XXX: Do we need to request any phy-reset ? */ + phy->rst = devm_reset_control_get(dev, "phy"); + if (IS_ERR(phy->rst)) { + dev_dbg(dev, "failed to get phy core reset: %ld\n", + PTR_ERR(phy->rst)); + phy->rst = NULL; + } + + generic_phy = devm_phy_create(dev, NULL, &phy_nop_gen_ops); + if (IS_ERR(generic_phy)) { + ret = PTR_ERR(generic_phy); + dev_err(dev, "failed to create generic phy %d\n", ret); + return ret; + } + phy->phy = generic_phy; + phy_set_drvdata(generic_phy, phy); + + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + if (IS_ERR(phy_provider)) { + ret = PTR_ERR(phy_provider); + dev_err(dev, "failed to register phy %d\n", ret); + } + + return ret; +} + +static const struct of_device_id phy_nop_id_table[] = { + { + .compatible = "phy-nop", + }, + { }, +}; +MODULE_DEVICE_TABLE(of, phy_nop_id_table); + +static struct platform_driver phy_nop_driver = { + .probe = phy_nop_probe, + .driver = { + .name = "phy_nop", + .of_match_table = of_match_ptr(phy_nop_id_table), + }, +}; + +module_platform_driver(phy_nop_driver); + +MODULE_DESCRIPTION("Generic No-op PHY driver"); +MODULE_LICENSE("GPL v2");