2021-01-18 18:28:21 +03:00
|
|
|
/* $NetBSD: i2cvar.h,v 1.22 2021/01/18 15:28:21 thorpej Exp $ */
|
2003-09-30 04:35:30 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2003 Wasabi Systems, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Steve C. Woodford and Jason R. Thorpe for Wasabi Systems, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project by
|
|
|
|
* Wasabi Systems, Inc.
|
|
|
|
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _DEV_I2C_I2CVAR_H_
|
|
|
|
#define _DEV_I2C_I2CVAR_H_
|
|
|
|
|
2018-06-17 00:22:13 +03:00
|
|
|
#include <sys/device.h>
|
2019-12-23 02:23:29 +03:00
|
|
|
#include <sys/mutex.h>
|
2003-09-30 04:35:30 +04:00
|
|
|
#include <dev/i2c/i2c_io.h>
|
2015-12-13 20:14:56 +03:00
|
|
|
#include <prop/proplib.h>
|
2003-09-30 04:35:30 +04:00
|
|
|
|
|
|
|
/* Flags passed to i2c routines. */
|
2020-12-29 03:26:51 +03:00
|
|
|
#define I2C_F_WRITE 0 /* new transfer is a write */
|
|
|
|
#define I2C_F_READ __BIT(0) /* new transfer is a read */
|
|
|
|
#define I2C_F_LAST __BIT(1) /* last byte of read */
|
|
|
|
#define I2C_F_STOP __BIT(2) /* send stop after byte */
|
|
|
|
#define I2C_F_POLL __BIT(3) /* poll, don't sleep */
|
|
|
|
#define I2C_F_PEC __BIT(4) /* smbus packet error checking */
|
|
|
|
#define I2C_F_SPEED __BITS(28,31) /* I2C transfer speed selector */
|
|
|
|
|
|
|
|
#define I2C_SPEED_SM 0 /* standard mode (100Kb/s) */
|
|
|
|
#define I2C_SPEED_FM 1 /* fast mode (400Kb/s) */
|
|
|
|
#define I2C_SPEED_FMPLUS 2 /* fast mode+ (1Mb/s) */
|
|
|
|
#define I2C_SPEED_HS 3 /* high speed (3.4Mb/s) */
|
2003-09-30 04:35:30 +04:00
|
|
|
|
Changes / enhancements to i2c indirect device auto-configuration:
— iic_search() chooses a “probe strategy” based on the
"i2c-indirect-probe-strategy” property on the “iic” instance.
Valid values are "smbus-quick-write”, "smbus-receive-byte”, and
“none”. If no value is specified, the default is "smbus-quick-write”.
— If the "i2c-indirect-device-whitelist” exists on the “iic” instance,
iic_search() will first check the driver name in the cfdata_t against
this list, and only allow the match/probe to move forward if the
cfdata_t driver name is in the list. This is primarily to accommodate
the Intel integrated memory controller neutered-i2c-thing.
— If the cfdata_t specifies a wildcard address, each address of the i2c
bus will be consulted. If the cfdata_t contains a nailed-down address,
then we limit the bus scan to that specific address.
— We explicitly skip reserved / special i2c addresses, such as the
General-Call address, etc.
— We introduce the notion of a “match quality” for i2c drivers. From
lowest-quality to highest-quality: matched by plausible address only,
matched by plausible address and poking at the bus to see if the
device looks reasonable, matched by direct-config “compatible” string,
matched by direct-config “driver name” string.
— If the “match quality” is merely “plausible address only”, then
iic_search() will use the probe strategy selected above to see if
a device responds to that address.
2018-06-07 16:30:49 +03:00
|
|
|
/* i2c bus instance properties */
|
|
|
|
#define I2C_PROP_INDIRECT_PROBE_STRATEGY \
|
|
|
|
"i2c-indirect-probe-strategy"
|
|
|
|
#define I2C_PROBE_STRATEGY_QUICK_WRITE \
|
|
|
|
"smbus-quick-write"
|
|
|
|
#define I2C_PROBE_STRATEGY_RECEIVE_BYTE \
|
|
|
|
"smbus-receive-byte"
|
|
|
|
#define I2C_PROBE_STRATEGY_NONE \
|
|
|
|
"none"
|
|
|
|
|
2020-07-07 19:14:23 +03:00
|
|
|
#define I2C_PROP_INDIRECT_DEVICE_PERMITLIST \
|
|
|
|
"i2c-indirect-device-permitlist"
|
Changes / enhancements to i2c indirect device auto-configuration:
— iic_search() chooses a “probe strategy” based on the
"i2c-indirect-probe-strategy” property on the “iic” instance.
Valid values are "smbus-quick-write”, "smbus-receive-byte”, and
“none”. If no value is specified, the default is "smbus-quick-write”.
— If the "i2c-indirect-device-whitelist” exists on the “iic” instance,
iic_search() will first check the driver name in the cfdata_t against
this list, and only allow the match/probe to move forward if the
cfdata_t driver name is in the list. This is primarily to accommodate
the Intel integrated memory controller neutered-i2c-thing.
— If the cfdata_t specifies a wildcard address, each address of the i2c
bus will be consulted. If the cfdata_t contains a nailed-down address,
then we limit the bus scan to that specific address.
— We explicitly skip reserved / special i2c addresses, such as the
General-Call address, etc.
— We introduce the notion of a “match quality” for i2c drivers. From
lowest-quality to highest-quality: matched by plausible address only,
matched by plausible address and poking at the bus to see if the
device looks reasonable, matched by direct-config “compatible” string,
matched by direct-config “driver name” string.
— If the “match quality” is merely “plausible address only”, then
iic_search() will use the probe strategy selected above to see if
a device responds to that address.
2018-06-07 16:30:49 +03:00
|
|
|
/* value is a prop_array of prop_strings */
|
|
|
|
|
2007-02-06 02:31:37 +03:00
|
|
|
struct ic_intr_list {
|
|
|
|
LIST_ENTRY(ic_intr_list) il_next;
|
|
|
|
int (*il_intr)(void *);
|
|
|
|
void *il_intrarg;
|
|
|
|
};
|
|
|
|
|
2003-09-30 04:35:30 +04:00
|
|
|
/*
|
|
|
|
* This structure provides the interface between the i2c framework
|
|
|
|
* and the underlying i2c controller.
|
|
|
|
*
|
|
|
|
* Note that this structure is designed specifically to allow us
|
|
|
|
* to either use the autoconfiguration framework or not. This
|
|
|
|
* allows a driver for a board with a private i2c bus use generic
|
|
|
|
* i2c client drivers for chips that might be on that board.
|
|
|
|
*/
|
|
|
|
typedef struct i2c_controller {
|
|
|
|
void *ic_cookie; /* controller private */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These provide synchronization in the presence of
|
|
|
|
* multiple users of the i2c bus. When a device
|
|
|
|
* driver wishes to perform transfers on the i2c
|
|
|
|
* bus, the driver should acquire the bus. When
|
|
|
|
* the driver is finished, it should release the
|
|
|
|
* bus.
|
|
|
|
*
|
2019-12-23 02:23:29 +03:00
|
|
|
* The main synchronization logic is handled by the
|
|
|
|
* generic i2c layer, but optional hooks to back-end
|
|
|
|
* drivers are provided in case additional processing
|
|
|
|
* is needed (e.g. enabling the i2c controller).
|
2003-09-30 04:35:30 +04:00
|
|
|
*/
|
2019-12-23 02:23:29 +03:00
|
|
|
kmutex_t ic_bus_lock;
|
2003-09-30 04:35:30 +04:00
|
|
|
int (*ic_acquire_bus)(void *, int);
|
|
|
|
void (*ic_release_bus)(void *, int);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The preferred API for clients of the i2c interface
|
|
|
|
* is the scripted API. This handles i2c controllers
|
|
|
|
* that do not provide raw access to the i2c signals.
|
|
|
|
*/
|
|
|
|
int (*ic_exec)(void *, i2c_op_t, i2c_addr_t, const void *, size_t,
|
|
|
|
void *, size_t, int);
|
|
|
|
|
|
|
|
int (*ic_send_start)(void *, int);
|
|
|
|
int (*ic_send_stop)(void *, int);
|
|
|
|
int (*ic_initiate_xfer)(void *, i2c_addr_t, int);
|
|
|
|
int (*ic_read_byte)(void *, uint8_t *, int);
|
|
|
|
int (*ic_write_byte)(void *, uint8_t, int);
|
2007-02-06 02:31:37 +03:00
|
|
|
|
|
|
|
LIST_HEAD(, ic_intr_list) ic_list;
|
|
|
|
LIST_HEAD(, ic_intr_list) ic_proc_list;
|
|
|
|
volatile int ic_running;
|
|
|
|
volatile int ic_pending;
|
2007-07-10 00:51:58 +04:00
|
|
|
struct lwp *ic_intr_thread;
|
2007-02-06 02:31:37 +03:00
|
|
|
const char *ic_devname;
|
2003-09-30 04:35:30 +04:00
|
|
|
} *i2c_tag_t;
|
|
|
|
|
|
|
|
/* Used to attach the i2c framework to the controller. */
|
|
|
|
struct i2cbus_attach_args {
|
|
|
|
i2c_tag_t iba_tag; /* the controller */
|
2015-12-13 20:14:56 +03:00
|
|
|
prop_array_t iba_child_devices; /* child devices (direct config) */
|
2003-09-30 04:35:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Used to attach devices on the i2c bus. */
|
|
|
|
struct i2c_attach_args {
|
|
|
|
i2c_tag_t ia_tag; /* our controller */
|
|
|
|
i2c_addr_t ia_addr; /* address of device */
|
2006-03-28 03:59:38 +04:00
|
|
|
int ia_type; /* bus type */
|
2010-02-28 14:34:42 +03:00
|
|
|
/* only set if using direct config */
|
|
|
|
const char * ia_name; /* name of the device */
|
|
|
|
int ia_ncompat; /* number of pointers in the
|
|
|
|
ia_compat array */
|
|
|
|
const char ** ia_compat; /* chip names */
|
2017-12-10 19:53:32 +03:00
|
|
|
prop_dictionary_t ia_prop; /* dictionnary for this device */
|
2010-02-28 14:34:42 +03:00
|
|
|
/*
|
2010-02-28 18:33:21 +03:00
|
|
|
* The following is of limited usefulness and should only be used
|
|
|
|
* in rare cases where we really know what we are doing. Example:
|
|
|
|
* a machine dependent i2c driver (located in sys/arch/$arch/dev)
|
2010-02-28 14:34:42 +03:00
|
|
|
* needing to access some firmware properties.
|
|
|
|
* Depending on the firmware in use, an identifier for the device
|
|
|
|
* may be present. Example: on OpenFirmware machines the device
|
|
|
|
* tree OF node - if available. This info is hard to transport
|
|
|
|
* down to MD drivers through the MI i2c bus otherwise.
|
2017-12-10 19:53:32 +03:00
|
|
|
*
|
|
|
|
* On ACPI platforms this is the ACPI_HANDLE of the device.
|
2010-02-28 14:34:42 +03:00
|
|
|
*/
|
|
|
|
uintptr_t ia_cookie; /* OF node in openfirmware machines */
|
2003-09-30 04:35:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* API presented to i2c controllers.
|
|
|
|
*/
|
|
|
|
int iicbus_print(void *, const char *);
|
2019-12-23 02:23:29 +03:00
|
|
|
void iic_tag_init(i2c_tag_t);
|
|
|
|
void iic_tag_fini(i2c_tag_t);
|
2018-06-17 00:22:13 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* API presented to i2c devices.
|
|
|
|
*/
|
2018-06-26 07:32:35 +03:00
|
|
|
int iic_compatible_match(const struct i2c_attach_args *,
|
2021-01-18 18:28:21 +03:00
|
|
|
const struct device_compatible_entry *);
|
2018-06-18 20:07:07 +03:00
|
|
|
bool iic_use_direct_match(const struct i2c_attach_args *, const cfdata_t,
|
|
|
|
const struct device_compatible_entry *, int *);
|
2021-01-18 18:28:21 +03:00
|
|
|
const struct device_compatible_entry *
|
|
|
|
iic_compatible_lookup(const struct i2c_attach_args *,
|
|
|
|
const struct device_compatible_entry *);
|
2003-09-30 04:35:30 +04:00
|
|
|
|
Changes / enhancements to i2c indirect device auto-configuration:
— iic_search() chooses a “probe strategy” based on the
"i2c-indirect-probe-strategy” property on the “iic” instance.
Valid values are "smbus-quick-write”, "smbus-receive-byte”, and
“none”. If no value is specified, the default is "smbus-quick-write”.
— If the "i2c-indirect-device-whitelist” exists on the “iic” instance,
iic_search() will first check the driver name in the cfdata_t against
this list, and only allow the match/probe to move forward if the
cfdata_t driver name is in the list. This is primarily to accommodate
the Intel integrated memory controller neutered-i2c-thing.
— If the cfdata_t specifies a wildcard address, each address of the i2c
bus will be consulted. If the cfdata_t contains a nailed-down address,
then we limit the bus scan to that specific address.
— We explicitly skip reserved / special i2c addresses, such as the
General-Call address, etc.
— We introduce the notion of a “match quality” for i2c drivers. From
lowest-quality to highest-quality: matched by plausible address only,
matched by plausible address and poking at the bus to see if the
device looks reasonable, matched by direct-config “compatible” string,
matched by direct-config “driver name” string.
— If the “match quality” is merely “plausible address only”, then
iic_search() will use the probe strategy selected above to see if
a device responds to that address.
2018-06-07 16:30:49 +03:00
|
|
|
/*
|
|
|
|
* Constants to indicate the quality of a match made by a driver's
|
|
|
|
* match routine, from lowest to higest:
|
|
|
|
*
|
|
|
|
* -- Address only; no other checks were made.
|
|
|
|
*
|
|
|
|
* -- Address + device probed and recognized.
|
|
|
|
*
|
|
|
|
* -- Direct-config match by "compatible" string.
|
|
|
|
*
|
|
|
|
* -- Direct-config match by specific driver name.
|
|
|
|
*/
|
|
|
|
#define I2C_MATCH_ADDRESS_ONLY 1
|
|
|
|
#define I2C_MATCH_ADDRESS_AND_PROBE 2
|
|
|
|
#define I2C_MATCH_DIRECT_COMPATIBLE 10
|
2018-06-17 00:22:13 +03:00
|
|
|
#define I2C_MATCH_DIRECT_COMPATIBLE_MAX 99
|
|
|
|
#define I2C_MATCH_DIRECT_SPECIFIC 100
|
Changes / enhancements to i2c indirect device auto-configuration:
— iic_search() chooses a “probe strategy” based on the
"i2c-indirect-probe-strategy” property on the “iic” instance.
Valid values are "smbus-quick-write”, "smbus-receive-byte”, and
“none”. If no value is specified, the default is "smbus-quick-write”.
— If the "i2c-indirect-device-whitelist” exists on the “iic” instance,
iic_search() will first check the driver name in the cfdata_t against
this list, and only allow the match/probe to move forward if the
cfdata_t driver name is in the list. This is primarily to accommodate
the Intel integrated memory controller neutered-i2c-thing.
— If the cfdata_t specifies a wildcard address, each address of the i2c
bus will be consulted. If the cfdata_t contains a nailed-down address,
then we limit the bus scan to that specific address.
— We explicitly skip reserved / special i2c addresses, such as the
General-Call address, etc.
— We introduce the notion of a “match quality” for i2c drivers. From
lowest-quality to highest-quality: matched by plausible address only,
matched by plausible address and poking at the bus to see if the
device looks reasonable, matched by direct-config “compatible” string,
matched by direct-config “driver name” string.
— If the “match quality” is merely “plausible address only”, then
iic_search() will use the probe strategy selected above to see if
a device responds to that address.
2018-06-07 16:30:49 +03:00
|
|
|
|
2003-09-30 04:35:30 +04:00
|
|
|
#ifdef _I2C_PRIVATE
|
|
|
|
/*
|
|
|
|
* Macros used internally by the i2c framework.
|
|
|
|
*/
|
|
|
|
#define iic_send_start(ic, flags) \
|
|
|
|
(*(ic)->ic_send_start)((ic)->ic_cookie, (flags))
|
|
|
|
#define iic_send_stop(ic, flags) \
|
|
|
|
(*(ic)->ic_send_stop)((ic)->ic_cookie, (flags))
|
|
|
|
#define iic_initiate_xfer(ic, addr, flags) \
|
|
|
|
(*(ic)->ic_initiate_xfer)((ic)->ic_cookie, (addr), (flags))
|
|
|
|
|
|
|
|
#define iic_read_byte(ic, bytep, flags) \
|
|
|
|
(*(ic)->ic_read_byte)((ic)->ic_cookie, (bytep), (flags))
|
|
|
|
#define iic_write_byte(ic, byte, flags) \
|
|
|
|
(*(ic)->ic_write_byte)((ic)->ic_cookie, (byte), (flags))
|
|
|
|
#endif /* _I2C_PRIVATE */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified API for clients of the i2c framework. Definitions
|
|
|
|
* in <dev/i2c/i2c_io.h>.
|
|
|
|
*/
|
2018-12-10 03:31:45 +03:00
|
|
|
int iic_acquire_bus(i2c_tag_t, int);
|
|
|
|
void iic_release_bus(i2c_tag_t, int);
|
2003-09-30 04:35:30 +04:00
|
|
|
int iic_exec(i2c_tag_t, i2c_op_t, i2c_addr_t, const void *,
|
|
|
|
size_t, void *, size_t, int);
|
|
|
|
|
|
|
|
int iic_smbus_write_byte(i2c_tag_t, i2c_addr_t, uint8_t, uint8_t, int);
|
2006-03-28 03:59:38 +04:00
|
|
|
int iic_smbus_write_word(i2c_tag_t, i2c_addr_t, uint8_t, uint16_t, int);
|
2003-09-30 04:35:30 +04:00
|
|
|
int iic_smbus_read_byte(i2c_tag_t, i2c_addr_t, uint8_t, uint8_t *, int);
|
2006-03-28 03:59:38 +04:00
|
|
|
int iic_smbus_read_word(i2c_tag_t, i2c_addr_t, uint8_t, uint16_t *, int);
|
2003-09-30 04:35:30 +04:00
|
|
|
int iic_smbus_receive_byte(i2c_tag_t, i2c_addr_t, uint8_t *, int);
|
2006-03-28 03:59:38 +04:00
|
|
|
int iic_smbus_send_byte(i2c_tag_t, i2c_addr_t, uint8_t, int);
|
|
|
|
int iic_smbus_quick_read(i2c_tag_t, i2c_addr_t, int);
|
|
|
|
int iic_smbus_quick_write(i2c_tag_t, i2c_addr_t, int);
|
|
|
|
int iic_smbus_block_read(i2c_tag_t, i2c_addr_t, uint8_t, uint8_t *,
|
|
|
|
size_t, int);
|
|
|
|
int iic_smbus_block_write(i2c_tag_t, i2c_addr_t, uint8_t, uint8_t *,
|
|
|
|
size_t, int);
|
2003-09-30 04:35:30 +04:00
|
|
|
|
2007-02-06 02:31:37 +03:00
|
|
|
void * iic_smbus_intr_establish(i2c_tag_t, int (*)(void *), void *);
|
|
|
|
void * iic_smbus_intr_establish_proc(i2c_tag_t, int (*)(void *), void *);
|
|
|
|
void iic_smbus_intr_disestablish(i2c_tag_t, void *);
|
|
|
|
void iic_smbus_intr_disestablish_proc(i2c_tag_t, void *);
|
|
|
|
int iic_smbus_intr(i2c_tag_t);
|
|
|
|
|
2003-09-30 04:35:30 +04:00
|
|
|
#endif /* _DEV_I2C_I2CVAR_H_ */
|