Skip to content

Commit 52cde85

Browse files
AnilKumar Chmarckleinebudde
authored andcommitted
can: c_can: Add d_can raminit support
Add D_CAN raminit support to C_CAN driver to enable D_CAN RAM, which holds all the message objects during transmission or receiving of data. This initialization/de-initialization should be done in synchronous with D_CAN clock. In case of AM335X-EVM (current user of D_CAN driver) message RAM is controlled through control module register for both instances. So control module register details is required to initialization or de-initialization of message RAM according to instance number. Control module memory resource is obtained from D_CAN dt node and instance number obtained from device tree aliases node. This patch was tested on AM335x-EVM along with pinctrl data addition patch, d_can dt aliases addition and control module data addition. pinctrl data addition is not added to am335x-evm.dts (only supports CPLD profile#0) because d_can1 is supported under CPLD profile#1. Signed-off-by: AnilKumar Ch <anilkumar@ti.com> [mkl: fix instance for non DT in probe, cleaned up raminit] Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent 03f52a0 commit 52cde85

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

drivers/net/can/c_can/c_can.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ static inline void c_can_pm_runtime_put_sync(const struct c_can_priv *priv)
233233
pm_runtime_put_sync(priv->device);
234234
}
235235

236+
static inline void c_can_reset_ram(const struct c_can_priv *priv, bool enable)
237+
{
238+
if (priv->raminit)
239+
priv->raminit(priv, enable);
240+
}
241+
236242
static inline int get_tx_next_msg_obj(const struct c_can_priv *priv)
237243
{
238244
return (priv->tx_next & C_CAN_NEXT_MSG_OBJ_MASK) +
@@ -1090,6 +1096,7 @@ static int c_can_open(struct net_device *dev)
10901096
struct c_can_priv *priv = netdev_priv(dev);
10911097

10921098
c_can_pm_runtime_get_sync(priv);
1099+
c_can_reset_ram(priv, true);
10931100

10941101
/* open the can device */
10951102
err = open_candev(dev);
@@ -1118,6 +1125,7 @@ static int c_can_open(struct net_device *dev)
11181125
exit_irq_fail:
11191126
close_candev(dev);
11201127
exit_open_fail:
1128+
c_can_reset_ram(priv, false);
11211129
c_can_pm_runtime_put_sync(priv);
11221130
return err;
11231131
}
@@ -1131,6 +1139,8 @@ static int c_can_close(struct net_device *dev)
11311139
c_can_stop(dev);
11321140
free_irq(dev->irq, dev);
11331141
close_candev(dev);
1142+
1143+
c_can_reset_ram(priv, false);
11341144
c_can_pm_runtime_put_sync(priv);
11351145

11361146
return 0;
@@ -1188,6 +1198,7 @@ int c_can_power_down(struct net_device *dev)
11881198

11891199
c_can_stop(dev);
11901200

1201+
c_can_reset_ram(priv, false);
11911202
c_can_pm_runtime_put_sync(priv);
11921203

11931204
return 0;
@@ -1206,6 +1217,7 @@ int c_can_power_up(struct net_device *dev)
12061217
WARN_ON(priv->type != BOSCH_D_CAN);
12071218

12081219
c_can_pm_runtime_get_sync(priv);
1220+
c_can_reset_ram(priv, true);
12091221

12101222
/* Clear PDR and INIT bits */
12111223
val = priv->read_reg(priv, C_CAN_CTRL_EX_REG);

drivers/net/can/c_can/c_can.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ struct c_can_priv {
169169
void *priv; /* for board-specific data */
170170
u16 irqstatus;
171171
enum c_can_dev_id type;
172+
u32 __iomem *raminit_ctrlreg;
173+
unsigned int instance;
174+
void (*raminit) (const struct c_can_priv *priv, bool enable);
172175
};
173176

174177
struct net_device *alloc_c_can_dev(void);

drivers/net/can/c_can/c_can_platform.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
#include "c_can.h"
4040

41+
#define CAN_RAMINIT_START_MASK(i) (1 << (i))
42+
4143
/*
4244
* 16-bit c_can registers can be arranged differently in the memory
4345
* architecture of different implementations. For example: 16-bit
@@ -68,6 +70,18 @@ static void c_can_plat_write_reg_aligned_to_32bit(struct c_can_priv *priv,
6870
writew(val, priv->base + 2 * priv->regs[index]);
6971
}
7072

73+
static void c_can_hw_raminit(const struct c_can_priv *priv, bool enable)
74+
{
75+
u32 val;
76+
77+
val = readl(priv->raminit_ctrlreg);
78+
if (enable)
79+
val |= CAN_RAMINIT_START_MASK(priv->instance);
80+
else
81+
val &= ~CAN_RAMINIT_START_MASK(priv->instance);
82+
writel(val, priv->raminit_ctrlreg);
83+
}
84+
7185
static struct platform_device_id c_can_id_table[] = {
7286
[BOSCH_C_CAN_PLATFORM] = {
7387
.name = KBUILD_MODNAME,
@@ -99,7 +113,7 @@ static int __devinit c_can_plat_probe(struct platform_device *pdev)
99113
const struct of_device_id *match;
100114
const struct platform_device_id *id;
101115
struct pinctrl *pinctrl;
102-
struct resource *mem;
116+
struct resource *mem, *res;
103117
int irq;
104118
struct clk *clk;
105119

@@ -178,6 +192,18 @@ static int __devinit c_can_plat_probe(struct platform_device *pdev)
178192
priv->can.ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES;
179193
priv->read_reg = c_can_plat_read_reg_aligned_to_16bit;
180194
priv->write_reg = c_can_plat_write_reg_aligned_to_16bit;
195+
196+
if (pdev->dev.of_node)
197+
priv->instance = of_alias_get_id(pdev->dev.of_node, "d_can");
198+
else
199+
priv->instance = pdev->id;
200+
201+
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
202+
priv->raminit_ctrlreg = devm_request_and_ioremap(&pdev->dev, res);
203+
if (!priv->raminit_ctrlreg || priv->instance < 0)
204+
dev_info(&pdev->dev, "control memory is not used for raminit\n");
205+
else
206+
priv->raminit = c_can_hw_raminit;
181207
break;
182208
default:
183209
ret = -EINVAL;

0 commit comments

Comments
 (0)