aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Meerwald <pmeerw@pmeerw.net>2014-08-19 18:43:00 -0400
committerJonathan Cameron <jic23@kernel.org>2014-09-14 15:50:58 -0400
commit402a324e6103c234f73564a3a611766414b6325b (patch)
tree70e07d5e3409b223f97feb187720d49d8121b133
parent6377aa496a0bc40af4f66574c813bb9a807a7e3a (diff)
iio:bma180: Implement _available sysfs attribute dynamically
makes it easier to add more chip variants and removes redundancy: scales and frequencies are now stated just once Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Cc: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/iio/accel/bma180.c54
1 files changed, 43 insertions, 11 deletions
diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
index f4d280456dd7..a543cffb4ec3 100644
--- a/drivers/iio/accel/bma180.c
+++ b/drivers/iio/accel/bma180.c
@@ -85,12 +85,6 @@ struct bma180_part_info {
85#define BMA180_DEF_BW 20 85#define BMA180_DEF_BW 20
86#define BMA180_DEF_SCALE 2452 86#define BMA180_DEF_SCALE 2452
87 87
88/* Available values for sysfs */
89#define BMA180_FLP_FREQ_AVAILABLE \
90 "10 20 40 75 150 300"
91#define BMA180_SCALE_AVAILABLE \
92 "0.001275 0.001863 0.002452 0.003727 0.004903 0.009709 0.019417"
93
94struct bma180_data { 88struct bma180_data {
95 struct i2c_client *client; 89 struct i2c_client *client;
96 struct iio_trigger *trig; 90 struct iio_trigger *trig;
@@ -349,13 +343,51 @@ err:
349 dev_err(&data->client->dev, "failed to disable the chip\n"); 343 dev_err(&data->client->dev, "failed to disable the chip\n");
350} 344}
351 345
352static IIO_CONST_ATTR(in_accel_filter_low_pass_3db_frequency_available, 346static ssize_t bma180_show_avail(char *buf, const int *vals, unsigned n,
353 BMA180_FLP_FREQ_AVAILABLE); 347 bool micros)
354static IIO_CONST_ATTR(in_accel_scale_available, BMA180_SCALE_AVAILABLE); 348{
349 size_t len = 0;
350 int i;
351
352 for (i = 0; i < n; i++) {
353 if (!vals[i])
354 continue;
355 len += scnprintf(buf + len, PAGE_SIZE - len,
356 micros ? "0.%06d " : "%d ", vals[i]);
357 }
358 buf[len - 1] = '\n';
359
360 return len;
361}
362
363static ssize_t bma180_show_filter_freq_avail(struct device *dev,
364 struct device_attribute *attr, char *buf)
365{
366 struct bma180_data *data = iio_priv(dev_to_iio_dev(dev));
367
368 return bma180_show_avail(buf, data->part_info->bw_table,
369 data->part_info->num_bw, false);
370}
371
372static ssize_t bma180_show_scale_avail(struct device *dev,
373 struct device_attribute *attr, char *buf)
374{
375 struct bma180_data *data = iio_priv(dev_to_iio_dev(dev));
376
377 return bma180_show_avail(buf, data->part_info->scale_table,
378 data->part_info->num_scales, true);
379}
380
381static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available,
382 S_IRUGO, bma180_show_filter_freq_avail, NULL, 0);
383
384static IIO_DEVICE_ATTR(in_accel_scale_available,
385 S_IRUGO, bma180_show_scale_avail, NULL, 0);
355 386
356static struct attribute *bma180_attributes[] = { 387static struct attribute *bma180_attributes[] = {
357 &iio_const_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr, 388 &iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.
358 &iio_const_attr_in_accel_scale_available.dev_attr.attr, 389 dev_attr.attr,
390 &iio_dev_attr_in_accel_scale_available.dev_attr.attr,
359 NULL, 391 NULL,
360}; 392};
361 393