summaryrefslogtreecommitdiff
path: root/include/linux/m4sensorhub.h
blob: 4b0cdd62eb8ba003130fc599ce760a21b7305581 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
 * Copyright (c) 2012, Motorola, 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 version 2 as
 * published by the Free Software Foundation.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef __M4SENSORHUB_H__
#define __M4SENSORHUB_H__

#include <linux/i2c.h>
#include <linux/platform_device.h>
#include <linux/m4sensorhub/m4sensorhub_registers.h>
#include <linux/m4sensorhub/m4sensorhub_irqs.h>
#include <linux/firmware.h>

#ifdef __KERNEL__

extern char m4sensorhub_debug;

#define M4SENSORHUB_DRIVER_NAME     "m4sensorhub"
#define M4SENSORHUB_I2C_ADDR        0x18

#define KDEBUG(i, format, s...) 			\
	do {						\
		if (m4sensorhub_debug >= i)             \
			printk(KERN_CRIT format, ##s);	\
	} while (0)

#define CHECK_REG_ACCESS_RETVAL(m4sensorhub, retval, reg) \
		((retval == m4sensorhub_reg_getsize(m4sensorhub, reg)) \
		 ? 0 : -EFAULT);

enum m4sensorhub_debug_level {
	M4SH_NODEBUG = 0x0,
	M4SH_CRITICAL,
	M4SH_ERROR,
	M4SH_WARNING,
	M4SH_NOTICE,
	M4SH_INFO,
	M4SH_DEBUG,
	M4SH_VERBOSE_DEBUG
};

enum m4sensorhub_mode {
	UNINITIALIZED,
	BOOTMODE,
	NORMALMODE
};

enum m4sensorhub_bootmode {
	BOOTMODE00,
	BOOTMODE01,
	BOOTMODE10,
	BOOTMODE11,
};

/* This enum is used to register M4 panic callback
 * The sequence of this enum is also the sequence of calling
 *   i.e. it will be called follow this enum 0, 1, 2 ... max
*/
enum m4sensorhub_panichdl_index {
	PANICHDL_DISPLAY_RESTORE,
	/* Please add enum before PANICHDL_IRQ_RESTORE
	   to make sure IRQ resotre will be called at last
	 */
	PANICHDL_IRQ_RESTORE, /* Keep it as the last one */
	PANICHDL_MAX = PANICHDL_IRQ_RESTORE+1
};

struct m4sensorhub_data;

/* args passed to init callback,
	p_m4sensorhub_data is pointer to M4's data
	p_data is the void * that was registered along
		with the function pointer*/
struct init_calldata {
	struct m4sensorhub_data *p_m4sensorhub_data;
	void *p_data;
};

struct m4sensorhub_platform_data {
	int (*hw_init)(struct m4sensorhub_data *);
	void (*hw_free)(struct m4sensorhub_data *);
	void (*hw_reset)(struct m4sensorhub_data *);
	int (*set_bootmode)(struct m4sensorhub_data *,
			    enum m4sensorhub_bootmode);
	int (*stillmode_exit)(void);
	int (*set_display_control)(int m4_ctrl, int gpio_mipi_mux);
};

struct m4sensorhub_hwconfig {
	int irq_gpio;
	int reset_gpio;
	int wake_gpio;
	int boot0_gpio;
	int boot1_gpio;
	int mpu_9150_en_gpio;
};

struct m4sensorhub_data {
	struct i2c_client *i2c_client;
	void *irqdata;
	void *panicdata;
	enum m4sensorhub_mode mode;
	struct m4sensorhub_platform_data *pdev;
	struct m4sensorhub_hwconfig hwconfig;
	char *filename;
	u16 fw_version;
};

/* Global (kernel) functions */

/* Client devices */
struct m4sensorhub_data *m4sensorhub_client_get_drvdata(void);

/* Register access */

/* m4sensorhub_reg_read()

   Read a register from the M4 sensor hub.

   Returns number of bytes read on success.
   Returns negative error code on failure

     m4sensorhub - pointer to the main m4sensorhub data struct
     reg - Register to be read
     value - array to return data.  Needs to be at least register's size
*/
#define m4sensorhub_reg_read(m4sensorhub, reg, value) \
	m4sensorhub_reg_read_n(m4sensorhub, reg, value, \
			       m4sensorhub_reg_getsize(m4sensorhub, reg))

/* m4sensorhub_reg_write()

   Read a register from the M4 sensor hub.

   Returns number of bytes write on success.
   Returns negative error code on failure

     m4sensorhub - pointer to the main m4sensorhub data struct
     reg - Register to be write
     value - array to return data.  Needs to be at least register's size
     mask - mask representing which bits to change in register.  If all bits
	    are to be changed, then &m4sh_no_mask can be passed here.
*/
#define m4sensorhub_reg_write(m4sensorhub, reg, value, mask) \
	m4sensorhub_reg_write_n(m4sensorhub, reg, value, mask, \
				m4sensorhub_reg_getsize(m4sensorhub, reg))
int m4sensorhub_reg_init(struct m4sensorhub_data *m4sensorhub);
int m4sensorhub_reg_shutdown(struct m4sensorhub_data *m4sensorhub);
int m4sensorhub_reg_read_n(struct m4sensorhub_data *m4sensorhub,
			   enum m4sensorhub_reg reg, unsigned char *value,
			   short num);
int m4sensorhub_reg_write_n(struct m4sensorhub_data *m4sensorhub,
			    enum m4sensorhub_reg reg, unsigned char *value,
			    unsigned char *mask, short num);
int m4sensorhub_reg_write_1byte(struct m4sensorhub_data *m4sensorhub,
				enum m4sensorhub_reg reg, unsigned char value,
				unsigned char mask);
int m4sensorhub_reg_getsize(struct m4sensorhub_data *m4sensorhub,
			    enum m4sensorhub_reg reg);
void m4sensorhub_reg_access_lock(void);
void m4sensorhub_reg_access_unlock(void);
int m4sensorhub_i2c_write_read(struct m4sensorhub_data *m4sensorhub,
				      u8 *buf, int writelen, int readlen);

int m4sensorhub_load_firmware(struct m4sensorhub_data *m4sensorhub,
	unsigned short force_upgrade,
	const struct firmware *firmware);

int m4sensorhub_401_load_firmware(struct m4sensorhub_data *m4sensorhub,
	unsigned short force_upgrade,
	const struct firmware *fm);

void m4sensorhub_hw_reset(struct m4sensorhub_data *m4sensorhub);

/* Interrupt handler */
int m4sensorhub_irq_init(struct m4sensorhub_data *m4sensorhub);
void m4sensorhub_irq_shutdown(struct m4sensorhub_data *m4sensorhub);
int m4sensorhub_irq_register(struct m4sensorhub_data *m4sensorhub,
			     enum m4sensorhub_irqs irq,
			     void (*cb_func) (enum m4sensorhub_irqs, void *),
			     void *data, uint8_t enable_timed_wakelock);
int m4sensorhub_irq_unregister(struct m4sensorhub_data *m4sensorhub,
			       enum m4sensorhub_irqs irq);
int m4sensorhub_irq_disable(struct m4sensorhub_data *m4sensorhub,
			    enum m4sensorhub_irqs irq);
int m4sensorhub_irq_enable(struct m4sensorhub_data *m4sensorhub,
			   enum m4sensorhub_irqs irq);
int m4sensorhub_irq_enable_get(struct m4sensorhub_data *m4sensorhub,
			       enum m4sensorhub_irqs irq);
void m4sensorhub_irq_pm_dbg_suspend(void);
void m4sensorhub_irq_pm_dbg_resume(void);

int m4sensorhub_panic_init(struct m4sensorhub_data *m4sensorhub);
void m4sensorhub_panic_shutdown(struct m4sensorhub_data *m4sensorhub);
int m4sensorhub_panic_register(struct m4sensorhub_data *m4sensorhub,
			   enum m4sensorhub_panichdl_index index,
			   void (*cb_func)(struct m4sensorhub_data *, void *),
			   void *data);
int m4sensorhub_panic_unregister(struct m4sensorhub_data *m4sensorhub,
				enum m4sensorhub_panichdl_index index);
void m4sensorhub_panic_process(struct m4sensorhub_data *m4sensorhub);
/* all M4 based drivers need to register an init call with the core,
 this callback will be executed once M4 core has properly set up FW
 on M4. For registration, a callback and a void* is passed in. When
 the callback is executed, the client provided void* is passed back
 as part of (init_calldata).p_data */
int m4sensorhub_register_initcall(int(*initfunc)(struct init_calldata *),
							void *pdata);
void m4sensorhub_unregister_initcall(
		int(*initfunc)(struct init_calldata *));

int m4sensorhub_irq_disable_all(struct m4sensorhub_data *m4sensorhub);

#endif /* __KERNEL__ */
#endif  /* __M4SENSORHUB_H__ */