summaryrefslogtreecommitdiff
path: root/drivers/net/can/spi/mcp25xxfd/mcp25xxfd_priv.h
blob: ced89e0b9e3c2b0e801389e0b5e8ee82711ad7d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* SPDX-License-Identifier: GPL-2.0 */

/* CAN bus driver for Microchip 25XXFD CAN Controller with SPI Interface
 *
 * Copyright 2019 Martin Sperl <kernel@martin.sperl.org>
 */
#ifndef __MCP25XXFD_PRIV_H
#define __MCP25XXFD_PRIV_H

#include <linux/clk.h>
#include <linux/debugfs.h>
#include <linux/gpio/driver.h>
#include <linux/mutex.h>
#include <linux/regulator/consumer.h>
#include <linux/spi/spi.h>

#include "mcp25xxfd_regs.h"

/* some defines for the driver */
#define DEVICE_NAME "mcp25xxfd"

enum mcp25xxfd_model {
	CAN_MCP2517FD	= 0x2517,
	CAN_MCP2518FD	= 0x2518,
};

struct mcp25xxfd_can_priv;
struct mcp25xxfd_priv {
	struct spi_device *spi;
	struct clk *clk;
#ifdef CONFIG_GPIOLIB
	struct gpio_chip gpio;
#endif
	struct mcp25xxfd_can_priv *cpriv;

	/* the actual model of the mcp25xxfd */
	enum mcp25xxfd_model model;

	/* full device name used for debugfs and interrupts */
	char device_name[32];

	/* everything clock related */
	int clock_freq;
	struct {
		/* clock configuration */
		int clock_pll;
		int clock_div2;
		int clock_odiv;
		int clock_allways_on;
		/* gpio related */
		bool gpio_open_drain;
		bool gpio0_xstandby;
	} config;

	/* lock for enabling/disabling the clock */
	struct mutex clk_user_lock;
	u32 clk_user_mask;
	u32 clk_sleep_mask;

	/* power related */
	struct regulator *power;

	/* the distinct spi_speeds to use for spi communication */
	u32 spi_setup_speed_hz;
	u32 spi_normal_speed_hz;
	u32 spi_use_speed_hz;

	/* spi-tx/rx buffers for efficient transfers
	 * used during setup and irq
	 */
	struct mutex spi_rxtx_lock; /* protects use of spi_tx/rx */
	u8 spi_tx[MCP25XXFD_SRAM_SIZE];
	u8 spi_rx[MCP25XXFD_SRAM_SIZE];

	/* configuration registers */
	struct {
		u32 osc;
		u32 iocon;
		u32 crc;
		u32 ecccon;
	} regs;

	/* debugfs related */
#ifdef CONFIG_CAN_MCP25XXFD_DEBUG_FS
	struct dentry *debugfs_dir;
	struct dentry *debugfs_regs_dir;
	struct {
		u64 spi_crc_read;
		u64 spi_crc_read_split;
	} stats;
#endif
};

#endif /* __MCP25XXFD_PRIV_H */