summaryrefslogtreecommitdiff
path: root/drivers/power/sprd_charge_ext.c
blob: 9d4cad5bc899c2e98fa8d91a980b8830cb33b5c1 (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
/*
 * Copyright (C) 2012 Spreadtrum Communications Inc.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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.
 */
#ifdef SPRDBAT_TWO_CHARGE_CHANNEL

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/types.h>
#include <linux/pci.h>
#include <linux/interrupt.h>
#include <asm/io.h>
#include <linux/hrtimer.h>
#include <linux/spinlock.h>
#include <linux/gpio.h>
#include <linux/irq.h>
#include <linux/wakelock.h>
#include <linux/delay.h>
#include <mach/hardware.h>
#include <mach/adi.h>
#include <mach/adc.h>
#include <mach/gpio.h>
#include <linux/device.h>

#include <linux/slab.h>
#include <linux/jiffies.h>
#include "sprd_battery.h"
#include <mach/usb.h>

struct sprdchg_drivier_data_ext {
    uint32_t gpio_vchg_ovi;
    uint32_t irq_vchg_ovi;
    uint32_t gpio_charge_en;
    uint32_t gpio_charge_done;
    struct work_struct ovi_irq_work;
};
static struct sprdchg_drivier_data_ext sprdchg_ext_ic;

int sprdchg_is_chg_done_ext(void)
{
	return gpio_get_value(sprdchg_ext_ic.gpio_charge_done);
}

void sprdchg_start_charge_ext(void)
{
	gpio_set_value(sprdchg_ext_ic.gpio_charge_en, 0);
}

void sprdchg_stop_charge_ext(void)
{
	gpio_set_value(sprdchg_ext_ic.gpio_charge_en, 1);
}

void sprdchg_open_ovi_fun_ext(void)
{
	irq_set_irq_type(sprdchg_ext_ic.irq_vchg_ovi, IRQ_TYPE_LEVEL_HIGH);
	enable_irq(sprdchg_ext_ic.irq_vchg_ovi);
}

void sprdchg_close_ovi_fun_ext(void)
{
	disable_irq_nosync(sprdchg_ext_ic.irq_vchg_ovi);
}

static void sprdchg_ovi_irq_works_ext(struct work_struct *work)
{
	int value;
	value = gpio_get_value(sprdchg_ext_ic.gpio_vchg_ovi);
	if (value) {
		sprdbat_charge_event_ext(SPRDBAT_CHG_EVENT_EXT_OVI);
	} else {
		sprdbat_charge_event_ext(SPRDBAT_CHG_EVENT_EXT_OVI_RESTART);
	}
}

static __used irqreturn_t sprdchg_vchg_ovi_irq_ext(int irq, void *dev_id)
{
	int value;
	value = gpio_get_value(sprdchg_ext_ic.gpio_vchg_ovi);
	if (value) {
		printk("sprdchg_vchg_ovi_irq_ext ovi high\n");
		irq_set_irq_type(sprdchg_ext_ic.irq_vchg_ovi, IRQ_TYPE_LEVEL_LOW);
	} else {
		printk("sprdchg_vchg_ovi_irq_ext ovi low\n");
		irq_set_irq_type(sprdchg_ext_ic.irq_vchg_ovi, IRQ_TYPE_LEVEL_HIGH);
	}
	schedule_work(&sprdchg_ext_ic.ovi_irq_work);
	return IRQ_HANDLED;
}

int sprdchg_charge_init_ext(struct platform_device *pdev)
{
	int ret = -ENODEV;
	struct resource *res = NULL;

	res = platform_get_resource(pdev, IORESOURCE_IO, 3);
	sprdchg_ext_ic.gpio_charge_done = res->start;
	res = platform_get_resource(pdev, IORESOURCE_IO, 4);
	sprdchg_ext_ic.gpio_charge_en = res->start;
	res = platform_get_resource(pdev, IORESOURCE_IO, 5);
	sprdchg_ext_ic.gpio_vchg_ovi = res->start;
	gpio_request(sprdchg_ext_ic.gpio_vchg_ovi, "vchg_ovi_ext");
	gpio_direction_input(sprdchg_ext_ic.gpio_vchg_ovi);
	sprdchg_ext_ic.irq_vchg_ovi = gpio_to_irq(sprdchg_ext_ic.gpio_vchg_ovi);
	set_irq_flags(sprdchg_ext_ic.irq_vchg_ovi, IRQF_VALID | IRQF_NOAUTOEN);
	ret = request_irq(sprdchg_ext_ic.irq_vchg_ovi, sprdchg_vchg_ovi_irq_ext,
		    IRQF_NO_SUSPEND, "sprdbat_vchg_ovi_ext", NULL);
	INIT_WORK(&sprdchg_ext_ic.ovi_irq_work, sprdchg_ovi_irq_works_ext);
	gpio_request(sprdchg_ext_ic.gpio_charge_done, "chg_done_ext");
	gpio_direction_input(sprdchg_ext_ic.gpio_charge_done);
	gpio_request(sprdchg_ext_ic.gpio_charge_en, "charge_en_ext");
	gpio_direction_output(sprdchg_ext_ic.gpio_charge_en, 1);
	sprdchg_stop_charge_ext();
	return ret;
}

void sprdchg_chg_monitor_cb_ext(void *data)
{
	return;
}

#endif /*  */