Lines Matching +full:poll +full:- +full:rate +full:- +full:ms

1 // SPDX-License-Identifier: GPL-2.0-only
53 * The following table lists the maximum appropriate poll interval for each
54 * available output data rate.
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()
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()
132 err = i2c_smbus_read_byte_data(tj9->client, INT_REL); in kxtj9_isr()
134 dev_err(&tj9->client->dev, in kxtj9_isr()
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()
153 return -EINVAL; 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()
167 /* Use the lowest ODR that can support the requested poll interval */ in kxtj9_update_odr()
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()
191 if (tj9->pdata.power_on) in kxtj9_device_power_on()
192 return tj9->pdata.power_on(); in kxtj9_device_power_on()
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()
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()
283 * to change the output data rate of the part. For consistency, we are using
284 * the set_poll method, which accepts a poll interval in milliseconds, and then
286 * data outputs will not be read AT the requested poll interval, rather, the
292 /* Returns currently selected poll interval (in ms) */
299 return sprintf(buf, "%d\n", tj9->last_poll_interval); in kxtj9_get_poll()
302 /* Allow users to select a new poll interval (in ms) */
308 struct input_dev *input_dev = tj9->input_dev; in kxtj9_set_poll()
317 guard(mutex)(&input_dev->mutex); in kxtj9_set_poll()
318 guard(disable_irq)(&client->irq); in kxtj9_set_poll()
324 tj9->last_poll_interval = max(interval, tj9->pdata.min_interval); in kxtj9_set_poll()
326 kxtj9_update_odr(tj9, tj9->last_poll_interval); in kxtj9_set_poll()
331 static DEVICE_ATTR(poll, S_IRUGO|S_IWUSR, kxtj9_get_poll, kxtj9_set_poll);
344 return client->irq ? attr->mode : 0; in kxtj9_attr_is_visible()
360 if (poll_interval != tj9->last_poll_interval) { in kxtj9_poll()
362 tj9->last_poll_interval = poll_interval; in kxtj9_poll()
370 if (tj9->pdata.exit) in kxtj9_platform_exit()
371 tj9->pdata.exit(); in kxtj9_platform_exit()
382 retval = i2c_smbus_read_byte_data(tj9->client, WHO_AM_I); in kxtj9_verify()
384 dev_err(&tj9->client->dev, "read err int source\n"); in kxtj9_verify()
388 retval = (retval != 0x07 && retval != 0x08) ? -EIO : 0; in kxtj9_verify()
398 dev_get_platdata(&client->dev); in kxtj9_probe()
403 if (!i2c_check_functionality(client->adapter, in kxtj9_probe()
405 dev_err(&client->dev, "client is not i2c capable\n"); in kxtj9_probe()
406 return -ENXIO; in kxtj9_probe()
410 dev_err(&client->dev, "platform data is NULL; exiting\n"); in kxtj9_probe()
411 return -EINVAL; in kxtj9_probe()
414 tj9 = devm_kzalloc(&client->dev, sizeof(*tj9), GFP_KERNEL); in kxtj9_probe()
416 dev_err(&client->dev, in kxtj9_probe()
418 return -ENOMEM; in kxtj9_probe()
421 tj9->client = client; in kxtj9_probe()
422 tj9->pdata = *pdata; in kxtj9_probe()
424 if (pdata->init) { in kxtj9_probe()
425 err = pdata->init(); in kxtj9_probe()
430 err = devm_add_action_or_reset(&client->dev, kxtj9_platform_exit, tj9); in kxtj9_probe()
436 dev_err(&client->dev, "device not recognized\n"); in kxtj9_probe()
442 tj9->ctrl_reg1 = tj9->pdata.res_12bit | tj9->pdata.g_range; in kxtj9_probe()
443 tj9->last_poll_interval = tj9->pdata.init_interval; in kxtj9_probe()
445 input_dev = devm_input_allocate_device(&client->dev); in kxtj9_probe()
447 dev_err(&client->dev, "input device allocate failed\n"); in kxtj9_probe()
448 return -ENOMEM; in kxtj9_probe()
452 tj9->input_dev = input_dev; in kxtj9_probe()
454 input_dev->name = "kxtj9_accel"; in kxtj9_probe()
455 input_dev->id.bustype = BUS_I2C; in kxtj9_probe()
457 input_dev->open = kxtj9_input_open; in kxtj9_probe()
458 input_dev->close = kxtj9_input_close; in kxtj9_probe()
460 input_set_abs_params(input_dev, ABS_X, -G_MAX, G_MAX, FUZZ, FLAT); in kxtj9_probe()
461 input_set_abs_params(input_dev, ABS_Y, -G_MAX, G_MAX, FUZZ, FLAT); in kxtj9_probe()
462 input_set_abs_params(input_dev, ABS_Z, -G_MAX, G_MAX, FUZZ, FLAT); in kxtj9_probe()
464 if (client->irq <= 0) { in kxtj9_probe()
472 dev_err(&client->dev, in kxtj9_probe()
474 input_dev->name, err); in kxtj9_probe()
478 if (client->irq) { in kxtj9_probe()
480 tj9->int_ctrl |= KXTJ9_IEN | KXTJ9_IEA | KXTJ9_IEL; in kxtj9_probe()
481 tj9->ctrl_reg1 |= DRDYE; in kxtj9_probe()
483 err = devm_request_threaded_irq(&client->dev, client->irq, in kxtj9_probe()
487 "kxtj9-irq", tj9); in kxtj9_probe()
489 dev_err(&client->dev, "request irq failed: %d\n", err); in kxtj9_probe()
501 struct input_dev *input_dev = tj9->input_dev; in kxtj9_suspend()
503 guard(mutex)(&input_dev->mutex); in kxtj9_suspend()
515 struct input_dev *input_dev = tj9->input_dev; in kxtj9_resume()
517 guard(mutex)(&input_dev->mutex); in kxtj9_resume()