From patchwork Fri Dec 8 10:09:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13485187 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 6D373C4167B for ; Fri, 8 Dec 2023 10:10:13 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TVRGXiNtbUf0ORuz8heCNd9wmXHxTPpu7PW1Pq7IaDQ=; b=LT11CIXuKI+8+F jUZH5YFH917TcwhjRGr3bFdWanZ3pBeN+ryJNseiQ2Us/1hiNcLCO6tQSPXPkqyAjiEaERe7O4tGj VHbQBpZmT92Knb2xNMxC28vUoG44jwS4kLK2km0bfk8R1S5Sef3R3ExgTyJJvJd5kqmWsYmZS5ze4 Dg1luulML2udlnTPbYXCChMApCMezmGICpUxPp0rheFUMJ3SwRkVtJURoffRPMhsKUoCmM1IFtlNC YckPDM5bd2GajwG/W/c4vvuKrcipVeyXXZJUHeMsxfb3WsE36gIH1w7WrBoNm0nAKUlncORJcUAFU 6f1QwZ5QThqJm9uwNCmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rBXnl-00FCfy-33; Fri, 08 Dec 2023 10:09:45 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rBXnf-00FCco-2B for linux-arm-kernel@lists.infradead.org; Fri, 08 Dec 2023 10:09:42 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-50c222a022dso1516357e87.1 for ; Fri, 08 Dec 2023 02:09:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702030178; x=1702634978; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=BQhBLJIefmvzYA/Py58YBQIvfKjKbstgbICKsncNOPs=; b=tRbLZ4/4vP1Bq78ntJ+L1Rzc3h7J0+ggK+t1y5gPWvHPyDzfd6ckgidJd6gWnxAFi5 A4OzaDII5kLOdtv8EdqW+OolanlOGLW9EGuIqkbgvGbJswnGoivuwBxh/2Ry5DZtp/Cd iJepMbdJKeROzJXcRYA+BVmpffOfBaPl+sGPwICxxSm64Iz7ezRTIHMCqS6Ne2jEOTsf HdKMOWN0xRj+8bkH8sP7SQnSp0xoa5N6/TH/9Lnc6jKPYRTsohZ4pvXsJLmiezs/qekm 794Iy5sHdHL0Lk7VnO7p1rr6fEduQLjNGcxDTV6Hq7xn/M0MI1Q24yOgM4VoynLoELyY RuBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702030178; x=1702634978; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BQhBLJIefmvzYA/Py58YBQIvfKjKbstgbICKsncNOPs=; b=GloQ8pk6AqvNLrOJOz13iuHuMOHQj0D/7LFzaIy+Bqyse6OzZ1433JyO23FDbq2Fkr 8TtuzhTQwPiD+8d4mHZBxexhH0NDwZheYF1VMetUOrFP2PzYwpdnEwnbuxhN65B6kBng MQhAWPazi4kXUDqsa5hml83ouhdOWuTV1Wnfe8sRiKofo4OKdsK7jxRqVstXl1MNMpXG s5d5wvatEb6nu9ZDh3v1TktQoJrFtWdPU/Jy8JJ6AqMd/6xZf5Q3ZohD6fGAEB6iuwZ2 fCuB0uTV5rwyMHYTZbCioMwMG4JLr1P2c/csUltiD+0uJ2dyQJyBWTxSvX2JEob+X4ob ikeQ== X-Gm-Message-State: AOJu0YxW4NPr3H4/Ek9QMnswDz8dhz4rKVzfegzSofcmxPe+mn3qOO2V /UUOvGOP8h0rut4aXLFTQui58w== X-Google-Smtp-Source: AGHT+IF3QhztmwDh6phbnNL/MSIHXHVpg1ufEn+gEmm8xgnt7lUT27GO3nRwVTmsFz+TX/dx8idZEQ== X-Received: by 2002:ac2:44ce:0:b0:50b:f380:c3b2 with SMTP id d14-20020ac244ce000000b0050bf380c3b2mr1882935lfm.46.1702030178344; Fri, 08 Dec 2023 02:09:38 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id m4-20020a194344000000b0050bfd7d8873sm174295lfj.254.2023.12.08.02.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 02:09:37 -0800 (PST) From: Linus Walleij Date: Fri, 08 Dec 2023 11:09:29 +0100 Subject: [PATCH 5/5] ASoC: wm8996: Convert to GPIO descriptors MIME-Version: 1.0 Message-Id: <20231208-descriptors-sound-wlf-v1-5-c4dab6f521ec@linaro.org> References: <20231208-descriptors-sound-wlf-v1-0-c4dab6f521ec@linaro.org> In-Reply-To: <20231208-descriptors-sound-wlf-v1-0-c4dab6f521ec@linaro.org> To: Krzysztof Kozlowski , Alim Akhtar , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: patches@opensource.cirrus.com, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sound@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231208_020939_742395_4093ADC6 X-CRM114-Status: GOOD ( 22.64 ) 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 This converts the WM8996 codec to use GPIO descriptors, an a similar way to WM5100. The driver is instantiating a GPIO chip named wm8996, and we get rid of the base address for the GPIO chip from the platform data and just use dynamic numbering. Move base and ngpio into the static gpio_chip template. Fix up the only in-tree user which is the Cragganmore 6410 module. Signed-off-by: Linus Walleij Reviewed-by: Charles Keepax Acked-by: Krzysztof Kozlowski --- arch/arm/mach-s3c/mach-crag6410-module.c | 14 ++++++-- include/sound/wm8996.h | 3 -- sound/soc/codecs/wm8996.c | 58 ++++++++++++++------------------ 3 files changed, 36 insertions(+), 39 deletions(-) diff --git a/arch/arm/mach-s3c/mach-crag6410-module.c b/arch/arm/mach-s3c/mach-crag6410-module.c index 59456fbebf1b..2de1a89f6e99 100644 --- a/arch/arm/mach-s3c/mach-crag6410-module.c +++ b/arch/arm/mach-s3c/mach-crag6410-module.c @@ -127,9 +127,16 @@ static struct wm8996_retune_mobile_config wm8996_retune[] = { }, }; +static struct gpiod_lookup_table wm8996_gpiod_table = { + .dev_id = "1-001a", /* Device 001a on I2C bus 1 */ + .table = { + GPIO_LOOKUP("GPION", 7, + "wlf,ldo1ena", GPIO_ACTIVE_HIGH), + { }, + }, +}; + static struct wm8996_pdata wm8996_pdata __initdata = { - .ldo_ena = S3C64XX_GPN(7), - .gpio_base = CODEC_GPIO_BASE, .micdet_def = 1, .inl_mode = WM8996_DIFFERRENTIAL_1, .inr_mode = WM8996_DIFFERRENTIAL_1, @@ -370,7 +377,8 @@ static const struct { .spi_devs = balblair_devs, .num_spi_devs = ARRAY_SIZE(balblair_devs) }, { .id = 0x39, .rev = 0xff, .name = "1254-EV1 Dallas Dhu", - .i2c_devs = wm1254_devs, .num_i2c_devs = ARRAY_SIZE(wm1254_devs) }, + .i2c_devs = wm1254_devs, .num_i2c_devs = ARRAY_SIZE(wm1254_devs), + .gpiod_table = &wm8996_gpiod_table }, { .id = 0x3a, .rev = 0xff, .name = "1259-EV1 Tobermory", .i2c_devs = wm1259_devs, .num_i2c_devs = ARRAY_SIZE(wm1259_devs) }, { .id = 0x3b, .rev = 0xff, .name = "1255-EV1 Kilchoman", diff --git a/include/sound/wm8996.h b/include/sound/wm8996.h index 247f9917e33d..342abeef288f 100644 --- a/include/sound/wm8996.h +++ b/include/sound/wm8996.h @@ -33,8 +33,6 @@ struct wm8996_retune_mobile_config { struct wm8996_pdata { int irq_flags; /** Set IRQ trigger flags; default active low */ - int ldo_ena; /** GPIO for LDO1; -1 for none */ - int micdet_def; /** Default MICDET_SRC/HP1FB_SRC/MICD_BIAS */ enum wm8996_inmode inl_mode; @@ -42,7 +40,6 @@ struct wm8996_pdata { u32 spkmute_seq; /** Value for register 0x802 */ - int gpio_base; u32 gpio_default[5]; int num_retune_mobile_cfgs; diff --git a/sound/soc/codecs/wm8996.c b/sound/soc/codecs/wm8996.c index df6195778c57..e738326e33ed 100644 --- a/sound/soc/codecs/wm8996.c +++ b/sound/soc/codecs/wm8996.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -51,7 +51,7 @@ struct wm8996_priv { struct regmap *regmap; struct snd_soc_component *component; - int ldo1ena; + struct gpio_desc *ldo_ena; int sysclk; int sysclk_src; @@ -1596,9 +1596,9 @@ static int wm8996_set_bias_level(struct snd_soc_component *component, return ret; } - if (wm8996->pdata.ldo_ena >= 0) { - gpio_set_value_cansleep(wm8996->pdata.ldo_ena, - 1); + if (wm8996->ldo_ena) { + gpiod_set_value_cansleep(wm8996->ldo_ena, + 1); msleep(5); } @@ -1615,8 +1615,8 @@ static int wm8996_set_bias_level(struct snd_soc_component *component, case SND_SOC_BIAS_OFF: regcache_cache_only(wm8996->regmap, true); - if (wm8996->pdata.ldo_ena >= 0) { - gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0); + if (wm8996->ldo_ena) { + gpiod_set_value_cansleep(wm8996->ldo_ena, 0); regcache_cache_only(wm8996->regmap, true); } regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies), @@ -2188,6 +2188,8 @@ static const struct gpio_chip wm8996_template_chip = { .direction_input = wm8996_gpio_direction_in, .get = wm8996_gpio_get, .can_sleep = 1, + .ngpio = 5, + .base = -1, }; static void wm8996_init_gpio(struct wm8996_priv *wm8996) @@ -2195,14 +2197,8 @@ static void wm8996_init_gpio(struct wm8996_priv *wm8996) int ret; wm8996->gpio_chip = wm8996_template_chip; - wm8996->gpio_chip.ngpio = 5; wm8996->gpio_chip.parent = wm8996->dev; - if (wm8996->pdata.gpio_base) - wm8996->gpio_chip.base = wm8996->pdata.gpio_base; - else - wm8996->gpio_chip.base = -1; - ret = gpiochip_add_data(&wm8996->gpio_chip, wm8996); if (ret != 0) dev_err(wm8996->dev, "Failed to add GPIOs: %d\n", ret); @@ -2771,15 +2767,15 @@ static int wm8996_i2c_probe(struct i2c_client *i2c) memcpy(&wm8996->pdata, dev_get_platdata(&i2c->dev), sizeof(wm8996->pdata)); - if (wm8996->pdata.ldo_ena > 0) { - ret = gpio_request_one(wm8996->pdata.ldo_ena, - GPIOF_OUT_INIT_LOW, "WM8996 ENA"); - if (ret < 0) { - dev_err(&i2c->dev, "Failed to request GPIO %d: %d\n", - wm8996->pdata.ldo_ena, ret); - goto err; - } + wm8996->ldo_ena = devm_gpiod_get_optional(&i2c->dev, "wlf,ldo1ena", + GPIOD_OUT_LOW); + if (IS_ERR(wm8996->ldo_ena)) { + ret = PTR_ERR(wm8996->ldo_ena); + dev_err(&i2c->dev, "Failed to request LDO ENA GPIO: %d\n", + ret); + goto err; } + gpiod_set_consumer_name(wm8996->ldo_ena, "WM8996 ENA"); for (i = 0; i < ARRAY_SIZE(wm8996->supplies); i++) wm8996->supplies[i].supply = wm8996_supply_names[i]; @@ -2814,8 +2810,8 @@ static int wm8996_i2c_probe(struct i2c_client *i2c) goto err_gpio; } - if (wm8996->pdata.ldo_ena > 0) { - gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 1); + if (wm8996->ldo_ena) { + gpiod_set_value_cansleep(wm8996->ldo_ena, 1); msleep(5); } @@ -2847,8 +2843,8 @@ static int wm8996_i2c_probe(struct i2c_client *i2c) dev_info(&i2c->dev, "revision %c\n", (reg & WM8996_CHIP_REV_MASK) + 'A'); - if (wm8996->pdata.ldo_ena > 0) { - gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0); + if (wm8996->ldo_ena) { + gpiod_set_value_cansleep(wm8996->ldo_ena, 0); regcache_cache_only(wm8996->regmap, true); } else { ret = regmap_write(wm8996->regmap, WM8996_SOFTWARE_RESET, @@ -3054,12 +3050,10 @@ static int wm8996_i2c_probe(struct i2c_client *i2c) wm8996_free_gpio(wm8996); err_regmap: err_enable: - if (wm8996->pdata.ldo_ena > 0) - gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0); + if (wm8996->ldo_ena) + gpiod_set_value_cansleep(wm8996->ldo_ena, 0); regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies), wm8996->supplies); err_gpio: - if (wm8996->pdata.ldo_ena > 0) - gpio_free(wm8996->pdata.ldo_ena); err: return ret; @@ -3070,10 +3064,8 @@ static void wm8996_i2c_remove(struct i2c_client *client) struct wm8996_priv *wm8996 = i2c_get_clientdata(client); wm8996_free_gpio(wm8996); - if (wm8996->pdata.ldo_ena > 0) { - gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0); - gpio_free(wm8996->pdata.ldo_ena); - } + if (wm8996->ldo_ena) + gpiod_set_value_cansleep(wm8996->ldo_ena, 0); } static const struct i2c_device_id wm8996_i2c_id[] = {