Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp3221554ybn; Fri, 27 Sep 2019 03:05:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzM6gd+mOTmqeCm2ylkh+O+Nb53wSoJRf6E00o39dw8vW9HYHdm9PNVXoFby9sO8xYpnoT7 X-Received: by 2002:a50:918d:: with SMTP id g13mr3519237eda.64.1569578706902; Fri, 27 Sep 2019 03:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569578706; cv=none; d=google.com; s=arc-20160816; b=U2Q4i9xoxG2Q4m1lGFqITrrp2+cuI7RjO47qCtcNmp3nsSyQcFafJNQ+CvSbzeM50P k35PwcsULkjqkajmY/iN2qQbgjgpBaqxu3LK43BI8MlHSnHvNRSPEqaU7XENK1vpMMoL KEIc5KfTjr1S8DfkwPmpOi1LQslzyMvC7bbvvjGahmTw2uun5BbDorRuDyE5/Ok07c0K TzjG6xoKllLgjLVzYQPv5/ELnwKV1NS1/f2e5RofAtwk0J9qZCQmTcAZSyBxWH8Vzreb /pHPscwBDEDnW0gA8ZySCQxHwHThFOPUrNvDL1fUUEaCFjATY/jISHXM0DaPs85CK3HZ 9+tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ZemAmQEK2KpnlxqR9c883Nq57/JX1CjlB/21cdc+F7M=; b=e6zM92U/RQLNPVJZfrdFZ1KidS3DecCUv1NB8+Y+zv2/kjJGzhyCScmg80dIMI7y4h eu1yqFJ25AomqQnqV2nlqsVZ1yW8RTz+Wq+K+jqmy4O3+tTKUXIaYj7RaK/aBryDpCqM QWLhqJehes1GBN6T3PME5w8O9gmiGCGgps1n+PM247VW1mFLpvxgyU6FXnZuH8dJfunV O5bBsZvYHZNUJW1MMNkOo8Z+yGu00YAUF0Bxfv7CP8ldnvpAHQACg0j1o6mniXu8Qy4T muogdr7CFgDkbsgaundo9cB33ZWsO7mvJqGP10b+LKeUdQYX/XSN/gChpWdqxC2hW2Y2 XCPQ== 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 e23si2506601ejt.379.2019.09.27.03.04.40; Fri, 27 Sep 2019 03:05:06 -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 S1727247AbfI0KE0 (ORCPT + 99 others); Fri, 27 Sep 2019 06:04:26 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:41531 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726988AbfI0KEZ (ORCPT ); Fri, 27 Sep 2019 06:04:25 -0400 Received: from localhost.localdomain (lfbn-1-17395-211.w86-250.abo.wanadoo.fr [86.250.200.211]) (Authenticated sender: paul.kocialkowski@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 59F0724001D; Fri, 27 Sep 2019 10:04:22 +0000 (UTC) From: Paul Kocialkowski To: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Rob Herring , Mark Rutland , Lee Jones , Thomas Petazzoni , Paul Kocialkowski Subject: [PATCH v3 5/5] gpio: syscon: Add support for the Xylon LogiCVC GPIOs Date: Fri, 27 Sep 2019 12:04:07 +0200 Message-Id: <20190927100407.1863293-6-paul.kocialkowski@bootlin.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927100407.1863293-1-paul.kocialkowski@bootlin.com> References: <20190927100407.1863293-1-paul.kocialkowski@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The LogiCVC display hardware block comes with GPIO capabilities that must be exposed separately from the main driver (as GPIOs) for use with regulators and panels. A syscon is used to share the same regmap across the two drivers. Since the GPIO capabilities are pretty simple, add them to the syscon GPIO driver. Signed-off-by: Paul Kocialkowski --- drivers/gpio/gpio-syscon.c | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/drivers/gpio/gpio-syscon.c b/drivers/gpio/gpio-syscon.c index 05c537ed73f1..cdcb913b8f0c 100644 --- a/drivers/gpio/gpio-syscon.c +++ b/drivers/gpio/gpio-syscon.c @@ -190,6 +190,70 @@ static const struct syscon_gpio_data keystone_dsp_gpio = { .set = keystone_gpio_set, }; +#define LOGICVC_CTRL_REG 0x40 +#define LOGICVC_CTRL_GPIO_SHIFT 11 +#define LOGICVC_CTRL_GPIO_BITS 5 + +#define LOGICVC_POWER_CTRL_REG 0x78 +#define LOGICVC_POWER_CTRL_GPIO_SHIFT 0 +#define LOGICVC_POWER_CTRL_GPIO_BITS 4 + +static void logicvc_gpio_offset(struct syscon_gpio_priv *priv, + unsigned offset, unsigned int *reg, + unsigned int *bit) +{ + if (offset >= LOGICVC_CTRL_GPIO_BITS) { + *reg = LOGICVC_POWER_CTRL_REG; + + /* To the (virtual) power ctrl offset. */ + offset -= LOGICVC_CTRL_GPIO_BITS; + /* To the actual bit offset in reg. */ + offset += LOGICVC_POWER_CTRL_GPIO_SHIFT; + } else { + *reg = LOGICVC_CTRL_REG; + + /* To the actual bit offset in reg. */ + offset += LOGICVC_CTRL_GPIO_SHIFT; + } + + *bit = BIT(offset); +} + +static int logicvc_gpio_get(struct gpio_chip *chip, unsigned offset) +{ + struct syscon_gpio_priv *priv = gpiochip_get_data(chip); + unsigned int reg; + unsigned int bit; + unsigned int value; + int ret; + + logicvc_gpio_offset(priv, offset, ®, &bit); + + ret = regmap_read(priv->syscon, reg, &value); + if (ret) + return ret; + + return !!(value & bit); +} + +static void logicvc_gpio_set(struct gpio_chip *chip, unsigned offset, int val) +{ + struct syscon_gpio_priv *priv = gpiochip_get_data(chip); + unsigned int reg; + unsigned int bit; + + logicvc_gpio_offset(priv, offset, ®, &bit); + + regmap_update_bits(priv->syscon, reg, bit, val ? bit : 0); +} + +static const struct syscon_gpio_data logicvc_gpio = { + .flags = GPIO_SYSCON_FEAT_OUT, + .bit_count = LOGICVC_CTRL_GPIO_BITS + LOGICVC_POWER_CTRL_GPIO_BITS, + .get = logicvc_gpio_get, + .set = logicvc_gpio_set, +}; + static const struct of_device_id syscon_gpio_ids[] = { { .compatible = "cirrus,ep7209-mctrl-gpio", @@ -203,6 +267,10 @@ static const struct of_device_id syscon_gpio_ids[] = { .compatible = "rockchip,rk3328-grf-gpio", .data = &rockchip_rk3328_gpio_mute, }, + { + .compatible = "xylon,logicvc-3.02.a-gpio", + .data = &logicvc_gpio, + }, { } }; MODULE_DEVICE_TABLE(of, syscon_gpio_ids); -- 2.23.0