Commit 114246e8 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Marc Kleine-Budde

can: rcar_canfd: Add helper variable dev

rcar_canfd_channel_probe() and rcar_canfd_probe() have many users of
"pdev->dev".  Introduce shorthands to simplify the code.
Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/all/2965edc7992ab54dc6c862910775f3466fca6b29.1674499048.git.geert+renesas@glider.beSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent d506b151
...@@ -1715,13 +1715,14 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, ...@@ -1715,13 +1715,14 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch,
{ {
const struct rcar_canfd_hw_info *info = gpriv->info; const struct rcar_canfd_hw_info *info = gpriv->info;
struct platform_device *pdev = gpriv->pdev; struct platform_device *pdev = gpriv->pdev;
struct device *dev = &pdev->dev;
struct rcar_canfd_channel *priv; struct rcar_canfd_channel *priv;
struct net_device *ndev; struct net_device *ndev;
int err = -ENODEV; int err = -ENODEV;
ndev = alloc_candev(sizeof(*priv), RCANFD_FIFO_DEPTH); ndev = alloc_candev(sizeof(*priv), RCANFD_FIFO_DEPTH);
if (!ndev) { if (!ndev) {
dev_err(&pdev->dev, "alloc_candev() failed\n"); dev_err(dev, "alloc_candev() failed\n");
return -ENOMEM; return -ENOMEM;
} }
priv = netdev_priv(ndev); priv = netdev_priv(ndev);
...@@ -1734,7 +1735,7 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, ...@@ -1734,7 +1735,7 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch,
priv->channel = ch; priv->channel = ch;
priv->gpriv = gpriv; priv->gpriv = gpriv;
priv->can.clock.freq = fcan_freq; priv->can.clock.freq = fcan_freq;
dev_info(&pdev->dev, "can_clk rate is %u\n", priv->can.clock.freq); dev_info(dev, "can_clk rate is %u\n", priv->can.clock.freq);
if (info->multi_channel_irqs) { if (info->multi_channel_irqs) {
char *irq_name; char *irq_name;
...@@ -1753,31 +1754,31 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, ...@@ -1753,31 +1754,31 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch,
goto fail; goto fail;
} }
irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, irq_name = devm_kasprintf(dev, GFP_KERNEL, "canfd.ch%d_err",
"canfd.ch%d_err", ch); ch);
if (!irq_name) { if (!irq_name) {
err = -ENOMEM; err = -ENOMEM;
goto fail; goto fail;
} }
err = devm_request_irq(&pdev->dev, err_irq, err = devm_request_irq(dev, err_irq,
rcar_canfd_channel_err_interrupt, 0, rcar_canfd_channel_err_interrupt, 0,
irq_name, priv); irq_name, priv);
if (err) { if (err) {
dev_err(&pdev->dev, "devm_request_irq CH Err(%d) failed, error %d\n", dev_err(dev, "devm_request_irq CH Err(%d) failed, error %d\n",
err_irq, err); err_irq, err);
goto fail; goto fail;
} }
irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, irq_name = devm_kasprintf(dev, GFP_KERNEL, "canfd.ch%d_trx",
"canfd.ch%d_trx", ch); ch);
if (!irq_name) { if (!irq_name) {
err = -ENOMEM; err = -ENOMEM;
goto fail; goto fail;
} }
err = devm_request_irq(&pdev->dev, tx_irq, err = devm_request_irq(dev, tx_irq,
rcar_canfd_channel_tx_interrupt, 0, rcar_canfd_channel_tx_interrupt, 0,
irq_name, priv); irq_name, priv);
if (err) { if (err) {
dev_err(&pdev->dev, "devm_request_irq Tx (%d) failed, error %d\n", dev_err(dev, "devm_request_irq Tx (%d) failed, error %d\n",
tx_irq, err); tx_irq, err);
goto fail; goto fail;
} }
...@@ -1801,7 +1802,7 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, ...@@ -1801,7 +1802,7 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch,
priv->can.do_set_mode = rcar_canfd_do_set_mode; priv->can.do_set_mode = rcar_canfd_do_set_mode;
priv->can.do_get_berr_counter = rcar_canfd_get_berr_counter; priv->can.do_get_berr_counter = rcar_canfd_get_berr_counter;
SET_NETDEV_DEV(ndev, &pdev->dev); SET_NETDEV_DEV(ndev, dev);
netif_napi_add_weight(ndev, &priv->napi, rcar_canfd_rx_poll, netif_napi_add_weight(ndev, &priv->napi, rcar_canfd_rx_poll,
RCANFD_NAPI_WEIGHT); RCANFD_NAPI_WEIGHT);
...@@ -1809,11 +1810,10 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, ...@@ -1809,11 +1810,10 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch,
gpriv->ch[priv->channel] = priv; gpriv->ch[priv->channel] = priv;
err = register_candev(ndev); err = register_candev(ndev);
if (err) { if (err) {
dev_err(&pdev->dev, dev_err(dev, "register_candev() failed, error %d\n", err);
"register_candev() failed, error %d\n", err);
goto fail_candev; goto fail_candev;
} }
dev_info(&pdev->dev, "device registered (channel %u)\n", priv->channel); dev_info(dev, "device registered (channel %u)\n", priv->channel);
return 0; return 0;
fail_candev: fail_candev:
...@@ -1837,6 +1837,7 @@ static void rcar_canfd_channel_remove(struct rcar_canfd_global *gpriv, u32 ch) ...@@ -1837,6 +1837,7 @@ static void rcar_canfd_channel_remove(struct rcar_canfd_global *gpriv, u32 ch)
static int rcar_canfd_probe(struct platform_device *pdev) static int rcar_canfd_probe(struct platform_device *pdev)
{ {
const struct rcar_canfd_hw_info *info; const struct rcar_canfd_hw_info *info;
struct device *dev = &pdev->dev;
void __iomem *addr; void __iomem *addr;
u32 sts, ch, fcan_freq; u32 sts, ch, fcan_freq;
struct rcar_canfd_global *gpriv; struct rcar_canfd_global *gpriv;
...@@ -1848,14 +1849,14 @@ static int rcar_canfd_probe(struct platform_device *pdev) ...@@ -1848,14 +1849,14 @@ static int rcar_canfd_probe(struct platform_device *pdev)
char name[9] = "channelX"; char name[9] = "channelX";
int i; int i;
info = of_device_get_match_data(&pdev->dev); info = of_device_get_match_data(dev);
if (of_property_read_bool(pdev->dev.of_node, "renesas,no-can-fd")) if (of_property_read_bool(dev->of_node, "renesas,no-can-fd"))
fdmode = false; /* Classical CAN only mode */ fdmode = false; /* Classical CAN only mode */
for (i = 0; i < info->max_channels; ++i) { for (i = 0; i < info->max_channels; ++i) {
name[7] = '0' + i; name[7] = '0' + i;
of_child = of_get_child_by_name(pdev->dev.of_node, name); of_child = of_get_child_by_name(dev->of_node, name);
if (of_child && of_device_is_available(of_child)) if (of_child && of_device_is_available(of_child))
channels_mask |= BIT(i); channels_mask |= BIT(i);
of_node_put(of_child); of_node_put(of_child);
...@@ -1888,7 +1889,7 @@ static int rcar_canfd_probe(struct platform_device *pdev) ...@@ -1888,7 +1889,7 @@ static int rcar_canfd_probe(struct platform_device *pdev)
} }
/* Global controller context */ /* Global controller context */
gpriv = devm_kzalloc(&pdev->dev, sizeof(*gpriv), GFP_KERNEL); gpriv = devm_kzalloc(dev, sizeof(*gpriv), GFP_KERNEL);
if (!gpriv) if (!gpriv)
return -ENOMEM; return -ENOMEM;
...@@ -1897,32 +1898,30 @@ static int rcar_canfd_probe(struct platform_device *pdev) ...@@ -1897,32 +1898,30 @@ static int rcar_canfd_probe(struct platform_device *pdev)
gpriv->fdmode = fdmode; gpriv->fdmode = fdmode;
gpriv->info = info; gpriv->info = info;
gpriv->rstc1 = devm_reset_control_get_optional_exclusive(&pdev->dev, gpriv->rstc1 = devm_reset_control_get_optional_exclusive(dev, "rstp_n");
"rstp_n");
if (IS_ERR(gpriv->rstc1)) if (IS_ERR(gpriv->rstc1))
return dev_err_probe(&pdev->dev, PTR_ERR(gpriv->rstc1), return dev_err_probe(dev, PTR_ERR(gpriv->rstc1),
"failed to get rstp_n\n"); "failed to get rstp_n\n");
gpriv->rstc2 = devm_reset_control_get_optional_exclusive(&pdev->dev, gpriv->rstc2 = devm_reset_control_get_optional_exclusive(dev, "rstc_n");
"rstc_n");
if (IS_ERR(gpriv->rstc2)) if (IS_ERR(gpriv->rstc2))
return dev_err_probe(&pdev->dev, PTR_ERR(gpriv->rstc2), return dev_err_probe(dev, PTR_ERR(gpriv->rstc2),
"failed to get rstc_n\n"); "failed to get rstc_n\n");
/* Peripheral clock */ /* Peripheral clock */
gpriv->clkp = devm_clk_get(&pdev->dev, "fck"); gpriv->clkp = devm_clk_get(dev, "fck");
if (IS_ERR(gpriv->clkp)) if (IS_ERR(gpriv->clkp))
return dev_err_probe(&pdev->dev, PTR_ERR(gpriv->clkp), return dev_err_probe(dev, PTR_ERR(gpriv->clkp),
"cannot get peripheral clock\n"); "cannot get peripheral clock\n");
/* fCAN clock: Pick External clock. If not available fallback to /* fCAN clock: Pick External clock. If not available fallback to
* CANFD clock * CANFD clock
*/ */
gpriv->can_clk = devm_clk_get(&pdev->dev, "can_clk"); gpriv->can_clk = devm_clk_get(dev, "can_clk");
if (IS_ERR(gpriv->can_clk) || (clk_get_rate(gpriv->can_clk) == 0)) { if (IS_ERR(gpriv->can_clk) || (clk_get_rate(gpriv->can_clk) == 0)) {
gpriv->can_clk = devm_clk_get(&pdev->dev, "canfd"); gpriv->can_clk = devm_clk_get(dev, "canfd");
if (IS_ERR(gpriv->can_clk)) if (IS_ERR(gpriv->can_clk))
return dev_err_probe(&pdev->dev, PTR_ERR(gpriv->can_clk), return dev_err_probe(dev, PTR_ERR(gpriv->can_clk),
"cannot get canfd clock\n"); "cannot get canfd clock\n");
gpriv->fcan = RCANFD_CANFDCLK; gpriv->fcan = RCANFD_CANFDCLK;
...@@ -1945,39 +1944,38 @@ static int rcar_canfd_probe(struct platform_device *pdev) ...@@ -1945,39 +1944,38 @@ static int rcar_canfd_probe(struct platform_device *pdev)
/* Request IRQ that's common for both channels */ /* Request IRQ that's common for both channels */
if (info->shared_global_irqs) { if (info->shared_global_irqs) {
err = devm_request_irq(&pdev->dev, ch_irq, err = devm_request_irq(dev, ch_irq,
rcar_canfd_channel_interrupt, 0, rcar_canfd_channel_interrupt, 0,
"canfd.ch_int", gpriv); "canfd.ch_int", gpriv);
if (err) { if (err) {
dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n", dev_err(dev, "devm_request_irq(%d) failed, error %d\n",
ch_irq, err); ch_irq, err);
goto fail_dev; goto fail_dev;
} }
err = devm_request_irq(&pdev->dev, g_irq, err = devm_request_irq(dev, g_irq, rcar_canfd_global_interrupt,
rcar_canfd_global_interrupt, 0, 0, "canfd.g_int", gpriv);
"canfd.g_int", gpriv);
if (err) { if (err) {
dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n", dev_err(dev, "devm_request_irq(%d) failed, error %d\n",
g_irq, err); g_irq, err);
goto fail_dev; goto fail_dev;
} }
} else { } else {
err = devm_request_irq(&pdev->dev, g_recc_irq, err = devm_request_irq(dev, g_recc_irq,
rcar_canfd_global_receive_fifo_interrupt, 0, rcar_canfd_global_receive_fifo_interrupt, 0,
"canfd.g_recc", gpriv); "canfd.g_recc", gpriv);
if (err) { if (err) {
dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n", dev_err(dev, "devm_request_irq(%d) failed, error %d\n",
g_recc_irq, err); g_recc_irq, err);
goto fail_dev; goto fail_dev;
} }
err = devm_request_irq(&pdev->dev, g_err_irq, err = devm_request_irq(dev, g_err_irq,
rcar_canfd_global_err_interrupt, 0, rcar_canfd_global_err_interrupt, 0,
"canfd.g_err", gpriv); "canfd.g_err", gpriv);
if (err) { if (err) {
dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n", dev_err(dev, "devm_request_irq(%d) failed, error %d\n",
g_err_irq, err); g_err_irq, err);
goto fail_dev; goto fail_dev;
} }
...@@ -1995,14 +1993,14 @@ static int rcar_canfd_probe(struct platform_device *pdev) ...@@ -1995,14 +1993,14 @@ static int rcar_canfd_probe(struct platform_device *pdev)
/* Enable peripheral clock for register access */ /* Enable peripheral clock for register access */
err = clk_prepare_enable(gpriv->clkp); err = clk_prepare_enable(gpriv->clkp);
if (err) { if (err) {
dev_err(&pdev->dev, dev_err(dev, "failed to enable peripheral clock, error %d\n",
"failed to enable peripheral clock, error %d\n", err); err);
goto fail_reset; goto fail_reset;
} }
err = rcar_canfd_reset_controller(gpriv); err = rcar_canfd_reset_controller(gpriv);
if (err) { if (err) {
dev_err(&pdev->dev, "reset controller failed\n"); dev_err(dev, "reset controller failed\n");
goto fail_clk; goto fail_clk;
} }
...@@ -2032,7 +2030,7 @@ static int rcar_canfd_probe(struct platform_device *pdev) ...@@ -2032,7 +2030,7 @@ static int rcar_canfd_probe(struct platform_device *pdev)
err = readl_poll_timeout((gpriv->base + RCANFD_GSTS), sts, err = readl_poll_timeout((gpriv->base + RCANFD_GSTS), sts,
!(sts & RCANFD_GSTS_GNOPM), 2, 500000); !(sts & RCANFD_GSTS_GNOPM), 2, 500000);
if (err) { if (err) {
dev_err(&pdev->dev, "global operational mode failed\n"); dev_err(dev, "global operational mode failed\n");
goto fail_mode; goto fail_mode;
} }
...@@ -2043,7 +2041,7 @@ static int rcar_canfd_probe(struct platform_device *pdev) ...@@ -2043,7 +2041,7 @@ static int rcar_canfd_probe(struct platform_device *pdev)
} }
platform_set_drvdata(pdev, gpriv); platform_set_drvdata(pdev, gpriv);
dev_info(&pdev->dev, "global operational state (clk %d, fdmode %d)\n", dev_info(dev, "global operational state (clk %d, fdmode %d)\n",
gpriv->fcan, gpriv->fdmode); gpriv->fcan, gpriv->fdmode);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment