Skip to contentSkip to conversation

x86: Add support for sound

PATCH New Simon Glass 4 participants 74 messages Jan 22, 2019 – Feb 17, 2019

Subsystems (5)
Device tree bindings x86 PCI ASoC +1 more subsystems
lore
Share & tools
lore
#0 lore raw

cover x86: Add support for sound

At present no x86 boards support sound. This series adds several options:

- legacy beep
- Intel HDA
- I2S with codec

These are enabled on coreboot, link and samus, respectively.

A number of related patches are included to make the above work.

Simon Glass (33):
log: Add a Kconfig option to set the default log level
log: Add documentation for convenience functions
log: Allow #define LOG_DEBUG to enable logging in a file
dm: syscon: Don't require a regmap for PCI devices
i2c: designware: Add error checking on init
pci: Don't export pci_hose_config_device()
pci: Fix comment in struct pci_child_platdata
gpio: Show inactive GPIOs when explicitly requested
gpio: Use case-insentive matching on the GPIO name
pci: Add IDs for Intel high-definition audio
sandbox: Add a note about the growing state_info struct
x86: Adjust I/O macros to work on 64-bit machines
x86: samus: Increase the pre-reloc memory
x86: link: Increase malloc size and decrease code size
x86: sandbox: pch: Add a CONFIG option for PCH
sandbox: pch: Add a test for the PCH uclass
pch: Add ioctl support
x86: ivybridge: Add a way to get the HDA config setting
sound: Mark sound_setup() as optional
sound: Add uclass operations for beeping
sound: Add support for Intel HDA
sandbox: sound: Silence sound for testing
sound: x86: link: Add sound support
sound: x86: Add beeping support in i8254
sound: Add a driver for the i8254 beep
x86: coreboot: Enable the beeper sound driver
x86: broadwell: Add support for the ADSP
x86: broadwell: Don't bother probing the PCH for pinctrl
x86: broadwell: Add support for serial I/O devices
x86: sound: Add support for broadwell I2S
sound: Add a driver for RealTek RT5677
x86: sound: Add sound support for samus (broadwell)
x86: Add sound support for samus

 arch/Kconfig                                  |    2 +
 arch/sandbox/dts/test.dts                     |    5 +
 arch/sandbox/include/asm/state.h              |    9 +
 arch/sandbox/include/asm/test.h               |   24 +
 arch/x86/cpu/broadwell/Makefile               |    1 +
 arch/x86/cpu/broadwell/adsp.c                 |  157 ++
 arch/x86/cpu/broadwell/pch.c                  |  110 ++
 arch/x86/cpu/broadwell/pinctrl_broadwell.c    |    3 +-
 arch/x86/cpu/ivybridge/Kconfig                |    1 +
 arch/x86/cpu/ivybridge/bd82x6x.c              |   19 +
 arch/x86/cpu/ivybridge/northbridge.c          |   27 +
 arch/x86/dts/chromebook_link.dts              |   91 ++
 arch/x86/dts/chromebook_samus.dts             |   49 +-
 arch/x86/include/asm/arch-broadwell/adsp.h    |   46 +
 arch/x86/include/asm/arch-broadwell/pch.h     |    3 +
 arch/x86/include/asm/arch-broadwell/rcb.h     |    2 +
 .../x86/include/asm/arch-broadwell/serialio.h |   82 +
 .../include/asm/arch-ivybridge/sandybridge.h  |    3 +
 arch/x86/include/asm/i8254.h                  |   18 +
 arch/x86/include/asm/io.h                     |   16 +-
 arch/x86/lib/i8254.c                          |   36 +-
 cmd/gpio.c                                    |   10 +-
 common/Kconfig                                |    9 +
 common/log.c                                  |    2 +-
 configs/chromebook_link_defconfig             |    5 +-
 configs/chromebook_samus_defconfig            |   11 +-
 configs/coreboot_defconfig                    |    3 +
 doc/README.log                                |   40 +
 doc/device-tree-bindings/sound/intel-hda.txt  |   26 +
 drivers/Kconfig                               |    2 +
 drivers/Makefile                              |    2 +-
 drivers/core/syscon-uclass.c                  |    4 +
 drivers/i2c/designware_i2c.c                  |   29 +-
 drivers/pch/Kconfig                           |    9 +
 drivers/pch/Makefile                          |    1 +
 drivers/pch/pch-uclass.c                      |   10 +
 drivers/pch/sandbox_pch.c                     |   86 +
 drivers/pci/pci.c                             |    7 +-
 drivers/sound/Kconfig                         |   40 +
 drivers/sound/Makefile                        |    5 +
 drivers/sound/broadwell_i2s.c                 |  306 ++++
 drivers/sound/broadwell_i2s.h                 |  301 ++++
 drivers/sound/broadwell_sound.c               |   65 +
 drivers/sound/hda_codec.c                     |  545 +++++++
 drivers/sound/i8254_beep.c                    |   38 +
 drivers/sound/ivybridge_sound.c               |  137 ++
 drivers/sound/rt5677.c                        |  334 ++++
 drivers/sound/rt5677.h                        | 1428 +++++++++++++++++
 drivers/sound/sandbox.c                       |   69 +-
 drivers/sound/sound-uclass.c                  |   36 +-
 include/dt-bindings/sound/azalia.h            |   29 +
 include/hda_codec.h                           |  103 ++
 include/log.h                                 |    7 +-
 include/pch.h                                 |   51 +-
 include/pci.h                                 |    8 +-
 include/pci_ids.h                             |    4 +
 include/sound.h                               |   46 +-
 test/dm/Makefile                              |    1 +
 test/dm/pch.c                                 |   55 +
 test/dm/sound.c                               |   21 +
 60 files changed, 4531 insertions(+), 58 deletions(-)
 create mode 100644 arch/x86/cpu/broadwell/adsp.c
 create mode 100644 arch/x86/include/asm/arch-broadwell/adsp.h
 create mode 100644 arch/x86/include/asm/arch-broadwell/serialio.h
 create mode 100644 doc/device-tree-bindings/sound/intel-hda.txt
 create mode 100644 drivers/pch/Kconfig
 create mode 100644 drivers/pch/sandbox_pch.c
 create mode 100644 drivers/sound/broadwell_i2s.c
 create mode 100644 drivers/sound/broadwell_i2s.h
 create mode 100644 drivers/sound/broadwell_sound.c
 create mode 100644 drivers/sound/hda_codec.c
 create mode 100644 drivers/sound/i8254_beep.c
 create mode 100644 drivers/sound/ivybridge_sound.c
 create mode 100644 drivers/sound/rt5677.c
 create mode 100644 drivers/sound/rt5677.h
 create mode 100644 include/dt-bindings/sound/azalia.h
 create mode 100644 include/hda_codec.h
 create mode 100644 test/dm/pch.c
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#1 lore raw

PATCH 1/33 log: Add a Kconfig option to set the default log level

At present the default log level is set to LOGL_INFO on start-up. Allow this to be controlled from Kconfig.

---

 common/Kconfig | 9 +++++++++
 common/log.c   | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)
common/Kconfig +9 -0
index 0a14bdedaa..2ee48e4a2a 100644
@@ -527,6 +527,15 @@ config TPL_LOG_MAX_LEVEL
 	    6 - detail
 	    7 - debug
 
+config LOG_DEFAULT_LEVEL
+	int "Default logging level to display"
+	default 5
+	help
+	  This is the default logging level set when U-Boot starts. It can
+	  be adjusted later using the 'log level' command. Note that setting
+	  this to a value abnove LOG_MAX_LEVEL will be ineffective, since the
+	  higher levels are not compiled in to U-Boot.
+
 config LOG_CONSOLE
 	bool "Allow log output to the console"
 	depends on LOG
common/log.c +1 -1
index ec14644516..ffb3cd6933 100644
@@ -316,7 +316,7 @@ int log_init(void)
 	}
 	gd->flags |= GD_FLG_LOG_READY;
 	if (!gd->default_log_level)
-		gd->default_log_level = LOGL_INFO;
+		gd->default_log_level = CONFIG_LOG_DEFAULT_LEVEL;
 	gd->log_fmt = LOGF_DEFAULT;
 
 	return 0;
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#2 lore raw

PATCH 1/33 log: Add a Kconfig option to set the default log level

Hi Simon,

Quoted 16 lines · Simon Glass

At present the default log level is set to LOGL_INFO on start-up. Allow this to be controlled from Kconfig.

---

 common/Kconfig | 9 +++++++++
 common/log.c   | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)
common/Kconfig +0 -0
index 0a14bdedaa..2ee48e4a2a 100644

common/Kconfig config TPL_LOG_MAX_LEVEL · line 532

Quoted 6 lines
common/Kconfig +3 -0
@@ -527,6 +527,15 @@ config TPL_LOG_MAX_LEVEL
            6 - detail
            7 - debug
 
+config LOG_DEFAULT_LEVEL
+       int "Default logging level to display"
+       default 5

Shouldn't it be 6 which is LOGL_INFO?

common/Kconfig config TPL_LOG_MAX_LEVEL · line 538

Quoted 6 lines
common/Kconfig +6 -0
+       help
+         This is the default logging level set when U-Boot starts. It can
+         be adjusted later using the 'log level' command. Note that setting
+         this to a value abnove LOG_MAX_LEVEL will be ineffective, since the
+         higher levels are not compiled in to U-Boot.
+

Other than that,

Regards,
Bin

#3 lore raw

PATCH 2/33 log: Add documentation for convenience functions

In reply to Simon Glass

The log_debug(), etc. function are documented only in the header file at present. Add a section to README.log also.

---

 doc/README.log | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
doc/README.log +26 -0
index 2ee1b753bc..96bc9523ef 100644
@@ -69,6 +69,32 @@ If CONFIG_LOG is not set, then no logging will be available.
 The above have SPL versions also, e.g. CONFIG_SPL_MAX_LOG_LEVEL.
 
 
+Convenience functions
+---------------------
+
+A number of convenience functions are available to shorten the code needed
+for logging:
+
+	log_err(_fmt...)
+	log_warning(_fmt...)
+	log_notice(_fmt...)
+	log_info(_fmt...)
+	log_debug(_fmt...)
+	log_content(_fmt...)
+	log_io(_fmt...)
+
+With these the log level is implicit in the name. The category is set by
+LOG_CATEGORY, which you can only define once per file, above all #includes:
+
+	#define LOG_CATEGORY LOGC_ALLOC
+
+or
+
+	#define LOG_CATEGORY UCLASS_SPI
+
+Remember that all uclasses IDs are log categories too.
+
+
 Log commands
 ------------
 
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#4 lore raw

PATCH 2/33 log: Add documentation for convenience functions

Quoted 10 lines · Simon Glass

The log_debug(), etc. function are documented only in the header file at present. Add a section to README.log also.

---

 doc/README.log | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
#5 lore raw

PATCH 3/33 log: Allow #define LOG_DEBUG to enable logging in a file

In reply to Simon Glass

At present it is possible to '#define DEBUG' at the top of a file which causes all debug() statements in that file to become active. There is currently no equivalent with logging, but this is a useful function.

Add a LOG_DEBUG define along with documentation.

---

 doc/README.log | 14 ++++++++++++++
 include/log.h  |  7 ++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
doc/README.log +14 -0
index 96bc9523ef..f8922af764 100644
@@ -69,6 +69,20 @@ If CONFIG_LOG is not set, then no logging will be available.
 The above have SPL versions also, e.g. CONFIG_SPL_MAX_LOG_LEVEL.
 
 
+Temporary logging within a single file
+--------------------------------------
+
+Sometimes it is useful to turn on logging just in one file. You can use this:
+
+   #define LOG_DEBUG
+
+to enable building in of all logging statements in a single file. Put it at
+the top of the file, before any #includes.
+
+To actually get U-Boot to output this you need to also set the default logging
+level - e.g. set CONFIG_LOG_DEFAULT_LEVEL to 7 or more.
+
+
 Convenience functions
 ---------------------
 
include/log.h +6 -1
index d7f6471006..acf2a14b91 100644
@@ -111,11 +111,16 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file,
 #endif
 
 #if CONFIG_IS_ENABLED(LOG)
+#ifdef LOG_DEBUG
+#define _LOG_DEBUG	1
+#else
+#define _LOG_DEBUG	0
+#endif
 
 /* Emit a log record if the level is less that the maximum */
 #define log(_cat, _level, _fmt, _args...) ({ \
 	int _l = _level; \
-	if (CONFIG_IS_ENABLED(LOG) && _l <= _LOG_MAX_LEVEL) \
+	if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG)) \
 		_log((enum log_category_t)(_cat), _l, __FILE__, __LINE__, \
 		      __func__, \
 		      pr_fmt(_fmt), ##_args); \
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#6 lore raw

PATCH 3/33 log: Allow #define LOG_DEBUG to enable logging in a file

Hi Simon,

Quoted 24 lines · Simon Glass

At present it is possible to '#define DEBUG' at the top of a file which causes all debug() statements in that file to become active. There is currently no equivalent with logging, but this is a useful function.

Add a LOG_DEBUG define along with documentation.

---

 doc/README.log | 14 ++++++++++++++
 include/log.h  |  7 ++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
doc/README.log +2 -0
index 96bc9523ef..f8922af764 100644
@@ -69,6 +69,20 @@ If CONFIG_LOG is not set, then no logging will be available.
 The above have SPL versions also, e.g. CONFIG_SPL_MAX_LOG_LEVEL.
 
 
+Temporary logging within a single file
+--------------------------------------

doc/README.log If CONFIG_LOG is not set, then no logging will be available. · line 83

Quoted 10 lines
doc/README.log +10 -0
+
+Sometimes it is useful to turn on logging just in one file. You can use this:
+
+   #define LOG_DEBUG
+
+to enable building in of all logging statements in a single file. Put it at
+the top of the file, before any #includes.
+
+To actually get U-Boot to output this you need to also set the default logging
+level - e.g. set CONFIG_LOG_DEFAULT_LEVEL to 7 or more.

Why should CONFIG_LOG_DEFAULT_LEVEL be 7 or more?

Quoted 18 lines
doc/README.log +2 -0
+
+
 Convenience functions
 ---------------------
 
include/log.h +5 -0
index d7f6471006..acf2a14b91 100644
@@ -111,11 +111,16 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file,
 #endif
 
 #if CONFIG_IS_ENABLED(LOG)
+#ifdef LOG_DEBUG
+#define _LOG_DEBUG     1
+#else
+#define _LOG_DEBUG     0
+#endif

include/log.h int _log(enum log_category_t cat, enum log_level_t level, const char *file,

Quoted 10 lines
include/log.h +1 -2
 
 /* Emit a log record if the level is less that the maximum */
 #define log(_cat, _level, _fmt, _args...) ({ \
        int _l = _level; \
-       if (CONFIG_IS_ENABLED(LOG) && _l <= _LOG_MAX_LEVEL) \
+       if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG)) \
                _log((enum log_category_t)(_cat), _l, __FILE__, __LINE__, \
                      __func__, \
                      pr_fmt(_fmt), ##_args); \
--

Regards,
Bin

#7 lore raw

PATCH 3/33 log: Allow #define LOG_DEBUG to enable logging in a file

Hi BIn,

Quoted 26 lines · Bin Meng

Hi Simon,

Quoted 22 lines · Simon Glass

At present it is possible to '#define DEBUG' at the top of a file which causes all debug() statements in that file to become active. There is currently no equivalent with logging, but this is a useful function.

Add a LOG_DEBUG define along with documentation.

---

 doc/README.log | 14 ++++++++++++++
 include/log.h  |  7 ++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
doc/README.log +0 -0
index 96bc9523ef..f8922af764 100644
@@ -69,6 +69,20 @@ If CONFIG_LOG is not set, then no logging will be available.
 The above have SPL versions also, e.g. CONFIG_SPL_MAX_LOG_LEVEL.
 
 
Quoted 14 lines

doc/README.log If CONFIG_LOG is not set, then no logging will be available. · line 83

Quoted 12 lines
doc/README.log +12 -0
+Temporary logging within a single file
+--------------------------------------
+
+Sometimes it is useful to turn on logging just in one file. You can use this:
+
+   #define LOG_DEBUG
+
+to enable building in of all logging statements in a single file. Put it at
+the top of the file, before any #includes.
+
+To actually get U-Boot to output this you need to also set the default logging
+level - e.g. set CONFIG_LOG_DEFAULT_LEVEL to 7 or more.

Why should CONFIG_LOG_DEFAULT_LEVEL be 7 or more?

I'll add a comment about that. I suspect there is a way to avoid this but so far I have not figured it out.

[..]

Regards,
Simon

#8 lore raw

PATCH 4/33 dm: syscon: Don't require a regmap for PCI devices

In reply to Simon Glass

At present it is not possible to use the syscon devices for PCI devices since a regmap is required. Since PCI uses a 3-cell address the conversion of the 'reg' property to an address always fails. In any case, the regmap is not useful with PCI since devices are accessed through the PCI bus which regmap does not support.

Add a special case for PCI syscon devices, so that they don't set up a regmap.

---

 drivers/core/syscon-uclass.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/core/syscon-uclass.c +4 -0
index 3cf9dd9dbe..afac6d6e37 100644
@@ -37,6 +37,10 @@ static int syscon_pre_probe(struct udevice *dev)
 {
 	struct syscon_uc_info *priv = dev_get_uclass_priv(dev);
 
+	/* Special case for PCI devices, which don't have a regmap */
+	if (device_get_uclass_id(dev->parent) == UCLASS_PCI)
+		return 0;
+
 	/*
 	 * With OF_PLATDATA we really have no way of knowing the format of
 	 * the device-specific platform data. So we assume that it starts with
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#9 lore raw

PATCH 4/33 dm: syscon: Don't require a regmap for PCI devices

Quoted 7 lines · Simon Glass

At present it is not possible to use the syscon devices for PCI devices since a regmap is required. Since PCI uses a 3-cell address the conversion of the 'reg' property to an address always fails. In any case, the regmap is not useful with PCI since devices are accessed through the PCI bus which regmap does not support.

Quoted 9 lines

Add a special case for PCI syscon devices, so that they don't set up a regmap.

---

 drivers/core/syscon-uclass.c | 4 ++++
 1 file changed, 4 insertions(+)
#10 lore raw

PATCH 5/33 i2c: designware: Add error checking on init

In reply to Simon Glass

At present this driver does not check whether it is able to actually communicate with the I2C controller. It prints a timeout message but still considers the probe to be successful.

To fix this, add some checking that the init succeeds.

---

 drivers/i2c/designware_i2c.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/i2c/designware_i2c.c +19 -10
index dbc3326b5a..63e40823f1 100644
@@ -38,14 +38,16 @@ struct dw_i2c {
 };
 
 #ifdef CONFIG_SYS_I2C_DW_ENABLE_STATUS_UNSUPPORTED
-static void dw_i2c_enable(struct i2c_regs *i2c_base, bool enable)
+static int  dw_i2c_enable(struct i2c_regs *i2c_base, bool enable)
 {
 	u32 ena = enable ? IC_ENABLE_0B : 0;
 
 	writel(ena, &i2c_base->ic_enable);
+
+	return 0;
 }
 #else
-static void dw_i2c_enable(struct i2c_regs *i2c_base, bool enable)
+static int dw_i2c_enable(struct i2c_regs *i2c_base, bool enable)
 {
 	u32 ena = enable ? IC_ENABLE_0B : 0;
 	int timeout = 100;
@@ -53,7 +55,7 @@ static void dw_i2c_enable(struct i2c_regs *i2c_base, bool enable)
 	do {
 		writel(ena, &i2c_base->ic_enable);
 		if ((readl(&i2c_base->ic_enable_status) & IC_ENABLE_0B) == ena)
-			return;
+			return 0;
 
 		/*
 		 * Wait 10 times the signaling period of the highest I2C
@@ -62,8 +64,9 @@ static void dw_i2c_enable(struct i2c_regs *i2c_base, bool enable)
 		 */
 		udelay(25);
 	} while (timeout--);
-
 	printf("timeout in %sabling I2C adapter\n", enable ? "en" : "dis");
+
+	return -ETIMEDOUT;
 }
 #endif
 
@@ -370,10 +373,14 @@ static int __dw_i2c_write(struct i2c_regs *i2c_base, u8 dev, uint addr,
  *
  * Initialization function.
  */
-static void __dw_i2c_init(struct i2c_regs *i2c_base, int speed, int slaveaddr)
+static int __dw_i2c_init(struct i2c_regs *i2c_base, int speed, int slaveaddr)
 {
+	int ret;
+
 	/* Disable i2c */
-	dw_i2c_enable(i2c_base, false);
+	ret = dw_i2c_enable(i2c_base, false);
+	if (ret)
+		return ret;
 
 	writel(IC_CON_SD | IC_CON_RE | IC_CON_SPD_FS | IC_CON_MM,
 	       &i2c_base->ic_con);
@@ -386,7 +393,11 @@ static void __dw_i2c_init(struct i2c_regs *i2c_base, int speed, int slaveaddr)
 #endif
 
 	/* Enable i2c */
-	dw_i2c_enable(i2c_base, true);
+	ret = dw_i2c_enable(i2c_base, true);
+	if (ret)
+		return ret;
+
+	return 0;
 }
 
 #ifndef CONFIG_DM_I2C
@@ -558,9 +569,7 @@ static int designware_i2c_probe(struct udevice *bus)
 	if (&priv->reset_ctl)
 		reset_deassert(&priv->reset_ctl);
 
-	__dw_i2c_init(priv->regs, 0, 0);
-
-	return 0;
+	return __dw_i2c_init(priv->regs, 0, 0);
 }
 
 static int designware_i2c_bind(struct udevice *dev)
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#11 lore raw

PATCH 5/33 i2c: designware: Add error checking on init

Hello Simon,

Am 22.01.2019 um 02:12 schrieb Simon Glass:

Quoted 11 lines

At present this driver does not check whether it is able to actually communicate with the I2C controller. It prints a timeout message but still considers the probe to be successful.

To fix this, add some checking that the init succeeds.

---

  drivers/i2c/designware_i2c.c | 29 +++++++++++++++++++----------
  1 file changed, 19 insertions(+), 10 deletions(-)

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#12 lore raw

PATCH 5/33 i2c: designware: Add error checking on init

In reply to Simon Glass
Quoted 5 lines · Simon Glass

At present this driver does not check whether it is able to actually communicate with the I2C controller. It prints a timeout message but still considers the probe to be successful.

Quoted 8 lines

To fix this, add some checking that the init succeeds.

---

 drivers/i2c/designware_i2c.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)
#13 lore raw

PATCH 6/33 pci: Don't export pci_hose_config_device()

In reply to Simon Glass

This function is not used outside this file so make it static.

---

 drivers/pci/pci.c | 7 ++-----
 include/pci.h     | 6 ------
 2 files changed, 2 insertions(+), 11 deletions(-)
drivers/pci/pci.c +2 -5
index 221054593e..e2195726c8 100644
@@ -184,11 +184,8 @@ pci_dev_t pci_find_devices(struct pci_device_id *ids, int index)
 	return -1;
 }
 
-int pci_hose_config_device(struct pci_controller *hose,
-			   pci_dev_t dev,
-			   unsigned long io,
-			   pci_addr_t mem,
-			   unsigned long command)
+static int pci_hose_config_device(struct pci_controller *hose, pci_dev_t dev,
+				  ulong io, pci_addr_t mem, ulong command)
 {
 	u32 bar_response;
 	unsigned int old_command;
include/pci.h +0 -6
index 785d7d28b7..ffd796becf 100644
@@ -735,12 +735,6 @@ extern pci_dev_t pci_find_device (unsigned int vendor, unsigned int device, int
 extern pci_dev_t pci_find_devices (struct pci_device_id *ids, int index);
 pci_dev_t pci_find_class(unsigned int find_class, int index);
 
-extern int pci_hose_config_device(struct pci_controller *hose,
-				  pci_dev_t dev,
-				  unsigned long io,
-				  pci_addr_t mem,
-				  unsigned long command);
-
 extern int pci_hose_find_capability(struct pci_controller *hose, pci_dev_t dev,
 				    int cap);
 extern int pci_hose_find_cap_start(struct pci_controller *hose, pci_dev_t dev,
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#15 lore raw

PATCH 7/33 pci: Fix comment in struct pci_child_platdata

In reply to Simon Glass

This is platdata, not private data, so the comment is currently incorrect. Fix it to avoid confusion.

---

 include/pci.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/pci.h +1 -1
index ffd796becf..1762518848 100644
@@ -822,7 +822,7 @@ struct udevice;
  *
  * Every device on a PCI bus has this per-child data.
  *
- * It can be accessed using dev_get_parent_priv(dev) if dev->parent is a
+ * It can be accessed using dev_get_parent_platdata(dev) if dev->parent is a
  * PCI bus (i.e. UCLASS_PCI)
  *
  * @devfn:	Encoded device and function index - see PCI_DEVFN()
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#17 lore raw

PATCH 8/33 gpio: Show inactive GPIOs when explicitly requested

In reply to Simon Glass

At present the gpio command only shows GPIOs which are marked as in use. This makes sense with 'gpio status' since we already have the '-a' flag to indicate that all GPIOs should be shown. But when a particular GPIO is requested, it seems better to always display it. At present the request is simply ignored.

Add an extra parameter for this to avoid changing the existing flag parameter.

---

 cmd/gpio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
cmd/gpio.c +4 -4
index c60946bc06..1bf7363b3a 100644
@@ -34,7 +34,7 @@ enum {
 };
 
 static void gpio_get_description(struct udevice *dev, const char *bank_name,
-				 int offset, int *flagsp)
+				 int offset, int *flagsp, bool show_all)
 {
 	char buf[80];
 	int ret;
@@ -42,7 +42,7 @@ static void gpio_get_description(struct udevice *dev, const char *bank_name,
 	ret = gpio_get_function(dev, offset, NULL);
 	if (ret < 0)
 		goto err;
-	if (!(*flagsp & FLAG_SHOW_ALL) && ret == GPIOF_UNUSED)
+	if (!show_all && !(*flagsp & FLAG_SHOW_ALL) && ret == GPIOF_UNUSED)
 		return;
 	if ((*flagsp & FLAG_SHOW_BANK) && bank_name) {
 		if (*flagsp & FLAG_SHOW_NEWLINE) {
@@ -98,11 +98,11 @@ static int do_gpio_status(bool all, const char *gpio_name)
 			if (gpio_name && *p) {
 				offset = simple_strtoul(p, NULL, 10);
 				gpio_get_description(dev, bank_name, offset,
-						     &flags);
+						     &flags, true);
 			} else {
 				for (offset = 0; offset < num_bits; offset++) {
 					gpio_get_description(dev, bank_name,
-							     offset, &flags);
+						     offset, &flags, false);
 				}
 			}
 		}
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#18 lore raw

PATCH 8/33 gpio: Show inactive GPIOs when explicitly requested

Hi Simon,

Quoted 10 lines · Simon Glass

At present the gpio command only shows GPIOs which are marked as in use. This makes sense with 'gpio status' since we already have the '-a' flag to indicate that all GPIOs should be shown. But when a particular GPIO is requested, it seems better to always display it. At present the request is simply ignored.

Add an extra parameter for this to avoid changing the existing flag parameter.

Could you provide an example here for better understanding?

Quoted 6 lines

---

 cmd/gpio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Regards,
Bin

#19 lore raw

PATCH 9/33 gpio: Use case-insentive matching on the GPIO name

In reply to Simon Glass

Allow the 'gpio' command to match GPIO bank names regardless of the case of each. While these are generally in upper case, it is useful to be able to provide lower case with the command.

---

 cmd/gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/gpio.c +1 -1
index 1bf7363b3a..8e1fc2544f 100644
@@ -90,7 +90,7 @@ static int do_gpio_status(bool all, const char *gpio_name)
 		banklen = bank_name ? strlen(bank_name) : 0;
 
 		if (!gpio_name || !bank_name ||
-		    !strncmp(gpio_name, bank_name, banklen)) {
+		    !strncasecmp(gpio_name, bank_name, banklen)) {
 			const char *p = NULL;
 			int offset;
 
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#20 lore raw

PATCH 9/33 gpio: Use case-insentive matching on the GPIO name

Quoted 11 lines · Simon Glass

Allow the 'gpio' command to match GPIO bank names regardless of the case of each. While these are generally in upper case, it is useful to be able to provide lower case with the command.

---

 cmd/gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#21 lore raw

PATCH 10/33 pci: Add IDs for Intel high-definition audio

In reply to Simon Glass

Add a few IDs for common HDA blocks and the ADSP used on samus.

---

 include/pci_ids.h | 4 ++++
 1 file changed, 4 insertions(+)
include/pci_ids.h +4 -0
index fdda679cc0..b33b85db55 100644
@@ -1363,6 +1363,7 @@
 #define PCI_DEVICE_ID_CREATIVE_EMU10K1	0x0002
 #define PCI_DEVICE_ID_CREATIVE_20K1	0x0005
 #define PCI_DEVICE_ID_CREATIVE_20K2	0x000b
+#define PCI_DEVICE_ID_CREATIVE_CA01322	0x0011
 #define PCI_SUBDEVICE_ID_CREATIVE_SB0760	0x0024
 #define PCI_SUBDEVICE_ID_CREATIVE_SB08801	0x0041
 #define PCI_SUBDEVICE_ID_CREATIVE_SB08802	0x0042
@@ -2827,6 +2828,7 @@
 #define PCI_DEVICE_ID_INTEL_ICH7_19	0x27dd
 #define PCI_DEVICE_ID_INTEL_ICH7_20	0x27de
 #define PCI_DEVICE_ID_INTEL_ICH7_21	0x27df
+#define PCI_DEVICE_ID_INTEL_COUGARPOINT_HDMI	0x2806
 #define PCI_DEVICE_ID_INTEL_ICH8_0	0x2810
 #define PCI_DEVICE_ID_INTEL_ICH8_1	0x2811
 #define PCI_DEVICE_ID_INTEL_ICH8_2	0x2812
@@ -3022,9 +3024,11 @@
 #define PCI_DEVICE_ID_INTEL_TCF_UART_2	0x8813
 #define PCI_DEVICE_ID_INTEL_TCF_UART_3	0x8814
 #define PCI_DEVICE_ID_INTEL_IXP2800	0x9004
+#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_ADSP	0x9cb6
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_AHCI	0x9c03
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LPC	0x9c45
 #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_AHCI	0x9c83
+#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_HDA	0x9ca0
 #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LPC	0x9cc3
 #define PCI_DEVICE_ID_INTEL_S21152BB	0xb152
 
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#22 lore raw

PATCH 10/33 pci: Add IDs for Intel high-definition audio

Hi Simon,

Quoted 30 lines · Simon Glass

Add a few IDs for common HDA blocks and the ADSP used on samus.

---

 include/pci_ids.h | 4 ++++
 1 file changed, 4 insertions(+)
include/pci_ids.h +2 -0
index fdda679cc0..b33b85db55 100644
@@ -1363,6 +1363,7 @@
 #define PCI_DEVICE_ID_CREATIVE_EMU10K1 0x0002
 #define PCI_DEVICE_ID_CREATIVE_20K1    0x0005
 #define PCI_DEVICE_ID_CREATIVE_20K2    0x000b
+#define PCI_DEVICE_ID_CREATIVE_CA01322 0x0011
 #define PCI_SUBDEVICE_ID_CREATIVE_SB0760       0x0024
 #define PCI_SUBDEVICE_ID_CREATIVE_SB08801      0x0041
 #define PCI_SUBDEVICE_ID_CREATIVE_SB08802      0x0042
@@ -2827,6 +2828,7 @@
 #define PCI_DEVICE_ID_INTEL_ICH7_19    0x27dd
 #define PCI_DEVICE_ID_INTEL_ICH7_20    0x27de
 #define PCI_DEVICE_ID_INTEL_ICH7_21    0x27df
+#define PCI_DEVICE_ID_INTEL_COUGARPOINT_HDMI   0x2806
 #define PCI_DEVICE_ID_INTEL_ICH8_0     0x2810
 #define PCI_DEVICE_ID_INTEL_ICH8_1     0x2811
 #define PCI_DEVICE_ID_INTEL_ICH8_2     0x2812

include/pci_ids.h line 3027

Quoted 4 lines
include/pci_ids.h +1 -0
@@ -3022,9 +3024,11 @@
 #define PCI_DEVICE_ID_INTEL_TCF_UART_2 0x8813
 #define PCI_DEVICE_ID_INTEL_TCF_UART_3 0x8814
 #define PCI_DEVICE_ID_INTEL_IXP2800    0x9004
+#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_ADSP  0x9cb6

This one should be inserted after PCI_DEVICE_ID_INTEL_WILDCATPOINT_HDA

include/pci_ids.h line 3033

Quoted 6 lines
include/pci_ids.h +1 -0
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_AHCI     0x9c03
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LPC      0x9c45
 #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_AHCI  0x9c83
+#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_HDA   0x9ca0
 #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LPC   0x9cc3
 #define PCI_DEVICE_ID_INTEL_S21152BB   0xb152

Regards,
Bin

#23 lore raw

PATCH 11/33 sandbox: Add a note about the growing state_info struct

In reply to Simon Glass

This struct is getting larger and in some cases is being used for things which would be better put into a driver. For example hwspinlock is not used outside of sandbox_hwspinlock.c.

Add a note to encourage people to put things elsewhere.

---

 arch/sandbox/include/asm/state.h | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/sandbox/include/asm/state.h +9 -0
index c724827f6c..2d773d3fa6 100644
@@ -102,6 +102,15 @@ struct sandbox_state {
 	ulong next_tag;			/* Next address tag to allocate */
 	struct list_head mapmem_head;	/* struct sandbox_mapmem_entry */
 	bool hwspinlock;		/* Hardware Spinlock status */
+
+	/*
+	 * This struct is getting large.
+	 *
+	 * Consider putting test data in driver-private structs, like
+	 * sandbox_pch.c.
+	 *
+	 * If you add new members, please put them above this comment.
+	 */
 };
 
 /* Minimum space we guarantee in the state FDT when calling read/write*/
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#24 lore raw

PATCH 11/33 sandbox: Add a note about the growing state_info struct

Quoted 5 lines · Simon Glass

This struct is getting larger and in some cases is being used for things which would be better put into a driver. For example hwspinlock is not used outside of sandbox_hwspinlock.c.

Quoted 8 lines

Add a note to encourage people to put things elsewhere.

---

 arch/sandbox/include/asm/state.h | 9 +++++++++
 1 file changed, 9 insertions(+)
#25 lore raw

PATCH 12/33 x86: Adjust I/O macros to work on 64-bit machines

In reply to Simon Glass

At present these macros give warnings on 64-bit machines and do not correctly do 32-bit accesses. Update them to use linux types.

---

 arch/x86/include/asm/io.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
arch/x86/include/asm/io.h +8 -8
index 81def0afd3..cf6c33cbe3 100644
@@ -57,19 +57,19 @@
  * memory location directly.
  */
 
-#define readb(addr) (*(volatile unsigned char *) (addr))
-#define readw(addr) (*(volatile unsigned short *) (addr))
-#define readl(addr) (*(volatile unsigned int *) (addr))
-#define readq(addr) (*(volatile unsigned long long *) (addr))
+#define readb(addr) (*(volatile u8 *)(uintptr_t)(addr))
+#define readw(addr) (*(volatile u16 *)(uintptr_t)(addr))
+#define readl(addr) (*(volatile u32 *)(uintptr_t)(addr))
+#define readq(addr) (*(volatile u64 *)(uintptr_t)(addr))
 #define __raw_readb readb
 #define __raw_readw readw
 #define __raw_readl readl
 #define __raw_readq readq
 
-#define writeb(b,addr) (*(volatile unsigned char *) (addr) = (b))
-#define writew(b,addr) (*(volatile unsigned short *) (addr) = (b))
-#define writel(b,addr) (*(volatile unsigned int *) (addr) = (b))
-#define writeq(b,addr) (*(volatile unsigned long long *) (addr) = (b))
+#define writeb(b, addr) (*(volatile u8 *)(addr) = (b))
+#define writew(b, addr) (*(volatile u16 *)(addr) = (b))
+#define writel(b, addr) (*(volatile u32 *)(addr) = (b))
+#define writeq(b, addr) (*(volatile u64 *)(addr) = (b))
 #define __raw_writeb writeb
 #define __raw_writew writew
 #define __raw_writel writel
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#26 lore raw

PATCH 12/33 x86: Adjust I/O macros to work on 64-bit machines

Quoted 10 lines · Simon Glass

At present these macros give warnings on 64-bit machines and do not correctly do 32-bit accesses. Update them to use linux types.

---

 arch/x86/include/asm/io.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
#27 lore raw

PATCH 13/33 x86: samus: Increase the pre-reloc memory

In reply to Simon Glass

This is too small now, likely due to the pre_reloc_only fixes. Increase it.

---

 configs/chromebook_samus_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configs/chromebook_samus_defconfig +1 -1
index e5483c5920..745cb3db0a 100644
@@ -1,6 +1,6 @@
 CONFIG_X86=y
 CONFIG_SYS_TEXT_BASE=0xFFE00000
-CONFIG_SYS_MALLOC_F_LEN=0x1a00
+CONFIG_SYS_MALLOC_F_LEN=0x1c00
 CONFIG_DEBUG_UART_BOARD_INIT=y
 CONFIG_DEBUG_UART_BASE=0x3f8
 CONFIG_DEBUG_UART_CLOCK=1843200
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#29 lore raw

PATCH 14/33 x86: link: Increase malloc size and decrease code size

In reply to Simon Glass

At present link does not boot since it has outgrown its pre-relocation malloc() size and its assigned code area. Increase the former and drop EFI loader support, which adds about 45KB!

---

 configs/chromebook_link_defconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
configs/chromebook_link_defconfig +2 -1
index b90aae610b..c402568c17 100644
@@ -1,6 +1,6 @@
 CONFIG_X86=y
 CONFIG_SYS_TEXT_BASE=0xFFF00000
-CONFIG_SYS_MALLOC_F_LEN=0x2000
+CONFIG_SYS_MALLOC_F_LEN=0x2400
 CONFIG_DEBUG_UART_BOARD_INIT=y
 CONFIG_DEBUG_UART_BASE=0x3f8
 CONFIG_DEBUG_UART_CLOCK=1843200
@@ -63,3 +63,4 @@ CONFIG_VIDEO_IVYBRIDGE_IGD=y
 CONFIG_CONSOLE_SCROLL_LINES=5
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
+# CONFIG_EFI_LOADER is not set
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#30 lore raw

PATCH 14/33 x86: link: Increase malloc size and decrease code size

Quoted 11 lines · Simon Glass

At present link does not boot since it has outgrown its pre-relocation malloc() size and its assigned code area. Increase the former and drop EFI loader support, which adds about 45KB!

---

 configs/chromebook_link_defconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
#31 lore raw

PATCH 15/33 x86: sandbox: pch: Add a CONFIG option for PCH

In reply to Simon Glass

At present this uclass is selected only on x86. In order to add a test for it, it must also support sandbox. Create a new CONFIG_PCH option and enable it on x86 and sandbox.

---

 arch/Kconfig        | 2 ++
 drivers/Kconfig     | 2 ++
 drivers/Makefile    | 2 +-
 drivers/pch/Kconfig | 9 +++++++++
 4 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 drivers/pch/Kconfig
arch/Kconfig +2 -0
index 35e2712fce..d9afe269f2 100644
@@ -117,6 +117,7 @@ config SANDBOX
 	imply VIRTIO_BLK
 	imply VIRTIO_NET
 	imply DM_SOUND
+	imply PCH
 
 config SH
 	bool "SuperH architecture"
@@ -160,6 +161,7 @@ config X86
 	imply USB_ETHER_ASIX
 	imply USB_ETHER_SMSC95XX
 	imply USB_HOST_ETHER
+	imply PCH
 
 config XTENSA
 	bool "Xtensa architecture"
drivers/Kconfig +2 -0
index e9fbadd13d..f24351ac4f 100644
@@ -64,6 +64,8 @@ source "drivers/nvme/Kconfig"
 
 source "drivers/pci/Kconfig"
 
+source "drivers/pch/Kconfig"
+
 source "drivers/pcmcia/Kconfig"
 
 source "drivers/phy/Kconfig"
drivers/Makefile +1 -1
index 4105864e2b..62722146c4 100644
@@ -87,7 +87,7 @@ obj-$(CONFIG_MMC) += mmc/
 obj-$(CONFIG_NVME) += nvme/
 obj-y += pcmcia/
 obj-y += dfu/
-obj-$(CONFIG_X86) += pch/
+obj-$(CONFIG_PCH) += pch/
 obj-y += phy/allwinner/
 obj-y += phy/marvell/
 obj-y += rtc/
drivers/pch/Kconfig new file +9 -0
new file mode 100644
index 0000000000..18f006de24
@@ -0,0 +1,9 @@
+config PCH
+	bool "Enable Platform-controller Hub (PCH) support"
+	depends on X86 || SANDBOX
+	help
+	  Most x86 chips include a PCH which is responsible for handling
+	  parts of the system not handled by that CPU. It supersedes the
+	  northbridge / southbridge architecture that was previously used. The
+	  PCH allows for higher performance since the memory functions are
+	  handled in the CPU.
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#32 lore raw

PATCH 15/33 x86: sandbox: pch: Add a CONFIG option for PCH

Quoted 6 lines · Simon Glass

At present this uclass is selected only on x86. In order to add a test for it, it must also support sandbox. Create a new CONFIG_PCH option and enable it on x86 and sandbox.

Quoted 9 lines

---

 arch/Kconfig        | 2 ++
 drivers/Kconfig     | 2 ++
 drivers/Makefile    | 2 +-
 drivers/pch/Kconfig | 9 +++++++++
 4 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 drivers/pch/Kconfig
#33 lore raw

PATCH 15/33 x86: sandbox: pch: Add a CONFIG option for PCH

In reply to Simon Glass
Quoted 66 lines · Simon Glass

At present this uclass is selected only on x86. In order to add a test for it, it must also support sandbox. Create a new CONFIG_PCH option and enable it on x86 and sandbox.

---

  arch/Kconfig        | 2 ++
  drivers/Kconfig     | 2 ++
  drivers/Makefile    | 2 +-
  drivers/pch/Kconfig | 9 +++++++++
  4 files changed, 14 insertions(+), 1 deletion(-)

create mode 100644 drivers/pch/Kconfig

arch/Kconfig +2 -0
index 35e2712fce..d9afe269f2 100644
@@ -117,6 +117,7 @@ config SANDBOX
  	imply VIRTIO_BLK
  	imply VIRTIO_NET
  	imply DM_SOUND
+	imply PCH
 
  config SH
  	bool "SuperH architecture"
@@ -160,6 +161,7 @@ config X86
  	imply USB_ETHER_ASIX
  	imply USB_ETHER_SMSC95XX
  	imply USB_HOST_ETHER
+	imply PCH
 
  config XTENSA
  	bool "Xtensa architecture"
drivers/Kconfig +2 -0
index e9fbadd13d..f24351ac4f 100644
@@ -64,6 +64,8 @@ source "drivers/nvme/Kconfig"
 
  source "drivers/pci/Kconfig"
 
+source "drivers/pch/Kconfig"
+
  source "drivers/pcmcia/Kconfig"
 
  source "drivers/phy/Kconfig"
drivers/Makefile +1 -1
index 4105864e2b..62722146c4 100644
@@ -87,7 +87,7 @@ obj-$(CONFIG_MMC) += mmc/
  obj-$(CONFIG_NVME) += nvme/
  obj-y += pcmcia/
  obj-y += dfu/
-obj-$(CONFIG_X86) += pch/
+obj-$(CONFIG_PCH) += pch/
  obj-y += phy/allwinner/
  obj-y += phy/marvell/
  obj-y += rtc/
drivers/pch/Kconfig new file +0 -0
new file mode 100644
index 0000000000..18f006de24

drivers/pch/Kconfig line 9

Quoted 9 lines
drivers/pch/Kconfig new file +9 -0
@@ -0,0 +1,9 @@
+config PCH
+	bool "Enable Platform-controller Hub (PCH) support"
+	depends on X86 || SANDBOX
+	help
+	  Most x86 chips include a PCH which is responsible for handling
+	  parts of the system not handled by that CPU. It supersedes the
+	  northbridge / southbridge architecture that was previously used. The
+	  PCH allows for higher performance since the memory functions are
+	  handled in the CPU.
#34 lore raw

PATCH 16/33 sandbox: pch: Add a test for the PCH uclass

In reply to Simon Glass

This uclass currently has no tests. Add a sandbox driver and some simple tests to provide basic coverage.

---

 arch/sandbox/dts/test.dts       |  4 ++
 arch/sandbox/include/asm/test.h |  8 ++++
 drivers/pch/Makefile            |  1 +
 drivers/pch/sandbox_pch.c       | 69 +++++++++++++++++++++++++++++++++
 test/dm/Makefile                |  1 +
 test/dm/pch.c                   | 36 +++++++++++++++++
 6 files changed, 119 insertions(+)
 create mode 100644 drivers/pch/sandbox_pch.c
 create mode 100644 test/dm/pch.c
arch/sandbox/dts/test.dts +4 -0
index 1d011ded7c..9144430cc0 100644
@@ -407,6 +407,10 @@
 		compatible = "sandbox,mmc";
 	};
 
+	pch {
+		compatible = "u-boot,sandbox-pch";
+	};
+
 	pci0: pci-controller0 {
 		compatible = "sandbox,pci";
 		device_type = "pci";
arch/sandbox/include/asm/test.h +8 -0
index 74f9618822..ce00ba51e4 100644
@@ -161,4 +161,12 @@ int sandbox_get_setup_called(struct udevice *dev);
  */
 int sandbox_get_sound_sum(struct udevice *dev);
 
+/**
+ * sandbox_get_pch_spi_protect() - Get the PCI SPI protection status
+ *
+ * @dev: Device to check
+ * @return 0 if not protected, 1 if protected
+ */
+int sandbox_get_pch_spi_protect(struct udevice *dev);
+
 #endif
drivers/pch/Makefile +1 -0
index 696cdffedb..8ea6b7852a 100644
@@ -3,3 +3,4 @@
 obj-y += pch-uclass.o
 obj-y += pch7.o
 obj-y += pch9.o
+obj-$(CONFIG_SANDBOX) += sandbox_pch.o
drivers/pch/sandbox_pch.c new file +69 -0

69 lines not on this page · raw message

test/dm/Makefile +1 -0
index 1b089960cb..49857c5092 100644
@@ -30,6 +30,7 @@ obj-y += ofnode.o
 obj-$(CONFIG_OSD) += osd.o
 obj-$(CONFIG_DM_VIDEO) += panel.o
 obj-$(CONFIG_DM_PCI) += pci.o
+obj-$(CONFIG_PCH) += pch.o
 obj-$(CONFIG_PHY) += phy.o
 obj-$(CONFIG_POWER_DOMAIN) += power-domain.o
 obj-$(CONFIG_DM_PWM) += pwm.o
test/dm/pch.c new file +36 -0
new file mode 100644
index 0000000000..f184445342
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018 Google LLC
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <pch.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+/* Test that sandbox PCH works correctly */
+static int dm_test_pch_base(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	u32 gbase, iobase;
+	ulong sbase;
+
+	ut_assertok(uclass_first_device_err(UCLASS_PCH, &dev));
+	ut_assertok(pch_get_spi_base(dev, &sbase));
+	ut_asserteq(0x10, sbase);
+
+	ut_asserteq(0, sandbox_get_pch_spi_protect(dev));
+	ut_assertok(pch_set_spi_protect(dev, true));
+	ut_asserteq(1, sandbox_get_pch_spi_protect(dev));
+
+	ut_assertok(pch_get_gpio_base(dev, &gbase));
+	ut_asserteq(0x20, gbase);
+
+	ut_assertok(pch_get_io_base(dev, &iobase));
+	ut_asserteq(0x30, iobase);
+
+	return 0;
+}
+DM_TEST(dm_test_pch_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#35 lore raw

PATCH 16/33 sandbox: pch: Add a test for the PCH uclass

Hi Simon,

Quoted 22 lines · Simon Glass

This uclass currently has no tests. Add a sandbox driver and some simple tests to provide basic coverage.

---

 arch/sandbox/dts/test.dts       |  4 ++
 arch/sandbox/include/asm/test.h |  8 ++++
 drivers/pch/Makefile            |  1 +
 drivers/pch/sandbox_pch.c       | 69 +++++++++++++++++++++++++++++++++
 test/dm/Makefile                |  1 +
 test/dm/pch.c                   | 36 +++++++++++++++++
 6 files changed, 119 insertions(+)
 create mode 100644 drivers/pch/sandbox_pch.c
 create mode 100644 test/dm/pch.c
arch/sandbox/dts/test.dts +0 -0
index 1d011ded7c..9144430cc0 100644

arch/sandbox/dts/test.dts line 411

Quoted 5 lines
arch/sandbox/dts/test.dts +2 -0
@@ -407,6 +407,10 @@
                compatible = "sandbox,mmc";
        };
 
+       pch {
+               compatible = "u-boot,sandbox-pch";

Shouldn't this be "sandbox,pch", to be in consistent with others like "sandbox,mmc", "sandbox,pci"?

arch/sandbox/dts/test.dts line 416

Quoted 5 lines
arch/sandbox/dts/test.dts +2 -0
+       };
+
        pci0: pci-controller0 {
                compatible = "sandbox,pci";
                device_type = "pci";

Other than that,

Regards,
Bin

#36 lore raw

PATCH 17/33 pch: Add ioctl support

In reply to Simon Glass

At present the PCH has 4 operations and these are reasonably widely used in the drivers. But sometimes we want to add rarely used operations, and each of these currently adds to the size of the PCH operations table.

Add an ioctl() method which can be easily expanded without any more impact on the operations table.

---

 drivers/pch/pch-uclass.c  | 10 ++++++++
 drivers/pch/sandbox_pch.c | 17 ++++++++++++++
 include/pch.h             | 48 ++++++++++++++++++++++++++++++++++++++-
 test/dm/pch.c             | 19 ++++++++++++++++
 4 files changed, 93 insertions(+), 1 deletion(-)
drivers/pch/pch-uclass.c +10 -0
index 831b283d7b..caf8b72803 100644
@@ -51,6 +51,16 @@ int pch_get_io_base(struct udevice *dev, u32 *iobasep)
 	return ops->get_io_base(dev, iobasep);
 }
 
+int pch_ioctl(struct udevice *dev, ulong req, void *data, int size)
+{
+	struct pch_ops *ops = pch_get_ops(dev);
+
+	if (!ops->ioctl)
+		return -ENOSYS;
+
+	return ops->ioctl(dev, req, data, size);
+}
+
 UCLASS_DRIVER(pch) = {
 	.id		= UCLASS_PCH,
 	.name		= "pch",
drivers/pch/sandbox_pch.c +17 -0
index 2209bff8d4..43688368ed 100644
@@ -48,11 +48,28 @@ static int sandbox_pch_get_io_base(struct udevice *dev, u32 *iobasep)
 	return 0;
 }
 
+int sandbox_pch_ioctl(struct udevice *dev, enum pch_req_t req, void *data,
+		      int size)
+{
+	switch (req) {
+	case PCH_REQ_TEST1:
+		return -ENOSYS;
+	case PCH_REQ_TEST2:
+		return *(char *)data;
+	case PCH_REQ_TEST3:
+		*(char *)data = 'x';
+		return 1;
+	default:
+		return -ENOSYS;
+	}
+}
+
 static const struct pch_ops sandbox_pch_ops = {
 	.get_spi_base	= sandbox_pch_get_spi_base,
 	.set_spi_protect = sandbox_pch_set_spi_protect,
 	.get_gpio_base	= sandbox_pch_get_gpio_base,
 	.get_io_base = sandbox_pch_get_io_base,
+	.ioctl		= sandbox_pch_ioctl,
 };
 
 static const struct udevice_id sandbox_pch_ids[] = {
include/pch.h +47 -1

64 lines not on this page · raw message

test/dm/pch.c +19 -0
index f184445342..54e33d187b 100644
@@ -34,3 +34,22 @@ static int dm_test_pch_base(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_pch_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test sandbox PCH ioctl */
+static int dm_test_pch_ioctl(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	char data;
+
+	ut_assertok(uclass_first_device_err(UCLASS_PCH, &dev));
+
+	ut_asserteq(-ENOSYS, pch_ioctl(dev, PCH_REQ_TEST1, NULL, 0));
+
+	ut_asserteq('a', pch_ioctl(dev, PCH_REQ_TEST2, "a", 1));
+
+	ut_asserteq(1, pch_ioctl(dev, PCH_REQ_TEST3, &data, 1));
+	ut_asserteq('x', data);
+
+	return 0;
+}
+DM_TEST(dm_test_pch_ioctl, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#37 lore raw

PATCH 17/33 pch: Add ioctl support

Hi Simon,

Quoted 8 lines · Simon Glass

At present the PCH has 4 operations and these are reasonably widely used in the drivers. But sometimes we want to add rarely used operations, and each of these currently adds to the size of the PCH operations table.

Add an ioctl() method which can be easily expanded without any more impact on the operations table.

Quoted 9 lines

---

 drivers/pch/pch-uclass.c  | 10 ++++++++
 drivers/pch/sandbox_pch.c | 17 ++++++++++++++
 include/pch.h             | 48 ++++++++++++++++++++++++++++++++++++++-
 test/dm/pch.c             | 19 ++++++++++++++++
 4 files changed, 93 insertions(+), 1 deletion(-)

But please see comments below.

Quoted 88 lines
drivers/pch/pch-uclass.c +10 -0
index 831b283d7b..caf8b72803 100644
@@ -51,6 +51,16 @@ int pch_get_io_base(struct udevice *dev, u32 *iobasep)
        return ops->get_io_base(dev, iobasep);
 }
 
+int pch_ioctl(struct udevice *dev, ulong req, void *data, int size)
+{
+       struct pch_ops *ops = pch_get_ops(dev);
+
+       if (!ops->ioctl)
+               return -ENOSYS;
+
+       return ops->ioctl(dev, req, data, size);
+}
+
 UCLASS_DRIVER(pch) = {
        .id             = UCLASS_PCH,
        .name           = "pch",
drivers/pch/sandbox_pch.c +17 -0
index 2209bff8d4..43688368ed 100644
@@ -48,11 +48,28 @@ static int sandbox_pch_get_io_base(struct udevice *dev, u32 *iobasep)
        return 0;
 }
 
+int sandbox_pch_ioctl(struct udevice *dev, enum pch_req_t req, void *data,
+                     int size)
+{
+       switch (req) {
+       case PCH_REQ_TEST1:
+               return -ENOSYS;
+       case PCH_REQ_TEST2:
+               return *(char *)data;
+       case PCH_REQ_TEST3:
+               *(char *)data = 'x';
+               return 1;
+       default:
+               return -ENOSYS;
+       }
+}
+
 static const struct pch_ops sandbox_pch_ops = {
        .get_spi_base   = sandbox_pch_get_spi_base,
        .set_spi_protect = sandbox_pch_set_spi_protect,
        .get_gpio_base  = sandbox_pch_get_gpio_base,
        .get_io_base = sandbox_pch_get_io_base,
+       .ioctl          = sandbox_pch_ioctl,
 };
 
 static const struct udevice_id sandbox_pch_ids[] = {
include/pch.h +18 -1
index 73994b8343..c9995702c1 100644
@@ -11,7 +11,20 @@
 
 #define BIOS_CTRL_BIOSWE       BIT(0)
 
-/* Operations for the Platform Controller Hub */
+/* All the supported PCH ioctls */
+enum pch_req_t {
+       PCH_REQ_TEST1,          /* Test requests for sandbox driver */
+       PCH_REQ_TEST2,
+       PCH_REQ_TEST3,
+
+       PCH_REQ_COUNT,          /* Number of ioctrls supported */
+};
+
+/**
+ * struct pch_ops - Operations for the Platform Controller Hub
+ *
+ * Consider using ioctl() to add rarely used or driver-specific operations.
+ */
 struct pch_ops {
        /**
         * get_spi_base() - get the address of SPI base
@@ -49,6 +62,23 @@ struct pch_ops {
         * @return 0 if OK, -ve on error (e.g. there is no IO base)
         */
        int (*get_io_base)(struct udevice *dev, u32 *iobasep);
+
+       /**
+        * ioctl() - perform misc read/write operations
+        *

include/pch.h struct pch_ops { · line 78

Quoted 10 lines
include/pch.h +10 -0
+        * This is a catch-all operation intended to avoid adding lots of
+        * methods to this uclass, of which few are commonly used. Uncommon
+        * operations that pertain only to a few devices in this uclass should
+        * use this method instead of adding new methods.
+        *
+        * @dev:        PCH device to check
+        * @req:        PCH request ID
+        * @data:       Input/output data
+        * @size:       Size of input data (and maximum size of output data)
+        * @return size of output data or 0 on sucesss, -ve on error

From the sandbox ioctl implementation, it never returns 0, so this is incorrect comment.

Quoted 13 lines
include/pch.h +6 -0
+        */
+       int (*ioctl)(struct udevice *dev, enum pch_req_t req, void *data,
+                    int size);
 };
 
 #define pch_get_ops(dev)        ((struct pch_ops *)(dev)->driver->ops)
@@ -90,4 +120,20 @@ int pch_get_gpio_base(struct udevice *dev, u32 *gbasep);
  */
 int pch_get_io_base(struct udevice *dev, u32 *iobasep);
 
+/**
+ * pch_ioctl() - perform misc read/write operations
+ *

include/pch.h int pch_get_gpio_base(struct udevice *dev, u32 *gbasep); · line 135

Quoted 10 lines
include/pch.h +10 -0
+ * This is a catch-all operation intended to avoid adding lots of
+ * methods to this uclass, of which few are commonly used. Uncommon
+ * operations that pertain only to a few devices in this uclass should
+ * use this method instead of adding new methods.
+ *
+ * @dev:       PCH device to check
+ * @req:       PCH request ID
+ * @data:      Input/output data
+ * @size:      Size of input data (and maximum size of output data)
+ * @return size of output data or 0 on sucesss, -ve on error

Ditto.

include/pch.h int pch_get_gpio_base(struct udevice *dev, u32 *gbasep); · line 139

Quoted 4 lines
include/pch.h +3 -0
+ */
+int pch_ioctl(struct udevice *dev, ulong req, void *data, int size);
+
 #endif

[snip]

Regards,
Bin

#38 lore raw

PATCH 18/33 x86: ivybridge: Add a way to get the HDA config setting

In reply to Simon Glass

Add a way check to whether HD audio is enabled. Use ioctl() to avoid adding too many unusual operations to PCH.

---

 arch/x86/cpu/ivybridge/bd82x6x.c | 19 +++++++++++++++++++
 include/pch.h                    |  3 +++
 2 files changed, 22 insertions(+)
arch/x86/cpu/ivybridge/bd82x6x.c +19 -0
index a78bb02544..7d16294a5e 100644
@@ -212,10 +212,29 @@ static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep)
 	return 0;
 }
 
+static int bd82x6x_ioctl(struct udevice *dev, enum pch_req_t req, void *data,
+			 int size)
+{
+	u32 rcba, val;
+
+	switch (req) {
+	case PCH_REQ_HDA_CONFIG:
+		dm_pci_read_config32(dev, PCH_RCBA, &rcba);
+		val = readl(rcba + 0x2030);
+		if (!(val & (1U << 31)))
+			return -ENOENT;
+
+		return val & 0xfe;
+	default:
+		return -ENOSYS;
+	}
+}
+
 static const struct pch_ops bd82x6x_pch_ops = {
 	.get_spi_base	= bd82x6x_pch_get_spi_base,
 	.set_spi_protect = bd82x6x_set_spi_protect,
 	.get_gpio_base	= bd82x6x_get_gpio_base,
+	.ioctl		= bd82x6x_ioctl,
 };
 
 static const struct udevice_id bd82x6x_ids[] = {
include/pch.h +3 -0
index c9995702c1..d1a8131794 100644
@@ -13,6 +13,9 @@
 
 /* All the supported PCH ioctls */
 enum pch_req_t {
+	/* Returns HDA config info if Azalia V1CTL enabled, -ENOENT if not */
+	PCH_REQ_HDA_CONFIG,
+
 	PCH_REQ_TEST1,		/* Test requests for sandbox driver */
 	PCH_REQ_TEST2,
 	PCH_REQ_TEST3,
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#39 lore raw

PATCH 18/33 x86: ivybridge: Add a way to get the HDA config setting

Hi Simon,

Quoted 18 lines · Simon Glass

Add a way check to whether HD audio is enabled. Use ioctl() to avoid adding too many unusual operations to PCH.

---

 arch/x86/cpu/ivybridge/bd82x6x.c | 19 +++++++++++++++++++
 include/pch.h                    |  3 +++
 2 files changed, 22 insertions(+)
arch/x86/cpu/ivybridge/bd82x6x.c +0 -0
index a78bb02544..7d16294a5e 100644
@@ -212,10 +212,29 @@ static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep)
        return 0;
 }

arch/x86/cpu/ivybridge/bd82x6x.c static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep) · line 223

Quoted 10 lines
arch/x86/cpu/ivybridge/bd82x6x.c +9 -0
 
+static int bd82x6x_ioctl(struct udevice *dev, enum pch_req_t req, void *data,
+                        int size)
+{
+       u32 rcba, val;
+
+       switch (req) {
+       case PCH_REQ_HDA_CONFIG:
+               dm_pci_read_config32(dev, PCH_RCBA, &rcba);
+               val = readl(rcba + 0x2030);

nits: macro for 0x2030?

arch/x86/cpu/ivybridge/bd82x6x.c static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep) · line 224

Quoted 1 line
arch/x86/cpu/ivybridge/bd82x6x.c +1 -0
+               if (!(val & (1U << 31)))

nits: use BIT(31) and another macro here?

Quoted 5 lines
arch/x86/cpu/ivybridge/bd82x6x.c +5 -0
+                       return -ENOENT;
+
+               return val & 0xfe;
+       default:
+               return -ENOSYS;

arch/x86/cpu/ivybridge/bd82x6x.c static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep) · line 239

Quoted 10 lines
arch/x86/cpu/ivybridge/bd82x6x.c +4 -0
+       }
+}
+
 static const struct pch_ops bd82x6x_pch_ops = {
        .get_spi_base   = bd82x6x_pch_get_spi_base,
        .set_spi_protect = bd82x6x_set_spi_protect,
        .get_gpio_base  = bd82x6x_get_gpio_base,
+       .ioctl          = bd82x6x_ioctl,
 };
 

Other than above,

Regards,
Bin

#40 lore raw

PATCH 19/33 sound: Mark sound_setup() as optional

In reply to Simon Glass

This method in the sound API is optional since some drivers can do this when probing or as part of SoC init. Mark it as such.

---

 drivers/sound/sound-uclass.c | 2 +-
 include/sound.h              | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/sound/sound-uclass.c +1 -1
index 2b83626889..067660623b 100644
@@ -16,7 +16,7 @@ int sound_setup(struct udevice *dev)
 	struct sound_ops *ops = sound_get_ops(dev);
 
 	if (!ops->setup)
-		return -ENOSYS;
+		return 0;
 
 	return ops->setup(dev);
 }
include/sound.h +1 -1
index b7959cc260..7d528c479e 100644
@@ -54,7 +54,7 @@ void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
 /* Operations for sound */
 struct sound_ops {
 	/**
-	 * setup() - Set up to play a sound
+	 * setup() - Set up to play a sound (optional)
 	 */
 	int (*setup)(struct udevice *dev);
 
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#41 lore raw

PATCH 19/33 sound: Mark sound_setup() as optional

Quoted 11 lines · Simon Glass

This method in the sound API is optional since some drivers can do this when probing or as part of SoC init. Mark it as such.

---

 drivers/sound/sound-uclass.c | 2 +-
 include/sound.h              | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
#42 lore raw

PATCH 20/33 sound: Add uclass operations for beeping

In reply to Simon Glass

Some audio codecs such as Intel HDA do not need to use digital data to play sounds, but instead have a way to emit beeps. Add this interface as an option. If the beep interface is not supported, then the sound uclass falls back to the I2S interface.

---

 arch/sandbox/include/asm/test.h | 16 ++++++++++++
 drivers/sound/sandbox.c         | 46 ++++++++++++++++++++++++++++++---
 drivers/sound/sound-uclass.c    | 34 +++++++++++++++++++++++-
 include/sound.h                 | 44 +++++++++++++++++++++++++++++++
 test/dm/sound.c                 | 21 +++++++++++++++
 5 files changed, 157 insertions(+), 4 deletions(-)
arch/sandbox/include/asm/test.h +16 -0
index ce00ba51e4..fc52f47f82 100644
@@ -161,6 +161,22 @@ int sandbox_get_setup_called(struct udevice *dev);
  */
 int sandbox_get_sound_sum(struct udevice *dev);
 
+/**
+ * sandbox_set_allow_beep() - Set whether the 'beep' interface is supported
+ *
+ * @dev: Device to update
+ * @allow: true to allow the start_beep() method, false to disallow it
+ */
+void sandbox_set_allow_beep(struct udevice *dev, bool allow);
+
+/**
+ * sandbox_get_beep_frequency() - Get the frequency of the current beep
+ *
+ * @dev: Device to check
+ * @return frequency of beep, if there is an active beep, else 0
+ */
+int sandbox_get_beep_frequency(struct udevice *dev);
+
 /**
  * sandbox_get_pch_spi_protect() - Get the PCI SPI protection status
  *
drivers/sound/sandbox.c +43 -3

70 lines not on this page · raw message

drivers/sound/sound-uclass.c +33 -1
index 067660623b..d49f29bcd5 100644
@@ -31,10 +31,30 @@ int sound_play(struct udevice *dev, void *data, uint data_size)
 	return ops->play(dev, data, data_size);
 }
 
+int sound_start_beep(struct udevice *dev, int frequency_hz)
+{
+	struct sound_ops *ops = sound_get_ops(dev);
+
+	if (!ops->start_beep)
+		return -ENOSYS;
+
+	return ops->start_beep(dev, frequency_hz);
+}
+
+int sound_stop_beep(struct udevice *dev)
+{
+	struct sound_ops *ops = sound_get_ops(dev);
+
+	if (!ops->stop_beep)
+		return -ENOSYS;
+
+	return ops->stop_beep(dev);
+}
+
 int sound_beep(struct udevice *dev, int msecs, int frequency_hz)
 {
 	struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
-	struct i2s_uc_priv *i2s_uc_priv = dev_get_uclass_priv(uc_priv->i2s);
+	struct i2s_uc_priv *i2s_uc_priv;
 	unsigned short *data;
 	uint data_size;
 	int ret;
@@ -43,7 +63,19 @@ int sound_beep(struct udevice *dev, int msecs, int frequency_hz)
 	if (ret && ret != -EALREADY)
 		return ret;
 
+	/* Try using the beep interface if available */
+	ret = sound_start_beep(dev, frequency_hz);
+	if (ret != -ENOSYS) {
+		if (ret)
+			return ret;
+		mdelay(msecs);
+		ret = sound_stop_beep(dev);
+
+		return ret;
+	}
+
 	/* Buffer length computation */
+	i2s_uc_priv = dev_get_uclass_priv(uc_priv->i2s);
 	data_size = i2s_uc_priv->samplingrate * i2s_uc_priv->channels;
 	data_size *= (i2s_uc_priv->bitspersample / SOUND_BITS_IN_BYTE);
 	data = malloc(data_size);
include/sound.h +44 -0

56 lines not on this page · raw message

test/dm/sound.c +21 -0
index 7d0b36e7a5..3767abbd1c 100644
@@ -32,3 +32,24 @@ static int dm_test_sound(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_sound, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test of the 'start beep' operations */
+static int dm_test_sound_beep(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+
+	/* check probe success */
+	ut_assertok(uclass_first_device_err(UCLASS_SOUND, &dev));
+	ut_asserteq(-ENOSYS, sound_start_beep(dev, 100));
+	ut_asserteq(0, sandbox_get_beep_frequency(dev));
+
+	sandbox_set_allow_beep(dev, true);
+	ut_asserteq(0, sound_start_beep(dev, 100));
+	ut_asserteq(100, sandbox_get_beep_frequency(dev));
+
+	ut_asserteq(0, sound_stop_beep(dev));
+	ut_asserteq(0, sandbox_get_beep_frequency(dev));
+
+	return 0;
+}
+DM_TEST(dm_test_sound_beep, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#43 lore raw

PATCH 20/33 sound: Add uclass operations for beeping

Quoted 7 lines · Simon Glass

Some audio codecs such as Intel HDA do not need to use digital data to play sounds, but instead have a way to emit beeps. Add this interface as an option. If the beep interface is not supported, then the sound uclass falls back to the I2S interface.

Quoted 9 lines

---

 arch/sandbox/include/asm/test.h | 16 ++++++++++++
 drivers/sound/sandbox.c         | 46 ++++++++++++++++++++++++++++++---
 drivers/sound/sound-uclass.c    | 34 +++++++++++++++++++++++-
 include/sound.h                 | 44 +++++++++++++++++++++++++++++++
 test/dm/sound.c                 | 21 +++++++++++++++
 5 files changed, 157 insertions(+), 4 deletions(-)
#44 lore raw

PATCH 21/33 sound: Add support for Intel HDA

In reply to Simon Glass

The Intel High-definition Audio is a newer-generation audio system which provides for transfer of a large number of audio stream, each containing up to 16 channels.

Add support for HDA as a library which can be used by other drivers. U-Boot currently uses only two channels (stereo).

---

 doc/device-tree-bindings/sound/intel-hda.txt |  26 +
 drivers/sound/Kconfig                        |   9 +
 drivers/sound/Makefile                       |   1 +
 drivers/sound/hda_codec.c                    | 545 +++++++++++++++++++
 include/dt-bindings/sound/azalia.h           |  29 +
 include/hda_codec.h                          | 103 ++++
 6 files changed, 713 insertions(+)
 create mode 100644 doc/device-tree-bindings/sound/intel-hda.txt
 create mode 100644 drivers/sound/hda_codec.c
 create mode 100644 include/dt-bindings/sound/azalia.h
 create mode 100644 include/hda_codec.h
doc/device-tree-bindings/sound/intel-hda.txt new file +26 -0
new file mode 100644
index 0000000000..16eb1cf133
@@ -0,0 +1,26 @@
+* Intel High-definition Audio
+
+Configuration is set using 'verbs' which are blocks of 16 bytes of data each
+with a different purpose, a little like a simple instruction set.
+
+Top-level node
+--------------
+
+Required properties:
+- compatible: "intel,bd82x6x-hda"
+- beep-verbs: list of verbs to send for a beep
+
+Optional properties
+- intel,beep-nid: Node ID to use for beep (will be detected if not provided)
+
+Required subnodes:
+- codecs: Contains a list of codec nodes
+
+
+* Codec nodes
+
+Required properties:
+- vendor-id: 16-bit vendor ID for audio codec
+- device-id: 16-bit device ID for audio codec
+- verbs: List of verbs, each 4 cells in length
+
drivers/sound/Kconfig +9 -0
index 506a60a7c7..a03d3057e1 100644
@@ -31,6 +31,15 @@ config I2S_SAMSUNG
 	  option provides an implementation for sound_init() and
 	  sound_play().
 
+config SOUND_INTEL_HDA
+	bool "Intel HDA audio codec"
+	depends on SOUND
+	help
+	  Most Intel chips have an HDA (High-definition audio) codec which can
+	  be used by U-Boot to play simple beeps. This is also sometimes called
+	  Azalia which was the development code-name. It requires setup
+	  information in the device tree (see intel-hda.txt).
+
 config SOUND_MAX98088
 	bool "Support Maxim max98088 audio codec"
 	depends on I2S
drivers/sound/Makefile +1 -0
index 238f33bbb4..705a09464d 100644
@@ -14,3 +14,4 @@ obj-$(CONFIG_SOUND_WM8994)	+= wm8994.o
 obj-$(CONFIG_SOUND_MAX98088)	+= max98088.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98090)	+= max98090.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o
+obj-$(CONFIG_SOUND_INTEL_HDA)	+= hda_codec.o
drivers/sound/hda_codec.c new file +545 -0

545 lines not on this page · raw message

include/dt-bindings/sound/azalia.h new file +29 -0
new file mode 100644
index 0000000000..e35ffa920d
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Intel HDA audio codec config. This is a mechanicm to configure codecs when
+ * using Intel HDA audio.
+ *
+ * Copyright 2018 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#ifndef __AZALIA_H
+#define __AZALIA_H
+
+#define AZALIA_PIN_CFG(codec, pin, val)			\
+	(((codec) << 28) | ((pin) << 20) | (0x71c << 8)	\
+		| ((val) & 0xff))			\
+	(((codec) << 28) | ((pin) << 20) | (0x71d << 8)	\
+		| (((val) >> 8) & 0xff))		\
+	(((codec) << 28) | ((pin) << 20) | (0x71e << 8)	\
+		| (((val) >> 16) & 0xff))		\
+	(((codec) << 28) | ((pin) << 20) | (0x71f << 8)	\
+		| (((val) >> 24) & 0xff))
+
+#define AZALIA_SUBVENDOR(codec, val)		    \
+	(((codec) << 28) | (0x01720 << 8) | ((val) & 0xff))	\
+	(((codec) << 28) | (0x01721 << 8) | (((val) >> 8) & 0xff)) \
+	(((codec) << 28) | (0x01722 << 8) | (((val) >> 16) & 0xff)) \
+	(((codec) << 28) | (0x01723 << 8) | (((val) >> 24) & 0xff))
+
+#endif /* __AZALIA_H */
include/hda_codec.h new file +103 -0

103 lines not on this page · raw message

Signature · 1 line
2.20.1.321.g9e740568ce-goog
#45 lore raw

PATCH 21/33 sound: Add support for Intel HDA

Hi Simon,

Quoted 8 lines · Simon Glass

The Intel High-definition Audio is a newer-generation audio system which provides for transfer of a large number of audio stream, each containing up to 16 channels.

Add support for HDA as a library which can be used by other drivers. U-Boot currently uses only two channels (stereo).

I don't have knowledge about Intel HDA, just provide some general comments below.

Quoted 21 lines

---

 doc/device-tree-bindings/sound/intel-hda.txt |  26 +
 drivers/sound/Kconfig                        |   9 +
 drivers/sound/Makefile                       |   1 +
 drivers/sound/hda_codec.c                    | 545 +++++++++++++++++++
 include/dt-bindings/sound/azalia.h           |  29 +
 include/hda_codec.h                          | 103 ++++
 6 files changed, 713 insertions(+)
 create mode 100644 doc/device-tree-bindings/sound/intel-hda.txt
 create mode 100644 drivers/sound/hda_codec.c
 create mode 100644 include/dt-bindings/sound/azalia.h
 create mode 100644 include/hda_codec.h
doc/device-tree-bindings/sound/intel-hda.txt new file +0 -0
new file mode 100644
index 0000000000..16eb1cf133

doc/device-tree-bindings/sound/intel-hda.txt line 10

Quoted 10 lines
doc/device-tree-bindings/sound/intel-hda.txt new file +10 -0
@@ -0,0 +1,26 @@
+* Intel High-definition Audio
+
+Configuration is set using 'verbs' which are blocks of 16 bytes of data each
+with a different purpose, a little like a simple instruction set.
+
+Top-level node
+--------------
+
+Required properties:
+- compatible: "intel,bd82x6x-hda"

It looks to me the Intel HDA is a well defined specification, is it possible to specify a generic name here something like "intel,hda" or "intel,hd-audio"?

Quoted 285 lines
doc/device-tree-bindings/sound/intel-hda.txt new file +16 -0
+- beep-verbs: list of verbs to send for a beep
+
+Optional properties
+- intel,beep-nid: Node ID to use for beep (will be detected if not provided)
+
+Required subnodes:
+- codecs: Contains a list of codec nodes
+
+
+* Codec nodes
+
+Required properties:
+- vendor-id: 16-bit vendor ID for audio codec
+- device-id: 16-bit device ID for audio codec
+- verbs: List of verbs, each 4 cells in length
+
drivers/sound/Kconfig +9 -0
index 506a60a7c7..a03d3057e1 100644
@@ -31,6 +31,15 @@ config I2S_SAMSUNG
          option provides an implementation for sound_init() and
          sound_play().
 
+config SOUND_INTEL_HDA
+       bool "Intel HDA audio codec"
+       depends on SOUND
+       help
+         Most Intel chips have an HDA (High-definition audio) codec which can
+         be used by U-Boot to play simple beeps. This is also sometimes called
+         Azalia which was the development code-name. It requires setup
+         information in the device tree (see intel-hda.txt).
+
 config SOUND_MAX98088
        bool "Support Maxim max98088 audio codec"
        depends on I2S
drivers/sound/Makefile +1 -0
index 238f33bbb4..705a09464d 100644
@@ -14,3 +14,4 @@ obj-$(CONFIG_SOUND_WM8994)    += wm8994.o
 obj-$(CONFIG_SOUND_MAX98088)   += max98088.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98090)   += max98090.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98095)   += max98095.o maxim_codec.o
+obj-$(CONFIG_SOUND_INTEL_HDA)  += hda_codec.o
drivers/sound/hda_codec.c new file +234 -0
new file mode 100644
index 0000000000..648038542e
@@ -0,0 +1,545 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Implementation of per-board codec beeping
+ * Copyright (c) 2011 The Chromium OS Authors.
+ * Copyright 2018 Google LLC
+ */
+
+#define LOG_CATEGORY   UCLASS_SOUND
+
+#include <common.h>
+#include <dm.h>
+#include <hda_codec.h>
+#include <pci.h>
+#include <sound.h>
+#include <asm/io.h>
+
+/**
+ * struct hda_regs - HDA registers
+ *
+ * https://wiki.osdev.org/Intel_High_Definition_Audio
+ */
+struct hda_regs {
+       u16 gcap;
+       u8 vmin;
+       u8 vmaj;
+       u16 outpay;
+       u16 inpay;
+       u32 gctl;
+       u16 wakeen;
+       u16 statests;
+       u8 reserved[0x50];
+       u32 cmd;                /* 0x60 */
+       u32 resp;
+       u32 icii;
+};
+
+enum {
+       HDA_ICII_BUSY                   = BIT(0),
+       HDA_ICII_VALID                  = BIT(1),
+
+       /* Common node IDs */
+       HDA_ROOT_NODE                   = 0x00,
+
+       /* HDA verbs fields */
+       HDA_VERB_NID_S                  = 20,
+       HDA_VERB_VERB_S                 = 8,
+       HDA_VERB_PARAM_S                = 0,
+
+       HDA_VERB_GET_PARAMS             = 0xf00,
+       HDA_VERB_SET_BEEP               = 0x70a,
+
+       /* GET_PARAMS parameter IDs */
+       GET_PARAMS_NODE_COUNT           = 0x04,
+       GET_PARAMS_AUDIO_GROUP_CAPS     = 0x08,
+       GET_PARAMS_AUDIO_WIDGET_CAPS    = 0x09,
+
+       /* Sub-node fields */
+       NUM_SUB_NODES_S                 = 0,
+       NUM_SUB_NODES_M                 = 0xff << NUM_SUB_NODES_S,
+       FIRST_SUB_NODE_S                = 16,
+       FIRST_SUB_NODE_M                = 0xff << FIRST_SUB_NODE_S,
+
+       /* Get Audio Function Group Capabilities fields */
+       AUDIO_GROUP_CAPS_BEEP_GEN       = 0x10000,
+
+       /* Get Audio Widget Capabilities fields */
+       AUDIO_WIDGET_TYPE_BEEP          = 0x7,
+       AUDIO_WIDGET_TYPE_S             = 20,
+       AUDIO_WIDGET_TYPE_M             = 0xf << AUDIO_WIDGET_TYPE_S,
+
+       BEEP_FREQ_BASE                  = 12000,
+};
+
+static inline uint hda_verb(uint nid, uint verb, uint param)
+{
+       return nid << HDA_VERB_NID_S | verb << HDA_VERB_VERB_S |
+               param << HDA_VERB_PARAM_S;
+}
+
+int hda_wait_for_ready(struct hda_regs *regs)
+{
+       int timeout = 1000;     /* Use a 1msec timeout */
+
+       while (timeout--) {
+               u32 reg32 = readl(&regs->icii);
+
+               if (!(reg32 & HDA_ICII_BUSY))
+                       return 0;
+               udelay(1);
+       }
+
+       return -ETIMEDOUT;
+}
+
+static int wait_for_response(struct hda_regs *regs, uint *response)
+{
+       int timeout = 1000;
+       u32 reg32;
+
+       /* Send the verb to the codec */
+       setbits_le32(&regs->icii, HDA_ICII_BUSY | HDA_ICII_VALID);
+
+       /* Use a 1msec timeout */
+       while (timeout--) {
+               reg32 = readl(&regs->icii);
+               if ((reg32 & (HDA_ICII_VALID | HDA_ICII_BUSY)) ==
+                       HDA_ICII_VALID) {
+                       if (response)
+                               *response = readl(&regs->resp);
+                       return 0;
+               }
+               udelay(1);
+       }
+
+       return -ETIMEDOUT;
+}
+
+int hda_wait_for_valid(struct hda_regs *regs)
+{
+       return wait_for_response(regs, NULL);
+}
+
+static int set_bits(void *port, u32 mask, u32 val)
+{
+       u32 reg32;
+       int count;
+
+       /* Write (val & mask) to port */
+       clrsetbits_le32(port, mask, val);
+
+       /* Wait for readback of register to match what was just written to it */
+       count = 50;
+       do {
+               /* Wait 1ms based on BKDG wait time */
+               mdelay(1);
+               reg32 = readl(port) & mask;
+       } while (reg32 != val && --count);
+
+       /* Timeout occurred */
+       if (!count)
+               return -ETIMEDOUT;
+
+       return 0;
+}
+
+int hda_codec_detect(struct hda_regs *regs)
+{
+       uint reg8;
+
+       /* Set Bit 0 to 1 to exit reset state (BAR + 0x8)[0] */
+       if (set_bits(&regs->gctl, 1, 1))
+               goto no_codec;
+
+       /* Write back the value once reset bit is set */
+       writew(readw(&regs->gcap), &regs->gcap);
+
+       /* Read in Codec location */
+       reg8 = readb(&regs->statests) & 0xf;
+       if (!reg8)
+               goto no_codec;
+
+       return reg8;
+
+no_codec:
+       /* Codec Not found - put HDA back in reset */
+       set_bits(&regs->gctl, 1, 0);
+       log_debug("No codec\n");
+
+       return 0;
+}
+
+static int find_verb_data(struct udevice *dev, uint id, ofnode *nodep)
+{
+       ofnode parent = dev_read_subnode(dev, "codecs");
+       ofnode node;
+       u32 vendor_id, device_id;
+
+       ofnode_for_each_subnode(node, parent) {
+               if (ofnode_read_u32(node, "vendor-id", &vendor_id) ||
+                   ofnode_read_u32(node, "device-id", &device_id)) {
+                       log_debug("Cannot get IDs for '%s'\n",
+                                 ofnode_get_name(node));
+                       return -EINVAL;
+               }
+               if (id != (vendor_id << 16 | device_id)) {
+                       log_debug("Skip codec node '%s' for %08x\n",
+                                 ofnode_get_name(node), id);
+                       continue;
+               }
+
+               log_debug("Found codec node '%s' for %08x\n",
+                         ofnode_get_name(node), id);
+               *nodep = node;
+               return 0;
+       }
+
+       return -ENOENT;
+}
+
+static int send_verbs(ofnode node, const char *prop_name, struct hda_regs *regs)
+{
+       int ret, verb_size, i;
+       const u32 *verb;
+
+       verb = ofnode_get_property(node, prop_name, &verb_size);
+       if (verb_size < 0) {
+               log_debug("No verb data\n");
+               return -EINVAL;
+       }
+       log_debug("verb_size: %d\n", verb_size);
+
+       for (i = 0; i < verb_size / sizeof(*verb); i++) {
+               ret = hda_wait_for_ready(regs);
+               if (ret) {
+                       log_debug("  codec ready timeout\n");
+                       return ret;
+               }
+
+               writel(fdt32_to_cpu(verb[i]), &regs->cmd);
+
+               ret = hda_wait_for_valid(regs);
+               if (ret) {
+                       log_debug("  codec valid timeout\n");
+                       return ret;
+               }
+       }
+
+       return 0;
+}
+
+static int codec_init(struct udevice *dev, struct hda_regs *regs, uint addr)
+{
+       ofnode node;
+       uint id;

drivers/sound/hda_codec.c line 244

Quoted 10 lines
drivers/sound/hda_codec.c new file +10 -0
+       int ret;
+
+       log_debug("Initializing codec #%d\n", addr);
+       ret = hda_wait_for_ready(regs);
+       if (ret) {
+               log_debug("  codec not ready\n");
+               return ret;
+       }
+
+       writel((addr << 28) | 0x000f0000, &regs->cmd);

nits: could use some macros here for 0xf0000?

Quoted 288 lines
drivers/sound/hda_codec.c new file +288 -0
+       ret = hda_wait_for_valid(regs);
+       if (ret) {
+               log_debug("  codec not valid\n");
+               return ret;
+       }
+
+       id = readl(&regs->resp);
+       log_debug("codec vid/did: %08x\n", id);
+       ret = find_verb_data(dev, id, &node);
+       if (ret) {
+               log_debug("No verb (err=%d)\n", ret);
+               return ret;
+       }
+       ret = send_verbs(node, "verbs", regs);
+       if (ret) {
+               log_debug("failed to send verbs (err=%d)\n", ret);
+               return ret;
+       }
+       log_debug("verb loaded\n");
+
+       return 0;
+}
+
+int hda_codecs_init(struct udevice *dev, struct hda_regs *regs, u32 codec_mask)
+{
+       int ret;
+       int i;
+
+       for (i = 3; i >= 0; i--) {
+               if (codec_mask & (1 << i)) {
+                       ret = codec_init(dev, regs, i);
+                       if (ret)
+                               return ret;
+               }
+       }
+
+       ret = send_verbs(dev_ofnode(dev), "beep-verbs", regs);
+       if (ret) {
+               log_debug("failed to send beep verbs (err=%d)\n", ret);
+               return ret;
+       }
+       log_debug("beep verbs loaded\n");
+
+       return 0;
+}
+
+/**
+ * exec_verb() - Write a verb to the codec
+ *
+ * @regs: HDA registers
+ * @val: Command to write
+ * @response: Set to response from codec
+ * @return 0 if OK, -ve on error
+ */
+static int exec_verb(struct hda_regs *regs, uint val, uint *response)
+{
+       int ret;
+
+       ret = hda_wait_for_ready(regs);
+       if (ret)
+               return ret;
+
+       writel(val, &regs->cmd);
+
+       return wait_for_response(regs, response);
+}
+
+/**
+ * get_subnode_info() - Get subnode information
+ *
+ * @regs: HDA registers
+ * @nid: Parent node ID to check
+ * @num_sub_nodesp: Returns number of subnodes
+ * @start_sub_node_nidp: Returns start subnode number
+ * @return 0 if OK, -ve on error
+ */
+static int get_subnode_info(struct hda_regs *regs, uint nid,
+                           uint *num_sub_nodesp, uint *start_sub_node_nidp)
+{
+       uint response;
+       int ret;
+
+       ret = exec_verb(regs, hda_verb(nid, HDA_VERB_GET_PARAMS,
+                                      GET_PARAMS_NODE_COUNT),
+                       &response);
+       if (ret < 0) {
+               printf("Audio: Error reading sub-node info %d\n", nid);
+               return ret;
+       }
+
+       *num_sub_nodesp = (response & NUM_SUB_NODES_M) >> NUM_SUB_NODES_S;
+       *start_sub_node_nidp = (response & FIRST_SUB_NODE_M) >>
+                        FIRST_SUB_NODE_S;
+
+       return 0;
+}
+
+/**
+ * find_beep_node_in_group() - Finds the beeping node
+ *
+ * Searches the audio group for a node that supports beeping
+ *
+ * @regs: HDA registers
+ * @group_nid: Group node ID to check
+ * @return 0 if OK, -ve on error
+ */
+static uint find_beep_node_in_group(struct hda_regs *regs, uint group_nid)
+{
+       uint node_count = 0;
+       uint current_nid = 0;
+       uint response;
+       uint end_nid;
+       int ret;
+
+       ret = get_subnode_info(regs, group_nid, &node_count, &current_nid);
+       if (ret < 0)
+               return 0;
+
+       end_nid = current_nid + node_count;
+       while (current_nid < end_nid) {
+               ret = exec_verb(regs,
+                               hda_verb(current_nid, HDA_VERB_GET_PARAMS,
+                                        GET_PARAMS_AUDIO_WIDGET_CAPS),
+                               &response);
+               if (ret < 0) {
+                       printf("Audio: Error reading widget caps\n");
+                       return 0;
+               }
+
+               if ((response & AUDIO_WIDGET_TYPE_M) >> AUDIO_WIDGET_TYPE_S ==
+                   AUDIO_WIDGET_TYPE_BEEP)
+                       return current_nid;
+
+               current_nid++;
+       }
+
+       return 0; /* no beep node found */
+}
+
+/**
+ * audio_group_has_beep_node() - Check if group has a beep node
+ *
+ * Checks if the given audio group contains a beep generator
+ * @regs: HDA registers
+ * @nid: Node ID to check
+ * @return 0 if OK, -ve on error
+ */
+static int audio_group_has_beep_node(struct hda_regs *regs, uint nid)
+{
+       uint response;
+       int ret;
+
+       ret = exec_verb(regs, hda_verb(nid, HDA_VERB_GET_PARAMS,
+                                      GET_PARAMS_AUDIO_GROUP_CAPS),
+                       &response);
+       if (ret < 0) {
+               printf("Audio: Error reading audio group caps %d\n", nid);
+               return 0;
+       }
+
+       return !!(response & AUDIO_GROUP_CAPS_BEEP_GEN);
+}
+
+/**
+ * get_hda_beep_nid() - Finds the node ID of the beep node
+ *
+ * Finds the nid of the beep node if it exists. Starts at the root node, for
+ * each sub-node checks if the group contains a beep node.  If the group
+ * contains a beep node, polls each node in the group until it is found.
+ *
+ * If the device has a intel,beep-nid property, the value of that is used
+ * instead.
+ *
+ * @dev: Sound device
+ * @return Node ID >0 if found, -ve error code otherwise
+ */
+static int get_hda_beep_nid(struct udevice *dev)
+{
+       struct hda_codec_priv *priv = dev_get_priv(dev);
+       uint current_nid = 0;
+       uint node_count = 0;
+       uint end_nid;
+       int ret;
+
+       /* If the field exists, use the beep nid set in the fdt */
+       ret = dev_read_u32(dev, "intel,beep-nid", &current_nid);
+       if (!ret)
+               return current_nid;
+
+       ret = get_subnode_info(priv->regs, HDA_ROOT_NODE, &node_count,
+                              &current_nid);
+       if (ret < 0)
+               return ret;
+
+       end_nid = current_nid + node_count;
+       while (current_nid < end_nid) {
+               if (audio_group_has_beep_node(priv->regs, current_nid))
+                       return find_beep_node_in_group(priv->regs,
+                                                      current_nid);
+               current_nid++;
+       }
+        /* no beep node found */
+
+       return -ENOENT;
+}
+
+/**
+ * set_beep_divisor() - Sets the beep divisor to set the pitch
+ *
+ * @priv: Device's private data
+ * @divider: Divider value (0 to disable the beep)
+ * @return 0 if OK, -ve on error
+ */
+static int set_beep_divisor(struct hda_codec_priv *priv, uint divider)
+{
+       return exec_verb(priv->regs,
+                        hda_verb(priv->beep_nid, HDA_VERB_SET_BEEP, divider),
+                        NULL);
+}
+
+int hda_codec_init(struct udevice *dev)
+{
+       struct hda_codec_priv *priv = dev_get_priv(dev);
+       ulong base_addr;
+
+       base_addr = dm_pci_read_bar32(dev, 0);
+       log_debug("base = %08lx\n", base_addr);
+       if (!base_addr)
+               return -EINVAL;
+
+       priv->regs = (struct hda_regs *)base_addr;
+
+       return 0;
+}
+
+int hda_codec_finish_init(struct udevice *dev)
+{
+       struct hda_codec_priv *priv = dev_get_priv(dev);
+       int ret;
+
+       ret = get_hda_beep_nid(dev);
+       if (ret <= 0) {
+               log_warning("Could not find beep NID (err=%d)\n", ret);
+               return ret ? ret : -ENOENT;
+       }
+       priv->beep_nid = ret;
+
+       return 0;
+}
+
+int hda_codec_start_beep(struct udevice *dev, int frequency_hz)
+{
+       struct hda_codec_priv *priv = dev_get_priv(dev);
+       uint divider_val;
+
+       if (!priv->beep_nid) {
+               log_err("Failed to find a beep-capable node\n");
+               return -ENOENT;
+       }
+
+       if (!frequency_hz)
+               divider_val = 0;        /* off */
+       else if (frequency_hz > BEEP_FREQ_BASE)
+               divider_val = 1;
+       else if (frequency_hz < BEEP_FREQ_BASE / 0xff)
+               divider_val = 0xff;
+       else
+               divider_val = 0xff & (BEEP_FREQ_BASE / frequency_hz);
+
+       return set_beep_divisor(priv, divider_val);
+}
+
+int hda_codec_stop_beep(struct udevice *dev)
+{
+       struct hda_codec_priv *priv = dev_get_priv(dev);
+
+       return set_beep_divisor(priv, 0);
+}
+
+static const struct sound_ops hda_codec_ops = {
+       .setup          = hda_codec_finish_init,
+       .start_beep     = hda_codec_start_beep,
+       .stop_beep      = hda_codec_stop_beep,
+};
+
+U_BOOT_DRIVER(hda_codec) = {
+       .name           = "hda_codec",
+       .id             = UCLASS_SOUND,

drivers/sound/hda_codec.c line 542

Quoted 10 lines
drivers/sound/hda_codec.c new file +10 -0
+       .ops            = &hda_codec_ops,
+       .priv_auto_alloc_size   = sizeof(struct hda_codec_priv),
+       .probe          = hda_codec_init,
+};
+
+static struct pci_device_id hda_supported[] = {
+       { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COUGARPOINT_HDA},
+       { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PANTHERPOINT_HDA},
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL,
+               PCI_DEVICE_ID_INTEL_WILDCATPOINT_HDA) },

If this driver can be applied to generic Intel HDA devices, I wonder if there is a generic class defined by the PCI spec we can put here in the table?

Quoted 20 lines
drivers/sound/hda_codec.c new file +3 -0
+};
+
+U_BOOT_PCI_DEVICE(hda_codec, hda_supported);
include/dt-bindings/sound/azalia.h new file +11 -0
new file mode 100644
index 0000000000..e35ffa920d
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Intel HDA audio codec config. This is a mechanicm to configure codecs when
+ * using Intel HDA audio.
+ *
+ * Copyright 2018 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#ifndef __AZALIA_H
+#define __AZALIA_H

include/dt-bindings/sound/azalia.h line 21

Quoted 10 lines
include/dt-bindings/sound/azalia.h new file +10 -0
+
+#define AZALIA_PIN_CFG(codec, pin, val)                        \
+       (((codec) << 28) | ((pin) << 20) | (0x71c << 8) \
+               | ((val) & 0xff))                       \
+       (((codec) << 28) | ((pin) << 20) | (0x71d << 8) \
+               | (((val) >> 8) & 0xff))                \
+       (((codec) << 28) | ((pin) << 20) | (0x71e << 8) \
+               | (((val) >> 16) & 0xff))               \
+       (((codec) << 28) | ((pin) << 20) | (0x71f << 8) \
+               | (((val) >> 24) & 0xff))

nits: can we use some macros for 0x71c/d/e/f?

include/dt-bindings/sound/azalia.h line 28

Quoted 7 lines
include/dt-bindings/sound/azalia.h new file +7 -0
+
+#define AZALIA_SUBVENDOR(codec, val)               \
+       (((codec) << 28) | (0x01720 << 8) | ((val) & 0xff))     \
+       (((codec) << 28) | (0x01721 << 8) | (((val) >> 8) & 0xff)) \
+       (((codec) << 28) | (0x01722 << 8) | (((val) >> 16) & 0xff)) \
+       (((codec) << 28) | (0x01723 << 8) | (((val) >> 24) & 0xff))
+

nits: can we use some macros for 0x01720/1/2/3?

Quoted 101 lines
include/dt-bindings/sound/azalia.h new file +1 -0
+#endif /* __AZALIA_H */
include/hda_codec.h new file +94 -0
new file mode 100644
index 0000000000..56de571f0f
@@ -0,0 +1,103 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Support for Intel High-Definition Audio codec
+ *
+ * Copyright 2018 Google LLC
+ *
+ * Taken from coreboot file of the same name
+ */
+
+#ifndef __HDA_CODEC_H_
+#define __HDA_CODEC_H_
+
+struct hda_regs;
+
+/**
+ * struct hda_codec_priv - Private data required by the HDA codec
+ *
+ * @regs: HDA registers
+ * @beep_nid: Node ID of beep node (>0)
+ */
+struct hda_codec_priv {
+       struct hda_regs *regs;
+       uint beep_nid;
+};
+
+/**
+ *  hda_wait_for_ready() - Wait for the codec to indicate it is ready
+ *
+ * @regs: HDA registers
+ * @return 0 if OK -ETIMEDOUT if codec did not respond in time
+ */
+int hda_wait_for_ready(struct hda_regs *regs);
+
+/**
+ *  hda_wait_for_valid() - Wait for the codec to accept the last command
+ *
+ * @regs: HDA registers
+ * @return 0 if OK -ETIMEDOUT if codec did not respond in time
+ */
+int hda_wait_for_valid(struct hda_regs *regs);
+
+/**
+ * hda_codec_detect() - Detect which codecs are present
+ *
+ * @regs: HDA registers
+ * @return bit mask of active codecs (0 if none)
+ * @return 0 if OK, -ve on error
+ */
+int hda_codec_detect(struct hda_regs *regs);
+
+/**
+ * hda_codecs_init() - Init all codecs
+ *
+ * @dev: Sound device
+ * @regs: HDA registers
+ * @codec_mask: Mask of codecs to init (bits 3:0)
+ * @return 0 if OK, -ve on error
+ */
+int hda_codecs_init(struct udevice *dev, struct hda_regs *regs, u32 codec_mask);
+
+/**
+ * hda_codec_start_beep() - Start beeping
+ *
+ * This tells the sound hardware to start a beep. It will continue until stopped
+ * by sound_stop_beep().
+ *
+ * @dev: Sound device
+ * @frequency_hz: Beep frequency in hertz
+ * @return if OK, -ve on error
+ */
+int hda_codec_start_beep(struct udevice *dev, int frequency_hz);
+
+/**
+ * hda_codec_stop_beep() - Stop beeping
+ *
+ * This tells the sound hardware to stop a previously started beep.
+ *
+ * @dev: Sound device
+ * @return if OK, -ve on error
+ */
+int hda_codec_stop_beep(struct udevice *dev);
+
+/**
+ * hda_codec_init() - Set up the HDA codec base address
+ *
+ * This should be called at the start of the probe() method.
+ *
+ * @dev: Sound device
+ * @return 0 if OK, -ve on error
+ */
+int hda_codec_init(struct udevice *dev);
+
+/**
+ * hda_codec_finish_init() - Finish setting up the HDA codec base address

include/hda_codec.h

Quoted 10 lines
include/hda_codec.h new file +9 -1
+ *
+ * This should be called at the end of the probe() method.
+ *
+ * @dev: Sound device
+ * @return 0 if OK, -ve on error
+ */
+int hda_codec_finish_init(struct udevice *dev);
+
+#endif /* __HDA_CODEC_H_ */
--

Regards,
Bin

#46 lore raw

PATCH 22/33 sandbox: sound: Silence sound for testing

In reply to Simon Glass

When testing the sound system we don't need the hear the beeps. The testing works by checking the data that would be emitted. Add a device-tree property to silence the sound, and enable it for testing.

---

 arch/sandbox/dts/test.dts |  1 +
 drivers/sound/sandbox.c   | 23 +++++++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)
arch/sandbox/dts/test.dts +1 -0
index 9144430cc0..5748cd60b1 100644
@@ -389,6 +389,7 @@
 	i2s: i2s {
 		compatible = "sandbox,i2s";
 		#sound-dai-cells = <1>;
+		sandbox,silent;	/* Don't emit sounds while testing */
 	};
 
 	misc-test {
drivers/sound/sandbox.c +21 -2
index 600523160f..4b57ef6759 100644
@@ -3,6 +3,8 @@
  * Copyright (c) 2013 Google, Inc
  */
 
+#define LOG_CATEGORY UCLASS_SOUND
+
 #include <common.h>
 #include <audio_codec.h>
 #include <dm.h>
@@ -20,6 +22,7 @@ struct sandbox_codec_priv {
 
 struct sandbox_i2s_priv {
 	int sum;	/* Use to sum the provided audio data */
+	bool silent;	/* Sound is silent, don't use SDL */
 };
 
 struct sandbox_sound_priv {
@@ -101,12 +104,21 @@ static int sandbox_i2s_tx_data(struct udevice *dev, void *data,
 	for (i = 0; i < data_size; i++)
 		priv->sum += ((uint8_t *)data)[i];
 
-	return sandbox_sdl_sound_play(data, data_size);
+	if (!priv->silent) {
+		int ret;
+
+		ret = sandbox_sdl_sound_play(data, data_size);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
 }
 
 static int sandbox_i2s_probe(struct udevice *dev)
 {
 	struct i2s_uc_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct sandbox_i2s_priv *priv = dev_get_priv(dev);
 
 	/* Use hard-coded values here */
 	uc_priv->rfs = 256;
@@ -117,8 +129,15 @@ static int sandbox_i2s_probe(struct udevice *dev)
 	uc_priv->channels = 2;
 	uc_priv->id = 1;
 
+	priv->silent = dev_read_bool(dev, "sandbox,silent");
+
 	/* Ignore any error here - we'll just have no sound */
-	sandbox_sdl_sound_init(uc_priv->samplingrate, uc_priv->channels);
+	if (priv->silent) {
+		log_warning("Sound is silenced\n");
+	} else if (sandbox_sdl_sound_init(uc_priv->samplingrate,
+					  uc_priv->channels)) {
+		priv->silent = true;
+	}
 
 	return 0;
 }
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#47 lore raw

PATCH 22/33 sandbox: sound: Silence sound for testing

Hi Simon,

Quoted 71 lines · Simon Glass

When testing the sound system we don't need the hear the beeps. The testing works by checking the data that would be emitted. Add a device-tree property to silence the sound, and enable it for testing.

---

 arch/sandbox/dts/test.dts |  1 +
 drivers/sound/sandbox.c   | 23 +++++++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)
arch/sandbox/dts/test.dts +1 -0
index 9144430cc0..5748cd60b1 100644
@@ -389,6 +389,7 @@
        i2s: i2s {
                compatible = "sandbox,i2s";
                #sound-dai-cells = <1>;
+               sandbox,silent; /* Don't emit sounds while testing */
        };
 
        misc-test {
drivers/sound/sandbox.c +13 -1
index 600523160f..4b57ef6759 100644
@@ -3,6 +3,8 @@
  * Copyright (c) 2013 Google, Inc
  */
 
+#define LOG_CATEGORY UCLASS_SOUND
+
 #include <common.h>
 #include <audio_codec.h>
 #include <dm.h>
@@ -20,6 +22,7 @@ struct sandbox_codec_priv {
 
 struct sandbox_i2s_priv {
        int sum;        /* Use to sum the provided audio data */
+       bool silent;    /* Sound is silent, don't use SDL */
 };
 
 struct sandbox_sound_priv {
@@ -101,12 +104,21 @@ static int sandbox_i2s_tx_data(struct udevice *dev, void *data,
        for (i = 0; i < data_size; i++)
                priv->sum += ((uint8_t *)data)[i];
 
-       return sandbox_sdl_sound_play(data, data_size);
+       if (!priv->silent) {
+               int ret;
+
+               ret = sandbox_sdl_sound_play(data, data_size);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
 }
 
 static int sandbox_i2s_probe(struct udevice *dev)
 {
        struct i2s_uc_priv *uc_priv = dev_get_uclass_priv(dev);
+       struct sandbox_i2s_priv *priv = dev_get_priv(dev);
 
        /* Use hard-coded values here */
        uc_priv->rfs = 256;
@@ -117,8 +129,15 @@ static int sandbox_i2s_probe(struct udevice *dev)
        uc_priv->channels = 2;
        uc_priv->id = 1;

drivers/sound/sandbox.c static int sandbox_i2s_probe(struct udevice *dev) · line 139

Quoted 10 lines
drivers/sound/sandbox.c +7 -1
 
+       priv->silent = dev_read_bool(dev, "sandbox,silent");
+
        /* Ignore any error here - we'll just have no sound */
-       sandbox_sdl_sound_init(uc_priv->samplingrate, uc_priv->channels);
+       if (priv->silent) {
+               log_warning("Sound is silenced\n");
+       } else if (sandbox_sdl_sound_init(uc_priv->samplingrate,
+                                         uc_priv->channels)) {
+               priv->silent = true;

should be false?

drivers/sound/sandbox.c static int sandbox_i2s_probe(struct udevice *dev) · line 143

Quoted 4 lines
drivers/sound/sandbox.c +1 -0
+       }
 
        return 0;
 }

Regards,
Bin

#48 lore raw

PATCH 22/33 sandbox: sound: Silence sound for testing

Hi Bin,

Quoted 76 lines · Bin Meng

Hi Simon,

Quoted 72 lines · Simon Glass

When testing the sound system we don't need the hear the beeps. The testing works by checking the data that would be emitted. Add a device-tree property to silence the sound, and enable it for testing.

---

 arch/sandbox/dts/test.dts |  1 +
 drivers/sound/sandbox.c   | 23 +++++++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)
arch/sandbox/dts/test.dts +1 -0
index 9144430cc0..5748cd60b1 100644
@@ -389,6 +389,7 @@
        i2s: i2s {
                compatible = "sandbox,i2s";
                #sound-dai-cells = <1>;
+               sandbox,silent; /* Don't emit sounds while testing */
        };
 
        misc-test {
drivers/sound/sandbox.c +13 -1
index 600523160f..4b57ef6759 100644
@@ -3,6 +3,8 @@
  * Copyright (c) 2013 Google, Inc
  */
 
+#define LOG_CATEGORY UCLASS_SOUND
+
 #include <common.h>
 #include <audio_codec.h>
 #include <dm.h>
@@ -20,6 +22,7 @@ struct sandbox_codec_priv {
 
 struct sandbox_i2s_priv {
        int sum;        /* Use to sum the provided audio data */
+       bool silent;    /* Sound is silent, don't use SDL */
 };
 
 struct sandbox_sound_priv {
@@ -101,12 +104,21 @@ static int sandbox_i2s_tx_data(struct udevice *dev, void *data,
        for (i = 0; i < data_size; i++)
                priv->sum += ((uint8_t *)data)[i];
 
-       return sandbox_sdl_sound_play(data, data_size);
+       if (!priv->silent) {
+               int ret;
+
+               ret = sandbox_sdl_sound_play(data, data_size);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
 }
 
 static int sandbox_i2s_probe(struct udevice *dev)
 {
        struct i2s_uc_priv *uc_priv = dev_get_uclass_priv(dev);
+       struct sandbox_i2s_priv *priv = dev_get_priv(dev);
 
        /* Use hard-coded values here */
        uc_priv->rfs = 256;
@@ -117,8 +129,15 @@ static int sandbox_i2s_probe(struct udevice *dev)
        uc_priv->channels = 2;
        uc_priv->id = 1;
 
Quoted 11 lines

drivers/sound/sandbox.c static int sandbox_i2s_probe(struct udevice *dev) · line 139

Quoted 9 lines
drivers/sound/sandbox.c +7 -1
+       priv->silent = dev_read_bool(dev, "sandbox,silent");
+
        /* Ignore any error here - we'll just have no sound */
-       sandbox_sdl_sound_init(uc_priv->samplingrate, uc_priv->channels);
+       if (priv->silent) {
+               log_warning("Sound is silenced\n");
+       } else if (sandbox_sdl_sound_init(uc_priv->samplingrate,
+                                         uc_priv->channels)) {
+               priv->silent = true;

should be false?

I don't think so. If an init error occurs then we want to silence the sound. I'll move the comment.

Regards,
Simon

#49 lore raw

PATCH 23/33 sound: x86: link: Add sound support

In reply to Simon Glass

Add sound support for link, using the HDA codec implementation.

---

 arch/x86/cpu/ivybridge/Kconfig                |   1 +
 arch/x86/cpu/ivybridge/northbridge.c          |  27 ++++
 arch/x86/dts/chromebook_link.dts              |  91 ++++++++++++
 .../include/asm/arch-ivybridge/sandybridge.h  |   3 +
 configs/chromebook_link_defconfig             |   2 +
 drivers/sound/Kconfig                         |  10 ++
 drivers/sound/Makefile                        |   1 +
 drivers/sound/ivybridge_sound.c               | 137 ++++++++++++++++++
 8 files changed, 272 insertions(+)
 create mode 100644 drivers/sound/ivybridge_sound.c
arch/x86/cpu/ivybridge/Kconfig +1 -0
index 5f0e60837c..2f42393786 100644
@@ -21,6 +21,7 @@ config NORTHBRIDGE_INTEL_IVYBRIDGE
 	imply USB_EHCI_HCD
 	imply USB_XHCI_HCD
 	imply VIDEO_VESA
+	imply SOUND_IVYBRIDGE
 
 if NORTHBRIDGE_INTEL_IVYBRIDGE
 
arch/x86/cpu/ivybridge/northbridge.c +27 -0
index 39bab7bdf3..0ac0a34acc 100644
@@ -177,6 +177,30 @@ static void sandybridge_setup_northbridge_bars(struct udevice *dev)
 	dm_pci_write_config8(dev, PAM6, 0x33);
 }
 
+static void sandybridge_init_iommu(struct udevice *dev)
+{
+	u32 capid0_a;
+
+	dm_pci_read_config32(dev, 0xe4, &capid0_a);
+	if (capid0_a & (1 << 23)) {
+		log_debug("capid0_a not needed\n");
+		return;
+	}
+
+	/* setup BARs */
+	writel(IOMMU_BASE1 >> 32, MCHBAR_REG(0x5404));
+	writel(IOMMU_BASE1 | 1, MCHBAR_REG(0x5400));
+	writel(IOMMU_BASE2 >> 32, MCHBAR_REG(0x5414));
+	writel(IOMMU_BASE2 | 1, MCHBAR_REG(0x5410));
+
+	/* lock policies */
+	writel(0x80000000, IOMMU_BASE1 + 0xff0);
+
+	/* Enable azalia sound */
+	writel(0x20000000, IOMMU_BASE2 + 0xff0);
+	writel(0xa0000000, IOMMU_BASE2 + 0xff0);
+}
+
 static int bd82x6x_northbridge_early_init(struct udevice *dev)
 {
 	const int chipset_type = SANDYBRIDGE_MOBILE;
@@ -197,6 +221,9 @@ static int bd82x6x_northbridge_early_init(struct udevice *dev)
 
 	sandybridge_setup_northbridge_bars(dev);
 
+	/* Setup IOMMU BARs */
+	sandybridge_init_iommu(dev);
+
 	/* Device Enable */
 	dm_pci_write_config32(dev, DEVEN, DEVEN_HOST | DEVEN_IGD);
 
arch/x86/dts/chromebook_link.dts +91 -0

106 lines not on this page · raw message

arch/x86/include/asm/arch-ivybridge/sandybridge.h +3 -0
index a96c951c85..a3a507f2b3 100644
@@ -43,6 +43,9 @@
 /* 4 KB per PCIe device */
 #define DEFAULT_PCIEXBAR	CONFIG_PCIE_ECAM_BASE
 
+#define IOMMU_BASE1		0xfed90000ULL
+#define IOMMU_BASE2		0xfed91000ULL
+
 /* Device 0:0.0 PCI configuration space (Host Bridge) */
 #define EPBAR		0x40
 #define MCHBAR		0x48
configs/chromebook_link_defconfig +2 -0
index c402568c17..6058dfaf0f 100644
@@ -33,6 +33,7 @@ CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_SOUND=y
 CONFIG_CMD_BOOTSTAGE=y
 CONFIG_CMD_TPM=y
 CONFIG_CMD_TPM_TEST=y
@@ -53,6 +54,7 @@ CONFIG_SYS_I2C_INTEL=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_LPC=y
 CONFIG_SYS_NS16550=y
+CONFIG_SOUND=y
 CONFIG_SPI=y
 CONFIG_TPM_TIS_LPC=y
 CONFIG_USB_STORAGE=y
drivers/sound/Kconfig +10 -0
index a03d3057e1..a414e8e712 100644
@@ -40,6 +40,16 @@ config SOUND_INTEL_HDA
 	  Azalia which was the development code-name. It requires setup
 	  information in the device tree (see intel-hda.txt).
 
+config SOUND_IVYBRIDGE
+	bool "Intel Ivybridge sound support"
+	depends on SOUND
+	select SOUND_INTEL_HDA
+	help
+	  Enable sound output on supported Intel ivybridge-based boards. This
+	  driver uses Intel's High-definition Audio (HDA) architecture,
+	  sometimes called Azalia. The audio codec is detected using a
+	  semi-automatic mechanism.
+
 config SOUND_MAX98088
 	bool "Support Maxim max98088 audio codec"
 	depends on I2S
drivers/sound/Makefile +1 -0
index 705a09464d..23893947be 100644
@@ -15,3 +15,4 @@ obj-$(CONFIG_SOUND_MAX98088)	+= max98088.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98090)	+= max98090.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o
 obj-$(CONFIG_SOUND_INTEL_HDA)	+= hda_codec.o
+obj-$(CONFIG_SOUND_IVYBRIDGE)	+= ivybridge_sound.o
drivers/sound/ivybridge_sound.c new file +137 -0

137 lines not on this page · raw message

Signature · 1 line
2.20.1.321.g9e740568ce-goog
#50 lore raw

PATCH 23/33 sound: x86: link: Add sound support

Hi Simon,

Quoted 50 lines · Simon Glass

Add sound support for link, using the HDA codec implementation.

---

 arch/x86/cpu/ivybridge/Kconfig                |   1 +
 arch/x86/cpu/ivybridge/northbridge.c          |  27 ++++
 arch/x86/dts/chromebook_link.dts              |  91 ++++++++++++
 .../include/asm/arch-ivybridge/sandybridge.h  |   3 +
 configs/chromebook_link_defconfig             |   2 +
 drivers/sound/Kconfig                         |  10 ++
 drivers/sound/Makefile                        |   1 +
 drivers/sound/ivybridge_sound.c               | 137 ++++++++++++++++++
 8 files changed, 272 insertions(+)
 create mode 100644 drivers/sound/ivybridge_sound.c
arch/x86/cpu/ivybridge/Kconfig +1 -0
index 5f0e60837c..2f42393786 100644
@@ -21,6 +21,7 @@ config NORTHBRIDGE_INTEL_IVYBRIDGE
        imply USB_EHCI_HCD
        imply USB_XHCI_HCD
        imply VIDEO_VESA
+       imply SOUND_IVYBRIDGE
 
 if NORTHBRIDGE_INTEL_IVYBRIDGE
 
arch/x86/cpu/ivybridge/northbridge.c +13 -0
index 39bab7bdf3..0ac0a34acc 100644
@@ -177,6 +177,30 @@ static void sandybridge_setup_northbridge_bars(struct udevice *dev)
        dm_pci_write_config8(dev, PAM6, 0x33);
 }
 
+static void sandybridge_init_iommu(struct udevice *dev)
+{
+       u32 capid0_a;
+
+       dm_pci_read_config32(dev, 0xe4, &capid0_a);
+       if (capid0_a & (1 << 23)) {
+               log_debug("capid0_a not needed\n");
+               return;
+       }
+
+       /* setup BARs */
+       writel(IOMMU_BASE1 >> 32, MCHBAR_REG(0x5404));
+       writel(IOMMU_BASE1 | 1, MCHBAR_REG(0x5400));

arch/x86/cpu/ivybridge/northbridge.c static void sandybridge_setup_northbridge_bars(struct udevice *dev) · line 202

Quoted 10 lines
arch/x86/cpu/ivybridge/northbridge.c +10 -0
+       writel(IOMMU_BASE2 >> 32, MCHBAR_REG(0x5414));
+       writel(IOMMU_BASE2 | 1, MCHBAR_REG(0x5410));
+
+       /* lock policies */
+       writel(0x80000000, IOMMU_BASE1 + 0xff0);
+
+       /* Enable azalia sound */
+       writel(0x20000000, IOMMU_BASE2 + 0xff0);
+       writel(0xa0000000, IOMMU_BASE2 + 0xff0);
+}

The function name looks it has something to do with IOMMU, but why does enabling sound support need IOMMU which is mainly for hypervisor stuff? Better providing some comments here, and if possible use macros instead of hard-coded numbers.

Quoted 32 lines
arch/x86/cpu/ivybridge/northbridge.c +4 -0
+
 static int bd82x6x_northbridge_early_init(struct udevice *dev)
 {
        const int chipset_type = SANDYBRIDGE_MOBILE;
@@ -197,6 +221,9 @@ static int bd82x6x_northbridge_early_init(struct udevice *dev)
 
        sandybridge_setup_northbridge_bars(dev);
 
+       /* Setup IOMMU BARs */
+       sandybridge_init_iommu(dev);
+
        /* Device Enable */
        dm_pci_write_config32(dev, DEVEN, DEVEN_HOST | DEVEN_IGD);
 
arch/x86/dts/chromebook_link.dts +3 -0
index f9f0979730..7e0a615a60 100644
@@ -1,6 +1,8 @@
 /dts-v1/;
 
 #include <dt-bindings/gpio/x86-gpio.h>
+#include <dt-bindings/sound/azalia.h>
+#include <pci_ids.h>
 
 /include/ "skeleton.dtsi"
 /include/ "keyboard.dtsi"
@@ -372,6 +374,30 @@
                        compatible = "ehci-pci";
                };
 
+               hda at 1b,0 {

arch/x86/dts/chromebook_link.dts line 387

Quoted 10 lines
arch/x86/dts/chromebook_link.dts +10 -0
+                       reg = <0x0000d800 0 0 0 0>;
+                       compatible = "intel,bd82x6x-hda";
+                       beep-verbs = <
+                               0x00170500      /* power up codec */
+                               0x00270500      /* power up DAC */
+                               0x00b70500      /* power up speaker */
+                               0x00b70740      /* enable speaker out */
+                               0x00b78d00      /* enable EAPD pin */
+                               0x00b70c02      /* set EAPD pin */
+                               0x0143b013>;    /* beep volume */

Are these verbs from the chipset datasheet?

Quoted 25 lines
arch/x86/dts/chromebook_link.dts +18 -0
+
+                       codecs {
+                               creative_codec: creative-ca0132 {
+                                       vendor-id = <PCI_VENDOR_ID_CREATIVE>;
+                                       device-id = <PCI_DEVICE_ID_CREATIVE_CA01322>;
+                               };
+                               intel_hdmi: hdmi {
+                                       vendor-id = <PCI_VENDOR_ID_INTEL>;
+                                       device-id = <PCI_DEVICE_ID_INTEL_COUGARPOINT_HDMI>;
+                               };
+                       };
+               };
+
                usb_0: usb at 1d,0 {
                        reg = <0x0000e800 0 0 0 0>;
                        compatible = "ehci-pci";
@@ -492,3 +518,68 @@
        };
 
 };
+
+&creative_codec {
+       verbs =  <
+               /* Malcolm Setup */
+               0x01570d09 0x01570c23 0x01570a01 0x01570df0

arch/x86/dts/chromebook_link.dts line 535

Quoted 10 lines
arch/x86/dts/chromebook_link.dts +10 -0
+               0x01570efe 0x01570775 0x015707d3 0x01570709
+               0x01570753 0x015707d4 0x015707ef 0x01570775
+               0x015707d3 0x01570709 0x01570702 0x01570737
+               0x01570778 0x01553cce 0x015575c9 0x01553dce
+               0x0155b7c9 0x01570de8 0x01570efe 0x01570702
+               0x01570768 0x01570762 0x01553ace 0x015546c9
+               0x01553bce 0x0155e8c9 0x01570d49 0x01570c88
+               0x01570d20 0x01570e19 0x01570700 0x01571a05
+               0x01571b29 0x01571a04 0x01571b29 0x01570a01
+

And here? Is this something one can easily get from the chipset datasheet? If not, better adding some comments to point out the sources of these magic numbers.

Quoted 89 lines
arch/x86/dts/chromebook_link.dts +50 -0
+               /* Pin Widget Verb Table */
+
+               /* NID 0x01, HDA Codec Subsystem ID Verb Table: 0x144DC0C2 */
+               AZALIA_SUBVENDOR(0x0, 0x144dc0c2)
+
+               /*
+                * Pin Complex (NID 0x0B)  Port-G Analog Unknown
+                * Speaker at Int N/A
+                */
+               AZALIA_PIN_CFG(0x0, 0x0b, 0x901700f0)
+
+               /* Pin Complex (NID 0x0C)  N/C */
+               AZALIA_PIN_CFG(0x0, 0x0c, 0x70f000f0)
+
+               /* Pin Complex (NID 0x0D)  N/C */
+               AZALIA_PIN_CFG(0x0, 0x0d, 0x70f000f0)
+
+               /* Pin Complex (NID 0x0E)  N/C */
+               AZALIA_PIN_CFG(0x0, 0x0e, 0x70f000f0)
+
+               /* Pin Complex (NID 0x0F)  N/C */
+               AZALIA_PIN_CFG(0x0, 0x0f, 0x70f000f0)
+
+               /* Pin Complex (NID 0x10) Port-D 1/8 Black HP Out at Ext Left */
+               AZALIA_PIN_CFG(0x0, 0x10, 0x032110f0)
+
+               /* Pin Complex (NID 0x11) Port-B Click Mic */
+               AZALIA_PIN_CFG(0x0, 0x11, 0x90a700f0)
+
+               /* Pin Complex (NID 0x12) Port-C Combo Jack Mic or D-Mic */
+               AZALIA_PIN_CFG(0x0, 0x12, 0x03a110f0)
+
+               /* Pin Complex (NID 0x13) What you hear */
+               AZALIA_PIN_CFG(0x0, 0x13, 0x90d600f0)>;
+};
+
+&intel_hdmi {
+       verbs = <
+               /* NID 0x01, HDA Codec Subsystem ID Verb Table: 0x80860101 */
+               AZALIA_SUBVENDOR(0x3, 0x80860101)
+
+               /* Pin Complex (NID 0x05) Digital Out at Int HDMI */
+               AZALIA_PIN_CFG(0x3, 0x05, 0x18560010)
+
+               /* Pin Complex (NID 0x06) Digital Out at Int HDMI */
+               AZALIA_PIN_CFG(0x3, 0x06, 0x18560020)
+
+               /* Pin Complex (NID 0x07) Digital Out at Int HDMI */
+               AZALIA_PIN_CFG(0x3, 0x07, 0x18560030)>;
+};
arch/x86/include/asm/arch-ivybridge/sandybridge.h +3 -0
index a96c951c85..a3a507f2b3 100644
@@ -43,6 +43,9 @@
 /* 4 KB per PCIe device */
 #define DEFAULT_PCIEXBAR       CONFIG_PCIE_ECAM_BASE
 
+#define IOMMU_BASE1            0xfed90000ULL
+#define IOMMU_BASE2            0xfed91000ULL
+
 /* Device 0:0.0 PCI configuration space (Host Bridge) */
 #define EPBAR          0x40
 #define MCHBAR         0x48
configs/chromebook_link_defconfig +2 -0
index c402568c17..6058dfaf0f 100644
@@ -33,6 +33,7 @@ CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_SOUND=y
 CONFIG_CMD_BOOTSTAGE=y
 CONFIG_CMD_TPM=y
 CONFIG_CMD_TPM_TEST=y
@@ -53,6 +54,7 @@ CONFIG_SYS_I2C_INTEL=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_LPC=y
 CONFIG_SYS_NS16550=y
+CONFIG_SOUND=y
 CONFIG_SPI=y
 CONFIG_TPM_TIS_LPC=y
 CONFIG_USB_STORAGE=y
drivers/sound/Kconfig +0 -0
index a03d3057e1..a414e8e712 100644

drivers/sound/Kconfig config SOUND_INTEL_HDA · line 48

Quoted 9 lines
drivers/sound/Kconfig +6 -0
@@ -40,6 +40,16 @@ config SOUND_INTEL_HDA
          Azalia which was the development code-name. It requires setup
          information in the device tree (see intel-hda.txt).
 
+config SOUND_IVYBRIDGE
+       bool "Intel Ivybridge sound support"
+       depends on SOUND
+       select SOUND_INTEL_HDA
+       help
+         Enable sound output on supported Intel ivybridge-based boards. This

nits: Ivybridge-based

Quoted 71 lines
drivers/sound/Kconfig +4 -0
+         driver uses Intel's High-definition Audio (HDA) architecture,
+         sometimes called Azalia. The audio codec is detected using a
+         semi-automatic mechanism.
+
 config SOUND_MAX98088
        bool "Support Maxim max98088 audio codec"
        depends on I2S
drivers/sound/Makefile +1 -0
index 705a09464d..23893947be 100644
@@ -15,3 +15,4 @@ obj-$(CONFIG_SOUND_MAX98088)  += max98088.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98090)   += max98090.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98095)   += max98095.o maxim_codec.o
 obj-$(CONFIG_SOUND_INTEL_HDA)  += hda_codec.o
+obj-$(CONFIG_SOUND_IVYBRIDGE)  += ivybridge_sound.o
drivers/sound/ivybridge_sound.c new file +49 -0
new file mode 100644
index 0000000000..49071b323c
@@ -0,0 +1,137 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Intel HDA audio (Azalia) for ivybridge
+ *
+ * Originally from coreboot file bd82x6x/azalia.c
+ *
+ * Copyright (C) 2008 Advanced Micro Devices, Inc.
+ * Copyright (C) 2008-2009 coresystems GmbH
+ * Copyright (C) 2011 The ChromiumOS Authors.
+ * Copyright 2018 Google LLC
+ */
+
+#define LOG_CATEGORY UCLASS_SOUND
+
+#include <common.h>
+#include <dm.h>
+#include <hda_codec.h>
+#include <pch.h>
+#include <sound.h>
+
+static int bd82x6x_azalia_probe(struct udevice *dev)
+{
+       struct pci_child_platdata *plat;
+       struct hda_codec_priv *priv;
+       struct udevice *pch;
+       u32 codec_mask;
+       int conf;
+       int ret;
+
+       /* Only init after relocation */
+       if (!(gd->flags & GD_FLG_RELOC))
+               return 0;
+
+       ret = hda_codec_init(dev);
+       if (ret) {
+               log_debug("Cannot set up HDA codec (err=%d)\n", ret);
+               return ret;
+       }
+       priv = dev_get_priv(dev);
+
+       ret = uclass_first_device_err(UCLASS_PCH, &pch);
+       log_debug("PCH %p %s\n", pch, pch->name);
+       if (ret)
+               return ret;
+
+       conf = pch_ioctl(pch, PCH_REQ_HDA_CONFIG, NULL, 0);
+       log_debug("conf = %x\n", conf);
+       if (conf >= 0) {
+               dm_pci_clrset_config32(dev, 0x120, 7 << 24 | 0xfe,

drivers/sound/ivybridge_sound.c line 59

Quoted 10 lines
drivers/sound/ivybridge_sound.c new file +10 -0
+                                      1 << 24 | // 2 << 24 for server
+                                      conf);
+
+               dm_pci_clrset_config16(dev, 0x78, 0, 1 << 1);
+       } else {
+               log_debug("V1CTL disabled\n");
+       }
+       dm_pci_clrset_config32(dev, 0x114, 0xfe, 0);
+
+       // Set VCi enable bit

nits: Use /* */

Quoted 62 lines
drivers/sound/ivybridge_sound.c new file +62 -0
+       dm_pci_clrset_config32(dev, 0x120, 0, 1U << 31);
+
+       /* Enable HDMI codec */
+       dm_pci_clrset_config32(dev, 0xc4, 0, 1 << 1);
+       dm_pci_clrset_config8(dev, 0x43, 0, 1 << 6);
+
+       /* Additional programming steps */
+       dm_pci_clrset_config32(dev, 0xc4, 0, 1 << 13);
+       dm_pci_clrset_config32(dev, 0xc4, 0, 1 << 10);
+       dm_pci_clrset_config32(dev, 0xd0, 1U << 31, 0);
+
+       /* Additional step on Panther Point */
+       plat = dev_get_parent_platdata(dev);
+       if (plat->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_HDA)
+               dm_pci_clrset_config32(dev, 0xc4, 0, 1 << 17);
+
+       dm_pci_write_config8(dev, 0x3c, 0xa); /* unused? */
+
+       /* Audio Control: Select Azalia mode */
+       dm_pci_clrset_config8(dev, 0x40, 0, 1);
+       dm_pci_clrset_config8(dev, 0x4d, 1 << 7, 0); /* Docking not supported */
+       codec_mask = hda_codec_detect(priv->regs);
+       log_debug("codec_mask = %02x\n", codec_mask);
+
+       if (codec_mask) {
+               ret = hda_codecs_init(dev, priv->regs, codec_mask);
+               if (ret) {
+                       log_err("Codec init failed (err=%d)\n", ret);
+                       return ret;
+               }
+       }
+
+       /* Enable dynamic clock gating */
+       dm_pci_clrset_config8(dev, 0x43, 7, BIT(2) | BIT(0));
+
+       ret = hda_codec_finish_init(dev);
+       if (ret) {
+               log_debug("Cannot set up HDA codec (err=%d)\n", ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int bd82x6x_azalia_setup(struct udevice *dev)
+{
+       return 0;
+}
+
+int bd82x6x_azalia_start_beep(struct udevice *dev, int frequency_hz)
+{
+       return hda_codec_start_beep(dev, frequency_hz);
+}
+
+int bd82x6x_azalia_stop_beep(struct udevice *dev)
+{
+       return hda_codec_stop_beep(dev);
+}
+
+static const struct sound_ops bd82x6x_azalia_ops = {
+       .setup          = bd82x6x_azalia_setup,
+       .start_beep     = bd82x6x_azalia_start_beep,

drivers/sound/ivybridge_sound.c line 131

Quoted 10 lines
drivers/sound/ivybridge_sound.c new file +10 -0
+       .stop_beep      = bd82x6x_azalia_stop_beep,
+};
+
+static const struct udevice_id bd82x6x_azalia_ids[] = {
+       { .compatible = "intel,bd82x6x-hda" },
+       { }
+};
+
+U_BOOT_DRIVER(bd82x6x_azalia_drv) = {
+       .name           = "bd82x6x",

The driver name is too generic. Could be "bd82x6x-hda"?

drivers/sound/ivybridge_sound.c

Quoted 7 lines
drivers/sound/ivybridge_sound.c new file +6 -1
+       .id             = UCLASS_SOUND,
+       .of_match       = bd82x6x_azalia_ids,
+       .probe          = bd82x6x_azalia_probe,
+       .ops            = &bd82x6x_azalia_ops,
+       .priv_auto_alloc_size   = sizeof(struct hda_codec_priv),
+};
--

Regards,
Bin

#51 lore raw

PATCH 23/33 sound: x86: link: Add sound support

Hi Bin,

Quoted 61 lines · Bin Meng

Hi Simon,

Quoted 57 lines · Simon Glass

Add sound support for link, using the HDA codec implementation.

---

 arch/x86/cpu/ivybridge/Kconfig                |   1 +
 arch/x86/cpu/ivybridge/northbridge.c          |  27 ++++
 arch/x86/dts/chromebook_link.dts              |  91 ++++++++++++
 .../include/asm/arch-ivybridge/sandybridge.h  |   3 +
 configs/chromebook_link_defconfig             |   2 +
 drivers/sound/Kconfig                         |  10 ++
 drivers/sound/Makefile                        |   1 +
 drivers/sound/ivybridge_sound.c               | 137 ++++++++++++++++++
 8 files changed, 272 insertions(+)
 create mode 100644 drivers/sound/ivybridge_sound.c
arch/x86/cpu/ivybridge/Kconfig +1 -0
index 5f0e60837c..2f42393786 100644
@@ -21,6 +21,7 @@ config NORTHBRIDGE_INTEL_IVYBRIDGE
        imply USB_EHCI_HCD
        imply USB_XHCI_HCD
        imply VIDEO_VESA
+       imply SOUND_IVYBRIDGE
 
 if NORTHBRIDGE_INTEL_IVYBRIDGE
 
arch/x86/cpu/ivybridge/northbridge.c +20 -0
index 39bab7bdf3..0ac0a34acc 100644
@@ -177,6 +177,30 @@ static void sandybridge_setup_northbridge_bars(struct udevice *dev)
        dm_pci_write_config8(dev, PAM6, 0x33);
 }
 
+static void sandybridge_init_iommu(struct udevice *dev)
+{
+       u32 capid0_a;
+
+       dm_pci_read_config32(dev, 0xe4, &capid0_a);
+       if (capid0_a & (1 << 23)) {
+               log_debug("capid0_a not needed\n");
+               return;
+       }
+
+       /* setup BARs */
+       writel(IOMMU_BASE1 >> 32, MCHBAR_REG(0x5404));
+       writel(IOMMU_BASE1 | 1, MCHBAR_REG(0x5400));
+       writel(IOMMU_BASE2 >> 32, MCHBAR_REG(0x5414));
+       writel(IOMMU_BASE2 | 1, MCHBAR_REG(0x5410));
+
+       /* lock policies */
+       writel(0x80000000, IOMMU_BASE1 + 0xff0);
+
+       /* Enable azalia sound */
Quoted 8 lines

arch/x86/cpu/ivybridge/northbridge.c static void sandybridge_setup_northbridge_bars(struct udevice *dev) · line 202

Quoted 3 lines
arch/x86/cpu/ivybridge/northbridge.c +3 -0
+       writel(0x20000000, IOMMU_BASE2 + 0xff0);
+       writel(0xa0000000, IOMMU_BASE2 + 0xff0);
+}

The function name looks it has something to do with IOMMU, but why does enabling sound support need IOMMU which is mainly for hypervisor stuff? Better providing some comments here, and if possible use macros instead of hard-coded numbers.

I've looked very hard but cannot find any documentation for these registers. They seem to be in a reserved area. The coreboot patch that this code came from is at
https://review.coreboot.org/c/coreboot/+/12194/2 but there are no comments.

Quoted 32 lines
Quoted 32 lines
arch/x86/cpu/ivybridge/northbridge.c +4 -0
+
 static int bd82x6x_northbridge_early_init(struct udevice *dev)
 {
        const int chipset_type = SANDYBRIDGE_MOBILE;
@@ -197,6 +221,9 @@ static int bd82x6x_northbridge_early_init(struct udevice *dev)
 
        sandybridge_setup_northbridge_bars(dev);
 
+       /* Setup IOMMU BARs */
+       sandybridge_init_iommu(dev);
+
        /* Device Enable */
        dm_pci_write_config32(dev, DEVEN, DEVEN_HOST | DEVEN_IGD);
 
arch/x86/dts/chromebook_link.dts +2 -0
index f9f0979730..7e0a615a60 100644
@@ -1,6 +1,8 @@
 /dts-v1/;
 
 #include <dt-bindings/gpio/x86-gpio.h>
+#include <dt-bindings/sound/azalia.h>
+#include <pci_ids.h>
 
 /include/ "skeleton.dtsi"
 /include/ "keyboard.dtsi"
@@ -372,6 +374,30 @@
                        compatible = "ehci-pci";
                };
 
Quoted 13 lines

arch/x86/dts/chromebook_link.dts line 387

Quoted 11 lines
arch/x86/dts/chromebook_link.dts +11 -0
+               hda at 1b,0 {
+                       reg = <0x0000d800 0 0 0 0>;
+                       compatible = "intel,bd82x6x-hda";
+                       beep-verbs = <
+                               0x00170500      /* power up codec */
+                               0x00270500      /* power up DAC */
+                               0x00b70500      /* power up speaker */
+                               0x00b70740      /* enable speaker out */
+                               0x00b78d00      /* enable EAPD pin */
+                               0x00b70c02      /* set EAPD pin */
+                               0x0143b013>;    /* beep volume */

Are these verbs from the chipset datasheet?

They are actually using the HD audio spec. In the first one 705 is to set the power state and 1 is the node ID.

It would be possible to change these to defines but it is quite laborious and I'm not sure how useful it is. I could use the macros to separate out the fields if you think that would help a lot. But people still need to look up the spec to understand these values.

I'll add a comment mentioning the specification again.

Quoted 32 lines
Quoted 32 lines
arch/x86/dts/chromebook_link.dts +24 -0
+
+                       codecs {
+                               creative_codec: creative-ca0132 {
+                                       vendor-id = <PCI_VENDOR_ID_CREATIVE>;
+                                       device-id = <PCI_DEVICE_ID_CREATIVE_CA01322>;
+                               };
+                               intel_hdmi: hdmi {
+                                       vendor-id = <PCI_VENDOR_ID_INTEL>;
+                                       device-id = <PCI_DEVICE_ID_INTEL_COUGARPOINT_HDMI>;
+                               };
+                       };
+               };
+
                usb_0: usb at 1d,0 {
                        reg = <0x0000e800 0 0 0 0>;
                        compatible = "ehci-pci";
@@ -492,3 +518,68 @@
        };
 
 };
+
+&creative_codec {
+       verbs =  <
+               /* Malcolm Setup */
+               0x01570d09 0x01570c23 0x01570a01 0x01570df0
+               0x01570efe 0x01570775 0x015707d3 0x01570709
+               0x01570753 0x015707d4 0x015707ef 0x01570775
+               0x015707d3 0x01570709 0x01570702 0x01570737
+               0x01570778 0x01553cce 0x015575c9 0x01553dce
+               0x0155b7c9 0x01570de8 0x01570efe 0x01570702
+               0x01570768 0x01570762 0x01553ace 0x015546c9
Quoted 8 lines

arch/x86/dts/chromebook_link.dts line 535

Quoted 4 lines
arch/x86/dts/chromebook_link.dts +4 -0
+               0x01553bce 0x0155e8c9 0x01570d49 0x01570c88
+               0x01570d20 0x01570e19 0x01570700 0x01571a05
+               0x01571b29 0x01571a04 0x01571b29 0x01570a01
+

And here? Is this something one can easily get from the chipset datasheet? If not, better adding some comments to point out the sources of these magic numbers.

Again I'll add a comment. Let me know what you think.

[..]

Regards,
Simon

#52 lore raw

PATCH 24/33 sound: x86: Add beeping support in i8254

In reply to Simon Glass

Adjust the code to allow beeping at different frequencies, using a calculated value for timer 2.

---

 arch/x86/include/asm/i8254.h | 18 ++++++++++++++++++
 arch/x86/lib/i8254.c         | 36 ++++++++++++++++++++++++++++++++----
 2 files changed, 50 insertions(+), 4 deletions(-)
arch/x86/include/asm/i8254.h +18 -0
index 65c97614d3..d769daf85d 100644
@@ -35,4 +35,22 @@
 /* The clock frequency of the i8253/i8254 PIT */
 #define PIT_TICK_RATE	1193182
 
+/**
+ * i8254_enable_beep() - Start a beep using the PCAT timer
+ *
+ * This starts beeping using the legacy i8254 timer. The beep may be silenced
+ * after a delay with i8254_disable_beep().
+ *
+ * @frequency_hz: Frequency of beep in Hz
+ * @return 0 if OK, -EINVAL if frequency_hz is 0
+ */
+int i8254_enable_beep(uint frequency_hz);
+
+/**
+ * i8254_disable_beep() - Disable the bepper
+ *
+ * This stops any existing beep
+ */
+void i8254_disable_beep(void);
+
 #endif /* _ASMI386_I8954_H_ */
arch/x86/lib/i8254.c +32 -4
index 1f1012488c..dac81101f0 100644
@@ -8,8 +8,21 @@
 #include <asm/io.h>
 #include <asm/i8254.h>
 
-#define TIMER1_VALUE	18	/* 15.6us */
-#define TIMER2_VALUE	0x0a8e	/* 440Hz */
+#define TIMER1_VALUE		18	/* 15.6us */
+#define BEEP_FREQUENCY_HZ	440
+#define PPC_PORTB		0x61
+#define PORTB_BEEP_ENABLE	0x3
+#define PIT_HZ			1193180L
+
+static void i8254_set_beep_freq(uint frequency_hz)
+{
+	uint countdown;
+
+	countdown = PIT_HZ / frequency_hz;
+
+	outb(countdown & 0xff, PIT_BASE + PIT_T2);
+	outb((countdown >> 8) & 0xff, PIT_BASE + PIT_T2);
+}
 
 int i8254_init(void)
 {
@@ -29,8 +42,23 @@ int i8254_init(void)
 	 */
 	outb(PIT_CMD_CTR2 | PIT_CMD_BOTH | PIT_CMD_MODE3,
 	     PIT_BASE + PIT_COMMAND);
-	outb(TIMER2_VALUE & 0xff, PIT_BASE + PIT_T2);
-	outb(TIMER2_VALUE >> 8, PIT_BASE + PIT_T2);
+	i8254_set_beep_freq(BEEP_FREQUENCY_HZ);
+
+	return 0;
+}
+
+int i8254_enable_beep(uint frequency_hz)
+{
+	if (!frequency_hz)
+		return -EINVAL;
+
+	i8254_set_beep_freq(frequency_hz);
+	setio_8(PPC_PORTB, PORTB_BEEP_ENABLE);
 
 	return 0;
 }
+
+void i8254_disable_beep(void)
+{
+	clrio_8(PPC_PORTB, PORTB_BEEP_ENABLE);
+}
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#53 lore raw

PATCH 24/33 sound: x86: Add beeping support in i8254

Hi Simon,

Quoted 43 lines · Simon Glass

Adjust the code to allow beeping at different frequencies, using a calculated value for timer 2.

---

 arch/x86/include/asm/i8254.h | 18 ++++++++++++++++++
 arch/x86/lib/i8254.c         | 36 ++++++++++++++++++++++++++++++++----
 2 files changed, 50 insertions(+), 4 deletions(-)
arch/x86/include/asm/i8254.h +18 -0
index 65c97614d3..d769daf85d 100644
@@ -35,4 +35,22 @@
 /* The clock frequency of the i8253/i8254 PIT */
 #define PIT_TICK_RATE  1193182
 
+/**
+ * i8254_enable_beep() - Start a beep using the PCAT timer
+ *
+ * This starts beeping using the legacy i8254 timer. The beep may be silenced
+ * after a delay with i8254_disable_beep().
+ *
+ * @frequency_hz: Frequency of beep in Hz
+ * @return 0 if OK, -EINVAL if frequency_hz is 0
+ */
+int i8254_enable_beep(uint frequency_hz);
+
+/**
+ * i8254_disable_beep() - Disable the bepper
+ *
+ * This stops any existing beep
+ */
+void i8254_disable_beep(void);
+
 #endif /* _ASMI386_I8954_H_ */
arch/x86/lib/i8254.c +0 -0
index 1f1012488c..dac81101f0 100644

arch/x86/lib/i8254.c line 13

Quoted 8 lines
arch/x86/lib/i8254.c +3 -2
@@ -8,8 +8,21 @@
 #include <asm/io.h>
 #include <asm/i8254.h>
 
-#define TIMER1_VALUE   18      /* 15.6us */
-#define TIMER2_VALUE   0x0a8e  /* 440Hz */
+#define TIMER1_VALUE           18      /* 15.6us */
+#define BEEP_FREQUENCY_HZ      440
+#define PPC_PORTB              0x61

What does PPC mean? According to
https://wiki.osdev.org/Non_Maskable_Interrupt, it is System Control Port.

arch/x86/lib/i8254.c line 15

Quoted 2 lines
arch/x86/lib/i8254.c +2 -0
+#define PORTB_BEEP_ENABLE      0x3
+#define PIT_HZ                 1193180L

There is PIT_TICK_RATE in i8254.h already.

Quoted 29 lines
arch/x86/lib/i8254.c +20 -2
+
+static void i8254_set_beep_freq(uint frequency_hz)
+{
+       uint countdown;
+
+       countdown = PIT_HZ / frequency_hz;
+
+       outb(countdown & 0xff, PIT_BASE + PIT_T2);
+       outb((countdown >> 8) & 0xff, PIT_BASE + PIT_T2);
+}
 
 int i8254_init(void)
 {
@@ -29,8 +42,23 @@ int i8254_init(void)
         */
        outb(PIT_CMD_CTR2 | PIT_CMD_BOTH | PIT_CMD_MODE3,
             PIT_BASE + PIT_COMMAND);
-       outb(TIMER2_VALUE & 0xff, PIT_BASE + PIT_T2);
-       outb(TIMER2_VALUE >> 8, PIT_BASE + PIT_T2);
+       i8254_set_beep_freq(BEEP_FREQUENCY_HZ);
+
+       return 0;
+}
+
+int i8254_enable_beep(uint frequency_hz)
+{
+       if (!frequency_hz)
+               return -EINVAL;
+

arch/x86/lib/i8254.c int i8254_init(void) · line 64

Quoted 10 lines
arch/x86/lib/i8254.c +7 -0
+       i8254_set_beep_freq(frequency_hz);
+       setio_8(PPC_PORTB, PORTB_BEEP_ENABLE);
 
        return 0;
 }
+
+void i8254_disable_beep(void)
+{
+       clrio_8(PPC_PORTB, PORTB_BEEP_ENABLE);
+}

Regards,
Bin

#54 lore raw

PATCH 25/33 sound: Add a driver for the i8254 beep

In reply to Simon Glass

Add a sound driver which can output simple beeps using this legacy timer.

---

 drivers/sound/Kconfig      | 12 ++++++++++++
 drivers/sound/Makefile     |  1 +
 drivers/sound/i8254_beep.c | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+)
 create mode 100644 drivers/sound/i8254_beep.c
drivers/sound/Kconfig +12 -0
index a414e8e712..36b329d016 100644
@@ -31,6 +31,18 @@ config I2S_SAMSUNG
 	  option provides an implementation for sound_init() and
 	  sound_play().
 
+config SOUND_I8254
+	bool "Intel i8254 timer / beeper"
+	depends on SOUND
+	help
+	  This enables support for a beeper that uses the i8254 timer chip.
+	  This can emit beeps at a fixed frequency. It is possible to control
+	  the length of the beeps, by turning a beep on, waiting for a period
+	  of time, then turning it off.
+
+	  This is quite an old feature, called PIT (Programmable Interval
+	  Timer), but is nonetheless still available on modern x86 machines.
+
 config SOUND_INTEL_HDA
 	bool "Intel HDA audio codec"
 	depends on SOUND
drivers/sound/Makefile +1 -0
index 23893947be..f01fb2f739 100644
@@ -15,4 +15,5 @@ obj-$(CONFIG_SOUND_MAX98088)	+= max98088.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98090)	+= max98090.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o
 obj-$(CONFIG_SOUND_INTEL_HDA)	+= hda_codec.o
+obj-$(CONFIG_SOUND_I8254)	+= i8254_beep.o
 obj-$(CONFIG_SOUND_IVYBRIDGE)	+= ivybridge_sound.o
drivers/sound/i8254_beep.c new file +38 -0
new file mode 100644
index 0000000000..c65ed268cf
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018 Google LLC
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <sound.h>
+#include <asm/i8254.h>
+
+int i8254_start_beep(struct udevice *dev, int frequency_hz)
+{
+	return i8254_enable_beep(frequency_hz);
+}
+
+int i8254_stop_beep(struct udevice *dev)
+{
+	i8254_disable_beep();
+
+	return 0;
+}
+
+static const struct sound_ops i8254_ops = {
+	.start_beep	= i8254_start_beep,
+	.stop_beep	= i8254_stop_beep,
+};
+
+static const struct udevice_id i8254_ids[] = {
+	{ .compatible = "i8254,beeper" },
+	{ }
+};
+
+U_BOOT_DRIVER(i8254_drv) = {
+	.name		= "bd82x6x",
+	.id		= UCLASS_SOUND,
+	.of_match	= i8254_ids,
+	.ops		= &i8254_ops,
+};
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#55 lore raw

PATCH 25/33 sound: Add a driver for the i8254 beep

Hi Simon,

Quoted 75 lines · Simon Glass

Add a sound driver which can output simple beeps using this legacy timer.

---

 drivers/sound/Kconfig      | 12 ++++++++++++
 drivers/sound/Makefile     |  1 +
 drivers/sound/i8254_beep.c | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+)
 create mode 100644 drivers/sound/i8254_beep.c
drivers/sound/Kconfig +12 -0
index a414e8e712..36b329d016 100644
@@ -31,6 +31,18 @@ config I2S_SAMSUNG
          option provides an implementation for sound_init() and
          sound_play().
 
+config SOUND_I8254
+       bool "Intel i8254 timer / beeper"
+       depends on SOUND
+       help
+         This enables support for a beeper that uses the i8254 timer chip.
+         This can emit beeps at a fixed frequency. It is possible to control
+         the length of the beeps, by turning a beep on, waiting for a period
+         of time, then turning it off.
+
+         This is quite an old feature, called PIT (Programmable Interval
+         Timer), but is nonetheless still available on modern x86 machines.
+
 config SOUND_INTEL_HDA
        bool "Intel HDA audio codec"
        depends on SOUND
drivers/sound/Makefile +1 -0
index 23893947be..f01fb2f739 100644
@@ -15,4 +15,5 @@ obj-$(CONFIG_SOUND_MAX98088)  += max98088.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98090)   += max98090.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98095)   += max98095.o maxim_codec.o
 obj-$(CONFIG_SOUND_INTEL_HDA)  += hda_codec.o
+obj-$(CONFIG_SOUND_I8254)      += i8254_beep.o
 obj-$(CONFIG_SOUND_IVYBRIDGE)  += ivybridge_sound.o
drivers/sound/i8254_beep.c new file +24 -0
new file mode 100644
index 0000000000..c65ed268cf
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018 Google LLC
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <sound.h>
+#include <asm/i8254.h>
+
+int i8254_start_beep(struct udevice *dev, int frequency_hz)
+{
+       return i8254_enable_beep(frequency_hz);
+}
+
+int i8254_stop_beep(struct udevice *dev)
+{
+       i8254_disable_beep();
+
+       return 0;
+}
+
+static const struct sound_ops i8254_ops = {
+       .start_beep     = i8254_start_beep,

drivers/sound/i8254_beep.c line 34

Quoted 10 lines
drivers/sound/i8254_beep.c new file +10 -0
+       .stop_beep      = i8254_stop_beep,
+};
+
+static const struct udevice_id i8254_ids[] = {
+       { .compatible = "i8254,beeper" },
+       { }
+};
+
+U_BOOT_DRIVER(i8254_drv) = {
+       .name           = "bd82x6x",

Looks a wrong name to me.

drivers/sound/i8254_beep.c

Quoted 5 lines
drivers/sound/i8254_beep.c new file +4 -1
+       .id             = UCLASS_SOUND,
+       .of_match       = i8254_ids,
+       .ops            = &i8254_ops,
+};
--

Regards,
Bin

#56 lore raw

PATCH 26/33 x86: coreboot: Enable the beeper sound driver

In reply to Simon Glass

Use the i8254 sound driver to support creating simple beeps.

---

 configs/coreboot_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/coreboot_defconfig +3 -0
index ad0b35f204..2795fe97ca 100644
@@ -23,6 +23,7 @@ CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_SOUND=y
 CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
@@ -35,4 +36,6 @@ CONFIG_DEFAULT_DEVICE_TREE="coreboot"
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
 # CONFIG_PCI_PNP is not set
+CONFIG_SOUND=y
+CONFIG_SOUND_I8254=y
 CONFIG_CONSOLE_SCROLL_LINES=5
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#58 lore raw

PATCH 27/33 x86: broadwell: Add support for the ADSP

In reply to Simon Glass

The Application Digital Signal Processor is used for sound processing with broadwell. Add a driver to support this.

---

 arch/x86/cpu/broadwell/Makefile            |   1 +
 arch/x86/cpu/broadwell/adsp.c              | 157 +++++++++++++++++++++
 arch/x86/include/asm/arch-broadwell/adsp.h |  46 ++++++
 arch/x86/include/asm/arch-broadwell/pch.h  |   3 +
 arch/x86/include/asm/arch-broadwell/rcb.h  |   2 +
 5 files changed, 209 insertions(+)
 create mode 100644 arch/x86/cpu/broadwell/adsp.c
 create mode 100644 arch/x86/include/asm/arch-broadwell/adsp.h
arch/x86/cpu/broadwell/Makefile +1 -0
index a032861e57..d3785aabdf 100644
@@ -2,6 +2,7 @@
 #
 # Copyright (c) 2016 Google, Inc
 
+obj-y += adsp.o
 obj-y += cpu.o
 obj-y += iobp.o
 obj-y += lpc.o
arch/x86/cpu/broadwell/adsp.c new file +157 -0

157 lines not on this page · raw message

arch/x86/include/asm/arch-broadwell/adsp.h new file +46 -0

46 lines not on this page · raw message

arch/x86/include/asm/arch-broadwell/pch.h +3 -0
index 23ccd68484..23153a040f 100644
@@ -109,6 +109,9 @@
 #define SATA_DTLE_EDGE_SHIFT	16
 
 /* Power Management */
+#define PCH_PCS			0x84
+#define  PCH_PCS_PS_D3HOT	3
+
 #define GEN_PMCON_1		0xa0
 #define  SMI_LOCK		(1 << 4)
 #define GEN_PMCON_2		0xa2
arch/x86/include/asm/arch-broadwell/rcb.h +2 -0
index e7340c1e5a..b7ce8746c8 100644
@@ -6,6 +6,8 @@
 #ifndef __asm_arch_rcba_h
 #define __asm_arch_rcba_h
 
+#define ACPIIRQEN	0x31e0	/* 32bit */
+
 #define PMSYNC_CONFIG	0x33c4	/* 32bit */
 #define PMSYNC_CONFIG2	0x33cc	/* 32bit */
 
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#59 lore raw

PATCH 27/33 x86: broadwell: Add support for the ADSP

Hi Simon,

Quoted 132 lines · Simon Glass

The Application Digital Signal Processor is used for sound processing with broadwell. Add a driver to support this.

---

 arch/x86/cpu/broadwell/Makefile            |   1 +
 arch/x86/cpu/broadwell/adsp.c              | 157 +++++++++++++++++++++
 arch/x86/include/asm/arch-broadwell/adsp.h |  46 ++++++
 arch/x86/include/asm/arch-broadwell/pch.h  |   3 +
 arch/x86/include/asm/arch-broadwell/rcb.h  |   2 +
 5 files changed, 209 insertions(+)
 create mode 100644 arch/x86/cpu/broadwell/adsp.c
 create mode 100644 arch/x86/include/asm/arch-broadwell/adsp.h
arch/x86/cpu/broadwell/Makefile +1 -0
index a032861e57..d3785aabdf 100644
@@ -2,6 +2,7 @@
 #
 # Copyright (c) 2016 Google, Inc
 
+obj-y += adsp.o
 obj-y += cpu.o
 obj-y += iobp.o
 obj-y += lpc.o
arch/x86/cpu/broadwell/adsp.c new file +98 -0
new file mode 100644
index 0000000000..a4cff45323
@@ -0,0 +1,157 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Support for Intel Application Digital Signal Processor
+ *
+ * Copyright 2019 Google LLC
+ *
+ * Modified from coreboot file of the same name
+ */
+
+#define LOG_CATEGORY UCLASS_SYSCON
+
+#include <common.h>
+#include <dm.h>
+#include <pci.h>
+#include <asm/io.h>
+#include <asm/cpu.h>
+#include <asm/intel_regs.h>
+#include <asm/arch/adsp.h>
+#include <asm/arch/pch.h>
+#include <asm/arch/rcb.h>
+
+enum pci_type_t {
+       LYNX_POINT,
+       WILDCAT_POINT,
+};
+
+struct broadwell_adsp_priv {
+       bool adsp_d3_pg_enable;
+       bool adsp_sram_pg_enable;
+       bool sio_acpi_mode;
+};
+
+static int broadwell_adsp_probe(struct udevice *dev)
+{
+       struct broadwell_adsp_priv *priv = dev_get_priv(dev);
+       enum pci_type_t type;
+       u32 bar0, bar1;
+       u32 tmp32;
+
+       /* Find BAR0 and BAR1 */
+       bar0 = dm_pci_read_bar32(dev, 0);
+       if (!bar0)
+               return -EINVAL;
+       bar1 = dm_pci_read_bar32(dev, 1);
+       if (!bar1)
+               return -EINVAL;
+
+       /*
+        * Set LTR value in DSP shim LTR control register to 3ms
+        * SNOOP_REQ[13]=1b SNOOP_SCALE[12:10]=100b (1ms) SNOOP_VAL[9:0]=3h
+        */
+       type = dev_get_driver_data(dev);
+       tmp32 = type == WILDCAT_POINT ? ADSP_SHIM_BASE_WPT : ADSP_SHIM_BASE_LPT;
+       writel(ADSP_SHIM_LTRC_VALUE, bar0 + tmp32);
+
+       /* Program VDRTCTL2 D19:F0:A8[31:0] = 0x00000fff */
+       dm_pci_write_config32(dev, ADSP_PCI_VDRTCTL2, ADSP_VDRTCTL2_VALUE);
+
+       /* Program ADSP IOBP VDLDAT1 to 0x040100 */
+       pch_iobp_write(ADSP_IOBP_VDLDAT1, ADSP_VDLDAT1_VALUE);
+
+       /* Set D3 Power Gating Enable in D19:F0:A0 based on PCH type */
+       dm_pci_read_config32(dev, ADSP_PCI_VDRTCTL0, &tmp32);
+       if (type == WILDCAT_POINT) {
+               if (priv->adsp_d3_pg_enable) {
+                       tmp32 &= ~ADSP_VDRTCTL0_D3PGD_WPT;
+                       if (priv->adsp_sram_pg_enable)
+                               tmp32 &= ~ADSP_VDRTCTL0_D3SRAMPGD_WPT;
+                       else
+                               tmp32 |= ADSP_VDRTCTL0_D3SRAMPGD_WPT;
+               } else {
+                       tmp32 |= ADSP_VDRTCTL0_D3PGD_WPT;
+               }
+       } else {
+               if (priv->adsp_d3_pg_enable) {
+                       tmp32 &= ~ADSP_VDRTCTL0_D3PGD_LPT;
+                       if (priv->adsp_sram_pg_enable)
+                               tmp32 &= ~ADSP_VDRTCTL0_D3SRAMPGD_LPT;
+                       else
+                               tmp32 |= ADSP_VDRTCTL0_D3SRAMPGD_LPT;
+               } else {
+                       tmp32 |= ADSP_VDRTCTL0_D3PGD_LPT;
+               }
+       }
+       dm_pci_write_config32(dev, ADSP_PCI_VDRTCTL0, tmp32);
+
+       /* Set PSF Snoop to SA, RCBA+0x3350[10]=1b */
+       setbits_le32(RCB_REG(0x3350), 1 << 10);
+
+       /* Set DSP IOBP PMCTL 0x1e0=0x3f */
+       pch_iobp_write(ADSP_IOBP_PMCTL, ADSP_PMCTL_VALUE);
+
+       if (priv->sio_acpi_mode) {
+               /* Configure for ACPI mode */
+               log_info("ADSP: Enable ACPI Mode IRQ3\n");
+
+               /* Set interrupt de-assert/assert opcode override to IRQ3 */
+               pch_iobp_write(ADSP_IOBP_VDLDAT2, ADSP_IOBP_ACPI_IRQ3);

arch/x86/cpu/broadwell/adsp.c line 108

Quoted 10 lines
arch/x86/cpu/broadwell/adsp.c new file +10 -0
+
+               /* Enable IRQ3 in RCBA */
+               setbits_le32(RCB_REG(ACPIIRQEN), ADSP_ACPI_IRQEN);
+
+               /* Set ACPI Interrupt Enable Bit */
+               pch_iobp_update(ADSP_IOBP_PCICFGCTL, ~ADSP_PCICFGCTL_SPCBAD,
+                               ADSP_PCICFGCTL_ACPIIE);
+
+               /* Put ADSP in D3hot */
+               //set

nits: /* */, and looks this line is useless?

Quoted 120 lines
arch/x86/cpu/broadwell/adsp.c new file +49 -0
+               clrbits_le32(bar1 + PCH_PCS, PCH_PCS_PS_D3HOT);
+       } else {
+               log_info("ADSP: Enable PCI Mode IRQ23\n");
+
+               /* Configure for PCI mode */
+               dm_pci_write_config32(dev, PCI_INTERRUPT_LINE, ADSP_PCI_IRQ);
+
+               /* Clear ACPI Interrupt Enable Bit */
+               pch_iobp_update(ADSP_IOBP_PCICFGCTL,
+                               ~(ADSP_PCICFGCTL_SPCBAD |
+                                ADSP_PCICFGCTL_ACPIIE), 0);
+       }
+
+       return 0;
+}
+
+static int broadwell_adsp_ofdata_to_platdata(struct udevice *dev)
+{
+       struct broadwell_adsp_priv *priv = dev_get_priv(dev);
+
+       priv->adsp_d3_pg_enable = dev_read_bool(dev, "intel,adsp-d3-pg-enable");
+       priv->adsp_sram_pg_enable = dev_read_bool(dev,
+                                                 "intel,adsp-sram-pg-enable");
+       priv->sio_acpi_mode = dev_read_bool(dev, "intel,sio-acpi-mode");
+
+       return 0;
+}
+
+static const struct udevice_id broadwell_adsp_ids[] = {
+       { .compatible = "intel,wildcatpoint-adsp", .data = WILDCAT_POINT },
+       { }
+};
+
+U_BOOT_DRIVER(broadwell_adsp_drv) = {
+       .name           = "adsp",
+       .id             = UCLASS_SYSCON,
+       .ofdata_to_platdata     = broadwell_adsp_ofdata_to_platdata,
+       .of_match       = broadwell_adsp_ids,
+       .bind           = dm_scan_fdt_dev,
+       .probe          = broadwell_adsp_probe,
+};
+
+static struct pci_device_id broadwell_adsp_supported[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL,
+               PCI_DEVICE_ID_INTEL_WILDCATPOINT_ADSP) },
+       { },
+};
+
+U_BOOT_PCI_DEVICE(broadwell_adsp_drv, broadwell_adsp_supported);
arch/x86/include/asm/arch-broadwell/adsp.h new file +46 -0
new file mode 100644
index 0000000000..eb825ce1c0
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Support for Intel Application Digital Signal Processor
+ *
+ * Copyright 2019 Google LLC
+ *
+ * Modified from coreboot file of the same name
+ */
+
+#ifndef __ASM_ARCH_BROADWELL_ADSP_H
+#define __ASM_ARCH_BROADWELL_ADSP_H
+
+#define ADSP_PCI_IRQ                   23
+#define ADSP_ACPI_IRQ                  3
+#define  ADSP_ACPI_IRQEN               BIT(3)
+
+#define ADSP_SHIM_BASE_LPT             0xe7000
+#define ADSP_SHIM_BASE_WPT             0xfb000
+#define  ADSP_SHIM_LTRC                        0xe0
+#define   ADSP_SHIM_LTRC_VALUE         0x3003
+#define  ADSP_SHIM_IMC                 0x28
+#define  ADSP_SHIM_IPCD                        0x40
+
+#define ADSP_PCI_VDRTCTL0              0xa0
+#define  ADSP_VDRTCTL0_D3PGD_LPT       BIT(1)
+#define  ADSP_VDRTCTL0_D3PGD_WPT       BIT(0)
+#define  ADSP_VDRTCTL0_D3SRAMPGD_LPT   BIT(2)
+#define  ADSP_VDRTCTL0_D3SRAMPGD_WPT   BIT(1)
+#define ADSP_PCI_VDRTCTL1              0xa4
+#define ADSP_PCI_VDRTCTL2              0xa8
+#define  ADSP_VDRTCTL2_VALUE           0x00000fff
+
+#define ADSP_IOBP_VDLDAT1              0xd7000624
+#define  ADSP_VDLDAT1_VALUE            0x00040100
+#define ADSP_IOBP_VDLDAT2              0xd7000628
+#define  ADSP_IOBP_ACPI_IRQ3           0xd9d8
+#define  ADSP_IOBP_ACPI_IRQ3I          0xd8d9
+#define  ADSP_IOBP_ACPI_IRQ4           0xdbda
+#define ADSP_IOBP_PMCTL                        0xd70001e0
+#define  ADSP_PMCTL_VALUE              0x3f
+#define ADSP_IOBP_PCICFGCTL            0xd7000500
+#define  ADSP_PCICFGCTL_PCICD          BIT(0)
+#define  ADSP_PCICFGCTL_ACPIIE         BIT(1)
+#define  ADSP_PCICFGCTL_SPCBAD         BIT(7)
+
+#endif /* __ASM_ARCH_BROADWELL_ADSP_H */
arch/x86/include/asm/arch-broadwell/pch.h +3 -0
index 23ccd68484..23153a040f 100644
@@ -109,6 +109,9 @@
 #define SATA_DTLE_EDGE_SHIFT   16
 
 /* Power Management */
+#define PCH_PCS                        0x84
+#define  PCH_PCS_PS_D3HOT      3
+
 #define GEN_PMCON_1            0xa0
 #define  SMI_LOCK              (1 << 4)
 #define GEN_PMCON_2            0xa2
arch/x86/include/asm/arch-broadwell/rcb.h +0 -0
index e7340c1e5a..b7ce8746c8 100644

arch/x86/include/asm/arch-broadwell/rcb.h

Quoted 9 lines
arch/x86/include/asm/arch-broadwell/rcb.h +2 -1
@@ -6,6 +6,8 @@
 #ifndef __asm_arch_rcba_h
 #define __asm_arch_rcba_h
 
+#define ACPIIRQEN      0x31e0  /* 32bit */
+
 #define PMSYNC_CONFIG  0x33c4  /* 32bit */
 #define PMSYNC_CONFIG2 0x33cc  /* 32bit */
 
--

Regards,
Bin

#60 lore raw

PATCH 28/33 x86: broadwell: Don't bother probing the PCH for pinctrl

In reply to Simon Glass

At present the pinctrl probes the PCH but since it only uses it to obtain a PCI address, this is no necessary. Avoiding this fixes one of the two co-dependent loops in broadwell.

This driver really should be a proper pinctrl driver, but for now it remains a syscon device.

---

 arch/x86/cpu/broadwell/pinctrl_broadwell.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/cpu/broadwell/pinctrl_broadwell.c +2 -1
index 914ecfb314..aa83abbf85 100644
@@ -16,6 +16,7 @@
 #include <asm/arch/gpio.h>
 #include <dt-bindings/gpio/x86-gpio.h>
 #include <dm/pinctrl.h>
+#include <dm/uclass-internal.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -214,7 +215,7 @@ static int broadwell_pinctrl_probe(struct udevice *dev)
 	u32 gpiobase;
 	int ret;
 
-	ret = uclass_first_device(UCLASS_PCH, &pch);
+	ret = uclass_find_first_device(UCLASS_PCH, &pch);
 	if (ret)
 		return ret;
 	if (!pch)
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#61 lore raw

PATCH 28/33 x86: broadwell: Don't bother probing the PCH for pinctrl

Quoted 5 lines · Simon Glass

At present the pinctrl probes the PCH but since it only uses it to obtain a PCI address, this is no necessary. Avoiding this fixes one of the two co-dependent loops in broadwell.

Quoted 9 lines

This driver really should be a proper pinctrl driver, but for now it remains a syscon device.

---

 arch/x86/cpu/broadwell/pinctrl_broadwell.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
#62 lore raw

PATCH 29/33 x86: broadwell: Add support for serial I/O devices

In reply to Simon Glass

Add support for initing the I2C device and ADSP on broadwell. These are needed for sound to work.

---

 arch/x86/cpu/broadwell/pch.c                  | 110 ++++++++++++++++++
 .../x86/include/asm/arch-broadwell/serialio.h |  82 +++++++++++++
 2 files changed, 192 insertions(+)
 create mode 100644 arch/x86/include/asm/arch-broadwell/serialio.h
arch/x86/cpu/broadwell/pch.c +110 -0
index 82506ba35e..73d3d3b515 100644
@@ -20,7 +20,9 @@
 #include <asm/arch/pch.h>
 #include <asm/arch/pm.h>
 #include <asm/arch/rcb.h>
+#include <asm/arch/serialio.h>
 #include <asm/arch/spi.h>
+#include <dm/uclass-internal.h>
 
 #define BIOS_CTRL	0xdc
 
@@ -456,6 +458,111 @@ static void systemagent_init(void)
 	cpu_set_power_limits(28);
 }
 
+/* Enable LTR Auto Mode for D21:F1-F6 */
+static void serialio_d21_ltr(u32 bar0)
+{
+	/* 1. Program BAR0 + 808h[2] = 0b */
+	clrbits_le32(bar0 + SIO_REG_PPR_GEN, SIO_REG_PPR_GEN_LTR_MODE_MASK);
+
+	/* 2. Program BAR0 + 804h[1:0] = 00b */
+	clrbits_le32(bar0 + SIO_REG_PPR_RST, SIO_REG_PPR_RST_ASSERT);
+
+	/* 3. Program BAR0 + 804h[1:0] = 11b */
+	setbits_le32(bar0 + SIO_REG_PPR_RST, SIO_REG_PPR_RST_ASSERT);
+
+	/* 4. Program BAR0 + 814h[31:0] = 00000000h */
+	writel(0, bar0 + SIO_REG_AUTO_LTR);
+}
+
+/* Select I2C voltage of 1.8V or 3.3V */
+static void serialio_i2c_voltage_sel(u32 bar0, uint voltage)
+{
+	clrsetbits_le32(bar0 + SIO_REG_PPR_GEN, SIO_REG_PPR_GEN_VOLTAGE_MASK,
+			SIO_REG_PPR_GEN_VOLTAGE(voltage));
+}
+
+/* Put Serial IO D21:F0-F6 device into desired mode */
+static void serialio_d21_mode(int sio_index, int int_pin, bool acpi_mode)
+{
+	u32 portctrl = SIO_IOBP_PORTCTRL_PM_CAP_PRSNT;
+
+	/* Snoop select 1 */
+	portctrl |= SIO_IOBP_PORTCTRL_SNOOP_SELECT(1);
+
+	/* Set interrupt pin */
+	portctrl |= SIO_IOBP_PORTCTRL_INT_PIN(int_pin);
+
+	if (acpi_mode) {
+		/* Enable ACPI interrupt mode */
+		portctrl |= SIO_IOBP_PORTCTRL_ACPI_IRQ_EN;
+	}
+
+	pch_iobp_update(SIO_IOBP_PORTCTRLX(sio_index), 0, portctrl);
+}
+
+/* Init sequence to be run once, done as part of D21:F0 (SDMA) init */
+static void serialio_init_once(bool acpi_mode)
+{
+	if (acpi_mode) {
+		/* Enable ACPI IRQ for IRQ13, IRQ7, IRQ6, IRQ5 in RCBA */
+		setbits_le32(RCB_REG(ACPIIRQEN),
+			     1 << 13 | 1 << 7 | 1 << 6 | 1 << 5);
+	}
+
+	/* Program IOBP CB000154h[12,9:8,4:0] = 1001100011111b */
+	pch_iobp_update(SIO_IOBP_GPIODF, ~0x0000131f, 0x0000131f);
+
+	/* Program IOBP CB000180h[5:0] = 111111b (undefined register) */
+	pch_iobp_update(0xcb000180, ~0x0000003f, 0x0000003f);
+}
+
+/**
+ * pch_serialio_init() - set up serial I/O devices
+ *
+ * @return 0 if OK, -ve on error
+ */
+static int pch_serialio_init(void)
+{
+	struct udevice *dev, *hda;
+	bool acpi_mode = true;
+	u32 bar0, bar1;
+	int ret;
+
+	ret = uclass_find_first_device(UCLASS_I2C, &dev);
+	if (ret)
+		return ret;
+	bar0 = dm_pci_read_bar32(dev, 0);
+	if (!bar0)
+		return -EINVAL;
+	bar1 = dm_pci_read_bar32(dev, 1);
+	if (!bar1)
+		return -EINVAL;
+
+	serialio_init_once(acpi_mode);
+	serialio_d21_mode(SIO_ID_SDMA, SIO_PIN_INTB, acpi_mode);
+
+	serialio_d21_ltr(bar0);
+	serialio_i2c_voltage_sel(bar0, 1); /* Select 1.8V always */
+	serialio_d21_mode(SIO_ID_I2C0, SIO_PIN_INTC, acpi_mode);
+	setbits_le32(bar1 + PCH_PCS, PCH_PCS_PS_D3HOT);
+
+	clrbits_le32(bar1 + PCH_PCS, PCH_PCS_PS_D3HOT);
+
+	setbits_le32(bar0 + SIO_REG_PPR_CLOCK, SIO_REG_PPR_CLOCK_EN);
+
+	/* Manually find the High-definition audio, to turn it off */
+	ret = dm_pci_bus_find_bdf(PCI_BDF(0, 0x1b, 0), &hda);
+	if (ret)
+		return -ENOENT;
+	dm_pci_clrset_config8(hda, 0x43, 0, 0x6f);
+
+	/* Route I/O buffers to ADSP function */
+	dm_pci_clrset_config8(hda, 0x42, 0, 1 << 7 | 1 << 6);
+	log_debug("HDA disabled, I/O buffers routed to ADSP\n");
+
+	return 0;
+}
+
 static int broadwell_pch_init(struct udevice *dev)
 {
 	int ret;
@@ -482,6 +589,9 @@ static int broadwell_pch_init(struct udevice *dev)
 		return ret;
 	pch_pm_init(dev);
 	pch_cg_init(dev);
+	ret = pch_serialio_init();
+	if (ret)
+		return ret;
 	systemagent_init();
 
 	return 0;
arch/x86/include/asm/arch-broadwell/serialio.h new file +82 -0

82 lines not on this page · raw message

Signature · 1 line
2.20.1.321.g9e740568ce-goog
#63 lore raw

PATCH 29/33 x86: broadwell: Add support for serial I/O devices

Quoted 4 lines · Simon Glass

Add support for initing the I2C device and ADSP on broadwell. These are needed for sound to work.

Quoted 8 lines

---

 arch/x86/cpu/broadwell/pch.c                  | 110 ++++++++++++++++++
 .../x86/include/asm/arch-broadwell/serialio.h |  82 +++++++++++++
 2 files changed, 192 insertions(+)
 create mode 100644 arch/x86/include/asm/arch-broadwell/serialio.h
#64 lore raw

PATCH 30/33 x86: sound: Add support for broadwell I2S

In reply to Simon Glass

I2S is used to send digital audio data to an audio codec. Add support for this on broadwell.

---

 drivers/sound/Makefile        |   1 +
 drivers/sound/broadwell_i2s.c | 306 ++++++++++++++++++++++++++++++++++
 drivers/sound/broadwell_i2s.h | 301 +++++++++++++++++++++++++++++++++
 3 files changed, 608 insertions(+)
 create mode 100644 drivers/sound/broadwell_i2s.c
 create mode 100644 drivers/sound/broadwell_i2s.h
drivers/sound/Makefile +1 -0
index f01fb2f739..102b3bca1a 100644
@@ -16,4 +16,5 @@ obj-$(CONFIG_SOUND_MAX98090)	+= max98090.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o
 obj-$(CONFIG_SOUND_INTEL_HDA)	+= hda_codec.o
 obj-$(CONFIG_SOUND_I8254)	+= i8254_beep.o
+obj-$(CONFIG_INTEL_BROADWELL)	+= broadwell_i2s.o
 obj-$(CONFIG_SOUND_IVYBRIDGE)	+= ivybridge_sound.o
drivers/sound/broadwell_i2s.c new file +306 -0

306 lines not on this page · raw message

drivers/sound/broadwell_i2s.h new file +301 -0

301 lines not on this page · raw message

Signature · 1 line
2.20.1.321.g9e740568ce-goog
#65 lore raw

PATCH 30/33 x86: sound: Add support for broadwell I2S

Quoted 5 lines · Simon Glass

I2S is used to send digital audio data to an audio codec. Add support for this on broadwell.

Quoted 9 lines

---

 drivers/sound/Makefile        |   1 +
 drivers/sound/broadwell_i2s.c | 306 ++++++++++++++++++++++++++++++++++
 drivers/sound/broadwell_i2s.h | 301 +++++++++++++++++++++++++++++++++
 3 files changed, 608 insertions(+)
 create mode 100644 drivers/sound/broadwell_i2s.c
 create mode 100644 drivers/sound/broadwell_i2s.h
#66 lore raw

PATCH 31/33 sound: Add a driver for RealTek RT5677

In reply to Simon Glass

This audio codec is used on samus. Add a driver for it.

---

 drivers/sound/Kconfig  |    9 +
 drivers/sound/Makefile |    1 +
 drivers/sound/rt5677.c |  334 ++++++++++
 drivers/sound/rt5677.h | 1428 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1772 insertions(+)
 create mode 100644 drivers/sound/rt5677.c
 create mode 100644 drivers/sound/rt5677.h
drivers/sound/Kconfig +9 -0
index 36b329d016..6eb183f4fd 100644
@@ -86,6 +86,15 @@ config SOUND_MAX98095
 	  audio data and I2C for codec control. At present it only works
 	  with the Samsung I2S driver.
 
+config SOUND_RT5677
+	bool "Support Realtek RT5677 audio codec"
+	depends on SOUND
+	help
+	  Enable the Realtek RT5677 audio codec. This is an I2S device used on
+	  some Chromebooks from around 2015 ('auron'). It is configured using
+	  an I2C interface and supports multiple sound inputs and outputs,
+	  including digital microphones.
+
 config SOUND_SANDBOX
 	bool "Support sandbox emulated audio codec"
 	depends on SANDBOX && SOUND
drivers/sound/Makefile +1 -0
index 102b3bca1a..29d0396e5d 100644
@@ -16,5 +16,6 @@ obj-$(CONFIG_SOUND_MAX98090)	+= max98090.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o
 obj-$(CONFIG_SOUND_INTEL_HDA)	+= hda_codec.o
 obj-$(CONFIG_SOUND_I8254)	+= i8254_beep.o
+obj-$(CONFIG_SOUND_RT5677)	+= rt5677.o
 obj-$(CONFIG_INTEL_BROADWELL)	+= broadwell_i2s.o
 obj-$(CONFIG_SOUND_IVYBRIDGE)	+= ivybridge_sound.o
drivers/sound/rt5677.c new file +334 -0

334 lines not on this page · raw message

drivers/sound/rt5677.h new file +1428 -0

1,428 lines not on this page · raw message

Signature · 1 line
2.20.1.321.g9e740568ce-goog
#67 lore raw

PATCH 31/33 sound: Add a driver for RealTek RT5677

Quoted 6 lines · Simon Glass

This audio codec is used on samus. Add a driver for it.

---

Quoted 8 lines
 drivers/sound/Kconfig  |    9 +
 drivers/sound/Makefile |    1 +
 drivers/sound/rt5677.c |  334 ++++++++++
 drivers/sound/rt5677.h | 1428 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1772 insertions(+)
 create mode 100644 drivers/sound/rt5677.c
 create mode 100644 drivers/sound/rt5677.h
#68 lore raw

PATCH 32/33 x86: sound: Add sound support for samus (broadwell)

In reply to Simon Glass

Add a sound driver for samus which ties together the audio codec and I2S controller.

---

 drivers/sound/Makefile          |  2 +-
 drivers/sound/broadwell_sound.c | 65 +++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 drivers/sound/broadwell_sound.c
drivers/sound/Makefile +1 -1
index 29d0396e5d..a9516e9c03 100644
@@ -17,5 +17,5 @@ obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o
 obj-$(CONFIG_SOUND_INTEL_HDA)	+= hda_codec.o
 obj-$(CONFIG_SOUND_I8254)	+= i8254_beep.o
 obj-$(CONFIG_SOUND_RT5677)	+= rt5677.o
-obj-$(CONFIG_INTEL_BROADWELL)	+= broadwell_i2s.o
+obj-$(CONFIG_INTEL_BROADWELL)	+= broadwell_i2s.o #broadwell_sound.o
 obj-$(CONFIG_SOUND_IVYBRIDGE)	+= ivybridge_sound.o
drivers/sound/broadwell_sound.c new file +65 -0

65 lines not on this page · raw message

Signature · 1 line
2.20.1.321.g9e740568ce-goog
#69 lore raw

PATCH 32/33 x86: sound: Add sound support for samus (broadwell)

Quoted 17 lines · Simon Glass

Add a sound driver for samus which ties together the audio codec and I2S controller.

---

 drivers/sound/Makefile          |  2 +-
 drivers/sound/broadwell_sound.c | 65 +++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 drivers/sound/broadwell_sound.c
drivers/sound/Makefile +0 -0
index 29d0396e5d..a9516e9c03 100644

drivers/sound/Makefile obj-$(CONFIG_SOUND_MAX98095) += max98095.o maxim_codec.o · line 20

Quoted 5 lines
drivers/sound/Makefile +1 -1
@@ -17,5 +17,5 @@ obj-$(CONFIG_SOUND_MAX98095)  += max98095.o maxim_codec.o
 obj-$(CONFIG_SOUND_INTEL_HDA)  += hda_codec.o
 obj-$(CONFIG_SOUND_I8254)      += i8254_beep.o
 obj-$(CONFIG_SOUND_RT5677)     += rt5677.o
-obj-$(CONFIG_INTEL_BROADWELL)  += broadwell_i2s.o
+obj-$(CONFIG_INTEL_BROADWELL)  += broadwell_i2s.o #broadwell_sound.o

#?

drivers/sound/broadwell_sound.c

Quoted 5 lines
drivers/sound/Makefile +0 -0
 obj-$(CONFIG_SOUND_IVYBRIDGE)  += ivybridge_sound.o
drivers/sound/broadwell_sound.c new file +0 -1
new file mode 100644
index 0000000000..6e083fe1f6
--- /dev/null

[snip]

Regards,
Bin

#70 lore raw

PATCH 32/33 x86: sound: Add sound support for samus (broadwell)

Hi Bin,

Quoted 14 lines · Bin Meng
Quoted 12 lines · Simon Glass

Add a sound driver for samus which ties together the audio codec and I2S controller.

---

 drivers/sound/Makefile          |  2 +-
 drivers/sound/broadwell_sound.c | 65 +++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 drivers/sound/broadwell_sound.c
Quoted 12 lines

drivers/sound/Makefile obj-$(CONFIG_SOUND_MAX98095) += max98095.o maxim_codec.o · line 20

Quoted 10 lines
drivers/sound/Makefile +1 -1
index 29d0396e5d..a9516e9c03 100644
@@ -17,5 +17,5 @@ obj-$(CONFIG_SOUND_MAX98095)  += max98095.o maxim_codec.o
 obj-$(CONFIG_SOUND_INTEL_HDA)  += hda_codec.o
 obj-$(CONFIG_SOUND_I8254)      += i8254_beep.o
 obj-$(CONFIG_SOUND_RT5677)     += rt5677.o
-obj-$(CONFIG_INTEL_BROADWELL)  += broadwell_i2s.o
+obj-$(CONFIG_INTEL_BROADWELL)  += broadwell_i2s.o #broadwell_sound.o

#?

This is so it builds without sound being enabled. I'll add a comment. It is removed in the next commit.

Regards,
Simon

#71 lore raw

PATCH 33/33 x86: Add sound support for samus

In reply to Simon Glass

Enable sound on samus using the broadwell I2S and an RT5677 audio codec.

---

 arch/x86/dts/chromebook_samus.dts  | 49 +++++++++++++++++++++++++++---
 configs/chromebook_samus_defconfig |  9 ++++++
 drivers/sound/Makefile             |  2 +-
 3 files changed, 55 insertions(+), 5 deletions(-)
arch/x86/dts/chromebook_samus.dts +45 -4
index b58936b4ac..ad687ce2cc 100644
@@ -494,10 +494,20 @@
 			intel,pre-graphics-delay = <200>;
 		};
 
-		me at 16,0 {
-			reg = <0x0000b000 0 0 0 0>;
-			compatible = "intel,me";
-			u-boot,dm-pre-reloc;
+		adsp at 13,0 {
+			reg = <0x00009800 0 0 0 0>;
+			compatible = "intel,wildcatpoint-adsp";
+			intel,adsp-d3-pg-enable = <0>;
+			intel,adsp-sram-pg-enable = <0>;
+			intel,sio-acpi-mode;
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			i2s: shim {
+				compatible = "intel,broadwell-i2s";
+				#sound-dai-cells = <1>;
+				reg = <0xfb000 0xfc000 0xfd000>;
+			};
 		};
 
 		usb_1: usb at 14,0 {
@@ -505,6 +515,25 @@
 			compatible = "xhci-pci";
 		};
 
+		i2c0: i2c at 15,1 {
+			reg = <0x0000a900 0 0 0 0>;
+			compatible = "snps,designware-i2c";
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			rt5677: rt5677 at 2c {
+				compatible = "realtek,rt5677";
+				#sound-dai-cells = <1>;
+				reg = <0x2c>;
+			};
+		};
+
+		me at 16,0 {
+			reg = <0x0000b000 0 0 0 0>;
+			compatible = "intel,me";
+			u-boot,dm-pre-reloc;
+		};
+
 		usb_0: usb at 1d,0 {
 			status = "disabled";
 			reg = <0x0000e800 0 0 0 0>;
@@ -626,4 +655,16 @@
 		};
 	};
 
+	sound {
+		compatible = "google,samus-sound";
+		codec-enable-gpio = <&gpio_b 11 GPIO_ACTIVE_HIGH>;
+		cpu {
+			sound-dai = <&i2s 0>;
+		};
+
+		codec {
+			sound-dai = <&rt5677 0>;
+		};
+	};
+
 };
configs/chromebook_samus_defconfig +9 -0
index 745cb3db0a..7e2453f244 100644
@@ -17,6 +17,7 @@ CONFIG_BOOTSTAGE_REPORT=y
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="root=/dev/sdb3 init=/sbin/init rootwait ro"
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
+CONFIG_LOG_DEFAULT_LEVEL=7
 CONFIG_MISC_INIT_R=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_LAST_STAGE_INIT=y
@@ -24,7 +25,9 @@ CONFIG_HUSH_PARSER=y
 CONFIG_CMD_CPU=y
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_GPIO=y
+CONFIG_CMD_I2C=y
 CONFIG_CMD_PART=y
+CONFIG_CMD_SATA=y
 CONFIG_CMD_SF=y
 CONFIG_CMD_SPI=y
 CONFIG_CMD_USB=y
@@ -33,6 +36,7 @@ CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_SOUND=y
 CONFIG_CMD_BOOTSTAGE=y
 CONFIG_CMD_TPM=y
 CONFIG_CMD_TPM_TEST=y
@@ -48,9 +52,14 @@ CONFIG_DEFAULT_DEVICE_TREE="chromebook_samus"
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
 CONFIG_CPU=y
+CONFIG_DM_I2C=y
+CONFIG_SYS_I2C_DW=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_LPC=y
 CONFIG_SYS_NS16550=y
+CONFIG_SOUND=y
+CONFIG_SOUND_I8254=y
+CONFIG_SOUND_RT5677=y
 CONFIG_SPI=y
 CONFIG_TPM_TIS_LPC=y
 CONFIG_USB_STORAGE=y
drivers/sound/Makefile +1 -1
index a9516e9c03..7b3c879aa2 100644
@@ -17,5 +17,5 @@ obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o
 obj-$(CONFIG_SOUND_INTEL_HDA)	+= hda_codec.o
 obj-$(CONFIG_SOUND_I8254)	+= i8254_beep.o
 obj-$(CONFIG_SOUND_RT5677)	+= rt5677.o
-obj-$(CONFIG_INTEL_BROADWELL)	+= broadwell_i2s.o #broadwell_sound.o
+obj-$(CONFIG_INTEL_BROADWELL)	+= broadwell_i2s.o broadwell_sound.o
 obj-$(CONFIG_SOUND_IVYBRIDGE)	+= ivybridge_sound.o
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#72 lore raw

PATCH 33/33 x86: Add sound support for samus

Hi Simon,

Quoted 11 lines · Simon Glass

Enable sound on samus using the broadwell I2S and an RT5677 audio codec.

---

 arch/x86/dts/chromebook_samus.dts  | 49 +++++++++++++++++++++++++++---
 configs/chromebook_samus_defconfig |  9 ++++++
 drivers/sound/Makefile             |  2 +-
 3 files changed, 55 insertions(+), 5 deletions(-)

Except one comment below:

Quoted 28 lines
arch/x86/dts/chromebook_samus.dts +14 -4
index b58936b4ac..ad687ce2cc 100644
@@ -494,10 +494,20 @@
                        intel,pre-graphics-delay = <200>;
                };
 
-               me at 16,0 {
-                       reg = <0x0000b000 0 0 0 0>;
-                       compatible = "intel,me";
-                       u-boot,dm-pre-reloc;
+               adsp at 13,0 {
+                       reg = <0x00009800 0 0 0 0>;
+                       compatible = "intel,wildcatpoint-adsp";
+                       intel,adsp-d3-pg-enable = <0>;
+                       intel,adsp-sram-pg-enable = <0>;
+                       intel,sio-acpi-mode;
+                       #address-cells = <1>;
+                       #size-cells = <0>;
+
+                       i2s: shim {
+                               compatible = "intel,broadwell-i2s";
+                               #sound-dai-cells = <1>;
+                               reg = <0xfb000 0xfc000 0xfd000>;
+                       };
                };
 

[snip]

drivers/sound/Makefile obj-$(CONFIG_SOUND_MAX98095) += max98095.o maxim_codec.o · line 20

Quoted 10 lines
drivers/sound/Makefile +1 -1
index a9516e9c03..7b3c879aa2 100644
@@ -17,5 +17,5 @@ obj-$(CONFIG_SOUND_MAX98095)  += max98095.o maxim_codec.o
 obj-$(CONFIG_SOUND_INTEL_HDA)  += hda_codec.o
 obj-$(CONFIG_SOUND_I8254)      += i8254_beep.o
 obj-$(CONFIG_SOUND_RT5677)     += rt5677.o
-obj-$(CONFIG_INTEL_BROADWELL)  += broadwell_i2s.o #broadwell_sound.o
+obj-$(CONFIG_INTEL_BROADWELL)  += broadwell_i2s.o broadwell_sound.o

This should be in patch [32/33].

drivers/sound/Makefile obj-$(CONFIG_SOUND_MAX98095) += max98095.o maxim_codec.o

Quoted 2 lines
drivers/sound/Makefile +0 -1
 obj-$(CONFIG_SOUND_IVYBRIDGE)  += ivybridge_sound.o
--

Regards,
Bin

#73 lore raw

PATCH 33/33 x86: Add sound support for samus

Hi Bin,

Quoted 51 lines · Bin Meng

Hi Simon,

Quoted 11 lines · Simon Glass

Enable sound on samus using the broadwell I2S and an RT5677 audio codec.

---

 arch/x86/dts/chromebook_samus.dts  | 49 +++++++++++++++++++++++++++---
 configs/chromebook_samus_defconfig |  9 ++++++
 drivers/sound/Makefile             |  2 +-
 3 files changed, 55 insertions(+), 5 deletions(-)

Except one comment below:

Quoted 28 lines
arch/x86/dts/chromebook_samus.dts +14 -4
index b58936b4ac..ad687ce2cc 100644
@@ -494,10 +494,20 @@
                        intel,pre-graphics-delay = <200>;
                };
 
-               me at 16,0 {
-                       reg = <0x0000b000 0 0 0 0>;
-                       compatible = "intel,me";
-                       u-boot,dm-pre-reloc;
+               adsp at 13,0 {
+                       reg = <0x00009800 0 0 0 0>;
+                       compatible = "intel,wildcatpoint-adsp";
+                       intel,adsp-d3-pg-enable = <0>;
+                       intel,adsp-sram-pg-enable = <0>;
+                       intel,sio-acpi-mode;
+                       #address-cells = <1>;
+                       #size-cells = <0>;
+
+                       i2s: shim {
+                               compatible = "intel,broadwell-i2s";
+                               #sound-dai-cells = <1>;
+                               reg = <0xfb000 0xfc000 0xfd000>;
+                       };
                };
 

[snip]

Quoted 12 lines

drivers/sound/Makefile obj-$(CONFIG_SOUND_MAX98095) += max98095.o maxim_codec.o · line 20

Quoted 10 lines
drivers/sound/Makefile +1 -1
index a9516e9c03..7b3c879aa2 100644
@@ -17,5 +17,5 @@ obj-$(CONFIG_SOUND_MAX98095)  += max98095.o maxim_codec.o
 obj-$(CONFIG_SOUND_INTEL_HDA)  += hda_codec.o
 obj-$(CONFIG_SOUND_I8254)      += i8254_beep.o
 obj-$(CONFIG_SOUND_RT5677)     += rt5677.o
-obj-$(CONFIG_INTEL_BROADWELL)  += broadwell_i2s.o #broadwell_sound.o
+obj-$(CONFIG_INTEL_BROADWELL)  += broadwell_i2s.o broadwell_sound.o

This should be in patch [32/33].

Yes, but see my previous comment.

Quoted 6 lines

drivers/sound/Makefile obj-$(CONFIG_SOUND_MAX98095) += max98095.o maxim_codec.o

Quoted 3 lines
drivers/sound/Makefile +0 -1
 obj-$(CONFIG_SOUND_IVYBRIDGE)  += ivybridge_sound.o
--

Regards,
Bin

Regards,
Simon