Skip to content

Commit c182fa0

Browse files
tmlindgregkh
authored andcommitted
bus: ti-sysc: Add quirk handling for reinit on context lost
[ Upstream commit 9d88136 ] Some interconnect target modules such as otg and gpmc on am335x need a re-init after resume. As we also have PM runtime cases where the context may be lost, let's handle these all with cpu_pm. For the am335x resume path, we already have cpu_pm_resume() call cpu_pm_cluster_exit(). Signed-off-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1e299b0 commit c182fa0

2 files changed

Lines changed: 103 additions & 6 deletions

File tree

‎drivers/bus/ti-sysc.c‎

Lines changed: 102 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/io.h>
77
#include <linux/clk.h>
88
#include <linux/clkdev.h>
9+
#include <linux/cpu_pm.h>
910
#include <linux/delay.h>
1011
#include <linux/list.h>
1112
#include <linux/module.h>
@@ -52,11 +53,18 @@ struct sysc_address {
5253
struct list_head node;
5354
};
5455

56+
struct sysc_module {
57+
struct sysc *ddata;
58+
struct list_head node;
59+
};
60+
5561
struct sysc_soc_info {
5662
unsigned long general_purpose:1;
5763
enum sysc_soc soc;
58-
struct mutex list_lock; /* disabled modules list lock */
64+
struct mutex list_lock; /* disabled and restored modules list lock */
5965
struct list_head disabled_modules;
66+
struct list_head restored_modules;
67+
struct notifier_block nb;
6068
};
6169

6270
enum sysc_clocks {
@@ -2442,6 +2450,79 @@ static struct dev_pm_domain sysc_child_pm_domain = {
24422450
}
24432451
};
24442452

2453+
/* Caller needs to take list_lock if ever used outside of cpu_pm */
2454+
static void sysc_reinit_modules(struct sysc_soc_info *soc)
2455+
{
2456+
struct sysc_module *module;
2457+
struct list_head *pos;
2458+
struct sysc *ddata;
2459+
int error = 0;
2460+
2461+
list_for_each(pos, &sysc_soc->restored_modules) {
2462+
module = list_entry(pos, struct sysc_module, node);
2463+
ddata = module->ddata;
2464+
error = sysc_reinit_module(ddata, ddata->enabled);
2465+
}
2466+
}
2467+
2468+
/**
2469+
* sysc_context_notifier - optionally reset and restore module after idle
2470+
* @nb: notifier block
2471+
* @cmd: unused
2472+
* @v: unused
2473+
*
2474+
* Some interconnect target modules need to be restored, or reset and restored
2475+
* on CPU_PM CPU_PM_CLUSTER_EXIT notifier. This is needed at least for am335x
2476+
* OTG and GPMC target modules even if the modules are unused.
2477+
*/
2478+
static int sysc_context_notifier(struct notifier_block *nb, unsigned long cmd,
2479+
void *v)
2480+
{
2481+
struct sysc_soc_info *soc;
2482+
2483+
soc = container_of(nb, struct sysc_soc_info, nb);
2484+
2485+
switch (cmd) {
2486+
case CPU_CLUSTER_PM_ENTER:
2487+
break;
2488+
case CPU_CLUSTER_PM_ENTER_FAILED: /* No need to restore context */
2489+
break;
2490+
case CPU_CLUSTER_PM_EXIT:
2491+
sysc_reinit_modules(soc);
2492+
break;
2493+
}
2494+
2495+
return NOTIFY_OK;
2496+
}
2497+
2498+
/**
2499+
* sysc_add_restored - optionally add reset and restore quirk hanlling
2500+
* @ddata: device data
2501+
*/
2502+
static void sysc_add_restored(struct sysc *ddata)
2503+
{
2504+
struct sysc_module *restored_module;
2505+
2506+
restored_module = kzalloc(sizeof(*restored_module), GFP_KERNEL);
2507+
if (!restored_module)
2508+
return;
2509+
2510+
restored_module->ddata = ddata;
2511+
2512+
mutex_lock(&sysc_soc->list_lock);
2513+
2514+
list_add(&restored_module->node, &sysc_soc->restored_modules);
2515+
2516+
if (sysc_soc->nb.notifier_call)
2517+
goto out_unlock;
2518+
2519+
sysc_soc->nb.notifier_call = sysc_context_notifier;
2520+
cpu_pm_register_notifier(&sysc_soc->nb);
2521+
2522+
out_unlock:
2523+
mutex_unlock(&sysc_soc->list_lock);
2524+
}
2525+
24452526
/**
24462527
* sysc_legacy_idle_quirk - handle children in omap_device compatible way
24472528
* @ddata: device driver data
@@ -2941,12 +3022,14 @@ static int sysc_add_disabled(unsigned long base)
29413022
}
29423023

29433024
/*
2944-
* One time init to detect the booted SoC and disable unavailable features.
3025+
* One time init to detect the booted SoC, disable unavailable features
3026+
* and initialize list for optional cpu_pm notifier.
3027+
*
29453028
* Note that we initialize static data shared across all ti-sysc instances
29463029
* so ddata is only used for SoC type. This can be called from module_init
29473030
* once we no longer need to rely on platform data.
29483031
*/
2949-
static int sysc_init_soc(struct sysc *ddata)
3032+
static int sysc_init_static_data(struct sysc *ddata)
29503033
{
29513034
const struct soc_device_attribute *match;
29523035
struct ti_sysc_platform_data *pdata;
@@ -2962,6 +3045,7 @@ static int sysc_init_soc(struct sysc *ddata)
29623045

29633046
mutex_init(&sysc_soc->list_lock);
29643047
INIT_LIST_HEAD(&sysc_soc->disabled_modules);
3048+
INIT_LIST_HEAD(&sysc_soc->restored_modules);
29653049
sysc_soc->general_purpose = true;
29663050

29673051
pdata = dev_get_platdata(ddata->dev);
@@ -3026,15 +3110,24 @@ static int sysc_init_soc(struct sysc *ddata)
30263110
return 0;
30273111
}
30283112

3029-
static void sysc_cleanup_soc(void)
3113+
static void sysc_cleanup_static_data(void)
30303114
{
3115+
struct sysc_module *restored_module;
30313116
struct sysc_address *disabled_module;
30323117
struct list_head *pos, *tmp;
30333118

30343119
if (!sysc_soc)
30353120
return;
30363121

3122+
if (sysc_soc->nb.notifier_call)
3123+
cpu_pm_unregister_notifier(&sysc_soc->nb);
3124+
30373125
mutex_lock(&sysc_soc->list_lock);
3126+
list_for_each_safe(pos, tmp, &sysc_soc->restored_modules) {
3127+
restored_module = list_entry(pos, struct sysc_module, node);
3128+
list_del(pos);
3129+
kfree(restored_module);
3130+
}
30383131
list_for_each_safe(pos, tmp, &sysc_soc->disabled_modules) {
30393132
disabled_module = list_entry(pos, struct sysc_address, node);
30403133
list_del(pos);
@@ -3102,7 +3195,7 @@ static int sysc_probe(struct platform_device *pdev)
31023195
ddata->dev = &pdev->dev;
31033196
platform_set_drvdata(pdev, ddata);
31043197

3105-
error = sysc_init_soc(ddata);
3198+
error = sysc_init_static_data(ddata);
31063199
if (error)
31073200
return error;
31083201

@@ -3200,6 +3293,9 @@ static int sysc_probe(struct platform_device *pdev)
32003293
pm_runtime_put(&pdev->dev);
32013294
}
32023295

3296+
if (ddata->cfg.quirks & SYSC_QUIRK_REINIT_ON_CTX_LOST)
3297+
sysc_add_restored(ddata);
3298+
32033299
return 0;
32043300

32053301
err:
@@ -3281,7 +3377,7 @@ static void __exit sysc_exit(void)
32813377
{
32823378
bus_unregister_notifier(&platform_bus_type, &sysc_nb);
32833379
platform_driver_unregister(&sysc_driver);
3284-
sysc_cleanup_soc();
3380+
sysc_cleanup_static_data();
32853381
}
32863382
module_exit(sysc_exit);
32873383

‎include/linux/platform_data/ti-sysc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct sysc_regbits {
5050
s8 emufree_shift;
5151
};
5252

53+
#define SYSC_QUIRK_REINIT_ON_CTX_LOST BIT(28)
5354
#define SYSC_QUIRK_REINIT_ON_RESUME BIT(27)
5455
#define SYSC_QUIRK_GPMC_DEBUG BIT(26)
5556
#define SYSC_MODULE_QUIRK_ENA_RESETDONE BIT(25)

0 commit comments

Comments
 (0)