aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfram Sang <wsa@the-dreams.de>2016-07-18 23:54:56 -0400
committerWolfram Sang <wsa@the-dreams.de>2016-07-18 23:57:23 -0400
commit38d0fc4662474c6219166505d0a68b45a583fcfb (patch)
treefb014e8392c9b575e4bd656c36e603dd144d0ab1
parentd380a20486b84895223d17a31d811a1195f6c50d (diff)
Revert "i2c: core: Add function for finding the bus speed from ACPI"
This reverts commit 55d38d060e999ca1a3ea6eb132105a0301e4cd04. There were too heavy merge conflicts and the driver code making use of this was not ready yet anyhow. So, we wait one cycle. Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r--drivers/i2c/i2c-core.c74
-rw-r--r--include/linux/i2c.h9
2 files changed, 15 insertions, 68 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 347494a8750e..abe41369eec1 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -105,13 +105,11 @@ struct gsb_buffer {
105 105
106struct i2c_acpi_lookup { 106struct i2c_acpi_lookup {
107 struct i2c_board_info *info; 107 struct i2c_board_info *info;
108 struct i2c_adapter *adapter; /* set only when registering slaves */
109 acpi_handle adapter_handle; 108 acpi_handle adapter_handle;
110 acpi_handle device_handle; 109 acpi_handle device_handle;
111 u32 min_speed;
112}; 110};
113 111
114static int i2c_acpi_find_resource(struct acpi_resource *ares, void *data) 112static int i2c_acpi_find_address(struct acpi_resource *ares, void *data)
115{ 113{
116 struct i2c_acpi_lookup *lookup = data; 114 struct i2c_acpi_lookup *lookup = data;
117 struct i2c_board_info *info = lookup->info; 115 struct i2c_board_info *info = lookup->info;
@@ -137,20 +135,17 @@ static int i2c_acpi_find_resource(struct acpi_resource *ares, void *data)
137 info->addr = sb->slave_address; 135 info->addr = sb->slave_address;
138 if (sb->access_mode == ACPI_I2C_10BIT_MODE) 136 if (sb->access_mode == ACPI_I2C_10BIT_MODE)
139 info->flags |= I2C_CLIENT_TEN; 137 info->flags |= I2C_CLIENT_TEN;
140 /* Save speed of the slowest device */
141 if (sb->connection_speed < lookup->min_speed)
142 lookup->min_speed = sb->connection_speed;
143 } 138 }
144 139
145 return 1; 140 return 1;
146} 141}
147 142
148static acpi_status i2c_acpi_slave_lookup(acpi_handle handle, u32 level, 143static acpi_status i2c_acpi_add_device(acpi_handle handle, u32 level,
149 void *data, void **return_value) 144 void *data, void **return_value)
150{ 145{
151 struct i2c_acpi_lookup *lookup = data; 146 struct i2c_adapter *adapter = data;
152 struct i2c_adapter *adapter = lookup->adapter;
153 struct list_head resource_list; 147 struct list_head resource_list;
148 struct i2c_acpi_lookup lookup;
154 struct resource_entry *entry; 149 struct resource_entry *entry;
155 struct i2c_board_info info; 150 struct i2c_board_info info;
156 struct acpi_device *adev; 151 struct acpi_device *adev;
@@ -164,8 +159,10 @@ static acpi_status i2c_acpi_slave_lookup(acpi_handle handle, u32 level,
164 memset(&info, 0, sizeof(info)); 159 memset(&info, 0, sizeof(info));
165 info.fwnode = acpi_fwnode_handle(adev); 160 info.fwnode = acpi_fwnode_handle(adev);
166 161
167 lookup->device_handle = handle; 162 memset(&lookup, 0, sizeof(lookup));
168 lookup->info = &info; 163 lookup.adapter_handle = ACPI_HANDLE(&adapter->dev);
164 lookup.device_handle = handle;
165 lookup.info = &info;
169 166
170 /* 167 /*
171 * Look up for I2cSerialBus resource with ResourceSource that 168 * Look up for I2cSerialBus resource with ResourceSource that
@@ -173,10 +170,10 @@ static acpi_status i2c_acpi_slave_lookup(acpi_handle handle, u32 level,
173 */ 170 */
174 INIT_LIST_HEAD(&resource_list); 171 INIT_LIST_HEAD(&resource_list);
175 ret = acpi_dev_get_resources(adev, &resource_list, 172 ret = acpi_dev_get_resources(adev, &resource_list,
176 i2c_acpi_find_resource, lookup); 173 i2c_acpi_find_address, &lookup);
177 acpi_dev_free_resource_list(&resource_list); 174 acpi_dev_free_resource_list(&resource_list);
178 175
179 if (ret < 0 || !info.addr || !lookup->adapter) 176 if (ret < 0 || !info.addr)
180 return AE_OK; 177 return AE_OK;
181 178
182 /* Then fill IRQ number if any */ 179 /* Then fill IRQ number if any */
@@ -207,14 +204,6 @@ static acpi_status i2c_acpi_slave_lookup(acpi_handle handle, u32 level,
207 204
208#define I2C_ACPI_MAX_SCAN_DEPTH 32 205#define I2C_ACPI_MAX_SCAN_DEPTH 32
209 206
210static acpi_status i2c_acpi_walk(struct i2c_acpi_lookup *lookup)
211{
212 return acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
213 I2C_ACPI_MAX_SCAN_DEPTH,
214 i2c_acpi_slave_lookup, NULL,
215 lookup, NULL);
216}
217
218/** 207/**
219 * i2c_acpi_register_devices - enumerate I2C slave devices behind adapter 208 * i2c_acpi_register_devices - enumerate I2C slave devices behind adapter
220 * @adap: pointer to adapter 209 * @adap: pointer to adapter
@@ -225,52 +214,19 @@ static acpi_status i2c_acpi_walk(struct i2c_acpi_lookup *lookup)
225 */ 214 */
226static void i2c_acpi_register_devices(struct i2c_adapter *adap) 215static void i2c_acpi_register_devices(struct i2c_adapter *adap)
227{ 216{
228 struct i2c_acpi_lookup lookup;
229 acpi_status status; 217 acpi_status status;
230 218
231 if (!has_acpi_companion(&adap->dev)) 219 if (!has_acpi_companion(&adap->dev))
232 return; 220 return;
233 221
234 memset(&lookup, 0, sizeof(lookup)); 222 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
235 lookup.adapter = adap; 223 I2C_ACPI_MAX_SCAN_DEPTH,
236 lookup.adapter_handle = ACPI_HANDLE(&adap->dev); 224 i2c_acpi_add_device, NULL,
237 225 adap, NULL);
238 status = i2c_acpi_walk(&lookup);
239 if (ACPI_FAILURE(status)) 226 if (ACPI_FAILURE(status))
240 dev_warn(&adap->dev, "failed to enumerate I2C slaves\n"); 227 dev_warn(&adap->dev, "failed to enumerate I2C slaves\n");
241} 228}
242 229
243/**
244 * i2c_acpi_find_bus_speed - find I2C bus speed from ACPI
245 * @dev: The device owning the bus
246 *
247 * Find the I2C bus speed by walking the ACPI namespace for all I2C slaves
248 * devices connected to this bus and use the speed of slowest device.
249 *
250 * Returns the speed in Hz or zero
251 */
252u32 i2c_acpi_find_bus_speed(struct device *dev)
253{
254 struct i2c_acpi_lookup lookup;
255 acpi_status status;
256
257 if (!has_acpi_companion(dev))
258 return 0;
259
260 memset(&lookup, 0, sizeof(lookup));
261 lookup.adapter_handle = ACPI_HANDLE(dev);
262 lookup.min_speed = UINT_MAX;
263
264 status = i2c_acpi_walk(&lookup);
265 if (ACPI_FAILURE(status)) {
266 dev_warn(dev, "unable to find I2C bus speed from ACPI\n");
267 return 0;
268 }
269
270 return lookup.min_speed != UINT_MAX ? lookup.min_speed : 0;
271}
272EXPORT_SYMBOL_GPL(i2c_acpi_find_bus_speed);
273
274#else /* CONFIG_ACPI */ 230#else /* CONFIG_ACPI */
275static inline void i2c_acpi_register_devices(struct i2c_adapter *adap) { } 231static inline void i2c_acpi_register_devices(struct i2c_adapter *adap) { }
276#endif /* CONFIG_ACPI */ 232#endif /* CONFIG_ACPI */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 5cde08719fb6..fffdc270ca18 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -766,13 +766,4 @@ static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node
766} 766}
767#endif /* CONFIG_OF */ 767#endif /* CONFIG_OF */
768 768
769#if IS_ENABLED(CONFIG_ACPI)
770u32 i2c_acpi_find_bus_speed(struct device *dev);
771#else
772static inline u32 i2c_acpi_find_bus_speed(struct device *dev)
773{
774 return 0;
775}
776#endif /* CONFIG_ACPI */
777
778#endif /* _LINUX_I2C_H */ 769#endif /* _LINUX_I2C_H */