Skip to content

Commit c1949ec

Browse files
pmeerwjic23
authored andcommitted
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>
1 parent 1b9030f commit c1949ec

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

‎drivers/iio/accel/bma180.c‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ enum {
3030
BMA180,
3131
};
3232

33+
struct bma180_data;
34+
3335
struct bma180_part_info {
3436
const struct iio_chan_spec *channels;
3537
unsigned num_channels;
3638
const int *scale_table;
3739
unsigned num_scales;
3840
const int *bw_table;
3941
unsigned num_bw;
42+
int (*chip_config)(struct bma180_data *data);
43+
void (*chip_disable)(struct bma180_data *data);
4044
};
4145

4246
/* Register set */
@@ -279,21 +283,28 @@ static int bma180_chip_init(struct bma180_data *data)
279283
int ret = i2c_smbus_read_byte_data(data->client, BMA180_CHIP_ID);
280284

281285
if (ret < 0)
282-
goto err;
283-
if (ret != BMA180_ID_REG_VAL) {
284-
ret = -ENODEV;
285-
goto err;
286-
}
286+
return ret;
287+
if (ret != BMA180_ID_REG_VAL)
288+
return -ENODEV;
287289

288290
ret = bma180_soft_reset(data);
289291
if (ret)
290-
goto err;
292+
return ret;
291293
/*
292294
* No serial transaction should occur within minimum 10 us
293295
* after soft_reset command
294296
*/
295297
msleep(20);
296298

299+
return 0;
300+
}
301+
302+
static int bma180_chip_config(struct bma180_data *data)
303+
{
304+
int ret = bma180_chip_init(data);
305+
306+
if (ret)
307+
goto err;
297308
ret = bma180_set_bits(data, BMA180_CTRL_REG0, BMA180_DIS_WAKE_UP, 1);
298309
if (ret)
299310
goto err;
@@ -319,7 +330,7 @@ static int bma180_chip_init(struct bma180_data *data)
319330
return 0;
320331

321332
err:
322-
dev_err(&data->client->dev, "failed to init the chip\n");
333+
dev_err(&data->client->dev, "failed to config the chip\n");
323334
return ret;
324335
}
325336

@@ -507,6 +518,8 @@ static const struct bma180_part_info bma180_part_info[] = {
507518
bma180_channels, ARRAY_SIZE(bma180_channels),
508519
bma180_scale_table, ARRAY_SIZE(bma180_scale_table),
509520
bma180_bw_table, ARRAY_SIZE(bma180_bw_table),
521+
bma180_chip_config,
522+
bma180_chip_disable,
510523
},
511524
};
512525

@@ -578,7 +591,7 @@ static int bma180_probe(struct i2c_client *client,
578591
data->client = client;
579592
data->part_info = &bma180_part_info[id->driver_data];
580593

581-
ret = bma180_chip_init(data);
594+
ret = data->part_info->chip_config(data);
582595
if (ret < 0)
583596
goto err_chip_disable;
584597

@@ -640,7 +653,7 @@ static int bma180_probe(struct i2c_client *client,
640653
err_trigger_free:
641654
iio_trigger_free(data->trig);
642655
err_chip_disable:
643-
bma180_chip_disable(data);
656+
data->part_info->chip_disable(data);
644657

645658
return ret;
646659
}
@@ -658,7 +671,7 @@ static int bma180_remove(struct i2c_client *client)
658671
}
659672

660673
mutex_lock(&data->mutex);
661-
bma180_chip_disable(data);
674+
data->part_info->chip_disable(data);
662675
mutex_unlock(&data->mutex);
663676

664677
return 0;

0 commit comments

Comments
 (0)