Irina Tirdea | d5b97f5 | 2015-01-11 21:10:15 +0200 | [diff] [blame] | 1 | /* |
| 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 Tirdea | 40cb761 | 2015-01-29 18:45:10 +0000 | [diff] [blame] | 24 | #define MMA9551_APPID_PEDOMETER 0x15 |
Irina Tirdea | 476c41a | 2015-04-13 18:40:53 +0300 | [diff] [blame] | 25 | #define MMA9551_APPID_RSC 0x17 |
Irina Tirdea | d5b97f5 | 2015-01-11 21:10:15 +0200 | [diff] [blame] | 26 | #define MMA9551_APPID_NONE 0xff |
| 27 | |
Irina Tirdea | 40cb761 | 2015-01-29 18:45:10 +0000 | [diff] [blame] | 28 | /* Reset/Suspend/Clear application app masks */ |
| 29 | #define MMA9551_RSC_PED BIT(21) |
| 30 | |
Irina Tirdea | d5b97f5 | 2015-01-11 21:10:15 +0200 | [diff] [blame] | 31 | #define MMA9551_AUTO_SUSPEND_DELAY_MS 2000 |
| 32 | |
| 33 | enum 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 | |
| 49 | int mma9551_read_config_byte(struct i2c_client *client, u8 app_id, |
| 50 | u16 reg, u8 *val); |
| 51 | int mma9551_write_config_byte(struct i2c_client *client, u8 app_id, |
| 52 | u16 reg, u8 val); |
| 53 | int mma9551_read_status_byte(struct i2c_client *client, u8 app_id, |
| 54 | u16 reg, u8 *val); |
Irina Tirdea | 40cb761 | 2015-01-29 18:45:10 +0000 | [diff] [blame] | 55 | int mma9551_read_config_word(struct i2c_client *client, u8 app_id, |
Irina Tirdea | b37c199 | 2015-04-13 18:41:02 +0300 | [diff] [blame] | 56 | u16 reg, u16 *val); |
Irina Tirdea | 40cb761 | 2015-01-29 18:45:10 +0000 | [diff] [blame] | 57 | int mma9551_write_config_word(struct i2c_client *client, u8 app_id, |
Irina Tirdea | b37c199 | 2015-04-13 18:41:02 +0300 | [diff] [blame] | 58 | u16 reg, u16 val); |
Irina Tirdea | d5b97f5 | 2015-01-11 21:10:15 +0200 | [diff] [blame] | 59 | int mma9551_read_status_word(struct i2c_client *client, u8 app_id, |
| 60 | u16 reg, u16 *val); |
Irina Tirdea | 40cb761 | 2015-01-29 18:45:10 +0000 | [diff] [blame] | 61 | int mma9551_read_config_words(struct i2c_client *client, u8 app_id, |
Irina Tirdea | b37c199 | 2015-04-13 18:41:02 +0300 | [diff] [blame] | 62 | u16 reg, u8 len, u16 *buf); |
Irina Tirdea | 40cb761 | 2015-01-29 18:45:10 +0000 | [diff] [blame] | 63 | int mma9551_read_status_words(struct i2c_client *client, u8 app_id, |
| 64 | u16 reg, u8 len, u16 *buf); |
| 65 | int mma9551_write_config_words(struct i2c_client *client, u8 app_id, |
| 66 | u16 reg, u8 len, u16 *buf); |
Irina Tirdea | d5b97f5 | 2015-01-11 21:10:15 +0200 | [diff] [blame] | 67 | int mma9551_update_config_bits(struct i2c_client *client, u8 app_id, |
| 68 | u16 reg, u8 mask, u8 val); |
| 69 | int mma9551_gpio_config(struct i2c_client *client, enum mma9551_gpio_pin pin, |
| 70 | u8 app_id, u8 bitnum, int polarity); |
| 71 | int mma9551_read_version(struct i2c_client *client); |
| 72 | int mma9551_set_device_state(struct i2c_client *client, bool enable); |
| 73 | int mma9551_set_power_state(struct i2c_client *client, bool on); |
| 74 | void mma9551_sleep(int freq); |
| 75 | int mma9551_read_accel_chan(struct i2c_client *client, |
| 76 | const struct iio_chan_spec *chan, |
| 77 | int *val, int *val2); |
| 78 | int mma9551_read_accel_scale(int *val, int *val2); |
Irina Tirdea | 40cb761 | 2015-01-29 18:45:10 +0000 | [diff] [blame] | 79 | int mma9551_app_reset(struct i2c_client *client, u32 app_mask); |
Irina Tirdea | d5b97f5 | 2015-01-11 21:10:15 +0200 | [diff] [blame] | 80 | |
| 81 | #endif /* _MMA9551_CORE_H_ */ |