static int bmm_wakeup(struct i2c_client *client) { int err = 0; int try_times = BMM_MAX_RETRY_WAKEUP; const u8 value = 0x01; u8 dummy; PINFO("waking up the chip..."); while (try_times) { err = bmm_i2c_write(client, BMM_REG_NAME(POWER_CNTL), (u8 *)&value, 1); mdelay(BMM_I2C_WRITE_DELAY_TIME); dummy = 0; err = bmm_i2c_read(client, BMM_REG_NAME(POWER_CNTL), &dummy, 1); if (value == dummy) break; try_times--; } PINFO("wake up result: %s, tried times: %d", (try_times > 0) ? "succeed" : "fail", BMM_MAX_RETRY_WAKEUP - try_times + 1); err = (try_times > 0) ? 0 : -1; return err; }
static void bmm_dump_reg(struct i2c_client *client) { int i; #ifdef CONFIG_MACH_LGE // //wbt 412964 'dbg_buf' array elements are used uninitialized in this function with index range: [16,63]. u8 dbg_buf[64] = ""; #else u8 dbg_buf[64]; #endif u8 dbg_buf_str[64 * 3 + 1] = ""; for (i = 0; i < BYTES_PER_LINE; i++) { dbg_buf[i] = i; sprintf(dbg_buf_str + i * 3, "%02x%c", dbg_buf[i], (((i + 1) % BYTES_PER_LINE == 0) ? '\n' : ' ')); } printk(KERN_DEBUG "%s\n", dbg_buf_str); bmm_i2c_read(client, BMM_REG_NAME(CHIP_ID), dbg_buf, 64); for (i = 0; i < 64; i++) { sprintf(dbg_buf_str + i * 3, "%02x%c", dbg_buf[i], (((i + 1) % BYTES_PER_LINE == 0) ? '\n' : ' ')); } printk(KERN_DEBUG "%s\n", dbg_buf_str); }
static int bmm_wakeup(struct i2c_client *client) { int err = 0; int try_times = BMM_MAX_RETRY_WAKEUP; const u8 value = 0x01; u8 dummy; pr_info("%s -waking up the chip...",__func__); usleep_range(4900, 5000); /*BMM_I2C_WRITE_DELAY_TIME*/ while (try_times) { err = bmm_i2c_write(client, BMM_REG_NAME(POWER_CNTL), (u8 *)&value, 1); usleep_range(4900, 5000); dummy = 0; err = bmm_i2c_read(client, BMM_REG_NAME(POWER_CNTL), &dummy, 1); if (value == dummy) break; try_times--; } pr_info("%s -wake up result: %s, tried times: %d",__func__, (try_times > 0) ? "succeed" : "fail", BMM_MAX_RETRY_WAKEUP - try_times + 1); err = (try_times > 0) ? 0 : -1; return err; }
static int bmm_check_chip_id(struct i2c_client *client) { int err = 0; u8 chip_id = 0; bmm_i2c_read(client, BMM_REG_NAME(CHIP_ID), &chip_id, 1); PINFO("read chip id result: %#x", chip_id); if ((chip_id & 0xff) != SENSOR_CHIP_ID_BMM) err = -1; return err; }
static int bmm_check_chip_id(struct i2c_client *client) { int err = -1; u8 chip_id = 0; u8 read_count = 0; while (read_count++ < CHECK_CHIP_ID_TIME_MAX) { bmm_i2c_read(client, BMM_REG_NAME(CHIP_ID), &chip_id, 1); pr_info("%s read chip id result: %#x", __func__,chip_id); if ((chip_id & 0xff) != SENSOR_CHIP_ID_BMM) { mdelay(1); } else { err = 0; break; } } return err; }
static void bmm_dump_reg(struct i2c_client *client) { int i; u8 dbg_buf[64]; u8 dbg_buf_str[64 * 3 + 1] = ""; for (i = 0; i < BYTES_PER_LINE; i++) { dbg_buf[i] = i; sprintf(dbg_buf_str + i * 3, "%02x%c", dbg_buf[i], (((i + 1) % BYTES_PER_LINE == 0) ? '\n' : ' ')); } printk(KERN_DEBUG "%s\n", dbg_buf_str); bmm_i2c_read(client, BMM_REG_NAME(CHIP_ID), dbg_buf, 64); for (i = 0; i < 64; i++) { sprintf(dbg_buf_str + i * 3, "%02x%c", dbg_buf[i], (((i + 1) % BYTES_PER_LINE == 0) ? '\n' : ' ')); } printk(KERN_DEBUG "%s\n", dbg_buf_str); }