hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/include/linux/i2c.h
....@@ -1,31 +1,16 @@
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
+ */
2610 #ifndef _LINUX_I2C_H
2711 #define _LINUX_I2C_H
2812
13
+#include <linux/acpi.h> /* for acpi_handle */
2914 #include <linux/mod_devicetable.h>
3015 #include <linux/device.h> /* for struct device */
3116 #include <linux/sched.h> /* for completion */
....@@ -51,7 +36,16 @@
5136 union i2c_smbus_data;
5237 struct i2c_board_info;
5338 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
5549
5650 struct module;
5751 struct property_entry;
....@@ -62,10 +56,10 @@
6256 * on a bus (or read from them). Apart from two basic transfer functions to
6357 * transmit one message at a time, a more complex version can be used to
6458 * 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.
6660 */
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);
6963
7064 /**
7165 * i2c_master_recv - issue a single I2C message in master receive mode
....@@ -129,11 +123,9 @@
129123
130124 /* Transfer num messages.
131125 */
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);
134127 /* 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);
137129
138130 /* This is the very generalized SMBus access routine. You probably do not
139131 want to use this, though; one of the functions below may be much easier,
....@@ -152,16 +144,14 @@
152144 /* Now follow the 'nice' access routines. These also document the calling
153145 conventions of i2c_smbus_xfer. */
154146
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);
165155
166156 static inline s32
167157 i2c_smbus_read_word_swapped(const struct i2c_client *client, u8 command)
....@@ -179,19 +169,18 @@
179169 }
180170
181171 /* 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);
186176 /* 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);
195184 int i2c_get_device_id(const struct i2c_client *client,
196185 struct i2c_device_identity *id);
197186 #endif /* I2C */
....@@ -242,7 +231,6 @@
242231 * @detect: Callback for device detection
243232 * @address_list: The I2C addresses to probe (for detect)
244233 * @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
246234 *
247235 * The driver.owner field should be set to the module owner of this driver.
248236 * The driver.name field should be set to the name of this driver.
....@@ -268,16 +256,16 @@
268256 unsigned int class;
269257
270258 /* 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);
273261
274262 /* New driver model interface to aid the seamless removal of the
275263 * current probe()'s, more commonly unused than used second parameter.
276264 */
277
- int (*probe_new)(struct i2c_client *);
265
+ int (*probe_new)(struct i2c_client *client);
278266
279267 /* driver model interfaces that don't relate to enumeration */
280
- void (*shutdown)(struct i2c_client *);
268
+ void (*shutdown)(struct i2c_client *client);
281269
282270 /* Alert callback, for example for the SMBus alert protocol.
283271 * The format and meaning of the data value depends on the protocol.
....@@ -286,7 +274,7 @@
286274 * For the SMBus Host Notify protocol, the data corresponds to the
287275 * 16-bit payload data reported by the slave device acting as master.
288276 */
289
- void (*alert)(struct i2c_client *, enum i2c_alert_protocol protocol,
277
+ void (*alert)(struct i2c_client *client, enum i2c_alert_protocol protocol,
290278 unsigned int data);
291279
292280 /* a ioctl like command that can be used to perform specific functions
....@@ -298,23 +286,21 @@
298286 const struct i2c_device_id *id_table;
299287
300288 /* 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);
302290 const unsigned short *address_list;
303291 struct list_head clients;
304
-
305
- bool disable_i2c_core_irq_mapping;
306292 };
307293 #define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)
308294
309295 /**
310296 * 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
313298 * @addr: Address used on the I2C bus connected to the parent adapter.
314299 * @name: Indicates the type of the device, usually a chip name that's
315300 * generic enough to hide second-sourcing and compatible revisions.
316301 * @adapter: manages the bus segment hosting this I2C device
317302 * @dev: Driver model device node for the slave.
303
+ * @init_irq: IRQ that was set at initialization
318304 * @irq: indicates the IRQ generated by this device (if any)
319305 * @detected: member of an i2c_driver.clients list or i2c-core's
320306 * userspace_devices list
....@@ -327,6 +313,15 @@
327313 */
328314 struct i2c_client {
329315 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
+
330325 unsigned short addr; /* chip address - NOTE: 7bit */
331326 /* addresses are stored in the */
332327 /* _LOWER_ 7 bits */
....@@ -342,25 +337,25 @@
342337 };
343338 #define to_i2c_client(d) container_of(d, struct i2c_client, dev)
344339
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);
349344
350345 static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
351346 {
352
- struct device * const dev = container_of(kobj, struct device, kobj);
347
+ struct device * const dev = kobj_to_dev(kobj);
353348 return to_i2c_client(dev);
354349 }
355350
356
-static inline void *i2c_get_clientdata(const struct i2c_client *dev)
351
+static inline void *i2c_get_clientdata(const struct i2c_client *client)
357352 {
358
- return dev_get_drvdata(&dev->dev);
353
+ return dev_get_drvdata(&client->dev);
359354 }
360355
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)
362357 {
363
- dev_set_drvdata(&dev->dev, data);
358
+ dev_set_drvdata(&client->dev, data);
364359 }
365360
366361 /* I2C slave support */
....@@ -374,9 +369,9 @@
374369 I2C_SLAVE_STOP,
375370 };
376371
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);
380375
381376 static inline int i2c_slave_event(struct i2c_client *client,
382377 enum i2c_slave_event event, u8 *val)
....@@ -410,7 +405,7 @@
410405 * that are present. This information is used to grow the driver model tree.
411406 * For mainboards this is done statically using i2c_register_board_info();
412407 * 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.
414409 */
415410 struct i2c_board_info {
416411 char type[I2C_NAME_SIZE];
....@@ -441,12 +436,13 @@
441436
442437
443438 #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
445441 * with integrated I2C, a config eeprom, sensors, and a codec that's
446442 * used in conjunction with the primary hardware.
447443 */
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);
450446
451447 /* If you don't know the exact address of an I2C device, use this variant
452448 * instead, which can probe for device presence in a list of possible
....@@ -454,27 +450,27 @@
454450 * it must return 1 on successful probe, 0 otherwise. If it is not provided,
455451 * a default probing method is used.
456452 */
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));
462458
463459 /* 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);
465461
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);
471464
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);
476467
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);
478474 #endif /* I2C */
479475
480476 /* Mainboard arch_initcall() code should register all its I2C devices.
....@@ -482,7 +478,7 @@
482478 * Modules for add-on boards must use other calls.
483479 */
484480 #ifdef CONFIG_I2C_BOARDINFO
485
-extern int
481
+int
486482 i2c_register_board_info(int busnum, struct i2c_board_info const *info,
487483 unsigned n);
488484 #else
....@@ -499,11 +495,15 @@
499495 * @master_xfer: Issue a set of i2c transactions to the given I2C adapter
500496 * defined by the msgs array, with num messages available to transfer via
501497 * 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.
502500 * @smbus_xfer: Issue smbus transactions to the given I2C adapter. If this
503501 * is not present, then the bus layer will try and convert the SMBus calls
504502 * 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.
505505 * @functionality: Return the flags that this algorithm/adapter pair supports
506
- * from the I2C_FUNC_* flags.
506
+ * from the ``I2C_FUNC_*`` flags.
507507 * @reg_slave: Register given client to I2C slave mode of this adapter
508508 * @unreg_slave: Unregister given client from I2C slave mode of this adapter
509509 *
....@@ -512,25 +512,33 @@
512512 * be addressed using the same bus algorithms - i.e. bit-banging or the PCF8584
513513 * to name two of the most common.
514514 *
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.
518518 */
519519 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
+ */
526529 int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs,
527530 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);
531539
532540 /* To determine what the adapter supports */
533
- u32 (*functionality) (struct i2c_adapter *);
541
+ u32 (*functionality)(struct i2c_adapter *adap);
534542
535543 #if IS_ENABLED(CONFIG_I2C_SLAVE)
536544 int (*reg_slave)(struct i2c_client *client);
....@@ -547,9 +555,9 @@
547555 * The main operations are wrapped by i2c_lock_bus and i2c_unlock_bus.
548556 */
549557 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);
553561 };
554562
555563 /**
....@@ -560,6 +568,10 @@
560568 * @scl_int_delay_ns: time IP core additionally needs to setup SCL in ns
561569 * @sda_fall_ns: time SDA signal takes to fall in ns; t(f) in the I2C specification
562570 * @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
563575 */
564576 struct i2c_timings {
565577 u32 bus_freq_hz;
....@@ -568,6 +580,8 @@
568580 u32 scl_int_delay_ns;
569581 u32 sda_fall_ns;
570582 u32 sda_hold_ns;
583
+ u32 digital_filter_width_ns;
584
+ u32 analog_filter_cutoff_freq_hz;
571585 };
572586
573587 /**
....@@ -592,6 +606,14 @@
592606 * may configure padmux here for SDA/SCL line or something else they want.
593607 * @scl_gpiod: gpiod of the SCL line. Only required for GPIO recovery.
594608 * @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.
595617 */
596618 struct i2c_bus_recovery_info {
597619 int (*recover_bus)(struct i2c_adapter *adap);
....@@ -608,6 +630,9 @@
608630 /* gpio recovery */
609631 struct gpio_desc *scl_gpiod;
610632 struct gpio_desc *sda_gpiod;
633
+ struct pinctrl *pinctrl;
634
+ struct pinctrl_state *pins_default;
635
+ struct pinctrl_state *pins_gpio;
611636 };
612637
613638 int i2c_recover_bus(struct i2c_adapter *adap);
....@@ -683,6 +708,9 @@
683708 int timeout; /* in jiffies */
684709 int retries;
685710 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
686714
687715 int nr;
688716 char name[48];
....@@ -698,14 +726,14 @@
698726 };
699727 #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
700728
701
-static inline void *i2c_get_adapdata(const struct i2c_adapter *dev)
729
+static inline void *i2c_get_adapdata(const struct i2c_adapter *adap)
702730 {
703
- return dev_get_drvdata(&dev->dev);
731
+ return dev_get_drvdata(&adap->dev);
704732 }
705733
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)
707735 {
708
- dev_set_drvdata(&dev->dev, data);
736
+ dev_set_drvdata(&adap->dev, data);
709737 }
710738
711739 static inline struct i2c_adapter *
....@@ -721,7 +749,7 @@
721749 return NULL;
722750 }
723751
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));
725753
726754 /* Adapter locking functions, exported for shared pin cases */
727755 #define I2C_LOCK_ROOT_ADAPTER BIT(0)
....@@ -765,15 +793,37 @@
765793 adapter->lock_ops->unlock_bus(adapter, flags);
766794 }
767795
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
+}
777827
778828 /* i2c adapter classes (bitmask) */
779829 #define I2C_CLASS_HWMON (1<<0) /* lm_sensors, ... */
....@@ -795,28 +845,30 @@
795845 /* administration...
796846 */
797847 #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);
801851
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);
804854
805855 /* use a define to avoid include chaining to get THIS_MODULE */
806856 #define i2c_add_driver(driver) \
807857 i2c_register_driver(THIS_MODULE, driver)
808858
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
+}
811863
812864 /* call the i2c_client->command() of all attached clients with
813865 * 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);
816868
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);
820872
821873 void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t, bool use_defaults);
822874
....@@ -888,15 +940,15 @@
888940
889941 #if IS_ENABLED(CONFIG_OF)
890942 /* 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);
892944
893945 /* 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);
895947
896948 /* must call i2c_put_adapter() when done with returned i2c_adapter device */
897949 struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node);
898950
899
-extern const struct of_device_id
951
+const struct of_device_id
900952 *i2c_of_match_device(const struct of_device_id *matches,
901953 struct i2c_client *client);
902954
....@@ -936,11 +988,22 @@
936988
937989 #endif /* CONFIG_OF */
938990
991
+struct acpi_resource;
992
+struct acpi_resource_i2c_serialbus;
993
+
939994 #if IS_ENABLED(CONFIG_ACPI)
995
+bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
996
+ struct acpi_resource_i2c_serialbus **i2c);
940997 u32 i2c_acpi_find_bus_speed(struct device *dev);
941998 struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
942999 struct i2c_board_info *info);
1000
+struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle);
9431001 #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
+}
9441007 static inline u32 i2c_acpi_find_bus_speed(struct device *dev)
9451008 {
9461009 return 0;
....@@ -948,6 +1011,10 @@
9481011 static inline struct i2c_client *i2c_acpi_new_device(struct device *dev,
9491012 int index, struct i2c_board_info *info)
9501013 {
1014
+ return ERR_PTR(-ENODEV);
1015
+}
1016
+static inline struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
1017
+{
9511018 return NULL;
9521019 }
9531020 #endif /* CONFIG_ACPI */