summaryrefslogtreecommitdiff
path: root/lwis_device_i2c.h
blob: 7d52d1f0a7b504f8c04cd9fad6a742e1727831f5 (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
/*
 * Google LWIS I2C Device Driver
 *
 * Copyright (c) 2018 Google, LLC
 *
 * 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.
 */

#ifndef LWIS_DEVICE_I2C_H_
#define LWIS_DEVICE_I2C_H_

#include <linux/i2c.h>
#include <linux/pinctrl/consumer.h>

#include "lwis_device.h"

#define MAX_I2C_LOCK_NUM 8

/*
 *  struct lwis_i2c_device
 *  "Derived" lwis_device struct, with added i2c related elements.
 */
struct lwis_i2c_device {
	struct lwis_device base_dev;
	int address;
	struct i2c_adapter *adapter;
	struct i2c_client *client;
	struct pinctrl *state_pinctrl;
	bool pinctrl_default_state_only;
	/* Group id for I2C lock */
	u32 i2c_lock_group_id;
	/* Mutex shared by the same group id's I2C devices */
	struct mutex *group_i2c_lock;
};

int lwis_i2c_device_deinit(void);

#if IS_ENABLED(CONFIG_INPUT_STMVL53L1)
/*
 * Module stmvl53l1 shares one i2c bus with some lwis i2c devices. And use the
 * two APIs in stmvl53l1 driver to well handle the enabling and disabling.
 */
extern bool is_shared_i2c_with_stmvl53l1(struct pinctrl *pinctrl);
extern int shared_i2c_set_state(struct device *dev, struct pinctrl *pinctrl, const char *state_str);
#endif

#endif /* LWIS_DEVICE_I2C_H_ */