.. | .. |
---|
1 | | -/* ------------------------------------------------------------------------- */ |
---|
2 | | -/* */ |
---|
3 | | -/* i2c.h - definitions for the i2c-bus interface */ |
---|
4 | | -/* */ |
---|
5 | | -/* ------------------------------------------------------------------------- */ |
---|
6 | | -/* Copyright (C) 1995-2000 Simon G. Vogl |
---|
7 | | - |
---|
8 | | - This program is free software; you can redistribute it and/or modify |
---|
9 | | - it under the terms of the GNU General Public License as published by |
---|
10 | | - the Free Software Foundation; either version 2 of the License, or |
---|
11 | | - (at your option) any later version. |
---|
12 | | - |
---|
13 | | - This program is distributed in the hope that it will be useful, |
---|
14 | | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | | - GNU General Public License for more details. |
---|
17 | | - |
---|
18 | | - You should have received a copy of the GNU General Public License |
---|
19 | | - along with this program; if not, write to the Free Software |
---|
20 | | - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
---|
21 | | - MA 02110-1301 USA. */ |
---|
22 | | -/* ------------------------------------------------------------------------- */ |
---|
23 | | - |
---|
24 | | -/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and |
---|
25 | | - Frodo Looijaard <frodol@dds.nl> */ |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
---|
| 2 | +/* |
---|
| 3 | + * i2c.h - definitions for the Linux i2c bus interface |
---|
| 4 | + * Copyright (C) 1995-2000 Simon G. Vogl |
---|
| 5 | + * Copyright (C) 2013-2019 Wolfram Sang <wsa@kernel.org> |
---|
| 6 | + * |
---|
| 7 | + * With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and |
---|
| 8 | + * Frodo Looijaard <frodol@dds.nl> |
---|
| 9 | + */ |
---|
26 | 10 | #ifndef _LINUX_I2C_H |
---|
27 | 11 | #define _LINUX_I2C_H |
---|
28 | 12 | |
---|
| 13 | +#include <linux/acpi.h> /* for acpi_handle */ |
---|
29 | 14 | #include <linux/mod_devicetable.h> |
---|
30 | 15 | #include <linux/device.h> /* for struct device */ |
---|
31 | 16 | #include <linux/sched.h> /* for completion */ |
---|
.. | .. |
---|
51 | 36 | union i2c_smbus_data; |
---|
52 | 37 | struct i2c_board_info; |
---|
53 | 38 | enum i2c_slave_event; |
---|
54 | | -typedef int (*i2c_slave_cb_t)(struct i2c_client *, enum i2c_slave_event, u8 *); |
---|
| 39 | +typedef int (*i2c_slave_cb_t)(struct i2c_client *client, |
---|
| 40 | + enum i2c_slave_event event, u8 *val); |
---|
| 41 | + |
---|
| 42 | +/* I2C Frequency Modes */ |
---|
| 43 | +#define I2C_MAX_STANDARD_MODE_FREQ 100000 |
---|
| 44 | +#define I2C_MAX_FAST_MODE_FREQ 400000 |
---|
| 45 | +#define I2C_MAX_FAST_MODE_PLUS_FREQ 1000000 |
---|
| 46 | +#define I2C_MAX_TURBO_MODE_FREQ 1400000 |
---|
| 47 | +#define I2C_MAX_HIGH_SPEED_MODE_FREQ 3400000 |
---|
| 48 | +#define I2C_MAX_ULTRA_FAST_MODE_FREQ 5000000 |
---|
55 | 49 | |
---|
56 | 50 | struct module; |
---|
57 | 51 | struct property_entry; |
---|
.. | .. |
---|
62 | 56 | * on a bus (or read from them). Apart from two basic transfer functions to |
---|
63 | 57 | * transmit one message at a time, a more complex version can be used to |
---|
64 | 58 | * transmit an arbitrary number of messages without interruption. |
---|
65 | | - * @count must be be less than 64k since msg.len is u16. |
---|
| 59 | + * @count must be less than 64k since msg.len is u16. |
---|
66 | 60 | */ |
---|
67 | | -extern int i2c_transfer_buffer_flags(const struct i2c_client *client, |
---|
68 | | - char *buf, int count, u16 flags); |
---|
| 61 | +int i2c_transfer_buffer_flags(const struct i2c_client *client, |
---|
| 62 | + char *buf, int count, u16 flags); |
---|
69 | 63 | |
---|
70 | 64 | /** |
---|
71 | 65 | * i2c_master_recv - issue a single I2C message in master receive mode |
---|
.. | .. |
---|
129 | 123 | |
---|
130 | 124 | /* Transfer num messages. |
---|
131 | 125 | */ |
---|
132 | | -extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, |
---|
133 | | - int num); |
---|
| 126 | +int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num); |
---|
134 | 127 | /* Unlocked flavor */ |
---|
135 | | -extern int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, |
---|
136 | | - int num); |
---|
| 128 | +int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num); |
---|
137 | 129 | |
---|
138 | 130 | /* This is the very generalized SMBus access routine. You probably do not |
---|
139 | 131 | want to use this, though; one of the functions below may be much easier, |
---|
.. | .. |
---|
152 | 144 | /* Now follow the 'nice' access routines. These also document the calling |
---|
153 | 145 | conventions of i2c_smbus_xfer. */ |
---|
154 | 146 | |
---|
155 | | -extern s32 i2c_smbus_read_byte(const struct i2c_client *client); |
---|
156 | | -extern s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value); |
---|
157 | | -extern s32 i2c_smbus_read_byte_data(const struct i2c_client *client, |
---|
158 | | - u8 command); |
---|
159 | | -extern s32 i2c_smbus_write_byte_data(const struct i2c_client *client, |
---|
160 | | - u8 command, u8 value); |
---|
161 | | -extern s32 i2c_smbus_read_word_data(const struct i2c_client *client, |
---|
162 | | - u8 command); |
---|
163 | | -extern s32 i2c_smbus_write_word_data(const struct i2c_client *client, |
---|
164 | | - u8 command, u16 value); |
---|
| 147 | +s32 i2c_smbus_read_byte(const struct i2c_client *client); |
---|
| 148 | +s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value); |
---|
| 149 | +s32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command); |
---|
| 150 | +s32 i2c_smbus_write_byte_data(const struct i2c_client *client, |
---|
| 151 | + u8 command, u8 value); |
---|
| 152 | +s32 i2c_smbus_read_word_data(const struct i2c_client *client, u8 command); |
---|
| 153 | +s32 i2c_smbus_write_word_data(const struct i2c_client *client, |
---|
| 154 | + u8 command, u16 value); |
---|
165 | 155 | |
---|
166 | 156 | static inline s32 |
---|
167 | 157 | i2c_smbus_read_word_swapped(const struct i2c_client *client, u8 command) |
---|
.. | .. |
---|
179 | 169 | } |
---|
180 | 170 | |
---|
181 | 171 | /* Returns the number of read bytes */ |
---|
182 | | -extern s32 i2c_smbus_read_block_data(const struct i2c_client *client, |
---|
183 | | - u8 command, u8 *values); |
---|
184 | | -extern s32 i2c_smbus_write_block_data(const struct i2c_client *client, |
---|
185 | | - u8 command, u8 length, const u8 *values); |
---|
| 172 | +s32 i2c_smbus_read_block_data(const struct i2c_client *client, |
---|
| 173 | + u8 command, u8 *values); |
---|
| 174 | +s32 i2c_smbus_write_block_data(const struct i2c_client *client, |
---|
| 175 | + u8 command, u8 length, const u8 *values); |
---|
186 | 176 | /* Returns the number of read bytes */ |
---|
187 | | -extern s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, |
---|
188 | | - u8 command, u8 length, u8 *values); |
---|
189 | | -extern s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, |
---|
190 | | - u8 command, u8 length, |
---|
191 | | - const u8 *values); |
---|
192 | | -extern s32 |
---|
193 | | -i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client, |
---|
194 | | - u8 command, u8 length, u8 *values); |
---|
| 177 | +s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, |
---|
| 178 | + u8 command, u8 length, u8 *values); |
---|
| 179 | +s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, |
---|
| 180 | + u8 command, u8 length, const u8 *values); |
---|
| 181 | +s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client, |
---|
| 182 | + u8 command, u8 length, |
---|
| 183 | + u8 *values); |
---|
195 | 184 | int i2c_get_device_id(const struct i2c_client *client, |
---|
196 | 185 | struct i2c_device_identity *id); |
---|
197 | 186 | #endif /* I2C */ |
---|
.. | .. |
---|
242 | 231 | * @detect: Callback for device detection |
---|
243 | 232 | * @address_list: The I2C addresses to probe (for detect) |
---|
244 | 233 | * @clients: List of detected clients we created (for i2c-core use only) |
---|
245 | | - * @disable_i2c_core_irq_mapping: Tell the i2c-core to not do irq-mapping |
---|
246 | 234 | * |
---|
247 | 235 | * The driver.owner field should be set to the module owner of this driver. |
---|
248 | 236 | * The driver.name field should be set to the name of this driver. |
---|
.. | .. |
---|
268 | 256 | unsigned int class; |
---|
269 | 257 | |
---|
270 | 258 | /* Standard driver model interfaces */ |
---|
271 | | - int (*probe)(struct i2c_client *, const struct i2c_device_id *); |
---|
272 | | - int (*remove)(struct i2c_client *); |
---|
| 259 | + int (*probe)(struct i2c_client *client, const struct i2c_device_id *id); |
---|
| 260 | + int (*remove)(struct i2c_client *client); |
---|
273 | 261 | |
---|
274 | 262 | /* New driver model interface to aid the seamless removal of the |
---|
275 | 263 | * current probe()'s, more commonly unused than used second parameter. |
---|
276 | 264 | */ |
---|
277 | | - int (*probe_new)(struct i2c_client *); |
---|
| 265 | + int (*probe_new)(struct i2c_client *client); |
---|
278 | 266 | |
---|
279 | 267 | /* driver model interfaces that don't relate to enumeration */ |
---|
280 | | - void (*shutdown)(struct i2c_client *); |
---|
| 268 | + void (*shutdown)(struct i2c_client *client); |
---|
281 | 269 | |
---|
282 | 270 | /* Alert callback, for example for the SMBus alert protocol. |
---|
283 | 271 | * The format and meaning of the data value depends on the protocol. |
---|
.. | .. |
---|
286 | 274 | * For the SMBus Host Notify protocol, the data corresponds to the |
---|
287 | 275 | * 16-bit payload data reported by the slave device acting as master. |
---|
288 | 276 | */ |
---|
289 | | - void (*alert)(struct i2c_client *, enum i2c_alert_protocol protocol, |
---|
| 277 | + void (*alert)(struct i2c_client *client, enum i2c_alert_protocol protocol, |
---|
290 | 278 | unsigned int data); |
---|
291 | 279 | |
---|
292 | 280 | /* a ioctl like command that can be used to perform specific functions |
---|
.. | .. |
---|
298 | 286 | const struct i2c_device_id *id_table; |
---|
299 | 287 | |
---|
300 | 288 | /* Device detection callback for automatic device creation */ |
---|
301 | | - int (*detect)(struct i2c_client *, struct i2c_board_info *); |
---|
| 289 | + int (*detect)(struct i2c_client *client, struct i2c_board_info *info); |
---|
302 | 290 | const unsigned short *address_list; |
---|
303 | 291 | struct list_head clients; |
---|
304 | | - |
---|
305 | | - bool disable_i2c_core_irq_mapping; |
---|
306 | 292 | }; |
---|
307 | 293 | #define to_i2c_driver(d) container_of(d, struct i2c_driver, driver) |
---|
308 | 294 | |
---|
309 | 295 | /** |
---|
310 | 296 | * struct i2c_client - represent an I2C slave device |
---|
311 | | - * @flags: I2C_CLIENT_TEN indicates the device uses a ten bit chip address; |
---|
312 | | - * I2C_CLIENT_PEC indicates it uses SMBus Packet Error Checking |
---|
| 297 | + * @flags: see I2C_CLIENT_* for possible flags |
---|
313 | 298 | * @addr: Address used on the I2C bus connected to the parent adapter. |
---|
314 | 299 | * @name: Indicates the type of the device, usually a chip name that's |
---|
315 | 300 | * generic enough to hide second-sourcing and compatible revisions. |
---|
316 | 301 | * @adapter: manages the bus segment hosting this I2C device |
---|
317 | 302 | * @dev: Driver model device node for the slave. |
---|
| 303 | + * @init_irq: IRQ that was set at initialization |
---|
318 | 304 | * @irq: indicates the IRQ generated by this device (if any) |
---|
319 | 305 | * @detected: member of an i2c_driver.clients list or i2c-core's |
---|
320 | 306 | * userspace_devices list |
---|
.. | .. |
---|
327 | 313 | */ |
---|
328 | 314 | struct i2c_client { |
---|
329 | 315 | unsigned short flags; /* div., see below */ |
---|
| 316 | +#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ |
---|
| 317 | +#define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */ |
---|
| 318 | + /* Must equal I2C_M_TEN below */ |
---|
| 319 | +#define I2C_CLIENT_SLAVE 0x20 /* we are the slave */ |
---|
| 320 | +#define I2C_CLIENT_HOST_NOTIFY 0x40 /* We want to use I2C host notify */ |
---|
| 321 | +#define I2C_CLIENT_WAKE 0x80 /* for board_info; true iff can wake */ |
---|
| 322 | +#define I2C_CLIENT_SCCB 0x9000 /* Use Omnivision SCCB protocol */ |
---|
| 323 | + /* Must match I2C_M_STOP|IGNORE_NAK */ |
---|
| 324 | + |
---|
330 | 325 | unsigned short addr; /* chip address - NOTE: 7bit */ |
---|
331 | 326 | /* addresses are stored in the */ |
---|
332 | 327 | /* _LOWER_ 7 bits */ |
---|
.. | .. |
---|
342 | 337 | }; |
---|
343 | 338 | #define to_i2c_client(d) container_of(d, struct i2c_client, dev) |
---|
344 | 339 | |
---|
345 | | -extern struct i2c_client *i2c_verify_client(struct device *dev); |
---|
346 | | -extern struct i2c_adapter *i2c_verify_adapter(struct device *dev); |
---|
347 | | -extern const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id, |
---|
348 | | - const struct i2c_client *client); |
---|
| 340 | +struct i2c_client *i2c_verify_client(struct device *dev); |
---|
| 341 | +struct i2c_adapter *i2c_verify_adapter(struct device *dev); |
---|
| 342 | +const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id, |
---|
| 343 | + const struct i2c_client *client); |
---|
349 | 344 | |
---|
350 | 345 | static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj) |
---|
351 | 346 | { |
---|
352 | | - struct device * const dev = container_of(kobj, struct device, kobj); |
---|
| 347 | + struct device * const dev = kobj_to_dev(kobj); |
---|
353 | 348 | return to_i2c_client(dev); |
---|
354 | 349 | } |
---|
355 | 350 | |
---|
356 | | -static inline void *i2c_get_clientdata(const struct i2c_client *dev) |
---|
| 351 | +static inline void *i2c_get_clientdata(const struct i2c_client *client) |
---|
357 | 352 | { |
---|
358 | | - return dev_get_drvdata(&dev->dev); |
---|
| 353 | + return dev_get_drvdata(&client->dev); |
---|
359 | 354 | } |
---|
360 | 355 | |
---|
361 | | -static inline void i2c_set_clientdata(struct i2c_client *dev, void *data) |
---|
| 356 | +static inline void i2c_set_clientdata(struct i2c_client *client, void *data) |
---|
362 | 357 | { |
---|
363 | | - dev_set_drvdata(&dev->dev, data); |
---|
| 358 | + dev_set_drvdata(&client->dev, data); |
---|
364 | 359 | } |
---|
365 | 360 | |
---|
366 | 361 | /* I2C slave support */ |
---|
.. | .. |
---|
374 | 369 | I2C_SLAVE_STOP, |
---|
375 | 370 | }; |
---|
376 | 371 | |
---|
377 | | -extern int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb); |
---|
378 | | -extern int i2c_slave_unregister(struct i2c_client *client); |
---|
379 | | -extern bool i2c_detect_slave_mode(struct device *dev); |
---|
| 372 | +int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb); |
---|
| 373 | +int i2c_slave_unregister(struct i2c_client *client); |
---|
| 374 | +bool i2c_detect_slave_mode(struct device *dev); |
---|
380 | 375 | |
---|
381 | 376 | static inline int i2c_slave_event(struct i2c_client *client, |
---|
382 | 377 | enum i2c_slave_event event, u8 *val) |
---|
.. | .. |
---|
410 | 405 | * that are present. This information is used to grow the driver model tree. |
---|
411 | 406 | * For mainboards this is done statically using i2c_register_board_info(); |
---|
412 | 407 | * bus numbers identify adapters that aren't yet available. For add-on boards, |
---|
413 | | - * i2c_new_device() does this dynamically with the adapter already known. |
---|
| 408 | + * i2c_new_client_device() does this dynamically with the adapter already known. |
---|
414 | 409 | */ |
---|
415 | 410 | struct i2c_board_info { |
---|
416 | 411 | char type[I2C_NAME_SIZE]; |
---|
.. | .. |
---|
441 | 436 | |
---|
442 | 437 | |
---|
443 | 438 | #if IS_ENABLED(CONFIG_I2C) |
---|
444 | | -/* Add-on boards should register/unregister their devices; e.g. a board |
---|
| 439 | +/* |
---|
| 440 | + * Add-on boards should register/unregister their devices; e.g. a board |
---|
445 | 441 | * with integrated I2C, a config eeprom, sensors, and a codec that's |
---|
446 | 442 | * used in conjunction with the primary hardware. |
---|
447 | 443 | */ |
---|
448 | | -extern struct i2c_client * |
---|
449 | | -i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info); |
---|
| 444 | +struct i2c_client * |
---|
| 445 | +i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info); |
---|
450 | 446 | |
---|
451 | 447 | /* If you don't know the exact address of an I2C device, use this variant |
---|
452 | 448 | * instead, which can probe for device presence in a list of possible |
---|
.. | .. |
---|
454 | 450 | * it must return 1 on successful probe, 0 otherwise. If it is not provided, |
---|
455 | 451 | * a default probing method is used. |
---|
456 | 452 | */ |
---|
457 | | -extern struct i2c_client * |
---|
458 | | -i2c_new_probed_device(struct i2c_adapter *adap, |
---|
459 | | - struct i2c_board_info *info, |
---|
460 | | - unsigned short const *addr_list, |
---|
461 | | - int (*probe)(struct i2c_adapter *, unsigned short addr)); |
---|
| 453 | +struct i2c_client * |
---|
| 454 | +i2c_new_scanned_device(struct i2c_adapter *adap, |
---|
| 455 | + struct i2c_board_info *info, |
---|
| 456 | + unsigned short const *addr_list, |
---|
| 457 | + int (*probe)(struct i2c_adapter *adap, unsigned short addr)); |
---|
462 | 458 | |
---|
463 | 459 | /* Common custom probe functions */ |
---|
464 | | -extern int i2c_probe_func_quick_read(struct i2c_adapter *, unsigned short addr); |
---|
| 460 | +int i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr); |
---|
465 | 461 | |
---|
466 | | -/* For devices that use several addresses, use i2c_new_dummy() to make |
---|
467 | | - * client handles for the extra addresses. |
---|
468 | | - */ |
---|
469 | | -extern struct i2c_client * |
---|
470 | | -i2c_new_dummy(struct i2c_adapter *adap, u16 address); |
---|
| 462 | +struct i2c_client * |
---|
| 463 | +i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address); |
---|
471 | 464 | |
---|
472 | | -extern struct i2c_client * |
---|
473 | | -i2c_new_secondary_device(struct i2c_client *client, |
---|
474 | | - const char *name, |
---|
475 | | - u16 default_addr); |
---|
| 465 | +struct i2c_client * |
---|
| 466 | +devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address); |
---|
476 | 467 | |
---|
477 | | -extern void i2c_unregister_device(struct i2c_client *); |
---|
| 468 | +struct i2c_client * |
---|
| 469 | +i2c_new_ancillary_device(struct i2c_client *client, |
---|
| 470 | + const char *name, |
---|
| 471 | + u16 default_addr); |
---|
| 472 | + |
---|
| 473 | +void i2c_unregister_device(struct i2c_client *client); |
---|
478 | 474 | #endif /* I2C */ |
---|
479 | 475 | |
---|
480 | 476 | /* Mainboard arch_initcall() code should register all its I2C devices. |
---|
.. | .. |
---|
482 | 478 | * Modules for add-on boards must use other calls. |
---|
483 | 479 | */ |
---|
484 | 480 | #ifdef CONFIG_I2C_BOARDINFO |
---|
485 | | -extern int |
---|
| 481 | +int |
---|
486 | 482 | i2c_register_board_info(int busnum, struct i2c_board_info const *info, |
---|
487 | 483 | unsigned n); |
---|
488 | 484 | #else |
---|
.. | .. |
---|
499 | 495 | * @master_xfer: Issue a set of i2c transactions to the given I2C adapter |
---|
500 | 496 | * defined by the msgs array, with num messages available to transfer via |
---|
501 | 497 | * the adapter specified by adap. |
---|
| 498 | + * @master_xfer_atomic: same as @master_xfer. Yet, only using atomic context |
---|
| 499 | + * so e.g. PMICs can be accessed very late before shutdown. Optional. |
---|
502 | 500 | * @smbus_xfer: Issue smbus transactions to the given I2C adapter. If this |
---|
503 | 501 | * is not present, then the bus layer will try and convert the SMBus calls |
---|
504 | 502 | * into I2C transfers instead. |
---|
| 503 | + * @smbus_xfer_atomic: same as @smbus_xfer. Yet, only using atomic context |
---|
| 504 | + * so e.g. PMICs can be accessed very late before shutdown. Optional. |
---|
505 | 505 | * @functionality: Return the flags that this algorithm/adapter pair supports |
---|
506 | | - * from the I2C_FUNC_* flags. |
---|
| 506 | + * from the ``I2C_FUNC_*`` flags. |
---|
507 | 507 | * @reg_slave: Register given client to I2C slave mode of this adapter |
---|
508 | 508 | * @unreg_slave: Unregister given client from I2C slave mode of this adapter |
---|
509 | 509 | * |
---|
.. | .. |
---|
512 | 512 | * be addressed using the same bus algorithms - i.e. bit-banging or the PCF8584 |
---|
513 | 513 | * to name two of the most common. |
---|
514 | 514 | * |
---|
515 | | - * The return codes from the @master_xfer field should indicate the type of |
---|
516 | | - * error code that occurred during the transfer, as documented in the kernel |
---|
517 | | - * Documentation file Documentation/i2c/fault-codes. |
---|
| 515 | + * The return codes from the ``master_xfer{_atomic}`` fields should indicate the |
---|
| 516 | + * type of error code that occurred during the transfer, as documented in the |
---|
| 517 | + * Kernel Documentation file Documentation/i2c/fault-codes.rst. |
---|
518 | 518 | */ |
---|
519 | 519 | struct i2c_algorithm { |
---|
520 | | - /* If an adapter algorithm can't do I2C-level access, set master_xfer |
---|
521 | | - to NULL. If an adapter algorithm can do SMBus access, set |
---|
522 | | - smbus_xfer. If set to NULL, the SMBus protocol is simulated |
---|
523 | | - using common I2C messages */ |
---|
524 | | - /* master_xfer should return the number of messages successfully |
---|
525 | | - processed, or a negative value on error */ |
---|
| 520 | + /* |
---|
| 521 | + * If an adapter algorithm can't do I2C-level access, set master_xfer |
---|
| 522 | + * to NULL. If an adapter algorithm can do SMBus access, set |
---|
| 523 | + * smbus_xfer. If set to NULL, the SMBus protocol is simulated |
---|
| 524 | + * using common I2C messages. |
---|
| 525 | + * |
---|
| 526 | + * master_xfer should return the number of messages successfully |
---|
| 527 | + * processed, or a negative value on error |
---|
| 528 | + */ |
---|
526 | 529 | int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs, |
---|
527 | 530 | int num); |
---|
528 | | - int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr, |
---|
529 | | - unsigned short flags, char read_write, |
---|
530 | | - u8 command, int size, union i2c_smbus_data *data); |
---|
| 531 | + int (*master_xfer_atomic)(struct i2c_adapter *adap, |
---|
| 532 | + struct i2c_msg *msgs, int num); |
---|
| 533 | + int (*smbus_xfer)(struct i2c_adapter *adap, u16 addr, |
---|
| 534 | + unsigned short flags, char read_write, |
---|
| 535 | + u8 command, int size, union i2c_smbus_data *data); |
---|
| 536 | + int (*smbus_xfer_atomic)(struct i2c_adapter *adap, u16 addr, |
---|
| 537 | + unsigned short flags, char read_write, |
---|
| 538 | + u8 command, int size, union i2c_smbus_data *data); |
---|
531 | 539 | |
---|
532 | 540 | /* To determine what the adapter supports */ |
---|
533 | | - u32 (*functionality) (struct i2c_adapter *); |
---|
| 541 | + u32 (*functionality)(struct i2c_adapter *adap); |
---|
534 | 542 | |
---|
535 | 543 | #if IS_ENABLED(CONFIG_I2C_SLAVE) |
---|
536 | 544 | int (*reg_slave)(struct i2c_client *client); |
---|
.. | .. |
---|
547 | 555 | * The main operations are wrapped by i2c_lock_bus and i2c_unlock_bus. |
---|
548 | 556 | */ |
---|
549 | 557 | struct i2c_lock_operations { |
---|
550 | | - void (*lock_bus)(struct i2c_adapter *, unsigned int flags); |
---|
551 | | - int (*trylock_bus)(struct i2c_adapter *, unsigned int flags); |
---|
552 | | - void (*unlock_bus)(struct i2c_adapter *, unsigned int flags); |
---|
| 558 | + void (*lock_bus)(struct i2c_adapter *adapter, unsigned int flags); |
---|
| 559 | + int (*trylock_bus)(struct i2c_adapter *adapter, unsigned int flags); |
---|
| 560 | + void (*unlock_bus)(struct i2c_adapter *adapter, unsigned int flags); |
---|
553 | 561 | }; |
---|
554 | 562 | |
---|
555 | 563 | /** |
---|
.. | .. |
---|
560 | 568 | * @scl_int_delay_ns: time IP core additionally needs to setup SCL in ns |
---|
561 | 569 | * @sda_fall_ns: time SDA signal takes to fall in ns; t(f) in the I2C specification |
---|
562 | 570 | * @sda_hold_ns: time IP core additionally needs to hold SDA in ns |
---|
| 571 | + * @digital_filter_width_ns: width in ns of spikes on i2c lines that the IP core |
---|
| 572 | + * digital filter can filter out |
---|
| 573 | + * @analog_filter_cutoff_freq_hz: threshold frequency for the low pass IP core |
---|
| 574 | + * analog filter |
---|
563 | 575 | */ |
---|
564 | 576 | struct i2c_timings { |
---|
565 | 577 | u32 bus_freq_hz; |
---|
.. | .. |
---|
568 | 580 | u32 scl_int_delay_ns; |
---|
569 | 581 | u32 sda_fall_ns; |
---|
570 | 582 | u32 sda_hold_ns; |
---|
| 583 | + u32 digital_filter_width_ns; |
---|
| 584 | + u32 analog_filter_cutoff_freq_hz; |
---|
571 | 585 | }; |
---|
572 | 586 | |
---|
573 | 587 | /** |
---|
.. | .. |
---|
592 | 606 | * may configure padmux here for SDA/SCL line or something else they want. |
---|
593 | 607 | * @scl_gpiod: gpiod of the SCL line. Only required for GPIO recovery. |
---|
594 | 608 | * @sda_gpiod: gpiod of the SDA line. Only required for GPIO recovery. |
---|
| 609 | + * @pinctrl: pinctrl used by GPIO recovery to change the state of the I2C pins. |
---|
| 610 | + * Optional. |
---|
| 611 | + * @pins_default: default pinctrl state of SCL/SDA lines, when they are assigned |
---|
| 612 | + * to the I2C bus. Optional. Populated internally for GPIO recovery, if |
---|
| 613 | + * state with the name PINCTRL_STATE_DEFAULT is found and pinctrl is valid. |
---|
| 614 | + * @pins_gpio: recovery pinctrl state of SCL/SDA lines, when they are used as |
---|
| 615 | + * GPIOs. Optional. Populated internally for GPIO recovery, if this state |
---|
| 616 | + * is called "gpio" or "recovery" and pinctrl is valid. |
---|
595 | 617 | */ |
---|
596 | 618 | struct i2c_bus_recovery_info { |
---|
597 | 619 | int (*recover_bus)(struct i2c_adapter *adap); |
---|
.. | .. |
---|
608 | 630 | /* gpio recovery */ |
---|
609 | 631 | struct gpio_desc *scl_gpiod; |
---|
610 | 632 | struct gpio_desc *sda_gpiod; |
---|
| 633 | + struct pinctrl *pinctrl; |
---|
| 634 | + struct pinctrl_state *pins_default; |
---|
| 635 | + struct pinctrl_state *pins_gpio; |
---|
611 | 636 | }; |
---|
612 | 637 | |
---|
613 | 638 | int i2c_recover_bus(struct i2c_adapter *adap); |
---|
.. | .. |
---|
683 | 708 | int timeout; /* in jiffies */ |
---|
684 | 709 | int retries; |
---|
685 | 710 | struct device dev; /* the adapter device */ |
---|
| 711 | + unsigned long locked_flags; /* owned by the I2C core */ |
---|
| 712 | +#define I2C_ALF_IS_SUSPENDED 0 |
---|
| 713 | +#define I2C_ALF_SUSPEND_REPORTED 1 |
---|
686 | 714 | |
---|
687 | 715 | int nr; |
---|
688 | 716 | char name[48]; |
---|
.. | .. |
---|
698 | 726 | }; |
---|
699 | 727 | #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) |
---|
700 | 728 | |
---|
701 | | -static inline void *i2c_get_adapdata(const struct i2c_adapter *dev) |
---|
| 729 | +static inline void *i2c_get_adapdata(const struct i2c_adapter *adap) |
---|
702 | 730 | { |
---|
703 | | - return dev_get_drvdata(&dev->dev); |
---|
| 731 | + return dev_get_drvdata(&adap->dev); |
---|
704 | 732 | } |
---|
705 | 733 | |
---|
706 | | -static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data) |
---|
| 734 | +static inline void i2c_set_adapdata(struct i2c_adapter *adap, void *data) |
---|
707 | 735 | { |
---|
708 | | - dev_set_drvdata(&dev->dev, data); |
---|
| 736 | + dev_set_drvdata(&adap->dev, data); |
---|
709 | 737 | } |
---|
710 | 738 | |
---|
711 | 739 | static inline struct i2c_adapter * |
---|
.. | .. |
---|
721 | 749 | return NULL; |
---|
722 | 750 | } |
---|
723 | 751 | |
---|
724 | | -int i2c_for_each_dev(void *data, int (*fn)(struct device *, void *)); |
---|
| 752 | +int i2c_for_each_dev(void *data, int (*fn)(struct device *dev, void *data)); |
---|
725 | 753 | |
---|
726 | 754 | /* Adapter locking functions, exported for shared pin cases */ |
---|
727 | 755 | #define I2C_LOCK_ROOT_ADAPTER BIT(0) |
---|
.. | .. |
---|
765 | 793 | adapter->lock_ops->unlock_bus(adapter, flags); |
---|
766 | 794 | } |
---|
767 | 795 | |
---|
768 | | -/*flags for the client struct: */ |
---|
769 | | -#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ |
---|
770 | | -#define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */ |
---|
771 | | - /* Must equal I2C_M_TEN below */ |
---|
772 | | -#define I2C_CLIENT_SLAVE 0x20 /* we are the slave */ |
---|
773 | | -#define I2C_CLIENT_HOST_NOTIFY 0x40 /* We want to use I2C host notify */ |
---|
774 | | -#define I2C_CLIENT_WAKE 0x80 /* for board_info; true iff can wake */ |
---|
775 | | -#define I2C_CLIENT_SCCB 0x9000 /* Use Omnivision SCCB protocol */ |
---|
776 | | - /* Must match I2C_M_STOP|IGNORE_NAK */ |
---|
| 796 | +/** |
---|
| 797 | + * i2c_mark_adapter_suspended - Report suspended state of the adapter to the core |
---|
| 798 | + * @adap: Adapter to mark as suspended |
---|
| 799 | + * |
---|
| 800 | + * When using this helper to mark an adapter as suspended, the core will reject |
---|
| 801 | + * further transfers to this adapter. The usage of this helper is optional but |
---|
| 802 | + * recommended for devices having distinct handlers for system suspend and |
---|
| 803 | + * runtime suspend. More complex devices are free to implement custom solutions |
---|
| 804 | + * to reject transfers when suspended. |
---|
| 805 | + */ |
---|
| 806 | +static inline void i2c_mark_adapter_suspended(struct i2c_adapter *adap) |
---|
| 807 | +{ |
---|
| 808 | + i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER); |
---|
| 809 | + set_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags); |
---|
| 810 | + i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER); |
---|
| 811 | +} |
---|
| 812 | + |
---|
| 813 | +/** |
---|
| 814 | + * i2c_mark_adapter_resumed - Report resumed state of the adapter to the core |
---|
| 815 | + * @adap: Adapter to mark as resumed |
---|
| 816 | + * |
---|
| 817 | + * When using this helper to mark an adapter as resumed, the core will allow |
---|
| 818 | + * further transfers to this adapter. See also further notes to |
---|
| 819 | + * @i2c_mark_adapter_suspended(). |
---|
| 820 | + */ |
---|
| 821 | +static inline void i2c_mark_adapter_resumed(struct i2c_adapter *adap) |
---|
| 822 | +{ |
---|
| 823 | + i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER); |
---|
| 824 | + clear_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags); |
---|
| 825 | + i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER); |
---|
| 826 | +} |
---|
777 | 827 | |
---|
778 | 828 | /* i2c adapter classes (bitmask) */ |
---|
779 | 829 | #define I2C_CLASS_HWMON (1<<0) /* lm_sensors, ... */ |
---|
.. | .. |
---|
795 | 845 | /* administration... |
---|
796 | 846 | */ |
---|
797 | 847 | #if IS_ENABLED(CONFIG_I2C) |
---|
798 | | -extern int i2c_add_adapter(struct i2c_adapter *); |
---|
799 | | -extern void i2c_del_adapter(struct i2c_adapter *); |
---|
800 | | -extern int i2c_add_numbered_adapter(struct i2c_adapter *); |
---|
| 848 | +int i2c_add_adapter(struct i2c_adapter *adap); |
---|
| 849 | +void i2c_del_adapter(struct i2c_adapter *adap); |
---|
| 850 | +int i2c_add_numbered_adapter(struct i2c_adapter *adap); |
---|
801 | 851 | |
---|
802 | | -extern int i2c_register_driver(struct module *, struct i2c_driver *); |
---|
803 | | -extern void i2c_del_driver(struct i2c_driver *); |
---|
| 852 | +int i2c_register_driver(struct module *owner, struct i2c_driver *driver); |
---|
| 853 | +void i2c_del_driver(struct i2c_driver *driver); |
---|
804 | 854 | |
---|
805 | 855 | /* use a define to avoid include chaining to get THIS_MODULE */ |
---|
806 | 856 | #define i2c_add_driver(driver) \ |
---|
807 | 857 | i2c_register_driver(THIS_MODULE, driver) |
---|
808 | 858 | |
---|
809 | | -extern struct i2c_client *i2c_use_client(struct i2c_client *client); |
---|
810 | | -extern void i2c_release_client(struct i2c_client *client); |
---|
| 859 | +static inline bool i2c_client_has_driver(struct i2c_client *client) |
---|
| 860 | +{ |
---|
| 861 | + return !IS_ERR_OR_NULL(client) && client->dev.driver; |
---|
| 862 | +} |
---|
811 | 863 | |
---|
812 | 864 | /* call the i2c_client->command() of all attached clients with |
---|
813 | 865 | * the given arguments */ |
---|
814 | | -extern void i2c_clients_command(struct i2c_adapter *adap, |
---|
815 | | - unsigned int cmd, void *arg); |
---|
| 866 | +void i2c_clients_command(struct i2c_adapter *adap, |
---|
| 867 | + unsigned int cmd, void *arg); |
---|
816 | 868 | |
---|
817 | | -extern struct i2c_adapter *i2c_get_adapter(int nr); |
---|
818 | | -extern void i2c_put_adapter(struct i2c_adapter *adap); |
---|
819 | | -extern unsigned int i2c_adapter_depth(struct i2c_adapter *adapter); |
---|
| 869 | +struct i2c_adapter *i2c_get_adapter(int nr); |
---|
| 870 | +void i2c_put_adapter(struct i2c_adapter *adap); |
---|
| 871 | +unsigned int i2c_adapter_depth(struct i2c_adapter *adapter); |
---|
820 | 872 | |
---|
821 | 873 | void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t, bool use_defaults); |
---|
822 | 874 | |
---|
.. | .. |
---|
888 | 940 | |
---|
889 | 941 | #if IS_ENABLED(CONFIG_OF) |
---|
890 | 942 | /* must call put_device() when done with returned i2c_client device */ |
---|
891 | | -extern struct i2c_client *of_find_i2c_device_by_node(struct device_node *node); |
---|
| 943 | +struct i2c_client *of_find_i2c_device_by_node(struct device_node *node); |
---|
892 | 944 | |
---|
893 | 945 | /* must call put_device() when done with returned i2c_adapter device */ |
---|
894 | | -extern struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node); |
---|
| 946 | +struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node); |
---|
895 | 947 | |
---|
896 | 948 | /* must call i2c_put_adapter() when done with returned i2c_adapter device */ |
---|
897 | 949 | struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node); |
---|
898 | 950 | |
---|
899 | | -extern const struct of_device_id |
---|
| 951 | +const struct of_device_id |
---|
900 | 952 | *i2c_of_match_device(const struct of_device_id *matches, |
---|
901 | 953 | struct i2c_client *client); |
---|
902 | 954 | |
---|
.. | .. |
---|
936 | 988 | |
---|
937 | 989 | #endif /* CONFIG_OF */ |
---|
938 | 990 | |
---|
| 991 | +struct acpi_resource; |
---|
| 992 | +struct acpi_resource_i2c_serialbus; |
---|
| 993 | + |
---|
939 | 994 | #if IS_ENABLED(CONFIG_ACPI) |
---|
| 995 | +bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, |
---|
| 996 | + struct acpi_resource_i2c_serialbus **i2c); |
---|
940 | 997 | u32 i2c_acpi_find_bus_speed(struct device *dev); |
---|
941 | 998 | struct i2c_client *i2c_acpi_new_device(struct device *dev, int index, |
---|
942 | 999 | struct i2c_board_info *info); |
---|
| 1000 | +struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle); |
---|
943 | 1001 | #else |
---|
| 1002 | +static inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, |
---|
| 1003 | + struct acpi_resource_i2c_serialbus **i2c) |
---|
| 1004 | +{ |
---|
| 1005 | + return false; |
---|
| 1006 | +} |
---|
944 | 1007 | static inline u32 i2c_acpi_find_bus_speed(struct device *dev) |
---|
945 | 1008 | { |
---|
946 | 1009 | return 0; |
---|
.. | .. |
---|
948 | 1011 | static inline struct i2c_client *i2c_acpi_new_device(struct device *dev, |
---|
949 | 1012 | int index, struct i2c_board_info *info) |
---|
950 | 1013 | { |
---|
| 1014 | + return ERR_PTR(-ENODEV); |
---|
| 1015 | +} |
---|
| 1016 | +static inline struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle) |
---|
| 1017 | +{ |
---|
951 | 1018 | return NULL; |
---|
952 | 1019 | } |
---|
953 | 1020 | #endif /* CONFIG_ACPI */ |
---|