Lines Matching +full:robot +full:- +full:electronics
1 // SPDX-License-Identifier: GPL-2.0-only
3 * srf08.c - Support for Devantech SRFxx ultrasonic ranger
7 * Copyright (c) 2016, 2017 Andreas Klinger <ak@it-klinger.de>
10 * https://www.robot-electronics.co.uk/htm/srf08tech.html
11 * https://www.robot-electronics.co.uk/htm/srf10tech.htm
12 * https://www.robot-electronics.co.uk/htm/srf02tech.htm
35 #define SRF08_CMD_RANGING_CM 0x51 /* Ranging Mode - Result in cm */
72 /* Sensor-Type */
75 /* Chip-specific information */
125 struct i2c_client *client = data->client; in srf08_read_ranging()
129 mutex_lock(&data->lock); in srf08_read_ranging()
131 ret = i2c_smbus_write_byte_data(data->client, in srf08_read_ranging()
134 dev_err(&client->dev, "write command - err: %d\n", ret); in srf08_read_ranging()
135 mutex_unlock(&data->lock); in srf08_read_ranging()
149 waittime = 1 + data->range_mm / 172; in srf08_read_ranging()
152 ret = i2c_smbus_read_byte_data(data->client, in srf08_read_ranging()
162 dev_err(&client->dev, "device not ready\n"); in srf08_read_ranging()
163 mutex_unlock(&data->lock); in srf08_read_ranging()
164 return -EIO; in srf08_read_ranging()
167 ret = i2c_smbus_read_word_swapped(data->client, in srf08_read_ranging()
170 dev_err(&client->dev, "cannot read distance: ret=%d\n", ret); in srf08_read_ranging()
171 mutex_unlock(&data->lock); in srf08_read_ranging()
175 mutex_unlock(&data->lock); in srf08_read_ranging()
183 struct iio_dev *indio_dev = pf->indio_dev; in srf08_trigger_handler()
191 mutex_lock(&data->lock); in srf08_trigger_handler()
193 data->scan.chan = sensor_data; in srf08_trigger_handler()
195 &data->scan, pf->timestamp); in srf08_trigger_handler()
197 mutex_unlock(&data->lock); in srf08_trigger_handler()
199 iio_trigger_notify_done(indio_dev->trig); in srf08_trigger_handler()
210 if (channel->type != IIO_DISTANCE) in srf08_read_raw()
211 return -EINVAL; in srf08_read_raw()
226 return -EINVAL; in srf08_read_raw()
245 return sprintf(buf, "%d.%03d\n", data->range_mm / 1000, in srf08_show_range_mm()
246 data->range_mm % 1000); in srf08_show_range_mm()
263 struct i2c_client *client = data->client; in srf08_write_range_mm()
267 ret = val / 43 - 1; in srf08_write_range_mm()
271 return -EINVAL; in srf08_write_range_mm()
275 mutex_lock(&data->lock); in srf08_write_range_mm()
279 dev_err(&client->dev, "write_range - err: %d\n", ret); in srf08_write_range_mm()
280 mutex_unlock(&data->lock); in srf08_write_range_mm()
284 data->range_mm = val; in srf08_write_range_mm()
286 mutex_unlock(&data->lock); in srf08_write_range_mm()
321 for (i = 0; i < data->chip_info->num_sensitivity_avail; i++) in srf08_show_sensitivity_available()
322 if (data->chip_info->sensitivity_avail[i]) in srf08_show_sensitivity_available()
324 data->chip_info->sensitivity_avail[i]); in srf08_show_sensitivity_available()
341 len = sprintf(buf, "%d\n", data->sensitivity); in srf08_show_sensitivity()
349 struct i2c_client *client = data->client; in srf08_write_sensitivity()
354 return -EINVAL; in srf08_write_sensitivity()
356 for (i = 0; i < data->chip_info->num_sensitivity_avail; i++) in srf08_write_sensitivity()
357 if (val == data->chip_info->sensitivity_avail[i]) { in srf08_write_sensitivity()
362 if (i >= data->chip_info->num_sensitivity_avail) in srf08_write_sensitivity()
363 return -EINVAL; in srf08_write_sensitivity()
365 mutex_lock(&data->lock); in srf08_write_sensitivity()
369 dev_err(&client->dev, "write_sensitivity - err: %d\n", ret); in srf08_write_sensitivity()
370 mutex_unlock(&data->lock); in srf08_write_sensitivity()
374 data->sensitivity = val; in srf08_write_sensitivity()
376 mutex_unlock(&data->lock); in srf08_write_sensitivity()
453 if (!i2c_check_functionality(client->adapter, in srf08_probe()
457 return -ENODEV; in srf08_probe()
459 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in srf08_probe()
461 return -ENOMEM; in srf08_probe()
465 data->client = client; in srf08_probe()
466 data->sensor_type = (enum srf08_sensor_type)id->driver_data; in srf08_probe()
468 switch (data->sensor_type) { in srf08_probe()
470 data->chip_info = &srf02_chip_info; in srf08_probe()
471 indio_dev->info = &srf02_info; in srf08_probe()
474 data->chip_info = &srf08_chip_info; in srf08_probe()
475 indio_dev->info = &srf08_info; in srf08_probe()
478 data->chip_info = &srf10_chip_info; in srf08_probe()
479 indio_dev->info = &srf08_info; in srf08_probe()
482 return -EINVAL; in srf08_probe()
485 indio_dev->name = id->name; in srf08_probe()
486 indio_dev->modes = INDIO_DIRECT_MODE; in srf08_probe()
487 indio_dev->channels = srf08_channels; in srf08_probe()
488 indio_dev->num_channels = ARRAY_SIZE(srf08_channels); in srf08_probe()
490 mutex_init(&data->lock); in srf08_probe()
492 ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, in srf08_probe()
495 dev_err(&client->dev, "setup of iio triggered buffer failed\n"); in srf08_probe()
499 if (data->chip_info->range_default) { in srf08_probe()
508 data->chip_info->range_default); in srf08_probe()
513 if (data->chip_info->sensitivity_default) { in srf08_probe()
522 data->chip_info->sensitivity_default); in srf08_probe()
527 return devm_iio_device_register(&client->dev, indio_dev); in srf08_probe()
557 MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>");