From patchwork Wed Nov 2 23:20:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13029349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0FBE7C4332F for ; Thu, 3 Nov 2022 00:30:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Xb6pXWKrziNBf71JYwsJbWPxaESr7+cxXahFTVPQK+Q=; b=FfUTe6m8t6KloV sJhvipsOnBNzfcRJtk/8Ghi5AyErydPexKzw/Qo3/gINDJHESzv7zbI1Btpzjd+b9Anqdn48oBBCO uTRKF1/O8rsjlYSzP1YphOPuz49vipuZawrBkJ1otgarEnkmWuhiXeGiyAkc+xvxczSavwW2OLfvm 3Uem9pwjRMqMhsKJRGJTD4eOGtnRs2tXZmPfSLLM6ZzMkY5C9nnoOzgyolY/qwgOHvy94t0no5wIW lCpffYoEynbcbe4/8+zE10A6Q5s+Wk/kGz8f3pYAsJIY/QXJ9QYoqZyNlPS7RwBG8GxDz4JrzncIK u7BqHcpBYOlrRnfp9k1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqO6O-00FJcs-0T; Thu, 03 Nov 2022 00:29:00 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqO5e-00FJ6v-Pb for linux-arm-kernel@bombadil.infradead.org; Thu, 03 Nov 2022 00:28:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=WS1e+43uL+FT/xkdxSFm6nee4mo2YYL1lmvIqpiOoFU=; b=TZ9HqBlbW94Xh3+8K/TIYWWdXK dgduc1NWJ9lY1/tAl0iLWx+oJZx3WiXqoRLgIlq3TQp5iP/u8FoqiGgBCujHBc971FRgZhqoew2+v pf7Xk8Ul5VizO2e3gt/aY11ndON1BBs6htn8Pa10g0d03O1l2RWlkNaJp8u7BrY9I3GY24X0SRCgG RJ99MCobv/laNLrIn7Lyl/g431TkG16VDj4AaCFzbIDJX1HVlRi6imginsqlOFBv6EnauaQALzyaX G3Y50dj1XqjYWjPvTiKdR8J5ZaLs6Xl+PVc3ZsUXjnNdILcrXRmmMQ/PLY62nLwy/iKhQ+J2uymZm zBxAQVBQ==; Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqN1q-008X4R-VV for linux-arm-kernel@lists.infradead.org; Wed, 02 Nov 2022 23:20:17 +0000 Received: by mail-pg1-x52d.google.com with SMTP id r18so148704pgr.12 for ; Wed, 02 Nov 2022 16:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WS1e+43uL+FT/xkdxSFm6nee4mo2YYL1lmvIqpiOoFU=; b=eNAW09APtQMwcF8srtLQ4v8T0sRnvgNmfHGFMZdDwC5B5NONfljMrDCUSdXxhZxwAS Si8f5RiURn8L/pDIk4NbK0PLKvOa7/cphvsv2PAk05tU/zHdSrErO4Tn9/5HTvSAEtg4 lloTdn1gVPlq+FLxaAtcBdz2Q+90hZULEalsqBD79E7eNlFV8N1Qp16tg64WEBLNN27y +ezxfpXb6N0KSdbh3UxwH8EnTRlBfNmcRVbvdyC5A1qYNNtqFT/IKBzoMMB12zEXybfD GRRF3owJwOlceGHIY33m7J39WzvkUNZl+dSZqvRpG/1vDqeJ2BtCDUSYLqHi3rgFbUxA ZSGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WS1e+43uL+FT/xkdxSFm6nee4mo2YYL1lmvIqpiOoFU=; b=SCE5TCRU7aF8M76b3oZBZOI3J2ruXXW5IrQKES85V9cHxPptw8kx4YxCB9ubsVqPKL gZau285Cft2Ng+xPisqc+4TwdrDbuwY8Bmv1bRNGppbemCkBuQZJLKTmT4KlK7NR8C6v WkYcGOnL/8PdIVVFDiOvpZbfP6XS0OLoZJOPM1oKVSBy8EDMV2qLV1S2dqDYgUNL2bZM z2t8Ukwvn+BoFP6MB0KJlsKEajCM3WWtNuDU4wTiemUWFFPalt4klMbnv04Mtjf3DcJV qUhR5KpR6fo1rj2QI+B13f0ij4yaTkmiEA7gOHNooJzevPDLvbPsfQjF6DShNJwqFiM0 sv1g== X-Gm-Message-State: ACrzQf3R/pYGqzIfDhhGtQX3wBbs+YCFKqG+k0sJAn+uLZwX8didqh2a ISbbP9GVw/OPKX2OqlUxeUq65PFhY2I= X-Google-Smtp-Source: AMsMyM4yOyeidT69MU0rVlgLhd+AuM79JodeBGbGUxHzsG5/nuu+7RMKT3vHWbJdgXDu52dKfwjQsQ== X-Received: by 2002:a63:f903:0:b0:46f:1b5:b4fd with SMTP id h3-20020a63f903000000b0046f01b5b4fdmr23233195pgi.544.1667431212859; Wed, 02 Nov 2022 16:20:12 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:a6ae:11ff:fe11:fcc3]) by smtp.gmail.com with ESMTPSA id p8-20020a170902780800b00186e2123506sm8842073pll.300.2022.11.02.16.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 16:20:12 -0700 (PDT) From: Dmitry Torokhov To: Tony Lindgren , Mark Brown Cc: Liam Girdwood , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] ASoC: tlv320aic3x: switch to using gpiod API Date: Wed, 2 Nov 2022 16:20:04 -0700 Message-Id: <20221102232004.1721864-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221102232004.1721864-1-dmitry.torokhov@gmail.com> References: <20221102232004.1721864-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221102_232015_231871_1C0DED0F X-CRM114-Status: GOOD ( 27.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Switch the driver from legacy gpio API that is deprecated to the newer gpiod API that respects line polarities described in ACPI/DT. The driver still tries to support shared reset lines, by first trying to allocate the reset GPIO normally, and then non-exclusively, although the utility of such support is questionable, toggling reset line from one driver/instance will result in all chips being reset, potentially at an inopportune moment. Note that this change depends on commit fbbbcd177a27 ("gpiolib: of: add quirk for locating reset lines with legacy bindings") to translate request for "reset" GPIO to the legacy name "gpio-reset" in case when proper name is not used. Signed-off-by: Dmitry Torokhov --- sound/soc/codecs/tlv320aic3x.c | 108 ++++++++++++--------------------- 1 file changed, 39 insertions(+), 69 deletions(-) diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c index 9b2bb99cc165..56e795a00e22 100644 --- a/sound/soc/codecs/tlv320aic3x.c +++ b/sound/soc/codecs/tlv320aic3x.c @@ -32,12 +32,12 @@ #include #include #include +#include #include #include -#include +#include #include #include -#include #include #include #include @@ -56,8 +56,6 @@ static const char *aic3x_supply_names[AIC3X_NUM_SUPPLIES] = { "DRVDD", /* ADC Analog and Output Driver Voltage */ }; -static LIST_HEAD(reset_list); - struct aic3x_priv; struct aic3x_disable_nb { @@ -80,9 +78,9 @@ struct aic3x_priv { unsigned int dai_fmt; unsigned int tdm_delay; unsigned int slot_width; - struct list_head list; int master; - int gpio_reset; + struct gpio_desc *gpio_reset; + bool shared_reset; int power; u16 model; @@ -1369,8 +1367,8 @@ static int aic3x_regulator_event(struct notifier_block *nb, * Put codec to reset and require cache sync as at least one * of the supplies was disabled */ - if (gpio_is_valid(aic3x->gpio_reset)) - gpio_set_value(aic3x->gpio_reset, 0); + if (aic3x->gpio_reset) + gpiod_set_value(aic3x->gpio_reset, 1); regcache_mark_dirty(aic3x->regmap); } @@ -1390,9 +1388,9 @@ static int aic3x_set_power(struct snd_soc_component *component, int power) goto out; aic3x->power = 1; - if (gpio_is_valid(aic3x->gpio_reset)) { + if (aic3x->gpio_reset) { udelay(1); - gpio_set_value(aic3x->gpio_reset, 1); + gpiod_set_value(aic3x->gpio_reset, 0); } /* Sync reg_cache with the hardware */ @@ -1598,19 +1596,6 @@ static int aic3x_init(struct snd_soc_component *component) return 0; } -static bool aic3x_is_shared_reset(struct aic3x_priv *aic3x) -{ - struct aic3x_priv *a; - - list_for_each_entry(a, &reset_list, list) { - if (gpio_is_valid(aic3x->gpio_reset) && - aic3x->gpio_reset == a->gpio_reset) - return true; - } - - return false; -} - static int aic3x_component_probe(struct snd_soc_component *component) { struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); @@ -1775,19 +1760,6 @@ int aic3x_probe(struct device *dev, struct regmap *regmap, kernel_ulong_t driver if (!ai3x_setup) return -ENOMEM; - ret = of_get_named_gpio(np, "reset-gpios", 0); - if (ret >= 0) { - aic3x->gpio_reset = ret; - } else { - ret = of_get_named_gpio(np, "gpio-reset", 0); - if (ret > 0) { - dev_warn(dev, "Using deprecated property \"gpio-reset\", please update your DT"); - aic3x->gpio_reset = ret; - } else { - aic3x->gpio_reset = -1; - } - } - if (of_property_read_u32_array(np, "ai3x-gpio-func", ai3x_setup->gpio_func, 2) >= 0) { aic3x->setup = ai3x_setup; @@ -1812,29 +1784,43 @@ int aic3x_probe(struct device *dev, struct regmap *regmap, kernel_ulong_t driver } else { aic3x->micbias_vg = AIC3X_MICBIAS_OFF; } - - } else { - aic3x->gpio_reset = -1; } aic3x->model = driver_data; - if (gpio_is_valid(aic3x->gpio_reset) && - !aic3x_is_shared_reset(aic3x)) { - ret = gpio_request(aic3x->gpio_reset, "tlv320aic3x reset"); - if (ret != 0) - goto err; - gpio_direction_output(aic3x->gpio_reset, 0); + aic3x->gpio_reset = devm_gpiod_get_optional(dev, "reset", + GPIOD_OUT_HIGH); + ret = PTR_ERR_OR_ZERO(aic3x->gpio_reset); + if (ret) { + if (ret != -EBUSY) + return ret; + + /* + * Apparently there are setups where the codec is sharing + * its reset line. Try to get it non-exclusively, although + * the utility of this is unclear: how do we make sure that + * resetting one chip will not disturb the others that share + * the same line? + */ + aic3x->gpio_reset = devm_gpiod_get(dev, "reset", + GPIOD_ASIS | GPIOD_FLAGS_BIT_NONEXCLUSIVE); + ret = PTR_ERR_OR_ZERO(aic3x->gpio_reset); + if (ret) + return ret; + + aic3x->shared_reset = true; } + gpiod_set_consumer_name(aic3x->gpio_reset, "tlv320aic3x reset"); + for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) aic3x->supplies[i].supply = aic3x_supply_names[i]; ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(aic3x->supplies), aic3x->supplies); - if (ret != 0) { + if (ret) { dev_err(dev, "Failed to request supplies: %d\n", ret); - goto err_gpio; + return ret; } aic3x_configure_ocmv(dev, aic3x); @@ -1843,26 +1829,14 @@ int aic3x_probe(struct device *dev, struct regmap *regmap, kernel_ulong_t driver ret = regmap_register_patch(aic3x->regmap, aic3007_class_d, ARRAY_SIZE(aic3007_class_d)); if (ret != 0) - dev_err(dev, "Failed to init class D: %d\n", - ret); + dev_err(dev, "Failed to init class D: %d\n", ret); } ret = devm_snd_soc_register_component(dev, &soc_component_dev_aic3x, &aic3x_dai, 1); - - if (ret != 0) - goto err_gpio; - - INIT_LIST_HEAD(&aic3x->list); - list_add(&aic3x->list, &reset_list); + if (ret) + return ret; return 0; - -err_gpio: - if (gpio_is_valid(aic3x->gpio_reset) && - !aic3x_is_shared_reset(aic3x)) - gpio_free(aic3x->gpio_reset); -err: - return ret; } EXPORT_SYMBOL(aic3x_probe); @@ -1870,13 +1844,9 @@ void aic3x_remove(struct device *dev) { struct aic3x_priv *aic3x = dev_get_drvdata(dev); - list_del(&aic3x->list); - - if (gpio_is_valid(aic3x->gpio_reset) && - !aic3x_is_shared_reset(aic3x)) { - gpio_set_value(aic3x->gpio_reset, 0); - gpio_free(aic3x->gpio_reset); - } + /* Leave the codec in reset state */ + if (aic3x->gpio_reset && !aic3x->shared_reset) + gpiod_set_value(aic3x->gpio_reset, 1); } EXPORT_SYMBOL(aic3x_remove);