Commit dc2696ba authored by Andreas Klinger's avatar Andreas Klinger Committed by Jonathan Cameron

iio: srf08: add support for srf02 in i2c mode

srf02 added with support for i2c interface

Attributes for setting max range or sensitivity are omitted for the case of
srf02 type sensor, because they are not supported by the hardware.
Signed-off-by: default avatarAndreas Klinger <ak@it-klinger.de>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent c5bf4a04
...@@ -57,12 +57,12 @@ config SX9500 ...@@ -57,12 +57,12 @@ config SX9500
module will be called sx9500. module will be called sx9500.
config SRF08 config SRF08
tristate "Devantech SRF08/SRF10 ultrasonic ranger sensor" tristate "Devantech SRF02/SRF08/SRF10 ultrasonic ranger sensor"
depends on I2C depends on I2C
help help
Say Y here to build a driver for Devantech SRF08/SRF10 ultrasonic Say Y here to build a driver for Devantech SRF02/SRF08/SRF10
ranger sensor. This driver can be used to measure the distance ultrasonic ranger sensors with i2c interface.
of objects. This driver can be used to measure the distance of objects.
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called srf08. module will be called srf08.
......
/* /*
* srf08.c - Support for Devantech SRFxx ultrasonic ranger * srf08.c - Support for Devantech SRFxx ultrasonic ranger
* with i2c interface * with i2c interface
* actually supported are srf08, srf10 * actually supported are srf02, srf08, srf10
* *
* Copyright (c) 2016 Andreas Klinger <ak@it-klinger.de> * Copyright (c) 2016, 2017 Andreas Klinger <ak@it-klinger.de>
* *
* This file is subject to the terms and conditions of version 2 of * This file is subject to the terms and conditions of version 2 of
* the GNU General Public License. See the file COPYING in the main * the GNU General Public License. See the file COPYING in the main
* directory of this archive for more details. * directory of this archive for more details.
* *
* For details about the device see: * For details about the device see:
* http://www.robot-electronics.co.uk/htm/srf08tech.html * http://www.robot-electronics.co.uk/htm/srf08tech.html
* http://www.robot-electronics.co.uk/htm/srf10tech.htm * http://www.robot-electronics.co.uk/htm/srf10tech.htm
* http://www.robot-electronics.co.uk/htm/srf02tech.htm
*/ */
#include <linux/err.h> #include <linux/err.h>
...@@ -36,9 +37,8 @@ ...@@ -36,9 +37,8 @@
#define SRF08_CMD_RANGING_CM 0x51 /* Ranging Mode - Result in cm */ #define SRF08_CMD_RANGING_CM 0x51 /* Ranging Mode - Result in cm */
#define SRF08_DEFAULT_RANGE 6020 /* default value of Range in mm */
enum srf08_sensor_type { enum srf08_sensor_type {
SRF02,
SRF08, SRF08,
SRF10, SRF10,
SRF_MAX_TYPE SRF_MAX_TYPE
...@@ -48,6 +48,9 @@ struct srf08_chip_info { ...@@ -48,6 +48,9 @@ struct srf08_chip_info {
const int *sensitivity_avail; const int *sensitivity_avail;
int num_sensitivity_avail; int num_sensitivity_avail;
int sensitivity_default; int sensitivity_default;
/* default value of Range in mm */
int range_default;
}; };
struct srf08_data { struct srf08_data {
...@@ -83,6 +86,14 @@ struct srf08_data { ...@@ -83,6 +86,14 @@ struct srf08_data {
* But with ADC's this term is already used differently and that's why it * But with ADC's this term is already used differently and that's why it
* is called "Sensitivity" here. * is called "Sensitivity" here.
*/ */
static const struct srf08_chip_info srf02_chip_info = {
.sensitivity_avail = NULL,
.num_sensitivity_avail = 0,
.sensitivity_default = 0,
.range_default = 0,
};
static const int srf08_sensitivity_avail[] = { static const int srf08_sensitivity_avail[] = {
94, 97, 100, 103, 107, 110, 114, 118, 94, 97, 100, 103, 107, 110, 114, 118,
123, 128, 133, 139, 145, 152, 159, 168, 123, 128, 133, 139, 145, 152, 159, 168,
...@@ -94,6 +105,8 @@ static const struct srf08_chip_info srf08_chip_info = { ...@@ -94,6 +105,8 @@ static const struct srf08_chip_info srf08_chip_info = {
.sensitivity_avail = srf08_sensitivity_avail, .sensitivity_avail = srf08_sensitivity_avail,
.num_sensitivity_avail = ARRAY_SIZE(srf08_sensitivity_avail), .num_sensitivity_avail = ARRAY_SIZE(srf08_sensitivity_avail),
.sensitivity_default = 1025, .sensitivity_default = 1025,
.range_default = 6020,
}; };
static const int srf10_sensitivity_avail[] = { static const int srf10_sensitivity_avail[] = {
...@@ -106,6 +119,8 @@ static const struct srf08_chip_info srf10_chip_info = { ...@@ -106,6 +119,8 @@ static const struct srf08_chip_info srf10_chip_info = {
.sensitivity_avail = srf10_sensitivity_avail, .sensitivity_avail = srf10_sensitivity_avail,
.num_sensitivity_avail = ARRAY_SIZE(srf10_sensitivity_avail), .num_sensitivity_avail = ARRAY_SIZE(srf10_sensitivity_avail),
.sensitivity_default = 700, .sensitivity_default = 700,
.range_default = 6020,
}; };
static int srf08_read_ranging(struct srf08_data *data) static int srf08_read_ranging(struct srf08_data *data)
...@@ -424,6 +439,15 @@ static const struct iio_info srf08_info = { ...@@ -424,6 +439,15 @@ static const struct iio_info srf08_info = {
.driver_module = THIS_MODULE, .driver_module = THIS_MODULE,
}; };
/*
* srf02 don't have an adjustable range or sensitivity,
* so we don't need attributes at all
*/
static const struct iio_info srf02_info = {
.read_raw = srf08_read_raw,
.driver_module = THIS_MODULE,
};
static int srf08_probe(struct i2c_client *client, static int srf08_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
...@@ -447,11 +471,17 @@ static int srf08_probe(struct i2c_client *client, ...@@ -447,11 +471,17 @@ static int srf08_probe(struct i2c_client *client,
data->sensor_type = (enum srf08_sensor_type)id->driver_data; data->sensor_type = (enum srf08_sensor_type)id->driver_data;
switch (data->sensor_type) { switch (data->sensor_type) {
case SRF02:
data->chip_info = &srf02_chip_info;
indio_dev->info = &srf02_info;
break;
case SRF08: case SRF08:
data->chip_info = &srf08_chip_info; data->chip_info = &srf08_chip_info;
indio_dev->info = &srf08_info;
break; break;
case SRF10: case SRF10:
data->chip_info = &srf10_chip_info; data->chip_info = &srf10_chip_info;
indio_dev->info = &srf08_info;
break; break;
default: default:
return -EINVAL; return -EINVAL;
...@@ -460,7 +490,6 @@ static int srf08_probe(struct i2c_client *client, ...@@ -460,7 +490,6 @@ static int srf08_probe(struct i2c_client *client,
indio_dev->name = id->name; indio_dev->name = id->name;
indio_dev->dev.parent = &client->dev; indio_dev->dev.parent = &client->dev;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = &srf08_info;
indio_dev->channels = srf08_channels; indio_dev->channels = srf08_channels;
indio_dev->num_channels = ARRAY_SIZE(srf08_channels); indio_dev->num_channels = ARRAY_SIZE(srf08_channels);
...@@ -473,24 +502,39 @@ static int srf08_probe(struct i2c_client *client, ...@@ -473,24 +502,39 @@ static int srf08_probe(struct i2c_client *client,
return ret; return ret;
} }
/* if (data->chip_info->range_default) {
* set default values of device here /*
* these register values cannot be read from the hardware * set default range of device in mm here
* therefore set driver specific default values * these register values cannot be read from the hardware
*/ * therefore set driver specific default values
ret = srf08_write_range_mm(data, SRF08_DEFAULT_RANGE); *
if (ret < 0) * srf02 don't have a default value so it'll be omitted
return ret; */
ret = srf08_write_range_mm(data,
data->chip_info->range_default);
if (ret < 0)
return ret;
}
ret = srf08_write_sensitivity(data, if (data->chip_info->sensitivity_default) {
/*
* set default sensitivity of device here
* these register values cannot be read from the hardware
* therefore set driver specific default values
*
* srf02 don't have a default value so it'll be omitted
*/
ret = srf08_write_sensitivity(data,
data->chip_info->sensitivity_default); data->chip_info->sensitivity_default);
if (ret < 0) if (ret < 0)
return ret; return ret;
}
return devm_iio_device_register(&client->dev, indio_dev); return devm_iio_device_register(&client->dev, indio_dev);
} }
static const struct of_device_id of_srf08_match[] = { static const struct of_device_id of_srf08_match[] = {
{ .compatible = "devantech,srf02", (void *)SRF02},
{ .compatible = "devantech,srf08", (void *)SRF08}, { .compatible = "devantech,srf08", (void *)SRF08},
{ .compatible = "devantech,srf10", (void *)SRF10}, { .compatible = "devantech,srf10", (void *)SRF10},
{}, {},
...@@ -499,6 +543,7 @@ static const struct of_device_id of_srf08_match[] = { ...@@ -499,6 +543,7 @@ static const struct of_device_id of_srf08_match[] = {
MODULE_DEVICE_TABLE(of, of_srf08_match); MODULE_DEVICE_TABLE(of, of_srf08_match);
static const struct i2c_device_id srf08_id[] = { static const struct i2c_device_id srf08_id[] = {
{ "srf02", SRF02 },
{ "srf08", SRF08 }, { "srf08", SRF08 },
{ "srf10", SRF10 }, { "srf10", SRF10 },
{ } { }
...@@ -516,5 +561,5 @@ static struct i2c_driver srf08_driver = { ...@@ -516,5 +561,5 @@ static struct i2c_driver srf08_driver = {
module_i2c_driver(srf08_driver); module_i2c_driver(srf08_driver);
MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>"); MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>");
MODULE_DESCRIPTION("Devantech SRF08/SRF10 ultrasonic ranger driver"); MODULE_DESCRIPTION("Devantech SRF02/SRF08/SRF10 i2c ultrasonic ranger driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment