summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/odm_kit/adaptations/pmu/tps6586x/nvodm_pmu_tps6586x_interrupt.c
blob: 229313c211bcc108cae3e3337c66dfa5b88f82af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * Copyright (c) 2009 NVIDIA Corporation.
 *
 * 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "nvodm_pmu_tps6586x_interrupt.h"
#include "nvodm_pmu_tps6586x_i2c.h"
#include "nvodm_pmu_tps6586x_supply_info_table.h"
#include "nvodm_services.h"
#include "nvodm_pmu_tps6586x_batterycharger.h"

/* INT_MASK3 */
#define TPS6586X_INT_BATT_INST 0x01
#define TPS6586X_INT_PACK_COLD_DET 0x02
#define TPS6586X_INT_PACK_HOT_DET 0x04
/* INT_MASK4 */
#define TPS6586X_INT_ALM2_INST          0x02
/* INT_MASK5 */
#define TPS6586X_INT_USB_DETECTION      0x04
#define TPS6586X_INT_AC_DETECTION       0x08
#define TPS6586X_INT_ALM1_DETECTION     0x10
#define TPS6586X_INT_LOWSYS_DETECTION   0x40

NvBool Tps6586xSetupInterrupt(NvOdmPmuDeviceHandle  hDevice,
                              TPS6586xStatus *pmuStatus)
{
    NvBool status = NV_FALSE;
    NvU32   data = 0;

    NV_ASSERT(hDevice);
    NV_ASSERT(pmuStatus);

    /* Init Pmu Status */
    pmuStatus->lowBatt    = NV_FALSE;
    pmuStatus->highTemp   = NV_FALSE;

    if (!Tps6586xBatteryChargerMainChgPresent(hDevice,&status))
        return NV_FALSE;
    pmuStatus->mChgPresent = status;

    /* Set up Interrupt Mask */
    /* Mask1 */
    data = 0xFF;
    if(! Tps6586xI2cWrite8(hDevice, TPS6586x_RB0_INT_MASK1, data ))
        return NV_FALSE;

    /* Mask2 */
    data = 0xFF;
    if(! Tps6586xI2cWrite8(hDevice, TPS6586x_RB1_INT_MASK2, data ))
        return NV_FALSE;

    /* Mask3: Battery detction, etc */
    data = 0;
    data = (NvU32)~(TPS6586X_INT_BATT_INST|TPS6586X_INT_PACK_COLD_DET|TPS6586X_INT_PACK_HOT_DET);
    if(! Tps6586xI2cWrite8(hDevice, TPS6586x_RB2_INT_MASK3, data ))
        return NV_FALSE;

    /* Mask4 */
    data = 0xFF;
    if(! Tps6586xI2cWrite8(hDevice, TPS6586x_RB3_INT_MASK4, data ))
        return NV_FALSE;

    /* Mask5: USB Detection; AC Detection; Low System detection;  */
    data = 0;
    data = (NvU32) ~(TPS6586X_INT_USB_DETECTION|TPS6586X_INT_AC_DETECTION|TPS6586X_INT_LOWSYS_DETECTION);
    if(! Tps6586xI2cWrite8(hDevice, TPS6586x_RB4_INT_MASK5, data ))
        return NV_FALSE;

    return NV_TRUE;
}

void Tps6586xInterruptHandler_int(NvOdmPmuDeviceHandle  hDevice,
                                  TPS6586xStatus *pmuStatus)
{
    NvU32   data = 0;

    /* INT_ACK1 */
    if (!Tps6586xI2cRead8(hDevice, TPS6586x_RB5_INT_ACK1, &data))
    {
        return;
    }
    pmuStatus->powerGood = (data & 0xFF);


    /* INT_ACK2 */
    if (!Tps6586xI2cRead8(hDevice, TPS6586x_RB6_INT_ACK2, &data))
    {
        return;
    }
    pmuStatus->powerGood |= ((data & 0xFF)<<8);

    /* INT_ACK3 */
    if (!Tps6586xI2cRead8(hDevice, TPS6586x_RB7_INT_ACK3, &data))
    {
        return;
    }
    if (data != 0)
    {
        /* ACK_RTCALM1 */
        if (data&0x01)
        {
        /* printk("%s ACK_RTC_ALM_1 detect!!!\n", __func__); */
        }

        /* ACK_CHGTEMP */
        if (data&0x40)
        {
            pmuStatus->highTemp = NV_TRUE;
        }
        /* ACK_ACDET & ACK_USBDET */
        if (data&0x0C)
        {
            pmuStatus->mChgPresent = NV_TRUE;
        }
    }

    /* INT_ACK4 */
    if (!Tps6586xI2cRead8(hDevice, TPS6586x_RB8_INT_ACK4, &data))
    {
        return;
    }
    if (data != 0)
    {
        /* ACK_RTCALM2 */
        if (data&0x04)
        {
        /* printk("%s ACK_RTC_ALM_2 detect!!!\n", __func__); */
        }
        /* LOW SYS */
        if (data&0x02)
        {
            pmuStatus->lowBatt = NV_TRUE;
        }
    }
}