staticint kxtj9_update_odr(struct kxtj9_data *tj9, unsignedint poll_interval)
{ int err; int i;
/* Use the lowest ODR that can support the requested poll interval */ for (i = 0; i < ARRAY_SIZE(kxtj9_odr_table); i++) {
tj9->data_ctrl = kxtj9_odr_table[i].mask; if (poll_interval < kxtj9_odr_table[i].cutoff) break;
}
staticint kxtj9_device_power_on(struct kxtj9_data *tj9)
{ if (tj9->pdata.power_on) return tj9->pdata.power_on();
return 0;
}
staticvoid kxtj9_device_power_off(struct kxtj9_data *tj9)
{ int err;
tj9->ctrl_reg1 &= PC1_OFF;
err = i2c_smbus_write_byte_data(tj9->client, CTRL_REG1, tj9->ctrl_reg1); if (err < 0)
dev_err(&tj9->client->dev, "soft power off failed\n");
if (tj9->pdata.power_off)
tj9->pdata.power_off();
}
staticint kxtj9_enable(struct kxtj9_data *tj9)
{ int err;
err = kxtj9_device_power_on(tj9); if (err < 0) return err;
/* ensure that PC1 is cleared before updating control registers */
err = i2c_smbus_write_byte_data(tj9->client, CTRL_REG1, 0); if (err < 0) return err;
/* only write INT_CTRL_REG1 if in irq mode */ if (tj9->client->irq) {
err = i2c_smbus_write_byte_data(tj9->client,
INT_CTRL1, tj9->int_ctrl); if (err < 0) return err;
}
err = kxtj9_update_g_range(tj9, tj9->pdata.g_range); if (err < 0) return err;
/* turn on outputs */
tj9->ctrl_reg1 |= PC1_ON;
err = i2c_smbus_write_byte_data(tj9->client, CTRL_REG1, tj9->ctrl_reg1); if (err < 0) return err;
err = kxtj9_update_odr(tj9, tj9->last_poll_interval); if (err < 0) return err;
/* clear initial interrupt if in irq mode */ if (tj9->client->irq) {
err = i2c_smbus_read_byte_data(tj9->client, INT_REL); if (err < 0) {
dev_err(&tj9->client->dev, "error clearing interrupt: %d\n", err); goto fail;
}
}
/* * When IRQ mode is selected, we need to provide an interface to allow the user * to change the output data rate of the part. For consistency, we are using * the set_poll method, which accepts a poll interval in milliseconds, and then * calls update_odr() while passing this value as an argument. In IRQ mode, the * data outputs will not be read AT the requested poll interval, rather, the * lowest ODR that can support the requested interval. The client application * will be responsible for retrieving data from the input node at the desired * interval.
*/
/* Lock the device to prevent races with open/close (and itself) */
guard(mutex)(&input_dev->mutex);
guard(disable_irq)(&client->irq);
/* * Set current interval to the greater of the minimum interval or * the requested interval
*/
tj9->last_poll_interval = max(interval, tj9->pdata.min_interval);
if (!i2c_check_functionality(client->adapter,
I2C_FUNC_I2C | I2C_FUNC_SMBUS_BYTE_DATA)) {
dev_err(&client->dev, "client is not i2c capable\n"); return -ENXIO;
}
if (!pdata) {
dev_err(&client->dev, "platform data is NULL; exiting\n"); return -EINVAL;
}
tj9 = devm_kzalloc(&client->dev, sizeof(*tj9), GFP_KERNEL); if (!tj9) {
dev_err(&client->dev, "failed to allocate memory for module data\n"); return -ENOMEM;
}
tj9->client = client;
tj9->pdata = *pdata;
if (pdata->init) {
err = pdata->init(); if (err < 0) return err;
}
err = devm_add_action_or_reset(&client->dev, kxtj9_platform_exit, tj9); if (err) return err;
err = kxtj9_verify(tj9); if (err < 0) {
dev_err(&client->dev, "device not recognized\n"); return err;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.