From patchwork Mon Jul 31 09:10:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinbo Zhu X-Patchwork-Id: 128528 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp1903311vqg; Mon, 31 Jul 2023 02:51:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlE+NXxYOR3vPMGcFpzeFeJVGN0UxY0+B/nazb2I4oDWtAAvN5yd02by5XX5LRYCJad+a2NS X-Received: by 2002:a17:902:f681:b0:1b8:7625:3042 with SMTP id l1-20020a170902f68100b001b876253042mr10932772plg.10.1690797068027; Mon, 31 Jul 2023 02:51:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690797068; cv=none; d=google.com; s=arc-20160816; b=IH9jJzXINoOZ1UCi3a9PuI4ziWmypCDAbWKJFg6B18kR3Gk3grlF0HttrwDpuipNic bFfZBsjy7jFCpPAtUl+zsx9eCvn/HvIBjo8Pqolg6EVZdDVPtwsKRUELTcJ12CloxRU7 4kkUF69pG/AYzwVVKaDmCsXhvAJ+xkXGp2tLWsR/UNnQNzrTqgQGocqW3+wGp9XuSq8K qNIp7yQAiFcmuHIhbfUImKS6j5IoD9EL87lr5P5nbM7k0EfrR5k9zSFMUOON2W0Dqp3u tBUacE56n5LKIVIzh392HS0JQSLg2A5smUZJaEQBBNwLLm2UYlqtv+pk0TIHH7Ob8sk/ n1AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=if7oEZQ9etOB5gTqlm3jZzW11VASvjyWK0/SiSi6dDk=; fh=teZAvrnU1k4B6t2Z9AwXPKAN+RYsEfJmvb3BgB5uIhw=; b=DHdhoN5NWgwgNjXFmIF4n5vc2DKH/aEzYnZ+H8Sl3xMH0XcMjD6upOp8xicFgD8542 caR0F4xyllJ3C8IHt/Rg4J5eNPaEWoSCRuI8R1zxdHy/mdBroaT4kjtdjN31fir4SQCe /JjtkIctDcPlkhwP1S560g1dvdBF1oakt95UO7D3Vy9z2Z5ygXrd4hP6558tepi1tZER fSfApJSGkovRZliXU09g4xS3/HMLChPZHUIWFAoQMJk13+tkwK4F5M2FlseHfj4HImyL OFDwqHuf9oEDOZbbxazg1kZBnhc2nu2SmnXhGZSnuxQ+cn314Wpm3AfDdhzVA9zalYxi sqUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q4-20020a17090311c400b001b7e19195b7si7283933plh.29.2023.07.31.02.50.55; Mon, 31 Jul 2023 02:51:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231129AbjGaJLY (ORCPT + 99 others); Mon, 31 Jul 2023 05:11:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbjGaJLW (ORCPT ); Mon, 31 Jul 2023 05:11:22 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 369E4102; Mon, 31 Jul 2023 02:11:20 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.201]) by gateway (Coremail) with SMTP id _____8Bx5fC1esdkRCINAA--.31526S3; Mon, 31 Jul 2023 17:11:17 +0800 (CST) Received: from localhost.localdomain (unknown [10.20.42.201]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxriOkesdk1DFCAA--.2097S3; Mon, 31 Jul 2023 17:11:17 +0800 (CST) From: Yinbo Zhu To: Linus Walleij , Bartosz Golaszewski , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jianmin Lv , wanghongliang@loongson.cn, Liu Peibao , loongson-kernel@lists.loongnix.cn, Yinbo Zhu Subject: [PATCH v2 1/2] gpio: dt-bindings: add parsing of loongson gpio offset Date: Mon, 31 Jul 2023 17:10:58 +0800 Message-Id: <20230731091059.17323-2-zhuyinbo@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230731091059.17323-1-zhuyinbo@loongson.cn> References: <20230731091059.17323-1-zhuyinbo@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxriOkesdk1DFCAA--.2097S3 X-CM-SenderInfo: 52kx5xhqerqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772929226512859320 X-GMAIL-MSGID: 1772929226512859320 Add parsing GPIO configure, input, output, interrupt register offset address and GPIO control mode support. Signed-off-by: Yinbo Zhu --- .../bindings/gpio/loongson,ls-gpio.yaml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml b/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml index fb86e8ce6349..cad67f8bfe6e 100644 --- a/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml +++ b/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml @@ -29,6 +29,33 @@ properties: gpio-ranges: true + loongson,gpio-conf-offset: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + This option indicate this GPIO configuration register offset address. + + loongson,gpio-out-offset: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + This option indicate this GPIO output register offset address. + + loongson,gpio-in-offset: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + This option indicate this GPIO input register offset address. + + loongson,gpio-ctrl-mode: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + This option indicate this GPIO control mode, where '0' represents + bit control mode and '1' represents byte control mode. + + loongson,gpio-inten-offset: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + This option indicate this GPIO interrupt enable register offset + address. + interrupts: minItems: 1 maxItems: 64 @@ -39,6 +66,11 @@ required: - ngpios - "#gpio-cells" - gpio-controller + - loongson,gpio-conf-offset + - loongson,gpio-in-offset + - loongson,gpio-out-offset + - loongson,gpio-ctrl-mode + - loongson,gpio-inten-offset - gpio-ranges - interrupts @@ -54,6 +86,11 @@ examples: ngpios = <64>; #gpio-cells = <2>; gpio-controller; + loongson,gpio-conf-offset = <0>; + loongson,gpio-in-offset = <0x20>; + loongson,gpio-out-offset = <0x10>; + loongson,gpio-ctrl-mode = <0>; + loongson,gpio-inten-offset = <0x30>; gpio-ranges = <&pctrl 0 0 15>, <&pctrl 16 16 15>, <&pctrl 32 32 10>, From patchwork Mon Jul 31 09:10:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinbo Zhu X-Patchwork-Id: 128495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp1892771vqg; Mon, 31 Jul 2023 02:21:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlEAFnIbCCCjXGe4SI1cA4fcAmxaH5QDW4IYbhcMHGOYAfBYK8m1DgHAG7nshJtXH5j9MsTb X-Received: by 2002:a17:902:a518:b0:1b5:5052:5af7 with SMTP id s24-20020a170902a51800b001b550525af7mr9546495plq.8.1690795282359; Mon, 31 Jul 2023 02:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690795282; cv=none; d=google.com; s=arc-20160816; b=al2T5dkrcB6fCG/qAJelS4H40prd6A0iOn5Yz4J+4ooHaQJG/1JPFPsQVlV9886o1F 8kHC3WVEIh0myOgmp9WFDyx9BZ+mGX/wdVxRtD6G6wMBqmM0T0Z+WF/6vTFiChukUAL2 xwnp1JpqUCHdCn3fnptQvT+pO2rMvAoTsVE8Fm5Drqj7q69QMdXIxExoZtdPSlGtzs8f GS5tdk5HfOeMXuFbmmRWHxbcn9yF6mZaEaqlhfX7qSUh6AZp3f+hbHYY7w8FWWgr2ahe CRExbz7TV4NN4FzSVYQG2o3ukrjBYw02i4Hayr9M3XKoyWlqXt6yTof6207by1Yaus7E ajsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oUu0R9D+Zyti2QixGF9gf0vMaZLFSpsu7vfvB3RMLh0=; fh=teZAvrnU1k4B6t2Z9AwXPKAN+RYsEfJmvb3BgB5uIhw=; b=HcHTFPFJPDNWBKrH1Cjbo932rMCDV+vC7LTM0DaXmMS5Hu6MnMoxotgq1E+0RAotKY TcfLuMCzjHBQEorEGnpPiUc07E3aZEugZ6uAheKqrOq3nwv2/hJiVvp48o8yKPSLDw5c zsYvlHTblbQfmWvXByAff6HrO3h0hMMBx0+00GP4hmmGBE3e8iWvzdzeqVS1d2GmvP6K k1BUBOQTblHJ2aP4F8Ly13Wyt6kqxVJoEVcYxD38sOl/ETjEv9gsY0ub1z5d9y92Kv5f 69QSBoT2Wu7qQphdclo5iDEyFJ1Amyw7+QJQNxCGCjOkpgB+MrP8YgDY7XccWGCxpRpK 3igw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id la4-20020a170902fa0400b001badbeac8d0si6834325plb.423.2023.07.31.02.21.08; Mon, 31 Jul 2023 02:21:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231620AbjGaJLb (ORCPT + 99 others); Mon, 31 Jul 2023 05:11:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230057AbjGaJLX (ORCPT ); Mon, 31 Jul 2023 05:11:23 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 38672103; Mon, 31 Jul 2023 02:11:20 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.201]) by gateway (Coremail) with SMTP id _____8BxJvG2esdkSSINAA--.31625S3; Mon, 31 Jul 2023 17:11:18 +0800 (CST) Received: from localhost.localdomain (unknown [10.20.42.201]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxriOkesdk1DFCAA--.2097S4; Mon, 31 Jul 2023 17:11:17 +0800 (CST) From: Yinbo Zhu To: Linus Walleij , Bartosz Golaszewski , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jianmin Lv , wanghongliang@loongson.cn, Liu Peibao , loongson-kernel@lists.loongnix.cn, Yinbo Zhu Subject: [PATCH v2 2/2] gpio: loongson: add firmware offset parse support Date: Mon, 31 Jul 2023 17:10:59 +0800 Message-Id: <20230731091059.17323-3-zhuyinbo@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230731091059.17323-1-zhuyinbo@loongson.cn> References: <20230731091059.17323-1-zhuyinbo@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxriOkesdk1DFCAA--.2097S4 X-CM-SenderInfo: 52kx5xhqerqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772927353874012590 X-GMAIL-MSGID: 1772927353874012590 Loongson GPIO controllers come in multiple variants that are compatible except for certain register offset values. Add support for device properties allowing to specify them in ACPI or DT. Signed-off-by: Yinbo Zhu --- drivers/gpio/gpio-loongson-64bit.c | 71 +++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-loongson-64bit.c b/drivers/gpio/gpio-loongson-64bit.c index 06213bbfabdd..7f92cb6205b2 100644 --- a/drivers/gpio/gpio-loongson-64bit.c +++ b/drivers/gpio/gpio-loongson-64bit.c @@ -26,6 +26,7 @@ struct loongson_gpio_chip_data { unsigned int conf_offset; unsigned int out_offset; unsigned int in_offset; + unsigned int inten_offset; }; struct loongson_gpio_chip { @@ -117,7 +118,17 @@ static void loongson_gpio_set(struct gpio_chip *chip, unsigned int pin, int valu static int loongson_gpio_to_irq(struct gpio_chip *chip, unsigned int offset) { + unsigned int u; struct platform_device *pdev = to_platform_device(chip->parent); + struct loongson_gpio_chip *lgpio = to_loongson_gpio_chip(chip); + + if (lgpio->chip_data->mode == BIT_CTRL_MODE) { + u = readl(lgpio->reg_base + lgpio->chip_data->inten_offset + offset / 32 * 4); + u |= BIT(offset % 32); + writel(u, lgpio->reg_base + lgpio->chip_data->inten_offset + offset / 32 * 4); + } else { + writeb(1, lgpio->reg_base + lgpio->chip_data->inten_offset + offset); + } return platform_get_irq(pdev, offset); } @@ -127,11 +138,30 @@ static int loongson_gpio_init(struct device *dev, struct loongson_gpio_chip *lgp { int ret; u32 ngpios; + unsigned int io_width; lgpio->reg_base = reg_base; + if (device_property_read_u32(dev, "ngpios", &ngpios) || !ngpios) + return -EINVAL; + + ret = DIV_ROUND_UP(ngpios, 8); + switch (ret) { + case 1 ... 2: + io_width = ret; + break; + case 3 ... 4: + io_width = 0x4; + break; + case 5 ... 8: + io_width = 0x8; + break; + default: + dev_err(dev, "unsupported io width\n"); + return -EINVAL; + } if (lgpio->chip_data->mode == BIT_CTRL_MODE) { - ret = bgpio_init(&lgpio->chip, dev, 8, + ret = bgpio_init(&lgpio->chip, dev, io_width, lgpio->reg_base + lgpio->chip_data->in_offset, lgpio->reg_base + lgpio->chip_data->out_offset, NULL, NULL, @@ -151,16 +181,35 @@ static int loongson_gpio_init(struct device *dev, struct loongson_gpio_chip *lgp spin_lock_init(&lgpio->lock); } - device_property_read_u32(dev, "ngpios", &ngpios); - - lgpio->chip.can_sleep = 0; lgpio->chip.ngpio = ngpios; - lgpio->chip.label = lgpio->chip_data->label; - lgpio->chip.to_irq = loongson_gpio_to_irq; + lgpio->chip.can_sleep = 0; + if (lgpio->chip_data->label) + lgpio->chip.label = lgpio->chip_data->label; + else + lgpio->chip.label = kstrdup(to_platform_device(dev)->name, GFP_KERNEL); + + if (lgpio->chip_data->inten_offset) + lgpio->chip.to_irq = loongson_gpio_to_irq; return devm_gpiochip_add_data(dev, &lgpio->chip, lgpio); } +static int loongson_gpio_get_props(struct device *dev, + struct loongson_gpio_chip *lgpio) +{ + const struct loongson_gpio_chip_data *d = lgpio->chip_data; + + if (device_property_read_u32(dev, "loongson,gpio-conf-offset", (u32 *)&d->conf_offset) + || device_property_read_u32(dev, "loongson,gpio-in-offset", (u32 *)&d->in_offset) + || device_property_read_u32(dev, "loongson,gpio-out-offset", (u32 *)&d->out_offset) + || device_property_read_u32(dev, "loongson,gpio-ctrl-mode", (u32 *)&d->mode)) + return -EINVAL; + + device_property_read_u32(dev, "loongson,gpio-inten-offset", (u32 *)&d->inten_offset); + + return 0; +} + static int loongson_gpio_probe(struct platform_device *pdev) { void __iomem *reg_base; @@ -172,7 +221,12 @@ static int loongson_gpio_probe(struct platform_device *pdev) if (!lgpio) return -ENOMEM; - lgpio->chip_data = device_get_match_data(dev); + lgpio->chip_data = devm_kzalloc(dev, sizeof(*lgpio->chip_data), GFP_KERNEL); + if (!lgpio->chip_data) + return -ENOMEM; + + if (loongson_gpio_get_props(dev, lgpio)) + lgpio->chip_data = device_get_match_data(dev); reg_base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(reg_base)) @@ -215,6 +269,9 @@ static const struct acpi_device_id loongson_gpio_acpi_match[] = { .id = "LOON0002", .driver_data = (kernel_ulong_t)&loongson_gpio_ls7a_data, }, + { + .id = "LOON0007", + }, {} }; MODULE_DEVICE_TABLE(acpi, loongson_gpio_acpi_match);