From patchwork Wed Sep 3 10:27:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Griffin X-Patchwork-Id: 36546 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oi0-f69.google.com (mail-oi0-f69.google.com [209.85.218.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B92DB2039B for ; Wed, 3 Sep 2014 10:29:51 +0000 (UTC) Received: by mail-oi0-f69.google.com with SMTP id a141sf1643355oig.8 for ; Wed, 03 Sep 2014 03:29:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=iSkTPIoEMOOOpvVzL5ZcW/x4iwfvYbq4jkEry4igfv8=; b=D6cti8cX9V86NtRf8YJG/3116P52GywfT5uVHnXbyIC1KSDKBh4/xdBRf8tAj3a5ED E6kpcJPfGteptdhzBC/UtwKoID0bA5n96mjp37S1Dh2yeqphvyRtWTjKkAnmqyh8gZdW q3i057nBuGKr3q+k9V9+9gnyoeOeFTwHLpuoUBCivBzDLEKpeTrEcvgX6jmQrRFPI+W1 Q2y7u3qz/9wg6Qhq90jgkH4hzYOXwLpzKK89EjcGKmS5LF4B/pdsfep3/R/2yF5BYOWp vCeI1zGjgg2GWpY00EYXUvCcJEc5P+eP5TkopgNjuWWw7Ys8fxcwz78z1fenKxNxAzjv sH7g== X-Gm-Message-State: ALoCoQlbm/ZzcBQetd9PsNHZ37YvlhEzCHj7TJ+kBTcojjS6Imc7Sl04lWW+R0E6pu5cwL5eI9KI X-Received: by 10.50.66.236 with SMTP id i12mr18927047igt.5.1409740191250; Wed, 03 Sep 2014 03:29:51 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.231 with SMTP id v94ls2728153qgd.14.gmail; Wed, 03 Sep 2014 03:29:51 -0700 (PDT) X-Received: by 10.220.251.200 with SMTP id mt8mr34530184vcb.24.1409740191091; Wed, 03 Sep 2014 03:29:51 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id l4si665658vdh.49.2014.09.03.03.29.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 03:29:51 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id hy4so8387785vcb.5 for ; Wed, 03 Sep 2014 03:29:51 -0700 (PDT) X-Received: by 10.52.238.227 with SMTP id vn3mr762316vdc.47.1409740190984; Wed, 03 Sep 2014 03:29:50 -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.45.67 with SMTP id uj3csp658318vcb; Wed, 3 Sep 2014 03:29:50 -0700 (PDT) X-Received: by 10.70.59.35 with SMTP id w3mr4795908pdq.51.1409740190066; Wed, 03 Sep 2014 03:29:50 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id de6si10093990pdb.232.2014.09.03.03.29.39 for ; Wed, 03 Sep 2014 03:29:40 -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 S932256AbaICK2o (ORCPT + 25 others); Wed, 3 Sep 2014 06:28:44 -0400 Received: from mail-we0-f179.google.com ([74.125.82.179]:60803 "EHLO mail-we0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755962AbaICK2K (ORCPT ); Wed, 3 Sep 2014 06:28:10 -0400 Received: by mail-we0-f179.google.com with SMTP id t60so8238891wes.24 for ; Wed, 03 Sep 2014 03:28:09 -0700 (PDT) X-Received: by 10.180.75.144 with SMTP id c16mr35079062wiw.9.1409740089008; Wed, 03 Sep 2014 03:28:09 -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 gk17sm3803619wic.16.2014.09.03.03.28.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 Sep 2014 03:28:08 -0700 (PDT) From: Peter Griffin To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, srinivas.kandagatla@gmail.com, maxime.coquelin@st.com, patrice.chotard@st.com, kishon@ti.com Cc: peter.griffin@linaro.org, lee.jones@linaro.org, devicetree@vger.kernel.org, Giuseppe Cavallaro Subject: [PATCH 1/3] phy: phy-stih407-usb: Add usb picoPHY driver found on stih407 SoC family Date: Wed, 3 Sep 2014 11:27:57 +0100 Message-Id: <1409740079-16554-2-git-send-email-peter.griffin@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1409740079-16554-1-git-send-email-peter.griffin@linaro.org> References: <1409740079-16554-1-git-send-email-peter.griffin@linaro.org> 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.174 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 is the generic phy driver for the picoPHY ports used by the USB2 and USB3 Host controllers available on STiH407 consumer electronic SoC families available from STMicroelectronics. Signed-off-by: Giuseppe Cavallaro Signed-off-by: Peter Griffin --- drivers/phy/Kconfig | 8 ++ drivers/phy/Makefile | 2 + drivers/phy/phy-stih407-usb.c | 185 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 195 insertions(+) create mode 100644 drivers/phy/phy-stih407-usb.c diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index 0dd7427..58018f7 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -230,4 +230,12 @@ config PHY_XGENE help This option enables support for APM X-Gene SoC multi-purpose PHY. +config PHY_STIH407_USB + tristate "STMicroelectronics USB2 picoPHY driver for STiH407 family" + depends on ARCH_STI + depends on GENERIC_PHY + help + Enable this support to enable the picoPHY device used by USB2 + and USB3 controllers on STMicroelectronics STiH407 SoC families. + endmenu diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index 95c69ed..c82ac59 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile @@ -28,3 +28,5 @@ obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o obj-$(CONFIG_PHY_ST_SPEAR1310_MIPHY) += phy-spear1310-miphy.o obj-$(CONFIG_PHY_ST_SPEAR1340_MIPHY) += phy-spear1340-miphy.o obj-$(CONFIG_PHY_XGENE) += phy-xgene.o +obj-$(CONFIG_PHY_STIH407_USB) += phy-stih407-usb.o + diff --git a/drivers/phy/phy-stih407-usb.c b/drivers/phy/phy-stih407-usb.c new file mode 100644 index 0000000..8019e3b --- /dev/null +++ b/drivers/phy/phy-stih407-usb.c @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2014 STMicroelectronics + * + * STMicroelectronics Generic PHY driver for STiH407 USB2. + * + * Author: Giuseppe Cavallaro + * + * 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 +#include +#include +#include +#include +#include +#include +#include + +/* Default PHY_SEL and REFCLKSEL configuration */ +#define STIH407_USB_PICOPHY_CTRL_PORT_CONF 0x6 +#define STIH407_USB_PICOPHY_CTRL_PORT_MASK 0x1f + +/* ports parameters overriding */ +#define STIH407_USB_PICOPHY_PARAM_DEF 0x39a4dc +#define STIH407_USB_PICOPHY_PARAM_MASK 0xffffffff + +struct stih407_usb2_picophy { + struct phy *phy; + struct regmap *regmap; + struct device *dev; + struct reset_control *rstc; + struct reset_control *rstport; + int ctrl; + int param; +}; + +static int stih407_usb2_pico_ctrl(struct stih407_usb2_picophy *phy_dev) +{ + reset_control_deassert(phy_dev->rstc); + + return regmap_update_bits(phy_dev->regmap, phy_dev->ctrl, + STIH407_USB_PICOPHY_CTRL_PORT_MASK, + STIH407_USB_PICOPHY_CTRL_PORT_CONF); +} + +static int stih407_usb2_init_port(struct phy *phy) +{ + int ret; + struct stih407_usb2_picophy *phy_dev = phy_get_drvdata(phy); + + stih407_usb2_pico_ctrl(phy_dev); + + ret = regmap_update_bits(phy_dev->regmap, + phy_dev->param, + STIH407_USB_PICOPHY_PARAM_MASK, + STIH407_USB_PICOPHY_PARAM_DEF); + if (ret) + return ret; + + return reset_control_deassert(phy_dev->rstport); +} + +static int stih407_usb2_exit_port(struct phy *phy) +{ + struct stih407_usb2_picophy *phy_dev = phy_get_drvdata(phy); + + /* + * Only port reset is asserted, phy global reset is kept untouched + * as other ports may still be active. When all ports are in reset + * state, assumption is made that power will be cut off on the phy, in + * case of suspend for instance. Theoretically, asserting individual + * reset (like here) or global reset should be equivalent. + */ + return reset_control_assert(phy_dev->rstport); +} + +static const struct phy_ops stih407_usb2_picophy_data = { + .init = stih407_usb2_init_port, + .exit = stih407_usb2_exit_port, + .owner = THIS_MODULE, +}; + +static const struct of_device_id stih407_usb2_picophy_of_match[]; + +static int stih407_usb2_picophy_probe(struct platform_device *pdev) +{ + const struct of_device_id *match; + struct stih407_usb2_picophy *phy_dev; + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct phy_provider *phy_provider; + struct phy *phy; + struct resource *res; + + phy_dev = devm_kzalloc(dev, sizeof(*phy_dev), GFP_KERNEL); + if (!phy_dev) + return -ENOMEM; + + match = of_match_device(stih407_usb2_picophy_of_match, dev); + if (!match) + return -ENODEV; + + phy_dev->dev = dev; + dev_set_drvdata(dev, phy_dev); + + phy_dev->rstc = devm_reset_control_get(dev, "global"); + if (IS_ERR(phy_dev->rstc)) { + dev_err(dev, "failed to ctrl picoPHY reset\n"); + return PTR_ERR(phy_dev->rstc); + } + + phy_dev->rstport = devm_reset_control_get(dev, "port"); + if (IS_ERR(phy_dev->rstport)) { + dev_err(dev, "failed to ctrl picoPHY reset\n"); + return PTR_ERR(phy_dev->rstport); + } + + /* Reset port by default: only deassert it in phy init */ + reset_control_assert(phy_dev->rstport); + + phy_dev->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg"); + if (IS_ERR(phy_dev->regmap)) { + dev_err(dev, "No syscfg phandle specified\n"); + return PTR_ERR(phy_dev->regmap); + } + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ctrl"); + if (!res) { + dev_err(dev, "No ctrl reg found\n"); + return -ENXIO; + } + phy_dev->ctrl = res->start; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "param"); + if (!res) { + dev_err(dev, "No param reg found\n"); + return -ENXIO; + } + phy_dev->param = res->start; + + phy = devm_phy_create(dev, NULL, match->data, NULL); + if (IS_ERR(phy)) { + dev_err(dev, "failed to create Display Port PHY\n"); + return PTR_ERR(phy); + } + + phy_dev->phy = phy; + phy_set_drvdata(phy, phy_dev); + + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + if (IS_ERR(phy_provider)) + return PTR_ERR(phy_provider); + + dev_info(dev, "STiH407 USB Generic picoPHY driver probed!"); + + return 0; +} + +static const struct of_device_id stih407_usb2_picophy_of_match[] = { + { .compatible = "st,stih407-usb2-phy", + .data = &stih407_usb2_picophy_data }, + { /*sentinel */ }, +}; + +MODULE_DEVICE_TABLE(of, stih407_usb2_picophy_of_match); + +static struct platform_driver stih407_usb2_picophy_driver = { + .probe = stih407_usb2_picophy_probe, + .driver = { + .name = "stih407-usb-genphy", + .of_match_table = stih407_usb2_picophy_of_match, + } +}; + +module_platform_driver(stih407_usb2_picophy_driver); + +MODULE_AUTHOR("Giuseppe Cavallaro "); +MODULE_DESCRIPTION("STMicroelectronics Generic picoPHY driver for STiH407"); +MODULE_LICENSE("GPL v2");