1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*******************************************************************************
3  *
4  * CTU CAN FD IP Core
5  *
6  * Copyright (C) 2015-2018 Ondrej Ille <ondrej.ille@gmail.com> FEE CTU
7  * Copyright (C) 2018-2021 Ondrej Ille <ondrej.ille@gmail.com> self-funded
8  * Copyright (C) 2018-2019 Martin Jerabek <martin.jerabek01@gmail.com> FEE CTU
9  * Copyright (C) 2018-2021 Pavel Pisa <pisa@cmp.felk.cvut.cz> FEE CTU/self-funded
10  *
11  * Project advisors:
12  *     Jiri Novak <jnovak@fel.cvut.cz>
13  *     Pavel Pisa <pisa@cmp.felk.cvut.cz>
14  *
15  * Department of Measurement         (http://meas.fel.cvut.cz/)
16  * Faculty of Electrical Engineering (http://www.fel.cvut.cz)
17  * Czech Technical University        (http://www.cvut.cz/)
18  ******************************************************************************/
19 
20 #ifndef __CTUCANFD__
21 #define __CTUCANFD__
22 
23 #include <linux/netdevice.h>
24 #include <linux/can/dev.h>
25 #include <linux/list.h>
26 
27 enum ctu_can_fd_can_registers;
28 
29 struct ctucan_priv {
30 	struct can_priv can; /* must be first member! */
31 
32 	void __iomem *mem_base;
33 	u32 (*read_reg)(struct ctucan_priv *priv,
34 			enum ctu_can_fd_can_registers reg);
35 	void (*write_reg)(struct ctucan_priv *priv,
36 			  enum ctu_can_fd_can_registers reg, u32 val);
37 
38 	unsigned int txb_head;
39 	unsigned int txb_tail;
40 	u32 txb_prio;
41 	unsigned int ntxbufs;
42 	spinlock_t tx_lock; /* spinlock to serialize allocation and processing of TX buffers */
43 
44 	struct napi_struct napi;
45 	struct device *dev;
46 	struct clk *can_clk;
47 
48 	int irq_flags;
49 	unsigned long drv_flags;
50 
51 	u32 rxfrm_first_word;
52 
53 	struct list_head peers_on_pdev;
54 };
55 
56 /**
57  * ctucan_probe_common - Device type independent registration call
58  *
59  * This function does all the memory allocation and registration for the CAN
60  * device.
61  *
62  * @dev:	Handle to the generic device structure
63  * @addr:	Base address of CTU CAN FD core address
64  * @irq:	Interrupt number
65  * @ntxbufs:	Number of implemented Tx buffers
66  * @can_clk_rate: Clock rate, if 0 then clock are taken from device node
67  * @pm_enable_call: Whether pm_runtime_enable should be called
68  * @set_drvdata_fnc: Function to set network driver data for physical device
69  *
70  * Return: 0 on success and failure value on error
71  */
72 int ctucan_probe_common(struct device *dev, void __iomem *addr,
73 			int irq, unsigned int ntxbufs,
74 			unsigned long can_clk_rate,
75 			int pm_enable_call,
76 			void (*set_drvdata_fnc)(struct device *dev,
77 						struct net_device *ndev));
78 
79 int ctucan_suspend(struct device *dev) __maybe_unused;
80 int ctucan_resume(struct device *dev) __maybe_unused;
81 
82 #endif /*__CTUCANFD__*/
83