From patchwork Mon Dec 10 17:37:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010562 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="d42rjyM7"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9Kw1n0vz9s3Z for ; Tue, 11 Dec 2018 04:39:00 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 01F47C2286F; Mon, 10 Dec 2018 17:38:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 1CCA5C22629; Mon, 10 Dec 2018 17:38:09 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D5EBDC21FE5; Mon, 10 Dec 2018 17:38:05 +0000 (UTC) Received: from mail-yb1-f199.google.com (mail-yb1-f199.google.com [209.85.219.199]) by lists.denx.de (Postfix) with ESMTPS id 57F7FC21FD5 for ; Mon, 10 Dec 2018 17:38:05 +0000 (UTC) Received: by mail-yb1-f199.google.com with SMTP id e137so8109441ybc.8 for ; Mon, 10 Dec 2018 09:38:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=B1O8Q36XBa/rTYHMnyVcht4eTEuCzgVaArF29lN0j2Y=; b=d42rjyM7+KzEqP7YPpi39+j3IE4Ivy+O31tA0VQP+pHC8T7OibGB2SboKIOTW8ReHY J9iNgsrKE2x/p3hBFzc9jhDDSkqOXn6am1cLI4Yc2PL1Vu+dRh16fKPgsxan9pLsYWXr q68B9yHVyn6Zw4mLM89bWPbom9QJVD5rK9u+8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=B1O8Q36XBa/rTYHMnyVcht4eTEuCzgVaArF29lN0j2Y=; b=o723dKehAsNGTIFVT9DGFLIJ7tqQdolyDeaNkZynrK3lslW8Dx56GXjRQ73PJcuWvp ARsp1r6FoaLgyYnOF847x+V7SNC+HZu2Ddda9AoEuK+NyqKUpgcDhPizmsRJh4t+YBGP MKrdaB2JaFWeBYz0R4SxqQ1AXKhbIQ5upRRS3V2nxGOvlz8DKvn3rS8yGQwYwyDTEh+W HPCbSyG5yRMgrBW7rNoxYPaoTywCeZc3PaBKClhexlrBmqPoaDiT/6CiEygsFkzY4nWH XAAvTyQRfa8ywC1YLdjVCNMBJmSN447vr0PEA96Z5tLxaP8llQumTpfteXUlh5NOmRuT j6dg== X-Gm-Message-State: AA+aEWaskYiO8AIADwNrZqq3C/bGICmwO9/QWkwwZ/XzJ/psKNCsZn2F 7VgNjgxmO3SFoLghD9DIA74ZloOMEoLMlTVK X-Google-Smtp-Source: AFSGD/V3Q2tcIllOenNYyBo1Yf9ARLVLFJZeGRAwQTY2k++nY29KJ7D3ArSp/xTo11/cgpLKASdUEldpCrMkoA+h X-Received: by 2002:a25:748a:: with SMTP id p132mr7489580ybc.103.1544463484153; Mon, 10 Dec 2018 09:38:04 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:30 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-2-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 01/22] dm: sound: exynos: Correct codec bus addresses X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" For snow the codec is at address 0x11 on the i2c bus, in 7-bit format. The device tree and code are in 8-bit format (i.e. shifted left one bit). Fix both. Fix pit in a similar way. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: - Add fix for pit and pi also - Fix up tabs in this commit instead of the later one arch/arm/dts/exynos5250-snow.dts | 4 ++-- arch/arm/dts/exynos5420-peach-pit.dts | 8 ++++---- arch/arm/dts/exynos5800-peach-pi.dts | 8 ++++---- drivers/sound/max98095.c | 3 +-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/arch/arm/dts/exynos5250-snow.dts b/arch/arm/dts/exynos5250-snow.dts index e99f6e72bf6..cb5067b9669 100644 --- a/arch/arm/dts/exynos5250-snow.dts +++ b/arch/arm/dts/exynos5250-snow.dts @@ -214,8 +214,8 @@ }; }; - soundcodec@22 { - reg = <0x22>; + soundcodec@11 { + reg = <0x11>; compatible = "maxim,max98095-codec"; }; }; diff --git a/arch/arm/dts/exynos5420-peach-pit.dts b/arch/arm/dts/exynos5420-peach-pit.dts index c86f9d9035d..bd0a9c116d4 100644 --- a/arch/arm/dts/exynos5420-peach-pit.dts +++ b/arch/arm/dts/exynos5420-peach-pit.dts @@ -69,10 +69,10 @@ i2c@12CD0000 { /* i2c7 */ clock-frequency = <100000>; - soundcodec@20 { - reg = <0x20>; - compatible = "maxim,max98090-codec"; - }; + soundcodec@10 { + reg = <0x10>; + compatible = "maxim,max98090-codec"; + }; edp-lvds-bridge@48 { compatible = "parade,ps8625"; diff --git a/arch/arm/dts/exynos5800-peach-pi.dts b/arch/arm/dts/exynos5800-peach-pi.dts index 7498519d6c6..239781b34bb 100644 --- a/arch/arm/dts/exynos5800-peach-pi.dts +++ b/arch/arm/dts/exynos5800-peach-pi.dts @@ -81,10 +81,10 @@ i2c@12CD0000 { /* i2c7 */ clock-frequency = <100000>; - soundcodec@20 { - reg = <0x20>; - compatible = "maxim,max98090-codec"; - }; + soundcodec@10 { + reg = <0x10>; + compatible = "maxim,max98090-codec"; + }; }; sound@3830000 { diff --git a/drivers/sound/max98095.c b/drivers/sound/max98095.c index 6a98dac04bb..7a3dbd09840 100644 --- a/drivers/sound/max98095.c +++ b/drivers/sound/max98095.c @@ -569,8 +569,7 @@ int max98095_init(const void *blob, enum en_max_audio_interface aif_id, i2c_set_bus_num(pcodec_info.i2c_bus); - /* shift the device address by 1 for 7 bit addressing */ - max98095_info.i2c_addr = pcodec_info.i2c_dev_addr >> 1; + max98095_info.i2c_addr = pcodec_info.i2c_dev_addr; ret = max98095_device_init(&max98095_info); if (ret < 0) { debug("%s: max98095 codec chip init failed\n", __func__); From patchwork Mon Dec 10 17:37:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010569 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Z7HZtiJm"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9Pr549Yz9s3l for ; Tue, 11 Dec 2018 04:42:24 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 6411BC22824; Mon, 10 Dec 2018 17:39:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id C2AABC22828; Mon, 10 Dec 2018 17:38:20 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id DE4DBC22828; Mon, 10 Dec 2018 17:38:11 +0000 (UTC) Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by lists.denx.de (Postfix) with ESMTPS id CC741C225E5 for ; Mon, 10 Dec 2018 17:38:06 +0000 (UTC) Received: by mail-io1-f72.google.com with SMTP id s8so11957638iob.2 for ; Mon, 10 Dec 2018 09:38:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=TX5y+GhzebIWKIP4mKVpiY73//HJfFpTlVzQ5YUisoE=; b=Z7HZtiJmVdpF57KNQzSZ8FaIE6qW248xQwOb4AhvrX57NST/j1nEpxW40bMEVp8q9W 6tVtJcrABDcu63Ebuh4quLod5nEKuxz5qfv2wiabpyZElioCUi95CL3cXwhyXeeJ3EuM stcTCa2SsHjRZr/ahnG0G00YnNk3Cne6VHG2g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=TX5y+GhzebIWKIP4mKVpiY73//HJfFpTlVzQ5YUisoE=; b=TFlvyWM6ZlVUspm4LZWsd5TmVnWotPds9Dh+tVApR9APjI1I2bL6UbrJDKjbcp/Hxh ZwcDLrHXrwtyaVOyEw1dQbe6A411WkbOS1j/LwRFYl7RoxwqEA6QgJgidpeE5ZUpSe2Y xNGGt2gJ25XT6IdSbV9BBTHsFTqzAGOEUNNKpPHzLjVOFkRFGOmLy0q4zLG7zCBz7GDY UO9w1OF2dqtaYfuBRI1bO2zKV8/p/955XXLq+1SNwEgGOrcvJIpjYP/EVjKSj1qwwEm/ kNMBVKrPJLfQACge++/sQWKyndyCz7VZIWVIZwGP9G6TI98cqmatj/uf8JB7gBEr0c8g vjKg== X-Gm-Message-State: AA+aEWa/XU3nKS/GbugGFEArOzb6LIxUAC9+r9hHvIV7YbHEj9xjJAti sL5o6f4s58BUcLA1Ig2OwU95QLZ8juPMA100 X-Google-Smtp-Source: AFSGD/V+zj9O9ANnAYLt/883htNzJCjD7vIvfCL1tdXmrSPb0UYKtqbuDigfUDJKnYKSZcbgBhpoL76NuQTz82Ys X-Received: by 2002:a24:15:: with SMTP id 21mr10065415ita.27.1544463485779; Mon, 10 Dec 2018 09:38:05 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:31 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-3-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 02/22] dm: sound: Create an option to use driver model for sound X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The U-Boot sound system provides basic support for beeping. At present it does not use driver model, but it needs to be converted. Add an option to enable driver model for sound. For now it is not connected to anything. Future work will add drivers which use this option. It will then be removed once everything is converted. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: - Use Kconfig instead of defconfig to define DM_SOUND arch/Kconfig | 1 + drivers/sound/Kconfig | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 947070fdd35..35e2712fce9 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -116,6 +116,7 @@ config SANDBOX imply VIRTIO_SANDBOX imply VIRTIO_BLK imply VIRTIO_NET + imply DM_SOUND config SH bool "SuperH architecture" diff --git a/drivers/sound/Kconfig b/drivers/sound/Kconfig index 5de86c05c60..93f6c36af32 100644 --- a/drivers/sound/Kconfig +++ b/drivers/sound/Kconfig @@ -12,6 +12,12 @@ config SOUND audio codecs are called from the sound-i2s code. This could be converted to driver model. +config DM_SOUND + bool "Use driver model for sound" + help + Enable this option to use driver model for sound devices. This is a + migration option and will be removed. + config I2S bool "Enable I2S support" depends on SOUND From patchwork Mon Dec 10 17:37:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010565 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ZiE1Gtr/"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9MW3YYsz9s3l for ; Tue, 11 Dec 2018 04:40:23 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 406A9C2283F; Mon, 10 Dec 2018 17:39:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id E8D24C2282B; Mon, 10 Dec 2018 17:38:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0CF5CC22687; Mon, 10 Dec 2018 17:38:12 +0000 (UTC) Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by lists.denx.de (Postfix) with ESMTPS id 320A8C2265E for ; Mon, 10 Dec 2018 17:38:08 +0000 (UTC) Received: by mail-io1-f72.google.com with SMTP id b21so11710434ioj.8 for ; Mon, 10 Dec 2018 09:38:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=cYROHGh1vEA4aS6SQoNWeooqe7zLhIcxcWW9Cn9bZ/A=; b=ZiE1Gtr/oLN/Dk36vfrq0HrdIFNiW8bR/hoF+3JaUsmfMLMZossJHo7hL/jB//cBnP RVsNUdDULhfjUVj0Oj85ww4C5H8kjkqG8tYoScK1cuc8FXhht0Ag4KkyBnfZ82mN2hxr 6/91P40XAYyzjr4fM024T1Vnv5fxpZ/W9uE0Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=cYROHGh1vEA4aS6SQoNWeooqe7zLhIcxcWW9Cn9bZ/A=; b=LQqtBzBhtm2rjT7vFDYIt82BjxrQQdeUyyoOwIJ+JtLUPgYq1q4HvxWxaHd+F/K7tS pPTbDff1EaeUQP3Sm3WBaVhmBpelnF8oQDpePIVK86nre7oKIW4y1iRNbP9D3OMIci7K 1OJShzQ5TxjmLs4P0M07ZJ0miZtJ+t20QSWOs9iMEZrn5yr9wHcjDisdE23WReeZ3Arj 93BxtGooHeCBR7HBJc6Un4bQsmnLqeM3U1xWpdpMZcxm+SM+AWVX4FrIqga20zycq6Cp 8WHAjq//bw6XWKI0hz2Rkg/wflhP/NpeQs8NNsq6DfAZG37ViWu/avMn21KpeHYOCVzY lL2A== X-Gm-Message-State: AA+aEWb7KtPtAI5Lk3KXdp2SHnBhKteLJIvb7h0alEs/TBil9lkXiUe6 KIO3oUexnij/9TiHx3OneYqwCKgwS8p8YuOS X-Google-Smtp-Source: AFSGD/WOmFWGS65da2lttd1gcFnksNLtZd+IWfDkO91xB9f6OvtAsgVprK6gD/woOWepCyx12YCFL/UmC55x3s/S X-Received: by 2002:a24:4597:: with SMTP id c23mr10504634itd.20.1544463487233; Mon, 10 Dec 2018 09:38:07 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:32 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-4-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 03/22] dm: sound: Rename samsung_i2s_priv to i2s_uc_priv X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This structure contains information that is likely needed by any i2s driver so it seems useful to attach it to the (forthcoming) i2c uclass. For now, just rename it. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: None drivers/sound/samsung-i2s.c | 4 ++-- drivers/sound/sound-i2s.c | 10 +++++----- include/i2s.h | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/sound/samsung-i2s.c b/drivers/sound/samsung-i2s.c index c07d3cdb4c8..5cd585808ab 100644 --- a/drivers/sound/samsung-i2s.c +++ b/drivers/sound/samsung-i2s.c @@ -255,7 +255,7 @@ static int i2s_set_samplesize(struct i2s_reg *i2s_reg, unsigned int blc) return 0; } -int i2s_transfer_tx_data(struct samsung_i2s_priv *pi2s_tx, unsigned int *data, +int i2s_transfer_tx_data(struct i2s_uc_priv *pi2s_tx, unsigned int *data, unsigned long data_size) { int i; @@ -293,7 +293,7 @@ int i2s_transfer_tx_data(struct samsung_i2s_priv *pi2s_tx, unsigned int *data, return 0; } -int i2s_tx_init(struct samsung_i2s_priv *pi2s_tx) +int i2s_tx_init(struct i2s_uc_priv *pi2s_tx) { int ret; struct i2s_reg *i2s_reg = diff --git a/drivers/sound/sound-i2s.c b/drivers/sound/sound-i2s.c index 106842a23db..ed130750b2e 100644 --- a/drivers/sound/sound-i2s.c +++ b/drivers/sound/sound-i2s.c @@ -20,15 +20,15 @@ #define SOUND_400_HZ 400 #define SOUND_BITS_IN_BYTE 8 -static struct samsung_i2s_priv g_i2stx_pri; +static struct i2s_uc_priv g_i2stx_pri; /* * get_sound_i2s_values gets values for i2s parameters * - * @param samsung_i2s_priv i2s transmitter transfer param structure + * @param i2s_uc_priv i2s transmitter transfer param structure * @param blob FDT blob if enabled else NULL */ -static int get_sound_i2s_values(struct samsung_i2s_priv *i2s, const void *blob) +static int get_sound_i2s_values(struct i2s_uc_priv *i2s, const void *blob) { int node; int error = 0; @@ -97,7 +97,7 @@ static int get_sound_i2s_values(struct samsung_i2s_priv *i2s, const void *blob) * @param pi2s_tx i2s parameters required by codec * @return int value, 0 for success */ -static int codec_init(const void *blob, struct samsung_i2s_priv *pi2s_tx) +static int codec_init(const void *blob, struct i2s_uc_priv *pi2s_tx) { int ret; const char *codectype; @@ -145,7 +145,7 @@ static int codec_init(const void *blob, struct samsung_i2s_priv *pi2s_tx) int sound_init(const void *blob) { int ret; - struct samsung_i2s_priv *pi2s_tx = &g_i2stx_pri; + struct i2s_uc_priv *pi2s_tx = &g_i2stx_pri; /* Get the I2S Values */ if (get_sound_i2s_values(pi2s_tx, blob) < 0) { diff --git a/include/i2s.h b/include/i2s.h index 800473abd9c..f23862ca040 100644 --- a/include/i2s.h +++ b/include/i2s.h @@ -76,7 +76,7 @@ struct i2s_reg { }; /* This structure stores the i2s related information */ -struct samsung_i2s_priv { +struct i2s_uc_priv { unsigned int rfs; /* LR clock frame size */ unsigned int bfs; /* Bit slock frame size */ unsigned int audio_pll_clk; /* Audio pll frequency in Hz */ @@ -96,7 +96,7 @@ struct samsung_i2s_priv { * * @return int value 0 for success, -1 in case of error */ -int i2s_transfer_tx_data(struct samsung_i2s_priv *pi2s_tx, uint *data, +int i2s_transfer_tx_data(struct i2s_uc_priv *pi2s_tx, unsigned int *data, unsigned long data_size); /* @@ -106,6 +106,6 @@ int i2s_transfer_tx_data(struct samsung_i2s_priv *pi2s_tx, uint *data, * * @return int value 0 for success, -1 in case of error */ -int i2s_tx_init(struct samsung_i2s_priv *pi2s_tx); +int i2s_tx_init(struct i2s_uc_priv *pi2s_tx); #endif /* __I2S_H__ */ From patchwork Mon Dec 10 17:37:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010572 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="j4ohoLEQ"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9RF0f0hz9s3Z for ; Tue, 11 Dec 2018 04:43:37 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 9C3E9C22847; Mon, 10 Dec 2018 17:40:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A5245C22641; Mon, 10 Dec 2018 17:38:29 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D55CDC2260B; Mon, 10 Dec 2018 17:38:14 +0000 (UTC) Received: from mail-it1-f199.google.com (mail-it1-f199.google.com [209.85.166.199]) by lists.denx.de (Postfix) with ESMTPS id B5188C227AA for ; Mon, 10 Dec 2018 17:38:09 +0000 (UTC) Received: by mail-it1-f199.google.com with SMTP id g7so15231623itg.7 for ; Mon, 10 Dec 2018 09:38:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=76AWmU01r75qEEqYPWvdzZkfY3PMSgi2gq+vfSkOKLs=; b=j4ohoLEQfl7PO8xUHIj+GTPU/sJDvNftylimZy15zmAzr7/ur7FU1iUCPfRVi7Yaa7 fEk6AAPxjtWwz0Uq07v6kEcJRMuNR1mMX9z5fF9uZWFvLC9SQYFKW3VD4XFFUOk1sMs7 im+hou75CY9XDZUlZ763Tok+vNLjhY4KUYhB0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=76AWmU01r75qEEqYPWvdzZkfY3PMSgi2gq+vfSkOKLs=; b=Z91HNunuDz8TjknvuXV8EfiOM4J/7g0wKrLLuwg0cnq6V49BCGuyC5gpBQQUC4Vl/R LiQS5MAkyrra/ha18VYDthKLhf55hvm7EjNejeRpRXTyUNps3U76EoCCivz2Mj/4tJOU XTI1cBZxLqcGCv8R7eUT1J+qL8Uhib9PvTih/HN3VPzWpvZZrpVtDDT0ZecZc6+b0wfc 3bo8gLW62TrgfDjvrL8/f0izSYqMUiPq6InbQAl63JIYlvhvjby1R/oHnsPNQgC7ej93 SWcuBDzUKiLesiYMQ/z/v6h6aVODBiGKOo2MxiALoTyol9W5BOjyLJr0gBXChNGAhJTi oVRw== X-Gm-Message-State: AA+aEWZDiG93ph2/K81uz0MUlMn5pdYKnAvbQOC7wmjNRjLJx1aZ/rDo nDwH4OI0SXFt1hNIdmBD8VQzYvsWAyo+CuJB X-Google-Smtp-Source: AFSGD/VoMv95oCF0/N66WdqFoF3R0kiyE5yhQBQwyvXRmOn9oMVYXTrvcqhi6wMJPpSw2xBP9+IpjHWt90ZTGfnh X-Received: by 2002:a24:594f:: with SMTP id p76mr10716390itb.10.1544463488702; Mon, 10 Dec 2018 09:38:08 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:33 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-5-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 04/22] dm: sound: Create a uclass for audio codecs X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" An audio codec provides a way to convert digital data to sound and vice versa. Add a simple uclass which just supports setting the parameters for the codec. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: None arch/sandbox/dts/test.dts | 7 ++++- arch/sandbox/include/asm/test.h | 10 ++++++ drivers/sound/Makefile | 1 + drivers/sound/codec-uclass.c | 26 ++++++++++++++++ drivers/sound/sandbox.c | 55 +++++++++++++++++++++++++++++++++ include/audio_codec.h | 48 ++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + test/dm/Makefile | 1 + test/dm/audio.c | 34 ++++++++++++++++++++ 9 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 drivers/sound/codec-uclass.c create mode 100644 include/audio_codec.h create mode 100644 test/dm/audio.c diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 082fcec3f9e..73425b125a9 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -42,7 +42,12 @@ osd0 = "/osd"; }; - cros_ec: cros-ec { + audio: audio-codec { + compatible = "sandbox,audio-codec"; + #sound-dai-cells = <1>; + }; + + cros_ec: cros-ec { reg = <0 0>; compatible = "google,cros-ec-sandbox"; diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 5e818392959..f70e0d84177 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -121,4 +121,14 @@ int sandbox_pwm_get_config(struct udevice *dev, uint channel, uint *period_nsp, */ void sandbox_sf_set_block_protect(struct udevice *dev, int bp_mask); +/** + * sandbox_get_codec_params() - Read back codec parameters + * + * This reads back the parameters set by audio_codec_set_params() for the + * sandbox audio driver. Arguments are as for that function. + */ +void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep, + int *mclk_freqp, int *bits_per_samplep, + uint *channelsp); + #endif diff --git a/drivers/sound/Makefile b/drivers/sound/Makefile index 696c5aecbe9..ae5fabed846 100644 --- a/drivers/sound/Makefile +++ b/drivers/sound/Makefile @@ -4,6 +4,7 @@ # R. Chandrasekar obj-$(CONFIG_SOUND) += sound.o +obj-$(CONFIG_DM_SOUND) += codec-uclass.o obj-$(CONFIG_I2S) += sound-i2s.o obj-$(CONFIG_I2S_SAMSUNG) += samsung-i2s.o obj-$(CONFIG_SOUND_SANDBOX) += sandbox.o diff --git a/drivers/sound/codec-uclass.c b/drivers/sound/codec-uclass.c new file mode 100644 index 00000000000..1ec77acfc1c --- /dev/null +++ b/drivers/sound/codec-uclass.c @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2018 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include + +int audio_codec_set_params(struct udevice *dev, int interface, int rate, + int mclk_freq, int bits_per_sample, uint channels) +{ + struct audio_codec_ops *ops = audio_codec_get_ops(dev); + + if (!ops->set_params) + return -ENOSYS; + + return ops->set_params(dev, interface, rate, mclk_freq, bits_per_sample, + channels); +} + +UCLASS_DRIVER(audio_codec) = { + .id = UCLASS_AUDIO_CODEC, + .name = "audio-codec", +}; diff --git a/drivers/sound/sandbox.c b/drivers/sound/sandbox.c index 94eff542824..d24eb9ae9ce 100644 --- a/drivers/sound/sandbox.c +++ b/drivers/sound/sandbox.c @@ -4,9 +4,19 @@ */ #include +#include +#include #include #include +struct sandbox_codec_priv { + int interface; + int rate; + int mclk_freq; + int bits_per_sample; + uint channels; +}; + int sound_play(uint32_t msec, uint32_t frequency) { sandbox_sdl_sound_start(frequency); @@ -20,3 +30,48 @@ int sound_init(const void *blob) { return sandbox_sdl_sound_init(); } + +void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep, + int *mclk_freqp, int *bits_per_samplep, + uint *channelsp) +{ + struct sandbox_codec_priv *priv = dev_get_priv(dev); + + *interfacep = priv->interface; + *ratep = priv->rate; + *mclk_freqp = priv->mclk_freq; + *bits_per_samplep = priv->bits_per_sample; + *channelsp = priv->channels; +} + +static int sandbox_codec_set_params(struct udevice *dev, int interface, + int rate, int mclk_freq, + int bits_per_sample, uint channels) +{ + struct sandbox_codec_priv *priv = dev_get_priv(dev); + + priv->interface = interface; + priv->rate = rate; + priv->mclk_freq = mclk_freq; + priv->bits_per_sample = bits_per_sample; + priv->channels = channels; + + return 0; +} + +static const struct audio_codec_ops sandbox_codec_ops = { + .set_params = sandbox_codec_set_params, +}; + +static const struct udevice_id sandbox_codec_ids[] = { + { .compatible = "sandbox,audio-codec" }, + { } +}; + +U_BOOT_DRIVER(sandbox_codec) = { + .name = "sandbox_codec", + .id = UCLASS_AUDIO_CODEC, + .of_match = sandbox_codec_ids, + .ops = &sandbox_codec_ops, + .priv_auto_alloc_size = sizeof(struct sandbox_codec_priv), +}; diff --git a/include/audio_codec.h b/include/audio_codec.h new file mode 100644 index 00000000000..25870995469 --- /dev/null +++ b/include/audio_codec.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2018 Google LLC + * Written by Simon Glass + */ + +#ifndef __AUDIO_CODEC_H__ +#define __AUDIO_CODEC_H__ + +/* + * An audio codec turns digital data into sound with various parameters to + * control its operation. + */ + +/* Operations for sound */ +struct audio_codec_ops { + /** + * set_params() - Set audio codec parameters + * + * @dev: Sound device + * @inteface: Interface number to use on codec + * @rate: Sampling rate in Hz + * @mclk_freq: Codec clock frequency in Hz + * @bits_per_sample: Must be 16 or 24 + * @channels: Number of channels to use (1=mono, 2=stereo) + * @return 0 if OK, -ve on error + */ + int (*set_params)(struct udevice *dev, int interface, int rate, + int mclk_freq, int bits_per_sample, uint channels); +}; + +#define audio_codec_get_ops(dev) ((struct audio_codec_ops *)(dev)->driver->ops) + +/** + * audio_codec_set_params() - Set audio codec parameters + * + * @dev: Sound device + * @inteface: Interface number to use on codec + * @rate: Sampling rate in Hz + * @mclk_freq: Codec clock frequency in Hz + * @bits_per_sample: Must be 16 or 24 + * @channels: Number of channels to use (1=mono, 2=stereo) + * @return 0 if OK, -ve on error + */ +int audio_codec_set_params(struct udevice *dev, int interface, int rate, + int mclk_freq, int bits_per_sample, uint channels); + +#endif /* __AUDIO_CODEC_H__ */ diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 037af0460c6..50aa35ee246 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -29,6 +29,7 @@ enum uclass_id { /* U-Boot uclasses start here - in alphabetical order */ UCLASS_ADC, /* Analog-to-digital converter */ UCLASS_AHCI, /* SATA disk controller */ + UCLASS_AUDIO_CODEC, /* Audio codec with control and data path */ UCLASS_AXI, /* AXI bus */ UCLASS_BLK, /* Block device */ UCLASS_BOARD, /* Device information from hardware */ diff --git a/test/dm/Makefile b/test/dm/Makefile index 2c9081e4dd6..ef450b7ed81 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o # subsystem you must add sandbox tests here. obj-$(CONFIG_UT_DM) += core.o ifneq ($(CONFIG_SANDBOX),) +obj-$(CONFIG_DM_SOUND) += audio.o obj-$(CONFIG_BLK) += blk.o obj-$(CONFIG_BOARD) += board.o obj-$(CONFIG_CLK) += clk.o diff --git a/test/dm/audio.c b/test/dm/audio.c new file mode 100644 index 00000000000..77c3a3625bd --- /dev/null +++ b/test/dm/audio.c @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2018 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include + +/* Basic test of the audio codec uclass */ +static int dm_test_audio(struct unit_test_state *uts) +{ + int interface, rate, mclk_freq, bits_per_sample; + struct udevice *dev; + uint channels; + + /* check probe success */ + ut_assertok(uclass_first_device_err(UCLASS_AUDIO_CODEC, &dev)); + ut_assertok(audio_codec_set_params(dev, 1, 2, 3, 4, 5)); + sandbox_get_codec_params(dev, &interface, &rate, &mclk_freq, + &bits_per_sample, &channels); + ut_asserteq(1, interface); + ut_asserteq(2, rate); + ut_asserteq(3, mclk_freq); + ut_asserteq(4, bits_per_sample); + ut_asserteq(5, channels); + + return 0; +} +DM_TEST(dm_test_audio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Mon Dec 10 17:37:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010570 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="lXlqBRMx"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9QC5VZSz9s3l for ; Tue, 11 Dec 2018 04:42:43 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 730D6C22403; Mon, 10 Dec 2018 17:41:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 70BECC22687; Mon, 10 Dec 2018 17:38:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 11166C22618; Mon, 10 Dec 2018 17:38:15 +0000 (UTC) Received: from mail-it1-f197.google.com (mail-it1-f197.google.com [209.85.166.197]) by lists.denx.de (Postfix) with ESMTPS id 21193C227FC for ; Mon, 10 Dec 2018 17:38:11 +0000 (UTC) Received: by mail-it1-f197.google.com with SMTP id y86so15266500ita.2 for ; Mon, 10 Dec 2018 09:38:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=W79hSeps504/Rny4IyTxBJLt3KTrClMaH4ykKyWp1Oc=; b=lXlqBRMxyov6B9/w/X/rbm9czJcOxHzTfxbWCUvVo51R4rFCi/gTezheuIx+STjaB+ 4p2B6cTSF4shZyXK8Nsqyj2dHNinsHnokQMEhnPyPAfAOj7cMuGc3TdD9pskhmQK4HLr suo2A2hfaRC9DWm1RgAcQXsejrpDJW8HY1TBk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=W79hSeps504/Rny4IyTxBJLt3KTrClMaH4ykKyWp1Oc=; b=HAV5HiVzovG2SLYk1QNk193ndBQVt43yqTsaQgP/m7LTlVOtSPwqRcwO19RvvDdosZ ooh4yLUqnsBu9ts9ynDyw14hBZvzPtY0LzytYfvEW9w7ITTGkabxyXQ4dxN6kTj26Msw akuj/rQDBFd16zkfRpjWu5T3B2Q/dK/sk3MpmJIqYSZ+YqgGB1cNlMz4b0fJwX6Ptmun lKWO0i2m9xcqBZHyQAhP2fXOFbxHpo7kQ/7956sBEa3sBQgmpxMLB+w4nUnZTKxNWn8E zwc3Hc239WoOfavRhU1qVGA3c1hav/ehXlsD9Iu+8kOXKCHWmJQ8USw9ZGAmHPiMUaHX wVqw== X-Gm-Message-State: AA+aEWbeULG5wBM1zcr6ht7tr4vV+jFjsLy6rq1oQXc6rgxz95Elpn7G 9lw7nP3JgINlHxpEE6LOF1it1Y1OxTwW0aLp X-Google-Smtp-Source: AFSGD/Ur7hJyHkhJjbRjwn1vforgJrCE/6wDCDis72yePv0+7GZ1v0bRntCE6B+TPEN0Iw1hqyV1fdZjP6WFqqAD X-Received: by 2002:a24:5f93:: with SMTP id r141mr10562227itb.4.1544463490103; Mon, 10 Dec 2018 09:38:10 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:34 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-6-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 05/22] dm: sound: Create a uclass for i2s X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The i2s bus is commonly used with audio codecs. It provides a way to stream digital data sychronously in both directions. U-Boot only supports audio output, so this uclass is very simple, with a single tx_data() method. Add a uclass and a test for i2s. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: None arch/sandbox/dts/test.dts | 7 +++- arch/sandbox/include/asm/test.h | 10 ++++++ drivers/sound/Makefile | 1 + drivers/sound/i2s-uclass.c | 25 ++++++++++++++ drivers/sound/sandbox.c | 60 ++++++++++++++++++++++++++++++++- include/dm/uclass-id.h | 1 + include/i2s.h | 32 +++++++++++++++--- test/dm/Makefile | 1 + test/dm/i2s.c | 32 ++++++++++++++++++ 9 files changed, 163 insertions(+), 6 deletions(-) create mode 100644 drivers/sound/i2s-uclass.c create mode 100644 test/dm/i2s.c diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 73425b125a9..28e2818ff37 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -47,7 +47,7 @@ #sound-dai-cells = <1>; }; - cros_ec: cros-ec { + cros_ec: cros-ec { reg = <0 0>; compatible = "google,cros-ec-sandbox"; @@ -378,6 +378,11 @@ u-boot,dm-pre-reloc; }; + i2s: i2s { + compatible = "sandbox,i2s"; + #sound-dai-cells = <1>; + }; + misc-test { compatible = "sandbox,misc_sandbox"; }; diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index f70e0d84177..71bd50bd5bc 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -131,4 +131,14 @@ void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep, int *mclk_freqp, int *bits_per_samplep, uint *channelsp); +/** + * sandbox_get_i2s_sum() - Read back the sum of the audio data so far + * + * This data is provided to the sandbox driver by the I2S tx_data() method. + * + * @dev: Device to check + * @return sum of audio data + */ +int sandbox_get_i2s_sum(struct udevice *dev); + #endif diff --git a/drivers/sound/Makefile b/drivers/sound/Makefile index ae5fabed846..4aced9d22b9 100644 --- a/drivers/sound/Makefile +++ b/drivers/sound/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_SOUND) += sound.o obj-$(CONFIG_DM_SOUND) += codec-uclass.o +obj-$(CONFIG_DM_SOUND) += i2s-uclass.o obj-$(CONFIG_I2S) += sound-i2s.o obj-$(CONFIG_I2S_SAMSUNG) += samsung-i2s.o obj-$(CONFIG_SOUND_SANDBOX) += sandbox.o diff --git a/drivers/sound/i2s-uclass.c b/drivers/sound/i2s-uclass.c new file mode 100644 index 00000000000..b741e3952d1 --- /dev/null +++ b/drivers/sound/i2s-uclass.c @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2018 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include + +int i2s_tx_data(struct udevice *dev, void *data, uint data_size) +{ + struct i2s_ops *ops = i2s_get_ops(dev); + + if (!ops->tx_data) + return -ENOSYS; + + return ops->tx_data(dev, data, data_size); +} + +UCLASS_DRIVER(i2s) = { + .id = UCLASS_I2S, + .name = "i2s", + .per_device_auto_alloc_size = sizeof(struct i2s_uc_priv), +}; diff --git a/drivers/sound/sandbox.c b/drivers/sound/sandbox.c index d24eb9ae9ce..2f7c68be0c8 100644 --- a/drivers/sound/sandbox.c +++ b/drivers/sound/sandbox.c @@ -4,8 +4,9 @@ */ #include -#include #include +#include +#include #include #include @@ -17,6 +18,10 @@ struct sandbox_codec_priv { uint channels; }; +struct sandbox_i2s_priv { + int sum; /* Use to sum the provided audio data */ +}; + int sound_play(uint32_t msec, uint32_t frequency) { sandbox_sdl_sound_start(frequency); @@ -44,6 +49,13 @@ void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep, *channelsp = priv->channels; } +int sandbox_get_i2s_sum(struct udevice *dev) +{ + struct sandbox_i2s_priv *priv = dev_get_priv(dev); + + return priv->sum; +} + static int sandbox_codec_set_params(struct udevice *dev, int interface, int rate, int mclk_freq, int bits_per_sample, uint channels) @@ -59,6 +71,34 @@ static int sandbox_codec_set_params(struct udevice *dev, int interface, return 0; } +static int sandbox_i2s_tx_data(struct udevice *dev, void *data, + uint data_size) +{ + struct sandbox_i2s_priv *priv = dev_get_priv(dev); + int i; + + for (i = 0; i < data_size; i++) + priv->sum += ((uint8_t *)data)[i]; + + return 0; +} + +static int sandbox_i2s_probe(struct udevice *dev) +{ + struct i2s_uc_priv *uc_priv = dev_get_uclass_priv(dev); + + /* Use hard-coded values here */ + uc_priv->rfs = 256; + uc_priv->bfs = 32; + uc_priv->audio_pll_clk = 192000000; + uc_priv->samplingrate = 48000; + uc_priv->bitspersample = 16; + uc_priv->channels = 2; + uc_priv->id = 1; + + return 0; +} + static const struct audio_codec_ops sandbox_codec_ops = { .set_params = sandbox_codec_set_params, }; @@ -75,3 +115,21 @@ U_BOOT_DRIVER(sandbox_codec) = { .ops = &sandbox_codec_ops, .priv_auto_alloc_size = sizeof(struct sandbox_codec_priv), }; + +static const struct i2s_ops sandbox_i2s_ops = { + .tx_data = sandbox_i2s_tx_data, +}; + +static const struct udevice_id sandbox_i2s_ids[] = { + { .compatible = "sandbox,i2s" }, + { } +}; + +U_BOOT_DRIVER(sandbox_i2s) = { + .name = "sandbox_i2s", + .id = UCLASS_I2S, + .of_match = sandbox_i2s_ids, + .ops = &sandbox_i2s_ops, + .probe = sandbox_i2s_probe, + .priv_auto_alloc_size = sizeof(struct sandbox_i2s_priv), +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 50aa35ee246..7ee5491e0b5 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -48,6 +48,7 @@ enum uclass_id { UCLASS_I2C_EEPROM, /* I2C EEPROM device */ UCLASS_I2C_GENERIC, /* Generic I2C device */ UCLASS_I2C_MUX, /* I2C multiplexer */ + UCLASS_I2S, /* I2S bus */ UCLASS_IDE, /* IDE device */ UCLASS_IRQ, /* Interrupt controller */ UCLASS_KEYBOARD, /* Keyboard input device */ diff --git a/include/i2s.h b/include/i2s.h index f23862ca040..28f6184811c 100644 --- a/include/i2s.h +++ b/include/i2s.h @@ -87,17 +87,41 @@ struct i2s_uc_priv { unsigned int id; /* I2S controller id */ }; +/* Operations for i2s devices */ +struct i2s_ops { + /** + * tx_data() - Transmit audio data + * + * @dev: I2C device + * @data: Data buffer to play + * @data_size: Size of data buffer in bytes + * @return 0 if OK, -ve on error + */ + int (*tx_data)(struct udevice *dev, void *data, uint data_size); +}; + +#define i2s_get_ops(dev) ((struct i2s_ops *)(dev)->driver->ops) + +/** + * i2s_tx_data() - Transmit audio data + * + * @dev: I2C device + * @data: Data buffer to play + * @data_size: Size of data buffer in bytes + * @return 0 if OK, -ve on error + */ +int i2s_tx_data(struct udevice *dev, void *data, uint data_size); + /* * Sends the given data through i2s tx * * @param pi2s_tx pointer of i2s transmitter parameter structure. * @param data address of the data buffer - * @param data_size array size of the int buffer (total size / size of int) - * + * @param data_size size of the data (in bytes) * @return int value 0 for success, -1 in case of error */ -int i2s_transfer_tx_data(struct i2s_uc_priv *pi2s_tx, unsigned int *data, - unsigned long data_size); +int i2s_transfer_tx_data(struct i2s_uc_priv *pi2s_tx, void *data, + uint data_size); /* * Initialise i2s transmiter diff --git a/test/dm/Makefile b/test/dm/Makefile index ef450b7ed81..28ede9a6695 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -22,6 +22,7 @@ obj-$(CONFIG_FIRMWARE) += firmware.o obj-$(CONFIG_DM_GPIO) += gpio.o obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o obj-$(CONFIG_DM_I2C) += i2c.o +obj-$(CONFIG_DM_SOUND) += i2s.o obj-$(CONFIG_LED) += led.o obj-$(CONFIG_DM_MAILBOX) += mailbox.o obj-$(CONFIG_DM_MMC) += mmc.o diff --git a/test/dm/i2s.c b/test/dm/i2s.c new file mode 100644 index 00000000000..49ebc3523c0 --- /dev/null +++ b/test/dm/i2s.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2018 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include + +/* Basic test of the i2s codec uclass */ +static int dm_test_i2s(struct unit_test_state *uts) +{ + struct udevice *dev; + u8 data[3]; + + /* check probe success */ + ut_assertok(uclass_first_device_err(UCLASS_I2S, &dev)); + data[0] = 1; + data[1] = 4; + data[2] = 6; + ut_assertok(i2s_tx_data(dev, data, ARRAY_SIZE(data))); + ut_asserteq(11, sandbox_get_i2s_sum(dev)); + ut_assertok(i2s_tx_data(dev, data, 1)); + ut_asserteq(12, sandbox_get_i2s_sum(dev)); + + return 0; +} +DM_TEST(dm_test_i2s, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Mon Dec 10 17:37:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010567 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="FzEwgoWo"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9Nv0X9bz9s3l for ; Tue, 11 Dec 2018 04:41:35 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id A4951C22462; Mon, 10 Dec 2018 17:40:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id CF7AAC22623; Mon, 10 Dec 2018 17:38:23 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BA013C2265C; Mon, 10 Dec 2018 17:38:16 +0000 (UTC) Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by lists.denx.de (Postfix) with ESMTPS id 7B205C22610 for ; Mon, 10 Dec 2018 17:38:12 +0000 (UTC) Received: by mail-io1-f70.google.com with SMTP id v8so11748417ioh.11 for ; Mon, 10 Dec 2018 09:38:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=66vx5QcmK0iGMQxVR2/EpK16N/mjN21l8ow4HB4BHgU=; b=FzEwgoWoIjWSuSwX/1AuzgkGjoshruwR0D+kAG3ZWya0sYpovRkEwbZjedjBZndVKJ YSBxCPs0b1msepvIAZDzO3wan+xMYVYhsExNgROkvSn/rrqV8+tgghxe152Lbp3l9ItG 3yJ1d8f7D4Fy1u/gYOHL2vQhpUN2ohKT4gEaE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=66vx5QcmK0iGMQxVR2/EpK16N/mjN21l8ow4HB4BHgU=; b=lgi1zYJ8rJizbLkob3SjSLSQ+7pHV/2eFdHrdpfxfI5yY8pI7FoVfNFPzK5Iv/VTyR 1lzr1ZX2GQY83VN0AypobsO418Nor1pXKM8RC+Tyuh9trg4JqeaBqNV8syWFSH67DvEQ 3Vop1Od6nxmPzOSwap9AJFBRdKo3gkSDhy9SJvRyh6mLI72jPjIyLizQV0R5UxdyZSAX BuYEIVP4+JensW29DuArIZKUJYE3l0pRXGyu5R73D6vH2BfmeE1zcQhHB0JqNKmXAuds TKhJZFReXX43bFahWePH/+GRLi0spnyIPuJYGZMHtMlKjqfPE9rWNxA49EjSwux8UGl9 ArCg== X-Gm-Message-State: AA+aEWZKPB908OpwuyX9KMmuCO6t8Po5MfEM8Sp0V3fl/OyNt2GrN8rc QfYRn/6RZCzCaTzY4mKYdXmNIQmIBcqg/ev0 X-Google-Smtp-Source: AFSGD/XHNA4Ia8qdBqEijC+/V1+jpUTERidtiFbdHF6tDsAuKEJ8Sjo0+4o3iBzkLxddQMa/Hfh6chFWUKsEGXQP X-Received: by 2002:a24:4ac4:: with SMTP id k187mr10570302itb.8.1544463491494; Mon, 10 Dec 2018 09:38:11 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:35 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-7-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 06/22] dm: sandbox: Update sound to use two buffers X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" At present we use a single buffer for sound which means we cannot be playing one sound while queueing up the next. This wouldn't matter except that a long sound (more than a second) has to be created as a single buffer, thus using a lot of memory. To better mimic what real sound drivers do, add support for double buffering in sandbox. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: None arch/sandbox/cpu/sdl.c | 88 ++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 25 deletions(-) diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c index c7a8d945492..4dacdbf993f 100644 --- a/arch/sandbox/cpu/sdl.c +++ b/arch/sandbox/cpu/sdl.c @@ -13,6 +13,21 @@ enum { SAMPLE_RATE = 22050, }; +/** + * struct buf_info - a data buffer holding audio data + * + * @pos: Current position playing in audio buffer + * @size: Size of data in audio buffer (0=empty) + * @alloced: Allocated size of audio buffer (max size it can hold) + * @data: Audio data + */ +struct buf_info { + uint pos; + uint size; + uint alloced; + uint8_t *data; +}; + static struct sdl_info { SDL_Surface *screen; int width; @@ -20,12 +35,11 @@ static struct sdl_info { int depth; int pitch; uint frequency; - uint audio_pos; - uint audio_size; uint sample_rate; - uint8_t *audio_data; bool audio_active; bool inited; + int cur_buf; + struct buf_info buf[2]; } sdl; static void sandbox_sdl_poll_events(void) @@ -243,24 +257,37 @@ int sandbox_sdl_key_pressed(int keycode) void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len) { + struct buf_info *buf; int avail; + int i; - avail = sdl.audio_size - sdl.audio_pos; - if (avail < len) - len = avail; - - SDL_MixAudio(stream, sdl.audio_data + sdl.audio_pos, len, - SDL_MIX_MAXVOLUME); - sdl.audio_pos += len; - - /* Loop if we are at the end */ - if (sdl.audio_pos == sdl.audio_size) - sdl.audio_pos = 0; + for (i = 0; i < 2; i++) { + buf = &sdl.buf[sdl.cur_buf]; + avail = buf->size - buf->pos; + if (avail <= 0) { + sdl.cur_buf = 1 - sdl.cur_buf; + continue; + } + if (avail > len) + avail = len; + + SDL_MixAudio(stream, buf->data + buf->pos, avail, + SDL_MIX_MAXVOLUME); + buf->pos += avail; + len -= avail; + + /* Move to next buffer if we are at the end */ + if (buf->pos == buf->size) + buf->size = 0; + else + break; + } } int sandbox_sdl_sound_init(void) { SDL_AudioSpec wanted; + int i; if (sandbox_sdl_ensure_init()) return -1; @@ -276,13 +303,20 @@ int sandbox_sdl_sound_init(void) wanted.callback = sandbox_sdl_fill_audio; wanted.userdata = NULL; - sdl.audio_size = sizeof(uint16_t) * wanted.freq; - sdl.audio_data = malloc(sdl.audio_size); - if (!sdl.audio_data) { - printf("%s: Out of memory\n", __func__); - return -1; + for (i = 0; i < 2; i++) { + struct buf_info *buf = &sdl.buf[i]; + + buf->alloced = sizeof(uint16_t) * wanted.freq * wanted.channels; + buf->data = malloc(buf->alloced); + if (!buf->data) { + printf("%s: Out of memory\n", __func__); + if (i == 1) + free(sdl.buf[0].data); + return -1; + } + buf->pos = 0; + buf->size = 0; } - sdl.audio_pos = 0; if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { printf("Unable to initialize SDL audio: %s\n", SDL_GetError()); @@ -296,23 +330,27 @@ int sandbox_sdl_sound_init(void) } sdl.audio_active = true; sdl.sample_rate = wanted.freq; + sdl.cur_buf = 0; return 0; err: - free(sdl.audio_data); + for (i = 0; i < 2; i++) + free(sdl.buf[i].data); return -1; } int sandbox_sdl_sound_start(uint frequency) { + struct buf_info *buf = &sdl.buf[0]; + if (!sdl.audio_active) return -1; sdl.frequency = frequency; - sound_create_square_wave(sdl.sample_rate, - (unsigned short *)sdl.audio_data, - sdl.audio_size, frequency); - sdl.audio_pos = 0; + sound_create_square_wave(sdl.sample_rate, (unsigned short *)buf->data, + buf->alloced, frequency); + buf->pos = 0; + buf->size = buf->alloced; SDL_PauseAudio(0); return 0; From patchwork Mon Dec 10 17:37:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010573 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="QgUDzWPB"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9St2Q6Vz9s3Z for ; Tue, 11 Dec 2018 04:45:02 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id F2A43C2282E; Mon, 10 Dec 2018 17:45:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 6A17AC22629; Mon, 10 Dec 2018 17:38:39 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8B30DC225E2; Mon, 10 Dec 2018 17:38:18 +0000 (UTC) Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by lists.denx.de (Postfix) with ESMTPS id E359FC22666 for ; Mon, 10 Dec 2018 17:38:13 +0000 (UTC) Received: by mail-io1-f70.google.com with SMTP id m5so11816516ioj.15 for ; Mon, 10 Dec 2018 09:38:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=eEfptcU3yTTmco/+luDB2QV8jMINArlakhdMBUJ/ZlU=; b=QgUDzWPBZZiy+N2pnTpcNcu0T8E+9aevYGYbodjvaThlSDD4I0BHECG2x2HketH5+q 3n/aiR+obwIonWAc8QGRRidFuvGY3cyo31HB259uhoOFWzffzcHrii8lkPPFasDGaQC/ SSdk9+uPb5G8MriOo8U+v4iSJovCY3S5A0P0M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=eEfptcU3yTTmco/+luDB2QV8jMINArlakhdMBUJ/ZlU=; b=ioPKO12L93JqcYCJKxcliZSxK2X+vy6shmyjjcD7fqCNGFXhzjrWMs6ipHZ2H5h66G TRx15Kb8h7uUIM6/X5w/NxVLSEuRLPO9+bVVTOlcjWJAvnUnkYChHmDKC6bPRkUB1zub 5geysyjtDifNpW27Nj2Mu+cFrdNEqIOu1zHkDgBj8lwvvlrcyMZENLlWya2ysQh2h7tF 0DJl0GmfouiRMiXH3BK1ija//KvxepXNqbMlNRge0a/msw1bR0c1+qI+XBPKtNLGzrsm fWPQei+DH/H3GupFqPXPjo/rn2R3UH/x+Od/9k5soM1M7XvdfgnsL9FgfoLy8/6sm/re 2wSA== X-Gm-Message-State: AA+aEWb8E+WnqoXUqKsaRW3KpfyjxQtqvrI5Sd0Sa+O3RnUrQ0fWT+l/ hQvKwQkrrC47CEZzERg/wGUZkIqS622xMiu0 X-Google-Smtp-Source: AFSGD/UvlT6VZiq7/6U4v590FIluumozdZwxGtiByEFeZD3eAo4i6aLaQFMksVtw8noUyEhzp3IDqswQrZ2ydl1i X-Received: by 2002:a24:4ac4:: with SMTP id k187mr10570352itb.8.1544463492910; Mon, 10 Dec 2018 09:38:12 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:36 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-8-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 07/22] dm: sound: Create a uclass for sound X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The sound driver pulls together the audio codec and i2s drivers in order to actually make sounds. It supports setup() and play() methods. The sound_find_codec_i2s() function allows locating the linked codec and i2s devices. They can be referred to from uclass-private data. Add a uclass and a test for sound. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: - Update 'init' command to print the error code arch/sandbox/dts/test.dts | 11 +++ arch/sandbox/include/asm/test.h | 20 +++++ cmd/sound.c | 23 +++++- drivers/sound/Makefile | 1 + drivers/sound/sandbox.c | 67 +++++++++++++++++ drivers/sound/sound-uclass.c | 127 ++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/sound.h | 70 +++++++++++++++++- test/dm/Makefile | 1 + test/dm/sound.c | 34 +++++++++ 10 files changed, 351 insertions(+), 4 deletions(-) create mode 100644 drivers/sound/sound-uclass.c create mode 100644 test/dm/sound.c diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 28e2818ff37..cedf514382f 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -536,6 +536,17 @@ compatible = "sandbox,smem"; }; + sound { + compatible = "sandbox,sound"; + cpu { + sound-dai = <&i2s 0>; + }; + + codec { + sound-dai = <&audio 0>; + }; + }; + spi@0 { #address-cells = <1>; #size-cells = <0>; diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 71bd50bd5bc..74f96188220 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -141,4 +141,24 @@ void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep, */ int sandbox_get_i2s_sum(struct udevice *dev); +/** + * sandbox_get_setup_called() - Returns the number of times setup(*) was called + * + * This is used in the sound test + * + * @dev: Device to check + * @return call count for the setup() method + */ +int sandbox_get_setup_called(struct udevice *dev); + +/** + * sandbox_get_sound_sum() - Read back the sum of the sound data so far + * + * This data is provided to the sandbox driver by the sound play() method. + * + * @dev: Device to check + * @return sum of audio data + */ +int sandbox_get_sound_sum(struct udevice *dev); + #endif diff --git a/cmd/sound.c b/cmd/sound.c index d1cbc14f8df..77f51529259 100644 --- a/cmd/sound.c +++ b/cmd/sound.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -14,11 +15,20 @@ DECLARE_GLOBAL_DATA_PTR; /* Initilaise sound subsystem */ static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) { +#ifdef CONFIG_DM_SOUND + struct udevice *dev; +#endif int ret; +#ifdef CONFIG_DM_SOUND + ret = uclass_first_device_err(UCLASS_SOUND, &dev); + if (!ret) + ret = sound_setup(dev); +#else ret = sound_init(gd->fdt_blob); +#endif if (ret) { - printf("Initialise Audio driver failed\n"); + printf("Initialise Audio driver failed (ret=%d)\n", ret); return CMD_RET_FAILURE; } @@ -28,6 +38,9 @@ static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) /* play sound from buffer */ static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) { +#ifdef CONFIG_DM_SOUND + struct udevice *dev; +#endif int ret = 0; int msec = 1000; int freq = 400; @@ -37,9 +50,15 @@ static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) if (argc > 2) freq = simple_strtoul(argv[2], NULL, 10); +#ifdef CONFIG_DM_SOUND + ret = uclass_first_device_err(UCLASS_SOUND, &dev); + if (!ret) + ret = sound_beep(dev, msec, freq); +#else ret = sound_play(msec, freq); +#endif if (ret) { - printf("play failed"); + printf("Sound device failed to play (err=%d)\n", ret); return CMD_RET_FAILURE; } diff --git a/drivers/sound/Makefile b/drivers/sound/Makefile index 4aced9d22b9..70d32c6d6f6 100644 --- a/drivers/sound/Makefile +++ b/drivers/sound/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_SOUND) += sound.o obj-$(CONFIG_DM_SOUND) += codec-uclass.o obj-$(CONFIG_DM_SOUND) += i2s-uclass.o obj-$(CONFIG_I2S) += sound-i2s.o +obj-$(CONFIG_DM_SOUND) += sound-uclass.o obj-$(CONFIG_I2S_SAMSUNG) += samsung-i2s.o obj-$(CONFIG_SOUND_SANDBOX) += sandbox.o obj-$(CONFIG_SOUND_WM8994) += wm8994.o diff --git a/drivers/sound/sandbox.c b/drivers/sound/sandbox.c index 2f7c68be0c8..ee2635f41d2 100644 --- a/drivers/sound/sandbox.c +++ b/drivers/sound/sandbox.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -22,6 +23,12 @@ struct sandbox_i2s_priv { int sum; /* Use to sum the provided audio data */ }; +struct sandbox_sound_priv { + int setup_called; + int sum; /* Use to sum the provided audio data */ +}; + +#ifndef CONFIG_DM_SOUND int sound_play(uint32_t msec, uint32_t frequency) { sandbox_sdl_sound_start(frequency); @@ -30,6 +37,7 @@ int sound_play(uint32_t msec, uint32_t frequency) return 0; } +#endif /* CONFIG_DM_SOUND */ int sound_init(const void *blob) { @@ -56,6 +64,20 @@ int sandbox_get_i2s_sum(struct udevice *dev) return priv->sum; } +int sandbox_get_setup_called(struct udevice *dev) +{ + struct sandbox_sound_priv *priv = dev_get_priv(dev); + + return priv->setup_called; +} + +int sandbox_get_sound_sum(struct udevice *dev) +{ + struct sandbox_sound_priv *priv = dev_get_priv(dev); + + return priv->sum; +} + static int sandbox_codec_set_params(struct udevice *dev, int interface, int rate, int mclk_freq, int bits_per_sample, uint channels) @@ -96,9 +118,35 @@ static int sandbox_i2s_probe(struct udevice *dev) uc_priv->channels = 2; uc_priv->id = 1; + return sandbox_sdl_sound_init(); +} + +static int sandbox_sound_setup(struct udevice *dev) +{ + struct sandbox_sound_priv *priv = dev_get_priv(dev); + + priv->setup_called++; + return 0; } +static int sandbox_sound_play(struct udevice *dev, void *data, uint data_size) +{ + struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev); + struct sandbox_sound_priv *priv = dev_get_priv(dev); + int i; + + for (i = 0; i < data_size; i++) + priv->sum += ((uint8_t *)data)[i]; + + return i2s_tx_data(uc_priv->i2s, data, data_size); +} + +static int sandbox_sound_probe(struct udevice *dev) +{ + return sound_find_codec_i2s(dev); +} + static const struct audio_codec_ops sandbox_codec_ops = { .set_params = sandbox_codec_set_params, }; @@ -133,3 +181,22 @@ U_BOOT_DRIVER(sandbox_i2s) = { .probe = sandbox_i2s_probe, .priv_auto_alloc_size = sizeof(struct sandbox_i2s_priv), }; + +static const struct sound_ops sandbox_sound_ops = { + .setup = sandbox_sound_setup, + .play = sandbox_sound_play, +}; + +static const struct udevice_id sandbox_sound_ids[] = { + { .compatible = "sandbox,sound" }, + { } +}; + +U_BOOT_DRIVER(sandbox_sound) = { + .name = "sandbox_sound", + .id = UCLASS_SOUND, + .of_match = sandbox_sound_ids, + .ops = &sandbox_sound_ops, + .priv_auto_alloc_size = sizeof(struct sandbox_sound_priv), + .probe = sandbox_sound_probe, +}; diff --git a/drivers/sound/sound-uclass.c b/drivers/sound/sound-uclass.c new file mode 100644 index 00000000000..71e753cb993 --- /dev/null +++ b/drivers/sound/sound-uclass.c @@ -0,0 +1,127 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2018 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include + +#define SOUND_BITS_IN_BYTE 8 + +int sound_setup(struct udevice *dev) +{ + struct sound_ops *ops = sound_get_ops(dev); + + if (!ops->setup) + return -ENOSYS; + + return ops->setup(dev); +} + +int sound_play(struct udevice *dev, void *data, uint data_size) +{ + struct sound_ops *ops = sound_get_ops(dev); + + if (!ops->play) + return -ENOSYS; + + return ops->play(dev, data, data_size); +} + +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); + unsigned short *data; + uint data_size; + int ret; + + ret = sound_setup(dev); + if (ret && ret != -EALREADY) + return ret; + + /* Buffer length computation */ + data_size = i2s_uc_priv->samplingrate * i2s_uc_priv->channels; + data_size *= (i2s_uc_priv->bitspersample / SOUND_BITS_IN_BYTE); + data = malloc(data_size); + if (!data) { + debug("%s: malloc failed\n", __func__); + return -ENOMEM; + } + + sound_create_square_wave(i2s_uc_priv->samplingrate, data, data_size, + frequency_hz); + + while (msecs >= 1000) { + ret = sound_play(dev, data, data_size); + msecs -= 1000; + } + if (msecs) { + unsigned long size = + (data_size * msecs) / (sizeof(int) * 1000); + + ret = sound_play(dev, data, size); + } + + free(data); + + return ret; +} + +int sound_find_codec_i2s(struct udevice *dev) +{ + struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev); + struct ofnode_phandle_args args; + ofnode node; + int ret; + + /* First the codec */ + node = ofnode_find_subnode(dev_ofnode(dev), "codec"); + if (!ofnode_valid(node)) { + debug("Failed to find /cpu subnode\n"); + return -EINVAL; + } + ret = ofnode_parse_phandle_with_args(node, "sound-dai", + "#sound-dai-cells", 0, 0, &args); + if (ret) { + debug("Cannot find phandle: %d\n", ret); + return ret; + } + ret = uclass_get_device_by_ofnode(UCLASS_AUDIO_CODEC, args.node, + &uc_priv->codec); + if (ret) { + debug("Cannot find codec: %d\n", ret); + return ret; + } + + /* Now the i2s */ + node = ofnode_find_subnode(dev_ofnode(dev), "cpu"); + if (!ofnode_valid(node)) { + debug("Failed to find /cpu subnode\n"); + return -EINVAL; + } + ret = ofnode_parse_phandle_with_args(node, "sound-dai", + "#sound-dai-cells", 0, 0, &args); + if (ret) { + debug("Cannot find phandle: %d\n", ret); + return ret; + } + ret = uclass_get_device_by_ofnode(UCLASS_I2S, args.node, &uc_priv->i2s); + if (ret) { + debug("Cannot find i2s: %d\n", ret); + return ret; + } + debug("Probed sound '%s' with codec '%s' and i2s '%s'\n", dev->name, + uc_priv->codec->name, uc_priv->i2s->name); + + return 0; +} + +UCLASS_DRIVER(sound) = { + .id = UCLASS_SOUND, + .name = "sound", + .per_device_auto_alloc_size = sizeof(struct sound_uc_priv), +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 7ee5491e0b5..ba6ed9b6c44 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -83,6 +83,7 @@ enum uclass_id { UCLASS_SERIAL, /* Serial UART */ UCLASS_SIMPLE_BUS, /* Bus with child devices */ UCLASS_SMEM, /* Shared memory interface */ + UCLASS_SOUND, /* Playing simple sounds */ UCLASS_SPI, /* SPI bus */ UCLASS_SPI_FLASH, /* SPI flash */ UCLASS_SPI_GENERIC, /* Generic SPI flash target */ diff --git a/include/sound.h b/include/sound.h index c4ac3193fe7..c94d2c37265 100644 --- a/include/sound.h +++ b/include/sound.h @@ -19,12 +19,27 @@ struct sound_codec_info { int i2c_dev_addr; }; -/* +/** + * struct sound_uc_priv - private uclass information about each sound device + * + * This is used to line the codec and i2s together + * + * @codec: Codec that is used for this sound device + * @i2s: I2S bus that is used for this sound device + * @setup_done: true if setup() has been called + */ +struct sound_uc_priv { + struct udevice *codec; + struct udevice *i2s; + int setup_done; +}; + +/** * Generates square wave sound data for 1 second * * @param sample_rate Sample rate in Hz * @param data data buffer pointer - * @param size size of the buffer + * @param size size of the buffer in bytes * @param freq frequency of the wave */ void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, @@ -37,6 +52,56 @@ void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, */ int sound_init(const void *blob); +#ifdef CONFIG_DM_SOUND +/* + * The sound uclass brings together a data transport (currently only I2C) and a + * codec (currently connected over I2C). + */ + +/* Operations for sound */ +struct sound_ops { + /** + * setup() - Set up to play a sound + */ + int (*setup)(struct udevice *dev); + + /** + * play() - Play a beep + * + * @dev: Sound device + * @data: Data buffer to play + * @data_size: Size of data buffer in bytes + * @return 0 if OK, -ve on error + */ + int (*play)(struct udevice *dev, void *data, uint data_size); +}; + +#define sound_get_ops(dev) ((struct sound_ops *)(dev)->driver->ops) + +/** + * setup() - Set up to play a sound + */ +int sound_setup(struct udevice *dev); + +/** + * play() - Play a beep + * + * @dev: Sound device + * @msecs: Duration of beep in milliseconds + * @frequency_hz: Frequency of the beep in Hertz + * @return 0 if OK, -ve on error + */ +int sound_beep(struct udevice *dev, int msecs, int frequency_hz); + +/** + * sound_find_codec_i2s() - Called by sound drivers to locate codec and i2s + * + * This finds the audio codec and i2s devices and puts them in the uclass's + * private data for this device. + */ +int sound_find_codec_i2s(struct udevice *dev); + +#else /* * plays the pcm data buffer in pcm_data.h through i2s1 to make the * sine wave sound @@ -44,5 +109,6 @@ int sound_init(const void *blob); * @return int 0 for success, -1 for error */ int sound_play(uint32_t msec, uint32_t frequency); +#endif /* CONFIG_DM_SOUND */ #endif /* __SOUND__H__ */ diff --git a/test/dm/Makefile b/test/dm/Makefile index 28ede9a6695..73f5dcf739e 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -55,6 +55,7 @@ obj-$(CONFIG_AXI) += axi.o obj-$(CONFIG_MISC) += misc.o obj-$(CONFIG_DM_SERIAL) += serial.o obj-$(CONFIG_CPU) += cpu.o +obj-$(CONFIG_DM_SOUND) += sound.o obj-$(CONFIG_TEE) += tee.o obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o obj-$(CONFIG_DMA) += dma.o diff --git a/test/dm/sound.c b/test/dm/sound.c new file mode 100644 index 00000000000..7d0b36e7a56 --- /dev/null +++ b/test/dm/sound.c @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2018 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include + +/* Basic test of the sound codec uclass */ +static int dm_test_sound(struct unit_test_state *uts) +{ + struct sound_uc_priv *uc_priv; + struct udevice *dev; + + /* check probe success */ + ut_assertok(uclass_first_device_err(UCLASS_SOUND, &dev)); + uc_priv = dev_get_uclass_priv(dev); + ut_asserteq_str("audio-codec", uc_priv->codec->name); + ut_asserteq_str("i2s", uc_priv->i2s->name); + ut_asserteq(0, sandbox_get_setup_called(dev)); + + ut_assertok(sound_beep(dev, 1, 100)); + ut_asserteq(4560, sandbox_get_sound_sum(dev)); + ut_assertok(sound_beep(dev, 1, 100)); + ut_asserteq(9120, sandbox_get_sound_sum(dev)); + + return 0; +} +DM_TEST(dm_test_sound, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Mon Dec 10 17:37:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010568 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="B+cZmpEe"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9PC4DC5z9s3Z for ; Tue, 11 Dec 2018 04:41:51 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 45610C2284E; Mon, 10 Dec 2018 17:40:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D55E4C22651; Mon, 10 Dec 2018 17:38:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B06B3C22403; Mon, 10 Dec 2018 17:38:19 +0000 (UTC) Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by lists.denx.de (Postfix) with ESMTPS id 57DA9C2263A for ; Mon, 10 Dec 2018 17:38:15 +0000 (UTC) Received: by mail-io1-f71.google.com with SMTP id s8so11958006iob.2 for ; Mon, 10 Dec 2018 09:38:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=aurQ0dTyBGdo9Q8rB5K0uaz2LA9HjaUpYaTX/QkbjeM=; b=B+cZmpEeCQQ4ocxD3JmgNtq/srsdfISx6VPxvywFqLlXy2NuxfIYFwS2r6Nv1pTNeU l0iCZHWnR07awRCNmvxEqbL6MG41Rnq6vMXjLzyrHYoNlv0fd1AexjYORg9D2anjwrGM zYSlnpou9feU6SJ24tSepujOflnNjwJZC3rOw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=aurQ0dTyBGdo9Q8rB5K0uaz2LA9HjaUpYaTX/QkbjeM=; b=HPwiZN1n5SAePkpzkPhScUT4DdgJQhrIh9guYOXATzWIKDudEr/dlaFRifSRToEMDg /GMslUK/hA+4Sv8+oADjAp/tXW6drLuC8fkBFKHnZbiuw/61N+/sivqOM+i2seT01FHM sBehHlm081BejPi1py9qtVzYCOpe4hjtt3cCpWszgquTpUO0YHOtuEre58cZYzo1KOaf fXWBsL5azWAOuoWm8ZS+aaDa7JhadeKR5tSaNvkzjW+HXks9i//jpE3HlUGrHklXAIxi /5Ge2FpxyB2V9lmrdlzmMrEKXVtarUfmUPb3UrjtyHEc9NUu3Y6jpm8G5tiY4uGQWlNt tgQQ== X-Gm-Message-State: AA+aEWYk3yeLXRT02Ik1wu8PhvHXSDOT10CMnTkIXlKihM1HuzZYHid6 exEHZKN1IyuBKFrnBHgZcVOVDVsi4sZEaTjJ X-Google-Smtp-Source: AFSGD/XysOcfZI/ytMCGLVB/OiH6rYcZM3houlFqqL840npAX+xjTGgZxI3JqC165WSgzibJoj+jOJfL4hWUZR16 X-Received: by 2002:a24:4509:: with SMTP id y9mr10985089ita.13.1544463494377; Mon, 10 Dec 2018 09:38:14 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:37 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-9-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 08/22] dm: core: Add a function to read into a unsigned int X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The current dev_read...() functions use s32 and u32 which are convenient for device tree but not so useful for normal code, which often wants to use normal integers for values. Add a helper which supports returning an unsigned int. Also add signed versions of the unsigned readers. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: None arch/sandbox/dts/test.dts | 2 ++ drivers/core/read.c | 23 ++++++++++++++++ include/dm/read.h | 58 +++++++++++++++++++++++++++++++++++++++ test/dm/test-fdt.c | 35 +++++++++++++++++++++++ 4 files changed, 118 insertions(+) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index cedf514382f..e5c14fec5d8 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -87,6 +87,8 @@ test2-gpios = <&gpio_a 1>, <&gpio_a 4>, <&gpio_b 6 1 3 2 1>, <&gpio_b 7 2 3 2 1>, <&gpio_b 8 4 3 2 1>, <&gpio_b 9 0xc 3 2 1>; + int-value = <1234>; + uint-value = <(-1234)>; }; junk { diff --git a/drivers/core/read.c b/drivers/core/read.c index cdd78be03e2..3c46b3674ed 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -21,6 +21,29 @@ int dev_read_u32_default(struct udevice *dev, const char *propname, int def) return ofnode_read_u32_default(dev_ofnode(dev), propname, def); } +int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp) +{ + return ofnode_read_u32(dev_ofnode(dev), propname, (u32 *)outp); +} + +int dev_read_s32_default(struct udevice *dev, const char *propname, int def) +{ + return ofnode_read_u32_default(dev_ofnode(dev), propname, def); +} + +int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp) +{ + u32 val; + int ret; + + ret = ofnode_read_u32(dev_ofnode(dev), propname, &val); + if (ret) + return ret; + *outp = val; + + return 0; +} + const char *dev_read_string(struct udevice *dev, const char *propname) { return ofnode_read_string(dev_ofnode(dev), propname); diff --git a/include/dm/read.h b/include/dm/read.h index efcbee15eca..389e30e7fb4 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -64,6 +64,38 @@ int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp); */ int dev_read_u32_default(struct udevice *dev, const char *propname, int def); +/** + * dev_read_s32() - read a signed 32-bit integer from a device's DT property + * + * @dev: device to read DT property from + * @propname: name of the property to read from + * @outp: place to put value (if found) + * @return 0 if OK, -ve on error + */ +int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp); + +/** + * dev_read_s32_default() - read a signed 32-bit int from a device's DT property + * + * @dev: device to read DT property from + * @propname: name of the property to read from + * @def: default value to return if the property has no value + * @return property value, or @def if not found + */ +int dev_read_s32_default(struct udevice *dev, const char *propname, int def); + +/** + * dev_read_u32u() - read a 32-bit integer from a device's DT property + * + * This version uses a standard uint type. + * + * @dev: device to read DT property from + * @propname: name of the property to read from + * @outp: place to put value (if found) + * @return 0 if OK, -ve on error + */ +int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp); + /** * dev_read_string() - Read a string from a device's DT property * @@ -492,6 +524,32 @@ static inline int dev_read_u32_default(struct udevice *dev, return ofnode_read_u32_default(dev_ofnode(dev), propname, def); } +static inline int dev_read_s32(struct udevice *dev, + const char *propname, s32 *outp) +{ + return ofnode_read_s32(dev_ofnode(dev), propname, outp); +} + +static inline int dev_read_s32_default(struct udevice *dev, + const char *propname, int def) +{ + return ofnode_read_s32_default(dev_ofnode(dev), propname, def); +} + +static inline int dev_read_u32u(struct udevice *dev, + const char *propname, uint *outp) +{ + u32 val; + int ret; + + ret = ofnode_read_u32(dev_ofnode(dev), propname, &val); + if (ret) + return ret; + *outp = val; + + return 0; +} + static inline const char *dev_read_string(struct udevice *dev, const char *propname) { diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 96d2528accb..984b80c02c8 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -736,3 +736,38 @@ static int dm_test_first_child(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_first_child, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test integer functions in dm_read_...() */ +static int dm_test_read_int(struct unit_test_state *uts) +{ + struct udevice *dev; + u32 val32; + s32 sval; + uint val; + + ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev)); + ut_asserteq_str("a-test", dev->name); + ut_assertok(dev_read_u32(dev, "int-value", &val32)); + ut_asserteq(1234, val32); + + ut_asserteq(-EINVAL, dev_read_u32(dev, "missing", &val32)); + ut_asserteq(6, dev_read_u32_default(dev, "missing", 6)); + + ut_asserteq(1234, dev_read_u32_default(dev, "int-value", 6)); + ut_asserteq(1234, val32); + + ut_asserteq(-EINVAL, dev_read_s32(dev, "missing", &sval)); + ut_asserteq(6, dev_read_s32_default(dev, "missing", 6)); + + ut_asserteq(-1234, dev_read_s32_default(dev, "uint-value", 6)); + ut_assertok(dev_read_s32(dev, "uint-value", &sval)); + ut_asserteq(-1234, sval); + + val = 0; + ut_asserteq(-EINVAL, dev_read_u32u(dev, "missing", &val)); + ut_assertok(dev_read_u32u(dev, "uint-value", &val)); + ut_asserteq(-1234, val); + + return 0; +} +DM_TEST(dm_test_read_int, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Mon Dec 10 17:37:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010577 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="c7LRYjip"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9Vb5LZ6z9s3l for ; Tue, 11 Dec 2018 04:46:31 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 7AD64C22836; Mon, 10 Dec 2018 17:45:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 6B0B4C22859; Mon, 10 Dec 2018 17:38:48 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CF80BC22833; Mon, 10 Dec 2018 17:38:21 +0000 (UTC) Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by lists.denx.de (Postfix) with ESMTPS id 4C667C2265E for ; Mon, 10 Dec 2018 17:38:17 +0000 (UTC) Received: by mail-qt1-f198.google.com with SMTP id n95so12138052qte.16 for ; Mon, 10 Dec 2018 09:38:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=fZhy6WvoWLDBbTvLmltBUzldVLSO8BhlGcezi82M7qA=; b=c7LRYjip/BmWxZCsLQpvNTBkB49pNjhJaNASpLBV2JucLdiHmTp+DTSY/90ypKn4Nu CcSXkgZTrgbPFkRFvauG7qr+KwicWepHF93854aSiIq0Je2v+4D74jLTvLAX1PWPcpDD 9WXJpXnCZn7BUWF4CEm8N4mbq3P7xs02IfIrU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=fZhy6WvoWLDBbTvLmltBUzldVLSO8BhlGcezi82M7qA=; b=LzMbbq72zfSdUMleE/zXPEik5qb4gUtLlz+FetesYLKs5/giMUK3MgY+EO5yU24wyR UWHtqSBnHxhkNTwX5hWlCOrxJn4aS1aq5N04cYyJ9EPW91YB0Fa7Vrq/QzCM3GKifwMn nfL3EziKS8PM+vypVU+tnGqkm78AyJUZmpIfDSCRD0oQxteoHRx3WbDRDzSA6vM0MNfe qMHkNjLnFDszWd9gqe2SFbBvZYv1sjcPTajgnWw4+CNpEaCmdRMspqqcaPIsmQXrJjmt cMXxd41SuAY4zMIbUPeRdujglF1MH5IzIzgbVsXaX4XmWUdco5+dDwUCG/rDsnYT6qFr eQlg== X-Gm-Message-State: AA+aEWbgzUkbBv7wbB+9WEnD6e8khIOLtlqqBMDxag7WyaBL6tGnP6AY IcSCMzAfcOrCw3zbSLbNT5oa+ktkbnVwW471 X-Google-Smtp-Source: AFSGD/UR6PPvKLHhVuDeC9yq5ZC8ddD3CAha+6FzP6aPHsdoDfraJHMHmAcWd7XmVMs8zDvTFmDbqxTu8+Qu8ye8 X-Received: by 2002:a37:6647:: with SMTP id a68mr9897812qkc.16.1544463496039; Mon, 10 Dec 2018 09:38:16 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:38 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-10-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 09/22] dm: sound: Start i2c IDs from 0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The current ID enums start from 1 but there does not seem to be any reason that they cannot start with 0. Adjust the code to avoid the +1 in codec_init(). Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: None drivers/sound/max98095.h | 2 +- drivers/sound/sound-i2s.c | 6 ++---- drivers/sound/wm8994.h | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/sound/max98095.h b/drivers/sound/max98095.h index 44b1e3a97b4..13ae177a86b 100644 --- a/drivers/sound/max98095.h +++ b/drivers/sound/max98095.h @@ -13,7 +13,7 @@ /* Available audio interface ports in wm8994 codec */ enum en_max_audio_interface { - AIF1 = 1, + AIF1, AIF2, }; diff --git a/drivers/sound/sound-i2s.c b/drivers/sound/sound-i2s.c index ed130750b2e..a2fc78154f1 100644 --- a/drivers/sound/sound-i2s.c +++ b/drivers/sound/sound-i2s.c @@ -120,13 +120,11 @@ static int codec_init(const void *blob, struct i2s_uc_priv *pi2s_tx) debug("device = %s\n", codectype); if (!strcmp(codectype, "wm8994")) { /* Check the codec type and initialise the same */ - ret = wm8994_init(blob, pi2s_tx->id + 1, - pi2s_tx->samplingrate, + ret = wm8994_init(blob, pi2s_tx->id, pi2s_tx->samplingrate, (pi2s_tx->samplingrate * (pi2s_tx->rfs)), pi2s_tx->bitspersample, pi2s_tx->channels); } else if (!strcmp(codectype, "max98095")) { - ret = max98095_init(blob, pi2s_tx->id + 1, - pi2s_tx->samplingrate, + ret = max98095_init(blob, pi2s_tx->id, pi2s_tx->samplingrate, (pi2s_tx->samplingrate * (pi2s_tx->rfs)), pi2s_tx->bitspersample); } else { diff --git a/drivers/sound/wm8994.h b/drivers/sound/wm8994.h index ef2878f87ca..e36e6269f00 100644 --- a/drivers/sound/wm8994.h +++ b/drivers/sound/wm8994.h @@ -15,7 +15,7 @@ /* Avilable audi interface ports in wm8994 codec */ enum en_audio_interface { - WM8994_AIF1 = 1, + WM8994_AIF1, WM8994_AIF2, WM8994_AIF3 }; From patchwork Mon Dec 10 17:37:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010581 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="oCOzDvK3"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9YJ6CWLz9s3Z for ; Tue, 11 Dec 2018 04:48:52 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 9425FC22849; Mon, 10 Dec 2018 17:48:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 4D9B9C22875; Mon, 10 Dec 2018 17:39:03 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 04583C22874; Mon, 10 Dec 2018 17:38:22 +0000 (UTC) Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by lists.denx.de (Postfix) with ESMTPS id A04D9C227AA for ; Mon, 10 Dec 2018 17:38:18 +0000 (UTC) Received: by mail-oi1-f198.google.com with SMTP id p131so6638509oia.21 for ; Mon, 10 Dec 2018 09:38:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=odpd0N/TfcHIcxgvRuo1h6rtUlElYYcTZFp4/r4Pe1E=; b=oCOzDvK3Z8XIq+hwb+jUvWrvooRh5vZdMhK3gxFxgYCH5JBYDYVe6F3BBNngqsOfhb JSxzGWswp0f61qpSiZiaBqGVVrbkg5+v1DHnlWwoq1JoGuKzy1JJvH5up8xbcQKMJ6Wu QGwETdzzuh1WRka5ZySeB2WEokx54BesSJkpY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=odpd0N/TfcHIcxgvRuo1h6rtUlElYYcTZFp4/r4Pe1E=; b=N+ci9eewnwWlFdi2/jZnXG9ch1FB7hnjMMzw1aoKYrQ2wzEZNGV50v08w6c9QE9B9L r/7X5y2dVrhl7vt2j3Q1QypoOlCPAw7JsvDTU6X2ylT+jALl8CAKOWaUdZ6nve9vWu/L 0gQynviG/dswl4+E+vOI0aM7kxYlogEu9JCs+2URt4+aQNAGrgu7a4tn0TSuFt8tZGlL n6RSE8NMiLv0LZfdFVksiDgHEzgLWvzpI9BqseIMevlPdMKkfy3eeYVFMea4iLc03zpH xwZmX4z8FDwagZHSNNXYNl8TaRUMEQKmzumvO3R8oR7/UzBuEvF9lZBYge1gh4+mVJK+ 8ucw== X-Gm-Message-State: AA+aEWYY4zckUYbtuU3wjFPD2RfwNesD90E2sf8UEMw5lbo8t+0fbWPm jYEwPG9+kRp4IfTm8GKHzHIbPo1XhvanCwQQ X-Google-Smtp-Source: AFSGD/XvD3wYZDEHrXlKtRnqEGlOC5wyRTzYAWUHyIBLG7x9vFwN5wBVPTHFuM0HjdIv+RtiLCxVmvN7UyZ1q7Sh X-Received: by 2002:a9d:6381:: with SMTP id w1mr9999980otk.47.1544463497416; Mon, 10 Dec 2018 09:38:17 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:39 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-11-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 10/22] dm: sound: Add conversion to driver model X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Move the existing hardware drivers over to use driver model. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: - Correct conversion for pit - Use void * for i2c and sound data arch/arm/dts/exynos5250-smdk5250.dts | 1 + arch/arm/dts/exynos5420-smdk5420.dts | 1 + drivers/sound/Makefile | 6 +- drivers/sound/max98095.c | 59 +++++++++++++- drivers/sound/samsung-i2s.c | 111 +++++++++++++++++++++++---- drivers/sound/samsung_sound.c | 101 ++++++++++++++++++++++++ drivers/sound/wm8994.c | 53 ++++++++++++- 7 files changed, 316 insertions(+), 16 deletions(-) create mode 100644 drivers/sound/samsung_sound.c diff --git a/arch/arm/dts/exynos5250-smdk5250.dts b/arch/arm/dts/exynos5250-smdk5250.dts index 8b695442b1a..bf60b82d449 100644 --- a/arch/arm/dts/exynos5250-smdk5250.dts +++ b/arch/arm/dts/exynos5250-smdk5250.dts @@ -62,6 +62,7 @@ i2c@12C70000 { soundcodec@1a { reg = <0x1a>; + u-boot,i2c-offset-len = <2>; compatible = "wolfson,wm8994-codec"; }; }; diff --git a/arch/arm/dts/exynos5420-smdk5420.dts b/arch/arm/dts/exynos5420-smdk5420.dts index cab5ddb61fa..daaa4666964 100644 --- a/arch/arm/dts/exynos5420-smdk5420.dts +++ b/arch/arm/dts/exynos5420-smdk5420.dts @@ -84,6 +84,7 @@ i2c@12C70000 { soundcodec@1a { reg = <0x1a>; + u-boot,i2c-offset-len = <2>; compatible = "wolfson,wm8994-codec"; }; }; diff --git a/drivers/sound/Makefile b/drivers/sound/Makefile index 70d32c6d6f6..75fa31ec534 100644 --- a/drivers/sound/Makefile +++ b/drivers/sound/Makefile @@ -6,9 +6,13 @@ obj-$(CONFIG_SOUND) += sound.o obj-$(CONFIG_DM_SOUND) += codec-uclass.o obj-$(CONFIG_DM_SOUND) += i2s-uclass.o -obj-$(CONFIG_I2S) += sound-i2s.o obj-$(CONFIG_DM_SOUND) += sound-uclass.o obj-$(CONFIG_I2S_SAMSUNG) += samsung-i2s.o obj-$(CONFIG_SOUND_SANDBOX) += sandbox.o +ifdef CONFIG_DM_SOUND +obj-$(CONFIG_I2S_SAMSUNG) += samsung_sound.o +else +obj-$(CONFIG_I2S) += sound-i2s.o +endif obj-$(CONFIG_SOUND_WM8994) += wm8994.o obj-$(CONFIG_SOUND_MAX98095) += max98095.o diff --git a/drivers/sound/max98095.c b/drivers/sound/max98095.c index 7a3dbd09840..d6710dfaa7a 100644 --- a/drivers/sound/max98095.c +++ b/drivers/sound/max98095.c @@ -11,6 +11,8 @@ */ #include +#include +#include #include #include #include @@ -28,6 +30,7 @@ struct max98095_priv { unsigned int rate; unsigned int fmt; int i2c_addr; + struct udevice *dev; }; /* Index 0 is reserved. */ @@ -48,7 +51,12 @@ static int max98095_i2c_write(struct max98095_priv *priv, unsigned int reg, { debug("%s: Write Addr : 0x%02X, Data : 0x%02X\n", __func__, reg, data); +#ifdef CONFIG_DM_SOUND + debug("dev = %s\n", priv->dev->name); + return dm_i2c_write(priv->dev, reg, &data, 1); +#else return i2c_write(priv->i2c_addr, reg, 1, &data, 1); +#endif } /* @@ -65,7 +73,11 @@ static unsigned int max98095_i2c_read(struct max98095_priv *priv, { int ret; +#ifdef CONFIG_DM_SOUND + return dm_i2c_read(priv->dev, reg, data, 1); +#else ret = i2c_read(priv->i2c_addr, reg, 1, data, 1); +#endif if (ret != 0) { debug("%s: Error while reading register %#04x\n", __func__, reg); @@ -484,7 +496,7 @@ static int max98095_do_init(struct max98095_priv *priv, ret = max98095_setup_interface(priv, aif_id); if (ret < 0) { - debug("%s: max98095 codec chip init failed\n", __func__); + debug("%s: max98095 setup interface failed\n", __func__); return ret; } @@ -507,6 +519,7 @@ static int max98095_do_init(struct max98095_priv *priv, return ret; } +#ifndef CONFIG_DM_SOUND static int get_max98095_codec_values(struct sound_codec_info *pcodec_info, const void *blob) { @@ -582,3 +595,47 @@ int max98095_init(const void *blob, enum en_max_audio_interface aif_id, return ret; } +#endif + +static int max98095_set_params(struct udevice *dev, int interface, int rate, + int mclk_freq, int bits_per_sample, + uint channels) +{ + struct max98095_priv *priv = dev_get_priv(dev); + + return max98095_do_init(priv, interface, rate, mclk_freq, + bits_per_sample); +} + +static int max98095_probe(struct udevice *dev) +{ + struct max98095_priv *priv = dev_get_priv(dev); + int ret; + + priv->dev = dev; + ret = max98095_device_init(priv); + if (ret < 0) { + debug("%s: max98095 codec chip init failed\n", __func__); + return ret; + } + + return 0; +} + +static const struct audio_codec_ops max98095_ops = { + .set_params = max98095_set_params, +}; + +static const struct udevice_id max98095_ids[] = { + { .compatible = "maxim,max98095" }, + { } +}; + +U_BOOT_DRIVER(max98095) = { + .name = "max98095", + .id = UCLASS_AUDIO_CODEC, + .of_match = max98095_ids, + .probe = max98095_probe, + .ops = &max98095_ops, + .priv_auto_alloc_size = sizeof(struct max98095_priv), +}; diff --git a/drivers/sound/samsung-i2s.c b/drivers/sound/samsung-i2s.c index 5cd585808ab..c19e08e7e30 100644 --- a/drivers/sound/samsung-i2s.c +++ b/drivers/sound/samsung-i2s.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -255,13 +256,13 @@ static int i2s_set_samplesize(struct i2s_reg *i2s_reg, unsigned int blc) return 0; } -int i2s_transfer_tx_data(struct i2s_uc_priv *pi2s_tx, unsigned int *data, - unsigned long data_size) +int i2s_transfer_tx_data(struct i2s_uc_priv *pi2s_tx, void *data, + uint data_size) { + struct i2s_reg *i2s_reg = (struct i2s_reg *)pi2s_tx->base_address; + u32 *ptr; int i; int start; - struct i2s_reg *i2s_reg = - (struct i2s_reg *)pi2s_tx->base_address; if (data_size < FIFO_LENGTH) { debug("%s : Invalid data size\n", __func__); @@ -269,17 +270,17 @@ int i2s_transfer_tx_data(struct i2s_uc_priv *pi2s_tx, unsigned int *data, } /* fill the tx buffer before stating the tx transmit */ - for (i = 0; i < FIFO_LENGTH; i++) - writel(*data++, &i2s_reg->txd); + for (i = 0, ptr = data; i < FIFO_LENGTH; i++) + writel(*ptr++, &i2s_reg->txd); - data_size -= FIFO_LENGTH; + data_size -= sizeof(*ptr) * FIFO_LENGTH; i2s_txctrl(i2s_reg, I2S_TX_ON); while (data_size > 0) { start = get_timer(0); if (!(CON_TXFIFO_FULL & (readl(&i2s_reg->con)))) { - writel(*data++, &i2s_reg->txd); - data_size--; + writel(*ptr++, &i2s_reg->txd); + data_size -= sizeof(*ptr); } else { if (get_timer(start) > TIMEOUT_I2S_TX) { i2s_txctrl(i2s_reg, I2S_TX_OFF); @@ -296,8 +297,8 @@ int i2s_transfer_tx_data(struct i2s_uc_priv *pi2s_tx, unsigned int *data, int i2s_tx_init(struct i2s_uc_priv *pi2s_tx) { int ret; - struct i2s_reg *i2s_reg = - (struct i2s_reg *)pi2s_tx->base_address; + struct i2s_reg *i2s_reg = (struct i2s_reg *)pi2s_tx->base_address; + if (pi2s_tx->id == 0) { /* Initialize GPIO for I2S-0 */ exynos_pinmux_config(PERIPH_ID_I2S0, 0); @@ -348,8 +349,8 @@ int i2s_tx_init(struct i2s_uc_priv *pi2s_tx) } /* Configure I2s format */ - ret = i2s_set_fmt(i2s_reg, (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | - SND_SOC_DAIFMT_CBM_CFM)); + ret = i2s_set_fmt(i2s_reg, SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBM_CFM); if (ret == 0) { i2s_set_lr_framesize(i2s_reg, pi2s_tx->rfs); ret = i2s_set_samplesize(i2s_reg, pi2s_tx->bitspersample); @@ -368,3 +369,87 @@ int i2s_tx_init(struct i2s_uc_priv *pi2s_tx) return ret; } + +static int samsung_i2s_tx_data(struct udevice *dev, void *data, uint data_size) +{ + struct i2s_uc_priv *priv = dev_get_uclass_priv(dev); + + return i2s_transfer_tx_data(priv, data, data_size); +} + +static int samsung_i2s_probe(struct udevice *dev) +{ + struct i2s_uc_priv *priv = dev_get_uclass_priv(dev); + + return i2s_tx_init(priv); +} + +static int samsung_i2s_ofdata_to_platdata(struct udevice *dev) +{ + struct i2s_uc_priv *priv = dev_get_uclass_priv(dev); + ulong base; + + /* + * Get the pre-defined sound specific values from FDT. + * All of these are expected to be correct otherwise + * wrong register values in i2s setup parameters + * may result in no sound play. + */ + base = dev_read_addr(dev); + if (base == FDT_ADDR_T_NONE) { + debug("%s: Missing i2s base\n", __func__); + return -EINVAL; + } + priv->base_address = base; + + if (dev_read_u32u(dev, "samsung,i2s-epll-clock-frequency", + &priv->audio_pll_clk)) + goto err; + debug("audio_pll_clk = %d\n", priv->audio_pll_clk); + if (dev_read_u32u(dev, "samsung,i2s-sampling-rate", + &priv->samplingrate)) + goto err; + debug("samplingrate = %d\n", priv->samplingrate); + if (dev_read_u32u(dev, "samsung,i2s-bits-per-sample", + &priv->bitspersample)) + goto err; + debug("bitspersample = %d\n", priv->bitspersample); + if (dev_read_u32u(dev, "samsung,i2s-channels", &priv->channels)) + goto err; + debug("channels = %d\n", priv->channels); + if (dev_read_u32u(dev, "samsung,i2s-lr-clk-framesize", &priv->rfs)) + goto err; + debug("rfs = %d\n", priv->rfs); + if (dev_read_u32u(dev, "samsung,i2s-bit-clk-framesize", &priv->bfs)) + goto err; + debug("bfs = %d\n", priv->bfs); + + if (dev_read_u32u(dev, "samsung,i2s-id", &priv->id)) + goto err; + debug("id = %d\n", priv->id); + + return 0; + +err: + debug("fail to get sound i2s node properties\n"); + + return -EINVAL; +} + +static const struct i2s_ops samsung_i2s_ops = { + .tx_data = samsung_i2s_tx_data, +}; + +static const struct udevice_id samsung_i2s_ids[] = { + { .compatible = "samsung,s5pv210-i2s" }, + { } +}; + +U_BOOT_DRIVER(samsung_i2s) = { + .name = "samsung_i2s", + .id = UCLASS_I2S, + .of_match = samsung_i2s_ids, + .probe = samsung_i2s_probe, + .ofdata_to_platdata = samsung_i2s_ofdata_to_platdata, + .ops = &samsung_i2s_ops, +}; diff --git a/drivers/sound/samsung_sound.c b/drivers/sound/samsung_sound.c new file mode 100644 index 00000000000..23b467c1de0 --- /dev/null +++ b/drivers/sound/samsung_sound.c @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2018 Google, LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include + +static int samsung_sound_setup(struct udevice *dev) +{ + struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev); + struct i2s_uc_priv *i2c_priv = dev_get_uclass_priv(uc_priv->i2s); + int ret; + + if (uc_priv->setup_done) + return -EALREADY; + ret = audio_codec_set_params(uc_priv->codec, i2c_priv->id, + i2c_priv->samplingrate, + i2c_priv->samplingrate * i2c_priv->rfs, + i2c_priv->bitspersample, + i2c_priv->channels); + if (ret) + return ret; + uc_priv->setup_done = true; + + return 0; +} + +static int samsung_sound_play(struct udevice *dev, void *data, uint data_size) +{ + struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev); + + return i2s_tx_data(uc_priv->i2s, data, data_size); +} + +static int samsung_sound_probe(struct udevice *dev) +{ + struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev); + struct ofnode_phandle_args args; + struct gpio_desc en_gpio; + ofnode node; + int ret; + + ret = gpio_request_by_name(dev, "codec-enable-gpio", 0, &en_gpio, + GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); + + /* Turn on the GPIO which connects to the codec's "enable" line. */ + if (!ret) + gpio_set_pull(gpio_get_number(&en_gpio), S5P_GPIO_PULL_NONE); + + ret = uclass_get_device_by_phandle(UCLASS_AUDIO_CODEC, dev, + "samsung,audio-codec", + &uc_priv->codec); + if (ret) { + debug("Failed to probe audio codec\n"); + return ret; + } + node = ofnode_find_subnode(dev_ofnode(dev), "cpu"); + if (!ofnode_valid(node)) { + debug("Failed to find /cpu subnode\n"); + return -EINVAL; + } + ret = ofnode_parse_phandle_with_args(node, "sound-dai", + "#sound-dai-cells", 0, 0, &args); + if (ret) { + debug("Cannot find phandle: %d\n", ret); + return ret; + } + ret = uclass_get_device_by_ofnode(UCLASS_I2S, args.node, &uc_priv->i2s); + if (ret) { + debug("Cannot find i2s: %d\n", ret); + return ret; + } + debug("Probed sound '%s' with codec '%s' and i2s '%s'\n", dev->name, + uc_priv->codec->name, uc_priv->i2s->name); + + return 0; +} + +static const struct sound_ops samsung_sound_ops = { + .setup = samsung_sound_setup, + .play = samsung_sound_play, +}; + +static const struct udevice_id samsung_sound_ids[] = { + { .compatible = "google,snow-audio-max98095" }, + { } +}; + +U_BOOT_DRIVER(samsung_sound) = { + .name = "samsung_sound", + .id = UCLASS_SOUND, + .of_match = samsung_sound_ids, + .probe = samsung_sound_probe, + .ops = &samsung_sound_ops, +}; diff --git a/drivers/sound/wm8994.c b/drivers/sound/wm8994.c index 1714f430f39..d731a0dd863 100644 --- a/drivers/sound/wm8994.c +++ b/drivers/sound/wm8994.c @@ -4,6 +4,8 @@ * R. Chandrasekar */ #include +#include +#include #include #include #include @@ -39,6 +41,7 @@ struct wm8994_priv { int aifclk[WM8994_MAX_AIF]; /* audio interface clock in Hz */ struct wm8994_fll_config fll[2]; /* fll config to configure fll */ int i2c_addr; + struct udevice *dev; }; /* wm 8994 supported sampling rate values */ @@ -79,7 +82,12 @@ static int wm8994_i2c_write(struct wm8994_priv *priv, unsigned int reg, val[1] = (unsigned char)(data & 0xff); debug("Write Addr : 0x%04X, Data : 0x%04X\n", reg, data); +#ifdef CONFIG_DM_SOUND + debug("dev = %s\n", priv->dev->name); + return dm_i2c_write(priv->dev, reg, val, 2); +#else return i2c_write(priv->i2c_addr, reg, 2, val, 2); +#endif } /* @@ -97,7 +105,11 @@ static unsigned int wm8994_i2c_read(struct wm8994_priv *priv, unsigned int reg, unsigned char val[2]; int ret; +#ifdef CONFIG_DM_SOUND + ret = dm_i2c_read(priv->dev, reg, val, 1); +#else ret = i2c_read(priv->i2c_addr, reg, 2, val, 2); +#endif if (ret != 0) { debug("%s: Error while reading register %#04x\n", __func__, reg); @@ -807,6 +819,7 @@ err: return -1; } +#ifndef CONFIG_DM_SOUND /* * Gets fdt values for wm8994 config parameters * @@ -859,6 +872,7 @@ static int get_codec_values(struct sound_codec_info *pcodec_info, return 0; } +#endif static int _wm8994_init(struct wm8994_priv *priv, enum en_audio_interface aif_id, int sampling_rate, @@ -873,7 +887,7 @@ static int _wm8994_init(struct wm8994_priv *priv, return ret; } - ret = wm8994_set_sysclk(priv, aif_id, WM8994_SYSCLK_MCLK1, mclk_freq); + ret = wm8994_set_sysclk(priv, aif_id, WM8994_SYSCLK_MCLK1, mclk_freq); if (ret < 0) { debug("%s: wm8994 codec set sys clock failed\n", __func__); return ret; @@ -891,6 +905,7 @@ static int _wm8994_init(struct wm8994_priv *priv, return ret; } +#ifndef CONFIG_DM_SOUND /* WM8994 Device Initialisation */ int wm8994_init(const void *blob, enum en_audio_interface aif_id, int sampling_rate, int mclk_freq, int bits_per_sample, @@ -918,3 +933,39 @@ int wm8994_init(const void *blob, enum en_audio_interface aif_id, return _wm8994_init(&wm8994_info, aif_id, sampling_rate, mclk_freq, bits_per_sample, channels); } +#endif + +static int wm8994_set_params(struct udevice *dev, int interface, int rate, + int mclk_freq, int bits_per_sample, uint channels) +{ + struct wm8994_priv *priv = dev_get_priv(dev); + + return _wm8994_init(priv, interface, rate, mclk_freq, bits_per_sample, + channels); +} + +static int wm8994_probe(struct udevice *dev) +{ + struct wm8994_priv *priv = dev_get_priv(dev); + + priv->dev = dev; + return wm8994_device_init(priv); +} + +static const struct audio_codec_ops wm8994_ops = { + .set_params = wm8994_set_params, +}; + +static const struct udevice_id wm8994_ids[] = { + { .compatible = "wolfson,wm8994" }, + { } +}; + +U_BOOT_DRIVER(wm8994) = { + .name = "wm8994", + .id = UCLASS_AUDIO_CODEC, + .of_match = wm8994_ids, + .probe = wm8994_probe, + .ops = &wm8994_ops, + .priv_auto_alloc_size = sizeof(struct wm8994_priv), +}; From patchwork Mon Dec 10 17:37:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010583 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="IKjWkj6N"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9cb3R4Tz9s3Z for ; Tue, 11 Dec 2018 04:51:43 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 27C32C2265E; Mon, 10 Dec 2018 17:49:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 44D3EC2284B; Mon, 10 Dec 2018 17:39:14 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5F51AC22669; Mon, 10 Dec 2018 17:38:26 +0000 (UTC) Received: from mail-it1-f199.google.com (mail-it1-f199.google.com [209.85.166.199]) by lists.denx.de (Postfix) with ESMTPS id B7152C22831 for ; Mon, 10 Dec 2018 17:38:19 +0000 (UTC) Received: by mail-it1-f199.google.com with SMTP id c73so14394318itd.1 for ; Mon, 10 Dec 2018 09:38:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=bYA4/9ylbbWuN3iT+sEEh3MH+Osn+CVhZFOezO5XBGE=; b=IKjWkj6Npnhrftv76E67AkSHp/i2KXAVgcrmUbIC2V3UO36OnXrXmIkRbVKFr5Y/E9 c44zEoZkq+1Xy5wO29IhuCAmTTgtAIbP1UWiy4l/TXPOQHhcP/FCoq0Pnpx1ofmafm07 1yeTl47uX4cOIug+u41wc0bqRpuy9kkMoxZyU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=bYA4/9ylbbWuN3iT+sEEh3MH+Osn+CVhZFOezO5XBGE=; b=cCP/Hmw0JIDb0gYIcV9W89Qzl2vzh80Lea9CTaFv+iLCfndYI6K4FPM/+8Vcsrseqw WVQX3nUdtY4CjuCFoqUn3iPBcY9e6LTJXiivcJvetAsRV3cXylcishUbl1jeK6R0+Zay F4GaFU5fFtzH0RaUrJFjLOAbZMZl/z8h96JyedSvpRldfG0mcgrKOynC2dCn8pUx8vKr eX69Ao9TcDP8irJGbZI/onk7B5fQsGZWFAFgVaDBecGk9x7A524AXAIQ45EDSrnDv2cI u1Odz9Cgxe/J1lG+VjSZ8kbK4fwoxNhan26NZ7xcVciYGclJ/uc+HE2lsnMBvpryPkMB cYVg== X-Gm-Message-State: AA+aEWb+BkEzFtttCffr+1Z4onW267CdKrLL1nZctekdc+Cg+jRtsTAH pc2b+XUBsGlCTbQD8CWFlXWvOxQrSeGF7p1g X-Google-Smtp-Source: AFSGD/UsEGn/ANZtINlxZX9ynUtOcRpkEfx9qhTkYh5dYG4vuxNGhoF9vFqmBmr1YPTaCHokZr0JKxN7vOy+mhQV X-Received: by 2002:a24:50c:: with SMTP id 12mr10473770itl.18.1544463498769; Mon, 10 Dec 2018 09:38:18 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:40 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-12-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 11/22] exynos: Add proid_is_exynos542x() for common 542x X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add a convenience function for any Exynos 542x chip. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: None arch/arm/mach-exynos/clock.c | 10 +++++----- arch/arm/mach-exynos/clock_init_exynos5.c | 2 +- arch/arm/mach-exynos/common_setup.h | 4 ++-- arch/arm/mach-exynos/include/mach/cpu.h | 4 +++- arch/arm/mach-exynos/include/mach/gpio.h | 4 ++-- arch/arm/mach-exynos/pinmux.c | 2 +- arch/arm/mach-exynos/power.c | 2 +- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/arch/arm/mach-exynos/clock.c b/arch/arm/mach-exynos/clock.c index 6a3cd44b5d3..2425a728669 100644 --- a/arch/arm/mach-exynos/clock.c +++ b/arch/arm/mach-exynos/clock.c @@ -345,7 +345,7 @@ static struct clk_bit_info *get_clk_bit_info(int peripheral) int i; struct clk_bit_info *info; - if (proid_is_exynos5420() || proid_is_exynos5422()) + if (proid_is_exynos542x()) info = exynos542x_bit_info; else info = exynos5_bit_info; @@ -557,7 +557,7 @@ static unsigned long exynos542x_get_periph_rate(int peripheral) unsigned long clock_get_periph_rate(int peripheral) { if (cpu_is_exynos5()) { - if (proid_is_exynos5420() || proid_is_exynos5422()) + if (proid_is_exynos542x()) return exynos542x_get_periph_rate(peripheral); return exynos5_get_periph_rate(peripheral); } else { @@ -1575,7 +1575,7 @@ static unsigned long exynos4_get_i2c_clk(void) unsigned long get_pll_clk(int pllreg) { if (cpu_is_exynos5()) { - if (proid_is_exynos5420() || proid_is_exynos5422()) + if (proid_is_exynos542x()) return exynos542x_get_pll_clk(pllreg); return exynos5_get_pll_clk(pllreg); } else if (cpu_is_exynos4()) { @@ -1691,7 +1691,7 @@ void set_mmc_clk(int dev_index, unsigned int div) div -= 1; if (cpu_is_exynos5()) { - if (proid_is_exynos5420() || proid_is_exynos5422()) + if (proid_is_exynos542x()) exynos5420_set_mmc_clk(dev_index, div); else exynos5_set_mmc_clk(dev_index, div); @@ -1739,7 +1739,7 @@ void set_mipi_clk(void) int set_spi_clk(int periph_id, unsigned int rate) { if (cpu_is_exynos5()) { - if (proid_is_exynos5420() || proid_is_exynos5422()) + if (proid_is_exynos542x()) return exynos5420_set_spi_clk(periph_id, rate); return exynos5_set_spi_clk(periph_id, rate); } diff --git a/arch/arm/mach-exynos/clock_init_exynos5.c b/arch/arm/mach-exynos/clock_init_exynos5.c index e63ef645239..1cb8d391e7c 100644 --- a/arch/arm/mach-exynos/clock_init_exynos5.c +++ b/arch/arm/mach-exynos/clock_init_exynos5.c @@ -968,7 +968,7 @@ static void exynos5420_system_clock_init(void) void system_clock_init(void) { - if (proid_is_exynos5420() || proid_is_exynos5422()) + if (proid_is_exynos542x()) exynos5420_system_clock_init(); else exynos5250_system_clock_init(); diff --git a/arch/arm/mach-exynos/common_setup.h b/arch/arm/mach-exynos/common_setup.h index 2829fb269ed..4e3702b9285 100644 --- a/arch/arm/mach-exynos/common_setup.h +++ b/arch/arm/mach-exynos/common_setup.h @@ -78,7 +78,7 @@ static inline void configure_l2_ctlr(void) CACHE_TAG_RAM_LATENCY_2_CYCLES | CACHE_DATA_RAM_LATENCY_2_CYCLES; - if (proid_is_exynos5420() || proid_is_exynos5422()) { + if (proid_is_exynos542x()) { val |= CACHE_ECC_AND_PARITY | CACHE_TAG_RAM_LATENCY_3_CYCLES | CACHE_DATA_RAM_LATENCY_3_CYCLES; @@ -97,7 +97,7 @@ static inline void configure_l2_actlr(void) { uint32_t val; - if (proid_is_exynos5420() || proid_is_exynos5422()) { + if (proid_is_exynos542x()) { mrc_l2_aux_ctlr(val); val |= CACHE_ENABLE_FORCE_L2_LOGIC | CACHE_DISABLE_CLEAN_EVICT; diff --git a/arch/arm/mach-exynos/include/mach/cpu.h b/arch/arm/mach-exynos/include/mach/cpu.h index aeb3755fe6b..766edeeb298 100644 --- a/arch/arm/mach-exynos/include/mach/cpu.h +++ b/arch/arm/mach-exynos/include/mach/cpu.h @@ -268,6 +268,8 @@ IS_EXYNOS_TYPE(exynos5250, 0x5250) IS_EXYNOS_TYPE(exynos5420, 0x5420) IS_EXYNOS_TYPE(exynos5422, 0x5422) +#define proid_is_exynos542x() (proid_is_exynos5420() || proid_is_exynos5422()) + #define SAMSUNG_BASE(device, base) \ static inline unsigned long __attribute__((no_instrument_function)) \ samsung_get_base_##device(void) \ @@ -277,7 +279,7 @@ static inline unsigned long __attribute__((no_instrument_function)) \ return EXYNOS4X12_##base; \ return EXYNOS4_##base; \ } else if (cpu_is_exynos5()) { \ - if (proid_is_exynos5420() || proid_is_exynos5422()) \ + if (proid_is_exynos542x()) \ return EXYNOS5420_##base; \ return EXYNOS5_##base; \ } \ diff --git a/arch/arm/mach-exynos/include/mach/gpio.h b/arch/arm/mach-exynos/include/mach/gpio.h index 272e00bae8f..f9975d7919f 100644 --- a/arch/arm/mach-exynos/include/mach/gpio.h +++ b/arch/arm/mach-exynos/include/mach/gpio.h @@ -1397,7 +1397,7 @@ static struct gpio_info exynos5420_gpio_data[EXYNOS5420_GPIO_NUM_PARTS] = { static inline struct gpio_info *get_gpio_data(void) { if (cpu_is_exynos5()) { - if (proid_is_exynos5420() || proid_is_exynos5422()) + if (proid_is_exynos542x()) return exynos5420_gpio_data; else return exynos5_gpio_data; @@ -1414,7 +1414,7 @@ static inline struct gpio_info *get_gpio_data(void) static inline unsigned int get_bank_num(void) { if (cpu_is_exynos5()) { - if (proid_is_exynos5420() || proid_is_exynos5422()) + if (proid_is_exynos542x()) return EXYNOS5420_GPIO_NUM_PARTS; else return EXYNOS5_GPIO_NUM_PARTS; diff --git a/arch/arm/mach-exynos/pinmux.c b/arch/arm/mach-exynos/pinmux.c index f6743ca0f6e..5072f4f5691 100644 --- a/arch/arm/mach-exynos/pinmux.c +++ b/arch/arm/mach-exynos/pinmux.c @@ -863,7 +863,7 @@ static int exynos4x12_pinmux_config(int peripheral, int flags) int exynos_pinmux_config(int peripheral, int flags) { if (cpu_is_exynos5()) { - if (proid_is_exynos5420() || proid_is_exynos5422()) + if (proid_is_exynos542x()) return exynos5420_pinmux_config(peripheral, flags); else if (proid_is_exynos5250()) return exynos5_pinmux_config(peripheral, flags); diff --git a/arch/arm/mach-exynos/power.c b/arch/arm/mach-exynos/power.c index 63c410aceff..f2a6c00dd62 100644 --- a/arch/arm/mach-exynos/power.c +++ b/arch/arm/mach-exynos/power.c @@ -124,7 +124,7 @@ static void exynos5420_set_usbdev_phy_ctrl(unsigned int enable) void set_usbdrd_phy_ctrl(unsigned int enable) { if (cpu_is_exynos5()) { - if (proid_is_exynos5420() || proid_is_exynos5422()) + if (proid_is_exynos542x()) exynos5420_set_usbdev_phy_ctrl(enable); else exynos5_set_usbdrd_phy_ctrl(enable); From patchwork Mon Dec 10 17:37:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010585 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="lhpPciKR"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9fD4Wl0z9s3C for ; Tue, 11 Dec 2018 04:53:08 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 46589C22860; Mon, 10 Dec 2018 17:51:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 59534C22878; Mon, 10 Dec 2018 17:39:31 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7890AC22893; Mon, 10 Dec 2018 17:38:26 +0000 (UTC) Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by lists.denx.de (Postfix) with ESMTPS id 4A009C2283E for ; Mon, 10 Dec 2018 17:38:21 +0000 (UTC) Received: by mail-io1-f71.google.com with SMTP id h7so12070148iof.19 for ; Mon, 10 Dec 2018 09:38:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=sWQko4m/+E8trERareyVfwlaCqk/qxc3GzvOjf3LSnA=; b=lhpPciKRCC6x0Nr/pn/L39fEWDuijM4702eAzp+b9SYrT2jgHqTIFPNQsTRh83TZUj Q59nxX8vc9lMuV4twmGHAsyvCXFzV4kgwN8I+YWOpcLBX0nm+LYWWxh3mhIPwSn2RMvS dn0D1WsZy6GJVo9Pm7tDQgSXWnBs7fp5/cI4k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=sWQko4m/+E8trERareyVfwlaCqk/qxc3GzvOjf3LSnA=; b=TbzeudEgbdc54keQMzWYNH3RFh8la32rhhVDzwp9ocwPHSJWRdXtRiChjBPcgVOXJW 6mt9YZfFmAy0TDPWdg8iYvh3v4Pws3LWlbaQ1iO7qRRzvwWP3AJW+Y25J2XmO6zQtSit ySSISBsMCbwg1Uq0hGzpeZogvyPlU+BOsYIsL4CcrXRKqlWHAXE4GFnxY7J5ihahN2pY sNXGrebuwJNR7x85ySlgMwiagqtYYG8rkYr5DauBiUPmEb0e/s6/508WRjD0bMOFhJxJ hEh+YoFZ+HHFFM8wa2pjs5r1sH3s0FgDA4n8/JOtyfFbEuCK8wGab12Ob4en/H25Tule Y5/A== X-Gm-Message-State: AA+aEWaXSn/MqH6Vfb9KpBuYw+LVBD+gdMeuS0ypzu+vz8hOLYsXFXRr nZQTD42pwSZFbT4McaP+QvQc+k2XRFZZnqYt X-Google-Smtp-Source: AFSGD/XAOtOO7BX9X/pGqEMkUFTisx3Lmemxz/L1ygsuCNFAV0Bl8m3YU9auZyMy+rrbq3klVGOlXvJnXjkg79Ua X-Received: by 2002:a05:660c:7ca:: with SMTP id e10mr10965427itl.16.1544463500267; Mon, 10 Dec 2018 09:38:20 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:41 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-13-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 12/22] exynos: Add support for exynos5420 i2s pinmux X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Allow setting the i2s pinmux correctly on exyno5420 so that i2c can be used on that SoC. Also rename EXYNOS_AUDSS to something consistent with other naming. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: None arch/arm/mach-exynos/clock.c | 21 +++++++++++++++++++-- arch/arm/mach-exynos/include/mach/clock.h | 3 +++ arch/arm/mach-exynos/pinmux.c | 17 +++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/arch/arm/mach-exynos/clock.c b/arch/arm/mach-exynos/clock.c index 2425a728669..73aa4cdad32 100644 --- a/arch/arm/mach-exynos/clock.c +++ b/arch/arm/mach-exynos/clock.c @@ -1317,6 +1317,19 @@ int exynos5_set_epll_clk(unsigned long rate) return 0; } +static int exynos5420_set_i2s_clk_source(void) +{ + struct exynos5420_clock *clk = + (struct exynos5420_clock *)samsung_get_base_clock(); + + setbits_le32(&clk->src_top6, EXYNOS5420_CLK_SRC_MOUT_EPLL); + clrsetbits_le32(&clk->src_mau, EXYNOS5420_AUDIO0_SEL_MASK, + (EXYNOS5420_CLK_SRC_SCLK_EPLL)); + setbits_le32(EXYNOS5_AUDIOSS_BASE, 1 << 0); + + return 0; +} + int exynos5_set_i2s_clk_source(unsigned int i2s_id) { struct exynos5_clock *clk = @@ -1758,8 +1771,12 @@ int set_i2s_clk_prescaler(unsigned int src_frq, unsigned int dst_frq, int set_i2s_clk_source(unsigned int i2s_id) { - if (cpu_is_exynos5()) - return exynos5_set_i2s_clk_source(i2s_id); + if (cpu_is_exynos5()) { + if (proid_is_exynos542x()) + return exynos5420_set_i2s_clk_source(); + else + return exynos5_set_i2s_clk_source(i2s_id); + } return 0; } diff --git a/arch/arm/mach-exynos/include/mach/clock.h b/arch/arm/mach-exynos/include/mach/clock.h index edf62bdf853..e4c706adeac 100644 --- a/arch/arm/mach-exynos/include/mach/clock.h +++ b/arch/arm/mach-exynos/include/mach/clock.h @@ -1370,10 +1370,13 @@ struct set_epll_con_val { #define AUDIO_1_RATIO_MASK 0x0f #define AUDIO0_SEL_MASK 0xf +#define EXYNOS5420_AUDIO0_SEL_MASK (0x3 << 28) #define AUDIO1_SEL_MASK 0xf #define CLK_SRC_SCLK_EPLL 0x7 +#define EXYNOS5420_CLK_SRC_SCLK_EPLL (0x6 << 28) #define CLK_SRC_MOUT_EPLL (1<<12) +#define EXYNOS5420_CLK_SRC_MOUT_EPLL BIT(20) #define AUDIO_CLKMUX_ASS (1<<0) /* CON0 bit-fields */ diff --git a/arch/arm/mach-exynos/pinmux.c b/arch/arm/mach-exynos/pinmux.c index 5072f4f5691..b24f1bb8f4f 100644 --- a/arch/arm/mach-exynos/pinmux.c +++ b/arch/arm/mach-exynos/pinmux.c @@ -378,6 +378,20 @@ static void exynos5_i2s_config(int peripheral) } } +static void exynos5420_i2s_config(int peripheral) +{ + int i; + + switch (peripheral) { + case PERIPH_ID_I2S0: + for (i = 0; i < 5; i++) + gpio_cfg_pin(EXYNOS5420_GPIO_Z0 + i, + S5P_GPIO_FUNC(0x02)); + break; + } +} + + void exynos5_spi_config(int peripheral) { int cfg = 0, pin = 0, i; @@ -550,6 +564,9 @@ static int exynos5420_pinmux_config(int peripheral, int flags) case PERIPH_ID_I2C10: exynos5420_i2c_config(peripheral); break; + case PERIPH_ID_I2S0: + exynos5420_i2s_config(peripheral); + break; case PERIPH_ID_PWM0: gpio_cfg_pin(EXYNOS5420_GPIO_B20, S5P_GPIO_FUNC(2)); break; From patchwork Mon Dec 10 17:37:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010584 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="b+h7Ta69"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9f76ZgHz9s3C for ; Tue, 11 Dec 2018 04:53:03 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 93207C22860; Mon, 10 Dec 2018 17:51:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3C006C2288E; Mon, 10 Dec 2018 17:39:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 919B0C22889; Mon, 10 Dec 2018 17:38:27 +0000 (UTC) Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by lists.denx.de (Postfix) with ESMTPS id 06502C22822 for ; Mon, 10 Dec 2018 17:38:23 +0000 (UTC) Received: by mail-io1-f69.google.com with SMTP id w5so12111851iom.3 for ; Mon, 10 Dec 2018 09:38:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=0K15umyS4R9jnNTC+a8C01ZNET3jLfNWEmsQ8dc320w=; b=b+h7Ta69dcxGSizg+3h+HxnBLN2xg510joz6GO1OyaxrREJQ5QZLdg+9Qf9YI2sw2x EqnC9oxhcJ9qI2ffTBYmKtjTub/hMFVvb5aZ37D/BS2m+X+YTaRz+yJ6btLIQkMC0xey XZQKq+qKYAmzD/MMSXtGGaDmoKmyEknP+ew8E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=0K15umyS4R9jnNTC+a8C01ZNET3jLfNWEmsQ8dc320w=; b=nXKmcMW+8ZTL/Ng3VTk/X0n/jTVuoyy3s0cinT5MRTI9Okq8qW3r0QhoeTTJtWrYcC XUcKQoo9l2GwW4PVUJz2mywMzmhCqSSXhKOHbxwIKjoCXRfTkXichpDkQcLrXewI8B7I wTivDpcEt/kSw0mKa3gp/D+zq8CR5Oo4XOcXXpLxjMfKd/o79Dd/mgVqlHuKqbynMTRG qQ0LrScsnq3Toa3beO/tDQiNiH5lbun422EW0+wEzsFIzL0VAD5a6rvR+wujCAuIbmlu 6GJimch7AKo7xJJtqWQx5602HiHQkQTIJr0Z0ytMPX9rWaAAMpd+DDY4Ed8VeaN0Fw6q yqQw== X-Gm-Message-State: AA+aEWb4im8nJOwhNbfJ39lgxj42pPWCaFjEJ6XrOFP9brpd4zmEU4CZ VUW9v1wpvWjEXzSBB1F5ZT4c7TJ8u3SOnDeV X-Google-Smtp-Source: AFSGD/VM7F0kGTIy0cX2pOcdsOqEqFSNuTdNAmpJ+REDGWnTy4D/h97lqyuRTzkAuolJ0d1xdclAWpN5MQUhPKye X-Received: by 2002:a05:660c:fd6:: with SMTP id m22mr10478359itn.14.1544463501954; Mon, 10 Dec 2018 09:38:21 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:42 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-14-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 13/22] dm: sound: Move common code out of maxim98095 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The register-access code is useful for any maxim codec. Move it out into its own file. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: - Add new patch to move common code out of maxim98095 drivers/sound/Makefile | 2 +- drivers/sound/max98095.c | 181 ++++++++++-------------------------- drivers/sound/max98095.h | 2 + drivers/sound/maxim_codec.c | 87 +++++++++++++++++ drivers/sound/maxim_codec.h | 67 +++++++++++++ 5 files changed, 204 insertions(+), 135 deletions(-) create mode 100644 drivers/sound/maxim_codec.c create mode 100644 drivers/sound/maxim_codec.h diff --git a/drivers/sound/Makefile b/drivers/sound/Makefile index 75fa31ec534..b08845599f9 100644 --- a/drivers/sound/Makefile +++ b/drivers/sound/Makefile @@ -15,4 +15,4 @@ else obj-$(CONFIG_I2S) += sound-i2s.o endif obj-$(CONFIG_SOUND_WM8994) += wm8994.o -obj-$(CONFIG_SOUND_MAX98095) += max98095.o +obj-$(CONFIG_SOUND_MAX98095) += max98095.o maxim_codec.o diff --git a/drivers/sound/max98095.c b/drivers/sound/max98095.c index d6710dfaa7a..e9bf64f82f8 100644 --- a/drivers/sound/max98095.c +++ b/drivers/sound/max98095.c @@ -25,96 +25,10 @@ #include "i2s.h" #include "max98095.h" -struct max98095_priv { - unsigned int sysclk; - unsigned int rate; - unsigned int fmt; - int i2c_addr; - struct udevice *dev; -}; - /* Index 0 is reserved. */ int rate_table[] = {0, 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000}; -/* - * Writes value to a device register through i2c - * - * @param priv Private data for driver - * @param reg reg number to be write - * @param data data to be writen to the above registor - * - * @return int value 1 for change, 0 for no change or negative error code. - */ -static int max98095_i2c_write(struct max98095_priv *priv, unsigned int reg, - unsigned char data) -{ - debug("%s: Write Addr : 0x%02X, Data : 0x%02X\n", - __func__, reg, data); -#ifdef CONFIG_DM_SOUND - debug("dev = %s\n", priv->dev->name); - return dm_i2c_write(priv->dev, reg, &data, 1); -#else - return i2c_write(priv->i2c_addr, reg, 1, &data, 1); -#endif -} - -/* - * Read a value from a device register through i2c - * - * @param priv Private data for driver - * @param reg reg number to be read - * @param data address of read data to be stored - * - * @return int value 0 for success, -1 in case of error. - */ -static unsigned int max98095_i2c_read(struct max98095_priv *priv, - unsigned int reg, unsigned char *data) -{ - int ret; - -#ifdef CONFIG_DM_SOUND - return dm_i2c_read(priv->dev, reg, data, 1); -#else - ret = i2c_read(priv->i2c_addr, reg, 1, data, 1); -#endif - if (ret != 0) { - debug("%s: Error while reading register %#04x\n", - __func__, reg); - return -1; - } - - return 0; -} - -/* - * update device register bits through i2c - * - * @param priv Private data for driver - * @param reg codec register - * @param mask register mask - * @param value new value - * - * @return int value 0 for success, non-zero error code. - */ -static int max98095_bic_or(struct max98095_priv *priv, unsigned int reg, - unsigned char mask, unsigned char value) -{ - int change, ret = 0; - unsigned char old, new; - - if (max98095_i2c_read(priv, reg, &old) != 0) - return -1; - new = (old & ~mask) | (value & mask); - change = (old != new) ? 1 : 0; - if (change) - ret = max98095_i2c_write(priv, reg, new); - if (ret < 0) - return ret; - - return change; -} - /* * codec mclk clock divider coefficients based on sampling rate * @@ -147,7 +61,7 @@ static int rate_value(int rate, u8 *value) * * @return -1 for error and 0 Success. */ -static int max98095_hw_params(struct max98095_priv *priv, +static int max98095_hw_params(struct maxim_priv *priv, enum en_max_audio_interface aif_id, unsigned int rate, unsigned int bits_per_sample) { @@ -169,12 +83,11 @@ static int max98095_hw_params(struct max98095_priv *priv, switch (bits_per_sample) { case 16: - error = max98095_bic_or(priv, M98095_DAI_FORMAT, M98095_DAI_WS, - 0); + error = maxim_bic_or(priv, M98095_DAI_FORMAT, M98095_DAI_WS, 0); break; case 24: - error = max98095_bic_or(priv, M98095_DAI_FORMAT, M98095_DAI_WS, - M98095_DAI_WS); + error = maxim_bic_or(priv, M98095_DAI_FORMAT, M98095_DAI_WS, + M98095_DAI_WS); break; default: debug("%s: Illegal bits per sample %d.\n", @@ -189,15 +102,15 @@ static int max98095_hw_params(struct max98095_priv *priv, } priv->rate = rate; - error |= max98095_bic_or(priv, M98095_DAI_CLKMODE, M98095_CLKMODE_MASK, + error |= maxim_bic_or(priv, M98095_DAI_CLKMODE, M98095_CLKMODE_MASK, regval); /* Update sample rate mode */ if (rate < 50000) - error |= max98095_bic_or(priv, M98095_DAI_FILTERS, + error |= maxim_bic_or(priv, M98095_DAI_FILTERS, M98095_DAI_DHF, 0); else - error |= max98095_bic_or(priv, M98095_DAI_FILTERS, + error |= maxim_bic_or(priv, M98095_DAI_FILTERS, M98095_DAI_DHF, M98095_DAI_DHF); if (error < 0) { @@ -216,7 +129,7 @@ static int max98095_hw_params(struct max98095_priv *priv, * * @return -1 for error and 0 success. */ -static int max98095_set_sysclk(struct max98095_priv *priv, unsigned int freq) +static int max98095_set_sysclk(struct maxim_priv *priv, unsigned int freq) { int error = 0; @@ -230,11 +143,11 @@ static int max98095_set_sysclk(struct max98095_priv *priv, unsigned int freq) * 0x03 (when master clk is 40MHz to 60MHz).. */ if ((freq >= 10000000) && (freq < 20000000)) { - error = max98095_i2c_write(priv, M98095_026_SYS_CLK, 0x10); + error = maxim_i2c_write(priv, M98095_026_SYS_CLK, 0x10); } else if ((freq >= 20000000) && (freq < 40000000)) { - error = max98095_i2c_write(priv, M98095_026_SYS_CLK, 0x20); + error = maxim_i2c_write(priv, M98095_026_SYS_CLK, 0x20); } else if ((freq >= 40000000) && (freq < 60000000)) { - error = max98095_i2c_write(priv, M98095_026_SYS_CLK, 0x30); + error = maxim_i2c_write(priv, M98095_026_SYS_CLK, 0x30); } else { debug("%s: Invalid master clock frequency\n", __func__); return -1; @@ -258,7 +171,7 @@ static int max98095_set_sysclk(struct max98095_priv *priv, unsigned int freq) * * @return -1 for error and 0 Success. */ -static int max98095_set_fmt(struct max98095_priv *priv, int fmt, +static int max98095_set_fmt(struct maxim_priv *priv, int fmt, enum en_max_audio_interface aif_id) { u8 regval = 0; @@ -288,8 +201,8 @@ static int max98095_set_fmt(struct max98095_priv *priv, int fmt, switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBS_CFS: /* Slave mode PLL */ - error |= max98095_i2c_write(priv, M98095_DAI_CLKCFG_HI, 0x80); - error |= max98095_i2c_write(priv, M98095_DAI_CLKCFG_LO, 0x00); + error |= maxim_i2c_write(priv, M98095_DAI_CLKCFG_HI, 0x80); + error |= maxim_i2c_write(priv, M98095_DAI_CLKCFG_LO, 0x00); break; case SND_SOC_DAIFMT_CBM_CFM: /* Set to master mode */ @@ -330,11 +243,11 @@ static int max98095_set_fmt(struct max98095_priv *priv, int fmt, return -1; } - error |= max98095_bic_or(priv, M98095_DAI_FORMAT, + error |= maxim_bic_or(priv, M98095_DAI_FORMAT, M98095_DAI_MAS | M98095_DAI_DLY | M98095_DAI_BCI | M98095_DAI_WCI, regval); - error |= max98095_i2c_write(priv, M98095_DAI_CLOCK, M98095_DAI_BSEL64); + error |= maxim_i2c_write(priv, M98095_DAI_CLOCK, M98095_DAI_BSEL64); if (error < 0) { debug("%s: Error setting i2s format.\n", __func__); @@ -350,7 +263,7 @@ static int max98095_set_fmt(struct max98095_priv *priv, int fmt, * @param priv Private data for driver * @return -1 for error and 0 success. */ -static int max98095_reset(struct max98095_priv *priv) +static int max98095_reset(struct maxim_priv *priv) { int i, ret; @@ -358,13 +271,13 @@ static int max98095_reset(struct max98095_priv *priv) * Gracefully reset the DSP core and the codec hardware in a proper * sequence. */ - ret = max98095_i2c_write(priv, M98095_00F_HOST_CFG, 0); + ret = maxim_i2c_write(priv, M98095_00F_HOST_CFG, 0); if (ret != 0) { debug("%s: Failed to reset DSP: %d\n", __func__, ret); return ret; } - ret = max98095_i2c_write(priv, M98095_097_PWR_SYS, 0); + ret = maxim_i2c_write(priv, M98095_097_PWR_SYS, 0); if (ret != 0) { debug("%s: Failed to reset codec: %d\n", __func__, ret); return ret; @@ -375,7 +288,7 @@ static int max98095_reset(struct max98095_priv *priv) * reset hardware control register. */ for (i = M98095_010_HOST_INT_CFG; i < M98095_REG_MAX_CACHED; i++) { - ret = max98095_i2c_write(priv, i, 0); + ret = maxim_i2c_write(priv, i, 0); if (ret < 0) { debug("%s: Failed to reset: %d\n", __func__, ret); return ret; @@ -392,7 +305,7 @@ static int max98095_reset(struct max98095_priv *priv) * * @returns -1 for error and 0 Success. */ -static int max98095_device_init(struct max98095_priv *priv) +static int max98095_device_init(struct maxim_priv *priv) { unsigned char id; int error = 0; @@ -412,7 +325,7 @@ static int max98095_device_init(struct max98095_priv *priv) priv->rate = -1U; priv->fmt = -1U; - error = max98095_i2c_read(priv, M98095_0FF_REV_ID, &id); + error = maxim_i2c_read(priv, M98095_0FF_REV_ID, &id); if (error < 0) { debug("%s: Failure reading hardware revision: %d\n", __func__, id); @@ -423,63 +336,63 @@ static int max98095_device_init(struct max98095_priv *priv) return 0; } -static int max98095_setup_interface(struct max98095_priv *priv, +static int max98095_setup_interface(struct maxim_priv *priv, enum en_max_audio_interface aif_id) { int error; - error = max98095_i2c_write(priv, M98095_097_PWR_SYS, M98095_PWRSV); + error = maxim_i2c_write(priv, M98095_097_PWR_SYS, M98095_PWRSV); /* * initialize registers to hardware default configuring audio * interface2 to DAC */ if (aif_id == AIF1) - error |= max98095_i2c_write(priv, M98095_048_MIX_DAC_LR, + error |= maxim_i2c_write(priv, M98095_048_MIX_DAC_LR, M98095_DAI1L_TO_DACL | M98095_DAI1R_TO_DACR); else - error |= max98095_i2c_write(priv, M98095_048_MIX_DAC_LR, + error |= maxim_i2c_write(priv, M98095_048_MIX_DAC_LR, M98095_DAI2M_TO_DACL | M98095_DAI2M_TO_DACR); - error |= max98095_i2c_write(priv, M98095_092_PWR_EN_OUT, + error |= maxim_i2c_write(priv, M98095_092_PWR_EN_OUT, M98095_SPK_SPREADSPECTRUM); - error |= max98095_i2c_write(priv, M98095_04E_CFG_HP, M98095_HPNORMAL); + error |= maxim_i2c_write(priv, M98095_04E_CFG_HP, M98095_HPNORMAL); if (aif_id == AIF1) - error |= max98095_i2c_write(priv, M98095_02C_DAI1_IOCFG, + error |= maxim_i2c_write(priv, M98095_02C_DAI1_IOCFG, M98095_S1NORMAL | M98095_SDATA); else - error |= max98095_i2c_write(priv, M98095_036_DAI2_IOCFG, + error |= maxim_i2c_write(priv, M98095_036_DAI2_IOCFG, M98095_S2NORMAL | M98095_SDATA); /* take the codec out of the shut down */ - error |= max98095_bic_or(priv, M98095_097_PWR_SYS, M98095_SHDNRUN, + error |= maxim_bic_or(priv, M98095_097_PWR_SYS, M98095_SHDNRUN, M98095_SHDNRUN); /* * route DACL and DACR output to HO and Speakers * Ordering: DACL, DACR, DACL, DACR */ - error |= max98095_i2c_write(priv, M98095_050_MIX_SPK_LEFT, 0x01); - error |= max98095_i2c_write(priv, M98095_051_MIX_SPK_RIGHT, 0x01); - error |= max98095_i2c_write(priv, M98095_04C_MIX_HP_LEFT, 0x01); - error |= max98095_i2c_write(priv, M98095_04D_MIX_HP_RIGHT, 0x01); + error |= maxim_i2c_write(priv, M98095_050_MIX_SPK_LEFT, 0x01); + error |= maxim_i2c_write(priv, M98095_051_MIX_SPK_RIGHT, 0x01); + error |= maxim_i2c_write(priv, M98095_04C_MIX_HP_LEFT, 0x01); + error |= maxim_i2c_write(priv, M98095_04D_MIX_HP_RIGHT, 0x01); /* power Enable */ - error |= max98095_i2c_write(priv, M98095_091_PWR_EN_OUT, 0xF3); + error |= maxim_i2c_write(priv, M98095_091_PWR_EN_OUT, 0xF3); /* set Volume */ - error |= max98095_i2c_write(priv, M98095_064_LVL_HP_L, 15); - error |= max98095_i2c_write(priv, M98095_065_LVL_HP_R, 15); - error |= max98095_i2c_write(priv, M98095_067_LVL_SPK_L, 16); - error |= max98095_i2c_write(priv, M98095_068_LVL_SPK_R, 16); + error |= maxim_i2c_write(priv, M98095_064_LVL_HP_L, 15); + error |= maxim_i2c_write(priv, M98095_065_LVL_HP_R, 15); + error |= maxim_i2c_write(priv, M98095_067_LVL_SPK_L, 16); + error |= maxim_i2c_write(priv, M98095_068_LVL_SPK_R, 16); /* Enable DAIs */ - error |= max98095_i2c_write(priv, M98095_093_BIAS_CTRL, 0x30); + error |= maxim_i2c_write(priv, M98095_093_BIAS_CTRL, 0x30); if (aif_id == AIF1) - error |= max98095_i2c_write(priv, M98095_096_PWR_DAC_CK, 0x01); + error |= maxim_i2c_write(priv, M98095_096_PWR_DAC_CK, 0x01); else - error |= max98095_i2c_write(priv, M98095_096_PWR_DAC_CK, 0x07); + error |= maxim_i2c_write(priv, M98095_096_PWR_DAC_CK, 0x07); if (error < 0) return -1; @@ -487,7 +400,7 @@ static int max98095_setup_interface(struct max98095_priv *priv, return 0; } -static int max98095_do_init(struct max98095_priv *priv, +static int max98095_do_init(struct maxim_priv *priv, enum en_max_audio_interface aif_id, int sampling_rate, int mclk_freq, int bits_per_sample) @@ -601,7 +514,7 @@ static int max98095_set_params(struct udevice *dev, int interface, int rate, int mclk_freq, int bits_per_sample, uint channels) { - struct max98095_priv *priv = dev_get_priv(dev); + struct maxim_priv *priv = dev_get_priv(dev); return max98095_do_init(priv, interface, rate, mclk_freq, bits_per_sample); @@ -609,7 +522,7 @@ static int max98095_set_params(struct udevice *dev, int interface, int rate, static int max98095_probe(struct udevice *dev) { - struct max98095_priv *priv = dev_get_priv(dev); + struct maxim_priv *priv = dev_get_priv(dev); int ret; priv->dev = dev; @@ -637,5 +550,5 @@ U_BOOT_DRIVER(max98095) = { .of_match = max98095_ids, .probe = max98095_probe, .ops = &max98095_ops, - .priv_auto_alloc_size = sizeof(struct max98095_priv), + .priv_auto_alloc_size = sizeof(struct maxim_priv), }; diff --git a/drivers/sound/max98095.h b/drivers/sound/max98095.h index 13ae177a86b..f189db728d1 100644 --- a/drivers/sound/max98095.h +++ b/drivers/sound/max98095.h @@ -11,6 +11,8 @@ #ifndef _MAX98095_H #define _MAX98095_H +#include "maxim_codec.h" + /* Available audio interface ports in wm8994 codec */ enum en_max_audio_interface { AIF1, diff --git a/drivers/sound/maxim_codec.c b/drivers/sound/maxim_codec.c new file mode 100644 index 00000000000..dcaf081988b --- /dev/null +++ b/drivers/sound/maxim_codec.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * maxim_codec.c -- MAXIM CODEC Common driver + * + * Copyright 2011 Maxim Integrated Products + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "maxim_codec.h" + +/* + * Writes value to a device register through i2c + * + * @param priv Private data for driver + * @param reg reg number to be write + * @param data data to be writen to the above registor + * + * @return int value 1 for change, 0 for no change or negative error code. + */ +int maxim_i2c_write(struct maxim_priv *priv, unsigned int reg, + unsigned char data) +{ + debug("%s: Write Addr : 0x%02X, Data : 0x%02X\n", + __func__, reg, data); + return dm_i2c_write(priv->dev, reg, &data, 1); +} + +/* + * Read a value from a device register through i2c + * + * @param priv Private data for driver + * @param reg reg number to be read + * @param data address of read data to be stored + * + * @return int value 0 for success, -1 in case of error. + */ +unsigned int maxim_i2c_read(struct maxim_priv *priv, unsigned int reg, + unsigned char *data) +{ + int ret; + + return dm_i2c_read(priv->dev, reg, data, 1); + if (ret != 0) { + debug("%s: Error while reading register %#04x\n", + __func__, reg); + return -1; + } + + return 0; +} + +/* + * update device register bits through i2c + * + * @param priv Private data for driver + * @param reg codec register + * @param mask register mask + * @param value new value + * + * @return int value 0 for success, non-zero error code. + */ +int maxim_bic_or(struct maxim_priv *priv, unsigned int reg, unsigned char mask, + unsigned char value) +{ + int change, ret = 0; + unsigned char old, new; + + if (maxim_i2c_read(priv, reg, &old) != 0) + return -1; + new = (old & ~mask) | (value & mask); + change = (old != new) ? 1 : 0; + if (change) + ret = maxim_i2c_write(priv, reg, new); + if (ret < 0) + return ret; + + return change; +} diff --git a/drivers/sound/maxim_codec.h b/drivers/sound/maxim_codec.h new file mode 100644 index 00000000000..a3128e0bb73 --- /dev/null +++ b/drivers/sound/maxim_codec.h @@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * maxim_codec.h -- MAXIM codec common interface file + * + * Copyright (C) 2013 Samsung Electronics + * D Krishna Mohan + */ + +#ifndef __MAXIM_COMMON_H__ +#define __MAXIM_COMMON_H__ + +enum maxim_codec_type { + MAX98095, + MAX98090, +}; + +struct maxim_priv { + enum maxim_codec_type devtype; + unsigned int sysclk; + unsigned int rate; + unsigned int fmt; + struct udevice *dev; +}; + +#define MAXIM_AUDIO_I2C_BUS 7 +#define MAXIM_AUDIO_I2C_REG_98095 0x22 + +#define MAXIM_AUDIO_I2C_REG MAXIM_AUDIO_I2C_REG_98095 + +/* + * Writes value to a device register through i2c + * + * @param priv Private data for driver + * @param reg reg number to be write + * @param data data to be writen to the above registor + * + * @return int value 1 for change, 0 for no change or negative error code. + */ +int maxim_i2c_write(struct maxim_priv *priv, unsigned int reg, + unsigned char data); + +/* + * Read a value from a device register through i2c + * + * @param priv Private data for driver + * @param reg reg number to be read + * @param data address of read data to be stored + * + * @return int value 0 for success, -1 in case of error. + */ +unsigned int maxim_i2c_read(struct maxim_priv *priv, unsigned int reg, + unsigned char *data); + +/* + * update device register bits through i2c + * + * @param priv Private data for driver + * @param reg codec register + * @param mask register mask + * @param value new value + * + * @return int value 0 for success, non-zero error code. + */ +int maxim_bic_or(struct maxim_priv *priv, unsigned int reg, unsigned char mask, + unsigned char value); + +#endif /* __MAXIM_COMMON_H__ */ From patchwork Mon Dec 10 17:37:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010582 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Ac+kXrtj"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9Ys66JXz9s3l for ; Tue, 11 Dec 2018 04:49:21 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 4D34DC22828; Mon, 10 Dec 2018 17:46:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id BB590C22877; Mon, 10 Dec 2018 17:38:57 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A791AC2286D; Mon, 10 Dec 2018 17:38:29 +0000 (UTC) Received: from mail-it1-f199.google.com (mail-it1-f199.google.com [209.85.166.199]) by lists.denx.de (Postfix) with ESMTPS id 636C8C22641 for ; Mon, 10 Dec 2018 17:38:24 +0000 (UTC) Received: by mail-it1-f199.google.com with SMTP id o205so14367612itc.2 for ; Mon, 10 Dec 2018 09:38:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=xb/rTLCptn3WuMunWpJfSsT/pRuyGxuhtRxKQlODlLw=; b=Ac+kXrtjB5rFelNvyi89D8N4z0Z1MCctGekFmrrXf182sSGo269e4P+fqI3OaOUHLa +Wp49dEIYMu54HdRft0dCdeDR5xQuQiYOlGiG9G4qOZ3/8qd5KTx99dx+qY+EympEwYs Xif6v4mEPEvVtxn93GdW6Ig2r2ioiXYWKub8w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xb/rTLCptn3WuMunWpJfSsT/pRuyGxuhtRxKQlODlLw=; b=SZXQBqPLrGdLdFKjXS5MgxJhT0w0f784K7egDhznbZs9X6rMfqT2LKKQIy6MBhogJN T3gWj8iEUNGCNoUAIIj4lrFqv+CaxajsCQrD90yIxVuSTe6LIbEoKz9aUTpQDohp1CkB /8GQ9CySB+wJ3VZJJLWiN6wUHlNWUelWgQ9FRlD0VTo0LWyA28oHiZgec1OE1DN9JdLB 0JY9AooyJcGy5HlWGkzzwWojYSXcQK3GLtdfFla9EHbqADu3qwV1wiJopokYzMGAH6P3 Q1aZm3ccqALjWPHVnHG9ErOu40yURFriHCJvvDHoEXJY0rETn1w3xk8WmxZ4APiGTbTE UU7g== X-Gm-Message-State: AA+aEWY1FMA2IfIFephmPRyW6lopCR0XzJwlBePKwznUUUzs5smSSbIY LbENR1wBzmETNc4Y4LAU8+E6jD6KoKP7uGSn X-Google-Smtp-Source: AFSGD/WUi3e6oE193u8ShNlTDDURmqjc9WK+UllW9eVU3448C0Bf2V0koeGcC2NzZyFGN+bBDL8Pwzi2LpnKQNxI X-Received: by 2002:a05:660c:fd6:: with SMTP id m22mr10478402itn.14.1544463503332; Mon, 10 Dec 2018 09:38:23 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:43 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-15-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 14/22] dm: sound: exynos: Add support for max98090 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add support for this new codec which is used by pit. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: - Add new patch with support for max98090 drivers/sound/Kconfig | 8 + drivers/sound/Makefile | 1 + drivers/sound/max98090.c | 377 ++++++++++++++++++++++ drivers/sound/max98090.h | 663 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 1049 insertions(+) create mode 100644 drivers/sound/max98090.c create mode 100644 drivers/sound/max98090.h diff --git a/drivers/sound/Kconfig b/drivers/sound/Kconfig index 93f6c36af32..18d7ca1dcb3 100644 --- a/drivers/sound/Kconfig +++ b/drivers/sound/Kconfig @@ -37,6 +37,14 @@ config I2S_SAMSUNG option provides an implementation for sound_init() and sound_play(). +config SOUND_MAX98090 + bool "Support Maxim max98090 audio codec" + depends on I2S_SAMSUNG + help + Enable the max98090 audio codec. This is connected via I2S for + audio data and I2C for codec control. At present it only works + with the Samsung I2S driver. + config SOUND_MAX98095 bool "Support Maxim max98095 audio codec" depends on I2S_SAMSUNG diff --git a/drivers/sound/Makefile b/drivers/sound/Makefile index b08845599f9..937df152fe6 100644 --- a/drivers/sound/Makefile +++ b/drivers/sound/Makefile @@ -15,4 +15,5 @@ else obj-$(CONFIG_I2S) += sound-i2s.o endif obj-$(CONFIG_SOUND_WM8994) += wm8994.o +obj-$(CONFIG_SOUND_MAX98090) += max98090.o maxim_codec.o obj-$(CONFIG_SOUND_MAX98095) += max98095.o maxim_codec.o diff --git a/drivers/sound/max98090.c b/drivers/sound/max98090.c new file mode 100644 index 00000000000..346ff5ffbec --- /dev/null +++ b/drivers/sound/max98090.c @@ -0,0 +1,377 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * max98090.c -- MAX98090 ALSA SoC Audio driver + * + * Copyright 2011 Maxim Integrated Products + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "maxim_codec.h" +#include "max98090.h" + +/* + * Sets hw params for max98090 + * + * @priv: max98090 information pointer + * @rate: Sampling rate + * @bits_per_sample: Bits per sample + * + * @return -EIO for error, 0 for success. + */ +int max98090_hw_params(struct maxim_priv *priv, unsigned int rate, + unsigned int bits_per_sample) +{ + int error; + unsigned char value; + + switch (bits_per_sample) { + case 16: + maxim_i2c_read(priv, M98090_REG_INTERFACE_FORMAT, &value); + error = maxim_bic_or(priv, M98090_REG_INTERFACE_FORMAT, + M98090_WS_MASK, 0); + maxim_i2c_read(priv, M98090_REG_INTERFACE_FORMAT, &value); + break; + default: + debug("%s: Illegal bits per sample %d.\n", + __func__, bits_per_sample); + return -1; + } + + /* Update filter mode */ + if (rate < 240000) + error |= maxim_bic_or(priv, M98090_REG_FILTER_CONFIG, + M98090_MODE_MASK, 0); + else + error |= maxim_bic_or(priv, M98090_REG_FILTER_CONFIG, + M98090_MODE_MASK, M98090_MODE_MASK); + + /* Update sample rate mode */ + if (rate < 50000) + error |= maxim_bic_or(priv, M98090_REG_FILTER_CONFIG, + M98090_DHF_MASK, 0); + else + error |= maxim_bic_or(priv, M98090_REG_FILTER_CONFIG, + M98090_DHF_MASK, M98090_DHF_MASK); + + if (error < 0) { + debug("%s: Error setting hardware params.\n", __func__); + return -EIO; + } + priv->rate = rate; + + return 0; +} + +/* + * Configures Audio interface system clock for the given frequency + * + * @priv: max98090 information + * @freq: Sampling frequency in Hz + * + * @return -EIO for error, 0 for success. + */ +int max98090_set_sysclk(struct maxim_priv *priv, unsigned int freq) +{ + int error = 0; + + /* Requested clock frequency is already setup */ + if (freq == priv->sysclk) + return 0; + + /* Setup clocks for slave mode, and using the PLL + * PSCLK = 0x01 (when master clk is 10MHz to 20MHz) + * 0x02 (when master clk is 20MHz to 40MHz).. + * 0x03 (when master clk is 40MHz to 60MHz).. + */ + if (freq >= 10000000 && freq < 20000000) { + error = maxim_i2c_write(priv, M98090_REG_SYSTEM_CLOCK, + M98090_PSCLK_DIV1); + } else if (freq >= 20000000 && freq < 40000000) { + error = maxim_i2c_write(priv, M98090_REG_SYSTEM_CLOCK, + M98090_PSCLK_DIV2); + } else if (freq >= 40000000 && freq < 60000000) { + error = maxim_i2c_write(priv, M98090_REG_SYSTEM_CLOCK, + M98090_PSCLK_DIV4); + } else { + debug("%s: Invalid master clock frequency\n", __func__); + return -1; + } + + debug("%s: Clock at %uHz\n", __func__, freq); + + if (error < 0) + return -1; + + priv->sysclk = freq; + + return 0; +} + +/* + * Sets Max98090 I2S format + * + * @priv: max98090 information + * @fmt: i2S format - supports a subset of the options defined in i2s.h. + * + * @return -EIO for error, 0 for success. + */ +int max98090_set_fmt(struct maxim_priv *priv, int fmt) +{ + u8 regval = 0; + int error = 0; + + if (fmt == priv->fmt) + return 0; + + priv->fmt = fmt; + + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { + case SND_SOC_DAIFMT_CBS_CFS: + /* Set to slave mode PLL - MAS mode off */ + error |= maxim_i2c_write(priv, M98090_REG_CLOCK_RATIO_NI_MSB, + 0x00); + error |= maxim_i2c_write(priv, M98090_REG_CLOCK_RATIO_NI_LSB, + 0x00); + error |= maxim_bic_or(priv, M98090_REG_CLOCK_MODE, + M98090_USE_M1_MASK, 0); + break; + case SND_SOC_DAIFMT_CBM_CFM: + /* Set to master mode */ + debug("Master mode not supported\n"); + break; + case SND_SOC_DAIFMT_CBS_CFM: + case SND_SOC_DAIFMT_CBM_CFS: + default: + debug("%s: Clock mode unsupported\n", __func__); + return -EINVAL; + } + + error |= maxim_i2c_write(priv, M98090_REG_MASTER_MODE, regval); + + regval = 0; + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { + case SND_SOC_DAIFMT_I2S: + regval |= M98090_DLY_MASK; + break; + case SND_SOC_DAIFMT_LEFT_J: + break; + case SND_SOC_DAIFMT_RIGHT_J: + regval |= M98090_RJ_MASK; + break; + case SND_SOC_DAIFMT_DSP_A: + /* Not supported mode */ + default: + debug("%s: Unrecognized format.\n", __func__); + return -EINVAL; + } + + switch (fmt & SND_SOC_DAIFMT_INV_MASK) { + case SND_SOC_DAIFMT_NB_NF: + break; + case SND_SOC_DAIFMT_NB_IF: + regval |= M98090_WCI_MASK; + break; + case SND_SOC_DAIFMT_IB_NF: + regval |= M98090_BCI_MASK; + break; + case SND_SOC_DAIFMT_IB_IF: + regval |= M98090_BCI_MASK | M98090_WCI_MASK; + break; + default: + debug("%s: Unrecognized inversion settings.\n", __func__); + return -EINVAL; + } + + error |= maxim_i2c_write(priv, M98090_REG_INTERFACE_FORMAT, regval); + + if (error < 0) { + debug("%s: Error setting i2s format.\n", __func__); + return -EIO; + } + + return 0; +} + +/* + * resets the audio codec + * + * @priv: max98090 information + * @return -EIO for error, 0 for success. + */ +static int max98090_reset(struct maxim_priv *priv) +{ + int ret; + + /* + * Gracefully reset the DSP core and the codec hardware in a proper + * sequence. + */ + ret = maxim_i2c_write(priv, M98090_REG_SOFTWARE_RESET, + M98090_SWRESET_MASK); + if (ret != 0) { + debug("%s: Failed to reset DSP: %d\n", __func__, ret); + return ret; + } + mdelay(20); + + return 0; +} + +/* + * Initialise max98090 codec device + * + * @priv: max98090 information + * + * @return -EIO for error, 0 for success. + */ +int max98090_device_init(struct maxim_priv *priv) +{ + unsigned char id; + int error = 0; + + /* Enable codec clock */ + set_xclkout(); + + /* reset the codec, the DSP core, and disable all interrupts */ + error = max98090_reset(priv); + if (error != 0) { + debug("Reset\n"); + return error; + } + + /* initialize private data */ + priv->sysclk = -1U; + priv->rate = -1U; + priv->fmt = -1U; + + error = maxim_i2c_read(priv, M98090_REG_REVISION_ID, &id); + if (error < 0) { + debug("%s: Failure reading hardware revision: %d\n", + __func__, id); + return -EIO; + } + debug("%s: Hardware revision: %d\n", __func__, id); + + return 0; +} + +static int max98090_setup_interface(struct maxim_priv *priv) +{ + unsigned char id; + int error; + + /* Reading interrupt status to clear them */ + error = maxim_i2c_read(priv, M98090_REG_DEVICE_STATUS, &id); + + error |= maxim_i2c_write(priv, M98090_REG_DAC_CONTROL, + M98090_DACHP_MASK); + error |= maxim_i2c_write(priv, M98090_REG_BIAS_CONTROL, + M98090_VCM_MODE_MASK); + + error |= maxim_i2c_write(priv, M98090_REG_LEFT_SPK_MIXER, 0x1); + error |= maxim_i2c_write(priv, M98090_REG_RIGHT_SPK_MIXER, 0x2); + + error |= maxim_i2c_write(priv, M98090_REG_LEFT_SPK_VOLUME, 0x25); + error |= maxim_i2c_write(priv, M98090_REG_RIGHT_SPK_VOLUME, 0x25); + + error |= maxim_i2c_write(priv, M98090_REG_CLOCK_RATIO_NI_MSB, 0x0); + error |= maxim_i2c_write(priv, M98090_REG_CLOCK_RATIO_NI_LSB, 0x0); + error |= maxim_i2c_write(priv, M98090_REG_MASTER_MODE, 0x0); + error |= maxim_i2c_write(priv, M98090_REG_INTERFACE_FORMAT, 0x0); + error |= maxim_i2c_write(priv, M98090_REG_IO_CONFIGURATION, + M98090_SDIEN_MASK); + error |= maxim_i2c_write(priv, M98090_REG_DEVICE_SHUTDOWN, + M98090_SHDNN_MASK); + error |= maxim_i2c_write(priv, M98090_REG_OUTPUT_ENABLE, + M98090_HPREN_MASK | M98090_HPLEN_MASK | + M98090_SPREN_MASK | M98090_SPLEN_MASK | + M98090_DAREN_MASK | M98090_DALEN_MASK); + error |= maxim_i2c_write(priv, M98090_REG_IO_CONFIGURATION, + M98090_SDOEN_MASK | M98090_SDIEN_MASK); + + if (error < 0) + return -EIO; + + return 0; +} + +static int max98090_do_init(struct maxim_priv *priv, int sampling_rate, + int mclk_freq, int bits_per_sample) +{ + int ret = 0; + + ret = max98090_setup_interface(priv); + if (ret < 0) { + debug("%s: max98090 setup interface failed\n", __func__); + return ret; + } + + ret = max98090_set_sysclk(priv, mclk_freq); + if (ret < 0) { + debug("%s: max98090 codec set sys clock failed\n", __func__); + return ret; + } + + ret = max98090_hw_params(priv, sampling_rate, bits_per_sample); + + if (ret == 0) { + ret = max98090_set_fmt(priv, SND_SOC_DAIFMT_I2S | + SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS); + } + + return ret; +} + +static int max98090_set_params(struct udevice *dev, int interface, int rate, + int mclk_freq, int bits_per_sample, + uint channels) +{ + struct maxim_priv *priv = dev_get_priv(dev); + + return max98090_do_init(priv, rate, mclk_freq, bits_per_sample); +} + +static int max98090_probe(struct udevice *dev) +{ + struct maxim_priv *priv = dev_get_priv(dev); + int ret; + + priv->dev = dev; + ret = max98090_device_init(priv); + if (ret < 0) { + debug("%s: max98090 codec chip init failed\n", __func__); + return ret; + } + + return 0; +} + +static const struct audio_codec_ops max98090_ops = { + .set_params = max98090_set_params, +}; + +static const struct udevice_id max98090_ids[] = { + { .compatible = "maxim,max98090" }, + { } +}; + +U_BOOT_DRIVER(max98090) = { + .name = "max98090", + .id = UCLASS_AUDIO_CODEC, + .of_match = max98090_ids, + .probe = max98090_probe, + .ops = &max98090_ops, + .priv_auto_alloc_size = sizeof(struct maxim_priv), +}; diff --git a/drivers/sound/max98090.h b/drivers/sound/max98090.h new file mode 100644 index 00000000000..3a6983b8e2c --- /dev/null +++ b/drivers/sound/max98090.h @@ -0,0 +1,663 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * max98090.h -- MAX98090 ALSA SoC Audio driver + * + * Copyright 2011 Maxim Integrated Products + */ + +#ifndef _MAX98090_H +#define _MAX98090_H + +#include "maxim_codec.h" + +/* MAX98090 Registers Definition */ + +#define M98090_REG_SOFTWARE_RESET 0x00 +#define M98090_REG_DEVICE_STATUS 0x01 + +#define M98090_REG_QUICK_SAMPLE_RATE 0x05 +#define M98090_REG_DAI_INTERFACE 0x06 +#define M98090_REG_DAC_PATH 0x07 + +#define M98090_REG_MIC_BIAS_VOLTAGE 0x12 +#define M98090_REG_DIGITAL_MIC_ENABLE 0x13 +#define M98090_REG_DIGITAL_MIC_CONFIG 0x14 +#define M98090_REG_SYSTEM_CLOCK 0x1B +#define M98090_REG_CLOCK_RATIO_NI_MSB 0x1D +#define M98090_REG_CLOCK_MODE 0x1C +#define M98090_REG_CLOCK_RATIO_NI_LSB 0x1E + +#define M98090_REG_MASTER_MODE 0x21 +#define M98090_REG_INTERFACE_FORMAT 0x22 +#define M98090_REG_IO_CONFIGURATION 0x25 +#define M98090_REG_FILTER_CONFIG 0x26 + +#define M98090_REG_LEFT_HP_MIXER 0x29 +#define M98090_REG_RIGHT_HP_MIXER 0x2a +#define M98090_REG_HP_CONTROL 0x2b +#define M98090_REG_LEFT_HP_VOLUME 0x2c +#define M98090_REG_RIGHT_HP_VOLUME 0x2d +#define M98090_REG_LEFT_SPK_MIXER 0x2e +#define M98090_REG_RIGHT_SPK_MIXER 0x2f +#define M98090_REG_SPK_CONTROL 0x30 +#define M98090_REG_LEFT_SPK_VOLUME 0x31 +#define M98090_REG_RIGHT_SPK_VOLUME 0x32 + +#define M98090_REG_RCV_LOUTL_CONTROL 0x38 +#define M98090_REG_RCV_LOUTL_VOLUME 0x39 +#define M98090_REG_LOUTR_MIXER 0x3a +#define M98090_REG_LOUTR_CONTROL 0x3b +#define M98090_REG_LOUTR_VOLUME 0x3c +#define M98090_REG_JACK_DETECT 0x3d +#define M98090_REG_INPUT_ENABLE 0x3e +#define M98090_REG_OUTPUT_ENABLE 0x3f +#define M98090_REG_LEVEL_CONTROL 0x40 +#define M98090_REG_DSP_FILTER_ENABLE 0x41 +#define M98090_REG_BIAS_CONTROL 0x42 +#define M98090_REG_DAC_CONTROL 0x43 +#define M98090_REG_ADC_CONTROL 0x44 +#define M98090_REG_DEVICE_SHUTDOWN 0x45 + +#define M98090_REG_REVISION_ID 0xff + +#define M98090_REG_CNT (0xff + 1) +#define M98090_REG_MAX_CACHed 0x45 + +/* MAX98090 Registers Bit Fields */ + +/* + * M98090_REG_SOFTWARE_RESET 0x00 + */ +#define M98090_SWRESET_MASK BIT(7) + +/* + * M98090_REG_QUICK_SAMPLE_RATE 0x05 + */ +#define M98090_SR_96K_MASK BIT(5) +#define M98090_SR_96K_SHIFT 5 +#define M98090_SR_96K_WIDTH 1 +#define M98090_SR_32K_MASK BIT(4) +#define M98090_SR_32K_SHIFT 4 +#define M98090_SR_32K_WIDTH 1 +#define M98090_SR_48K_MASK BIT(3) +#define M98090_SR_48K_SHIFT 3 +#define M98090_SR_48K_WIDTH 1 +#define M98090_SR_44K1_MASK BIT(2) +#define M98090_SR_44K1_SHIFT 2 +#define M98090_SR_44K1_WIDTH 1 +#define M98090_SR_16K_MASK BIT(1) +#define M98090_SR_16K_SHIFT 1 +#define M98090_SR_16K_WIDTH 1 +#define M98090_SR_8K_MASK BIT(0) +#define M98090_SR_8K_SHIFT 0 +#define M98090_SR_8K_WIDTH 1 +#define M98090_SR_MASK 0x3F +#define M98090_SR_ALL_SHIFT 0 +#define M98090_SR_ALL_WIDTH 8 +#define M98090_SR_ALL_NUM BIT(M98090_SR_ALL_WIDTH) + +/* + * M98090_REG_DAI_INTERFACE 0x06 + */ +#define M98090_RJ_M_MASK BIT(5) +#define M98090_RJ_M_SHIFT 5 +#define M98090_RJ_M_WIDTH 1 +#define M98090_RJ_S_MASK BIT(4) +#define M98090_RJ_S_SHIFT 4 +#define M98090_RJ_S_WIDTH 1 +#define M98090_LJ_M_MASK BIT(3) +#define M98090_LJ_M_SHIFT 3 +#define M98090_LJ_M_WIDTH 1 +#define M98090_LJ_S_MASK BIT(2) +#define M98090_LJ_S_SHIFT 2 +#define M98090_LJ_S_WIDTH 1 +#define M98090_I2S_M_MASK BIT(1) +#define M98090_I2S_M_SHIFT 1 +#define M98090_I2S_M_WIDTH 1 +#define M98090_I2S_S_MASK BIT(0) +#define M98090_I2S_S_SHIFT 0 +#define M98090_I2S_S_WIDTH 1 +#define M98090_DAI_ALL_SHIFT 0 +#define M98090_DAI_ALL_WIDTH 8 +#define M98090_DAI_ALL_NUM BIT(M98090_DAI_ALL_WIDTH) + +/* + * M98090_REG_DAC_PATH 0x07 + */ +#define M98090_DIG2_HP_MASK BIT(7) +#define M98090_DIG2_HP_SHIFT 7 +#define M98090_DIG2_HP_WIDTH 1 +#define M98090_DIG2_EAR_MASK BIT(6) +#define M98090_DIG2_EAR_SHIFT 6 +#define M98090_DIG2_EAR_WIDTH 1 +#define M98090_DIG2_SPK_MASK BIT(5) +#define M98090_DIG2_SPK_SHIFT 5 +#define M98090_DIG2_SPK_WIDTH 1 +#define M98090_DIG2_LOUT_MASK BIT(4) +#define M98090_DIG2_LOUT_SHIFT 4 +#define M98090_DIG2_LOUT_WIDTH 1 +#define M98090_DIG2_ALL_SHIFT 0 +#define M98090_DIG2_ALL_WIDTH 8 +#define M98090_DIG2_ALL_NUM BIT(M98090_DIG2_ALL_WIDTH) + +/* + * M98090_REG_MIC_BIAS_VOLTAGE 0x12 + */ +#define M98090_MBVSEL_MASK (3 << 0) +#define M98090_MBVSEL_SHIFT 0 +#define M98090_MBVSEL_WIDTH 2 +#define M98090_MBVSEL_2V8 (3 << 0) +#define M98090_MBVSEL_2V55 (2 << 0) +#define M98090_MBVSEL_2V4 BIT(0) +#define M98090_MBVSEL_2V2 (0 << 0) + +/* + * M98090_REG_DIGITAL_MIC_ENABLE 0x13 + */ +#define M98090_MICCLK_MASK (7 << 4) +#define M98090_MICCLK_SHIFT 4 +#define M98090_MICCLK_WIDTH 3 +#define M98090_DIGMIC4_MASK BIT(3) +#define M98090_DIGMIC4_SHIFT 3 +#define M98090_DIGMIC4_WIDTH 1 +#define M98090_DIGMIC4_NUM BIT(M98090_DIGMIC4_WIDTH) +#define M98090_DIGMIC3_MASK BIT(2) +#define M98090_DIGMIC3_SHIFT 2 +#define M98090_DIGMIC3_WIDTH 1 +#define M98090_DIGMIC3_NUM BIT(M98090_DIGMIC3_WIDTH) +#define M98090_DIGMICR_MASK BIT(1) +#define M98090_DIGMICR_SHIFT 1 +#define M98090_DIGMICR_WIDTH 1 +#define M98090_DIGMICR_NUM BIT(M98090_DIGMICR_WIDTH) +#define M98090_DIGMICL_MASK BIT(0) +#define M98090_DIGMICL_SHIFT 0 +#define M98090_DIGMICL_WIDTH 1 +#define M98090_DIGMICL_NUM BIT(M98090_DIGMICL_WIDTH) + +/* + * M98090_REG_DIGITAL_MIC_CONFIG 0x14 + */ +#define M98090_DMIC_COMP_MASK (15 << 4) +#define M98090_DMIC_COMP_SHIFT 4 +#define M98090_DMIC_COMP_WIDTH 4 +#define M98090_DMIC_COMP_NUM BIT(M98090_DMIC_COMP_WIDTH) +#define M98090_DMIC_FREQ_MASK (3 << 0) +#define M98090_DMIC_FREQ_SHIFT 0 +#define M98090_DMIC_FREQ_WIDTH 2 + +/* + * M98090_REG_CLOCK_MODE 0x1B + */ +#define M98090_PSCLK_MASK (3 << 4) +#define M98090_PSCLK_SHIFT 4 +#define M98090_PSCLK_WIDTH 2 +#define M98090_PSCLK_DISABLED (0 << 4) +#define M98090_PSCLK_DIV1 BIT(4) +#define M98090_PSCLK_DIV2 (2 << 4) +#define M98090_PSCLK_DIV4 (3 << 4) + +/* + * M98090_REG_INTERFACE_FORMAT 0x22 + */ +#define M98090_RJ_MASK BIT(5) +#define M98090_RJ_SHIFT 5 +#define M98090_RJ_WIDTH 1 +#define M98090_WCI_MASK BIT(4) +#define M98090_WCI_SHIFT 4 +#define M98090_WCI_WIDTH 1 +#define M98090_BCI_MASK BIT(3) +#define M98090_BCI_SHIFT 3 +#define M98090_BCI_WIDTH 1 +#define M98090_DLY_MASK BIT(2) +#define M98090_DLY_SHIFT 2 +#define M98090_DLY_WIDTH 1 +#define M98090_WS_MASK (3 << 0) +#define M98090_WS_SHIFT 0 +#define M98090_WS_WIDTH 2 +#define M98090_WS_NUM BIT(M98090_WS_WIDTH) + +/* M98090_REG_IO_CONFIGURATION 0x25 */ +#define M98090_LTEN_MASK BIT(5) +#define M98090_LTEN_SHIFT 5 +#define M98090_LTEN_WIDTH 1 +#define M98090_LTEN_NUM BIT(M98090_LTEN_WIDTH) +#define M98090_LBEN_MASK BIT(4) +#define M98090_LBEN_SHIFT 4 +#define M98090_LBEN_WIDTH 1 +#define M98090_LBEN_NUM BIT(M98090_LBEN_WIDTH) +#define M98090_DMONO_MASK BIT(3) +#define M98090_DMONO_SHIFT 3 +#define M98090_DMONO_WIDTH 1 +#define M98090_DMONO_NUM BIT(M98090_DMONO_WIDTH) +#define M98090_HIZOFF_MASK BIT(2) +#define M98090_HIZOFF_SHIFT 2 +#define M98090_HIZOFF_WIDTH 1 +#define M98090_HIZOFF_NUM BIT(M98090_HIZOFF_WIDTH) +#define M98090_SDOEN_MASK BIT(1) +#define M98090_SDOEN_SHIFT 1 +#define M98090_SDOEN_WIDTH 1 +#define M98090_SDOEN_NUM BIT(M98090_SDOEN_WIDTH) +#define M98090_SDIEN_MASK BIT(0) +#define M98090_SDIEN_SHIFT 0 +#define M98090_SDIEN_WIDTH 1 +#define M98090_SDIEN_NUM BIT(M98090_SDIEN_WIDTH) + +/* + * M98090_REG_FILTER_CONFIG 0x26 + */ +#define M98090_MODE_MASK BIT(7) +#define M98090_MODE_SHIFT 7 +#define M98090_MODE_WIDTH 1 +#define M98090_AHPF_MASK BIT(6) +#define M98090_AHPF_SHIFT 6 +#define M98090_AHPF_WIDTH 1 +#define M98090_AHPF_NUM BIT(M98090_AHPF_WIDTH) +#define M98090_DHPF_MASK BIT(5) +#define M98090_DHPF_SHIFT 5 +#define M98090_DHPF_WIDTH 1 +#define M98090_DHPF_NUM BIT(M98090_DHPF_WIDTH) +#define M98090_DHF_MASK BIT(4) +#define M98090_DHF_SHIFT 4 +#define M98090_DHF_WIDTH 1 +#define M98090_FLT_DMIC34MODE_MASK BIT(3) +#define M98090_FLT_DMIC34MODE_SHIFT 3 +#define M98090_FLT_DMIC34MODE_WIDTH 1 +#define M98090_FLT_DMIC34HPF_MASK BIT(2) +#define M98090_FLT_DMIC34HPF_SHIFT 2 +#define M98090_FLT_DMIC34HPF_WIDTH 1 +#define M98090_FLT_DMIC34HPF_NUM BIT(M98090_FLT_DMIC34HPF_WIDTH) + +/* + * M98090_REG_CLOCK_MODE + */ +#define M98090_FREQ_MASK (15 << 4) +#define M98090_FREQ_SHIFT 4 +#define M98090_FREQ_WIDTH 4 +#define M98090_USE_M1_MASK BIT(0) +#define M98090_USE_M1_SHIFT 0 +#define M98090_USE_M1_WIDTH 1 +#define M98090_USE_M1_NUM BIT(M98090_USE_M1_WIDTH) + +/* + * M98090_REG_LEFT_HP_MIXER 0x29 + */ +#define M98090_MIXHPL_MIC2_MASK BIT(5) +#define M98090_MIXHPL_MIC2_SHIFT 5 +#define M98090_MIXHPL_MIC2_WIDTH 1 +#define M98090_MIXHPL_MIC1_MASK BIT(4) +#define M98090_MIXHPL_MIC1_SHIFT 4 +#define M98090_MIXHPL_MIC1_WIDTH 1 +#define M98090_MIXHPL_LINEB_MASK BIT(3) +#define M98090_MIXHPL_LINEB_SHIFT 3 +#define M98090_MIXHPL_LINEB_WIDTH 1 +#define M98090_MIXHPL_LINEA_MASK BIT(2) +#define M98090_MIXHPL_LINEA_SHIFT 2 +#define M98090_MIXHPL_LINEA_WIDTH 1 +#define M98090_MIXHPL_DACR_MASK BIT(1) +#define M98090_MIXHPL_DACR_SHIFT 1 +#define M98090_MIXHPL_DACR_WIDTH 1 +#define M98090_MIXHPL_DACL_MASK BIT(0) +#define M98090_MIXHPL_DACL_SHIFT 0 +#define M98090_MIXHPL_DACL_WIDTH 1 +#define M98090_MIXHPL_MASK (63 << 0) +#define M98090_MIXHPL_SHIFT 0 +#define M98090_MIXHPL_WIDTH 6 + +/* + * M98090_REG_RIGHT_HP_MIXER 0x2A + */ +#define M98090_MIXHPR_MIC2_MASK BIT(5) +#define M98090_MIXHPR_MIC2_SHIFT 5 +#define M98090_MIXHPR_MIC2_WIDTH 1 +#define M98090_MIXHPR_MIC1_MASK BIT(4) +#define M98090_MIXHPR_MIC1_SHIFT 4 +#define M98090_MIXHPR_MIC1_WIDTH 1 +#define M98090_MIXHPR_LINEB_MASK BIT(3) +#define M98090_MIXHPR_LINEB_SHIFT 3 +#define M98090_MIXHPR_LINEB_WIDTH 1 +#define M98090_MIXHPR_LINEA_MASK BIT(2) +#define M98090_MIXHPR_LINEA_SHIFT 2 +#define M98090_MIXHPR_LINEA_WIDTH 1 +#define M98090_MIXHPR_DACR_MASK BIT(1) +#define M98090_MIXHPR_DACR_SHIFT 1 +#define M98090_MIXHPR_DACR_WIDTH 1 +#define M98090_MIXHPR_DACL_MASK BIT(0) +#define M98090_MIXHPR_DACL_SHIFT 0 +#define M98090_MIXHPR_DACL_WIDTH 1 +#define M98090_MIXHPR_MASK (63 << 0) +#define M98090_MIXHPR_SHIFT 0 +#define M98090_MIXHPR_WIDTH 6 + +/* + * M98090_REG_LEFT_HP_VOLUME 0x2C + */ +#define M98090_HPLM_MASK BIT(7) +#define M98090_HPLM_SHIFT 7 +#define M98090_HPLM_WIDTH 1 +#define M98090_HPVOLL_MASK (31 << 0) +#define M98090_HPVOLL_SHIFT 0 +#define M98090_HPVOLL_WIDTH 5 +#define M98090_HPVOLL_NUM BIT(M98090_HPVOLL_WIDTH) + +/* + * M98090_REG_RIGHT_HP_VOLUME 0x2D + */ +#define M98090_HPRM_MASK BIT(7) +#define M98090_HPRM_SHIFT 7 +#define M98090_HPRM_WIDTH 1 +#define M98090_HPVOLR_MASK (31 << 0) +#define M98090_HPVOLR_SHIFT 0 +#define M98090_HPVOLR_WIDTH 5 +#define M98090_HPVOLR_NUM BIT(M98090_HPVOLR_WIDTH) + +/* + * M98090_REG_LEFT_SPK_MIXER 0x2E + */ +#define M98090_MIXSPL_MIC2_MASK BIT(5) +#define M98090_MIXSPL_MIC2_SHIFT 5 +#define M98090_MIXSPL_MIC2_WIDTH 1 +#define M98090_MIXSPL_MIC1_MASK BIT(4) +#define M98090_MIXSPL_MIC1_SHIFT 4 +#define M98090_MIXSPL_MIC1_WIDTH 1 +#define M98090_MIXSPL_LINEB_MASK BIT(3) +#define M98090_MIXSPL_LINEB_SHIFT 3 +#define M98090_MIXSPL_LINEB_WIDTH 1 +#define M98090_MIXSPL_LINEA_MASK BIT(2) +#define M98090_MIXSPL_LINEA_SHIFT 2 +#define M98090_MIXSPL_LINEA_WIDTH 1 +#define M98090_MIXSPL_DACR_MASK BIT(1) +#define M98090_MIXSPL_DACR_SHIFT 1 +#define M98090_MIXSPL_DACR_WIDTH 1 +#define M98090_MIXSPL_DACL_MASK BIT(0) +#define M98090_MIXSPL_DACL_SHIFT 0 +#define M98090_MIXSPL_DACL_WIDTH 1 +#define M98090_MIXSPL_MASK (63 << 0) +#define M98090_MIXSPL_SHIFT 0 +#define M98090_MIXSPL_WIDTH 6 +#define M98090_MIXSPR_DACR_MASK BIT(1) +#define M98090_MIXSPR_DACR_SHIFT 1 +#define M98090_MIXSPR_DACR_WIDTH 1 + +/* + * M98090_REG_RIGHT_SPK_MIXER 0x2F + */ +#define M98090_SPK_SLAVE_MASK BIT(6) +#define M98090_SPK_SLAVE_SHIFT 6 +#define M98090_SPK_SLAVE_WIDTH 1 +#define M98090_MIXSPR_MIC2_MASK BIT(5) +#define M98090_MIXSPR_MIC2_SHIFT 5 +#define M98090_MIXSPR_MIC2_WIDTH 1 +#define M98090_MIXSPR_MIC1_MASK BIT(4) +#define M98090_MIXSPR_MIC1_SHIFT 4 +#define M98090_MIXSPR_MIC1_WIDTH 1 +#define M98090_MIXSPR_LINEB_MASK BIT(3) +#define M98090_MIXSPR_LINEB_SHIFT 3 +#define M98090_MIXSPR_LINEB_WIDTH 1 +#define M98090_MIXSPR_LINEA_MASK BIT(2) +#define M98090_MIXSPR_LINEA_SHIFT 2 +#define M98090_MIXSPR_LINEA_WIDTH 1 +#define M98090_MIXSPR_DACR_MASK BIT(1) +#define M98090_MIXSPR_DACR_SHIFT 1 +#define M98090_MIXSPR_DACR_WIDTH 1 +#define M98090_MIXSPR_DACL_MASK BIT(0) +#define M98090_MIXSPR_DACL_SHIFT 0 +#define M98090_MIXSPR_DACL_WIDTH 1 +#define M98090_MIXSPR_MASK (63 << 0) +#define M98090_MIXSPR_SHIFT 0 +#define M98090_MIXSPR_WIDTH 6 + +/* + * M98090_REG_LEFT_SPK_VOLUME 0x31 + */ +#define M98090_SPLM_MASK BIT(7) +#define M98090_SPLM_SHIFT 7 +#define M98090_SPLM_WIDTH 1 +#define M98090_SPVOLL_MASK (63 << 0) +#define M98090_SPVOLL_SHIFT 0 +#define M98090_SPVOLL_WIDTH 6 +#define M98090_SPVOLL_NUM 40 + +/* + * M98090_REG_RIGHT_SPK_VOLUME 0x32 + */ +#define M98090_SPRM_MASK BIT(7) +#define M98090_SPRM_SHIFT 7 +#define M98090_SPRM_WIDTH 1 +#define M98090_SPVOLR_MASK (63 << 0) +#define M98090_SPVOLR_SHIFT 0 +#define M98090_SPVOLR_WIDTH 6 +#define M98090_SPVOLR_NUM 40 + +/* + * M98090_REG_RCV_LOUTL_MIXER 0x37 + */ +#define M98090_MIXRCVL_MIC2_MASK BIT(5) +#define M98090_MIXRCVL_MIC2_SHIFT 5 +#define M98090_MIXRCVL_MIC2_WIDTH 1 +#define M98090_MIXRCVL_MIC1_MASK BIT(4) +#define M98090_MIXRCVL_MIC1_SHIFT 4 +#define M98090_MIXRCVL_MIC1_WIDTH 1 +#define M98090_MIXRCVL_LINEB_MASK BIT(3) +#define M98090_MIXRCVL_LINEB_SHIFT 3 +#define M98090_MIXRCVL_LINEB_WIDTH 1 +#define M98090_MIXRCVL_LINEA_MASK BIT(2) +#define M98090_MIXRCVL_LINEA_SHIFT 2 +#define M98090_MIXRCVL_LINEA_WIDTH 1 +#define M98090_MIXRCVL_DACR_MASK BIT(1) +#define M98090_MIXRCVL_DACR_SHIFT 1 +#define M98090_MIXRCVL_DACR_WIDTH 1 +#define M98090_MIXRCVL_DACL_MASK BIT(0) +#define M98090_MIXRCVL_DACL_SHIFT 0 +#define M98090_MIXRCVL_DACL_WIDTH 1 +#define M98090_MIXRCVL_MASK (63 << 0) +#define M98090_MIXRCVL_SHIFT 0 +#define M98090_MIXRCVL_WIDTH 6 + +/* + * M98090_REG_RCV_LOUTL_CONTROL 0x38 + */ +#define M98090_MIXRCVLG_MASK (3 << 0) +#define M98090_MIXRCVLG_SHIFT 0 +#define M98090_MIXRCVLG_WIDTH 2 +#define M98090_MIXRCVLG_NUM BIT(M98090_MIXRCVLG_WIDTH) + +/* + * M98090_REG_RCV_LOUTL_VOLUME 0x39 + */ +#define M98090_RCVLM_MASK BIT(7) +#define M98090_RCVLM_SHIFT 7 +#define M98090_RCVLM_WIDTH 1 +#define M98090_RCVLVOL_MASK (31 << 0) +#define M98090_RCVLVOL_SHIFT 0 +#define M98090_RCVLVOL_WIDTH 5 +#define M98090_RCVLVOL_NUM BIT(M98090_RCVLVOL_WIDTH) + +/* + * M98090_REG_LOUTR_MIXER 0x3A + */ +#define M98090_LINMOD_MASK BIT(7) +#define M98090_LINMOD_SHIFT 7 +#define M98090_LINMOD_WIDTH 1 +#define M98090_MIXRCVR_MIC2_MASK BIT(5) +#define M98090_MIXRCVR_MIC2_SHIFT 5 +#define M98090_MIXRCVR_MIC2_WIDTH 1 +#define M98090_MIXRCVR_MIC1_MASK BIT(4) +#define M98090_MIXRCVR_MIC1_SHIFT 4 +#define M98090_MIXRCVR_MIC1_WIDTH 1 +#define M98090_MIXRCVR_LINEB_MASK BIT(3) +#define M98090_MIXRCVR_LINEB_SHIFT 3 +#define M98090_MIXRCVR_LINEB_WIDTH 1 +#define M98090_MIXRCVR_LINEA_MASK BIT(2) +#define M98090_MIXRCVR_LINEA_SHIFT 2 +#define M98090_MIXRCVR_LINEA_WIDTH 1 +#define M98090_MIXRCVR_DACR_MASK BIT(1) +#define M98090_MIXRCVR_DACR_SHIFT 1 +#define M98090_MIXRCVR_DACR_WIDTH 1 +#define M98090_MIXRCVR_DACL_MASK BIT(0) +#define M98090_MIXRCVR_DACL_SHIFT 0 +#define M98090_MIXRCVR_DACL_WIDTH 1 +#define M98090_MIXRCVR_MASK (63 << 0) +#define M98090_MIXRCVR_SHIFT 0 +#define M98090_MIXRCVR_WIDTH 6 + +/* + * M98090_REG_LOUTR_VOLUME 0x3C + */ +#define M98090_RCVRM_MASK BIT(7) +#define M98090_RCVRM_SHIFT 7 +#define M98090_RCVRM_WIDTH 1 +#define M98090_RCVRVOL_MASK (31 << 0) +#define M98090_RCVRVOL_SHIFT 0 +#define M98090_RCVRVOL_WIDTH 5 +#define M98090_RCVRVOL_NUM BIT(M98090_RCVRVOL_WIDTH) + +/* + * M98090_REG_JACK_DETECT 0x3D + */ +#define M98090_JDETEN_MASK BIT(7) +#define M98090_JDETEN_SHIFT 7 +#define M98090_JDETEN_WIDTH 1 +#define M98090_JDWK_MASK BIT(6) +#define M98090_JDWK_SHIFT 6 +#define M98090_JDWK_WIDTH 1 +#define M98090_JDEB_MASK (3 << 0) +#define M98090_JDEB_SHIFT 0 +#define M98090_JDEB_WIDTH 2 +#define M98090_JDEB_25MS (0 << 0) +#define M98090_JDEB_50MS BIT(0) +#define M98090_JDEB_100MS (2 << 0) +#define M98090_JDEB_200MS (3 << 0) + +/* + * M98090_REG_INPUT_ENABLE 0x3E + */ +#define M98090_MBEN_MASK BIT(4) +#define M98090_MBEN_SHIFT 4 +#define M98090_MBEN_WIDTH 1 +#define M98090_LINEAEN_MASK BIT(3) +#define M98090_LINEAEN_SHIFT 3 +#define M98090_LINEAEN_WIDTH 1 +#define M98090_LINEBEN_MASK BIT(2) +#define M98090_LINEBEN_SHIFT 2 +#define M98090_LINEBEN_WIDTH 1 +#define M98090_ADREN_MASK BIT(1) +#define M98090_ADREN_SHIFT 1 +#define M98090_ADREN_WIDTH 1 +#define M98090_ADLEN_MASK BIT(0) +#define M98090_ADLEN_SHIFT 0 +#define M98090_ADLEN_WIDTH 1 + +/* + * M98090_REG_OUTPUT_ENABLE 0x3F + */ +#define M98090_HPREN_MASK BIT(7) +#define M98090_HPREN_SHIFT 7 +#define M98090_HPREN_WIDTH 1 +#define M98090_HPLEN_MASK BIT(6) +#define M98090_HPLEN_SHIFT 6 +#define M98090_HPLEN_WIDTH 1 +#define M98090_SPREN_MASK BIT(5) +#define M98090_SPREN_SHIFT 5 +#define M98090_SPREN_WIDTH 1 +#define M98090_SPLEN_MASK BIT(4) +#define M98090_SPLEN_SHIFT 4 +#define M98090_SPLEN_WIDTH 1 +#define M98090_RCVLEN_MASK BIT(3) +#define M98090_RCVLEN_SHIFT 3 +#define M98090_RCVLEN_WIDTH 1 +#define M98090_RCVREN_MASK BIT(2) +#define M98090_RCVREN_SHIFT 2 +#define M98090_RCVREN_WIDTH 1 +#define M98090_DAREN_MASK BIT(1) +#define M98090_DAREN_SHIFT 1 +#define M98090_DAREN_WIDTH 1 +#define M98090_DALEN_MASK BIT(0) +#define M98090_DALEN_SHIFT 0 +#define M98090_DALEN_WIDTH 1 + +/* + * M98090_REG_LEVEL_CONTROL 0x40 + */ +#define M98090_ZDENN_MASK BIT(2) +#define M98090_ZDENN_SHIFT 2 +#define M98090_ZDENN_WIDTH 1 +#define M98090_ZDENN_NUM BIT(M98090_ZDENN_WIDTH) +#define M98090_VS2ENN_MASK BIT(1) +#define M98090_VS2ENN_SHIFT 1 +#define M98090_VS2ENN_WIDTH 1 +#define M98090_VS2ENN_NUM BIT(M98090_VS2ENN_WIDTH) +#define M98090_VSENN_MASK BIT(0) +#define M98090_VSENN_SHIFT 0 +#define M98090_VSENN_WIDTH 1 +#define M98090_VSENN_NUM BIT(M98090_VSENN_WIDTH) + +/* + * M98090_REG_BIAS_CONTROL 0x42 + */ +#define M98090_VCM_MODE_MASK BIT(0) +#define M98090_VCM_MODE_SHIFT 0 +#define M98090_VCM_MODE_WIDTH 1 +#define M98090_VCM_MODE_NUM BIT(M98090_VCM_MODE_WIDTH) + +/* + * M98090_REG_DAC_CONTROL 0x43 + */ +#define M98090_PERFMODE_MASK BIT(1) +#define M98090_PERFMODE_SHIFT 1 +#define M98090_PERFMODE_WIDTH 1 +#define M98090_PERFMODE_NUM BIT(M98090_PERFMODE_WIDTH) +#define M98090_DACHP_MASK BIT(0) +#define M98090_DACHP_SHIFT 0 +#define M98090_DACHP_WIDTH 1 +#define M98090_DACHP_NUM BIT(M98090_DACHP_WIDTH) + +/* + * M98090_REG_ADC_CONTROL 0x44 + */ +#define M98090_OSR128_MASK BIT(2) +#define M98090_OSR128_SHIFT 2 +#define M98090_OSR128_WIDTH 1 +#define M98090_ADCDITHER_MASK BIT(1) +#define M98090_ADCDITHER_SHIFT 1 +#define M98090_ADCDITHER_WIDTH 1 +#define M98090_ADCDITHER_NUM BIT(M98090_ADCDITHER_WIDTH) +#define M98090_ADCHP_MASK BIT(0) +#define M98090_ADCHP_SHIFT 0 +#define M98090_ADCHP_WIDTH 1 +#define M98090_ADCHP_NUM BIT(M98090_ADCHP_WIDTH) + +/* + * M98090_REG_DEVICE_SHUTDOWN 0x45 + */ +#define M98090_SHDNN_MASK BIT(7) +#define M98090_SHDNN_SHIFT 7 +#define M98090_SHDNN_WIDTH 1 + +/* + * M98090_REG_REVISION_ID 0xFF + */ +#define M98090_REVID_MASK (255 << 0) +#define M98090_REVID_SHIFT 0 +#define M98090_REVID_WIDTH 8 +#define M98090_REVID_NUM BIT(M98090_REVID_WIDTH) + +/* function prototype */ + +/* + * initialise max98090 sound codec device for the given configuration + * + * @param blob FDT node for codec values + * @param sampling_rate Sampling rate (Hz) + * @param mclk_freq MCLK Frequency (Hz) + * @param bits_per_sample bits per Sample (must be 16 or 24) + * + * @returns -1 for error and 0 Success. + */ +int max98090_init(const void *blob, int sampling_rate, int mclk_freq, + int bits_per_sample); +int max98090_set_sysclk(struct maxim_priv *max98090, uint freq); +int max98090_hw_params(struct maxim_priv *max98090, uint rate, + uint bits_per_sample); +int max98090_device_init(struct maxim_priv *max98090); +int max98090_set_fmt(struct maxim_priv *max98090, int fmt); +#endif From patchwork Mon Dec 10 17:37:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010591 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="jwf5PO1L"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9gZ6pCMz9s3C for ; Tue, 11 Dec 2018 04:54:18 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id AD288C22838; Mon, 10 Dec 2018 17:49:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8C76CC2286C; Mon, 10 Dec 2018 17:39:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AB8C3C22653; Mon, 10 Dec 2018 17:38:30 +0000 (UTC) Received: from mail-it1-f198.google.com (mail-it1-f198.google.com [209.85.166.198]) by lists.denx.de (Postfix) with ESMTPS id 224BFC22403 for ; Mon, 10 Dec 2018 17:38:26 +0000 (UTC) Received: by mail-it1-f198.google.com with SMTP id c73so14394504itd.1 for ; Mon, 10 Dec 2018 09:38:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=NbkR3DIcNDZWK4RRg1vgSVHhchQ5JSUGp5ysWh7BtqY=; b=jwf5PO1L9QTOs022CKFiloEJjYe78cCEg3hxkt6sFDADdKYmKQhkk+iZhIFxegNdV/ InJxtjLKTKQTgc8p+W6Ak+Dvb3PRNfY9Iz1AKpHxoxkcESqFXwhJ0ldLqmYMexnwMJpQ PRpYb0K409I9rqyn68a8UoG7YDCJhfnYso/y8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=NbkR3DIcNDZWK4RRg1vgSVHhchQ5JSUGp5ysWh7BtqY=; b=Pilx9yMPhUWupnnGQMO3ufl74Z5VqwUBGnOJKA6HBi6oH5ipsGSd0T8XPNsOQ1jG5+ DX4asLwkZ3IU/7zAN/36jp/R45d/oaxhqCHmsZqnMDy/3hl1LcchbANf9Kkd+C3zqRYn /N2GrfAd8OGNQqze4/XjoYGEZizmK6bWihffWbtMxjensGolhZvCfCq0TyiegS0OAE4o r3UQdZovZBM2tIsZYut+zGXJhQBwUOKs3O8e8eSQU1FO44k16W4rw4aJxzOVScFvqAyr WEIIfsVQwmlUVp9eUhTXy+2q/qhcadCV5o1yJsexRfhMslmSFLl35lO4s+xsGYx0PQoQ FYzA== X-Gm-Message-State: AA+aEWagzXuZNyAZ+YdW/PchCIOb90KBEQeXKsE4rcmar1wjb9762Dj8 IArDwL8PfCJHRxoMpKvZ3a+Wu0Peka6s2ZIN X-Google-Smtp-Source: AFSGD/WluGzNol1jHcq1bxucNIA4XX325VAjFk87jcq6NXyEpBhD1E1viuRi98NY050Py8/GJc5L6IZseKy3ebO9 X-Received: by 2002:a24:fe42:: with SMTP id w63mr10979546ith.13.1544463505045; Mon, 10 Dec 2018 09:38:25 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:44 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-16-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 15/22] dm: exynos: sound: Convert to use driver model X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Update snow's device tree and config to use driver model for sound. Also update the others as best we can. Spring does not appear to have audio support in the kernel. The smdk5250 and smdk5420 boards use a wolfson codec which I cannot test with. So the only boards that is tested and known to work are snow, pit and pi. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: - Correct conversion for pit and pi, updating commit message arch/arm/dts/exynos5250-smdk5250.dts | 20 ++++++++++++++++++-- arch/arm/dts/exynos5250-snow.dts | 21 ++++++++++++++++----- arch/arm/dts/exynos5250-spring.dts | 24 ++++++++++++++++++++---- arch/arm/dts/exynos5250.dtsi | 15 ++++++++++----- arch/arm/dts/exynos5420-peach-pit.dts | 20 ++++++++++++++++++-- arch/arm/dts/exynos5420-smdk5420.dts | 20 ++++++++++++++++++-- arch/arm/dts/exynos54xx.dtsi | 14 ++++++++++++++ arch/arm/dts/exynos5800-peach-pi.dts | 20 ++++++++++++++++++-- configs/arndale_defconfig | 1 + configs/peach-pi_defconfig | 3 +++ configs/peach-pit_defconfig | 3 +++ configs/smdk5250_defconfig | 1 + configs/snow_defconfig | 1 + configs/spring_defconfig | 1 + drivers/sound/samsung_sound.c | 3 +++ 15 files changed, 145 insertions(+), 22 deletions(-) diff --git a/arch/arm/dts/exynos5250-smdk5250.dts b/arch/arm/dts/exynos5250-smdk5250.dts index bf60b82d449..e542a790761 100644 --- a/arch/arm/dts/exynos5250-smdk5250.dts +++ b/arch/arm/dts/exynos5250-smdk5250.dts @@ -60,10 +60,26 @@ }; i2c@12C70000 { - soundcodec@1a { + wm8994: soundcodec@1a { reg = <0x1a>; u-boot,i2c-offset-len = <2>; - compatible = "wolfson,wm8994-codec"; + compatible = "wolfson,wm8994"; + #sound-dai-cells = <1>; + }; + }; + + sound { + compatible = "google,smdk5250-audio-wm8994"; + + samsung,model = "SMDK5250-I2S-WM8994"; + samsung,audio-codec = <&wm8994>; + + cpu { + sound-dai = <&i2s0 0>; + }; + + codec { + sound-dai = <&wm8994 0>; }; }; diff --git a/arch/arm/dts/exynos5250-snow.dts b/arch/arm/dts/exynos5250-snow.dts index cb5067b9669..7587dc0ff24 100644 --- a/arch/arm/dts/exynos5250-snow.dts +++ b/arch/arm/dts/exynos5250-snow.dts @@ -40,7 +40,6 @@ mmc3 = "/mmc@12230000"; serial0 = "/serial@12C30000"; console = "/serial@12C30000"; - i2s = "/sound@3830000"; }; memory { @@ -214,9 +213,10 @@ }; }; - soundcodec@11 { + max98095: codec@11 { + compatible = "maxim,max98095"; reg = <0x11>; - compatible = "maxim,max98095-codec"; + #sound-dai-cells = <1>; }; }; @@ -273,9 +273,20 @@ }; }; - sound@3830000 { - samsung,codec-type = "max98095"; + sound { + compatible = "google,snow-audio-max98095"; + + samsung,model = "Snow-I2S-MAX98095"; + samsung,audio-codec = <&max98095>; codec-enable-gpio = <&gpx1 7 GPIO_ACTIVE_HIGH>; + + cpu { + sound-dai = <&i2s0 0>; + }; + + codec { + sound-dai = <&max98095 0>; + }; }; sound@12d60000 { diff --git a/arch/arm/dts/exynos5250-spring.dts b/arch/arm/dts/exynos5250-spring.dts index 7633d36874f..191e12af6a1 100644 --- a/arch/arm/dts/exynos5250-spring.dts +++ b/arch/arm/dts/exynos5250-spring.dts @@ -34,7 +34,6 @@ mmc0 = "/mmc@12200000"; serial0 = "/serial@12C30000"; console = "/serial@12C30000"; - i2s = "/sound@3830000"; }; memory { @@ -639,10 +638,27 @@ }; }; - soundcodec@20 { - reg = <0x20>; - compatible = "maxim,max98088-codec"; + max98095: soundcodec@10 { + reg = <0x10>; + compatible = "maxim,max98095"; + #sound-dai-cells = <1>; }; + + sound { + compatible = "google,spring-audio-max98095"; + + samsung,model = "Spring-I2S-MAX98095"; + samsung,audio-codec = <&max98095>; + + cpu { + sound-dai = <&i2s0 0>; + }; + + codec { + sound-dai = <&max98095 0>; + }; + }; + }; #include "cros-ec-keyboard.dtsi" diff --git a/arch/arm/dts/exynos5250.dtsi b/arch/arm/dts/exynos5250.dtsi index 502c687802e..66c5b6dca95 100644 --- a/arch/arm/dts/exynos5250.dtsi +++ b/arch/arm/dts/exynos5250.dtsi @@ -78,9 +78,12 @@ #size-cells = <0>; }; - sound@3830000 { - compatible = "samsung,exynos-sound"; - reg = <0x3830000 0x50>; + i2s0: i2s@3830000 { + compatible = "samsung,s5pv210-i2s"; + reg = <0x03830000 0x100>; + samsung,idma-addr = <0x03000000>; + #clock-cells = <1>; + #sound-dai-cells = <1>; samsung,i2s-epll-clock-frequency = <192000000>; samsung,i2s-sampling-rate = <48000>; samsung,i2s-bits-per-sample = <16>; @@ -90,9 +93,11 @@ samsung,i2s-id = <0>; }; - sound@12d60000 { - compatible = "samsung,exynos-sound"; + i2s1: i2s@12d60000 { + compatible = "samsung,s5pv210-i2s"; reg = <0x12d60000 0x20>; + #clock-cells = <1>; + #sound-dai-cells = <1>; samsung,i2s-epll-clock-frequency = <192000000>; samsung,i2s-sampling-rate = <48000>; samsung,i2s-bits-per-sample = <16>; diff --git a/arch/arm/dts/exynos5420-peach-pit.dts b/arch/arm/dts/exynos5420-peach-pit.dts index bd0a9c116d4..4a96a18110a 100644 --- a/arch/arm/dts/exynos5420-peach-pit.dts +++ b/arch/arm/dts/exynos5420-peach-pit.dts @@ -67,11 +67,27 @@ }; }; + sound { + compatible = "google,peach-audio-max98090"; + + samsung,model = "PEACH-I2S-MAX98090"; + samsung,audio-codec = <&max98090>; + + cpu { + sound-dai = <&i2s0 0>; + }; + + codec { + sound-dai = <&max98090 0>; + }; + }; + i2c@12CD0000 { /* i2c7 */ clock-frequency = <100000>; - soundcodec@10 { + max98090: soundcodec@10 { reg = <0x10>; - compatible = "maxim,max98090-codec"; + compatible = "maxim,max98090"; + #sound-dai-cells = <1>; }; edp-lvds-bridge@48 { diff --git a/arch/arm/dts/exynos5420-smdk5420.dts b/arch/arm/dts/exynos5420-smdk5420.dts index daaa4666964..7a5da674fbe 100644 --- a/arch/arm/dts/exynos5420-smdk5420.dts +++ b/arch/arm/dts/exynos5420-smdk5420.dts @@ -82,10 +82,26 @@ }; i2c@12C70000 { - soundcodec@1a { + wm8994: soundcodec@1a { reg = <0x1a>; u-boot,i2c-offset-len = <2>; - compatible = "wolfson,wm8994-codec"; + compatible = "wolfson,wm8994"; + #sound-dai-cells = <1>; + }; + }; + + sound { + compatible = "samsung,smdk5420-audio-wm8994"; + + samsung,model = "Snow-I2S-MAX98095"; + samsung,audio-codec = <&wm8994>; + + cpu { + sound-dai = <&i2s0 0>; + }; + + codec { + sound-dai = <&wm8994 0>; }; }; diff --git a/arch/arm/dts/exynos54xx.dtsi b/arch/arm/dts/exynos54xx.dtsi index 09bef56e6c2..221da8b4850 100644 --- a/arch/arm/dts/exynos54xx.dtsi +++ b/arch/arm/dts/exynos54xx.dtsi @@ -104,6 +104,20 @@ interrupts = <0 203 0>; }; + i2s0: i2s@3830000 { + compatible = "samsung,s5pv210-i2s"; + reg = <0x03830000 0x100>; + #sound-dai-cells = <1>; + samsung,idma-addr = <0x03000000>; + samsung,i2s-epll-clock-frequency = <192000000>; + samsung,i2s-sampling-rate = <48000>; + samsung,i2s-bits-per-sample = <16>; + samsung,i2s-channels = <2>; + samsung,i2s-lr-clk-framesize = <256>; + samsung,i2s-bit-clk-framesize = <32>; + samsung,i2s-id = <0>; + }; + mmc@12200000 { samsung,bus-width = <8>; samsung,timing = <1 3 3>; diff --git a/arch/arm/dts/exynos5800-peach-pi.dts b/arch/arm/dts/exynos5800-peach-pi.dts index 239781b34bb..63c0b186e42 100644 --- a/arch/arm/dts/exynos5800-peach-pi.dts +++ b/arch/arm/dts/exynos5800-peach-pi.dts @@ -79,11 +79,27 @@ }; }; + sound { + compatible = "google,peach-audio-max98090"; + + samsung,model = "PEACH-I2S-MAX98090"; + samsung,audio-codec = <&max98090>; + + cpu { + sound-dai = <&i2s0 0>; + }; + + codec { + sound-dai = <&max98090 0>; + }; + }; + i2c@12CD0000 { /* i2c7 */ clock-frequency = <100000>; - soundcodec@10 { + max98090: soundcodec@10 { reg = <0x10>; - compatible = "maxim,max98090-codec"; + compatible = "maxim,max98090"; + #sound-dai-cells = <1>; }; }; diff --git a/configs/arndale_defconfig b/configs/arndale_defconfig index 2b6af4b2215..22881c3a2c6 100644 --- a/configs/arndale_defconfig +++ b/configs/arndale_defconfig @@ -31,6 +31,7 @@ CONFIG_MMC_SDHCI_S5P=y CONFIG_SMC911X=y CONFIG_SMC911X_BASE=0x5000000 CONFIG_SOUND=y +CONFIG_DM_SOUND=y CONFIG_I2S=y CONFIG_I2S_SAMSUNG=y CONFIG_SOUND_MAX98095=y diff --git a/configs/peach-pi_defconfig b/configs/peach-pi_defconfig index 338eae20b41..5ced3423160 100644 --- a/configs/peach-pi_defconfig +++ b/configs/peach-pi_defconfig @@ -21,6 +21,7 @@ CONFIG_CMD_USB=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y CONFIG_CMD_TIME=y +CONFIG_CMD_SOUND=y CONFIG_CMD_PMIC=y CONFIG_CMD_REGULATOR=y CONFIG_CMD_TPM=y @@ -50,8 +51,10 @@ CONFIG_REGULATOR_TPS65090=y CONFIG_DM_PWM=y CONFIG_PWM_EXYNOS=y CONFIG_SOUND=y +CONFIG_DM_SOUND=y CONFIG_I2S=y CONFIG_I2S_SAMSUNG=y +CONFIG_SOUND_MAX98090=y CONFIG_SOUND_MAX98095=y CONFIG_SOUND_WM8994=y CONFIG_EXYNOS_SPI=y diff --git a/configs/peach-pit_defconfig b/configs/peach-pit_defconfig index 933c823ea86..b1fe3f73abb 100644 --- a/configs/peach-pit_defconfig +++ b/configs/peach-pit_defconfig @@ -20,6 +20,7 @@ CONFIG_CMD_USB=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y CONFIG_CMD_TIME=y +CONFIG_CMD_SOUND=y CONFIG_CMD_PMIC=y CONFIG_CMD_REGULATOR=y CONFIG_CMD_TPM=y @@ -49,8 +50,10 @@ CONFIG_REGULATOR_TPS65090=y CONFIG_DM_PWM=y CONFIG_PWM_EXYNOS=y CONFIG_SOUND=y +CONFIG_DM_SOUND=y CONFIG_I2S=y CONFIG_I2S_SAMSUNG=y +CONFIG_SOUND_MAX98090=y CONFIG_SOUND_MAX98095=y CONFIG_SOUND_WM8994=y CONFIG_EXYNOS_SPI=y diff --git a/configs/smdk5250_defconfig b/configs/smdk5250_defconfig index 161454b33fd..90ee0ffbc9d 100644 --- a/configs/smdk5250_defconfig +++ b/configs/smdk5250_defconfig @@ -44,6 +44,7 @@ CONFIG_DM_PMIC_MAX77686=y CONFIG_DM_REGULATOR=y CONFIG_DM_REGULATOR_MAX77686=y CONFIG_SOUND=y +CONFIG_DM_SOUND=y CONFIG_I2S=y CONFIG_I2S_SAMSUNG=y CONFIG_SOUND_MAX98095=y diff --git a/configs/snow_defconfig b/configs/snow_defconfig index 21080091a7d..4d1c53d4291 100644 --- a/configs/snow_defconfig +++ b/configs/snow_defconfig @@ -61,6 +61,7 @@ CONFIG_DM_PWM=y CONFIG_PWM_EXYNOS=y CONFIG_DEBUG_UART_S5P=y CONFIG_SOUND=y +CONFIG_DM_SOUND=y CONFIG_I2S=y CONFIG_I2S_SAMSUNG=y CONFIG_SOUND_MAX98095=y diff --git a/configs/spring_defconfig b/configs/spring_defconfig index ca1799895e8..8f9436c74af 100644 --- a/configs/spring_defconfig +++ b/configs/spring_defconfig @@ -61,6 +61,7 @@ CONFIG_DM_PWM=y CONFIG_PWM_EXYNOS=y CONFIG_DEBUG_UART_S5P=y CONFIG_SOUND=y +CONFIG_DM_SOUND=y CONFIG_I2S=y CONFIG_I2S_SAMSUNG=y CONFIG_SOUND_MAX98095=y diff --git a/drivers/sound/samsung_sound.c b/drivers/sound/samsung_sound.c index 23b467c1de0..1d711c87322 100644 --- a/drivers/sound/samsung_sound.c +++ b/drivers/sound/samsung_sound.c @@ -89,6 +89,9 @@ static const struct sound_ops samsung_sound_ops = { static const struct udevice_id samsung_sound_ids[] = { { .compatible = "google,snow-audio-max98095" }, + { .compatible = "google,spring-audio-max98095" }, + { .compatible = "samsung,smdk5420-audio-wm8994" }, + { .compatible = "google,peach-audio-max98090" }, { } }; From patchwork Mon Dec 10 17:37:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010594 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ag1GDw2r"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9hY3gcPz9s3C for ; Tue, 11 Dec 2018 04:55:09 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 42CD7C22864; Mon, 10 Dec 2018 17:50:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3D142C22669; Mon, 10 Dec 2018 17:39:22 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3E05EC22879; Mon, 10 Dec 2018 17:38:32 +0000 (UTC) Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by lists.denx.de (Postfix) with ESMTPS id 73A98C22833 for ; Mon, 10 Dec 2018 17:38:27 +0000 (UTC) Received: by mail-io1-f69.google.com with SMTP id n25so12088133iog.13 for ; Mon, 10 Dec 2018 09:38:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=bd6ndixep1OdeCeZ4mR3ozgKEi8//hfNJwWWHSvX7G0=; b=ag1GDw2rSJTw3ayDEIl8X8rYQ9xqUjwkansjTvnF/LqCp1S/bvAHAa84EAFcCrqNdE WdAPfgcW40CDvoz+uYPbvxu5AiYb0hXw06zIuZni0rru6OILbIFfskK8DvzI8aEAdfe9 gu4gXUqO6WojzF5WaPBymd2ZHZWdS0NIGFcnw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=bd6ndixep1OdeCeZ4mR3ozgKEi8//hfNJwWWHSvX7G0=; b=OikGpavxssLSvYkR0tpnHat9GEAjLDp7YnoVOPecL6/DQ1TOIDHs4yP5Nu5fwEj6B0 3Ss6yCrxHr2+5SHOuIu/Ea4u/g6kyohB+QKrfQuEMbcnjncPRTxX1mIsWwWiBS3xVr1J WcxygSYVdOMU2sumr8DLEKIMv5T7JAgAZ/NhqzrkkZdixydl8dhvz4rN8xDxNukRTibV 1uURTUvVjmCXjgDwYGBXaXT2GbpGP5hChqoWl7zzLSuKAIuh2eBgdmb4c5YZPyIwP3wS tPHmLEerHtev96WIK2gox9BjBv7cRUsrQPq+SvX/5XfNU5DN6JCICddvWqEMEh0mhBXm mzSA== X-Gm-Message-State: AA+aEWbvZ/OUZ+UBVZa89Sl0BatNUT4UwRMQUCRvspPSDR4n9YEMNQYI KhtN3OORm7SIMj8rHon+mdIHiIL1vz2Qbnrr X-Google-Smtp-Source: AFSGD/VM8EB3NkN6O0dvI+l07jHRP5VujrjnqNsxGr22HM9xKIISkJidS7+WTlQ8RALNbtHxZZJM09WvQiFZ2O07 X-Received: by 2002:a24:16d3:: with SMTP id a202mr10164395ita.21.1544463506457; Mon, 10 Dec 2018 09:38:26 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:45 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-17-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 16/22] dm: sandbox: sound: Convert to use driver model X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Update sandbox's device tree and config to use driver model for sound. Use the double buffer for sound output so that we don't need to wait for the sound to complete before returning. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: - Add new patch to convert sandbox to use driver model arch/sandbox/cpu/sdl.c | 36 ++++++++++++++++++++++------------ arch/sandbox/dts/sandbox.dts | 21 ++++++++++++++++++++ arch/sandbox/include/asm/sdl.h | 8 ++++++++ 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c index 4dacdbf993f..8fc7c172e3a 100644 --- a/arch/sandbox/cpu/sdl.c +++ b/arch/sandbox/cpu/sdl.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -40,6 +41,7 @@ static struct sdl_info { bool inited; int cur_buf; struct buf_info buf[2]; + bool running; } sdl; static void sandbox_sdl_poll_events(void) @@ -331,6 +333,7 @@ int sandbox_sdl_sound_init(void) sdl.audio_active = true; sdl.sample_rate = wanted.freq; sdl.cur_buf = 0; + sdl.running = 0; return 0; @@ -340,27 +343,36 @@ err: return -1; } -int sandbox_sdl_sound_start(uint frequency) +int sandbox_sdl_sound_play(const void *data, uint size) { - struct buf_info *buf = &sdl.buf[0]; + struct buf_info *buf; - if (!sdl.audio_active) - return -1; - sdl.frequency = frequency; - sound_create_square_wave(sdl.sample_rate, (unsigned short *)buf->data, - buf->alloced, frequency); + buf = &sdl.buf[0]; + if (buf->size) + buf = &sdl.buf[1]; + while (buf->size) + usleep(1000); + + if (size > buf->alloced) + return -E2BIG; + + memcpy(buf->data, data, size); + buf->size = size; buf->pos = 0; - buf->size = buf->alloced; - SDL_PauseAudio(0); + if (!sdl.running) { + SDL_PauseAudio(0); + sdl.running = 1; + } return 0; } int sandbox_sdl_sound_stop(void) { - if (!sdl.audio_active) - return -1; - SDL_PauseAudio(1); + if (sdl.running) { + SDL_PauseAudio(1); + sdl.running = 0; + } return 0; } diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts index ce3c88c221d..ae3189ec8cf 100644 --- a/arch/sandbox/dts/sandbox.dts +++ b/arch/sandbox/dts/sandbox.dts @@ -18,6 +18,11 @@ stdout-path = "/serial"; }; + audio: audio-codec { + compatible = "sandbox,audio-codec"; + #sound-dai-cells = <1>; + }; + cros_ec: cros-ec { reg = <0 0>; u-boot,dm-pre-reloc; @@ -127,6 +132,11 @@ }; }; + i2s: i2s { + compatible = "sandbox,i2s"; + #sound-dai-cells = <1>; + }; + lcd { u-boot,dm-pre-reloc; compatible = "sandbox,lcd-sdl"; @@ -190,6 +200,17 @@ compatible = "sandbox,reset"; }; + sound { + compatible = "sandbox,sound"; + cpu { + sound-dai = <&i2s 0>; + }; + + codec { + sound-dai = <&audio 0>; + }; + }; + spi@0 { u-boot,dm-pre-reloc; #address-cells = <1>; diff --git a/arch/sandbox/include/asm/sdl.h b/arch/sandbox/include/asm/sdl.h index 1c4380c592a..0143ed9e621 100644 --- a/arch/sandbox/include/asm/sdl.h +++ b/arch/sandbox/include/asm/sdl.h @@ -68,6 +68,14 @@ int sandbox_sdl_sound_start(uint frequency); */ int sandbox_sdl_sound_stop(void); +/** + * sandbox_sdl_sound_play() - Play a sound + * + * @data: Data to play (typically 16-bit) + * @count: Number of bytes in data + */ +int sandbox_sdl_sound_play(const void *data, uint count); + /** * sandbox_sdl_sound_init() - set up the sound system * From patchwork Mon Dec 10 17:37:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010578 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="lZF0lCM4"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9WH6zp3z9s3Z for ; Tue, 11 Dec 2018 04:47:07 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 5559AC22822; Mon, 10 Dec 2018 17:46:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id EFABEC22863; Mon, 10 Dec 2018 17:38:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D7836C22865; Mon, 10 Dec 2018 17:38:33 +0000 (UTC) Received: from mail-it1-f199.google.com (mail-it1-f199.google.com [209.85.166.199]) by lists.denx.de (Postfix) with ESMTPS id C6B98C225F3 for ; Mon, 10 Dec 2018 17:38:28 +0000 (UTC) Received: by mail-it1-f199.google.com with SMTP id k133so15251588ite.4 for ; Mon, 10 Dec 2018 09:38:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=/Hq/I/aiMnmDjgBmhqgZGXZqow3pLkU0byPrfau4nK8=; b=lZF0lCM4j9WJrRByPtAnWpyvfOOgK/+y6h4QPenjnxubqVfTy9Fm9Vdq2b7qdf912A hLCR5TAbWUdlgg9nVey+Uh4MTZ6zROnFLcq+Zk1Ph/0qXCtAldQVdPLQYYt+OlYWnby8 hLoO10yIpx7yoQR4il7z96pOtmnxtPy0zTOSM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=/Hq/I/aiMnmDjgBmhqgZGXZqow3pLkU0byPrfau4nK8=; b=bs72I3miyHvenZnBykoa9ew2Cviiom6ltq1Nt0h6tJPh0X1J4DNSLrRQ3ME8QTp4g5 yzRfzGUYqbM/OJFcSLQ5KIkrIrXKaFz9QUvFxDv1/58uCVo1toAeyaQ+TM9K0UbcQLsU hWS0Krp3G82I2eyWECn156NxGD3aghwBPJfGYe3zjoxXBnMzZeWltEB162amNCa9gdjT nQUsvkna2vPjl1oKM/H8obwJGHDqbdKuSYGV+Af0FsEyy6oR0VKmuQo+1xRhSz1xyPRg 9ECE8JBg7oryKNmiOipn2XYMtB4vssZ0CA3GgeQu5mZ0m5+qFxCd1HhU/rxdqQ1p6GtQ 9TYQ== X-Gm-Message-State: AA+aEWYnrHALTVXxaCH9IbfXuJtrh0c+3Zr7tArBTKh+ru0X8q3RXYyv EPbryHXEnFEGctTD1AOAzQ3xDVIbEfoVdgnI X-Google-Smtp-Source: AFSGD/WY5Ls2jCrOVPAWkj32Lu+7DSbpqvL8rZrFz8Yn83WRVNntg4GFwi/1yzya34FKihZvzuRDgdP36SNcMD9U X-Received: by 2002:a24:16d3:: with SMTP id a202mr10164435ita.21.1544463507852; Mon, 10 Dec 2018 09:38:27 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:46 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-18-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 17/22] dm: exynos: Drop CONFIG_DM_I2C_COMPAT X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This option is not needed anymore for all exynos boards except arndale. Update the config. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: None configs/peach-pi_defconfig | 1 - configs/peach-pit_defconfig | 1 - configs/smdk5250_defconfig | 1 - configs/smdk5420_defconfig | 1 - configs/snow_defconfig | 1 - configs/spring_defconfig | 1 - 6 files changed, 6 deletions(-) diff --git a/configs/peach-pi_defconfig b/configs/peach-pi_defconfig index 5ced3423160..32b32dd901c 100644 --- a/configs/peach-pi_defconfig +++ b/configs/peach-pi_defconfig @@ -29,7 +29,6 @@ CONFIG_CMD_TPM_TEST=y CONFIG_CMD_EXT4_WRITE=y CONFIG_DEFAULT_DEVICE_TREE="exynos5800-peach-pi" CONFIG_ENV_IS_IN_SPI_FLASH=y -CONFIG_DM_I2C_COMPAT=y CONFIG_I2C_CROS_EC_TUNNEL=y CONFIG_I2C_MUX=y CONFIG_I2C_ARB_GPIO_CHALLENGE=y diff --git a/configs/peach-pit_defconfig b/configs/peach-pit_defconfig index b1fe3f73abb..7018737ab4f 100644 --- a/configs/peach-pit_defconfig +++ b/configs/peach-pit_defconfig @@ -28,7 +28,6 @@ CONFIG_CMD_TPM_TEST=y CONFIG_CMD_EXT4_WRITE=y CONFIG_DEFAULT_DEVICE_TREE="exynos5420-peach-pit" CONFIG_ENV_IS_IN_SPI_FLASH=y -CONFIG_DM_I2C_COMPAT=y CONFIG_I2C_CROS_EC_TUNNEL=y CONFIG_I2C_MUX=y CONFIG_I2C_ARB_GPIO_CHALLENGE=y diff --git a/configs/smdk5250_defconfig b/configs/smdk5250_defconfig index 90ee0ffbc9d..1e058227e41 100644 --- a/configs/smdk5250_defconfig +++ b/configs/smdk5250_defconfig @@ -30,7 +30,6 @@ CONFIG_CMD_REGULATOR=y CONFIG_CMD_EXT4_WRITE=y CONFIG_DEFAULT_DEVICE_TREE="exynos5250-smdk5250" CONFIG_ENV_IS_IN_SPI_FLASH=y -CONFIG_DM_I2C_COMPAT=y CONFIG_MMC_DW=y CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_S5P=y diff --git a/configs/smdk5420_defconfig b/configs/smdk5420_defconfig index 433e9a8447f..4e4558944cc 100644 --- a/configs/smdk5420_defconfig +++ b/configs/smdk5420_defconfig @@ -25,7 +25,6 @@ CONFIG_CMD_TIME=y CONFIG_CMD_EXT4_WRITE=y CONFIG_DEFAULT_DEVICE_TREE="exynos5420-smdk5420" CONFIG_ENV_IS_IN_SPI_FLASH=y -CONFIG_DM_I2C_COMPAT=y CONFIG_MMC_DW=y CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_S5P=y diff --git a/configs/snow_defconfig b/configs/snow_defconfig index 4d1c53d4291..10e11fbb337 100644 --- a/configs/snow_defconfig +++ b/configs/snow_defconfig @@ -34,7 +34,6 @@ CONFIG_CMD_TPM_TEST=y CONFIG_CMD_EXT4_WRITE=y CONFIG_DEFAULT_DEVICE_TREE="exynos5250-snow" CONFIG_ENV_IS_IN_SPI_FLASH=y -CONFIG_DM_I2C_COMPAT=y CONFIG_I2C_CROS_EC_LDO=y CONFIG_I2C_MUX=y CONFIG_I2C_ARB_GPIO_CHALLENGE=y diff --git a/configs/spring_defconfig b/configs/spring_defconfig index 8f9436c74af..844a87734b8 100644 --- a/configs/spring_defconfig +++ b/configs/spring_defconfig @@ -34,7 +34,6 @@ CONFIG_CMD_TPM_TEST=y CONFIG_CMD_EXT4_WRITE=y CONFIG_DEFAULT_DEVICE_TREE="exynos5250-spring" CONFIG_ENV_IS_IN_SPI_FLASH=y -CONFIG_DM_I2C_COMPAT=y CONFIG_I2C_CROS_EC_LDO=y CONFIG_I2C_MUX=y CONFIG_I2C_ARB_GPIO_CHALLENGE=y From patchwork Mon Dec 10 17:37:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010580 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="NJXY5xUf"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9Xx4dYFz9s3Z for ; Tue, 11 Dec 2018 04:48:33 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 5273CC22835; Mon, 10 Dec 2018 17:47:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 7E9B6C22843; Mon, 10 Dec 2018 17:38:59 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7052DC22879; Mon, 10 Dec 2018 17:38:34 +0000 (UTC) Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by lists.denx.de (Postfix) with ESMTPS id CB5C1C227D5 for ; Mon, 10 Dec 2018 17:38:30 +0000 (UTC) Received: by mail-ot1-f69.google.com with SMTP id q11so4903659otl.23 for ; Mon, 10 Dec 2018 09:38:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=SNm8eYh1C9WQGw+dOkrFzKoY3BobbJIxaqpx3heH5A0=; b=NJXY5xUfJXzKf1BZEoI/tGfN6io0hddXZr4MW3DUx0VFujRwxCOGRXmWWagr0b+MDH ZgAfKmVnB8e1+pF0Yfx9UWnX36Fn2W/7gDLEJmpOywufCQANRigCyOVUxpYjtpW/qyRZ 5GTF+9EnuCjdfKFGPcdMsSNtKUvQLv1NuTB8Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=SNm8eYh1C9WQGw+dOkrFzKoY3BobbJIxaqpx3heH5A0=; b=MZ/KaQHxua3wuF/TuPW0Thr2nxRdc9XPMJ/lByG7lE+VqQNVQ+ddxDrr1rNuETAc4T B/VFPZN1EiOXTf0B2GvN0CBhmeuojXcxpP8RHXVpvXJ+TAt5HJwAMPg9yu6ggmjdsu6B weNaXnv1u5sNE1BDdJPfZuIDNTLCn+pLz1euF44KhPic1nKmz4KNcjgFNOINvEdZZOWr GEfUA+K5H2hJh/xspXMmSjWomKYt7VWv6SuxCAx2RZh/lT3mZ9XN7HSJScZlpWzvEh/K np6tO6U0v9ZAOmiYt8ywDtpOxXwSn8HU3svXLOJb7IsrY0yzI/c/pJb7fLnkglaqOg/p wtqA== X-Gm-Message-State: AA+aEWahCLyfKRESKauGUVXSrNIoxjE85UkjqZFPvHp547FJ86dVTpS1 gLkWFEJwHrAi76DvECMP78rNFoHwkBKGHtnO X-Google-Smtp-Source: AFSGD/VrCQE54sWb6ls0ADLkY88khdvCucOO/LPJCFSC8DKiT0Ij4RFcS0Qli15eiLxVCOHKiWMloDSmyTELDM1H X-Received: by 2002:aca:560b:: with SMTP id k11mr10645970oib.34.1544463509345; Mon, 10 Dec 2018 09:38:29 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:47 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-19-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 18/22] dm: sound: Complete migration to driver model X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" All users of sound are converted to use driver model. Drop the old code and the CONFIG_DM_SOUND option. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: - Drop CONFIG_DM_SOUND from all defconfig files - Fix up sandbox files to remove old code - Update the rest of the samsung boards - Remove unused sandbox code also - Drop patches previously applied arch/sandbox/cpu/sdl.c | 1 - arch/sandbox/include/asm/sdl.h | 21 ++-- arch/sandbox/include/asm/sound.h | 13 -- cmd/sound.c | 12 -- configs/arndale_defconfig | 1 - configs/peach-pi_defconfig | 1 - configs/peach-pit_defconfig | 1 - configs/smdk5250_defconfig | 1 - configs/snow_defconfig | 1 - configs/spring_defconfig | 1 - drivers/sound/Kconfig | 6 - drivers/sound/Makefile | 10 +- drivers/sound/max98095.c | 78 ------------ drivers/sound/sandbox.c | 19 +-- drivers/sound/sound-i2s.c | 206 ------------------------------- drivers/sound/wm8994.c | 95 -------------- include/sound.h | 18 --- test/dm/Makefile | 6 +- 18 files changed, 16 insertions(+), 475 deletions(-) delete mode 100644 arch/sandbox/include/asm/sound.h delete mode 100644 drivers/sound/sound-i2s.c diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c index 8fc7c172e3a..7eb2df7ddad 100644 --- a/arch/sandbox/cpu/sdl.c +++ b/arch/sandbox/cpu/sdl.c @@ -7,7 +7,6 @@ #include #include #include -#include #include enum { diff --git a/arch/sandbox/include/asm/sdl.h b/arch/sandbox/include/asm/sdl.h index 0143ed9e621..2799a8bee06 100644 --- a/arch/sandbox/include/asm/sdl.h +++ b/arch/sandbox/include/asm/sdl.h @@ -54,12 +54,12 @@ int sandbox_sdl_scan_keys(int key[], int max_keys); int sandbox_sdl_key_pressed(int keycode); /** - * sandbox_sdl_sound_start() - start playing a sound + * sandbox_sdl_sound_play() - Play a sound * - * @frequency: Frequency of sounds in Hertz - * @return 0 if OK, -ENODEV if no sound is available + * @data: Data to play (typically 16-bit) + * @count: Number of bytes in data */ -int sandbox_sdl_sound_start(uint frequency); +int sandbox_sdl_sound_play(const void *data, uint count); /** * sandbox_sdl_sound_stop() - stop playing a sound @@ -68,14 +68,6 @@ int sandbox_sdl_sound_start(uint frequency); */ int sandbox_sdl_sound_stop(void); -/** - * sandbox_sdl_sound_play() - Play a sound - * - * @data: Data to play (typically 16-bit) - * @count: Number of bytes in data - */ -int sandbox_sdl_sound_play(const void *data, uint count); - /** * sandbox_sdl_sound_init() - set up the sound system * @@ -110,6 +102,11 @@ static inline int sandbox_sdl_sound_start(uint frequency) return -ENODEV; } +int sandbox_sdl_sound_play(const void *data, uint count) +{ + return -ENODEV; +} + static inline int sandbox_sdl_sound_stop(void) { return -ENODEV; diff --git a/arch/sandbox/include/asm/sound.h b/arch/sandbox/include/asm/sound.h deleted file mode 100644 index a6015b0f60f..00000000000 --- a/arch/sandbox/include/asm/sound.h +++ /dev/null @@ -1,13 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (c) 2013 Google, Inc - */ - -#ifndef __SANDBOX_SOUND_H -#define __SANDBOX_SOUND_H - -int sound_play(unsigned int msec, unsigned int frequency); - -int sound_init(const void *blob); - -#endif diff --git a/cmd/sound.c b/cmd/sound.c index 77f51529259..638f29df21d 100644 --- a/cmd/sound.c +++ b/cmd/sound.c @@ -15,18 +15,12 @@ DECLARE_GLOBAL_DATA_PTR; /* Initilaise sound subsystem */ static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) { -#ifdef CONFIG_DM_SOUND struct udevice *dev; -#endif int ret; -#ifdef CONFIG_DM_SOUND ret = uclass_first_device_err(UCLASS_SOUND, &dev); if (!ret) ret = sound_setup(dev); -#else - ret = sound_init(gd->fdt_blob); -#endif if (ret) { printf("Initialise Audio driver failed (ret=%d)\n", ret); return CMD_RET_FAILURE; @@ -38,9 +32,7 @@ static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) /* play sound from buffer */ static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) { -#ifdef CONFIG_DM_SOUND struct udevice *dev; -#endif int ret = 0; int msec = 1000; int freq = 400; @@ -50,13 +42,9 @@ static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) if (argc > 2) freq = simple_strtoul(argv[2], NULL, 10); -#ifdef CONFIG_DM_SOUND ret = uclass_first_device_err(UCLASS_SOUND, &dev); if (!ret) ret = sound_beep(dev, msec, freq); -#else - ret = sound_play(msec, freq); -#endif if (ret) { printf("Sound device failed to play (err=%d)\n", ret); return CMD_RET_FAILURE; diff --git a/configs/arndale_defconfig b/configs/arndale_defconfig index 22881c3a2c6..2b6af4b2215 100644 --- a/configs/arndale_defconfig +++ b/configs/arndale_defconfig @@ -31,7 +31,6 @@ CONFIG_MMC_SDHCI_S5P=y CONFIG_SMC911X=y CONFIG_SMC911X_BASE=0x5000000 CONFIG_SOUND=y -CONFIG_DM_SOUND=y CONFIG_I2S=y CONFIG_I2S_SAMSUNG=y CONFIG_SOUND_MAX98095=y diff --git a/configs/peach-pi_defconfig b/configs/peach-pi_defconfig index 32b32dd901c..14c835cad81 100644 --- a/configs/peach-pi_defconfig +++ b/configs/peach-pi_defconfig @@ -50,7 +50,6 @@ CONFIG_REGULATOR_TPS65090=y CONFIG_DM_PWM=y CONFIG_PWM_EXYNOS=y CONFIG_SOUND=y -CONFIG_DM_SOUND=y CONFIG_I2S=y CONFIG_I2S_SAMSUNG=y CONFIG_SOUND_MAX98090=y diff --git a/configs/peach-pit_defconfig b/configs/peach-pit_defconfig index 7018737ab4f..9a3a11504de 100644 --- a/configs/peach-pit_defconfig +++ b/configs/peach-pit_defconfig @@ -49,7 +49,6 @@ CONFIG_REGULATOR_TPS65090=y CONFIG_DM_PWM=y CONFIG_PWM_EXYNOS=y CONFIG_SOUND=y -CONFIG_DM_SOUND=y CONFIG_I2S=y CONFIG_I2S_SAMSUNG=y CONFIG_SOUND_MAX98090=y diff --git a/configs/smdk5250_defconfig b/configs/smdk5250_defconfig index 1e058227e41..21018d8b1b1 100644 --- a/configs/smdk5250_defconfig +++ b/configs/smdk5250_defconfig @@ -43,7 +43,6 @@ CONFIG_DM_PMIC_MAX77686=y CONFIG_DM_REGULATOR=y CONFIG_DM_REGULATOR_MAX77686=y CONFIG_SOUND=y -CONFIG_DM_SOUND=y CONFIG_I2S=y CONFIG_I2S_SAMSUNG=y CONFIG_SOUND_MAX98095=y diff --git a/configs/snow_defconfig b/configs/snow_defconfig index 10e11fbb337..e0c1bf862c0 100644 --- a/configs/snow_defconfig +++ b/configs/snow_defconfig @@ -60,7 +60,6 @@ CONFIG_DM_PWM=y CONFIG_PWM_EXYNOS=y CONFIG_DEBUG_UART_S5P=y CONFIG_SOUND=y -CONFIG_DM_SOUND=y CONFIG_I2S=y CONFIG_I2S_SAMSUNG=y CONFIG_SOUND_MAX98095=y diff --git a/configs/spring_defconfig b/configs/spring_defconfig index 844a87734b8..c089517692e 100644 --- a/configs/spring_defconfig +++ b/configs/spring_defconfig @@ -60,7 +60,6 @@ CONFIG_DM_PWM=y CONFIG_PWM_EXYNOS=y CONFIG_DEBUG_UART_S5P=y CONFIG_SOUND=y -CONFIG_DM_SOUND=y CONFIG_I2S=y CONFIG_I2S_SAMSUNG=y CONFIG_SOUND_MAX98095=y diff --git a/drivers/sound/Kconfig b/drivers/sound/Kconfig index 18d7ca1dcb3..c0d97cca338 100644 --- a/drivers/sound/Kconfig +++ b/drivers/sound/Kconfig @@ -12,12 +12,6 @@ config SOUND audio codecs are called from the sound-i2s code. This could be converted to driver model. -config DM_SOUND - bool "Use driver model for sound" - help - Enable this option to use driver model for sound devices. This is a - migration option and will be removed. - config I2S bool "Enable I2S support" depends on SOUND diff --git a/drivers/sound/Makefile b/drivers/sound/Makefile index 937df152fe6..1de4346ec7a 100644 --- a/drivers/sound/Makefile +++ b/drivers/sound/Makefile @@ -4,16 +4,12 @@ # R. Chandrasekar obj-$(CONFIG_SOUND) += sound.o -obj-$(CONFIG_DM_SOUND) += codec-uclass.o -obj-$(CONFIG_DM_SOUND) += i2s-uclass.o -obj-$(CONFIG_DM_SOUND) += sound-uclass.o +obj-$(CONFIG_SOUND) += codec-uclass.o +obj-$(CONFIG_SOUND) += i2s-uclass.o +obj-$(CONFIG_SOUND) += sound-uclass.o obj-$(CONFIG_I2S_SAMSUNG) += samsung-i2s.o obj-$(CONFIG_SOUND_SANDBOX) += sandbox.o -ifdef CONFIG_DM_SOUND obj-$(CONFIG_I2S_SAMSUNG) += samsung_sound.o -else -obj-$(CONFIG_I2S) += sound-i2s.o -endif obj-$(CONFIG_SOUND_WM8994) += wm8994.o obj-$(CONFIG_SOUND_MAX98090) += max98090.o maxim_codec.o obj-$(CONFIG_SOUND_MAX98095) += max98095.o maxim_codec.o diff --git a/drivers/sound/max98095.c b/drivers/sound/max98095.c index e9bf64f82f8..93be50c34a2 100644 --- a/drivers/sound/max98095.c +++ b/drivers/sound/max98095.c @@ -432,84 +432,6 @@ static int max98095_do_init(struct maxim_priv *priv, return ret; } -#ifndef CONFIG_DM_SOUND -static int get_max98095_codec_values(struct sound_codec_info *pcodec_info, - const void *blob) -{ - int error = 0; - enum fdt_compat_id compat; - int node; - int parent; - - /* Get the node from FDT for codec */ - node = fdtdec_next_compatible(blob, 0, COMPAT_MAXIM_98095_CODEC); - if (node <= 0) { - debug("EXYNOS_SOUND: No node for codec in device tree\n"); - debug("node = %d\n", node); - return -1; - } - - parent = fdt_parent_offset(blob, node); - if (parent < 0) { - debug("%s: Cannot find node parent\n", __func__); - return -1; - } - - compat = fdtdec_lookup(blob, parent); - switch (compat) { - case COMPAT_SAMSUNG_S3C2440_I2C: - pcodec_info->i2c_bus = i2c_get_bus_num_fdt(parent); - error |= pcodec_info->i2c_bus; - debug("i2c bus = %d\n", pcodec_info->i2c_bus); - pcodec_info->i2c_dev_addr = fdtdec_get_int(blob, node, - "reg", 0); - error |= pcodec_info->i2c_dev_addr; - debug("i2c dev addr = %x\n", pcodec_info->i2c_dev_addr); - break; - default: - debug("%s: Unknown compat id %d\n", __func__, compat); - return -1; - } - if (error == -1) { - debug("fail to get max98095 codec node properties\n"); - return -1; - } - - return 0; -} - -/* max98095 Device Initialisation */ -int max98095_init(const void *blob, enum en_max_audio_interface aif_id, - int sampling_rate, int mclk_freq, - int bits_per_sample) -{ - int ret; - int old_bus = i2c_get_bus_num(); - struct sound_codec_info pcodec_info; - struct max98095_priv max98095_info; - - if (get_max98095_codec_values(&pcodec_info, blob) < 0) { - debug("FDT Codec values failed\n"); - return -1; - } - - i2c_set_bus_num(pcodec_info.i2c_bus); - - max98095_info.i2c_addr = pcodec_info.i2c_dev_addr; - ret = max98095_device_init(&max98095_info); - if (ret < 0) { - debug("%s: max98095 codec chip init failed\n", __func__); - return ret; - } - - ret = max98095_do_init(&max98095_info, aif_id, sampling_rate, mclk_freq, - bits_per_sample); - i2c_set_bus_num(old_bus); - - return ret; -} -#endif - static int max98095_set_params(struct udevice *dev, int interface, int rate, int mclk_freq, int bits_per_sample, uint channels) diff --git a/drivers/sound/sandbox.c b/drivers/sound/sandbox.c index ee2635f41d2..4a3b41dd002 100644 --- a/drivers/sound/sandbox.c +++ b/drivers/sound/sandbox.c @@ -8,7 +8,6 @@ #include #include #include -#include #include struct sandbox_codec_priv { @@ -28,22 +27,6 @@ struct sandbox_sound_priv { int sum; /* Use to sum the provided audio data */ }; -#ifndef CONFIG_DM_SOUND -int sound_play(uint32_t msec, uint32_t frequency) -{ - sandbox_sdl_sound_start(frequency); - mdelay(msec); - sandbox_sdl_sound_stop(); - - return 0; -} -#endif /* CONFIG_DM_SOUND */ - -int sound_init(const void *blob) -{ - return sandbox_sdl_sound_init(); -} - void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep, int *mclk_freqp, int *bits_per_samplep, uint *channelsp) @@ -102,7 +85,7 @@ 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 0; + return sandbox_sdl_sound_play(data, data_size); } static int sandbox_i2s_probe(struct udevice *dev) diff --git a/drivers/sound/sound-i2s.c b/drivers/sound/sound-i2s.c deleted file mode 100644 index a2fc78154f1..00000000000 --- a/drivers/sound/sound-i2s.c +++ /dev/null @@ -1,206 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (C) 2012 Samsung Electronics - * R. Chandrasekar - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "wm8994.h" -#include "max98095.h" - -/* defines */ -#define SOUND_400_HZ 400 -#define SOUND_BITS_IN_BYTE 8 - -static struct i2s_uc_priv g_i2stx_pri; - -/* - * get_sound_i2s_values gets values for i2s parameters - * - * @param i2s_uc_priv i2s transmitter transfer param structure - * @param blob FDT blob if enabled else NULL - */ -static int get_sound_i2s_values(struct i2s_uc_priv *i2s, const void *blob) -{ - int node; - int error = 0; - int base; - - node = fdt_path_offset(blob, "i2s"); - if (node <= 0) { - debug("EXYNOS_SOUND: No node for sound in device tree\n"); - return -1; - } - - /* - * Get the pre-defined sound specific values from FDT. - * All of these are expected to be correct otherwise - * wrong register values in i2s setup parameters - * may result in no sound play. - */ - base = fdtdec_get_addr(blob, node, "reg"); - if (base == FDT_ADDR_T_NONE) { - debug("%s: Missing i2s base\n", __func__); - return -1; - } - i2s->base_address = base; - - i2s->audio_pll_clk = fdtdec_get_int(blob, - node, "samsung,i2s-epll-clock-frequency", -1); - error |= i2s->audio_pll_clk; - debug("audio_pll_clk = %d\n", i2s->audio_pll_clk); - i2s->samplingrate = fdtdec_get_int(blob, - node, "samsung,i2s-sampling-rate", -1); - error |= i2s->samplingrate; - debug("samplingrate = %d\n", i2s->samplingrate); - i2s->bitspersample = fdtdec_get_int(blob, - node, "samsung,i2s-bits-per-sample", -1); - error |= i2s->bitspersample; - debug("bitspersample = %d\n", i2s->bitspersample); - i2s->channels = fdtdec_get_int(blob, - node, "samsung,i2s-channels", -1); - error |= i2s->channels; - debug("channels = %d\n", i2s->channels); - i2s->rfs = fdtdec_get_int(blob, - node, "samsung,i2s-lr-clk-framesize", -1); - error |= i2s->rfs; - debug("rfs = %d\n", i2s->rfs); - i2s->bfs = fdtdec_get_int(blob, - node, "samsung,i2s-bit-clk-framesize", -1); - error |= i2s->bfs; - debug("bfs = %d\n", i2s->bfs); - - i2s->id = fdtdec_get_int(blob, node, "samsung,i2s-id", -1); - error |= i2s->id; - debug("id = %d\n", i2s->id); - - if (error == -1) { - debug("fail to get sound i2s node properties\n"); - return -1; - } - - return 0; -} - -/* - * Init codec - * - * @param blob FDT blob - * @param pi2s_tx i2s parameters required by codec - * @return int value, 0 for success - */ -static int codec_init(const void *blob, struct i2s_uc_priv *pi2s_tx) -{ - int ret; - const char *codectype; - int node; - - /* Get the node from FDT for sound */ - node = fdt_path_offset(blob, "i2s"); - if (node <= 0) { - debug("EXYNOS_SOUND: No node for sound in device tree\n"); - debug("node = %d\n", node); - return -1; - } - - /* - * Get the pre-defined sound codec specific values from FDT. - * All of these are expected to be correct otherwise sound - * can not be played - */ - codectype = fdt_getprop(blob, node, "samsung,codec-type", NULL); - debug("device = %s\n", codectype); - if (!strcmp(codectype, "wm8994")) { - /* Check the codec type and initialise the same */ - ret = wm8994_init(blob, pi2s_tx->id, pi2s_tx->samplingrate, - (pi2s_tx->samplingrate * (pi2s_tx->rfs)), - pi2s_tx->bitspersample, pi2s_tx->channels); - } else if (!strcmp(codectype, "max98095")) { - ret = max98095_init(blob, pi2s_tx->id, pi2s_tx->samplingrate, - (pi2s_tx->samplingrate * (pi2s_tx->rfs)), - pi2s_tx->bitspersample); - } else { - debug("%s: Unknown codec type %s\n", __func__, codectype); - return -1; - } - - if (ret) { - debug("%s: Codec init failed\n", __func__); - return -1; - } - - return 0; -} - -int sound_init(const void *blob) -{ - int ret; - struct i2s_uc_priv *pi2s_tx = &g_i2stx_pri; - - /* Get the I2S Values */ - if (get_sound_i2s_values(pi2s_tx, blob) < 0) { - debug(" FDT I2S values failed\n"); - return -1; - } - - if (codec_init(blob, pi2s_tx) < 0) { - debug(" Codec init failed\n"); - return -1; - } - - ret = i2s_tx_init(pi2s_tx); - if (ret) { - debug("%s: Failed to init i2c transmit: ret=%d\n", __func__, - ret); - return ret; - } - - - return ret; -} - -int sound_play(uint32_t msec, uint32_t frequency) -{ - unsigned int *data; - unsigned long data_size; - unsigned int ret = 0; - - /*Buffer length computation */ - data_size = g_i2stx_pri.samplingrate * g_i2stx_pri.channels; - data_size *= (g_i2stx_pri.bitspersample / SOUND_BITS_IN_BYTE); - data = malloc(data_size); - - if (data == NULL) { - debug("%s: malloc failed\n", __func__); - return -1; - } - - sound_create_square_wave(g_i2stx_pri.samplingrate, - (unsigned short *)data, - data_size / sizeof(unsigned short), - frequency); - - while (msec >= 1000) { - ret = i2s_transfer_tx_data(&g_i2stx_pri, data, - (data_size / sizeof(int))); - msec -= 1000; - } - if (msec) { - unsigned long size = - (data_size * msec) / (sizeof(int) * 1000); - - ret = i2s_transfer_tx_data(&g_i2stx_pri, data, size); - } - - free(data); - - return ret; -} diff --git a/drivers/sound/wm8994.c b/drivers/sound/wm8994.c index d731a0dd863..b290c4e8791 100644 --- a/drivers/sound/wm8994.c +++ b/drivers/sound/wm8994.c @@ -40,7 +40,6 @@ struct wm8994_priv { int mclk[WM8994_MAX_AIF]; /* master clock frequency in Hz */ int aifclk[WM8994_MAX_AIF]; /* audio interface clock in Hz */ struct wm8994_fll_config fll[2]; /* fll config to configure fll */ - int i2c_addr; struct udevice *dev; }; @@ -82,12 +81,7 @@ static int wm8994_i2c_write(struct wm8994_priv *priv, unsigned int reg, val[1] = (unsigned char)(data & 0xff); debug("Write Addr : 0x%04X, Data : 0x%04X\n", reg, data); -#ifdef CONFIG_DM_SOUND - debug("dev = %s\n", priv->dev->name); return dm_i2c_write(priv->dev, reg, val, 2); -#else - return i2c_write(priv->i2c_addr, reg, 2, val, 2); -#endif } /* @@ -105,11 +99,7 @@ static unsigned int wm8994_i2c_read(struct wm8994_priv *priv, unsigned int reg, unsigned char val[2]; int ret; -#ifdef CONFIG_DM_SOUND ret = dm_i2c_read(priv->dev, reg, val, 1); -#else - ret = i2c_read(priv->i2c_addr, reg, 2, val, 2); -#endif if (ret != 0) { debug("%s: Error while reading register %#04x\n", __func__, reg); @@ -819,61 +809,6 @@ err: return -1; } -#ifndef CONFIG_DM_SOUND -/* - * Gets fdt values for wm8994 config parameters - * - * @param pcodec_info codec information structure - * @param blob FDT blob - * @return int value, 0 for success - */ -static int get_codec_values(struct sound_codec_info *pcodec_info, - const void *blob) -{ - int error = 0; - enum fdt_compat_id compat; - int node; - int parent; - - /* Get the node from FDT for codec */ - node = fdtdec_next_compatible(blob, 0, COMPAT_WOLFSON_WM8994_CODEC); - if (node <= 0) { - debug("EXYNOS_SOUND: No node for codec in device tree\n"); - debug("node = %d\n", node); - return -1; - } - - parent = fdt_parent_offset(blob, node); - if (parent < 0) { - debug("%s: Cannot find node parent\n", __func__); - return -1; - } - - compat = fdtdec_lookup(blob, parent); - switch (compat) { - case COMPAT_SAMSUNG_S3C2440_I2C: - pcodec_info->i2c_bus = i2c_get_bus_num_fdt(parent); - error |= pcodec_info->i2c_bus; - debug("i2c bus = %d\n", pcodec_info->i2c_bus); - pcodec_info->i2c_dev_addr = fdtdec_get_int(blob, node, - "reg", 0); - error |= pcodec_info->i2c_dev_addr; - debug("i2c dev addr = %d\n", pcodec_info->i2c_dev_addr); - break; - default: - debug("%s: Unknown compat id %d\n", __func__, compat); - return -1; - } - - if (error == -1) { - debug("fail to get wm8994 codec node properties\n"); - return -1; - } - - return 0; -} -#endif - static int _wm8994_init(struct wm8994_priv *priv, enum en_audio_interface aif_id, int sampling_rate, int mclk_freq, int bits_per_sample, @@ -905,36 +840,6 @@ static int _wm8994_init(struct wm8994_priv *priv, return ret; } -#ifndef CONFIG_DM_SOUND -/* WM8994 Device Initialisation */ -int wm8994_init(const void *blob, enum en_audio_interface aif_id, - int sampling_rate, int mclk_freq, int bits_per_sample, - unsigned int channels) -{ - struct sound_codec_info pcodec_info; - struct wm8994_priv wm8994_info; - int ret; - - /* Get the codec Values */ - if (get_codec_values(&pcodec_info, blob) < 0) { - debug("FDT Codec values failed\n"); - return -1; - } - - /* shift the device address by 1 for 7 bit addressing */ - wm8994_info.i2c_addr = pcodec_info.i2c_dev_addr; - i2c_set_bus_num(pcodec_info.i2c_bus); - ret = wm8994_device_init(&wm8994_info); - if (ret < 0) { - debug("%s: wm8994 codec chip init failed\n", __func__); - return ret; - } - - return _wm8994_init(&wm8994_info, aif_id, sampling_rate, mclk_freq, - bits_per_sample, channels); -} -#endif - static int wm8994_set_params(struct udevice *dev, int interface, int rate, int mclk_freq, int bits_per_sample, uint channels) { diff --git a/include/sound.h b/include/sound.h index c94d2c37265..02acefd34f0 100644 --- a/include/sound.h +++ b/include/sound.h @@ -45,14 +45,6 @@ struct sound_uc_priv { void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, uint freq); -/* - * Initialises audio sub system - * @param blob Pointer of device tree node or NULL if none. - * @return int value 0 for success, -1 for error - */ -int sound_init(const void *blob); - -#ifdef CONFIG_DM_SOUND /* * The sound uclass brings together a data transport (currently only I2C) and a * codec (currently connected over I2C). @@ -101,14 +93,4 @@ int sound_beep(struct udevice *dev, int msecs, int frequency_hz); */ int sound_find_codec_i2s(struct udevice *dev); -#else -/* - * plays the pcm data buffer in pcm_data.h through i2s1 to make the - * sine wave sound - * - * @return int 0 for success, -1 for error - */ -int sound_play(uint32_t msec, uint32_t frequency); -#endif /* CONFIG_DM_SOUND */ - #endif /* __SOUND__H__ */ diff --git a/test/dm/Makefile b/test/dm/Makefile index 73f5dcf739e..6b451060d8a 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -13,7 +13,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o # subsystem you must add sandbox tests here. obj-$(CONFIG_UT_DM) += core.o ifneq ($(CONFIG_SANDBOX),) -obj-$(CONFIG_DM_SOUND) += audio.o +obj-$(CONFIG_SOUND) += audio.o obj-$(CONFIG_BLK) += blk.o obj-$(CONFIG_BOARD) += board.o obj-$(CONFIG_CLK) += clk.o @@ -22,7 +22,7 @@ obj-$(CONFIG_FIRMWARE) += firmware.o obj-$(CONFIG_DM_GPIO) += gpio.o obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o obj-$(CONFIG_DM_I2C) += i2c.o -obj-$(CONFIG_DM_SOUND) += i2s.o +obj-$(CONFIG_SOUND) += i2s.o obj-$(CONFIG_LED) += led.o obj-$(CONFIG_DM_MAILBOX) += mailbox.o obj-$(CONFIG_DM_MMC) += mmc.o @@ -55,7 +55,7 @@ obj-$(CONFIG_AXI) += axi.o obj-$(CONFIG_MISC) += misc.o obj-$(CONFIG_DM_SERIAL) += serial.o obj-$(CONFIG_CPU) += cpu.o -obj-$(CONFIG_DM_SOUND) += sound.o +obj-$(CONFIG_SOUND) += sound.o obj-$(CONFIG_TEE) += tee.o obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o obj-$(CONFIG_DMA) += dma.o From patchwork Mon Dec 10 17:37:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010579 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="D+O375OI"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9XV4nbHz9s3Z for ; Tue, 11 Dec 2018 04:48:06 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id D7B92C22618; Mon, 10 Dec 2018 17:45:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 1CBD6C22865; Mon, 10 Dec 2018 17:38:51 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E24FDC2260B; Mon, 10 Dec 2018 17:38:36 +0000 (UTC) Received: from mail-it1-f198.google.com (mail-it1-f198.google.com [209.85.166.198]) by lists.denx.de (Postfix) with ESMTPS id 9E9DBC22835 for ; Mon, 10 Dec 2018 17:38:31 +0000 (UTC) Received: by mail-it1-f198.google.com with SMTP id p66so6595279itc.0 for ; Mon, 10 Dec 2018 09:38:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=zH7eZoxn54cOjYMfgQNMcTH+MDoIjdUJ2ic8cw1F22M=; b=D+O375OIR6W0XCTvc/wPefbGLTEXmGPBK21k2wyhIl/w3aGyzCkXFdnfWlJNq6E9Nt gFvYXbbx0WRb1EA3Ag/viwkQGsFo2XLYA/jdqm2BeCRPNn14jrZlKzTHuGEO390KewtG vnmkRrqMxrMQ+NPf7JQkdD1T4vtEYIiwGA+0I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=zH7eZoxn54cOjYMfgQNMcTH+MDoIjdUJ2ic8cw1F22M=; b=b2qPiGsYBg7Ccoo0KteCxtFeKdpF5/9WLrbalEzfgCgfqob08ZGudwL3IXNC7HJKMb 4HfSAm+a7lHNlvD1i/I02tlJqIf2kH8b/cuA+NQlzwfUlbdx4yVUhUrbfYzWApdB+K2/ +f2CxA9NiTO4OGRw62UcnS1t/8bvWiJChtjIppAxWsjhJNVwGINGqQAua3vYa4FAN4XA BGPz1uNnFXKvmyM9n5tkWrP2PrhsHLbyg9xZO6mXQkI9LERgPZNqpEy14/GcwDzj0h8T r19JorERHEsMbx//hG+RuVd6kPK0pKXuvBt+D2ml6drKCOC3+84IKHro883VqVQK9g2t +clg== X-Gm-Message-State: AA+aEWbZe1UPaUQcIrv++8qjXwMNw4aDd5wyquYPG18cQV1jsxczaP83 K4kNi9FlMBdoO5oVIwR9f7IINJWcVkEKzXcK X-Google-Smtp-Source: AFSGD/VdR8Jm+nLR3S8rKgeX16oxhNCq1I9R7x0yvpzYCfYxWgCs1X804gp/nsWCLwjcKNIKbB+qvSJVOJVbzNZz X-Received: by 2002:a24:4ac3:: with SMTP id k186mr10710435itb.37.1544463510670; Mon, 10 Dec 2018 09:38:30 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:48 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-20-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 19/22] dm: sound: Fix license headers X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Fix a few files whos license headers were not converted to SPDX. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: - Add new patch to fix license headers drivers/sound/max98095.c | 7 ++----- drivers/sound/max98095.h | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/sound/max98095.c b/drivers/sound/max98095.c index 93be50c34a2..624c5d24ef3 100644 --- a/drivers/sound/max98095.c +++ b/drivers/sound/max98095.c @@ -1,13 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * max98095.c -- MAX98095 ALSA SoC Audio driver * * Copyright 2011 Maxim Integrated Products * - * Modified for uboot by R. Chandrasekar (rcsekar@samsung.com) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. + * Modified for U-Boot by R. Chandrasekar (rcsekar@samsung.com) */ #include diff --git a/drivers/sound/max98095.h b/drivers/sound/max98095.h index f189db728d1..1521f3f02f9 100644 --- a/drivers/sound/max98095.h +++ b/drivers/sound/max98095.h @@ -1,11 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * max98095.h -- MAX98095 ALSA SoC Audio driver * * Copyright 2011 Maxim Integrated Products - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. */ #ifndef _MAX98095_H From patchwork Mon Dec 10 17:37:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010592 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Rabi/vnr"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9hC1RMTz9s3C for ; Tue, 11 Dec 2018 04:54:51 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id ECF89C2286F; Mon, 10 Dec 2018 17:50:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 0EFCDC22889; Mon, 10 Dec 2018 17:39:26 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EFBADC22653; Mon, 10 Dec 2018 17:38:37 +0000 (UTC) Received: from mail-it1-f198.google.com (mail-it1-f198.google.com [209.85.166.198]) by lists.denx.de (Postfix) with ESMTPS id 4D9E8C2263A for ; Mon, 10 Dec 2018 17:38:33 +0000 (UTC) Received: by mail-it1-f198.google.com with SMTP id c73so14394773itd.1 for ; Mon, 10 Dec 2018 09:38:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=gBQr+RrKXYRWBaC1Tf4SxYHAhT4QVRWh1qrfTvCESsw=; b=Rabi/vnrGSuXysF1PV7+ClxO4lSjVz5hwiHJSf80OlFSHRcF05jCfloogrCs3NkfrK YBeEtHDy/w1Kxif97bvM2b+a8orzDda9Y9U415pl9QxYNQRtolRsHIT0IHFwlF98Pe/T Re3Xnruy8uLhqRYjY3APRE2N5iRlOmwpOd14s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=gBQr+RrKXYRWBaC1Tf4SxYHAhT4QVRWh1qrfTvCESsw=; b=O3H7Yd+JDOYRiOki/+5IlRGZ4MuGtahx0kM+HdJDwU+tk07TDGicQROiA7DKndvgsR JKwm35rFehwSCQ+Qw2jO5FcVzGts0YsRk4rD5SIsT2gasN6UshjwYFPWyMD+AeJs8qte wTjqoUeKRy3W5UygPHXMbldB3F1SqeNRfS54EnJ1VY+10wFJAXNQcKn/GG+haO/SkeWc nGkXaYq/c97l+xk9VQVcCQT6hPyPKGu4BpK95TNKkx8EvxzwAJWmZjcu/DyYWgJYJQKi 8rhVJaneX2z2suJ5Vuo603D7CDSQdMY6BCliq4Nj11vEL44xDZh69EVixBUnnNnHR7co qoAw== X-Gm-Message-State: AA+aEWbOP+v5TzGYkpq38XvKZtSWsu6b917szeQe1Bs70Fovzdkdd53L uxiolDJLxTIQG1MdrVh8lMVqQixL+dnc0JsQ X-Google-Smtp-Source: AFSGD/UxnzFbPoNWje8YVDvl6LEYevZN0+33OUSkxkT4ZTxXtNBgpZ11g/ClwnN28ox7ULL+rH6JvqXaGWH8CRE3 X-Received: by 2002:a24:2289:: with SMTP id o131mr10973190ito.7.1544463512331; Mon, 10 Dec 2018 09:38:32 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:49 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-21-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 20/22] dm: sound: max98095: Tidy up error codes X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Return a valid error code instead of -1. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: - Add new patch to tidy up error codes in max98095 drivers/sound/max98095.c | 47 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/drivers/sound/max98095.c b/drivers/sound/max98095.c index 624c5d24ef3..99c0e996b4f 100644 --- a/drivers/sound/max98095.c +++ b/drivers/sound/max98095.c @@ -46,7 +46,7 @@ static int rate_value(int rate, u8 *value) } *value = 1; - return -1; + return -EINVAL; } /* @@ -56,7 +56,7 @@ static int rate_value(int rate, u8 *value) * @param rate Sampling rate * @param bits_per_sample Bits per sample * - * @return -1 for error and 0 Success. + * @return 0 for success or negative error code. */ static int max98095_hw_params(struct maxim_priv *priv, enum en_max_audio_interface aif_id, @@ -89,13 +89,13 @@ static int max98095_hw_params(struct maxim_priv *priv, default: debug("%s: Illegal bits per sample %d.\n", __func__, bits_per_sample); - return -1; + return -EINVAL; } if (rate_value(rate, ®val)) { debug("%s: Failed to set sample rate to %d.\n", __func__, rate); - return -1; + return -EINVAL; } priv->rate = rate; @@ -112,7 +112,7 @@ static int max98095_hw_params(struct maxim_priv *priv, if (error < 0) { debug("%s: Error setting hardware params.\n", __func__); - return -1; + return -EIO; } return 0; @@ -124,7 +124,7 @@ static int max98095_hw_params(struct maxim_priv *priv, * @param priv max98095 information * @param freq Sampling frequency in Hz * - * @return -1 for error and 0 success. + * @return 0 for success or negative error code. */ static int max98095_set_sysclk(struct maxim_priv *priv, unsigned int freq) { @@ -147,13 +147,13 @@ static int max98095_set_sysclk(struct maxim_priv *priv, unsigned int freq) error = maxim_i2c_write(priv, M98095_026_SYS_CLK, 0x30); } else { debug("%s: Invalid master clock frequency\n", __func__); - return -1; + return -EINVAL; } debug("%s: Clock at %uHz\n", __func__, freq); if (error < 0) - return -1; + return -EIO; priv->sysclk = freq; return 0; @@ -166,7 +166,7 @@ static int max98095_set_sysclk(struct maxim_priv *priv, unsigned int freq) * @param fmt i2S format - supports a subset of the options defined * in i2s.h. * - * @return -1 for error and 0 Success. + * @return 0 for success or negative error code. */ static int max98095_set_fmt(struct maxim_priv *priv, int fmt, enum en_max_audio_interface aif_id) @@ -209,7 +209,7 @@ static int max98095_set_fmt(struct maxim_priv *priv, int fmt, case SND_SOC_DAIFMT_CBM_CFS: default: debug("%s: Clock mode unsupported\n", __func__); - return -1; + return -EINVAL; } switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { @@ -220,7 +220,7 @@ static int max98095_set_fmt(struct maxim_priv *priv, int fmt, break; default: debug("%s: Unrecognized format.\n", __func__); - return -1; + return -EINVAL; } switch (fmt & SND_SOC_DAIFMT_INV_MASK) { @@ -237,7 +237,7 @@ static int max98095_set_fmt(struct maxim_priv *priv, int fmt, break; default: debug("%s: Unrecognized inversion settings.\n", __func__); - return -1; + return -EINVAL; } error |= maxim_bic_or(priv, M98095_DAI_FORMAT, @@ -248,7 +248,7 @@ static int max98095_set_fmt(struct maxim_priv *priv, int fmt, if (error < 0) { debug("%s: Error setting i2s format.\n", __func__); - return -1; + return -EIO; } return 0; @@ -258,7 +258,7 @@ static int max98095_set_fmt(struct maxim_priv *priv, int fmt, * resets the audio codec * * @param priv Private data for driver - * @return -1 for error and 0 success. + * @return 0 for success or negative error code. */ static int max98095_reset(struct maxim_priv *priv) { @@ -299,22 +299,21 @@ static int max98095_reset(struct maxim_priv *priv) * Intialise max98095 codec device * * @param priv max98095 information - * - * @returns -1 for error and 0 Success. + * @return 0 for success or negative error code. */ static int max98095_device_init(struct maxim_priv *priv) { unsigned char id; - int error = 0; + int ret; /* Enable codec clock */ set_xclkout(); /* reset the codec, the DSP core, and disable all interrupts */ - error = max98095_reset(priv); - if (error != 0) { + ret = max98095_reset(priv); + if (ret != 0) { debug("Reset\n"); - return error; + return ret; } /* initialize private data */ @@ -322,11 +321,11 @@ static int max98095_device_init(struct maxim_priv *priv) priv->rate = -1U; priv->fmt = -1U; - error = maxim_i2c_read(priv, M98095_0FF_REV_ID, &id); - if (error < 0) { + ret = maxim_i2c_read(priv, M98095_0FF_REV_ID, &id); + if (ret < 0) { debug("%s: Failure reading hardware revision: %d\n", __func__, id); - return error; + return ret; } debug("%s: Hardware revision: %c\n", __func__, (id - 0x40) + 'A'); @@ -392,7 +391,7 @@ static int max98095_setup_interface(struct maxim_priv *priv, error |= maxim_i2c_write(priv, M98095_096_PWR_DAC_CK, 0x07); if (error < 0) - return -1; + return -EIO; return 0; } From patchwork Mon Dec 10 17:37:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010593 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="PpfPjZxg"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9hL2fMwz9s3C for ; Tue, 11 Dec 2018 04:54:58 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 0A770C22868; Mon, 10 Dec 2018 17:49:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 2D222C2284C; Mon, 10 Dec 2018 17:39:08 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 24019C22869; Mon, 10 Dec 2018 17:38:38 +0000 (UTC) Received: from mail-it1-f200.google.com (mail-it1-f200.google.com [209.85.166.200]) by lists.denx.de (Postfix) with ESMTPS id 045E8C227D5 for ; Mon, 10 Dec 2018 17:38:35 +0000 (UTC) Received: by mail-it1-f200.google.com with SMTP id 123so15251903itv.6 for ; Mon, 10 Dec 2018 09:38:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=4SGuSXr4hhUB5icnsR+W6y9AltT3uefBcHCyllUmh1I=; b=PpfPjZxg9Iql/HZB8bpiBKGEWELWpNud+/Tcv2P3SLGDP+9AUe1bcXO4I0T8OGiWRE jhSM2VL+p+m1l1vPcHnBuas2lysx2GyJhpCHPdPc8a72zviY43xByWawyv31f0KJaMEb 82RekNHQdgNW1arMEJIHBeWECA7VdiJzvQWiw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4SGuSXr4hhUB5icnsR+W6y9AltT3uefBcHCyllUmh1I=; b=aDoHKSMKX+4woIuvYIGmaYWNV7PnQaLbx1Ewc7GyLPod/HSk4hcKKZ/FcCtm75CZJK xMGIegHqKy5tWnH5o8yAI4HUErNsuPO9YnerG93TZbgmVr8uDwNFlM/clPjAIB5/3UJ0 gPT0szSt5VP3sTFfE2jyzwnTw6vKO5dmMo4zL00edJuAXDs6mRr5EzmpoQlLY0Zotnql gT1/AKvyun9/Bp6dKVZ1U+ADOlW+F24AfJ4OSiJCGJccxMwpfCjZ4wELyUuXunq9aoK1 3aUEoLMMM7ao1xNDl7F6u5gr7tL46hy92LAEAxoPjqu38+PDuaguyM8DIMLkcqxwjhX5 lckw== X-Gm-Message-State: AA+aEWbi6WEDqNJEQxivP5PCraHSyx01Tgb9B+SJ5AJ/Rp6f/bbJE9z4 H0Jv+GbTNjIhBSS2giuhnHe+XQ31XoMFLJHd X-Google-Smtp-Source: AFSGD/Wrv7GzjZe2WWM/aDuWl1iiKL7G/dBTLyb6F3jafZt+sif23BnQmtoF4oh0ZwcWV8vLLgWSA85zoGnzsYZK X-Received: by 2002:a24:594f:: with SMTP id p76mr10717158itb.10.1544463513998; Mon, 10 Dec 2018 09:38:33 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:50 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-22-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 21/22] dm: sandbox: Allow selection of sample rate and channels X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" At present these parameters are hard-coded in the sdl interface code. Allow them to be specified by the driver instead. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: None arch/sandbox/cpu/sdl.c | 10 +++------- arch/sandbox/include/asm/sdl.h | 6 ++++-- drivers/sound/sandbox.c | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c index 7eb2df7ddad..66de4040fc8 100644 --- a/arch/sandbox/cpu/sdl.c +++ b/arch/sandbox/cpu/sdl.c @@ -9,10 +9,6 @@ #include #include -enum { - SAMPLE_RATE = 22050, -}; - /** * struct buf_info - a data buffer holding audio data * @@ -285,7 +281,7 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len) } } -int sandbox_sdl_sound_init(void) +int sandbox_sdl_sound_init(int rate, int channels) { SDL_AudioSpec wanted; int i; @@ -297,9 +293,9 @@ int sandbox_sdl_sound_init(void) return 0; /* Set the audio format */ - wanted.freq = SAMPLE_RATE; + wanted.freq = rate; wanted.format = AUDIO_S16; - wanted.channels = 1; /* 1 = mono, 2 = stereo */ + wanted.channels = channels; wanted.samples = 1024; /* Good low-latency value for callback */ wanted.callback = sandbox_sdl_fill_audio; wanted.userdata = NULL; diff --git a/arch/sandbox/include/asm/sdl.h b/arch/sandbox/include/asm/sdl.h index 2799a8bee06..1027b59e732 100644 --- a/arch/sandbox/include/asm/sdl.h +++ b/arch/sandbox/include/asm/sdl.h @@ -71,9 +71,11 @@ int sandbox_sdl_sound_stop(void); /** * sandbox_sdl_sound_init() - set up the sound system * + * @rate: Sample rate to use + * @channels: Number of channels to use (1=mono, 2=stereo) * @return 0 if OK, -ENODEV if no sound is available */ -int sandbox_sdl_sound_init(void); +int sandbox_sdl_sound_init(int rate, int channels); #else static inline int sandbox_sdl_init_display(int width, int height, @@ -112,7 +114,7 @@ static inline int sandbox_sdl_sound_stop(void) return -ENODEV; } -static inline int sandbox_sdl_sound_init(void) +int sandbox_sdl_sound_init(int rate, int channels) { return -ENODEV; } diff --git a/drivers/sound/sandbox.c b/drivers/sound/sandbox.c index 4a3b41dd002..a4f15088236 100644 --- a/drivers/sound/sandbox.c +++ b/drivers/sound/sandbox.c @@ -101,7 +101,7 @@ static int sandbox_i2s_probe(struct udevice *dev) uc_priv->channels = 2; uc_priv->id = 1; - return sandbox_sdl_sound_init(); + return sandbox_sdl_sound_init(uc_priv->samplingrate, uc_priv->channels); } static int sandbox_sound_setup(struct udevice *dev) From patchwork Mon Dec 10 17:37:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1010590 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="KS117YFL"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43D9gD5WzGz9s3C for ; Tue, 11 Dec 2018 04:54:00 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 71410C226AF; Mon, 10 Dec 2018 17:48:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 42622C22883; Mon, 10 Dec 2018 17:39:04 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9DC6FC2286A; Mon, 10 Dec 2018 17:38:40 +0000 (UTC) Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by lists.denx.de (Postfix) with ESMTPS id B261BC22835 for ; Mon, 10 Dec 2018 17:38:36 +0000 (UTC) Received: by mail-qk1-f198.google.com with SMTP id k203so10922145qke.2 for ; Mon, 10 Dec 2018 09:38:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=GgdZQ/dyVrRehPYUcQUvuCzHKAhEgfem4wH/5tEnpKo=; b=KS117YFLp/XhRROk8NFBJy8suJ+NgecX2AMm0PYkIHjIrMnfxkm+HneSoUixCTaswM +4oOlDJnday1QIg5geP5REmoWdY40Y6RMIzrsZXv/DqvKVDWZW8rXvmX6Cde4ue7dBE+ s4Q7OblDsIGA+efrliVCWlLXU1QlNRhTA8ZQk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=GgdZQ/dyVrRehPYUcQUvuCzHKAhEgfem4wH/5tEnpKo=; b=M9pq+nAjvVI3HtXHKS8HVKk4Zo4GMfqMBlpnl2xuQvigwO4VY9bsymzXUMzWTRbDtj R8yp1oky0eZTXFjZH/QZYMai/GT8ICbT/LOtklwj1ELP7I/TJssx7rvE8V3+xB6CEf3W eBLodmedYfJWuE1JIEp6hGhaiWrqseU+b9wIgf5R4bZV7reHNry2HzeLIlefS39g8iCr zDdTWYDP1QJxOf/SWEFFwI9IdJPWm1ix0LHkFjG+qWJ54FiAnDKUPT3Md2wWHiZdaLEL BpYXVzayCY3gZ1jWka3dN+9/jIeP+3uFZz5HDdGY5uDFMCjTr0VzPqkNZDpH6W7NGDnV Yc0Q== X-Gm-Message-State: AA+aEWZ38NUr1wQDOj3LxlwT0/CNyL0twx2bSarxmDGlg0/p4Hoasb85 I1brScnKrLpgae8hz19Ab+bkgHlu+/pFyko8 X-Google-Smtp-Source: AFSGD/UtTNflb45xfFLoGZFKCxYRgnMspCXP+G660PSIXURJ7ZsgVciAKu41lLgzEXKbwwSh+O9xYq28QhETjb7+ X-Received: by 2002:a0c:96d7:: with SMTP id b23mr8472239qvd.48.1544463515552; Mon, 10 Dec 2018 09:38:35 -0800 (PST) Date: Mon, 10 Dec 2018 10:37:51 -0700 In-Reply-To: <20181210173751.177266-1-sjg@chromium.org> Message-Id: <20181210173751.177266-23-sjg@chromium.org> Mime-Version: 1.0 References: <20181210173751.177266-1-sjg@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v2 22/22] dm: sound: Use the correct number of channels for sound X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" At present the 'beep' sound generates a waveform for only one channel even if two are being used. This means that the beep is twice the frequency it should be. Correct this by making it a parameter. The fix in a previous commit was correct for sandbox but not for other boards. Fixes: 03f11e87a8 ("sound: Correct data output in sound_create_square_wave()") Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: - Add new patch to use the correct number of channels for sound drivers/sound/sound-uclass.c | 2 +- drivers/sound/sound.c | 11 +++++++---- include/sound.h | 11 ++++++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/sound/sound-uclass.c b/drivers/sound/sound-uclass.c index 71e753cb993..2b836268896 100644 --- a/drivers/sound/sound-uclass.c +++ b/drivers/sound/sound-uclass.c @@ -53,7 +53,7 @@ int sound_beep(struct udevice *dev, int msecs, int frequency_hz) } sound_create_square_wave(i2s_uc_priv->samplingrate, data, data_size, - frequency_hz); + frequency_hz, i2s_uc_priv->channels); while (msecs >= 1000) { ret = sound_play(dev, data, data_size); diff --git a/drivers/sound/sound.c b/drivers/sound/sound.c index 4f0ad0d8f0d..dd3f9db4f75 100644 --- a/drivers/sound/sound.c +++ b/drivers/sound/sound.c @@ -8,7 +8,7 @@ #include void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, - uint freq) + uint freq, uint channels) { const unsigned short amplitude = 16000; /* between 1 and 32767 */ const int period = freq ? sample_rate / freq : 0; @@ -21,14 +21,17 @@ void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, size--; while (size) { - int i; + int i, j; + for (i = 0; size && i < half; i++) { size -= 2; - *data++ = amplitude; + for (j = 0; j < channels; j++) + *data++ = amplitude; } for (i = 0; size && i < period - half; i++) { size -= 2; - *data++ = -amplitude; + for (j = 0; j < channels; j++) + *data++ = -amplitude; } } } diff --git a/include/sound.h b/include/sound.h index 02acefd34f0..b7959cc2607 100644 --- a/include/sound.h +++ b/include/sound.h @@ -37,13 +37,14 @@ struct sound_uc_priv { /** * Generates square wave sound data for 1 second * - * @param sample_rate Sample rate in Hz - * @param data data buffer pointer - * @param size size of the buffer in bytes - * @param freq frequency of the wave + * @sample_rate: Sample rate in Hz + * @data: data buffer pointer + * @size: size of the buffer in bytes + * @freq: frequency of the wave + * @channels: Number of channels to use */ void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, - uint freq); + uint freq, uint channels); /* * The sound uclass brings together a data transport (currently only I2C) and a