Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1196025imj; Thu, 14 Feb 2019 02:48:42 -0800 (PST) X-Google-Smtp-Source: AHgI3IZHQq6zLDUYMcMa6ciiCj+99tiqyX6hd0CYhRHjpz+8XB8mUeJpvirevN4cx+VrmGsfbWxe X-Received: by 2002:a17:902:5a8d:: with SMTP id r13mr3457442pli.190.1550141322704; Thu, 14 Feb 2019 02:48:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550141322; cv=none; d=google.com; s=arc-20160816; b=fNmjugsFwOt1rgGBUJeKUaN4HLKh0lbvVjZSCJ3vY0LDy9ch0ERO1OjHrTQ72JjVVY mDUaFx9EbvI5SJbUU88aOaEh7BfMZKA2+s5hFtRH2Y62u8j3RwyYe78LaJjFM+sSICJb j1mlXvRRg6Iv09WIqBwjPi9pYqVA1xLOKhjszI+rDSig4HOrSV6j2UsDT58KmiXn5a3/ 5yPwDCR4fJnNEUeL5pyqxXeknttUTlAq7OsZmn4jfL0HPkuKbewnWpV4CR8MHVwD3MLT 63R6OHVvaG1fvkcxnGOs5POGz+g46cZ4AnzXtpYCZ0Rke4JdPzY2U3MciTJBOkM+lfmC Vdag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=kDCwze7MSZ/0VU4jDuhIzch9cw/tNFuydaj2r0ScsoA=; b=AzXkBvvdaxm4VfPVoFAN18JE12w07Af4CK4ygEqj/qF1wR1SWxvTnBTe57Q4jx6BfZ dVZQfKZm4/LOajXibvPV8mKXoZbQpmEgYd0LZtBEj0griVAgQvD5ty4ZSCj5AH77hjP1 8xII4eFJ/nTbkwQtsJWT41AWdT+cab8K997PJ8sic5BqomLBclnrWPVCppNhHAUnk9S2 01QRXxLv1dLMXGTRlKv+KJdme9C+fraVZRCaosGCnngDA84GgApisrUwG3WFVhPUAn7L pbMsxlElby8bGE64K6IbQio769A75VsO3xxcNQVwL9G8SpchKmSi6lEqEq1aNmEhC8TW /fuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=R6Cepmj7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31si2178055plh.274.2019.02.14.02.48.26; Thu, 14 Feb 2019 02:48:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=R6Cepmj7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405273AbfBNDow (ORCPT + 99 others); Wed, 13 Feb 2019 22:44:52 -0500 Received: from mail-eopbgr20064.outbound.protection.outlook.com ([40.107.2.64]:55461 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2391237AbfBNDou (ORCPT ); Wed, 13 Feb 2019 22:44:50 -0500 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=kDCwze7MSZ/0VU4jDuhIzch9cw/tNFuydaj2r0ScsoA=; b=R6Cepmj76lRPTBD/W97uPfGUn5sQKWj1ogyKY9xaRGfNdgBcHRrzagjtkxLrqrWl/FHUMPO91OvYs2tXWBDtwFL8p+YY7bNtyU5L3th5w9N+XWko3ITv7sTAZ6VMiyVH2DoTuNTheEpIv3tbY7NyzccM8nYtCGKpmkjFy48ahqU= Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com (52.134.72.18) by DB3PR0402MB3659.eurprd04.prod.outlook.com (52.134.66.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1601.21; Thu, 14 Feb 2019 03:44:31 +0000 Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::14e8:6d2e:fe21:4fd5]) by DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::14e8:6d2e:fe21:4fd5%3]) with mapi id 15.20.1601.023; Thu, 14 Feb 2019 03:44:31 +0000 From: Anson Huang To: "robh+dt@kernel.org" , "mark.rutland@arm.com" , "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , "festevam@gmail.com" , "a.zummo@towertech.it" , "alexandre.belloni@bootlin.com" , Aisheng Dong , "ulf.hansson@linaro.org" , "sboyd@kernel.org" , Daniel Baluta , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-rtc@vger.kernel.org" CC: dl-linux-imx Subject: [PATCH V2 2/4] firmware: imx: enable imx scu general irq function Thread-Topic: [PATCH V2 2/4] firmware: imx: enable imx scu general irq function Thread-Index: AQHUxBeY1ru6LM154k6AIjlXsKZZtA== Date: Thu, 14 Feb 2019 03:44:31 +0000 Message-ID: <1550115535-14488-3-git-send-email-Anson.Huang@nxp.com> References: <1550115535-14488-1-git-send-email-Anson.Huang@nxp.com> In-Reply-To: <1550115535-14488-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: HK0P153CA0020.APCP153.PROD.OUTLOOK.COM (2603:1096:203:18::32) To DB3PR0402MB3916.eurprd04.prod.outlook.com (2603:10a6:8:10::18) 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: 380b0b78-e477-4849-e53b-08d6922eba4b x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600110)(711020)(4605077)(4618075)(2017052603328)(7153060)(7193020);SRVR:DB3PR0402MB3659; x-ms-traffictypediagnostic: DB3PR0402MB3659: x-microsoft-exchange-diagnostics: =?iso-8859-1?Q?1;DB3PR0402MB3659;23:pWUaDS72ji8SLC7HohfkmRlvBcU0VXpmcX+t9?= =?iso-8859-1?Q?9WLnyYTgve7vgHj2BGAbDFt2kcjD6fa8MU3yeKzDEfKpjFf7M3pAXsGQuy?= =?iso-8859-1?Q?mD30DOPf4uHfGlSTeKuDaHWZrMsVvqyHEEMGdA+x2m2lfakeW7Kmyxkb1k?= =?iso-8859-1?Q?lxopMQ1CFNBmiOyjXMXnFixWR9mGS/LEMFjMN21q9NkVtYCM9OOvp2xz11?= =?iso-8859-1?Q?qWsQl/jPfs63iXfODsWGMsOyy1yeSXnDbR/WsEcRt3SWBvZ1w9WEVdFMiH?= =?iso-8859-1?Q?vZP84teAZjeXevkbCpHTUYx+IHkfwReMuW2bC39oNtlQ7TWwMaCjElJ3Cy?= =?iso-8859-1?Q?c9EaGGsUUhmjN0WzDSp/MKxPjkylcNtMxmjcBdPKYPOCoVjfd5zYOYAPar?= =?iso-8859-1?Q?OJiDF0OzDAHWYnPCIx4N8SPn3PGiDffJEVYFAK8TN1SNT4jUpg5IIsUO3A?= =?iso-8859-1?Q?H0vVTe1vCmx+/G8+cLKWIu2RvOHsPXqSSH/cUq7qgParu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MtlJ2409sQB4Gn3DxQJY6KBhw+hkxpVCw=3D?= =?iso-8859-1?Q?=3D?= x-microsoft-antispam-prvs: x-forefront-prvs: 09480768F8 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(979002)(366004)(346002)(39860400002)(376002)(396003)(136003)(199004)(189003)(476003)(2616005)(68736007)(53936002)(52116002)(66066001)(14454004)(76176011)(486006)(86362001)(50226002)(4326008)(26005)(6512007)(2201001)(478600001)(71200400001)(6436002)(8936002)(6486002)(25786009)(446003)(8676002)(71190400001)(81156014)(81166006)(11346002)(186003)(2501003)(105586002)(3846002)(6116002)(386003)(6506007)(99286004)(102836004)(7416002)(316002)(2906002)(305945005)(110136005)(97736004)(7736002)(14444005)(106356001)(256004)(36756003)(921003)(1121003)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:DB3PR0402MB3659;H:DB3PR0402MB3916.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: LmYLh770MDOwOpkLWlNODWE0VBI+aOg5JonEmMXhELdmjdC7B3CsD3eZLmXQN1l57UcK6mWjko6DFu8FLYlwPiBNiwb8YHVkgesImb75TgEGAHyB5Z1b/ACKxT3wahtq7CD99aBFCVWyC4FtV1QeqJV2ov2UgItiXJdEYWnfUOn3IrV+SNQGlkvLmhHDP44Ly15C+ipjPqF53aNrisVU0bLGyPpzWSXAr2zxmjvaH2pxzV0Y4S/cMRAp2Z7LaVL4EW2GyYjHcz3Sd6uxYfPiKIprQCXDSu2Hcb7vI6BzS/wbyAvuhJrZEiYGSOCXH+kISZPGVk/QKPu7ktgxRH34DVkN2BZ7awkGxmV34IMSnum80KGHeNi3UMeAs6tI5nGxITHeRaaLMk252vQSb2cvqAT94cTljBRsn4za3clf6s0= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 380b0b78-e477-4849-e53b-08d6922eba4b X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Feb 2019 03:44:25.9954 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0402MB3659 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The System Controller Firmware (SCFW) controls RTC, thermal and WDOG etc., these resources' interrupt function are managed by SCU. When any IRQ pending, SCU will notify Linux via MU general interrupt channel #3, and Linux kernel needs to call SCU APIs to get IRQ status and notify each module to handle the interrupt. Since there is no data transmission for SCU IRQ notification, so doorbell mode is used for this MU channel, and SCU driver will use notifier mechanism to broadcast to every module which registers the SCU block notifier. Signed-off-by: Anson Huang --- No change since V1. --- drivers/firmware/imx/imx-scu.c | 101 +++++++++++++++++++++++++++++++++++= ++++ include/linux/firmware/imx/sci.h | 3 ++ 2 files changed, 104 insertions(+) diff --git a/drivers/firmware/imx/imx-scu.c b/drivers/firmware/imx/imx-scu.= c index 2bb1a19..e93bea5 100644 --- a/drivers/firmware/imx/imx-scu.c +++ b/drivers/firmware/imx/imx-scu.c @@ -7,6 +7,7 @@ * */ =20 +#include #include #include #include @@ -21,6 +22,8 @@ =20 #define SCU_MU_CHAN_NUM 8 #define MAX_RX_TIMEOUT (msecs_to_jiffies(30)) +#define IMX_SC_IRQ_FUNC_STATUS 2 +#define IMX_SC_IRQ_NUM_GROUP 6 =20 struct imx_sc_chan { struct imx_sc_ipc *sc_ipc; @@ -77,7 +80,23 @@ static int imx_sc_linux_errmap[IMX_SC_ERR_LAST] =3D { -EIO, /* IMX_SC_ERR_FAIL */ }; =20 +struct imx_sc_msg_irq_get_status { + struct imx_sc_rpc_msg hdr; + union { + struct { + u16 resource; + u8 group; + u8 reserved; + } send; + struct { + u32 status; + } receive; + } data; +} __packed; + static struct imx_sc_ipc *imx_sc_ipc_handle; +static struct work_struct imx_sc_general_irq_work; +static BLOCKING_NOTIFIER_HEAD(imx_scu_notifier_chain); =20 static inline int imx_sc_to_linux_errno(int errno) { @@ -194,6 +213,86 @@ int imx_scu_call_rpc(struct imx_sc_ipc *sc_ipc, void *= msg, bool have_resp) } EXPORT_SYMBOL(imx_scu_call_rpc); =20 +int imx_scu_register_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&imx_scu_notifier_chain, nb); +} +EXPORT_SYMBOL(imx_scu_register_notifier); + +int imx_scu_unregister_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&imx_scu_notifier_chain, nb); +} +EXPORT_SYMBOL(imx_scu_unregister_notifier); + +static int imx_scu_notifier_call_chain(unsigned long status, u8 *group) +{ + return blocking_notifier_call_chain(&imx_scu_notifier_chain, + status, (void *)group); +} + +static void imx_scu_general_irq_work_handler(struct work_struct *work) +{ + struct imx_sc_msg_irq_get_status msg; + struct imx_sc_rpc_msg *hdr =3D &msg.hdr; + u32 irq_status; + int ret; + u8 i; + + for (i =3D 0; i < IMX_SC_IRQ_NUM_GROUP; i++) { + hdr->ver =3D IMX_SC_RPC_VERSION; + hdr->svc =3D IMX_SC_RPC_SVC_IRQ; + hdr->func =3D IMX_SC_IRQ_FUNC_STATUS; + hdr->size =3D 2; + + msg.data.send.resource =3D IMX_SC_R_MU_1A; + msg.data.send.group =3D i; + + ret =3D imx_scu_call_rpc(imx_sc_ipc_handle, &msg, true); + if (ret) { + pr_err("get irq status failed, ret %d\n", ret); + return; + } + + irq_status =3D msg.data.receive.status; + if (!irq_status) + continue; + + imx_scu_notifier_call_chain(irq_status, &i); + } +} + +static void imx_scu_rxdb_callback(struct mbox_client *c, void *msg) +{ + schedule_work(&imx_sc_general_irq_work); +} + +static int imx_scu_enable_general_irq_channel(struct device *dev) +{ + struct mbox_client *cl; + struct mbox_chan *ch; + int ret =3D 0; + + cl =3D devm_kzalloc(dev, sizeof(*cl), GFP_KERNEL); + if (!cl) + return -ENOMEM; + + cl->dev =3D dev; + cl->rx_callback =3D imx_scu_rxdb_callback; + + /* SCU general IRQ uses general interrupt channel 3 */ + ch =3D mbox_request_channel_byname(cl, "gi3"); + if (IS_ERR(ch)) { + ret =3D PTR_ERR(ch); + dev_err(dev, "failed to request mbox chan gi3, ret %d\n", ret); + return ret; + } + + INIT_WORK(&imx_sc_general_irq_work, imx_scu_general_irq_work_handler); + + return ret; +} + static int imx_scu_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -246,6 +345,8 @@ static int imx_scu_probe(struct platform_device *pdev) =20 imx_sc_ipc_handle =3D sc_ipc; =20 + imx_scu_enable_general_irq_channel(dev); + dev_info(dev, "NXP i.MX SCU Initialized\n"); =20 return devm_of_platform_populate(dev); diff --git a/include/linux/firmware/imx/sci.h b/include/linux/firmware/imx/= sci.h index ebc5509..9d608db 100644 --- a/include/linux/firmware/imx/sci.h +++ b/include/linux/firmware/imx/sci.h @@ -15,4 +15,7 @@ =20 #include #include + +int imx_scu_register_notifier(struct notifier_block *nb); +int imx_scu_unregister_notifier(struct notifier_block *nb); #endif /* _SC_SCI_H */ --=20 2.7.4