0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LINUX_I2C_H
0011 #define _LINUX_I2C_H
0012
0013 #include <linux/acpi.h> /* for acpi_handle */
0014 #include <linux/bits.h>
0015 #include <linux/mod_devicetable.h>
0016 #include <linux/device.h> /* for struct device */
0017 #include <linux/sched.h> /* for completion */
0018 #include <linux/mutex.h>
0019 #include <linux/regulator/consumer.h>
0020 #include <linux/rtmutex.h>
0021 #include <linux/irqdomain.h> /* for Host Notify IRQ */
0022 #include <linux/of.h> /* for struct device_node */
0023 #include <linux/swab.h> /* for swab16 */
0024 #include <uapi/linux/i2c.h>
0025
0026 extern struct bus_type i2c_bus_type;
0027 extern struct device_type i2c_adapter_type;
0028 extern struct device_type i2c_client_type;
0029
0030
0031
0032 struct i2c_msg;
0033 struct i2c_algorithm;
0034 struct i2c_adapter;
0035 struct i2c_client;
0036 struct i2c_driver;
0037 struct i2c_device_identity;
0038 union i2c_smbus_data;
0039 struct i2c_board_info;
0040 enum i2c_slave_event;
0041 typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
0042 enum i2c_slave_event event, u8 *val);
0043
0044
0045 #define I2C_MAX_STANDARD_MODE_FREQ 100000
0046 #define I2C_MAX_FAST_MODE_FREQ 400000
0047 #define I2C_MAX_FAST_MODE_PLUS_FREQ 1000000
0048 #define I2C_MAX_TURBO_MODE_FREQ 1400000
0049 #define I2C_MAX_HIGH_SPEED_MODE_FREQ 3400000
0050 #define I2C_MAX_ULTRA_FAST_MODE_FREQ 5000000
0051
0052 struct module;
0053 struct property_entry;
0054
0055 #if IS_ENABLED(CONFIG_I2C)
0056
0057 const char *i2c_freq_mode_string(u32 bus_freq_hz);
0058
0059
0060
0061
0062
0063
0064
0065
0066 int i2c_transfer_buffer_flags(const struct i2c_client *client,
0067 char *buf, int count, u16 flags);
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 static inline int i2c_master_recv(const struct i2c_client *client,
0078 char *buf, int count)
0079 {
0080 return i2c_transfer_buffer_flags(client, buf, count, I2C_M_RD);
0081 };
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092 static inline int i2c_master_recv_dmasafe(const struct i2c_client *client,
0093 char *buf, int count)
0094 {
0095 return i2c_transfer_buffer_flags(client, buf, count,
0096 I2C_M_RD | I2C_M_DMA_SAFE);
0097 };
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107 static inline int i2c_master_send(const struct i2c_client *client,
0108 const char *buf, int count)
0109 {
0110 return i2c_transfer_buffer_flags(client, (char *)buf, count, 0);
0111 };
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122 static inline int i2c_master_send_dmasafe(const struct i2c_client *client,
0123 const char *buf, int count)
0124 {
0125 return i2c_transfer_buffer_flags(client, (char *)buf, count,
0126 I2C_M_DMA_SAFE);
0127 };
0128
0129
0130
0131 int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
0132
0133 int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
0134
0135
0136
0137
0138
0139
0140 s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
0141 unsigned short flags, char read_write, u8 command,
0142 int protocol, union i2c_smbus_data *data);
0143
0144
0145 s32 __i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
0146 unsigned short flags, char read_write, u8 command,
0147 int protocol, union i2c_smbus_data *data);
0148
0149
0150
0151
0152 u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count);
0153 s32 i2c_smbus_read_byte(const struct i2c_client *client);
0154 s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value);
0155 s32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command);
0156 s32 i2c_smbus_write_byte_data(const struct i2c_client *client,
0157 u8 command, u8 value);
0158 s32 i2c_smbus_read_word_data(const struct i2c_client *client, u8 command);
0159 s32 i2c_smbus_write_word_data(const struct i2c_client *client,
0160 u8 command, u16 value);
0161
0162 static inline s32
0163 i2c_smbus_read_word_swapped(const struct i2c_client *client, u8 command)
0164 {
0165 s32 value = i2c_smbus_read_word_data(client, command);
0166
0167 return (value < 0) ? value : swab16(value);
0168 }
0169
0170 static inline s32
0171 i2c_smbus_write_word_swapped(const struct i2c_client *client,
0172 u8 command, u16 value)
0173 {
0174 return i2c_smbus_write_word_data(client, command, swab16(value));
0175 }
0176
0177
0178 s32 i2c_smbus_read_block_data(const struct i2c_client *client,
0179 u8 command, u8 *values);
0180 s32 i2c_smbus_write_block_data(const struct i2c_client *client,
0181 u8 command, u8 length, const u8 *values);
0182
0183 s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client,
0184 u8 command, u8 length, u8 *values);
0185 s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client,
0186 u8 command, u8 length, const u8 *values);
0187 s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client,
0188 u8 command, u8 length,
0189 u8 *values);
0190 int i2c_get_device_id(const struct i2c_client *client,
0191 struct i2c_device_identity *id);
0192 #endif
0193
0194
0195
0196
0197
0198
0199
0200 struct i2c_device_identity {
0201 u16 manufacturer_id;
0202 #define I2C_DEVICE_ID_NXP_SEMICONDUCTORS 0
0203 #define I2C_DEVICE_ID_NXP_SEMICONDUCTORS_1 1
0204 #define I2C_DEVICE_ID_NXP_SEMICONDUCTORS_2 2
0205 #define I2C_DEVICE_ID_NXP_SEMICONDUCTORS_3 3
0206 #define I2C_DEVICE_ID_RAMTRON_INTERNATIONAL 4
0207 #define I2C_DEVICE_ID_ANALOG_DEVICES 5
0208 #define I2C_DEVICE_ID_STMICROELECTRONICS 6
0209 #define I2C_DEVICE_ID_ON_SEMICONDUCTOR 7
0210 #define I2C_DEVICE_ID_SPRINTEK_CORPORATION 8
0211 #define I2C_DEVICE_ID_ESPROS_PHOTONICS_AG 9
0212 #define I2C_DEVICE_ID_FUJITSU_SEMICONDUCTOR 10
0213 #define I2C_DEVICE_ID_FLIR 11
0214 #define I2C_DEVICE_ID_O2MICRO 12
0215 #define I2C_DEVICE_ID_ATMEL 13
0216 #define I2C_DEVICE_ID_NONE 0xffff
0217 u16 part_id;
0218 u8 die_revision;
0219 };
0220
0221 enum i2c_alert_protocol {
0222 I2C_PROTOCOL_SMBUS_ALERT,
0223 I2C_PROTOCOL_SMBUS_HOST_NOTIFY,
0224 };
0225
0226
0227
0228
0229
0230
0231 enum i2c_driver_flags {
0232 I2C_DRV_ACPI_WAIVE_D0_PROBE = BIT(0),
0233 };
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271 struct i2c_driver {
0272 unsigned int class;
0273
0274
0275 int (*probe)(struct i2c_client *client, const struct i2c_device_id *id);
0276 int (*remove)(struct i2c_client *client);
0277
0278
0279
0280
0281 int (*probe_new)(struct i2c_client *client);
0282
0283
0284 void (*shutdown)(struct i2c_client *client);
0285
0286
0287
0288
0289
0290
0291
0292
0293 void (*alert)(struct i2c_client *client, enum i2c_alert_protocol protocol,
0294 unsigned int data);
0295
0296
0297
0298
0299 int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);
0300
0301 struct device_driver driver;
0302 const struct i2c_device_id *id_table;
0303
0304
0305 int (*detect)(struct i2c_client *client, struct i2c_board_info *info);
0306 const unsigned short *address_list;
0307 struct list_head clients;
0308
0309 u32 flags;
0310 };
0311 #define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334 struct i2c_client {
0335 unsigned short flags;
0336 #define I2C_CLIENT_PEC 0x04
0337 #define I2C_CLIENT_TEN 0x10
0338
0339 #define I2C_CLIENT_SLAVE 0x20
0340 #define I2C_CLIENT_HOST_NOTIFY 0x40
0341 #define I2C_CLIENT_WAKE 0x80
0342 #define I2C_CLIENT_SCCB 0x9000
0343
0344
0345 unsigned short addr;
0346
0347
0348 char name[I2C_NAME_SIZE];
0349 struct i2c_adapter *adapter;
0350 struct device dev;
0351 int init_irq;
0352 int irq;
0353 struct list_head detected;
0354 #if IS_ENABLED(CONFIG_I2C_SLAVE)
0355 i2c_slave_cb_t slave_cb;
0356 #endif
0357 void *devres_group_id;
0358 };
0359 #define to_i2c_client(d) container_of(d, struct i2c_client, dev)
0360
0361 struct i2c_adapter *i2c_verify_adapter(struct device *dev);
0362 const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
0363 const struct i2c_client *client);
0364
0365 static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
0366 {
0367 struct device * const dev = kobj_to_dev(kobj);
0368 return to_i2c_client(dev);
0369 }
0370
0371 static inline void *i2c_get_clientdata(const struct i2c_client *client)
0372 {
0373 return dev_get_drvdata(&client->dev);
0374 }
0375
0376 static inline void i2c_set_clientdata(struct i2c_client *client, void *data)
0377 {
0378 dev_set_drvdata(&client->dev, data);
0379 }
0380
0381
0382
0383 #if IS_ENABLED(CONFIG_I2C_SLAVE)
0384 enum i2c_slave_event {
0385 I2C_SLAVE_READ_REQUESTED,
0386 I2C_SLAVE_WRITE_REQUESTED,
0387 I2C_SLAVE_READ_PROCESSED,
0388 I2C_SLAVE_WRITE_RECEIVED,
0389 I2C_SLAVE_STOP,
0390 };
0391
0392 int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb);
0393 int i2c_slave_unregister(struct i2c_client *client);
0394 bool i2c_detect_slave_mode(struct device *dev);
0395 int i2c_slave_event(struct i2c_client *client,
0396 enum i2c_slave_event event, u8 *val);
0397 #else
0398 static inline bool i2c_detect_slave_mode(struct device *dev) { return false; }
0399 #endif
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424
0425
0426 struct i2c_board_info {
0427 char type[I2C_NAME_SIZE];
0428 unsigned short flags;
0429 unsigned short addr;
0430 const char *dev_name;
0431 void *platform_data;
0432 struct device_node *of_node;
0433 struct fwnode_handle *fwnode;
0434 const struct software_node *swnode;
0435 const struct resource *resources;
0436 unsigned int num_resources;
0437 int irq;
0438 };
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450 #define I2C_BOARD_INFO(dev_type, dev_addr) \
0451 .type = dev_type, .addr = (dev_addr)
0452
0453
0454 #if IS_ENABLED(CONFIG_I2C)
0455
0456
0457
0458
0459
0460 struct i2c_client *
0461 i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info);
0462
0463
0464
0465
0466
0467
0468
0469 struct i2c_client *
0470 i2c_new_scanned_device(struct i2c_adapter *adap,
0471 struct i2c_board_info *info,
0472 unsigned short const *addr_list,
0473 int (*probe)(struct i2c_adapter *adap, unsigned short addr));
0474
0475
0476 int i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr);
0477
0478 struct i2c_client *
0479 i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address);
0480
0481 struct i2c_client *
0482 devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address);
0483
0484 struct i2c_client *
0485 i2c_new_ancillary_device(struct i2c_client *client,
0486 const char *name,
0487 u16 default_addr);
0488
0489 void i2c_unregister_device(struct i2c_client *client);
0490
0491 struct i2c_client *i2c_verify_client(struct device *dev);
0492 #else
0493 static inline struct i2c_client *i2c_verify_client(struct device *dev)
0494 {
0495 return NULL;
0496 }
0497 #endif
0498
0499
0500
0501
0502
0503 #ifdef CONFIG_I2C_BOARDINFO
0504 int
0505 i2c_register_board_info(int busnum, struct i2c_board_info const *info,
0506 unsigned n);
0507 #else
0508 static inline int
0509 i2c_register_board_info(int busnum, struct i2c_board_info const *info,
0510 unsigned n)
0511 {
0512 return 0;
0513 }
0514 #endif
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543 struct i2c_algorithm {
0544
0545
0546
0547
0548
0549
0550
0551
0552
0553 int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs,
0554 int num);
0555 int (*master_xfer_atomic)(struct i2c_adapter *adap,
0556 struct i2c_msg *msgs, int num);
0557 int (*smbus_xfer)(struct i2c_adapter *adap, u16 addr,
0558 unsigned short flags, char read_write,
0559 u8 command, int size, union i2c_smbus_data *data);
0560 int (*smbus_xfer_atomic)(struct i2c_adapter *adap, u16 addr,
0561 unsigned short flags, char read_write,
0562 u8 command, int size, union i2c_smbus_data *data);
0563
0564
0565 u32 (*functionality)(struct i2c_adapter *adap);
0566
0567 #if IS_ENABLED(CONFIG_I2C_SLAVE)
0568 int (*reg_slave)(struct i2c_client *client);
0569 int (*unreg_slave)(struct i2c_client *client);
0570 #endif
0571 };
0572
0573
0574
0575
0576
0577
0578
0579
0580
0581 struct i2c_lock_operations {
0582 void (*lock_bus)(struct i2c_adapter *adapter, unsigned int flags);
0583 int (*trylock_bus)(struct i2c_adapter *adapter, unsigned int flags);
0584 void (*unlock_bus)(struct i2c_adapter *adapter, unsigned int flags);
0585 };
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600 struct i2c_timings {
0601 u32 bus_freq_hz;
0602 u32 scl_rise_ns;
0603 u32 scl_fall_ns;
0604 u32 scl_int_delay_ns;
0605 u32 sda_fall_ns;
0606 u32 sda_hold_ns;
0607 u32 digital_filter_width_ns;
0608 u32 analog_filter_cutoff_freq_hz;
0609 };
0610
0611
0612
0613
0614
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625
0626
0627
0628
0629
0630
0631
0632
0633
0634
0635
0636
0637
0638
0639
0640
0641
0642 struct i2c_bus_recovery_info {
0643 int (*recover_bus)(struct i2c_adapter *adap);
0644
0645 int (*get_scl)(struct i2c_adapter *adap);
0646 void (*set_scl)(struct i2c_adapter *adap, int val);
0647 int (*get_sda)(struct i2c_adapter *adap);
0648 void (*set_sda)(struct i2c_adapter *adap, int val);
0649 int (*get_bus_free)(struct i2c_adapter *adap);
0650
0651 void (*prepare_recovery)(struct i2c_adapter *adap);
0652 void (*unprepare_recovery)(struct i2c_adapter *adap);
0653
0654
0655 struct gpio_desc *scl_gpiod;
0656 struct gpio_desc *sda_gpiod;
0657 struct pinctrl *pinctrl;
0658 struct pinctrl_state *pins_default;
0659 struct pinctrl_state *pins_gpio;
0660 };
0661
0662 int i2c_recover_bus(struct i2c_adapter *adap);
0663
0664
0665 int i2c_generic_scl_recovery(struct i2c_adapter *adap);
0666
0667
0668
0669
0670
0671
0672
0673
0674
0675
0676
0677
0678
0679
0680
0681
0682
0683
0684
0685
0686
0687
0688 struct i2c_adapter_quirks {
0689 u64 flags;
0690 int max_num_msgs;
0691 u16 max_write_len;
0692 u16 max_read_len;
0693 u16 max_comb_1st_msg_len;
0694 u16 max_comb_2nd_msg_len;
0695 };
0696
0697
0698 #define I2C_AQ_COMB BIT(0)
0699
0700 #define I2C_AQ_COMB_WRITE_FIRST BIT(1)
0701
0702 #define I2C_AQ_COMB_READ_SECOND BIT(2)
0703
0704 #define I2C_AQ_COMB_SAME_ADDR BIT(3)
0705
0706 #define I2C_AQ_COMB_WRITE_THEN_READ (I2C_AQ_COMB | I2C_AQ_COMB_WRITE_FIRST | \
0707 I2C_AQ_COMB_READ_SECOND | I2C_AQ_COMB_SAME_ADDR)
0708
0709 #define I2C_AQ_NO_CLK_STRETCH BIT(4)
0710
0711 #define I2C_AQ_NO_ZERO_LEN_READ BIT(5)
0712 #define I2C_AQ_NO_ZERO_LEN_WRITE BIT(6)
0713 #define I2C_AQ_NO_ZERO_LEN (I2C_AQ_NO_ZERO_LEN_READ | I2C_AQ_NO_ZERO_LEN_WRITE)
0714
0715 #define I2C_AQ_NO_REP_START BIT(7)
0716
0717
0718
0719
0720
0721 struct i2c_adapter {
0722 struct module *owner;
0723 unsigned int class;
0724 const struct i2c_algorithm *algo;
0725 void *algo_data;
0726
0727
0728 const struct i2c_lock_operations *lock_ops;
0729 struct rt_mutex bus_lock;
0730 struct rt_mutex mux_lock;
0731
0732 int timeout;
0733 int retries;
0734 struct device dev;
0735 unsigned long locked_flags;
0736 #define I2C_ALF_IS_SUSPENDED 0
0737 #define I2C_ALF_SUSPEND_REPORTED 1
0738
0739 int nr;
0740 char name[48];
0741 struct completion dev_released;
0742
0743 struct mutex userspace_clients_lock;
0744 struct list_head userspace_clients;
0745
0746 struct i2c_bus_recovery_info *bus_recovery_info;
0747 const struct i2c_adapter_quirks *quirks;
0748
0749 struct irq_domain *host_notify_domain;
0750 struct regulator *bus_regulator;
0751 };
0752 #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
0753
0754 static inline void *i2c_get_adapdata(const struct i2c_adapter *adap)
0755 {
0756 return dev_get_drvdata(&adap->dev);
0757 }
0758
0759 static inline void i2c_set_adapdata(struct i2c_adapter *adap, void *data)
0760 {
0761 dev_set_drvdata(&adap->dev, data);
0762 }
0763
0764 static inline struct i2c_adapter *
0765 i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter)
0766 {
0767 #if IS_ENABLED(CONFIG_I2C_MUX)
0768 struct device *parent = adapter->dev.parent;
0769
0770 if (parent != NULL && parent->type == &i2c_adapter_type)
0771 return to_i2c_adapter(parent);
0772 else
0773 #endif
0774 return NULL;
0775 }
0776
0777 int i2c_for_each_dev(void *data, int (*fn)(struct device *dev, void *data));
0778
0779
0780 #define I2C_LOCK_ROOT_ADAPTER BIT(0)
0781 #define I2C_LOCK_SEGMENT BIT(1)
0782
0783
0784
0785
0786
0787
0788
0789 static inline void
0790 i2c_lock_bus(struct i2c_adapter *adapter, unsigned int flags)
0791 {
0792 adapter->lock_ops->lock_bus(adapter, flags);
0793 }
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803 static inline int
0804 i2c_trylock_bus(struct i2c_adapter *adapter, unsigned int flags)
0805 {
0806 return adapter->lock_ops->trylock_bus(adapter, flags);
0807 }
0808
0809
0810
0811
0812
0813
0814
0815 static inline void
0816 i2c_unlock_bus(struct i2c_adapter *adapter, unsigned int flags)
0817 {
0818 adapter->lock_ops->unlock_bus(adapter, flags);
0819 }
0820
0821
0822
0823
0824
0825
0826
0827
0828
0829
0830
0831 static inline void i2c_mark_adapter_suspended(struct i2c_adapter *adap)
0832 {
0833 i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
0834 set_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags);
0835 i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
0836 }
0837
0838
0839
0840
0841
0842
0843
0844
0845
0846 static inline void i2c_mark_adapter_resumed(struct i2c_adapter *adap)
0847 {
0848 i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
0849 clear_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags);
0850 i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
0851 }
0852
0853
0854 #define I2C_CLASS_HWMON (1<<0)
0855 #define I2C_CLASS_DDC (1<<3)
0856 #define I2C_CLASS_SPD (1<<7)
0857
0858 #define I2C_CLASS_DEPRECATED (1<<8)
0859
0860
0861 #define I2C_CLIENT_END 0xfffeU
0862
0863
0864 #define I2C_ADDRS(addr, addrs...) \
0865 ((const unsigned short []){ addr, ## addrs, I2C_CLIENT_END })
0866
0867
0868
0869
0870
0871
0872 #if IS_ENABLED(CONFIG_I2C)
0873 int i2c_add_adapter(struct i2c_adapter *adap);
0874 int devm_i2c_add_adapter(struct device *dev, struct i2c_adapter *adapter);
0875 void i2c_del_adapter(struct i2c_adapter *adap);
0876 int i2c_add_numbered_adapter(struct i2c_adapter *adap);
0877
0878 int i2c_register_driver(struct module *owner, struct i2c_driver *driver);
0879 void i2c_del_driver(struct i2c_driver *driver);
0880
0881
0882 #define i2c_add_driver(driver) \
0883 i2c_register_driver(THIS_MODULE, driver)
0884
0885 static inline bool i2c_client_has_driver(struct i2c_client *client)
0886 {
0887 return !IS_ERR_OR_NULL(client) && client->dev.driver;
0888 }
0889
0890
0891
0892 void i2c_clients_command(struct i2c_adapter *adap,
0893 unsigned int cmd, void *arg);
0894
0895 struct i2c_adapter *i2c_get_adapter(int nr);
0896 void i2c_put_adapter(struct i2c_adapter *adap);
0897 unsigned int i2c_adapter_depth(struct i2c_adapter *adapter);
0898
0899 void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t, bool use_defaults);
0900
0901
0902 static inline u32 i2c_get_functionality(struct i2c_adapter *adap)
0903 {
0904 return adap->algo->functionality(adap);
0905 }
0906
0907
0908 static inline int i2c_check_functionality(struct i2c_adapter *adap, u32 func)
0909 {
0910 return (func & i2c_get_functionality(adap)) == func;
0911 }
0912
0913
0914
0915
0916
0917
0918
0919
0920 static inline bool i2c_check_quirks(struct i2c_adapter *adap, u64 quirks)
0921 {
0922 if (!adap->quirks)
0923 return false;
0924 return (adap->quirks->flags & quirks) == quirks;
0925 }
0926
0927
0928 static inline int i2c_adapter_id(struct i2c_adapter *adap)
0929 {
0930 return adap->nr;
0931 }
0932
0933 static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
0934 {
0935 return (msg->addr << 1) | (msg->flags & I2C_M_RD ? 1 : 0);
0936 }
0937
0938 u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold);
0939 void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred);
0940
0941 int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr);
0942
0943
0944
0945
0946
0947
0948
0949
0950 #define module_i2c_driver(__i2c_driver) \
0951 module_driver(__i2c_driver, i2c_add_driver, \
0952 i2c_del_driver)
0953
0954
0955
0956
0957
0958
0959
0960
0961
0962 #define builtin_i2c_driver(__i2c_driver) \
0963 builtin_driver(__i2c_driver, i2c_add_driver)
0964
0965 #endif
0966
0967 #if IS_ENABLED(CONFIG_OF)
0968
0969 struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
0970
0971
0972 struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node);
0973
0974
0975 struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node);
0976
0977 const struct of_device_id
0978 *i2c_of_match_device(const struct of_device_id *matches,
0979 struct i2c_client *client);
0980
0981 int of_i2c_get_board_info(struct device *dev, struct device_node *node,
0982 struct i2c_board_info *info);
0983
0984 #else
0985
0986 static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
0987 {
0988 return NULL;
0989 }
0990
0991 static inline struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
0992 {
0993 return NULL;
0994 }
0995
0996 static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)
0997 {
0998 return NULL;
0999 }
1000
1001 static inline const struct of_device_id
1002 *i2c_of_match_device(const struct of_device_id *matches,
1003 struct i2c_client *client)
1004 {
1005 return NULL;
1006 }
1007
1008 static inline int of_i2c_get_board_info(struct device *dev,
1009 struct device_node *node,
1010 struct i2c_board_info *info)
1011 {
1012 return -ENOTSUPP;
1013 }
1014
1015 #endif
1016
1017 struct acpi_resource;
1018 struct acpi_resource_i2c_serialbus;
1019
1020 #if IS_ENABLED(CONFIG_ACPI)
1021 bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
1022 struct acpi_resource_i2c_serialbus **i2c);
1023 int i2c_acpi_client_count(struct acpi_device *adev);
1024 u32 i2c_acpi_find_bus_speed(struct device *dev);
1025 struct i2c_client *i2c_acpi_new_device_by_fwnode(struct fwnode_handle *fwnode,
1026 int index,
1027 struct i2c_board_info *info);
1028 struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle);
1029 bool i2c_acpi_waive_d0_probe(struct device *dev);
1030 #else
1031 static inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
1032 struct acpi_resource_i2c_serialbus **i2c)
1033 {
1034 return false;
1035 }
1036 static inline int i2c_acpi_client_count(struct acpi_device *adev)
1037 {
1038 return 0;
1039 }
1040 static inline u32 i2c_acpi_find_bus_speed(struct device *dev)
1041 {
1042 return 0;
1043 }
1044 static inline struct i2c_client *i2c_acpi_new_device_by_fwnode(
1045 struct fwnode_handle *fwnode, int index,
1046 struct i2c_board_info *info)
1047 {
1048 return ERR_PTR(-ENODEV);
1049 }
1050 static inline struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
1051 {
1052 return NULL;
1053 }
1054 static inline bool i2c_acpi_waive_d0_probe(struct device *dev)
1055 {
1056 return false;
1057 }
1058 #endif
1059
1060 static inline struct i2c_client *i2c_acpi_new_device(struct device *dev,
1061 int index,
1062 struct i2c_board_info *info)
1063 {
1064 return i2c_acpi_new_device_by_fwnode(dev_fwnode(dev), index, info);
1065 }
1066
1067 #endif