13d0407baSopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
23d0407baSopenharmony_ci/*
33d0407baSopenharmony_ci * i2c.h - definitions for the Linux i2c bus interface
43d0407baSopenharmony_ci * Copyright (C) 1995-2000 Simon G. Vogl
53d0407baSopenharmony_ci * Copyright (C) 2013-2019 Wolfram Sang <wsa@kernel.org>
63d0407baSopenharmony_ci *
73d0407baSopenharmony_ci * With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
83d0407baSopenharmony_ci * Frodo Looijaard <frodol@dds.nl>
93d0407baSopenharmony_ci */
103d0407baSopenharmony_ci#ifndef _LINUX_I2C_H
113d0407baSopenharmony_ci#define _LINUX_I2C_H
123d0407baSopenharmony_ci
133d0407baSopenharmony_ci#include <linux/acpi.h> /* for acpi_handle */
143d0407baSopenharmony_ci#include <linux/mod_devicetable.h>
153d0407baSopenharmony_ci#include <linux/device.h> /* for struct device */
163d0407baSopenharmony_ci#include <linux/sched.h>  /* for completion */
173d0407baSopenharmony_ci#include <linux/mutex.h>
183d0407baSopenharmony_ci#include <linux/rtmutex.h>
193d0407baSopenharmony_ci#include <linux/irqdomain.h> /* for Host Notify IRQ */
203d0407baSopenharmony_ci#include <linux/of.h>        /* for struct device_node */
213d0407baSopenharmony_ci#include <linux/swab.h>      /* for swab16 */
223d0407baSopenharmony_ci#include <uapi/linux/i2c.h>
233d0407baSopenharmony_ci
243d0407baSopenharmony_ciextern struct bus_type i2c_bus_type;
253d0407baSopenharmony_ciextern struct device_type i2c_adapter_type;
263d0407baSopenharmony_ciextern struct device_type i2c_client_type;
273d0407baSopenharmony_ci
283d0407baSopenharmony_ci/* --- General options ------------------------------------------------    */
293d0407baSopenharmony_ci
303d0407baSopenharmony_cistruct i2c_msg;
313d0407baSopenharmony_cistruct i2c_algorithm;
323d0407baSopenharmony_cistruct i2c_adapter;
333d0407baSopenharmony_cistruct i2c_client;
343d0407baSopenharmony_cistruct i2c_driver;
353d0407baSopenharmony_cistruct i2c_device_identity;
363d0407baSopenharmony_ciunion i2c_smbus_data;
373d0407baSopenharmony_cistruct i2c_board_info;
383d0407baSopenharmony_cienum i2c_slave_event;
393d0407baSopenharmony_citypedef int (*i2c_slave_cb_t)(struct i2c_client *client, enum i2c_slave_event event, u8 *val);
403d0407baSopenharmony_ci
413d0407baSopenharmony_ci/* I2C Frequency Modes */
423d0407baSopenharmony_ci#define I2C_MAX_STANDARD_MODE_FREQ 100000
433d0407baSopenharmony_ci#define I2C_MAX_FAST_MODE_FREQ 400000
443d0407baSopenharmony_ci#define I2C_MAX_FAST_MODE_PLUS_FREQ 1000000
453d0407baSopenharmony_ci#define I2C_MAX_TURBO_MODE_FREQ 1400000
463d0407baSopenharmony_ci#define I2C_MAX_HIGH_SPEED_MODE_FREQ 3400000
473d0407baSopenharmony_ci#define I2C_MAX_ULTRA_FAST_MODE_FREQ 5000000
483d0407baSopenharmony_ci
493d0407baSopenharmony_cistruct module;
503d0407baSopenharmony_cistruct property_entry;
513d0407baSopenharmony_ci
523d0407baSopenharmony_ci#if IS_ENABLED(CONFIG_I2C)
533d0407baSopenharmony_ci/*
543d0407baSopenharmony_ci * The master routines are the ones normally used to transmit data to devices
553d0407baSopenharmony_ci * on a bus (or read from them). Apart from two basic transfer functions to
563d0407baSopenharmony_ci * transmit one message at a time, a more complex version can be used to
573d0407baSopenharmony_ci * transmit an arbitrary number of messages without interruption.
583d0407baSopenharmony_ci * @count must be less than 64k since msg.len is u16.
593d0407baSopenharmony_ci */
603d0407baSopenharmony_ciint i2c_transfer_buffer_flags(const struct i2c_client *client, char *buf, int count, u16 flags);
613d0407baSopenharmony_ci
623d0407baSopenharmony_ci/**
633d0407baSopenharmony_ci * i2c_master_recv - issue a single I2C message in master receive mode
643d0407baSopenharmony_ci * @client: Handle to slave device
653d0407baSopenharmony_ci * @buf: Where to store data read from slave
663d0407baSopenharmony_ci * @count: How many bytes to read, must be less than 64k since msg.len is u16
673d0407baSopenharmony_ci *
683d0407baSopenharmony_ci * Returns negative errno, or else the number of bytes read.
693d0407baSopenharmony_ci */
703d0407baSopenharmony_cistatic inline int i2c_master_recv(const struct i2c_client *client, char *buf, int count)
713d0407baSopenharmony_ci{
723d0407baSopenharmony_ci    return i2c_transfer_buffer_flags(client, buf, count, I2C_M_RD);
733d0407baSopenharmony_ci};
743d0407baSopenharmony_ci
753d0407baSopenharmony_ci/**
763d0407baSopenharmony_ci * i2c_master_recv_dmasafe - issue a single I2C message in master receive mode
773d0407baSopenharmony_ci *                 using a DMA safe buffer
783d0407baSopenharmony_ci * @client: Handle to slave device
793d0407baSopenharmony_ci * @buf: Where to store data read from slave, must be safe to use with DMA
803d0407baSopenharmony_ci * @count: How many bytes to read, must be less than 64k since msg.len is u16
813d0407baSopenharmony_ci *
823d0407baSopenharmony_ci * Returns negative errno, or else the number of bytes read.
833d0407baSopenharmony_ci */
843d0407baSopenharmony_cistatic inline int i2c_master_recv_dmasafe(const struct i2c_client *client, char *buf, int count)
853d0407baSopenharmony_ci{
863d0407baSopenharmony_ci    return i2c_transfer_buffer_flags(client, buf, count, I2C_M_RD | I2C_M_DMA_SAFE);
873d0407baSopenharmony_ci};
883d0407baSopenharmony_ci
893d0407baSopenharmony_ci/**
903d0407baSopenharmony_ci * i2c_master_send - issue a single I2C message in master transmit mode
913d0407baSopenharmony_ci * @client: Handle to slave device
923d0407baSopenharmony_ci * @buf: Data that will be written to the slave
933d0407baSopenharmony_ci * @count: How many bytes to write, must be less than 64k since msg.len is u16
943d0407baSopenharmony_ci *
953d0407baSopenharmony_ci * Returns negative errno, or else the number of bytes written.
963d0407baSopenharmony_ci */
973d0407baSopenharmony_cistatic inline int i2c_master_send(const struct i2c_client *client, const char *buf, int count)
983d0407baSopenharmony_ci{
993d0407baSopenharmony_ci    return i2c_transfer_buffer_flags(client, (char *)buf, count, 0);
1003d0407baSopenharmony_ci};
1013d0407baSopenharmony_ci
1023d0407baSopenharmony_ci/**
1033d0407baSopenharmony_ci * i2c_master_send_dmasafe - issue a single I2C message in master transmit mode
1043d0407baSopenharmony_ci *                 using a DMA safe buffer
1053d0407baSopenharmony_ci * @client: Handle to slave device
1063d0407baSopenharmony_ci * @buf: Data that will be written to the slave, must be safe to use with DMA
1073d0407baSopenharmony_ci * @count: How many bytes to write, must be less than 64k since msg.len is u16
1083d0407baSopenharmony_ci *
1093d0407baSopenharmony_ci * Returns negative errno, or else the number of bytes written.
1103d0407baSopenharmony_ci */
1113d0407baSopenharmony_cistatic inline int i2c_master_send_dmasafe(const struct i2c_client *client, const char *buf, int count)
1123d0407baSopenharmony_ci{
1133d0407baSopenharmony_ci    return i2c_transfer_buffer_flags(client, (char *)buf, count, I2C_M_DMA_SAFE);
1143d0407baSopenharmony_ci};
1153d0407baSopenharmony_ci
1163d0407baSopenharmony_ci/* Transfer num messages.
1173d0407baSopenharmony_ci */
1183d0407baSopenharmony_ciint i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
1193d0407baSopenharmony_ci/* Unlocked flavor */
1203d0407baSopenharmony_ciint __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
1213d0407baSopenharmony_ci
1223d0407baSopenharmony_ci/* This is the very generalized SMBus access routine. You probably do not
1233d0407baSopenharmony_ci   want to use this, though; one of the functions below may be much easier,
1243d0407baSopenharmony_ci   and probably just as fast.
1253d0407baSopenharmony_ci   Note that we use i2c_adapter here, because you do not need a specific
1263d0407baSopenharmony_ci   smbus adapter to call this function. */
1273d0407baSopenharmony_cis32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, char read_write, u8 command,
1283d0407baSopenharmony_ci                   int protocol, union i2c_smbus_data *data);
1293d0407baSopenharmony_ci
1303d0407baSopenharmony_ci/* Unlocked flavor */
1313d0407baSopenharmony_cis32 __i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, char read_write, u8 command,
1323d0407baSopenharmony_ci                     int protocol, union i2c_smbus_data *data);
1333d0407baSopenharmony_ci
1343d0407baSopenharmony_ci/* Now follow the 'nice' access routines. These also document the calling
1353d0407baSopenharmony_ci   conventions of i2c_smbus_xfer. */
1363d0407baSopenharmony_ci
1373d0407baSopenharmony_cis32 i2c_smbus_read_byte(const struct i2c_client *client);
1383d0407baSopenharmony_cis32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value);
1393d0407baSopenharmony_cis32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command);
1403d0407baSopenharmony_cis32 i2c_smbus_write_byte_data(const struct i2c_client *client, u8 command, u8 value);
1413d0407baSopenharmony_cis32 i2c_smbus_read_word_data(const struct i2c_client *client, u8 command);
1423d0407baSopenharmony_cis32 i2c_smbus_write_word_data(const struct i2c_client *client, u8 command, u16 value);
1433d0407baSopenharmony_ci
1443d0407baSopenharmony_cistatic inline s32 i2c_smbus_read_word_swapped(const struct i2c_client *client, u8 command)
1453d0407baSopenharmony_ci{
1463d0407baSopenharmony_ci    s32 value = i2c_smbus_read_word_data(client, command);
1473d0407baSopenharmony_ci
1483d0407baSopenharmony_ci    return (value < 0) ? value : swab16(value);
1493d0407baSopenharmony_ci}
1503d0407baSopenharmony_ci
1513d0407baSopenharmony_cistatic inline s32 i2c_smbus_write_word_swapped(const struct i2c_client *client, u8 command, u16 value)
1523d0407baSopenharmony_ci{
1533d0407baSopenharmony_ci    return i2c_smbus_write_word_data(client, command, swab16(value));
1543d0407baSopenharmony_ci}
1553d0407baSopenharmony_ci
1563d0407baSopenharmony_ci/* Returns the number of read bytes */
1573d0407baSopenharmony_cis32 i2c_smbus_read_block_data(const struct i2c_client *client, u8 command, u8 *values);
1583d0407baSopenharmony_cis32 i2c_smbus_write_block_data(const struct i2c_client *client, u8 command, u8 length, const u8 *values);
1593d0407baSopenharmony_ci/* Returns the number of read bytes */
1603d0407baSopenharmony_cis32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, u8 command, u8 length, u8 *values);
1613d0407baSopenharmony_cis32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, u8 command, u8 length, const u8 *values);
1623d0407baSopenharmony_cis32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client, u8 command, u8 length, u8 *values);
1633d0407baSopenharmony_ciint i2c_get_device_id(const struct i2c_client *client, struct i2c_device_identity *id);
1643d0407baSopenharmony_ci#endif /* I2C */
1653d0407baSopenharmony_ci
1663d0407baSopenharmony_ci/**
1673d0407baSopenharmony_ci * struct i2c_device_identity - i2c client device identification
1683d0407baSopenharmony_ci * @manufacturer_id: 0 - 4095, database maintained by NXP
1693d0407baSopenharmony_ci * @part_id: 0 - 511, according to manufacturer
1703d0407baSopenharmony_ci * @die_revision: 0 - 7, according to manufacturer
1713d0407baSopenharmony_ci */
1723d0407baSopenharmony_cistruct i2c_device_identity {
1733d0407baSopenharmony_ci    u16 manufacturer_id;
1743d0407baSopenharmony_ci#define I2C_DEVICE_ID_NXP_SEMICONDUCTORS 0
1753d0407baSopenharmony_ci#define I2C_DEVICE_ID_NXP_SEMICONDUCTORS_1 1
1763d0407baSopenharmony_ci#define I2C_DEVICE_ID_NXP_SEMICONDUCTORS_2 2
1773d0407baSopenharmony_ci#define I2C_DEVICE_ID_NXP_SEMICONDUCTORS_3 3
1783d0407baSopenharmony_ci#define I2C_DEVICE_ID_RAMTRON_INTERNATIONAL 4
1793d0407baSopenharmony_ci#define I2C_DEVICE_ID_ANALOG_DEVICES 5
1803d0407baSopenharmony_ci#define I2C_DEVICE_ID_STMICROELECTRONICS 6
1813d0407baSopenharmony_ci#define I2C_DEVICE_ID_ON_SEMICONDUCTOR 7
1823d0407baSopenharmony_ci#define I2C_DEVICE_ID_SPRINTEK_CORPORATION 8
1833d0407baSopenharmony_ci#define I2C_DEVICE_ID_ESPROS_PHOTONICS_AG 9
1843d0407baSopenharmony_ci#define I2C_DEVICE_ID_FUJITSU_SEMICONDUCTOR 10
1853d0407baSopenharmony_ci#define I2C_DEVICE_ID_FLIR 11
1863d0407baSopenharmony_ci#define I2C_DEVICE_ID_O2MICRO 12
1873d0407baSopenharmony_ci#define I2C_DEVICE_ID_ATMEL 13
1883d0407baSopenharmony_ci#define I2C_DEVICE_ID_NONE 0xffff
1893d0407baSopenharmony_ci    u16 part_id;
1903d0407baSopenharmony_ci    u8 die_revision;
1913d0407baSopenharmony_ci};
1923d0407baSopenharmony_ci
1933d0407baSopenharmony_cienum i2c_alert_protocol {
1943d0407baSopenharmony_ci    I2C_PROTOCOL_SMBUS_ALERT,
1953d0407baSopenharmony_ci    I2C_PROTOCOL_SMBUS_HOST_NOTIFY,
1963d0407baSopenharmony_ci};
1973d0407baSopenharmony_ci
1983d0407baSopenharmony_ci/**
1993d0407baSopenharmony_ci * struct i2c_driver - represent an I2C device driver
2003d0407baSopenharmony_ci * @class: What kind of i2c device we instantiate (for detect)
2013d0407baSopenharmony_ci * @probe: Callback for device binding - soon to be deprecated
2023d0407baSopenharmony_ci * @probe_new: New callback for device binding
2033d0407baSopenharmony_ci * @remove: Callback for device unbinding
2043d0407baSopenharmony_ci * @shutdown: Callback for device shutdown
2053d0407baSopenharmony_ci * @alert: Alert callback, for example for the SMBus alert protocol
2063d0407baSopenharmony_ci * @command: Callback for bus-wide signaling (optional)
2073d0407baSopenharmony_ci * @driver: Device driver model driver
2083d0407baSopenharmony_ci * @id_table: List of I2C devices supported by this driver
2093d0407baSopenharmony_ci * @detect: Callback for device detection
2103d0407baSopenharmony_ci * @address_list: The I2C addresses to probe (for detect)
2113d0407baSopenharmony_ci * @clients: List of detected clients we created (for i2c-core use only)
2123d0407baSopenharmony_ci *
2133d0407baSopenharmony_ci * The driver.owner field should be set to the module owner of this driver.
2143d0407baSopenharmony_ci * The driver.name field should be set to the name of this driver.
2153d0407baSopenharmony_ci *
2163d0407baSopenharmony_ci * For automatic device detection, both @detect and @address_list must
2173d0407baSopenharmony_ci * be defined. @class should also be set, otherwise only devices forced
2183d0407baSopenharmony_ci * with module parameters will be created. The detect function must
2193d0407baSopenharmony_ci * fill at least the name field of the i2c_board_info structure it is
2203d0407baSopenharmony_ci * handed upon successful detection, and possibly also the flags field.
2213d0407baSopenharmony_ci *
2223d0407baSopenharmony_ci * If @detect is missing, the driver will still work fine for enumerated
2233d0407baSopenharmony_ci * devices. Detected devices simply won't be supported. This is expected
2243d0407baSopenharmony_ci * for the many I2C/SMBus devices which can't be detected reliably, and
2253d0407baSopenharmony_ci * the ones which can always be enumerated in practice.
2263d0407baSopenharmony_ci *
2273d0407baSopenharmony_ci * The i2c_client structure which is handed to the @detect callback is
2283d0407baSopenharmony_ci * not a real i2c_client. It is initialized just enough so that you can
2293d0407baSopenharmony_ci * call i2c_smbus_read_byte_data and friends on it. Don't do anything
2303d0407baSopenharmony_ci * else with it. In particular, calling dev_dbg and friends on it is
2313d0407baSopenharmony_ci * not allowed.
2323d0407baSopenharmony_ci */
2333d0407baSopenharmony_cistruct i2c_driver {
2343d0407baSopenharmony_ci    unsigned int class;
2353d0407baSopenharmony_ci
2363d0407baSopenharmony_ci    /* Standard driver model interfaces */
2373d0407baSopenharmony_ci    int (*probe)(struct i2c_client *client, const struct i2c_device_id *id);
2383d0407baSopenharmony_ci    int (*remove)(struct i2c_client *client);
2393d0407baSopenharmony_ci
2403d0407baSopenharmony_ci    /* New driver model interface to aid the seamless removal of the
2413d0407baSopenharmony_ci     * current probe()'s, more commonly unused than used second parameter.
2423d0407baSopenharmony_ci     */
2433d0407baSopenharmony_ci    int (*probe_new)(struct i2c_client *client);
2443d0407baSopenharmony_ci
2453d0407baSopenharmony_ci    /* driver model interfaces that don't relate to enumeration  */
2463d0407baSopenharmony_ci    void (*shutdown)(struct i2c_client *client);
2473d0407baSopenharmony_ci
2483d0407baSopenharmony_ci    /* Alert callback, for example for the SMBus alert protocol.
2493d0407baSopenharmony_ci     * The format and meaning of the data value depends on the protocol.
2503d0407baSopenharmony_ci     * For the SMBus alert protocol, there is a single bit of data passed
2513d0407baSopenharmony_ci     * as the alert response's low bit ("event flag").
2523d0407baSopenharmony_ci     * For the SMBus Host Notify protocol, the data corresponds to the
2533d0407baSopenharmony_ci     * 16-bit payload data reported by the slave device acting as master.
2543d0407baSopenharmony_ci     */
2553d0407baSopenharmony_ci    void (*alert)(struct i2c_client *client, enum i2c_alert_protocol protocol, unsigned int data);
2563d0407baSopenharmony_ci
2573d0407baSopenharmony_ci    /* a ioctl like command that can be used to perform specific functions
2583d0407baSopenharmony_ci     * with the device.
2593d0407baSopenharmony_ci     */
2603d0407baSopenharmony_ci    int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);
2613d0407baSopenharmony_ci
2623d0407baSopenharmony_ci    struct device_driver driver;
2633d0407baSopenharmony_ci    const struct i2c_device_id *id_table;
2643d0407baSopenharmony_ci
2653d0407baSopenharmony_ci    /* Device detection callback for automatic device creation */
2663d0407baSopenharmony_ci    int (*detect)(struct i2c_client *client, struct i2c_board_info *info);
2673d0407baSopenharmony_ci    const unsigned short *address_list;
2683d0407baSopenharmony_ci    struct list_head clients;
2693d0407baSopenharmony_ci};
2703d0407baSopenharmony_ci#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)
2713d0407baSopenharmony_ci
2723d0407baSopenharmony_ci/**
2733d0407baSopenharmony_ci * struct i2c_client - represent an I2C slave device
2743d0407baSopenharmony_ci * @flags: see I2C_CLIENT_* for possible flags
2753d0407baSopenharmony_ci * @addr: Address used on the I2C bus connected to the parent adapter.
2763d0407baSopenharmony_ci * @name: Indicates the type of the device, usually a chip name that's
2773d0407baSopenharmony_ci *    generic enough to hide second-sourcing and compatible revisions.
2783d0407baSopenharmony_ci * @adapter: manages the bus segment hosting this I2C device
2793d0407baSopenharmony_ci * @dev: Driver model device node for the slave.
2803d0407baSopenharmony_ci * @init_irq: IRQ that was set at initialization
2813d0407baSopenharmony_ci * @irq: indicates the IRQ generated by this device (if any)
2823d0407baSopenharmony_ci * @detected: member of an i2c_driver.clients list or i2c-core's
2833d0407baSopenharmony_ci *    userspace_devices list
2843d0407baSopenharmony_ci * @slave_cb: Callback when I2C slave mode of an adapter is used. The adapter
2853d0407baSopenharmony_ci *    calls it to pass on slave events to the slave driver.
2863d0407baSopenharmony_ci *
2873d0407baSopenharmony_ci * An i2c_client identifies a single device (i.e. chip) connected to an
2883d0407baSopenharmony_ci * i2c bus. The behaviour exposed to Linux is defined by the driver
2893d0407baSopenharmony_ci * managing the device.
2903d0407baSopenharmony_ci */
2913d0407baSopenharmony_cistruct i2c_client {
2923d0407baSopenharmony_ci    unsigned short flags;           /* div., see below        */
2933d0407baSopenharmony_ci#define I2C_CLIENT_PEC 0x04         /* Use Packet Error Checking */
2943d0407baSopenharmony_ci#define I2C_CLIENT_TEN 0x10         /* we have a ten bit chip address */
2953d0407baSopenharmony_ci                                    /* Must equal I2C_M_TEN below */
2963d0407baSopenharmony_ci#define I2C_CLIENT_SLAVE 0x20       /* we are the slave */
2973d0407baSopenharmony_ci#define I2C_CLIENT_HOST_NOTIFY 0x40 /* We want to use I2C host notify */
2983d0407baSopenharmony_ci#define I2C_CLIENT_WAKE 0x80        /* for board_info; true iff can wake */
2993d0407baSopenharmony_ci#define I2C_CLIENT_SCCB 0x9000      /* Use Omnivision SCCB protocol */
3003d0407baSopenharmony_ci                                    /* Must match I2C_M_STOP|IGNORE_NAK */
3013d0407baSopenharmony_ci
3023d0407baSopenharmony_ci    unsigned short addr; /* chip address - NOTE: 7bit    */
3033d0407baSopenharmony_ci                         /* addresses are stored in the    */
3043d0407baSopenharmony_ci                         /* _LOWER_ 7 bits        */
3053d0407baSopenharmony_ci    char name[I2C_NAME_SIZE];
3063d0407baSopenharmony_ci    struct i2c_adapter *adapter; /* the adapter we sit on    */
3073d0407baSopenharmony_ci    struct device dev;           /* the device structure        */
3083d0407baSopenharmony_ci    int init_irq;                /* irq set at initialization    */
3093d0407baSopenharmony_ci    int irq;                     /* irq issued by device        */
3103d0407baSopenharmony_ci    struct list_head detected;
3113d0407baSopenharmony_ci#if IS_ENABLED(CONFIG_I2C_SLAVE)
3123d0407baSopenharmony_ci    i2c_slave_cb_t slave_cb; /* callback for slave mode    */
3133d0407baSopenharmony_ci#endif
3143d0407baSopenharmony_ci};
3153d0407baSopenharmony_ci#define to_i2c_client(d) container_of(d, struct i2c_client, dev)
3163d0407baSopenharmony_ci
3173d0407baSopenharmony_cistruct i2c_client *i2c_verify_client(struct device *dev);
3183d0407baSopenharmony_cistruct i2c_adapter *i2c_verify_adapter(struct device *dev);
3193d0407baSopenharmony_ciconst struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id, const struct i2c_client *client);
3203d0407baSopenharmony_ci
3213d0407baSopenharmony_cistatic inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
3223d0407baSopenharmony_ci{
3233d0407baSopenharmony_ci    struct device *const dev = kobj_to_dev(kobj);
3243d0407baSopenharmony_ci    return to_i2c_client(dev);
3253d0407baSopenharmony_ci}
3263d0407baSopenharmony_ci
3273d0407baSopenharmony_cistatic inline void *i2c_get_clientdata(const struct i2c_client *client)
3283d0407baSopenharmony_ci{
3293d0407baSopenharmony_ci    return dev_get_drvdata(&client->dev);
3303d0407baSopenharmony_ci}
3313d0407baSopenharmony_ci
3323d0407baSopenharmony_cistatic inline void i2c_set_clientdata(struct i2c_client *client, void *data)
3333d0407baSopenharmony_ci{
3343d0407baSopenharmony_ci    dev_set_drvdata(&client->dev, data);
3353d0407baSopenharmony_ci}
3363d0407baSopenharmony_ci
3373d0407baSopenharmony_ci/* I2C slave support */
3383d0407baSopenharmony_ci
3393d0407baSopenharmony_ci#if IS_ENABLED(CONFIG_I2C_SLAVE)
3403d0407baSopenharmony_cienum i2c_slave_event {
3413d0407baSopenharmony_ci    I2C_SLAVE_READ_REQUESTED,
3423d0407baSopenharmony_ci    I2C_SLAVE_WRITE_REQUESTED,
3433d0407baSopenharmony_ci    I2C_SLAVE_READ_PROCESSED,
3443d0407baSopenharmony_ci    I2C_SLAVE_WRITE_RECEIVED,
3453d0407baSopenharmony_ci    I2C_SLAVE_STOP,
3463d0407baSopenharmony_ci};
3473d0407baSopenharmony_ci
3483d0407baSopenharmony_ciint i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb);
3493d0407baSopenharmony_ciint i2c_slave_unregister(struct i2c_client *client);
3503d0407baSopenharmony_cibool i2c_detect_slave_mode(struct device *dev);
3513d0407baSopenharmony_ci
3523d0407baSopenharmony_cistatic inline int i2c_slave_event(struct i2c_client *client, enum i2c_slave_event event, u8 *val)
3533d0407baSopenharmony_ci{
3543d0407baSopenharmony_ci    return client->slave_cb(client, event, val);
3553d0407baSopenharmony_ci}
3563d0407baSopenharmony_ci#else
3573d0407baSopenharmony_cistatic inline bool i2c_detect_slave_mode(struct device *dev)
3583d0407baSopenharmony_ci{
3593d0407baSopenharmony_ci    return false;
3603d0407baSopenharmony_ci}
3613d0407baSopenharmony_ci#endif
3623d0407baSopenharmony_ci
3633d0407baSopenharmony_ci/**
3643d0407baSopenharmony_ci * struct i2c_board_info - template for device creation
3653d0407baSopenharmony_ci * @type: chip type, to initialize i2c_client.name
3663d0407baSopenharmony_ci * @flags: to initialize i2c_client.flags
3673d0407baSopenharmony_ci * @addr: stored in i2c_client.addr
3683d0407baSopenharmony_ci * @dev_name: Overrides the default <busnr>-<addr> dev_name if set
3693d0407baSopenharmony_ci * @platform_data: stored in i2c_client.dev.platform_data
3703d0407baSopenharmony_ci * @of_node: pointer to OpenFirmware device node
3713d0407baSopenharmony_ci * @fwnode: device node supplied by the platform firmware
3723d0407baSopenharmony_ci * @properties: additional device properties for the device
3733d0407baSopenharmony_ci * @resources: resources associated with the device
3743d0407baSopenharmony_ci * @num_resources: number of resources in the @resources array
3753d0407baSopenharmony_ci * @irq: stored in i2c_client.irq
3763d0407baSopenharmony_ci *
3773d0407baSopenharmony_ci * I2C doesn't actually support hardware probing, although controllers and
3783d0407baSopenharmony_ci * devices may be able to use I2C_SMBUS_QUICK to tell whether or not there's
3793d0407baSopenharmony_ci * a device at a given address.  Drivers commonly need more information than
3803d0407baSopenharmony_ci * that, such as chip type, configuration, associated IRQ, and so on.
3813d0407baSopenharmony_ci *
3823d0407baSopenharmony_ci * i2c_board_info is used to build tables of information listing I2C devices
3833d0407baSopenharmony_ci * that are present.  This information is used to grow the driver model tree.
3843d0407baSopenharmony_ci * For mainboards this is done statically using i2c_register_board_info();
3853d0407baSopenharmony_ci * bus numbers identify adapters that aren't yet available.  For add-on boards,
3863d0407baSopenharmony_ci * i2c_new_client_device() does this dynamically with the adapter already known.
3873d0407baSopenharmony_ci */
3883d0407baSopenharmony_cistruct i2c_board_info {
3893d0407baSopenharmony_ci    char type[I2C_NAME_SIZE];
3903d0407baSopenharmony_ci    unsigned short flags;
3913d0407baSopenharmony_ci    unsigned short addr;
3923d0407baSopenharmony_ci    const char *dev_name;
3933d0407baSopenharmony_ci    void *platform_data;
3943d0407baSopenharmony_ci    struct device_node *of_node;
3953d0407baSopenharmony_ci    struct fwnode_handle *fwnode;
3963d0407baSopenharmony_ci    const struct property_entry *properties;
3973d0407baSopenharmony_ci    const struct resource *resources;
3983d0407baSopenharmony_ci    unsigned int num_resources;
3993d0407baSopenharmony_ci    int irq;
4003d0407baSopenharmony_ci};
4013d0407baSopenharmony_ci
4023d0407baSopenharmony_ci/**
4033d0407baSopenharmony_ci * I2C_BOARD_INFO - macro used to list an i2c device and its address
4043d0407baSopenharmony_ci * @dev_type: identifies the device type
4053d0407baSopenharmony_ci * @dev_addr: the device's address on the bus.
4063d0407baSopenharmony_ci *
4073d0407baSopenharmony_ci * This macro initializes essential fields of a struct i2c_board_info,
4083d0407baSopenharmony_ci * declaring what has been provided on a particular board.  Optional
4093d0407baSopenharmony_ci * fields (such as associated irq, or device-specific platform_data)
4103d0407baSopenharmony_ci * are provided using conventional syntax.
4113d0407baSopenharmony_ci */
4123d0407baSopenharmony_ci#define I2C_BOARD_INFO(dev_type, dev_addr) .type = (dev_type), .addr = (dev_addr)
4133d0407baSopenharmony_ci
4143d0407baSopenharmony_ci#if IS_ENABLED(CONFIG_I2C)
4153d0407baSopenharmony_ci/*
4163d0407baSopenharmony_ci * Add-on boards should register/unregister their devices; e.g. a board
4173d0407baSopenharmony_ci * with integrated I2C, a config eeprom, sensors, and a codec that's
4183d0407baSopenharmony_ci * used in conjunction with the primary hardware.
4193d0407baSopenharmony_ci */
4203d0407baSopenharmony_cistruct i2c_client *i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info);
4213d0407baSopenharmony_ci
4223d0407baSopenharmony_ci/* If you don't know the exact address of an I2C device, use this variant
4233d0407baSopenharmony_ci * instead, which can probe for device presence in a list of possible
4243d0407baSopenharmony_ci * addresses. The "probe" callback function is optional. If it is provided,
4253d0407baSopenharmony_ci * it must return 1 on successful probe, 0 otherwise. If it is not provided,
4263d0407baSopenharmony_ci * a default probing method is used.
4273d0407baSopenharmony_ci */
4283d0407baSopenharmony_cistruct i2c_client *i2c_new_scanned_device(struct i2c_adapter *adap, struct i2c_board_info *info,
4293d0407baSopenharmony_ci                                          unsigned short const *addr_list,
4303d0407baSopenharmony_ci                                          int (*probe)(struct i2c_adapter *adap, unsigned short addr));
4313d0407baSopenharmony_ci
4323d0407baSopenharmony_ci/* Common custom probe functions */
4333d0407baSopenharmony_ciint i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr);
4343d0407baSopenharmony_ci
4353d0407baSopenharmony_cistruct i2c_client *i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address);
4363d0407baSopenharmony_ci
4373d0407baSopenharmony_cistruct i2c_client *devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address);
4383d0407baSopenharmony_ci
4393d0407baSopenharmony_cistruct i2c_client *i2c_new_ancillary_device(struct i2c_client *client, const char *name, u16 default_addr);
4403d0407baSopenharmony_ci
4413d0407baSopenharmony_civoid i2c_unregister_device(struct i2c_client *client);
4423d0407baSopenharmony_ci#endif /* I2C */
4433d0407baSopenharmony_ci
4443d0407baSopenharmony_ci/* Mainboard arch_initcall() code should register all its I2C devices.
4453d0407baSopenharmony_ci * This is done at arch_initcall time, before declaring any i2c adapters.
4463d0407baSopenharmony_ci * Modules for add-on boards must use other calls.
4473d0407baSopenharmony_ci */
4483d0407baSopenharmony_ci#ifdef CONFIG_I2C_BOARDINFO
4493d0407baSopenharmony_ciint i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsigned n);
4503d0407baSopenharmony_ci#else
4513d0407baSopenharmony_cistatic inline int i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsigned n)
4523d0407baSopenharmony_ci{
4533d0407baSopenharmony_ci    return 0;
4543d0407baSopenharmony_ci}
4553d0407baSopenharmony_ci#endif /* I2C_BOARDINFO */
4563d0407baSopenharmony_ci
4573d0407baSopenharmony_ci/**
4583d0407baSopenharmony_ci * struct i2c_algorithm - represent I2C transfer method
4593d0407baSopenharmony_ci * @master_xfer: Issue a set of i2c transactions to the given I2C adapter
4603d0407baSopenharmony_ci *   defined by the msgs array, with num messages available to transfer via
4613d0407baSopenharmony_ci *   the adapter specified by adap.
4623d0407baSopenharmony_ci * @master_xfer_atomic: same as @master_xfer. Yet, only using atomic context
4633d0407baSopenharmony_ci *   so e.g. PMICs can be accessed very late before shutdown. Optional.
4643d0407baSopenharmony_ci * @smbus_xfer: Issue smbus transactions to the given I2C adapter. If this
4653d0407baSopenharmony_ci *   is not present, then the bus layer will try and convert the SMBus calls
4663d0407baSopenharmony_ci *   into I2C transfers instead.
4673d0407baSopenharmony_ci * @smbus_xfer_atomic: same as @smbus_xfer. Yet, only using atomic context
4683d0407baSopenharmony_ci *   so e.g. PMICs can be accessed very late before shutdown. Optional.
4693d0407baSopenharmony_ci * @functionality: Return the flags that this algorithm/adapter pair supports
4703d0407baSopenharmony_ci *   from the ``I2C_FUNC_*`` flags.
4713d0407baSopenharmony_ci * @reg_slave: Register given client to I2C slave mode of this adapter
4723d0407baSopenharmony_ci * @unreg_slave: Unregister given client from I2C slave mode of this adapter
4733d0407baSopenharmony_ci *
4743d0407baSopenharmony_ci * The following structs are for those who like to implement new bus drivers:
4753d0407baSopenharmony_ci * i2c_algorithm is the interface to a class of hardware solutions which can
4763d0407baSopenharmony_ci * be addressed using the same bus algorithms - i.e. bit-banging or the PCF8584
4773d0407baSopenharmony_ci * to name two of the most common.
4783d0407baSopenharmony_ci *
4793d0407baSopenharmony_ci * The return codes from the ``master_xfer{_atomic}`` fields should indicate the
4803d0407baSopenharmony_ci * type of error code that occurred during the transfer, as documented in the
4813d0407baSopenharmony_ci * Kernel Documentation file Documentation/i2c/fault-codes.rst.
4823d0407baSopenharmony_ci */
4833d0407baSopenharmony_cistruct i2c_algorithm {
4843d0407baSopenharmony_ci    /*
4853d0407baSopenharmony_ci     * If an adapter algorithm can't do I2C-level access, set master_xfer
4863d0407baSopenharmony_ci     * to NULL. If an adapter algorithm can do SMBus access, set
4873d0407baSopenharmony_ci     * smbus_xfer. If set to NULL, the SMBus protocol is simulated
4883d0407baSopenharmony_ci     * using common I2C messages.
4893d0407baSopenharmony_ci     *
4903d0407baSopenharmony_ci     * master_xfer should return the number of messages successfully
4913d0407baSopenharmony_ci     * processed, or a negative value on error
4923d0407baSopenharmony_ci     */
4933d0407baSopenharmony_ci    int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
4943d0407baSopenharmony_ci    int (*master_xfer_atomic)(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
4953d0407baSopenharmony_ci    int (*smbus_xfer)(struct i2c_adapter *adap, u16 addr, unsigned short flags, char read_write, u8 command, int size,
4963d0407baSopenharmony_ci                      union i2c_smbus_data *data);
4973d0407baSopenharmony_ci    int (*smbus_xfer_atomic)(struct i2c_adapter *adap, u16 addr, unsigned short flags, char read_write, u8 command,
4983d0407baSopenharmony_ci                             int size, union i2c_smbus_data *data);
4993d0407baSopenharmony_ci
5003d0407baSopenharmony_ci    /* To determine what the adapter supports */
5013d0407baSopenharmony_ci    u32 (*functionality)(struct i2c_adapter *adap);
5023d0407baSopenharmony_ci
5033d0407baSopenharmony_ci#if IS_ENABLED(CONFIG_I2C_SLAVE)
5043d0407baSopenharmony_ci    int (*reg_slave)(struct i2c_client *client);
5053d0407baSopenharmony_ci    int (*unreg_slave)(struct i2c_client *client);
5063d0407baSopenharmony_ci#endif
5073d0407baSopenharmony_ci};
5083d0407baSopenharmony_ci
5093d0407baSopenharmony_ci/**
5103d0407baSopenharmony_ci * struct i2c_lock_operations - represent I2C locking operations
5113d0407baSopenharmony_ci * @lock_bus: Get exclusive access to an I2C bus segment
5123d0407baSopenharmony_ci * @trylock_bus: Try to get exclusive access to an I2C bus segment
5133d0407baSopenharmony_ci * @unlock_bus: Release exclusive access to an I2C bus segment
5143d0407baSopenharmony_ci *
5153d0407baSopenharmony_ci * The main operations are wrapped by i2c_lock_bus and i2c_unlock_bus.
5163d0407baSopenharmony_ci */
5173d0407baSopenharmony_cistruct i2c_lock_operations {
5183d0407baSopenharmony_ci    void (*lock_bus)(struct i2c_adapter *adapter, unsigned int flags);
5193d0407baSopenharmony_ci    int (*trylock_bus)(struct i2c_adapter *adapter, unsigned int flags);
5203d0407baSopenharmony_ci    void (*unlock_bus)(struct i2c_adapter *adapter, unsigned int flags);
5213d0407baSopenharmony_ci};
5223d0407baSopenharmony_ci
5233d0407baSopenharmony_ci/**
5243d0407baSopenharmony_ci * struct i2c_timings - I2C timing information
5253d0407baSopenharmony_ci * @bus_freq_hz: the bus frequency in Hz
5263d0407baSopenharmony_ci * @scl_rise_ns: time SCL signal takes to rise in ns; t(r) in the I2C specification
5273d0407baSopenharmony_ci * @scl_fall_ns: time SCL signal takes to fall in ns; t(f) in the I2C specification
5283d0407baSopenharmony_ci * @scl_int_delay_ns: time IP core additionally needs to setup SCL in ns
5293d0407baSopenharmony_ci * @sda_fall_ns: time SDA signal takes to fall in ns; t(f) in the I2C specification
5303d0407baSopenharmony_ci * @sda_hold_ns: time IP core additionally needs to hold SDA in ns
5313d0407baSopenharmony_ci * @digital_filter_width_ns: width in ns of spikes on i2c lines that the IP core
5323d0407baSopenharmony_ci *    digital filter can filter out
5333d0407baSopenharmony_ci * @analog_filter_cutoff_freq_hz: threshold frequency for the low pass IP core
5343d0407baSopenharmony_ci *    analog filter
5353d0407baSopenharmony_ci */
5363d0407baSopenharmony_cistruct i2c_timings {
5373d0407baSopenharmony_ci    u32 bus_freq_hz;
5383d0407baSopenharmony_ci    u32 scl_rise_ns;
5393d0407baSopenharmony_ci    u32 scl_fall_ns;
5403d0407baSopenharmony_ci    u32 scl_int_delay_ns;
5413d0407baSopenharmony_ci    u32 sda_fall_ns;
5423d0407baSopenharmony_ci    u32 sda_hold_ns;
5433d0407baSopenharmony_ci    u32 digital_filter_width_ns;
5443d0407baSopenharmony_ci    u32 analog_filter_cutoff_freq_hz;
5453d0407baSopenharmony_ci};
5463d0407baSopenharmony_ci
5473d0407baSopenharmony_ci/**
5483d0407baSopenharmony_ci * struct i2c_bus_recovery_info - I2C bus recovery information
5493d0407baSopenharmony_ci * @recover_bus: Recover routine. Either pass driver's recover_bus() routine, or
5503d0407baSopenharmony_ci *    i2c_generic_scl_recovery().
5513d0407baSopenharmony_ci * @get_scl: This gets current value of SCL line. Mandatory for generic SCL
5523d0407baSopenharmony_ci *      recovery. Populated internally for generic GPIO recovery.
5533d0407baSopenharmony_ci * @set_scl: This sets/clears the SCL line. Mandatory for generic SCL recovery.
5543d0407baSopenharmony_ci *      Populated internally for generic GPIO recovery.
5553d0407baSopenharmony_ci * @get_sda: This gets current value of SDA line. This or set_sda() is mandatory
5563d0407baSopenharmony_ci *    for generic SCL recovery. Populated internally, if sda_gpio is a valid
5573d0407baSopenharmony_ci *    GPIO, for generic GPIO recovery.
5583d0407baSopenharmony_ci * @set_sda: This sets/clears the SDA line. This or get_sda() is mandatory for
5593d0407baSopenharmony_ci *    generic SCL recovery. Populated internally, if sda_gpio is a valid GPIO,
5603d0407baSopenharmony_ci *    for generic GPIO recovery.
5613d0407baSopenharmony_ci * @get_bus_free: Returns the bus free state as seen from the IP core in case it
5623d0407baSopenharmony_ci *    has a more complex internal logic than just reading SDA. Optional.
5633d0407baSopenharmony_ci * @prepare_recovery: This will be called before starting recovery. Platform may
5643d0407baSopenharmony_ci *    configure padmux here for SDA/SCL line or something else they want.
5653d0407baSopenharmony_ci * @unprepare_recovery: This will be called after completing recovery. Platform
5663d0407baSopenharmony_ci *    may configure padmux here for SDA/SCL line or something else they want.
5673d0407baSopenharmony_ci * @scl_gpiod: gpiod of the SCL line. Only required for GPIO recovery.
5683d0407baSopenharmony_ci * @sda_gpiod: gpiod of the SDA line. Only required for GPIO recovery.
5693d0407baSopenharmony_ci * @pinctrl: pinctrl used by GPIO recovery to change the state of the I2C pins.
5703d0407baSopenharmony_ci *      Optional.
5713d0407baSopenharmony_ci * @pins_default: default pinctrl state of SCL/SDA lines, when they are assigned
5723d0407baSopenharmony_ci *      to the I2C bus. Optional. Populated internally for GPIO recovery, if
5733d0407baSopenharmony_ci *      state with the name PINCTRL_STATE_DEFAULT is found and pinctrl is valid.
5743d0407baSopenharmony_ci * @pins_gpio: recovery pinctrl state of SCL/SDA lines, when they are used as
5753d0407baSopenharmony_ci *      GPIOs. Optional. Populated internally for GPIO recovery, if this state
5763d0407baSopenharmony_ci *      is called "gpio" or "recovery" and pinctrl is valid.
5773d0407baSopenharmony_ci */
5783d0407baSopenharmony_cistruct i2c_bus_recovery_info {
5793d0407baSopenharmony_ci    int (*recover_bus)(struct i2c_adapter *adap);
5803d0407baSopenharmony_ci
5813d0407baSopenharmony_ci    int (*get_scl)(struct i2c_adapter *adap);
5823d0407baSopenharmony_ci    void (*set_scl)(struct i2c_adapter *adap, int val);
5833d0407baSopenharmony_ci    int (*get_sda)(struct i2c_adapter *adap);
5843d0407baSopenharmony_ci    void (*set_sda)(struct i2c_adapter *adap, int val);
5853d0407baSopenharmony_ci    int (*get_bus_free)(struct i2c_adapter *adap);
5863d0407baSopenharmony_ci
5873d0407baSopenharmony_ci    void (*prepare_recovery)(struct i2c_adapter *adap);
5883d0407baSopenharmony_ci    void (*unprepare_recovery)(struct i2c_adapter *adap);
5893d0407baSopenharmony_ci
5903d0407baSopenharmony_ci    /* gpio recovery */
5913d0407baSopenharmony_ci    struct gpio_desc *scl_gpiod;
5923d0407baSopenharmony_ci    struct gpio_desc *sda_gpiod;
5933d0407baSopenharmony_ci    struct pinctrl *pinctrl;
5943d0407baSopenharmony_ci    struct pinctrl_state *pins_default;
5953d0407baSopenharmony_ci    struct pinctrl_state *pins_gpio;
5963d0407baSopenharmony_ci};
5973d0407baSopenharmony_ci
5983d0407baSopenharmony_ciint i2c_recover_bus(struct i2c_adapter *adap);
5993d0407baSopenharmony_ci
6003d0407baSopenharmony_ci/* Generic recovery routines */
6013d0407baSopenharmony_ciint i2c_generic_scl_recovery(struct i2c_adapter *adap);
6023d0407baSopenharmony_ci
6033d0407baSopenharmony_ci/**
6043d0407baSopenharmony_ci * struct i2c_adapter_quirks - describe flaws of an i2c adapter
6053d0407baSopenharmony_ci * @flags: see I2C_AQ_* for possible flags and read below
6063d0407baSopenharmony_ci * @max_num_msgs: maximum number of messages per transfer
6073d0407baSopenharmony_ci * @max_write_len: maximum length of a write message
6083d0407baSopenharmony_ci * @max_read_len: maximum length of a read message
6093d0407baSopenharmony_ci * @max_comb_1st_msg_len: maximum length of the first msg in a combined message
6103d0407baSopenharmony_ci * @max_comb_2nd_msg_len: maximum length of the second msg in a combined message
6113d0407baSopenharmony_ci *
6123d0407baSopenharmony_ci * Note about combined messages: Some I2C controllers can only send one message
6133d0407baSopenharmony_ci * per transfer, plus something called combined message or write-then-read.
6143d0407baSopenharmony_ci * This is (usually) a small write message followed by a read message and
6153d0407baSopenharmony_ci * barely enough to access register based devices like EEPROMs. There is a flag
6163d0407baSopenharmony_ci * to support this mode. It implies max_num_msg = 2 and does the length checks
6173d0407baSopenharmony_ci * with max_comb_*_len because combined message mode usually has its own
6183d0407baSopenharmony_ci * limitations. Because of HW implementations, some controllers can actually do
6193d0407baSopenharmony_ci * write-then-anything or other variants. To support that, write-then-read has
6203d0407baSopenharmony_ci * been broken out into smaller bits like write-first and read-second which can
6213d0407baSopenharmony_ci * be combined as needed.
6223d0407baSopenharmony_ci */
6233d0407baSopenharmony_ci
6243d0407baSopenharmony_cistruct i2c_adapter_quirks {
6253d0407baSopenharmony_ci    u64 flags;
6263d0407baSopenharmony_ci    int max_num_msgs;
6273d0407baSopenharmony_ci    u16 max_write_len;
6283d0407baSopenharmony_ci    u16 max_read_len;
6293d0407baSopenharmony_ci    u16 max_comb_1st_msg_len;
6303d0407baSopenharmony_ci    u16 max_comb_2nd_msg_len;
6313d0407baSopenharmony_ci};
6323d0407baSopenharmony_ci
6333d0407baSopenharmony_ci/* enforce max_num_msgs = 2 and use max_comb_*_len for length checks */
6343d0407baSopenharmony_ci#define I2C_AQ_COMB BIT(0)
6353d0407baSopenharmony_ci/* first combined message must be write */
6363d0407baSopenharmony_ci#define I2C_AQ_COMB_WRITE_FIRST BIT(1)
6373d0407baSopenharmony_ci/* second combined message must be read */
6383d0407baSopenharmony_ci#define I2C_AQ_COMB_READ_SECOND BIT(2)
6393d0407baSopenharmony_ci/* both combined messages must have the same target address */
6403d0407baSopenharmony_ci#define I2C_AQ_COMB_SAME_ADDR BIT(3)
6413d0407baSopenharmony_ci/* convenience macro for typical write-then read case */
6423d0407baSopenharmony_ci#define I2C_AQ_COMB_WRITE_THEN_READ                                                                                    \
6433d0407baSopenharmony_ci    (I2C_AQ_COMB | I2C_AQ_COMB_WRITE_FIRST | I2C_AQ_COMB_READ_SECOND | I2C_AQ_COMB_SAME_ADDR)
6443d0407baSopenharmony_ci/* clock stretching is not supported */
6453d0407baSopenharmony_ci#define I2C_AQ_NO_CLK_STRETCH BIT(4)
6463d0407baSopenharmony_ci/* message cannot have length of 0 */
6473d0407baSopenharmony_ci#define I2C_AQ_NO_ZERO_LEN_READ BIT(5)
6483d0407baSopenharmony_ci#define I2C_AQ_NO_ZERO_LEN_WRITE BIT(6)
6493d0407baSopenharmony_ci#define I2C_AQ_NO_ZERO_LEN (I2C_AQ_NO_ZERO_LEN_READ | I2C_AQ_NO_ZERO_LEN_WRITE)
6503d0407baSopenharmony_ci/* adapter cannot do repeated START */
6513d0407baSopenharmony_ci#define I2C_AQ_NO_REP_START BIT(7)
6523d0407baSopenharmony_ci
6533d0407baSopenharmony_ci/*
6543d0407baSopenharmony_ci * i2c_adapter is the structure used to identify a physical i2c bus along
6553d0407baSopenharmony_ci * with the access algorithms necessary to access it.
6563d0407baSopenharmony_ci */
6573d0407baSopenharmony_cistruct i2c_adapter {
6583d0407baSopenharmony_ci    struct module *owner;
6593d0407baSopenharmony_ci    unsigned int class;               /* classes to allow probing for */
6603d0407baSopenharmony_ci    const struct i2c_algorithm *algo; /* the algorithm to access the bus */
6613d0407baSopenharmony_ci    void *algo_data;
6623d0407baSopenharmony_ci
6633d0407baSopenharmony_ci    /* data fields that are valid for all devices    */
6643d0407baSopenharmony_ci    const struct i2c_lock_operations *lock_ops;
6653d0407baSopenharmony_ci    struct rt_mutex bus_lock;
6663d0407baSopenharmony_ci    struct rt_mutex mux_lock;
6673d0407baSopenharmony_ci
6683d0407baSopenharmony_ci    int timeout; /* in jiffies */
6693d0407baSopenharmony_ci    int retries;
6703d0407baSopenharmony_ci    struct device dev;          /* the adapter device */
6713d0407baSopenharmony_ci    unsigned long locked_flags; /* owned by the I2C core */
6723d0407baSopenharmony_ci#define I2C_ALF_IS_SUSPENDED 0
6733d0407baSopenharmony_ci#define I2C_ALF_SUSPEND_REPORTED 1
6743d0407baSopenharmony_ci
6753d0407baSopenharmony_ci    int nr;
6763d0407baSopenharmony_ci    char name[48];
6773d0407baSopenharmony_ci    struct completion dev_released;
6783d0407baSopenharmony_ci
6793d0407baSopenharmony_ci    struct mutex userspace_clients_lock;
6803d0407baSopenharmony_ci    struct list_head userspace_clients;
6813d0407baSopenharmony_ci
6823d0407baSopenharmony_ci    struct i2c_bus_recovery_info *bus_recovery_info;
6833d0407baSopenharmony_ci    const struct i2c_adapter_quirks *quirks;
6843d0407baSopenharmony_ci
6853d0407baSopenharmony_ci    struct irq_domain *host_notify_domain;
6863d0407baSopenharmony_ci};
6873d0407baSopenharmony_ci#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
6883d0407baSopenharmony_ci
6893d0407baSopenharmony_cistatic inline void *i2c_get_adapdata(const struct i2c_adapter *adap)
6903d0407baSopenharmony_ci{
6913d0407baSopenharmony_ci    return dev_get_drvdata(&adap->dev);
6923d0407baSopenharmony_ci}
6933d0407baSopenharmony_ci
6943d0407baSopenharmony_cistatic inline void i2c_set_adapdata(struct i2c_adapter *adap, void *data)
6953d0407baSopenharmony_ci{
6963d0407baSopenharmony_ci    dev_set_drvdata(&adap->dev, data);
6973d0407baSopenharmony_ci}
6983d0407baSopenharmony_ci
6993d0407baSopenharmony_cistatic inline struct i2c_adapter *i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter)
7003d0407baSopenharmony_ci{
7013d0407baSopenharmony_ci#if IS_ENABLED(CONFIG_I2C_MUX)
7023d0407baSopenharmony_ci    struct device *parent = adapter->dev.parent;
7033d0407baSopenharmony_ci
7043d0407baSopenharmony_ci    if (parent != NULL && parent->type == &i2c_adapter_type) {
7053d0407baSopenharmony_ci        return to_i2c_adapter(parent);
7063d0407baSopenharmony_ci    } else
7073d0407baSopenharmony_ci#endif
7083d0407baSopenharmony_ci        return NULL;
7093d0407baSopenharmony_ci}
7103d0407baSopenharmony_ci
7113d0407baSopenharmony_ciint i2c_for_each_dev(void *data, int (*fn)(struct device *dev, void *data));
7123d0407baSopenharmony_ci
7133d0407baSopenharmony_ci/* Adapter locking functions, exported for shared pin cases */
7143d0407baSopenharmony_ci#define I2C_LOCK_ROOT_ADAPTER BIT(0)
7153d0407baSopenharmony_ci#define I2C_LOCK_SEGMENT BIT(1)
7163d0407baSopenharmony_ci
7173d0407baSopenharmony_ci/**
7183d0407baSopenharmony_ci * i2c_lock_bus - Get exclusive access to an I2C bus segment
7193d0407baSopenharmony_ci * @adapter: Target I2C bus segment
7203d0407baSopenharmony_ci * @flags: I2C_LOCK_ROOT_ADAPTER locks the root i2c adapter, I2C_LOCK_SEGMENT
7213d0407baSopenharmony_ci *    locks only this branch in the adapter tree
7223d0407baSopenharmony_ci */
7233d0407baSopenharmony_cistatic inline void i2c_lock_bus(struct i2c_adapter *adapter, unsigned int flags)
7243d0407baSopenharmony_ci{
7253d0407baSopenharmony_ci    adapter->lock_ops->lock_bus(adapter, flags);
7263d0407baSopenharmony_ci}
7273d0407baSopenharmony_ci
7283d0407baSopenharmony_ci/**
7293d0407baSopenharmony_ci * i2c_trylock_bus - Try to get exclusive access to an I2C bus segment
7303d0407baSopenharmony_ci * @adapter: Target I2C bus segment
7313d0407baSopenharmony_ci * @flags: I2C_LOCK_ROOT_ADAPTER tries to locks the root i2c adapter,
7323d0407baSopenharmony_ci *    I2C_LOCK_SEGMENT tries to lock only this branch in the adapter tree
7333d0407baSopenharmony_ci *
7343d0407baSopenharmony_ci * Return: true if the I2C bus segment is locked, false otherwise
7353d0407baSopenharmony_ci */
7363d0407baSopenharmony_cistatic inline int i2c_trylock_bus(struct i2c_adapter *adapter, unsigned int flags)
7373d0407baSopenharmony_ci{
7383d0407baSopenharmony_ci    return adapter->lock_ops->trylock_bus(adapter, flags);
7393d0407baSopenharmony_ci}
7403d0407baSopenharmony_ci
7413d0407baSopenharmony_ci/**
7423d0407baSopenharmony_ci * i2c_unlock_bus - Release exclusive access to an I2C bus segment
7433d0407baSopenharmony_ci * @adapter: Target I2C bus segment
7443d0407baSopenharmony_ci * @flags: I2C_LOCK_ROOT_ADAPTER unlocks the root i2c adapter, I2C_LOCK_SEGMENT
7453d0407baSopenharmony_ci *    unlocks only this branch in the adapter tree
7463d0407baSopenharmony_ci */
7473d0407baSopenharmony_cistatic inline void i2c_unlock_bus(struct i2c_adapter *adapter, unsigned int flags)
7483d0407baSopenharmony_ci{
7493d0407baSopenharmony_ci    adapter->lock_ops->unlock_bus(adapter, flags);
7503d0407baSopenharmony_ci}
7513d0407baSopenharmony_ci
7523d0407baSopenharmony_ci/**
7533d0407baSopenharmony_ci * i2c_mark_adapter_suspended - Report suspended state of the adapter to the core
7543d0407baSopenharmony_ci * @adap: Adapter to mark as suspended
7553d0407baSopenharmony_ci *
7563d0407baSopenharmony_ci * When using this helper to mark an adapter as suspended, the core will reject
7573d0407baSopenharmony_ci * further transfers to this adapter. The usage of this helper is optional but
7583d0407baSopenharmony_ci * recommended for devices having distinct handlers for system suspend and
7593d0407baSopenharmony_ci * runtime suspend. More complex devices are free to implement custom solutions
7603d0407baSopenharmony_ci * to reject transfers when suspended.
7613d0407baSopenharmony_ci */
7623d0407baSopenharmony_cistatic inline void i2c_mark_adapter_suspended(struct i2c_adapter *adap)
7633d0407baSopenharmony_ci{
7643d0407baSopenharmony_ci    i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
7653d0407baSopenharmony_ci    set_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags);
7663d0407baSopenharmony_ci    i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
7673d0407baSopenharmony_ci}
7683d0407baSopenharmony_ci
7693d0407baSopenharmony_ci/**
7703d0407baSopenharmony_ci * i2c_mark_adapter_resumed - Report resumed state of the adapter to the core
7713d0407baSopenharmony_ci * @adap: Adapter to mark as resumed
7723d0407baSopenharmony_ci *
7733d0407baSopenharmony_ci * When using this helper to mark an adapter as resumed, the core will allow
7743d0407baSopenharmony_ci * further transfers to this adapter. See also further notes to
7753d0407baSopenharmony_ci * @i2c_mark_adapter_suspended().
7763d0407baSopenharmony_ci */
7773d0407baSopenharmony_cistatic inline void i2c_mark_adapter_resumed(struct i2c_adapter *adap)
7783d0407baSopenharmony_ci{
7793d0407baSopenharmony_ci    i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
7803d0407baSopenharmony_ci    clear_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags);
7813d0407baSopenharmony_ci    i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
7823d0407baSopenharmony_ci}
7833d0407baSopenharmony_ci
7843d0407baSopenharmony_ci/* i2c adapter classes (bitmask) */
7853d0407baSopenharmony_ci#define I2C_CLASS_HWMON (1 << 0) /* lm_sensors, ... */
7863d0407baSopenharmony_ci#define I2C_CLASS_DDC (1 << 3)   /* DDC bus on graphics adapters */
7873d0407baSopenharmony_ci#define I2C_CLASS_SPD (1 << 7)   /* Memory modules */
7883d0407baSopenharmony_ci/* Warn users that the adapter doesn't support classes anymore */
7893d0407baSopenharmony_ci#define I2C_CLASS_DEPRECATED (1 << 8)
7903d0407baSopenharmony_ci
7913d0407baSopenharmony_ci/* Internal numbers to terminate lists */
7923d0407baSopenharmony_ci#define I2C_CLIENT_END 0xfffeU
7933d0407baSopenharmony_ci
7943d0407baSopenharmony_ci/* Construct an I2C_CLIENT_END-terminated array of i2c addresses */
7953d0407baSopenharmony_ci#define I2C_ADDRS(addr, addrs...) ((const unsigned short[]) {addr, ##addrs, I2C_CLIENT_END})
7963d0407baSopenharmony_ci
7973d0407baSopenharmony_ci/* ----- functions exported by i2c.o */
7983d0407baSopenharmony_ci
7993d0407baSopenharmony_ci/* administration...
8003d0407baSopenharmony_ci */
8013d0407baSopenharmony_ci#if IS_ENABLED(CONFIG_I2C)
8023d0407baSopenharmony_ciint i2c_add_adapter(struct i2c_adapter *adap);
8033d0407baSopenharmony_civoid i2c_del_adapter(struct i2c_adapter *adap);
8043d0407baSopenharmony_ciint i2c_add_numbered_adapter(struct i2c_adapter *adap);
8053d0407baSopenharmony_ci
8063d0407baSopenharmony_ciint i2c_register_driver(struct module *owner, struct i2c_driver *driver);
8073d0407baSopenharmony_civoid i2c_del_driver(struct i2c_driver *driver);
8083d0407baSopenharmony_ci
8093d0407baSopenharmony_ci/* use a define to avoid include chaining to get THIS_MODULE */
8103d0407baSopenharmony_ci#define i2c_add_driver(driver) i2c_register_driver(THIS_MODULE, driver)
8113d0407baSopenharmony_ci
8123d0407baSopenharmony_cistatic inline bool i2c_client_has_driver(struct i2c_client *client)
8133d0407baSopenharmony_ci{
8143d0407baSopenharmony_ci    return !IS_ERR_OR_NULL(client) && client->dev.driver;
8153d0407baSopenharmony_ci}
8163d0407baSopenharmony_ci
8173d0407baSopenharmony_ci/* call the i2c_client->command() of all attached clients with
8183d0407baSopenharmony_ci * the given arguments */
8193d0407baSopenharmony_civoid i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg);
8203d0407baSopenharmony_ci
8213d0407baSopenharmony_cistruct i2c_adapter *i2c_get_adapter(int nr);
8223d0407baSopenharmony_civoid i2c_put_adapter(struct i2c_adapter *adap);
8233d0407baSopenharmony_ciunsigned int i2c_adapter_depth(struct i2c_adapter *adapter);
8243d0407baSopenharmony_ci
8253d0407baSopenharmony_civoid i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t, bool use_defaults);
8263d0407baSopenharmony_ci
8273d0407baSopenharmony_ci/* Return the functionality mask */
8283d0407baSopenharmony_cistatic inline u32 i2c_get_functionality(struct i2c_adapter *adap)
8293d0407baSopenharmony_ci{
8303d0407baSopenharmony_ci    return adap->algo->functionality(adap);
8313d0407baSopenharmony_ci}
8323d0407baSopenharmony_ci
8333d0407baSopenharmony_ci/* Return 1 if adapter supports everything we need, 0 if not. */
8343d0407baSopenharmony_cistatic inline int i2c_check_functionality(struct i2c_adapter *adap, u32 func)
8353d0407baSopenharmony_ci{
8363d0407baSopenharmony_ci    return (func & i2c_get_functionality(adap)) == func;
8373d0407baSopenharmony_ci}
8383d0407baSopenharmony_ci
8393d0407baSopenharmony_ci/**
8403d0407baSopenharmony_ci * i2c_check_quirks() - Function for checking the quirk flags in an i2c adapter
8413d0407baSopenharmony_ci * @adap: i2c adapter
8423d0407baSopenharmony_ci * @quirks: quirk flags
8433d0407baSopenharmony_ci *
8443d0407baSopenharmony_ci * Return: true if the adapter has all the specified quirk flags, false if not
8453d0407baSopenharmony_ci */
8463d0407baSopenharmony_cistatic inline bool i2c_check_quirks(struct i2c_adapter *adap, u64 quirks)
8473d0407baSopenharmony_ci{
8483d0407baSopenharmony_ci    if (!adap->quirks) {
8493d0407baSopenharmony_ci        return false;
8503d0407baSopenharmony_ci    }
8513d0407baSopenharmony_ci    return (adap->quirks->flags & quirks) == quirks;
8523d0407baSopenharmony_ci}
8533d0407baSopenharmony_ci
8543d0407baSopenharmony_ci/* Return the adapter number for a specific adapter */
8553d0407baSopenharmony_cistatic inline int i2c_adapter_id(struct i2c_adapter *adap)
8563d0407baSopenharmony_ci{
8573d0407baSopenharmony_ci    return adap->nr;
8583d0407baSopenharmony_ci}
8593d0407baSopenharmony_ci
8603d0407baSopenharmony_cistatic inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
8613d0407baSopenharmony_ci{
8623d0407baSopenharmony_ci    return (msg->addr << 1) | (msg->flags & I2C_M_RD ? 1 : 0);
8633d0407baSopenharmony_ci}
8643d0407baSopenharmony_ci
8653d0407baSopenharmony_ciu8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold);
8663d0407baSopenharmony_civoid i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred);
8673d0407baSopenharmony_ci
8683d0407baSopenharmony_ciint i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr);
8693d0407baSopenharmony_ci/**
8703d0407baSopenharmony_ci * module_i2c_driver() - Helper macro for registering a modular I2C driver
8713d0407baSopenharmony_ci * @__i2c_driver: i2c_driver struct
8723d0407baSopenharmony_ci *
8733d0407baSopenharmony_ci * Helper macro for I2C drivers which do not do anything special in module
8743d0407baSopenharmony_ci * init/exit. This eliminates a lot of boilerplate. Each module may only
8753d0407baSopenharmony_ci * use this macro once, and calling it replaces module_init() and module_exit()
8763d0407baSopenharmony_ci */
8773d0407baSopenharmony_ci#define module_i2c_driver(__i2c_driver) module_driver(__i2c_driver, i2c_add_driver, i2c_del_driver)
8783d0407baSopenharmony_ci
8793d0407baSopenharmony_ci/**
8803d0407baSopenharmony_ci * builtin_i2c_driver() - Helper macro for registering a builtin I2C driver
8813d0407baSopenharmony_ci * @__i2c_driver: i2c_driver struct
8823d0407baSopenharmony_ci *
8833d0407baSopenharmony_ci * Helper macro for I2C drivers which do not do anything special in their
8843d0407baSopenharmony_ci * init. This eliminates a lot of boilerplate. Each driver may only
8853d0407baSopenharmony_ci * use this macro once, and calling it replaces device_initcall().
8863d0407baSopenharmony_ci */
8873d0407baSopenharmony_ci#define builtin_i2c_driver(__i2c_driver) builtin_driver(__i2c_driver, i2c_add_driver)
8883d0407baSopenharmony_ci
8893d0407baSopenharmony_ci#endif /* I2C */
8903d0407baSopenharmony_ci
8913d0407baSopenharmony_ci#if IS_ENABLED(CONFIG_OF)
8923d0407baSopenharmony_ci/* must call put_device() when done with returned i2c_client device */
8933d0407baSopenharmony_cistruct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
8943d0407baSopenharmony_ci
8953d0407baSopenharmony_ci/* must call put_device() when done with returned i2c_adapter device */
8963d0407baSopenharmony_cistruct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node);
8973d0407baSopenharmony_ci
8983d0407baSopenharmony_ci/* must call i2c_put_adapter() when done with returned i2c_adapter device */
8993d0407baSopenharmony_cistruct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node);
9003d0407baSopenharmony_ci
9013d0407baSopenharmony_ciconst struct of_device_id *i2c_of_match_device(const struct of_device_id *matches, struct i2c_client *client);
9023d0407baSopenharmony_ci
9033d0407baSopenharmony_ciint of_i2c_get_board_info(struct device *dev, struct device_node *node, struct i2c_board_info *info);
9043d0407baSopenharmony_ci
9053d0407baSopenharmony_ci#else
9063d0407baSopenharmony_ci
9073d0407baSopenharmony_cistatic inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
9083d0407baSopenharmony_ci{
9093d0407baSopenharmony_ci    return NULL;
9103d0407baSopenharmony_ci}
9113d0407baSopenharmony_ci
9123d0407baSopenharmony_cistatic inline struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
9133d0407baSopenharmony_ci{
9143d0407baSopenharmony_ci    return NULL;
9153d0407baSopenharmony_ci}
9163d0407baSopenharmony_ci
9173d0407baSopenharmony_cistatic inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)
9183d0407baSopenharmony_ci{
9193d0407baSopenharmony_ci    return NULL;
9203d0407baSopenharmony_ci}
9213d0407baSopenharmony_ci
9223d0407baSopenharmony_cistatic inline const struct of_device_id *i2c_of_match_device(const struct of_device_id *matches,
9233d0407baSopenharmony_ci                                                             struct i2c_client *client)
9243d0407baSopenharmony_ci{
9253d0407baSopenharmony_ci    return NULL;
9263d0407baSopenharmony_ci}
9273d0407baSopenharmony_ci
9283d0407baSopenharmony_cistatic inline int of_i2c_get_board_info(struct device *dev, struct device_node *node, struct i2c_board_info *info)
9293d0407baSopenharmony_ci{
9303d0407baSopenharmony_ci    return -ENOTSUPP;
9313d0407baSopenharmony_ci}
9323d0407baSopenharmony_ci
9333d0407baSopenharmony_ci#endif /* CONFIG_OF */
9343d0407baSopenharmony_ci
9353d0407baSopenharmony_cistruct acpi_resource;
9363d0407baSopenharmony_cistruct acpi_resource_i2c_serialbus;
9373d0407baSopenharmony_ci
9383d0407baSopenharmony_ci#if IS_ENABLED(CONFIG_ACPI)
9393d0407baSopenharmony_cibool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, struct acpi_resource_i2c_serialbus **i2c);
9403d0407baSopenharmony_ciu32 i2c_acpi_find_bus_speed(struct device *dev);
9413d0407baSopenharmony_cistruct i2c_client *i2c_acpi_new_device(struct device *dev, int index, struct i2c_board_info *info);
9423d0407baSopenharmony_cistruct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle);
9433d0407baSopenharmony_ci#else
9443d0407baSopenharmony_cistatic inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, struct acpi_resource_i2c_serialbus **i2c)
9453d0407baSopenharmony_ci{
9463d0407baSopenharmony_ci    return false;
9473d0407baSopenharmony_ci}
9483d0407baSopenharmony_cistatic inline u32 i2c_acpi_find_bus_speed(struct device *dev)
9493d0407baSopenharmony_ci{
9503d0407baSopenharmony_ci    return 0;
9513d0407baSopenharmony_ci}
9523d0407baSopenharmony_cistatic inline struct i2c_client *i2c_acpi_new_device(struct device *dev, int index, struct i2c_board_info *info)
9533d0407baSopenharmony_ci{
9543d0407baSopenharmony_ci    return ERR_PTR(-ENODEV);
9553d0407baSopenharmony_ci}
9563d0407baSopenharmony_cistatic inline struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
9573d0407baSopenharmony_ci{
9583d0407baSopenharmony_ci    return NULL;
9593d0407baSopenharmony_ci}
9603d0407baSopenharmony_ci#endif /* CONFIG_ACPI */
9613d0407baSopenharmony_ci
9623d0407baSopenharmony_ci#endif /* _LINUX_I2C_H */
963