Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp333279rwb; Wed, 9 Nov 2022 03:11:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf48TPpDvfn27JzmzfasgrfMaA/WudibBQOlNnihqdtx0C+5oAJytj0QwhjXyAlx/uu/1Qhz X-Received: by 2002:a17:906:58d2:b0:7ae:9d65:6d3 with SMTP id e18-20020a17090658d200b007ae9d6506d3mr678573ejs.12.1667992301754; Wed, 09 Nov 2022 03:11:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667992301; cv=none; d=google.com; s=arc-20160816; b=TlohJkWHf/F7xtjnMb44trIJtM3MCGgiIqi+OmD3nYJWwPCIZwVAwT/5pTv36sBBTH vQxvk3bZD7aeohtZpF8OGwJWSLpi+2vym0f0x3CRZF7YYWuWWeAb3nhRve/MsVfwG7By 4rRDizwLWh7MZrrEdcFK6mpfy8gtkjMUcbRXxecl5f81rgVbmBKXk5ZjZEluj7EzgTuo NlU1AUpu2nUSi3lss8XOo7xpb+G459IX+9/1ORxwu7v7MOEwejImTXXLVebAi6jm8SmR h/KCKEKBbmwWhTt/You51EXNTeEV8EQy/nedD1Y7gXcs+KlKzcmZ4PPK47N7mZMBqT64 tPOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject; bh=tfNu2fkM0nRbUiJ00Y96MEHmwzFm+CSNIm/yMZ3EUIQ=; b=KeMd4+mCCEg/8/8hRuhd+22LfJCZdLdb9J4VSYzJ/LX5loV6G7AI+8F+3V5xs2I/3r SENKkvHQdy7TSXp/Yos+wj6PNY7MvR/7rSlPEBOFrEOadg+mEmdvwk1M3RjSWWyCjWcp cbzF7dTo7qT0b6GMpAZJIq49uVeOhcWi2bv/WEsawgY2yaQmz00lXP+8IS/mTFA/glr8 q9DXMfDkg1nm9TT8NzfJ8qGy5mIK+kSwLsWZtdj4eiyis8dun8O/ANxDfS3HYFpINwYM WKeO7N6wq1i2qtTGgN59sqNrXpsLZgWXw9jE6EFP0DczNub4bckzrRX1vIZjPJXXJEKr +tkw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i28-20020a1709067a5c00b007add405cccdsi10374959ejo.444.2022.11.09.03.11.18; Wed, 09 Nov 2022 03:11:41 -0800 (PST) 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 S229801AbiKIKDe (ORCPT + 93 others); Wed, 9 Nov 2022 05:03:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230086AbiKIKDb (ORCPT ); Wed, 9 Nov 2022 05:03:31 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 681F960FF; Wed, 9 Nov 2022 02:03:29 -0800 (PST) Received: from loongson.cn (unknown [10.180.13.64]) by gateway (Coremail) with SMTP id _____8Dx_7fuemtjN4cFAA--.16170S3; Wed, 09 Nov 2022 18:03:26 +0800 (CST) Received: from [10.180.13.64] (unknown [10.180.13.64]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxNlfqemtjqn8PAA--.24744S2; Wed, 09 Nov 2022 18:03:23 +0800 (CST) Subject: Re: [PATCH v6 1/2] soc: loongson: add GUTS driver for loongson-2 platforms To: Rob Herring , Krzysztof Kozlowski , Arnd Bergmann , Hector Martin , Lubomir Rintel , Conor Dooley , Linus Walleij , Hitomi Hasegawa , Heiko Stuebner , Brian Norris , Sven Peter , loongarch@lists.linux.dev, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, soc@kernel.org References: <20221104024835.3570-1-zhuyinbo@loongson.cn> From: Yinbo Zhu Message-ID: <57c9f565-e75b-0c8f-fdce-9dc8c334d50f@loongson.cn> Date: Wed, 9 Nov 2022 18:03:22 +0800 User-Agent: Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20221104024835.3570-1-zhuyinbo@loongson.cn> Content-Type: text/plain; charset=gbk; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxNlfqemtjqn8PAA--.24744S2 X-CM-SenderInfo: 52kx5xhqerqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoW3tr4kXrWxJF1UtFy5GryDZFb_yoWDZFy8pa n3CayfCFWUXF47Zrn8Ja4UWFyY9ayxCasrur4xW3s8urykA347XFyxGFyUZrs7ArykA342 qF95u3yjkFW7A3DanT9S1TB71UUUUbJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bqAFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUXVWUAwA2ocxC64 kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28E F7xvwVC0I7IYx2IY6xkF7I0E14v26r4j6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr1j6rxdM2kKe7AKxVWUtVW8ZwAS0I0E0xvYzxvE 52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I 80ewAv7VC0I7IYx2IY67AKxVWUtVWrXwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC 6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lc7I2V7IY0VAS07AlzVAYIcxG8wCY1x0262kKe7 AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCF04k20xvE74AGY7Cv6cx26rWl4I8I3I0E4IkC 6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jw0_GFylx2IqxVAqx4xG67AKxVWUJVWUGwC20s 026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF 0xvE2Ix0cI8IcVAFwI0_Xr0_Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0x vE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_Cr1UMIIF0xvEx4A2 jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxU4_HUDUUUU X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 Hi maintainer, This patch I had verified that base on mainline 6.1-rc3 tree, it is okay, if no other issue, please you help me merge it to upstream. Thanks, Yinbo. ?? 2022/11/4 ????10:48, Yinbo Zhu ะด??: > The global utilities block controls PCIE device enabling, alternate > function selection for multiplexed signals, consistency of HDA, USB > and PCIE, configuration of memory controller, rtc controller, lio > controller, and clock control. > > This patch adds a driver to manage and access global utilities block > for loongarch architecture Loongson-2 SoCs. Initially only reading SVR > and registering soc device are supported. Other guts accesses, such > as reading PMON configuration by default, should eventually be added > into this driver as well. > > Signed-off-by: Yinbo Zhu > Reviewed-by: Arnd Bergmann > --- > Change in v6: > 1. Add full name spelling about GUTS in Kconfig. > 2. Add reviewed-by information. > Change in v5: > 1. Add all history change log information. > Change in v4: > 1. Remove menu information in Kconfig. > Change in v3: > 1. Replace string loongson2/Loongson2 with Loongson-2/loongson-2 > in commit message, Kconfig, Makefile file. > 2. Replace string LOONGSON2 with LOONGSON-2. > Change in v2: > 1. Add architecture support commit log description. > 2. Add other guts accesses plan commit log description. > 3. Add "depends on LOONGARCH || COMPILE_TEST" for > LOONGSON2_GUTS in Kconfig. > 4. Move the scfg_guts to .c file from .h and delete .h. > 5. Remove __packed on scfg_guts. > > MAINTAINERS | 6 + > drivers/soc/Kconfig | 1 + > drivers/soc/Makefile | 1 + > drivers/soc/loongson/Kconfig | 18 +++ > drivers/soc/loongson/Makefile | 6 + > drivers/soc/loongson/loongson2_guts.c | 189 ++++++++++++++++++++++++++ > 6 files changed, 221 insertions(+) > create mode 100644 drivers/soc/loongson/Kconfig > create mode 100644 drivers/soc/loongson/Makefile > create mode 100644 drivers/soc/loongson/loongson2_guts.c > > diff --git a/MAINTAINERS b/MAINTAINERS > index c9dc5ddbd9fe..20ce056ae207 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -12041,6 +12041,12 @@ S: Maintained > F: Documentation/devicetree/bindings/pinctrl/loongson,ls2k-pinctrl.yaml > F: drivers/pinctrl/pinctrl-loongson2.c > > +LOONGSON-2 SOC SERIES GUTS DRIVER > +M: Yinbo Zhu > +L: loongarch@lists.linux.dev > +S: Maintained > +F: drivers/soc/loongson/loongson2_guts.c > + > LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI) > M: Sathya Prakash > M: Sreekanth Reddy > diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig > index e461c071189b..5dbb09f843f7 100644 > --- a/drivers/soc/Kconfig > +++ b/drivers/soc/Kconfig > @@ -13,6 +13,7 @@ source "drivers/soc/fujitsu/Kconfig" > source "drivers/soc/imx/Kconfig" > source "drivers/soc/ixp4xx/Kconfig" > source "drivers/soc/litex/Kconfig" > +source "drivers/soc/loongson/Kconfig" > source "drivers/soc/mediatek/Kconfig" > source "drivers/soc/microchip/Kconfig" > source "drivers/soc/pxa/Kconfig" > diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile > index 69ba6508cf2c..fff513bd522d 100644 > --- a/drivers/soc/Makefile > +++ b/drivers/soc/Makefile > @@ -18,6 +18,7 @@ obj-y += imx/ > obj-y += ixp4xx/ > obj-$(CONFIG_SOC_XWAY) += lantiq/ > obj-$(CONFIG_LITEX_SOC_CONTROLLER) += litex/ > +obj-y += loongson/ > obj-y += mediatek/ > obj-y += microchip/ > obj-y += pxa/ > diff --git a/drivers/soc/loongson/Kconfig b/drivers/soc/loongson/Kconfig > new file mode 100644 > index 000000000000..df52599ae87b > --- /dev/null > +++ b/drivers/soc/loongson/Kconfig > @@ -0,0 +1,18 @@ > +# SPDX-License-Identifier: GPL-2.0+ > +# > +# Loongson-2 series SoC drivers > +# > + > +config LOONGSON2_GUTS > + tristate "Loongson-2 SoC Global UtiliTieS (GUTS) register block" > + depends on LOONGARCH || COMPILE_TEST > + select SOC_BUS > + help > + The global utilities block controls PCIE device enabling, alternate > + function selection for multiplexed signals, consistency of HDA, USB > + and PCIE, configuration of memory controller, rtc controller, lio > + controller, and clock control. This patch adds a driver to manage > + and access global utilities block for loongarch architecture Loongson-2 > + SoCs. Initially only reading SVR and registering soc device are > + supported. Other guts accesses, such as reading PMON configuration by > + default, should eventually be added into this driver as well. > diff --git a/drivers/soc/loongson/Makefile b/drivers/soc/loongson/Makefile > new file mode 100644 > index 000000000000..263c486df638 > --- /dev/null > +++ b/drivers/soc/loongson/Makefile > @@ -0,0 +1,6 @@ > +# SPDX-License-Identifier: GPL-2.0+ > +# > +# Makefile for the Linux Kernel SoC Loongson-2 specific device drivers > +# > + > +obj-$(CONFIG_LOONGSON2_GUTS) += loongson2_guts.o > diff --git a/drivers/soc/loongson/loongson2_guts.c b/drivers/soc/loongson/loongson2_guts.c > new file mode 100644 > index 000000000000..8f3d5465c7e8 > --- /dev/null > +++ b/drivers/soc/loongson/loongson2_guts.c > @@ -0,0 +1,189 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Author: Yinbo Zhu > + * Copyright (C) 2022-2023 Loongson Technology Corporation Limited > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +static struct soc_device_attribute soc_dev_attr; > +static struct soc_device *soc_dev; > + > +/* > + * Global Utility Registers. > + * > + * Not all registers defined in this structure are available on all chips, so > + * you are expected to know whether a given register actually exists on your > + * chip before you access it. > + * > + * Also, some registers are similar on different chips but have slightly > + * different names. In these cases, one name is chosen to avoid extraneous > + * #ifdefs. > + */ > +struct scfg_guts { > + u32 svr; /* Version Register */ > + u8 res0[4]; > + u16 feature; /* Feature Register */ > + u32 vendor; /* Vendor Register */ > + u8 res1[6]; > + u32 id; > + u8 res2[0x3ff8 - 0x18]; > + u32 chip; > +}; > + > +static struct guts { > + struct scfg_guts __iomem *regs; > + bool little_endian; > +} *guts; > + > +struct loongson2_soc_die_attr { > + char *die; > + u32 svr; > + u32 mask; > +}; > + > +/* SoC die attribute definition for Loongson-2 platform */ > +static const struct loongson2_soc_die_attr loongson2_soc_die[] = { > + > + /* > + * LA-based SoCs Loongson-2 Series > + */ > + > + /* Die: 2k1000la, SoC: 2k1000la */ > + { .die = "2K1000LA", > + .svr = 0x00000013, > + .mask = 0x000000ff, > + }, > + { }, > +}; > + > +static const struct loongson2_soc_die_attr *loongson2_soc_die_match( > + u32 svr, const struct loongson2_soc_die_attr *matches) > +{ > + while (matches->svr) { > + if (matches->svr == (svr & matches->mask)) > + return matches; > + matches++; > + }; > + > + return NULL; > +} > + > +static u32 loongson2_guts_get_svr(void) > +{ > + u32 svr = 0; > + > + if (!guts || !guts->regs) > + return svr; > + > + if (guts->little_endian) > + svr = ioread32(&guts->regs->svr); > + else > + svr = ioread32be(&guts->regs->svr); > + > + return svr; > +} > + > +static int loongson2_guts_probe(struct platform_device *pdev) > +{ > + struct device_node *root, *np = pdev->dev.of_node; > + struct device *dev = &pdev->dev; > + struct resource *res; > + const struct loongson2_soc_die_attr *soc_die; > + const char *machine; > + u32 svr; > + > + /* Initialize guts */ > + guts = devm_kzalloc(dev, sizeof(*guts), GFP_KERNEL); > + if (!guts) > + return -ENOMEM; > + > + guts->little_endian = of_property_read_bool(np, "little-endian"); > + > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + guts->regs = ioremap(res->start, res->end - res->start + 1); > + if (IS_ERR(guts->regs)) > + return PTR_ERR(guts->regs); > + > + /* Register soc device */ > + root = of_find_node_by_path("/"); > + if (of_property_read_string(root, "model", &machine)) > + of_property_read_string_index(root, "compatible", 0, &machine); > + of_node_put(root); > + if (machine) > + soc_dev_attr.machine = devm_kstrdup(dev, machine, GFP_KERNEL); > + > + svr = loongson2_guts_get_svr(); > + soc_die = loongson2_soc_die_match(svr, loongson2_soc_die); > + if (soc_die) { > + soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, > + "Loongson %s", soc_die->die); > + } else { > + soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, "Loongson"); > + } > + if (!soc_dev_attr.family) > + return -ENOMEM; > + soc_dev_attr.soc_id = devm_kasprintf(dev, GFP_KERNEL, > + "svr:0x%08x", svr); > + if (!soc_dev_attr.soc_id) > + return -ENOMEM; > + soc_dev_attr.revision = devm_kasprintf(dev, GFP_KERNEL, "%d.%d", > + (svr >> 4) & 0xf, svr & 0xf); > + if (!soc_dev_attr.revision) > + return -ENOMEM; > + > + soc_dev = soc_device_register(&soc_dev_attr); > + if (IS_ERR(soc_dev)) > + return PTR_ERR(soc_dev); > + > + pr_info("Machine: %s\n", soc_dev_attr.machine); > + pr_info("SoC family: %s\n", soc_dev_attr.family); > + pr_info("SoC ID: %s, Revision: %s\n", > + soc_dev_attr.soc_id, soc_dev_attr.revision); > + > + return 0; > +} > + > +static int loongson2_guts_remove(struct platform_device *dev) > +{ > + soc_device_unregister(soc_dev); > + > + return 0; > +} > + > +/* > + * Table for matching compatible strings, for device tree > + * guts node, for Loongson-2 SoCs. > + */ > +static const struct of_device_id loongson2_guts_of_match[] = { > + { .compatible = "loongson,ls2k-chipid", }, > + {} > +}; > +MODULE_DEVICE_TABLE(of, loongson2_guts_of_match); > + > +static struct platform_driver loongson2_guts_driver = { > + .driver = { > + .name = "loongson2-guts", > + .of_match_table = loongson2_guts_of_match, > + }, > + .probe = loongson2_guts_probe, > + .remove = loongson2_guts_remove, > +}; > + > +static int __init loongson2_guts_init(void) > +{ > + return platform_driver_register(&loongson2_guts_driver); > +} > +core_initcall(loongson2_guts_init); > + > +static void __exit loongson2_guts_exit(void) > +{ > + platform_driver_unregister(&loongson2_guts_driver); > +} > +module_exit(loongson2_guts_exit); >