From patchwork Wed Apr 24 12:34:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 1090116 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="opjj36S2"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44q0Bj40JLz9s7T for ; Wed, 24 Apr 2019 22:34:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730128AbfDXMeb (ORCPT ); Wed, 24 Apr 2019 08:34:31 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:42199 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729947AbfDXMea (ORCPT ); Wed, 24 Apr 2019 08:34:30 -0400 Received: by mail-lj1-f193.google.com with SMTP id i186so2776490lji.9; Wed, 24 Apr 2019 05:34:28 -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=wf7ZRFtlZtJ8GcqpzCHA0EDoifX2NsdN7Z4criiz7iY=; b=opjj36S251P/wxnDnNH1ylzmwC26Q19UTYlBIMgpUd/S7G5j1oPMa9uiAQvQVuyCky MwOv2Vfx7nkEIJLbTAfB0sD5EIY+GSLtlcU0lcunyimdV1DQiOlcS47E9NvcaAg3fzKf mrAYf3ZYk2YetGq/4aJo5/rBsJT7uTV6Xg5Rvtr7aCm0a/6u8Dvp/ngxdpRFRi6ZhSC5 1vJ8oKtvAkkR0TUIQtOqnMCIGSXK+Px/6KeI8o6O/sKZ5LEpGBunVdmU8/lnWnMgqPWb Vm5xhdh2/ZKPlQD/bCDpaC5K8A39oItYkTMuaRiZylcinOSsLLafz+3yYh0OcLSs2wfu v6HA== 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=wf7ZRFtlZtJ8GcqpzCHA0EDoifX2NsdN7Z4criiz7iY=; b=ezA9iYuqib217tQyX3FWrg4W9rOCcW8Sf3B0N4szNJWTJDwt7txgkYaxy5kCygQUCf 48RiZcRhFm8E6YMYx5iqrCX6PdDhsbwp5LtudENDEeYKDvVzhMW/NuCCaunKQ7pz5VV1 dX0I1GeZUNPc429H8mvL/1dpc0h/9UFcrP6hb7t0WbJyRGsV31qMYh1ODFowgwvB1Ihu Sn2LzSz9A6r78fuk57KCvxo5E8LezeK1SGg1RkNqQSqNnfyLZURZ75cHhVrj33flEia3 wIty3QG+qmImoAvrkP0GTvn69TOZLH+ZNPq8p1yq4g7Mimq9pPuhQWt1HnSZE1oFouP/ J3VQ== X-Gm-Message-State: APjAAAUwrJra20IGBRrMHq2cS30vx4WLfxh85EyiEB5InwUkkA5M9DTH 07pZeTUi089sWMIXREvcCwc= X-Google-Smtp-Source: APXvYqwWJihLtO71OddV96Wq9YTgrCnq8TKmn+DEVQrnS+cGY+FzMNncvS62s283f3zU8dtC+aahVw== X-Received: by 2002:a2e:309:: with SMTP id 9mr18068680ljd.114.1556109267833; Wed, 24 Apr 2019 05:34:27 -0700 (PDT) Received: from localhost.localdomain ([5.164.240.123]) by smtp.gmail.com with ESMTPSA id t14sm3765962lji.33.2019.04.24.05.34.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 05:34:27 -0700 (PDT) From: Serge Semin To: Peter Korsgaard , Peter Rosin Cc: Serge Semin , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] i2c-mux-gpio: Unpin a platform-based device initialization Date: Wed, 24 Apr 2019 15:34:10 +0300 Message-Id: <20190424123414.25311-2-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424123414.25311-1-fancer.lancer@gmail.com> References: <20190424123414.25311-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org We can unpin a code specific for i2c-mux-gpio device declared as platform device. In this case the platform data just needs to be copied to the private storage and if GPIO chip pointer is referring to a valid GPIO chip descriptor save it' base number for further GPIOs request and initialization. The rest of the code is common for both platform and OF-based setups. Signed-off-by: Serge Semin --- drivers/i2c/muxes/i2c-mux-gpio.c | 67 ++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c index 13882a2a4f60..24cf6ec02e75 100644 --- a/drivers/i2c/muxes/i2c-mux-gpio.c +++ b/drivers/i2c/muxes/i2c-mux-gpio.c @@ -136,44 +136,51 @@ static int i2c_mux_gpio_probe_dt(struct gpiomux *mux, } #endif +static int i2c_mux_gpio_probe_plat(struct gpiomux *mux, + struct platform_device *pdev) +{ + struct i2c_mux_gpio_platform_data *data = dev_get_platdata(&pdev->dev); + struct gpio_chip *gpio; + + /* + * If a GPIO chip name is provided, the GPIO pin numbers provided are + * relative to its base GPIO number. Otherwise they are absolute. + */ + if (data->gpio_chip) { + gpio = gpiochip_find(data->gpio_chip, + match_gpio_chip_by_label); + if (!gpio) + return -EPROBE_DEFER; + + mux->gpio_base = gpio->base; + } else { + mux->gpio_base = 0; + } + + memcpy(&mux->data, data, sizeof(mux->data)); + + return 0; +} + static int i2c_mux_gpio_probe(struct platform_device *pdev) { struct i2c_mux_core *muxc; struct gpiomux *mux; struct i2c_adapter *parent; struct i2c_adapter *root; - unsigned initial_state, gpio_base; + unsigned initial_state; int i, ret; mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); if (!mux) return -ENOMEM; - if (!dev_get_platdata(&pdev->dev)) { + if (!dev_get_platdata(&pdev->dev)) ret = i2c_mux_gpio_probe_dt(mux, pdev); - if (ret < 0) - return ret; - } else { - memcpy(&mux->data, dev_get_platdata(&pdev->dev), - sizeof(mux->data)); - } - - /* - * If a GPIO chip name is provided, the GPIO pin numbers provided are - * relative to its base GPIO number. Otherwise they are absolute. - */ - if (mux->data.gpio_chip) { - struct gpio_chip *gpio; - - gpio = gpiochip_find(mux->data.gpio_chip, - match_gpio_chip_by_label); - if (!gpio) - return -EPROBE_DEFER; - - gpio_base = gpio->base; - } else { - gpio_base = 0; - } + else + ret = i2c_mux_gpio_probe_plat(mux, pdev); + if (ret < 0) + return ret; parent = i2c_get_adapter(mux->data.parent); if (!parent) @@ -194,7 +201,6 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) root = i2c_root_adapter(&parent->dev); muxc->mux_locked = true; - mux->gpio_base = gpio_base; if (mux->data.idle != I2C_MUX_GPIO_NO_IDLE) { initial_state = mux->data.idle; @@ -207,14 +213,15 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) struct device *gpio_dev; struct gpio_desc *gpio_desc; - ret = gpio_request(gpio_base + mux->data.gpios[i], "i2c-mux-gpio"); + ret = gpio_request(mux->gpio_base + mux->data.gpios[i], + "i2c-mux-gpio"); if (ret) { dev_err(&pdev->dev, "Failed to request GPIO %d\n", mux->data.gpios[i]); goto err_request_gpio; } - ret = gpio_direction_output(gpio_base + mux->data.gpios[i], + ret = gpio_direction_output(mux->gpio_base + mux->data.gpios[i], initial_state & (1 << i)); if (ret) { dev_err(&pdev->dev, @@ -224,7 +231,7 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) goto err_request_gpio; } - gpio_desc = gpio_to_desc(gpio_base + mux->data.gpios[i]); + gpio_desc = gpio_to_desc(mux->gpio_base + mux->data.gpios[i]); mux->gpios[i] = gpio_desc; if (!muxc->mux_locked) @@ -256,7 +263,7 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) i = mux->data.n_gpios; err_request_gpio: for (; i > 0; i--) - gpio_free(gpio_base + mux->data.gpios[i - 1]); + gpio_free(mux->gpio_base + mux->data.gpios[i - 1]); alloc_failed: i2c_put_adapter(parent); From patchwork Wed Apr 24 12:34:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 1090117 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Sivt99Ft"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44q0Bq6YbQz9s71 for ; Wed, 24 Apr 2019 22:34:59 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729997AbfDXMex (ORCPT ); Wed, 24 Apr 2019 08:34:53 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:43832 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729980AbfDXMeb (ORCPT ); Wed, 24 Apr 2019 08:34:31 -0400 Received: by mail-lj1-f193.google.com with SMTP id k2so2454549lje.10; Wed, 24 Apr 2019 05:34:29 -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=+6jZN0Vl+RAhZC6JCcbsfReiinM9CSI7nwA9921XKbc=; b=Sivt99FtZ99ucSadBRT7+jKo6PgRiDrIdIKM0xeRsSIYW/nyie0pdUBsvctRCNeRKD BdIsG3m6AZ14SyyPu+wcDSQv5eslrWcYVnmjM8GLQqCZnfXFyABunMOx46ZZEMBRNn5T +v6u3uW3so/LFGe9u/K9rGKklt1etx+znyhLwrBVvudo1TN5g2SoEvbWF+OZybrIdihc AOwgOZKwpcPOHCv4wfL/+2q5ewDl1xUArMvhR3ttB/1IbBxn7dd7RhXLdEch9B63BlEt sdVjrqvilxql6CyamolZaOdLJYREmqcKylkAqUpCPPK5Ewk1/9XH1Ah+ciBHl9tEBj2L 1k2A== 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=+6jZN0Vl+RAhZC6JCcbsfReiinM9CSI7nwA9921XKbc=; b=hAagbGuaBcMoxZW6N/JsSpNbJWu6wcX8xVMgvKMn5NIb+WRokdaz0xSfZ2P3vUNiM3 rBFtLUP4XGIDSLGFieT1JpWFx2TAX/3kwP0tjhlVh7Kq/zvm6pl5UN6jxUZqOUFUNend zivZZn1RpBtzNlGSrnPrptQI/aIfHlGydloR0CWkZH3a1mZAUyqX0hs63tZ2JyfWWavE 2NkCoVi3I/V/NNZYcHgbpn3NAI8a91Uf6RF4Q5TL6MJ5xbFlMtyRbP0JUahnljmNcSBv J+h9D7nXvhyMwx3J7z9wRQ3nibT6mSmS60B5+TkRwhVne8ZQgmGE/TWoHTSRSA0xzY8j Vjjw== X-Gm-Message-State: APjAAAV0Ryv1wbQWRsPNAY5EW3viIVLHcTqCh26tiG6FURk+84j8PhS0 iLdzjiMte+yrgeel7iB68D0= X-Google-Smtp-Source: APXvYqxVoKFpn7RTcP5ZMITNPRVJKuo+skfqYWzaaAff9L8EQ6XAYTdO9V4ba83QxyiXOrbdHBWkDg== X-Received: by 2002:a2e:8347:: with SMTP id l7mr17260574ljh.17.1556109269170; Wed, 24 Apr 2019 05:34:29 -0700 (PDT) Received: from localhost.localdomain ([5.164.240.123]) by smtp.gmail.com with ESMTPSA id t14sm3765962lji.33.2019.04.24.05.34.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 05:34:28 -0700 (PDT) From: Serge Semin To: Peter Korsgaard , Peter Rosin Cc: Serge Semin , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] i2c-mux-gpio: Return an error if no config data found Date: Wed, 24 Apr 2019 15:34:11 +0300 Message-Id: <20190424123414.25311-3-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424123414.25311-1-fancer.lancer@gmail.com> References: <20190424123414.25311-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org It's pointless and might be even errors prone to proceed with further initialization if neither of- no platform-based settings were discovered. Just return an error in this case. Signed-off-by: Serge Semin --- drivers/i2c/muxes/i2c-mux-gpio.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c index 24cf6ec02e75..a14fe132b0c3 100644 --- a/drivers/i2c/muxes/i2c-mux-gpio.c +++ b/drivers/i2c/muxes/i2c-mux-gpio.c @@ -132,7 +132,7 @@ static int i2c_mux_gpio_probe_dt(struct gpiomux *mux, static int i2c_mux_gpio_probe_dt(struct gpiomux *mux, struct platform_device *pdev) { - return 0; + return -EINVAL; } #endif @@ -142,6 +142,9 @@ static int i2c_mux_gpio_probe_plat(struct gpiomux *mux, struct i2c_mux_gpio_platform_data *data = dev_get_platdata(&pdev->dev); struct gpio_chip *gpio; + if (!data) + return -EINVAL; + /* * If a GPIO chip name is provided, the GPIO pin numbers provided are * relative to its base GPIO number. Otherwise they are absolute. @@ -175,11 +178,10 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) if (!mux) return -ENOMEM; - if (!dev_get_platdata(&pdev->dev)) + ret = i2c_mux_gpio_probe_plat(mux, pdev); + if (ret) ret = i2c_mux_gpio_probe_dt(mux, pdev); - else - ret = i2c_mux_gpio_probe_plat(mux, pdev); - if (ret < 0) + if (ret) return ret; parent = i2c_get_adapter(mux->data.parent); From patchwork Wed Apr 24 12:34:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 1090115 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="CNSmJ2ei"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44q0Bh1C32z9s7T for ; Wed, 24 Apr 2019 22:34:52 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730175AbfDXMed (ORCPT ); Wed, 24 Apr 2019 08:34:33 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:36149 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730125AbfDXMec (ORCPT ); Wed, 24 Apr 2019 08:34:32 -0400 Received: by mail-lj1-f196.google.com with SMTP id l6so1878107ljb.3; Wed, 24 Apr 2019 05:34:31 -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=YW8mkRr9Gd3ekemnp28mgGnOxmrO43x9tEZ83C3zgJg=; b=CNSmJ2eitEaO22Rm5rSTGBQSGNibnCZQHV8j6ec9BF2rLCA8SVeQQGJ5uVWI1dHNfn 97JTJePCD4Z1SFe5kPGw5tdSScBMq+HUomeNC+OCrecepCD2bYx2y8yKhvw3Bo1gkRvm s+g+XNvGXJi5jMiIqmJ6tlTtS9AxOkpNAuAAsHdoK7X3e6Hr5fd1f58o3Zt4uju2y92N JfX4cdnqbpcLee1Zu6I+Y4i8Ci3LF9feW6AsjhkYyaFa4jrf5wshvNeq4tDgNDpLPGzj zRQKvoAgVvgNpiBpLu10zGoKe0ojeQ7b87+aP7yZBYOuKZIL3uhhgtofLwKTWnPYXcTO oexQ== 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=YW8mkRr9Gd3ekemnp28mgGnOxmrO43x9tEZ83C3zgJg=; b=Dwpsasdt8NzTjn8xC5uiz52q+XtY7wLey8EgVFWJ1mszy1ChREhurFdPweBq23bcP6 8T8nAOcg6BRhPHVCx+7TQqeje9F5vBeSrA7O99m+R+xBALsE0S3ZSTQBNpVQ9t1oVAgy +9XCbCK2zMUMPWEoNmMy0aeQT7al7ftlm90UwezUvPnFr6v5uhbeoKD0/lETq1O1rQ7r LXch2SKQdCWuyGHg2I8HKFgYjJauTLfsceRifubaqB7vxkK3UUHnLMu1O0/+rDyHcptp fXh9UiKW85r3QoCBKMjlD95AFjIzUSo8021YnjzmxKmNR0DULeS1DAve0zD/W7N90Cc+ X9vQ== X-Gm-Message-State: APjAAAVU+GIdlzY2BvG1Y6CNbKqVA4uO94WDvoCp3T1t38fQmnqyPeLU UYJA6j+H0ogvKyxz31METbI= X-Google-Smtp-Source: APXvYqxXCYrW7mwtF1t+GDFiO+IqpaZ7oR8SzyVQN6RUckJAg1xkkZX5L2bakLgH2q5qdPux1jTTng== X-Received: by 2002:a2e:888a:: with SMTP id k10mr3820729lji.57.1556109270294; Wed, 24 Apr 2019 05:34:30 -0700 (PDT) Received: from localhost.localdomain ([5.164.240.123]) by smtp.gmail.com with ESMTPSA id t14sm3765962lji.33.2019.04.24.05.34.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 05:34:29 -0700 (PDT) From: Serge Semin To: Peter Korsgaard , Peter Rosin Cc: Serge Semin , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] i2c-mux-gpio: Save initial channel number to the idle data field Date: Wed, 24 Apr 2019 15:34:12 +0300 Message-Id: <20190424123414.25311-4-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424123414.25311-1-fancer.lancer@gmail.com> References: <20190424123414.25311-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org In case if the idle state has been specified in the data structure, the idle variable is left untouched as before, so to keep a default channel number enabled in the mux idle state. But if a platform doesn't specify which channel is going to be enabled by default, we as before don't setup the deselect callback, but the initial state is saved in the idle variable for further initialization. We can safely do this here since that variable is used for initial state setting only, when no idling lane is specified. The reason of this change is to prepare the code for future GPIOs request path being split up into of- and plat- based methods. The idle variable here is used as a container of the initial state for both of the paths in case of idle-channel isn't specified. Signed-off-by: Serge Semin --- drivers/i2c/muxes/i2c-mux-gpio.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c index a14fe132b0c3..535c83c43371 100644 --- a/drivers/i2c/muxes/i2c-mux-gpio.c +++ b/drivers/i2c/muxes/i2c-mux-gpio.c @@ -171,7 +171,6 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) struct gpiomux *mux; struct i2c_adapter *parent; struct i2c_adapter *root; - unsigned initial_state; int i, ret; mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); @@ -204,12 +203,14 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) muxc->mux_locked = true; - if (mux->data.idle != I2C_MUX_GPIO_NO_IDLE) { - initial_state = mux->data.idle; + /* + * Set descelect callback if idle state has been setup otherwise just + * use the idle variable to store the initial muxer value. + */ + if (mux->data.idle != I2C_MUX_GPIO_NO_IDLE) muxc->deselect = i2c_mux_gpio_deselect; - } else { - initial_state = mux->data.values[0]; - } + else + mux->data.idle = mux->data.values[0]; for (i = 0; i < mux->data.n_gpios; i++) { struct device *gpio_dev; @@ -224,7 +225,7 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) } ret = gpio_direction_output(mux->gpio_base + mux->data.gpios[i], - initial_state & (1 << i)); + mux->data.idle & (1 << i)); if (ret) { dev_err(&pdev->dev, "Failed to set direction of GPIO %d to output\n", From patchwork Wed Apr 24 12:34:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 1090114 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="kD30lbVM"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44q0Bd4jH6z9s71 for ; Wed, 24 Apr 2019 22:34:49 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730202AbfDXMef (ORCPT ); Wed, 24 Apr 2019 08:34:35 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:45804 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730140AbfDXMee (ORCPT ); Wed, 24 Apr 2019 08:34:34 -0400 Received: by mail-lf1-f66.google.com with SMTP id t11so14513691lfl.12; Wed, 24 Apr 2019 05:34:32 -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=9M/tOm0l7xcRJSE038y20vsgQZbIvMnyyQr45cZvG0A=; b=kD30lbVM0SpLODmOvZ2HqS8KiXE0qs5E/MNE86hqfLl7UvB5hdcN00sjovKLsdt3k2 1eI8to0M3Jj7sqElbIXW4DOMxsY6Xu4PqJwvYulPD4y7NN2QdHxL3gcOiXRMJYWCRsQL 6VRdHflz7qOoQWr9daVH0KaRkuWv4TyOPHiaP7MDZMS7tj1XqSJ1Ev/W2aKIe+cTLAlw 7n7veGxhSfYvUyN0D0edvCdntSxcnMZVzyTqG0aNlDS84QPUHzkE/5C5Rjg0ibWXE/Ue DL1388HnhXUu0ExE63gPPT5Rr6h/zuXq+EbMi6XqUE62UmeORAiTtw1gfBhl7+meIzzA H85w== 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=9M/tOm0l7xcRJSE038y20vsgQZbIvMnyyQr45cZvG0A=; b=Xr1x5eboXMTNtyCJNIyNg5mOkWIjKulqrQzDZvz/WrL0QvUlP30+OijD5rc1g6kDoZ CJpmbDxyEuROk7dhmku/k3ZYlUEdzFQefBLbJfAQBLPvc8c2jvvQTlt3ApWupJBoRoT6 Bk1U7H6PnlgfabdoIZcxL56ag830SBR1UXn3ZS/cwHiIQhF8LJwTfxjBcWOtkBUpdYei kyN7m4eB3Q0nRIDJDCBwlJcZBwunHI2h87aLlciyJ0jtla2vg/JMCCa+GmuiV8oExhme F6lWjEOCgAmmSiL68ecKoZu5UndEUI9FYdtYnYGWQInfyaX83O4Uz5WeYs1kaoCfFbem WY9Q== X-Gm-Message-State: APjAAAVO7mKMZZuXQLGOd2tW8W6cQOANrJH4b0wS/oLe3QMKoa88pC1H +35BHgXtULbs0GC698CIp00= X-Google-Smtp-Source: APXvYqwPjMAHNQkagANpF1GNWXg7lWPLa0iL6rtyoEK7eaTYaPCrvkESIcorussVIFRZ4fFFcPff9A== X-Received: by 2002:ac2:4186:: with SMTP id z6mr16915147lfh.50.1556109271706; Wed, 24 Apr 2019 05:34:31 -0700 (PDT) Received: from localhost.localdomain ([5.164.240.123]) by smtp.gmail.com with ESMTPSA id t14sm3765962lji.33.2019.04.24.05.34.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 05:34:31 -0700 (PDT) From: Serge Semin To: Peter Korsgaard , Peter Rosin Cc: Serge Semin , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] i2c-mux-gpio: Unpin the platform-specific GPIOs request code Date: Wed, 24 Apr 2019 15:34:13 +0300 Message-Id: <20190424123414.25311-5-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424123414.25311-1-fancer.lancer@gmail.com> References: <20190424123414.25311-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The GPIOs request loop can be safely moved to a separate function. First of all it shall improve the code readability. Secondly the initialization loop at this point is used for both of- and platform_data-based initialization paths, but it will be changed in the next patch, so by isolating the code we'll simplify the future work. Signed-off-by: Serge Semin --- drivers/i2c/muxes/i2c-mux-gpio.c | 105 +++++++++++++++++++------------ 1 file changed, 64 insertions(+), 41 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c index 535c83c43371..317c019e1415 100644 --- a/drivers/i2c/muxes/i2c-mux-gpio.c +++ b/drivers/i2c/muxes/i2c-mux-gpio.c @@ -165,12 +165,68 @@ static int i2c_mux_gpio_probe_plat(struct gpiomux *mux, return 0; } +static int i2c_mux_gpio_request_plat(struct gpiomux *mux, + struct platform_device *pdev) +{ + struct i2c_mux_core *muxc = platform_get_drvdata(pdev); + struct gpio_desc *gpio_desc; + struct i2c_adapter *root; + struct device *gpio_dev; + int i, ret; + + root = i2c_root_adapter(&muxc->parent->dev); + + for (i = 0; i < mux->data.n_gpios; i++) { + ret = gpio_request(mux->gpio_base + mux->data.gpios[i], + "i2c-mux-gpio"); + if (ret) { + dev_err(&pdev->dev, "Failed to request GPIO %d\n", + mux->data.gpios[i]); + goto err_request_gpio; + } + + ret = gpio_direction_output(mux->gpio_base + mux->data.gpios[i], + mux->data.idle & (1 << i)); + if (ret) { + dev_err(&pdev->dev, + "Failed to set direction of GPIO %d to output\n", + mux->data.gpios[i]); + i++; /* gpio_request above succeeded, so must free */ + goto err_request_gpio; + } + + gpio_desc = gpio_to_desc(mux->gpio_base + mux->data.gpios[i]); + mux->gpios[i] = gpio_desc; + + if (!muxc->mux_locked) + continue; + + gpio_dev = &gpio_desc->gdev->dev; + muxc->mux_locked = i2c_root_adapter(gpio_dev) == root; + } + + return 0; + +err_request_gpio: + for (; i > 0; i--) + gpio_free(mux->gpio_base + mux->data.gpios[i - 1]); + + return ret; +} + +static void i2c_mux_gpio_free(struct gpiomux *mux) +{ + int i; + + for (i = 0; i < mux->data.n_gpios; i++) + gpiod_free(mux->gpios[i]); +} + static int i2c_mux_gpio_probe(struct platform_device *pdev) { struct i2c_mux_core *muxc; struct gpiomux *mux; struct i2c_adapter *parent; - struct i2c_adapter *root; int i, ret; mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); @@ -199,8 +255,6 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) platform_set_drvdata(pdev, muxc); - root = i2c_root_adapter(&parent->dev); - muxc->mux_locked = true; /* @@ -212,37 +266,9 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) else mux->data.idle = mux->data.values[0]; - for (i = 0; i < mux->data.n_gpios; i++) { - struct device *gpio_dev; - struct gpio_desc *gpio_desc; - - ret = gpio_request(mux->gpio_base + mux->data.gpios[i], - "i2c-mux-gpio"); - if (ret) { - dev_err(&pdev->dev, "Failed to request GPIO %d\n", - mux->data.gpios[i]); - goto err_request_gpio; - } - - ret = gpio_direction_output(mux->gpio_base + mux->data.gpios[i], - mux->data.idle & (1 << i)); - if (ret) { - dev_err(&pdev->dev, - "Failed to set direction of GPIO %d to output\n", - mux->data.gpios[i]); - i++; /* gpio_request above succeeded, so must free */ - goto err_request_gpio; - } - - gpio_desc = gpio_to_desc(mux->gpio_base + mux->data.gpios[i]); - mux->gpios[i] = gpio_desc; - - if (!muxc->mux_locked) - continue; - - gpio_dev = &gpio_desc->gdev->dev; - muxc->mux_locked = i2c_root_adapter(gpio_dev) == root; - } + ret = i2c_mux_gpio_request_plat(mux, pdev); + if (ret) + goto alloc_failed; if (muxc->mux_locked) dev_info(&pdev->dev, "mux-locked i2c mux\n"); @@ -263,10 +289,9 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) add_adapter_failed: i2c_mux_del_adapters(muxc); - i = mux->data.n_gpios; -err_request_gpio: - for (; i > 0; i--) - gpio_free(mux->gpio_base + mux->data.gpios[i - 1]); + + i2c_mux_gpio_free(mux); + alloc_failed: i2c_put_adapter(parent); @@ -277,12 +302,10 @@ static int i2c_mux_gpio_remove(struct platform_device *pdev) { struct i2c_mux_core *muxc = platform_get_drvdata(pdev); struct gpiomux *mux = i2c_mux_priv(muxc); - int i; i2c_mux_del_adapters(muxc); - for (i = 0; i < mux->data.n_gpios; i++) - gpio_free(mux->gpio_base + mux->data.gpios[i]); + i2c_mux_gpio_free(mux); i2c_put_adapter(muxc->parent); From patchwork Wed Apr 24 12:34:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 1090113 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JkrrzxTm"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44q0BQ6WhTz9s9G for ; Wed, 24 Apr 2019 22:34:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730210AbfDXMeg (ORCPT ); Wed, 24 Apr 2019 08:34:36 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:33555 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730179AbfDXMef (ORCPT ); Wed, 24 Apr 2019 08:34:35 -0400 Received: by mail-lf1-f65.google.com with SMTP id j11so14533594lfm.0; Wed, 24 Apr 2019 05:34:33 -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=Z+tI0Q1OGQBkYUEkcCnHn7Px/HZGg+Sa4rTg9VRP4b8=; b=JkrrzxTmbVRS8a3h6Yhhpi37YJ3I4vLZOtoKvRcP1uWGHAzjgglp/MnGdxho+3c1vl EYJXmZT0yiKU84iXTC6WlYkRXK3Hyafsm7uhusuD0cS7T86geQcIC7Gxk//l5AaP17S3 yGZPXWR27+Niherd0G1CW2grBE64VaA6xPhSDiSMyl+Dv/NkzzzR2cSlVeHmGVmJPRfX 5dCUgJnjUOBdtH5a2IeINKZMZtQn4ZZoFqJSn7QruGYnHeIuCQXLT4v15Wle+362rrfD JdrGFD+IqYo3J5g9Y7gn7PaieOInA6ZGAwwDVrAWZOfo7tCYV+r7OBwdvCkRRiYWMkRj tiYA== 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=Z+tI0Q1OGQBkYUEkcCnHn7Px/HZGg+Sa4rTg9VRP4b8=; b=Kcs7wYf8ZcEM/476x4ssWHJdy4Atjh68KeNu+iNUeixptCbUfrqwQ5bSoLqQ1Tc0mc 5E6/p1CH8HCbzST62u1qUkfQu2TiOwNrm0MnAvcT2RPzA6Ak8GXfbLxTKk0l0KKVQKTl qrm0jYKPZKDsouhxeod30gFmcdxpBxEaEG2DKwpXix4LM0am2g7yWne/hfFSLRrCpbhT G5lQQkz+hIPUxeXUP1fxdr9UbqmR/pkzzbS6Hr+xAzvkuZO4GE1sjZ+meT693mT1unbs TfByaZRX/zZl3PlylBEa/FCmO3GDscyiy8aH7h6UXiiWkQWOCk6a6ys41KV0z/vP4Rdk +ZyA== X-Gm-Message-State: APjAAAWs9bRgVlR6RSWO43LthWE88jojSfTkAM2exaa2ltlPkWYaDNsm GrSWfJgdQYOHHsC7/uye1ZfyJId5LT4= X-Google-Smtp-Source: APXvYqycaq60cJsOdTkAU6dlTdGRC5+M3wPvTU2oADAD2jKti2MVOgSlOzIYJd7xRdahfmyckjk6mQ== X-Received: by 2002:a19:2943:: with SMTP id p64mr18735911lfp.0.1556109272895; Wed, 24 Apr 2019 05:34:32 -0700 (PDT) Received: from localhost.localdomain ([5.164.240.123]) by smtp.gmail.com with ESMTPSA id t14sm3765962lji.33.2019.04.24.05.34.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 05:34:32 -0700 (PDT) From: Serge Semin To: Peter Korsgaard , Peter Rosin Cc: Serge Semin , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] i2c-mux-gpio: Create of-based GPIOs request method Date: Wed, 24 Apr 2019 15:34:14 +0300 Message-Id: <20190424123414.25311-6-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424123414.25311-1-fancer.lancer@gmail.com> References: <20190424123414.25311-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Most modern platforms provide a dts with description of the devices available in the system. It may also include i2c-gpio-mux'es. Up until now the i2c-mux-gpio driver supported it' dts nodes, but performed the GPIOs request by means of legacy GPIO API, which by design and due to being legacy doesn't know anything about of/dtb/fdt/dts stuff. It means even though the i2c-gpio-mux dts nodes are successfully mapped to the kernel i2c-mux devices, the GPIOs used for initialization are requested without OF_GPIO_* flags setup. It causes problems on the platforms which fully rely on dts and reside, for instance, i2c-gpio-muxes with active low or open drain GPIOs connected. It is fixed by implementing a dedicated method for full dts-based GPIOs requests. It is mostly similar to the platform one, but utilizes the gpiod_get_from_of_node() method to request the GPIOs. Finally the platform code i2c-gpio-mux devices are also supported. So the fallback to dtb is performed only if array with GPIOs isn't detected. Signed-off-by: Serge Semin --- drivers/i2c/muxes/i2c-mux-gpio.c | 65 ++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c index 317c019e1415..e5e10ba35ad9 100644 --- a/drivers/i2c/muxes/i2c-mux-gpio.c +++ b/drivers/i2c/muxes/i2c-mux-gpio.c @@ -65,8 +65,8 @@ static int i2c_mux_gpio_probe_dt(struct gpiomux *mux, struct device_node *np = pdev->dev.of_node; struct device_node *adapter_np, *child; struct i2c_adapter *adapter; - unsigned *values, *gpios; - int i = 0, ret; + unsigned int *values; + int i = 0; if (!np) return -ENODEV; @@ -109,24 +109,48 @@ static int i2c_mux_gpio_probe_dt(struct gpiomux *mux, return -EINVAL; } - gpios = devm_kcalloc(&pdev->dev, - mux->data.n_gpios, sizeof(*mux->data.gpios), - GFP_KERNEL); - if (!gpios) { - dev_err(&pdev->dev, "Cannot allocate gpios array"); - return -ENOMEM; - } + return 0; +} + +static int i2c_mux_gpio_request_dt(struct gpiomux *mux, + struct platform_device *pdev) +{ + struct i2c_mux_core *muxc = platform_get_drvdata(pdev); + struct device_node *np = pdev->dev.of_node; + struct i2c_adapter *root; + struct device *gpio_dev; + enum gpiod_flags dflags; + int i, ret; + + root = i2c_root_adapter(&muxc->parent->dev); for (i = 0; i < mux->data.n_gpios; i++) { - ret = of_get_named_gpio(np, "mux-gpios", i); - if (ret < 0) - return ret; - gpios[i] = ret; - } + if (mux->data.idle & (1 << i)) + dflags = GPIOD_OUT_HIGH; + else + dflags = GPIOD_OUT_LOW; + + mux->gpios[i] = gpiod_get_from_of_node(np, "mux-gpios", i, + dflags, "i2c-mux-gpio"); + if (IS_ERR(mux->gpios[i])) { + ret = PTR_ERR(mux->gpios[i]); + goto err_request_gpio; + } - mux->data.gpios = gpios; + if (!muxc->mux_locked) + continue; + + gpio_dev = &mux->gpios[i]->gdev->dev; + muxc->mux_locked = i2c_root_adapter(gpio_dev) == root; + } return 0; + +err_request_gpio: + for (i--; i >= 0; i--) + gpiod_free(mux->gpios[i]); + + return ret; } #else static int i2c_mux_gpio_probe_dt(struct gpiomux *mux, @@ -134,6 +158,12 @@ static int i2c_mux_gpio_probe_dt(struct gpiomux *mux, { return -EINVAL; } + +static int i2c_mux_gpio_request_dt(struct gpiomux *mux, + struct platform_device *pdev) +{ + return -EINVAL; +} #endif static int i2c_mux_gpio_probe_plat(struct gpiomux *mux, @@ -174,6 +204,9 @@ static int i2c_mux_gpio_request_plat(struct gpiomux *mux, struct device *gpio_dev; int i, ret; + if (!mux->data.gpios) + return -EINVAL; + root = i2c_root_adapter(&muxc->parent->dev); for (i = 0; i < mux->data.n_gpios; i++) { @@ -267,6 +300,8 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) mux->data.idle = mux->data.values[0]; ret = i2c_mux_gpio_request_plat(mux, pdev); + if (ret) + ret = i2c_mux_gpio_request_dt(mux, pdev); if (ret) goto alloc_failed;