can: tcan45x: Make wake-up GPIO an optional GPIO
authorDan Murphy <dmurphy@ti.com>
Wed, 4 Dec 2019 17:51:12 +0000 (11:51 -0600)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Sun, 8 Dec 2019 11:22:01 +0000 (12:22 +0100)
The device has the ability to disable the wake-up pin option. The
wake-up pin can be either force to GND or Vsup and does not have to be
tied to a GPIO. In order for the device to not use the wake-up feature
write the register to disable the WAKE_CONFIG option.

Signed-off-by: Dan Murphy <dmurphy@ti.com>
Cc: Sean Nyekjaer <sean@geanix.com>
Reviewed-by: Sean Nyekjaer <sean@geanix.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/m_can/tcan4x5x.c

index d5d4bfa..4e1789e 100644 (file)
 #define TCAN4X5X_MODE_STANDBY BIT(6)
 #define TCAN4X5X_MODE_NORMAL BIT(7)
 
+#define TCAN4X5X_DISABLE_WAKE_MSK      (BIT(31) | BIT(30))
+
 #define TCAN4X5X_SW_RESET BIT(2)
 
 #define TCAN4X5X_MCAN_CONFIGURED BIT(5)
@@ -338,6 +340,14 @@ static int tcan4x5x_init(struct m_can_classdev *cdev)
        return ret;
 }
 
+static int tcan4x5x_disable_wake(struct m_can_classdev *cdev)
+{
+       struct tcan4x5x_priv *tcan4x5x = cdev->device_data;
+
+       return regmap_update_bits(tcan4x5x->regmap, TCAN4X5X_CONFIG,
+                                 TCAN4X5X_DISABLE_WAKE_MSK, 0x00);
+}
+
 static int tcan4x5x_parse_config(struct m_can_classdev *cdev)
 {
        struct tcan4x5x_priv *tcan4x5x = cdev->device_data;
@@ -345,8 +355,10 @@ static int tcan4x5x_parse_config(struct m_can_classdev *cdev)
        tcan4x5x->device_wake_gpio = devm_gpiod_get(cdev->dev, "device-wake",
                                                    GPIOD_OUT_HIGH);
        if (IS_ERR(tcan4x5x->device_wake_gpio)) {
-               dev_err(cdev->dev, "device-wake gpio not defined\n");
-               return -EINVAL;
+               if (PTR_ERR(tcan4x5x->power) == -EPROBE_DEFER)
+                       return -EPROBE_DEFER;
+
+               tcan4x5x_disable_wake(cdev);
        }
 
        tcan4x5x->reset_gpio = devm_gpiod_get_optional(cdev->dev, "reset",
@@ -430,10 +442,6 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 
        spi_set_drvdata(spi, priv);
 
-       ret = tcan4x5x_parse_config(mcan_class);
-       if (ret)
-               goto out_clk;
-
        /* Configure the SPI bus */
        spi->bits_per_word = 32;
        ret = spi_setup(spi);
@@ -443,6 +451,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
        priv->regmap = devm_regmap_init(&spi->dev, &tcan4x5x_bus,
                                        &spi->dev, &tcan4x5x_regmap);
 
+       ret = tcan4x5x_parse_config(mcan_class);
+       if (ret)
+               goto out_clk;
+
        tcan4x5x_power_enable(priv->power, 1);
 
        ret = m_can_class_register(mcan_class);