Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4254547yba; Tue, 7 May 2019 15:03:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsXUNtj4XXskvUc3/yKRsXSip+ugaRKBQOSIVRURrDvoYPT7RBpC1mhpmMAkOhjii4tOhJ X-Received: by 2002:a63:ff04:: with SMTP id k4mr42374654pgi.117.1557266628858; Tue, 07 May 2019 15:03:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557266628; cv=none; d=google.com; s=arc-20160816; b=umT8BQBtc5tuCslPKqABjRTcoceWwHRenw1L2Fnb6/fUd8XhQ4TMt3cfGssi1qN80A dzL3fD+w/uWiURbjrXilQcSgoIAVECAYb5AjVUtt+UToQXGLCHhAxqxu95rhiEcrHl3m DPn8KvTY7NglPFPgnNoT9uf3VjDkMnzPcC8qFDUlSzPhrIip5s1a0nQ5YU9HvcvBb4z7 mfpMmR4Oj23GaWB+NDRS816B1oj8encuBf88GnTUngBQW4oAESvT8ukUSXvHVDA7Bwf6 CitiI2nZmHGGG1SlhrS5oDE4jSt6OgBdzJ0j0/HGcOASr5FjdTI8dPwZAjhHofPk2s4P kSmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CGuDJR+4xPbyKsu/ODbUE97ci/DB/Fe9Iq0akCcSZNc=; b=oOdlEd85pHs1v8K/71XIV3uBsN1ViiMahaYS/45zG47S9XXbScZq24WBNGNzreoV5D Q5xhBd+71f6/SgovDyWjo4qjOKSX8ltpfmWZWJZESWLpW6A21tfI6qEWY3TgnOhox4r5 VAA++6d1/lsRXL9OKFUoFICBJ4CM+k9zi2gtWWVnxd7+fK3eohpi1TBI3X02JyEOuUzV rhIUtJZcvpFfrxgSG1beyan5x5cuhD8eManxD3VjyzLuTEu6rrnl7BcYWQAGPEpGky6c hoCQ1gAS1K217Mu4L4Mabd8JAOdpqCzvJ6LwtkKGRh/lCY6MMgmdr6yh9q28hSlaHpLO 5anw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Gy/JK2ho"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j12si18585284pgp.118.2019.05.07.15.03.32; Tue, 07 May 2019 15:03:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Gy/JK2ho"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726516AbfEGWBo (ORCPT + 99 others); Tue, 7 May 2019 18:01:44 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:39847 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726225AbfEGWBo (ORCPT ); Tue, 7 May 2019 18:01:44 -0400 Received: by mail-it1-f195.google.com with SMTP id m186so712667itd.4 for ; Tue, 07 May 2019 15:01:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CGuDJR+4xPbyKsu/ODbUE97ci/DB/Fe9Iq0akCcSZNc=; b=Gy/JK2hoUldlBLG5FfqWprZgc844D6WxSXGn5abZEHWoE5taMPqKBzs1NrlZk/+Zp0 u+gU+XEOw0nGOAZ+aG5ujm/DnzRpRLx1cnAxaYQ23k8wdb3nW2D04GFksRYpYkvRT2tA qT07M2NzLFP5PBxly9r6p6RQRA0wtT2VNuF5g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CGuDJR+4xPbyKsu/ODbUE97ci/DB/Fe9Iq0akCcSZNc=; b=ZVwD2akNuZGWSsSEyHPKSJysZbIkyOHLFtODfGaDfpYPpOjWrjm6iz0AiKNp4clrqg RqRqvwEy/Hg5ElryfOsZciJwSDbf2VRjqvn9buUuJrx9e7t6bBcJRE88OiltDvMWpt48 I/3E8govwGOEW4XIxR+V0bn/p1jVNiJ3CJ2fy9EinROxMSjyeoM/8Ie/bL0LQ+50G2kU +G3j0bsS4nOsqZwTyrO6aRIIUiuKBjftZZKml01gqtoWM1d83Cy2nyxLt6t/p6RKaAS7 pQuJyfzpYVYtoLxTA+C2wpFNOsY4k5J5zwO46+5oGyp66C1vO7fe5lrczXZfQO+zsNU8 QTDA== X-Gm-Message-State: APjAAAXAblJwOh/tGUO+bZvtBVT966K/sAtXc8ah/FfOl4ciI7B8105P eJ6MnkC7UP16xvVCOnvE6o5E0whB3j0= X-Received: by 2002:a05:660c:443:: with SMTP id d3mr601501itl.147.1557266502667; Tue, 07 May 2019 15:01:42 -0700 (PDT) Received: from localhost ([2620:15c:183:200:33ce:f5cf:f863:d3a6]) by smtp.gmail.com with ESMTPSA id 140sm171151itv.44.2019.05.07.15.01.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 15:01:41 -0700 (PDT) From: Fletcher Woodruff To: linux-kernel@vger.kernel.org Cc: Fletcher Woodruff , Jaroslav Kysela , Liam Girdwood , Mark Brown , Oder Chiou , Takashi Iwai , Curtis Malainey , alsa-devel@alsa-project.org Subject: [PATCH v5 3/3] ASoC: rt5677: fall back to DT prop names on error Date: Tue, 7 May 2019 16:01:15 -0600 Message-Id: <20190507220115.90395-4-fletcherw@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190507220115.90395-1-fletcherw@chromium.org> References: <20190507220115.90395-1-fletcherw@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The rt5677 driver uses ACPI-style property names to read from the device API. However, these do not match the property names in _DSD used on the Chromebook Pixel 2015, which are closer to the Device Tree style. Unify the two functions for reading from the device API so that they try ACPI-style names first and fall back to the DT names on error. With this patch, plugging and unplugging the headphone jack switches between headphones and speakers automatically. Signed-off-by: Fletcher Woodruff --- sound/soc/codecs/rt5677.c | 74 +++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 091ef3e78fe3d2..3a4796cabd18ea 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -4998,48 +4998,50 @@ static const struct acpi_device_id rt5677_acpi_match[] = { }; MODULE_DEVICE_TABLE(acpi, rt5677_acpi_match); -static void rt5677_read_acpi_properties(struct rt5677_priv *rt5677, +static void rt5677_read_device_properties(struct rt5677_priv *rt5677, struct device *dev) { u32 val; - if (!device_property_read_u32(dev, "DCLK", &val)) - rt5677->pdata.dmic2_clk_pin = val; + rt5677->pdata.in1_diff = + device_property_read_bool(dev, "IN1") || + device_property_read_bool(dev, "realtek,in1-differential"); - rt5677->pdata.in1_diff = device_property_read_bool(dev, "IN1"); - rt5677->pdata.in2_diff = device_property_read_bool(dev, "IN2"); - rt5677->pdata.lout1_diff = device_property_read_bool(dev, "OUT1"); - rt5677->pdata.lout2_diff = device_property_read_bool(dev, "OUT2"); - rt5677->pdata.lout3_diff = device_property_read_bool(dev, "OUT3"); + rt5677->pdata.in2_diff = + device_property_read_bool(dev, "IN2") || + device_property_read_bool(dev, "realtek,in2-differential"); - device_property_read_u32(dev, "JD1", &rt5677->pdata.jd1_gpio); - device_property_read_u32(dev, "JD2", &rt5677->pdata.jd2_gpio); - device_property_read_u32(dev, "JD3", &rt5677->pdata.jd3_gpio); -} + rt5677->pdata.lout1_diff = + device_property_read_bool(dev, "OUT1") || + device_property_read_bool(dev, "realtek,lout1-differential"); -static void rt5677_read_device_properties(struct rt5677_priv *rt5677, - struct device *dev) -{ - rt5677->pdata.in1_diff = device_property_read_bool(dev, - "realtek,in1-differential"); - rt5677->pdata.in2_diff = device_property_read_bool(dev, - "realtek,in2-differential"); - rt5677->pdata.lout1_diff = device_property_read_bool(dev, - "realtek,lout1-differential"); - rt5677->pdata.lout2_diff = device_property_read_bool(dev, - "realtek,lout2-differential"); - rt5677->pdata.lout3_diff = device_property_read_bool(dev, - "realtek,lout3-differential"); + rt5677->pdata.lout2_diff = + device_property_read_bool(dev, "OUT2") || + device_property_read_bool(dev, "realtek,lout2-differential"); + + rt5677->pdata.lout3_diff = + device_property_read_bool(dev, "OUT3") || + device_property_read_bool(dev, "realtek,lout3-differential"); device_property_read_u8_array(dev, "realtek,gpio-config", - rt5677->pdata.gpio_config, RT5677_GPIO_NUM); - - device_property_read_u32(dev, "realtek,jd1-gpio", - &rt5677->pdata.jd1_gpio); - device_property_read_u32(dev, "realtek,jd2-gpio", - &rt5677->pdata.jd2_gpio); - device_property_read_u32(dev, "realtek,jd3-gpio", - &rt5677->pdata.jd3_gpio); + rt5677->pdata.gpio_config, + RT5677_GPIO_NUM); + + if (!device_property_read_u32(dev, "DCLK", &val) || + !device_property_read_u32(dev, "realtek,dmic2_clk_pin", &val)) + rt5677->pdata.dmic2_clk_pin = val; + + if (!device_property_read_u32(dev, "JD1", &val) || + !device_property_read_u32(dev, "realtek,jd1-gpio", &val)) + rt5677->pdata.jd1_gpio = val; + + if (!device_property_read_u32(dev, "JD2", &val) || + !device_property_read_u32(dev, "realtek,jd2-gpio", &val)) + rt5677->pdata.jd2_gpio = val; + + if (!device_property_read_u32(dev, "JD3", &val) || + !device_property_read_u32(dev, "realtek,jd3-gpio", &val)) + rt5677->pdata.jd3_gpio = val; } struct rt5677_irq_desc { @@ -5283,20 +5285,18 @@ static int rt5677_i2c_probe(struct i2c_client *i2c) match_id = of_match_device(rt5677_of_match, &i2c->dev); if (match_id) rt5677->type = (enum rt5677_type)match_id->data; - - rt5677_read_device_properties(rt5677, &i2c->dev); } else if (ACPI_HANDLE(&i2c->dev)) { const struct acpi_device_id *acpi_id; acpi_id = acpi_match_device(rt5677_acpi_match, &i2c->dev); if (acpi_id) rt5677->type = (enum rt5677_type)acpi_id->driver_data; - - rt5677_read_acpi_properties(rt5677, &i2c->dev); } else { return -EINVAL; } + rt5677_read_device_properties(rt5677, &i2c->dev); + /* pow-ldo2 and reset are optional. The codec pins may be statically * connected on the board without gpios. If the gpio device property * isn't specified, devm_gpiod_get_optional returns NULL. -- 2.21.0.1020.gf2820cf01a-goog