40
40
#define CAN_RAMINIT_START_MASK (i ) (0x001 << (i))
41
41
#define CAN_RAMINIT_DONE_MASK (i ) (0x100 << (i))
42
42
#define CAN_RAMINIT_ALL_MASK (i ) (0x101 << (i))
43
+ #define DCAN_RAM_INIT_BIT (1 << 3)
43
44
static DEFINE_SPINLOCK (raminit_lock );
44
45
/*
45
46
* 16-bit c_can registers can be arranged differently in the memory
@@ -80,7 +81,7 @@ static void c_can_hw_raminit_wait_ti(const struct c_can_priv *priv, u32 mask,
80
81
udelay (1 );
81
82
}
82
83
83
- static void c_can_hw_raminit (const struct c_can_priv * priv , bool enable )
84
+ static void c_can_hw_raminit_ti (const struct c_can_priv * priv , bool enable )
84
85
{
85
86
u32 mask = CAN_RAMINIT_ALL_MASK (priv -> instance );
86
87
u32 ctrl ;
@@ -96,14 +97,14 @@ static void c_can_hw_raminit(const struct c_can_priv *priv, bool enable)
96
97
ctrl |= CAN_RAMINIT_DONE_MASK (priv -> instance );
97
98
writel (ctrl , priv -> raminit_ctrlreg );
98
99
ctrl &= ~CAN_RAMINIT_DONE_MASK (priv -> instance );
99
- c_can_hw_raminit_wait (priv , ctrl , mask );
100
+ c_can_hw_raminit_wait_ti (priv , ctrl , mask );
100
101
101
102
if (enable ) {
102
103
/* Set start bit and wait for the done bit. */
103
104
ctrl |= CAN_RAMINIT_START_MASK (priv -> instance );
104
105
writel (ctrl , priv -> raminit_ctrlreg );
105
106
ctrl |= CAN_RAMINIT_DONE_MASK (priv -> instance );
106
- c_can_hw_raminit_wait (priv , ctrl , mask );
107
+ c_can_hw_raminit_wait_ti (priv , ctrl , mask );
107
108
}
108
109
spin_unlock (& raminit_lock );
109
110
}
@@ -136,6 +137,28 @@ static void d_can_plat_write_reg32(const struct c_can_priv *priv, enum reg index
136
137
writel (val , priv -> base + priv -> regs [index ]);
137
138
}
138
139
140
+ static void c_can_hw_raminit_wait (const struct c_can_priv * priv , u32 mask )
141
+ {
142
+ while (priv -> read_reg32 (priv , C_CAN_FUNCTION_REG ) & mask )
143
+ udelay (1 );
144
+ }
145
+
146
+ static void c_can_hw_raminit (const struct c_can_priv * priv , bool enable )
147
+ {
148
+ u32 ctrl ;
149
+
150
+ ctrl = priv -> read_reg32 (priv , C_CAN_FUNCTION_REG );
151
+ ctrl &= ~DCAN_RAM_INIT_BIT ;
152
+ priv -> write_reg32 (priv , C_CAN_FUNCTION_REG , ctrl );
153
+ c_can_hw_raminit_wait (priv , ctrl );
154
+
155
+ if (enable ) {
156
+ ctrl |= DCAN_RAM_INIT_BIT ;
157
+ priv -> write_reg32 (priv , C_CAN_FUNCTION_REG , ctrl );
158
+ c_can_hw_raminit_wait (priv , ctrl );
159
+ }
160
+ }
161
+
139
162
static struct platform_device_id c_can_id_table [] = {
140
163
[BOSCH_C_CAN_PLATFORM ] = {
141
164
.name = KBUILD_MODNAME ,
@@ -255,11 +278,20 @@ static int c_can_plat_probe(struct platform_device *pdev)
255
278
priv -> instance = pdev -> id ;
256
279
257
280
res = platform_get_resource (pdev , IORESOURCE_MEM , 1 );
281
+ /* Not all D_CAN modules have a separate register for the D_CAN
282
+ * RAM initialization. Use default RAM init bit in D_CAN module
283
+ * if not specified in DT.
284
+ */
285
+ if (!res ) {
286
+ priv -> raminit = c_can_hw_raminit ;
287
+ break ;
288
+ }
289
+
258
290
priv -> raminit_ctrlreg = devm_ioremap_resource (& pdev -> dev , res );
259
291
if (IS_ERR (priv -> raminit_ctrlreg ) || priv -> instance < 0 )
260
292
dev_info (& pdev -> dev , "control memory is not used for raminit\n" );
261
293
else
262
- priv -> raminit = c_can_hw_raminit ;
294
+ priv -> raminit = c_can_hw_raminit_ti ;
263
295
break ;
264
296
default :
265
297
ret = - EINVAL ;
0 commit comments