glados: Add support for audio beep

Add support for beeping by using GPIO based PDM output to the
SSM4567 audio amplifier.  Only the left speaker is used because
the PDM output stream is not very clean and using both speakers
can cause the audio to not be synchronous on both speakers.

The sample rate is tuned to make the tone sound appropriate given
the slow rate of the PDM clock.  The clock start value is tuned
to reduce the audio startup pop and crackling as much as possible.

The GPIOs that are used are GPP_F0 and GPP_F2 and they are configured
to be outputs but then will be returned to input when depthcharge
exits.

BUG=chrome-os-partner:42283
BRANCH=none
TEST=test audio beep on glados

Change-Id: I6d1385de9300ad1e455a9a76effc76ac20142b32
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/301385
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
diff --git a/board/glados/defconfig b/board/glados/defconfig
index eaf70a1..5cc4991 100644
--- a/board/glados/defconfig
+++ b/board/glados/defconfig
@@ -18,6 +18,8 @@
 CONFIG_KERNEL_ZIMAGE=y
 
 # Drivers
+CONFIG_DRIVER_BUS_I2C_DESIGNWARE=y
+CONFIG_DRIVER_BUS_I2C_DESIGNWARE_PCI=y
 CONFIG_DRIVER_EC_CROS=y
 CONFIG_DRIVER_EC_CROS_LPC=y
 CONFIG_DRIVER_EC_CROS_PASSTHRU=y
@@ -27,6 +29,9 @@
 CONFIG_DRIVER_INPUT_USB=y
 CONFIG_DRIVER_POWER_PCH=y
 CONFIG_DRIVER_SDHCI=y
+CONFIG_DRIVER_SOUND_GPIO_PDM=y
+CONFIG_DRIVER_SOUND_ROUTE=y
+CONFIG_DRIVER_SOUND_SSM4567=y
 CONFIG_DRIVER_STORAGE_MMC=y
 CONFIG_DRIVER_STORAGE_SDHCI_PCI=y
 CONFIG_DRIVER_TPM_LPC=y
diff --git a/src/board/glados/board.c b/src/board/glados/board.c
index d4cf7e1..8cb7614 100644
--- a/src/board/glados/board.c
+++ b/src/board/glados/board.c
@@ -28,18 +28,22 @@
 
 #include "base/init_funcs.h"
 #include "base/list.h"
+#include "drivers/bus/i2c/designware.h"
+#include "drivers/bus/i2c/i2c.h"
 #include "drivers/ec/cros/lpc.h"
 #include "drivers/flash/flash.h"
 #include "drivers/flash/memmapped.h"
 #include "drivers/gpio/skylake.h"
 #include "drivers/gpio/sysinfo.h"
 #include "drivers/power/pch.h"
+#include "drivers/sound/gpio_pdm.h"
+#include "drivers/sound/route.h"
+#include "drivers/sound/ssm4567.h"
 #include "drivers/storage/blockdev.h"
 #include "drivers/storage/sdhci.h"
 #include "drivers/tpm/lpc.h"
 #include "drivers/tpm/tpm.h"
 #include "vboot/util/flag.h"
-#include "drivers/bus/usb/usb.h"
 
 /*
  * Clock frequencies for the eMMC and SD ports are defined below. The minimum
@@ -82,6 +86,28 @@
 	list_insert_after(&sd->mmc_ctrlr.ctrlr.list_node,
 				&removable_block_dev_controllers);
 
+	/* Speaker Amp Codec is on I2C4 */
+	DesignwareI2c *i2c4 =
+		new_pci_designware_i2c(PCI_DEV(0, 0x19, 2), 400000);
+	ssm4567Codec *speaker_amp_left =
+		new_ssm4567_codec(&i2c4->ops, 0x34, SSM4567_MODE_PDM);
+
+	/* Use GPIO to bit-bang PDM to the codec */
+	GpioCfg *i2s2_sclk = new_skylake_gpio_output(GPP_F0, 0);
+	GpioCfg *i2s2_txd  = new_skylake_gpio_output(GPP_F2, 0);
+	GpioPdm *pdm = new_gpio_pdm(&i2s2_sclk->ops,	/* PDM Clock GPIO */
+				    &i2s2_txd->ops,	/* PDM Data GPIO */
+				    85000,		/* Clock Start */
+				    16000,		/* Sample Rate */
+				    2,			/* Channels */
+				    1000);		/* Volume */
+
+	/* Connect the Codec to the PDM source */
+	SoundRoute *sound = new_sound_route(&pdm->ops);
+	list_insert_after(&speaker_amp_left->component.list_node,
+			  &sound->components);
+	sound_set_ops(&sound->ops);
+
 	return 0;
 }