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 24 #define MMA9551_APPID_PEDOMETER 0x15 25 #define MMA9551_APPID_RCS 0x17 26 #define MMA9551_APPID_NONE 0xff 27 28 /* Reset/Suspend/Clear application app masks */ 29 #define MMA9551_RSC_PED BIT(21) 30 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); 55 int mma9551_read_config_word(struct i2c_client *client, u8 app_id, 56 u16 reg, u16 *val); 57 int mma9551_write_config_word(struct i2c_client *client, u8 app_id, 58 u16 reg, u16 val); 59 int mma9551_read_status_word(struct i2c_client *client, u8 app_id, 60 u16 reg, u16 *val); 61 int mma9551_read_config_words(struct i2c_client *client, u8 app_id, 62 u16 reg, u8 len, u16 *buf); 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); 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); 79 int mma9551_app_reset(struct i2c_client *client, u32 app_mask); 80 81 #endif /* _MMA9551_CORE_H_ */ 82