aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/accel
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:25:59 -0400
commitc1949ec18e50e1e23f3045a7c3836c289f553bb8 (patch)
tree459f21ec4e29262f5135bbf6b562182573f4922d /drivers/iio/accel
parent1b9030f5a0ac7c71bc733af3c9c1064204fc0258 (diff)
iio:bma180: Introduce part-specific _config() and disable() code
move part of bma180_init() to bma180_config() (split initialization and configuration code); configuration is heavily chip-specific Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Cc: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/accel')
-rw-r--r--drivers/iio/accel/bma180.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
index 5df5991294df..933645547f82 100644
--- a/drivers/iio/accel/bma180.c
+++ b/drivers/iio/accel/bma180.c
@@ -30,6 +30,8 @@ enum {
30 BMA180, 30 BMA180,
31}; 31};
32 32
33struct bma180_data;
34
33struct bma180_part_info { 35struct bma180_part_info {
34 const struct iio_chan_spec *channels; 36 const struct iio_chan_spec *channels;
35 unsigned num_channels; 37 unsigned num_channels;
@@ -37,6 +39,8 @@ struct bma180_part_info {
37 unsigned num_scales; 39 unsigned num_scales;
38 const int *bw_table; 40 const int *bw_table;
39 unsigned num_bw; 41 unsigned num_bw;
42 int (*chip_config)(struct bma180_data *data);
43 void (*chip_disable)(struct bma180_data *data);
40}; 44};
41 45
42/* Register set */ 46/* Register set */
@@ -279,21 +283,28 @@ static int bma180_chip_init(struct bma180_data *data)
279 int ret = i2c_smbus_read_byte_data(data->client, BMA180_CHIP_ID); 283 int ret = i2c_smbus_read_byte_data(data->client, BMA180_CHIP_ID);
280 284
281 if (ret < 0) 285 if (ret < 0)
282 goto err; 286 return ret;
283 if (ret != BMA180_ID_REG_VAL) { 287 if (ret != BMA180_ID_REG_VAL)
284 ret = -ENODEV; 288 return -ENODEV;
285 goto err;
286 }
287 289
288 ret = bma180_soft_reset(data); 290 ret = bma180_soft_reset(data);
289 if (ret) 291 if (ret)
290 goto err; 292 return ret;
291 /* 293 /*
292 * No serial transaction should occur within minimum 10 us 294 * No serial transaction should occur within minimum 10 us
293 * after soft_reset command 295 * after soft_reset command
294 */ 296 */
295 msleep(20); 297 msleep(20);
296 298
299 return 0;
300}
301
302static int bma180_chip_config(struct bma180_data *data)
303{
304 int ret = bma180_chip_init(data);
305
306 if (ret)
307 goto err;
297 ret = bma180_set_bits(data, BMA180_CTRL_REG0, BMA180_DIS_WAKE_UP, 1); 308 ret = bma180_set_bits(data, BMA180_CTRL_REG0, BMA180_DIS_WAKE_UP, 1);
298 if (ret) 309 if (ret)
299 goto err; 310 goto err;
@@ -319,7 +330,7 @@ static int bma180_chip_init(struct bma180_data *data)
319 return 0; 330 return 0;
320 331
321err: 332err:
322 dev_err(&data->client->dev, "failed to init the chip\n"); 333 dev_err(&data->client->dev, "failed to config the chip\n");
323 return ret; 334 return ret;
324} 335}
325 336
@@ -507,6 +518,8 @@ static const struct bma180_part_info bma180_part_info[] = {
507 bma180_channels, ARRAY_SIZE(bma180_channels), 518 bma180_channels, ARRAY_SIZE(bma180_channels),
508 bma180_scale_table, ARRAY_SIZE(bma180_scale_table), 519 bma180_scale_table, ARRAY_SIZE(bma180_scale_table),
509 bma180_bw_table, ARRAY_SIZE(bma180_bw_table), 520 bma180_bw_table, ARRAY_SIZE(bma180_bw_table),
521 bma180_chip_config,
522 bma180_chip_disable,
510 }, 523 },
511}; 524};
512 525
@@ -578,7 +591,7 @@ static int bma180_probe(struct i2c_client *client,
578 data->client = client; 591 data->client = client;
579 data->part_info = &bma180_part_info[id->driver_data]; 592 data->part_info = &bma180_part_info[id->driver_data];
580 593
581 ret = bma180_chip_init(data); 594 ret = data->part_info->chip_config(data);
582 if (ret < 0) 595 if (ret < 0)
583 goto err_chip_disable; 596 goto err_chip_disable;
584 597
@@ -640,7 +653,7 @@ err_trigger_unregister:
640err_trigger_free: 653err_trigger_free:
641 iio_trigger_free(data->trig); 654 iio_trigger_free(data->trig);
642err_chip_disable: 655err_chip_disable:
643 bma180_chip_disable(data); 656 data->part_info->chip_disable(data);
644 657
645 return ret; 658 return ret;
646} 659}
@@ -658,7 +671,7 @@ static int bma180_remove(struct i2c_client *client)
658 } 671 }
659 672
660 mutex_lock(&data->mutex); 673 mutex_lock(&data->mutex);
661 bma180_chip_disable(data); 674 data->part_info->chip_disable(data);
662 mutex_unlock(&data->mutex); 675 mutex_unlock(&data->mutex);
663 676
664 return 0; 677 return 0;