get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/1.1/patches/2230086/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2230086,
    "url": "http://patchwork.ozlabs.org/api/1.1/patches/2230086/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/linux-gpio/patch/20260429074356.118420-15-herve.codina@bootlin.com/",
    "project": {
        "id": 42,
        "url": "http://patchwork.ozlabs.org/api/1.1/projects/42/?format=api",
        "name": "Linux GPIO development",
        "link_name": "linux-gpio",
        "list_id": "linux-gpio.vger.kernel.org",
        "list_email": "linux-gpio@vger.kernel.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20260429074356.118420-15-herve.codina@bootlin.com>",
    "date": "2026-04-29T07:43:50",
    "name": "[v2,14/17] ASoC: simple-amplifier: gpio-audio-amp: Add support for gain-ranges",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "42594bb7ce60fc1f4a58469f0258ee5d69275046",
    "submitter": {
        "id": 81983,
        "url": "http://patchwork.ozlabs.org/api/1.1/people/81983/?format=api",
        "name": "Herve Codina",
        "email": "herve.codina@bootlin.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/linux-gpio/patch/20260429074356.118420-15-herve.codina@bootlin.com/mbox/",
    "series": [
        {
            "id": 502009,
            "url": "http://patchwork.ozlabs.org/api/1.1/series/502009/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/linux-gpio/list/?series=502009",
            "date": "2026-04-29T07:43:41",
            "name": "ASoC: Add support for GPIOs driven amplifiers",
            "version": 2,
            "mbox": "http://patchwork.ozlabs.org/series/502009/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2230086/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2230086/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "\n <linux-gpio+bounces-35771-incoming=patchwork.ozlabs.org@vger.kernel.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "linux-gpio@vger.kernel.org"
        ],
        "Delivered-To": "patchwork-incoming@legolas.ozlabs.org",
        "Authentication-Results": [
            "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256\n header.s=dkim header.b=hlMwPf7d;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c09:e001:a7::12fc:5321; helo=sto.lore.kernel.org;\n envelope-from=linux-gpio+bounces-35771-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)",
            "smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com\n header.b=\"hlMwPf7d\"",
            "smtp.subspace.kernel.org;\n arc=none smtp.client-ip=185.246.84.56",
            "smtp.subspace.kernel.org;\n dmarc=pass (p=reject dis=none) header.from=bootlin.com",
            "smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=bootlin.com"
        ],
        "Received": [
            "from sto.lore.kernel.org (sto.lore.kernel.org\n [IPv6:2600:3c09:e001:a7::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g58Xy2S3Xz1yHv\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 17:47:46 +1000 (AEST)",
            "from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sto.lore.kernel.org (Postfix) with ESMTP id 6F14330207AF\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 07:46:07 +0000 (UTC)",
            "from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id ED84F3BA25C;\n\tWed, 29 Apr 2026 07:44:52 +0000 (UTC)",
            "from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id AA31D3BAD88;\n\tWed, 29 Apr 2026 07:44:49 +0000 (UTC)",
            "from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233])\n\tby smtpout-02.galae.net (Postfix) with ESMTPS id 5DEC31A347A;\n\tWed, 29 Apr 2026 07:44:48 +0000 (UTC)",
            "from mail.galae.net (mail.galae.net [212.83.136.155])\n\tby smtpout-01.galae.net (Postfix) with ESMTPS id 32FA1601DF;\n\tWed, 29 Apr 2026 07:44:48 +0000 (UTC)",
            "from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon)\n with ESMTPSA id DB8E91072989F;\n\tWed, 29 Apr 2026 09:44:44 +0200 (CEST)"
        ],
        "ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777448692; cv=none;\n b=YQnwSXTyF5SwtKj7DJnNsUP+QisNiHe7B1AIFwSYYhjGfpcppMKe/2tCcAIQ0dj+imBHxKH8S3Pcvk6ZTFZl9OFag00na+Enljzodes9ZRrOrznPeSnzy+E1kGmAFGUbML+Mt/qRdVeJMQAFeiNxbZAfGHA0AB397YgL9tsZFq4=",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777448692; c=relaxed/simple;\n\tbh=c54ycmmXNL7RxkCfzxWn0i8aq65sjwGiQUFNX+2OQc4=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=gZmaHQDNmArj+wuQykFsBTqC8+pMxPrRSuxUC7vQqrPwukX2kEGyJr1co8KNC4JEuBT4JUNsduYAY1B37OWZUKWmqevafCsH8Zz8vi/sIHxiMDe2r/qVQMWPcAT7a0Fj13FBJfTJv9GnQtONVZcWi4u24K+0Vjj/7phsntKs3tw=",
        "ARC-Authentication-Results": "i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=reject dis=none) header.from=bootlin.com;\n spf=pass smtp.mailfrom=bootlin.com;\n dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com\n header.b=hlMwPf7d; arc=none smtp.client-ip=185.246.84.56",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim;\n\tt=1777448687; h=from:subject:date:message-id:to:cc:mime-version:\n\t content-transfer-encoding:in-reply-to:references;\n\tbh=3G44daaR6HwKqj68j84FK3yKhXwmvmSMQaPXApsQR/4=;\n\tb=hlMwPf7dwECvlQTBLo/FhK1gUjmiq8mx7esMjGjIH2jHjo7BvEYB8XrIT17/Kq4iQLH7Vz\n\tmeu5Zq4o56jak1sN44iLh8HLvWKiNr40hBg8yAGaCn52W0H8eh7qIA7sglcWfGbDtPQ7Yn\n\tY6gdc+LMfMMObqWjAX90UFoqL3iZNS7STt8KJt05LHNh6rxcdlLB48GaXDNZCG0ad5XcDw\n\tWtGFUinknqRcYlCpxkz6wQIEsNcFZmznjaD+DIJG08W5jx17tr5iTlg9Uw5n21QEv9ROvL\n\tSr5c2zSn1v4PYFQ5L75zmiPQRoOf2+gvgQlRfchex9CSBY/YG5kkVS+OYaaJfA==",
        "From": "Herve Codina <herve.codina@bootlin.com>",
        "To": "Herve Codina <herve.codina@bootlin.com>,\n\tBartosz Golaszewski <brgl@kernel.org>,\n\tLinus Walleij <linusw@kernel.org>,\n\tLiam Girdwood <lgirdwood@gmail.com>,\n\tMark Brown <broonie@kernel.org>,\n\tRob Herring <robh@kernel.org>,\n\tKrzysztof Kozlowski <krzk+dt@kernel.org>,\n\tConor Dooley <conor+dt@kernel.org>,\n\tSaravana Kannan <saravanak@kernel.org>,\n\tJaroslav Kysela <perex@perex.cz>,\n\tTakashi Iwai <tiwai@suse.com>",
        "Cc": "linux-sound@vger.kernel.org,\n\tlinux-gpio@vger.kernel.org,\n\tdevicetree@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\tChristophe Leroy <christophe.leroy@csgroup.eu>,\n\tThomas Petazzoni <thomas.petazzoni@bootlin.com>",
        "Subject": "[PATCH v2 14/17] ASoC: simple-amplifier: gpio-audio-amp: Add support\n for gain-ranges",
        "Date": "Wed, 29 Apr 2026 09:43:50 +0200",
        "Message-ID": "<20260429074356.118420-15-herve.codina@bootlin.com>",
        "X-Mailer": "git-send-email 2.53.0",
        "In-Reply-To": "<20260429074356.118420-1-herve.codina@bootlin.com>",
        "References": "<20260429074356.118420-1-herve.codina@bootlin.com>",
        "Precedence": "bulk",
        "X-Mailing-List": "linux-gpio@vger.kernel.org",
        "List-Id": "<linux-gpio.vger.kernel.org>",
        "List-Subscribe": "<mailto:linux-gpio+subscribe@vger.kernel.org>",
        "List-Unsubscribe": "<mailto:linux-gpio+unsubscribe@vger.kernel.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-Last-TLS-Session-Version": "TLSv1.3"
    },
    "content": "The mapping between physical gain values and gpio values can be\nexpressed using ranges described in the gain-ranges property.\n\nThis gain-ranges property is an array of ranges.\n\nEach range in the array is defined by the first point and last point in\nthe range. Those points are a pair of values, the gpios value and the\nrelated gain (dB) value.\n\nWith that, a given range defines N possible items (from the first point\ngpios value to the last point gpios value) in order to set a gain from\nthe first point gain value to the last point gain value.\n\nHandle this description and the related kcontrol.\n\nSigned-off-by: Herve Codina <herve.codina@bootlin.com>\n---\n sound/soc/codecs/simple-amplifier.c | 310 +++++++++++++++++++++++++++-\n 1 file changed, 305 insertions(+), 5 deletions(-)",
    "diff": "diff --git a/sound/soc/codecs/simple-amplifier.c b/sound/soc/codecs/simple-amplifier.c\nindex 4f4a3c10f883..b25332a76549 100644\n--- a/sound/soc/codecs/simple-amplifier.c\n+++ b/sound/soc/codecs/simple-amplifier.c\n@@ -7,11 +7,16 @@\n #include <linux/bitmap.h>\n #include <linux/bits.h>\n #include <linux/gpio/consumer.h>\n+#include <linux/math.h>\n+#include <linux/minmax.h>\n #include <linux/mod_devicetable.h>\n #include <linux/module.h>\n #include <linux/platform_device.h>\n #include <linux/regulator/consumer.h>\n+#include <linux/slab.h>\n #include <sound/soc.h>\n+#include <linux/sort.h>\n+#include <sound/tlv.h>\n \n struct simple_amp_single {\n \tstruct gpio_desc *gpio;\n@@ -20,11 +25,35 @@ struct simple_amp_single {\n \tconst char *control_name;\n };\n \n+struct simple_amp_point {\n+\tu32 gpio_val;\n+\tint gain_db;\n+};\n+\n+struct simple_amp_range {\n+\tunsigned int nb_points;\n+\tstruct simple_amp_point min;\n+\tstruct simple_amp_point max;\n+};\n+\n+struct simple_amp_ranges {\n+\tunsigned int nb_ranges;\n+\tstruct simple_amp_range *tab_ranges;\n+};\n+\n+enum simple_amp_mode {\n+\tSIMPLE_AMP_MODE_NONE,\n+\tSIMPLE_AMP_MODE_RANGES,\n+};\n+\n struct simple_amp_multi {\n \tstruct gpio_descs *gpios;\n \tu32 kctrl_val;\n \tu32 kctrl_max;\n \tconst char *control_name;\n+\tunsigned int *tlv_array;\n+\tenum simple_amp_mode mode;\n+\tstruct simple_amp_ranges ranges;\n };\n \n struct simple_amp_data {\n@@ -195,6 +224,32 @@ static int simple_amp_single_add_kcontrol(struct snd_soc_component *component,\n \treturn snd_soc_add_component_controls(component, &control, 1);\n }\n \n+static u32 simple_amp_multi_ranges_kctrl_to_gpio(u32 kctrl_val,\n+\t\t\t\t\t\t struct simple_amp_ranges *ranges)\n+{\n+\tstruct simple_amp_range *range;\n+\tu32 index = kctrl_val;\n+\tunsigned int i;\n+\n+\tfor (i = 0; i < ranges->nb_ranges; i++) {\n+\t\trange = &ranges->tab_ranges[i];\n+\n+\t\tif (index < range->nb_points)\n+\t\t\treturn (range->max.gpio_val >= range->min.gpio_val) ?\n+\t\t\t\trange->min.gpio_val + index :\n+\t\t\t\trange->min.gpio_val - index;\n+\n+\t\tindex -= range->nb_points;\n+\t}\n+\n+\t/*\n+\t * Given index out of possible ranges. This is shouldn't happen.\n+\t * Signal the issue and return the maximum value\n+\t */\n+\tWARN(1, \"kctrl_val %u out of ranges\\n\", kctrl_val);\n+\treturn ranges->tab_ranges[ranges->nb_ranges - 1].max.gpio_val;\n+}\n+\n static int simple_amp_multi_kctrl_write_gpios(struct simple_amp_multi *multi,\n \t\t\t\t\t      u32 kctrl_val)\n {\n@@ -204,7 +259,12 @@ static int simple_amp_multi_kctrl_write_gpios(struct simple_amp_multi *multi,\n \tif (kctrl_val > multi->kctrl_max)\n \t\treturn -EINVAL;\n \n-\tgpio_val = kctrl_val;\n+\tif (multi->mode == SIMPLE_AMP_MODE_RANGES)\n+\t\tgpio_val = simple_amp_multi_ranges_kctrl_to_gpio(kctrl_val,\n+\t\t\t\t\t\t\t\t &multi->ranges);\n+\telse\n+\t\tgpio_val = kctrl_val;\n+\n \tbitmap_from_arr32(bm, &gpio_val, multi->gpios->ndescs);\n \n \treturn gpiod_multi_set_value_cansleep(multi->gpios, bm);\n@@ -252,6 +312,38 @@ static int simple_amp_multi_kctrl_int_put(struct snd_kcontrol *kcontrol,\n \treturn 1; /* The value changed */\n }\n \n+static int *simple_amp_alloc_tlv_ranges(const struct simple_amp_ranges *ranges)\n+{\n+\tunsigned int index;\n+\tunsigned int *tlv;\n+\tunsigned int *t;\n+\tunsigned int i;\n+\n+\ttlv = kzalloc_objs(*tlv, 2 + ranges->nb_ranges * 6, GFP_KERNEL);\n+\tif (!tlv)\n+\t\treturn NULL;\n+\n+\tt = tlv;\n+\n+\t/* Fill first TLV */\n+\t*t++ = SNDRV_CTL_TLVT_DB_RANGE; /* Tag */\n+\t*t++ = ranges->nb_ranges * 6 * sizeof(*tlv); /* Len */\n+\t/* Ranges are sorted from lower to higher value */\n+\tindex = 0;\n+\tfor (i = 0; i < ranges->nb_ranges; i++) {\n+\t\t/* Fill range item i */\n+\t\t*t++ = index;  /* min */\n+\t\tindex += ranges->tab_ranges[i].nb_points;\n+\t\t*t++ = index - 1;  /* max */\n+\t\t*t++ = SNDRV_CTL_TLVT_DB_MINMAX; /* Tag */\n+\t\t*t++ = 2 * sizeof(*tlv); /* Len */\n+\t\t*t++ = ranges->tab_ranges[i].min.gain_db; /* min_dB */\n+\t\t*t++ = ranges->tab_ranges[i].max.gain_db; /* max_dB */\n+\t}\n+\n+\treturn tlv;\n+}\n+\n static int simple_amp_multi_add_kcontrol(struct snd_soc_component *component,\n \t\t\t\t\t struct simple_amp_multi *multi)\n {\n@@ -265,12 +357,39 @@ static int simple_amp_multi_add_kcontrol(struct snd_soc_component *component,\n \t};\n \tint ret;\n \n+\tswitch (multi->mode) {\n+\tcase SIMPLE_AMP_MODE_RANGES:\n+\t\tmulti->tlv_array = simple_amp_alloc_tlv_ranges(&multi->ranges);\n+\t\tif (!multi->tlv_array)\n+\t\t\treturn -ENOMEM;\n+\n+\t\tcontrol.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\n+\t\t\t\t SNDRV_CTL_ELEM_ACCESS_READWRITE;\n+\t\tcontrol.tlv.p = multi->tlv_array;\n+\t\tbreak;\n+\n+\tcase SIMPLE_AMP_MODE_NONE:\n+\t\t/* Already set control configuration is enough */\n+\t\tbreak;\n+\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n \t/* Be consistent between multi->kctrl_val value and the GPIOs value */\n \tret = simple_amp_multi_kctrl_write_gpios(multi, multi->kctrl_val);\n \tif (ret)\n-\t\treturn ret;\n+\t\tgoto err_free_tlv_array;\n \n-\treturn snd_soc_add_component_controls(component, &control, 1);\n+\tret = snd_soc_add_component_controls(component, &control, 1);\n+\tif (ret)\n+\t\tgoto err_free_tlv_array;\n+\n+\treturn 0;\n+\n+err_free_tlv_array:\n+\tkfree(multi->tlv_array);\n+\treturn ret;\n }\n \n static int simple_amp_add_basic_dapm(struct snd_soc_component *component)\n@@ -407,8 +526,17 @@ static int simple_amp_component_probe(struct snd_soc_component *component)\n \treturn 0;\n }\n \n+static void simple_amp_component_remove(struct snd_soc_component *component)\n+{\n+\tstruct simple_amp *simple_amp = snd_soc_component_get_drvdata(component);\n+\n+\tkfree(simple_amp->gain.tlv_array);\n+\tsimple_amp->gain.tlv_array = NULL;\n+}\n+\n static const struct snd_soc_component_driver simple_amp_component_driver = {\n \t.probe = simple_amp_component_probe,\n+\t.remove = simple_amp_component_remove,\n };\n \n static int simple_amp_parse_single_gpio(struct device *dev,\n@@ -426,10 +554,172 @@ static int simple_amp_parse_single_gpio(struct device *dev,\n \treturn 0;\n }\n \n+static int simple_amp_cmp_ranges(const void *a, const void *b)\n+{\n+\tconst struct simple_amp_range *a_range = a;\n+\tconst struct simple_amp_range *b_range = b;\n+\n+\t/* Ranges a and b don't overlap. This has been already checked */\n+\n+\treturn a_range->min.gain_db - b_range->max.gain_db;\n+}\n+\n+static int simple_amp_check_new_range(const struct simple_amp_range *new_range,\n+\t\t\t\t      const struct simple_amp_range *tab_ranges,\n+\t\t\t\t      unsigned int nb_ranges)\n+{\n+\tunsigned int i;\n+\n+\tfor (i = 0; i < nb_ranges; i++) {\n+\t\t/* Check for range overlaps */\n+\t\tif (new_range->min.gain_db >= tab_ranges[i].min.gain_db &&\n+\t\t    new_range->min.gain_db <= tab_ranges[i].max.gain_db)\n+\t\t\treturn -EINVAL;\n+\n+\t\tif (new_range->max.gain_db >= tab_ranges[i].min.gain_db &&\n+\t\t    new_range->max.gain_db <= tab_ranges[i].max.gain_db)\n+\t\t\treturn -EINVAL;\n+\t}\n+\treturn 0;\n+}\n+\n+static int simple_amp_parse_ranges(struct device *dev,\n+\t\t\t\t   struct simple_amp_multi *multi,\n+\t\t\t\t   const char *ranges_property)\n+{\n+\tstruct simple_amp_ranges *ranges = &multi->ranges;\n+\tstruct simple_amp_range *range;\n+\tstruct device_node *np = dev->of_node;\n+\tstruct simple_amp_point first_point;\n+\tunsigned int max_gpio_val;\n+\tunsigned int i;\n+\tint ret;\n+\tu32 u;\n+\ts32 s;\n+\n+\tmax_gpio_val = (1 << multi->gpios->ndescs) - 1;\n+\n+\tret = of_property_count_u32_elems(np, ranges_property);\n+\tif (ret <= 0)\n+\t\treturn ret;\n+\n+\t/*\n+\t * One range item is composed of 2 points and each point is composed of\n+\t * 2 values.\n+\t */\n+\tif (ret % 4)\n+\t\treturn -EINVAL;\n+\n+\tranges->nb_ranges = ret / 4;\n+\n+\t/* The worst case is one range per possible gpio value */\n+\tif (ranges->nb_ranges > max_gpio_val + 1)\n+\t\treturn -EINVAL;\n+\n+\tranges->tab_ranges = devm_kcalloc(dev, ranges->nb_ranges,\n+\t\t\t\t\t  sizeof(*ranges->tab_ranges),\n+\t\t\t\t\t  GFP_KERNEL);\n+\tif (!ranges->tab_ranges)\n+\t\treturn -ENOMEM;\n+\n+\tmulti->kctrl_max = 0;\n+\tfor (i = 0; i < ranges->nb_ranges; i++) {\n+\t\trange = &ranges->tab_ranges[i];\n+\n+\t\t/* First gpios value */\n+\t\tret = of_property_read_u32_index(np, ranges_property, i * 4, &u);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t\tif (u > max_gpio_val)\n+\t\t\treturn -EINVAL;\n+\n+\t\trange->min.gpio_val = u;\n+\n+\t\t/* First Gain value */\n+\t\tret = of_property_read_s32_index(np, ranges_property, i * 4 + 1, &s);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\trange->min.gain_db = s;\n+\n+\t\t/* Second gpios value */\n+\t\tret = of_property_read_u32_index(np, ranges_property, i * 4 + 2, &u);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t\tif (u > max_gpio_val)\n+\t\t\treturn -EINVAL;\n+\n+\t\trange->max.gpio_val = u;\n+\n+\t\t/* Second Gain value */\n+\t\tret = of_property_read_s32_index(np, ranges_property, i * 4 + 3, &s);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\trange->max.gain_db = s;\n+\n+\t\t/* Save the first point for later usage */\n+\t\tif (i == 0)\n+\t\t\tfirst_point = range->min;\n+\n+\t\t/* Fix min and max if needed */\n+\t\tif (range->min.gain_db > range->max.gain_db)\n+\t\t\tswap(range->min, range->max);\n+\n+\t\tret = simple_amp_check_new_range(range, ranges->tab_ranges, i);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\trange->nb_points = abs_diff(range->min.gpio_val,\n+\t\t\t\t\t    range->max.gpio_val) + 1;\n+\n+\t\tmulti->kctrl_max += range->nb_points;\n+\t}\n+\n+\tmulti->kctrl_max -= 1;\n+\n+\t/* Sort the tab_range array by gain_db value */\n+\tsort(ranges->tab_ranges, ranges->nb_ranges, sizeof(*ranges->tab_ranges),\n+\t     simple_amp_cmp_ranges, NULL);\n+\n+\t/*\n+\t * multi->kctrl_val is the index in tab_ranges.\n+\t *\n+\t * Choose to have the initial amplification value set to the first point\n+\t * available in the first range available in the tab_ranges array before\n+\t * sorting.\n+\t *\n+\t * This first point has been identified before sorting. Search for it in\n+\t * the sorted array in order to set the multi->kctrl_val initial value.\n+\t */\n+\tmulti->kctrl_val = 0;\n+\tfor (i = 0; i < ranges->nb_ranges; i++) {\n+\t\trange = &ranges->tab_ranges[i];\n+\n+\t\tif (range->min.gpio_val == first_point.gpio_val &&\n+\t\t    range->min.gain_db == first_point.gain_db)\n+\t\t\tbreak;\n+\n+\t\tmulti->kctrl_val += range->nb_points;\n+\n+\t\tif (range->max.gpio_val == first_point.gpio_val &&\n+\t\t    range->max.gain_db == first_point.gain_db) {\n+\t\t\tmulti->kctrl_val--;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n static int simple_amp_parse_multi_gpio(struct device *dev,\n \t\t\t\t       struct simple_amp_multi *multi,\n-\t\t\t\t       const char *gpios_property)\n+\t\t\t\t       const char *gpios_property,\n+\t\t\t\t       const char *ranges_property)\n {\n+\tstruct device_node *np = dev->of_node;\n+\tint ret;\n+\n \t/* Start with the value 0 (GPIO inactive). Can be changed later */\n \tmulti->kctrl_val = 0;\n \tmulti->gpios = devm_gpiod_get_array_optional(dev, gpios_property, GPIOD_OUT_LOW);\n@@ -448,6 +738,15 @@ static int simple_amp_parse_multi_gpio(struct device *dev,\n \t/* Set default value for the kctrl_max. Can be changed later */\n \tmulti->kctrl_max = (1 << multi->gpios->ndescs) - 1;\n \n+\tmulti->mode = SIMPLE_AMP_MODE_NONE;\n+\tif (of_property_present(np, ranges_property)) {\n+\t\tret = simple_amp_parse_ranges(dev, multi, ranges_property);\n+\t\tif (ret < 0)\n+\t\t\treturn dev_err_probe(dev, ret, \"Failed to parse '%s'\\n\",\n+\t\t\t\t\t     ranges_property);\n+\t\tmulti->mode = SIMPLE_AMP_MODE_RANGES;\n+\t}\n+\n \treturn 0;\n }\n \n@@ -485,7 +784,8 @@ static int simple_amp_probe(struct platform_device *pdev)\n \t}\n \n \tif (simple_amp->data->supports & SIMPLE_AUDIO_SUPPORT_PGA) {\n-\t\tret = simple_amp_parse_multi_gpio(dev, &simple_amp->gain, \"gain\");\n+\t\tret = simple_amp_parse_multi_gpio(dev, &simple_amp->gain, \"gain\",\n+\t\t\t\t\t\t  \"gain-ranges\");\n \t\tif (ret)\n \t\t\treturn ret;\n \t}\n",
    "prefixes": [
        "v2",
        "14/17"
    ]
}