AM335X: CM3: Remove some non-essential module handling code

CM3 should be worried about only the essential modules.
The additional module handling code can and should be
removed.

Note that PSP kernels still require a EMIF enable because of a bug
in sleep33xx.S. This is moved to pm_handlers so that it can be
later conditionally executed only for those older kernels.

Signed-off-by: Vaibhav Bedia <vaibhav.bedia@ti.com>
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
AM335X: CM3: Let MPU configure the IPs for wakeup

This patch just removes some debug code which was initially
added to debug incorrect wakeup configuration in IPs from
MPU code. Now that we have a working configuration on MPU
side the debug code in CM3 can be dropped.

Signed-off-by: Vaibhav Bedia <vaibhav.bedia@ti.com>
AM335X: CM3: Fix issue in parameter parsing for command handlers

cmd_global_data.data which is passed to all the
command handlers (a8_lp_cmd3_handler etc) was always
pointing to the data in IPC registers irrespective
of the value of 'use_default_val'. Because of this,
the values populated to the members of ds0_data,
ds1_data, standby_data (Ex:wake_sources) are ignored
by the command handlers.

This issue was noticed while trying to get standby mode
working with only MPU_WAKE as wake source.

Signed-off-by: Satyanarayana Sandhya <sandhya.satyanarayana@ti.com>
Signed-off-by: Vaibhav Bedia <vaibhav.bedia@ti.com>
AM335X: CM3: Leverage generic wakeup configuration for Standby

Instead of a new function to configure MPU_WAKE
as the supported wakeup mode, leverage the pre-
existing function shared across various DSx states.
Since MPU_WAKE in other DS modes can cause issues
the definition of WAKE_ALL macro is revised to skip
MPU_WAKE as a valid wakeup source in DSx.

Signed-off-by: Satyanarayana Sandhya <sandhya.satyanarayana@ti.com>
Signed-off-by: Vaibhav Bedia <vaibhav.bedia@ti.com>
AM335X: CM3: Rework DPLL power sequence for PG 2.X

No functional change. Just some rework to get rid
of some code duplication.

Signed-off-by: Vaibhav Bedia <vaibhav.bedia@ti.com>
AM335X: CM3: Turn on compiler optimization

This should have been done some time back but as someone
said 'premature optimization is the source of all evil' ;)

Signed-off-by: Vaibhav Bedia <vaibhav.bedia@ti.com>
AM335X: CM3: Check SoC ID along with SoC Rev in DPLL code

Instead of relying just on the SoC rev field check
the SoC ID also. At the same time consolidate the
DPLL power sequencing code and place it under proper
checks.

Signed-off-by: Vaibhav Bedia <vaibhav.bedia@ti.com>
AM335X: CM3: Move low power optimizations from MPU to CM3

Currently a lot of low power optimizations are done
from MPU code running out of OCMC RAM. The biggest
issue with this approach is that the assembly code
is quite big and folks have found it hard to review
and fixup issues in this dense piece of code.

Now that we have validated most of the combinations
(DDR2/3, VTT control etc) this piece of code aka the
black magic can be moved to CM3 without any difference
in functionality.

To take care of board variations, one of the reserved
IPC registers is now opened up for use. MPU code needs
to populate the following information in IPC_MSG_REG4
@ 0x44E11338:
Bits 2:0 - Memory type : DDR2 -> 2, DDR3 -> 3
Bit 3 - External VTT control : 1 -> true 0 -> false
Bit 9:4 - GPIO0 pin used for controlling VTT regulator

With the above information correctly populated, CM3
takes care of powering down the PLLs, manipulating
the DDR IOs, VTP controller, external VTT regulator,
MPU SRAM LDO and DDR RESET line in the recommended
sequence (same as what was done in MPU assembly code)
to save power in low power states.

A new set of V2 commands is created for newer kernels
to use so that the firmware maintains backwards
compatibility with older kernels.

Signed-off-by: Hebbar, Gururaja <gururaja.hebbar@ti.com>
Signed-off-by: Vaibhav Bedia <vaibhav.bedia@ti.com>
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
AM335X: CM3: Pass along the wakeup reason to MPU

Pass along the wakeup reason to MPU in one of the IPC
registers. Also add a debug bit to halt the system on
resume.

Signed-off-by: Vaibhav Bedia <vaibhav.bedia@ti.com>
AM335X: CM3: Add I2C sleep/wake sequence support

This patch adds support for writing I2C sequences during the sleep and
wake sequence. This enables features such as OPP50 (0.95V) for VDD CORE,
as on DDR3 systems this state can only be active with the memory
controller disabled.

The sequences are written to the end of the M3's DMEM. The offsets of
the sequences are passed as u16's in reg6 of the IPC registers, the
sleep sequence as the low word, the wake sequence as the high word. The
offsets are based on the start of DMEM. The sequences are a series of
transfers in the form:

u8 length | u8 chip address | u8 byte0/reg address | u8 byte 1 | u8 byte n ...

The length indicates the number of bytes to transfer, including the
register address. The length of each transfer is limited by the I2C
buffer size of 32 bytes. A length of zero terminates the sequence.

The sequence is prependend by an unsigned short representing the
transfer speed in kHz;

I attempted to add the possibilities of delays to the sequence, but I
could not get the SysTick functionality to work. Either the interrupt,
or the flag indicating the timer had rolled over.

Signed-off-by: Russ Dill <Russ.Dill@ti.com>
Signed-off-by: Vaibhav Bedia <vaibhav.bedia@ti.com>
AM335X: CM3: Ignore ON state settings for on-chip memories

ON state of the different on-chip memories, if required, can be
controlled from MPU itself. Moreover, so far we were just
restoring the pre-DS settings for these bits and hence there
is no functional difference in removing these from CM3. Doing
so also lets us repurpose some previous DS_PARAM bits. One of
the ON state bits in PD_PER is now repurposed for controlling
the second bank of OCMC memory in the next SoC.

Signed-off-by: Vaibhav Bedia <vaibhav.bedia@ti.com>
AM437X: CM3: Basic DS0 support

Update CM3 with basic support needed to enter and exit
DeepSleep state on AM437x. Most the changes in this
patch rework the pre-existing AM335x support to make
it generic enough to be usable on AM437x.

Signed-off-by: Vaibhav Bedia <vaibhav.bedia@ti.com>
CM3: Fix bug in rtc_enable_check

This check will always evaluate to true because a misplacement of a paren.

Signed-off-by: Russ Dill <Russ.Dill@ti.com>
CM3: Add additional warning options and compile options

-fno-delete-null-pointer-checks - Don't assume that just because a pointer is NULL,
operations on it can be complied out

-fno-strict-overflow - Don't assume that just because integer math overflows,
subsequent operations can be compiled out.

Signed-off-by: Russ Dill <Russ.Dill@ti.com>
CM3: Allow firmware to be built my newer versions of gcc

Newer versions of GCC add a build id section into the elf. This
section comes before text which ends up creating a problem
as we need vectors first. Move the .note.gnu.build-id section
after our text and rodata to keep things sane.

Signed-off-by: Russ Dill <Russ.Dill@ti.com>
CM3: Fix C style prototype issues.

The declaration for several functions are incomplete as they contain
an empty parameter list, insert void.

Signed-off-by: Russ Dill <russ.dill@ti.com>
CM3: Make var_mod static.

It is local to this file, don't pollute.

Signed-off-by: Russ Dill <Russ.Dill@ti.com>
CM3: Remove unused pd_*_pwrstst_next

Signed-off-by: Russ Dill <Russ.Dill@ti.com>
CM3: Remove unused reg_mod prototype

Signed-off-by: Russ Dill <Russ.Dill@ti.com>
CM3: Declare missing type for _next_pd_*_stctrl_val functions.

Signed-off-by: Russ Dill <Russ.Dill@ti.com>