<p>Werner Zeh has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/23748">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">drivers/i2c: Add chip driver for I/O expander PCA9538<br><br>The chip PCA9538 is a 8 bit I/O expander connected to the systems I2C<br>bus. Add a chip driver to support this chip.<br><br>Beside the pure chip driver two interface functions are provided to read<br>the state of the pins and write output values to the pins.<br>As the slave address of this chip is hardware configurable the function<br>pca9538_get_dev() is used to get the right slave address. This function<br>needs to be implemented in mainboard code if one needs to use the<br>interface functions to read and write I/O state.<br><br>Change-Id: Ic856123b4f4c8b721928ee3a2a4bb37833ea4b20<br>Signed-off-by: Werner Zeh <werner.zeh@siemens.com><br>---<br>A src/drivers/i2c/pca9538/Kconfig<br>A src/drivers/i2c/pca9538/Makefile.inc<br>A src/drivers/i2c/pca9538/chip.h<br>A src/drivers/i2c/pca9538/pca9538.c<br>A src/drivers/i2c/pca9538/pca9538.h<br>5 files changed, 136 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/48/23748/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/drivers/i2c/pca9538/Kconfig b/src/drivers/i2c/pca9538/Kconfig</span><br><span>new file mode 100644</span><br><span>index 0000000..558332b</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/i2c/pca9538/Kconfig</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+config DRIVERS_I2C_PCA9538</span><br><span style="color: hsl(120, 100%, 40%);">+       bool</span><br><span style="color: hsl(120, 100%, 40%);">+  default n</span><br><span style="color: hsl(120, 100%, 40%);">+     help</span><br><span style="color: hsl(120, 100%, 40%);">+    Enable support for I2C I/O expander PCA9538.</span><br><span>diff --git a/src/drivers/i2c/pca9538/Makefile.inc b/src/drivers/i2c/pca9538/Makefile.inc</span><br><span>new file mode 100644</span><br><span>index 0000000..cc35a24</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/i2c/pca9538/Makefile.inc</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+ramstage-$(CONFIG_DRIVERS_I2C_PCA9538) += pca9538.c</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ifeq ($(CONFIG_DRIVERS_I2C_PCA9538),y)</span><br><span style="color: hsl(120, 100%, 40%);">+CFLAGS_x86_32 += -Isrc/drivers/i2c/pca9538</span><br><span style="color: hsl(120, 100%, 40%);">+endif</span><br><span>diff --git a/src/drivers/i2c/pca9538/chip.h b/src/drivers/i2c/pca9538/chip.h</span><br><span>new file mode 100644</span><br><span>index 0000000..9c60aab</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/i2c/pca9538/chip.h</span><br><span>@@ -0,0 +1,21 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 Siemens AG</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct drivers_i2c_pca9538_config {</span><br><span style="color: hsl(120, 100%, 40%);">+    unsigned char in_out;   /* Use bit as input(1) or output (0). */</span><br><span style="color: hsl(120, 100%, 40%);">+      unsigned char invert;   /* If a bit is 1, the input will be inverted. */</span><br><span style="color: hsl(120, 100%, 40%);">+      unsigned char out_val;  /* Initial output value to drive. */</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span>diff --git a/src/drivers/i2c/pca9538/pca9538.c b/src/drivers/i2c/pca9538/pca9538.c</span><br><span>new file mode 100644</span><br><span>index 0000000..2841a77</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/i2c/pca9538/pca9538.c</span><br><span>@@ -0,0 +1,68 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 Siemens AG</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <device/i2c_bus.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <device/device.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <console/console.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include "pca9538.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "chip.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* This function can be used from outside the chip driver to read input. */</span><br><span style="color: hsl(120, 100%, 40%);">+uint8_t pca9538_read_input(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  struct device *dev = pca9538_get_dev();</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     if (!dev)</span><br><span style="color: hsl(120, 100%, 40%);">+             return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+     else</span><br><span style="color: hsl(120, 100%, 40%);">+          return (uint8_t)(i2c_dev_readb_at(dev, INPUT_REG));</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* This function can be used from outside the chip driver to set output. */</span><br><span style="color: hsl(120, 100%, 40%);">+void pca9538_set_output(uint8_t val)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        struct device *dev = pca9538_get_dev();</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     if (dev)</span><br><span style="color: hsl(120, 100%, 40%);">+              i2c_dev_writeb_at(dev, OUTPUT_REG, val);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void pca9538_init(struct device *dev)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        struct drivers_i2c_pca9538_config *config = dev->chip_info;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      /* Set up registers as requested in devicetree. */</span><br><span style="color: hsl(120, 100%, 40%);">+    i2c_dev_writeb_at(dev, IO_CONFIG_REG, config->in_out);</span><br><span style="color: hsl(120, 100%, 40%);">+     i2c_dev_writeb_at(dev, INPUT_INVERT_REG, config->invert);</span><br><span style="color: hsl(120, 100%, 40%);">+  i2c_dev_writeb_at(dev, OUTPUT_REG, config->out_val);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct device_operations pca9538_ops = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .read_resources         = DEVICE_NOOP,</span><br><span style="color: hsl(120, 100%, 40%);">+        .set_resources          = DEVICE_NOOP,</span><br><span style="color: hsl(120, 100%, 40%);">+        .enable_resources       = DEVICE_NOOP,</span><br><span style="color: hsl(120, 100%, 40%);">+        .init                   = pca9538_init,</span><br><span style="color: hsl(120, 100%, 40%);">+       .final                  = DEVICE_NOOP</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void pca9538_enable(struct device *dev)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        dev->ops = &pca9538_ops;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct chip_operations drivers_i2c_pca9538_ops = {</span><br><span style="color: hsl(120, 100%, 40%);">+      CHIP_NAME("PCA9538")</span><br><span style="color: hsl(120, 100%, 40%);">+        .enable_dev = pca9538_enable</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span>diff --git a/src/drivers/i2c/pca9538/pca9538.h b/src/drivers/i2c/pca9538/pca9538.h</span><br><span>new file mode 100644</span><br><span>index 0000000..9c28845</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/i2c/pca9538/pca9538.h</span><br><span>@@ -0,0 +1,37 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 Siemens AG</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifndef _I2C_PCA9538_H_</span><br><span style="color: hsl(120, 100%, 40%);">+#define _I2C_PCA9538_H_</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <types.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Register layout */</span><br><span style="color: hsl(120, 100%, 40%);">+#define INPUT_REG            0x00</span><br><span style="color: hsl(120, 100%, 40%);">+#define OUTPUT_REG                0x01</span><br><span style="color: hsl(120, 100%, 40%);">+#define INPUT_INVERT_REG  0x02</span><br><span style="color: hsl(120, 100%, 40%);">+#define IO_CONFIG_REG             0x03</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Provide some functions to read input and write output values. */</span><br><span style="color: hsl(120, 100%, 40%);">+uint8_t pca9538_read_input(void);</span><br><span style="color: hsl(120, 100%, 40%);">+void pca9538_set_output(uint8_t val);</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Provide a way to get the right device structure for the I/O expander.</span><br><span style="color: hsl(120, 100%, 40%);">+ * The user of this driver has to provide this function if read/write of I/O</span><br><span style="color: hsl(120, 100%, 40%);">+ * values on the I/O expander is needed.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+struct device *pca9538_get_dev(void);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#endif /* _I2C_PCA9538_H_ */</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/23748">change 23748</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/23748"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ic856123b4f4c8b721928ee3a2a4bb37833ea4b20 </div>
<div style="display:none"> Gerrit-Change-Number: 23748 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Werner Zeh <werner.zeh@siemens.com> </div>