Skip to content

Commit 71222bf

Browse files
gwendalcrjic23
authored andcommitted
iio: ak8975: minor fixes
Fixes code duplication, return of function. Check client->irq properly when setting up optional irq handler. Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Hartmut Knaack <knaack.h@gmx.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 56ae98a commit 71222bf

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

drivers/iio/magnetometer/ak8975.c

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@
6464
#define AK8975_REG_CNTL 0x0A
6565
#define AK8975_REG_CNTL_MODE_SHIFT 0
6666
#define AK8975_REG_CNTL_MODE_MASK (0xF << AK8975_REG_CNTL_MODE_SHIFT)
67-
#define AK8975_REG_CNTL_MODE_POWER_DOWN 0
68-
#define AK8975_REG_CNTL_MODE_ONCE 1
69-
#define AK8975_REG_CNTL_MODE_SELF_TEST 8
70-
#define AK8975_REG_CNTL_MODE_FUSE_ROM 0xF
67+
#define AK8975_REG_CNTL_MODE_POWER_DOWN 0x00
68+
#define AK8975_REG_CNTL_MODE_ONCE 0x01
69+
#define AK8975_REG_CNTL_MODE_SELF_TEST 0x08
70+
#define AK8975_REG_CNTL_MODE_FUSE_ROM 0x0F
7171

7272
#define AK8975_REG_RSVC 0x0B
7373
#define AK8975_REG_ASTC 0x0C
@@ -166,8 +166,8 @@ static int ak8975_setup_irq(struct ak8975_data *data)
166166
irq = gpio_to_irq(data->eoc_gpio);
167167

168168
rc = devm_request_irq(&client->dev, irq, ak8975_irq_handler,
169-
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
170-
dev_name(&client->dev), data);
169+
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
170+
dev_name(&client->dev), data);
171171
if (rc < 0) {
172172
dev_err(&client->dev,
173173
"irq %d request failed, (gpio %d): %d\n",
@@ -231,8 +231,12 @@ static int ak8975_setup(struct i2c_client *client)
231231
AK8975_REG_CNTL_MODE_POWER_DOWN,
232232
AK8975_REG_CNTL_MODE_MASK,
233233
AK8975_REG_CNTL_MODE_SHIFT);
234+
if (ret < 0) {
235+
dev_err(&client->dev, "Error in setting power-down mode\n");
236+
return ret;
237+
}
234238

235-
if (data->eoc_gpio > 0 || client->irq) {
239+
if (data->eoc_gpio > 0 || client->irq > 0) {
236240
ret = ak8975_setup_irq(data);
237241
if (ret < 0) {
238242
dev_err(&client->dev,
@@ -241,11 +245,6 @@ static int ak8975_setup(struct i2c_client *client)
241245
}
242246
}
243247

244-
if (ret < 0) {
245-
dev_err(&client->dev, "Error in setting power-down mode\n");
246-
return ret;
247-
}
248-
249248
/*
250249
* Precalculate scale factor (in Gauss units) for each axis and
251250
* store in the device data.
@@ -550,24 +549,18 @@ static int ak8975_probe(struct i2c_client *client,
550549
/* Perform some basic start-of-day setup of the device. */
551550
err = ak8975_setup(client);
552551
if (err < 0) {
553-
dev_err(&client->dev, "AK8975 initialization fails\n");
552+
dev_err(&client->dev, "%s initialization fails\n", name);
554553
return err;
555554
}
556555

557-
data->client = client;
558556
mutex_init(&data->lock);
559-
data->eoc_gpio = eoc_gpio;
560557
indio_dev->dev.parent = &client->dev;
561558
indio_dev->channels = ak8975_channels;
562559
indio_dev->num_channels = ARRAY_SIZE(ak8975_channels);
563560
indio_dev->info = &ak8975_info;
564561
indio_dev->modes = INDIO_DIRECT_MODE;
565562
indio_dev->name = name;
566-
err = devm_iio_device_register(&client->dev, indio_dev);
567-
if (err < 0)
568-
return err;
569-
570-
return 0;
563+
return devm_iio_device_register(&client->dev, indio_dev);
571564
}
572565

573566
static const struct i2c_device_id ak8975_id[] = {
@@ -588,7 +581,7 @@ MODULE_DEVICE_TABLE(of, ak8975_of_match);
588581
static struct i2c_driver ak8975_driver = {
589582
.driver = {
590583
.name = "ak8975",
591-
.of_match_table = ak8975_of_match,
584+
.of_match_table = of_match_ptr(ak8975_of_match),
592585
.acpi_match_table = ACPI_PTR(ak_acpi_match),
593586
},
594587
.probe = ak8975_probe,

0 commit comments

Comments
 (0)