i2c: Add a generic driver to generate ACPI info

Many I2C devices produce roughly the same ACPI data with just things like
the GPIO/interrupt information being different.

This can be handled by a generic driver along with some information in the
device tree.

Add a generic i2c driver for this purpose.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heiko Schocher <hs@denx.de>
This commit is contained in:
Simon Glass
2020-09-22 12:45:01 -06:00
committed by Bin Meng
parent bddbaf5edf
commit fd42f263ce
7 changed files with 381 additions and 0 deletions

View File

@@ -10,7 +10,9 @@
#define __ACPI_DEVICE_H
#include <i2c.h>
#include <irq.h>
#include <spi.h>
#include <asm-generic/gpio.h>
#include <linux/bitops.h>
struct acpi_ctx;
@@ -235,6 +237,59 @@ struct acpi_spi {
const char *resource;
};
/**
* struct acpi_i2c_priv - Information read from device tree
*
* This is used by devices which want to specify various pieces of ACPI
* information, including power control. It allows a generic function to
* generate the information for ACPI, based on device-tree properties.
*
* @disable_gpio_export_in_crs: Don't export GPIOs in the CRS
* @reset_gpio: GPIO used to assert reset to the device
* @enable_gpio: GPIO used to enable the device
* @stop_gpio: GPIO used to stop the device
* @irq_gpio: GPIO used for interrupt (if @irq is not used)
* @irq: IRQ used for interrupt (if @irq_gpio is not used)
* @hid: _HID value for device (required)
* @uid: _UID value for device
* @desc: _DDN value for device
* @wake: Wake event, e.g. GPE0_DW1_15; 0 if none
* @property_count: Number of other DSD properties (currently always 0)
* @probed: true set set 'linux,probed' property
* @compat_string: Device tree compatible string to report through ACPI
* @has_power_resource: true if this device has a power resource
* @reset_delay_ms: Delay after de-asserting reset, in ms
* @reset_off_delay_ms: Delay after asserting reset (during power off)
* @enable_delay_ms: Delay after asserting enable
* @enable_off_delay_ms: Delay after de-asserting enable (during power off)
* @stop_delay_ms: Delay after de-aserting stop
* @stop_off_delay_ms: Delay after asserting stop (during power off)
* @hid_desc_reg_offset: HID register offset (for Human Interface Devices)
*/
struct acpi_i2c_priv {
bool disable_gpio_export_in_crs;
struct gpio_desc reset_gpio;
struct gpio_desc enable_gpio;
struct gpio_desc irq_gpio;
struct gpio_desc stop_gpio;
struct irq irq;
const char *hid;
u32 uid;
const char *desc;
u32 wake;
u32 property_count;
bool probed;
const char *compat_string;
bool has_power_resource;
u32 reset_delay_ms;
u32 reset_off_delay_ms;
u32 enable_delay_ms;
u32 enable_off_delay_ms;
u32 stop_delay_ms;
u32 stop_off_delay_ms;
u32 hid_desc_reg_offset;
};
/**
* acpi_device_path() - Get the full path to an ACPI device
*

View File

@@ -58,6 +58,12 @@ enum i2c_address_mode {
I2C_MODE_10_BIT
};
/** enum i2c_device_t - Types of I2C devices, used for compatible strings */
enum i2c_device_t {
I2C_DEVICE_GENERIC,
I2C_DEVICE_HID_OVER_I2C,
};
struct udevice;
/**
* struct dm_i2c_chip - information about an i2c chip
@@ -558,6 +564,23 @@ int i2c_emul_find(struct udevice *dev, struct udevice **emulp);
*/
struct udevice *i2c_emul_get_device(struct udevice *emul);
/* ACPI operations for generic I2C devices */
extern struct acpi_ops i2c_acpi_ops;
/**
* acpi_i2c_ofdata_to_platdata() - Read properties intended for ACPI
*
* This reads the generic I2C properties from the device tree, so that these
* can be used to create ACPI information for the device.
*
* See the i2c/generic-acpi.txt binding file for information about the
* properties.
*
* @dev: I2C device to process
* @return 0 if OK, -EINVAL if acpi,hid is not present
*/
int acpi_i2c_ofdata_to_platdata(struct udevice *dev);
#ifndef CONFIG_DM_I2C
/*