From patchwork Thu Apr 11 05:22:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 788216 Received: from mail5.25mail.st (mail5.25mail.st [74.50.62.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA2CB1C0DE7; Thu, 11 Apr 2024 05:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.50.62.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712813030; cv=none; b=b1PTsdqVv8aeJiWLF4yWYxyQAQJeCAs1x4KJ31deKnaO8fYB7X1WH8FgRHFTSMJguin0kLBW5kc3mtYBCekaaZP8TlNkzp/dK1WiEBJRPnTKSToBTGttFj6QAgvnAlfWKZc2H1bJl7iI+gZ8JtfH53833Get4K04Wtil2gR6fwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712813030; c=relaxed/simple; bh=6jjiVUe5YOImZgDXsgqmOEfi4ySQyj03YKG67dWJEeM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g4MtK7t0tXqlLShVRB44qRjW0zIWgEsoozE4AATJiUymoYQFEsoKBdiAQO7V2DMAH0Ehx/Zkhqo/B+e1obWvJ9fqjPYRuYQ6x7Tx+sUBzQMJRG+vvCnl26FAkNE5O1bq4pnVo69cgKg/53Wz28zELEkvpaXQCxYRN+4JxjpP/xM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atomide.com; spf=fail smtp.mailfrom=atomide.com; dkim=pass (2048-bit key) header.d=atomide.com header.i=@atomide.com header.b=WjuapCUO; arc=none smtp.client-ip=74.50.62.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atomide.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=atomide.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=atomide.com header.i=@atomide.com header.b="WjuapCUO" Received: from localhost (91-158-86-216.elisa-laajakaista.fi [91.158.86.216]) by mail5.25mail.st (Postfix) with ESMTPSA id 3263D6084E; Thu, 11 Apr 2024 05:23:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=atomide.com; s=25mailst; t=1712813027; bh=6jjiVUe5YOImZgDXsgqmOEfi4ySQyj03YKG67dWJEeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WjuapCUOaPmI6mMcntHJh0h7Tw3CbxrAK7bFbtSgt11qvgmzL+eIoNUDuYl0KdB6C Yp5+C4OH3F/1EJD60oTzsLmAS1a++DtJZUTwfJKxmqwjbC8J165ItaK0YXtWvGAsxp blYPjJl92F7juHYRbc+47ovz+yhyr64I7BAsuBBdRJBqWgwgtA4Ieea2AUrs9SBSMW 6OtsegoXqctpLLdraMgxjk0/aE8y6adiP/UKwhHQ4kHRVHuYDKc9P7zzIyx2wLo2kQ 1pjVcf7LgV450oaCF5U/U6VaBE2yNBbLlJyTcyCRCXJNGK9f2HdbimRDAYCNQj4z4I mUFKHEwj+JSxA== From: Tony Lindgren To: linux-omap@vger.kernel.org Cc: Dhruva Gole , Greg Kroah-Hartman , Philipp Zabel , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [RFC PATCH 1/4] reset: Fall back to lookup if no reset node is found Date: Thu, 11 Apr 2024 08:22:54 +0300 Message-ID: <20240411052257.2113-2-tony@atomide.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411052257.2113-1-tony@atomide.com> References: <20240411052257.2113-1-tony@atomide.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fall back to lookup if the reset node does not exist. When creating and removing subdevices on an interconnect, the parent device may provide resets for the children using struct reset_control_lookup instead using devicetree. Signed-off-by: Tony Lindgren --- drivers/reset/core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -1141,12 +1141,17 @@ struct reset_control *__reset_control_get(struct device *dev, const char *id, int index, bool shared, bool optional, bool acquired) { + struct reset_control *rstc; + if (WARN_ON(shared && acquired)) return ERR_PTR(-EINVAL); - if (dev->of_node) - return __of_reset_control_get(dev->of_node, id, index, shared, + if (dev->of_node) { + rstc = __of_reset_control_get(dev->of_node, id, index, shared, optional, acquired); + if (!(IS_ERR(rstc) && PTR_ERR(rstc) == -ENOENT)) + return rstc; + } return __reset_control_get_from_lookup(dev, id, shared, optional, acquired); From patchwork Thu Apr 11 05:22:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 788958 Received: from mail5.25mail.st (mail5.25mail.st [74.50.62.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 504DB13C807; Thu, 11 Apr 2024 05:24:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.50.62.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712813044; cv=none; b=gOg9xv77LNUHXYC3MTcplG4b7aJYVLZBHsR/7YdjTLR7w3WoYM/WjC3ZkAcm5zuqMVkKZMUzJo5YkcXSoOY6rsIRjeZrmafiNL3tlNTlimZimb4Ic/9iHp6saNyGAYRpffXgaULdYV1jLnmurdRkMqZ4zLFQU5gDmgikOiN41LA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712813044; c=relaxed/simple; bh=RxRBurBGdPk3v0RcZD82O+R1FR1mCURyTzkpzUuQ/vI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=akrFvtzV3kwX4Ll1Z4oXQsLb1btD93DwKhydPdUlCNlxCm7L/PAC2bJhFtzFzYQagLsWe9DR92T8E5ZU6OBsXkTbyjJbqWZUz7q0/FGRLkxFF7XVE/hg/KvhRwdczCj60Ubw072HqSdrHjN+GlU8pwj1Z4kMMrjBpsUeG5ZPdDU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atomide.com; spf=fail smtp.mailfrom=atomide.com; dkim=pass (2048-bit key) header.d=atomide.com header.i=@atomide.com header.b=NbzEkW4X; arc=none smtp.client-ip=74.50.62.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atomide.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=atomide.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=atomide.com header.i=@atomide.com header.b="NbzEkW4X" Received: from localhost (91-158-86-216.elisa-laajakaista.fi [91.158.86.216]) by mail5.25mail.st (Postfix) with ESMTPSA id BEBE7603E6; Thu, 11 Apr 2024 05:23:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=atomide.com; s=25mailst; t=1712813042; bh=RxRBurBGdPk3v0RcZD82O+R1FR1mCURyTzkpzUuQ/vI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NbzEkW4XkG/SqlwO7q/4+GMiTqUo6d4uGZop/AeLCJo5hWWGv6sZYC1aZDU20pHFf 2mODQjLanR372gLIaP4F0PhidfjvQH49RpGXp7DoFpW58o47x74V3Sea+azNwDUsf4 Yg+6icKsntQIFbRkaMUCqGxoyGtR1G5P62xbuNCV28hcLEF0OZ1s/dRSZfyqLoApCx f0gxQusk0Z243byf7VMLp9ry4sFqxqH5zEfMyQZ2jbD6/4kVlgiR9tr74DZ7i6B+KU v3mDXJAMLfzcg2jRGx0Y2rx0o7vr7CJQk9myafAiUudCsddTmx0Yp2a9p9gVrzsj5r YZn52SqSJaRvw== From: Tony Lindgren To: linux-omap@vger.kernel.org Cc: Dhruva Gole , Greg Kroah-Hartman , Philipp Zabel , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [RFC PATCH 2/4] reset: Allow removing a lookup Date: Thu, 11 Apr 2024 08:22:55 +0300 Message-ID: <20240411052257.2113-3-tony@atomide.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411052257.2113-1-tony@atomide.com> References: <20240411052257.2113-1-tony@atomide.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If a parent device provides resets for the child devices using a lookup table, let's also allow removal of the lookup table when removing the child devices. Signed-off-by: Tony Lindgren --- drivers/reset/core.c | 27 +++++++++++++++++++++++++++ include/linux/reset-controller.h | 7 +++++++ 2 files changed, 34 insertions(+) diff --git a/drivers/reset/core.c b/drivers/reset/core.c --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -217,6 +217,33 @@ void reset_controller_add_lookup(struct reset_control_lookup *lookup, } EXPORT_SYMBOL_GPL(reset_controller_add_lookup); +/** + * reset_controller_remove_lookup - unregister a set of lookup entries + * @lookup: array of reset lookup entries + * @num_entries: number of entries in the lookup array + */ +void reset_controller_remove_lookup(struct reset_control_lookup *lookup, + unsigned int num_entries) +{ + struct reset_control_lookup *entry; + unsigned int i; + + mutex_lock(&reset_lookup_mutex); + for (i = 0; i < num_entries; i++) { + entry = &lookup[i]; + + if (!entry->dev_id || !entry->provider) { + pr_warn("%s(): reset lookup entry badly specified, skipping\n", + __func__); + continue; + } + + list_del(&entry->list); + } + mutex_unlock(&reset_lookup_mutex); +} +EXPORT_SYMBOL_GPL(reset_controller_remove_lookup); + static inline struct reset_control_array * rstc_to_array(struct reset_control *rstc) { return container_of(rstc, struct reset_control_array, base); diff --git a/include/linux/reset-controller.h b/include/linux/reset-controller.h --- a/include/linux/reset-controller.h +++ b/include/linux/reset-controller.h @@ -93,6 +93,8 @@ int devm_reset_controller_register(struct device *dev, void reset_controller_add_lookup(struct reset_control_lookup *lookup, unsigned int num_entries); +void reset_controller_remove_lookup(struct reset_control_lookup *lookup, + unsigned int num_entries); #else static inline int reset_controller_register(struct reset_controller_dev *rcdev) { @@ -113,6 +115,11 @@ static inline void reset_controller_add_lookup(struct reset_control_lookup *look unsigned int num_entries) { } + +static inline void reset_controller_remove_lookup(struct reset_control_lookup *lookup, + unsigned int num_entries) +{ +} #endif #endif From patchwork Thu Apr 11 05:22:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 788215 Received: from mail5.25mail.st (mail5.25mail.st [74.50.62.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1759713C806; Thu, 11 Apr 2024 05:24:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.50.62.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712813059; cv=none; b=GfYDk625Ndlxmg6M2z9MSVOr8C23H+mjtKlOkyilAe+Djba9Ij1J3SETX6IRjuVyoh4cA+mnt5Kx+xN2zCb49XrrYTJyHAXJBOVrh/Fu+Zr4XEJpRbwq/oOnAZwE3e8nfcH2pR8mDy6mT81Q9BnHYeoXWij0fkgj4d9gp9UuKnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712813059; c=relaxed/simple; bh=WR9O76GumOlNTXVFrACeC491JghxmHVFac0PfnhnFCI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UXRR3HMJkvuWQesOKulyXaBEYgEXzpDqmeeZjDTjI79bYSPfpWcideWIe7j7zeVW9pwjsPriUZKkkIp/4ZFPFBq03Htu9b8TFy8bLhSkdcnD0wf6FoUQ5aln7hHff29V3Xkx3If+dV8VQXsj/+ieGwY5KD9BICgztkqEky2/Vzk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atomide.com; spf=fail smtp.mailfrom=atomide.com; dkim=pass (2048-bit key) header.d=atomide.com header.i=@atomide.com header.b=JTpXVoEq; arc=none smtp.client-ip=74.50.62.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atomide.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=atomide.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=atomide.com header.i=@atomide.com header.b="JTpXVoEq" Received: from localhost (91-158-86-216.elisa-laajakaista.fi [91.158.86.216]) by mail5.25mail.st (Postfix) with ESMTPSA id 52885603E6; Thu, 11 Apr 2024 05:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=atomide.com; s=25mailst; t=1712813057; bh=WR9O76GumOlNTXVFrACeC491JghxmHVFac0PfnhnFCI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JTpXVoEqsH8CQVr3SccEkkw7fTI14yW5Fo3EQaut3+NiBmHZSfvbeNWmEog1CZAUR AwLJjVItiVSzM5yxi1+wJkUiXubfiNv+fvFbW+XcrYcu5fAoFZtTDRbySpM4Sp/D/L ZTYpoFgWEBtcckNiAQLSE5aF2coDkrcO1ARw9ow/rKzHFeT0AtvL6F2Zy+rczdE9Ml /H4TD4mt5jY5XvUnK415zlkEQ/DyaOoChcUY8Bw1fatO5rtiRyOpmoVMAaswWIC7Vw 2vCZ8qTcxjEUedLu8A7c7uhI9mkHGG+pRCGQISIGOxtg0pXBVcK9iYWAjwQIU7eVtb LocFKUlC8rPfg== From: Tony Lindgren To: linux-omap@vger.kernel.org Cc: Dhruva Gole , Greg Kroah-Hartman , Philipp Zabel , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [RFC PATCH 3/4] bus: ti-sysc: Implement reset control framework for soft reset Date: Thu, 11 Apr 2024 08:22:56 +0300 Message-ID: <20240411052257.2113-4-tony@atomide.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411052257.2113-1-tony@atomide.com> References: <20240411052257.2113-1-tony@atomide.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We can implement reset control framework for ti-sysc for the connected devices to use for the interconnect target reset. Signed-off-by: Tony Lindgren --- drivers/bus/ti-sysc.c | 109 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/drivers/bus/ti-sysc.c b/drivers/bus/ti-sysc.c --- a/drivers/bus/ti-sysc.c +++ b/drivers/bus/ti-sysc.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,7 @@ #define SOC_FLAG(match, flag) { .machine = match, .data = (void *)(flag), } +#define TI_SYSC_SOFTRESET_ID 0 #define MAX_MODULE_SOFTRESET_WAIT 10000 enum sysc_soc { @@ -79,6 +81,11 @@ struct sysc_soc_info { struct notifier_block nb; }; +struct sysc_reset_lookup { + struct list_head node; + struct reset_control_lookup lookup; +}; + enum sysc_clocks { SYSC_FCK, SYSC_ICK, @@ -147,6 +154,9 @@ struct sysc { const char **clock_roles; int nr_clocks; struct reset_control *rsts; + struct reset_controller_dev rcdev; + struct list_head child_resets; + struct mutex child_lock; /* child device data list lock */ const char *legacy_mode; const struct sysc_capabilities *cap; struct sysc_config cfg; @@ -2194,6 +2204,46 @@ static int sysc_reset(struct sysc *ddata) return error; } +/* + * Only handles the softreset for the interconnect target, does not consider + * the device specific external resets. We must ensure the interconnect target + * is runtime PM active for the reset. And we must restore the sysconfig + * register after reset. Locking is currently not needed as we only touch the + * sysconfig register on PM runtime state changes, and no other sysconfig + * register access happens when the interconnect target is runtime PM active. + * Interconnect targets with multiple children must coordinate the reset + * usage with reset_control_get_shared(). + */ +static int ti_sysc_reset_control_reset(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct sysc *ddata; + int error; + + if (id != TI_SYSC_SOFTRESET_ID) + return -EINVAL; + + ddata = container_of(rcdev, struct sysc, rcdev); + + error = pm_runtime_resume_and_get(ddata->dev); + if (error < 0) + return error; + + error = sysc_reset(ddata); + if (error) + dev_warn(ddata->dev, "reset failed: %i\n", error); + + sysc_write_sysconfig(ddata, ddata->sysconfig); + + pm_runtime_put_sync(ddata->dev); + + return error; +} + +static const struct reset_control_ops ti_sysc_reset_ops = { + .reset = ti_sysc_reset_control_reset, +}; + /* * At this point the module is configured enough to read the revision but * module may not be completely configured yet to use PM runtime. Enable @@ -2408,6 +2458,45 @@ static int sysc_child_add_clocks(struct sysc *ddata, return 0; } +static int sysc_child_add_reset(struct sysc *ddata, + struct device *child) +{ + struct sysc_reset_lookup *srl; + + srl = kzalloc(sizeof(*srl), GFP_KERNEL); + if (!srl) + return -ENOMEM; + + srl->lookup.provider = dev_name(ddata->dev); + srl->lookup.index = TI_SYSC_SOFTRESET_ID; + srl->lookup.dev_id = dev_name(child); + srl->lookup.con_id = "softreset"; + reset_controller_add_lookup(&srl->lookup, 1); + mutex_lock(&ddata->child_lock); + list_add(&srl->node, &ddata->child_resets); + mutex_unlock(&ddata->child_lock); + + return 0; +} + +static void sysc_child_remove_reset(struct sysc *ddata, + struct device *child) +{ + struct sysc_reset_lookup *srl; + + mutex_lock(&ddata->child_lock); + list_for_each_entry(srl, &ddata->child_resets, node) { + if (srl->lookup.index == TI_SYSC_SOFTRESET_ID && + !strcmp(dev_name(child), srl->lookup.dev_id)) { + reset_controller_remove_lookup(&srl->lookup, 1); + list_del(&srl->node); + kfree(srl); + break; + } + } + mutex_unlock(&ddata->child_lock); +} + static const struct device_type sysc_device_type = { }; @@ -2541,6 +2630,14 @@ static int sysc_notifier_call(struct notifier_block *nb, error = sysc_child_add_clocks(ddata, dev); if (error) return error; + + error = sysc_child_add_reset(ddata, dev); + if (error) + return error; + + break; + case BUS_NOTIFY_REMOVED_DEVICE: + sysc_child_remove_reset(ddata, dev); break; default: break; @@ -3186,6 +3283,8 @@ static int sysc_probe(struct platform_device *pdev) ddata->offsets[SYSC_SYSCONFIG] = -ENODEV; ddata->offsets[SYSC_SYSSTATUS] = -ENODEV; ddata->dev = &pdev->dev; + mutex_init(&ddata->child_lock); + INIT_LIST_HEAD(&ddata->child_resets); platform_set_drvdata(pdev, ddata); error = sysc_init_static_data(ddata); @@ -3266,6 +3365,16 @@ static int sysc_probe(struct platform_device *pdev) ddata->dev->type = &sysc_device_type; + ddata->rcdev.owner = THIS_MODULE; + ddata->rcdev.nr_resets = 1; + ddata->rcdev.ops = &ti_sysc_reset_ops; + ddata->rcdev.dev = &pdev->dev; + ddata->rcdev.of_node = ddata->dev->of_node; + + error = devm_reset_controller_register(ddata->dev, &ddata->rcdev); + if (error) + goto err; + if (!ddata->reserved) { error = of_platform_populate(ddata->dev->of_node, sysc_match_table, From patchwork Thu Apr 11 05:22:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 788957 Received: from mail5.25mail.st (mail5.25mail.st [74.50.62.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6455D13C80B; Thu, 11 Apr 2024 05:24:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.50.62.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712813074; cv=none; b=mjqBNqxawufwt0cVisZc9K4eBlG+OX3dp2STVfEMY02z5E8q/lUhWCkeHii/DG9208sStxeZFum/epfp15ZqJ/nKdSZ34PKNIsDXCP9OV5gCt0Ft645LjtIH7shhg6Ig1FpjjkfnwFB3vxMAt9XdByh+sLN1hg5CGclotgfBRYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712813074; c=relaxed/simple; bh=cMcNbp6qZx7YcqIcrUoQemHHiu6y77uoRqWrfG6QieM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pv/croC6fy1Nn4mKTkJ6UHajbTPi729MkssR2SJw4CmmqxkocGB/CwCKyFXIPTN1Zx4KjpE8ipnujNsfmR0sJsNkyyikZ4GGTMAMDge17sugcDWKjeZXUwL3l1ptOi6s+wP2iwkZvRUtg3Q74XtyKajPrUjI8H6EbzeIMtdP72Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atomide.com; spf=fail smtp.mailfrom=atomide.com; dkim=pass (2048-bit key) header.d=atomide.com header.i=@atomide.com header.b=AeUASavu; arc=none smtp.client-ip=74.50.62.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atomide.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=atomide.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=atomide.com header.i=@atomide.com header.b="AeUASavu" Received: from localhost (91-158-86-216.elisa-laajakaista.fi [91.158.86.216]) by mail5.25mail.st (Postfix) with ESMTPSA id E1BD7603E6; Thu, 11 Apr 2024 05:24:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=atomide.com; s=25mailst; t=1712813071; bh=cMcNbp6qZx7YcqIcrUoQemHHiu6y77uoRqWrfG6QieM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AeUASavufVbze58Mcc9yiMZJUZ+AJzhhii033h76dvsglXYe3qZI2Lsq77j8/xr2J 3HwNxRpYEhzkwfafWiENZPo1PYovEvN/M4piTHHX52WYTrZPqXrhMGG/UUlW4vNO7U KyKRqAeOKBWATbTiy2JwaPaWAOev0HLF2gxr+pLblT5Vwajz0Mv89evAkTeeBKTVdw X19HisXNj4blrVKw4sk7BsvR+MH4Y9zezDI0QEApL6ji7Q+E7uHA6oO3xB4/e70QvH r4f/eUqv2ppiFs8RFXA1jjA2TxTpVnHdd+yvWGC/6qdL6zHTmVnGFPZpGg8x0qxpvG r6KCs1WxRJG7w== From: Tony Lindgren To: linux-omap@vger.kernel.org Cc: Dhruva Gole , Greg Kroah-Hartman , Philipp Zabel , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [RFC PATCH 4/4] serial: 8250: omap: Use reset control for resets Date: Thu, 11 Apr 2024 08:22:57 +0300 Message-ID: <20240411052257.2113-5-tony@atomide.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411052257.2113-1-tony@atomide.com> References: <20240411052257.2113-1-tony@atomide.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For at least am335x and omap4, we set the UART_ERRATA_CLOCK_DISABLE quirk that ends up calling reset for the interconnect target. We can do this with reset control framework and simplify the 8250_omap driver. Signed-off-by: Tony Lindgren --- drivers/tty/serial/8250/8250_omap.c | 66 +++++++++++------------------ 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "8250.h" @@ -147,6 +148,7 @@ struct omap8250_priv { struct pm_qos_request pm_qos_request; struct work_struct qos_work; struct uart_8250_dma omap8250_dma; + struct reset_control *reset; spinlock_t rx_dma_lock; bool rx_dma_broken; bool throttled; @@ -1490,6 +1492,14 @@ static int omap8250_probe(struct platform_device *pdev) priv->line = -ENODEV; priv->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; priv->calc_latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; + + if (priv->habit & UART_ERRATA_CLOCK_DISABLE) { + priv->reset = devm_reset_control_get_exclusive(&pdev->dev, + "softreset"); + if (IS_ERR(priv->reset)) + return PTR_ERR(priv->reset); + } + cpu_latency_qos_add_request(&priv->pm_qos_request, priv->latency); INIT_WORK(&priv->qos_work, omap8250_uart_qos_work); @@ -1695,47 +1705,6 @@ static void uart_write(struct omap8250_priv *priv, u32 reg, u32 val) writel(val, priv->membase + (reg << OMAP_UART_REGSHIFT)); } -/* TODO: in future, this should happen via API in drivers/reset/ */ -static int omap8250_soft_reset(struct device *dev) -{ - struct omap8250_priv *priv = dev_get_drvdata(dev); - int timeout = 100; - int sysc; - int syss; - - /* - * At least on omap4, unused uarts may not idle after reset without - * a basic scr dma configuration even with no dma in use. The - * module clkctrl status bits will be 1 instead of 3 blocking idle - * for the whole clockdomain. The softreset below will clear scr, - * and we restore it on resume so this is safe to do on all SoCs - * needing omap8250_soft_reset() quirk. Do it in two writes as - * recommended in the comment for omap8250_update_scr(). - */ - uart_write(priv, UART_OMAP_SCR, OMAP_UART_SCR_DMAMODE_1); - uart_write(priv, UART_OMAP_SCR, - OMAP_UART_SCR_DMAMODE_1 | OMAP_UART_SCR_DMAMODE_CTL); - - sysc = uart_read(priv, UART_OMAP_SYSC); - - /* softreset the UART */ - sysc |= OMAP_UART_SYSC_SOFTRESET; - uart_write(priv, UART_OMAP_SYSC, sysc); - - /* By experiments, 1us enough for reset complete on AM335x */ - do { - udelay(1); - syss = uart_read(priv, UART_OMAP_SYSS); - } while (--timeout && !(syss & OMAP_UART_SYSS_RESETDONE)); - - if (!timeout) { - dev_err(dev, "timed out waiting for reset done\n"); - return -ETIMEDOUT; - } - - return 0; -} - static int omap8250_runtime_suspend(struct device *dev) { struct omap8250_priv *priv = dev_get_drvdata(dev); @@ -1747,7 +1716,20 @@ static int omap8250_runtime_suspend(struct device *dev) if (priv->habit & UART_ERRATA_CLOCK_DISABLE) { int ret; - ret = omap8250_soft_reset(dev); + /* + * At least on omap4, unused uarts may not idle after reset without + * a basic scr dma configuration even with no dma in use. The + * module clkctrl status bits will be 1 instead of 3 blocking idle + * for the whole clockdomain. The softreset below will clear scr, + * and we restore it on resume so this is safe to do on all SoCs + * needing omap8250_soft_reset() quirk. Do it in two writes as + * recommended in the comment for omap8250_update_scr(). + */ + uart_write(priv, UART_OMAP_SCR, OMAP_UART_SCR_DMAMODE_1); + uart_write(priv, UART_OMAP_SCR, + OMAP_UART_SCR_DMAMODE_1 | OMAP_UART_SCR_DMAMODE_CTL); + + ret = reset_control_reset(priv->reset); if (ret) return ret;