Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1241631pxj; Fri, 18 Jun 2021 02:48:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEV5gWbuS8NVoyrMtFbgK/sUM7XM2gV6/FYM4kVWiRy1DVUzVRWmqAtc7qEkxZQdCVq3sM X-Received: by 2002:a05:6402:1cad:: with SMTP id cz13mr3735874edb.67.1624009737179; Fri, 18 Jun 2021 02:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624009737; cv=none; d=google.com; s=arc-20160816; b=OlH1RiU/Z9FD2EYsZAca0OF0dicyh/rn+wqtiWD1bH+GZIRk6D/mMmhmE0bquvH4/d eEwU4U3t3HI7PRLn84Iuk2bA1wQyBova6ahx1a/53DrXKf5PjxaFrwPP0wLjTeX+UZS8 2iQf6X9UeDg36i/D24ruLkiccor8pNsMNk9rsArGIbIKhTkr/Dgs8mHEYDgJAwDd+roQ p4KFxN219WollKvZGeBC8ZN6AruujCFlyb9oVVtbIklrWDGLm1z7EKR9oNu9oIaPavWN 8Vc8hhtAm8/klVGsnAN4/NePlMywTrh2EQM5qeD4ZK+3vixuHJ1VcgWRSupGaVXEaTXL oaSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8MpyH2W/Qi16vZF1RutDfX/LXWayA+uMuphu1a4gDY8=; b=p16JPCEhADBsxJcvBmWyA3P+y/dIkG8BPauxC8fmBqaiximiy3b2/HgOvDtj4WLD3A C8nyKso4iA1EBcEzhjcT/f+4dF+Tbk5eji32vFX6olYt4GYzLUgGA/jQ13+TPNagoSbi AVnsjPYrGC8t4S14SCM3KNrX9dEEd5i6uRZPDNWHQAD3DPxbVsyMckqNC1ZJdb+P2Ic2 NrMYcEgYlzEsCiik19oU9VBJXzLVGg13mVSGTfB2F9YQi3xXCPeXo2fA0bfgTArnHhvj 9S7kg+OOh3Hkfmkio2lh3yJIz3Zow4WefUf6YLLoZKAgowznS+BLcshr4WnA+7wYvwst bpZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WS97S26s; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gf1si2019399ejb.318.2021.06.18.02.48.34; Fri, 18 Jun 2021 02:48:57 -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=@linaro.org header.s=google header.b=WS97S26s; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231305AbhFRJqV (ORCPT + 99 others); Fri, 18 Jun 2021 05:46:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231436AbhFRJqT (ORCPT ); Fri, 18 Jun 2021 05:46:19 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24A99C061760 for ; Fri, 18 Jun 2021 02:44:08 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id bp38so15750167lfb.0 for ; Fri, 18 Jun 2021 02:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8MpyH2W/Qi16vZF1RutDfX/LXWayA+uMuphu1a4gDY8=; b=WS97S26sHLsjWjnE4s2jX0/ynLhPoe0+VUb0hrL9k3lZ0LxP5jHd7PkAhea6aF429B Y+qwux8Btsy6lCFc/+i0aB6x+MGHD46ahPFfVf9Kn937OEb7QczXPOCIZ5HHNUyUf3It eRH8Rij5W3fCdq0jCzeEpTpd+D1wycYbbYve+Z6hubf30WMg4FgSff9vD2mA7cJkyhFf 5lWW9sZtAOSfGYqO0hAZaCntF5/qPm97kpkeIYlGl3o7puopBYT1CW/z6FTdet91yO38 sBphYsO/Ty7OXJY8TkssfooKxvef+GmimD8/2MjK1tXm5GRKIrMxXyV0BQP8arKq2Pft ZlIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8MpyH2W/Qi16vZF1RutDfX/LXWayA+uMuphu1a4gDY8=; b=TqRuKuSEVyGQROd3BE1pXioOOy1FGEGxZdvgKu4Gm73IVk7l2va/6niv22us4Ijr2w NWZww8uV4A5r6TkDS0ZmX8I4We0i6+Csfa+BHE5Xd06EnqXwciX0gYSiJE/iUjGSY5rg ONYCd77UGTFu/poM7YSLILq/5P43DVmNNOR0nic2CtMGDXKhdPj4VhW/mns2wcSHTDXw /bFGoviw94OBDQgWS2V/xHhT/k4TywsqJTIuCAGkzajfoPn+K7Wh1HLc6jpJI+vFUHdm VfR2vtYgugxf+bbkS1xEelqMUKzWpLLPBaF/YNK+rlT8o/ExbnPfGoq2mEEky3ATcHti waHw== X-Gm-Message-State: AOAM5328qyFVU7ZAr5l8UqCGwjvKfgxxECm1uoMUNJKd30TgdRWmEcmf BEXL/QeffNIcRxvrQFznlyV1GnRtbwjXU9HF+SL43A== X-Received: by 2002:a05:6512:3241:: with SMTP id c1mr2595058lfr.29.1624009446392; Fri, 18 Jun 2021 02:44:06 -0700 (PDT) MIME-Version: 1.0 References: <20210615080553.2021061-1-piyush.mehta@xilinx.com> <20210615080553.2021061-3-piyush.mehta@xilinx.com> In-Reply-To: <20210615080553.2021061-3-piyush.mehta@xilinx.com> From: Linus Walleij Date: Fri, 18 Jun 2021 11:43:55 +0200 Message-ID: Subject: Re: [PATCH 2/2] gpio: modepin: Add driver support for modepin GPIO controller To: Piyush Mehta Cc: Bartosz Golaszewski , Rob Herring , "open list:GPIO SUBSYSTEM" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , linux-kernel , Linux ARM , git , Srinivas Goud , Michal Simek Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Piyush! thanks for your patch! On Tue, Jun 15, 2021 at 10:06 AM Piyush Mehta wrote: > This patch adds support for the mode pin GPIO controller. GPIO Modepin > driver set and get the value and status of the PS_MODE pin, based on > device-tree pin configuration. These 4-bits boot-mode pins are dedicated > configurable as input/output. After the stabilization of the system, > these mode pins are sampled. > > Signed-off-by: Piyush Mehta OK, sounds interesting! > +#include I think I saw somewhere that this is not needed anymore, check if you need it. > +#define GET_OUTEN_PIN(pin) (1U << (pin)) Delete this macro and just use BIT(pin) inline. #include > +static int modepin_gpio_get_value(struct gpio_chip *chip, unsigned int pin) > +{ > + u32 out_en; > + u32 regval = 0; > + int ret; > + > + out_en = GET_OUTEN_PIN(pin); Drop this and out_en > + ret = zynqmp_pm_bootmode_read(®val); > + if (ret) { > + pr_err("modepin: get value err %d\n", ret); > + return ret; > + } > + > + return (out_en & (regval >> 8U)) ? 1 : 0; return !!(regval & BIT(pin + 8)); should work and is easier to read IMO. We just check the right bit immediately. > +static void modepin_gpio_set_value(struct gpio_chip *chip, unsigned int pin, > + int state) > +{ > + u32 out_en; > + u32 bootpin_val = 0; > + int ret; > + > + out_en = GET_OUTEN_PIN(pin); Skip this helper variable. > + state = state != 0 ? out_en : 0; Uh that is really hard to read and modified a parameter. Skip that too. > + bootpin_val = (state << (8U)) | out_en; What you want is mask and set. bootpin_val = BIT(pin + 8); > + /* Configure bootpin value */ > + ret = zynqmp_pm_bootmode_write(bootpin_val); This just looks weird. Why are you not reading the value first since you are using read/modify/write? I *think* you want to do this: ret = zynqmp_pm_bootmode_read(&val); if (ret) /* error handling */ if (state) val |= BIT(pin + 8); else val &= ~BIT(pin + 8); ret = zynqmp_pm_bootmode_write(val); if (ret) /* error handling */ > +/* > + * modepin_gpio_dir_in - Set the direction of the specified GPIO pin as input > + * @chip: gpio_chip instance to be worked on > + * @pin: gpio pin number within the device > + * > + * Return: 0 always > + */ > +static int modepin_gpio_dir_in(struct gpio_chip *chip, unsigned int pin) > +{ > + return 0; > +} I think you said this was configurable in the commit message. Use the define GPIO_LINE_DIRECTION_OUT rather than 0. > +static int modepin_gpio_dir_out(struct gpio_chip *chip, unsigned int pin, > + int state) > +{ > + return 0; > +} Configurable? > + status = devm_gpiochip_add_data(&pdev->dev, chip, chip); > + if (status) > + dev_err_probe(&pdev->dev, status, > + "Failed to add GPIO chip\n"); just return dev_err_probe(...) Yours, Linus Walleij