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+
5561struct 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
6270enum sysc_clocks {
@@ -2477,6 +2485,79 @@ static struct dev_pm_domain sysc_child_pm_domain = {
24772485 }
24782486};
24792487
2488+ /* Caller needs to take list_lock if ever used outside of cpu_pm */
2489+ static void sysc_reinit_modules (struct sysc_soc_info * soc )
2490+ {
2491+ struct sysc_module * module ;
2492+ struct list_head * pos ;
2493+ struct sysc * ddata ;
2494+ int error = 0 ;
2495+
2496+ list_for_each (pos , & sysc_soc -> restored_modules ) {
2497+ module = list_entry (pos , struct sysc_module , node );
2498+ ddata = module -> ddata ;
2499+ error = sysc_reinit_module (ddata , ddata -> enabled );
2500+ }
2501+ }
2502+
2503+ /**
2504+ * sysc_context_notifier - optionally reset and restore module after idle
2505+ * @nb: notifier block
2506+ * @cmd: unused
2507+ * @v: unused
2508+ *
2509+ * Some interconnect target modules need to be restored, or reset and restored
2510+ * on CPU_PM CPU_PM_CLUSTER_EXIT notifier. This is needed at least for am335x
2511+ * OTG and GPMC target modules even if the modules are unused.
2512+ */
2513+ static int sysc_context_notifier (struct notifier_block * nb , unsigned long cmd ,
2514+ void * v )
2515+ {
2516+ struct sysc_soc_info * soc ;
2517+
2518+ soc = container_of (nb , struct sysc_soc_info , nb );
2519+
2520+ switch (cmd ) {
2521+ case CPU_CLUSTER_PM_ENTER :
2522+ break ;
2523+ case CPU_CLUSTER_PM_ENTER_FAILED : /* No need to restore context */
2524+ break ;
2525+ case CPU_CLUSTER_PM_EXIT :
2526+ sysc_reinit_modules (soc );
2527+ break ;
2528+ }
2529+
2530+ return NOTIFY_OK ;
2531+ }
2532+
2533+ /**
2534+ * sysc_add_restored - optionally add reset and restore quirk hanlling
2535+ * @ddata: device data
2536+ */
2537+ static void sysc_add_restored (struct sysc * ddata )
2538+ {
2539+ struct sysc_module * restored_module ;
2540+
2541+ restored_module = kzalloc (sizeof (* restored_module ), GFP_KERNEL );
2542+ if (!restored_module )
2543+ return ;
2544+
2545+ restored_module -> ddata = ddata ;
2546+
2547+ mutex_lock (& sysc_soc -> list_lock );
2548+
2549+ list_add (& restored_module -> node , & sysc_soc -> restored_modules );
2550+
2551+ if (sysc_soc -> nb .notifier_call )
2552+ goto out_unlock ;
2553+
2554+ sysc_soc -> nb .notifier_call = sysc_context_notifier ;
2555+ cpu_pm_register_notifier (& sysc_soc -> nb );
2556+
2557+ out_unlock :
2558+ mutex_unlock (& sysc_soc -> list_lock );
2559+ }
2560+
24802561/**
24812562 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
24822563 * @ddata: device driver data
@@ -2976,12 +3057,14 @@ static int sysc_add_disabled(unsigned long base)
29763057}
29773058
29783059/*
2979- * One time init to detect the booted SoC and disable unavailable features.
3060+ * One time init to detect the booted SoC, disable unavailable features
3061+ * and initialize list for optional cpu_pm notifier.
3062+ *
29803063 * Note that we initialize static data shared across all ti-sysc instances
29813064 * so ddata is only used for SoC type. This can be called from module_init
29823065 * once we no longer need to rely on platform data.
29833066 */
2984- static int sysc_init_soc (struct sysc * ddata )
3067+ static int sysc_init_static_data (struct sysc * ddata )
29853068{
29863069 const struct soc_device_attribute * match ;
29873070 struct ti_sysc_platform_data * pdata ;
@@ -2997,6 +3080,7 @@ static int sysc_init_soc(struct sysc *ddata)
29973080
29983081 mutex_init (& sysc_soc -> list_lock );
29993082 INIT_LIST_HEAD (& sysc_soc -> disabled_modules );
3083+ INIT_LIST_HEAD (& sysc_soc -> restored_modules );
30003084 sysc_soc -> general_purpose = true;
30013085
30023086 pdata = dev_get_platdata (ddata -> dev );
@@ -3060,15 +3144,24 @@ static int sysc_init_soc(struct sysc *ddata)
30603144 return 0 ;
30613145}
30623146
3063- static void sysc_cleanup_soc (void )
3147+ static void sysc_cleanup_static_data (void )
30643148{
3149+ struct sysc_module * restored_module ;
30653150 struct sysc_address * disabled_module ;
30663151 struct list_head * pos , * tmp ;
30673152
30683153 if (!sysc_soc )
30693154 return ;
30703155
3156+ if (sysc_soc -> nb .notifier_call )
3157+ cpu_pm_unregister_notifier (& sysc_soc -> nb );
3158+
30713159 mutex_lock (& sysc_soc -> list_lock );
3160+ list_for_each_safe (pos , tmp , & sysc_soc -> restored_modules ) {
3161+ restored_module = list_entry (pos , struct sysc_module , node );
3162+ list_del (pos );
3163+ kfree (restored_module );
3164+ }
30723165 list_for_each_safe (pos , tmp , & sysc_soc -> disabled_modules ) {
30733166 disabled_module = list_entry (pos , struct sysc_address , node );
30743167 list_del (pos );
@@ -3136,7 +3229,7 @@ static int sysc_probe(struct platform_device *pdev)
31363229 ddata -> dev = & pdev -> dev ;
31373230 platform_set_drvdata (pdev , ddata );
31383231
3139- error = sysc_init_soc (ddata );
3232+ error = sysc_init_static_data (ddata );
31403233 if (error )
31413234 return error ;
31423235
@@ -3234,6 +3327,9 @@ static int sysc_probe(struct platform_device *pdev)
32343327 pm_runtime_put (& pdev -> dev );
32353328 }
32363329
3330+ if (ddata -> cfg .quirks & SYSC_QUIRK_REINIT_ON_CTX_LOST )
3331+ sysc_add_restored (ddata );
3332+
32373333 return 0 ;
32383334
32393335err :
@@ -3315,7 +3411,7 @@ static void __exit sysc_exit(void)
33153411{
33163412 bus_unregister_notifier (& platform_bus_type , & sysc_nb );
33173413 platform_driver_unregister (& sysc_driver );
3318- sysc_cleanup_soc ();
3414+ sysc_cleanup_static_data ();
33193415}
33203416module_exit (sysc_exit );
33213417
0 commit comments