| /***************************************************************************** |
| * Copyright Statement: |
| * -------------------- |
| * This software is protected by Copyright and the information contained |
| * herein is confidential. The software may not be copied and the information |
| * contained herein may not be used or disclosed except with the written |
| * permission of MediaTek Inc. (C) 2005 |
| * |
| * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| * |
| * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| * |
| * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| * |
| *****************************************************************************/ |
| |
| /***************************************************************************** |
| * |
| * Filename: |
| * --------- |
| * dcl_pmu.c |
| * |
| * Project: |
| * -------- |
| * MOLY |
| * |
| * Description: |
| * ------------ |
| * This Module defines DCL (Driver Common Layer) of the PMIC driver. |
| * |
| * Author: |
| * ------- |
| * ------- |
| * |
| *============================================================================ |
| * HISTORY |
| * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| *------------------------------------------------------------------------------ |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| *------------------------------------------------------------------------------ |
| * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| *============================================================================ |
| ****************************************************************************/ |
| |
| #include "kal_debug.h" |
| #include "kal_public_api.h" |
| #include "kal_hrt_api.h" |
| #include "intrCtrl.h" |
| #include "dcl.h" |
| #include "pmif.h" |
| #include "spmi.h" |
| #include "pmif_sw.h" |
| #include "spmi_sw.h" |
| #include "us_timer.h" |
| #include "drv_features.h" |
| |
| #if defined (DRV_SPMI_OFF) || DRV_SPMI_NOT_SUPPORT |
| |
| DCL_STATUS DclSPMI_Initialize(void) |
| { |
| return STATUS_UNSUPPORTED; |
| } |
| |
| DCL_HANDLE DclSPMI_Open(DCL_DEV dev, DCL_FLAGS flags) |
| { |
| return STATUS_UNSUPPORTED; |
| } |
| |
| DCL_STATUS DclSPMI_ReadData(DCL_HANDLE handle, DCL_BUFF *buff, DCL_BUFF_LEN buf_len, DCL_OPTIONS options) |
| { |
| return STATUS_UNSUPPORTED; |
| } |
| |
| DCL_STATUS DclSPMI_WriteData(DCL_HANDLE handle, DCL_BUFF *buff, DCL_BUFF_LEN buf_len, DCL_OPTIONS options) |
| { |
| return STATUS_UNSUPPORTED; |
| } |
| |
| DCL_STATUS DclSPMI_Configure(DCL_HANDLE handle, DCL_CONFIGURE_T *configure) |
| { |
| return STATUS_UNSUPPORTED; |
| } |
| |
| DCL_STATUS DclSPMI_RegisterCallback(DCL_HANDLE handle, DCL_EVENT event, PFN_DCL_CALLBACK callback) |
| { |
| return STATUS_UNSUPPORTED; |
| } |
| |
| DCL_STATUS DclSPMI_Control(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data) |
| { |
| return STATUS_UNSUPPORTED; |
| } |
| |
| DCL_STATUS DclSPMI_Close(DCL_HANDLE handle) |
| { |
| return STATUS_UNSUPPORTED; |
| } |
| |
| #else /* DRV_SPMI_OFF */ |
| SPMI_CONTROL_HANDLER spmi_control_handler = 0; |
| static DCL_UINT32 dcl_spmi_handle_count = 0; |
| |
| /************************************************************************* |
| * FUNCTION |
| * DclSPMI_Initialize |
| * |
| * DESCRIPTION |
| * This function is to initialize SPMI module |
| * |
| * PARAMETERS |
| * None |
| * |
| * RETURNS |
| * STATUS_OK |
| * |
| *************************************************************************/ |
| DCL_STATUS DclSPMI_Initialize(void) |
| { |
| #if defined(MT6885) || defined(MT6873) || defined(MERCURY) |
| pmif_spmi_init(SPMI_MASTER_0); |
| #elif defined(MT6853) |
| #if defined(MT6315) |
| pmif_spmi_init(SPMI_MASTER_1); |
| #else |
| pmif_spmi_init(SPMI_MASTER_1); |
| pmif_spmi_init(SPMI_MASTER_P_1); |
| #endif |
| #else |
| pmif_spmi_init(SPMI_MASTER_1); |
| pmif_spmi_init(SPMI_MASTER_P_1); |
| #endif |
| |
| return STATUS_OK; |
| } |
| |
| /************************************************************************* |
| * FUNCTION |
| * DclSPMI_Open |
| * |
| * DESCRIPTION |
| * This function is to open the SPMI module and return a handle |
| * |
| * PARAMETERS |
| * dev: only valid for DCL_SPMI |
| * flags: no sepcial flags is needed. Please use FLAGS_NONE |
| * |
| * RETURNS |
| * DCL_HANDLE_INVALID: Open failed. |
| * other value: a valid handle |
| * |
| *************************************************************************/ |
| DCL_HANDLE DclSPMI_Open(DCL_DEV dev, DCL_FLAGS flags) |
| { |
| kal_uint32 handle; |
| |
| if (dev != DCL_SPMI) { |
| /* Incorrecr device ID */ |
| return DCL_HANDLE_INVALID; |
| } |
| kal_hrt_take_itc_lock(KAL_ITC_SPMI_LOCK, KAL_INFINITE_WAIT); |
| dcl_spmi_handle_count++; |
| handle = dcl_spmi_handle_count; |
| kal_hrt_give_itc_lock(KAL_ITC_SPMI_LOCK); |
| |
| /* Register DCL default lisr */ |
| return handle; |
| } |
| |
| /************************************************************************* |
| * FUNCTION |
| * DclSPMI_ReadData |
| * |
| * DESCRIPTION |
| * This function is not supported for the SPMI module now. |
| * |
| * PARAMETERS |
| * N/A |
| * |
| * RETURNS |
| * STATUS_UNSUPPORTED |
| * |
| *************************************************************************/ |
| DCL_STATUS DclSPMI_ReadData(DCL_HANDLE handle, DCL_BUFF *buff, DCL_BUFF_LEN buf_len, DCL_OPTIONS options) |
| { |
| |
| return STATUS_UNSUPPORTED; |
| } |
| |
| /************************************************************************* |
| * FUNCTION |
| * DclSPMI_WriteData |
| * |
| * DESCRIPTION |
| * This function is not supported for the SPMI module now. |
| * |
| * PARAMETERS |
| * N/A |
| * |
| * RETURNS |
| * STATUS_UNSUPPORTED |
| * |
| *************************************************************************/ |
| DCL_STATUS DclSPMI_WriteData(DCL_HANDLE handle, DCL_BUFF *buff, DCL_BUFF_LEN buf_len, DCL_OPTIONS options) |
| { |
| |
| return STATUS_UNSUPPORTED; |
| } |
| |
| /************************************************************************* |
| * FUNCTION |
| * DclSPMI_Configure |
| * |
| * DESCRIPTION |
| * This function is not supported for the SPMI module now. |
| * |
| * PARAMETERS |
| * N/A |
| * |
| * RETURNS |
| * STATUS_UNSUPPORTED |
| * |
| *************************************************************************/ |
| DCL_STATUS DclSPMI_Configure(DCL_HANDLE handle, DCL_CONFIGURE_T *configure) |
| { |
| |
| return STATUS_UNSUPPORTED; |
| } |
| |
| /************************************************************************* |
| * FUNCTION |
| * DclSPMI_RegisterCallback |
| * |
| * DESCRIPTION |
| * This function is not supported for the SPMI module now. |
| * |
| * PARAMETERS |
| * N/A |
| * |
| * RETURNS |
| * STATUS_UNSUPPORTED |
| * |
| *************************************************************************/ |
| DCL_STATUS DclSPMI_RegisterCallback(DCL_HANDLE handle, DCL_EVENT event, PFN_DCL_CALLBACK callback) |
| { |
| return STATUS_UNSUPPORTED; |
| } |
| |
| /************************************************************************* |
| * FUNCTION |
| * DclSPMI_Control |
| * |
| * DESCRIPTION |
| * This function is to send command to control the SPMI module. |
| * |
| * PARAMETERS |
| * handle: The handle value returned from DclSPMI_Open |
| * cmd: a control command for SPMI module |
| * RETURNS |
| * STATUS_OK: command is executed successfully. |
| * STATUS_FAIL: command is failed. |
| * STATUS_INVALID_CMD: It's a invalid command. |
| * STATUS_UNSUPPORTED: It's a unsupported command. |
| * |
| *************************************************************************/ |
| DCL_STATUS DclSPMI_Control_Priv(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data) |
| { |
| struct spmi_device *md_dev; |
| DCL_INT32 ret = STATUS_OK, cmd_ret = 0; |
| |
| switch(cmd) { |
| case EXT_REGISTER_READL: |
| { |
| SPMI_CTRL_EXT_REGISTER_READL *cmd = &(data->rSPMIExtRegisterReadL); |
| unsigned char rdata = 0; |
| |
| md_dev = get_spmi_device(SPMI_MASTER_0, (unsigned int)cmd->type); |
| //TBD md_dev = get_spmi_device(SPMI_MASTER_0, slaveid); |
| cmd_ret = spmi_ext_register_readl(md_dev, cmd->addr, |
| &rdata, cmd->len); |
| if (cmd_ret) |
| ret = STATUS_FAIL; |
| cmd->value = rdata; |
| } |
| break; |
| |
| case EXT_REGISTER_WRITEL: |
| { |
| SPMI_CTRL_EXT_REGISTER_WRITEL *cmd = &(data->rSPMIExtRegisterWriteL); |
| unsigned char wdata = 0; |
| |
| md_dev = get_spmi_device(SPMI_MASTER_0, (unsigned int)cmd->type); |
| wdata = (unsigned char)cmd->value; |
| cmd_ret = spmi_ext_register_writel(md_dev, cmd->addr, |
| &wdata, cmd->len); |
| if (cmd_ret) |
| ret = STATUS_FAIL; |
| } |
| break; |
| |
| case EXT_REGISTER_READL_FIELD: |
| { |
| SPMI_CTRL_EXT_REGISTER_READL_FIELD *cmd = &(data->rSPMIExtRegisterReadLField); |
| unsigned char rdata = 0; |
| |
| md_dev = get_spmi_device(SPMI_MASTER_0, (unsigned int)cmd->type); |
| cmd_ret = spmi_ext_register_readl_field(md_dev, cmd->addr, |
| &rdata, cmd->len, cmd->mask, cmd->shift); |
| if (cmd_ret) |
| ret = STATUS_FAIL; |
| cmd->value = rdata; |
| } |
| break; |
| |
| case EXT_REGISTER_WRITEL_FIELD: |
| { |
| SPMI_CTRL_EXT_REGISTER_WRITEL_FIELD *cmd = &(data->rSPMIExtRegisterWriteLField); |
| unsigned char wdata = 0; |
| |
| md_dev = get_spmi_device(SPMI_MASTER_0, (unsigned int)cmd->type); |
| wdata = (unsigned char)cmd->value; |
| cmd_ret = spmi_ext_register_writel_field(md_dev, cmd->addr, |
| &wdata, cmd->len, cmd->mask, cmd->shift); |
| if (cmd_ret) |
| ret = STATUS_FAIL; |
| } |
| break; |
| |
| case REGISTER_READ: |
| { |
| SPMI_CTRL_EXT_REGISTER_READL *cmd = &(data->rSPMIExtRegisterReadL); |
| unsigned char rdata = 0; |
| |
| md_dev = get_spmi_device(SPMI_MASTER_0, (unsigned int)cmd->type); |
| cmd_ret = spmi_register_read(md_dev, cmd->addr, &rdata); |
| if (cmd_ret) |
| ret = STATUS_FAIL; |
| cmd->value = rdata; |
| } |
| break; |
| |
| case REGISTER_WRITE: |
| { |
| SPMI_CTRL_EXT_REGISTER_WRITEL *cmd = &(data->rSPMIExtRegisterWriteL); |
| unsigned char wdata = 0; |
| |
| md_dev = get_spmi_device(SPMI_MASTER_0, (unsigned int)cmd->type); |
| wdata = (unsigned char)cmd->value; |
| cmd_ret = spmi_register_write(md_dev, cmd->addr, wdata); |
| if (cmd_ret) |
| ret = STATUS_FAIL; |
| } |
| break; |
| |
| case EXT_REGISTER_READ: |
| { |
| SPMI_CTRL_EXT_REGISTER_READL *cmd = &(data->rSPMIExtRegisterReadL); |
| unsigned char rdata = 0; |
| |
| md_dev = get_spmi_device(SPMI_MASTER_0, (unsigned int)cmd->type); |
| cmd_ret = spmi_ext_register_read(md_dev, cmd->addr, |
| &rdata, cmd->len); |
| if (cmd_ret) |
| ret = STATUS_FAIL; |
| cmd->value = rdata; |
| } |
| break; |
| |
| case EXT_REGISTER_WRITE: |
| { |
| SPMI_CTRL_EXT_REGISTER_WRITEL *cmd = &(data->rSPMIExtRegisterWriteL); |
| unsigned char wdata = 0; |
| |
| md_dev = get_spmi_device(SPMI_MASTER_0, (unsigned int)cmd->type); |
| wdata = (unsigned char)cmd->value; |
| cmd_ret = spmi_ext_register_write(md_dev, cmd->addr, |
| &wdata, cmd->len); |
| if (cmd_ret) |
| ret = STATUS_FAIL; |
| } |
| break; |
| } |
| |
| return ret; |
| } |
| |
| DCL_STATUS DclSPMI_Control(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data) |
| { |
| return DclSPMI_Control_Priv(handle, cmd, data); |
| } |
| /************************************************************************* |
| * FUNCTION |
| * DclSPMI_Close |
| * |
| * DESCRIPTION |
| * This function is to close the SPMI module. |
| * |
| * PARAMETERS |
| * handle: the returned handle value of DclSPMI_Close |
| * |
| * RETURNS |
| * STATUS_OK |
| * |
| *************************************************************************/ |
| DCL_STATUS DclSPMI_Close(DCL_HANDLE handle) |
| { |
| return STATUS_OK; |
| } |
| |
| #endif /* endif DRV_SPMI_OFF */ |
| |