PM / AVS: SmartReflex: update NVALUE table handling

The following new fields added to NVALUE table:
- volt_margin;
- volt_calibrated;
- volt_dynamic_nominal;
- errgain;

These fields are designed for the following usage in the different
SmartReflex calibration algorithms. For this reason
sr_retrieve_nvalue_row() function become public - it may be called
from outside, for example by SmartReflex calibration functions.

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
PM / AVS: SmartReflex: retrieve omap_sr* from pdata on driver remove

struct omap_sr* is stored in platform data during SmartReflex driver
probe. Therefore on driver remove it can be directly accessed,
benefit of such solution - is removing of one _sr_lookup()
function call.

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
PM / AVS: SmartReflex: do not use class configure callback in driver

SmartReflex class is marked for removal. Patch removes one
of dependencies between SmartReflex driver and SmartReflex class.
The only what class callback did - is a direct call of
sr_configure_errgen(sr). Now it is called directly instead of
callback to class.

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
PM / AVS: SmartReflex: add new data which defines calibration type

Different algorithms of SmartReflex calibration can be defined
using only three parameters:
- calibration period (continuous or periodic)
- calibration voltage (nominal or pre-calibrated)
- calibration loop (hardware or software)

Patch adds needed field to struct omap_sr, according to these
fields, driver will decide which algorithm of calibration
should be used.

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
PM / AVS: SmartReflex: init driver using DTB

SmartReflex SoC is going to be placed in Device Tree.
Patch adds posibility to use it, it updates init sequence of
SmartReflex driver:
- SmartReflex speific data is retrieved from DTB
- NVALUES are read from EFUSES during driver probe

To keep backward compatibility, SmartReflex can be initialized
in the usual way - using platform_device and platform_data, which are
defined in sr_device.c. This path is used if DTB is not defined for
corresponding SmartReflex.

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
PM / AVS: SmartReflex: introduce notifiers flags

SmartReflex IP V1 and V2 have different registers and offsets.
Currently, we pass the status as is to the class driver. However,
since we don't pass the version of the underlying SR hardware
to the Class driver, it will not be unable to make consistent
sense of the status bits coming over to it.

A class driver should be able to function without dependency
on the exact IP version it is actually running on. We hence
introduce our own translation in software level for a generic
notification flag.

As part of this change, we will now call the notifier iff we get
a match with the notifier flags that the class driver requested.

Signed-off-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
PM / AVS: SmartReflex: introduce notifier_control

We need some mechanism from class drivers to control when notifiers
should be triggered and when not, currently we have none, which makes
Class driver usage of the interrupt events almost impossible.

We also ensure that disable/enable or irq is always guarenteed to be
paired. The need to do this is because of the mixture of interrupt based
and polling based operations that is implemented as the most optimal
strategy for various SmartReflex AVS class

Introduce an SmartReflex driver API for doing the same. This is useful
for SmartReflex AVS class 1.5 or 2 drivers.

Signed-off-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
PM / AVS: SmartReflex: add supply regulator for voltage control

SmartReflex needs supply regulator to do actual voltage scaling.
For example - class 0 does direct voltage scaling, without any
calibration loop. Also driver needs to reset voltages (i.e.
scale them to nominal) in case when SmartReflex is explicitly
disabled.

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
PM / AVS: SmartReflex: introduce API for voltage reset

SmartReflex driver is designed to be responsible for voltages reset.
Patch provides API to do this.

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
PM / AVS: VP: add public API for using in SmartReflex

Some SmartReflex calibration algorithms require direct access to
Voltage Processor. Patch introduces the following API:
- int omap_vp_update_errorgain(struct device *v_dev, u8 errorgain);
- int omap_vp_enable(struct device *v_dev, u32 target_volt);
- void omap_vp_disable(struct device *v_dev);
- u32 omap_vp_get_voltage(struct device *v_dev);
- bool omap_vp_check_tranxdone(struct device *v_dev);
- void omap_vp_clear_tranxdone(struct device *v_dev);

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
PM / AVS: VP: introduce irqsave lock for VP regmap

VP API function which retrieves current voltage is used
in atomic context - in SmartReflex interrupt handler, therefore
default regmap lock is not enough - it doesn't disable interrupts,
and it can't be used for synchronization between IRQ context
and kernel thread context where regulator_get_voltage() is typically
used. spin_lock_irqsave / spin_unlock_irqrestore functions should be
used here, otherwise a deadlock may occur.

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
PM / AVS: SmartReflex: introduce SmartReflex Algorithms module

Now SmartReflex is designed to work without such abstraction
as "SmartReflex class". It is designed to choose appropriate
calibration algorithm, according to it settings retrieved from
device tree. Algorithms module is a container of calibration
logic. All algorithms are "private". The only API which is
exported is:

Init algorithms on boot:
- int sr_init_algs(struct omap_sr *sr);
- int sr_deinit_algs(struct omap_sr *sr);

"Getters" for calibration algorithms. Used for appropriate initialization
of driver callbacks, according to DTB parameters (calibration type,
voltage type and loop type).

sr_start_calibration_pfunc
sr_get_start_calibration_func(enum omap_sr_calibration_period period);

sr_stop_calibration_pfunc
sr_get_stop_calibration_func(enum omap_sr_calibration_period period);

sr_start_loop_pfunc
sr_get_start_loop_func(enum omap_sr_calibration_loop loop);

sr_stop_loop_pfunc
sr_get_stop_loop_func(enum omap_sr_calibration_loop loop);

Right now the following instances are implemented:
- Continuous claibration. Was used in class 3
- Periodic calibration. Was used in class 1.5
- HW calibration loop. Was used in class 3 and 1.5

Other algorithms are not covered by this patch.
Their implementation is pending. It will be introduced asap.

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
PM / AVS: SmartReflex: start using Algorithms module

SmartReflex Algorithms is already introduced. Now it is
started to be used. Patch adds it appropriate initialization
and needed calls for calibration start/stop.

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
PM / AVS: SmartReflex: sr_class is removed as useless

Since SmartReflex Algorithm module is started being used,
SmartReflex class is not needed any more. Now it usage is
removed from driver.

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
ARM: dts: OMAP4430: add device node for AVS

Patch adds AVS device node definition for MPU voltagedomain.
Current DTB entry contains data to make SmartReflex working
as class 3.0 - continuous calibration, HW loop.

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
TEST ONLY: PM / AVS: force calibration on boot on OPP_NOM

Patch is added to verify first time calibration,
which occurs immediately after SmartReflex driver probe.

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
ARM: dts: OMAP4430: modify smartreflex_mpu device node for class 1.5

Patch adds needed data to make Smartreflex driver working as
class 1.5 - periodic calibration, HW loop

Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>