Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp649246pxb; Tue, 2 Feb 2021 14:19:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLFX3p0Fg+HYV1krFM+Q2YMDUUk+w2cUu6PyF4wKxyGpl+lxtDgJ4MrL97Df+Df3RUCv08 X-Received: by 2002:a17:906:149a:: with SMTP id x26mr148942ejc.486.1612304397193; Tue, 02 Feb 2021 14:19:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612304397; cv=none; d=google.com; s=arc-20160816; b=dCWGkSpUzMQATTxG6BRAfza66dfjYgpZ/XP9pffVmNF771NI/8rG2XhGACacTghui/ LQx3ciQ3BGBESI7ZdqmgcGunQjmRYiBhU/Y9q+2uGyDhPEyY/SiYycD/bhg/0DgwA48J B1O3fWTJygKq8icoddAKtzg0Vg7ReFQBSwkFP9RtBAc+vg2sHret/XfbaOSzkuVWjXv6 fz77shknNiz1PNYFFJmrb6ydnWyraMB45T+QNgMfxzC4FWHTnK4YXa3pWCeSC8G9leFN ksK30dM/ZyAey1vmjIdD9k/klhAlxOcxzWJnTHK5VVz1TjbUC2wF5hAvB5PIcKcahxb4 yKhw== 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=NL/I/BuRrrACgurhUs3cVKRwX323hl2f+ZOCamuPdHc=; b=w/RFDCWGIkfldEczVcw88wmtXXJRdurlsb72aY64hyYsytMdyYhexjZVLzMj5fvoth wgdSIiIVNe6SqIdveIw7VRHVY3O6CbYqCBXhPSLgnIZ92UBR2QEbFzGybcjjj85E7BYn +wZQnfogHhooIKLz9GhkBopRsrSKHi7n0pSLqqB4sjCG5VjY/plsABb2xA0u1u/o5lss YZnnDB/aQV4sK1SG+iVtiQ8dUO+XdSOGKJKvm/reg7nQi63MncU6OYVW4M7i0DGv/iax 67IxwQErcnRIDt6mJbh8wGVvY2E6qO9nuoVqwSUadDgPjtbBCduLjU++pWa9nzWw52rD eAvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q4MrU9ZA; 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 de20si100395ejc.753.2021.02.02.14.19.22; Tue, 02 Feb 2021 14:19:57 -0800 (PST) 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=Q4MrU9ZA; 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 S233622AbhBBOGN (ORCPT + 99 others); Tue, 2 Feb 2021 09:06:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233501AbhBBN60 (ORCPT ); Tue, 2 Feb 2021 08:58:26 -0500 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1658C061786 for ; Tue, 2 Feb 2021 05:57:43 -0800 (PST) Received: by mail-lj1-x22f.google.com with SMTP id b20so16202434ljo.1 for ; Tue, 02 Feb 2021 05:57:43 -0800 (PST) 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=NL/I/BuRrrACgurhUs3cVKRwX323hl2f+ZOCamuPdHc=; b=Q4MrU9ZAwKq4E1DSZLMnCoc4OEZF8kZhBb2pF0FJiU3Pi5Qclgben0NCZKzz5YtTJB 9a4T0NrurxbKFRVHL6nRf6cayFXco1vtMTAguuMELuH9WCvLtWBfUr4o74pyHto/FpQ7 SkCuriyomu1Wkgd7fCSuzlV8RxSFtLhU1Z9Fq4n5J0g5fBIJTV0FJ1FB9uBjVC43z07k iELYQJGHgpO1v5aWng7dMxzibJvi7M5nng5stkf/znfHZNjSLIThrhjx7F8V3iowvbhj yyGTbdZNBUCbVz/fJi4R9U4EL1R9nfq16BAxk7QsmXSvwDk22WaWUMFxetzRVfVAzlgV yG2g== 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=NL/I/BuRrrACgurhUs3cVKRwX323hl2f+ZOCamuPdHc=; b=Kv+JAiZwQp/fgxVhm7yGyRaTj8Izki2IMJrBYgyMh+t++6eI55DLHDamgYIhWpjkrB 4yAldVCOTweOOraiKOW6sP7c9m+jQ4PqR9T4Y8wc6GqTSOuzQyxRffxAuEx/7wFsNwBC 5jM5bhJCUspNhveG4NYIBbSh7rfzQlPaR5/EyEul/cd379BfMAHQJg1n1XKCNfKCxqi7 6cPKHqWzSoS7vmSw6AqRvNrT1v9PeraYR0xIsy4dLNMIXn7dlEaU2hYn6uPZFI44Z1pH BAum4kk4CwsfjD2j30ETIW2fZPYq2+kvNuJy3bKiqfwKBmMnh3dYoa576sUWhyOugFuP Yt7w== X-Gm-Message-State: AOAM53386QcwTmKOhbnypK378haR7X4aMYbZtahOi/xpjbgZGkI476/Y NO2Ck5tx+9P6bFubgHx1Ar8JPhuSJnDmNKJlxT9t9w== X-Received: by 2002:a2e:8ec3:: with SMTP id e3mr12733519ljl.467.1612274262224; Tue, 02 Feb 2021 05:57:42 -0800 (PST) MIME-Version: 1.0 References: <20210128153601.153126-1-alban.bedel@aerq.com> In-Reply-To: <20210128153601.153126-1-alban.bedel@aerq.com> From: Linus Walleij Date: Tue, 2 Feb 2021 14:57:31 +0100 Message-ID: Subject: Re: [PATCH] gpio: pca953x: add support for open drain pins on PCAL6524 To: Alban Bedel Cc: Bartosz Golaszewski , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 28, 2021 at 4:36 PM Alban Bedel wrote: > From a quick glance at various datasheet the PCAL6524 seems to be the > only chip in this familly that support setting the drive mode of > single pins. Other chips either don't support it at all, or can only > set the drive mode of whole banks, which doesn't map to the GPIO API. > > Add a new flag, PCAL6524, to mark chips that have the extra registers > needed for this feature. Then mark the needed register banks as > readable and writable, here we don't set OUT_CONF as writable, > although it is, as we only need to read it. Finally add a function > that configure the OUT_INDCONF register when the GPIO API set the > drive mode of the pins. > > Signed-off-by: Alban Bedel Thats's nice! > + * Output port configuration 0x40 + 7 * bank_size R > + * > + * - PCAL6524 with individual pin configuration > + * Individual pin output config 0x40 + 12 * bank_size RW So this will become 0x70? It's a bit hard for me this weird register layout... > +static int pcal6524_gpio_set_drive_mode(struct pca953x_chip *chip, > + unsigned int offset, > + unsigned long config) > +{ > + u8 out_conf_reg = pca953x_recalc_addr( > + chip, PCAL953X_OUT_CONF, 0); > + u8 out_indconf_reg = pca953x_recalc_addr( > + chip, PCAL6524_OUT_INDCONF, offset); > + u8 mask = BIT(offset % BANK_SZ), val; Split to two variable declarations please, this is hard to read. > + unsigned int out_conf; > + int ret; So we set mask to the bit index for the line we want to affect. > + if (config == PIN_CONFIG_DRIVE_OPEN_DRAIN) > + val = mask; > + else if (config == PIN_CONFIG_DRIVE_PUSH_PULL) > + val = 0; > + else > + return -EINVAL; And this makes sense, we set it to 1 to enable open drain. > + /* Invert the value if ODENn is set */ > + ret = regmap_read(chip->regmap, out_conf_reg, &out_conf); > + if (ret) > + goto exit; > + if (out_conf & BIT(offset / BANK_SZ)) I suppose this could be written if (out_conf & mask)? > + val ^= mask; Invert? Why? The datasheet says: "If the ODENx bit is set at logic 0 (push-pull), any bit set to logic 1 in the IOCRx register will reverse the output state of that pin only to open-drain. When ODENx bit is set at logic 1 (open-drain), a logic 1 in IOCRx will set that pin to push-pull." So your logic is accounting for the fact that someone go and set one of the bits in ODENx to 1, but aren't they all by default set to zero (or should be programmed by the driver to zero) so that you can control open drain individually here by simply setting the corresponding bit to 1 for open drain and 0 for push-pull? > + /* Configure the drive mode */ > + ret = regmap_write_bits(chip->regmap, out_indconf_reg, mask, val); Yours, Linus Walleij