From nobody Wed Feb 11 14:27:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAA08C6FD1C for ; Tue, 14 Mar 2023 15:12:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231502AbjCNPMl (ORCPT ); Tue, 14 Mar 2023 11:12:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230357AbjCNPMY (ORCPT ); Tue, 14 Mar 2023 11:12:24 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05B5E11EA9 for ; Tue, 14 Mar 2023 08:12:23 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id t15so14673153wrz.7 for ; Tue, 14 Mar 2023 08:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; t=1678806741; 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=PSrec+nBwM+c2dQQeNVjKvZ5AfVGgxg/yYXQBrWPGyQ=; b=0PbFTDbB3iqQ+6B6JXcc9N2aOoYFez/WZp8jLJ+U14nAeRdstbXlrz5nCLrsmu+8vg zrZc9+pn9FlyY7AbhfO6DZ6ZAtMa2BBofJjYjfT3YAZOBfjaLLaSM3GJ82Pr5ypWNVa2 kI+8U7OK7Et9uwE9s1EVsBIEPxuFbcPFhRnyDzXaDmrgTWTUmh7UjHFQz52GNzg04HYT MbwN/mByHaj0BkQK3LrzzXMTKzoDMJCH4fLt/x2TjJowl5N2M8JjUbGj0ZNHLPvGQQ3W kekv73o6UPUG78wFrDRTMQp5yMitEW0p+8uIsMjTwsdPcHPVDe8ldRNV8by6kxRcrdGR uY4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678806741; 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=PSrec+nBwM+c2dQQeNVjKvZ5AfVGgxg/yYXQBrWPGyQ=; b=XXBKcq3JxQ7NjWBhJchXKtIR6coMVC7RyoaTVCFmVkIJHBYUlZhDt7caq5kER/f3oZ pzlLx+uhGxZfWCulDE9NKM0t1pglKYVyFvisGcQuT6rN0ZrRDhME87i4PyW1+b0lXYES tUZbKO4mPigXml7H0TLl67MQTgv+LUhBGCWD8mr+Wr2Hgwf1O5jEVPWeqOokmJrH21ng HWo7xxczld3e3B5MzLtI8sPpjOs563ieXc3eCX9/oOFbNDmdKEsnDj2S7vWKe4YF3rao pVVNQhr13lpyx7+ghZPOHaQtJO43dUUA1QSidkrxPoxRxzF26HJKWlXA2ys4GZI96fhG GITA== X-Gm-Message-State: AO0yUKX9kcxZuKPKS81+1Rk6MxLx36YxRx+ddToCtAw3Ux2CzxOWztoV tt/FPV7QsYJEvo7i1uKdD/08DQ== X-Google-Smtp-Source: AK7set8nWY958Ivm09aRAnCvmEiM0RkXJPN4MN+X/TFRi4qWMFOg1Wj9FrzzG9fsSrjBWEySGL132g== X-Received: by 2002:a5d:6289:0:b0:2ce:a944:2c6a with SMTP id k9-20020a5d6289000000b002cea9442c6amr6058726wru.70.1678806741490; Tue, 14 Mar 2023 08:12:21 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4090:a247:8056:be7d:83e:a6a5:4659]) by smtp.gmail.com with ESMTPSA id d9-20020a5d4f89000000b002c707b336c9sm2320158wru.36.2023.03.14.08.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 08:12:21 -0700 (PDT) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , Rob Herring , Krzysztof Kozlowski Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Markus Schneider-Pargmann Subject: [PATCH 5/5] can: tcan4x5x: Add support for tcan4552/4553 Date: Tue, 14 Mar 2023 16:12:01 +0100 Message-Id: <20230314151201.2317134-6-msp@baylibre.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314151201.2317134-1-msp@baylibre.com> References: <20230314151201.2317134-1-msp@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" tcan4552 and tcan4553 do not have wake or state pins, so they are currently not compatible with the generic driver. The generic driver uses tcan4x5x_disable_state() and tcan4x5x_disable_wake() if the gpios are not defined. These functions use register bits that are not available in tcan4552/4553. This patch adds support by introducing version information to reflect if the chip has wake and state pins. Also the version is now checked. Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/tcan4x5x-core.c | 113 ++++++++++++++++++++------ 1 file changed, 89 insertions(+), 24 deletions(-) diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/= tcan4x5x-core.c index fb9375fa20ec..e7fa509dacc9 100644 --- a/drivers/net/can/m_can/tcan4x5x-core.c +++ b/drivers/net/can/m_can/tcan4x5x-core.c @@ -7,6 +7,7 @@ #define TCAN4X5X_EXT_CLK_DEF 40000000 =20 #define TCAN4X5X_DEV_ID1 0x00 +#define TCAN4X5X_DEV_ID1_TCAN 0x4e414354 /* ASCII TCAN */ #define TCAN4X5X_DEV_ID2 0x04 #define TCAN4X5X_REV 0x08 #define TCAN4X5X_STATUS 0x0C @@ -103,6 +104,13 @@ #define TCAN4X5X_WD_3_S_TIMER BIT(29) #define TCAN4X5X_WD_6_S_TIMER (BIT(28) | BIT(29)) =20 +struct tcan4x5x_version_info { + u32 id2_register; + + bool has_wake_pin; + bool has_state_pin; +}; + static inline struct tcan4x5x_priv *cdev_to_priv(struct m_can_classdev *cd= ev) { return container_of(cdev, struct tcan4x5x_priv, cdev); @@ -254,18 +262,53 @@ static int tcan4x5x_disable_state(struct m_can_classd= ev *cdev) TCAN4X5X_DISABLE_INH_MSK, 0x01); } =20 -static int tcan4x5x_get_gpios(struct m_can_classdev *cdev) +static int tcan4x5x_verify_version( + struct tcan4x5x_priv *priv, + const struct tcan4x5x_version_info *version_info) +{ + u32 val; + int ret; + + ret =3D regmap_read(priv->regmap, TCAN4X5X_DEV_ID1, &val); + if (ret) + return ret; + + if (val !=3D TCAN4X5X_DEV_ID1_TCAN) { + dev_err(&priv->spi->dev, "Not a tcan device %x\n", val); + return -ENODEV; + } + + if (!version_info->id2_register) + return 0; + + ret =3D regmap_read(priv->regmap, TCAN4X5X_DEV_ID2, &val); + if (ret) + return ret; + + if (version_info->id2_register !=3D val) { + dev_err(&priv->spi->dev, "Not the specified TCAN device, id2: %x !=3D %x= \n", + version_info->id2_register, val); + return -ENODEV; + } + + return 0; +} + +static int tcan4x5x_get_gpios(struct m_can_classdev *cdev, + const struct tcan4x5x_version_info *version_info) { struct tcan4x5x_priv *tcan4x5x =3D cdev_to_priv(cdev); int ret; =20 - tcan4x5x->device_wake_gpio =3D devm_gpiod_get(cdev->dev, "device-wake", - GPIOD_OUT_HIGH); - if (IS_ERR(tcan4x5x->device_wake_gpio)) { - if (PTR_ERR(tcan4x5x->device_wake_gpio) =3D=3D -EPROBE_DEFER) - return -EPROBE_DEFER; + if (version_info->has_wake_pin) { + tcan4x5x->device_wake_gpio =3D devm_gpiod_get(cdev->dev, "device-wake", + GPIOD_OUT_HIGH); + if (IS_ERR(tcan4x5x->device_wake_gpio)) { + if (PTR_ERR(tcan4x5x->device_wake_gpio) =3D=3D -EPROBE_DEFER) + return -EPROBE_DEFER; =20 - tcan4x5x_disable_wake(cdev); + tcan4x5x_disable_wake(cdev); + } } =20 tcan4x5x->reset_gpio =3D devm_gpiod_get_optional(cdev->dev, "reset", @@ -277,12 +320,14 @@ static int tcan4x5x_get_gpios(struct m_can_classdev *= cdev) if (ret) return ret; =20 - tcan4x5x->device_state_gpio =3D devm_gpiod_get_optional(cdev->dev, - "device-state", - GPIOD_IN); - if (IS_ERR(tcan4x5x->device_state_gpio)) { - tcan4x5x->device_state_gpio =3D NULL; - tcan4x5x_disable_state(cdev); + if (version_info->has_state_pin) { + tcan4x5x->device_state_gpio =3D devm_gpiod_get_optional(cdev->dev, + "device-state", + GPIOD_IN); + if (IS_ERR(tcan4x5x->device_state_gpio)) { + tcan4x5x->device_state_gpio =3D NULL; + tcan4x5x_disable_state(cdev); + } } =20 return 0; @@ -301,8 +346,13 @@ static int tcan4x5x_can_probe(struct spi_device *spi) { struct tcan4x5x_priv *priv; struct m_can_classdev *mcan_class; + const struct tcan4x5x_version_info *version_info; int freq, ret; =20 + version_info =3D of_device_get_match_data(&spi->dev); + if (!version_info) + version_info =3D (void *)spi_get_device_id(spi)->driver_data; + mcan_class =3D m_can_class_allocate_dev(&spi->dev, sizeof(struct tcan4x5x_priv)); if (!mcan_class) @@ -361,7 +411,11 @@ static int tcan4x5x_can_probe(struct spi_device *spi) if (ret) goto out_m_can_class_free_dev; =20 - ret =3D tcan4x5x_get_gpios(mcan_class); + ret =3D tcan4x5x_verify_version(priv, version_info); + if (ret) + goto out_power; + + ret =3D tcan4x5x_get_gpios(mcan_class, version_info); if (ret) goto out_power; =20 @@ -394,21 +448,32 @@ static void tcan4x5x_can_remove(struct spi_device *sp= i) m_can_class_free_dev(priv->cdev.net); } =20 +static const struct tcan4x5x_version_info tcan4x5x_generic =3D { + .has_state_pin =3D true, + .has_wake_pin =3D true, +}; + +static const struct tcan4x5x_version_info tcan4x5x_tcan4552 =3D { + .id2_register =3D 0x32353534, /* ASCII =3D 4552 */ +}; + +static const struct tcan4x5x_version_info tcan4x5x_tcan4553 =3D { + .id2_register =3D 0x33353534, /* ASCII =3D 4553 */ +}; + static const struct of_device_id tcan4x5x_of_match[] =3D { - { - .compatible =3D "ti,tcan4x5x", - }, { - /* sentinel */ - }, + { .compatible =3D "ti,tcan4x5x", .data =3D &tcan4x5x_generic }, + { .compatible =3D "ti,tcan4552", .data =3D &tcan4x5x_tcan4552 }, + { .compatible =3D "ti,tcan4553", .data =3D &tcan4x5x_tcan4553 }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, tcan4x5x_of_match); =20 static const struct spi_device_id tcan4x5x_id_table[] =3D { - { - .name =3D "tcan4x5x", - }, { - /* sentinel */ - }, + { .name =3D "tcan4x5x", .driver_data =3D (unsigned long) &tcan4x5x_generi= c, }, + { .name =3D "tcan4552", .driver_data =3D (unsigned long) &tcan4x5x_tcan45= 52, }, + { .name =3D "tcan4553", .driver_data =3D (unsigned long) &tcan4x5x_tcan45= 53, }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(spi, tcan4x5x_id_table); =20 --=20 2.39.2