diff options
Diffstat (limited to 'drivers/i2c/algos/i2c-algo-bit.c')
-rw-r--r-- | drivers/i2c/algos/i2c-algo-bit.c | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index a39e6cff86e7..d6d58684712b 100644 --- a/drivers/i2c/algos/i2c-algo-bit.c +++ b/drivers/i2c/algos/i2c-algo-bit.c | |||
@@ -232,9 +232,17 @@ static int i2c_inb(struct i2c_adapter *i2c_adap) | |||
232 | * Sanity check for the adapter hardware - check the reaction of | 232 | * Sanity check for the adapter hardware - check the reaction of |
233 | * the bus lines only if it seems to be idle. | 233 | * the bus lines only if it seems to be idle. |
234 | */ | 234 | */ |
235 | static int test_bus(struct i2c_algo_bit_data *adap, char *name) | 235 | static int test_bus(struct i2c_adapter *i2c_adap) |
236 | { | 236 | { |
237 | int scl, sda; | 237 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; |
238 | const char *name = i2c_adap->name; | ||
239 | int scl, sda, ret; | ||
240 | |||
241 | if (adap->pre_xfer) { | ||
242 | ret = adap->pre_xfer(i2c_adap); | ||
243 | if (ret < 0) | ||
244 | return -ENODEV; | ||
245 | } | ||
238 | 246 | ||
239 | if (adap->getscl == NULL) | 247 | if (adap->getscl == NULL) |
240 | pr_info("%s: Testing SDA only, SCL is not readable\n", name); | 248 | pr_info("%s: Testing SDA only, SCL is not readable\n", name); |
@@ -297,11 +305,19 @@ static int test_bus(struct i2c_algo_bit_data *adap, char *name) | |||
297 | "while pulling SCL high!\n", name); | 305 | "while pulling SCL high!\n", name); |
298 | goto bailout; | 306 | goto bailout; |
299 | } | 307 | } |
308 | |||
309 | if (adap->post_xfer) | ||
310 | adap->post_xfer(i2c_adap); | ||
311 | |||
300 | pr_info("%s: Test OK\n", name); | 312 | pr_info("%s: Test OK\n", name); |
301 | return 0; | 313 | return 0; |
302 | bailout: | 314 | bailout: |
303 | sdahi(adap); | 315 | sdahi(adap); |
304 | sclhi(adap); | 316 | sclhi(adap); |
317 | |||
318 | if (adap->post_xfer) | ||
319 | adap->post_xfer(i2c_adap); | ||
320 | |||
305 | return -ENODEV; | 321 | return -ENODEV; |
306 | } | 322 | } |
307 | 323 | ||
@@ -600,12 +616,14 @@ static const struct i2c_algorithm i2c_bit_algo = { | |||
600 | /* | 616 | /* |
601 | * registering functions to load algorithms at runtime | 617 | * registering functions to load algorithms at runtime |
602 | */ | 618 | */ |
603 | static int i2c_bit_prepare_bus(struct i2c_adapter *adap) | 619 | static int __i2c_bit_add_bus(struct i2c_adapter *adap, |
620 | int (*add_adapter)(struct i2c_adapter *)) | ||
604 | { | 621 | { |
605 | struct i2c_algo_bit_data *bit_adap = adap->algo_data; | 622 | struct i2c_algo_bit_data *bit_adap = adap->algo_data; |
623 | int ret; | ||
606 | 624 | ||
607 | if (bit_test) { | 625 | if (bit_test) { |
608 | int ret = test_bus(bit_adap, adap->name); | 626 | ret = test_bus(adap); |
609 | if (ret < 0) | 627 | if (ret < 0) |
610 | return -ENODEV; | 628 | return -ENODEV; |
611 | } | 629 | } |
@@ -614,30 +632,27 @@ static int i2c_bit_prepare_bus(struct i2c_adapter *adap) | |||
614 | adap->algo = &i2c_bit_algo; | 632 | adap->algo = &i2c_bit_algo; |
615 | adap->retries = 3; | 633 | adap->retries = 3; |
616 | 634 | ||
635 | ret = add_adapter(adap); | ||
636 | if (ret < 0) | ||
637 | return ret; | ||
638 | |||
639 | /* Complain if SCL can't be read */ | ||
640 | if (bit_adap->getscl == NULL) { | ||
641 | dev_warn(&adap->dev, "Not I2C compliant: can't read SCL\n"); | ||
642 | dev_warn(&adap->dev, "Bus may be unreliable\n"); | ||
643 | } | ||
617 | return 0; | 644 | return 0; |
618 | } | 645 | } |
619 | 646 | ||
620 | int i2c_bit_add_bus(struct i2c_adapter *adap) | 647 | int i2c_bit_add_bus(struct i2c_adapter *adap) |
621 | { | 648 | { |
622 | int err; | 649 | return __i2c_bit_add_bus(adap, i2c_add_adapter); |
623 | |||
624 | err = i2c_bit_prepare_bus(adap); | ||
625 | if (err) | ||
626 | return err; | ||
627 | |||
628 | return i2c_add_adapter(adap); | ||
629 | } | 650 | } |
630 | EXPORT_SYMBOL(i2c_bit_add_bus); | 651 | EXPORT_SYMBOL(i2c_bit_add_bus); |
631 | 652 | ||
632 | int i2c_bit_add_numbered_bus(struct i2c_adapter *adap) | 653 | int i2c_bit_add_numbered_bus(struct i2c_adapter *adap) |
633 | { | 654 | { |
634 | int err; | 655 | return __i2c_bit_add_bus(adap, i2c_add_numbered_adapter); |
635 | |||
636 | err = i2c_bit_prepare_bus(adap); | ||
637 | if (err) | ||
638 | return err; | ||
639 | |||
640 | return i2c_add_numbered_adapter(adap); | ||
641 | } | 656 | } |
642 | EXPORT_SYMBOL(i2c_bit_add_numbered_bus); | 657 | EXPORT_SYMBOL(i2c_bit_add_numbered_bus); |
643 | 658 | ||