tegra: baseband: fix wrong value assignment. Thanks Anders Candell for the heads up.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
Signed-off-by: Andreas Pohl <apohl79@gmail.com>
freezer: fix current->state restoration race in refrigerator()

refrigerator() saves current->state before entering frozen state and
restores it before returning using __set_current_state(); however,
this is racy, for example, please consider the following sequence.

	set_current_state(TASK_INTERRUPTIBLE);
	try_to_freeze();
	if (kthread_should_stop())
		break;
	schedule();

If kthread_stop() races with ->state restoration, the restoration can
restore ->state to TASK_INTERRUPTIBLE after kthread_stop() sets it to
TASK_RUNNING but kthread_should_stop() may still see zero
->should_stop because there's no memory barrier between restoring
TASK_INTERRUPTIBLE and kthread_should_stop() test.

This isn't restricted to kthread_should_stop().  current->state is
often used in memory barrier based synchronization and silently
restoring it w/o mb breaks them.

Use set_current_state() instead.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
Signed-off-by: Andreas Pohl <apohl79@gmail.com>
PM / Hibernate: Freeze kernel threads after preallocating memory

There is a problem with the current ordering of hibernate code which
leads to deadlocks in some filesystems' memory shrinkers.  Namely,
some filesystems use freezable kernel threads that are inactive when
the hibernate memory preallocation is carried out.  Those same
filesystems use memory shrinkers that may be triggered by the
hibernate memory preallocation.  If those memory shrinkers wait for
the frozen kernel threads, the hibernate process deadlocks (this
happens with XFS, for one example).

Apparently, it is not technically viable to redesign the filesystems
in question to avoid the situation described above, so the only
possible solution of this issue is to defer the freezing of kernel
threads until the hibernate memory preallocation is done, which is
implemented by this change.

Unfortunately, this requires the memory preallocation to be done
before the "prepare" stage of device freeze, so after this change the
only way drivers can allocate additional memory for their freeze
routines in a clean way is to use PM notifiers.

Reported-by: Christoph <cr2005@u-club.de>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
Signed-off-by: Andreas Pohl <apohl79@gmail.com>
tegra_hotplug: merge the driver cleanup from Mako.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
Signed-off-by: Andreas Pohl <apohl79@gmail.com>
smp: we already have debug pr_info from tegra_hotplug, no need to get some debug from here.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
Signed-off-by: Andreas Pohl <apohl79@gmail.com>
tegra: cleanup suspend/resume mess, remove useless functions that cap speeds for edp and other clocks, tweak the power states latency residency, make sure the device enters LP0 on suspend. Hope nothing major breaks with this.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
Signed-off-by: Andreas Pohl <apohl79@gmail.com>