From patchwork Wed Aug 6 17:03:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Griffin X-Patchwork-Id: 34981 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 05AF720523 for ; Wed, 6 Aug 2014 17:03:50 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id b6sf8850202yha.1 for ; Wed, 06 Aug 2014 10:03:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=tOkZBw5Ki37HVzN23TVrV4ZCDGg+0VgNPJU+TGOZk3g=; b=LQPOyr/DeEBdnuH/XwVyWNLTR/t6Ok3G1mim5Ma3P1MvNwLVEP+uik3P/sKczPElGz 7niwN2MZ0tMnePVgoMXBcCppwtBNs0pPkvl/SjsVqV6EQ/5STkNO/MPC5DKddu+ko76b dN3/Pv5ezhNdDuw7LNTGolWoZPydrMQfI0RQXCLxaWyygFLmawUi5WAdDSTYdOHMPjPn noj34tFZ8EhPr3FYmMhChMfo9/cja9PgJvCb/rSrVpXZYpGEtYX4IkRy+1g8GM/iLbfs mAu8Gn03UNJfHIszLf/CoK0EOowH5NMzeZR6wbdxhNKTNUw6IW6okcVPzEoknJlc5zL1 FyTA== X-Gm-Message-State: ALoCoQltH2phCPOUMpPSGyS25q3CJubiHk4vw1SoIeq7CnFUkmpprPSwgGsNIBOLl2rb/2MK8fs1 X-Received: by 10.236.155.132 with SMTP id j4mr782350yhk.56.1407344629830; Wed, 06 Aug 2014 10:03:49 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.51.78 with SMTP id t72ls276438qga.87.gmail; Wed, 06 Aug 2014 10:03:49 -0700 (PDT) X-Received: by 10.220.183.65 with SMTP id cf1mr2019357vcb.76.1407344629682; Wed, 06 Aug 2014 10:03:49 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id fx7si726171vec.92.2014.08.06.10.03.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Aug 2014 10:03:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id lf12so4473963vcb.12 for ; Wed, 06 Aug 2014 10:03:49 -0700 (PDT) X-Received: by 10.52.5.201 with SMTP id u9mr1857693vdu.85.1407344629579; Wed, 06 Aug 2014 10:03:49 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp40475vcb; Wed, 6 Aug 2014 10:03:48 -0700 (PDT) X-Received: by 10.66.170.171 with SMTP id an11mr4416273pac.146.1407344628555; Wed, 06 Aug 2014 10:03:48 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oq10si1363483pac.48.2014.08.06.10.03.47 for ; Wed, 06 Aug 2014 10:03:48 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752854AbaHFRDZ (ORCPT + 26 others); Wed, 6 Aug 2014 13:03:25 -0400 Received: from mail-we0-f170.google.com ([74.125.82.170]:46663 "EHLO mail-we0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932782AbaHFRDW (ORCPT ); Wed, 6 Aug 2014 13:03:22 -0400 Received: by mail-we0-f170.google.com with SMTP id w62so2986101wes.15 for ; Wed, 06 Aug 2014 10:03:20 -0700 (PDT) X-Received: by 10.180.221.172 with SMTP id qf12mr17668799wic.18.1407344600913; Wed, 06 Aug 2014 10:03:20 -0700 (PDT) Received: from localhost.localdomain (cpc14-aztw22-2-0-cust189.18-1.cable.virginm.net. [82.45.1.190]) by mx.google.com with ESMTPSA id f6sm3712805wja.25.2014.08.06.10.03.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Aug 2014 10:03:20 -0700 (PDT) From: Peter Griffin To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, stern@rowland.harvard.edu, srinivas.kandagatla@gmail.com, maxime.coquelin@st.com, patrice.chotard@st.com, arnd@arndb.de Cc: peter.griffin@linaro.org, lee.jones@linaro.org, devicetree@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 1/6] usb: host: usb-st-common: Add common code required by ohci-st and ehci-st Date: Wed, 6 Aug 2014 18:03:04 +0100 Message-Id: <1407344589-24863-2-git-send-email-peter.griffin@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1407344589-24863-1-git-send-email-peter.griffin@linaro.org> References: <1407344589-24863-1-git-send-email-peter.griffin@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.griffin@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch abstracts out some common code required by both the ehci-st and ohci-st drivers. Signed-off-by: Peter Griffin --- drivers/usb/host/usb-st-common.c | 99 ++++++++++++++++++++++++++++++++++++++++ drivers/usb/host/usb-st-common.h | 34 ++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 drivers/usb/host/usb-st-common.c create mode 100644 drivers/usb/host/usb-st-common.h diff --git a/drivers/usb/host/usb-st-common.c b/drivers/usb/host/usb-st-common.c new file mode 100644 index 0000000..ddfdbf6 --- /dev/null +++ b/drivers/usb/host/usb-st-common.c @@ -0,0 +1,99 @@ +/* + * Common code shared between ehci-st.c and ohci-st.c + * + * Copyright (C) 2014 STMicroelectronics – All Rights Reserved + * + * Author: Peter Griffin + * + * Derived from ohci-platform.c and ehci-platform.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include + +#include "usb-st-common.h" + +int st_usb_platform_power_on(struct st_platform_priv *priv) +{ + int clk, ret; + + if (priv->pwr) { + ret = reset_control_deassert(priv->pwr); + if (ret) + return ret; + } + + if (priv->rst) { + ret = reset_control_deassert(priv->rst); + if (ret) + goto err_assert_power; + } + + /* some SoCs don't have a dedicated 48Mhz clock, but those that do + need the rate to be explicitly set */ + if (priv->clk48) { + ret = clk_set_rate(priv->clk48, 48000000); + if (ret) + goto err_assert_reset; + } + + for (clk = 0; clk < USB_MAX_CLKS && priv->clks[clk]; clk++) { + ret = clk_prepare_enable(priv->clks[clk]); + if (ret) + goto err_disable_clks; + } + + if (priv->phy) { + ret = phy_init(priv->phy); + if (ret) + goto err_disable_clks; + + ret = phy_power_on(priv->phy); + if (ret) + goto err_exit_phy; + } + + return 0; + +err_exit_phy: + phy_exit(priv->phy); +err_disable_clks: + while (--clk >= 0) + clk_disable_unprepare(priv->clks[clk]); +err_assert_reset: + if (priv->rst) + ret = reset_control_assert(priv->rst); +err_assert_power: + if (priv->pwr) + ret = reset_control_assert(priv->pwr); + + return ret; +} +EXPORT_SYMBOL(st_usb_platform_power_on); + +void st_usb_platform_power_off(struct st_platform_priv *priv) +{ + int clk; + + if (priv->pwr) + reset_control_assert(priv->pwr); + + if (priv->rst) + reset_control_assert(priv->rst); + + if (priv->phy) { + phy_power_off(priv->phy); + phy_exit(priv->phy); + } + + for (clk = USB_MAX_CLKS - 1; clk >= 0; clk--) + if (priv->clks[clk]) + clk_disable_unprepare(priv->clks[clk]); + +} +EXPORT_SYMBOL(st_usb_platform_power_off); diff --git a/drivers/usb/host/usb-st-common.h b/drivers/usb/host/usb-st-common.h new file mode 100644 index 0000000..5ee7fb0 --- /dev/null +++ b/drivers/usb/host/usb-st-common.h @@ -0,0 +1,34 @@ +/* + * ST ehci / ohci common header file + * + * Copyright (C) 2014 STMicroelectronics – All Rights Reserved + * + * Author: Peter Griffin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#ifndef __USB_ST_COMMON_H +#define __USB_ST_COMMON_H + +#include +#include +#include + +#define USB_MAX_CLKS 3 + +struct st_platform_priv { + struct clk *clks[USB_MAX_CLKS]; + struct clk *clk48; + struct reset_control *rst; + struct reset_control *pwr; + struct phy *phy; +}; + +int st_usb_platform_power_on(struct st_platform_priv *priv); +void st_usb_platform_power_off(struct st_platform_priv *priv); + +#endif /* __USB_ST_COMMON_H */