aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/i2c.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/i2c.h')
-rw-r--r--include/linux/i2c.h112
1 files changed, 88 insertions, 24 deletions
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 0f774406fad0..419a38e7c315 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -55,7 +55,7 @@ typedef int (*i2c_slave_cb_t)(struct i2c_client *, enum i2c_slave_event, u8 *);
55struct module; 55struct module;
56struct property_entry; 56struct property_entry;
57 57
58#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 58#if IS_ENABLED(CONFIG_I2C)
59/* 59/*
60 * The master routines are the ones normally used to transmit data to devices 60 * The master routines are the ones normally used to transmit data to devices
61 * on a bus (or read from them). Apart from two basic transfer functions to 61 * on a bus (or read from them). Apart from two basic transfer functions to
@@ -63,10 +63,68 @@ struct property_entry;
63 * transmit an arbitrary number of messages without interruption. 63 * transmit an arbitrary number of messages without interruption.
64 * @count must be be less than 64k since msg.len is u16. 64 * @count must be be less than 64k since msg.len is u16.
65 */ 65 */
66extern int i2c_master_send(const struct i2c_client *client, const char *buf, 66extern int i2c_transfer_buffer_flags(const struct i2c_client *client,
67 int count); 67 char *buf, int count, u16 flags);
68extern int i2c_master_recv(const struct i2c_client *client, char *buf, 68
69 int count); 69/**
70 * i2c_master_recv - issue a single I2C message in master receive mode
71 * @client: Handle to slave device
72 * @buf: Where to store data read from slave
73 * @count: How many bytes to read, must be less than 64k since msg.len is u16
74 *
75 * Returns negative errno, or else the number of bytes read.
76 */
77static inline int i2c_master_recv(const struct i2c_client *client,
78 char *buf, int count)
79{
80 return i2c_transfer_buffer_flags(client, buf, count, I2C_M_RD);
81};
82
83/**
84 * i2c_master_recv_dmasafe - issue a single I2C message in master receive mode
85 * using a DMA safe buffer
86 * @client: Handle to slave device
87 * @buf: Where to store data read from slave, must be safe to use with DMA
88 * @count: How many bytes to read, must be less than 64k since msg.len is u16
89 *
90 * Returns negative errno, or else the number of bytes read.
91 */
92static inline int i2c_master_recv_dmasafe(const struct i2c_client *client,
93 char *buf, int count)
94{
95 return i2c_transfer_buffer_flags(client, buf, count,
96 I2C_M_RD | I2C_M_DMA_SAFE);
97};
98
99/**
100 * i2c_master_send - issue a single I2C message in master transmit mode
101 * @client: Handle to slave device
102 * @buf: Data that will be written to the slave
103 * @count: How many bytes to write, must be less than 64k since msg.len is u16
104 *
105 * Returns negative errno, or else the number of bytes written.
106 */
107static inline int i2c_master_send(const struct i2c_client *client,
108 const char *buf, int count)
109{
110 return i2c_transfer_buffer_flags(client, (char *)buf, count, 0);
111};
112
113/**
114 * i2c_master_send_dmasafe - issue a single I2C message in master transmit mode
115 * using a DMA safe buffer
116 * @client: Handle to slave device
117 * @buf: Data that will be written to the slave, must be safe to use with DMA
118 * @count: How many bytes to write, must be less than 64k since msg.len is u16
119 *
120 * Returns negative errno, or else the number of bytes written.
121 */
122static inline int i2c_master_send_dmasafe(const struct i2c_client *client,
123 const char *buf, int count)
124{
125 return i2c_transfer_buffer_flags(client, (char *)buf, count,
126 I2C_M_DMA_SAFE);
127};
70 128
71/* Transfer num messages. 129/* Transfer num messages.
72 */ 130 */
@@ -354,7 +412,7 @@ struct i2c_board_info {
354 .type = dev_type, .addr = (dev_addr) 412 .type = dev_type, .addr = (dev_addr)
355 413
356 414
357#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 415#if IS_ENABLED(CONFIG_I2C)
358/* Add-on boards should register/unregister their devices; e.g. a board 416/* Add-on boards should register/unregister their devices; e.g. a board
359 * with integrated I2C, a config eeprom, sensors, and a codec that's 417 * with integrated I2C, a config eeprom, sensors, and a codec that's
360 * used in conjunction with the primary hardware. 418 * used in conjunction with the primary hardware.
@@ -485,40 +543,43 @@ struct i2c_timings {
485/** 543/**
486 * struct i2c_bus_recovery_info - I2C bus recovery information 544 * struct i2c_bus_recovery_info - I2C bus recovery information
487 * @recover_bus: Recover routine. Either pass driver's recover_bus() routine, or 545 * @recover_bus: Recover routine. Either pass driver's recover_bus() routine, or
488 * i2c_generic_scl_recovery() or i2c_generic_gpio_recovery(). 546 * i2c_generic_scl_recovery().
489 * @get_scl: This gets current value of SCL line. Mandatory for generic SCL 547 * @get_scl: This gets current value of SCL line. Mandatory for generic SCL
490 * recovery. Used internally for generic GPIO recovery. 548 * recovery. Populated internally for generic GPIO recovery.
491 * @set_scl: This sets/clears SCL line. Mandatory for generic SCL recovery. Used 549 * @set_scl: This sets/clears the SCL line. Mandatory for generic SCL recovery.
492 * internally for generic GPIO recovery. 550 * Populated internally for generic GPIO recovery.
493 * @get_sda: This gets current value of SDA line. Optional for generic SCL 551 * @get_sda: This gets current value of SDA line. Optional for generic SCL
494 * recovery. Used internally, if sda_gpio is a valid GPIO, for generic GPIO 552 * recovery. Populated internally, if sda_gpio is a valid GPIO, for generic
495 * recovery. 553 * GPIO recovery.
554 * @set_sda: This sets/clears the SDA line. Optional for generic SCL recovery.
555 * Populated internally, if sda_gpio is a valid GPIO, for generic GPIO
556 * recovery.
496 * @prepare_recovery: This will be called before starting recovery. Platform may 557 * @prepare_recovery: This will be called before starting recovery. Platform may
497 * configure padmux here for SDA/SCL line or something else they want. 558 * configure padmux here for SDA/SCL line or something else they want.
498 * @unprepare_recovery: This will be called after completing recovery. Platform 559 * @unprepare_recovery: This will be called after completing recovery. Platform
499 * may configure padmux here for SDA/SCL line or something else they want. 560 * may configure padmux here for SDA/SCL line or something else they want.
500 * @scl_gpio: gpio number of the SCL line. Only required for GPIO recovery. 561 * @scl_gpiod: gpiod of the SCL line. Only required for GPIO recovery.
501 * @sda_gpio: gpio number of the SDA line. Only required for GPIO recovery. 562 * @sda_gpiod: gpiod of the SDA line. Only required for GPIO recovery.
502 */ 563 */
503struct i2c_bus_recovery_info { 564struct i2c_bus_recovery_info {
504 int (*recover_bus)(struct i2c_adapter *); 565 int (*recover_bus)(struct i2c_adapter *adap);
505 566
506 int (*get_scl)(struct i2c_adapter *); 567 int (*get_scl)(struct i2c_adapter *adap);
507 void (*set_scl)(struct i2c_adapter *, int val); 568 void (*set_scl)(struct i2c_adapter *adap, int val);
508 int (*get_sda)(struct i2c_adapter *); 569 int (*get_sda)(struct i2c_adapter *adap);
570 void (*set_sda)(struct i2c_adapter *adap, int val);
509 571
510 void (*prepare_recovery)(struct i2c_adapter *); 572 void (*prepare_recovery)(struct i2c_adapter *adap);
511 void (*unprepare_recovery)(struct i2c_adapter *); 573 void (*unprepare_recovery)(struct i2c_adapter *adap);
512 574
513 /* gpio recovery */ 575 /* gpio recovery */
514 int scl_gpio; 576 struct gpio_desc *scl_gpiod;
515 int sda_gpio; 577 struct gpio_desc *sda_gpiod;
516}; 578};
517 579
518int i2c_recover_bus(struct i2c_adapter *adap); 580int i2c_recover_bus(struct i2c_adapter *adap);
519 581
520/* Generic recovery routines */ 582/* Generic recovery routines */
521int i2c_generic_gpio_recovery(struct i2c_adapter *adap);
522int i2c_generic_scl_recovery(struct i2c_adapter *adap); 583int i2c_generic_scl_recovery(struct i2c_adapter *adap);
523 584
524/** 585/**
@@ -706,7 +767,7 @@ i2c_unlock_adapter(struct i2c_adapter *adapter)
706 767
707/* administration... 768/* administration...
708 */ 769 */
709#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 770#if IS_ENABLED(CONFIG_I2C)
710extern int i2c_add_adapter(struct i2c_adapter *); 771extern int i2c_add_adapter(struct i2c_adapter *);
711extern void i2c_del_adapter(struct i2c_adapter *); 772extern void i2c_del_adapter(struct i2c_adapter *);
712extern int i2c_add_numbered_adapter(struct i2c_adapter *); 773extern int i2c_add_numbered_adapter(struct i2c_adapter *);
@@ -769,6 +830,9 @@ static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
769 return (msg->addr << 1) | (msg->flags & I2C_M_RD ? 1 : 0); 830 return (msg->addr << 1) | (msg->flags & I2C_M_RD ? 1 : 0);
770} 831}
771 832
833u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold);
834void i2c_release_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf);
835
772int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr); 836int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr);
773/** 837/**
774 * module_i2c_driver() - Helper macro for registering a modular I2C driver 838 * module_i2c_driver() - Helper macro for registering a modular I2C driver