From patchwork Thu May 6 16:25:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis K X-Patchwork-Id: 1475162 X-Patchwork-Delegate: koen.vandeputte@ncentric.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=XddP6ZOF; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Z1sOlZNh; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FbfCZ6dGKz9sCD for ; Fri, 7 May 2021 02:28:42 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8x3TqS36aKbdhvZt9y6+1ilC+OnbTmnnNU9ufqRQBqY=; b=XddP6ZOFpkSE7YAeql4e6cFj2 HCYhbiLvvDg1Td2s70bH6VOzuPTKvu2sxdIn5kG9P+1SN36+cBMekrwN39kCTlDAr2LDZq7lByljS u9AKK/8+3Wh9tg0unerQDNmZP+ZGC+7qz6nEMPxDDrnnyfa5Exa6P7ifqk+QqcJuBXlWVJtkizhoj MBc+T4tjmaCzIaafX4liGHtU6pRF/dg25vH99kEY0sEkXURLufoQ5R97JxAB4xT8bxtEXfguFnZpL W2xb+eQn+J3M4a8SuFG9vt4GocLm94yp/Fx26m1aJOXjcF52BrhXyeUMp6wGZhxsnGRBOCbUbPhwt 1BAdR4MEg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1legqG-004np8-0B; Thu, 06 May 2021 16:27:12 +0000 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1legpv-004ngj-MI for openwrt-devel@lists.openwrt.org; Thu, 06 May 2021 16:26:53 +0000 Received: by mail-lf1-x12b.google.com with SMTP id c3so8630100lfs.7 for ; Thu, 06 May 2021 09:26:51 -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=L+ji14hhYmE0QlbKae1im69KswjiKvkDdq5uQJnGnfM=; b=Z1sOlZNhqNYEqdDQvIpa6vo7MeWqGOmIMb2HUqW6ugMjjCY3vjv3Gog/YadmzDRIWw v/9Ss1wI9KALkGTgNu13RNkjjkbhqOZqbAhvDNNpej3AsswxM1rvbUGZaR/jLCPbrVVq fSPHge5D+M6v6FnK3SHV8vp4N5Hivi5UZHt1Ll3q7opjiZr3zr5bq7N6h6tB9OtT4fOD wivwOwlIp1i1UyjIb3mhiOOMbUxWFYY/0Ti0BJBAKD9P97DwhF+UPXSeoOGOO7aZQ2dZ AgPsSb8MHXisc9fvxOVio4YfBWxwX3uf8CDjm8+0vP/UTVeclPre+d5QyExnFeKvGG46 JOFg== 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=L+ji14hhYmE0QlbKae1im69KswjiKvkDdq5uQJnGnfM=; b=o7est4JCEsE1DhLXVjQFFW1D2dhOMKfal5KKoNr5CixQyXvnO71VQiFGkhH20fTOcc BLsg2BdFJY5wGss4xKVApUtfKfgte1efJBRkhTrAxUvysf2jQvzjK+wpRElU8O4Oi+JV 6p8ER7ITbXfY61n4y6XmHf3K1/gHEbp72uaNjP90b069U/C6cY6XT9Pf6C2powVXXAS1 RXM0pAZLZy+ZutMfA6CsYHDeyxkgdpJlJHKuIcTXMEw3EYry48/6pX+/gDntzf0+RrmT WKpbCXTrsRCnx6OwWrd5JsMSFKdtmBEd7dcLLf9H5n4szCUiUe6bvEuI8aYCV/XkYP72 KSmw== X-Gm-Message-State: AOAM531fey1Xm+WSLYEHMJiqEsX/Q802F22F1n8TV6aAUw6tFFXD1fji 5E0AtxmpOqEcXYITr2ppEfT29y76Cy4= X-Google-Smtp-Source: ABdhPJw2HQ7EEX3JdcLP0Q6fFYtij0IvJoAxEt0xo/BcwjHV/Y1sqobu1DL4rEyOQgv5zJ2xWHxJRw== X-Received: by 2002:a05:6512:3619:: with SMTP id f25mr1582877lfs.399.1620318409030; Thu, 06 May 2021 09:26:49 -0700 (PDT) Received: from kalashnikov.user.kdf.lan ([89.18.140.18]) by smtp.gmail.com with ESMTPSA id i1sm787164lfe.53.2021.05.06.09.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 09:26:48 -0700 (PDT) From: Denis Kalashnikov To: openwrt-devel@lists.openwrt.org Cc: Gabor Juhos Subject: [PATCH 2/4] ath79: add GPIO-latch driver for Mikrotik RB91xG Date: Thu, 6 May 2021 19:25:12 +0300 Message-Id: <20210506162514.5913-3-denis281089@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210506162514.5913-1-denis281089@gmail.com> References: <20210506162514.5913-1-denis281089@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210506_172652_017377_577B8636 X-CRM114-Status: GOOD ( 21.12 ) X-Spam-Score: 0.1 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This driver exports GPIO lines on the latch that are not used for NAND control lines (but used for data lines). It doesn't request byself SoC gpio lines and set them through API provided by rb91x-ngl. [...] Content analysis details: (0.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:12b listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [denis281089[at]gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [denis281089[at]gmail.com] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This driver exports GPIO lines on the latch that are not used for NAND control lines (but used for data lines). It doesn't request byself SoC gpio lines and set them through API provided by rb91x-ngl. Exported lines are used for power LED, user LED and nCS of the Shift Register. Signed-off-by: Denis Kalashnikov --- .../files/drivers/gpio/gpio-latch-rb91x.c | 127 ++++++++++++++++++ target/linux/ath79/mikrotik/config-default | 1 + .../patches-5.4/939-mikrotik-rb91x.patch | 23 ++++ 3 files changed, 151 insertions(+) create mode 100644 target/linux/ath79/files/drivers/gpio/gpio-latch-rb91x.c diff --git a/target/linux/ath79/files/drivers/gpio/gpio-latch-rb91x.c b/target/linux/ath79/files/drivers/gpio/gpio-latch-rb91x.c new file mode 100644 index 0000000000..f1ed8ebc96 --- /dev/null +++ b/target/linux/ath79/files/drivers/gpio/gpio-latch-rb91x.c @@ -0,0 +1,127 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Driver of GPIO controller on a 8-bit NAND latch (LVC573) on MikroTik RB91x. + * + * Copyright (C) 2021 Denis Kalashnikov + */ + +#include +#include +#include +#include +#include + +#include + +#define DRIVER_NAME "rb91x-gpio-latch" + +static int get(struct gpio_chip *gc, unsigned offset) +{ + return -ENOSYS; +} + +static void set(struct gpio_chip *gc, unsigned offset, int value) +{ + struct rb91x_ngl *ngl = gpiochip_get_data(gc); + + ngl->latch_gpio_set_value(ngl, offset, value); +} + +static int direction_input(struct gpio_chip *gc, unsigned offset) +{ + return -ENOSYS; +} + +static int direction_output(struct gpio_chip *gc, unsigned offset, int value) +{ + struct rb91x_ngl *ngl = gpiochip_get_data(gc); + + ngl->latch_gpio_set_value(ngl, offset, value); + + return 0; +} + +static int probe(struct platform_device *pdev) +{ + struct gpio_chip *gc; + struct device_node *of_node = pdev->dev.of_node; + struct device *dev = &pdev->dev, *parent = pdev->dev.parent; + struct rb91x_ngl *ngl; + int ret; + u32 val; + + pr_info(DRIVER_NAME " driver probe\n"); + + if (!parent) + return -ENODEV; + + gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); + if (!gc) + return -ENOMEM; + + /* + ret = of_property_read_u32(of_node, "base", &val); + if (ret < 0) { + dev_err(dev, "Could not read required 'base' property\n"); + return -EINVAL; + } + pr_info(DRIVER_NAME ": base = %d\n", val); + gc->base = val; + */ + gc->base = -1; /* Request dynamic allocation */ + + ngl = dev_get_drvdata(parent); + if (!ngl) { + pr_err(DRIVER_NAME " ngl is null\n"); + return -EINVAL; + } + + gc->label = DRIVER_NAME; + gc->parent = dev; + gc->can_sleep = true; + gc->ngpio = ngl->latch_gpios_count(ngl); + gc->get = get; + gc->set = set; + gc->direction_input = direction_input, + gc->direction_output = direction_output; + gc->of_node = of_node; + + platform_set_drvdata(pdev, gc); + + ret = gpiochip_add_data(gc, ngl); + if (ret) { + pr_err(DRIVER_NAME ": failed to add gpio chip: %d\n", ret); + return ret; + } + + return 0; +} + +static int remove(struct platform_device *pdev) +{ + gpiochip_remove(platform_get_drvdata(pdev)); + return 0; +} + +static const struct of_device_id match[] = { + { .compatible = "mikrotik," DRIVER_NAME }, + {}, +}; + +MODULE_DEVICE_TABLE(of, match); + +static struct platform_driver rb91x_gpio_latch_driver = { + .probe = probe, + .remove = remove, + .driver = { + .name = DRIVER_NAME, + .owner = THIS_MODULE, + .of_match_table = match, + }, +}; + +module_platform_driver(rb91x_gpio_latch_driver); + +MODULE_DESCRIPTION("Driver for GPIO on MikroTik RB91x NAND latch"); +MODULE_AUTHOR("Denis Kalashnikov "); +MODULE_LICENSE("GPL v2"); diff --git a/target/linux/ath79/mikrotik/config-default b/target/linux/ath79/mikrotik/config-default index 67c980a491..92b7824eba 100644 --- a/target/linux/ath79/mikrotik/config-default +++ b/target/linux/ath79/mikrotik/config-default @@ -1,6 +1,7 @@ CONFIG_CRC16=y CONFIG_CRYPTO_DEFLATE=y CONFIG_GPIO_LATCH=y +CONFIG_GPIO_LATCH_RB91X=y CONFIG_GPIO_RB4XX=y CONFIG_GPIO_WATCHDOG=y CONFIG_GPIO_WATCHDOG_ARCH_INITCALL=y diff --git a/target/linux/ath79/patches-5.4/939-mikrotik-rb91x.patch b/target/linux/ath79/patches-5.4/939-mikrotik-rb91x.patch index a85db0892c..f2135d486b 100644 --- a/target/linux/ath79/patches-5.4/939-mikrotik-rb91x.patch +++ b/target/linux/ath79/patches-5.4/939-mikrotik-rb91x.patch @@ -19,3 +19,26 @@ obj-$(CONFIG_MFD_RB4XX_CPLD) += rb4xx-cpld.o + +obj-$(CONFIG_MFD_RB91X_NGL) += rb91x-ngl.o +--- a/drivers/gpio/Kconfig ++++ b/drivers/gpio/Kconfig +@@ -130,6 +130,10 @@ config GPIO_ATH79 + Select this option to enable GPIO driver for + Atheros AR71XX/AR724X/AR913X SoC devices. + ++config GPIO_LATCH_RB91X ++ tristate "Mikrotik RB91X GPIO latch driver" ++ depends on MFD_RB91X_NGL ++ + config GPIO_RASPBERRYPI_EXP + tristate "Raspberry Pi 3 GPIO Expander" + default RASPBERRYPI_FIRMWARE +--- a/drivers/gpio/Makefile ++++ b/drivers/gpio/Makefile +@@ -67,6 +67,7 @@ obj-$(CONFIG_GPIO_IT87) += gpio-it87.o + obj-$(CONFIG_GPIO_IXP4XX) += gpio-ixp4xx.o + obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o + obj-$(CONFIG_GPIO_KEMPLD) += gpio-kempld.o ++obj-$(CONFIG_GPIO_LATCH_RB91X) += gpio-latch-rb91x.o + obj-$(CONFIG_GPIO_LOONGSON1) += gpio-loongson1.o + obj-$(CONFIG_GPIO_LOONGSON) += gpio-loongson.o + obj-$(CONFIG_GPIO_LP3943) += gpio-lp3943.o