From patchwork Wed Aug 23 03:34:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinbo Zhu X-Patchwork-Id: 136634 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp270125vqm; Tue, 22 Aug 2023 23:26:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjO8MUW9eo9Wb5f1ztNZGWGtAfABNpU3HXlWe39aJ0zz6CifEOEm9JzdJ35dCevE31339S X-Received: by 2002:a05:6a00:1884:b0:68a:3c7a:12a7 with SMTP id x4-20020a056a00188400b0068a3c7a12a7mr9141478pfh.5.1692771974808; Tue, 22 Aug 2023 23:26:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692771974; cv=none; d=google.com; s=arc-20160816; b=YHmNp9e+Yn370XFzw4E5xgIUViJUnISW3T8M++nb+Hwu5i2GhJnsc3PCL744/b9U4s Oblp6rEJb+xsbeEgQbM4eQF8C1ASwbooYkRt0g9phdzGc5iCgofmSdSlWNTlYzGk3En+ Y9lTsoEkisn83tYQiCDCErJcJ/Vzo9c2NOHHfW+QETNxy9Ss9d/Bp86yZKxCWi6cOSVJ W4l8+4JSw3PlcUvuzde70evIXsrG9nwSIg9ZmncqI+9VQgUMR9cYpWeEwSQVKaBvPGy1 Gj75SJNQhOQOV0hZsQYPiCkYaRfLpUwbyqP5Mily6bcMtwgpD2SwvDf+nKWGoA52eSgu CIdQ== 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=8TJnNib18gr7ssiC7e1c4LpbwJwBeNLAIylSpqmKLW0=; fh=03M9NuUp7mf+kiarWzGb9RQmG0WNybTkFW4IRsSZJPI=; b=FmnLGozycyyqjDes+onvTTwgJLRTjgG6OnKUrsZwP3bPKl6R7+iY8AWywp70lN9wJy n75KXjMHx6oMB7ZlZn7wxkWURJonGOnzKQlknxMAe7m0pK8UP/VDrkmNsl/4PCEXUMYh WbhrkYqp9JDWX+Sf+/eedXnYy8aRa3IafYNFDXhR+5VvwmxNGxsyiXK+zUbMJX5jp4lS fjn4K8DYIQJdOreQ7tD5eqQMA2eutfbs2Bj4gKUKTXdFSOYhMgGoCFxCpPp3ueuDDqia vAa/lh3CKyiFEsFY+F6CJpy9Z3+vSgEzAaJPhADedSE40lB3CcvYG/Uf2vws6M0jBuu0 vXog== 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 g1-20020a63dd41000000b00565354f7f7fsi10504034pgj.346.2023.08.22.23.26.00; Tue, 22 Aug 2023 23:26:14 -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 S232443AbjHWDei (ORCPT + 99 others); Tue, 22 Aug 2023 23:34:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231938AbjHWDeh (ORCPT ); Tue, 22 Aug 2023 23:34:37 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 13DF9E4A; Tue, 22 Aug 2023 20:34:33 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.201]) by gateway (Coremail) with SMTP id _____8BxuOhIfuVkYRYbAA--.19686S3; Wed, 23 Aug 2023 11:34:32 +0800 (CST) Received: from localhost.localdomain (unknown [10.20.42.201]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxDCNEfuVk7_FgAA--.20841S3; Wed, 23 Aug 2023 11:34:32 +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, loongson-kernel@lists.loongnix.cn, Yinbo Zhu Subject: [PATCH v4 1/2] gpio: dt-bindings: add more loongson gpio chip support Date: Wed, 23 Aug 2023 11:34:26 +0800 Message-Id: <20230823033427.23072-2-zhuyinbo@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230823033427.23072-1-zhuyinbo@loongson.cn> References: <20230823033427.23072-1-zhuyinbo@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxDCNEfuVk7_FgAA--.20841S3 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 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: 1775000066357241011 X-GMAIL-MSGID: 1775000066357241011 This patch was to add loongson 2k0500, 2k2000 and 3a5000 gpio chip dt-bindings support in yaml file. Signed-off-by: Yinbo Zhu Reviewed-by: Conor Dooley --- .../bindings/gpio/loongson,ls-gpio.yaml | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml b/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml index fb86e8ce6349..97472f1529a0 100644 --- a/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml +++ b/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml @@ -11,9 +11,24 @@ maintainers: properties: compatible: - enum: - - loongson,ls2k-gpio - - loongson,ls7a-gpio + oneOf: + - enum: + - loongson,ls2k-gpio + - loongson,ls2k0500-gpio0 + - loongson,ls2k0500-gpio1 + - loongson,ls2k2000-gpio0 + - loongson,ls2k2000-gpio1 + - loongson,ls2k2000-gpio2 + - loongson,ls3a5000-gpio + - loongson,ls7a-gpio + - items: + - enum: + - loongson,ls2k1000-gpio + - const: loongson,ls2k-gpio + - items: + - enum: + - loongson,ls7a1000-gpio + - const: loongson,ls7a-gpio reg: maxItems: 1 @@ -49,7 +64,7 @@ examples: #include gpio0: gpio@1fe00500 { - compatible = "loongson,ls2k-gpio"; + compatible = "loongson,ls2k1000-gpio", "loongson,ls2k-gpio"; reg = <0x1fe00500 0x38>; ngpios = <64>; #gpio-cells = <2>; From patchwork Wed Aug 23 03:34:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinbo Zhu X-Patchwork-Id: 136641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp335472vqm; Wed, 23 Aug 2023 02:16:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1tMachv4hxETHXXQ5/2NolfYuI0PshiuDcdVkR7U8zysAYBB15N/M+3bT7z0pl/VxdyJW X-Received: by 2002:a05:6512:531:b0:500:7cab:efc3 with SMTP id o17-20020a056512053100b005007cabefc3mr5671684lfc.11.1692782186787; Wed, 23 Aug 2023 02:16:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692782186; cv=none; d=google.com; s=arc-20160816; b=eWpNcRJcUbhK4vRP8cn6EbMiNXwW3ZDYslHQ6Cj94cIQiPhrBS6tgly1FTiM3uVq0t GTJRDG+dOTpebzLmLPjOrigkD5lgSMvWPGxeBuV45SXqfgCcGxzo88IdRqL5OTdNrplu kjnLcHVF7ct8nYai/tH7IBHaNnOLqabvYH1xzQ1mhHbbPNmjHPrTxTeTitDcHeLGzSf7 VN2WcNpm8on/2aCYVMvL2gP+b/vm12FFtiSEVP54Nlk6aq2Rshs4cxYzL7/ieSuifbNs FFw2DRsiiXnb1+7q86wcaLMDDs8HeHKMonC7mZvujY7UXaNwpIbfscQYglm38DSdIcX8 53Lw== 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=VL5mQJpXZLTh9QpF+34HStZWdYtCklPT737dkoV5wxs=; fh=03M9NuUp7mf+kiarWzGb9RQmG0WNybTkFW4IRsSZJPI=; b=iz/Vn4T/5TNZ7LmbZCS54v5NfksSSHs0pAQWdpc2fv/BWIY+0w5r9UxbOpCuLM98Jn quLeX0jLHQ9GH5lcNpudM0ygGsKQbl0anAdrFph+30fzNR13DqVxJK54395U+F3/AZkP f3RDlRKm/t/SSCF/TmV3epuLF+C1Yl5cNc9XDflvYlc3xKnHIMofnCmTR+a5w/WtiV/7 FTliEdzP4mrWWVfJKSl7182ulQJORtOkL8yGQj1qzeNktGED2ODVP0uQOSBT8IIZ3wjO 6bsVjs8w98Nx1TikzzjOTl1PYxLoienq51XEZlwCYTmhc40xHehCtGmdnH2DNwaVYLHc gX5Q== 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 me4-20020a170906aec400b009a1e1f4139bsi494739ejb.29.2023.08.23.02.16.01; Wed, 23 Aug 2023 02:16:25 -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 S232456AbjHWDen (ORCPT + 99 others); Tue, 22 Aug 2023 23:34:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232155AbjHWDeh (ORCPT ); Tue, 22 Aug 2023 23:34:37 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2885EE4D; Tue, 22 Aug 2023 20:34:33 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.201]) by gateway (Coremail) with SMTP id _____8DxqOpIfuVkZhYbAA--.45669S3; Wed, 23 Aug 2023 11:34:32 +0800 (CST) Received: from localhost.localdomain (unknown [10.20.42.201]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxDCNEfuVk7_FgAA--.20841S4; Wed, 23 Aug 2023 11:34:32 +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, loongson-kernel@lists.loongnix.cn, Yinbo Zhu Subject: [PATCH v4 2/2] gpio: loongson: add more gpio chip support Date: Wed, 23 Aug 2023 11:34:27 +0800 Message-Id: <20230823033427.23072-3-zhuyinbo@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230823033427.23072-1-zhuyinbo@loongson.cn> References: <20230823033427.23072-1-zhuyinbo@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxDCNEfuVk7_FgAA--.20841S4 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 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: 1774997483218504620 X-GMAIL-MSGID: 1775010774438359258 This patch was to add loongson 2k0500, 2k2000 and 3a5000 gpio chip driver support. Signed-off-by: Yinbo Zhu --- drivers/gpio/gpio-loongson-64bit.c | 136 +++++++++++++++++++++++++++-- 1 file changed, 128 insertions(+), 8 deletions(-) diff --git a/drivers/gpio/gpio-loongson-64bit.c b/drivers/gpio/gpio-loongson-64bit.c index 06213bbfabdd..8786d0a21bbb 100644 --- a/drivers/gpio/gpio-loongson-64bit.c +++ b/drivers/gpio/gpio-loongson-64bit.c @@ -23,9 +23,10 @@ enum loongson_gpio_mode { struct loongson_gpio_chip_data { const char *label; enum loongson_gpio_mode mode; - unsigned int conf_offset; - unsigned int out_offset; - unsigned int in_offset; + u32 conf_offset; + u32 out_offset; + u32 in_offset; + u32 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,12 +181,11 @@ 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->inten_offset) + lgpio->chip.to_irq = loongson_gpio_to_irq; return devm_gpiochip_add_data(dev, &lgpio->chip, lgpio); } @@ -187,6 +216,57 @@ static const struct loongson_gpio_chip_data loongson_gpio_ls2k_data = { .conf_offset = 0x0, .in_offset = 0x20, .out_offset = 0x10, + .inten_offset = 0x30, +}; + +static const struct loongson_gpio_chip_data loongson_gpio_ls2k0500_data0 = { + .label = "ls2k0500_gpio", + .mode = BIT_CTRL_MODE, + .conf_offset = 0x0, + .in_offset = 0x8, + .out_offset = 0x10, + .inten_offset = 0xb0, +}; + +static const struct loongson_gpio_chip_data loongson_gpio_ls2k0500_data1 = { + .label = "ls2k0500_gpio", + .mode = BIT_CTRL_MODE, + .conf_offset = 0x0, + .in_offset = 0x8, + .out_offset = 0x10, + .inten_offset = 0x98, +}; + +static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data0 = { + .label = "ls2k2000_gpio", + .mode = BIT_CTRL_MODE, + .conf_offset = 0x0, + .in_offset = 0xc, + .out_offset = 0x8, +}; + +static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data1 = { + .label = "ls2k2000_gpio", + .mode = BIT_CTRL_MODE, + .conf_offset = 0x0, + .in_offset = 0x20, + .out_offset = 0x10, +}; + +static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data2 = { + .label = "ls2k2000_gpio", + .mode = BIT_CTRL_MODE, + .conf_offset = 0x84, + .in_offset = 0x88, + .out_offset = 0x80, +}; + +static const struct loongson_gpio_chip_data loongson_gpio_ls3a5000_data = { + .label = "ls3a5000_gpio", + .mode = BIT_CTRL_MODE, + .conf_offset = 0x0, + .in_offset = 0xc, + .out_offset = 0x8, }; static const struct loongson_gpio_chip_data loongson_gpio_ls7a_data = { @@ -202,6 +282,30 @@ static const struct of_device_id loongson_gpio_of_match[] = { .compatible = "loongson,ls2k-gpio", .data = &loongson_gpio_ls2k_data, }, + { + .compatible = "loongson,ls2k0500-gpio0", + .data = &loongson_gpio_ls2k0500_data0, + }, + { + .compatible = "loongson,ls2k0500-gpio1", + .data = &loongson_gpio_ls2k0500_data1, + }, + { + .compatible = "loongson,ls2k2000-gpio0", + .data = &loongson_gpio_ls2k2000_data0, + }, + { + .compatible = "loongson,ls2k2000-gpio1", + .data = &loongson_gpio_ls2k2000_data1, + }, + { + .compatible = "loongson,ls2k2000-gpio2", + .data = &loongson_gpio_ls2k2000_data2, + }, + { + .compatible = "loongson,ls3a5000-gpio", + .data = &loongson_gpio_ls3a5000_data, + }, { .compatible = "loongson,ls7a-gpio", .data = &loongson_gpio_ls7a_data, @@ -215,6 +319,22 @@ static const struct acpi_device_id loongson_gpio_acpi_match[] = { .id = "LOON0002", .driver_data = (kernel_ulong_t)&loongson_gpio_ls7a_data, }, + { + .id = "LOON0007", + .driver_data = (kernel_ulong_t)&loongson_gpio_ls3a5000_data, + }, + { + .id = "LOON000A", + .driver_data = (kernel_ulong_t)&loongson_gpio_ls2k2000_data0, + }, + { + .id = "LOON000B", + .driver_data = (kernel_ulong_t)&loongson_gpio_ls2k2000_data1, + }, + { + .id = "LOON000C", + .driver_data = (kernel_ulong_t)&loongson_gpio_ls2k2000_data2, + }, {} }; MODULE_DEVICE_TABLE(acpi, loongson_gpio_acpi_match);