can: m_can: allow keeping the transceiver running in suspend
[linux-block.git] / drivers / net / can / m_can / m_can.h
CommitLineData
f524f829
DM
1/* SPDX-License-Identifier: GPL-2.0 */
2/* CAN bus driver for Bosch M_CAN controller
3 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
4 */
5
6#ifndef _CAN_M_CAN_H_
7#define _CAN_M_CAN_H_
8
9#include <linux/can/core.h>
09451f24 10#include <linux/can/dev.h>
1be37d3b 11#include <linux/can/rx-offload.h>
09451f24 12#include <linux/clk.h>
f524f829 13#include <linux/completion.h>
09451f24 14#include <linux/delay.h>
f524f829
DM
15#include <linux/device.h>
16#include <linux/dma-mapping.h>
17#include <linux/freezer.h>
b382380c 18#include <linux/hrtimer.h>
f524f829
DM
19#include <linux/interrupt.h>
20#include <linux/io.h>
09451f24 21#include <linux/iopoll.h>
f524f829
DM
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/netdevice.h>
25#include <linux/of.h>
d836cb5f 26#include <linux/phy/phy.h>
09451f24
VY
27#include <linux/pinctrl/consumer.h>
28#include <linux/pm_runtime.h>
29#include <linux/slab.h>
30#include <linux/uaccess.h>
f524f829
DM
31
32/* m_can lec values */
33enum m_can_lec_type {
34 LEC_NO_ERROR = 0,
35 LEC_STUFF_ERROR,
36 LEC_FORM_ERROR,
37 LEC_ACK_ERROR,
38 LEC_BIT1_ERROR,
39 LEC_BIT0_ERROR,
40 LEC_CRC_ERROR,
6a8836e3 41 LEC_NO_CHANGE,
f524f829
DM
42};
43
44enum m_can_mram_cfg {
45 MRAM_SIDF = 0,
46 MRAM_XIDF,
47 MRAM_RXF0,
48 MRAM_RXF1,
49 MRAM_RXB,
50 MRAM_TXE,
51 MRAM_TXB,
52 MRAM_CFG_NUM,
53};
54
55/* address offset and element number for each FIFO/Buffer in the Message RAM */
56struct mram_cfg {
57 u16 off;
58 u8 num;
59};
60
441ac340 61struct m_can_classdev;
f524f829
DM
62struct m_can_ops {
63 /* Device specific call backs */
441ac340
DM
64 int (*clear_interrupts)(struct m_can_classdev *cdev);
65 u32 (*read_reg)(struct m_can_classdev *cdev, int reg);
66 int (*write_reg)(struct m_can_classdev *cdev, int reg, int val);
e3938177 67 int (*read_fifo)(struct m_can_classdev *cdev, int addr_offset, void *val, size_t val_count);
441ac340 68 int (*write_fifo)(struct m_can_classdev *cdev, int addr_offset,
e3938177 69 const void *val, size_t val_count);
441ac340 70 int (*init)(struct m_can_classdev *cdev);
f524f829
DM
71};
72
e668673e
MSP
73struct m_can_tx_op {
74 struct m_can_classdev *cdev;
75 struct work_struct work;
76 struct sk_buff *skb;
c306c387 77 bool submit;
e668673e
MSP
78};
79
441ac340 80struct m_can_classdev {
f524f829 81 struct can_priv can;
1be37d3b 82 struct can_rx_offload offload;
f524f829
DM
83 struct napi_struct napi;
84 struct net_device *net;
85 struct device *dev;
86 struct clk *hclk;
87 struct clk *cclk;
88
89 struct workqueue_struct *tx_wq;
d836cb5f 90 struct phy *transceiver;
f524f829 91
ec390d08
MSP
92 ktime_t irq_timer_wait;
93
f524f829
DM
94 struct m_can_ops *ops;
95
f524f829 96 int version;
f524f829
DM
97 u32 irqstatus;
98
99 int pm_clock_support;
4a94d7e3 100 int pm_wake_source;
f524f829
DM
101 int is_peripheral;
102
07f25091
MSP
103 // Cached M_CAN_IE register content
104 u32 active_interrupts;
105 u32 rx_max_coalesced_frames_irq;
106 u32 rx_coalesce_usecs_irq;
c306c387 107 u32 tx_max_coalesced_frames;
ec390d08
MSP
108 u32 tx_max_coalesced_frames_irq;
109 u32 tx_coalesce_usecs_irq;
07f25091 110
80c5bac0 111 // Store this internally to avoid fetch delays on peripheral chips
e668673e
MSP
112 u32 tx_fifo_putidx;
113
1fa80e23
MSP
114 /* Protects shared state between start_xmit and m_can_isr */
115 spinlock_t tx_handling_spinlock;
116 int tx_fifo_in_flight;
117
e668673e
MSP
118 struct m_can_tx_op *tx_ops;
119 int tx_fifo_size;
120 int next_tx_op;
80c5bac0 121
c306c387
MSP
122 int nr_txs_without_submit;
123 /* bitfield of fifo elements that will be submitted together */
124 u32 tx_peripheral_submit;
125
f524f829 126 struct mram_cfg mcfg[MRAM_CFG_NUM];
b382380c
JM
127
128 struct hrtimer hrtimer;
f524f829
DM
129};
130
ac33ffd3 131struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, int sizeof_priv);
a8c22f5b 132void m_can_class_free_dev(struct net_device *net);
441ac340
DM
133int m_can_class_register(struct m_can_classdev *cdev);
134void m_can_class_unregister(struct m_can_classdev *cdev);
135int m_can_class_get_clocks(struct m_can_classdev *cdev);
e3938177 136int m_can_init_ram(struct m_can_classdev *priv);
c1b17ea7 137int m_can_check_mram_cfg(struct m_can_classdev *cdev, u32 mram_max_size);
f524f829
DM
138
139int m_can_class_suspend(struct device *dev);
140int m_can_class_resume(struct device *dev);
141#endif /* _CAN_M_H_ */