[coreboot-gerrit] New patch to review for coreboot: drivers/i2c/generic: Re-factor SSDT generation code

Furquan Shaikh (furquan@google.com) gerrit at coreboot.org
Sat Oct 22 01:47:57 CEST 2016


Furquan Shaikh (furquan at google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17089

-gerrit

commit f230c588a66b15db26b13234a51183b948b75f86
Author: Furquan Shaikh <furquan at chromium.org>
Date:   Fri Oct 21 16:24:07 2016 -0700

    drivers/i2c/generic: Re-factor SSDT generation code
    
    1. Export i2c_generic_fill_ssdt to allow other device-specific i2c
    drivers to share and re-use the same code for generating AML code for
    SSDT. In order to achieve this, following changes are required:
     a. Add macro I2C_GENERIC_CONFIG that defines a structure with all
     generic i2c device-tree properties. This macro should be placed by the
     using driver at the start of its config structure.
     b. Accept a callback function to add any device specific information to
     SSDT. If generic driver is used directly by a device, callback would be
     NULL. Other devices using a separate i2c driver can provide a callback
     to add any properties to SSDT.
    2. Allow device to provide _CID.
    
    BUG=chrome-os-partner:57846
    
    Change-Id: I3a0054e22b81f9d6d407bef417eae5e9edc04ee4
    Signed-off-by: Furquan Shaikh <furquan at chromium.org>
---
 src/drivers/i2c/generic/chip.h    | 31 +--------------
 src/drivers/i2c/generic/generic.c | 16 +++++++-
 src/drivers/i2c/generic/generic.h | 80 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 96 insertions(+), 31 deletions(-)

diff --git a/src/drivers/i2c/generic/chip.h b/src/drivers/i2c/generic/chip.h
index e84fc38..4614ba3 100644
--- a/src/drivers/i2c/generic/chip.h
+++ b/src/drivers/i2c/generic/chip.h
@@ -1,34 +1,7 @@
 #include <arch/acpi_device.h>
 #include <device/i2c.h>
+#include "generic.h"
 
 struct drivers_i2c_generic_config {
-	const char *hid;	/* ACPI _HID (required) */
-	const char *name;	/* ACPI Device Name */
-	const char *desc;	/* Device Description */
-	unsigned uid;		/* ACPI _UID */
-	enum i2c_speed speed;	/* Bus speed in Hz, default is I2C_SPEED_FAST */
-	unsigned wake;		/* Wake GPE */
-	struct acpi_irq irq;	/* Interrupt */
-
-	/*
-	 * This flag will add a device propery which will indicate
-	 * to the OS that it should probe this device before adding it.
-	 *
-	 * This can be used to declare a device that may not exist on
-	 * the board, for example to support multiple trackpad vendors.
-	 */
-	int probed;
-
-	/* GPIO used to indicate if this device is present */
-	unsigned device_present_gpio;
-	unsigned device_present_gpio_invert;
-
-	/* GPIO used to take device out of reset or to put it into reset. */
-        unsigned reset_gpio;
-	/* Delay to be inserted after device is taken out of reset. */
-	unsigned reset_delay_ms;
-	/* GPIO used to enable device. */
-	unsigned enable_gpio;
-	/* Delay to be inserted after device is enabled. */
-	unsigned enable_delay_ms;
+	I2C_GENERIC_CONFIG;
 };
diff --git a/src/drivers/i2c/generic/generic.c b/src/drivers/i2c/generic/generic.c
index 7f078b0..410f396 100644
--- a/src/drivers/i2c/generic/generic.c
+++ b/src/drivers/i2c/generic/generic.c
@@ -61,7 +61,8 @@ static void i2c_generic_add_power_res(struct drivers_i2c_generic_config *config)
 	acpigen_pop_len();		/* PowerResource PRIC */
 }
 
-static void i2c_generic_fill_ssdt(struct device *dev)
+void i2c_generic_fill_ssdt(struct device *dev,
+			   void (*callback)(struct device *dev))
 {
 	struct drivers_i2c_generic_config *config = dev->chip_info;
 	const char *scope = acpi_device_scope(dev);
@@ -85,6 +86,8 @@ static void i2c_generic_fill_ssdt(struct device *dev)
 	acpigen_write_scope(scope);
 	acpigen_write_device(acpi_device_name(dev));
 	acpigen_write_name_string("_HID", config->hid);
+	if (config->cid)
+		acpigen_write_name_string("_CID", config->cid);
 	acpigen_write_name_integer("_UID", config->uid);
 	acpigen_write_name_string("_DDN", config->desc);
 	acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
@@ -111,6 +114,10 @@ static void i2c_generic_fill_ssdt(struct device *dev)
 	/* Power Resource */
 	i2c_generic_add_power_res(config);
 
+	/* Callback if any. */
+	if (callback)
+		callback(dev);
+
 	acpigen_pop_len(); /* Device */
 	acpigen_pop_len(); /* Scope */
 
@@ -118,6 +125,11 @@ static void i2c_generic_fill_ssdt(struct device *dev)
 	       config->desc ? : dev->chip_ops->name, dev_path(dev));
 }
 
+static void i2c_generic_fill_ssdt_generator(struct device *dev)
+{
+	i2c_generic_fill_ssdt(dev, NULL);
+}
+
 /* Use name specified in config or build one from I2C address */
 static const char *i2c_generic_acpi_name(struct device *dev)
 {
@@ -139,7 +151,7 @@ static struct device_operations i2c_generic_ops = {
 	.enable_resources	  = DEVICE_NOOP,
 #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
 	.acpi_name		  = &i2c_generic_acpi_name,
-	.acpi_fill_ssdt_generator = &i2c_generic_fill_ssdt,
+	.acpi_fill_ssdt_generator = &i2c_generic_fill_ssdt_generator,
 #endif
 };
 
diff --git a/src/drivers/i2c/generic/generic.h b/src/drivers/i2c/generic/generic.h
new file mode 100644
index 0000000..60445c2
--- /dev/null
+++ b/src/drivers/i2c/generic/generic.h
@@ -0,0 +1,80 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2016 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __I2C_GENERIC_GENERIC_H__
+#define __I2C_GENERIC_GENERIC_H__
+
+#include <device/device.h>
+
+/*
+ * Macro defining all the generic i2c device-tree properties that are used by
+ * ssdt generator. Drivers using i2c_generic_fill_ssdt should place this macro
+ * at the start of their config structure.
+ */
+#define I2C_GENERIC_CONFIG						\
+	struct {							\
+		/* ACPI _HID (required) */				\
+		const char *hid;					\
+		/* ACPI _CID */					\
+		const char *cid;					\
+		/* ACPI Device Name */					\
+		const char *name;					\
+		/* Device Description */				\
+		const char *desc;					\
+		/* ACPI _UID */					\
+		unsigned uid;						\
+		/* Bus speed in Hz, default is I2C_SPEED_FAST */	\
+		enum i2c_speed speed;					\
+		/* Wake GPE */						\
+		unsigned wake;						\
+		/* Interrupt */					\
+		struct acpi_irq irq;					\
+		/*							\
+		 * This flag will add a device propery which will	\
+		 * indicate to the OS that it should probe this	\
+		 * device before adding it.				\
+		 *							\
+		 * This can be used to declare a device that may not	\
+		 * exist on the board, for example to support multiple	\
+		 * trackpad vendors.					\
+		 */							\
+		int probed;						\
+		/* GPIO used to indicate if this device is present */	\
+		unsigned device_present_gpio;				\
+		unsigned device_present_gpio_invert;			\
+		/*							\
+		 * GPIO used to take device out of reset or to put	\
+		 * it into reset. */					\
+		unsigned reset_gpio;					\
+		/*							\
+		 * Delay to be inserted after device is taken out of	\
+		 * reset. */						\
+		unsigned reset_delay_ms;				\
+		/* GPIO used to enable device. */			\
+		unsigned enable_gpio;					\
+		/* Delay to be inserted after device is enabled. */	\
+		unsigned enable_delay_ms;				\
+	}
+
+/*
+ * Fills in generic information about i2c device from device-tree
+ * properties. Place I2C_GENERIC_CONFIG at the start of device config
+ * structure. Callback can be provided to fill in any device-specific
+ * information in SSDT.
+ */
+void i2c_generic_fill_ssdt(struct device *dev,
+			   void (*callback)(struct device *dev));
+
+#endif /* __I2C_GENERIC_GENERIC_H__ */



More information about the coreboot-gerrit mailing list