From patchwork Mon Feb 27 10:57:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Paracuellos X-Patchwork-Id: 13153180 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D639AC64ED6 for ; Mon, 27 Feb 2023 10:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbjB0K6N (ORCPT ); Mon, 27 Feb 2023 05:58:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbjB0K6M (ORCPT ); Mon, 27 Feb 2023 05:58:12 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6D529EE4; Mon, 27 Feb 2023 02:58:10 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id bv17so5737300wrb.5; Mon, 27 Feb 2023 02:58:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=tnZe77O04Wi6t00vWipQfVmBBAx1Is2ZWNAespWbpaw=; b=gMaVrmBNFyZA3PKVfkLWgfaalbAd8Iy1p5KsCpUsbm85PHastzbtDAl8dn+P55Y2/N groYWNXgCK8nz7t8AfZmBuqs9doqafgO3UCw/xy8SmtKIxcaWg0OmvVB2fyCDqqqDwNQ fFjfLswzGYYBKIZ4XFWn1ddhu6rhz6vGgmiG1738foG6NDlEbyfmRySI8TuRwknXTz4x BDUbR6S7ggOtMroz9hPVKPkiiVVrcWFyAEhCYML+HCZaR/GNaL14oFe9g3LrkPBlh3/U j2Pl9Ez6zH7ipZVs41BIyN81tEPAGN56gRzHsdQiVZjvp0/RoZZ4yMLs353NEJdIkPCY 9CLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=tnZe77O04Wi6t00vWipQfVmBBAx1Is2ZWNAespWbpaw=; b=y0BELKDvHiJ1LeHHnXDDDdPcgSu6QJITBjw+wDjb0rvlnpPNHx6IbZdkwh54W3fsEi ZjFjAHt4AJjAPFuUhAbW2znaKdm8ankPKKNX69zoGyryGLNJC1QoZSQKn4QIwAUX6ym0 vZRacu6CV2KTl4m+LbmawWJV3e2sSQbUjuZFUw//Rcs5ixal4bqYSCTPaB1BHgNNpkbC 325Wcg+ovUo+9UsahC+gM9wKS03cRRSmSlJd9bk5dX7aii3Kh4I6d4uRO66yj/+YYEDa kMG3qcp4J1xGcQqcISuRv/KtkUI7AC2ybZ3kzjohtLoBuNx274GeQXvhM+kggIOh8ChJ BVzg== X-Gm-Message-State: AO0yUKVtuqIvAipHLQKS+sCv3XcJv+ZbhT41et+ZnP5TplmqSLDMAXQ5 Hhwjdo/K131S6ImuvMAMlMXmR2xLhW4= X-Google-Smtp-Source: AK7set82GupIzkEIFy4bqPqu5a4V4MV3GEeXP9Z94MdMh3GAhpGZa6uMALcC1OuWntCgvHNphosmtA== X-Received: by 2002:adf:f247:0:b0:2c7:1e00:d514 with SMTP id b7-20020adff247000000b002c71e00d514mr11484247wrp.38.1677495489091; Mon, 27 Feb 2023 02:58:09 -0800 (PST) Received: from localhost.localdomain (106.red-88-13-29.dynamicip.rima-tde.net. [88.13.29.106]) by smtp.gmail.com with ESMTPSA id a4-20020a5d5704000000b002c559843748sm6806122wrv.10.2023.02.27.02.58.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:58:08 -0800 (PST) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, git@johnthomson.fastmail.com.au Subject: [PATCH 01/12] mips: ralink: rt305x: define RT305X_SYSC_BASE with __iomem Date: Mon, 27 Feb 2023 11:57:55 +0100 Message-Id: <20230227105806.2394101-2-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> References: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org So that RT305X_SYSC_BASE can be used later in multiple functions without needing to repeat this __iomem declaration each time Signed-off-by: Sergio Paracuellos --- arch/mips/include/asm/mach-ralink/rt305x.h | 3 ++- arch/mips/ralink/rt305x.c | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/mips/include/asm/mach-ralink/rt305x.h b/arch/mips/include/asm/mach-ralink/rt305x.h index 4d8e8c8d83ce..ef58f7bff957 100644 --- a/arch/mips/include/asm/mach-ralink/rt305x.h +++ b/arch/mips/include/asm/mach-ralink/rt305x.h @@ -43,7 +43,8 @@ static inline int soc_is_rt5350(void) return ralink_soc == RT305X_SOC_RT5350; } -#define RT305X_SYSC_BASE 0x10000000 +#define IOMEM(x) ((void __iomem *)(KSEG1ADDR(x))) +#define RT305X_SYSC_BASE IOMEM(0x10000000) #define SYSC_REG_CHIP_NAME0 0x00 #define SYSC_REG_CHIP_NAME1 0x04 diff --git a/arch/mips/ralink/rt305x.c b/arch/mips/ralink/rt305x.c index 8b095a9dcb15..135a46517763 100644 --- a/arch/mips/ralink/rt305x.c +++ b/arch/mips/ralink/rt305x.c @@ -21,11 +21,10 @@ static unsigned long rt5350_get_mem_size(void) { - void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT305X_SYSC_BASE); unsigned long ret; u32 t; - t = __raw_readl(sysc + SYSC_REG_SYSTEM_CONFIG); + t = __raw_readl(RT305X_SYSC_BASE + SYSC_REG_SYSTEM_CONFIG); t = (t >> RT5350_SYSCFG0_DRAM_SIZE_SHIFT) & RT5350_SYSCFG0_DRAM_SIZE_MASK; @@ -142,14 +141,13 @@ void __init ralink_of_remap(void) void __init prom_soc_init(struct ralink_soc_info *soc_info) { - void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT305X_SYSC_BASE); unsigned char *name; u32 n0; u32 n1; u32 id; - n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0); - n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1); + n0 = __raw_readl(RT305X_SYSC_BASE + SYSC_REG_CHIP_NAME0); + n1 = __raw_readl(RT305X_SYSC_BASE + SYSC_REG_CHIP_NAME1); if (n0 == RT3052_CHIP_NAME0 && n1 == RT3052_CHIP_NAME1) { unsigned long icache_sets; From patchwork Mon Feb 27 10:57:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Paracuellos X-Patchwork-Id: 13153181 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08D28C64ED8 for ; Mon, 27 Feb 2023 10:58:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229971AbjB0K6P (ORCPT ); Mon, 27 Feb 2023 05:58:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbjB0K6N (ORCPT ); Mon, 27 Feb 2023 05:58:13 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AC565FC3; Mon, 27 Feb 2023 02:58:12 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id l1so2679988wry.12; Mon, 27 Feb 2023 02:58:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=tHJ28rGYoNleFVDOkHjpHIMUmWDA43thW23nuYI9tAQ=; b=EK9YaRCT3GX41yW7xA+KEywd62d/Cd7kjaiaMgDyGKVCGCpmpccGv1GzezuqgCxvYv MYyIMxpt4ok71jEdzRDaAIl3ZZ/i7La22i5z7kgJSGPkBCWPa3hP5Hq0Y/eFkRRwy90h CEZdUfnZH5xkDEaOCD/bICbSng0wtPMtR/PEZxZHlObzwCE6pR7WgxBGyi40SaWmgBvw LXTgQ40vBwnwoI3PvgZnN7rgqZgTLK56i46MCDAFuKzcY/IVpOzMGHsAg7/dTKpgFMDP aku+jzeDUuurA3ykbafPss8fZFFdDFwUXMOT+IeCYyscMOfum16bW362FselW0BJl3RV +h/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=tHJ28rGYoNleFVDOkHjpHIMUmWDA43thW23nuYI9tAQ=; b=45K6gcXU5JVK/yIXSc9BAXZP39zTCw1gaDuBQiy5zKeeZjNS+cfG5xBoWXDcgaVle3 GX+eZFowHigWAlKeUckFYoocQRoyWTJ3LDnckrYxcScdgNWEIJ+WMw17CK8FuFfrQ2nM +nPQAqM3bJh7d8tGjx1pe4eXItZUUr+/hEOpIDhsR2VIoSlaIyWw4Pc35iQneLTnxAPf L7kxbByegHVW90ZdxVg+xJ2rg8551g7CODG2tTEgJ7zVxV/6ZETGC2wP36ZH4yg+UXLR P1XW+ZVtjYKlh8UBqkW/QlFM43wDmW/BPjWNAU3XtYiBXJdiP9V54Pn9h4RyvRKQt5nj 5v6Q== X-Gm-Message-State: AO0yUKVMrvIe9Ghu9vmmv6LmvVcTJZrzscpmPAei5PrThaJ19lvSc5fQ 1zRaXlsVZ/r7cydkwChd2OtC4Ao4Pvc= X-Google-Smtp-Source: AK7set9+/e6z4/dzp7NqkF3ZUUbUakHpZK3dIcLBN1vDOiD6ek9nlE8MvFlXTAoswShRkjsx0J0LZw== X-Received: by 2002:a5d:48c6:0:b0:2c5:58fc:e1bb with SMTP id p6-20020a5d48c6000000b002c558fce1bbmr21073847wrs.10.1677495490197; Mon, 27 Feb 2023 02:58:10 -0800 (PST) Received: from localhost.localdomain (106.red-88-13-29.dynamicip.rima-tde.net. [88.13.29.106]) by smtp.gmail.com with ESMTPSA id a4-20020a5d5704000000b002c559843748sm6806122wrv.10.2023.02.27.02.58.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:58:09 -0800 (PST) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, git@johnthomson.fastmail.com.au Subject: [PATCH 02/12] mips: ralink: rt305x: soc queries and tests as functions Date: Mon, 27 Feb 2023 11:57:56 +0100 Message-Id: <20230227105806.2394101-3-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> References: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Move the SoC register value queries and tests to specific functions, to remove repetition of logic. No functional changes intended Signed-off-by: Sergio Paracuellos --- arch/mips/ralink/rt305x.c | 97 +++++++++++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 20 deletions(-) diff --git a/arch/mips/ralink/rt305x.c b/arch/mips/ralink/rt305x.c index 135a46517763..a24143c739ee 100644 --- a/arch/mips/ralink/rt305x.c +++ b/arch/mips/ralink/rt305x.c @@ -139,52 +139,109 @@ void __init ralink_of_remap(void) panic("Failed to remap core resources"); } -void __init prom_soc_init(struct ralink_soc_info *soc_info) +static unsigned int __init rt305x_get_soc_name0(void) +{ + return __raw_readl(RT305X_SYSC_BASE + SYSC_REG_CHIP_NAME0); +} + +static unsigned int __init rt305x_get_soc_name1(void) { - unsigned char *name; - u32 n0; - u32 n1; - u32 id; + return __raw_readl(RT305X_SYSC_BASE + SYSC_REG_CHIP_NAME1); +} - n0 = __raw_readl(RT305X_SYSC_BASE + SYSC_REG_CHIP_NAME0); - n1 = __raw_readl(RT305X_SYSC_BASE + SYSC_REG_CHIP_NAME1); +static bool __init rt3052_soc_valid(void) +{ + if (rt305x_get_soc_name0() == RT3052_CHIP_NAME0 && + rt305x_get_soc_name1() == RT3052_CHIP_NAME1) + return true; + else + return false; +} - if (n0 == RT3052_CHIP_NAME0 && n1 == RT3052_CHIP_NAME1) { +static bool __init rt3350_soc_valid(void) +{ + if (rt305x_get_soc_name0() == RT3350_CHIP_NAME0 && + rt305x_get_soc_name1() == RT3350_CHIP_NAME1) + return true; + else + return false; +} + +static bool __init rt3352_soc_valid(void) +{ + if (rt305x_get_soc_name0() == RT3352_CHIP_NAME0 && + rt305x_get_soc_name1() == RT3352_CHIP_NAME1) + return true; + else + return false; +} + +static bool __init rt5350_soc_valid(void) +{ + if (rt305x_get_soc_name0() == RT5350_CHIP_NAME0 && + rt305x_get_soc_name1() == RT5350_CHIP_NAME1) + return true; + else + return false; +} + +static const char __init *rt305x_get_soc_name(struct ralink_soc_info *soc_info) +{ + if (rt3052_soc_valid()) { unsigned long icache_sets; icache_sets = (read_c0_config1() >> 22) & 7; if (icache_sets == 1) { ralink_soc = RT305X_SOC_RT3050; - name = "RT3050"; soc_info->compatible = "ralink,rt3050-soc"; + return "RT3050"; } else { ralink_soc = RT305X_SOC_RT3052; - name = "RT3052"; soc_info->compatible = "ralink,rt3052-soc"; + return "RT3052"; } - } else if (n0 == RT3350_CHIP_NAME0 && n1 == RT3350_CHIP_NAME1) { + } else if (rt3350_soc_valid()) { ralink_soc = RT305X_SOC_RT3350; - name = "RT3350"; soc_info->compatible = "ralink,rt3350-soc"; - } else if (n0 == RT3352_CHIP_NAME0 && n1 == RT3352_CHIP_NAME1) { + return "RT3350"; + } else if (rt3352_soc_valid()) { ralink_soc = RT305X_SOC_RT3352; - name = "RT3352"; soc_info->compatible = "ralink,rt3352-soc"; - } else if (n0 == RT5350_CHIP_NAME0 && n1 == RT5350_CHIP_NAME1) { + return "RT3352"; + } else if (rt5350_soc_valid()) { ralink_soc = RT305X_SOC_RT5350; - name = "RT5350"; soc_info->compatible = "ralink,rt5350-soc"; + return "RT5350"; } else { - panic("rt305x: unknown SoC, n0:%08x n1:%08x", n0, n1); + panic("rt305x: unknown SoC, n0:%08x n1:%08x", + rt305x_get_soc_name0(), rt305x_get_soc_name1()); } +} + +static unsigned int __init rt305x_get_soc_id(void) +{ + return __raw_readl(RT305X_SYSC_BASE + SYSC_REG_CHIP_ID); +} + +static unsigned int __init rt305x_get_soc_ver(void) +{ + return (rt305x_get_soc_id() >> CHIP_ID_ID_SHIFT) & CHIP_ID_ID_MASK; +} - id = __raw_readl(sysc + SYSC_REG_CHIP_ID); +static unsigned int __init rt305x_get_soc_rev(void) +{ + return (rt305x_get_soc_id() & CHIP_ID_REV_MASK); +} + +void __init prom_soc_init(struct ralink_soc_info *soc_info) +{ + const char *name = rt305x_get_soc_name(soc_info); snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN, "Ralink %s id:%u rev:%u", name, - (id >> CHIP_ID_ID_SHIFT) & CHIP_ID_ID_MASK, - (id & CHIP_ID_REV_MASK)); + rt305x_get_soc_ver(), + rt305x_get_soc_rev()); soc_info->mem_base = RT305X_SDRAM_BASE; if (soc_is_rt5350()) { From patchwork Mon Feb 27 10:57:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Paracuellos X-Patchwork-Id: 13153182 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A9BEC7EE2D for ; Mon, 27 Feb 2023 10:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229817AbjB0K6R (ORCPT ); Mon, 27 Feb 2023 05:58:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230059AbjB0K6O (ORCPT ); Mon, 27 Feb 2023 05:58:14 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E969CCA37; Mon, 27 Feb 2023 02:58:12 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id t15so5728593wrz.7; Mon, 27 Feb 2023 02:58:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=kfZlvyD8rTZQbpQrkIlLlvAbU21XIuea0Ob/RtnHs1U=; b=kif3rjC5DZzlITC9ZiIlLLV1GPEFuq0QTF4KSI0Pap7DXwFdqaW0rTfovI/5Y99mzT Yt+TbxPB+blULAQNX3feY4zpOdFl2aK5lbsxmXcXOP8Z+0J5u+il/lP4iRXWXd4GxK3N GuUr8ZCoztrHQdovCqWGLWgRfdATvAKh8BkJAKiZoZTq/lwewdbcvRjNB3w5hPQaablF mAfT6Lq7jH3wCaJS4nN/2bdZny9GEpCUegYb7aS1ucnrg+8m/S7pGEq9ag0/KGHChXvw KLS9oy1N6xQZaqiM6Rm5sfWELjVnWl56Nxa+g8xZOTsuaeKsaLqGqjHEeenlkwWjileC 1oOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=kfZlvyD8rTZQbpQrkIlLlvAbU21XIuea0Ob/RtnHs1U=; b=Vs/kuNGd046+aQ/fcCvQ2ssztVz6SCJRmB6IvP3w+nBtB2MVtL0sGmyPPWuUKN6DrD U7trAyTaZ+EXu0vHDPITI+Wt7jVvpeHgIDsGlrdtZejq7enzutyIPQttmQQA4oVy4rT7 IebLT761Ryqk1+iXSqWrGX1HL5gl/uWALgiZ72s8PKPqmER61EP/+tZAe4VN4IhVY64k JM1iAvqqTDgw1OfexJaN2Rs8EzA6arn1Nm0J0iOybFjuHLMGj8UbkA7Lct40V5pyu9jU PAHlDe5KRkoS08BEAV59T+BHUqN1GJRik19khqX0PaIYipJoL9IMuaxMVQijDhmydU+9 NirQ== X-Gm-Message-State: AO0yUKVCt8t/uvD/VEsKwFICOms1uzvyVCiWmDrOdjuo2PWWxFfj8Mlu l1x9eBOgHjoYVfQ1Ez/xLGYSmMmqajM= X-Google-Smtp-Source: AK7set/yOo+O4Atmx3ogx4palFZ4WkH53bAEddE4+yuzkAbiT1njKJ9z0G5mtmVx8ef5JkPjeaBJUg== X-Received: by 2002:adf:e58f:0:b0:2c5:a07e:4bb6 with SMTP id l15-20020adfe58f000000b002c5a07e4bb6mr20110631wrm.33.1677495491221; Mon, 27 Feb 2023 02:58:11 -0800 (PST) Received: from localhost.localdomain (106.red-88-13-29.dynamicip.rima-tde.net. [88.13.29.106]) by smtp.gmail.com with ESMTPSA id a4-20020a5d5704000000b002c559843748sm6806122wrv.10.2023.02.27.02.58.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:58:10 -0800 (PST) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, git@johnthomson.fastmail.com.au Subject: [PATCH 03/12] mips: ralink: rt305x: introduce 'soc_device' initialization Date: Mon, 27 Feb 2023 11:57:57 +0100 Message-Id: <20230227105806.2394101-4-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> References: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org RT305x SoCs have their own 'ralink_soc_info' structure with some information about the soc itself. In order to be able to retrieve this information from driver code and avoid architecture dependencies for retrieving these details introduce this 'soc_device'. Set 'data' pointer points to the struct 'ralink_soc_info' to be able to export also current soc information using this mechanism. We need to select 'SOC_BUS' in Kconfig configuration for these SoCs. Signed-off-by: Sergio Paracuellos --- arch/mips/ralink/Kconfig | 1 + arch/mips/ralink/rt305x.c | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig index 06031796c87b..658e12b34ccc 100644 --- a/arch/mips/ralink/Kconfig +++ b/arch/mips/ralink/Kconfig @@ -32,6 +32,7 @@ choice config SOC_RT305X bool "RT305x" + select SOC_BUS config SOC_RT3883 bool "RT3883" diff --git a/arch/mips/ralink/rt305x.c b/arch/mips/ralink/rt305x.c index a24143c739ee..d8dcc5cc66cc 100644 --- a/arch/mips/ralink/rt305x.c +++ b/arch/mips/ralink/rt305x.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include @@ -19,6 +21,8 @@ #include "common.h" +static struct ralink_soc_info *soc_info_ptr; + static unsigned long rt5350_get_mem_size(void) { unsigned long ret; @@ -233,6 +237,46 @@ static unsigned int __init rt305x_get_soc_rev(void) return (rt305x_get_soc_id() & CHIP_ID_REV_MASK); } +static const char __init *rt305x_get_soc_id_name(void) +{ + if (soc_is_rt3050()) + return "rt3050"; + else if (soc_is_rt3052()) + return "rt3052"; + else if (soc_is_rt3350()) + return "rt3350"; + else if (soc_is_rt3352()) + return "rt3352"; + else if (soc_is_rt5350()) + return "rt5350"; + else + return "invalid"; +} + +static int __init rt305x_soc_dev_init(void) +{ + struct soc_device *soc_dev; + struct soc_device_attribute *soc_dev_attr; + + soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); + if (!soc_dev_attr) + return -ENOMEM; + + soc_dev_attr->family = "Ralink"; + soc_dev_attr->soc_id = rt305x_get_soc_id_name(); + + soc_dev_attr->data = soc_info_ptr; + + soc_dev = soc_device_register(soc_dev_attr); + if (IS_ERR(soc_dev)) { + kfree(soc_dev_attr); + return PTR_ERR(soc_dev); + } + + return 0; +} +device_initcall(rt305x_soc_dev_init); + void __init prom_soc_init(struct ralink_soc_info *soc_info) { const char *name = rt305x_get_soc_name(soc_info); @@ -253,4 +297,6 @@ void __init prom_soc_init(struct ralink_soc_info *soc_info) soc_info->mem_size_min = RT3352_MEM_SIZE_MIN; soc_info->mem_size_max = RT3352_MEM_SIZE_MAX; } + + soc_info_ptr = soc_info; } From patchwork Mon Feb 27 10:57:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Paracuellos X-Patchwork-Id: 13153183 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3EBCC64ED6 for ; Mon, 27 Feb 2023 10:58:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230086AbjB0K6S (ORCPT ); Mon, 27 Feb 2023 05:58:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230025AbjB0K6P (ORCPT ); Mon, 27 Feb 2023 05:58:15 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ACC9EB54; Mon, 27 Feb 2023 02:58:14 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id l25so5743642wrb.3; Mon, 27 Feb 2023 02:58:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=q66bHBctBFwEmexbcNsZu9cAPfXaFAcm9g/elou8jLA=; b=Xpgb9y8iqSWjnhj+rVJyKp+DC9qju+tBwbsyml1lWuUdzchm8yoV7Rb5E6WymIpjOQ 5h2PYNVcBxHRo8GDrcNDNs3rCbrtx147rxajFPpgCWy4g5bPq7QtMWIg/VoeXrh+h+dP BC8u3IVaj9Mq8TdUB4vu3M7rSGviM2GehrHw0S8NOr7DksC483B9ui51ejMQes/vwtQl oj2w3Dw1Kjt3GelIam/yASEiYsDeJl3k96PlxnKO6aN8bJNQyGltP4PZcBTGgvT4dL5+ r1xt7l3aWOCSla56cqJ32dcWgEH06HlPEi264qmNswEust4aSMaE0zaUFsD+HJihGYsl KFag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=q66bHBctBFwEmexbcNsZu9cAPfXaFAcm9g/elou8jLA=; b=BebraczbNfGGnAMYAme7w4vScdbX4na4Zbnx2CEPpLxCpn8aKx9TKQYSjfVTXFNA6h gBOfY54e33GztPju/e762nWJaS/ZO5wc+E8vdZNgeI6dL0Ea0G2Sdfbt0+mtTuixIRt8 JcGB6yCHypt22LN3gUioAB7q3/S+oHRMM+3JNeJFF2dEjuzJ4/dXmOWQKE02gjX67kl2 A2mA1w2E1gbpTT0JecEVYEa+6+fY2mPrh21JukfXgF4q8ZbSdfLrtPa2uOVNudgAtncS 5hdVYsfEfdkXFmLJ9vx2PnNasjUDj8f5UyVP2JvFsN+LqV+9JxvXIeGpF9eAtCAnKdPN 2kjQ== X-Gm-Message-State: AO0yUKWIK8xa9byYrcmPeKnGkwe6/AR5clKryhg/cBWs+Um2cndv66WY VHpaiCWEwaqlmi0VocLAgF9o2vk5Z3Y= X-Google-Smtp-Source: AK7set8t+Y0N56zWcxYuaD+Nq5bTRsi71w9WAwKD4Jr4NgczEakae7DPbS/8kgLuqHbpAag4lwfdYA== X-Received: by 2002:a5d:604a:0:b0:2c7:16c3:175e with SMTP id j10-20020a5d604a000000b002c716c3175emr9900360wrt.64.1677495492145; Mon, 27 Feb 2023 02:58:12 -0800 (PST) Received: from localhost.localdomain (106.red-88-13-29.dynamicip.rima-tde.net. [88.13.29.106]) by smtp.gmail.com with ESMTPSA id a4-20020a5d5704000000b002c559843748sm6806122wrv.10.2023.02.27.02.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:58:11 -0800 (PST) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, git@johnthomson.fastmail.com.au Subject: [PATCH 04/12] mips: ralink: rt3883: define RT3883_SYSC_BASE with __iomem Date: Mon, 27 Feb 2023 11:57:58 +0100 Message-Id: <20230227105806.2394101-5-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> References: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org So that RT3883_SYSC_BASE can be used later in multiple functions without needing to repeat this __iomem declaration each time Signed-off-by: Sergio Paracuellos --- arch/mips/include/asm/mach-ralink/rt3883.h | 4 +++- arch/mips/ralink/rt3883.c | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/mips/include/asm/mach-ralink/rt3883.h b/arch/mips/include/asm/mach-ralink/rt3883.h index f250de9c055b..ad25d5e8d2dc 100644 --- a/arch/mips/include/asm/mach-ralink/rt3883.h +++ b/arch/mips/include/asm/mach-ralink/rt3883.h @@ -10,8 +10,10 @@ #include +#define IOMEM(x) ((void __iomem *)(KSEG1ADDR(x))) + #define RT3883_SDRAM_BASE 0x00000000 -#define RT3883_SYSC_BASE 0x10000000 +#define RT3883_SYSC_BASE IOMEM(0x10000000) #define RT3883_TIMER_BASE 0x10000100 #define RT3883_INTC_BASE 0x10000200 #define RT3883_MEMC_BASE 0x10000300 diff --git a/arch/mips/ralink/rt3883.c b/arch/mips/ralink/rt3883.c index d9875f146d66..fa215c07558d 100644 --- a/arch/mips/ralink/rt3883.c +++ b/arch/mips/ralink/rt3883.c @@ -72,15 +72,14 @@ void __init ralink_of_remap(void) void __init prom_soc_init(struct ralink_soc_info *soc_info) { - void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT3883_SYSC_BASE); const char *name; u32 n0; u32 n1; u32 id; - n0 = __raw_readl(sysc + RT3883_SYSC_REG_CHIPID0_3); - n1 = __raw_readl(sysc + RT3883_SYSC_REG_CHIPID4_7); - id = __raw_readl(sysc + RT3883_SYSC_REG_REVID); + n0 = __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_CHIPID0_3); + n1 = __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_CHIPID4_7); + id = __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_REVID); if (n0 == RT3883_CHIP_NAME0 && n1 == RT3883_CHIP_NAME1) { soc_info->compatible = "ralink,rt3883-soc"; From patchwork Mon Feb 27 10:57:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Paracuellos X-Patchwork-Id: 13153184 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63F7DC64ED8 for ; Mon, 27 Feb 2023 10:58:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230116AbjB0K6T (ORCPT ); Mon, 27 Feb 2023 05:58:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230050AbjB0K6P (ORCPT ); Mon, 27 Feb 2023 05:58:15 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA5E615CAB; Mon, 27 Feb 2023 02:58:14 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id az36so3966357wmb.1; Mon, 27 Feb 2023 02:58:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=i9SGqf47sYexP4KDD8i5u1pt87QH5U1h+xP3iiJeOMw=; b=HFIqa8q05zIgTCCwkryZi+hCLVkH/xf9Bxogc+r4MkJyv6T8wLfUNv3ZcQOMpLJEfk H3fi+mzu3ucuJVmW23xRnYXtVXcAScE0Lzw6lYf8SfyT4stI7Y9XSVqFV8rX3Zxg/OH8 tdskHzTbWkd1BT5mBKyRLe7d0vrBC8JZxMvbJUzE6Hv51G/6Cq22azMocNVT/V2IL9ji Inr/4zvbec/ZP90nqZ3SqoTjb8nhjSpgpBwMG4m5KHCP2CS9XYWAch7Nu0wYhQT2gkH8 La6eibI2m+HtjawvSRgMhET+dGB+UL7yx6pfsys/E2nAbGX/C7aAkQKHMHdQFcqh5XhL MzqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=i9SGqf47sYexP4KDD8i5u1pt87QH5U1h+xP3iiJeOMw=; b=xJoquucfLW/yhdf+oz2c2Jm+TQi/3KvO+IkjvfMGJSn5jaC7fyBP4wtvpSEJsgdW0S VGNjiavUXWrx2VHbw6e9IZ3QCDOu9uQW3Qujl0PBxhQ783G20D0D83cCqft/IEHH6pDU 0RIX36tHDCrFD/lfdErpO8REvIeYsO77JHjP9VmJKIrJAst5MkcHMqra+syKwcEnAuZz bMdFeqAsLvChv4NCaGHyY5KBLeHvCO+gcfdHajy+w33ItIm1wr3Sy/8YEmEUb8UDlEVF 5pEda5JcKnHowuZ78aNmrIKejPqml+JHNmUlpm7a97qbJ9XPfZ7V/d9vcaR9BNidzc+g CpPQ== X-Gm-Message-State: AO0yUKU6LtB25u/G6QZUcALsQQZjoKoKPIXoc+jZmJCm/oexJ7rkEhCR JWl5W5vUi5AsAlpgt0bmoyxE+aIxSuQ= X-Google-Smtp-Source: AK7set+oYRbWSTwvKo+nrUvfnVrD0G8X4blNmedmw1BBYNPEMarlzxAVjFSjnPMIQAMaBbwdWyAZSg== X-Received: by 2002:a05:600c:44d3:b0:3da:fc30:bfc5 with SMTP id f19-20020a05600c44d300b003dafc30bfc5mr17749497wmo.13.1677495493031; Mon, 27 Feb 2023 02:58:13 -0800 (PST) Received: from localhost.localdomain (106.red-88-13-29.dynamicip.rima-tde.net. [88.13.29.106]) by smtp.gmail.com with ESMTPSA id a4-20020a5d5704000000b002c559843748sm6806122wrv.10.2023.02.27.02.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:58:12 -0800 (PST) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, git@johnthomson.fastmail.com.au Subject: [PATCH 05/12] mips: ralink: rt3883: soc queries and tests as functions Date: Mon, 27 Feb 2023 11:57:59 +0100 Message-Id: <20230227105806.2394101-6-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> References: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Move the SoC register value queries and tests to specific functions, to remove repetition of logic. No functional changes intended Signed-off-by: Sergio Paracuellos --- arch/mips/ralink/rt3883.c | 64 +++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/arch/mips/ralink/rt3883.c b/arch/mips/ralink/rt3883.c index fa215c07558d..6f8541a4bc8e 100644 --- a/arch/mips/ralink/rt3883.c +++ b/arch/mips/ralink/rt3883.c @@ -70,29 +70,61 @@ void __init ralink_of_remap(void) panic("Failed to remap core resources"); } -void __init prom_soc_init(struct ralink_soc_info *soc_info) +static unsigned int __init rt3883_get_soc_name0(void) +{ + return __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_CHIPID0_3); +} + +static unsigned int __init rt3883_get_soc_name1(void) +{ + return __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_CHIPID4_7); +} + +static bool __init rt3883_soc_valid(void) +{ + if (rt3883_get_soc_name0() == RT3883_CHIP_NAME0 && + rt3883_get_soc_name1() == RT3883_CHIP_NAME1) + return true; + else + return false; +} + +static const char __init *rt3883_get_soc_name(void) +{ + if (rt3883_soc_valid()) + return "RT3883"; + else + return "invalid"; +} + +static unsigned int __init rt3883_get_soc_id(void) { - const char *name; - u32 n0; - u32 n1; - u32 id; + return __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_REVID); +} - n0 = __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_CHIPID0_3); - n1 = __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_CHIPID4_7); - id = __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_REVID); +static unsigned int __init rt3883_get_soc_ver(void) +{ + return (rt3883_get_soc_id() >> RT3883_REVID_VER_ID_SHIFT) & RT3883_REVID_VER_ID_MASK; +} - if (n0 == RT3883_CHIP_NAME0 && n1 == RT3883_CHIP_NAME1) { +static unsigned int __init rt3883_get_soc_rev(void) +{ + return (rt3883_get_soc_id() & RT3883_REVID_ECO_ID_MASK); +} + +void __init prom_soc_init(struct ralink_soc_info *soc_info) +{ + if (rt3883_soc_valid()) soc_info->compatible = "ralink,rt3883-soc"; - name = "RT3883"; - } else { - panic("rt3883: unknown SoC, n0:%08x n1:%08x", n0, n1); - } + else + panic("rt3883: unknown SoC, n0:%08x n1:%08x", + rt3883_get_soc_name0(), rt3883_get_soc_name1()); snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN, "Ralink %s ver:%u eco:%u", - name, - (id >> RT3883_REVID_VER_ID_SHIFT) & RT3883_REVID_VER_ID_MASK, - (id & RT3883_REVID_ECO_ID_MASK)); + rt3883_get_soc_name(), + rt3883_get_soc_ver(), + rt3883_get_soc_rev()); soc_info->mem_base = RT3883_SDRAM_BASE; soc_info->mem_size_min = RT3883_MEM_SIZE_MIN; From patchwork Mon Feb 27 10:58:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Paracuellos X-Patchwork-Id: 13153185 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B8E8C64ED6 for ; Mon, 27 Feb 2023 10:58:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230136AbjB0K6Y (ORCPT ); Mon, 27 Feb 2023 05:58:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230071AbjB0K6R (ORCPT ); Mon, 27 Feb 2023 05:58:17 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E470CBBA4; Mon, 27 Feb 2023 02:58:15 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id h14so5736855wru.4; Mon, 27 Feb 2023 02:58:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=kdLIQJlJWnELjON9nBGeYOy/CiIIUc1Jm+enmEwgejU=; b=Si7wHOgxp7FKgb9sqtCU1ATOpyTMrA1JejnS6/GufE3c0dXf/ZfUdByyAeIn6RjlHQ D+XpFSaQSRB25ckaKlcYMvYcRHJH3gG8MvNzrsazoOQppT4QCjcpIScWMBV/r6brqBY6 D+N5tgu9Xqg25Vr1S4kLm0yP1ARusLMwD3AR4FF18mPypZO6BgrMgNh9LyVZSRFDaQqM P8g8fx1LJTW3luvJcwWIjWVRzCWpyvNhrBMGNK+kW3gZLkz7mxWNtSf18BBC6lIgojTU Hq+vGV4Fw2e6qAzyhXofOa/azwN98tEPjMWwmkIMPoBTCzBUlfVoKZE+GtXdU/mGXJg+ kTPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=kdLIQJlJWnELjON9nBGeYOy/CiIIUc1Jm+enmEwgejU=; b=xK/ORg/PhaTN3/OpvvTtq2ZwrXGLWUQFhI0K31Pjal9V7q/xDvA4a/F631hUp+xiZc Cq/2T2iT7gZfNVmbERnhYaSyCsT6zFGMWfhhbKtKM9y0yRaCwqxCzj9Ak1YhbWCd2j9V 9wsD55WiODAOjhgkbQhS8S3CPKUPceVcASWZ2gJCUrALMmWITgKaGBCrL79hIS+Tv+0y xx4SvSH8iPefSU7ge+6QooGm1aDNuXNvzOKZJ/AVcuJEhCh97mSsevp0JgD9E5vrSY0v CFMPsa4l9fF+uCNTZZo2R71hgOEKqzHKJEpgEQlxL9AxNGIo/6T6SrPboM3vIpVvGNT+ 4UIA== X-Gm-Message-State: AO0yUKVFxUnYv7iV90W4pFJqbVTXjdEXMRmHRKdaToZtA5PjAd/Bz0xW O6fSBRN6G6dZiuwlrMZjUYowgC667aQ= X-Google-Smtp-Source: AK7set8Wy5J+ZaIXb1rYxVW9GugSr/pTe4HJ7WJLll4S3vSID4GqvvUPBFWuO+dCDpSgEtUJWY5lPQ== X-Received: by 2002:a05:6000:1287:b0:2c7:a39:6e2e with SMTP id f7-20020a056000128700b002c70a396e2emr15365864wrx.15.1677495493991; Mon, 27 Feb 2023 02:58:13 -0800 (PST) Received: from localhost.localdomain (106.red-88-13-29.dynamicip.rima-tde.net. [88.13.29.106]) by smtp.gmail.com with ESMTPSA id a4-20020a5d5704000000b002c559843748sm6806122wrv.10.2023.02.27.02.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:58:13 -0800 (PST) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, git@johnthomson.fastmail.com.au Subject: [PATCH 06/12] mips: ralink: rt3883: introduce 'soc_device' initialization Date: Mon, 27 Feb 2023 11:58:00 +0100 Message-Id: <20230227105806.2394101-7-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> References: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org RT3883 SoC have its own 'ralink_soc_info' structure with some information about the soc itself. In order to be able to retrieve this information from driver code and avoid architecture dependencies for retrieving these details introduce this 'soc_device'. Set 'data' pointer points to the struct 'ralink_soc_info' to be able to export also current soc information using this mechanism. We need to select 'SOC_BUS' in Kconfig configuration for these SoCs. Signed-off-by: Sergio Paracuellos --- arch/mips/ralink/Kconfig | 1 + arch/mips/ralink/rt3883.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig index 658e12b34ccc..f657e55b10b7 100644 --- a/arch/mips/ralink/Kconfig +++ b/arch/mips/ralink/Kconfig @@ -37,6 +37,7 @@ choice config SOC_RT3883 bool "RT3883" select HAVE_PCI + select SOC_BUS config SOC_MT7620 bool "MT7620/8" diff --git a/arch/mips/ralink/rt3883.c b/arch/mips/ralink/rt3883.c index 6f8541a4bc8e..cca887af378f 100644 --- a/arch/mips/ralink/rt3883.c +++ b/arch/mips/ralink/rt3883.c @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include @@ -17,6 +19,8 @@ #include "common.h" +static struct ralink_soc_info *soc_info_ptr; + void __init ralink_clk_init(void) { unsigned long cpu_rate, sys_rate; @@ -112,6 +116,30 @@ static unsigned int __init rt3883_get_soc_rev(void) return (rt3883_get_soc_id() & RT3883_REVID_ECO_ID_MASK); } +static int __init rt3883_soc_dev_init(void) +{ + struct soc_device *soc_dev; + struct soc_device_attribute *soc_dev_attr; + + soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); + if (!soc_dev_attr) + return -ENOMEM; + + soc_dev_attr->family = "Ralink"; + soc_dev_attr->soc_id = rt3883_get_soc_name(); + + soc_dev_attr->data = soc_info_ptr; + + soc_dev = soc_device_register(soc_dev_attr); + if (IS_ERR(soc_dev)) { + kfree(soc_dev_attr); + return PTR_ERR(soc_dev); + } + + return 0; +} +device_initcall(rt3883_soc_dev_init); + void __init prom_soc_init(struct ralink_soc_info *soc_info) { if (rt3883_soc_valid()) @@ -131,4 +159,5 @@ void __init prom_soc_init(struct ralink_soc_info *soc_info) soc_info->mem_size_max = RT3883_MEM_SIZE_MAX; ralink_soc = RT3883_SOC; + soc_info_ptr = soc_info; } From patchwork Mon Feb 27 10:58:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Paracuellos X-Patchwork-Id: 13153187 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DAA7C7EE31 for ; Mon, 27 Feb 2023 10:58:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229749AbjB0K6Z (ORCPT ); Mon, 27 Feb 2023 05:58:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229944AbjB0K6S (ORCPT ); Mon, 27 Feb 2023 05:58:18 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97449CA37; Mon, 27 Feb 2023 02:58:16 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id h14so5736883wru.4; Mon, 27 Feb 2023 02:58:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=job8OjNMmgGAToT54F6bhg5jAGzIyUdmtqvbHKYK1dE=; b=Dq5nTkrv4NsOu2ZhEiH1eT4O+XdbX5EPH3rS+KF0eEt3F/81ZXxFmNFQOVZSALlAbq KU95NDES7wkBgmUbjb9L2pypbQEQvxcdzXecOKm9UWRgfX0VIhkyu80qHvsyCIvVLV4K vJ/FGhO9baaKJlebaeWrSy1VxmyGE3QifeWyG1gsA+jDFjKmUQiPg59SHa+UQWqoSIfa HzvEUCH9W3bzthq9VohIkQlC2KnVbw8hkrGPxW+JCaWpnsC3coovH82rka3IW/OiQHws ERWZwoDxByiQzvBAIn83vg2mSZJWNucimNzaAU28m12qTF11a3vVsZlYBf+MMmk14PM+ hX6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=job8OjNMmgGAToT54F6bhg5jAGzIyUdmtqvbHKYK1dE=; b=XegnYYCYggxx4JefFIEekLRz4DyNSQcE26LenCniAgNuYqbYbsYBYYAzmV1fKAw5Lb RoRncQZAVTxvr46VL5rwN1lPPKeJJ3a3GHRMC5PhtNXjRfTqXczfJKS9UCjFqYXIvUzS o790suGamS/OLx5FwaY+fb4dkTBEsa4zBUhkmubGBAH0kgcbxHdD1+XUa6TFpJ5QZcSb LzDP55MRlLRdV9dLr+zS6QjNZiwF7HDWKdsnFsg0vheAL1upqHz4Gt5JMRgtjRPvU9OG fwwz6w6LxzXrPSxMGz52cdSGI3n31uK7AMO9dN4+b/ieA5RILMoog01hmKaDvlhE0UV4 Iypg== X-Gm-Message-State: AO0yUKVmKiMKbOUFUofWoT8JIY+Ju2f0s65mUDEmoshZ+A0pBWzqZ07r S8cM36mI6Mogpz4U8FR7GOiibtVVG7g= X-Google-Smtp-Source: AK7set/Svomg/t/SIOSOkAXql0lxaZjxzyOXD3Ly6NJKJ/Y6mqXBwLAxQg50AYQ4UYRc/GAOLNwgiw== X-Received: by 2002:adf:eacd:0:b0:2c7:107c:e172 with SMTP id o13-20020adfeacd000000b002c7107ce172mr11744605wrn.41.1677495494879; Mon, 27 Feb 2023 02:58:14 -0800 (PST) Received: from localhost.localdomain (106.red-88-13-29.dynamicip.rima-tde.net. [88.13.29.106]) by smtp.gmail.com with ESMTPSA id a4-20020a5d5704000000b002c559843748sm6806122wrv.10.2023.02.27.02.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:58:14 -0800 (PST) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, git@johnthomson.fastmail.com.au Subject: [PATCH 07/12] mips: ralink: rt288x: define RT2880_SYSC_BASE with __iomem Date: Mon, 27 Feb 2023 11:58:01 +0100 Message-Id: <20230227105806.2394101-8-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> References: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org So that RT2880_SYSC_BASE can be used later in multiple functions without needing to repeat this __iomem declaration each time Signed-off-by: Sergio Paracuellos --- arch/mips/include/asm/mach-ralink/rt288x.h | 3 ++- arch/mips/ralink/rt288x.c | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/mips/include/asm/mach-ralink/rt288x.h b/arch/mips/include/asm/mach-ralink/rt288x.h index 5f213534f0f5..66a999cd1d80 100644 --- a/arch/mips/include/asm/mach-ralink/rt288x.h +++ b/arch/mips/include/asm/mach-ralink/rt288x.h @@ -11,7 +11,8 @@ #ifndef _RT288X_REGS_H_ #define _RT288X_REGS_H_ -#define RT2880_SYSC_BASE 0x00300000 +#define IOMEM(x) ((void __iomem *)(KSEG1ADDR(x))) +#define RT2880_SYSC_BASE IOMEM(0x00300000) #define SYSC_REG_CHIP_NAME0 0x00 #define SYSC_REG_CHIP_NAME1 0x04 diff --git a/arch/mips/ralink/rt288x.c b/arch/mips/ralink/rt288x.c index 493335db2fe1..12f339138c4c 100644 --- a/arch/mips/ralink/rt288x.c +++ b/arch/mips/ralink/rt288x.c @@ -59,15 +59,14 @@ void __init ralink_of_remap(void) void __init prom_soc_init(struct ralink_soc_info *soc_info) { - void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT2880_SYSC_BASE); const char *name; u32 n0; u32 n1; u32 id; - n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0); - n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1); - id = __raw_readl(sysc + SYSC_REG_CHIP_ID); + n0 = __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME0); + n1 = __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME1); + id = __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_ID); if (n0 == RT2880_CHIP_NAME0 && n1 == RT2880_CHIP_NAME1) { soc_info->compatible = "ralink,r2880-soc"; From patchwork Mon Feb 27 10:58:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Paracuellos X-Patchwork-Id: 13153186 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF4C2C7EE2E for ; Mon, 27 Feb 2023 10:58:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229794AbjB0K6Z (ORCPT ); Mon, 27 Feb 2023 05:58:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230107AbjB0K6T (ORCPT ); Mon, 27 Feb 2023 05:58:19 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7881BDE7; Mon, 27 Feb 2023 02:58:17 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id bt28so5724382wrb.8; Mon, 27 Feb 2023 02:58:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=pyFswsU5blBWB3R8zkCeMIKub72woh5mwnj70Smv9S8=; b=WrKoEYCRoiuoijz+5EgwT0GCDCgA7OStrdV3smFUHQPZHv89J9KydYSzFCcjbWc3ST rWKZNxQ9M8HXJ/7V4vjSou7rLCtQB3oK+u+I+Eszd4VmqmpfrmIMYnYe0Y5VZOP5sPqS N/m774P7238e0xWhOp7Oys5nMIc3HGnCla9xlYT2MDb0NFcfEWApHmLF7knEPSmizOtO BFd9KoeDqhFkzWmNmlEKvpWr82nbI+5RhDPGvaTm+/O9qA4j06K+GQ6YkP3ulflPART/ p+MNtPZt6cH70sca6IszV+jkXWftMpacM15tQSW/S6sSODBevCcBnQ1B9jqlxW6srYrD TFpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=pyFswsU5blBWB3R8zkCeMIKub72woh5mwnj70Smv9S8=; b=vfnNAfpHhbkp87viNB8GPAerV3nYV1Evt2QcLo4bVdPaCUoDMg7OkvjMyTF/xn1aRv Pmq8d/TDPD+/1X9bOK/12gAJvSXBEjDY5XFHC3EKS51QaG91zSsbdTpPFU3vt29Xccp2 Kmk94Eru44Uz1JCaYdWXHTWZ7fNYliaAEhPyrD4Zb/kDXur9MpzeLwWnRbcaWgrWDY0L 4/d1Rh6e/+qHT1Gvksv2vDG2gepZBAomH2SSssbDzuyyVWugJj5PYJ5YXPF0CTesVSCu aW+RK+iTzXRBgoyhsxnFO5f8jONjVC1wSwuyPb/BVJCl/mv9Q75Sp9Go3VRdTTODm2GG GYbg== X-Gm-Message-State: AO0yUKUOGAjMyWjLcxbD5qO6cKFn0tHbBeEtn7zB4rkdEd4c29kdAia2 pE2GTOejlmxUhaIhdRoJo4dEmUWMseg= X-Google-Smtp-Source: AK7set8W+WXc2c87wsDTU/HXsC15zg5hCg8ENARRT4BNpGiiUHo3pe+POJV3qnHoycIS8E2ogV0srQ== X-Received: by 2002:adf:dd4e:0:b0:2c7:148c:b054 with SMTP id u14-20020adfdd4e000000b002c7148cb054mr12471021wrm.29.1677495495851; Mon, 27 Feb 2023 02:58:15 -0800 (PST) Received: from localhost.localdomain (106.red-88-13-29.dynamicip.rima-tde.net. [88.13.29.106]) by smtp.gmail.com with ESMTPSA id a4-20020a5d5704000000b002c559843748sm6806122wrv.10.2023.02.27.02.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:58:15 -0800 (PST) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, git@johnthomson.fastmail.com.au Subject: [PATCH 08/12] mips: ralink: rt288x: soc queries and tests as functions Date: Mon, 27 Feb 2023 11:58:02 +0100 Message-Id: <20230227105806.2394101-9-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> References: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Move the SoC register value queries and tests to specific functions, to remove repetition of logic. No functional changes intended Signed-off-by: Sergio Paracuellos --- arch/mips/ralink/rt288x.c | 63 +++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/arch/mips/ralink/rt288x.c b/arch/mips/ralink/rt288x.c index 12f339138c4c..a417b8b89b94 100644 --- a/arch/mips/ralink/rt288x.c +++ b/arch/mips/ralink/rt288x.c @@ -57,29 +57,60 @@ void __init ralink_of_remap(void) panic("Failed to remap core resources"); } -void __init prom_soc_init(struct ralink_soc_info *soc_info) +static unsigned int __init rt2880_get_soc_name0(void) { - const char *name; - u32 n0; - u32 n1; - u32 id; + return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME0); +} - n0 = __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME0); - n1 = __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME1); - id = __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_ID); +static unsigned int __init rt2880_get_soc_name1(void) +{ + return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME1); +} - if (n0 == RT2880_CHIP_NAME0 && n1 == RT2880_CHIP_NAME1) { +static bool __init rt2880_soc_valid(void) +{ + if (rt2880_get_soc_name0() == RT2880_CHIP_NAME0 && + rt2880_get_soc_name1() == RT2880_CHIP_NAME1) + return true; + else + return false; +} + +static const char __init *rt2880_get_soc_name(void) +{ + if (rt2880_soc_valid()) + return "RT2880"; + else + return "invalid"; +} + +static unsigned int __init rt2880_get_soc_id(void) +{ + return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_ID); +} + +static unsigned int __init rt2880_get_soc_ver(void) +{ + return (rt2880_get_soc_id() >> CHIP_ID_ID_SHIFT) & CHIP_ID_ID_MASK; +} + +static unsigned int __init rt2880_get_soc_rev(void) +{ + return (rt2880_get_soc_id() & CHIP_ID_REV_MASK); +} +void __init prom_soc_init(struct ralink_soc_info *soc_info) +{ + if (rt2880_soc_valid()) soc_info->compatible = "ralink,r2880-soc"; - name = "RT2880"; - } else { - panic("rt288x: unknown SoC, n0:%08x n1:%08x", n0, n1); - } + else + panic("rt288x: unknown SoC, n0:%08x n1:%08x", + rt2880_get_soc_name0(), rt2880_get_soc_name1()); snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN, "Ralink %s id:%u rev:%u", - name, - (id >> CHIP_ID_ID_SHIFT) & CHIP_ID_ID_MASK, - (id & CHIP_ID_REV_MASK)); + rt2880_get_soc_name(), + rt2880_get_soc_ver(), + rt2880_get_soc_rev()); soc_info->mem_base = RT2880_SDRAM_BASE; soc_info->mem_size_min = RT2880_MEM_SIZE_MIN; From patchwork Mon Feb 27 10:58:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Paracuellos X-Patchwork-Id: 13153188 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66C2EC64ED6 for ; Mon, 27 Feb 2023 10:58:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230150AbjB0K61 (ORCPT ); Mon, 27 Feb 2023 05:58:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbjB0K6W (ORCPT ); Mon, 27 Feb 2023 05:58:22 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2259199DC; Mon, 27 Feb 2023 02:58:18 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id v16so2929834wrn.0; Mon, 27 Feb 2023 02:58:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=S+BgnLruvamK2++KZsoFKmP2nKS18Ke5ejpmduGAEa8=; b=bsA9jGbaN8/IzJibEXpIpiU+I4jQ5MyTYNC5aKwo5JfsIU+U+UpYJkku4o75VITbfT ztIb5Gt7dd3veZMIBVrtHFRL5U68PzSuNGSGf2lo1InFqhgU19onwegovG3b95B9eV0y QYhE/dUY2xQvT6LYHaQzIJWhAgnZNMKKAuRbGpISLFJLdhbMGgY0YUjCemXH9KkOgGbH 2G7qMOHCT6Aj+ZJZwml/a3UjFgmE99SF/k4/qaZmXajqVJBIe82pYjQbtsHluxO7vq6l 9qUeC5enc6s54FrGL6i9I3h2G//xTCIcsNdMbKwKYuFyhQRMDBOb1gbidWZGzBO4f/Sf ov5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=S+BgnLruvamK2++KZsoFKmP2nKS18Ke5ejpmduGAEa8=; b=Ao3EKhMqdjtOb/lK93CTfSO7F9CR73BDrOpHqAQ+fuiLk69ueWgXinMXc2jRXjF5Wf hT/IcSaEM6TjK5fHkPviT8OVWjQv7biu8qzQRYiLO9Yrj3tkf3j0VvHfY41ekArMt3fz 0A5inTBffaLoESpAJKCX97pZnjp6gNiEmHkGK00FX6sHK5yZ5WU747QXSyyATaV6/Hdj dSB78543jPJvW/iDjK/E41Xw44OZFl681XTyAqPrOOz/nMVp5vnevepBCHe/S3DnDNje aQZ8jrI3/YMgPvI3odr6Bg1W61wCsHnEWKbHG8hkEpr1dlEZgp7Uui6YPOdx0FN7ztzD sJ2g== X-Gm-Message-State: AO0yUKU5K+iv7BVcWUjlrqF0O2QmE5rl8y1/JcLXf79GXixhcBUNmRDU J7Hmj4R/+Tw+DmMJo9APR9aaF4DVDbI= X-Google-Smtp-Source: AK7set+0++ntSAzlqXozngN8qg3LJc/I6BmsBNjR85BiuQQzSfrPyYT4TaQ1bK1QsbwF9A9+M88qAw== X-Received: by 2002:adf:f0cd:0:b0:2c7:d75:373a with SMTP id x13-20020adff0cd000000b002c70d75373amr14358125wro.1.1677495496839; Mon, 27 Feb 2023 02:58:16 -0800 (PST) Received: from localhost.localdomain (106.red-88-13-29.dynamicip.rima-tde.net. [88.13.29.106]) by smtp.gmail.com with ESMTPSA id a4-20020a5d5704000000b002c559843748sm6806122wrv.10.2023.02.27.02.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:58:16 -0800 (PST) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, git@johnthomson.fastmail.com.au Subject: [PATCH 09/12] mips: ralink: rt288x: introduce 'soc_device' initialization Date: Mon, 27 Feb 2023 11:58:03 +0100 Message-Id: <20230227105806.2394101-10-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> References: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org RT288X SoCs have their own 'ralink_soc_info' structure with some information about the soc itself. In order to be able to retrieve this information from driver code and avoid architecture dependencies for retrieving these details introduce this 'soc_device'. Set 'data' pointer points to the struct 'ralink_soc_info' to be able to export also current soc information using this mechanism. We need to select 'SOC_BUS' in Kconfig configuration for these SoCs. Signed-off-by: Sergio Paracuellos --- arch/mips/ralink/Kconfig | 1 + arch/mips/ralink/rt288x.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig index f657e55b10b7..3e01e2df96b0 100644 --- a/arch/mips/ralink/Kconfig +++ b/arch/mips/ralink/Kconfig @@ -29,6 +29,7 @@ choice select MIPS_AUTO_PFN_OFFSET select MIPS_L1_CACHE_SHIFT_4 select HAVE_PCI + select SOC_BUS config SOC_RT305X bool "RT305x" diff --git a/arch/mips/ralink/rt288x.c b/arch/mips/ralink/rt288x.c index a417b8b89b94..456ba0b2599e 100644 --- a/arch/mips/ralink/rt288x.c +++ b/arch/mips/ralink/rt288x.c @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include @@ -17,6 +19,8 @@ #include "common.h" +static struct ralink_soc_info *soc_info_ptr; + void __init ralink_clk_init(void) { unsigned long cpu_rate, wmac_rate = 40000000; @@ -98,6 +102,31 @@ static unsigned int __init rt2880_get_soc_rev(void) { return (rt2880_get_soc_id() & CHIP_ID_REV_MASK); } + +static int __init rt2880_soc_dev_init(void) +{ + struct soc_device *soc_dev; + struct soc_device_attribute *soc_dev_attr; + + soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); + if (!soc_dev_attr) + return -ENOMEM; + + soc_dev_attr->family = "Ralink"; + soc_dev_attr->soc_id = rt2880_get_soc_name(); + + soc_dev_attr->data = soc_info_ptr; + + soc_dev = soc_device_register(soc_dev_attr); + if (IS_ERR(soc_dev)) { + kfree(soc_dev_attr); + return PTR_ERR(soc_dev); + } + + return 0; +} +device_initcall(rt2880_soc_dev_init); + void __init prom_soc_init(struct ralink_soc_info *soc_info) { if (rt2880_soc_valid()) @@ -117,4 +146,5 @@ void __init prom_soc_init(struct ralink_soc_info *soc_info) soc_info->mem_size_max = RT2880_MEM_SIZE_MAX; ralink_soc = RT2880_SOC; + soc_info_ptr = soc_info; } From patchwork Mon Feb 27 10:58:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Paracuellos X-Patchwork-Id: 13153189 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29855C64ED8 for ; Mon, 27 Feb 2023 10:59:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229975AbjB0K6d (ORCPT ); Mon, 27 Feb 2023 05:58:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230118AbjB0K6X (ORCPT ); Mon, 27 Feb 2023 05:58:23 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73D7E1B572; Mon, 27 Feb 2023 02:58:19 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id q16so5750438wrw.2; Mon, 27 Feb 2023 02:58:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=brrg22pJXALLuqjwL3ofKoGSohLv11kyaas+ufZNm48=; b=RIhWaol/uA/GNrRqyAErinRj1oB4C/GL0DLtY0DOT2EJ+VVYsUi/YSlfPHNlwGpN1x FGP8CNWcKOnQjKERksMLpDjk0u+4UGV3ExIzToMCsEKTR5Maapq5t4cXkvxT9iYSWLAG ritysr5OvqfRTuwE97V4/8yaRrBWX06n11KuQtEz/Dd9IJCLwReXZ9HZtn+2PwYU76+f O7ACNKJl2yFoFOnKoFtQ/KhGM94bTFMP9i5HLXWkgSe/L/M5Fpq2uumH747ryXgM9B4g dG5k5YpxI7VmMcb/m6md6KDLFFSc/We4MJCGDadidjJ8li4dxHUJGINPO5G8youlnUD1 QphA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=brrg22pJXALLuqjwL3ofKoGSohLv11kyaas+ufZNm48=; b=bY+RwKuCz7eFPQu60J5atcamzns9BRkQmRsqgsNu3ZR33sn2pqk3IauVo3itX+qlgr f12AwV+C7ScrO1UEnou01px36fWZtZeAojI488qgHon0uxk7t2632meMXlvzvbdM+KFf c+8VcP3URM71xmXOCubzTZGgYWkUkPkuCaliIhbyIzbbUvUAcNMjYiUFlyEP35GmjKcm 9HOlBLyZr/lQGbtjoR/UvICUJNNzm9XJx04wHnWI11st1vr2EVuF2zaEs4uNxYeKIf4P VtGCfORvWMmbtAxtqPbolHEc6viQbZOjs/U9G9pRtEM8F9ANEawE/NyqGdrUdFIJxv0v dOAQ== X-Gm-Message-State: AO0yUKV3XtGBBqZ79RK6X+4Dct8xWxOr8PNELzWoXfrkM+j+bFkNb5pK hmoWhV6QaTkSttWw9wV0VH1UWLonLY4= X-Google-Smtp-Source: AK7set9lNcxC/d4NqXiCLUZzcfLrT9s1IijfjXJOsnnvvduAq/nlWLBWs9mgyUZbl/vGDvggQC29FA== X-Received: by 2002:adf:dd45:0:b0:2c7:a55:bef5 with SMTP id u5-20020adfdd45000000b002c70a55bef5mr14150209wrm.23.1677495497782; Mon, 27 Feb 2023 02:58:17 -0800 (PST) Received: from localhost.localdomain (106.red-88-13-29.dynamicip.rima-tde.net. [88.13.29.106]) by smtp.gmail.com with ESMTPSA id a4-20020a5d5704000000b002c559843748sm6806122wrv.10.2023.02.27.02.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:58:17 -0800 (PST) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, git@johnthomson.fastmail.com.au Subject: [PATCH 10/12] mips: ralink: mt7620: define MT7620_SYSC_BASE with __iomem Date: Mon, 27 Feb 2023 11:58:04 +0100 Message-Id: <20230227105806.2394101-11-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> References: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org So that MT7620_SYSC_BASE can be used later in multiple functions without needing to repeat this __iomem declaration each time Signed-off-by: Sergio Paracuellos --- arch/mips/include/asm/mach-ralink/mt7620.h | 3 ++- arch/mips/ralink/mt7620.c | 15 +++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/mips/include/asm/mach-ralink/mt7620.h b/arch/mips/include/asm/mach-ralink/mt7620.h index d51dfad8f543..3e37705ea9cf 100644 --- a/arch/mips/include/asm/mach-ralink/mt7620.h +++ b/arch/mips/include/asm/mach-ralink/mt7620.h @@ -11,7 +11,8 @@ #ifndef _MT7620_REGS_H_ #define _MT7620_REGS_H_ -#define MT7620_SYSC_BASE 0x10000000 +#define IOMEM(x) ((void __iomem *)(KSEG1ADDR(x))) +#define MT7620_SYSC_BASE IOMEM(0x10000000) #define SYSC_REG_CHIP_NAME0 0x00 #define SYSC_REG_CHIP_NAME1 0x04 diff --git a/arch/mips/ralink/mt7620.c b/arch/mips/ralink/mt7620.c index ae1fa0391c88..c13b73b6ee3f 100644 --- a/arch/mips/ralink/mt7620.c +++ b/arch/mips/ralink/mt7620.c @@ -326,7 +326,6 @@ mt7628_dram_init(struct ralink_soc_info *soc_info) void __init prom_soc_init(struct ralink_soc_info *soc_info) { - void __iomem *sysc = (void __iomem *) KSEG1ADDR(MT7620_SYSC_BASE); unsigned char *name = NULL; u32 n0; u32 n1; @@ -336,9 +335,9 @@ void __init prom_soc_init(struct ralink_soc_info *soc_info) u32 pmu1; u32 bga; - n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0); - n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1); - rev = __raw_readl(sysc + SYSC_REG_CHIP_REV); + n0 = __raw_readl(MT7620_SYSC_BASE + SYSC_REG_CHIP_NAME0); + n1 = __raw_readl(MT7620_SYSC_BASE + SYSC_REG_CHIP_NAME1); + rev = __raw_readl(MT7620_SYSC_BASE + SYSC_REG_CHIP_REV); bga = (rev >> CHIP_REV_PKG_SHIFT) & CHIP_REV_PKG_MASK; if (n0 == MT7620_CHIP_NAME0 && n1 == MT7620_CHIP_NAME1) { @@ -352,7 +351,7 @@ void __init prom_soc_init(struct ralink_soc_info *soc_info) soc_info->compatible = "ralink,mt7620n-soc"; } } else if (n0 == MT7620_CHIP_NAME0 && n1 == MT7628_CHIP_NAME1) { - u32 efuse = __raw_readl(sysc + SYSC_REG_EFUSE_CFG); + u32 efuse = __raw_readl(MT7620_SYSC_BASE + SYSC_REG_EFUSE_CFG); if (efuse & EFUSE_MT7688) { ralink_soc = MT762X_SOC_MT7688; @@ -372,7 +371,7 @@ void __init prom_soc_init(struct ralink_soc_info *soc_info) (rev >> CHIP_REV_VER_SHIFT) & CHIP_REV_VER_MASK, (rev & CHIP_REV_ECO_MASK)); - cfg0 = __raw_readl(sysc + SYSC_REG_SYSTEM_CONFIG0); + cfg0 = __raw_readl(MT7620_SYSC_BASE + SYSC_REG_SYSTEM_CONFIG0); if (is_mt76x8()) { dram_type = cfg0 & DRAM_TYPE_MT7628_MASK; } else { @@ -388,8 +387,8 @@ void __init prom_soc_init(struct ralink_soc_info *soc_info) else mt7620_dram_init(soc_info); - pmu0 = __raw_readl(sysc + PMU0_CFG); - pmu1 = __raw_readl(sysc + PMU1_CFG); + pmu0 = __raw_readl(MT7620_SYSC_BASE + PMU0_CFG); + pmu1 = __raw_readl(MT7620_SYSC_BASE + PMU1_CFG); pr_info("Analog PMU set to %s control\n", (pmu0 & PMU_SW_SET) ? ("sw") : ("hw")); From patchwork Mon Feb 27 10:58:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Paracuellos X-Patchwork-Id: 13153191 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 351ADC64ED8 for ; Mon, 27 Feb 2023 10:59:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229572AbjB0K7D (ORCPT ); Mon, 27 Feb 2023 05:59:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230139AbjB0K6Y (ORCPT ); Mon, 27 Feb 2023 05:58:24 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D57812BF8; Mon, 27 Feb 2023 02:58:20 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id j2so5715324wrh.9; Mon, 27 Feb 2023 02:58:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=sUV9hLKOdU18pBMiDrMjFGutWffcfv1IB6gkYAwpmlw=; b=Ur6w/ahwqv/lj3FjKNGY7RbDcan7PvkgloTbDyYRRh1gpj8KzbA6Cmb/d4LIRKLjUs MJineUYEOjpaR6vbOXl5TblUDJfBPY+BiNhXfhK6B1aoZimRLaXWLFjzRtf6UlnGn+lM IB9kUKCSF7RpIaG2//IlpXEh+ZaMkaTBdDKylIyBlhFFJgy1Zpk4PAAYTaxWy5ku7Ly4 Lrb8VHOmhzoDVpr6cIND+rwszj80mOfEy1qelMInJv8ynnDmDCZyRqsFSp4c4aI2zEFd NAglJ5HfohCpioezXfvPVgytrnC/+pdsf5FNcamWme1fJ3C7+GlMzQuhn0ARd1knGz4Q os0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=sUV9hLKOdU18pBMiDrMjFGutWffcfv1IB6gkYAwpmlw=; b=6G92hDgRd5sGLbVa90gbh40znFX/kMZuI2G7DtoMnSITVk4STCZn+EoQNZr0SHdudC HrA1fnKm5UmOcYVsdBBIoOGrXnTKfWfulk8HBTT9QG6U7YvN4C03HL+slQG9ijS9gYGd miiCDQY5jM5ASly6vGO3FTJDTChm9xUmDMkgdLpCQPvKDsO3YeiASTHIxqoGAbVpdzBQ ss4Ta12V70g5pRUiU9f0Gf1dDl0SZk+0kOe0QCldX81vlwn9raqeGmRgFuTNE3SDnaaO NGQ3V46/8+p5onzsveCM6rCiISacb4oSR+C+v7ujHoWEx9HrS4EKy9wWJG7A8PbYUzyF mx8Q== X-Gm-Message-State: AO0yUKVb9ceEVAwH+5mkElZ7Tml/kz31VFbEOhNEqycJkClvttbTcwkg 2JoUQJKZqBFlNKBKbHef8hRuxadHhxA= X-Google-Smtp-Source: AK7set8vQA/DiJ5hLWxIEZq7BZ30IrR4eJYp1TCY+Wu0F8k/8RowI0djS8gFJDaDzVXUm2sEo1/Nrg== X-Received: by 2002:adf:fbc8:0:b0:2c5:5ff8:93e5 with SMTP id d8-20020adffbc8000000b002c55ff893e5mr18944881wrs.44.1677495498702; Mon, 27 Feb 2023 02:58:18 -0800 (PST) Received: from localhost.localdomain (106.red-88-13-29.dynamicip.rima-tde.net. [88.13.29.106]) by smtp.gmail.com with ESMTPSA id a4-20020a5d5704000000b002c559843748sm6806122wrv.10.2023.02.27.02.58.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:58:18 -0800 (PST) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, git@johnthomson.fastmail.com.au Subject: [PATCH 11/12] mips: ralink: mt7620: soc queries and tests as functions Date: Mon, 27 Feb 2023 11:58:05 +0100 Message-Id: <20230227105806.2394101-12-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> References: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Move the SoC register value queries and tests to specific functions, to remove repetition of logic. No functional changes intended Signed-off-by: Sergio Paracuellos --- arch/mips/ralink/mt7620.c | 94 ++++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 22 deletions(-) diff --git a/arch/mips/ralink/mt7620.c b/arch/mips/ralink/mt7620.c index c13b73b6ee3f..8604d91f3375 100644 --- a/arch/mips/ralink/mt7620.c +++ b/arch/mips/ralink/mt7620.c @@ -324,34 +324,76 @@ mt7628_dram_init(struct ralink_soc_info *soc_info) } } -void __init prom_soc_init(struct ralink_soc_info *soc_info) +static unsigned int __init mt7620_get_soc_name0(void) { - unsigned char *name = NULL; - u32 n0; - u32 n1; - u32 rev; - u32 cfg0; - u32 pmu0; - u32 pmu1; - u32 bga; + return __raw_readl(MT7620_SYSC_BASE + SYSC_REG_CHIP_NAME0); +} + +static unsigned int __init mt7620_get_soc_name1(void) +{ + return __raw_readl(MT7620_SYSC_BASE + SYSC_REG_CHIP_NAME1); +} + +static bool __init mt7620_soc_valid(void) +{ + if (mt7620_get_soc_name0() == MT7620_CHIP_NAME0 && + mt7620_get_soc_name1() == MT7620_CHIP_NAME1) + return true; + else + return false; +} + +static bool __init mt7628_soc_valid(void) +{ + if (mt7620_get_soc_name0() == MT7620_CHIP_NAME0 && + mt7620_get_soc_name1() == MT7628_CHIP_NAME1) + return true; + else + return false; +} - n0 = __raw_readl(MT7620_SYSC_BASE + SYSC_REG_CHIP_NAME0); - n1 = __raw_readl(MT7620_SYSC_BASE + SYSC_REG_CHIP_NAME1); - rev = __raw_readl(MT7620_SYSC_BASE + SYSC_REG_CHIP_REV); - bga = (rev >> CHIP_REV_PKG_SHIFT) & CHIP_REV_PKG_MASK; +static unsigned int __init mt7620_get_rev(void) +{ + return __raw_readl(MT7620_SYSC_BASE + SYSC_REG_CHIP_REV); +} + +static unsigned int __init mt7620_get_bga(void) +{ + return (mt7620_get_rev() >> CHIP_REV_PKG_SHIFT) & CHIP_REV_PKG_MASK; +} + +static unsigned int __init mt7620_get_efuse(void) +{ + return __raw_readl(MT7620_SYSC_BASE + SYSC_REG_EFUSE_CFG); +} + +static unsigned int __init mt7620_get_soc_ver(void) +{ + return (mt7620_get_rev() >> CHIP_REV_VER_SHIFT) & CHIP_REV_VER_MASK; +} + +static unsigned int __init mt7620_get_soc_eco(void) +{ + return (mt7620_get_rev() & CHIP_REV_ECO_MASK); +} + +static const char __init *mt7620_get_soc_name(struct ralink_soc_info *soc_info) +{ + if (mt7620_soc_valid()) { + u32 bga = mt7620_get_bga(); - if (n0 == MT7620_CHIP_NAME0 && n1 == MT7620_CHIP_NAME1) { if (bga) { ralink_soc = MT762X_SOC_MT7620A; - name = "MT7620A"; soc_info->compatible = "ralink,mt7620a-soc"; + return "MT7620A"; } else { ralink_soc = MT762X_SOC_MT7620N; - name = "MT7620N"; soc_info->compatible = "ralink,mt7620n-soc"; + return "MT7620N"; } - } else if (n0 == MT7620_CHIP_NAME0 && n1 == MT7628_CHIP_NAME1) { - u32 efuse = __raw_readl(MT7620_SYSC_BASE + SYSC_REG_EFUSE_CFG); + } else if (mt7628_soc_valid()) { + u32 efuse = mt7620_get_efuse(); + unsigned char *name = NULL; if (efuse & EFUSE_MT7688) { ralink_soc = MT762X_SOC_MT7688; @@ -361,15 +403,23 @@ void __init prom_soc_init(struct ralink_soc_info *soc_info) name = "MT7628AN"; } soc_info->compatible = "ralink,mt7628an-soc"; + return name; } else { - panic("mt762x: unknown SoC, n0:%08x n1:%08x\n", n0, n1); + panic("mt762x: unknown SoC, n0:%08x n1:%08x\n", + mt7620_get_soc_name0(), mt7620_get_soc_name1()); } +} + +void __init prom_soc_init(struct ralink_soc_info *soc_info) +{ + const char *name = mt7620_get_soc_name(soc_info); + u32 cfg0; + u32 pmu0; + u32 pmu1; snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN, "MediaTek %s ver:%u eco:%u", - name, - (rev >> CHIP_REV_VER_SHIFT) & CHIP_REV_VER_MASK, - (rev & CHIP_REV_ECO_MASK)); + name, mt7620_get_soc_ver(), mt7620_get_soc_eco()); cfg0 = __raw_readl(MT7620_SYSC_BASE + SYSC_REG_SYSTEM_CONFIG0); if (is_mt76x8()) { From patchwork Mon Feb 27 10:58:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Paracuellos X-Patchwork-Id: 13153190 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF6B0C7EE37 for ; Mon, 27 Feb 2023 10:59:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230281AbjB0K7B (ORCPT ); Mon, 27 Feb 2023 05:59:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbjB0K6Z (ORCPT ); Mon, 27 Feb 2023 05:58:25 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7155D10AAE; Mon, 27 Feb 2023 02:58:21 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id l7-20020a05600c4f0700b003e79fa98ce1so3559817wmq.2; Mon, 27 Feb 2023 02:58:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=LUIj51PNz0xKbBS1KQE1NGFBEuNj+zGXmUx8EwDrEEo=; b=TJYUtDgqq9fjYccEW/VNEByBE9lmodlqJVkF6UoDUTECzXGQdVxmSRkGnC4sgATJ3C OpV7BIvpnGMbb7e69N6ba26mdPG9o4UWaAMeMFP2M3c7urK3w3RT4ftZBgAHY1V+DMIL 90aS0fgh3JohfkogcQBFi2Kt1DY36wNdY9iOzRZ31CUkyzQUPnOEeNrFkdr7ka54XUaM /lZ/W9DlOkXM50U25a06s5tX4JAh5Ns5MfDkuDmNC2zWOc7ZgXQJHYBppp5RdzzqQzqe EL2rlrcA8QcuAJ6JpAQOpbNh5q4gGhhrZ1/sGnin3kTYE7H/Ixh1OpS0h6FtvSQLqwNs NSnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=LUIj51PNz0xKbBS1KQE1NGFBEuNj+zGXmUx8EwDrEEo=; b=18PhZNM2JKTkS/imc+fwP4Icb9490dJYlWjPDcXIMJTSq8hvuPk0cTGOzdgUdvMeCR 7Ma0pJTxVzgMYd49b3V6AWeBzRY9CoZ1bfpFMcYVZ5bGl7qeEe9SSXCcsye4FvRdXdyj ZIViPWG2/Q9+mAywtdzBKxS6BufswwBFsddlL674h268vaIpVtiDEZXPJw8kQXjUONdV t/eWrpt2ZaTnpvZvq76mXe/BQeDKpWx6uQQcQPSJHDzRKpoC9t1B6RTOpu7lYTkzrlSM SuAhTov+6dBUX9nLKRpprZwcGaxFfw4L6GPzXTFEzBVCvIjklC8eJGXiX7AIzY+otZ4g yGNw== X-Gm-Message-State: AO0yUKV5zaTt/40pIH9i7PCG7AXJI7Fol1kyeWlpQBs1oQjjEiADwC10 UWVGm25s3s9Hszu31V1XThmJbllWpiI= X-Google-Smtp-Source: AK7set8P3IPV4EDc0sawNE5O19VB7XhcUX9DCeoL6NHPAEmlnNulXRB7DJzxpQ1Nlmp34Q5Xp35isg== X-Received: by 2002:a05:600c:19cb:b0:3eb:4cb5:e13 with SMTP id u11-20020a05600c19cb00b003eb4cb50e13mr386314wmq.31.1677495499660; Mon, 27 Feb 2023 02:58:19 -0800 (PST) Received: from localhost.localdomain (106.red-88-13-29.dynamicip.rima-tde.net. [88.13.29.106]) by smtp.gmail.com with ESMTPSA id a4-20020a5d5704000000b002c559843748sm6806122wrv.10.2023.02.27.02.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:58:19 -0800 (PST) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, git@johnthomson.fastmail.com.au Subject: [PATCH 12/12] mips: ralink: mt7620: introduce 'soc_device' initialization Date: Mon, 27 Feb 2023 11:58:06 +0100 Message-Id: <20230227105806.2394101-13-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> References: <20230227105806.2394101-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org MT7620 SoCs have their own 'ralink_soc_info' structure with some information about the soc itself. In order to be able to retrieve this information from driver code and avoid architecture dependencies for retrieving these details introduce this 'soc_device'. Set 'data' pointer points to the struct 'ralink_soc_info' to be able to export also current soc information using this mechanism. We need to select 'SOC_BUS' in Kconfig configuration for these SoCs. Signed-off-by: Sergio Paracuellos --- arch/mips/ralink/Kconfig | 1 + arch/mips/ralink/mt7620.c | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig index 3e01e2df96b0..088d46f16800 100644 --- a/arch/mips/ralink/Kconfig +++ b/arch/mips/ralink/Kconfig @@ -44,6 +44,7 @@ choice bool "MT7620/8" select CPU_MIPSR2_IRQ_VI select HAVE_PCI + select SOC_BUS config SOC_MT7621 bool "MT7621" diff --git a/arch/mips/ralink/mt7620.c b/arch/mips/ralink/mt7620.c index 8604d91f3375..4435f50b8d24 100644 --- a/arch/mips/ralink/mt7620.c +++ b/arch/mips/ralink/mt7620.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include @@ -49,6 +51,8 @@ /* does the board have sdram or ddram */ static int dram_type; +static struct ralink_soc_info *soc_info_ptr; + static __init u32 mt7620_calc_rate(u32 ref_rate, u32 mul, u32 div) { @@ -410,6 +414,44 @@ static const char __init *mt7620_get_soc_name(struct ralink_soc_info *soc_info) } } +static const char __init *mt7620_get_soc_id_name(void) +{ + if (ralink_soc == MT762X_SOC_MT7620A) + return "mt7620a"; + else if (ralink_soc == MT762X_SOC_MT7620N) + return "mt7620n"; + else if (ralink_soc == MT762X_SOC_MT7688) + return "mt7688"; + else if (ralink_soc == MT762X_SOC_MT7628AN) + return "mt7628n"; + else + return "invalid"; +} + +static int __init mt7620_soc_dev_init(void) +{ + struct soc_device *soc_dev; + struct soc_device_attribute *soc_dev_attr; + + soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); + if (!soc_dev_attr) + return -ENOMEM; + + soc_dev_attr->family = "Ralink"; + soc_dev_attr->soc_id = mt7620_get_soc_id_name(); + + soc_dev_attr->data = soc_info_ptr; + + soc_dev = soc_device_register(soc_dev_attr); + if (IS_ERR(soc_dev)) { + kfree(soc_dev_attr); + return PTR_ERR(soc_dev); + } + + return 0; +} +device_initcall(mt7620_soc_dev_init); + void __init prom_soc_init(struct ralink_soc_info *soc_info) { const char *name = mt7620_get_soc_name(soc_info); @@ -444,4 +486,6 @@ void __init prom_soc_init(struct ralink_soc_info *soc_info) (pmu0 & PMU_SW_SET) ? ("sw") : ("hw")); pr_info("Digital PMU set to %s control\n", (pmu1 & DIG_SW_SEL) ? ("sw") : ("hw")); + + soc_info_ptr = soc_info; }