Lines Matching refs:tj9

80 static int kxtj9_i2c_read(struct kxtj9_data *tj9, u8 addr, u8 *data, int len)  in kxtj9_i2c_read()  argument
84 .addr = tj9->client->addr, in kxtj9_i2c_read()
85 .flags = tj9->client->flags, in kxtj9_i2c_read()
90 .addr = tj9->client->addr, in kxtj9_i2c_read()
91 .flags = tj9->client->flags | I2C_M_RD, in kxtj9_i2c_read()
97 return i2c_transfer(tj9->client->adapter, msgs, 2); in kxtj9_i2c_read()
100 static void kxtj9_report_acceleration_data(struct kxtj9_data *tj9) in kxtj9_report_acceleration_data() argument
106 err = kxtj9_i2c_read(tj9, XOUT_L, (u8 *)acc_data, 6); in kxtj9_report_acceleration_data()
108 dev_err(&tj9->client->dev, "accelerometer data read failed\n"); in kxtj9_report_acceleration_data()
110 x = le16_to_cpu(acc_data[tj9->pdata.axis_map_x]); in kxtj9_report_acceleration_data()
111 y = le16_to_cpu(acc_data[tj9->pdata.axis_map_y]); in kxtj9_report_acceleration_data()
112 z = le16_to_cpu(acc_data[tj9->pdata.axis_map_z]); in kxtj9_report_acceleration_data()
114 x >>= tj9->shift; in kxtj9_report_acceleration_data()
115 y >>= tj9->shift; in kxtj9_report_acceleration_data()
116 z >>= tj9->shift; in kxtj9_report_acceleration_data()
118 input_report_abs(tj9->input_dev, ABS_X, tj9->pdata.negate_x ? -x : x); in kxtj9_report_acceleration_data()
119 input_report_abs(tj9->input_dev, ABS_Y, tj9->pdata.negate_y ? -y : y); in kxtj9_report_acceleration_data()
120 input_report_abs(tj9->input_dev, ABS_Z, tj9->pdata.negate_z ? -z : z); in kxtj9_report_acceleration_data()
121 input_sync(tj9->input_dev); in kxtj9_report_acceleration_data()
126 struct kxtj9_data *tj9 = dev; in kxtj9_isr() local
130 kxtj9_report_acceleration_data(tj9); in kxtj9_isr()
132 err = i2c_smbus_read_byte_data(tj9->client, INT_REL); in kxtj9_isr()
134 dev_err(&tj9->client->dev, in kxtj9_isr()
140 static int kxtj9_update_g_range(struct kxtj9_data *tj9, u8 new_g_range) in kxtj9_update_g_range() argument
144 tj9->shift = 4; in kxtj9_update_g_range()
147 tj9->shift = 3; in kxtj9_update_g_range()
150 tj9->shift = 2; in kxtj9_update_g_range()
156 tj9->ctrl_reg1 &= 0xe7; in kxtj9_update_g_range()
157 tj9->ctrl_reg1 |= new_g_range; in kxtj9_update_g_range()
162 static int kxtj9_update_odr(struct kxtj9_data *tj9, unsigned int poll_interval) in kxtj9_update_odr() argument
169 tj9->data_ctrl = kxtj9_odr_table[i].mask; in kxtj9_update_odr()
174 err = i2c_smbus_write_byte_data(tj9->client, CTRL_REG1, 0); in kxtj9_update_odr()
178 err = i2c_smbus_write_byte_data(tj9->client, DATA_CTRL, tj9->data_ctrl); in kxtj9_update_odr()
182 err = i2c_smbus_write_byte_data(tj9->client, CTRL_REG1, tj9->ctrl_reg1); in kxtj9_update_odr()
189 static int kxtj9_device_power_on(struct kxtj9_data *tj9) in kxtj9_device_power_on() argument
191 if (tj9->pdata.power_on) in kxtj9_device_power_on()
192 return tj9->pdata.power_on(); in kxtj9_device_power_on()
197 static void kxtj9_device_power_off(struct kxtj9_data *tj9) in kxtj9_device_power_off() argument
201 tj9->ctrl_reg1 &= PC1_OFF; in kxtj9_device_power_off()
202 err = i2c_smbus_write_byte_data(tj9->client, CTRL_REG1, tj9->ctrl_reg1); in kxtj9_device_power_off()
204 dev_err(&tj9->client->dev, "soft power off failed\n"); in kxtj9_device_power_off()
206 if (tj9->pdata.power_off) in kxtj9_device_power_off()
207 tj9->pdata.power_off(); in kxtj9_device_power_off()
210 static int kxtj9_enable(struct kxtj9_data *tj9) in kxtj9_enable() argument
214 err = kxtj9_device_power_on(tj9); in kxtj9_enable()
219 err = i2c_smbus_write_byte_data(tj9->client, CTRL_REG1, 0); in kxtj9_enable()
224 if (tj9->client->irq) { in kxtj9_enable()
225 err = i2c_smbus_write_byte_data(tj9->client, in kxtj9_enable()
226 INT_CTRL1, tj9->int_ctrl); in kxtj9_enable()
231 err = kxtj9_update_g_range(tj9, tj9->pdata.g_range); in kxtj9_enable()
236 tj9->ctrl_reg1 |= PC1_ON; in kxtj9_enable()
237 err = i2c_smbus_write_byte_data(tj9->client, CTRL_REG1, tj9->ctrl_reg1); in kxtj9_enable()
241 err = kxtj9_update_odr(tj9, tj9->last_poll_interval); in kxtj9_enable()
246 if (tj9->client->irq) { in kxtj9_enable()
247 err = i2c_smbus_read_byte_data(tj9->client, INT_REL); in kxtj9_enable()
249 dev_err(&tj9->client->dev, in kxtj9_enable()
258 kxtj9_device_power_off(tj9); in kxtj9_enable()
262 static void kxtj9_disable(struct kxtj9_data *tj9) in kxtj9_disable() argument
264 kxtj9_device_power_off(tj9); in kxtj9_disable()
269 struct kxtj9_data *tj9 = input_get_drvdata(input); in kxtj9_input_open() local
271 return kxtj9_enable(tj9); in kxtj9_input_open()
276 struct kxtj9_data *tj9 = input_get_drvdata(dev); in kxtj9_input_close() local
278 kxtj9_disable(tj9); in kxtj9_input_close()
297 struct kxtj9_data *tj9 = i2c_get_clientdata(client); in kxtj9_get_poll() local
299 return sprintf(buf, "%d\n", tj9->last_poll_interval); in kxtj9_get_poll()
307 struct kxtj9_data *tj9 = i2c_get_clientdata(client); in kxtj9_set_poll() local
308 struct input_dev *input_dev = tj9->input_dev; in kxtj9_set_poll()
325 tj9->last_poll_interval = max(interval, tj9->pdata.min_interval); in kxtj9_set_poll()
327 kxtj9_update_odr(tj9, tj9->last_poll_interval); in kxtj9_set_poll()
359 struct kxtj9_data *tj9 = input_get_drvdata(input); in kxtj9_poll() local
362 kxtj9_report_acceleration_data(tj9); in kxtj9_poll()
364 if (poll_interval != tj9->last_poll_interval) { in kxtj9_poll()
365 kxtj9_update_odr(tj9, poll_interval); in kxtj9_poll()
366 tj9->last_poll_interval = poll_interval; in kxtj9_poll()
372 struct kxtj9_data *tj9 = data; in kxtj9_platform_exit() local
374 if (tj9->pdata.exit) in kxtj9_platform_exit()
375 tj9->pdata.exit(); in kxtj9_platform_exit()
378 static int kxtj9_verify(struct kxtj9_data *tj9) in kxtj9_verify() argument
382 retval = kxtj9_device_power_on(tj9); in kxtj9_verify()
386 retval = i2c_smbus_read_byte_data(tj9->client, WHO_AM_I); in kxtj9_verify()
388 dev_err(&tj9->client->dev, "read err int source\n"); in kxtj9_verify()
395 kxtj9_device_power_off(tj9); in kxtj9_verify()
403 struct kxtj9_data *tj9; in kxtj9_probe() local
418 tj9 = devm_kzalloc(&client->dev, sizeof(*tj9), GFP_KERNEL); in kxtj9_probe()
419 if (!tj9) { in kxtj9_probe()
425 tj9->client = client; in kxtj9_probe()
426 tj9->pdata = *pdata; in kxtj9_probe()
434 err = devm_add_action_or_reset(&client->dev, kxtj9_platform_exit, tj9); in kxtj9_probe()
438 err = kxtj9_verify(tj9); in kxtj9_probe()
444 i2c_set_clientdata(client, tj9); in kxtj9_probe()
446 tj9->ctrl_reg1 = tj9->pdata.res_12bit | tj9->pdata.g_range; in kxtj9_probe()
447 tj9->last_poll_interval = tj9->pdata.init_interval; in kxtj9_probe()
455 input_set_drvdata(input_dev, tj9); in kxtj9_probe()
456 tj9->input_dev = input_dev; in kxtj9_probe()
484 tj9->int_ctrl |= KXTJ9_IEN | KXTJ9_IEA | KXTJ9_IEL; in kxtj9_probe()
485 tj9->ctrl_reg1 |= DRDYE; in kxtj9_probe()
491 "kxtj9-irq", tj9); in kxtj9_probe()
504 struct kxtj9_data *tj9 = i2c_get_clientdata(client); in kxtj9_suspend() local
505 struct input_dev *input_dev = tj9->input_dev; in kxtj9_suspend()
510 kxtj9_disable(tj9); in kxtj9_suspend()
519 struct kxtj9_data *tj9 = i2c_get_clientdata(client); in kxtj9_resume() local
520 struct input_dev *input_dev = tj9->input_dev; in kxtj9_resume()
525 kxtj9_enable(tj9); in kxtj9_resume()