From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796025239; b=tE4LzkL8Yaw6+88Kgf21gO66ux80KoJua8SelAVhURCD1ybHvUukAiy+jbZheQEWXGzc QokNHqc9bIcmUDbdZFNEXmgzJiyC6bOP5CqVM0WysjZDLAlDe110dYdhmLqS4IKs2tedj gX7NLNWH9VptBVEXgjlgJ2EO7TtGWSbOYSRK0XPIGKNrwLbR/XwjiT50B+Ln4sQqBMU4U 0HSr4eVpn9RwABay0JHcnSb1jFTP3u84tcA7cxZXA+ND4dZtgCo4tVbi6z7nHjgjfl9Cs AUM4TBw/2j5z6uUXiTPUML1B3kRW1Tod3tIL/WTGnXk04+uUomVtSHESp95/15uqHtQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796025239; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Proofpoint-ORIG-GUID:X-Authority-Analysis: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-GUID: X-Proofpoint-Spam-Info:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=J1sHqyQ0rK02sHBgC9n5Y38p9+IBHGTSG7jD4xBPQ7s=; b=CQc8mo9gFDMxpRCwO/vTefr8MBdxfzMsnTLjzKM6pQjvxeeaCssT3AeFhA/O7jS3KeKr ND/OKXiZVE/CAKuB9WWvXvqWiS1dPAfVy+Im4NBq3aykq+y/F+u2/tI6w2gwKB7rwLbjK KpZAUhAsi+eVTzynSiAUU4cAf4S1lKHFK8cHx9An4mmFIPNUFLMXuJyhINYPUkfPupc2d aCLiNiVH92jDN4pjgu/60NstLRxLicH2SkpvNlB7//xjEOJ0eRU9CXjwe9R0Wzyh+Y67P +mpfvuszFMkVsVEAETnMtjJ9HXVXc8Jwq3WoP5kdNeFRzkm6ocle8W96uIglvWl5j6Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=kUgfKSw+; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=ABSM2oHj; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C5C8606A32E for ; Mon, 30 Nov 2026 07:53:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C5C8606A32E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=kUgfKSw+; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=ABSM2oHj Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AU5GYOY2653932 for ; Mon, 30 Nov 2026 07:53:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=J1sHqyQ0rK0 2sHBgC9n5Y38p9+IBHGTSG7jD4xBPQ7s=; b=kUgfKSw+Pon+PQvJQDZpTj/GITp twq5fSe+NKzCHjrxZMl7NhdvXAv2GYi+dQr/lj3I6zo7J0gbFc8Z0m6ULegW5N6f tNh7c/fz17XHYrrcFMBi70mSe1tg47YiX/Rs++P2dzlfeUudcfqwawWKcFErk9fd jMmjGornclCcYBTSwLL76U4AxOuVUrEbjY10NE9BfAxGbILg7bJcrWrd+Za1zXPO 44xdMTQKpp9j/7kRgI+rFN3zwGfufAYs9YxpICqyg6IR5k6i9Fc2c6r/Ubn6fP+S dndc+Nc9Cqv737mdLyMgssCHIxCwIqVxFEzQv1OLZyHobYA3PC7oOzyjlUw== Received: from mail-dy1-f198.google.com (mail-dy1-f198.google.com [74.125.82.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j7mnenjhs-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 07:53:57 +0000 (GMT) Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-375bac6bd21so9915791eec.0 for ; Sun, 29 Nov 2026 23:53:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796025237; x=1796630037; darn=vger.kernel.org; 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:content-type; bh=J1sHqyQ0rK02sHBgC9n5Y38p9+IBHGTSG7jD4xBPQ7s=; b=ABSM2oHj4IQCKrvmioJ8FRWynSHtmTmlv3/spUY+qraoxeGxJPI/yAcgEghKTzKb9h Qww3HZYxpRQ8D/HTQAAC3gfn8mYopEcJ8e0Z9YcyAITgxE4KrjsvoZDw+isqlVkmrOFQ 4J8HO3h+3+Vx8lrLlmWKP4PlnYXwZwbIiwfezPfspZqEV8YyiAqos4rXePTYEFbthzN/ ffdTQJeR9zK1U0n95dShTVzOo3qULI3E7q45eUAMidIjd8g54iTypdnZLtnl8rTbCBiO D3dN+1BtIQRaAQYGVYY8P8lrPR9MsqA5dfre5aOe3wOzaai3uaPPLWffjzHTvrEfUGX+ dwSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796025237; x=1796630037; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=J1sHqyQ0rK02sHBgC9n5Y38p9+IBHGTSG7jD4xBPQ7s=; b=zmq18h5hHrBZXdVXD+1gaXWGlyGu/+e98l3jrmDzF6ez0m7+dDaIuaGYHdluqRUTxm Rcn+EJdWd+MBULp6lICVmzbaWs8wIMcDggl7tskJaOTLPLNj7HXXn8jJ+tPCEQdK3IrD iIcYP+42g2N5jB1M2AOdrvd1YYT7kEcipL4VcIma3BpjBpDpbOWsPKbeTO0ai4/s7nWm dyN+tWfx5UPcuw0RBKLuDABmQ7ZFtdMNsoSVvjFugm+guu6ZYfRnN9t1RukZmCDzX6jG /HGXPIE/IYiE7qTJewVtziDCM4TVXcjmyp84azatvx7hONJuKMZsnxZwuxR2BrRIEMab VjqA== X-Forwarded-Encrypted: i=1; AL+hErEZHa+tlA0qLCAkhXXSGv8iGJC7ffs62vNcZ589jajuYA3Nec09iaZsMyuWvi75F5fzJkerH4hjmrw4Vuw=@vger.kernel.org X-Gm-Message-State: APuU4Z/vRgXx/qmNwbbmRDnyYGBIMdTDOA0NvawXXtZb8VgRy4dzPpAM V/Fa5x83HSnaN26oC42R24nag63FpcwbB6l2hbDfjqx+30avHMxYRf67XR3SgdveAS3+S0GoKd1 7alKtIHcxI0vfA010E2+/5+leBSmViEwv5JKD1P6YYOUM3Dk81J72ImmqGc5G0YKmiu4= X-Gm-Gg: AZFdTZdLfq6akBo/oRAcEJW4o2bUCD9P+JlkqeZmC4qcZIJO2ODVhs4TUEIWOXK+kA7 JeRppqUBlnmH17vciaMPPKIqvhDgWmAToyOu4YQ94uPpn46tQ+kf9rVTEvGyFLWn5K0F3007ynV jHyNfmaatmuiv3WsRjACLnFtdzvNmUz9KsZTvW7Ys3xsAeT8SiUB8dciNQUN2gvDP2XDeWH4i3N qqUmKZV/DdBSp5fQm4zzW1TGJg7DusGq8ecmlhPrCLO9zMpB3lC9HHD0UKBYeLseLGcjQIJ6u3b 61fcDTYnccw+XOerPv9mfxkalSGzC1C9D8rN9/cAHJfq5Taba0tKbsB+ct9FMNTZJ+mufrEz6iF Ap+o2h+UY7q7bZ4DdpBwIARddBz++20o8QHQnshJ8wC6T0nN7PwnfwbRcxBvUQgEPquyY1lCtG/ 16ebalT7iT64xJSkbCVArMcn1zpqGJi5If X-Received: by 2002:a05:693c:25cc:b0:369:f17d:efb with SMTP id 5a478bee46e88-384b3e77699mr45544200eec.10.1796025236979; Sun, 29 Nov 2026 23:53:56 -0800 (PST) X-Received: by 2002:a05:693c:25cc:b0:369:f17d:efb with SMTP id 5a478bee46e88-384b3e77699mr45544164eec.10.1796025236411; Sun, 29 Nov 2026 23:53:56 -0800 (PST) Received: from QCOM-aGQu4IUr3Y.qualcomm.com (i-global052.qualcomm.com. [199.106.103.52]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38707b612cbsm19865156eec.4.2026.11.29.23.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 23:53:56 -0800 (PST) From: Shawn Guo To: Srinivas Kandagatla , Mark Brown Cc: Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Mohit Sharma , Ajay Kumar Nandam , Prasad Kumpatla , linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Shawn Guo Subject: [PATCH v2 3/3] ASoC: qcom: q6prm: Keep the clock controller across DSP restarts Date: Mon, 30 Nov 2026 15:53:33 +0800 Message-ID: <20261130075333.43354-4-shengchao.guo@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130075333.43354-1-shengchao.guo@oss.qualcomm.com> References: <20261130075333.43354-1-shengchao.guo@oss.qualcomm.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-ORIG-GUID: HBJPxM8n1o22fPEba8o5QfBsc4CrLNIq X-Authority-Analysis: v=2.4 cv=Rf8FmFtv c=1 sm=1 tr=0 ts=6b0d2b95 cx=c_pps a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=b9+bayejhc3NMeqCNyeLQQ==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=ZkN0dkQvXNnz3tZD4J4A:9 a=bBxd6f-gb0O0v-kibOvt:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDAzMSBTYWx0ZWRfX3cXkZ7FsOfHs +7YFtTxd2tf/222S5hWquBqogWmZykx4hDK/Xu4+h+a6Im375eoWeKi4NNYZ3/S+R84I+gAerVb M5ZR1eulMTC1xQR1vCMFRyM/uT78nz4XwXMdsD10gTf/awJWD965zgUgzi4nvCIu7mYEWKFhmA2 R8sHdsf+VtQTKuZ6KAfSGwinJzc3VJKuos2XqREyGaZQ+2Vtg1xhdRlIHdONcOIE8FMUWrAMb8U mLNH8wxaR3z4Rl/jslkVTmrvh6C7VS38X9bdEULGSqA0MtfNf6Xh+lLqzDTUNb1lqsp6yCf4FIM escK/t14CTutRGO7S4+tFcRgU3N9DLMdtwC4Al9o1SEwbmOXvO9MS2nnO+uajRemaT1T1aWCfsL Kbc9er93/fV0WE0WtoFTTqyLGE1/Y8hXL4xFRQpy3OK7t0Wb9DbT4lFm4Z2o1CNfsllGdp5q1QL hO4hVkkpw6rpYvOVOcg== X-Proofpoint-GUID: HBJPxM8n1o22fPEba8o5QfBsc4CrLNIq X-Proofpoint-Spam-Info: AW1haW4tMjYxMTMwMDAzMSBTYWx0ZWRfXyDzhbkmCe7uf MnM+E0ARsTw10mwf1iZjgmsG08qhgLKoB+JRnQgZaF56/imP0ne8x2UPW1mlGe7lSE9JM8axFNN uszvpuzZKG4vY6Jl7+WjfBIrCTW7vws= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-30_02,2026-11-27_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 impostorscore=0 priorityscore=1501 suspectscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611300031 The q6prm LPASS clock controller is populated as a child of the q6prm GPR device. That device is unregistered whenever the DSP stops, which unregisters the clock provider while consumers still hold their clocks. fw_devlink links the consumers to the remoteproc device rather than to the clock controller, so they stay bound, and their clk handles fall back to clk_nodrv_ops. After the DSP comes back, every operation on those handles fails with -ENXIO. On Nord RRD, playback after an ADSP restart fails with: pcm1681 0-004c: Failed to enable sck: -6 Pointing the device link at the clock controller would not help. fw_devlink picks the remoteproc device because the clock-controller node has no device yet when the remoteproc binds, so the consumers are moved up to that bound ancestor. With a link to the controller instead, the driver core unbinds the consumers when the controller goes away, but nothing probes them again once the DSP is back: the link is deleted with the controller, and fw_devlink does not link the consumers to the new controller device, since it creates device links only once, from fwnode links that it then drops. Tested with such a link on Nord RIDE, pcm1681 and the sound card stay unbound after an ADSP restart. Even if fw_devlink handled this, every consumer of a DSP clock would be torn down and probed again on each restart. Create the clock controller device once and keep it until the module is unloaded. Its parent is the closest platform device ancestor of the GPR device, which is the remoteproc platform device. That device persists across DSP restarts, while the rpmsg and remoteproc devices between it and the GPR device do not. The device tree is unchanged: the controller keeps its clock-controller node under the q6prm node, so no binding change is needed. Each probe of the q6prm GPR device attaches its instance to the existing controller, found by device tree node, and restores the clocks that consumers held across the restart. Remove detaches the instance first, so new clock requests fail with -EBUSY while the DSP is down, then marks the prepared clocks as lost. Since q6prm now destroys these devices itself, replace module_gpr_driver() with explicit init and exit functions. q6prm also calls into snd-q6dsp-common now, so select SND_SOC_QDSP6_COMMON. Signed-off-by: Shawn Guo --- sound/soc/qcom/Kconfig | 1 + sound/soc/qcom/qdsp6/q6prm.c | 190 ++++++++++++++++++++++++++++++++--- 2 files changed, 178 insertions(+), 13 deletions(-) diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index f6d810931a9a..74f0190b05f1 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -127,6 +127,7 @@ config SND_SOC_QDSP6_PRM_LPASS_CLOCKS config SND_SOC_QDSP6_PRM tristate + select SND_SOC_QDSP6_COMMON select SND_SOC_QDSP6_PRM_LPASS_CLOCKS config SND_SOC_QCOM_OFFLOAD_UTILS diff --git a/sound/soc/qcom/qdsp6/q6prm.c b/sound/soc/qcom/qdsp6/q6prm.c index 73b5a96e8311..861d48bdb5ea 100644 --- a/sound/soc/qcom/qdsp6/q6prm.c +++ b/sound/soc/qcom/qdsp6/q6prm.c @@ -8,22 +8,56 @@ #include #include #include +#include #include #include #include #include #include "q6apm.h" +#include "q6dsp-lpass-clocks.h" #include "q6prm.h" #include "audioreach.h" +struct q6prm_clkctl; + struct q6prm { struct device *dev; gpr_device_t *gdev; wait_queue_head_t wait; struct gpr_ibasic_rsp_result_t result; struct mutex lock; + struct q6prm_clkctl *clkctl; }; +/* + * The q6prm GPR device is removed whenever the DSP stops, but clock consumers + * hold their clk handles across a DSP restart. The clock controller device is + * therefore created only once, under the remoteproc device, and kept until the + * module is unloaded. Its clock ops reach the q6prm instance of the running + * DSP through @prm, which is NULL while the DSP is down. + */ +struct q6prm_clkctl { + struct list_head node; + struct device_node *np; + struct platform_device *pdev; + struct q6prm *prm; +}; + +static DEFINE_MUTEX(q6prm_clkctl_lock); +static LIST_HEAD(q6prm_clkctl_list); + +/* Called with q6prm_clkctl_lock held */ +static struct q6prm *q6prm_clkctl_get_prm(struct device *dev) +{ + struct q6prm_clkctl *ctl; + + list_for_each_entry(ctl, &q6prm_clkctl_list, node) + if (ctl->np == dev->of_node) + return ctl->prm; + + return NULL; +} + #define PRM_CMD_REQUEST_HW_RSC 0x0100100F #define PRM_CMD_RSP_REQUEST_HW_RSC 0x02001002 #define PRM_CMD_RELEASE_HW_RSC 0x01001010 @@ -63,9 +97,8 @@ static int q6prm_send_cmd_sync(struct q6prm *prm, struct gpr_pkt *pkt, uint32_t NULL, &prm->wait, pkt, rsp_opcode); } -static int q6prm_set_hw_core_req(struct device *dev, uint32_t hw_block_id, bool enable) +static int q6prm_set_hw_core_req(struct q6prm *prm, uint32_t hw_block_id, bool enable) { - struct q6prm *prm = dev_get_drvdata(dev->parent); struct apm_module_param_data *param_data; struct prm_cmd_request_hw_core *req; gpr_device_t *gdev = prm->gdev; @@ -105,21 +138,35 @@ static int q6prm_set_hw_core_req(struct device *dev, uint32_t hw_block_id, bool int q6prm_vote_lpass_core_hw(struct device *dev, uint32_t hw_block_id, const char *client_name, uint32_t *client_handle) { - return q6prm_set_hw_core_req(dev, hw_block_id, true); + struct q6prm *prm; + guard(mutex)(&q6prm_clkctl_lock); + + prm = q6prm_clkctl_get_prm(dev); + if (!prm) + return -EBUSY; + + return q6prm_set_hw_core_req(prm, hw_block_id, true); } EXPORT_SYMBOL_GPL(q6prm_vote_lpass_core_hw); int q6prm_unvote_lpass_core_hw(struct device *dev, uint32_t hw_block_id, uint32_t client_handle) { - return q6prm_set_hw_core_req(dev, hw_block_id, false); + struct q6prm *prm; + + guard(mutex)(&q6prm_clkctl_lock); + + prm = q6prm_clkctl_get_prm(dev); + if (!prm) + return -EBUSY; + + return q6prm_set_hw_core_req(prm, hw_block_id, false); } EXPORT_SYMBOL_GPL(q6prm_unvote_lpass_core_hw); -static int q6prm_request_lpass_clock(struct device *dev, int clk_id, int clk_attr, int clk_root, +static int q6prm_request_lpass_clock(struct q6prm *prm, int clk_id, int clk_attr, int clk_root, unsigned int freq) { - struct q6prm *prm = dev_get_drvdata(dev->parent); struct apm_module_param_data *param_data; struct prm_cmd_request_rsc *req; gpr_device_t *gdev = prm->gdev; @@ -148,10 +195,9 @@ static int q6prm_request_lpass_clock(struct device *dev, int clk_id, int clk_att return q6prm_send_cmd_sync(prm, pkt, PRM_CMD_RSP_REQUEST_HW_RSC); } -static int q6prm_release_lpass_clock(struct device *dev, int clk_id, int clk_attr, int clk_root, +static int q6prm_release_lpass_clock(struct q6prm *prm, int clk_id, int clk_attr, int clk_root, unsigned int freq) { - struct q6prm *prm = dev_get_drvdata(dev->parent); struct apm_module_param_data *param_data; struct prm_cmd_release_rsc *rel; gpr_device_t *gdev = prm->gdev; @@ -180,10 +226,18 @@ static int q6prm_release_lpass_clock(struct device *dev, int clk_id, int clk_att int q6prm_set_lpass_clock(struct device *dev, int clk_id, int clk_attr, int clk_root, unsigned int freq) { - if (freq) - return q6prm_request_lpass_clock(dev, clk_id, clk_attr, clk_root, freq); + struct q6prm *prm; - return q6prm_release_lpass_clock(dev, clk_id, clk_attr, clk_root, freq); + guard(mutex)(&q6prm_clkctl_lock); + + prm = q6prm_clkctl_get_prm(dev); + if (!prm) + return -EBUSY; + + if (freq) + return q6prm_request_lpass_clock(prm, clk_id, clk_attr, clk_root, freq); + + return q6prm_release_lpass_clock(prm, clk_id, clk_attr, clk_root, freq); } EXPORT_SYMBOL_GPL(q6prm_set_lpass_clock); @@ -212,10 +266,76 @@ static int prm_callback(const struct gpr_resp_pkt *data, void *priv, int op) return 0; } +/* + * The GPR device sits on a chain of rpmsg and remoteproc devices that are all + * torn down when the DSP stops. Its closest platform device ancestor is the + * remoteproc platform device, which stays across DSP restarts. + */ +static struct device *q6prm_clkctl_parent(struct device *dev) +{ + for (dev = dev->parent; dev; dev = dev->parent) + if (dev_is_platform(dev)) + return dev; + + return NULL; +} + +static int q6prm_clkctl_attach(struct q6prm *prm) +{ + struct device *dev = prm->dev; + struct q6prm_clkctl *ctl = NULL, *iter; + struct device_node *np; + + np = of_get_child_by_name(dev->of_node, "clock-controller"); + if (!np) + return 0; + + scoped_guard(mutex, &q6prm_clkctl_lock) { + list_for_each_entry(iter, &q6prm_clkctl_list, node) { + if (iter->np == np) { + ctl = iter; + break; + } + } + + if (ctl) { + of_node_put(np); + } else { + ctl = kzalloc_obj(*ctl); + if (!ctl) { + of_node_put(np); + return -ENOMEM; + } + + ctl->np = np; + list_add(&ctl->node, &q6prm_clkctl_list); + } + + ctl->prm = prm; + } + + /* Created on first probe, once its clock ops can already reach the DSP */ + if (!ctl->pdev) { + ctl->pdev = of_platform_device_create(ctl->np, NULL, + q6prm_clkctl_parent(dev)); + if (!ctl->pdev) { + scoped_guard(mutex, &q6prm_clkctl_lock) + ctl->prm = NULL; + return dev_err_probe(dev, -ENODEV, + "Failed to create clock controller\n"); + } + } + + prm->clkctl = ctl; + + return 0; +} + static int prm_probe(gpr_device_t *gdev) { struct device *dev = &gdev->dev; struct q6prm *cc; + int ret; cc = devm_kzalloc_obj(dev, *cc); if (!cc) @@ -230,7 +350,29 @@ static int prm_probe(gpr_device_t *gdev) if (!q6apm_is_adsp_ready()) return -EPROBE_DEFER; - return devm_of_platform_populate(dev); + ret = q6prm_clkctl_attach(cc); + if (ret) + return ret; + + if (cc->clkctl) + q6dsp_clock_dsp_up(&cc->clkctl->pdev->dev); + + return 0; +} + +static void prm_remove(gpr_device_t *gdev) +{ + struct q6prm *prm = dev_get_drvdata(&gdev->dev); + struct q6prm_clkctl *ctl = prm->clkctl; + + if (!ctl) + return; + + /* Fail new clock requests first, then mark what the DSP dropped */ + scoped_guard(mutex, &q6prm_clkctl_lock) + ctl->prm = NULL; + + q6dsp_clock_dsp_down(&ctl->pdev->dev); } #ifdef CONFIG_OF @@ -243,6 +385,7 @@ MODULE_DEVICE_TABLE(of, prm_device_id); static gpr_driver_t prm_driver = { .probe = prm_probe, + .remove = prm_remove, .gpr_callback = prm_callback, .driver = { .name = "qcom-prm", @@ -250,6 +393,27 @@ static gpr_driver_t prm_driver = { }, }; -module_gpr_driver(prm_driver); +static int __init q6prm_init(void) +{ + return apr_driver_register(&prm_driver); +} +module_init(q6prm_init); + +static void __exit q6prm_exit(void) +{ + struct q6prm_clkctl *ctl, *tmp; + + apr_driver_unregister(&prm_driver); + + list_for_each_entry_safe(ctl, tmp, &q6prm_clkctl_list, node) { + if (ctl->pdev) + of_platform_device_destroy(&ctl->pdev->dev, NULL); + of_node_put(ctl->np); + list_del(&ctl->node); + kfree(ctl); + } +} +module_exit(q6prm_exit); + MODULE_DESCRIPTION("Q6 Proxy Resource Manager"); MODULE_LICENSE("GPL"); -- 2.43.0