static void bma255_set_int_enable(struct i2c_client *client, unsigned char InterruptType , unsigned char value) { unsigned char reg; bma255_smbus_read_byte(client, BMA255_INT_ENABLE1_REG, ®); switch (InterruptType) { case SLOPE_X_INT: /* Slope X Interrupt */ reg = BMA255_SET_BITSLICE(reg, BMA255_EN_SLOPE_X_INT, value); break; case SLOPE_Y_INT: /* Slope Y Interrupt */ reg = BMA255_SET_BITSLICE(reg, BMA255_EN_SLOPE_Y_INT, value); break; case SLOPE_Z_INT: /* Slope Z Interrupt */ reg = BMA255_SET_BITSLICE(reg, BMA255_EN_SLOPE_Z_INT, value); break; default: break; } bma255_smbus_write_byte(client, BMA255_INT_ENABLE1_REG, ®); }
static int bma255_set_range(struct i2c_client *client, unsigned char range) { int ret = 0 ; unsigned char buf; ret = bma255_smbus_read_byte(client, BMA255_RANGE_SEL_REG, &buf); switch (range) { case BMA255_RANGE_2G: buf = BMA255_SET_BITSLICE(buf, BMA255_RANGE_SEL, 3); break; case BMA255_RANGE_4G: buf = BMA255_SET_BITSLICE(buf, BMA255_RANGE_SEL, 5); break; case BMA255_RANGE_8G: buf = BMA255_SET_BITSLICE(buf, BMA255_RANGE_SEL, 8); break; case BMA255_RANGE_16G: buf = BMA255_SET_BITSLICE(buf, BMA255_RANGE_SEL, 12); break; default: buf = BMA255_SET_BITSLICE(buf, BMA255_RANGE_SEL, 3); break; } ret += bma255_smbus_write_byte(client, BMA255_RANGE_SEL_REG, &buf); return ret; }
static void bma255_slope_enable(struct i2c_client *client, int enable, int factory_mode) { unsigned char reg; if (enable == ON) { bma255_smbus_read_byte(client, BMA255_EN_INT1_PAD_SLOPE__REG, ®); reg = BMA255_SET_BITSLICE(reg, BMA255_EN_INT1_PAD_SLOPE, ON); bma255_smbus_write_byte(client, BMA255_EN_INT1_PAD_SLOPE__REG, ®); bma255_smbus_read_byte(client, BMA255_INT_MODE_SEL__REG, ®); reg = BMA255_SET_BITSLICE(reg, BMA255_INT_MODE_SEL, 0x01); bma255_smbus_write_byte(client, BMA255_INT_MODE_SEL__REG, ®); bma255_smbus_read_byte(client, BMA255_SLOPE_DUR__REG, ®); reg = BMA255_SET_BITSLICE(reg, BMA255_SLOPE_DUR, SLOPE_DURATION_VALUE); bma255_smbus_write_byte(client, BMA255_SLOPE_DUR__REG, ®); if (factory_mode == OFF) { reg = SLOPE_THRESHOLD_VALUE; bma255_smbus_write_byte(client, BMA255_SLOPE_THRES__REG, ®); bma255_set_int_enable(client, SLOPE_X_INT, ON); bma255_set_int_enable(client, SLOPE_Y_INT, ON); bma255_set_int_enable(client, SLOPE_Z_INT, ON); } else { reg = 0x00; bma255_smbus_write_byte(client, BMA255_SLOPE_THRES__REG, ®); bma255_set_int_enable(client, SLOPE_Z_INT, ON); } bma255_set_bandwidth(client, BMA255_BW_7_81HZ); } else if (enable == OFF) { bma255_smbus_read_byte(client, BMA255_EN_INT1_PAD_SLOPE__REG, ®); reg = BMA255_SET_BITSLICE(reg, BMA255_EN_INT1_PAD_SLOPE, OFF); bma255_smbus_write_byte(client, BMA255_EN_INT1_PAD_SLOPE__REG, ®); bma255_set_int_enable(client, SLOPE_X_INT, OFF); bma255_set_int_enable(client, SLOPE_Y_INT, OFF); bma255_set_int_enable(client, SLOPE_Z_INT, OFF); bma255_set_bandwidth(client, BMA255_BW_125HZ); } }
static int bma255_set_bandwidth(struct i2c_client *client, unsigned char bandwidth) { int ret = 0; unsigned char buf; if (bandwidth <= 7 || bandwidth >= 16) bandwidth = BMA255_BW_1000HZ; ret = bma255_smbus_read_byte(client, BMA255_BANDWIDTH__REG, &buf); buf = BMA255_SET_BITSLICE(buf, BMA255_BANDWIDTH, bandwidth); ret += bma255_smbus_write_byte(client, BMA255_BANDWIDTH__REG, &buf); return ret; }
static int bma255_set_mode(struct bma255_p *data, unsigned char mode) { int ret = 0; unsigned char buf1, buf2; struct i2c_client *client = data->client; mutex_lock(&data->mode_mutex); ret = bma255_smbus_read_byte(client, BMA255_MODE_CTRL_REG, &buf1); ret += bma255_smbus_read_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); switch (mode) { case BMA255_MODE_NORMAL: buf1 = BMA255_SET_BITSLICE(buf1, BMA255_MODE_CTRL, 0); buf2 = BMA255_SET_BITSLICE(buf2, BMA255_LOW_POWER_MODE, 0); ret += bma255_smbus_write_byte(client, BMA255_MODE_CTRL_REG, &buf1); mdelay(1); ret += bma255_smbus_write_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); break; case BMA255_MODE_LOWPOWER1: buf1 = BMA255_SET_BITSLICE(buf1, BMA255_MODE_CTRL, 2); buf2 = BMA255_SET_BITSLICE(buf2, BMA255_LOW_POWER_MODE, 0); ret += bma255_smbus_write_byte(client, BMA255_MODE_CTRL_REG, &buf1); mdelay(1); ret += bma255_smbus_write_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); break; case BMA255_MODE_SUSPEND: buf1 = BMA255_SET_BITSLICE(buf1, BMA255_MODE_CTRL, 4); buf2 = BMA255_SET_BITSLICE(buf2, BMA255_LOW_POWER_MODE, 0); ret += bma255_smbus_write_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); mdelay(1); ret += bma255_smbus_write_byte(client, BMA255_MODE_CTRL_REG, &buf1); break; case BMA255_MODE_DEEP_SUSPEND: buf1 = BMA255_SET_BITSLICE(buf1, BMA255_MODE_CTRL, 1); buf2 = BMA255_SET_BITSLICE(buf2, BMA255_LOW_POWER_MODE, 1); ret += bma255_smbus_write_byte(client, BMA255_MODE_CTRL_REG, &buf1); mdelay(1); ret += bma255_smbus_write_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); break; case BMA255_MODE_LOWPOWER2: buf1 = BMA255_SET_BITSLICE(buf1, BMA255_MODE_CTRL, 2); buf2 = BMA255_SET_BITSLICE(buf2, BMA255_LOW_POWER_MODE, 1); ret += bma255_smbus_write_byte(client, BMA255_MODE_CTRL_REG, &buf1); mdelay(1); ret += bma255_smbus_write_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); break; case BMA255_MODE_STANDBY: buf1 = BMA255_SET_BITSLICE(buf1, BMA255_MODE_CTRL, 4); buf2 = BMA255_SET_BITSLICE(buf2, BMA255_LOW_POWER_MODE, 1); ret += bma255_smbus_write_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); mdelay(1); ret += bma255_smbus_write_byte(client, BMA255_MODE_CTRL_REG, &buf1); break; default: ret = -EINVAL; break; } pr_info("[SENSOR]: %s - change mode %u\n", __func__, mode); mutex_unlock(&data->mode_mutex); return ret; }
static int bma255_set_mode(struct i2c_client *client, unsigned char mode) { int ret = 0; unsigned char buf1, buf2, buf3; ret = bma255_smbus_read_byte(client, BMA255_MODE_CTRL_REG, &buf1); ret += bma255_smbus_read_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); ret += bma255_smbus_read_byte(client, BMA255_BW_SEL_REG, &buf3); switch (mode) { case BMA255_MODE_NORMAL: buf1 = BMA255_SET_BITSLICE(buf1, BMA255_MODE_CTRL, 0); buf2 = BMA255_SET_BITSLICE(buf2, BMA255_LOW_POWER_MODE, 0); buf3 = BMA255_SET_BITSLICE(buf3, BMA255_BANDWIDTH, 3); ret += bma255_smbus_write_byte(client, BMA255_MODE_CTRL_REG, &buf1); mdelay(1); ret += bma255_smbus_write_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); mdelay(1); ret += bma255_smbus_write_byte(client, BMA255_BW_SEL_REG, &buf3); break; case BMA255_MODE_LOWPOWER1: buf1 = BMA255_SET_BITSLICE(buf1, BMA255_MODE_CTRL, 2); buf2 = BMA255_SET_BITSLICE(buf2, BMA255_LOW_POWER_MODE, 0); ret += bma255_smbus_write_byte(client, BMA255_MODE_CTRL_REG, &buf1); mdelay(1); ret += bma255_smbus_write_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); break; case BMA255_MODE_SUSPEND: buf1 = BMA255_SET_BITSLICE(buf1, BMA255_MODE_CTRL, 4); buf2 = BMA255_SET_BITSLICE(buf2, BMA255_LOW_POWER_MODE, 0); ret += bma255_smbus_write_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); mdelay(1); ret += bma255_smbus_write_byte(client, BMA255_MODE_CTRL_REG, &buf1); break; case BMA255_MODE_DEEP_SUSPEND: buf1 = BMA255_SET_BITSLICE(buf1, BMA255_MODE_CTRL, 1); buf2 = BMA255_SET_BITSLICE(buf2, BMA255_LOW_POWER_MODE, 1); ret += bma255_smbus_write_byte(client, BMA255_MODE_CTRL_REG, &buf1); mdelay(1); ret += bma255_smbus_write_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); break; case BMA255_MODE_LOWPOWER2: buf1 = BMA255_SET_BITSLICE(buf1, BMA255_MODE_CTRL, 2); buf2 = BMA255_SET_BITSLICE(buf2, BMA255_LOW_POWER_MODE, 1); ret += bma255_smbus_write_byte(client, BMA255_MODE_CTRL_REG, &buf1); mdelay(1); ret += bma255_smbus_write_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); break; case BMA255_MODE_STANDBY: buf1 = BMA255_SET_BITSLICE(buf1, BMA255_MODE_CTRL, 4); buf2 = BMA255_SET_BITSLICE(buf2, BMA255_LOW_POWER_MODE, 1); ret += bma255_smbus_write_byte(client, BMA255_LOW_NOISE_CTRL_REG, &buf2); mdelay(1); ret += bma255_smbus_write_byte(client, BMA255_MODE_CTRL_REG, &buf1); break; default: ret = -EINVAL; break; } return ret; }