From patchwork Mon Oct 17 09:16:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 3328 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1348984wrs; Mon, 17 Oct 2022 02:22:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6sbsadgeYHfW+rKp/PCHnUgmQ8uMn0bwVZlVfg8ENweX0COF1uR2z9sO0FpQJvaUTxfM5W X-Received: by 2002:a17:903:1ce:b0:185:4aa1:4021 with SMTP id e14-20020a17090301ce00b001854aa14021mr10340127plh.122.1665998549952; Mon, 17 Oct 2022 02:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665998549; cv=none; d=google.com; s=arc-20160816; b=Pa/8teBK/0PjJMsm5wKuQtuLCV3lPSzoW+527VCAvCFYjcNkq+5NT9QpM4P42igxMT CG2EqqK9VSD9DRNvdwf0dQGXu8TV7Mv4X24OenWodFmpeLz5gbniOqXzCOTWFl/4AfhQ jtS77MmXZKKUtjhSA5nQGYp/MmSvT4EztK3AbQ+SBdehfiwnmkKj0akYG5G9XNOGKz8P DUYH6FSCbn7dR4DkpFX03Ve8/MCvVgNQXmUCFzw89vdCIc6JKEfSJAJ89SU0Hl06ekQp Q7buIdnemu731pv0YsCzZ3IRPkXbxEYe97rQPFGnvp4YGU76foBgPt1rPlRT1eh0jXnc 64Yg== 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=EPVBhK0rbpktxQd3uq2/qvgXoXQppgBSdJVYd8YExeY=; b=A+SX4oXjonUr9HWzq+BtjTIOxElrPSQQT56SVZFXrHuiyS7dILTwu/HZpRF89ghP0h 3NMnYcaxcVuu7K/0mvK0cF+5Av7W76Di9mBh5eTILyw5qugxsOSNOA5VHbhIfYSbirGV UqNp8ogSW3o2G8Z/Ht2SIeNkurMwSRaA7VeagtVHa12XzTKf0kWyptZaQiv4WLmWgyLM P7ZeeAtCdxEQOM0t/yk3WhWpFSC7nUA7iyTy+PtOsFMDCXvWFBPwsSTjeE85H0sieuAB Ar5Ba+sUOBv7K7+E3b00LkBVVcryslXdnZ3hYqltBMDttzPrJLjhQnHcP6bzEQmcBAoK X51w== 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 i13-20020a170902c94d00b0017bcea4e6b6si12036284pla.234.2022.10.17.02.22.17; Mon, 17 Oct 2022 02:22:29 -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 S230037AbiJQJTI (ORCPT + 99 others); Mon, 17 Oct 2022 05:19:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231185AbiJQJSW (ORCPT ); Mon, 17 Oct 2022 05:18:22 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 433224CA04; Mon, 17 Oct 2022 02:18:02 -0700 (PDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4MrWZw6JtGz4xFy; Mon, 17 Oct 2022 20:16:40 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (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 mail.ozlabs.org (Postfix) with ESMTPSA id 4MrWZr4gbFz4xG9; Mon, 17 Oct 2022 20:16:36 +1100 (AEDT) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: linux-spi@vger.kernel.org Cc: Mark Brown , Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, linux-aspeed@lists.ozlabs.org, openbmc@lists.ozlabs.org, Joel Stanley , Andrew Jeffery , Chin-Ting Kuo , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , Naresh Solanki Subject: [PATCH linux v2 1/3] spi: dt-bindings: aspeed: Add a ranges property Date: Mon, 17 Oct 2022 11:16:22 +0200 Message-Id: <20221017091624.130227-2-clg@kaod.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221017091624.130227-1-clg@kaod.org> References: <20221017091624.130227-1-clg@kaod.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746926095203117776?= X-GMAIL-MSGID: =?utf-8?q?1746926095203117776?= "ranges" predefines settings for the decoding ranges of each CS. Cc: Naresh Solanki Cc: Chin-Ting Kuo Signed-off-by: Cédric Le Goater --- .../devicetree/bindings/spi/aspeed,ast2600-fmc.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/devicetree/bindings/spi/aspeed,ast2600-fmc.yaml b/Documentation/devicetree/bindings/spi/aspeed,ast2600-fmc.yaml index fa8f4ac20985..a11cbc4c4c5c 100644 --- a/Documentation/devicetree/bindings/spi/aspeed,ast2600-fmc.yaml +++ b/Documentation/devicetree/bindings/spi/aspeed,ast2600-fmc.yaml @@ -38,6 +38,14 @@ properties: interrupts: maxItems: 1 + ranges: + minItems: 1 + maxItems: 5 + description: | + Defines the address mapping for child devices with four integer + values for each chip-select line in use: + 0 + required: - compatible - reg @@ -58,6 +66,7 @@ examples: compatible = "aspeed,ast2600-fmc"; clocks = <&syscon ASPEED_CLK_AHB>; interrupts = ; + ranges = <0 0 0x20000000 0x2000000>, <1 0 0x22000000 0x2000000>; flash@0 { reg = < 0 >; From patchwork Mon Oct 17 09:16:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 3329 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1349091wrs; Mon, 17 Oct 2022 02:22:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4lYokOkpDh93r/1aOworoqQ/x9HHuQeHhfgWUusxO4mm726NVvjkj8xuJwbh2JdEz+c0xJ X-Received: by 2002:a17:903:22d0:b0:185:5421:a5d3 with SMTP id y16-20020a17090322d000b001855421a5d3mr2140254plg.119.1665998576212; Mon, 17 Oct 2022 02:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665998576; cv=none; d=google.com; s=arc-20160816; b=UBSIKhsD+tr2iaSW0rRmONeHjG1gy91EGt/LB4xWhBKX8zfoPNUr/YnfJhmUTZv5Zr OcwhH7/ENqzlt1aKyh9yhSedHY4Yl4zfzm6CzKALCj0mvdqevCUwpJpA8e6D+pB+c6NF nMOY8rAlKtdUdf+1tjggOJh8+4qIYzSCV/5xOd5b/ns7O8w86fEaYjxqjaRHs+6LKmxC lHGF7+alb3JIAScBCg6bK1uiIAQpFvkXM2JmPXy1SB/50vitF0HTJfuEsGJD1yE/NO5p 3s6/KBmq26gtDJEM0TzNzs31+ocH3Zq7VLAoZCMsy+1sykh7vylH+aUrX6RJKvLbdw1y TnPg== 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=Pf7pirSML3zl9F7iEDsHz+ljnsC7lcQm58paC4rjGtc=; b=girRkfyasz2AqzGESqcwSsrtWmrf+HuLBpoOUcpYCAio1pq/upgS6gQ8bEVHej9WHN Rp+AoB8E8R1oYQ440phznzkVNv78wj/ixTgRx5VhgckmiaqwghWFmGk2XnhBNOuG55Eh ZXaEDiTFrxuKHwMpo4cRrUCPgemJbs4DignL92yGKO7x6NkiOx1SeqdsnLuubQLQpv01 oqKSdZ4VvVf/gQMGzSG1w1NqIuh5zUDfEd/A72JwVkz48nzhg/GNax1Psj1kRVvHuA+q 7sOhu7/pOMRDYQCvd0EkQ15qppjQoiuymg0IW+b+QgWMzun34oIRIXrKbL4JVzHniHwD FMlw== 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 d11-20020a17090a628b00b001f31da6b2d2si10022423pjj.154.2022.10.17.02.22.44; Mon, 17 Oct 2022 02:22:56 -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 S229993AbiJQJWG (ORCPT + 99 others); Mon, 17 Oct 2022 05:22:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231252AbiJQJVw (ORCPT ); Mon, 17 Oct 2022 05:21:52 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1A6713D30; Mon, 17 Oct 2022 02:21:48 -0700 (PDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4MrWb13WWgz4xGm; Mon, 17 Oct 2022 20:16:45 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (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 mail.ozlabs.org (Postfix) with ESMTPSA id 4MrWZx343vz4wgv; Mon, 17 Oct 2022 20:16:41 +1100 (AEDT) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: linux-spi@vger.kernel.org Cc: Mark Brown , Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, linux-aspeed@lists.ozlabs.org, openbmc@lists.ozlabs.org, Joel Stanley , Andrew Jeffery , Chin-Ting Kuo , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , Naresh Solanki Subject: [PATCH linux v2 2/3] spi: aspeed: Handle custom decoding ranges Date: Mon, 17 Oct 2022 11:16:23 +0200 Message-Id: <20221017091624.130227-3-clg@kaod.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221017091624.130227-1-clg@kaod.org> References: <20221017091624.130227-1-clg@kaod.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS autolearn=no 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746926123155197159?= X-GMAIL-MSGID: =?utf-8?q?1746926123155197159?= The "ranges" property predefines settings for the decoding ranges of each CS. If found in the DT, the driver applies the settings at probe time. The default behavior is to set the decoding range of each CS using the flash device size when the spi slave is setup. Cc: Naresh Solanki Cc: Chin-Ting Kuo Signed-off-by: Cédric Le Goater --- drivers/spi/spi-aspeed-smc.c | 65 +++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-aspeed-smc.c b/drivers/spi/spi-aspeed-smc.c index b90571396a60..75e1d08bbd00 100644 --- a/drivers/spi/spi-aspeed-smc.c +++ b/drivers/spi/spi-aspeed-smc.c @@ -96,6 +96,7 @@ struct aspeed_spi { u32 ahb_base_phy; u32 ahb_window_size; struct device *dev; + bool fixed_windows; struct clk *clk; u32 clk_freq; @@ -382,6 +383,7 @@ static const char *aspeed_spi_get_name(struct spi_mem *mem) struct aspeed_spi_window { u32 cs; + u32 reg; u32 offset; u32 size; }; @@ -396,6 +398,7 @@ static void aspeed_spi_get_windows(struct aspeed_spi *aspi, for (cs = 0; cs < aspi->data->max_cs; cs++) { reg_val = readl(aspi->regs + CE0_SEGMENT_ADDR_REG + cs * 4); windows[cs].cs = cs; + windows[cs].reg = reg_val; windows[cs].size = data->segment_end(aspi, reg_val) - data->segment_start(aspi, reg_val); windows[cs].offset = data->segment_start(aspi, reg_val) - aspi->ahb_base_phy; @@ -572,7 +575,8 @@ static int aspeed_spi_dirmap_create(struct spi_mem_dirmap_desc *desc) if (op->data.dir != SPI_MEM_DATA_IN) return -EOPNOTSUPP; - aspeed_spi_chip_adjust_window(chip, desc->info.offset, desc->info.length); + if (!aspi->fixed_windows) + aspeed_spi_chip_adjust_window(chip, desc->info.offset, desc->info.length); if (desc->info.length > chip->ahb_window_size) dev_warn(aspi->dev, "CE%d window (%dMB) too small for mapping", @@ -712,6 +716,61 @@ static void aspeed_spi_enable(struct aspeed_spi *aspi, bool enable) aspeed_spi_chip_enable(aspi, cs, enable); } +static int aspeed_spi_chip_read_ranges(struct device_node *node, struct aspeed_spi *aspi) +{ + const char *range_prop = "ranges"; + struct property *prop; + struct aspeed_spi_window ranges[ASPEED_SPI_MAX_NUM_CS]; + int prop_size; + int count; + int ret; + int i; + + prop = of_find_property(node, range_prop, &prop_size); + if (!prop) + return 0; + + count = prop_size / sizeof(*ranges); + if (count > aspi->data->max_cs) { + dev_err(aspi->dev, "invalid '%s' property %d\n", range_prop, count); + return -EINVAL; + } + + if (count < aspi->data->max_cs) + dev_dbg(aspi->dev, "'%s' property does not cover all CE\n", + range_prop); + + ret = of_property_read_u32_array(node, range_prop, (u32 *)ranges, count * 4); + if (ret) + return ret; + + dev_info(aspi->dev, "Using preset decoding ranges\n"); + for (i = 0; i < count; i++) { + struct aspeed_spi_window *win = &ranges[i]; + + if (win->cs > aspi->data->max_cs) { + dev_err(aspi->dev, "CE%d range is invalid", win->cs); + return -EINVAL; + } + + /* Trim top bit of the address to keep offset */ + win->offset &= aspi->ahb_window_size - 1; + + /* Minimal check */ + if (win->offset + win->size > aspi->ahb_window_size) { + dev_warn(aspi->dev, "CE%d range is too large", win->cs); + return -EINVAL; + } + + ret = aspeed_spi_set_window(aspi, win); + if (ret) + return ret; + } + + aspi->fixed_windows = true; + return 0; +} + static int aspeed_spi_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -767,6 +826,10 @@ static int aspeed_spi_probe(struct platform_device *pdev) return ret; } + ret = aspeed_spi_chip_read_ranges(dev->of_node, aspi); + if (ret) + return ret; + /* IRQ is for DMA, which the driver doesn't support yet */ ctlr->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL | data->mode_bits; From patchwork Mon Oct 17 09:16:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 3327 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1348971wrs; Mon, 17 Oct 2022 02:22:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7esaSgBTvIzwPJzCyVGB5z3F481EfaEl7aFe7XXW3n4Wxt+xCGCA/RnnO9u0oNXTbjVn7q X-Received: by 2002:a05:6a00:1907:b0:557:e83b:1671 with SMTP id y7-20020a056a00190700b00557e83b1671mr11535547pfi.65.1665998547627; Mon, 17 Oct 2022 02:22:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665998547; cv=none; d=google.com; s=arc-20160816; b=FhEw8CNupnHN+hxuIj4PcxmqeAC2EhPwSX6RO+fq6F9yjRrhsNCxdbGWoSZ4WH7XWR 938pKyFFc6n0cPwjZaqWVAcsJr2rSMt01uTxBvjjZGUWg9gOZvhE3u+5wAxhet0jcnZf PqJlq2PXESljTT2Y/xmKCxAvi0NaLwBpwqjD3xJ83OU+zlbcsxrjZMPDhuURCznhZWxm uq1EpbYvDeVSkex571J2U6xfzG+GppjkA3zDIinoJfhqj1IaNUU0VOOY5AVLXcXhaksH m8gMk2pg3naIKGei+6GLZ26cer3LaX1W/og9lPO3bybljTGMuWOnLIVvbTnzl4DC6Xzv ONgA== 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=9c/piuBJ/cUJ6zSlcjPWKZ1mEmNbQ7bRd/X58Mq9/8I=; b=Bj2pLt00GN/9v0VRQGn9k2JAM6UgpII0J1mJIwU35LWVzKvwpKFn8uvfsm8XT2JAYO c0dhfaAdpSX/nfRqPTU8Bu5x1DsATacEKHxKh+Od2kK5ezpahUsq/pnuXuv+QlzNZywR GJFhjKOCgF9uiB6SIvwjcbS+7JVQwwsvlAXJOy4xxdkFGdDdPSl7xvCK+Pu+Cbxsi+37 XfBOYKXGaPCQ7Asm4aco8YxNLQLlOUzd8eHIXV1waHcgzanmqRkMs7F5lKB4vAxxahvk qWYdw7pqGXOcwi8LkpTX5cXTeW9D+SRM3DyPm+8LeP1xd0jEQTr4foK8R8G3A0L5jv9A QMug== 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 s1-20020aa78bc1000000b005355298e9c3si10523561pfd.228.2022.10.17.02.22.14; Mon, 17 Oct 2022 02:22:27 -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 S229977AbiJQJSZ (ORCPT + 99 others); Mon, 17 Oct 2022 05:18:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230037AbiJQJST (ORCPT ); Mon, 17 Oct 2022 05:18:19 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D13FC40561; Mon, 17 Oct 2022 02:18:02 -0700 (PDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4MrWb55sqhz4xG9; Mon, 17 Oct 2022 20:16:49 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (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 mail.ozlabs.org (Postfix) with ESMTPSA id 4MrWb20658z4xGG; Mon, 17 Oct 2022 20:16:45 +1100 (AEDT) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: linux-spi@vger.kernel.org Cc: Mark Brown , Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, linux-aspeed@lists.ozlabs.org, openbmc@lists.ozlabs.org, Joel Stanley , Andrew Jeffery , Chin-Ting Kuo , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH linux v2 3/3] spi: aspeed: Introduce a "ranges" debugfs file Date: Mon, 17 Oct 2022 11:16:24 +0200 Message-Id: <20221017091624.130227-4-clg@kaod.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221017091624.130227-1-clg@kaod.org> References: <20221017091624.130227-1-clg@kaod.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS autolearn=no 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746926092902605287?= X-GMAIL-MSGID: =?utf-8?q?1746926092902605287?= This dumps the mapping windows, or decoding ranges, of all devices possibly attached of the controller. To be noted that a top level "spi" debugfs directory is created to hold the intermediate directory of the driver instance. Cc: Chin-Ting Kuo Signed-off-by: Cédric Le Goater --- drivers/spi/spi-aspeed-smc.c | 66 +++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-aspeed-smc.c b/drivers/spi/spi-aspeed-smc.c index 75e1d08bbd00..a79e5cc8ac5b 100644 --- a/drivers/spi/spi-aspeed-smc.c +++ b/drivers/spi/spi-aspeed-smc.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -102,6 +103,9 @@ struct aspeed_spi { u32 clk_freq; struct aspeed_spi_chip chips[ASPEED_SPI_MAX_NUM_CS]; +#if IS_ENABLED(CONFIG_DEBUG_FS) + struct dentry *debugfs; +#endif }; static u32 aspeed_spi_get_io_mode(const struct spi_mem_op *op) @@ -716,6 +720,65 @@ static void aspeed_spi_enable(struct aspeed_spi *aspi, bool enable) aspeed_spi_chip_enable(aspi, cs, enable); } +#if IS_ENABLED(CONFIG_DEBUG_FS) +static int aspeed_spi_ranges_debug_show(struct seq_file *m, void *private) +{ + struct aspeed_spi *aspi = m->private; + struct aspeed_spi_window windows[ASPEED_SPI_MAX_NUM_CS] = { 0 }; + u32 cs; + + if (aspi->data == &ast2400_spi_data) + return 0; + + aspeed_spi_get_windows(aspi, windows); + + seq_puts(m, " offset size register\n"); + for (cs = 0; cs < aspi->data->max_cs; cs++) { + if (!windows[cs].reg) + seq_printf(m, "CE%d: disabled\n", cs); + else + seq_printf(m, "CE%d: 0x%.8x 0x%.8x 0x%x\n", cs, + windows[cs].offset, windows[cs].size, + windows[cs].reg); + } + return 0; +} +DEFINE_SHOW_ATTRIBUTE(aspeed_spi_ranges_debug); + +static int aspeed_spi_debugfs_init(struct spi_controller *ctlr) +{ + struct aspeed_spi *aspi = spi_controller_get_devdata(ctlr); + struct dentry *rootdir = NULL; + + rootdir = debugfs_lookup("spi", NULL); + if (!rootdir) + rootdir = debugfs_create_dir("spi", NULL); + + aspi->debugfs = debugfs_create_dir(dev_name(&ctlr->dev), rootdir); + if (!aspi->debugfs) + return -ENOMEM; + + debugfs_create_file("ranges", 0444, aspi->debugfs, (void *)aspi, + &aspeed_spi_ranges_debug_fops); + return 0; +} + +static void aspeed_spi_debugfs_remove(struct aspeed_spi *aspi) +{ + debugfs_remove_recursive(aspi->debugfs); +} + +#else +static inline int aspeed_spi_debugfs_init(struct spi_controller *ctlr) +{ + return 0; +} + +static inline void aspeed_spi_debugfs_remove(struct aspeed_spi *aspi) +{ +} +#endif /* IS_ENABLED(CONFIG_DEBUG_FS) */ + static int aspeed_spi_chip_read_ranges(struct device_node *node, struct aspeed_spi *aspi) { const char *range_prop = "ranges"; @@ -845,7 +908,7 @@ static int aspeed_spi_probe(struct platform_device *pdev) dev_err(&pdev->dev, "spi_register_controller failed\n"); goto disable_clk; } - return 0; + return aspeed_spi_debugfs_init(ctlr); disable_clk: clk_disable_unprepare(aspi->clk); @@ -856,6 +919,7 @@ static int aspeed_spi_remove(struct platform_device *pdev) { struct aspeed_spi *aspi = platform_get_drvdata(pdev); + aspeed_spi_debugfs_remove(aspi); aspeed_spi_enable(aspi, false); clk_disable_unprepare(aspi->clk); return 0;