i2c-core-acpi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /*
  2. * Linux I2C core ACPI support code
  3. *
  4. * Copyright (C) 2014 Intel Corp, Author: Lan Tianyu <tianyu.lan@intel.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. */
  11. #include <linux/acpi.h>
  12. #include <linux/device.h>
  13. #include <linux/err.h>
  14. #include <linux/i2c.h>
  15. #include <linux/list.h>
  16. #include <linux/module.h>
  17. #include <linux/slab.h>
  18. #include "i2c-core.h"
  19. struct i2c_acpi_handler_data {
  20. struct acpi_connection_info info;
  21. struct i2c_adapter *adapter;
  22. };
  23. struct gsb_buffer {
  24. u8 status;
  25. u8 len;
  26. union {
  27. u16 wdata;
  28. u8 bdata;
  29. u8 data[0];
  30. };
  31. } __packed;
  32. struct i2c_acpi_lookup {
  33. struct i2c_board_info *info;
  34. acpi_handle adapter_handle;
  35. acpi_handle device_handle;
  36. acpi_handle search_handle;
  37. int n;
  38. int index;
  39. u32 speed;
  40. u32 min_speed;
  41. };
  42. static int i2c_acpi_fill_info(struct acpi_resource *ares, void *data)
  43. {
  44. struct i2c_acpi_lookup *lookup = data;
  45. struct i2c_board_info *info = lookup->info;
  46. struct acpi_resource_i2c_serialbus *sb;
  47. acpi_status status;
  48. if (info->addr || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS)
  49. return 1;
  50. sb = &ares->data.i2c_serial_bus;
  51. if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C)
  52. return 1;
  53. if (lookup->index != -1 && lookup->n++ != lookup->index)
  54. return 1;
  55. status = acpi_get_handle(lookup->device_handle,
  56. sb->resource_source.string_ptr,
  57. &lookup->adapter_handle);
  58. if (!ACPI_SUCCESS(status))
  59. return 1;
  60. info->addr = sb->slave_address;
  61. lookup->speed = sb->connection_speed;
  62. if (sb->access_mode == ACPI_I2C_10BIT_MODE)
  63. info->flags |= I2C_CLIENT_TEN;
  64. return 1;
  65. }
  66. static const struct acpi_device_id i2c_acpi_ignored_device_ids[] = {
  67. /*
  68. * ACPI video acpi_devices, which are handled by the acpi-video driver
  69. * sometimes contain a SERIAL_TYPE_I2C ACPI resource, ignore these.
  70. */
  71. { ACPI_VIDEO_HID, 0 },
  72. {}
  73. };
  74. static int i2c_acpi_do_lookup(struct acpi_device *adev,
  75. struct i2c_acpi_lookup *lookup)
  76. {
  77. struct i2c_board_info *info = lookup->info;
  78. struct list_head resource_list;
  79. int ret;
  80. if (acpi_bus_get_status(adev) || !adev->status.present ||
  81. acpi_device_enumerated(adev))
  82. return -EINVAL;
  83. if (acpi_match_device_ids(adev, i2c_acpi_ignored_device_ids) == 0)
  84. return -ENODEV;
  85. memset(info, 0, sizeof(*info));
  86. lookup->device_handle = acpi_device_handle(adev);
  87. /* Look up for I2cSerialBus resource */
  88. INIT_LIST_HEAD(&resource_list);
  89. ret = acpi_dev_get_resources(adev, &resource_list,
  90. i2c_acpi_fill_info, lookup);
  91. acpi_dev_free_resource_list(&resource_list);
  92. if (ret < 0 || !info->addr)
  93. return -EINVAL;
  94. return 0;
  95. }
  96. static int i2c_acpi_get_info(struct acpi_device *adev,
  97. struct i2c_board_info *info,
  98. struct i2c_adapter *adapter,
  99. acpi_handle *adapter_handle)
  100. {
  101. struct list_head resource_list;
  102. struct resource_entry *entry;
  103. struct i2c_acpi_lookup lookup;
  104. int ret;
  105. memset(&lookup, 0, sizeof(lookup));
  106. lookup.info = info;
  107. lookup.index = -1;
  108. ret = i2c_acpi_do_lookup(adev, &lookup);
  109. if (ret)
  110. return ret;
  111. if (adapter) {
  112. /* The adapter must match the one in I2cSerialBus() connector */
  113. if (ACPI_HANDLE(&adapter->dev) != lookup.adapter_handle)
  114. return -ENODEV;
  115. } else {
  116. struct acpi_device *adapter_adev;
  117. /* The adapter must be present */
  118. if (acpi_bus_get_device(lookup.adapter_handle, &adapter_adev))
  119. return -ENODEV;
  120. if (acpi_bus_get_status(adapter_adev) ||
  121. !adapter_adev->status.present)
  122. return -ENODEV;
  123. }
  124. info->fwnode = acpi_fwnode_handle(adev);
  125. if (adapter_handle)
  126. *adapter_handle = lookup.adapter_handle;
  127. /* Then fill IRQ number if any */
  128. INIT_LIST_HEAD(&resource_list);
  129. ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
  130. if (ret < 0)
  131. return -EINVAL;
  132. resource_list_for_each_entry(entry, &resource_list) {
  133. if (resource_type(entry->res) == IORESOURCE_IRQ) {
  134. info->irq = entry->res->start;
  135. break;
  136. }
  137. }
  138. acpi_dev_free_resource_list(&resource_list);
  139. acpi_set_modalias(adev, dev_name(&adev->dev), info->type,
  140. sizeof(info->type));
  141. return 0;
  142. }
  143. static void i2c_acpi_register_device(struct i2c_adapter *adapter,
  144. struct acpi_device *adev,
  145. struct i2c_board_info *info)
  146. {
  147. adev->power.flags.ignore_parent = true;
  148. acpi_device_set_enumerated(adev);
  149. if (!i2c_new_device(adapter, info)) {
  150. adev->power.flags.ignore_parent = false;
  151. dev_err(&adapter->dev,
  152. "failed to add I2C device %s from ACPI\n",
  153. dev_name(&adev->dev));
  154. }
  155. }
  156. static acpi_status i2c_acpi_add_device(acpi_handle handle, u32 level,
  157. void *data, void **return_value)
  158. {
  159. struct i2c_adapter *adapter = data;
  160. struct acpi_device *adev;
  161. struct i2c_board_info info;
  162. if (acpi_bus_get_device(handle, &adev))
  163. return AE_OK;
  164. if (i2c_acpi_get_info(adev, &info, adapter, NULL))
  165. return AE_OK;
  166. i2c_acpi_register_device(adapter, adev, &info);
  167. return AE_OK;
  168. }
  169. #define I2C_ACPI_MAX_SCAN_DEPTH 32
  170. /**
  171. * i2c_acpi_register_devices - enumerate I2C slave devices behind adapter
  172. * @adap: pointer to adapter
  173. *
  174. * Enumerate all I2C slave devices behind this adapter by walking the ACPI
  175. * namespace. When a device is found it will be added to the Linux device
  176. * model and bound to the corresponding ACPI handle.
  177. */
  178. void i2c_acpi_register_devices(struct i2c_adapter *adap)
  179. {
  180. acpi_status status;
  181. if (!has_acpi_companion(&adap->dev))
  182. return;
  183. status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
  184. I2C_ACPI_MAX_SCAN_DEPTH,
  185. i2c_acpi_add_device, NULL,
  186. adap, NULL);
  187. if (ACPI_FAILURE(status))
  188. dev_warn(&adap->dev, "failed to enumerate I2C slaves\n");
  189. }
  190. const struct acpi_device_id *
  191. i2c_acpi_match_device(const struct acpi_device_id *matches,
  192. struct i2c_client *client)
  193. {
  194. if (!(client && matches))
  195. return NULL;
  196. return acpi_match_device(matches, &client->dev);
  197. }
  198. static acpi_status i2c_acpi_lookup_speed(acpi_handle handle, u32 level,
  199. void *data, void **return_value)
  200. {
  201. struct i2c_acpi_lookup *lookup = data;
  202. struct acpi_device *adev;
  203. if (acpi_bus_get_device(handle, &adev))
  204. return AE_OK;
  205. if (i2c_acpi_do_lookup(adev, lookup))
  206. return AE_OK;
  207. if (lookup->search_handle != lookup->adapter_handle)
  208. return AE_OK;
  209. if (lookup->speed <= lookup->min_speed)
  210. lookup->min_speed = lookup->speed;
  211. return AE_OK;
  212. }
  213. /**
  214. * i2c_acpi_find_bus_speed - find I2C bus speed from ACPI
  215. * @dev: The device owning the bus
  216. *
  217. * Find the I2C bus speed by walking the ACPI namespace for all I2C slaves
  218. * devices connected to this bus and use the speed of slowest device.
  219. *
  220. * Returns the speed in Hz or zero
  221. */
  222. u32 i2c_acpi_find_bus_speed(struct device *dev)
  223. {
  224. struct i2c_acpi_lookup lookup;
  225. struct i2c_board_info dummy;
  226. acpi_status status;
  227. if (!has_acpi_companion(dev))
  228. return 0;
  229. memset(&lookup, 0, sizeof(lookup));
  230. lookup.search_handle = ACPI_HANDLE(dev);
  231. lookup.min_speed = UINT_MAX;
  232. lookup.info = &dummy;
  233. lookup.index = -1;
  234. status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
  235. I2C_ACPI_MAX_SCAN_DEPTH,
  236. i2c_acpi_lookup_speed, NULL,
  237. &lookup, NULL);
  238. if (ACPI_FAILURE(status)) {
  239. dev_warn(dev, "unable to find I2C bus speed from ACPI\n");
  240. return 0;
  241. }
  242. return lookup.min_speed != UINT_MAX ? lookup.min_speed : 0;
  243. }
  244. EXPORT_SYMBOL_GPL(i2c_acpi_find_bus_speed);
  245. static int i2c_acpi_find_match_adapter(struct device *dev, void *data)
  246. {
  247. struct i2c_adapter *adapter = i2c_verify_adapter(dev);
  248. if (!adapter)
  249. return 0;
  250. return ACPI_HANDLE(dev) == (acpi_handle)data;
  251. }
  252. static int i2c_acpi_find_match_device(struct device *dev, void *data)
  253. {
  254. return ACPI_COMPANION(dev) == data;
  255. }
  256. static struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
  257. {
  258. struct device *dev;
  259. dev = bus_find_device(&i2c_bus_type, NULL, handle,
  260. i2c_acpi_find_match_adapter);
  261. return dev ? i2c_verify_adapter(dev) : NULL;
  262. }
  263. static struct i2c_client *i2c_acpi_find_client_by_adev(struct acpi_device *adev)
  264. {
  265. struct device *dev;
  266. dev = bus_find_device(&i2c_bus_type, NULL, adev,
  267. i2c_acpi_find_match_device);
  268. return dev ? i2c_verify_client(dev) : NULL;
  269. }
  270. static int i2c_acpi_notify(struct notifier_block *nb, unsigned long value,
  271. void *arg)
  272. {
  273. struct acpi_device *adev = arg;
  274. struct i2c_board_info info;
  275. acpi_handle adapter_handle;
  276. struct i2c_adapter *adapter;
  277. struct i2c_client *client;
  278. switch (value) {
  279. case ACPI_RECONFIG_DEVICE_ADD:
  280. if (i2c_acpi_get_info(adev, &info, NULL, &adapter_handle))
  281. break;
  282. adapter = i2c_acpi_find_adapter_by_handle(adapter_handle);
  283. if (!adapter)
  284. break;
  285. i2c_acpi_register_device(adapter, adev, &info);
  286. break;
  287. case ACPI_RECONFIG_DEVICE_REMOVE:
  288. if (!acpi_device_enumerated(adev))
  289. break;
  290. client = i2c_acpi_find_client_by_adev(adev);
  291. if (!client)
  292. break;
  293. i2c_unregister_device(client);
  294. put_device(&client->dev);
  295. break;
  296. }
  297. return NOTIFY_OK;
  298. }
  299. struct notifier_block i2c_acpi_notifier = {
  300. .notifier_call = i2c_acpi_notify,
  301. };
  302. /**
  303. * i2c_acpi_new_device - Create i2c-client for the Nth I2cSerialBus resource
  304. * @dev: Device owning the ACPI resources to get the client from
  305. * @index: Index of ACPI resource to get
  306. * @info: describes the I2C device; note this is modified (addr gets set)
  307. * Context: can sleep
  308. *
  309. * By default the i2c subsys creates an i2c-client for the first I2cSerialBus
  310. * resource of an acpi_device, but some acpi_devices have multiple I2cSerialBus
  311. * resources, in that case this function can be used to create an i2c-client
  312. * for other I2cSerialBus resources in the Current Resource Settings table.
  313. *
  314. * Also see i2c_new_device, which this function calls to create the i2c-client.
  315. *
  316. * Returns a pointer to the new i2c-client, or NULL if the adapter is not found.
  317. */
  318. struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
  319. struct i2c_board_info *info)
  320. {
  321. struct i2c_acpi_lookup lookup;
  322. struct i2c_adapter *adapter;
  323. struct acpi_device *adev;
  324. LIST_HEAD(resource_list);
  325. int ret;
  326. adev = ACPI_COMPANION(dev);
  327. if (!adev)
  328. return NULL;
  329. memset(&lookup, 0, sizeof(lookup));
  330. lookup.info = info;
  331. lookup.device_handle = acpi_device_handle(adev);
  332. lookup.index = index;
  333. ret = acpi_dev_get_resources(adev, &resource_list,
  334. i2c_acpi_fill_info, &lookup);
  335. acpi_dev_free_resource_list(&resource_list);
  336. if (ret < 0 || !info->addr)
  337. return NULL;
  338. adapter = i2c_acpi_find_adapter_by_handle(lookup.adapter_handle);
  339. if (!adapter)
  340. return NULL;
  341. return i2c_new_device(adapter, info);
  342. }
  343. EXPORT_SYMBOL_GPL(i2c_acpi_new_device);
  344. #ifdef CONFIG_ACPI_I2C_OPREGION
  345. static int acpi_gsb_i2c_read_bytes(struct i2c_client *client,
  346. u8 cmd, u8 *data, u8 data_len)
  347. {
  348. struct i2c_msg msgs[2];
  349. int ret;
  350. u8 *buffer;
  351. buffer = kzalloc(data_len, GFP_KERNEL);
  352. if (!buffer)
  353. return AE_NO_MEMORY;
  354. msgs[0].addr = client->addr;
  355. msgs[0].flags = client->flags;
  356. msgs[0].len = 1;
  357. msgs[0].buf = &cmd;
  358. msgs[1].addr = client->addr;
  359. msgs[1].flags = client->flags | I2C_M_RD;
  360. msgs[1].len = data_len;
  361. msgs[1].buf = buffer;
  362. ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
  363. if (ret < 0) {
  364. /* Getting a NACK is unfortunately normal with some DSTDs */
  365. if (ret == -EREMOTEIO)
  366. dev_dbg(&client->adapter->dev, "i2c read %d bytes from client@%#x starting at reg %#x failed, error: %d\n",
  367. data_len, client->addr, cmd, ret);
  368. else
  369. dev_err(&client->adapter->dev, "i2c read %d bytes from client@%#x starting at reg %#x failed, error: %d\n",
  370. data_len, client->addr, cmd, ret);
  371. } else {
  372. memcpy(data, buffer, data_len);
  373. }
  374. kfree(buffer);
  375. return ret;
  376. }
  377. static int acpi_gsb_i2c_write_bytes(struct i2c_client *client,
  378. u8 cmd, u8 *data, u8 data_len)
  379. {
  380. struct i2c_msg msgs[1];
  381. u8 *buffer;
  382. int ret = AE_OK;
  383. buffer = kzalloc(data_len + 1, GFP_KERNEL);
  384. if (!buffer)
  385. return AE_NO_MEMORY;
  386. buffer[0] = cmd;
  387. memcpy(buffer + 1, data, data_len);
  388. msgs[0].addr = client->addr;
  389. msgs[0].flags = client->flags;
  390. msgs[0].len = data_len + 1;
  391. msgs[0].buf = buffer;
  392. ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
  393. if (ret < 0)
  394. dev_err(&client->adapter->dev, "i2c write failed\n");
  395. kfree(buffer);
  396. return ret;
  397. }
  398. static acpi_status
  399. i2c_acpi_space_handler(u32 function, acpi_physical_address command,
  400. u32 bits, u64 *value64,
  401. void *handler_context, void *region_context)
  402. {
  403. struct gsb_buffer *gsb = (struct gsb_buffer *)value64;
  404. struct i2c_acpi_handler_data *data = handler_context;
  405. struct acpi_connection_info *info = &data->info;
  406. struct acpi_resource_i2c_serialbus *sb;
  407. struct i2c_adapter *adapter = data->adapter;
  408. struct i2c_client *client;
  409. struct acpi_resource *ares;
  410. u32 accessor_type = function >> 16;
  411. u8 action = function & ACPI_IO_MASK;
  412. acpi_status ret;
  413. int status;
  414. ret = acpi_buffer_to_resource(info->connection, info->length, &ares);
  415. if (ACPI_FAILURE(ret))
  416. return ret;
  417. client = kzalloc(sizeof(*client), GFP_KERNEL);
  418. if (!client) {
  419. ret = AE_NO_MEMORY;
  420. goto err;
  421. }
  422. if (!value64 || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) {
  423. ret = AE_BAD_PARAMETER;
  424. goto err;
  425. }
  426. sb = &ares->data.i2c_serial_bus;
  427. if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C) {
  428. ret = AE_BAD_PARAMETER;
  429. goto err;
  430. }
  431. client->adapter = adapter;
  432. client->addr = sb->slave_address;
  433. if (sb->access_mode == ACPI_I2C_10BIT_MODE)
  434. client->flags |= I2C_CLIENT_TEN;
  435. switch (accessor_type) {
  436. case ACPI_GSB_ACCESS_ATTRIB_SEND_RCV:
  437. if (action == ACPI_READ) {
  438. status = i2c_smbus_read_byte(client);
  439. if (status >= 0) {
  440. gsb->bdata = status;
  441. status = 0;
  442. }
  443. } else {
  444. status = i2c_smbus_write_byte(client, gsb->bdata);
  445. }
  446. break;
  447. case ACPI_GSB_ACCESS_ATTRIB_BYTE:
  448. if (action == ACPI_READ) {
  449. status = i2c_smbus_read_byte_data(client, command);
  450. if (status >= 0) {
  451. gsb->bdata = status;
  452. status = 0;
  453. }
  454. } else {
  455. status = i2c_smbus_write_byte_data(client, command,
  456. gsb->bdata);
  457. }
  458. break;
  459. case ACPI_GSB_ACCESS_ATTRIB_WORD:
  460. if (action == ACPI_READ) {
  461. status = i2c_smbus_read_word_data(client, command);
  462. if (status >= 0) {
  463. gsb->wdata = status;
  464. status = 0;
  465. }
  466. } else {
  467. status = i2c_smbus_write_word_data(client, command,
  468. gsb->wdata);
  469. }
  470. break;
  471. case ACPI_GSB_ACCESS_ATTRIB_BLOCK:
  472. if (action == ACPI_READ) {
  473. status = i2c_smbus_read_block_data(client, command,
  474. gsb->data);
  475. if (status >= 0) {
  476. gsb->len = status;
  477. status = 0;
  478. }
  479. } else {
  480. status = i2c_smbus_write_block_data(client, command,
  481. gsb->len, gsb->data);
  482. }
  483. break;
  484. case ACPI_GSB_ACCESS_ATTRIB_MULTIBYTE:
  485. if (action == ACPI_READ) {
  486. status = acpi_gsb_i2c_read_bytes(client, command,
  487. gsb->data, info->access_length);
  488. if (status > 0)
  489. status = 0;
  490. } else {
  491. status = acpi_gsb_i2c_write_bytes(client, command,
  492. gsb->data, info->access_length);
  493. }
  494. break;
  495. default:
  496. dev_warn(&adapter->dev, "protocol 0x%02x not supported for client 0x%02x\n",
  497. accessor_type, client->addr);
  498. ret = AE_BAD_PARAMETER;
  499. goto err;
  500. }
  501. gsb->status = status;
  502. err:
  503. kfree(client);
  504. ACPI_FREE(ares);
  505. return ret;
  506. }
  507. int i2c_acpi_install_space_handler(struct i2c_adapter *adapter)
  508. {
  509. acpi_handle handle;
  510. struct i2c_acpi_handler_data *data;
  511. acpi_status status;
  512. if (!adapter->dev.parent)
  513. return -ENODEV;
  514. handle = ACPI_HANDLE(adapter->dev.parent);
  515. if (!handle)
  516. return -ENODEV;
  517. data = kzalloc(sizeof(struct i2c_acpi_handler_data),
  518. GFP_KERNEL);
  519. if (!data)
  520. return -ENOMEM;
  521. data->adapter = adapter;
  522. status = acpi_bus_attach_private_data(handle, (void *)data);
  523. if (ACPI_FAILURE(status)) {
  524. kfree(data);
  525. return -ENOMEM;
  526. }
  527. status = acpi_install_address_space_handler(handle,
  528. ACPI_ADR_SPACE_GSBUS,
  529. &i2c_acpi_space_handler,
  530. NULL,
  531. data);
  532. if (ACPI_FAILURE(status)) {
  533. dev_err(&adapter->dev, "Error installing i2c space handler\n");
  534. acpi_bus_detach_private_data(handle);
  535. kfree(data);
  536. return -ENOMEM;
  537. }
  538. acpi_walk_dep_device_list(handle);
  539. return 0;
  540. }
  541. void i2c_acpi_remove_space_handler(struct i2c_adapter *adapter)
  542. {
  543. acpi_handle handle;
  544. struct i2c_acpi_handler_data *data;
  545. acpi_status status;
  546. if (!adapter->dev.parent)
  547. return;
  548. handle = ACPI_HANDLE(adapter->dev.parent);
  549. if (!handle)
  550. return;
  551. acpi_remove_address_space_handler(handle,
  552. ACPI_ADR_SPACE_GSBUS,
  553. &i2c_acpi_space_handler);
  554. status = acpi_bus_get_private_data(handle, (void **)&data);
  555. if (ACPI_SUCCESS(status))
  556. kfree(data);
  557. acpi_bus_detach_private_data(handle);
  558. }
  559. #endif /* CONFIG_ACPI_I2C_OPREGION */