-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
can: tcan4x5x: move regmap code into seperate file
This patch moves the regmap code into a seperate file. Reviewed-by: Dan Murphy <dmurphy@ti.com> Tested-by: Sean Nyekjaer <sean@geanix.com> Link: https://lore.kernel.org/r/20201215231746.1132907-5-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
- Loading branch information
Marc Kleine-Budde
committed
Jan 6, 2021
1 parent
7813887
commit 67def4e
Showing
4 changed files
with
133 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
// | ||
// tcan4x5x - Texas Instruments TCAN4x5x Family CAN controller driver | ||
// | ||
// Copyright (c) 2020 Pengutronix, | ||
// Marc Kleine-Budde <kernel@pengutronix.de> | ||
// Copyright (c) 2018-2019 Texas Instruments Incorporated | ||
// http://www.ti.com/ | ||
|
||
#include "tcan4x5x.h" | ||
|
||
#define TCAN4X5X_WRITE_CMD (0x61 << 24) | ||
#define TCAN4X5X_READ_CMD (0x41 << 24) | ||
|
||
#define TCAN4X5X_MAX_REGISTER 0x8fff | ||
|
||
static int regmap_spi_gather_write(void *context, const void *reg, | ||
size_t reg_len, const void *val, | ||
size_t val_len) | ||
{ | ||
struct device *dev = context; | ||
struct spi_device *spi = to_spi_device(dev); | ||
struct spi_message m; | ||
u32 addr; | ||
struct spi_transfer t[2] = { | ||
{ .tx_buf = &addr, .len = reg_len, .cs_change = 0,}, | ||
{ .tx_buf = val, .len = val_len, }, | ||
}; | ||
|
||
addr = TCAN4X5X_WRITE_CMD | (*((u16 *)reg) << 8) | val_len >> 2; | ||
|
||
spi_message_init(&m); | ||
spi_message_add_tail(&t[0], &m); | ||
spi_message_add_tail(&t[1], &m); | ||
|
||
return spi_sync(spi, &m); | ||
} | ||
|
||
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 - 4); | ||
} | ||
|
||
static int regmap_spi_async_write(void *context, | ||
const void *reg, size_t reg_len, | ||
const void *val, size_t val_len, | ||
struct regmap_async *a) | ||
{ | ||
return -ENOTSUPP; | ||
} | ||
|
||
static struct regmap_async *regmap_spi_async_alloc(void) | ||
{ | ||
return NULL; | ||
} | ||
|
||
static int tcan4x5x_regmap_read(void *context, | ||
const void *reg, size_t reg_size, | ||
void *val, size_t val_size) | ||
{ | ||
struct device *dev = context; | ||
struct spi_device *spi = to_spi_device(dev); | ||
|
||
u32 addr = TCAN4X5X_READ_CMD | (*((u16 *)reg) << 8) | val_size >> 2; | ||
|
||
return spi_write_then_read(spi, &addr, reg_size, (u32 *)val, val_size); | ||
} | ||
|
||
static const struct regmap_config tcan4x5x_regmap = { | ||
.reg_bits = 32, | ||
.val_bits = 32, | ||
.cache_type = REGCACHE_NONE, | ||
.max_register = TCAN4X5X_MAX_REGISTER, | ||
}; | ||
|
||
static struct regmap_bus tcan4x5x_bus = { | ||
.write = tcan4x5x_regmap_write, | ||
.gather_write = regmap_spi_gather_write, | ||
.async_write = regmap_spi_async_write, | ||
.async_alloc = regmap_spi_async_alloc, | ||
.read = tcan4x5x_regmap_read, | ||
.read_flag_mask = 0x00, | ||
.reg_format_endian_default = REGMAP_ENDIAN_NATIVE, | ||
.val_format_endian_default = REGMAP_ENDIAN_NATIVE, | ||
}; | ||
|
||
int tcan4x5x_regmap_init(struct tcan4x5x_priv *priv) | ||
{ | ||
priv->regmap = devm_regmap_init(&priv->spi->dev, &tcan4x5x_bus, | ||
&priv->spi->dev, &tcan4x5x_regmap); | ||
return PTR_ERR_OR_ZERO(priv->regmap); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 | ||
* | ||
* tcan4x5x - Texas Instruments TCAN4x5x Family CAN controller driver | ||
* | ||
* Copyright (c) 2020 Pengutronix, | ||
* Marc Kleine-Budde <kernel@pengutronix.de> | ||
*/ | ||
|
||
#ifndef _TCAN4X5X_H | ||
#define _TCAN4X5X_H | ||
|
||
#include <linux/gpio/consumer.h> | ||
#include <linux/regmap.h> | ||
#include <linux/regmap.h> | ||
#include <linux/regulator/consumer.h> | ||
#include <linux/spi/spi.h> | ||
|
||
#include "m_can.h" | ||
|
||
struct tcan4x5x_priv { | ||
struct m_can_classdev cdev; | ||
|
||
struct regmap *regmap; | ||
struct spi_device *spi; | ||
|
||
struct gpio_desc *reset_gpio; | ||
struct gpio_desc *device_wake_gpio; | ||
struct gpio_desc *device_state_gpio; | ||
struct regulator *power; | ||
}; | ||
|
||
int tcan4x5x_regmap_init(struct tcan4x5x_priv *priv); | ||
|
||
#endif |