diff options
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/i2c-sensor-detect.c | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/drivers/i2c/i2c-sensor-detect.c b/drivers/i2c/i2c-sensor-detect.c index f99a8161a9f1..5aede3ca9cb0 100644 --- a/drivers/i2c/i2c-sensor-detect.c +++ b/drivers/i2c/i2c-sensor-detect.c | |||
@@ -25,42 +25,34 @@ | |||
25 | #include <linux/i2c-sensor.h> | 25 | #include <linux/i2c-sensor.h> |
26 | 26 | ||
27 | static unsigned short empty[] = {I2C_CLIENT_END}; | 27 | static unsigned short empty[] = {I2C_CLIENT_END}; |
28 | static unsigned int empty_isa[] = {I2C_CLIENT_ISA_END}; | ||
29 | 28 | ||
30 | /* Very inefficient for ISA detects, and won't work for 10-bit addresses! */ | 29 | /* Won't work for 10-bit addresses! */ |
31 | int i2c_detect(struct i2c_adapter *adapter, | 30 | int i2c_detect(struct i2c_adapter *adapter, |
32 | struct i2c_address_data *address_data, | 31 | struct i2c_address_data *address_data, |
33 | int (*found_proc) (struct i2c_adapter *, int, int)) | 32 | int (*found_proc) (struct i2c_adapter *, int, int)) |
34 | { | 33 | { |
35 | int addr, i, found, j, err; | 34 | int addr, i, found, j, err; |
36 | struct i2c_force_data *this_force; | 35 | struct i2c_force_data *this_force; |
37 | int is_isa = i2c_is_isa_adapter(adapter); | 36 | int adapter_id = i2c_adapter_id(adapter); |
38 | int adapter_id = | ||
39 | is_isa ? ANY_I2C_ISA_BUS : i2c_adapter_id(adapter); | ||
40 | unsigned short *normal_i2c; | 37 | unsigned short *normal_i2c; |
41 | unsigned int *normal_isa; | ||
42 | unsigned short *probe; | 38 | unsigned short *probe; |
43 | unsigned short *ignore; | 39 | unsigned short *ignore; |
44 | 40 | ||
45 | /* Forget it if we can't probe using SMBUS_QUICK */ | 41 | /* Forget it if we can't probe using SMBUS_QUICK */ |
46 | if ((!is_isa) && | 42 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) |
47 | !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) | ||
48 | return -1; | 43 | return -1; |
49 | 44 | ||
50 | /* Use default "empty" list if the adapter doesn't specify any */ | 45 | /* Use default "empty" list if the adapter doesn't specify any */ |
51 | normal_i2c = probe = ignore = empty; | 46 | normal_i2c = probe = ignore = empty; |
52 | normal_isa = empty_isa; | ||
53 | if (address_data->normal_i2c) | 47 | if (address_data->normal_i2c) |
54 | normal_i2c = address_data->normal_i2c; | 48 | normal_i2c = address_data->normal_i2c; |
55 | if (address_data->normal_isa) | ||
56 | normal_isa = address_data->normal_isa; | ||
57 | if (address_data->probe) | 49 | if (address_data->probe) |
58 | probe = address_data->probe; | 50 | probe = address_data->probe; |
59 | if (address_data->ignore) | 51 | if (address_data->ignore) |
60 | ignore = address_data->ignore; | 52 | ignore = address_data->ignore; |
61 | 53 | ||
62 | for (addr = 0x00; addr <= (is_isa ? 0xffff : 0x7f); addr++) { | 54 | for (addr = 0x00; addr <= 0x7f; addr++) { |
63 | if (!is_isa && i2c_check_addr(adapter, addr)) | 55 | if (i2c_check_addr(adapter, addr)) |
64 | continue; | 56 | continue; |
65 | 57 | ||
66 | /* If it is in one of the force entries, we don't do any | 58 | /* If it is in one of the force entries, we don't do any |
@@ -69,7 +61,7 @@ int i2c_detect(struct i2c_adapter *adapter, | |||
69 | for (i = 0; !found && (this_force = address_data->forces + i, this_force->force); i++) { | 61 | for (i = 0; !found && (this_force = address_data->forces + i, this_force->force); i++) { |
70 | for (j = 0; !found && (this_force->force[j] != I2C_CLIENT_END); j += 2) { | 62 | for (j = 0; !found && (this_force->force[j] != I2C_CLIENT_END); j += 2) { |
71 | if ( ((adapter_id == this_force->force[j]) || | 63 | if ( ((adapter_id == this_force->force[j]) || |
72 | ((this_force->force[j] == ANY_I2C_BUS) && !is_isa)) && | 64 | (this_force->force[j] == ANY_I2C_BUS)) && |
73 | (addr == this_force->force[j + 1]) ) { | 65 | (addr == this_force->force[j + 1]) ) { |
74 | dev_dbg(&adapter->dev, "found force parameter for adapter %d, addr %04x\n", adapter_id, addr); | 66 | dev_dbg(&adapter->dev, "found force parameter for adapter %d, addr %04x\n", adapter_id, addr); |
75 | if ((err = found_proc(adapter, addr, this_force->kind))) | 67 | if ((err = found_proc(adapter, addr, this_force->kind))) |
@@ -85,8 +77,7 @@ int i2c_detect(struct i2c_adapter *adapter, | |||
85 | right now */ | 77 | right now */ |
86 | for (i = 0; !found && (ignore[i] != I2C_CLIENT_END); i += 2) { | 78 | for (i = 0; !found && (ignore[i] != I2C_CLIENT_END); i += 2) { |
87 | if ( ((adapter_id == ignore[i]) || | 79 | if ( ((adapter_id == ignore[i]) || |
88 | ((ignore[i] == ANY_I2C_BUS) && | 80 | (ignore[i] == ANY_I2C_BUS)) && |
89 | !is_isa)) && | ||
90 | (addr == ignore[i + 1])) { | 81 | (addr == ignore[i + 1])) { |
91 | dev_dbg(&adapter->dev, "found ignore parameter for adapter %d, addr %04x\n", adapter_id, addr); | 82 | dev_dbg(&adapter->dev, "found ignore parameter for adapter %d, addr %04x\n", adapter_id, addr); |
92 | found = 1; | 83 | found = 1; |
@@ -97,19 +88,10 @@ int i2c_detect(struct i2c_adapter *adapter, | |||
97 | 88 | ||
98 | /* Now, we will do a detection, but only if it is in the normal or | 89 | /* Now, we will do a detection, but only if it is in the normal or |
99 | probe entries */ | 90 | probe entries */ |
100 | if (is_isa) { | 91 | for (i = 0; !found && (normal_i2c[i] != I2C_CLIENT_END); i += 1) { |
101 | for (i = 0; !found && (normal_isa[i] != I2C_CLIENT_ISA_END); i += 1) { | 92 | if (addr == normal_i2c[i]) { |
102 | if (addr == normal_isa[i]) { | 93 | found = 1; |
103 | dev_dbg(&adapter->dev, "found normal isa entry for adapter %d, addr %04x\n", adapter_id, addr); | 94 | dev_dbg(&adapter->dev, "found normal i2c entry for adapter %d, addr %02x\n", adapter_id, addr); |
104 | found = 1; | ||
105 | } | ||
106 | } | ||
107 | } else { | ||
108 | for (i = 0; !found && (normal_i2c[i] != I2C_CLIENT_END); i += 1) { | ||
109 | if (addr == normal_i2c[i]) { | ||
110 | found = 1; | ||
111 | dev_dbg(&adapter->dev, "found normal i2c entry for adapter %d, addr %02x\n", adapter_id, addr); | ||
112 | } | ||
113 | } | 95 | } |
114 | } | 96 | } |
115 | 97 | ||
@@ -117,7 +99,7 @@ int i2c_detect(struct i2c_adapter *adapter, | |||
117 | !found && (probe[i] != I2C_CLIENT_END); | 99 | !found && (probe[i] != I2C_CLIENT_END); |
118 | i += 2) { | 100 | i += 2) { |
119 | if (((adapter_id == probe[i]) || | 101 | if (((adapter_id == probe[i]) || |
120 | ((probe[i] == ANY_I2C_BUS) && !is_isa)) | 102 | (probe[i] == ANY_I2C_BUS)) |
121 | && (addr == probe[i + 1])) { | 103 | && (addr == probe[i + 1])) { |
122 | dev_dbg(&adapter->dev, "found probe parameter for adapter %d, addr %04x\n", adapter_id, addr); | 104 | dev_dbg(&adapter->dev, "found probe parameter for adapter %d, addr %04x\n", adapter_id, addr); |
123 | found = 1; | 105 | found = 1; |
@@ -128,8 +110,7 @@ int i2c_detect(struct i2c_adapter *adapter, | |||
128 | 110 | ||
129 | /* OK, so we really should examine this address. First check | 111 | /* OK, so we really should examine this address. First check |
130 | whether there is some client here at all! */ | 112 | whether there is some client here at all! */ |
131 | if (is_isa || | 113 | if (i2c_smbus_xfer(adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL) >= 0) |
132 | (i2c_smbus_xfer (adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL) >= 0)) | ||
133 | if ((err = found_proc(adapter, addr, -1))) | 114 | if ((err = found_proc(adapter, addr, -1))) |
134 | return err; | 115 | return err; |
135 | } | 116 | } |