From patchwork Thu Jul 1 02:23:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 469345 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 C6B27C11F6A for ; Thu, 1 Jul 2021 02:24:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADE9B6147E for ; Thu, 1 Jul 2021 02:24:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238636AbhGAC1U (ORCPT ); Wed, 30 Jun 2021 22:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238624AbhGAC1S (ORCPT ); Wed, 30 Jun 2021 22:27:18 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4612AC0617AD; Wed, 30 Jun 2021 19:24:48 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id u20so6115307ljo.12; Wed, 30 Jun 2021 19:24:48 -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=RCwohtIz3sCtyYyXBVentwmefpHY5XVxUVHIc+3K8pk=; b=XxV2PXccub5gL4UFzOEf2lkunHDZ6JDQIsv3Pkr16ah73RBm7xcGYlqWEolys4Ur+r 3tkygAmQYHm+q3gdEMA1GrL7qb7Tjrz8jupGkjQDhPIv5lqWZ1qIaVhwCzNbLeHVjj7u AFxRblkyWF6IYcT446qkn4INxKWeqJBcccZCppYkka6l4qRdbuA7Kf9bx414LlK7elB7 dcXySBbrzNaOFCLFlqWZTweNHtgMqjDsvpEs1b5dJlspMqUkHN3/d+ilqcd+d+fJwB3J IpsK1ZNI3jpOF3+QYzoPDNMbZnH1kW844FlAb5CbFD8ufqKfxQkfaCd5u/xDerBT7Gg4 zR/g== 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=RCwohtIz3sCtyYyXBVentwmefpHY5XVxUVHIc+3K8pk=; b=tIXyyCcASkC/SYoibNhB+c37Vx08yDcDiLQS7vthfnyIX7Fd60bPIzIrNDfbYvrueg EMnrXhweo+EIr401AxbFzTtX6gefIdqqVyjj99no56y7+SANiH2zZZoQU4X58B2ZYjIb Llab23CC9xmS+fFRVBA6eDkLcJhY/4h2f6jyLa2ZnQogHVv3eUSwR52EPZ+Hrxhhgbqe V+4J3QioUcIMMJ06keDhyk9MNc5uq+MHG/uhZq2Fg+3hkJWPqPgPaxyA0yB9RCzkhrD0 ZhDIG6OTDFha3PHwFAA/AtDzSr1UMsDeTeO1EHvDfAvUmCnXcXlc25OJ5gmyR7gWVXse 6+OQ== X-Gm-Message-State: AOAM532H99JMaHWkqLux5ucHkSZuyGUTn1JiFXB1GMXIEOiRwe1KJHLh YaVgBR7S3iWyuyZQsgr9kBI= X-Google-Smtp-Source: ABdhPJyMARDiyQ+EZ9AIx/bYIcUlMrTrOT7a1tX7E9FK7PHW8cPpFgduAmN2JM1n/Pjyuh6AKkUB6g== X-Received: by 2002:a2e:502:: with SMTP id 2mr10228083ljf.36.1625106286623; Wed, 30 Jun 2021 19:24:46 -0700 (PDT) Received: from localhost.localdomain (94-29-37-113.dynamic.spd-mgts.ru. [94.29.37.113]) by smtp.gmail.com with ESMTPSA id v7sm2407262ljn.14.2021.06.30.19.24.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 19:24:46 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Rob Herring , Sebastian Reichel , Peter Chen , Greg Kroah-Hartman , Felipe Balbi , David Heidelberg Cc: devicetree@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v1 03/12] soc/tegra: pmc: Expose USB regmap to all SoCs Date: Thu, 1 Jul 2021 05:23:56 +0300 Message-Id: <20210701022405.10817-4-digetx@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210701022405.10817-1-digetx@gmail.com> References: <20210701022405.10817-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org All Tegra SoCs prior to Tegra186 have USB power controls within the Power Management controller. These controls need to be configured by USB driver. Expose the regmap to these SoCs. Signed-off-by: Dmitry Osipenko --- drivers/soc/tegra/pmc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c index b5a924baef4e..f8fcfc9750f9 100644 --- a/drivers/soc/tegra/pmc.c +++ b/drivers/soc/tegra/pmc.c @@ -3212,7 +3212,7 @@ static const struct tegra_pmc_soc tegra20_pmc_soc = { .pmc_clks_data = NULL, .num_pmc_clks = 0, .has_blink_output = true, - .has_usb_sleepwalk = false, + .has_usb_sleepwalk = true, }; static const char * const tegra30_powergates[] = { @@ -3273,7 +3273,7 @@ static const struct tegra_pmc_soc tegra30_pmc_soc = { .pmc_clks_data = tegra_pmc_clks_data, .num_pmc_clks = ARRAY_SIZE(tegra_pmc_clks_data), .has_blink_output = true, - .has_usb_sleepwalk = false, + .has_usb_sleepwalk = true, }; static const char * const tegra114_powergates[] = { @@ -3330,7 +3330,7 @@ static const struct tegra_pmc_soc tegra114_pmc_soc = { .pmc_clks_data = tegra_pmc_clks_data, .num_pmc_clks = ARRAY_SIZE(tegra_pmc_clks_data), .has_blink_output = true, - .has_usb_sleepwalk = false, + .has_usb_sleepwalk = true, }; static const char * const tegra124_powergates[] = { From patchwork Thu Jul 1 02:23:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 469342 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 937D3C11F68 for ; Thu, 1 Jul 2021 02:25:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B3B26146D for ; Thu, 1 Jul 2021 02:25:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238657AbhGAC1V (ORCPT ); Wed, 30 Jun 2021 22:27:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238633AbhGAC1T (ORCPT ); Wed, 30 Jun 2021 22:27:19 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C182C0617AE; Wed, 30 Jun 2021 19:24:49 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id k21so6191601ljh.2; Wed, 30 Jun 2021 19:24:49 -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=2cruuUsOAPQVLtszR01ej2dNa4b85BlFaFd+gq/wwh4=; b=sxA3+eMqkFNJZHIKU6U0A4Kz+/A3/V/cMXcOHnTNWngxNBGjnes4KKRwyrPq2tzcIT KpKGKLk4/N6lbEVRaLiH+RiSeC2OmDoXGtu2z023ae4JptSQJYc8GWjJz8O4+xItGJOB ynRib5XOOm9abC1dDaOb7bglwv7GwLGkuW5C3GBPc51TAPbnVPExgC8vHL7qm4/V409a 0jIJF8gRJ3EbSIWQ9Iwkrm+l0xo6km0YBqIIvOhSgxAdLuMbcm7XSWsXvz1LnUIvKcaH +YqJQ64WPCnwttShpnWuTNa91WkfmEgAqPvqpx6UTuUapaFDu1KkgFH/IndWUrvzxGZX yqyQ== 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=2cruuUsOAPQVLtszR01ej2dNa4b85BlFaFd+gq/wwh4=; b=lFZkPngBjgFklfZe7ngjlK6Wq3ElmB8jCeLd2o0tqaCBN6eOKNkkctVy7b4NfPaSoc xl9v549Bt6Rq1/z9NxFoRSLDWw6Q5UdD3bsGK7FZavw9I1c0vYq0YlW4WuQj8GwpdOLw 7S9bQIvdq46LO8sHTJaG8Lt9ebXVlWuAFyb5Wy6Ip8w7/SEe6cA5jVNL8KlWwml4Y8Xq cLGL19gfFKOb+P/HZwl2RaNYcDYq3O6Hs1FXGcDnOcOfjMdTBYGw0gShWwDrE6IeZ2ok TxexlXVj+hSEE/W3ZRwh1V/j0Is5asJ7zjyeiLZvJqWJjSq08yBPiy3SN7Uf/gmsBaLG MPPg== X-Gm-Message-State: AOAM531O65gNrduCtl6uWJuOTLAYnHKrvNK+ugDVExFFwow93YLROcXd s3mDkEEgmbKFuXijDnTYxUs= X-Google-Smtp-Source: ABdhPJwb2LvXguv2N+ndnCaVlt9ZONVVy6UEcXkOrVJtQXX1TjJBQb2gQVNIe86sk0Srgh6d5a6Nbw== X-Received: by 2002:a2e:8e29:: with SMTP id r9mr9913017ljk.370.1625106287433; Wed, 30 Jun 2021 19:24:47 -0700 (PDT) Received: from localhost.localdomain (94-29-37-113.dynamic.spd-mgts.ru. [94.29.37.113]) by smtp.gmail.com with ESMTPSA id v7sm2407262ljn.14.2021.06.30.19.24.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 19:24:47 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Rob Herring , Sebastian Reichel , Peter Chen , Greg Kroah-Hartman , Felipe Balbi , David Heidelberg Cc: devicetree@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v1 04/12] usb: phy: tegra: Support OTG mode programming Date: Thu, 1 Jul 2021 05:23:57 +0300 Message-Id: <20210701022405.10817-5-digetx@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210701022405.10817-1-digetx@gmail.com> References: <20210701022405.10817-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Support programming USB PHY into OTG mode. Signed-off-by: Dmitry Osipenko --- drivers/usb/phy/phy-tegra-usb.c | 166 +++++++++++++++++++++++++++++- include/linux/usb/tegra_usb_phy.h | 5 + 2 files changed, 167 insertions(+), 4 deletions(-) diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c index c0f432d509aa..621f527baa8a 100644 --- a/drivers/usb/phy/phy-tegra-usb.c +++ b/drivers/usb/phy/phy-tegra-usb.c @@ -63,6 +63,10 @@ #define A_VBUS_VLD_WAKEUP_EN BIT(30) #define USB_PHY_VBUS_WAKEUP_ID 0x408 +#define ID_INT_EN BIT(0) +#define ID_CHG_DET BIT(1) +#define VBUS_WAKEUP_INT_EN BIT(8) +#define VBUS_WAKEUP_CHG_DET BIT(9) #define VBUS_WAKEUP_STS BIT(10) #define VBUS_WAKEUP_WAKEUP_EN BIT(30) @@ -158,6 +162,10 @@ #define USB_USBMODE_HOST (3 << 0) #define USB_USBMODE_DEVICE (2 << 0) +#define PMC_USB_AO 0xf0 +#define VBUS_WAKEUP_PD_P0 BIT(2) +#define ID_PD_P0 BIT(3) + static DEFINE_SPINLOCK(utmip_pad_lock); static unsigned int utmip_pad_count; @@ -533,13 +541,14 @@ static int utmi_phy_power_on(struct tegra_usb_phy *phy) val &= ~USB_WAKE_ON_RESUME_EN; writel_relaxed(val, base + USB_SUSP_CTRL); - if (phy->mode == USB_DR_MODE_PERIPHERAL) { + if (phy->mode != USB_DR_MODE_HOST) { val = readl_relaxed(base + USB_SUSP_CTRL); val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV); writel_relaxed(val, base + USB_SUSP_CTRL); val = readl_relaxed(base + USB_PHY_VBUS_WAKEUP_ID); val &= ~VBUS_WAKEUP_WAKEUP_EN; + val &= ~(ID_INT_EN | VBUS_WAKEUP_INT_EN); writel_relaxed(val, base + USB_PHY_VBUS_WAKEUP_ID); val = readl_relaxed(base + USB_PHY_VBUS_SENSORS); @@ -687,9 +696,11 @@ static int utmi_phy_power_off(struct tegra_usb_phy *phy) * Ask VBUS sensor to generate wake event once cable is * connected. */ - if (phy->mode == USB_DR_MODE_PERIPHERAL) { + if (phy->mode != USB_DR_MODE_HOST) { val = readl_relaxed(base + USB_PHY_VBUS_WAKEUP_ID); val |= VBUS_WAKEUP_WAKEUP_EN; + val |= ID_INT_EN | VBUS_WAKEUP_INT_EN; + val &= ~(ID_CHG_DET | VBUS_WAKEUP_CHG_DET); writel_relaxed(val, base + USB_PHY_VBUS_WAKEUP_ID); val = readl_relaxed(base + USB_PHY_VBUS_SENSORS); @@ -893,6 +904,9 @@ static void tegra_usb_phy_shutdown(struct usb_phy *u_phy) if (WARN_ON(!phy->freq)) return; + if (phy->irq > 0) + free_irq(phy->irq, phy); + tegra_usb_phy_power_off(phy); if (!phy->is_ulpi_phy) @@ -916,14 +930,90 @@ static int tegra_usb_phy_set_wakeup(struct usb_phy *u_phy, bool enable) static int tegra_usb_phy_set_suspend(struct usb_phy *u_phy, int suspend) { struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); + int ret; if (WARN_ON(!phy->freq)) return -EINVAL; + if (phy->irq > 0) + disable_irq(phy->irq); + if (suspend) - return tegra_usb_phy_power_off(phy); + ret = tegra_usb_phy_power_off(phy); else - return tegra_usb_phy_power_on(phy); + ret = tegra_usb_phy_power_on(phy); + + if (phy->irq > 0) + enable_irq(phy->irq); + + return ret; +} + +static irqreturn_t tegra_usb_phy_isr(int irq, void *data) +{ + u32 val, int_mask = ID_CHG_DET | VBUS_WAKEUP_CHG_DET; + struct tegra_usb_phy *phy = data; + void __iomem *base = phy->regs; + + /* + * The PHY interrupt also wakes the USB controller driver since + * interrupt is shared. We don't do anything in the PHY driver, + * so just clear the interrupt. + */ + val = readl_relaxed(base + USB_PHY_VBUS_WAKEUP_ID); + writel_relaxed(val, base + USB_PHY_VBUS_WAKEUP_ID); + + return val & int_mask ? IRQ_HANDLED : IRQ_NONE; +} + +static int tegra_usb_phy_configure_pmc(struct tegra_usb_phy *phy) +{ + int err, val = 0; + + /* older device-trees don't have PMC regmap */ + if (!phy->pmc_regmap) + return 0; + + /* should be initialized if regmap presents */ + if (WARN_ON_ONCE(phy->instance < 0)) + return 0; + + /* + * Tegra20 has a different layout of PMC USB register bits and AO is + * enabled by default after system reset on Tegra20, so assume nothing + * to do on Tegra20. + */ + if (!phy->soc_config->requires_pmc_ao_power_up) + return 0; + + /* enable VBUS wake-up detector */ + if (phy->mode != USB_DR_MODE_HOST) + val |= VBUS_WAKEUP_PD_P0 << phy->instance * 4; + + /* enable ID-pin ACC detector for OTG mode switching */ + if (phy->mode == USB_DR_MODE_OTG) + val |= ID_PD_P0 << phy->instance * 4; + + /* disable detectors to reset them */ + err = regmap_set_bits(phy->pmc_regmap, PMC_USB_AO, val); + if (err) { + dev_err(phy->u_phy.dev, "Failed to disable PMC AO: %d\n", err); + return err; + } + + usleep_range(10, 100); + + /* enable detectors */ + err = regmap_clear_bits(phy->pmc_regmap, PMC_USB_AO, val); + if (err) { + dev_err(phy->u_phy.dev, "Failed to enable PMC AO: %d\n", err); + return err; + } + + /* detectors starts to work after 10ms */ + usleep_range(10000, 15000); + + return 0; } static int tegra_usb_phy_init(struct usb_phy *u_phy) @@ -967,12 +1057,26 @@ static int tegra_usb_phy_init(struct usb_phy *u_phy) goto disable_vbus; } + err = tegra_usb_phy_configure_pmc(phy); + if (err) + goto close_phy; + err = tegra_usb_phy_power_on(phy); if (err) goto close_phy; + if (phy->irq > 0) { + err = request_irq(phy->irq, tegra_usb_phy_isr, IRQF_SHARED, + dev_name(phy->u_phy.dev), phy); + if (err) + goto pwr_off_phy; + } + return 0; +pwr_off_phy: + tegra_usb_phy_power_off(phy); + close_phy: if (!phy->is_ulpi_phy) utmip_pad_close(phy); @@ -1135,11 +1239,50 @@ static int utmi_phy_probe(struct tegra_usb_phy *tegra_phy, return 0; } +static void tegra_usb_phy_put_pmc_device(void *dev) +{ + put_device(dev); +} + +static struct regmap *tegra_usb_phy_get_pmc_regmap(struct device *dev) +{ + struct platform_device *pmc_pdev; + struct device_node *np; + struct regmap *regmap; + int err; + + np = of_parse_phandle(dev->of_node, "nvidia,pmc", 0); + if (!np) { + dev_warn_once(dev, "nvidia,pmc is missing, please update your device-tree\n"); + return NULL; + } + + pmc_pdev = of_find_device_by_node(np); + of_node_put(np); + if (!pmc_pdev) + return ERR_PTR(-ENODEV); + + err = devm_add_action_or_reset(dev, tegra_usb_phy_put_pmc_device, + &pmc_pdev->dev); + if (err) + return ERR_PTR(err); + + if (!platform_get_drvdata(pmc_pdev)) + return ERR_PTR(-EPROBE_DEFER); + + regmap = dev_get_regmap(&pmc_pdev->dev, "usb_sleepwalk"); + if (!regmap) + return ERR_PTR(-EINVAL); + + return regmap; +} + static const struct tegra_phy_soc_config tegra20_soc_config = { .utmi_pll_config_in_car_module = false, .has_hostpc = false, .requires_usbmode_setup = false, .requires_extra_tuning_parameters = false, + .requires_pmc_ao_power_up = false, }; static const struct tegra_phy_soc_config tegra30_soc_config = { @@ -1147,6 +1290,7 @@ static const struct tegra_phy_soc_config tegra30_soc_config = { .has_hostpc = true, .requires_usbmode_setup = true, .requires_extra_tuning_parameters = true, + .requires_pmc_ao_power_up = true, }; static const struct of_device_id tegra_usb_phy_id_table[] = { @@ -1172,6 +1316,7 @@ static int tegra_usb_phy_probe(struct platform_device *pdev) return -ENOMEM; tegra_phy->soc_config = of_device_get_match_data(&pdev->dev); + tegra_phy->irq = platform_get_irq_optional(pdev, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { @@ -1215,6 +1360,19 @@ static int tegra_usb_phy_probe(struct platform_device *pdev) return err; } + tegra_phy->pmc_regmap = tegra_usb_phy_get_pmc_regmap(&pdev->dev); + err = PTR_ERR_OR_ZERO(tegra_phy->pmc_regmap); + if (err) { + dev_err_probe(&pdev->dev, err, "Failed to get PMC regmap\n"); + return err; + } + + /* older device-trees don't specify instance ID */ + err = of_property_read_u32(np, "nvidia,phy-instance", + &tegra_phy->instance); + if (err) + tegra_phy->instance = -1; + phy_type = of_usb_get_phy_mode(np); switch (phy_type) { case USBPHY_INTERFACE_MODE_UTMI: diff --git a/include/linux/usb/tegra_usb_phy.h b/include/linux/usb/tegra_usb_phy.h index fd1c9f6a4e37..d3e65eb9e16f 100644 --- a/include/linux/usb/tegra_usb_phy.h +++ b/include/linux/usb/tegra_usb_phy.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -30,6 +31,7 @@ * enter host mode * requires_extra_tuning_parameters: true if xcvr_hsslew, hssquelch_level * and hsdiscon_level should be set for adequate signal quality + * requires_pmc_ao_power_up: true if USB AO is powered down by default */ struct tegra_phy_soc_config { @@ -37,6 +39,7 @@ struct tegra_phy_soc_config { bool has_hostpc; bool requires_usbmode_setup; bool requires_extra_tuning_parameters; + bool requires_pmc_ao_power_up; }; struct tegra_utmip_config { @@ -62,6 +65,7 @@ enum tegra_usb_phy_port_speed { struct tegra_xtal_freq; struct tegra_usb_phy { + int irq; int instance; const struct tegra_xtal_freq *freq; void __iomem *regs; @@ -70,6 +74,7 @@ struct tegra_usb_phy { struct clk *pll_u; struct clk *pad_clk; struct regulator *vbus; + struct regmap *pmc_regmap; enum usb_dr_mode mode; void *config; const struct tegra_phy_soc_config *soc_config; From patchwork Thu Jul 1 02:23:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 469344 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 1C357C47E48 for ; Thu, 1 Jul 2021 02:24:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E6EA961469 for ; Thu, 1 Jul 2021 02:24:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238666AbhGAC1W (ORCPT ); Wed, 30 Jun 2021 22:27:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238639AbhGAC1U (ORCPT ); Wed, 30 Jun 2021 22:27:20 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76256C0617A8; Wed, 30 Jun 2021 19:24:50 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id u25so6132690ljj.11; Wed, 30 Jun 2021 19:24:50 -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=IwL3qryTNfgwkU5i7nwmV+nzWjMAB8DcHs6NfVFo2aw=; b=tIusmnHfpa7QldsC+QYuL0IiSy5lUtLgTU2ip2anCvjeciwgULJeDsonrJ+yE7Xk6l tXLc10VR93uc2MwE5oVK0C+bXZmKMJvoll+Rj4AmzqJuQzUqCW1M0L0eWMWSxh9Iu639 3KahBcBhl8XapWawTh3V18wJmhZaaYOzYVEsyf89hLwbVa/88wTEggdv5HeA0gginkZ2 +SPq5XqFyvKOYLUDRA3tLGlkR94ffAxn6FoTPGSvcTUD13aQajiSkTWkrBw4oUgevK3c NAIyLzZOwBkTFdiQHvDRoBdFKz6nLpu5V6/Lf62iaz5JVJzGuV4tcLru5TVJri5ZtrVu tXhA== 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=IwL3qryTNfgwkU5i7nwmV+nzWjMAB8DcHs6NfVFo2aw=; b=UVHqQaq1Sx+pgyLZZLEHYv4kGN+28tiHUHsYqYXDXDg3gpawWW6nAC9MhEg6aMJaUZ jgUr0Xh3zBqtAM2XRiTRgQz1m6rqAyZf4l8dDo8vVDcl9b7U3I0TP32F6J6zRNyrtm1B cDfFsYJrh8fB/v7SuxAd1QDK4ZQ1IQtRK6rmqgl3Fv5pHi75OPY42vXWRLSCmv0S098a a1or6PTUSTjRjo+rbcgF4C8oVew3vPINQmInXXf+IeSOvBkUBxtlfbo8cLDnBHOwC2PH NjHQ15zsO+R2U/U4ouARggN5A+WplWsLctoOinpQ2qSFKo0koOl+Q4QWpHV+MQ+y4WxE 9Iog== X-Gm-Message-State: AOAM533uc1U4ndVxcL7TbY27/E+88nmDKWdbdKvHjqr7/hMA3YD7UMJP YL7KvEwe+LsyLrHBrpC8JKM= X-Google-Smtp-Source: ABdhPJz3UUBzoGKmaBnOPlxMEk6Za+dxEHeTazeZhoLEMO5I1u8ovsFD22Y1hTttln9f0lqnfwyINQ== X-Received: by 2002:a2e:9cd:: with SMTP id 196mr10135948ljj.98.1625106288905; Wed, 30 Jun 2021 19:24:48 -0700 (PDT) Received: from localhost.localdomain (94-29-37-113.dynamic.spd-mgts.ru. [94.29.37.113]) by smtp.gmail.com with ESMTPSA id v7sm2407262ljn.14.2021.06.30.19.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 19:24:48 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Rob Herring , Sebastian Reichel , Peter Chen , Greg Kroah-Hartman , Felipe Balbi , David Heidelberg Cc: devicetree@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v1 06/12] dt-bindings: power: supply: smb347-charger: Document USB VBUS regulator Date: Thu, 1 Jul 2021 05:23:59 +0300 Message-Id: <20210701022405.10817-7-digetx@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210701022405.10817-1-digetx@gmail.com> References: <20210701022405.10817-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org SMB347 can supply power to USB VBUS, which is required by OTG-cable devices that want to switch USB port into the host mode. Add USB VBUS regulator properties. Signed-off-by: Dmitry Osipenko --- .../power/supply/summit,smb347-charger.yaml | 28 +++++++++++++++++++ .../dt-bindings/power/summit,smb347-charger.h | 4 +++ 2 files changed, 32 insertions(+) diff --git a/Documentation/devicetree/bindings/power/supply/summit,smb347-charger.yaml b/Documentation/devicetree/bindings/power/supply/summit,smb347-charger.yaml index 983fc215c1e5..cd3d834f734d 100644 --- a/Documentation/devicetree/bindings/power/supply/summit,smb347-charger.yaml +++ b/Documentation/devicetree/bindings/power/supply/summit,smb347-charger.yaml @@ -73,6 +73,24 @@ properties: - 1 # SMB3XX_SOFT_TEMP_COMPENSATE_CURRENT Current compensation - 2 # SMB3XX_SOFT_TEMP_COMPENSATE_VOLTAGE Voltage compensation + summit,inok-polarity: + description: | + Polarity of INOK signal indicating presence of external power supply. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: + - 0 # SMB3XX_SYSOK_INOK_ACTIVE_LOW + - 1 # SMB3XX_SYSOK_INOK_ACTIVE_HIGH + + usb-vbus: + $ref: "../../regulator/regulator.yaml#" + type: object + + properties: + summit,needs-inok-toggle: + type: boolean + description: INOK signal is fixed and polarity needs to be toggled + in order to enable/disable output mode. + allOf: - if: properties: @@ -134,6 +152,7 @@ examples: reg = <0x7f>; summit,enable-charge-control = ; + summit,inok-polarity = ; summit,chip-temperature-threshold-celsius = <110>; summit,mains-current-limit-microamp = <2000000>; summit,usb-current-limit-microamp = <500000>; @@ -141,6 +160,15 @@ examples: summit,enable-mains-charging; monitored-battery = <&battery>; + + usb-vbus { + regulator-name = "usb_vbus"; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + regulator-min-microamp = <750000>; + regulator-max-microamp = <750000>; + summit,needs-inok-toggle; + }; }; }; diff --git a/include/dt-bindings/power/summit,smb347-charger.h b/include/dt-bindings/power/summit,smb347-charger.h index d918bf321a71..3205699b5e41 100644 --- a/include/dt-bindings/power/summit,smb347-charger.h +++ b/include/dt-bindings/power/summit,smb347-charger.h @@ -16,4 +16,8 @@ #define SMB3XX_CHG_ENABLE_PIN_ACTIVE_LOW 1 #define SMB3XX_CHG_ENABLE_PIN_ACTIVE_HIGH 2 +/* Polarity of INOK signal */ +#define SMB3XX_SYSOK_INOK_ACTIVE_LOW 0 +#define SMB3XX_SYSOK_INOK_ACTIVE_HIGH 1 + #endif From patchwork Thu Jul 1 02:24:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 469340 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 5FF16C11F6D for ; Thu, 1 Jul 2021 02:25:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45ABC6147E for ; Thu, 1 Jul 2021 02:25:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238780AbhGAC1g (ORCPT ); Wed, 30 Jun 2021 22:27:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238664AbhGAC1W (ORCPT ); Wed, 30 Jun 2021 22:27:22 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48AB8C0613A2; Wed, 30 Jun 2021 19:24:51 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id f13so6137658ljp.10; Wed, 30 Jun 2021 19:24:51 -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=esff+ZXqqz83swKvK/vBkagYD4H4gF2qZzwq0FaHQEk=; b=LfHrbtJT8SQNYgOxuByF33zsi0fUJ2IMbfbtKeIMm49coJc97ACnpMGGtCM9PDt+fc up57htuFcMKqIJNIWGYbatAi+OVn40wnQw0ij8HAj/TYUkIJdpuwfIZCYFxDg6iQJPQr wuw3W23Fi43sVQZ7XcQ11LiM+Q5nasbnPy6SalNEeHUiXzMEwVsdFOrmKLYXyPJezuGK z8MEjs7L4J/THe1x1Bd7V5seBpsTE8kEw63svctJBGTbyJ+jmd0IRoeLkteQXPB41F6+ +ZTKcBG1xpJ+mEpIPS/IDXqgaenRzs9Q9TXm9oZTO7wHAHhcE6duhKhsg7YtZdO9FJ1n dO3w== 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=esff+ZXqqz83swKvK/vBkagYD4H4gF2qZzwq0FaHQEk=; b=QrTW5Ee1EbqY7juR6IB1Bc4FDzObPvc+zXZsMORjcui9k+A1UISVP3O5aB+LZcCkCf Ow+lH7iqP+l1cprh2Z24LfyZZSf0seWLM/cF3B49AyM6ldr6HsFS01I5XsezuDJVXRFl TTANFDx16GWx8EGHkA3Vc6SyUsv4Jo6echF78q7ql+7xfxBJaYvnBnX+DNY7mKZInDkm mJtYajWkDRh6r2iGHEg/FUhMpzzayZqEKKP2v5v59yTrLFAa5DAVzh5q3efMFw9u435A Si3VkcXfH5Twt5t5zp5GY+vtD9UXXlMykHEDIRAeNN6ASRTKhK/bvNXbkad6CGlh6yF5 nX4g== X-Gm-Message-State: AOAM531RLzbSuTniDf5DokG3dcmtkO5IpSQqwL9tHT9LZt6Kz4ao24g2 yQtTw8N1xSzO8DBL6fOHIGI= X-Google-Smtp-Source: ABdhPJz+J6+TdtzyRYMkQ/xx/qSunXyMi5ChDbDhNBwakwQ2/5icuNKzrcTHjPloczTgbBDUBe87qQ== X-Received: by 2002:a2e:6d11:: with SMTP id i17mr10419938ljc.75.1625106289654; Wed, 30 Jun 2021 19:24:49 -0700 (PDT) Received: from localhost.localdomain (94-29-37-113.dynamic.spd-mgts.ru. [94.29.37.113]) by smtp.gmail.com with ESMTPSA id v7sm2407262ljn.14.2021.06.30.19.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 19:24:49 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Rob Herring , Sebastian Reichel , Peter Chen , Greg Kroah-Hartman , Felipe Balbi , David Heidelberg Cc: devicetree@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v1 07/12] power: supply: smb347-charger: Make smb347_set_writable() IRQ-safe Date: Thu, 1 Jul 2021 05:24:00 +0300 Message-Id: <20210701022405.10817-8-digetx@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210701022405.10817-1-digetx@gmail.com> References: <20210701022405.10817-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The smb347_set_writable() is used by interrupt handler and outside of it. The interrupt should be disabled when the function is used outside of interrupt handler in order to prevent racing with the interrupt context. Add new parameter to smb347_set_writable() that allows to disable IRQ. Signed-off-by: Dmitry Osipenko --- drivers/power/supply/smb347-charger.c | 30 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/power/supply/smb347-charger.c b/drivers/power/supply/smb347-charger.c index df240420f2de..db1378b41f80 100644 --- a/drivers/power/supply/smb347-charger.c +++ b/drivers/power/supply/smb347-charger.c @@ -671,10 +671,22 @@ static int smb347_set_temp_limits(struct smb347_charger *smb) * * Returns %0 on success and negative errno in case of failure. */ -static int smb347_set_writable(struct smb347_charger *smb, bool writable) +static int smb347_set_writable(struct smb347_charger *smb, bool writable, + bool irq_toggle) { - return regmap_update_bits(smb->regmap, CMD_A, CMD_A_ALLOW_WRITE, - writable ? CMD_A_ALLOW_WRITE : 0); + struct i2c_client *client = to_i2c_client(smb->dev); + int ret; + + if (writable && irq_toggle && !smb->irq_unsupported) + disable_irq(client->irq); + + ret = regmap_update_bits(smb->regmap, CMD_A, CMD_A_ALLOW_WRITE, + writable ? CMD_A_ALLOW_WRITE : 0); + + if ((!writable || ret) && irq_toggle && !smb->irq_unsupported) + enable_irq(client->irq); + + return ret; } static int smb347_hw_init(struct smb347_charger *smb) @@ -682,7 +694,7 @@ static int smb347_hw_init(struct smb347_charger *smb) unsigned int val; int ret; - ret = smb347_set_writable(smb, true); + ret = smb347_set_writable(smb, true, false); if (ret < 0) return ret; @@ -758,7 +770,7 @@ static int smb347_hw_init(struct smb347_charger *smb) ret = smb347_start_stop_charging(smb); fail: - smb347_set_writable(smb, false); + smb347_set_writable(smb, false, false); return ret; } @@ -866,7 +878,7 @@ static int smb347_irq_set(struct smb347_charger *smb, bool enable) if (smb->irq_unsupported) return 0; - ret = smb347_set_writable(smb, true); + ret = smb347_set_writable(smb, true, true); if (ret < 0) return ret; @@ -891,7 +903,7 @@ static int smb347_irq_set(struct smb347_charger *smb, bool enable) ret = regmap_update_bits(smb->regmap, CFG_PIN, CFG_PIN_EN_CHARGER_ERROR, enable ? CFG_PIN_EN_CHARGER_ERROR : 0); fail: - smb347_set_writable(smb, false); + smb347_set_writable(smb, false, true); return ret; } @@ -919,7 +931,7 @@ static int smb347_irq_init(struct smb347_charger *smb, if (!client->irq) return 0; - ret = smb347_set_writable(smb, true); + ret = smb347_set_writable(smb, true, false); if (ret < 0) return ret; @@ -931,7 +943,7 @@ static int smb347_irq_init(struct smb347_charger *smb, CFG_STAT_ACTIVE_HIGH | CFG_STAT_DISABLED, CFG_STAT_DISABLED); - smb347_set_writable(smb, false); + smb347_set_writable(smb, false, false); if (ret < 0) { dev_warn(smb->dev, "failed to initialize IRQ: %d\n", ret); From patchwork Thu Jul 1 02:24:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 469343 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 68821C11F7D for ; Thu, 1 Jul 2021 02:24:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F8D161492 for ; Thu, 1 Jul 2021 02:24:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238691AbhGAC1Z (ORCPT ); Wed, 30 Jun 2021 22:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238673AbhGAC1X (ORCPT ); Wed, 30 Jun 2021 22:27:23 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7EB0C0617A8; Wed, 30 Jun 2021 19:24:51 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id q4so6118507ljp.13; Wed, 30 Jun 2021 19:24:51 -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=BFXR8UJAJfYBsWt7j+dPhOe713FxNJqHeaZ6mJiooJo=; b=PK62oc2eMNNQ6fbAE/rLJKzZ2fEctzHg/zwUBO/9i6KwADR2bcleLT9ktF9W4q2UaB bwJZBnbGvOG5PKx1j5lwHivo8dbjBqaljlzOaON4KQw/WGkREIkHk2kxcOKORCFMmlMW rEsPtJHBL5AbQMW7Ywzxtdlx1UgqbD7K8uFNWQLc6aYBxYvnHwuiCcwp3oN2F+jDlJIK Cvjhgjy5uQt2sjZF9c5+bXypA6IqxBg6KNnr1pJINDleJrUx1xgqLMzg2b0tmv/PhZ8Q AGbhfYK6bOKuMhL+VqgpkOWZaZNVKq38fYZucm2dWNV+VCk/oUmdCRnUmE+KkSNu3IrI kYfg== 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=BFXR8UJAJfYBsWt7j+dPhOe713FxNJqHeaZ6mJiooJo=; b=Kvu/YkFlLTKHVJaAwqT4a5Lb3zvJfBWPq4CONe0dbkCm28Hmjnmo0fQUrPMzMaPEH1 zD5CLOasHO9TuDKkKWIbs7dh+L68hOPTJWgfirkXfR+xmDuuB8DwlTxucKWiMikSjLFc tX8+nd3Oq/FHLBm+Mq0Lw9VfPwo9NZVzphSyayZKNkP1OnDZ4QYWF7GZBm/EOM7Edvlc jOfLFZ3qwcSd5bMBoKShLELsN0SZsCNh9mi3bRXCuTDVq40rwfVAod126M4cRJtFjFGY 8RagDbJq/r1MyCHpd3lGQFKICcH3TdspG3pkpa3eXhmi6JN59Ff1OCJPvsatSO71H3As IV3w== X-Gm-Message-State: AOAM532HObtiTNdPrWh+qv+uyshxPHPIBkIvAWRHzjGNhWibOvp2gvxS 4IKGsBIOYLFtUTF9dKjJenU= X-Google-Smtp-Source: ABdhPJw/Rj4deuEH5QIk2/cuYLMxw+SwxZOEK2ukcEiuy3kFs6NDJMl8Hiicl+LCn1mE0MWIkKkyXw== X-Received: by 2002:a2e:974f:: with SMTP id f15mr10061298ljj.434.1625106290320; Wed, 30 Jun 2021 19:24:50 -0700 (PDT) Received: from localhost.localdomain (94-29-37-113.dynamic.spd-mgts.ru. [94.29.37.113]) by smtp.gmail.com with ESMTPSA id v7sm2407262ljn.14.2021.06.30.19.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 19:24:50 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Rob Herring , Sebastian Reichel , Peter Chen , Greg Kroah-Hartman , Felipe Balbi , David Heidelberg Cc: devicetree@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v1 08/12] power: supply: smb347-charger: Remove caching of charger state Date: Thu, 1 Jul 2021 05:24:01 +0300 Message-Id: <20210701022405.10817-9-digetx@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210701022405.10817-1-digetx@gmail.com> References: <20210701022405.10817-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Regmap already provides us with the caching, so remove caching of charger state to make code cleaner. Signed-off-by: Dmitry Osipenko --- drivers/power/supply/smb347-charger.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/power/supply/smb347-charger.c b/drivers/power/supply/smb347-charger.c index db1378b41f80..f81c60c679a0 100644 --- a/drivers/power/supply/smb347-charger.c +++ b/drivers/power/supply/smb347-charger.c @@ -135,7 +135,6 @@ * @id: SMB charger ID * @mains_online: is AC/DC input connected * @usb_online: is USB input connected - * @charging_enabled: is charging enabled * @irq_unsupported: is interrupt unsupported by SMB hardware * @max_charge_current: maximum current (in uA) the battery can be charged * @max_charge_voltage: maximum voltage (in uV) the battery can be charged @@ -192,7 +191,6 @@ struct smb347_charger { unsigned int id; bool mains_online; bool usb_online; - bool charging_enabled; bool irq_unsupported; unsigned int max_charge_current; @@ -358,21 +356,13 @@ static int smb347_charging_status(struct smb347_charger *smb) static int smb347_charging_set(struct smb347_charger *smb, bool enable) { - int ret = 0; - if (smb->enable_control != SMB3XX_CHG_ENABLE_SW) { dev_dbg(smb->dev, "charging enable/disable in SW disabled\n"); return 0; } - if (smb->charging_enabled != enable) { - ret = regmap_update_bits(smb->regmap, CMD_A, CMD_A_CHG_ENABLED, - enable ? CMD_A_CHG_ENABLED : 0); - if (!ret) - smb->charging_enabled = enable; - } - - return ret; + return regmap_update_bits(smb->regmap, CMD_A, CMD_A_CHG_ENABLED, + enable ? CMD_A_CHG_ENABLED : 0); } static inline int smb347_charging_enable(struct smb347_charger *smb) From patchwork Thu Jul 1 02:24:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 469341 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 1BB47C11F7A for ; Thu, 1 Jul 2021 02:25:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F371461627 for ; Thu, 1 Jul 2021 02:25:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238732AbhGAC1a (ORCPT ); Wed, 30 Jun 2021 22:27:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238695AbhGAC1Z (ORCPT ); Wed, 30 Jun 2021 22:27:25 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0992C061756; Wed, 30 Jun 2021 19:24:54 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id d16so8908492lfn.3; Wed, 30 Jun 2021 19:24:54 -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=+unlqaajKL+UdtGKZaBkJ1mKCovLdUju0d1rygjTQhE=; b=U1f0aL/dsUy1ATWelleHa9rQI5g5jUd+AjxgB+5npU89mZoHOugUN9T8DmQYDgH2Fj kStJ7b9KyuFRYJz2MBMIuUpUM3grAkr54sQTsh9+LRK3pM//wzAes2cyf+7Va/VR018D TSP2lfHHwTbSU0GZuKGAMHgKTYyIIdIIXF9AzaKs/a39+t88PppneFd3Zjf4O79jIqXA liDnW4775e3NagthQAIG2LrcRstkYCOLMWibKxb3BQNuk0RxdVtzqbiF0mgPUkJh+lDb G55QTWZ7bQQahv/H4POlpzSHfCakKQh3ooCbCESlktHCEv1s0FiET4i+LrJduqrGOwad sebw== 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=+unlqaajKL+UdtGKZaBkJ1mKCovLdUju0d1rygjTQhE=; b=naCpQgXejg51j8iIFY+NRL6KEUaL35hc+eS7GxlUTbK+olXJbuKy8D12R4G8ts8IiH UxIZlUa/aUC8TxY+ul8hDxExBYjf4NGMK7J1eh0InzkAL8ub5NwyzunhLI2IqwjzNHvw CRNYYDYkagl4TYw3HnJL1SfAW/UZov0cIMxLFQvJIPhCwyZMMTFr6OlEPZJ65g+/u0zB aC7z0zFIBfnhdEYxEJeqQnQ7I7mCQlS5kObGaTaZ7O2xpDjW7/a2OF3EjUm08yMc4zGt InfvGkMB6P1GOsRIHmyEqRe38hhRxsaq1CoWMIcJUfHJMOFpXieL9GbDEoSfhjqphSI/ 06Gg== X-Gm-Message-State: AOAM531NoHgQw8BxVy0fJz+yJVoEx2+g/KzVvWSHPXV07K+VL2FwNmdB yBWTUkUPYwPoaO//CyWN3So= X-Google-Smtp-Source: ABdhPJwRFghxwlHjwBfKGp6n4gvKiwCuXQ94+KGQ/Dq0axXpCaFiWVoPodkv6TpT22lTa+8o/SercQ== X-Received: by 2002:a05:6512:1048:: with SMTP id c8mr29229001lfb.480.1625106293053; Wed, 30 Jun 2021 19:24:53 -0700 (PDT) Received: from localhost.localdomain (94-29-37-113.dynamic.spd-mgts.ru. [94.29.37.113]) by smtp.gmail.com with ESMTPSA id v7sm2407262ljn.14.2021.06.30.19.24.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 19:24:52 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Rob Herring , Sebastian Reichel , Peter Chen , Greg Kroah-Hartman , Felipe Balbi , David Heidelberg Cc: devicetree@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v1 12/12] ARM: tegra: nexus7: Enable USB OTG mode Date: Thu, 1 Jul 2021 05:24:05 +0300 Message-Id: <20210701022405.10817-13-digetx@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210701022405.10817-1-digetx@gmail.com> References: <20210701022405.10817-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Nexus 7 has OTG-cable microUSB port, enable OTG mode. USB peripheral devices now can be connected to Nexus 7 using OTG adapter, switching USB port into host mode. Signed-off-by: Dmitry Osipenko --- .../tegra30-asus-nexus7-grouper-common.dtsi | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/arm/boot/dts/tegra30-asus-nexus7-grouper-common.dtsi b/arch/arm/boot/dts/tegra30-asus-nexus7-grouper-common.dtsi index 8bc552b09672..c341e8971b2f 100644 --- a/arch/arm/boot/dts/tegra30-asus-nexus7-grouper-common.dtsi +++ b/arch/arm/boot/dts/tegra30-asus-nexus7-grouper-common.dtsi @@ -941,9 +941,29 @@ power_supply: charger@6a { interrupts = ; summit,enable-charge-control = ; + summit,inok-polarity = ; summit,enable-usb-charging; monitored-battery = <&battery_cell>; + + usb_vbus: usb-vbus { + regulator-name = "usb_vbus"; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + regulator-min-microamp = <750000>; + regulator-max-microamp = <750000>; + + /* + * SMB347 INOK input pin is connected to PMIC's + * ACOK output, which is fixed to ACTIVE_LOW as + * long as battery voltage is in a good range. + * + * Active INOK disables SMB347 output, so polarity + * needs to be toggled when we want to get the + * output. + */ + summit,needs-inok-toggle; + }; }; }; @@ -1017,12 +1037,13 @@ sdmmc4: mmc@78000600 { usb@7d000000 { compatible = "nvidia,tegra30-udc"; status = "okay"; - dr_mode = "peripheral"; + dr_mode = "otg"; + vbus-supply = <&usb_vbus>; }; usb-phy@7d000000 { status = "okay"; - dr_mode = "peripheral"; + dr_mode = "otg"; nvidia,hssync-start-delay = <0>; nvidia,xcvr-lsfslew = <2>; nvidia,xcvr-lsrslew = <2>;