[PATCH can-next v2] can: mcp251xfd: ACPI support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Stefano Offredi <stefano.offredi@xxxxxxxxx>

This patch makes the Microchip MCP251xFD driver compatible with
hardware parameters loading from ACPI tables.

It's a patch for the 5.15 kernel version for which I could do tests on.

The ACPI driver hardware description table I used is the following:

DefinitionBlock ("can.aml", "SSDT", 1, "mcp2518fd", "Intel", 0x00000003)
{
    External (\_SB.PC00.SPI0, DeviceObj)
    Scope (\_SB.PC00.SPI0)
    {
        Device (CAN0) {
            Name (_HID, "MCP2518")
            Name (_CID, "mcp2518fd")
            Name (_DDN, "CAN SPI device connected to CS0")
            Name (_CRS, ResourceTemplate () {
                SpiSerialBus (
                    0,                             // Chip select
                    PolarityLow,             // Chip select is active low
                    FourWireMode,        // Full duplex
                    8,                              // Bits per word is 8 (byte)
                    ControllerInitiated,    // Don't care
                    20000000,                // 20 MHz
                    ClockPolarityLow,     // SPI mode 0
                    ClockPhaseFirst,      // SPI mode 0
                    "\\_SB.PC00.SPI0",  // SPI host controller
                    0                               // Must be 0
                )
                GpioInt (Edge, ActiveLow, ExclusiveAndWake, PullDefault, 0,
                    "\\_SB.GPI0", 0, ResourceConsumer, ,
                    )
                    {
                       2
                    }
            })
            Name (_DSD, Package ()
            {
                ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
                Package ()
                {
                    Package () {"rxint-gpios", Package () { ^CAN0, 0, 0, 0 } },
                    Package (2) {"clock-frequency",  40000000 }
                }
            })
         }
     }
 }

Signed-off-by: Stefano Offredi <stefano.offredi@xxxxxxxxx>
Signed-off-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>
---
This is a continuation of Stefano Offredi's work. For easier review
I've rebased the patch to current net-next/main and fixed the
indention.
---
Changes in v2:
- rebased to net-next/main
- fix indention
---
 drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 34 ++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
index 3bc56517fe7a99d96dd43750a8ddd21961138e41..ee066dc2fdaa97ebadb5dc975957426c563adc9e 100644
--- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
+++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
@@ -12,6 +12,9 @@
 // Copyright (c) 2019 Martin Sperl <kernel@xxxxxxxxxxxxxxxx>
 //
 
+#ifdef CONFIG_ACPI
+#include <linux/acpi.h>
+#endif
 #include <linux/unaligned.h>
 #include <linux/bitfield.h>
 #include <linux/clk.h>
@@ -2002,6 +2005,23 @@ static const struct spi_device_id mcp251xfd_id_table[] = {
 };
 MODULE_DEVICE_TABLE(spi, mcp251xfd_id_table);
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id  mcp251xfd_acpi_id_table[] = {
+	{ "MCP2517", .driver_data = (kernel_ulong_t)&mcp251xfd_devtype_data_mcp2517fd, },
+	{ "MCP2518", .driver_data = (kernel_ulong_t)&mcp251xfd_devtype_data_mcp2518fd, },
+	{ "MCP251X", .driver_data = (kernel_ulong_t)&mcp251xfd_devtype_data_mcp251xfd, },
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, mcp251xfd_acpi_id_table);
+
+static const struct acpi_gpio_params rx_int_gpios = { 1, 0, false };
+
+static const struct acpi_gpio_mapping acpi_mcp251xfd_gpios[] = {
+	{ "rx-int-gpios", &rx_int_gpios, 1 },
+	{},
+};
+#endif
+
 static int mcp251xfd_probe(struct spi_device *spi)
 {
 	struct net_device *ndev;
@@ -2012,11 +2032,20 @@ static int mcp251xfd_probe(struct spi_device *spi)
 	bool pll_enable = false;
 	u32 freq = 0;
 	int err;
+	int ret;
 
 	if (!spi->irq)
 		return dev_err_probe(&spi->dev, -ENXIO,
 				     "No IRQ specified (maybe node \"interrupts-extended\" in DT missing)!\n");
 
+#ifdef CONFIG_ACPI
+	ret = devm_acpi_dev_add_driver_gpios(&spi->dev, acpi_mcp251xfd_gpios);
+	if (ret) {
+		dev_dbg(&spi->dev, "failed to add gpios mapping table\n");
+		return ret;
+	}
+#endif
+
 	rx_int = devm_gpiod_get_optional(&spi->dev, "microchip,rx-int",
 					 GPIOD_IN);
 	if (IS_ERR(rx_int))
@@ -2049,6 +2078,8 @@ static int mcp251xfd_probe(struct spi_device *spi)
 		if (err)
 			return dev_err_probe(&spi->dev, err,
 					     "Failed to get clock-frequency!\n");
+
+		dev_dbg(&spi->dev, "using clock-frequency %d Hz\n", freq);
 	}
 
 	/* Sanity check */
@@ -2204,6 +2235,9 @@ static struct spi_driver mcp251xfd_driver = {
 		.name = DEVICE_NAME,
 		.pm = &mcp251xfd_pm_ops,
 		.of_match_table = mcp251xfd_of_match,
+#ifdef CONFIG_ACPI
+		.acpi_match_table = ACPI_PTR(mcp251xfd_acpi_id_table),
+#endif
 	},
 	.probe = mcp251xfd_probe,
 	.remove = mcp251xfd_remove,

---
base-commit: a0e1fc921cb0651cd11469bf5378ec342bf7094d
change-id: 20241209-mcp251xfd-acpi-79b57084512f

Best regards,
-- 
Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>






[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux