Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1278890lqh; Mon, 6 May 2024 02:45:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUR2DUmQkCLVkOHyxvuBIyxWtzyeMTIlLx0SW+p2uSf+v7QiNBen7HoRLiuvUlvFaN9rF/6AH8G/ynQxeeLLJpJosPjq8D0hpQRTOmTmg== X-Google-Smtp-Source: AGHT+IHwsopAR9xe9iw3Tlr/nyLG4M6Z9/xQ61COrx0C/offINMxYjBatAxa6stuejx1Z+a6Axxd X-Received: by 2002:a17:90a:6fc4:b0:2ae:72a3:2ed4 with SMTP id e62-20020a17090a6fc400b002ae72a32ed4mr8774321pjk.15.1714988725335; Mon, 06 May 2024 02:45:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714988725; cv=pass; d=google.com; s=arc-20160816; b=Shy9dqJSGotp2lqaeUeBUiOZ0OIjv24iYAHF7T77ASL3XptUWbBlLm+3g/M8zG5DuI In3GmKoiSpcSad+Tt3KHQ1c/LsyM2gG+jbjhVXEWLxwIdQW1wbFvIdqWBMEZrJzHnthY uEtpmqG+YN/9ysYyHhsuSbwRzXsNIYuSpnO0PDpjb3zOm0FjqhzD6dPyNhaT2XqvFGpP TMR/2gCeTzRlj4RNSZukCC71Hr5jUie4TDmnHtCp4zpm2z/p9iEvAPFWYs8Zwr03aoho MKssKweTVqU8RfqWwD4THzyRmaXO6lupcNF2b9V8VD7f+GCxaBBFrqo3FfNq1sFZLxJx RscA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=E2cyG8zDb6E1/doiGe+v0thXY2W3fpc0LazZWdOtNow=; fh=NY5hY5vecEGk10bGcIJmsl3T7EyhPmY6EUt4vUA1Z4U=; b=D/1EJ/UEjI2+Q3OSDVXXe2cG3108oi7MaSaKyfk5gMlPJbm7E6/nnHuFUwibrVrdgH VPB9VtRaGAzGtNt5OlYJn+8Dox+IU1Wl6I9F/L9HSUWq7JUHb8iiK1aGjH+o7fA12MlV i7oKv+qHDeWezNH3UeebhAA9BobgyW98+XLlq66xXD2aUysgSE2wr4BFjWO/lBkiU/ow 5HK6KnGZGzHCxwjIuRVb/RTHbbKKoD5oGQ5UP735zsmSfnFelGrwNQSXQ8DlFv7crVsO wr53u6OnMqr2qL8eLcH/gpGwqtdaR9jR7UwFShWHF9MB8v4jYjyZjQ7KuViV73Ex6PUr /xyg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-169599-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169599-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id t12-20020a17090ae50c00b002aeae8eda5csi10576965pjy.135.2024.05.06.02.45.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 02:45:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169599-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-169599-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169599-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 63164B23296 for ; Mon, 6 May 2024 09:43:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E2DE1428E0; Mon, 6 May 2024 09:43:24 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 715D11422D9 for ; Mon, 6 May 2024 09:43:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714988603; cv=none; b=pzeqrFnNsWWNZ/qp5X2UfNYMOgerJR5M9hbJ/D/hIfq9sjm1gXeajYr3SAOIVrUofUwd7siNfm10ShbblyQie5vXODuUGMaNdNl+xYCORxOsm8B12PACmfC20ws90/zY/rTANrviBqSikFhqwywItYG2y9U1HlAuabI/JYEI0H0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714988603; c=relaxed/simple; bh=myTU4/Q6NGtbmF0r92u+3CCOIh0NaCf/KXPLPkrYEbY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jm363GNfEAVlbOuVIp8Fgc34AtwnBQQdE46Eh3LxpwDUdJi+YTVrLUh7p1uz9fiSwYwJccPiX3ZXGC+oeqrTWIZiQKUyHbwt0M7laDrsfliSj7t/dATEklsPoQfrYfY2KSgpAkcYsMH6fGOj4eOTDX5ElKG4CutBMzo/YjWfF78= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s3usD-0003qB-BH; Mon, 06 May 2024 11:43:05 +0200 Received: from [2a0a:edc0:0:b01:1d::7b] (helo=bjornoya.blackshift.org) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s3usC-00GEwf-DY; Mon, 06 May 2024 11:43:04 +0200 Received: from pengutronix.de (unknown [172.20.34.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id 026EB2CB411; Mon, 06 May 2024 09:43:04 +0000 (UTC) Date: Mon, 6 May 2024 11:43:03 +0200 From: Marc Kleine-Budde To: Gregor Herburger Cc: Manivannan Sadhasivam , Thomas Kopp , Vincent Mailhol , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux@ew.tq-group.com Subject: Re: [PATCH v2 5/6] can: mcp251xfd: add gpio functionality Message-ID: <20240506-pygmy-wolf-of-advance-afb194-mkl@pengutronix.de> References: <20240506-mcp251xfd-gpio-feature-v2-0-615b16fa8789@ew.tq-group.com> <20240506-mcp251xfd-gpio-feature-v2-5-615b16fa8789@ew.tq-group.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="2x6ow623o46vxnne" Content-Disposition: inline In-Reply-To: <20240506-mcp251xfd-gpio-feature-v2-5-615b16fa8789@ew.tq-group.com> X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org --2x6ow623o46vxnne Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 06.05.2024 07:59:47, Gregor Herburger wrote: > The mcp251xfd devices allow two pins to be configured as gpio. Add this > functionality to driver. >=20 > Signed-off-by: Gregor Herburger > --- > drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 173 +++++++++++++++++++= ++++++ > drivers/net/can/spi/mcp251xfd/mcp251xfd.h | 6 + > 2 files changed, 179 insertions(+) >=20 > diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c b/drivers/net= /can/spi/mcp251xfd/mcp251xfd-core.c > index 4739ad80ef2a..de301f3a2f4e 100644 > --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c > +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c > @@ -16,6 +16,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1768,6 +1769,172 @@ static int mcp251xfd_register_check_rx_int(struct= mcp251xfd_priv *priv) > return 0; > } > =20 > +#ifdef CONFIG_GPIOLIB > +static const char * const mcp251xfd_gpio_names[] =3D {"GPIO0", "GPIO1"}; please add spaces after { and before }. > + > +static int mcp251xfd_gpio_request(struct gpio_chip *chip, unsigned int o= ffset) > +{ > + struct mcp251xfd_priv *priv =3D gpiochip_get_data(chip); > + u32 pin_mask =3D MCP251XFD_REG_IOCON_PM0 << offset; Can you add MCP251XFD_REG_IOCON_PM(), MCP251XFD_REG_IOCON_TRIS(), MCP251XFD_REG_IOCON_LAT(), MCP251XFD_REG_IOCON_GPIO() macros? > + int ret; > + > + if (priv->rx_int && offset =3D=3D 1) { > + netdev_err(priv->ndev, "Can't use GPIO 1 with RX-INT!\n"); > + return -EINVAL; > + } > + > + ret =3D pm_runtime_resume_and_get(priv->ndev->dev.parent); > + if (ret) > + return ret; > + > + return regmap_update_bits(priv->map_reg, MCP251XFD_REG_IOCON, > + pin_mask, pin_mask); > +} > + > +static void mcp251xfd_gpio_free(struct gpio_chip *chip, unsigned int off= set) > +{ > + struct mcp251xfd_priv *priv =3D gpiochip_get_data(chip); > + > + pm_runtime_put(priv->ndev->dev.parent); > +} > + > +static int mcp251xfd_gpio_get_direction(struct gpio_chip *chip, > + unsigned int offset) > +{ > + struct mcp251xfd_priv *priv =3D gpiochip_get_data(chip); > + u32 mask =3D MCP251XFD_REG_IOCON_TRIS0 << offset; > + u32 val; > + > + regmap_read(priv->map_reg, MCP251XFD_REG_IOCON, &val); Please print an error if regmap_read() throws an error. > + > + if (mask & val) > + return GPIO_LINE_DIRECTION_IN; > + > + return GPIO_LINE_DIRECTION_OUT; > +} > + > +static int mcp251xfd_gpio_get(struct gpio_chip *chip, unsigned int offse= t) > +{ > + struct mcp251xfd_priv *priv =3D gpiochip_get_data(chip); > + u32 mask =3D MCP251XFD_REG_IOCON_GPIO0 << offset; > + u32 val; > + > + regmap_read(priv->map_reg, MCP251XFD_REG_IOCON, &val); same here > + > + return !!(mask & val); > +} > + > +static int mcp251xfd_gpio_get_multiple(struct gpio_chip *chip, unsigned = long *mask, > + unsigned long *bit) > +{ > + struct mcp251xfd_priv *priv =3D gpiochip_get_data(chip); > + u32 val; > + int ret; > + > + ret =3D regmap_read(priv->map_reg, MCP251XFD_REG_IOCON, &val); > + if (ret) > + return ret; > + > + *bit =3D FIELD_GET(MCP251XFD_REG_IOCON_GPIO_MASK, val) & *mask; > + > + return 0; > +} > + > +static int mcp251xfd_gpio_direction_output(struct gpio_chip *chip, > + unsigned int offset, int value) > +{ > + struct mcp251xfd_priv *priv =3D gpiochip_get_data(chip); > + u32 dir_mask =3D MCP251XFD_REG_IOCON_TRIS0 << offset; > + u32 val_mask =3D MCP251XFD_REG_IOCON_LAT0 << offset; > + u32 val; > + > + if (value) > + val =3D val_mask; > + else > + val =3D 0; > + > + return regmap_update_bits(priv->map_reg, MCP251XFD_REG_IOCON, > + dir_mask | val_mask, val); > +} > + > +static int mcp251xfd_gpio_direction_input(struct gpio_chip *chip, > + unsigned int offset) > +{ > + struct mcp251xfd_priv *priv =3D gpiochip_get_data(chip); > + u32 dir_mask =3D MCP251XFD_REG_IOCON_TRIS0 << offset; > + > + return regmap_update_bits(priv->map_reg, MCP251XFD_REG_IOCON, > + dir_mask, dir_mask); > +} > + > +static void mcp251xfd_gpio_set(struct gpio_chip *chip, unsigned int offs= et, > + int value) > +{ > + struct mcp251xfd_priv *priv =3D gpiochip_get_data(chip); > + u32 val_mask =3D MCP251XFD_REG_IOCON_LAT0 << offset; > + u32 val; > + int ret; > + > + if (value) > + val =3D val_mask; > + else > + val =3D 0; > + > + ret =3D regmap_update_bits(priv->map_reg, MCP251XFD_REG_IOCON, > + val_mask, val); > + if (ret) > + dev_warn(&priv->spi->dev, > + "Failed to set GPIO %u: %d\n", offset, ret); dev_error() > +} > + > +static void mcp251xfd_gpio_set_multiple(struct gpio_chip *chip, unsigned= long *mask, > + unsigned long *bits) > +{ > + struct mcp251xfd_priv *priv =3D gpiochip_get_data(chip); > + u32 val; > + int ret; > + > + val =3D FIELD_PREP(MCP251XFD_REG_IOCON_LAT_MASK, *bits); > + > + ret =3D regmap_update_bits(priv->map_reg, MCP251XFD_REG_IOCON, > + MCP251XFD_REG_IOCON_LAT_MASK, val); > + if (ret) > + dev_warn(&priv->spi->dev, "Failed to set GPIOs %d\n", ret); dev_error() regards, Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung N=C3=BCrnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 | --2x6ow623o46vxnne Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEUEC6huC2BN0pvD5fKDiiPnotvG8FAmY4piQACgkQKDiiPnot vG+GyAf9EysdM/a8rlYZsemizlyNfZsVdm55Lvk/z1KBOe1AnQy1PSsj3nOlgbc+ aDLCX6Pk2aHeV/IdFI6WjVvyZnu9RLH7K/FfPu9WMgXb4d9tjb8eKvi4AZBgOoIL FQvjYkGiURFEyNsyAg1LNrzE+vM6Hlbt0LRnBAHVQcTSeiPVj/a5F72mZH14/IfE GHa8zxi9QMVuzTcdikJdMC4TrQMPM7LdrU4nDoEg96LbVMowmd2BpNViiD74UNtG blBWbm7+IJysQABmL47o4JK0xdjseb6hACx8BtxNPKA3YNGvxHSmXw0nFCre7+2d keEWG+PcOCG50FLfcYn0GrMQjqam4A== =OZUz -----END PGP SIGNATURE----- --2x6ow623o46vxnne--