ARM: OMAP: android_omap_defconfig: lock CPU freq during suspend

Add cmdline parameter to lock CPUFreq during system suspend/resume

 "omap-cpufreq.safe_suspend_freq=600000000"

As result, the freq will be locked to at suspend:
- OMAP4430 freq=600000000
- OMAP4460 freq=700000000
- OMAP4470 freq=800000000
- OMAP54xx freq=1000000000

Change-Id: I841b98bb93efeccfcf8b768f61f1f35a05c7098a
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
cpufreq: OMAP: add ability to lock MPU freq to user defined value during
suspend

Currently there the following scenario will prevent system from entering
suspend:
- boot system with USB device connected
- USB subsystem will set QoS constraint and lock Core to OPP100
- start system wide suspend "echo mem > sys/power/state"
- suspend will be aborted by AVS

[   82.982238] sr_classp5_suspend_noirq: smartreflex_core Calibration is
active, abort suspend

It happens because Core is locked to OPP100 by USB during boot and its
OPP50 will not be enabled until USB releases its QoS constraint. As
result, OPP50 isn't calibrated.
When USB is suspended during system wide suspend it releases QoS
constraint and CPUFreq framework will be able to switch Core to OPP50
(and it's doing this).
Therefore, when AVS sr_classp5_suspend_noirq() callback will be called -
it will detect that calibration has been started or there is a try to do
suspend with un-calibrated voltage and aborts system suspend.

In addition, the CPUFreq may request to scale MPU to High OPP at any
time during system wide suspend/resume - which may lead to system
instability or overheat, because AVS and thermal framework may be
suspended at this time.

Hence, add OMAP CPUFreq module parameter "safe_suspend_freq" which allows to
set frequency to be used during system wide suspend/resume (if set to 0
- system will be suspended using current frequency).
For example:
  echo 700000 > sys/module/omap_cpufreq/parameters/safe_suspend_freq

"safe_suspend_freq" should be selected carefully, because thermal
throttling will be inactive until freq is unlocked.

The CPUFreq lock is applied from PM_SUSPEND_PREPARE/PM_POST_SUSPEND PM
events notifiers handler.

Change-Id: I25f7ccf4ee7f44612e796cf80d8940237afe3b7c
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
ARM: OMAP3+: SmartReflex: print Vnom when suspend aborted by AVS

In case if suspend has been aborted by AVS the following messages might
be logged:
[   82.982238] sr_classp5_suspend_noirq: smartreflex_core Calibration is
active, abort suspend
 - or -
[   82.982238] sr_classp5_suspend_noirq: smartreflex_core Calibration
hasn't been done, abort suspend

It's very useful to know which OPP has not been calibrated yet at this
moment. Hence, add Vnom voltage value to these messages.

For example:
[   82.982238] sr_classp5_suspend_noirq: smartreflex_core Calibration is
active, abort suspend (Vnom=962000)

Change-Id: Ie556a2e11dfa6075cc2d89d496a4933bca7ea5dd
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Merge "ARM: OMAP: android_omap_defconfig: lock CPU freq during suspend" into p-android-omap-3.4
ti-st: tty_hci: Check kzalloc return value.

Check for error condition returned by kzalloc.

Change-Id: I658cba57b9177ff68feb63d6a0e701d2a226960f
Signed-off-by: Oleksandr Kozaruk <oleksandr.kozaruk@ti.com>
ti-st: tty_hci: Remove redundant assignment.

Clean up for the code: remove redundant assignment.

Change-Id: I595b549fedec4c89177f342c957e95668f184442
Signed-off-by: Oleksandr Kozaruk <oleksandr.kozaruk@ti.com>
ti-st: tty_hci: Fix race condition in hci_tty_open.

Race condition is possible in the hci_tty driver.
The race result in NULL pointer dereference due to
struct sk_buff_head rx_list is used without prior
initialization.

The error condition can easily reproduced with the script
and COM-7 wilink hardware module:
while [ 1 ]; do echo -n "fail" > /dev/nfc; sleep 2; done

[   56.229614] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[   56.238494] pgd = c0004000
[   56.241485] [00000000] *pgd=00000000
[   56.245513] Internal error: Oops: 805 [#1] PREEMPT SMP ARM
[   56.251586] Modules linked in: rproc_drm(O) tf_driver(O) gps_drv wl18xx(O) wl12xx(O) wlcore(O) mac80211(O) pvrsrvkm_sgx544_112(O) cfg80211(O) compat(O) [last unloaded: wlcore_sdio]
[   56.270141] CPU: 0    Tainted: G        W  O  (3.4.34-01546-g66a9034 #82)
[   56.277618] PC is at skb_queue_tail+0x2c/0x50
[   56.282409] LR is at _raw_spin_lock_irqsave+0x10/0x14
[   56.287994] pc : [<c04eeb04>]    lr : [<c0686618>]    psr: 60000193
[   56.287994] sp : d6cbde60  ip : d6cbde50  fp : d6cbde7c
[   56.300628] r10: d6ecf5d4  r9 : d6ecf558  r8 : 00000000
[   56.306335] r7 : d6ecf5ac  r6 : cb78347c  r5 : d67c6500  r4 : cb783470
[   56.313537] r3 : 00000000  r2 : a0000193  r1 : d67c6500  r0 : a0000193
[   56.320648] Flags: nZCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment kernel
[   56.328796] Control: 10c5387d  Table: 8b6a804a  DAC: 00000015
       [skiped ...]
[   57.452667] Backtrace:
[   57.455474] [<c04eead8>] (skb_queue_tail+0x0/0x50) from [<c0300bec>] (st_receive+0x18/0x34)
[   57.464630]  r6:d5920c59 r5:00000004 r4:cb783440 r3:c0300bd4
[   57.471191] [<c0300bd4>] (st_receive+0x0/0x34) from [<c02fe924>] (st_send_frame+0x50/0xac)
[   57.480255]  r4:d6ecf540 r3:c0300bd4
[   57.484344] [<c02fe8d4>] (st_send_frame+0x0/0xac) from [<c02ff13c>] (st_int_recv+0x1fc/0x3a0)
[   57.493713]  r5:00000000 r4:d6ecf540
[   57.497894] [<c02fef40>] (st_int_recv+0x0/0x3a0) from [<c02fe548>] (st_tty_receive+0x24/0x28)
[   57.507171] [<c02fe524>] (st_tty_receive+0x0/0x28) from [<c02bbac0>] (flush_to_ldisc+0x150/0x1b4)
[   57.516906] [<c02bb970>] (flush_to_ldisc+0x0/0x1b4) from [<c0061950>] (process_one_work+0x134/0x4ac)
[   57.526916] [<c006181c>] (process_one_work+0x0/0x4ac) from [<c0061e54>] (worker_thread+0x18c/0x3d8)
[   57.536865] [<c0061cc8>] (worker_thread+0x0/0x3d8) from [<c00668d0>] (kthread+0x90/0x9c)
[   57.545684] [<c0066840>] (kthread+0x0/0x9c) from [<c004a8a8>] (do_exit+0x0/0x804)
[   57.553894]  r6:c004a8a8 r5:c0066840 r4:d6c5dec4

Change-Id: Ife34d53b4fad45d1db600d71450b06dce0328b2c
Signed-off-by: Oleksandr Kozaruk <oleksandr.kozaruk@ti.com>
ti-st: tty_hci: Properly unregister protocols in open.

In case of error condition registered protocols were not
unregistered from st core when open syscall was called. Memory
allocated for the driver data was just freed. Then callback
from st_register() called st_reg_complete_cb, and complete()
had the argument from the already freed memory.

This could be the reason of the null pointer dereference, as in
the log below. The issue is rarely reproduced.

[  132.189086] (stc): st_register(12)
[  132.198394] (stc):  chnl_id list empty :12
[  132.205352] (stk) : st_kim_start
[  132.329040] (stk) :ldisc_install = 1
[  133.087829] mtp_open
[  133.329010] (stk) :ldisc installation timeout
[  133.334960] (stk) :ldisc_install = 0
[  134.336853] (stk) : timed out waiting for ldisc to be un-installed
[  134.463165] (stk) :ldisc_install = 1
[  135.469757] (stk) :ldisc installation timeout
[  135.474334] (stk) :ldisc_install = 0
[  135.557830] init: sys_prop: permission denied uid:1003 name:service.bootanim.exit
[  135.653076] init: Boot Animation exit
[  135.895965] (hci_tty): inside hci_tty_open (d66bce38, d66ff480)
[  135.902435] (stc): st_register(4)
[  135.906494] (stc):  ST_REG_IN_PROGRESS:4
[  135.910858] (stc): add_channel_to_table: id 4
[  136.477478] (stk) : timed out waiting for ldisc to be un-installed
[  136.594635] (stk) :ldisc_install = 1
[  137.595001] (stk) :ldisc installation timeout
[  137.603759] (stk) :ldisc_install = 0
[  138.602508] (stk) : timed out waiting for ldisc to be un-installed
[  138.727478] (stk) :ldisc_install = 1
[  139.727722] (stk) :ldisc installation timeout
[  139.733734] (stk) :ldisc_install = 0
[  140.580657] binder: release 1324:1324 transaction 19588 out, still active
[  140.735321] (stk) : timed out waiting for ldisc to be un-installed
[  140.852447] (stk) :ldisc_install = 1
[  141.852478] (stk) :ldisc installation timeout
[  141.857360] (stk) :ldisc_install = 0
[  141.914978] (hci_tty): Timeout(6 sec),didn't get reg completion signal from ST
[  142.868072] (stk) : timed out waiting for ldisc to be un-installed
[  142.985382] (stk) :ldisc_install = 1
[  143.985351] (stk) :ldisc installation timeout
[  143.991546] (stk) :ldisc_install = 0
[  144.993072] (stk) : timed out waiting for ldisc to be un-installed
[  145.002960] (stc):  KIM failure complete callback
[  145.008392] (stc):  st_reg_complete
[  145.012725] (hci_tty): @ st_reg_completion_cb
[  145.017639] Unable to handle kernel NULL pointer dereference at virtual address 00000010
[  145.026428] pgd = c7cc0000
[  145.029388] [00000010] *pgd=00000000
[  145.033386] Internal error: Oops: 5 [#1] PREEMPT SMP ARM
[  145.039215] Modules linked in: rproc_drm(O) tf_driver(O) gps_drv wl18xx(O) wl12xx(O) wlcore(O) mac80211(O) cfg80211(O) pvrsrvkm_sgx540_120(O) compat(O)
[  145.054870] CPU: 1    Tainted: G        W  O  (3.4.34 #1)
[  145.060821] PC is at __wake_up_common+0x2c/0x94
[  145.065734] LR is at complete+0x4c/0x60
[  145.069915] pc : [<c006ee4c>]    lr : [<c0070378>]    psr: a0000093
         [skiped...]
[  146.023742] Backtrace:
[  146.026550] [<c006ee20>] (__wake_up_common+0x0/0x94) from [<c0070378>] (complete+0x4c/0x60)
[  146.035644] [<c007032c>] (complete+0x0/0x60) from [<c0301f20>] (st_reg_completion_cb+0x30/0x38)
[  146.045104]  r6:d6ef5cd0 r5:00000092 r4:d617dd40
[  146.050384] [<c0301ef0>] (st_reg_completion_cb+0x0/0x38) from [<c02ffd34>] (st_reg_complete+0x60/0xa8)
[  146.060516]  r5:d6ef5cc4 r4:00000004
[  146.064575] [<c02ffcd4>] (st_reg_complete+0x0/0xa8) from [<c02fffac>] (st_register+0x230/0x324)
[  146.074066] [<c02ffd7c>] (st_register+0x0/0x324) from [<c0323cac>] (nfc_drv_open+0xe8/0x1e4)
[  146.083251]  r7:c8ec3840 r6:c0a5f89c r5:00000000 r4:c6016140
[  146.089752] [<c0323bc4>] (nfc_drv_open+0x0/0x1e4) from [<c0117aec>] (chrdev_open+0x9c/0x164)
[  146.098937] [<c0117a50>] (chrdev_open+0x0/0x164) from [<c0111b88>] (__dentry_open+0x200/0x2b8)
[  146.108306]  r8:c0117a50 r7:d66b1b28 r6:d5e1e910 r5:d69806f0 r4:c8ec3840
[  146.115997] [<c0111988>] (__dentry_open+0x0/0x2b8) from [<c0112c24>] (nameidata_to_filp+0x68/0x70)
[  146.125701] [<c0112bbc>] (nameidata_to_filp+0x0/0x70) from [<c01211ac>] (do_last.isra.20+0x150/0x6d4)
[  146.135711]  r7:00000026 r6:00000000 r5:00020002 r4:c6ccfed8
[  146.142272] [<c012105c>] (do_last.isra.20+0x0/0x6d4) from [<c0121954>] (path_openat+0xc0/0x3b8)
[  146.151672] [<c0121894>] (path_openat+0x0/0x3b8) from [<c0121d5c>] (do_filp_open+0x34/0x88)
[  146.160766] [<c0121d28>] (do_filp_open+0x0/0x88) from [<c0112d20>] (do_sys_open+0xf4/0x18c)
[  146.169830]  r7:00000001 r6:00000027 r5:00020002 r4:d63d1000
[  146.176330] [<c0112c2c>] (do_sys_open+0x0/0x18c) from [<c0112de0>] (sys_open+0x28/0x2c)
[  146.185058] [<c0112db8>] (sys_open+0x0/0x2c) from [<c0013680>] (ret_fast_syscall+0x0/0x30)
[  146.194061] Code: e1a08003 e50b2030 e157000c e59b9004 (e41c400c)
[

Change-Id: I10085ef1b1bc91ce3be01e179aa995287af271f1
Signed-off-by: Oleksandr Kozaruk <oleksandr.kozaruk@ti.com>
Merge remote-tracking branch 'origin/p-linux-omap-3.4' into HEAD
HACK: ARM: OMAP4: wakeupgen: Ignore 8th interrupt on GP devices

On OMAP4 GP devices 8th (secure) interrupt is constantly pending.
The source of this interrupt is CONTROL_CORE_SEC_STATUS register.
All its bits are OR'ed and wired to 8th GIC interrupt.
This resister contains power domain reset statuses.

Just after boot CONTROL_CORE_SEC_STATUS has at least one bit set,
so as soon as GIC is initialized in kernel it asserts 8th IRQ to A9.
The register can't be cleared on GP device because it is accessible
for write only from secure privileged mode.

CONTROL_CORE_SEC_STATUS_IRQ_MASK_DISABLE can be used to mask sources
from CONTROL_CORE_SEC_STATUS, but after reset all bits are unmasked
and can be masked only from secure privileged mode.

To workaround this issue on OMAP4 GP devices just ignore
8th interrupt in pending interrupts check.

Change-Id: I6ae41c82bb5b201a5bc9eb735f248be3e86d7a18
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@ti.com>
Signed-off-by: Taras Kondratiuk <taras@ti.com>
HACK: ARM: OMAP4470: wakeupgen: Enable ROM_CPU1_BACKUP errata

Commit 6a9c42c3f84fad476200a6e19e106ba3eea9787b
("ARM: OMAP4460: wakeupgen: set GIC_CPU0 backup status flag always")
introduced a fix for OMAP4460 ROM code bug.
The bug causes CPU0 crash in the ROM code during wakeup
from device off because of GIC resisters corruption.

This ROM code bug should be fixed in OMAP4470,
but we observe similar crash of CPU0 on wakeup.
Extending the errata WA to 4470 fixes CPU0 wakeup.
So enable it until the real rootcause is found.

Change-Id: I09744623e511042e2641489eb50f8a7178b43356
Signed-off-by: Taras Kondratiuk <taras@ti.com>
thermal: bandgap: Meld TSHUT config functions into one function

On OMAP4470 CONTROL_TSHUT_THRESHOLD was changed to one time writable
register, in difference to OMAP4460 where this register could be
rewrited at any time. Because of this we need to configure it using
one write operation.
So considering this, high and low thresholds should be configured
in one function. To accomplish that changing temp_sensor_configure_tshut_thigh()
and temp_sensor_configure_tlow() to just temp_sensor_configure_tshut().

Change-Id: Ib41b77f83cf07bd13c5a880dbd7cc652bdf73e77
Signed-off-by: Ruslan Ruslichenko <ruslan.ruslichenko@ti.com>
thermal: bandgap: Add TSHUT_CONFIG_ONCE feature

As on OMAP4470 TSHUT config is one time writebale register, we need to ensure
that driver does not try to reconfigure it after it was configured earlier during
boot.
For OMAP4470 GP devices content of tshut config register is not restored
after OFF mode, and it need to be configured manually to prevent spurious TSHUT
interrupt generation.

Change-Id: I6f232d02b534926fd987aaa4b4a87aa522cc8079
Signed-off-by: Ruslan Ruslichenko <ruslan.ruslichenko@ti.com>
thermal: bandgap: Set bandgap to single mode after suspend

After suspend bandgap should be set to single mode to avoid temperature
reading before TSHUT config and other critical registers are configured.
Other way, spurious TSHUT interrupts can be generated as temperature
conversion is done and TSHUT registers are not setup properly yet.
As on some devices continuous mode is default value after suspend and
reset, so we need to set it to single mode manually before enabling
bandgap functional clock.

Change-Id: Ie2a2f3c32ec284c9d40f3fb80e76a54147080540
Signed-off-by: Ruslan Ruslichenko <ruslan.ruslichenko@ti.com>
ARM: omap4plus_pm_min_defconfig: Enable Thermal support

It is not safe to work without thermal framework support, as device
can get overheat and corrupted. Additionally some critical thermal
registers need to be configured (like TSHUT registers) or problem
with OFF mode, warm reset may appear or device even can be damaged
if TSHUT interrupt is not configured and handled properly.

Change-Id: Ia4775e5f5d7411b995fbe76d3999a9a38c0d496a
Signed-off-by: Ruslan Ruslichenko <ruslan.ruslichenko@ti.com>
Merge remote-tracking branch 'origin/p-linux-omap-3.4' into HEAD
Revert "OMAP: Ignore undocumented pending interrupt"

This reverts commit e747449ea4934cb9bfbc8c807855f2d17d265f3b.
Merge branch 'p-android-omap-3.4' of git://git.omapzoom.org/kernel/omap into p-android-omap-3.4