From patchwork Wed Sep 11 18:07:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 827472 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp922145wrc; Wed, 11 Sep 2024 11:07:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWYQttw1HkWUBXTyxER8dMWuIyONpdA9FN3+PVkgaIUOl6tfZiKiWVhpdyxTHRXMN14Uy/0mw==@linaro.org X-Google-Smtp-Source: AGHT+IFt2pkcc+8tcqH6Ypfxa3+i7Mx/fhpKqn7dxDlZAEn6n+eJC72KXdMwKO5nmS+tkT+Kx9Wp X-Received: by 2002:a17:907:e64e:b0:a86:7d62:4c28 with SMTP id a640c23a62f3a-a90295a6016mr28514766b.30.1726078051124; Wed, 11 Sep 2024 11:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726078051; cv=none; d=google.com; s=arc-20240605; b=YPsR9O0YrGQev5NuxeSJNTZcD2S0dbffVWDCbGE7p6MXUgllS4Ivr/+pSgdNIXTOgc lDFJhhsIyedTsMCu/xOiebsD9rLH/BoHnO29G6856X5JdatTc34FoXyDNyX9gMCVTDDy aXYcdsgfnivMsA+atXbRL2xHPiooU6HjSyPoWCwMBayGYunnma9djqN/HgB+n4IQ18PT uomTZeurpcoTYAHcsfriNGxvkf0Z1xkysFj4rjSLm8hjQceDz2GCZbXOlgdCCFXxSYTX H8sf0JdGn9oinvwL3Doj9G2uf2zQjGM9m75Q532bzFfizaISWsABxgB0wwlrwHb28piF psvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=wiAtme929kZSm5f6Dxzpw/4FODGxe7FfO8rO9BH0BXE=; fh=/OduIcglOGGyJf7qok+ShyNh7iqbi/Fa16pAiaWGx3U=; b=CN9mwfUaRfP9NkIpVzd6oLtv80j/CIZ8zEIL9ygPBuKHzgDjSOBgZduSXBGFzYTWxN 0xQhiUnlxp/r5JKjzF7vVCJLTT1a0fhf4rWyARSfE15IY6zCc+nshsJ6kSZh78YIxqyY PK04L5iYd9iH1c3UF60pqKfJTz9bu2HG+/PDJjXEW6wbF/IxuzJGbk1YEFe9gt8vZv4/ ihD2hUW3nQwurzxCvKUkb2dJwhRA6+F4xgYv8R0uoHZRi7lzBFrSnwuAgVyT9Su1v3gN 9aQ7+kq3EpZ3UnfjXHL7ZPXjo7snnpJTxZJYjVcjEjVV2ry7Qdb9sXbeV3YvLC6FCeF+ 60DQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YuJioySZ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-a8d2584ccb8si759498766b.84.2024.09.11.11.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 11:07:31 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YuJioySZ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 27B4889304; Wed, 11 Sep 2024 20:07:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="YuJioySZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6AD4888E83; Wed, 11 Sep 2024 20:07:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7183C892FF for ; Wed, 11 Sep 2024 20:07:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=neil.armstrong@linaro.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-42cacabd2e0so243655e9.3 for ; Wed, 11 Sep 2024 11:07:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726078039; x=1726682839; darn=lists.denx.de; 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=wiAtme929kZSm5f6Dxzpw/4FODGxe7FfO8rO9BH0BXE=; b=YuJioySZrs0FBEi1JTv8C/cHZBgVXUfsIiJbJ09dCcpLxmy82m2jdgdXUt6OsKHMTU w6uSIg7osT3enS/FrwYPLhMgT3NZP3Aubxzl44Z4RLdbXBTz1MZuOf9lNY1cD0eciPPj FiD1RsaXcnsGTeJBPu2waEpv316aRuRMSRLCyN8hY+P8r/LgUODPAprpZiKHDAv5Xods k8U3jw44POEL0G5RG2qHcql4te9CuMzkSwztSeGuszTDV6fuQTXMnD1OXhy4OjG4cXjI Z3iD28MbfDfbITev4WBHsc7O60G1OdatBojU3agehemOGndE/WbxVez1F7Z3cvsnidif kz8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726078039; x=1726682839; 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=wiAtme929kZSm5f6Dxzpw/4FODGxe7FfO8rO9BH0BXE=; b=ma5g9B5rkbbtSVfkAX19Jw8zxiyBDxuGayio05bdm2rjqXRsBa9jaree/CYT/P5t5r 4nAQvF7N8POugqA6X1bkMDn39imOgyEzGWYvu9a3U9rqYdTnRrnRUpi+67mfQrlZJyJB cU6f/Ygh1ilQDthFl238zIT+SyacuG9tR6tIO58ohTDwr84/40hxGx2CC24E4vfBAdEh vo+Tw6NucnwGUOM5L2ZZVCNCMdvz0MOeeGVU1Lv0NqrjzkwBypCztpfbMMm3fDfdwO6J 4V1KyuAVtc07QjNFJ5b5Q+nWlVQO/rRfklk9bMq5XDgfSTWmS8hjqe2XG80gkoXcMEBZ QhPQ== X-Forwarded-Encrypted: i=1; AJvYcCW9RghF9bw25UBTVwCPFhHHiU4VL0uazTSEGxycWndfduD1QmuqBPCl8vIVjERD6Ml37aC9NR0=@lists.denx.de X-Gm-Message-State: AOJu0YzqcN36G6LVAseG1IpZtg/Jh+N/RH5w66oWsFagtYhsLnJSq3M6 jEyUEhvE/EQeNMggWrwlwAYBnN8r32I1Ta1XkZ8kYI+hPnLBDP0cW2iQIWmZUrxFth0N+46tWzN H X-Received: by 2002:a05:600c:1e0f:b0:42c:bc03:e765 with SMTP id 5b1f17b1804b1-42cdb53bbddmr3160535e9.16.1726078038680; Wed, 11 Sep 2024 11:07:18 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37895675b8bsm12192404f8f.54.2024.09.11.11.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 11:07:18 -0700 (PDT) From: Neil Armstrong Date: Wed, 11 Sep 2024 20:07:14 +0200 Subject: [PATCH v2 1/2] gpio: msm: add support for special pins MIME-Version: 1.0 Message-Id: <20240911-topic-sm8x50-msm-gpio-special-pins-sm8250-v2-1-c49834055128@linaro.org> References: <20240911-topic-sm8x50-msm-gpio-special-pins-sm8250-v2-0-c49834055128@linaro.org> In-Reply-To: <20240911-topic-sm8x50-msm-gpio-special-pins-sm8250-v2-0-c49834055128@linaro.org> To: Caleb Connolly , Sumit Garg , Tom Rini Cc: u-boot-qcom@groups.io, u-boot@lists.denx.de, Neil Armstrong X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4823; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=hpzDe3p6sPzJQLFujHI5KRQb2puJ+WsxzjYzQ7F0P44=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBm4dxU8IkZwwWmw30vKQAEet9zgPU3Scv1VyYmq1L/ tjSRSaeJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZuHcVAAKCRB33NvayMhJ0euhD/ 9hlnf7iAXkIde2kIvuqVgEJNDhGeMs8yQFRl8g0Ce0YUHxdAG7TsUb/jSzakZ3FM+TIASvnqAb5md2 b/5RGZM5VktnJeRFmx0EbPHnuytmJYihUbUUvbc1b+PMdCplmvKiTVY9HArZKzOq+8nUNgVlNxwzoX +1DlwA0PabI8B8xlWjInvLUCXAOpWoXWRVXr7C71CJtZyS8pC6HGBin/Fs3sMQJufy8x+NZTLx3eVB r3GNvJH6wKjZUooWdiy/hF6hyMQSouSloDE/2oQnJ5JieFdaYo62bf5BJUw8W/bGYOxtNOGgBHskv8 oEpwmj4Sn1C8ksU9lCAquhdBBGWH1dJnrYOJefTENqwcEDVIjuy9wj5ObA1qqhkRiZKUIyfhc2juYU oPq6RJ527QqmLomgtyqEHj7jjiHiWciNqsbxIYYL3xH4WdTSfI0+wG7F4lGCxwK7n5sBDspjom1+Me WI/gMrqAmfvTW/g1N9wvGz2ifPPOKf8OOmKob6MlamYcWJJr7w2OsJXJ3YolaOxKT4mc/B9/79frRz Zeg4Ro2gUpsdAyOm7xC/m/cYDtWrXLMUVhwGRgNeBNk7gtPlcTm4zG8A6jivRQiK/J4mWoALCtHsVB W3KUIesk2qTzcGSVnkTBLOAYgoewKnp9+hZ0+D6tBLFbn3G760rlFxvQ7/sA== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Leverage the data introduced in the struct msm_special_pin_data to allow setting the gpio direction and value if supported by the pin data. Signed-off-by: Neil Armstrong --- drivers/gpio/msm_gpio.c | 97 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 89 insertions(+), 8 deletions(-) diff --git a/drivers/gpio/msm_gpio.c b/drivers/gpio/msm_gpio.c index 2fb266f1285..cea073b3297 100644 --- a/drivers/gpio/msm_gpio.c +++ b/drivers/gpio/msm_gpio.c @@ -34,13 +34,31 @@ struct msm_gpio_bank { #define GPIO_IN_OUT_REG(dev, x) \ (GPIO_CONFIG_REG(dev, x) + 0x4) +static void msm_gpio_direction_input_special(struct msm_gpio_bank *priv, + unsigned int gpio) +{ + unsigned int offset = gpio - priv->pin_data->special_pins_start; + const struct msm_special_pin_data *data; + + if (!priv->pin_data->special_pins_data) + return; + + data = &priv->pin_data->special_pins_data[offset]; + + if (!data->ctl_reg || data->oe_bit >= 31) + return; + + /* switch direction */ + clrsetbits_le32(priv->base + data->ctl_reg, + BIT(data->oe_bit), 0); +} + static void msm_gpio_direction_input(struct udevice *dev, unsigned int gpio) { struct msm_gpio_bank *priv = dev_get_priv(dev); - /* Always NOP for special pins, assume they're in the correct state */ if (qcom_is_special_pin(priv->pin_data, gpio)) - return; + msm_gpio_direction_input_special(priv, gpio); /* Disable OE bit */ clrsetbits_le32(priv->base + GPIO_CONFIG_REG(dev, gpio), @@ -49,13 +67,33 @@ static void msm_gpio_direction_input(struct udevice *dev, unsigned int gpio) return; } +static int msm_gpio_set_value_special(struct msm_gpio_bank *priv, + unsigned int gpio, int value) +{ + unsigned int offset = gpio - priv->pin_data->special_pins_start; + const struct msm_special_pin_data *data; + + if (!priv->pin_data->special_pins_data) + return 0; + + data = &priv->pin_data->special_pins_data[offset]; + + if (!data->io_reg || data->out_bit >= 31) + return 0; + + value = !!value; + /* set value */ + writel(value << data->out_bit, priv->base + data->io_reg); + + return 0; +} + static int msm_gpio_set_value(struct udevice *dev, unsigned int gpio, int value) { struct msm_gpio_bank *priv = dev_get_priv(dev); - /* Always NOP for special pins, assume they're in the correct state */ if (qcom_is_special_pin(priv->pin_data, gpio)) - return 0; + return msm_gpio_set_value_special(priv, gpio, value); value = !!value; /* set value */ @@ -64,14 +102,42 @@ static int msm_gpio_set_value(struct udevice *dev, unsigned int gpio, int value) return 0; } +static int msm_gpio_direction_output_special(struct msm_gpio_bank *priv, + unsigned int gpio, + int value) +{ + unsigned int offset = gpio - priv->pin_data->special_pins_start; + const struct msm_special_pin_data *data; + + if (!priv->pin_data->special_pins_data) + return 0; + + data = &priv->pin_data->special_pins_data[offset]; + + if (!data->io_reg || data->out_bit >= 31) + return 0; + + value = !!value; + /* set value */ + writel(value << data->out_bit, priv->base + data->io_reg); + + if (!data->ctl_reg || data->oe_bit >= 31) + return 0; + + /* switch direction */ + clrsetbits_le32(priv->base + data->ctl_reg, + BIT(data->oe_bit), BIT(data->oe_bit)); + + return 0; +} + static int msm_gpio_direction_output(struct udevice *dev, unsigned int gpio, int value) { struct msm_gpio_bank *priv = dev_get_priv(dev); - /* Always NOP for special pins, assume they're in the correct state */ if (qcom_is_special_pin(priv->pin_data, gpio)) - return 0; + return msm_gpio_direction_output_special(priv, gpio, value); value = !!value; /* set value */ @@ -100,13 +166,28 @@ static int msm_gpio_set_flags(struct udevice *dev, unsigned int gpio, ulong flag return 0; } +static int msm_gpio_get_value_special(struct msm_gpio_bank *priv, unsigned int gpio) +{ + unsigned int offset = gpio - priv->pin_data->special_pins_start; + const struct msm_special_pin_data *data; + + if (!priv->pin_data->special_pins_data) + return 0; + + data = &priv->pin_data->special_pins_data[offset]; + + if (!data->io_reg || data->in_bit >= 31) + return 0; + + return !!(readl(priv->base + data->io_reg) >> data->in_bit); +} + static int msm_gpio_get_value(struct udevice *dev, unsigned int gpio) { struct msm_gpio_bank *priv = dev_get_priv(dev); - /* Always NOP for special pins, assume they're in the correct state */ if (qcom_is_special_pin(priv->pin_data, gpio)) - return 0; + return msm_gpio_get_value_special(priv, gpio); return !!(readl(priv->base + GPIO_IN_OUT_REG(dev, gpio)) >> GPIO_IN); }