Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * i2c.h - definitions for the Linux i2c bus interface
0004  * Copyright (C) 1995-2000 Simon G. Vogl
0005  * Copyright (C) 2013-2019 Wolfram Sang <wsa@kernel.org>
0006  *
0007  * With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
0008  * Frodo Looijaard <frodol@dds.nl>
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 /* --- General options ------------------------------------------------ */
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 /* I2C Frequency Modes */
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 /* Return the Frequency mode string based on the bus frequency */
0057 const char *i2c_freq_mode_string(u32 bus_freq_hz);
0058 
0059 /*
0060  * The master routines are the ones normally used to transmit data to devices
0061  * on a bus (or read from them). Apart from two basic transfer functions to
0062  * transmit one message at a time, a more complex version can be used to
0063  * transmit an arbitrary number of messages without interruption.
0064  * @count must be less than 64k since msg.len is u16.
0065  */
0066 int i2c_transfer_buffer_flags(const struct i2c_client *client,
0067                   char *buf, int count, u16 flags);
0068 
0069 /**
0070  * i2c_master_recv - issue a single I2C message in master receive mode
0071  * @client: Handle to slave device
0072  * @buf: Where to store data read from slave
0073  * @count: How many bytes to read, must be less than 64k since msg.len is u16
0074  *
0075  * Returns negative errno, or else the number of bytes read.
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  * i2c_master_recv_dmasafe - issue a single I2C message in master receive mode
0085  *               using a DMA safe buffer
0086  * @client: Handle to slave device
0087  * @buf: Where to store data read from slave, must be safe to use with DMA
0088  * @count: How many bytes to read, must be less than 64k since msg.len is u16
0089  *
0090  * Returns negative errno, or else the number of bytes read.
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  * i2c_master_send - issue a single I2C message in master transmit mode
0101  * @client: Handle to slave device
0102  * @buf: Data that will be written to the slave
0103  * @count: How many bytes to write, must be less than 64k since msg.len is u16
0104  *
0105  * Returns negative errno, or else the number of bytes written.
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  * i2c_master_send_dmasafe - issue a single I2C message in master transmit mode
0115  *               using a DMA safe buffer
0116  * @client: Handle to slave device
0117  * @buf: Data that will be written to the slave, must be safe to use with DMA
0118  * @count: How many bytes to write, must be less than 64k since msg.len is u16
0119  *
0120  * Returns negative errno, or else the number of bytes written.
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 /* Transfer num messages.
0130  */
0131 int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
0132 /* Unlocked flavor */
0133 int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
0134 
0135 /* This is the very generalized SMBus access routine. You probably do not
0136    want to use this, though; one of the functions below may be much easier,
0137    and probably just as fast.
0138    Note that we use i2c_adapter here, because you do not need a specific
0139    smbus adapter to call this function. */
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 /* Unlocked flavor */
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 /* Now follow the 'nice' access routines. These also document the calling
0150    conventions of i2c_smbus_xfer. */
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 /* Returns the number of read bytes */
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 /* Returns the number of read bytes */
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 /* I2C */
0193 
0194 /**
0195  * struct i2c_device_identity - i2c client device identification
0196  * @manufacturer_id: 0 - 4095, database maintained by NXP
0197  * @part_id: 0 - 511, according to manufacturer
0198  * @die_revision: 0 - 7, according to manufacturer
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  * enum i2c_driver_flags - Flags for an I2C device driver
0228  *
0229  * @I2C_DRV_ACPI_WAIVE_D0_PROBE: Don't put the device in D0 state for probe
0230  */
0231 enum i2c_driver_flags {
0232     I2C_DRV_ACPI_WAIVE_D0_PROBE = BIT(0),
0233 };
0234 
0235 /**
0236  * struct i2c_driver - represent an I2C device driver
0237  * @class: What kind of i2c device we instantiate (for detect)
0238  * @probe: Callback for device binding - soon to be deprecated
0239  * @probe_new: New callback for device binding
0240  * @remove: Callback for device unbinding
0241  * @shutdown: Callback for device shutdown
0242  * @alert: Alert callback, for example for the SMBus alert protocol
0243  * @command: Callback for bus-wide signaling (optional)
0244  * @driver: Device driver model driver
0245  * @id_table: List of I2C devices supported by this driver
0246  * @detect: Callback for device detection
0247  * @address_list: The I2C addresses to probe (for detect)
0248  * @clients: List of detected clients we created (for i2c-core use only)
0249  * @flags: A bitmask of flags defined in &enum i2c_driver_flags
0250  *
0251  * The driver.owner field should be set to the module owner of this driver.
0252  * The driver.name field should be set to the name of this driver.
0253  *
0254  * For automatic device detection, both @detect and @address_list must
0255  * be defined. @class should also be set, otherwise only devices forced
0256  * with module parameters will be created. The detect function must
0257  * fill at least the name field of the i2c_board_info structure it is
0258  * handed upon successful detection, and possibly also the flags field.
0259  *
0260  * If @detect is missing, the driver will still work fine for enumerated
0261  * devices. Detected devices simply won't be supported. This is expected
0262  * for the many I2C/SMBus devices which can't be detected reliably, and
0263  * the ones which can always be enumerated in practice.
0264  *
0265  * The i2c_client structure which is handed to the @detect callback is
0266  * not a real i2c_client. It is initialized just enough so that you can
0267  * call i2c_smbus_read_byte_data and friends on it. Don't do anything
0268  * else with it. In particular, calling dev_dbg and friends on it is
0269  * not allowed.
0270  */
0271 struct i2c_driver {
0272     unsigned int class;
0273 
0274     /* Standard driver model interfaces */
0275     int (*probe)(struct i2c_client *client, const struct i2c_device_id *id);
0276     int (*remove)(struct i2c_client *client);
0277 
0278     /* New driver model interface to aid the seamless removal of the
0279      * current probe()'s, more commonly unused than used second parameter.
0280      */
0281     int (*probe_new)(struct i2c_client *client);
0282 
0283     /* driver model interfaces that don't relate to enumeration  */
0284     void (*shutdown)(struct i2c_client *client);
0285 
0286     /* Alert callback, for example for the SMBus alert protocol.
0287      * The format and meaning of the data value depends on the protocol.
0288      * For the SMBus alert protocol, there is a single bit of data passed
0289      * as the alert response's low bit ("event flag").
0290      * For the SMBus Host Notify protocol, the data corresponds to the
0291      * 16-bit payload data reported by the slave device acting as master.
0292      */
0293     void (*alert)(struct i2c_client *client, enum i2c_alert_protocol protocol,
0294               unsigned int data);
0295 
0296     /* a ioctl like command that can be used to perform specific functions
0297      * with the device.
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     /* Device detection callback for automatic device creation */
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  * struct i2c_client - represent an I2C slave device
0315  * @flags: see I2C_CLIENT_* for possible flags
0316  * @addr: Address used on the I2C bus connected to the parent adapter.
0317  * @name: Indicates the type of the device, usually a chip name that's
0318  *  generic enough to hide second-sourcing and compatible revisions.
0319  * @adapter: manages the bus segment hosting this I2C device
0320  * @dev: Driver model device node for the slave.
0321  * @init_irq: IRQ that was set at initialization
0322  * @irq: indicates the IRQ generated by this device (if any)
0323  * @detected: member of an i2c_driver.clients list or i2c-core's
0324  *  userspace_devices list
0325  * @slave_cb: Callback when I2C slave mode of an adapter is used. The adapter
0326  *  calls it to pass on slave events to the slave driver.
0327  * @devres_group_id: id of the devres group that will be created for resources
0328  *  acquired when probing this device.
0329  *
0330  * An i2c_client identifies a single device (i.e. chip) connected to an
0331  * i2c bus. The behaviour exposed to Linux is defined by the driver
0332  * managing the device.
0333  */
0334 struct i2c_client {
0335     unsigned short flags;       /* div., see below      */
0336 #define I2C_CLIENT_PEC      0x04    /* Use Packet Error Checking */
0337 #define I2C_CLIENT_TEN      0x10    /* we have a ten bit chip address */
0338                     /* Must equal I2C_M_TEN below */
0339 #define I2C_CLIENT_SLAVE    0x20    /* we are the slave */
0340 #define I2C_CLIENT_HOST_NOTIFY  0x40    /* We want to use I2C host notify */
0341 #define I2C_CLIENT_WAKE     0x80    /* for board_info; true iff can wake */
0342 #define I2C_CLIENT_SCCB     0x9000  /* Use Omnivision SCCB protocol */
0343                     /* Must match I2C_M_STOP|IGNORE_NAK */
0344 
0345     unsigned short addr;        /* chip address - NOTE: 7bit    */
0346                     /* addresses are stored in the  */
0347                     /* _LOWER_ 7 bits       */
0348     char name[I2C_NAME_SIZE];
0349     struct i2c_adapter *adapter;    /* the adapter we sit on    */
0350     struct device dev;      /* the device structure     */
0351     int init_irq;           /* irq set at initialization    */
0352     int irq;            /* irq issued by device     */
0353     struct list_head detected;
0354 #if IS_ENABLED(CONFIG_I2C_SLAVE)
0355     i2c_slave_cb_t slave_cb;    /* callback for slave mode  */
0356 #endif
0357     void *devres_group_id;      /* ID of probe devres group */
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 /* I2C slave support */
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  * struct i2c_board_info - template for device creation
0403  * @type: chip type, to initialize i2c_client.name
0404  * @flags: to initialize i2c_client.flags
0405  * @addr: stored in i2c_client.addr
0406  * @dev_name: Overrides the default <busnr>-<addr> dev_name if set
0407  * @platform_data: stored in i2c_client.dev.platform_data
0408  * @of_node: pointer to OpenFirmware device node
0409  * @fwnode: device node supplied by the platform firmware
0410  * @swnode: software node for the device
0411  * @resources: resources associated with the device
0412  * @num_resources: number of resources in the @resources array
0413  * @irq: stored in i2c_client.irq
0414  *
0415  * I2C doesn't actually support hardware probing, although controllers and
0416  * devices may be able to use I2C_SMBUS_QUICK to tell whether or not there's
0417  * a device at a given address.  Drivers commonly need more information than
0418  * that, such as chip type, configuration, associated IRQ, and so on.
0419  *
0420  * i2c_board_info is used to build tables of information listing I2C devices
0421  * that are present.  This information is used to grow the driver model tree.
0422  * For mainboards this is done statically using i2c_register_board_info();
0423  * bus numbers identify adapters that aren't yet available.  For add-on boards,
0424  * i2c_new_client_device() does this dynamically with the adapter already known.
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  * I2C_BOARD_INFO - macro used to list an i2c device and its address
0442  * @dev_type: identifies the device type
0443  * @dev_addr: the device's address on the bus.
0444  *
0445  * This macro initializes essential fields of a struct i2c_board_info,
0446  * declaring what has been provided on a particular board.  Optional
0447  * fields (such as associated irq, or device-specific platform_data)
0448  * are provided using conventional syntax.
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  * Add-on boards should register/unregister their devices; e.g. a board
0457  * with integrated I2C, a config eeprom, sensors, and a codec that's
0458  * used in conjunction with the primary hardware.
0459  */
0460 struct i2c_client *
0461 i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info);
0462 
0463 /* If you don't know the exact address of an I2C device, use this variant
0464  * instead, which can probe for device presence in a list of possible
0465  * addresses. The "probe" callback function is optional. If it is provided,
0466  * it must return 1 on successful probe, 0 otherwise. If it is not provided,
0467  * a default probing method is used.
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 /* Common custom probe functions */
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 /* I2C */
0498 
0499 /* Mainboard arch_initcall() code should register all its I2C devices.
0500  * This is done at arch_initcall time, before declaring any i2c adapters.
0501  * Modules for add-on boards must use other calls.
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 /* I2C_BOARDINFO */
0515 
0516 /**
0517  * struct i2c_algorithm - represent I2C transfer method
0518  * @master_xfer: Issue a set of i2c transactions to the given I2C adapter
0519  *   defined by the msgs array, with num messages available to transfer via
0520  *   the adapter specified by adap.
0521  * @master_xfer_atomic: same as @master_xfer. Yet, only using atomic context
0522  *   so e.g. PMICs can be accessed very late before shutdown. Optional.
0523  * @smbus_xfer: Issue smbus transactions to the given I2C adapter. If this
0524  *   is not present, then the bus layer will try and convert the SMBus calls
0525  *   into I2C transfers instead.
0526  * @smbus_xfer_atomic: same as @smbus_xfer. Yet, only using atomic context
0527  *   so e.g. PMICs can be accessed very late before shutdown. Optional.
0528  * @functionality: Return the flags that this algorithm/adapter pair supports
0529  *   from the ``I2C_FUNC_*`` flags.
0530  * @reg_slave: Register given client to I2C slave mode of this adapter
0531  * @unreg_slave: Unregister given client from I2C slave mode of this adapter
0532  *
0533  * The following structs are for those who like to implement new bus drivers:
0534  * i2c_algorithm is the interface to a class of hardware solutions which can
0535  * be addressed using the same bus algorithms - i.e. bit-banging or the PCF8584
0536  * to name two of the most common.
0537  *
0538  * The return codes from the ``master_xfer{_atomic}`` fields should indicate the
0539  * type of error code that occurred during the transfer, as documented in the
0540  * Kernel Documentation file Documentation/i2c/fault-codes.rst. Otherwise, the
0541  * number of messages executed should be returned.
0542  */
0543 struct i2c_algorithm {
0544     /*
0545      * If an adapter algorithm can't do I2C-level access, set master_xfer
0546      * to NULL. If an adapter algorithm can do SMBus access, set
0547      * smbus_xfer. If set to NULL, the SMBus protocol is simulated
0548      * using common I2C messages.
0549      *
0550      * master_xfer should return the number of messages successfully
0551      * processed, or a negative value on error
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     /* To determine what the adapter supports */
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  * struct i2c_lock_operations - represent I2C locking operations
0575  * @lock_bus: Get exclusive access to an I2C bus segment
0576  * @trylock_bus: Try to get exclusive access to an I2C bus segment
0577  * @unlock_bus: Release exclusive access to an I2C bus segment
0578  *
0579  * The main operations are wrapped by i2c_lock_bus and i2c_unlock_bus.
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  * struct i2c_timings - I2C timing information
0589  * @bus_freq_hz: the bus frequency in Hz
0590  * @scl_rise_ns: time SCL signal takes to rise in ns; t(r) in the I2C specification
0591  * @scl_fall_ns: time SCL signal takes to fall in ns; t(f) in the I2C specification
0592  * @scl_int_delay_ns: time IP core additionally needs to setup SCL in ns
0593  * @sda_fall_ns: time SDA signal takes to fall in ns; t(f) in the I2C specification
0594  * @sda_hold_ns: time IP core additionally needs to hold SDA in ns
0595  * @digital_filter_width_ns: width in ns of spikes on i2c lines that the IP core
0596  *  digital filter can filter out
0597  * @analog_filter_cutoff_freq_hz: threshold frequency for the low pass IP core
0598  *  analog filter
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  * struct i2c_bus_recovery_info - I2C bus recovery information
0613  * @recover_bus: Recover routine. Either pass driver's recover_bus() routine, or
0614  *  i2c_generic_scl_recovery().
0615  * @get_scl: This gets current value of SCL line. Mandatory for generic SCL
0616  *      recovery. Populated internally for generic GPIO recovery.
0617  * @set_scl: This sets/clears the SCL line. Mandatory for generic SCL recovery.
0618  *      Populated internally for generic GPIO recovery.
0619  * @get_sda: This gets current value of SDA line. This or set_sda() is mandatory
0620  *  for generic SCL recovery. Populated internally, if sda_gpio is a valid
0621  *  GPIO, for generic GPIO recovery.
0622  * @set_sda: This sets/clears the SDA line. This or get_sda() is mandatory for
0623  *  generic SCL recovery. Populated internally, if sda_gpio is a valid GPIO,
0624  *  for generic GPIO recovery.
0625  * @get_bus_free: Returns the bus free state as seen from the IP core in case it
0626  *  has a more complex internal logic than just reading SDA. Optional.
0627  * @prepare_recovery: This will be called before starting recovery. Platform may
0628  *  configure padmux here for SDA/SCL line or something else they want.
0629  * @unprepare_recovery: This will be called after completing recovery. Platform
0630  *  may configure padmux here for SDA/SCL line or something else they want.
0631  * @scl_gpiod: gpiod of the SCL line. Only required for GPIO recovery.
0632  * @sda_gpiod: gpiod of the SDA line. Only required for GPIO recovery.
0633  * @pinctrl: pinctrl used by GPIO recovery to change the state of the I2C pins.
0634  *      Optional.
0635  * @pins_default: default pinctrl state of SCL/SDA lines, when they are assigned
0636  *      to the I2C bus. Optional. Populated internally for GPIO recovery, if
0637  *      state with the name PINCTRL_STATE_DEFAULT is found and pinctrl is valid.
0638  * @pins_gpio: recovery pinctrl state of SCL/SDA lines, when they are used as
0639  *      GPIOs. Optional. Populated internally for GPIO recovery, if this state
0640  *      is called "gpio" or "recovery" and pinctrl is valid.
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     /* gpio recovery */
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 /* Generic recovery routines */
0665 int i2c_generic_scl_recovery(struct i2c_adapter *adap);
0666 
0667 /**
0668  * struct i2c_adapter_quirks - describe flaws of an i2c adapter
0669  * @flags: see I2C_AQ_* for possible flags and read below
0670  * @max_num_msgs: maximum number of messages per transfer
0671  * @max_write_len: maximum length of a write message
0672  * @max_read_len: maximum length of a read message
0673  * @max_comb_1st_msg_len: maximum length of the first msg in a combined message
0674  * @max_comb_2nd_msg_len: maximum length of the second msg in a combined message
0675  *
0676  * Note about combined messages: Some I2C controllers can only send one message
0677  * per transfer, plus something called combined message or write-then-read.
0678  * This is (usually) a small write message followed by a read message and
0679  * barely enough to access register based devices like EEPROMs. There is a flag
0680  * to support this mode. It implies max_num_msg = 2 and does the length checks
0681  * with max_comb_*_len because combined message mode usually has its own
0682  * limitations. Because of HW implementations, some controllers can actually do
0683  * write-then-anything or other variants. To support that, write-then-read has
0684  * been broken out into smaller bits like write-first and read-second which can
0685  * be combined as needed.
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 /* enforce max_num_msgs = 2 and use max_comb_*_len for length checks */
0698 #define I2C_AQ_COMB         BIT(0)
0699 /* first combined message must be write */
0700 #define I2C_AQ_COMB_WRITE_FIRST     BIT(1)
0701 /* second combined message must be read */
0702 #define I2C_AQ_COMB_READ_SECOND     BIT(2)
0703 /* both combined messages must have the same target address */
0704 #define I2C_AQ_COMB_SAME_ADDR       BIT(3)
0705 /* convenience macro for typical write-then read case */
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 /* clock stretching is not supported */
0709 #define I2C_AQ_NO_CLK_STRETCH       BIT(4)
0710 /* message cannot have length of 0 */
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 /* adapter cannot do repeated START */
0715 #define I2C_AQ_NO_REP_START     BIT(7)
0716 
0717 /*
0718  * i2c_adapter is the structure used to identify a physical i2c bus along
0719  * with the access algorithms necessary to access it.
0720  */
0721 struct i2c_adapter {
0722     struct module *owner;
0723     unsigned int class;       /* classes to allow probing for */
0724     const struct i2c_algorithm *algo; /* the algorithm to access the bus */
0725     void *algo_data;
0726 
0727     /* data fields that are valid for all devices   */
0728     const struct i2c_lock_operations *lock_ops;
0729     struct rt_mutex bus_lock;
0730     struct rt_mutex mux_lock;
0731 
0732     int timeout;            /* in jiffies */
0733     int retries;
0734     struct device dev;      /* the adapter device */
0735     unsigned long locked_flags; /* owned by the I2C core */
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 /* Adapter locking functions, exported for shared pin cases */
0780 #define I2C_LOCK_ROOT_ADAPTER BIT(0)
0781 #define I2C_LOCK_SEGMENT      BIT(1)
0782 
0783 /**
0784  * i2c_lock_bus - Get exclusive access to an I2C bus segment
0785  * @adapter: Target I2C bus segment
0786  * @flags: I2C_LOCK_ROOT_ADAPTER locks the root i2c adapter, I2C_LOCK_SEGMENT
0787  *  locks only this branch in the adapter tree
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  * i2c_trylock_bus - Try to get exclusive access to an I2C bus segment
0797  * @adapter: Target I2C bus segment
0798  * @flags: I2C_LOCK_ROOT_ADAPTER tries to locks the root i2c adapter,
0799  *  I2C_LOCK_SEGMENT tries to lock only this branch in the adapter tree
0800  *
0801  * Return: true if the I2C bus segment is locked, false otherwise
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  * i2c_unlock_bus - Release exclusive access to an I2C bus segment
0811  * @adapter: Target I2C bus segment
0812  * @flags: I2C_LOCK_ROOT_ADAPTER unlocks the root i2c adapter, I2C_LOCK_SEGMENT
0813  *  unlocks only this branch in the adapter tree
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  * i2c_mark_adapter_suspended - Report suspended state of the adapter to the core
0823  * @adap: Adapter to mark as suspended
0824  *
0825  * When using this helper to mark an adapter as suspended, the core will reject
0826  * further transfers to this adapter. The usage of this helper is optional but
0827  * recommended for devices having distinct handlers for system suspend and
0828  * runtime suspend. More complex devices are free to implement custom solutions
0829  * to reject transfers when suspended.
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  * i2c_mark_adapter_resumed - Report resumed state of the adapter to the core
0840  * @adap: Adapter to mark as resumed
0841  *
0842  * When using this helper to mark an adapter as resumed, the core will allow
0843  * further transfers to this adapter. See also further notes to
0844  * @i2c_mark_adapter_suspended().
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 /* i2c adapter classes (bitmask) */
0854 #define I2C_CLASS_HWMON     (1<<0)  /* lm_sensors, ... */
0855 #define I2C_CLASS_DDC       (1<<3)  /* DDC bus on graphics adapters */
0856 #define I2C_CLASS_SPD       (1<<7)  /* Memory modules */
0857 /* Warn users that the adapter doesn't support classes anymore */
0858 #define I2C_CLASS_DEPRECATED    (1<<8)
0859 
0860 /* Internal numbers to terminate lists */
0861 #define I2C_CLIENT_END      0xfffeU
0862 
0863 /* Construct an I2C_CLIENT_END-terminated array of i2c addresses */
0864 #define I2C_ADDRS(addr, addrs...) \
0865     ((const unsigned short []){ addr, ## addrs, I2C_CLIENT_END })
0866 
0867 
0868 /* ----- functions exported by i2c.o */
0869 
0870 /* administration...
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 /* use a define to avoid include chaining to get THIS_MODULE */
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 /* call the i2c_client->command() of all attached clients with
0891  * the given arguments */
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 /* Return the functionality mask */
0902 static inline u32 i2c_get_functionality(struct i2c_adapter *adap)
0903 {
0904     return adap->algo->functionality(adap);
0905 }
0906 
0907 /* Return 1 if adapter supports everything we need, 0 if not. */
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  * i2c_check_quirks() - Function for checking the quirk flags in an i2c adapter
0915  * @adap: i2c adapter
0916  * @quirks: quirk flags
0917  *
0918  * Return: true if the adapter has all the specified quirk flags, false if not
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 /* Return the adapter number for a specific adapter */
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  * module_i2c_driver() - Helper macro for registering a modular I2C driver
0944  * @__i2c_driver: i2c_driver struct
0945  *
0946  * Helper macro for I2C drivers which do not do anything special in module
0947  * init/exit. This eliminates a lot of boilerplate. Each module may only
0948  * use this macro once, and calling it replaces module_init() and module_exit()
0949  */
0950 #define module_i2c_driver(__i2c_driver) \
0951     module_driver(__i2c_driver, i2c_add_driver, \
0952             i2c_del_driver)
0953 
0954 /**
0955  * builtin_i2c_driver() - Helper macro for registering a builtin I2C driver
0956  * @__i2c_driver: i2c_driver struct
0957  *
0958  * Helper macro for I2C drivers which do not do anything special in their
0959  * init. This eliminates a lot of boilerplate. Each driver may only
0960  * use this macro once, and calling it replaces device_initcall().
0961  */
0962 #define builtin_i2c_driver(__i2c_driver) \
0963     builtin_driver(__i2c_driver, i2c_add_driver)
0964 
0965 #endif /* I2C */
0966 
0967 #if IS_ENABLED(CONFIG_OF)
0968 /* must call put_device() when done with returned i2c_client device */
0969 struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
0970 
0971 /* must call put_device() when done with returned i2c_adapter device */
0972 struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node);
0973 
0974 /* must call i2c_put_adapter() when done with returned i2c_adapter device */
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 /* CONFIG_OF */
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 /* CONFIG_ACPI */
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 /* _LINUX_I2C_H */