From patchwork Thu Apr 11 06:49:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anson Huang X-Patchwork-Id: 10895147 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 AAE2B1805 for ; Thu, 11 Apr 2019 06:49:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D5C928A89 for ; Thu, 11 Apr 2019 06:49:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80EEB28C79; Thu, 11 Apr 2019 06:49:27 +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 96C8728A89 for ; Thu, 11 Apr 2019 06:49:26 +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:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=D6wu9xavSc94AR5gto16KwGs2epzoB9Wj8GwFcosGeQ=; b=lSZN5Gl+R4I6Aj 1prneD49VuTwLb6tMvFCPZezOuSB1/5Lii+oRd1Z13qSoSrS6MoGvyyKK5ljRheh7a6ing6hoq18N jytnvyvbWnP0HL1HZcoRUAh2OA6CJl48g8xTmZJ9nZCln8nskia6ZXIENK9DAtymAcIyfz0boFTIW QQqUGjOvTX8+EjR/jzB477IECJzsLl8gXTQ4/xRbaoqe1a4k4/72BHCV7DKvMJWUKDHOwf+wLMfoo Yjx0KtNWIdEGt6nh/8GqsJLXshkzyvmPXd71vUqXYDUz79LmEGKXBsqEaIM+9mkGUwnWmtFCb8UL2 W3937CKo16Ht+pAjuXiw==; 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 1hETWT-0005Lf-U8; Thu, 11 Apr 2019 06:49:21 +0000 Received: from mail-eopbgr00074.outbound.protection.outlook.com ([40.107.0.74] helo=EUR02-AM5-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hETWP-0005L4-Im for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2019 06:49:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zMxeJQENe4MxlLJvvo6BuMS5uiNKaroK0JSJ2CA8Zus=; b=OtClyIkia6W59vCd0SP9Fhd6OKQZmlkvSagIqz3oMb7mz+GujhRCjQnxkrGPcVL81aEg5dNccZJ3L6ynSgAkZ7jeSU2UppgD3REYAaPXNc+dlhcBf6tjREJWgQwGkUSik4CFsD4Afz+PiOqD6ua9DUWuRU7qz4kht6eGzenN0o0= Received: from AM6PR0402MB3911.eurprd04.prod.outlook.com (52.133.30.10) by AM6PR0402MB3910.eurprd04.prod.outlook.com (52.133.29.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1771.18; Thu, 11 Apr 2019 06:49:13 +0000 Received: from AM6PR0402MB3911.eurprd04.prod.outlook.com ([fe80::7cb2:3013:bfa9:8ddd]) by AM6PR0402MB3911.eurprd04.prod.outlook.com ([fe80::7cb2:3013:bfa9:8ddd%4]) with mapi id 15.20.1771.016; Thu, 11 Apr 2019 06:49:13 +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" , "heiko@sntech.de" , "horms+renesas@verge.net.au" , "olof@lixom.net" , Andy Gross , "bjorn.andersson@linaro.org" , "jagan@amarulasolutions.com" , "enric.balletbo@collabora.com" , "stefan.wahren@i2se.com" , "ezequiel@collabora.com" , "marc.w.gonzalez@free.fr" , "robh@kernel.org" , "l.stach@pengutronix.de" , Abel Vesa , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH 1/2] soc: imx-sc: add i.MX system controller soc driver support Thread-Topic: [PATCH 1/2] soc: imx-sc: add i.MX system controller soc driver support Thread-Index: AQHU8DKsAg9Kriz6B0mooDc33xId4w== Date: Thu, 11 Apr 2019 06:49:12 +0000 Message-ID: <1554965048-19450-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: HK0PR01CA0034.apcprd01.prod.exchangelabs.com (2603:1096:203:3e::22) To AM6PR0402MB3911.eurprd04.prod.outlook.com (2603:10a6:209:1c::10) 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: 3dad51af-f545-4b4f-e4f0-08d6be49ce6e x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600139)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:AM6PR0402MB3910; x-ms-traffictypediagnostic: AM6PR0402MB3910: x-ld-processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr x-microsoft-antispam-prvs: x-forefront-prvs: 00046D390F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(346002)(136003)(396003)(366004)(39860400002)(199004)(189003)(105586002)(2501003)(97736004)(6116002)(53936002)(5660300002)(508600001)(71190400001)(7736002)(3846002)(6436002)(25786009)(2906002)(14454004)(6486002)(305945005)(4326008)(6512007)(81156014)(186003)(52116002)(486006)(102836004)(476003)(386003)(50226002)(8676002)(2616005)(36756003)(6506007)(8936002)(256004)(71200400001)(316002)(86362001)(99286004)(2201001)(81166006)(106356001)(66066001)(110136005)(68736007)(7416002)(26005)(921003)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR0402MB3910; H:AM6PR0402MB3911.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: NllsBW0ExJCDxKzBcQLXreDHmYMks2wBwBA7sOr6rFeCKc6s0EzsFc+a8Z54GG5xtUvHLHRozUPgck/SP/eSrjGxgZsIQyYVuMb5IgoybbOBKHyqvwCtUGt8wdg4hsSJjXdpOdVrql3k0n9F/nI/oKsiElreYzY8Rwtj+aIjQ/mO7Mv8u1Jfw5tkBin8oWH9PnoVKOLjGLk8wbe3qx69KnJehbqzWylbvpYjwX2hPxux9l9B3EzVrNANiHRruRiBAepAwX8Yea8wXtoypLG9ZzZSRZz4tqS2WZTVMq7LQfD9TUo2tVpcISzEoV/bsUjLSBFEb7N4dg9ypfQbbqWVPeGt3UBehG2eSp22ciO3X2D5N5JFWL7d90+r8yfapVWJWWiLW/HUJzfdCM1Jqg6iPPLCtXXOf/Pcq4lEhR/ZZ/M= MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3dad51af-f545-4b4f-e4f0-08d6be49ce6e X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Apr 2019 06:49:12.9031 (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: AM6PR0402MB3910 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190410_234917_830871_ED8E5236 X-CRM114-Status: GOOD ( 18.83 ) 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 i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and fuse etc.. This patch adds i.MX system controller soc driver support, Linux kernel has to communicate with system controller via MU (message unit) IPC to get soc revision, uid etc.. 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 i.MX8QXP i.mx8qxp-mek# cat /sys/devices/soc0/machine Freescale i.MX8QXP MEK i.mx8qxp-mek# cat /sys/devices/soc0/revision 1.1 i.mx8qxp-mek# cat /sys/devices/soc0/soc_uid 7B64280B57AC1898 Signed-off-by: Anson Huang Reviewed-by: Abel Vesa --- drivers/soc/imx/Kconfig | 7 ++ drivers/soc/imx/Makefile | 1 + drivers/soc/imx/soc-imx-sc.c | 220 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+) create mode 100644 drivers/soc/imx/soc-imx-sc.c diff --git a/drivers/soc/imx/Kconfig b/drivers/soc/imx/Kconfig index d80f899..c902b89 100644 --- a/drivers/soc/imx/Kconfig +++ b/drivers/soc/imx/Kconfig @@ -7,4 +7,11 @@ config IMX_GPCV2_PM_DOMAINS select PM_GENERIC_DOMAINS default y if SOC_IMX7D +config IMX_SC_SOC + depends on IMX_SCU || COMPILE_TEST + tristate "i.MX System Controller SoC support" + help + If you say yes here you get support for the i.MX System + Controller SoC module. + endmenu diff --git a/drivers/soc/imx/Makefile b/drivers/soc/imx/Makefile index 506a6f3..d00606d 100644 --- a/drivers/soc/imx/Makefile +++ b/drivers/soc/imx/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_HAVE_IMX_GPC) += gpc.o obj-$(CONFIG_IMX_GPCV2_PM_DOMAINS) += gpcv2.o +obj-$(CONFIG_IMX_SC_SOC) += soc-imx-sc.o diff --git a/drivers/soc/imx/soc-imx-sc.c b/drivers/soc/imx/soc-imx-sc.c new file mode 100644 index 0000000..029d754 --- /dev/null +++ b/drivers/soc/imx/soc-imx-sc.c @@ -0,0 +1,220 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2019 NXP. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define IMX_SC_SOC_DRIVER_NAME "imx-sc-soc" + +#define SOC_REV_MAJOR_OFFSET 0x4 +#define SOC_REV_MAJOR_MASK 0xf +#define SOC_REV_MINOR_OFFSET 0x4 +#define SOC_REV_MINOR_MASK 0xf + +#define get_soc_rev_major(rev) ((rev >> SOC_REV_MAJOR_OFFSET) & SOC_REV_MAJOR_MASK) +#define get_soc_rev_minor(rev) ((rev >> SOC_REV_MINOR_OFFSET) & SOC_REV_MINOR_MASK) + +static u32 imx_sc_soc_rev = IMX_CHIP_REVISION_UNKNOWN; +static u64 imx_sc_soc_uid; + +static struct imx_sc_ipc *soc_ipc_handle; +static struct platform_device *imx_sc_soc_pdev; + +struct imx_sc_msg_misc_get_soc_id { + struct imx_sc_rpc_msg hdr; + union { + struct { + u32 control; + u16 resource; + } __packed send; + struct { + u32 id; + u16 reserved; + } __packed resp; + } data; +}; + +struct imx_sc_msg_misc_get_soc_uid { + struct imx_sc_rpc_msg hdr; + u32 id_l; + u32 id_h; +}; + +static inline void imx_sc_set_soc_revision(u32 rev) +{ + imx_sc_soc_rev = rev; +} + +unsigned int imx_get_soc_revision(void) +{ + return imx_sc_soc_rev; +} +EXPORT_SYMBOL(imx_get_soc_revision); + +static u32 imx_init_revision_from_scu(void) +{ + struct imx_sc_msg_misc_get_soc_id msg; + struct imx_sc_msg_misc_get_soc_uid msg1; + struct imx_sc_rpc_msg *hdr = &msg.hdr; + struct imx_sc_rpc_msg *hdr1 = &msg1.hdr; + u32 id, rev; + 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("misc get control failed, ret %d\n", ret); + return ret; + } + + id = msg.data.resp.id; + + rev = (id >> 5) & 0xf; + rev = (((rev >> 2) + 1) << 4) | (rev & 0x3); + + imx_sc_set_soc_revision(rev); + + hdr1->ver = IMX_SC_RPC_VERSION; + hdr1->svc = IMX_SC_RPC_SVC_MISC; + hdr1->func = IMX_SC_MISC_FUNC_UNIQUE_ID; + hdr1->size = 1; + + /* the return value of SCU FW is in correct, can NOT check the ret */ + ret = imx_scu_call_rpc(soc_ipc_handle, &msg1, true); + + imx_sc_soc_uid = msg1.id_h; + imx_sc_soc_uid <<= 32; + imx_sc_soc_uid |= msg1.id_l; + + return rev; +} + +static ssize_t imx_sc_get_soc_uid(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "%016llX\n", imx_sc_soc_uid); +} + +static struct device_attribute imx_sc_uid = + __ATTR(soc_uid, 0444, imx_sc_get_soc_uid, NULL); + +static int imx_sc_soc_probe(struct platform_device *pdev) +{ + struct soc_device_attribute *soc_dev_attr; + u32 rev = IMX_CHIP_REVISION_UNKNOWN; + struct soc_device *soc_dev; + u32 soc_rev; + int ret; + + ret = imx_scu_get_handle(&soc_ipc_handle); + if (ret) + return ret; + + soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); + if (!soc_dev_attr) + return -ENOMEM; + + soc_dev_attr->family = "Freescale i.MX"; + + if (of_machine_is_compatible("fsl,imx8qxp")) + soc_dev_attr->soc_id = "i.MX8QXP"; + else + soc_dev_attr->soc_id = "unknown"; + + rev = imx_init_revision_from_scu(); + if (rev == IMX_CHIP_REVISION_UNKNOWN) + dev_info(&pdev->dev, "CPU identified as %s, unknown revision\n", + soc_dev_attr->soc_id); + else + dev_info(&pdev->dev, "CPU identified as %s, silicon rev %d.%d\n", + soc_dev_attr->soc_id, + get_soc_rev_major(rev), + get_soc_rev_minor(rev)); + + soc_rev = imx_get_soc_revision(); + soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d", + get_soc_rev_major(rev), + get_soc_rev_minor(rev)); + if (!soc_dev_attr->revision) { + ret = -ENOMEM; + goto free_soc; + } + + of_property_read_string(of_root, "model", &soc_dev_attr->machine); + + soc_dev = soc_device_register(soc_dev_attr); + if (IS_ERR(soc_dev)) { + ret = PTR_ERR(soc_dev); + goto free_rev; + } + + ret = device_create_file(soc_device_to_device(soc_dev), &imx_sc_uid); + if (ret) + dev_err(&pdev->dev, "could not register sysfs entry\n"); + + return ret; + +free_rev: + kfree(soc_dev_attr->revision); +free_soc: + kfree(soc_dev_attr); + return ret; +} + +static struct platform_driver imx_sc_soc_driver = { + .driver = { + .name = IMX_SC_SOC_DRIVER_NAME, + }, + .probe = imx_sc_soc_probe, +}; + +static int __init imx_sc_soc_init(void) +{ + int ret; + + ret = platform_driver_register(&imx_sc_soc_driver); + if (ret) + return ret; + + imx_sc_soc_pdev = + platform_device_register_simple(IMX_SC_SOC_DRIVER_NAME, + -1, + NULL, + 0); + if (IS_ERR(imx_sc_soc_pdev)) { + ret = PTR_ERR(imx_sc_soc_pdev); + goto unreg_platform_driver; + } + + return 0; + +unreg_platform_driver: + platform_driver_unregister(&imx_sc_soc_driver); + return ret; +} + +static void __exit imx_sc_soc_exit(void) +{ + platform_device_unregister(imx_sc_soc_pdev); + platform_driver_unregister(&imx_sc_soc_driver); +} + +module_init(imx_sc_soc_init); +module_exit(imx_sc_soc_exit);