Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp227981imm; Thu, 10 May 2018 19:18:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrVRFjSs0lb/6yf1TXsuRR/S+V/64hyRTKUER0v+Ab3fxtJEych8EpQOoSFH4EA9SR5zbar X-Received: by 2002:a62:8d51:: with SMTP id z78-v6mr3575270pfd.69.1526005091036; Thu, 10 May 2018 19:18:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526005091; cv=none; d=google.com; s=arc-20160816; b=IbwE5Cm2+gB8rrenVJ5qeNHXRzkxAKe/XBX6V5fciIiMUtnuxQsj5Hy8ZUd/ci6NTt i2AzU6PCYNdS8zz4grb27spO0e24TxansUCvkPEg+KK2ms4tHkR+E+BG+5D9tIpmp2Vx sVfDVffbrO1eMq9bFTFO3LMpKzCoPSrTwTFpZ06udycFpwS4KvOOw0aou+I4iHe4Frw9 yX23CKuza6Af4okmiBPJlwapSlB9kIvZfIUCN8GBalbEuOWmO7esJ4TZG/w8KO7RmwuO FSehUMj5NnpML4yX4EApwgFtgfm1ZJtOk8zIS3Ea204CXvkhKFw8LSuGxmxpchtmcYHT AXjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=aYOmV/umwb/YFPwdkGs3JTRZxzuv5mFVu7GfHMXkrao=; b=Jli5XPJDVJSZ8i9ehBwix0n+Sc5BefGPWzLo1dAgL47sU+q/gXwtemxSqEEPb0Tifk qzvpcagwL6yX0fhdPEoeqEdfNzU/mKMEiULpPZwTWpDl0mvNzz6xMqsrNv/xLoECG0ug tKh8ihPjoZb3iKAOIVkR0V8fGbHiC2P2+xVqy/CMih1L0+eIaZXxM2fYrljRlW9p8+LW myB7azuCQ4bEuz4ejHKT6Y+fsug/JMgQJZYd+gR9NHgr7qTDK0nLSDoBtU1/3a7z+mfK 6OOEzoh3MfBDR1JE4UOXBVM6UKZ2HtXTwYiCeu3D2zymIzMWuoFDA0PnNvEvLE6rZzPg FN9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d15-v6si2113037plj.186.2018.05.10.19.17.56; Thu, 10 May 2018 19:18:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752043AbeEKCRq (ORCPT + 99 others); Thu, 10 May 2018 22:17:46 -0400 Received: from regular1.263xmail.com ([211.150.99.138]:54296 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750798AbeEKCRo (ORCPT ); Thu, 10 May 2018 22:17:44 -0400 Received: from djw?t-chip.com.cn (unknown [192.168.167.242]) by regular1.263xmail.com (Postfix) with ESMTP id 94EC57A2D; Fri, 11 May 2018 10:17:34 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from [168.168.100.35] (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id B99E13B0; Fri, 11 May 2018 10:17:14 +0800 (CST) X-IP-DOMAINF: 1 X-RL-SENDER: djw@t-chip.com.cn X-FST-TO: linux-arm-kernel@lists.infradead.org X-SENDER-IP: 183.57.25.242 X-LOGIN-NAME: djw@t-chip.com.cn X-UNIQUE-TAG: <932fd55ab982b0020d4b4d1c2c8187cb> X-ATTACHMENT-NUM: 0 X-SENDER: djw@t-chip.com.cn X-DNS-TYPE: 0 Received: from [168.168.100.35] (unknown [183.57.25.242]) by smtp.263.net (Postfix) whith ESMTP id 14350C464PA; Fri, 11 May 2018 10:17:29 +0800 (CST) Subject: Re: [PATCH v1 2/5] gpio: syscon: Add gpio-syscon for rockchip To: Robin Murphy , linux-rockchip@lists.infradead.org Cc: Mark Rutland , devicetree@vger.kernel.org, Wayne Chou , Heiko Stuebner , Linus Walleij , linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Rob Herring , linux-arm-kernel@lists.infradead.org References: <1525943800-14095-1-git-send-email-djw@t-chip.com.cn> <1525943800-14095-3-git-send-email-djw@t-chip.com.cn> From: Levin Du Message-ID: Date: Fri, 11 May 2018 10:16:48 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-05-10 10:56 PM, Robin Murphy wrote: > >> diff --git >> a/Documentation/devicetree/bindings/gpio/rockchip,gpio-syscon.txt >> b/Documentation/devicetree/bindings/gpio/rockchip,gpio-syscon.txt >> new file mode 100644 >> index 0000000..e4c1650 >> --- /dev/null >> +++ b/Documentation/devicetree/bindings/gpio/rockchip,gpio-syscon.txt >> @@ -0,0 +1,41 @@ >> +* Rockchip GPIO support for GRF_SOC_CON registers >> + >> +Required properties: >> +- compatible: Should contain "rockchip,gpio-syscon". >> +- gpio-controller: Marks the device node as a gpio controller. >> +- #gpio-cells: Should be two. The first cell is the pin number and > > I would suggest s/pin number/bit number in the associated GRF > register/ here. At least in this RK3328 case there's only one pin, > which isn't numbered, and if you naively considered it pin 0 of this > 'bank' you'd already have the wrong number. Since we're dealing with > the "random SoC-specific controls" region of the GRF as opposed to the > relatively-consistent and organised pinmux parts, I don't think we > should rely on any assumptions about how things are laid out. > > I was initially going to suggest a more specific compatible string as > well, but on reflection I think the generic "rockchip,gpio-syscon" for > basic "flip this single GRF bit" functionality actually is the right > way to go. In the specific RK3328 GPIO_MUTE case, there look to be 4 > bits in total related to this pin - the enable, value, and some pull > controls (which I assume apply when the output is disabled) - if at > some point in future we *did* want to start explicitly controlling the > rest of them too, then would be a good time to define a separate > "rockchip,rk3328-gpio-mute" binding (and probably a dedicated driver) > for that specialised functionality, independently of this basic one. > Good point! I'll fix the doc. >>   +static void rockchip_gpio_set(struct gpio_chip *chip, unsigned int >> offset, >> +                  int val) >> +{ >> +    struct syscon_gpio_priv *priv = gpiochip_get_data(chip); >> +    unsigned int offs; >> +    u8 bit; >> +    u32 data; >> +    int ret; >> + >> +    offs = priv->dreg_offset + priv->data->dat_bit_offset + offset; > > data->dat_bit_offset is always 0 here, but given that wrapping large > offsets to successive GRF registers doesn't make sense (and wouldn't > work anyway with this arithmetic) I don't think you even need this > calculation of offs at all... > >> +    bit = offs % SYSCON_REG_BITS; > > ... since it would suffice to use offset here... > >> +    data = (val ? BIT(bit) : 0) | BIT(bit + 16); >> +    ret = regmap_write(priv->syscon, >> +               (offs / SYSCON_REG_BITS) * SYSCON_REG_SIZE, > > ... and priv->dreg_offset here. > rockchip_gpio_set() follows the conventional offset handling in the gpio-syscon driver. dreg_offset will get multiplied by 8 (dreg_offset <<= 3) in syscon_gpio_probe(). I'm not sure if this needs to simplify, or stay the same as others. Thanks Levin