18c2ecf20Sopenharmony_ci=====================
28c2ecf20Sopenharmony_ciThe OMAP PM interface
38c2ecf20Sopenharmony_ci=====================
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciThis document describes the temporary OMAP PM interface.  Driver
68c2ecf20Sopenharmony_ciauthors use these functions to communicate minimum latency or
78c2ecf20Sopenharmony_cithroughput constraints to the kernel power management code.
88c2ecf20Sopenharmony_ciOver time, the intention is to merge features from the OMAP PM
98c2ecf20Sopenharmony_ciinterface into the Linux PM QoS code.
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ciDrivers need to express PM parameters which:
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci- support the range of power management parameters present in the TI SRF;
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci- separate the drivers from the underlying PM parameter
168c2ecf20Sopenharmony_ci  implementation, whether it is the TI SRF or Linux PM QoS or Linux
178c2ecf20Sopenharmony_ci  latency framework or something else;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci- specify PM parameters in terms of fundamental units, such as
208c2ecf20Sopenharmony_ci  latency and throughput, rather than units which are specific to OMAP
218c2ecf20Sopenharmony_ci  or to particular OMAP variants;
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci- allow drivers which are shared with other architectures (e.g.,
248c2ecf20Sopenharmony_ci  DaVinci) to add these constraints in a way which won't affect non-OMAP
258c2ecf20Sopenharmony_ci  systems,
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci- can be implemented immediately with minimal disruption of other
288c2ecf20Sopenharmony_ci  architectures.
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciThis document proposes the OMAP PM interface, including the following
328c2ecf20Sopenharmony_cifive power management functions for driver code:
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci1. Set the maximum MPU wakeup latency::
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci   (*pdata->set_max_mpu_wakeup_lat)(struct device *dev, unsigned long t)
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci2. Set the maximum device wakeup latency::
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci   (*pdata->set_max_dev_wakeup_lat)(struct device *dev, unsigned long t)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci3. Set the maximum system DMA transfer start latency (CORE pwrdm)::
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci   (*pdata->set_max_sdma_lat)(struct device *dev, long t)
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci4. Set the minimum bus throughput needed by a device::
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci   (*pdata->set_min_bus_tput)(struct device *dev, u8 agent_id, unsigned long r)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci5. Return the number of times the device has lost context::
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci   (*pdata->get_dev_context_loss_count)(struct device *dev)
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ciFurther documentation for all OMAP PM interface functions can be
568c2ecf20Sopenharmony_cifound in arch/arm/plat-omap/include/mach/omap-pm.h.
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciThe OMAP PM layer is intended to be temporary
608c2ecf20Sopenharmony_ci---------------------------------------------
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciThe intention is that eventually the Linux PM QoS layer should support
638c2ecf20Sopenharmony_cithe range of power management features present in OMAP3.  As this
648c2ecf20Sopenharmony_cihappens, existing drivers using the OMAP PM interface can be modified
658c2ecf20Sopenharmony_cito use the Linux PM QoS code; and the OMAP PM interface can disappear.
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciDriver usage of the OMAP PM functions
698c2ecf20Sopenharmony_ci-------------------------------------
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ciAs the 'pdata' in the above examples indicates, these functions are
728c2ecf20Sopenharmony_ciexposed to drivers through function pointers in driver .platform_data
738c2ecf20Sopenharmony_cistructures.  The function pointers are initialized by the `board-*.c`
748c2ecf20Sopenharmony_cifiles to point to the corresponding OMAP PM functions:
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci- set_max_dev_wakeup_lat will point to
778c2ecf20Sopenharmony_ci  omap_pm_set_max_dev_wakeup_lat(), etc.  Other architectures which do
788c2ecf20Sopenharmony_ci  not support these functions should leave these function pointers set
798c2ecf20Sopenharmony_ci  to NULL.  Drivers should use the following idiom::
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci        if (pdata->set_max_dev_wakeup_lat)
828c2ecf20Sopenharmony_ci            (*pdata->set_max_dev_wakeup_lat)(dev, t);
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ciThe most common usage of these functions will probably be to specify
858c2ecf20Sopenharmony_cithe maximum time from when an interrupt occurs, to when the device
868c2ecf20Sopenharmony_cibecomes accessible.  To accomplish this, driver writers should use the
878c2ecf20Sopenharmony_ciset_max_mpu_wakeup_lat() function to constrain the MPU wakeup
888c2ecf20Sopenharmony_cilatency, and the set_max_dev_wakeup_lat() function to constrain the
898c2ecf20Sopenharmony_cidevice wakeup latency (from clk_enable() to accessibility).  For
908c2ecf20Sopenharmony_ciexample::
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci        /* Limit MPU wakeup latency */
938c2ecf20Sopenharmony_ci        if (pdata->set_max_mpu_wakeup_lat)
948c2ecf20Sopenharmony_ci            (*pdata->set_max_mpu_wakeup_lat)(dev, tc);
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci        /* Limit device powerdomain wakeup latency */
978c2ecf20Sopenharmony_ci        if (pdata->set_max_dev_wakeup_lat)
988c2ecf20Sopenharmony_ci            (*pdata->set_max_dev_wakeup_lat)(dev, td);
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci        /* total wakeup latency in this example: (tc + td) */
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ciThe PM parameters can be overwritten by calling the function again
1038c2ecf20Sopenharmony_ciwith the new value.  The settings can be removed by calling the
1048c2ecf20Sopenharmony_cifunction with a t argument of -1 (except in the case of
1058c2ecf20Sopenharmony_ciset_max_bus_tput(), which should be called with an r argument of 0).
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ciThe fifth function above, omap_pm_get_dev_context_loss_count(),
1088c2ecf20Sopenharmony_ciis intended as an optimization to allow drivers to determine whether the
1098c2ecf20Sopenharmony_cidevice has lost its internal context.  If context has been lost, the
1108c2ecf20Sopenharmony_cidriver must restore its internal context before proceeding.
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ciOther specialized interface functions
1148c2ecf20Sopenharmony_ci-------------------------------------
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ciThe five functions listed above are intended to be usable by any
1178c2ecf20Sopenharmony_cidevice driver.  DSPBridge and CPUFreq have a few special requirements.
1188c2ecf20Sopenharmony_ciDSPBridge expresses target DSP performance levels in terms of OPP IDs.
1198c2ecf20Sopenharmony_ciCPUFreq expresses target MPU performance levels in terms of MPU
1208c2ecf20Sopenharmony_cifrequency.  The OMAP PM interface contains functions for these
1218c2ecf20Sopenharmony_cispecialized cases to convert that input information (OPPs/MPU
1228c2ecf20Sopenharmony_cifrequency) into the form that the underlying power management
1238c2ecf20Sopenharmony_ciimplementation needs:
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci6. `(*pdata->dsp_get_opp_table)(void)`
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci7. `(*pdata->dsp_set_min_opp)(u8 opp_id)`
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci8. `(*pdata->dsp_get_opp)(void)`
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci9. `(*pdata->cpu_get_freq_table)(void)`
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci10. `(*pdata->cpu_set_freq)(unsigned long f)`
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci11. `(*pdata->cpu_get_freq)(void)`
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ciCustomizing OPP for platform
1388c2ecf20Sopenharmony_ci============================
1398c2ecf20Sopenharmony_ciDefining CONFIG_PM should enable OPP layer for the silicon
1408c2ecf20Sopenharmony_ciand the registration of OPP table should take place automatically.
1418c2ecf20Sopenharmony_ciHowever, in special cases, the default OPP table may need to be
1428c2ecf20Sopenharmony_citweaked, for e.g.:
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci * enable default OPPs which are disabled by default, but which
1458c2ecf20Sopenharmony_ci   could be enabled on a platform
1468c2ecf20Sopenharmony_ci * Disable an unsupported OPP on the platform
1478c2ecf20Sopenharmony_ci * Define and add a custom opp table entry
1488c2ecf20Sopenharmony_ci   in these cases, the board file needs to do additional steps as follows:
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ciarch/arm/mach-omapx/board-xyz.c::
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	#include "pm.h"
1538c2ecf20Sopenharmony_ci	....
1548c2ecf20Sopenharmony_ci	static void __init omap_xyz_init_irq(void)
1558c2ecf20Sopenharmony_ci	{
1568c2ecf20Sopenharmony_ci		....
1578c2ecf20Sopenharmony_ci		/* Initialize the default table */
1588c2ecf20Sopenharmony_ci		omapx_opp_init();
1598c2ecf20Sopenharmony_ci		/* Do customization to the defaults */
1608c2ecf20Sopenharmony_ci		....
1618c2ecf20Sopenharmony_ci	}
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ciNOTE:
1648c2ecf20Sopenharmony_ci  omapx_opp_init will be omap3_opp_init or as required
1658c2ecf20Sopenharmony_ci  based on the omap family.
166