Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4292823pxk; Tue, 22 Sep 2020 15:55:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTkl2/WZ2fwHyZ5LmH8ZejgyR4HVgBhwu8ZA9nC0NQHVOYbgfvM65BF2/pNZWUzF6oGA4m X-Received: by 2002:a17:906:fca7:: with SMTP id qw7mr7228902ejb.522.1600815343434; Tue, 22 Sep 2020 15:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600815343; cv=none; d=google.com; s=arc-20160816; b=B84ogK1H6yFMwmqBGGKYEZkl+f0IuLrhaIS7aA/j9WakOGkuriEvZqvvZSbykAIYD4 MkuU1/CEU7Aaldh7g1JhZLX7ytJbzhx0W4dW9in/ki7R1BX0XOiIWITY61GGS8IYUu9E fJYfHMTqY/UPFZmHrkNeuzVClIYau+EiEi/qLjSPs8sxpEfroIKw/oMTyu2gtVNK/7e5 wD24PfNv2hQWt7f5uJYITwy1rHYlpOFzefHiNZWmi9BzCb/QPj+67LD/EIsdxPCMZevz EgSiZr5dZxjsT7bjIugc60ux/GGkkJHWZ7586t54qfL58LB/Cf4JU+Zj359zMUGnYuEp 1OTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WFZKHQfoiStVzgHOD3Vl3XMwQ6CDFlBEXqNiQ3V7k1k=; b=EWnaATIzB5b97fZKWkLnx7Sxb/tuUBcxpenq9VcK4hpZ02Ukqkh1MkyE516XpR5Br8 d9UrF2D7ziQ77YbL/+Ve2DXVHuKT/F3CuoEIiRmlKoJDzxMqoBaqovvYqz4dFOVAGfzv 242JMCdz7J/DrCqKVXXkQCWaX4k6F2jytIWTgQ41E7zxbAl50RaJ8vgPMBmSPGmYgpUh qki30BXB8eyJwuZrlQfA5KWycW8V+Qr3VSiI7kimF2qPW4o8dPeow+0YCxKMm9y1eaYb SA3586r7tH6YFeCT9ULNUsILW6qz/DuwsakkU0txwcfoV0mPlWzz81SO/nSaqDb3r/fY UTMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FWVJ+szE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z12si11998423eju.152.2020.09.22.15.55.20; Tue, 22 Sep 2020 15:55:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FWVJ+szE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727159AbgIVWxl (ORCPT + 99 others); Tue, 22 Sep 2020 18:53:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727028AbgIVWw7 (ORCPT ); Tue, 22 Sep 2020 18:52:59 -0400 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1ADFC0613D8; Tue, 22 Sep 2020 15:52:55 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id y2so19835104lfy.10; Tue, 22 Sep 2020 15:52:55 -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=WFZKHQfoiStVzgHOD3Vl3XMwQ6CDFlBEXqNiQ3V7k1k=; b=FWVJ+szE+0bIxYL5wuoS/eSETI7hLUUuzmXWKNXh2sJh5PJtckMhrnfad2l78puFpL GB62EU17r15dP++AfphwZqkUrcz0WVKzKyfKDAGAdE0t5D37mch9aQKcT/fLfU7555O6 Y3NL+eRe5XLlUP7Hu2Nmjz0lDLhVNBD+5ESEmzHtP4ZGBJp6Utuuhn9MjStrghKXtQkU XHLe004ffvTFEPPOYEF0KkHAG69QaCyLCBms58aM2GI9jMbV4psifbxN7a4bSSmXnbLb xSoN6l0yVObDSD7oADyS/YWv0XOFZTkZ2D49Fj9O7Oz8dbaEamLQHms2zlnUrFCa5FGl UwtQ== 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=WFZKHQfoiStVzgHOD3Vl3XMwQ6CDFlBEXqNiQ3V7k1k=; b=U6tPVL2AA+V8FQKTeoVjoV4aPkTAkF1vopsY3UWniEf5ce0NwhHMFHXC2w0AFEiuR7 H46vvZYNiar7L2NauaRNv/rD4B+ZAgV3tQDimh7dNgJhPWyrW0gfTkXIqsjNphx3sRLR /IRlIowh3VvBNC+LMN1JYtDn9VB2lMQniR53RXRxr0an+CGK0vz1qV+NJ2bO9Vnq3A3h JNBbTQAzxxe1BAZxVqgvw1cgQHafZXlcgTTQA1iguhEbvPKx6iKKMXv5lhAh6ZARSjha wmFUj0LRCtbMiTGpZkMmswrt1UNEsUZXVgk4shbQ59XiNb3uVmKJ+CDi0CD1LAaRoT2F L5qA== X-Gm-Message-State: AOAM532gaIDgS0M1Cslze8D4u+IFiLnm+yVCqf97BPGKTDpVJ/cIRlhc Ocs7MXTq9H5hSJGKbeafk3Q= X-Received: by 2002:a05:6512:3e8:: with SMTP id n8mr2391291lfq.492.1600815174258; Tue, 22 Sep 2020 15:52:54 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id l15sm3977588lfk.71.2020.09.22.15.52.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 15:52:53 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 25/32] i2c: tegra: Factor out hardware initialization into separate function Date: Wed, 23 Sep 2020 01:51:48 +0300 Message-Id: <20200922225155.10798-26-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200922225155.10798-1-digetx@gmail.com> References: <20200922225155.10798-1-digetx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Factor out hardware initialization into a separate function from the probe function. The only place where runtime PM needs to be resumed during probe is the place of hardware initialization, hence it makes sense to factor out it in order to have a bit cleaner error handling in tegra_i2c_probe(). Acked-by: Thierry Reding Tested-by: Thierry Reding Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 72ad0e8e89d2..a02675924a6f 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1660,9 +1660,23 @@ static void tegra_i2c_release_clocks(struct tegra_i2c_dev *i2c_dev) clk_bulk_unprepare(i2c_dev->nclocks, i2c_dev->clocks); } +static int tegra_i2c_init_hardware(struct tegra_i2c_dev *i2c_dev) +{ + int ret; + + ret = pm_runtime_get_sync(i2c_dev->dev); + if (ret < 0) + dev_err(i2c_dev->dev, "runtime resume failed: %d\n", ret); + else + ret = tegra_i2c_init(i2c_dev); + + pm_runtime_put(i2c_dev->dev); + + return ret; +} + static int tegra_i2c_probe(struct platform_device *pdev) { - struct device *dev = &pdev->dev; struct tegra_i2c_dev *i2c_dev; struct resource *res; int ret; @@ -1728,15 +1742,10 @@ static int tegra_i2c_probe(struct platform_device *pdev) if (!i2c_dev->is_vi) pm_runtime_irq_safe(&pdev->dev); pm_runtime_enable(&pdev->dev); - ret = pm_runtime_get_sync(i2c_dev->dev); - if (ret < 0) { - dev_err(dev, "runtime resume failed\n"); - goto put_rpm; - } - ret = tegra_i2c_init(i2c_dev); + ret = tegra_i2c_init_hardware(i2c_dev); if (ret) - goto put_rpm; + goto release_rpm; i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); i2c_dev->adapter.dev.of_node = pdev->dev.of_node; @@ -1757,14 +1766,11 @@ static int tegra_i2c_probe(struct platform_device *pdev) ret = i2c_add_numbered_adapter(&i2c_dev->adapter); if (ret) - goto put_rpm; - - pm_runtime_put(&pdev->dev); + goto release_rpm; return 0; -put_rpm: - pm_runtime_put_sync(&pdev->dev); +release_rpm: pm_runtime_disable(&pdev->dev); tegra_i2c_release_dma(i2c_dev); -- 2.27.0