/*
 * Copyright 2005 Freescale Semiconductor, Inc. All Rights Reserved.
 */

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  
 * 02111-1307, USA
 *
 */

#ifndef _PMIC_POWER_H
#define _PMIC_POWER_H

/*!
 * @defgroup PMIC_RR_POWER Roadrunner Power Driver
 * @ingroup PMIC_RR_DRVRS
 */

/*!
 * @file pmic_power.h
 * @brief This is the header of PMIC power driver. 
 *
 * @ingroup PMIC_RR_POWER
 */

#include <asm/ioctl.h>

/*!
 * @name IOCTL user space interface
 */ 
/*! @{ */

/*!
 * Turn on a regulator.
 */ 
#define PMIC_REGULATOR_ON                 _IOWR('p', 0xf0, int)

/*!
 * Turn off a regulator.
 */ 
#define PMIC_REGULATOR_OFF                _IOWR('p', 0xf1, int)

/*!
 * Set regulator configuration.
 */ 
#define PMIC_REGULATOR_SET_CONFIG         _IOWR('p', 0xf2, int)

/*!
 * Get regualtor configuration.
 */ 
#define PMIC_REGULATOR_GET_CONFIG         _IOWR('p', 0xf3, int)

/*! @} */

/*!
 * VHOLD regulator output voltage setting.
 */
typedef enum {
        VH_1_875V,            /*!< 1.875V */
        VH_2_5V,              /*!< 2.5V */
        VH_1_55V,             /*!< 1.55V */
        VH_PASSTHROUGH,       /*!< Pass-through mode */
 } t_vhold_voltage;

/*!
 * PMIC power control configuration.
 */
typedef struct {
        bool            pc_enable;       /*!< Power cut enable */
        unsigned char   pc_timer;        /*!< Power cut timer value */
        bool            pc_count_enable; /*!< Power cut counter enable, 
                                              If TURE, Power cuts are disabled
                                              when pc_count > pc_max_count; 
                                              If FALSE, Power cuts are not
                                              disabled when 
                                              pc_count > pc_max_count */
        unsigned char   pc_count;        /*!< Power cut count */
        unsigned char   pc_max_count;    /*!< Power cut maximum count */
        bool            warm_enable;     /*!< User Off state enable */                          
        bool            clk_32k_enable;  /*!< 32 kHz output buffer enable
                                              during memory hold */
        t_vhold_voltage vhold_voltage;   /*!< output voltage for VHOLD */
        unsigned char   mem_timer;       /*!< duration of the memory hold timer */
        bool            mem_allon;       /*!< memory hold timer infinity mode,
                                              If TRUE, the memory hold timer will 
                                              be set to infinity and the mem_timer
                                              field will be ingored */
} t_pc_config;

/*!
 * brief PMIC regulators.
 */
typedef enum {
        SW1 = 0,                       /*!< Switch mode regulator 1 */
        SW2,                           /*!< Switch mode regulator 2 */ 
        SW3,                           /*!< Switch mode regulator 3 */
        V1,                            /*!< Linear voltage regulator V1 */
        V2,                            /*!< Linear voltage regulator V2 */ 
        V3,                            /*!< Linear voltage regulator V3 */
        V4,                            /*!< Linear voltage regulator V4 */
        VSIM,                          /*!< Linear voltage regulator VSIM */
        V_VIB,                         /*!< Linear voltage regulator V_VIB */ 
        VMMC,                          /*!< Linear voltage regulator VMMC */ 
} t_pmic_regulator;

/*!
 * @enum t_rr_regulator_voltage_sw1
 * @brief Roadrunner Switch mode regulator SW1 output voltages.
 */
typedef enum {
        SW1_1V = 0,                    /*!< 1.0 V */
        SW1_1_1V,                      /*!< 1.1 V */
        SW1_1_2V,                      /*!< 1.2 V */
        SW1_1_3V,                      /*!< 1.3 V */
        SW1_1_4V,                      /*!< 1.4 V */
        SW1_1_55V,                     /*!< 1.55 V */
        SW1_1_625V,                    /*!< 1.625 V */
        SW1_1_875V,                    /*!< 1.875 V */
 } t_rr_regulator_voltage_sw1;

/*!
 * @enum t_rr_regulator_voltage_sw2
 * @brief Roadrunner Switch mode regulator SW2 output voltages.
  */
typedef enum {
        SW2_1V = 0,                    /*!< 1.0 V */
        SW2_1_1V,                      /*!< 1.1 V */
        SW2_1_2V,                      /*!< 1.2 V */
        SW2_1_3V,                      /*!< 1.3 V */
        SW2_1_4V,                      /*!< 1.4 V */
        SW2_1_55V,                     /*!< 1.55 V */
        SW2_1_625V,                    /*!< 1.625 V */
        SW2_1_875V,                    /*!< 1.875 V */
} t_rr_regulator_voltage_sw2;

/*!
 * @enum t_rr_regulator_voltage_sw3
 * @brief Roadrunner Switch mode regulator SW2 output voltages.
 */
typedef enum {
        SW3_5_1V = 0,                  /*!< 5.1 V */
        SW3_5_6V,                      /*!< 5.6 V */
 } t_rr_regulator_voltage_sw3;

/*!
 * @enum t_rr_regulator_voltage_v1
 * @brief Roadrunner linear regulator V1 output voltages.
 */
typedef enum {
        V1_2_775V = 0,                 /*!< 2.775 V */
        V1_1_2V,                       /*!< 1.2 V */
        V1_1_3V,                       /*!< 1.3 V */
        V1_1_4V,                       /*!< 1.4 V */
        V1_1_55V,                      /*!< 1.55 V */
        V1_1_75V,                      /*!< 1.75 V */
        V1_1_875V,                     /*!< 1.875 V */
        V1_2_475V,                     /*!< 2.475 V */
} t_rr_regulator_voltage_v1;

/*!
 * @enum t_rr_regulator_voltage_v2
 * @brief Roadrunner linear regulator V2 output voltage, V2 has fixed 
 * output voltage 2.775 volts.
 */
typedef enum {
        V2_2_775V = 0,                 /*!< 2.775 V */
} t_rr_regulator_voltage_v2;

/*!
 * @enum t_rr_regulator_voltage_v3
 * @brief Roadrunner linear regulator V3 output voltage.
 */
typedef enum {
        V3_2_775V = 0,                 /*!< 2.775 V */
        V3_1_875V ,                    /*!< 1.875 V */
} t_rr_regulator_voltage_v3;

/*!
 * @enum t_rr_regulator_voltage_v4
 * @brief Roadrunner linear regulator V4 output voltage, V4 has fixed 
 * output voltage 2.775 volts.
 */
typedef enum {
        V4_2_775V = 0,                 /*!< 2.775 V */
} t_rr_regulator_voltage_v4;

/*!
 * @enum t_rr_regulator_voltage_vsim
 * @brief Roadrunner linear regulator VSIM output voltage.
 */
typedef enum {
        VSIM_1_8V = 0,                 /*!< 1.8 V */
        VSIM_3V,                       /*!< 3 V */
} t_rr_regulator_voltage_vsim;

/*!
 * @enum t_rr_regulator_voltage_vvib
 * @brief Roadrunner linear regulator V_VIB output voltage.
 */
typedef enum {
        V_VIB_2V = 0,                  /*!< 2 V */
        V_VIB_3V,                      /*!< 3 V */
} t_rr_regulator_voltage_vvib;

/*!
 * @enum t_rr_regulator_voltage_vmmc
 * @brief Roadrunner linear regulator VMMC output voltage.
 */
typedef enum {
        VMMC_OFF = 0,                  /*!< Output off */
        VMMC_1_6V,                     /*!< 1.6 V */
        VMMC_1_8V,                     /*!< 1.8 V */
        VMMC_2V,                       /*!< 2 V */
        VMMC_2_2V,                     /*!< 2.2 V */
        VMMC_2_4V,                     /*!< 2.4 V */
        VMMC_2_6V,                     /*!< 2.6 V */
        VMMC_2_8V,                     /*!< 2.8 V */
        VMMC_3V,                       /*!< 3 V */
        VMMC_3_2V,                     /*!< 3.2 V */
        VMMC_3_3V,                     /*!< 3.3 V */
        VMMC_3_4V,                     /*!< 3.4 V */
} t_rr_regulator_voltage_vmmc;

/*!
 * @union t_rr_regulator_voltage
 * @brief Roadrunner regulator output voltages.
 */
typedef union {
        t_rr_regulator_voltage_sw1 sw1;                /*!< SW1 voltage */
        t_rr_regulator_voltage_sw2 sw2;                /*!< SW2 voltage */
        t_rr_regulator_voltage_sw3 sw3;                /*!< SW3 voltage */
        t_rr_regulator_voltage_v1 v1;                  /*!< V1 voltage */
        t_rr_regulator_voltage_v2 v2;                  /*!< V2 voltage */
        t_rr_regulator_voltage_v3 v3;                  /*!< V3 voltage */
        t_rr_regulator_voltage_v4 v4;                  /*!< V4 voltage */
        t_rr_regulator_voltage_vsim vsim;              /*!< VSIM voltage */
        t_rr_regulator_voltage_vvib v_vib;             /*!< V_VIB voltage */
        t_rr_regulator_voltage_vmmc vmmc;              /*!< VMMC voltage */
} t_rr_regulator_voltage;

/*!
 * Generic PMIC regulator voltage. 
 */
typedef t_rr_regulator_voltage t_regulator_voltage;

/*!
 * @enum t_rr_regulator_sw_mode
 * @brief define switch mode regulator mode.
 * 
 * The synchronous rectifier can be disabled (and pulse-skipping enabled) to improve low
 * current efficiency. Software should disable synchronous rectifier / enable the pulse
 * skipping for average loads less than approximately 30 mA, depending on the quiescent
 * current penalty due to synchronous mode.
 */
typedef enum {
        SYNC_RECT = 0,
        PULSE_SKIP,
} t_rr_regulator_sw_mode;

/*!
 * Generic PMIC switch mode regulator mode.
 */
typedef t_rr_regulator_sw_mode t_regulator_sw_mode;

/*!
 * @enum t_regulator_lp_mode
 * @brief Low power mode control modes.
 */
typedef enum {
        /*!
         * Low Power Mode is disabled
         */
        LOW_POWER_DISABLED = 0,
        /*!
         * Low Power Mode is contorled by STANDBY pin and/or LVS pin
         */
        LOW_POWER_CTRL_BY_PIN,
        /*!
         * Set Low Power mode no matter of hardware pins
         */
        LOW_POWER
} t_regulator_lp_mode;

/*!
 * @struct t_regulator_config
 * @brief regulator configuration.
 * 
 */
typedef struct {
        /*!
         * Switch mode regulator operation mode. This field only applies to 
         * switch mode regulators.
         */
        t_regulator_sw_mode mode;
        /*!
         * Regulator output voltage.
         */
        t_regulator_voltage voltage;
        /*!
         * Regulator output voltage in LVS mode.
         */
        t_regulator_voltage voltage_lvs;
        /*!
         * Regulator output voltage in standby mode.
         */
        t_regulator_voltage voltage_stby;
        /*!
         * Regulator low power mode.
         */
        t_regulator_lp_mode lp_mode;
} t_regulator_config;

/*!
 * @struct t_regulator_cfg_param
 * @brief regulator configuration structure for IOCTL.
 * 
 */
typedef struct {
        /*!
         * Regulator.
         */
        t_pmic_regulator regulator;
        /*!
         * Regulator configuration.
         */
        t_regulator_config cfg;
} t_regulator_cfg_param;


/* EXPORTED FUNCTIONS */

/*!
 * This function sets user power off in power control register and thus powers
 * off the phone. 
 *
 * @return       This function returns PMIC_SUCCESS if successful.
 */ 
PMIC_STATUS pmic_power_off(void);

/*!
 * This function sets the power control configuration.
 *
 * @param        pc_config   power control configuration.
 *
 * @return       This function returns PMIC_SUCCESS if successful.
 */ 
PMIC_STATUS pmic_power_set_pc_config(t_pc_config* pc_config);

/*!
 * This function retrives the power control configuration.
 *
 * @param        pc_config   pointer to power control configuration.
 *
 * @return       This function returns PMIC_SUCCESS if successful.
 */ 
PMIC_STATUS pmic_power_get_pc_config(t_pc_config* pc_config);

/*!
 * This function turns on a regulator.
 *
 * @param        regulator    The regulator to be truned on.
 *
 * @return       This function returns PMIC_SUCCESS if successful.
 */ 
PMIC_STATUS pmic_power_regulator_on(t_pmic_regulator regulator);


/*!
 * This function turns off a regulator.
 *
 * @param        regulator    The regulator to be truned off.
 *
 * @return       This function returns PMIC_SUCCESS if successful.
 */ 
PMIC_STATUS pmic_power_regulator_off(t_pmic_regulator regulator);

/*!
 * This function sets the regulator output voltage.
 *
 * @param        regulator    The regulator to be truned off.
 * @param        voltage      The regulator output voltage.
 *
 * @return       This function returns PMIC_SUCCESS if successful.
 */ 
PMIC_STATUS pmic_power_regulator_set_voltage(t_pmic_regulator regulator,
                                             t_regulator_voltage voltage);

/*!
 * This function retrives the regulator output voltage.
 *
 * @param        regulator    The regulator to be truned off.
 * @param        voltage      Pointer to regulator output voltage.
 *
 * @return       This function returns PMIC_SUCCESS if successful.
 */ 
PMIC_STATUS pmic_power_regulator_get_voltage(t_pmic_regulator regulator,
                                             t_regulator_voltage* voltage);

/*!
 * This function sets the regulator configuration.
 *
 * @param        regulator    The regulator to be truned off.
 * @param        config       The regulator output configuration.
 *
 * @return       This function returns PMIC_SUCCESS if successful.
 */ 
PMIC_STATUS pmic_power_regulator_set_config(t_pmic_regulator regulator,
                                            t_regulator_config* config);

/*!
 * This function retrives the regulator output configuration.
 *
 * @param        regulator    The regulator to be truned off.
 * @param        config       Pointer to regulator configuration.
 *
 * @return       This function returns PMIC_SUCCESS if successful.
 */ 
PMIC_STATUS pmic_power_regulator_get_config(t_pmic_regulator regulator,
                                            t_regulator_config* config);

#endif /* _PMIC_POWER_H */
