<p>Naveen Manohar has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/26059">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">drivers/i2c: Add driver for rt5682 codec<br><br>This commit adds a new driver for the RT5682 codec to use instead<br>of the generic i2c driver.  Since the kernel needs additional<br>driver-specific device properties we need a Coreboot driver that can<br>provide those properties.<br><br>The kernel driver devicetree properties for this codec are at:<br>linux/Documentation/devicetree/bindings/sound/rt5668.txt<br><br>BUG=b:79235534<br>TEST=With the series merged & required driver support in kernel.<br>Verify Headset Audio playback.<br><br>Change-Id: Ief6dd3756490d611e230bcf7785bc371d6fb37cf<br>Signed-off-by: Naveen Manohar <naveen.m@intel.com><br>---<br>A src/drivers/i2c/rt5682/Kconfig<br>A src/drivers/i2c/rt5682/Makefile.inc<br>A src/drivers/i2c/rt5682/chip.h<br>A src/drivers/i2c/rt5682/rt5682.c<br>4 files changed, 145 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/59/26059/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/drivers/i2c/rt5682/Kconfig b/src/drivers/i2c/rt5682/Kconfig</span><br><span>new file mode 100644</span><br><span>index 0000000..030cc2e</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/i2c/rt5682/Kconfig</span><br><span>@@ -0,0 +1,4 @@</span><br><span style="color: hsl(120, 100%, 40%);">+config DRIVERS_I2C_RT5682</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%);">+     depends on HAVE_ACPI_TABLES</span><br><span>diff --git a/src/drivers/i2c/rt5682/Makefile.inc b/src/drivers/i2c/rt5682/Makefile.inc</span><br><span>new file mode 100644</span><br><span>index 0000000..f8b3c12</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/i2c/rt5682/Makefile.inc</span><br><span>@@ -0,0 +1 @@</span><br><span style="color: hsl(120, 100%, 40%);">+ramstage-$(CONFIG_DRIVERS_I2C_RT5682) += rt5682.c</span><br><span>diff --git a/src/drivers/i2c/rt5682/chip.h b/src/drivers/i2c/rt5682/chip.h</span><br><span>new file mode 100644</span><br><span>index 0000000..cf1263b</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/i2c/rt5682/chip.h</span><br><span>@@ -0,0 +1,34 @@</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 2018 Google Inc.</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%);">+ * Realtek RT5682 audio codec devicetree bindings</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+struct drivers_i2c_rt5682_config {</span><br><span style="color: hsl(120, 100%, 40%);">+        /* I2C Bus Frequency in Hertz (default 400kHz) */</span><br><span style="color: hsl(120, 100%, 40%);">+     unsigned int bus_speed;</span><br><span style="color: hsl(120, 100%, 40%);">+       /* Identifier for multiple chips */</span><br><span style="color: hsl(120, 100%, 40%);">+   unsigned int uid;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* Allow GPIO based interrupt or PIRQ */</span><br><span style="color: hsl(120, 100%, 40%);">+      struct acpi_gpio irq_gpio;</span><br><span style="color: hsl(120, 100%, 40%);">+    struct acpi_irq irq;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* Manual offset value to compensate DC offset for L/R channels */</span><br><span style="color: hsl(120, 100%, 40%);">+    uint32_t dc_offset_l_manual;</span><br><span style="color: hsl(120, 100%, 40%);">+  uint32_t dc_offset_r_manual;</span><br><span style="color: hsl(120, 100%, 40%);">+  uint32_t dc_offset_l_manual_mic;</span><br><span style="color: hsl(120, 100%, 40%);">+      uint32_t dc_offset_r_manual_mic;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span>diff --git a/src/drivers/i2c/rt5682/rt5682.c b/src/drivers/i2c/rt5682/rt5682.c</span><br><span>new file mode 100644</span><br><span>index 0000000..c903dac</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/i2c/rt5682/rt5682.c</span><br><span>@@ -0,0 +1,106 @@</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 2018 Google Inc.</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 <arch/acpi.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <arch/acpi_device.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <arch/acpigen.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <console/console.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <device/i2c.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <device/device.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <device/path.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdint.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <string.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%);">+#define RT5682_ACPI_NAME  "RT58"</span><br><span style="color: hsl(120, 100%, 40%);">+#define RT5682_ACPI_HID               "10EC5682"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define RT5682_DP_INT(key, val) \</span><br><span style="color: hsl(120, 100%, 40%);">+     acpi_dp_add_integer(dp, "realtek," key, (val))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void rt5682_fill_ssdt(struct device *dev)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       struct drivers_i2c_rt5682_config *config = dev->chip_info;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *scope = acpi_device_scope(dev);</span><br><span style="color: hsl(120, 100%, 40%);">+   struct acpi_i2c i2c = {</span><br><span style="color: hsl(120, 100%, 40%);">+               .address = dev->path.i2c.device,</span><br><span style="color: hsl(120, 100%, 40%);">+           .mode_10bit = dev->path.i2c.mode_10bit,</span><br><span style="color: hsl(120, 100%, 40%);">+            .speed = config->bus_speed ? : I2C_SPEED_FAST,</span><br><span style="color: hsl(120, 100%, 40%);">+             .resource = scope,</span><br><span style="color: hsl(120, 100%, 40%);">+    };</span><br><span style="color: hsl(120, 100%, 40%);">+    struct acpi_dp *dp;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!dev->enabled || !scope)</span><br><span style="color: hsl(120, 100%, 40%);">+               return;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Device */</span><br><span style="color: hsl(120, 100%, 40%);">+  acpigen_write_scope(scope);</span><br><span style="color: hsl(120, 100%, 40%);">+   acpigen_write_device(acpi_device_name(dev));</span><br><span style="color: hsl(120, 100%, 40%);">+  acpigen_write_name_string("_HID", RT5682_ACPI_HID);</span><br><span style="color: hsl(120, 100%, 40%);">+ acpigen_write_name_integer("_UID", config->uid);</span><br><span style="color: hsl(120, 100%, 40%);">+ acpigen_write_name_string("_DDN", dev->chip_ops->name);</span><br><span style="color: hsl(120, 100%, 40%);">+       acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       /* Resources */</span><br><span style="color: hsl(120, 100%, 40%);">+       acpigen_write_name("_CRS");</span><br><span style="color: hsl(120, 100%, 40%);">+ acpigen_write_resourcetemplate_header();</span><br><span style="color: hsl(120, 100%, 40%);">+      acpi_device_write_i2c(&i2c);</span><br><span style="color: hsl(120, 100%, 40%);">+      /* Allow either GpioInt() or Interrupt() */</span><br><span style="color: hsl(120, 100%, 40%);">+   if (config->irq_gpio.pin_count)</span><br><span style="color: hsl(120, 100%, 40%);">+            acpi_device_write_gpio(&config->irq_gpio);</span><br><span style="color: hsl(120, 100%, 40%);">+     else</span><br><span style="color: hsl(120, 100%, 40%);">+          acpi_device_write_interrupt(&config->irq);</span><br><span style="color: hsl(120, 100%, 40%);">+     acpigen_write_resourcetemplate_footer();</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    /* Device Properties */</span><br><span style="color: hsl(120, 100%, 40%);">+       dp = acpi_dp_new_table("_DSD");</span><br><span style="color: hsl(120, 100%, 40%);">+     if (config->irq_gpio.pin_count)</span><br><span style="color: hsl(120, 100%, 40%);">+            acpi_dp_add_gpio(dp, "irq-gpios", acpi_device_path(dev), 0, 0,</span><br><span style="color: hsl(120, 100%, 40%);">+                       config->irq_gpio.polarity == ACPI_GPIO_ACTIVE_LOW);</span><br><span style="color: hsl(120, 100%, 40%);">+       RT5682_DP_INT("dc_offset_l_manual", config->dc_offset_l_manual);</span><br><span style="color: hsl(120, 100%, 40%);">+ RT5682_DP_INT("dc_offset_r_manual", config->dc_offset_r_manual);</span><br><span style="color: hsl(120, 100%, 40%);">+ RT5682_DP_INT("dc_offset_l_manual_mic", config->dc_offset_l_manual_mic);</span><br><span style="color: hsl(120, 100%, 40%);">+ RT5682_DP_INT("dc_offset_r_manual_mic", config->dc_offset_r_manual_mic);</span><br><span style="color: hsl(120, 100%, 40%);">+ acpi_dp_write(dp);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  acpigen_pop_len(); /* Device */</span><br><span style="color: hsl(120, 100%, 40%);">+       acpigen_pop_len(); /* Scope */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev),</span><br><span style="color: hsl(120, 100%, 40%);">+                   dev->chip_ops->name, dev->path.i2c.device);</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 const char *rt5682_acpi_name(const struct device *dev)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   return RT5682_ACPI_NAME;</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 rt5682_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%);">+        .acpi_name                      = &rt5682_acpi_name,</span><br><span style="color: hsl(120, 100%, 40%);">+      .acpi_fill_ssdt_generator       = &rt5682_fill_ssdt,</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 rt5682_enable(struct device *dev)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      dev->ops = &rt5682_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_rt5682_ops = {</span><br><span style="color: hsl(120, 100%, 40%);">+        CHIP_NAME("Realtek RT5682 Codec")</span><br><span style="color: hsl(120, 100%, 40%);">+   .enable_dev = &rt5682_enable</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/26059">change 26059</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/26059"/><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: Ief6dd3756490d611e230bcf7785bc371d6fb37cf </div>
<div style="display:none"> Gerrit-Change-Number: 26059 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Naveen Manohar <naveen.m@intel.com> </div>