aboutsummaryrefslogtreecommitdiff
path: root/include/linux/mfd/pcf50606/core.h
blob: b45d7ebc137aac07e5e8723dfc0079d97412bb40 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * core.h  -- Core driver for NXP PCF50606
 *
 * (C) 2006-2008 by Openmoko, 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.
 */

#ifndef __LINUX_MFD_PCF50606_CORE_H
#define __LINUX_MFD_PCF50606_CORE_H

#include <linux/i2c.h>
#include <linux/workqueue.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
#include <linux/power_supply.h>

#include <linux/mfd/pcf50606/pmic.h>
#include <linux/mfd/pcf50606/input.h>
#include <linux/mfd/pcf50606/mbc.h>
#include <linux/mfd/pcf50606/rtc.h>
#include <linux/mfd/pcf50606/adc.h>
#include <linux/mfd/pcf50606/wdt.h>

struct pcf50606;

struct pcf50606_platform_data {
	struct regulator_init_data reg_init_data[PCF50606_NUM_REGULATORS];

	char **batteries;
	int num_batteries;

	/* Callbacks */
	void (*probe_done)(struct pcf50606 *);
	void (*mbc_event_callback)(struct pcf50606 *, int);
	void (*regulator_registered)(struct pcf50606 *, int);
	void (*force_shutdown)(struct pcf50606 *);

	u8 resumers[3];

	/* Runtime data - filled by driver afer probe */
	struct pcf50606 *pcf;
};

struct pcf50606_irq {
	void (*handler)(struct pcf50606 *, int, void *);
	void *data;
};

int pcf50606_irq_mask(struct pcf50606 *pcf, int irq);
int pcf50606_irq_unmask(struct pcf50606 *pcf, int irq);
int pcf50606_irq_mask_get(struct pcf50606 *pcf, int irq);

int pcf50606_read_block(struct pcf50606 *, u8 reg,
					int nr_regs, u8 *data);
int pcf50606_write_block(struct pcf50606 *pcf, u8 reg,
					int nr_regs, u8 *data);
u8 pcf50606_reg_read(struct pcf50606 *, u8 reg);
int pcf50606_reg_write(struct pcf50606 *pcf, u8 reg, u8 val);

int pcf50606_reg_set_bit_mask(struct pcf50606 *pcf, u8 reg, u8 mask, u8 val);
int pcf50606_reg_clear_bits(struct pcf50606 *pcf, u8 reg, u8 bits);

/* Interrupt registers */

#define PCF50606_REG_INT1	0x02
#define	PCF50606_REG_INT2	0x03
#define	PCF50606_REG_INT3	0x04

#define PCF50606_REG_INT1M	0x05
#define	PCF50606_REG_INT2M	0x06
#define	PCF50606_REG_INT3M	0x07

enum {
	/* Chip IRQs */
	PCF50606_IRQ_ONKEYR,
	PCF50606_IRQ_ONKEYF,
	PCF50606_IRQ_ONKEY1S,
	PCF50606_IRQ_EXTONR,
	PCF50606_IRQ_EXTONF,
	PCF50606_IRQ_SECOND,
	PCF50606_IRQ_ALARM,
	PCF50606_IRQ_CHGINS,
	PCF50606_IRQ_CHGRM,
	PCF50606_IRQ_CHGFOK,
	PCF50606_IRQ_CHGERR,
	PCF50606_IRQ_CHGFRDY,
	PCF50606_IRQ_CHGPROT,
	PCF50606_IRQ_CHGWD10S,
	PCF50606_IRQ_CHGWDEXP,
	PCF50606_IRQ_ADCRDY,
	PCF50606_IRQ_ACDINS,
	PCF50606_IRQ_ACDREM,
	PCF50606_IRQ_TSCPRES,
	PCF50606_IRQ_LOWBAT,
	PCF50606_IRQ_HIGHTMP,

	/* Always last */
	PCF50606_NUM_IRQ,
};

struct pcf50606 {
	struct device *dev;
	struct i2c_client *i2c_client;

	struct pcf50606_platform_data *pdata;
	int irq;
	struct pcf50606_irq irq_handler[PCF50606_NUM_IRQ];
	struct work_struct irq_work;
	struct mutex lock;

	u8 mask_regs[3];

	u8 suspend_irq_masks[3];
	u8 resume_reason[3];
	int is_suspended;

	int onkey1s_held;

	struct pcf50606_pmic pmic;
	struct pcf50606_input input;
	struct pcf50606_mbc mbc;
	struct pcf50606_rtc rtc;
	struct pcf50606_adc adc;
	struct pcf50606_wdt wdt;
};

enum pcf50606_reg_int1 {
	PCF50606_INT1_ONKEYR	= 0x01,	/* ONKEY rising edge */
	PCF50606_INT1_ONKEYF	= 0x02,	/* ONKEY falling edge */
	PCF50606_INT1_ONKEY1S	= 0x04,	/* OMKEY at least 1sec low */
	PCF50606_INT1_EXTONR	= 0x08,	/* EXTON rising edge */
	PCF50606_INT1_EXTONF	= 0x10,	/* EXTON falling edge */
	PCF50606_INT1_SECOND	= 0x40,	/* RTC periodic second interrupt */
	PCF50606_INT1_ALARM	= 0x80, /* RTC alarm time is reached */
};

enum pcf50606_reg_int2 {
	PCF50606_INT2_CHGINS	= 0x01, /* Charger inserted */
	PCF50606_INT2_CHGRM	= 0x02, /* Charger removed */
	PCF50606_INT2_CHGFOK	= 0x04,	/* Fast charging OK */
	PCF50606_INT2_CHGERR	= 0x08,	/* Error in charging mode */
	PCF50606_INT2_CHGFRDY	= 0x10,	/* Fast charge completed */
	PCF50606_INT2_CHGPROT	= 0x20,	/* Charging protection interrupt */
	PCF50606_INT2_CHGWD10S	= 0x40,	/* Charger watchdig expires in 10s */
	PCF50606_INT2_CHGWDEXP	= 0x80,	/* Charger watchdog expires */
};

enum pcf50606_reg_int3 {
	PCF50606_INT3_ADCRDY	= 0x01,	/* ADC conversion finished */
	PCF50606_INT3_ACDINS	= 0x02,	/* Accessory inserted */
	PCF50606_INT3_ACDREM	= 0x04, /* Accessory removed */
	PCF50606_INT3_TSCPRES	= 0x08,	/* Touch screen pressed */
	PCF50606_INT3_LOWBAT	= 0x40,	/* Low battery voltage */
	PCF50606_INT3_HIGHTMP	= 0x80, /* High temperature */
};

#endif