blob: 5e88e6454dfd927c7d49e0307614a1a85c4ec3d3 [file] [log] [blame]
Irina Tirdead5b97f52015-01-11 21:10:15 +02001/*
2 * Common code for Freescale MMA955x Intelligent Sensor Platform drivers
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _MMA9551_CORE_H_
16#define _MMA9551_CORE_H_
17
18/* Applications IDs */
19#define MMA9551_APPID_VERSION 0x00
20#define MMA9551_APPID_GPIO 0x03
21#define MMA9551_APPID_AFE 0x06
22#define MMA9551_APPID_TILT 0x0B
23#define MMA9551_APPID_SLEEP_WAKE 0x12
Irina Tirdea40cb7612015-01-29 18:45:10 +000024#define MMA9551_APPID_PEDOMETER 0x15
Irina Tirdea476c41a2015-04-13 18:40:53 +030025#define MMA9551_APPID_RSC 0x17
Irina Tirdead5b97f52015-01-11 21:10:15 +020026#define MMA9551_APPID_NONE 0xff
27
Irina Tirdea40cb7612015-01-29 18:45:10 +000028/* Reset/Suspend/Clear application app masks */
29#define MMA9551_RSC_PED BIT(21)
30
Irina Tirdead5b97f52015-01-11 21:10:15 +020031#define MMA9551_AUTO_SUSPEND_DELAY_MS 2000
32
33enum mma9551_gpio_pin {
34 mma9551_gpio6 = 0,
35 mma9551_gpio7,
36 mma9551_gpio8,
37 mma9551_gpio9,
38 mma9551_gpio_max = mma9551_gpio9,
39};
40
41#define MMA9551_ACCEL_CHANNEL(axis) { \
42 .type = IIO_ACCEL, \
43 .modified = 1, \
44 .channel2 = axis, \
45 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
46 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
47}
48
49int mma9551_read_config_byte(struct i2c_client *client, u8 app_id,
50 u16 reg, u8 *val);
51int mma9551_write_config_byte(struct i2c_client *client, u8 app_id,
52 u16 reg, u8 val);
53int mma9551_read_status_byte(struct i2c_client *client, u8 app_id,
54 u16 reg, u8 *val);
Irina Tirdea40cb7612015-01-29 18:45:10 +000055int mma9551_read_config_word(struct i2c_client *client, u8 app_id,
Irina Tirdeab37c1992015-04-13 18:41:02 +030056 u16 reg, u16 *val);
Irina Tirdea40cb7612015-01-29 18:45:10 +000057int mma9551_write_config_word(struct i2c_client *client, u8 app_id,
Irina Tirdeab37c1992015-04-13 18:41:02 +030058 u16 reg, u16 val);
Irina Tirdead5b97f52015-01-11 21:10:15 +020059int mma9551_read_status_word(struct i2c_client *client, u8 app_id,
60 u16 reg, u16 *val);
Irina Tirdea40cb7612015-01-29 18:45:10 +000061int mma9551_read_config_words(struct i2c_client *client, u8 app_id,
Irina Tirdeab37c1992015-04-13 18:41:02 +030062 u16 reg, u8 len, u16 *buf);
Irina Tirdea40cb7612015-01-29 18:45:10 +000063int mma9551_read_status_words(struct i2c_client *client, u8 app_id,
64 u16 reg, u8 len, u16 *buf);
65int mma9551_write_config_words(struct i2c_client *client, u8 app_id,
66 u16 reg, u8 len, u16 *buf);
Irina Tirdead5b97f52015-01-11 21:10:15 +020067int mma9551_update_config_bits(struct i2c_client *client, u8 app_id,
68 u16 reg, u8 mask, u8 val);
69int mma9551_gpio_config(struct i2c_client *client, enum mma9551_gpio_pin pin,
70 u8 app_id, u8 bitnum, int polarity);
71int mma9551_read_version(struct i2c_client *client);
72int mma9551_set_device_state(struct i2c_client *client, bool enable);
73int mma9551_set_power_state(struct i2c_client *client, bool on);
74void mma9551_sleep(int freq);
75int mma9551_read_accel_chan(struct i2c_client *client,
76 const struct iio_chan_spec *chan,
77 int *val, int *val2);
78int mma9551_read_accel_scale(int *val, int *val2);
Irina Tirdea40cb7612015-01-29 18:45:10 +000079int mma9551_app_reset(struct i2c_client *client, u32 app_mask);
Irina Tirdead5b97f52015-01-11 21:10:15 +020080
81#endif /* _MMA9551_CORE_H_ */