ARM: 7668/1: fix memset-related crashes caused by recent GCC (4.7.2) optimizations

Recent GCC versions (e.g. GCC-4.7.2) perform optimizations based on
assumptions about the implementation of memset and similar functions.
The current ARM optimized memset code does not return the value of
its first argument, as is usually expected from standard
implementations.

For instance in the following function:

void debug_mutex_lock_common(struct mutex *lock, struct mutex_waiter
*waiter)
{
	memset(waiter, MUTEX_DEBUG_INIT, sizeof(*waiter));
	waiter->magic = waiter;
	INIT_LIST_HEAD(&waiter->list);
}

compiled as:

800554d0 <debug_mutex_lock_common>:
800554d0:       e92d4008        push    {r3, lr}
800554d4:       e1a00001        mov     r0, r1
800554d8:       e3a02010        mov     r2, #16 ; 0x10
800554dc:       e3a01011        mov     r1, #17 ; 0x11
800554e0:       eb04426e        bl      80165ea0 <memset>
800554e4:       e1a03000        mov     r3, r0
800554e8:       e583000c        str     r0, [r3, #12]
800554ec:       e5830000        str     r0, [r3]
800554f0:       e5830004        str     r0, [r3, #4]
800554f4:       e8bd8008        pop     {r3, pc}

GCC assumes memset returns the value of pointer 'waiter' in register r0;
causing
register/memory corruptions.

This patch fixes the return value of the assembly version of memset.
It adds a 'mov' instruction and merges an additional load+store into
existing load/store instructions.
For ease of review, here is a breakdown of the patch into 4 simple
steps:

Step 1
======
Perform the following substitutions:
ip -> r8, then
r0 -> ip,
and insert 'mov ip, r0' as the first statement of the function.
At this point, we have a memset() implementation returning the proper
result,
but corrupting r8 on some paths (the ones that were using ip).

Step 2
======
Make sure r8 is saved and restored when (! CALGN(1)+0) == 1:

save r8:
-       str     lr, [sp, #-4]!
+       stmfd   sp!, {r8, lr}

and restore r8 on both exit paths:
-       ldmeqfd sp!, {pc}               @ Now <64 bytes to go.
+       ldmeqfd sp!, {r8, pc}           @ Now <64 bytes to go.
(...)
        tst     r2, #16
        stmneia ip!, {r1, r3, r8, lr}
-       ldr     lr, [sp], #4
+       ldmfd   sp!, {r8, lr}

Step 3
======
Make sure r8 is saved and restored when (! CALGN(1)+0) == 0:

save r8:
-       stmfd   sp!, {r4-r7, lr}
+       stmfd   sp!, {r4-r8, lr}

and restore r8 on both exit paths:
        bgt     3b
-       ldmeqfd sp!, {r4-r7, pc}
+       ldmeqfd sp!, {r4-r8, pc}
(...)
        tst     r2, #16
        stmneia ip!, {r4-r7}
-       ldmfd   sp!, {r4-r7, lr}
+       ldmfd   sp!, {r4-r8, lr}

Step 4
======
Rewrite register list "r4-r7, r8" as "r4-r8".

Change-Id: Ia78097371ce5bd58abb234db5ec170b9fe9d8f78
Signed-off-by: Ivan Djelic <ivan.djelic@parrot.com>
Reviewed-by: Nicolas Pitre <nico@linaro.org>
Signed-off-by: Dirk Behme <dirk.behme@gmail.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

ARM: 7670/1: fix the memset fix

Commit 455bd4c430b0 ("ARM: 7668/1: fix memset-related crashes caused by
recent GCC (4.7.2) optimizations") attempted to fix a compliance issue
with the memset return value.  However the memset itself became broken
by that patch for misaligned pointers.

This fixes the above by branching over the entry code from the
misaligned fixup code to avoid reloading the original pointer.

Also, because the function entry alignment is wrong in the Thumb mode
compilation, that fixup code is moved to the end.

While at it, the entry instructions are slightly reworked to help dual
issue pipelines.

Change-Id: I18ae82b7a22ff69e07ee59e887a3e400584db13d
Signed-off-by: Nicolas Pitre <nico@linaro.org>
Tested-by: Alexander Holler <holler@ahsoftware.de>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
disable CONFIG_SECURITY_SELINUX_DEVELOP

Change-Id: I05267c8e3044c639aa26e24f5435d4adafdb7d55
Merge "disable CONFIG_SECURITY_SELINUX_DEVELOP" into cm-11.0
Merge "ARM: 7668/1: fix memset-related crashes caused by recent GCC (4.7.2) optimizations" into cm-11.0
rtc: alarm: Add power-on alarm feature

Android does not support powering up of phone through alarm.
Adding shutdown hook in alarm driver which will set alarm while phone
is going down so as to power-up the phone after alarm expiration.

CRs-Fixed: 432312
Change-Id: I21786d264b93f7c0c660823a0a1a221c1b4df7b2
Signed-off-by: Ashay Jaiswal <ashayj@codeaurora.org>
rtc: alarm: Set power-on alarm 120 sec before actual alarm time

This will add extra buffer time for booting-up the device before
actual alarm expiration time.

Change-Id: I02cad84c394a6aab943fff37a1a0de56bb511f56
Signed-off-by: Mohit Aggarwal <maggarwa@codeaurora.org>
Signed-off-by: Ashay Jaiswal <ashayj@codeaurora.org>
kernel: alarm: :fix the BUG that device automatically powers on

The value of alarm.time is invalid if we get it by:
    memset(&alarm, 0, sizeof(alarm)).
So function of rtc_set_alarm aborts before it really calls into:
    rtc->ops->set_alarm.
Then we can`t disable the RTC alarm by that. The result is some
alarms enabled by alarm_suspend are not disabled correctly during
alarm_resume. And device will automatically power on.

CRs-fixed: 524051
Change-Id: Ibc99e62878d17ad4f50325630bf0862207e2cf3f
Signed-off-by: Figo Wang <figow@codeaurora.org>
kernel: alarm: add dedicated alarm type for poweroff alarm

Now we use type of RTC_WAKEUP for the poweroff alarm.
Actually lots of other applications also use this type.
But these applications never expect the device will
power on after it has been shut down. So we need to
add dedicated alarm type for the Deskclock or similar
applications.

CRs-fixed: 529674
Change-Id: I9b7911906446daa1aeb5835478c9837f8ef797f2
Signed-off-by: Figo Wang <figow@codeaurora.org>
kernel: alarm: Do not call rtc_alarm_irq_enable in IRQ Disabled context

Currently shutdown hook of alarm driver is calling
the rtc_alarm_irq_enable API in interrupts disabled
context. So fix the alarm_shutdown function to call
in API rtc_alarm_irq_enable in interrupt enabled context.

CRs-Fixed: 591790
Change-Id: Iebd82482be1dc95c6c978b617e1c18eb36e1b6eb
Signed-off-by: Prasad Sodagudi <psodagud@codeaurora.org>
board-8064-pmic: enable rtc_alarm_powerup

Change-Id: I7a54ce234cf7b8d208509ea8bb83ad49723553f9
sec-battery: Standardize the output of the "online" property

Return "0" when no power supply is present

Change-Id: Ic873705c20468cb5e7898fa2ddff5828cd5928cf
power: pm8921-charger: vote D0 when running kickstart

There is a small window when the PMIC could lock up while
running the kickstart routine. If PMIC sleeps right while
kickstart is run, it causes a short sleep which is known
to cause PMIC locksup.

To prevent these, specifically vote for D0 clock while
running kickstart which guarantees that the PMIC will not
sleep.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>

Conflicts:
	drivers/power/pm8921-charger.c

Change-Id: I830749c19c79fd63238769ecf7472d03d67e7aa2
power: pm8921-bms: fix calibration and UVLO issues

The bms is not running a hkadc calibration before calculating the
first SOC. This causes accuracy issues with the power on SOC.

Also when the battery gets in the low voltage range, don't limit
the corrections. We have seen UVLO where even though the BMS was
calculating SOC quickly it was not lowering the SOC fast enough.
Skip limiting ocv change when battery is near cutoff voltage.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>

Conflicts:
	drivers/power/pm8921-bms.c

Change-Id: I746a9b003135d51d51c7d039d411689ca69571dc
power: pm8921-charger: Add delay after turning on D0 (TCXO) clock

On APQ8064, TCXO cannot be turned off before its warm-up period (4ms).
This is not required on the platform which have a CXO. Add a warm-up
delay after turning on D0 (which turns on the TCXO).

Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/board-8064-pmic.c
	drivers/power/pm8921-charger.c
	include/linux/mfd/pm8xxx/pm8921-charger.h

Change-Id: Iaa91b8051d6d6ed7bd6394cc920411792b176224
power: pm8921-charger: Fix delay in USB wall-charger removal

Avoid scheduling time optimization for the vin_min work. This
prevents delay in USB removal detection for USB wall-charger.

CRs-Fixed: 579548
Change-Id: I578a0a70122e4d10ff932a41d6c6ac58e5ef121d
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>
Merge remote-tracking branch 'upstream/cm-11.0' into cm-11.0