summaryrefslogtreecommitdiff
path: root/include/linux/mfd/max77665.h
blob: c594451994a7539d9b82eca400ace4a113303ea1 (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
/*
 * Core driver interface for MAXIM77665
 *
 * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.

 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.

 * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
 */

#ifndef __LINUX_MFD_MAX77665_H
#define __LINUX_MFD_MAX77665_H

#include <linux/irq.h>
#include <linux/regmap.h>

/* Max77665 irq register */
#define MAX77665_REG_INTSRC		0x22
#define MAX77665_REG_INTSRC_MASK	0x23
#define MAX77665_INTSRC_CHGR_MASK	BIT(0)
#define MAX77665_INTSRC_TOP_MASK	BIT(1)
#define MAX77665_INTSRC_FLASH_MASK	BIT(2)
#define MAX77665_INTSRC_MUIC_MASK	BIT(3)

#define MAX77665_REG_TOP_SYS_INT_STS	0x24
#define MAX77665_REG_TOP_SYS_INT_MASK	0x26
#define MAX77665_TOP_SYS_INT_120C	BIT(0)
#define MAX77665_TOP_SYS_INT_140C	BIT(1)
#define MAX77665_TOP_SYS_INT_LOWSYS	BIT(3)

/* MAX77665 Interrups */
enum {
	MAX77665_IRQ_CHARGER,
	MAX77665_IRQ_TOP_SYS,
	MAX77665_IRQ_FLASH,
	MAX77665_IRQ_MUIC,
	MAX77665_NUM_IRQ,
};

enum {
	MAX77665_I2C_SLAVE_PMIC,
	MAX77665_I2C_SLAVE_MUIC,
	MAX77665_I2C_SLAVE_HAPTIC,
	MAX77665_I2C_SLAVE_MAX,
};

enum {
	MAX77665_CELL_CHARGER,
	MAX77665_CELL_FLASH,
	MAX77665_CELL_MUIC,
	MAX77665_CELL_HAPTIC,
	MAX77665_CELL_MAX,
};

struct max77665 {
	struct device		*dev;
	struct i2c_client	*client[MAX77665_I2C_SLAVE_MAX];
	struct regmap		*regmap[MAX77665_I2C_SLAVE_MAX];
	struct regmap_irq_chip_data *regmap_irq_data;
	int			irq_base;
	int			top_sys_irq;
};

struct max77665_cell_data {
	void *pdata;
	size_t size;
};

struct max77665_system_interrupt {
	bool enable_thermal_interrupt;
	bool enable_low_sys_interrupt;
};

struct max77665_platform_data {
	int irq_base;
	unsigned long irq_flag;
	struct max77665_system_interrupt *system_interrupt;
	struct max77665_cell_data charger_platform_data;
	struct max77665_cell_data flash_platform_data;
	struct max77665_cell_data muic_platform_data;
	struct max77665_cell_data haptic_platform_data;
};

static inline int max77665_write(struct device *dev, int slv_id,
		int reg, uint8_t val)
{
	struct max77665 *maxim = dev_get_drvdata(dev);

	return regmap_write(maxim->regmap[slv_id], reg, val);
}

static inline int max77665_read(struct device *dev, int slv_id,
		int reg, uint8_t *val)
{
	struct max77665 *maxim = dev_get_drvdata(dev);
	unsigned int temp_val;
	int ret;

	ret = regmap_read(maxim->regmap[slv_id], reg, &temp_val);
	if (!ret)
		*val = temp_val;
	return ret;
}

static inline int max77665_bulk_read(struct device *dev, int slv_id,
		int reg, int count, void *val)
{
	struct max77665 *maxim = dev_get_drvdata(dev);

	return regmap_bulk_read(maxim->regmap[slv_id], reg, val, count);
}

static inline int max77665_update_bits(struct device *dev, int slv_id,
		int reg, unsigned int mask, unsigned int  val)
{
	struct max77665 *maxim = dev_get_drvdata(dev);

	return regmap_update_bits(maxim->regmap[slv_id], reg, mask, val);
}

static inline int max77665_set_bits(struct device *dev, int slv_id,
		int reg, uint8_t bit_num)
{
	struct max77665 *maxim = dev_get_drvdata(dev);

	return regmap_update_bits(maxim->regmap[slv_id],
				reg, BIT(bit_num), ~0u);
}

static inline int max77665_clr_bits(struct device *dev, int slv_id,
		int reg, uint8_t bit_num)
{
	struct max77665 *maxim = dev_get_drvdata(dev);

	return regmap_update_bits(maxim->regmap[slv_id],
				reg, BIT(bit_num), 0u);
}

#endif /*__LINUX_MFD_MAX77665_H */