Skip to content

Commit a9c6920

Browse files
Pavel Machekmarckleinebudde
authored andcommitted
can: c_can: add hwinit support for non-TI devices
Non-TI chips (including socfpga) needs different raminit sequence. Implement it. Tested-by: Thor Thayer <tthayer@altera.com> Signed-off-by: Thor Thayer <tthayer@altera.com> Signed-off-by: Pavel Machek <pavel@denx.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent ccbc535 commit a9c6920

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

drivers/net/can/c_can/c_can.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ enum reg {
7878
C_CAN_INTPND2_REG,
7979
C_CAN_MSGVAL1_REG,
8080
C_CAN_MSGVAL2_REG,
81+
C_CAN_FUNCTION_REG,
8182
};
8283

8384
static const u16 reg_map_c_can[] = {
@@ -129,6 +130,7 @@ static const u16 reg_map_d_can[] = {
129130
[C_CAN_BRPEXT_REG] = 0x0E,
130131
[C_CAN_INT_REG] = 0x10,
131132
[C_CAN_TEST_REG] = 0x14,
133+
[C_CAN_FUNCTION_REG] = 0x18,
132134
[C_CAN_TXRQST1_REG] = 0x88,
133135
[C_CAN_TXRQST2_REG] = 0x8A,
134136
[C_CAN_NEWDAT1_REG] = 0x9C,

drivers/net/can/c_can/c_can_platform.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define CAN_RAMINIT_START_MASK(i) (0x001 << (i))
4141
#define CAN_RAMINIT_DONE_MASK(i) (0x100 << (i))
4242
#define CAN_RAMINIT_ALL_MASK(i) (0x101 << (i))
43+
#define DCAN_RAM_INIT_BIT (1 << 3)
4344
static DEFINE_SPINLOCK(raminit_lock);
4445
/*
4546
* 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,
8081
udelay(1);
8182
}
8283

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)
8485
{
8586
u32 mask = CAN_RAMINIT_ALL_MASK(priv->instance);
8687
u32 ctrl;
@@ -96,14 +97,14 @@ static void c_can_hw_raminit(const struct c_can_priv *priv, bool enable)
9697
ctrl |= CAN_RAMINIT_DONE_MASK(priv->instance);
9798
writel(ctrl, priv->raminit_ctrlreg);
9899
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);
100101

101102
if (enable) {
102103
/* Set start bit and wait for the done bit. */
103104
ctrl |= CAN_RAMINIT_START_MASK(priv->instance);
104105
writel(ctrl, priv->raminit_ctrlreg);
105106
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);
107108
}
108109
spin_unlock(&raminit_lock);
109110
}
@@ -136,6 +137,28 @@ static void d_can_plat_write_reg32(const struct c_can_priv *priv, enum reg index
136137
writel(val, priv->base + priv->regs[index]);
137138
}
138139

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+
139162
static struct platform_device_id c_can_id_table[] = {
140163
[BOSCH_C_CAN_PLATFORM] = {
141164
.name = KBUILD_MODNAME,
@@ -255,11 +278,20 @@ static int c_can_plat_probe(struct platform_device *pdev)
255278
priv->instance = pdev->id;
256279

257280
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+
258290
priv->raminit_ctrlreg = devm_ioremap_resource(&pdev->dev, res);
259291
if (IS_ERR(priv->raminit_ctrlreg) || priv->instance < 0)
260292
dev_info(&pdev->dev, "control memory is not used for raminit\n");
261293
else
262-
priv->raminit = c_can_hw_raminit;
294+
priv->raminit = c_can_hw_raminit_ti;
263295
break;
264296
default:
265297
ret = -EINVAL;

0 commit comments

Comments
 (0)