Commit 7e263cea88995d0b4b9fb659a95c382128feca71
Committed by
Kumar Gala
1 parent
b9b1bc8542
Exists in
master
and in
54 other branches
post/i2c: Clean up detection logic
The logic previously used in the I2C post was a bit convoluted. Signed-off-by: Peter Tyser <ptyser@xes-inc.com> Acked-by: Heiko Schocher <hs@denx.de> Acked-by: Wolfgang Denk <wd@denx.de> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Showing 1 changed file with 13 additions and 16 deletions Side-by-side Diff
post/drivers/i2c.c
... | ... | @@ -51,38 +51,35 @@ |
51 | 51 | /* No devices found */ |
52 | 52 | return -1; |
53 | 53 | #else |
54 | - unsigned int good = 0; | |
55 | - unsigned int bad = 0; | |
54 | + unsigned int ret = 0; | |
56 | 55 | int j; |
57 | - unsigned char i2c_addr_list[] = I2C_ADDR_LIST; | |
58 | - unsigned char i2c_miss_list[] = I2C_ADDR_LIST; | |
56 | + const unsigned char i2c_addr_list[] = I2C_ADDR_LIST; | |
59 | 57 | |
60 | 58 | for (i = 0; i < 128; i++) { |
61 | 59 | if (i2c_probe(i) != 0) |
62 | 60 | continue; |
61 | + | |
63 | 62 | for (j = 0; j < sizeof(i2c_addr_list); ++j) { |
64 | 63 | if (i == i2c_addr_list[j]) { |
65 | - good++; | |
66 | - i2c_miss_list[j] = 0xFF; | |
64 | + i2c_addr_list[j] = 0xff; | |
67 | 65 | break; |
68 | 66 | } |
69 | 67 | } |
70 | 68 | |
71 | 69 | if (j == sizeof(i2c_addr_list)) { |
72 | - bad++; | |
73 | - post_log("I2C: addr %02X not expected\n", i); | |
70 | + ret = -1; | |
71 | + post_log("I2C: addr %02x not expected\n", i); | |
74 | 72 | } |
75 | 73 | } |
76 | 74 | |
77 | - if (good != sizeof(i2c_addr_list)) { | |
78 | - for (j = 0; j < sizeof(i2c_miss_list); ++j) { | |
79 | - if (i2c_miss_list[j] != 0xFF) { | |
80 | - post_log("I2C: addr %02X did not respond\n", | |
81 | - i2c_miss_list[j]); | |
82 | - } | |
83 | - } | |
75 | + for (i = 0; i < sizeof(i2c_addr_list); ++i) { | |
76 | + if (i2c_addr_list[i] == 0xff) | |
77 | + continue; | |
78 | + post_log("I2C: addr %02x did not respond\n", i2c_addr_list[i]); | |
79 | + ret = -1; | |
84 | 80 | } |
85 | - return ((good == sizeof(i2c_addr_list)) && (bad == 0)) ? 0 : -1; | |
81 | + | |
82 | + return ret; | |
86 | 83 | #endif |
87 | 84 | } |
88 | 85 |