From patchwork Fri Mar 24 16:52:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 13187002 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7F96AC76195 for ; Fri, 24 Mar 2023 16:53:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=zy7YbQUC8X9ur++ZqzpMytItODAEcKiERNClS2nBRus=; b=xjxrQo1zIsfUUT 9txacPxxfTMnfboP/ro2w2QLzRy1NtKjJNecUxxd3icpAOkZAf9SAORyr0JwSJxJ/rWcxBtgwZn4b by7BHz0bJjWZ8l22gfRzA6PMZX0mCpSi7Ba6cdRinkSOsPHA8nhtHHZUYSEhyue3MNDjp8Xfz9/Rm jWNZXYrH0WVrwKaN0h7nylNKWe0AxnxTMIru7RxRrsWYKTo45N6FyUriebG3+rr5fchcuLhJyYKqL zGzDDshyqo/23Ehc2vp5UDJKqLX7hCjtlIaqnguonOh+1PTe44/UwfQZ4+ZGMqNMBaOaO4UDxOmcU zvwQ4vZthnmOfWtk30dA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pfkf1-0051Xx-0W; Fri, 24 Mar 2023 16:53:03 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pfkel-0051T1-2g for linux-arm-kernel@lists.infradead.org; Fri, 24 Mar 2023 16:52:49 +0000 Received: by mail-pf1-x436.google.com with SMTP id s8so1654056pfk.5 for ; Fri, 24 Mar 2023 09:52:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679676765; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8UmG7kTY7wjWcxkBXGijn5KqU6ZYb3Prx7pN3zRMZ2Q=; b=QVEqXaO0vwbg6qjXz3p/QiK0qIDvtFqAcZvJt3om0UyJ5+nosdtMGMbAVa/In6hj/w 0+ZwuC7B75j+g1KDkicEbZ7/Q/xWoHazfxg3v+uqOL3522+PaRj1VS0jSt3dF6L9rvM1 TXJipMfXePUNNeIEyhXzjjD19TU3PPhBTAl4uWKbrDj+i2eTgnmZZn4GDoa50RCZFmEB Tchet5lHEGcf+l4KoTxe8L9EdlqoYNgJ/SG7/OxNWuCPddbqZMXvNhuRW7Hrpl6NDO+D MH1DT7EVv/VXD+wlvHH0yJIA3OydtPXoDqcBGnZHYGbKt79L9kLk5DKAKycKKDn8wt4k iGBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679676765; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8UmG7kTY7wjWcxkBXGijn5KqU6ZYb3Prx7pN3zRMZ2Q=; b=L+76/Dm82llBWn80izv5klqsQ3OIE7GPHLHx5HlzUxRsuV+GkRi2otpHjrFDljiDfM L8n5FzG8VSSv447yAo+J9eg+NyIZTuT1QDevkQkubGsEt4/+RxaGzJ22RkLAawI73M/V SwrVc0CwI3Zdrxh3lIM2J2uGNC1WWo/7VVPzjKNcAK3ZNlQqTUE3E/Gp4tzz/tTZFqQr a/7QSWtxMozphWFVH16YfC/P0tea6cTWmDYjG/YjxIOSVv/gOZFhIZrogpMzx7dS3kyC SgS7rqZYd4gaIG7N/D+deARBV+onnnE3b8RkOGEUjWbnnrDDfrhx6PbPL9+JO/J2IRji J2Tw== X-Gm-Message-State: AAQBX9cwx+BOOmTQIaS2TVDkrJtbyh4H0UB/ew3V0CcNh/kr9qmeYFyX pLshqXHdkKmCv4TPbdRM//0= X-Google-Smtp-Source: AK7set+KBVxkxFHsXaMsVsIir/eox0dKYMv1EYMazIh/KAM89fItbtAbbbylsEN1+4M6KgzY6HlOlw== X-Received: by 2002:aa7:9629:0:b0:628:1274:4d60 with SMTP id r9-20020aa79629000000b0062812744d60mr3776739pfg.21.1679676764785; Fri, 24 Mar 2023 09:52:44 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id a5-20020aa780c5000000b0062b5a55835dsm1420289pfn.213.2023.03.24.09.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 09:52:44 -0700 (PDT) From: Florian Fainelli To: linux-kernel@vger.kernel.org Cc: Florian Fainelli , Broadcom internal kernel review list , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM BCM7XXX ARM ARCHITECTURE) Subject: [PATCH 3/3] memory: brcmstb_memc: Add new DDR attributes Date: Fri, 24 Mar 2023 09:52:31 -0700 Message-Id: <20230324165231.3468069-4-f.fainelli@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230324165231.3468069-1-f.fainelli@gmail.com> References: <20230324165231.3468069-1-f.fainelli@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230324_095247_868309_567CCD12 X-CRM114-Status: GOOD ( 14.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Provide information about the DDR size, type, width, total width, dual/single rank. This is useful for reporting purposes and inventory of the system(s). Signed-off-by: Florian Fainelli --- drivers/memory/brcmstb_memc.c | 80 ++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/drivers/memory/brcmstb_memc.c b/drivers/memory/brcmstb_memc.c index 67c75e21c95e..032567dfd6e2 100644 --- a/drivers/memory/brcmstb_memc.c +++ b/drivers/memory/brcmstb_memc.c @@ -13,7 +13,14 @@ #define REG_MEMC_CNTRLR_CONFIG 0x00 #define CNTRLR_CONFIG_LPDDR4_SHIFT 5 -#define CNTRLR_CONFIG_MASK 0xf +#define CNTRLR_CONFIG_MASK GENMASK(3, 0) +#define CNTRLR_CONFIG_SIZE_SHIFT 4 +#define CNTRLR_CONFIG_SIZE_MASK GENMASK(7, 4) +#define CNTRLR_CONFIG_WIDTH_SHIFT 8 +#define CNTRLR_CONFIG_WIDTH_MASK GENMASK(9, 8) +#define CNTRLR_CONFIG_TOT_WIDTH_SHIFT 10 +#define CNTRLR_CONFIG_TOT_WIDTH_MASK GENMASK(11, 10) +#define CNTRLR_CONFIG_RANK_SHIFT 16 #define REG_MEMC_SRPD_CFG_21 0x20 #define REG_MEMC_SRPD_CFG_20 0x34 #define REG_MEMC_SRPD_CFG_1x 0x3c @@ -63,6 +70,67 @@ static int brcmstb_memc_srpd_config(struct brcmstb_memc *memc, return 0; } +static ssize_t ddr_rank_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct brcmstb_memc *memc = dev_get_drvdata(dev); + + return sprintf(buf, "%s\n", + memc->config_reg & CNTRLR_CONFIG_RANK_SHIFT ? + "dual" : "single"); +} + +static ssize_t ddr_size_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct brcmstb_memc *memc = dev_get_drvdata(dev); + u32 val = (memc->config_reg & CNTRLR_CONFIG_SIZE_MASK) >> + CNTRLR_CONFIG_SIZE_SHIFT; + + return sprintf(buf, "%dMb\n", 256 << val); +} + +static ssize_t ddr_total_width_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct brcmstb_memc *memc = dev_get_drvdata(dev); + u32 val = (memc->config_reg & CNTRLR_CONFIG_TOT_WIDTH_MASK) >> + CNTRLR_CONFIG_TOT_WIDTH_SHIFT; + + return sprintf(buf, "x%d\n", 8 << val); +} + +static ssize_t ddr_type_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct brcmstb_memc *memc = dev_get_drvdata(dev); + const char *ddr_type_to_str[] = { + "DDR2", + "DDR3", + "DDR4", + "GDDR5M", + "GDDR5", + "LPDDR4", + }; + u32 val = memc->config_reg & CNTRLR_CONFIG_MASK; + const char *type = "unknown"; + + if (val < ARRAY_SIZE(ddr_type_to_str)) + type = ddr_type_to_str[val]; + + return sprintf(buf, "%s\n", type); +} + +static ssize_t ddr_width_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct brcmstb_memc *memc = dev_get_drvdata(dev); + u32 val = (memc->config_reg & CNTRLR_CONFIG_WIDTH_MASK) >> + CNTRLR_CONFIG_WIDTH_SHIFT; + + return sprintf(buf, "x%d\n", 8 << val); +} + static ssize_t frequency_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -105,10 +173,20 @@ static ssize_t srpd_store(struct device *dev, struct device_attribute *attr, return count; } +static DEVICE_ATTR_RO(ddr_rank); +static DEVICE_ATTR_RO(ddr_size); +static DEVICE_ATTR_RO(ddr_total_width); +static DEVICE_ATTR_RO(ddr_type); +static DEVICE_ATTR_RO(ddr_width); static DEVICE_ATTR_RO(frequency); static DEVICE_ATTR_RW(srpd); static struct attribute *dev_attrs[] = { + &dev_attr_ddr_rank.attr, + &dev_attr_ddr_size.attr, + &dev_attr_ddr_total_width.attr, + &dev_attr_ddr_type.attr, + &dev_attr_ddr_width.attr, &dev_attr_frequency.attr, &dev_attr_srpd.attr, NULL,