From patchwork Wed May 22 06:23:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anson Huang X-Patchwork-Id: 10955185 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 356B6112C for ; Wed, 22 May 2019 06:23:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19E2128B2D for ; Wed, 22 May 2019 06:23:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DADB28B36; Wed, 22 May 2019 06:23:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 637EE28B2D for ; Wed, 22 May 2019 06:23:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-ID:Message-ID:Date :Subject:To:From:Reply-To:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=DZDWmOByzbLy4yrj7ZAT0qd1gP+1BYB/LDbc8WmGjY0=; b=T2Qf/Hu8mezwPi OpInhUvGVg2+gT/SIRbieesrBGBUzBWzzxhOK2OZWWl4IMTct7+5PtimNrrLrInRXPNK1M0BEux+i yEsUzBSnO7h1NSUd63bgZe8yTuGI2aBr9Bv7gc4uI8QJ01uHzvrQyHoQDeLiqcjTC/sPnbGNljwfJ uXq7LHJ9Zp7e6LUAkvOJDrOhSKeE5kdrRMQupX23Hl1g/XxwVZpqncIlA87bd/k57UZdyGWmu3e2P McfLsLcEM4Sm5pQnbr8jpbh33+bSphFqqsnbo+HJ8F3PAr0NJVxJzFI8INesF9rJw6QvR7wiH+Ruv +OyjsuKdyVwz1qLTpUlQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hTKf5-0001wh-RC; Wed, 22 May 2019 06:23:39 +0000 Received: from mail-eopbgr20041.outbound.protection.outlook.com ([40.107.2.41] helo=EUR02-VE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hTKf2-0001wL-2q for linux-arm-kernel@lists.infradead.org; Wed, 22 May 2019 06:23:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=B3/yQ8WQegMzQavf9PPoPb0aqwyXQdv/VrCiEgX98s8=; b=HajHFarCcZAzSehDhlfQ8eywOfs4CQn6+ehVf2lMvu9iC70VAgN1PPiryoNTd9ayO1arROG444c7yhHTHjA5sxJ3bYXaUEes19YzTURgDVrbbCRBlYPElCUmytyuPtMejTawPm4MpJ+sw/OBXGUJVZI0VBsvOdkY/wZKdwIpnGQ= Received: from AM0PR0402MB3905.eurprd04.prod.outlook.com (52.133.37.151) by AM0PR0402MB3330.eurprd04.prod.outlook.com (52.133.47.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.20; Wed, 22 May 2019 06:23:32 +0000 Received: from AM0PR0402MB3905.eurprd04.prod.outlook.com ([fe80::b99f:920e:7f36:7af9]) by AM0PR0402MB3905.eurprd04.prod.outlook.com ([fe80::b99f:920e:7f36:7af9%5]) with mapi id 15.20.1900.020; Wed, 22 May 2019 06:23:32 +0000 From: Anson Huang To: "catalin.marinas@arm.com" , "will.deacon@arm.com" , "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , "festevam@gmail.com" , "maxime.ripard@bootlin.com" , "agross@kernel.org" , "olof@lixom.net" , "horms+renesas@verge.net.au" , "jagan@amarulasolutions.com" , "bjorn.andersson@linaro.org" , Leonard Crestez , "dinguyen@kernel.org" , "enric.balletbo@collabora.com" , Abel Vesa , "l.stach@pengutronix.de" , "robh@kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH V5 1/2] soc: imx: Add SCU SoC info driver support Thread-Topic: [PATCH V5 1/2] soc: imx: Add SCU SoC info driver support Thread-Index: AQHVEGbg2QLbsVO1oE+jxvonbRb8fg== Date: Wed, 22 May 2019 06:23:31 +0000 Message-ID: <1558505898-722-1-git-send-email-Anson.Huang@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: HK0PR01CA0056.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::20) To AM0PR0402MB3905.eurprd04.prod.outlook.com (2603:10a6:208:b::23) authentication-results: spf=none (sender IP is ) smtp.mailfrom=anson.huang@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 2adf1dce-202a-4842-0d20-08d6de7e02b2 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:AM0PR0402MB3330; x-ms-traffictypediagnostic: AM0PR0402MB3330: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2201; x-forefront-prvs: 0045236D47 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(979002)(366004)(189003)(199004)(498600001)(3846002)(2906002)(53936002)(6116002)(7416002)(66066001)(5660300002)(14454004)(476003)(2616005)(6486002)(6436002)(486006)(99286004)(36756003)(305945005)(66946007)(73956011)(26005)(6512007)(8676002)(7736002)(66556008)(110136005)(71200400001)(2501003)(81166006)(64756008)(66446008)(386003)(71190400001)(6506007)(81156014)(25786009)(66476007)(52116002)(186003)(4326008)(68736007)(50226002)(8936002)(256004)(102836004)(2201001)(86362001)(921003)(1121003)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0402MB3330; H:AM0PR0402MB3905.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: DWzGLPSK0+lF3igsmZ2YgzACU4tmaxpXvzCODEtJ88RoA5Q/yRQnM+y3oJx7A+4dnKZqx8A6lfy+KjFlebfnAxCsAHFNV2REbGQPinNrgTF3C4bC4E/S3DskhIsLKpe+AIry4jBUjpi/JAkxQl2Loywwr4xDGJURwrBa6CyAVqzFEM2AeyQEVZTPJWMUicXCHzzT4G1cAbyd+OB+Xb51MTSNsbKYqzEWjHIGNDoKVNZBfF71otxgmBPxYGTZx6P6+oUpZQwGBErkh95SrG+S3VQ8a9MeZBc5ZnWzIHq0YSJGY80k+eFAqXmRwn6LehIB9b5tWNoqaGHJjDVwpJojAtHJkXCQ6Ftf4x49qQyxLm9x4EYn/cHLq6V54EK6NHJ5GhahgSUR//7iMG88QH0K5dqGkDt/clx6uTAZy0S2mqs= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2adf1dce-202a-4842-0d20-08d6de7e02b2 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 May 2019 06:23:32.1477 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3330 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190521_232336_252589_5190E420 X-CRM114-Status: GOOD ( 19.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dl-linux-imx Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add i.MX SCU SoC info driver to support i.MX8QXP SoC, introduce driver dependency into Kconfig as CONFIG_IMX_SCU must be selected to support i.MX SCU SoC driver, also need to use platform driver model to make sure IMX_SCU driver is probed before i.MX SCU SoC driver. With this patch, SoC info can be read from sysfs: i.mx8qxp-mek# cat /sys/devices/soc0/family Freescale i.MX i.mx8qxp-mek# cat /sys/devices/soc0/soc_id 0x2 i.mx8qxp-mek# cat /sys/devices/soc0/machine Freescale i.MX8QXP MEK i.mx8qxp-mek# cat /sys/devices/soc0/revision 1.1 Signed-off-by: Anson Huang Reviewed-by: Abel Vesa --- Changes since V4: - using extern struct of_root instead of searching it again from DT; - add of_node_put() after "fsl,imx-scu" is found. --- drivers/soc/imx/Kconfig | 9 +++ drivers/soc/imx/Makefile | 1 + drivers/soc/imx/soc-imx-scu.c | 155 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 drivers/soc/imx/soc-imx-scu.c diff --git a/drivers/soc/imx/Kconfig b/drivers/soc/imx/Kconfig index d80f899..cbc1a41 100644 --- a/drivers/soc/imx/Kconfig +++ b/drivers/soc/imx/Kconfig @@ -7,4 +7,13 @@ config IMX_GPCV2_PM_DOMAINS select PM_GENERIC_DOMAINS default y if SOC_IMX7D +config IMX_SCU_SOC + bool "i.MX System Controller Unit SoC info support" + depends on IMX_SCU + select SOC_BUS + help + If you say yes here you get support for the NXP i.MX System + Controller Unit SoC info module, it will provide the SoC info + like SoC family, ID and revision etc. + endmenu diff --git a/drivers/soc/imx/Makefile b/drivers/soc/imx/Makefile index d6b529e0..ddf343d 100644 --- a/drivers/soc/imx/Makefile +++ b/drivers/soc/imx/Makefile @@ -1,3 +1,4 @@ obj-$(CONFIG_HAVE_IMX_GPC) += gpc.o obj-$(CONFIG_IMX_GPCV2_PM_DOMAINS) += gpcv2.o obj-$(CONFIG_ARCH_MXC) += soc-imx8.o +obj-$(CONFIG_IMX_SCU_SOC) += soc-imx-scu.o diff --git a/drivers/soc/imx/soc-imx-scu.c b/drivers/soc/imx/soc-imx-scu.c new file mode 100644 index 0000000..17deb4e --- /dev/null +++ b/drivers/soc/imx/soc-imx-scu.c @@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2019 NXP. + */ + +#include +#include +#include +#include +#include +#include + +#define IMX_SCU_SOC_DRIVER_NAME "imx-scu-soc" + +static struct imx_sc_ipc *soc_ipc_handle; + +struct imx_sc_msg_misc_get_soc_id { + struct imx_sc_rpc_msg hdr; + union { + struct { + u32 control; + u16 resource; + } send; + struct { + u32 id; + u16 reserved; + } resp; + } data; +} __packed; + +static u32 imx_scu_soc_id(void) +{ + struct imx_sc_msg_misc_get_soc_id msg; + struct imx_sc_rpc_msg *hdr = &msg.hdr; + int ret; + + hdr->ver = IMX_SC_RPC_VERSION; + hdr->svc = IMX_SC_RPC_SVC_MISC; + hdr->func = IMX_SC_MISC_FUNC_GET_CONTROL; + hdr->size = 3; + + msg.data.send.control = IMX_SC_C_ID; + msg.data.send.resource = IMX_SC_R_SYSTEM; + + ret = imx_scu_call_rpc(soc_ipc_handle, &msg, true); + if (ret) { + pr_err("%s: get soc info failed, ret %d\n", __func__, ret); + /* return 0 means getting revision failed */ + return 0; + } + + return msg.data.resp.id; +} + +static int imx_scu_soc_probe(struct platform_device *pdev) +{ + struct soc_device_attribute *soc_dev_attr; + struct soc_device *soc_dev; + u32 id, val; + int ret; + + /* wait i.MX SCU driver ready */ + ret = imx_scu_get_handle(&soc_ipc_handle); + if (ret) + return ret; + + soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr), + GFP_KERNEL); + if (!soc_dev_attr) + return -ENOMEM; + + soc_dev_attr->family = "Freescale i.MX"; + + ret = of_property_read_string(of_root, + "model", + &soc_dev_attr->machine); + if (ret) + return ret; + + id = imx_scu_soc_id(); + + /* format soc_id value passed from SCU firmware */ + val = id & 0x1f; + soc_dev_attr->soc_id = val ? kasprintf(GFP_KERNEL, "0x%x", val) + : "unknown"; + if (!soc_dev_attr->soc_id) + return -ENOMEM; + + /* format revision value passed from SCU firmware */ + val = (id >> 5) & 0xf; + val = (((val >> 2) + 1) << 4) | (val & 0x3); + soc_dev_attr->revision = val ? kasprintf(GFP_KERNEL, + "%d.%d", + (val >> 4) & 0xf, + val & 0xf) : "unknown"; + if (!soc_dev_attr->revision) { + ret = -ENOMEM; + goto free_soc_id; + } + + soc_dev = soc_device_register(soc_dev_attr); + if (IS_ERR(soc_dev)) { + ret = PTR_ERR(soc_dev); + goto free_revision; + } + + return 0; + +free_revision: + kfree(soc_dev_attr->revision); +free_soc_id: + kfree(soc_dev_attr->soc_id); + return ret; +} + +static struct platform_driver imx_scu_soc_driver = { + .driver = { + .name = IMX_SCU_SOC_DRIVER_NAME, + }, + .probe = imx_scu_soc_probe, +}; + +static int __init imx_scu_soc_init(void) +{ + struct platform_device *imx_scu_soc_pdev; + struct device_node *np; + int ret; + + np = of_find_compatible_node(NULL, NULL, "fsl,imx-scu"); + if (!np) + return -ENODEV; + + of_node_put(np); + + ret = platform_driver_register(&imx_scu_soc_driver); + if (ret) + return ret; + + imx_scu_soc_pdev = + platform_device_register_simple(IMX_SCU_SOC_DRIVER_NAME, + -1, + NULL, + 0); + if (IS_ERR(imx_scu_soc_pdev)) { + ret = PTR_ERR(imx_scu_soc_pdev); + goto unreg_platform_driver; + } + + return 0; + +unreg_platform_driver: + platform_driver_unregister(&imx_scu_soc_driver); + return ret; +} +device_initcall(imx_scu_soc_init);