From patchwork Wed Jan 24 07:45:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 767318 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAD6B17BA7 for ; Wed, 24 Jan 2024 07:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706082348; cv=none; b=RHdxyKbmHR0VVGqtbGKb3urVOPrIncWO3I5deJGRpfkRJm3//3NH+i9oEPFr+IQ2OIQAtoEMmE/+3PuFfyoF0U+khU3TwYTaCepJ5qWfdyhuyxXZB/mkaN+2Af+KAUufRZxVEXU4CcEj5PM942er9Wy2BRXpjLiJ2MVKz4PdAOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706082348; c=relaxed/simple; bh=oh0sTMif6CnOQLiL5a5MmyT0hcKnwI/jjGqAII0YSDc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P4i3nFDFsAv/aTUyVUDLLcfum+WWCFh/EXHcXGVANyPGYzDSG65kqPPhMUUGd7TR69uxZANJm2c0Df9UGy5l4YZeimrKnF7b7YpkQ0rqqZhb5rI6lFmI+Mw7O5mYvqulZT2rFeXJ7IbPkR8bGJOIM/51WyYcZPqbzqv+LDLoKNY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=h0OiU3Tp; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="h0OiU3Tp" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-55a354a65afso4468035a12.0 for ; Tue, 23 Jan 2024 23:45:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706082345; x=1706687145; darn=vger.kernel.org; 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=lRX88GpgU1fgsZxup3Gn93xc8N0Fj24AFUmctHwLfn4=; b=h0OiU3TpQicg0o3kpaS0v/nI2qe7EBYWo9w/H00iiGH0qw6TggAGYMAAFll2MGZyKT XpKErrU/WfdLcbD7gvAIe5op7mQDI8THOBiSXlGNUnhx0EoZF3Slvj+zyHmm397xw9+t G5ESlNL0edDsu37+6ECeOG0v1iYWYicC7QXk41n8f/5Lu7sijWTZUfJRgTRFqzywskXF LPLewqX2CKUBgbFbyQs3X6lXJV3WiDOiKimD8NvFO2wS0N5U5I2LMUxIB68QH512G84P TLkNmMM/bFlv0IXKLdjp0R6qWYcKN+pHBq4tOlTSYepHA2AHzBVzfYkSkOPWTK2Nu9hh LkUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706082345; x=1706687145; 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=lRX88GpgU1fgsZxup3Gn93xc8N0Fj24AFUmctHwLfn4=; b=tV/TJZHVxaz2vzQLYoOQi165LwmS0ituNMOzauaXB1RamYoF+Vp/xbt0FtgkcNtElo Newok7NPeuFaTOJPWcSVSyAU1D+s5wSx1Eyj7pTucw9Dnm0p401msjr23b/ViVzkHqU5 tLjuZ0RDtSawPf6BQ1P1rwxMUdtPaBW/Jvn0L21MXF83zyGjJ7uh54SkBpvLgFE3UJ5M 3LOmfMvn3AzhTHf22K1GvEzd2imruv370SZEoTp0/2NJJMQUFkai+dKhJY5faTrwFFVI yXoFmB3PlM0hZTgpEEdhKXRNRCDYzTikYCDe1WE9O1MViEBPG9eSdjIvXIgssTsuOYMo hXxA== X-Gm-Message-State: AOJu0YxH5HFCpuAtQ23o5LaUP0+88O3ZXc1lvGTvEU5TJuiaQvt2yAzN SiMnl6vND8iuUGOIn9Xovyj3iDxom3o2vli7JvuGTheXtUt6+JuiUri6XT9J62k= X-Google-Smtp-Source: AGHT+IHIiivpDee0vXa9Za1ZlMPh5ql9o2I3lx2sDE7uKWnN6FQlUAjNNnKSKOW8KA9hLJkFcO5VfQ== X-Received: by 2002:a05:6402:26d4:b0:55a:e42c:fafd with SMTP id x20-20020a05640226d400b0055ae42cfafdmr2239875edd.25.1706082345305; Tue, 23 Jan 2024 23:45:45 -0800 (PST) Received: from krzk-bin.. ([178.197.215.66]) by smtp.gmail.com with ESMTPSA id c4-20020a056402100400b0055c8a30152bsm1306951edu.83.2024.01.23.23.45.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 23:45:44 -0800 (PST) From: Krzysztof Kozlowski To: Srinivas Kandagatla , Banajit Goswami , Bjorn Andersson , Konrad Dybcio , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , "Rafael J. Wysocki" , Viresh Kumar , Frank Rowand , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-arm-msm@vger.kernel.org, linux-sound@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: Krzysztof Kozlowski , Bartosz Golaszewski , Sean Anderson Subject: [PATCH v5 6/6] ASoC: codecs: wsa884x: Allow sharing reset GPIO Date: Wed, 24 Jan 2024 08:45:27 +0100 Message-Id: <20240124074527.48869-7-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240124074527.48869-1-krzysztof.kozlowski@linaro.org> References: <20240124074527.48869-1-krzysztof.kozlowski@linaro.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On some boards with multiple WSA8840/WSA8845 speakers, the reset (shutdown) GPIO is shared between two speakers. Use the reset controller framework and its "reset-gpio" driver to handle this case. This allows bring-up and proper handling of all WSA884x speakers on X1E80100-CRD board. Cc: Bartosz Golaszewski Cc: Sean Anderson Reviewed-by: Philipp Zabel Signed-off-by: Krzysztof Kozlowski --- If previous patches are fine, then this commit is independent and could be taken via ASoC. --- sound/soc/codecs/wsa884x.c | 53 +++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c index f2653df84e4a..a9767ef0e39d 100644 --- a/sound/soc/codecs/wsa884x.c +++ b/sound/soc/codecs/wsa884x.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -699,6 +700,7 @@ struct wsa884x_priv { struct sdw_stream_runtime *sruntime; struct sdw_port_config port_config[WSA884X_MAX_SWR_PORTS]; struct gpio_desc *sd_n; + struct reset_control *sd_reset; bool port_prepared[WSA884X_MAX_SWR_PORTS]; bool port_enable[WSA884X_MAX_SWR_PORTS]; unsigned int variant; @@ -1799,9 +1801,22 @@ static struct snd_soc_dai_driver wsa884x_dais[] = { }, }; -static void wsa884x_gpio_powerdown(void *data) +static void wsa884x_reset_powerdown(void *data) { - gpiod_direction_output(data, 1); + struct wsa884x_priv *wsa884x = data; + + if (wsa884x->sd_reset) + reset_control_assert(wsa884x->sd_reset); + else + gpiod_direction_output(wsa884x->sd_n, 1); +} + +static void wsa884x_reset_deassert(struct wsa884x_priv *wsa884x) +{ + if (wsa884x->sd_reset) + reset_control_deassert(wsa884x->sd_reset); + else + gpiod_direction_output(wsa884x->sd_n, 0); } static void wsa884x_regulator_disable(void *data) @@ -1809,6 +1824,27 @@ static void wsa884x_regulator_disable(void *data) regulator_bulk_disable(WSA884X_SUPPLIES_NUM, data); } +static int wsa884x_get_reset(struct device *dev, struct wsa884x_priv *wsa884x) +{ + wsa884x->sd_reset = devm_reset_control_get_optional_shared(dev, NULL); + if (IS_ERR(wsa884x->sd_reset)) + return dev_err_probe(dev, PTR_ERR(wsa884x->sd_reset), + "Failed to get reset\n"); + else if (wsa884x->sd_reset) + return 0; + /* + * else: NULL, so use the backwards compatible way for powerdown-gpios, + * which does not handle sharing GPIO properly. + */ + wsa884x->sd_n = devm_gpiod_get_optional(dev, "powerdown", + GPIOD_OUT_HIGH); + if (IS_ERR(wsa884x->sd_n)) + return dev_err_probe(dev, PTR_ERR(wsa884x->sd_n), + "Shutdown Control GPIO not found\n"); + + return 0; +} + static int wsa884x_probe(struct sdw_slave *pdev, const struct sdw_device_id *id) { @@ -1838,11 +1874,9 @@ static int wsa884x_probe(struct sdw_slave *pdev, if (ret) return ret; - wsa884x->sd_n = devm_gpiod_get_optional(dev, "powerdown", - GPIOD_OUT_HIGH); - if (IS_ERR(wsa884x->sd_n)) - return dev_err_probe(dev, PTR_ERR(wsa884x->sd_n), - "Shutdown Control GPIO not found\n"); + ret = wsa884x_get_reset(dev, wsa884x); + if (ret) + return ret; dev_set_drvdata(dev, wsa884x); wsa884x->slave = pdev; @@ -1858,9 +1892,8 @@ static int wsa884x_probe(struct sdw_slave *pdev, pdev->prop.sink_dpn_prop = wsa884x_sink_dpn_prop; pdev->prop.scp_int1_mask = SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY; - /* Bring out of reset */ - gpiod_direction_output(wsa884x->sd_n, 0); - ret = devm_add_action_or_reset(dev, wsa884x_gpio_powerdown, wsa884x->sd_n); + wsa884x_reset_deassert(wsa884x); + ret = devm_add_action_or_reset(dev, wsa884x_reset_powerdown, wsa884x); if (ret) return ret;