From patchwork Mon Nov 20 10:41:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Strozek X-Patchwork-Id: 167035 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp2109777vqn; Mon, 20 Nov 2023 02:43:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5Ip00MPjCTh08LixAxz2BJVraesAa7VvLUBtBae3NB/wG8qaSSrZ6vu1qqF/cR0fAt+LR X-Received: by 2002:a05:6808:1783:b0:3b2:e27e:ac9d with SMTP id bg3-20020a056808178300b003b2e27eac9dmr8973709oib.50.1700477015220; Mon, 20 Nov 2023 02:43:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700477015; cv=none; d=google.com; s=arc-20160816; b=lyjduoA/SlFXJ7mqO55ox/ZuRhNpzBUq9TWkVOYkpFoii2NhWrfbzmP90+ohkmKei7 tjALWg2KLJRZRRHZ53wT5VsRBM8Qi8r4Fn/uoWIbPdHLcKtp8ZVuP06XI10vaerNPYwX 28Kf6E6GxSoZH4ddiLczszbSwtuLCb29RcnhrFwCzYZz/+lsZ3pxikZVwS64sVCvHbSu vVBn1UJ2zJusCceHQzQXMv3BzMDZ6jUz374rKsX/htdNqTLvbFIeHaqB8PCns/o8Ot/Z KShTWRiuc1NGrcaxdzQ92IXro7GTDZ6Hu/OVnaWV53LfJ9kuElVWSTvGt8PT5LRcBBKw ceqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=QnKDSoljUFXrzRR/u1NiJJkj1yGGpZS1WlDMjC/Kvsk=; fh=KySyJaCx6e9HlRw2D2oLQPSdTHBwZsIBeFoG7LcS+QY=; b=ewGE608DjsHos/yP6ZZSvZyYVIhyqOu3LdTad1cNBJYwxDoiVR/xIdBiTUiklU+Z1S wTkYXgV5Q1hIiyB9E8eP+PXEQG81iv6Ed9Uz/F47/GWUyeAMD6Iw7Gzacb7e8OM2aADe r4aH5Fm7XAaNAl8yzht7nokzQjGsjfLXhHUNcUovE3RwOxX2tMs8uZrrNMQmsudRDMBf yMXJI+3cpyz7yvI4G7bLoJP/BnWr/khEjhHj0KXorCAByUbKlZGuTGxjvtKY6QJ9yWmZ kyBeoHuEtcCsDTvnhqIqcx0heCxCjgqdpNdLmLZVGbXwWYJFlSgqz9gaBrYt2QDcwCat kGfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b="BTJQ//Ak"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id x3-20020a636303000000b005be0028c5easi7847687pgb.401.2023.11.20.02.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 02:43:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b="BTJQ//Ak"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 691CD8046BF1; Mon, 20 Nov 2023 02:43:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232775AbjKTKnI (ORCPT + 27 others); Mon, 20 Nov 2023 05:43:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232744AbjKTKmn (ORCPT ); Mon, 20 Nov 2023 05:42:43 -0500 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1829D9; Mon, 20 Nov 2023 02:42:33 -0800 (PST) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 3AK6oXQc014560; Mon, 20 Nov 2023 04:42:26 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=PODMain02222019; bh=Q nKDSoljUFXrzRR/u1NiJJkj1yGGpZS1WlDMjC/Kvsk=; b=BTJQ//Ak1jfYU35qu JPOEtG+wP9BFBc2BKoVfv6c5jrvLIumuBvTUwWCi+sF2yfHurXrEEv0+7HQ49E69 8EEtLsYjR0ozlKBBMFu1X82IzvVx/bUhe1hiiaHPbvO0Hg9/a533TWJ1tguHT95X d/gYp7mlbQh5BcW2ySIWoarmM5iJU78UyvC/wEHIbSOy7txtDn70iWt9okD5P+nV Gay9Wsjs3Wu7XIFbEv7nKSO2idp4dBlH3Gk39zD0jAq0c2z+/u8bc2/YHOQUquiT IJxFcS4cUKzRNq6tSCAjQnB0Pg3wm5zQnEAIev2IbmAY4ptkbkilyBY10MomVDP+ fQMsA== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3ueuj29p3x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Nov 2023 04:42:25 -0600 (CST) Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Mon, 20 Nov 2023 10:42:23 +0000 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.39 via Frontend Transport; Mon, 20 Nov 2023 10:42:23 +0000 Received: from upx-tgl-008-ubuntu.ad.cirrus.com (upx-tgl-008-ubuntu.ad.cirrus.com [198.90.251.167]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 978A6B12; Mon, 20 Nov 2023 10:42:23 +0000 (UTC) From: Maciej Strozek To: Mark Brown CC: James Schulman , David Rhodes , Liam Girdwood , , , , , Maciej Strozek Subject: [PATCH v2 6/7] ASoC: cs43130: Allow driver to work without IRQ thread Date: Mon, 20 Nov 2023 10:41:53 +0000 Message-ID: <20231120104153.76248-1-mstrozek@opensource.cirrus.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: jZqzVRSxffeY3nz0j56nbOsuMT_4BWL9 X-Proofpoint-GUID: jZqzVRSxffeY3nz0j56nbOsuMT_4BWL9 X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 20 Nov 2023 02:43:30 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783079386586218913 X-GMAIL-MSGID: 1783079386586218913 This is to support systems without physical IRQ connection. The device only requires the IRQ for a couple of internal delays, this polling mechanism is a fallback when no IRQ is specified. Signed-off-by: Maciej Strozek --- V1 -> V2: Add changelog message sound/soc/codecs/cs43130.c | 56 +++++++++++++++++++++++++++++++------- sound/soc/codecs/cs43130.h | 1 + 2 files changed, 47 insertions(+), 10 deletions(-) -- 2.34.1 diff --git a/sound/soc/codecs/cs43130.c b/sound/soc/codecs/cs43130.c index fd39328579fb..1e7c32eedc7b 100644 --- a/sound/soc/codecs/cs43130.c +++ b/sound/soc/codecs/cs43130.c @@ -326,6 +326,43 @@ static int cs43130_set_pll(struct snd_soc_component *component, int pll_id, int return ret; } +static int cs43130_wait_for_completion(struct cs43130_private *cs43130, struct completion *to_poll, + int time) +{ + int stickies, offset, flag; + int ret = 0; + + if (cs43130->has_irq_line) { + ret = wait_for_completion_timeout(to_poll, msecs_to_jiffies(time)); + } else { + if (to_poll == &cs43130->xtal_rdy) { + offset = 0; + flag = CS43130_XTAL_RDY_INT; + } else if (to_poll == &cs43130->pll_rdy) { + offset = 0; + flag = CS43130_PLL_RDY_INT; + } else if (to_poll == &cs43130->hpload_evt) { + offset = 3; + flag = CS43130_HPLOAD_NO_DC_INT | CS43130_HPLOAD_UNPLUG_INT | + CS43130_HPLOAD_OOR_INT | CS43130_HPLOAD_AC_INT | + CS43130_HPLOAD_DC_INT | CS43130_HPLOAD_ON_INT | + CS43130_HPLOAD_OFF_INT; + } else { + return 0; + } + + ret = regmap_read_poll_timeout(cs43130->regmap, CS43130_INT_STATUS_1 + offset, + stickies, (stickies & flag), + 1000, time * 1000); + + /* + * Return 0 for an timeout/error to be consistent with wait_for_completion_timeout + */ + ret = !ret; + } + return ret; +} + static int cs43130_change_clksrc(struct snd_soc_component *component, enum cs43130_mclk_src_sel src) { @@ -364,8 +401,7 @@ static int cs43130_change_clksrc(struct snd_soc_component *component, CS43130_XTAL_RDY_INT_MASK, 0); regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL, CS43130_PDN_XTAL_MASK, 0); - ret = wait_for_completion_timeout(&cs43130->xtal_rdy, - msecs_to_jiffies(100)); + ret = cs43130_wait_for_completion(cs43130, &cs43130->xtal_rdy, 100); regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1, CS43130_XTAL_RDY_INT_MASK, 1 << CS43130_XTAL_RDY_INT_SHIFT); @@ -400,8 +436,7 @@ static int cs43130_change_clksrc(struct snd_soc_component *component, CS43130_XTAL_RDY_INT_MASK, 0); regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL, CS43130_PDN_XTAL_MASK, 0); - ret = wait_for_completion_timeout(&cs43130->xtal_rdy, - msecs_to_jiffies(100)); + ret = cs43130_wait_for_completion(cs43130, &cs43130->xtal_rdy, 100); regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1, CS43130_XTAL_RDY_INT_MASK, 1 << CS43130_XTAL_RDY_INT_SHIFT); @@ -416,8 +451,7 @@ static int cs43130_change_clksrc(struct snd_soc_component *component, CS43130_PLL_RDY_INT_MASK, 0); regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL, CS43130_PDN_PLL_MASK, 0); - ret = wait_for_completion_timeout(&cs43130->pll_rdy, - msecs_to_jiffies(100)); + ret = cs43130_wait_for_completion(cs43130, &cs43130->pll_rdy, 100); regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1, CS43130_PLL_RDY_INT_MASK, 1 << CS43130_PLL_RDY_INT_SHIFT); @@ -2040,8 +2074,8 @@ static int cs43130_hpload_proc(struct cs43130_private *cs43130, regmap_multi_reg_write(cs43130->regmap, seq, seq_size); - ret = wait_for_completion_timeout(&cs43130->hpload_evt, - msecs_to_jiffies(1000)); + ret = cs43130_wait_for_completion(cs43130, &cs43130->hpload_evt, 1000); + regmap_read(cs43130->regmap, CS43130_INT_MASK_4, &msk); if (!ret) { dev_err(cs43130->dev, "Timeout waiting for HPLOAD interrupt\n"); @@ -2545,8 +2579,10 @@ static int cs43130_i2c_probe(struct i2c_client *client) IRQF_ONESHOT | IRQF_TRIGGER_LOW, "cs43130", cs43130); if (ret != 0) { - dev_err(cs43130->dev, "Failed to request IRQ: %d\n", ret); - goto err; + dev_dbg(cs43130->dev, "Failed to request IRQ: %d, will poll instead\n", ret); + cs43130->has_irq_line = 0; + } else { + cs43130->has_irq_line = 1; } cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO; diff --git a/sound/soc/codecs/cs43130.h b/sound/soc/codecs/cs43130.h index d3f595bbd3ba..dbdb5b262f1b 100644 --- a/sound/soc/codecs/cs43130.h +++ b/sound/soc/codecs/cs43130.h @@ -508,6 +508,7 @@ struct cs43130_private { struct gpio_desc *reset_gpio; unsigned int dev_id; /* codec device ID */ int xtal_ibias; + bool has_irq_line; /* shared by both DAIs */ struct mutex clk_mutex;