[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251013-marvellous-acoustic-bison-3ed5d4-mkl@pengutronix.de>
Date: Mon, 13 Oct 2025 11:36:16 +0200
From: Marc Kleine-Budde <mkl@...gutronix.de>
To: Dimitri Fedrau via B4 Relay <devnull+dimitri.fedrau.liebherr.com@...nel.org>
Cc: Vinod Koul <vkoul@...nel.org>,
Kishon Vijay Abraham I <kishon@...nel.org>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor Dooley <conor+dt@...nel.org>,
linux-phy@...ts.infradead.org, devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
Dimitri Fedrau <dimitri.fedrau@...bherr.com>, Dimitri Fedrau <dima.fedrau@...il.com>,
linux-can@...r.kernel.org
Subject: Re: [PATCH v3 2/2] phy: add basic support for NXPs TJA1145 CAN
transceiver
On 13.10.2025 11:19:19, Dimitri Fedrau via B4 Relay wrote:
> From: Dimitri Fedrau <dimitri.fedrau@...bherr.com>
>
> Add basic driver support for NXPs TJA1145 CAN transceiver which brings the
> PHY up/down by switching to normal/standby mode using SPI commands.
>
> Signed-off-by: Dimitri Fedrau <dimitri.fedrau@...bherr.com>
> ---
> drivers/phy/Kconfig | 10 +++
> drivers/phy/Makefile | 1 +
> drivers/phy/phy-nxp-tja1145.c | 185 ++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 196 insertions(+)
>
> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> index 678dd0452f0aa0597773433f04d2a9ba77474d2a..2f2c8f29cce2beb20c584adfe8acfe23de14e128 100644
> --- a/drivers/phy/Kconfig
> +++ b/drivers/phy/Kconfig
> @@ -101,6 +101,16 @@ config PHY_NXP_PTN3222
> schemes. It supports all three USB 2.0 data rates: Low Speed, Full
> Speed and High Speed.
>
> +config PHY_NXP_TJA1145
> + tristate "NXP TJA1145 CAN transceiver PHY"
> + select GENERIC_PHY
> + select REGMAP_SPI
> + depends on SPI
> + help
> + This option enables support for NXPs TJA1145 CAN transceiver as a PHY.
> + This driver provides function for putting the transceiver in various
> + functional modes using SPI commands.
> +
> source "drivers/phy/allwinner/Kconfig"
> source "drivers/phy/amlogic/Kconfig"
> source "drivers/phy/broadcom/Kconfig"
> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
> index bfb27fb5a494283d7fd05dd670ebd1b12df8b1a1..48eac644d1e2b20f986f80de95b40c26d080358b 100644
> --- a/drivers/phy/Makefile
> +++ b/drivers/phy/Makefile
> @@ -13,6 +13,7 @@ obj-$(CONFIG_PHY_SNPS_EUSB2) += phy-snps-eusb2.o
> obj-$(CONFIG_USB_LGM_PHY) += phy-lgm-usb.o
> obj-$(CONFIG_PHY_AIROHA_PCIE) += phy-airoha-pcie.o
> obj-$(CONFIG_PHY_NXP_PTN3222) += phy-nxp-ptn3222.o
> +obj-$(CONFIG_PHY_NXP_TJA1145) += phy-nxp-tja1145.o
> obj-y += allwinner/ \
> amlogic/ \
> broadcom/ \
> diff --git a/drivers/phy/phy-nxp-tja1145.c b/drivers/phy/phy-nxp-tja1145.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..4d3aa5bfcd88d5755fa37e0d42bfa8293dee2155
> --- /dev/null
> +++ b/drivers/phy/phy-nxp-tja1145.c
> @@ -0,0 +1,185 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2025 Liebherr-Electronics and Drives GmbH
> + */
> +#include <linux/bitfield.h>
> +#include <linux/module.h>
> +#include <linux/regmap.h>
> +
> +#include <linux/phy/phy.h>
> +#include <linux/spi/spi.h>
> +
> +#define TJA1145_MODE_CTRL 0x01
> +#define TJA1145_MODE_CTRL_MC GENMASK(2, 0)
> +#define TJA1145_MODE_CRTL_STBY BIT(2)
> +#define TJA1145_MODE_CRTL_NORMAL TJA1145_MODE_CTRL_MC
> +
> +#define TJA1145_CAN_CTRL 0x20
> +#define TJA1145_CAN_CTRL_CMC GENMASK(1, 0)
> +#define TJA1145_CAN_CTRL_ACTIVE BIT(1)
> +
> +#define TJA1145_IDENT 0x7e
> +#define TJA1145_IDENT_TJA1145T 0x70
> +
> +#define TJA1145_SPI_READ_BIT BIT(0)
> +#define TJA1145T_MAX_BITRATE 1000000
> +
> +static int tja1145_phy_power_on(struct phy *phy)
> +{
> + struct regmap *map = phy_get_drvdata(phy);
> + int ret;
> +
> + /*
> + * Switch operating mode to normal which is the active operating mode.
> + * In this mode, the device is fully operational.
> + */
> + ret = regmap_update_bits(map, TJA1145_MODE_CTRL, TJA1145_MODE_CTRL_MC,
> + TJA1145_MODE_CRTL_NORMAL);
> + if (ret)
> + return ret;
> +
> + /*
> + * Switch to CAN operating mode active where the PHY can transmit and
> + * receive data.
> + */
> + return regmap_update_bits(map, TJA1145_CAN_CTRL, TJA1145_CAN_CTRL_CMC,
> + TJA1145_CAN_CTRL_ACTIVE);
> +}
> +
> +static int tja1145_phy_power_off(struct phy *phy)
> +{
> + struct regmap *map = phy_get_drvdata(phy);
> +
> + /*
> + * Switch to operating mode standby, the PHY is unable to transmit or
> + * receive data in standby mode.
> + */
> + return regmap_update_bits(map, TJA1145_MODE_CTRL, TJA1145_MODE_CTRL_MC,
> + TJA1145_MODE_CRTL_STBY);
> +}
> +
> +static const struct phy_ops tja1145_phy_ops = {
> + .power_on = tja1145_phy_power_on,
> + .power_off = tja1145_phy_power_off,
> +};
> +
> +static const struct regmap_range tja1145_wr_holes_ranges[] = {
> + regmap_reg_range(0x00, 0x00),
> + regmap_reg_range(0x02, 0x03),
> + regmap_reg_range(0x05, 0x05),
> + regmap_reg_range(0x0b, 0x1f),
> + regmap_reg_range(0x21, 0x22),
> + regmap_reg_range(0x24, 0x25),
> + regmap_reg_range(0x30, 0x4b),
> + regmap_reg_range(0x4d, 0x60),
> + regmap_reg_range(0x62, 0x62),
> + regmap_reg_range(0x65, 0x67),
> + regmap_reg_range(0x70, 0xff),
> +};
> +
> +static const struct regmap_access_table tja1145_wr_table = {
> + .no_ranges = tja1145_wr_holes_ranges,
> + .n_no_ranges = ARRAY_SIZE(tja1145_wr_holes_ranges),
> +};
> +
> +static const struct regmap_range tja1145_rd_holes_ranges[] = {
> + regmap_reg_range(0x00, 0x00),
> + regmap_reg_range(0x02, 0x02),
> + regmap_reg_range(0x05, 0x05),
> + regmap_reg_range(0x0b, 0x1f),
> + regmap_reg_range(0x21, 0x21),
> + regmap_reg_range(0x24, 0x25),
> + regmap_reg_range(0x30, 0x4a),
> + regmap_reg_range(0x4d, 0x5f),
> + regmap_reg_range(0x62, 0x62),
> + regmap_reg_range(0x65, 0x67),
> + regmap_reg_range(0x70, 0x7d),
> + regmap_reg_range(0x7f, 0xff),
> +};
> +
> +static const struct regmap_access_table tja1145_rd_table = {
> + .no_ranges = tja1145_rd_holes_ranges,
> + .n_no_ranges = ARRAY_SIZE(tja1145_rd_holes_ranges),
> +};
> +
> +
Nitpick: double newline.
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists