aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-core.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-06-25 21:42:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-06-25 21:42:39 -0400
commit24867481b8c0a3bc3ab53b634e3cc03680ac3ac6 (patch)
tree87a0f018c5e0fb61275b5a48977108ad1a33aa8b /drivers/i2c/i2c-core.c
parent9390bd0d14b4585f7ac2df15ff5f52af182251e1 (diff)
parenta294aba164389a3d2c40dfcf5f3989a3bbfe38a2 (diff)
Merge branch 'i2c/for-4.2' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c updates from Wolfram Sang: "Highlights: - new drivers for Mediatek I2C, APM X-Gene, Broadcom Settop - major updates to at91, davinci - bugfixes to the mux infrastructure when dealing with the new quirk mechanism - more users for the bus recovery feature - further improvements to the slave framework Plus the usual bunch of smaller driver and core improvements and fixes. There is one patch removing old code from an ARM platform. This has been acked by the sh_mobile maintainer Simon Horman" * 'i2c/for-4.2' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (48 commits) i2c: busses: i2c-bcm2835: limits cdiv to allowed values i2c: sh_mobile: use proper type for timeout i2c: sh_mobile: use adapter default for timeout i2c: rcar: use proper type for timeout i2c: rcar: use adapter default for timeout i2c: designware: Make sure the device is suspended before disabling runtime PM i2c: tegra: apply size limit quirk i2c: tegra: don't advertise SMBUS_QUICK i2c: octeon: remove unused signal handling i2c: davinci: Optimize SCL generation i2c: mux: pca954x: Use __i2c_transfer because of quirks i2c: mux: Use __i2c_transfer() instead of calling parent's master_xfer() i2c: use parent adapter quirks in mux i2c: bcm2835: clear reserved bits in S-Register ARM: shmobile: r8a7740: remove I2C errata handling i2c: sh_mobile: add errata workaround i2c: at91: fix code checker warnings i2c: busses: xgene-slimpro: fix incorrect __init declation for probe i2c: davinci: Avoid sending to own address i2c: davinci: Refactor i2c_davinci_wait_bus_not_busy() ...
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r--drivers/i2c/i2c-core.c63
1 files changed, 40 insertions, 23 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index fc2ee8213fb6..069a41f116dd 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -257,7 +257,7 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command,
257 struct acpi_connection_info *info = &data->info; 257 struct acpi_connection_info *info = &data->info;
258 struct acpi_resource_i2c_serialbus *sb; 258 struct acpi_resource_i2c_serialbus *sb;
259 struct i2c_adapter *adapter = data->adapter; 259 struct i2c_adapter *adapter = data->adapter;
260 struct i2c_client client; 260 struct i2c_client *client;
261 struct acpi_resource *ares; 261 struct acpi_resource *ares;
262 u32 accessor_type = function >> 16; 262 u32 accessor_type = function >> 16;
263 u8 action = function & ACPI_IO_MASK; 263 u8 action = function & ACPI_IO_MASK;
@@ -268,6 +268,12 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command,
268 if (ACPI_FAILURE(ret)) 268 if (ACPI_FAILURE(ret))
269 return ret; 269 return ret;
270 270
271 client = kzalloc(sizeof(*client), GFP_KERNEL);
272 if (!client) {
273 ret = AE_NO_MEMORY;
274 goto err;
275 }
276
271 if (!value64 || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) { 277 if (!value64 || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) {
272 ret = AE_BAD_PARAMETER; 278 ret = AE_BAD_PARAMETER;
273 goto err; 279 goto err;
@@ -279,75 +285,73 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command,
279 goto err; 285 goto err;
280 } 286 }
281 287
282 memset(&client, 0, sizeof(client)); 288 client->adapter = adapter;
283 client.adapter = adapter; 289 client->addr = sb->slave_address;
284 client.addr = sb->slave_address;
285 client.flags = 0;
286 290
287 if (sb->access_mode == ACPI_I2C_10BIT_MODE) 291 if (sb->access_mode == ACPI_I2C_10BIT_MODE)
288 client.flags |= I2C_CLIENT_TEN; 292 client->flags |= I2C_CLIENT_TEN;
289 293
290 switch (accessor_type) { 294 switch (accessor_type) {
291 case ACPI_GSB_ACCESS_ATTRIB_SEND_RCV: 295 case ACPI_GSB_ACCESS_ATTRIB_SEND_RCV:
292 if (action == ACPI_READ) { 296 if (action == ACPI_READ) {
293 status = i2c_smbus_read_byte(&client); 297 status = i2c_smbus_read_byte(client);
294 if (status >= 0) { 298 if (status >= 0) {
295 gsb->bdata = status; 299 gsb->bdata = status;
296 status = 0; 300 status = 0;
297 } 301 }
298 } else { 302 } else {
299 status = i2c_smbus_write_byte(&client, gsb->bdata); 303 status = i2c_smbus_write_byte(client, gsb->bdata);
300 } 304 }
301 break; 305 break;
302 306
303 case ACPI_GSB_ACCESS_ATTRIB_BYTE: 307 case ACPI_GSB_ACCESS_ATTRIB_BYTE:
304 if (action == ACPI_READ) { 308 if (action == ACPI_READ) {
305 status = i2c_smbus_read_byte_data(&client, command); 309 status = i2c_smbus_read_byte_data(client, command);
306 if (status >= 0) { 310 if (status >= 0) {
307 gsb->bdata = status; 311 gsb->bdata = status;
308 status = 0; 312 status = 0;
309 } 313 }
310 } else { 314 } else {
311 status = i2c_smbus_write_byte_data(&client, command, 315 status = i2c_smbus_write_byte_data(client, command,
312 gsb->bdata); 316 gsb->bdata);
313 } 317 }
314 break; 318 break;
315 319
316 case ACPI_GSB_ACCESS_ATTRIB_WORD: 320 case ACPI_GSB_ACCESS_ATTRIB_WORD:
317 if (action == ACPI_READ) { 321 if (action == ACPI_READ) {
318 status = i2c_smbus_read_word_data(&client, command); 322 status = i2c_smbus_read_word_data(client, command);
319 if (status >= 0) { 323 if (status >= 0) {
320 gsb->wdata = status; 324 gsb->wdata = status;
321 status = 0; 325 status = 0;
322 } 326 }
323 } else { 327 } else {
324 status = i2c_smbus_write_word_data(&client, command, 328 status = i2c_smbus_write_word_data(client, command,
325 gsb->wdata); 329 gsb->wdata);
326 } 330 }
327 break; 331 break;
328 332
329 case ACPI_GSB_ACCESS_ATTRIB_BLOCK: 333 case ACPI_GSB_ACCESS_ATTRIB_BLOCK:
330 if (action == ACPI_READ) { 334 if (action == ACPI_READ) {
331 status = i2c_smbus_read_block_data(&client, command, 335 status = i2c_smbus_read_block_data(client, command,
332 gsb->data); 336 gsb->data);
333 if (status >= 0) { 337 if (status >= 0) {
334 gsb->len = status; 338 gsb->len = status;
335 status = 0; 339 status = 0;
336 } 340 }
337 } else { 341 } else {
338 status = i2c_smbus_write_block_data(&client, command, 342 status = i2c_smbus_write_block_data(client, command,
339 gsb->len, gsb->data); 343 gsb->len, gsb->data);
340 } 344 }
341 break; 345 break;
342 346
343 case ACPI_GSB_ACCESS_ATTRIB_MULTIBYTE: 347 case ACPI_GSB_ACCESS_ATTRIB_MULTIBYTE:
344 if (action == ACPI_READ) { 348 if (action == ACPI_READ) {
345 status = acpi_gsb_i2c_read_bytes(&client, command, 349 status = acpi_gsb_i2c_read_bytes(client, command,
346 gsb->data, info->access_length); 350 gsb->data, info->access_length);
347 if (status > 0) 351 if (status > 0)
348 status = 0; 352 status = 0;
349 } else { 353 } else {
350 status = acpi_gsb_i2c_write_bytes(&client, command, 354 status = acpi_gsb_i2c_write_bytes(client, command,
351 gsb->data, info->access_length); 355 gsb->data, info->access_length);
352 } 356 }
353 break; 357 break;
@@ -361,6 +365,7 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command,
361 gsb->status = status; 365 gsb->status = status;
362 366
363 err: 367 err:
368 kfree(client);
364 ACPI_FREE(ares); 369 ACPI_FREE(ares);
365 return ret; 370 return ret;
366} 371}
@@ -1276,7 +1281,7 @@ static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap,
1276 } 1281 }
1277 1282
1278 addr = of_get_property(node, "reg", &len); 1283 addr = of_get_property(node, "reg", &len);
1279 if (!addr || (len < sizeof(int))) { 1284 if (!addr || (len < sizeof(*addr))) {
1280 dev_err(&adap->dev, "of_i2c: invalid reg on %s\n", 1285 dev_err(&adap->dev, "of_i2c: invalid reg on %s\n",
1281 node->full_name); 1286 node->full_name);
1282 return ERR_PTR(-EINVAL); 1287 return ERR_PTR(-EINVAL);
@@ -1677,7 +1682,7 @@ void i2c_del_adapter(struct i2c_adapter *adap)
1677 * FIXME: This is old code and should ideally be replaced by an 1682 * FIXME: This is old code and should ideally be replaced by an
1678 * alternative which results in decoupling the lifetime of the struct 1683 * alternative which results in decoupling the lifetime of the struct
1679 * device from the i2c_adapter, like spi or netdev do. Any solution 1684 * device from the i2c_adapter, like spi or netdev do. Any solution
1680 * should be throughly tested with DEBUG_KOBJECT_RELEASE enabled! 1685 * should be thoroughly tested with DEBUG_KOBJECT_RELEASE enabled!
1681 */ 1686 */
1682 init_completion(&adap->dev_released); 1687 init_completion(&adap->dev_released);
1683 device_unregister(&adap->dev); 1688 device_unregister(&adap->dev);
@@ -2918,18 +2923,24 @@ int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb)
2918{ 2923{
2919 int ret; 2924 int ret;
2920 2925
2921 if (!client || !slave_cb) 2926 if (!client || !slave_cb) {
2927 WARN(1, "insufficent data\n");
2922 return -EINVAL; 2928 return -EINVAL;
2929 }
2923 2930
2924 if (!(client->flags & I2C_CLIENT_TEN)) { 2931 if (!(client->flags & I2C_CLIENT_TEN)) {
2925 /* Enforce stricter address checking */ 2932 /* Enforce stricter address checking */
2926 ret = i2c_check_addr_validity(client->addr); 2933 ret = i2c_check_addr_validity(client->addr);
2927 if (ret) 2934 if (ret) {
2935 dev_err(&client->dev, "%s: invalid address\n", __func__);
2928 return ret; 2936 return ret;
2937 }
2929 } 2938 }
2930 2939
2931 if (!client->adapter->algo->reg_slave) 2940 if (!client->adapter->algo->reg_slave) {
2941 dev_err(&client->dev, "%s: not supported by adapter\n", __func__);
2932 return -EOPNOTSUPP; 2942 return -EOPNOTSUPP;
2943 }
2933 2944
2934 client->slave_cb = slave_cb; 2945 client->slave_cb = slave_cb;
2935 2946
@@ -2937,8 +2948,10 @@ int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb)
2937 ret = client->adapter->algo->reg_slave(client); 2948 ret = client->adapter->algo->reg_slave(client);
2938 i2c_unlock_adapter(client->adapter); 2949 i2c_unlock_adapter(client->adapter);
2939 2950
2940 if (ret) 2951 if (ret) {
2941 client->slave_cb = NULL; 2952 client->slave_cb = NULL;
2953 dev_err(&client->dev, "%s: adapter returned error %d\n", __func__, ret);
2954 }
2942 2955
2943 return ret; 2956 return ret;
2944} 2957}
@@ -2948,8 +2961,10 @@ int i2c_slave_unregister(struct i2c_client *client)
2948{ 2961{
2949 int ret; 2962 int ret;
2950 2963
2951 if (!client->adapter->algo->unreg_slave) 2964 if (!client->adapter->algo->unreg_slave) {
2965 dev_err(&client->dev, "%s: not supported by adapter\n", __func__);
2952 return -EOPNOTSUPP; 2966 return -EOPNOTSUPP;
2967 }
2953 2968
2954 i2c_lock_adapter(client->adapter); 2969 i2c_lock_adapter(client->adapter);
2955 ret = client->adapter->algo->unreg_slave(client); 2970 ret = client->adapter->algo->unreg_slave(client);
@@ -2957,6 +2972,8 @@ int i2c_slave_unregister(struct i2c_client *client)
2957 2972
2958 if (ret == 0) 2973 if (ret == 0)
2959 client->slave_cb = NULL; 2974 client->slave_cb = NULL;
2975 else
2976 dev_err(&client->dev, "%s: adapter returned error %d\n", __func__, ret);
2960 2977
2961 return ret; 2978 return ret;
2962} 2979}