aboutsummaryrefslogtreecommitdiff
path: root/include/linux/sensors/sensorhub.h
blob: 24b0ceeb5109f6e2c685a5102ca51d3c89b4fdff (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
/**
 * Hillcrest SensorHub driver
 *
 * Copyright (C) 2013-14 Hillcrest Labs, Inc.
 *
 * 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.
 *
 * 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 __SENSORHUB__
#define __SENSORHUB__

#ifdef __KERNEL__
#include <linux/ioctl.h>
#else
#include <sys/ioctl.h>
#endif


/**
 * Each read() returns a (variable length) sensorhub_input_event structure if
 * SH_IOC_SET_REPORT_METADATA is enabled. The HID input report is placed at the
 * end of the header section and can be accessed with the msg field.
 */
struct sensorhub_input_event {
	// event timestamp in nanoseconds
	__u64 timestamp;
	// variable length msg array
	__u32 len;
	__u8 msg[];
} __attribute__((packed));
/* ioctl Interface */
/* Get sysfs path where attributes are defined */
#define SH_IOC_GET_SYSFS_PATH(len) _IOC(_IOC_READ, 'S', 0x01, len)

/**
 *  Get and Set feature reports
 *  The first byte of the buffer for each op should be the report id
 *  The ioctl returns the length of the bytes read/written from/to the
 *  device.
 */
#define SH_IOC_GET_FEATURE(len)    _IOC(_IOC_READ | _IOC_WRITE, 'S', 0x02, len)
#define SH_IOC_SET_FEATURE(len)    _IOC(_IOC_READ | _IOC_WRITE, 'S', 0x03, len)

/**
 * Enable/disable report metadata.
 * When enabled, each read will be pre-fixed with a struct sensorhub_input_event
 */
#define SH_IOC_SET_REPORT_METADATA _IOW('S', 0x04, int)

#ifdef __KERNEL__

#define SENSORHUB_I2C_ID "sensorhub"
#define SENSORHUB_I2C_ADDR 0x48

struct sensorhub_platform_data {
	/**
	 * The IRQ number for the sensorhub interrupt
	 */
	int irq;
	/**
	 * The GPIO corresponding to the interrupt
	 * Must be configured as an input and pull-up enabled
	 */
	int gpio_interrupt;
	/**
	 * A GPIO to reset the hardware
	 * Must be configured as an output
	 */
	int gpio_reset;
	/**
	 * An optional debug (output) GPIO used by the driver
	 * Must be configured as an output
	 */
	int gpio_debug;
	/**
	 * A wakeup pin for the Sensorhub.
	 * Must be configured as an output.
	 */
	int gpio_wakeup;
	/**
	 * Callback function for any platform initialization/de-init
	 * @param enabled = 1 on first hardware access, 0 on shutdown
	 */
	int (* setup)(struct device *dev, int enabled);
};

#endif /* __KERNEL__ */

#endif  /* __SENSORHUB__ */