diff options
Diffstat (limited to 'drivers/net/can/m_can/tcan4x5x.c')
-rw-r--r-- | drivers/net/can/m_can/tcan4x5x.c | 53 |
1 files changed, 13 insertions, 40 deletions
diff --git a/drivers/net/can/m_can/tcan4x5x.c b/drivers/net/can/m_can/tcan4x5x.c index b115b2e5333f..3db619209fe1 100644 --- a/drivers/net/can/m_can/tcan4x5x.c +++ b/drivers/net/can/m_can/tcan4x5x.c @@ -113,12 +113,10 @@ struct tcan4x5x_priv { struct regmap *regmap; struct spi_device *spi; - struct mutex tcan4x5x_lock; /* SPI device lock */ struct m_can_classdev *mcan_dev; struct gpio_desc *reset_gpio; - struct gpio_desc *interrupt_gpio; struct gpio_desc *device_wake_gpio; struct gpio_desc *device_state_gpio; struct regulator *power; @@ -179,7 +177,7 @@ static int regmap_spi_gather_write(void *context, const void *reg, { .tx_buf = val, .len = val_len, }, }; - addr = TCAN4X5X_WRITE_CMD | (*((u16 *)reg) << 8) | val_len >> 3; + addr = TCAN4X5X_WRITE_CMD | (*((u16 *)reg) << 8) | val_len >> 2; spi_message_init(&m); spi_message_add_tail(&t[0], &m); @@ -193,7 +191,7 @@ static int tcan4x5x_regmap_write(void *context, const void *data, size_t count) u16 *reg = (u16 *)(data); const u32 *val = data + 4; - return regmap_spi_gather_write(context, reg, 4, val, count); + return regmap_spi_gather_write(context, reg, 4, val, count - 4); } static int regmap_spi_async_write(void *context, @@ -234,11 +232,9 @@ static struct regmap_bus tcan4x5x_bus = { static u32 tcan4x5x_read_reg(struct m_can_classdev *cdev, int reg) { - struct tcan4x5x_priv *priv = (struct tcan4x5x_priv *)cdev->device_data; + struct tcan4x5x_priv *priv = cdev->device_data; u32 val; - tcan4x5x_check_wake(priv); - regmap_read(priv->regmap, priv->reg_offset + reg, &val); return val; @@ -246,11 +242,9 @@ static u32 tcan4x5x_read_reg(struct m_can_classdev *cdev, int reg) static u32 tcan4x5x_read_fifo(struct m_can_classdev *cdev, int addr_offset) { - struct tcan4x5x_priv *priv = (struct tcan4x5x_priv *)cdev->device_data; + struct tcan4x5x_priv *priv = cdev->device_data; u32 val; - tcan4x5x_check_wake(priv); - regmap_read(priv->regmap, priv->mram_start + addr_offset, &val); return val; @@ -258,9 +252,7 @@ static u32 tcan4x5x_read_fifo(struct m_can_classdev *cdev, int addr_offset) static int tcan4x5x_write_reg(struct m_can_classdev *cdev, int reg, int val) { - struct tcan4x5x_priv *priv = (struct tcan4x5x_priv *)cdev->device_data; - - tcan4x5x_check_wake(priv); + struct tcan4x5x_priv *priv = cdev->device_data; return regmap_write(priv->regmap, priv->reg_offset + reg, val); } @@ -268,10 +260,7 @@ static int tcan4x5x_write_reg(struct m_can_classdev *cdev, int reg, int val) static int tcan4x5x_write_fifo(struct m_can_classdev *cdev, int addr_offset, int val) { - struct tcan4x5x_priv *priv = - (struct tcan4x5x_priv *)cdev->device_data; - - tcan4x5x_check_wake(priv); + struct tcan4x5x_priv *priv = cdev->device_data; return regmap_write(priv->regmap, priv->mram_start + addr_offset, val); } @@ -290,22 +279,15 @@ static int tcan4x5x_power_enable(struct regulator *reg, int enable) static int tcan4x5x_write_tcan_reg(struct m_can_classdev *cdev, int reg, int val) { - struct tcan4x5x_priv *priv = - (struct tcan4x5x_priv *)cdev->device_data; - - tcan4x5x_check_wake(priv); + struct tcan4x5x_priv *priv = cdev->device_data; return regmap_write(priv->regmap, reg, val); } static int tcan4x5x_clear_interrupts(struct m_can_classdev *cdev) { - struct tcan4x5x_priv *tcan4x5x = - (struct tcan4x5x_priv *)cdev->device_data; int ret; - tcan4x5x_check_wake(tcan4x5x); - ret = tcan4x5x_write_tcan_reg(cdev, TCAN4X5X_STATUS, TCAN4X5X_CLEAR_ALL_INT); if (ret) @@ -331,8 +313,7 @@ static int tcan4x5x_clear_interrupts(struct m_can_classdev *cdev) static int tcan4x5x_init(struct m_can_classdev *cdev) { - struct tcan4x5x_priv *tcan4x5x = - (struct tcan4x5x_priv *)cdev->device_data; + struct tcan4x5x_priv *tcan4x5x = cdev->device_data; int ret; tcan4x5x_check_wake(tcan4x5x); @@ -359,15 +340,7 @@ static int tcan4x5x_init(struct m_can_classdev *cdev) static int tcan4x5x_parse_config(struct m_can_classdev *cdev) { - struct tcan4x5x_priv *tcan4x5x = - (struct tcan4x5x_priv *)cdev->device_data; - - tcan4x5x->interrupt_gpio = devm_gpiod_get(cdev->dev, "data-ready", - GPIOD_IN); - if (IS_ERR(tcan4x5x->interrupt_gpio)) { - dev_err(cdev->dev, "data-ready gpio not defined\n"); - return -EINVAL; - } + struct tcan4x5x_priv *tcan4x5x = cdev->device_data; tcan4x5x->device_wake_gpio = devm_gpiod_get(cdev->dev, "device-wake", GPIOD_OUT_HIGH); @@ -387,8 +360,6 @@ static int tcan4x5x_parse_config(struct m_can_classdev *cdev) if (IS_ERR(tcan4x5x->device_state_gpio)) tcan4x5x->device_state_gpio = NULL; - cdev->net->irq = gpiod_to_irq(tcan4x5x->interrupt_gpio); - tcan4x5x->power = devm_regulator_get_optional(cdev->dev, "vsup"); if (PTR_ERR(tcan4x5x->power) == -EPROBE_DEFER) @@ -420,6 +391,9 @@ static int tcan4x5x_can_probe(struct spi_device *spi) int freq, ret; mcan_class = m_can_class_allocate_dev(&spi->dev); + if (!mcan_class) + return -ENOMEM; + priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; @@ -450,6 +424,7 @@ static int tcan4x5x_can_probe(struct spi_device *spi) mcan_class->is_peripheral = true; mcan_class->bit_timing = &tcan4x5x_bittiming_const; mcan_class->data_timing = &tcan4x5x_data_bittiming_const; + mcan_class->net->irq = spi->irq; spi_set_drvdata(spi, priv); @@ -466,8 +441,6 @@ static int tcan4x5x_can_probe(struct spi_device *spi) priv->regmap = devm_regmap_init(&spi->dev, &tcan4x5x_bus, &spi->dev, &tcan4x5x_regmap); - mutex_init(&priv->tcan4x5x_lock); - tcan4x5x_power_enable(priv->power, 1); ret = m_can_class_register(mcan_class); |