Skip to content

Commit a43a072

Browse files
committed
Merge tag 'linux-can-next-for-5.17-20211208' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next
Marc Kleine-Budde says: ==================== can-next 2021-12-08 The first patch is by Vincent Mailhol and replaces the custom CAN units with generic one form linux/units.h. The next 3 patches are by Evgeny Boger and add Allwinner R40 support to the sun4i CAN driver. Andy Shevchenko contributes 4 patches to the hi311x CAN driver, consisting of cleanups and converting the driver to the device property API. * tag 'linux-can-next-for-5.17-20211208' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next: can: hi311x: hi3110_can_probe(): convert to use dev_err_probe() can: hi311x: hi3110_can_probe(): make use of device property API can: hi311x: hi3110_can_probe(): try to get crystal clock rate from property can: hi311x: hi3110_can_probe(): use devm_clk_get_optional() to get the input clock ARM: dts: sun8i: r40: add node for CAN controller can: sun4i_can: add support for R40 CAN controller dt-bindings: net: can: add support for Allwinner R40 CAN controller can: bittiming: replace CAN units with the generic ones from linux/units.h ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 3a262c7 + 6a93ea3 commit a43a072

File tree

8 files changed

+138
-41
lines changed

8 files changed

+138
-41
lines changed

Documentation/devicetree/bindings/net/can/allwinner,sun4i-a10-can.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ properties:
1717
- const: allwinner,sun7i-a20-can
1818
- const: allwinner,sun4i-a10-can
1919
- const: allwinner,sun4i-a10-can
20+
- const: allwinner,sun8i-r40-can
2021

2122
reg:
2223
maxItems: 1
@@ -27,6 +28,19 @@ properties:
2728
clocks:
2829
maxItems: 1
2930

31+
resets:
32+
maxItems: 1
33+
34+
if:
35+
properties:
36+
compatible:
37+
contains:
38+
const: allwinner,sun8i-r40-can
39+
40+
then:
41+
required:
42+
- resets
43+
3044
required:
3145
- compatible
3246
- reg
@@ -47,5 +61,15 @@ examples:
4761
interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
4862
clocks = <&ccu CLK_APB1_CAN>;
4963
};
64+
- |
65+
#define RST_BUS_CAN 68
66+
#define CLK_BUS_CAN 91
67+
can1: can@1c2bc00 {
68+
compatible = "allwinner,sun8i-r40-can";
69+
reg = <0x01c2bc00 0x400>;
70+
interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
71+
clocks = <&ccu CLK_BUS_CAN>;
72+
resets = <&ccu RST_BUS_CAN>;
73+
};
5074
5175
...

arch/arm/boot/dts/sun8i-r40.dtsi

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,16 @@
511511
#interrupt-cells = <3>;
512512
#gpio-cells = <3>;
513513

514+
can_ph_pins: can-ph-pins {
515+
pins = "PH20", "PH21";
516+
function = "can";
517+
};
518+
519+
can_pa_pins: can-pa-pins {
520+
pins = "PA16", "PA17";
521+
function = "can";
522+
};
523+
514524
clk_out_a_pin: clk-out-a-pin {
515525
pins = "PI12";
516526
function = "clk_out_a";
@@ -926,6 +936,15 @@
926936
#size-cells = <0>;
927937
};
928938

939+
can0: can@1c2bc00 {
940+
compatible = "allwinner,sun8i-r40-can";
941+
reg = <0x01c2bc00 0x400>;
942+
interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
943+
clocks = <&ccu CLK_BUS_CAN>;
944+
resets = <&ccu RST_BUS_CAN>;
945+
status = "disabled";
946+
};
947+
929948
i2c4: i2c@1c2c000 {
930949
compatible = "allwinner,sun6i-a31-i2c";
931950
reg = <0x01c2c000 0x400>;

drivers/net/can/dev/bittiming.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (C) 2008-2009 Wolfgang Grandegger <[email protected]>
55
*/
66

7+
#include <linux/units.h>
78
#include <linux/can/dev.h>
89

910
#ifdef CONFIG_CAN_CALC_BITTIMING
@@ -81,9 +82,9 @@ int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
8182
if (bt->sample_point) {
8283
sample_point_nominal = bt->sample_point;
8384
} else {
84-
if (bt->bitrate > 800 * CAN_KBPS)
85+
if (bt->bitrate > 800 * KILO /* BPS */)
8586
sample_point_nominal = 750;
86-
else if (bt->bitrate > 500 * CAN_KBPS)
87+
else if (bt->bitrate > 500 * KILO /* BPS */)
8788
sample_point_nominal = 800;
8889
else
8990
sample_point_nominal = 875;

drivers/net/can/spi/hi311x.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
#include <linux/interrupt.h>
2626
#include <linux/io.h>
2727
#include <linux/kernel.h>
28+
#include <linux/mod_devicetable.h>
2829
#include <linux/module.h>
2930
#include <linux/netdevice.h>
30-
#include <linux/of.h>
31-
#include <linux/of_device.h>
3231
#include <linux/platform_device.h>
32+
#include <linux/property.h>
3333
#include <linux/regulator/consumer.h>
3434
#include <linux/slab.h>
3535
#include <linux/spi/spi.h>
@@ -828,19 +828,25 @@ MODULE_DEVICE_TABLE(spi, hi3110_id_table);
828828

829829
static int hi3110_can_probe(struct spi_device *spi)
830830
{
831-
const struct of_device_id *of_id = of_match_device(hi3110_of_match,
832-
&spi->dev);
831+
struct device *dev = &spi->dev;
833832
struct net_device *net;
834833
struct hi3110_priv *priv;
834+
const void *match;
835835
struct clk *clk;
836-
int freq, ret;
836+
u32 freq;
837+
int ret;
838+
839+
clk = devm_clk_get_optional(&spi->dev, NULL);
840+
if (IS_ERR(clk))
841+
return dev_err_probe(dev, PTR_ERR(clk), "no CAN clock source defined\n");
837842

838-
clk = devm_clk_get(&spi->dev, NULL);
839-
if (IS_ERR(clk)) {
840-
dev_err(&spi->dev, "no CAN clock source defined\n");
841-
return PTR_ERR(clk);
843+
if (clk) {
844+
freq = clk_get_rate(clk);
845+
} else {
846+
ret = device_property_read_u32(dev, "clock-frequency", &freq);
847+
if (ret)
848+
return dev_err_probe(dev, ret, "Failed to get clock-frequency!\n");
842849
}
843-
freq = clk_get_rate(clk);
844850

845851
/* Sanity check */
846852
if (freq > 40000000)
@@ -851,11 +857,9 @@ static int hi3110_can_probe(struct spi_device *spi)
851857
if (!net)
852858
return -ENOMEM;
853859

854-
if (!IS_ERR(clk)) {
855-
ret = clk_prepare_enable(clk);
856-
if (ret)
857-
goto out_free;
858-
}
860+
ret = clk_prepare_enable(clk);
861+
if (ret)
862+
goto out_free;
859863

860864
net->netdev_ops = &hi3110_netdev_ops;
861865
net->flags |= IFF_ECHO;
@@ -870,8 +874,9 @@ static int hi3110_can_probe(struct spi_device *spi)
870874
CAN_CTRLMODE_LISTENONLY |
871875
CAN_CTRLMODE_BERR_REPORTING;
872876

873-
if (of_id)
874-
priv->model = (enum hi3110_model)(uintptr_t)of_id->data;
877+
match = device_get_match_data(dev);
878+
if (match)
879+
priv->model = (enum hi3110_model)(uintptr_t)match;
875880
else
876881
priv->model = spi_get_device_id(spi)->driver_data;
877882
priv->net = net;
@@ -918,9 +923,7 @@ static int hi3110_can_probe(struct spi_device *spi)
918923

919924
ret = hi3110_hw_probe(spi);
920925
if (ret) {
921-
if (ret == -ENODEV)
922-
dev_err(&spi->dev, "Cannot initialize %x. Wrong wiring?\n",
923-
priv->model);
926+
dev_err_probe(dev, ret, "Cannot initialize %x. Wrong wiring?\n", priv->model);
924927
goto error_probe;
925928
}
926929
hi3110_hw_sleep(spi);
@@ -938,14 +941,12 @@ static int hi3110_can_probe(struct spi_device *spi)
938941
hi3110_power_enable(priv->power, 0);
939942

940943
out_clk:
941-
if (!IS_ERR(clk))
942-
clk_disable_unprepare(clk);
944+
clk_disable_unprepare(clk);
943945

944946
out_free:
945947
free_candev(net);
946948

947-
dev_err(&spi->dev, "Probe failed, err=%d\n", -ret);
948-
return ret;
949+
return dev_err_probe(dev, ret, "Probe failed\n");
949950
}
950951

951952
static int hi3110_can_remove(struct spi_device *spi)
@@ -957,8 +958,7 @@ static int hi3110_can_remove(struct spi_device *spi)
957958

958959
hi3110_power_enable(priv->power, 0);
959960

960-
if (!IS_ERR(priv->clk))
961-
clk_disable_unprepare(priv->clk);
961+
clk_disable_unprepare(priv->clk);
962962

963963
free_candev(net);
964964

drivers/net/can/sun4i_can.c

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include <linux/of.h>
6262
#include <linux/of_device.h>
6363
#include <linux/platform_device.h>
64+
#include <linux/reset.h>
6465

6566
#define DRV_NAME "sun4i_can"
6667

@@ -200,10 +201,20 @@
200201
#define SUN4I_CAN_MAX_IRQ 20
201202
#define SUN4I_MODE_MAX_RETRIES 100
202203

204+
/**
205+
* struct sun4ican_quirks - Differences between SoC variants.
206+
*
207+
* @has_reset: SoC needs reset deasserted.
208+
*/
209+
struct sun4ican_quirks {
210+
bool has_reset;
211+
};
212+
203213
struct sun4ican_priv {
204214
struct can_priv can;
205215
void __iomem *base;
206216
struct clk *clk;
217+
struct reset_control *reset;
207218
spinlock_t cmdreg_lock; /* lock for concurrent cmd register writes */
208219
};
209220

@@ -702,6 +713,13 @@ static int sun4ican_open(struct net_device *dev)
702713
goto exit_irq;
703714
}
704715

716+
/* software reset deassert */
717+
err = reset_control_deassert(priv->reset);
718+
if (err) {
719+
netdev_err(dev, "could not deassert CAN reset\n");
720+
goto exit_soft_reset;
721+
}
722+
705723
/* turn on clocking for CAN peripheral block */
706724
err = clk_prepare_enable(priv->clk);
707725
if (err) {
@@ -723,6 +741,8 @@ static int sun4ican_open(struct net_device *dev)
723741
exit_can_start:
724742
clk_disable_unprepare(priv->clk);
725743
exit_clock:
744+
reset_control_assert(priv->reset);
745+
exit_soft_reset:
726746
free_irq(dev->irq, dev);
727747
exit_irq:
728748
close_candev(dev);
@@ -736,6 +756,7 @@ static int sun4ican_close(struct net_device *dev)
736756
netif_stop_queue(dev);
737757
sun4i_can_stop(dev);
738758
clk_disable_unprepare(priv->clk);
759+
reset_control_assert(priv->reset);
739760

740761
free_irq(dev->irq, dev);
741762
close_candev(dev);
@@ -750,9 +771,27 @@ static const struct net_device_ops sun4ican_netdev_ops = {
750771
.ndo_start_xmit = sun4ican_start_xmit,
751772
};
752773

774+
static const struct sun4ican_quirks sun4ican_quirks_a10 = {
775+
.has_reset = false,
776+
};
777+
778+
static const struct sun4ican_quirks sun4ican_quirks_r40 = {
779+
.has_reset = true,
780+
};
781+
753782
static const struct of_device_id sun4ican_of_match[] = {
754-
{.compatible = "allwinner,sun4i-a10-can"},
755-
{},
783+
{
784+
.compatible = "allwinner,sun4i-a10-can",
785+
.data = &sun4ican_quirks_a10
786+
}, {
787+
.compatible = "allwinner,sun7i-a20-can",
788+
.data = &sun4ican_quirks_a10
789+
}, {
790+
.compatible = "allwinner,sun8i-r40-can",
791+
.data = &sun4ican_quirks_r40
792+
}, {
793+
/* sentinel */
794+
},
756795
};
757796

758797
MODULE_DEVICE_TABLE(of, sun4ican_of_match);
@@ -771,10 +810,28 @@ static int sun4ican_probe(struct platform_device *pdev)
771810
{
772811
struct device_node *np = pdev->dev.of_node;
773812
struct clk *clk;
813+
struct reset_control *reset = NULL;
774814
void __iomem *addr;
775815
int err, irq;
776816
struct net_device *dev;
777817
struct sun4ican_priv *priv;
818+
const struct sun4ican_quirks *quirks;
819+
820+
quirks = of_device_get_match_data(&pdev->dev);
821+
if (!quirks) {
822+
dev_err(&pdev->dev, "failed to determine the quirks to use\n");
823+
err = -ENODEV;
824+
goto exit;
825+
}
826+
827+
if (quirks->has_reset) {
828+
reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
829+
if (IS_ERR(reset)) {
830+
dev_err(&pdev->dev, "unable to request reset\n");
831+
err = PTR_ERR(reset);
832+
goto exit;
833+
}
834+
}
778835

779836
clk = of_clk_get(np, 0);
780837
if (IS_ERR(clk)) {
@@ -818,6 +875,7 @@ static int sun4ican_probe(struct platform_device *pdev)
818875
CAN_CTRLMODE_3_SAMPLES;
819876
priv->base = addr;
820877
priv->clk = clk;
878+
priv->reset = reset;
821879
spin_lock_init(&priv->cmdreg_lock);
822880

823881
platform_set_drvdata(pdev, dev);

drivers/net/can/usb/etas_es58x/es581_4.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include <linux/kernel.h>
13+
#include <linux/units.h>
1314
#include <asm/unaligned.h>
1415

1516
#include "es58x_core.h"
@@ -469,8 +470,8 @@ const struct es58x_parameters es581_4_param = {
469470
.bittiming_const = &es581_4_bittiming_const,
470471
.data_bittiming_const = NULL,
471472
.tdc_const = NULL,
472-
.bitrate_max = 1 * CAN_MBPS,
473-
.clock = {.freq = 50 * CAN_MHZ},
473+
.bitrate_max = 1 * MEGA /* BPS */,
474+
.clock = {.freq = 50 * MEGA /* Hz */},
474475
.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC,
475476
.tx_start_of_frame = 0xAFAF,
476477
.rx_start_of_frame = 0xFAFA,

drivers/net/can/usb/etas_es58x/es58x_fd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
#include <linux/kernel.h>
15+
#include <linux/units.h>
1516
#include <asm/unaligned.h>
1617

1718
#include "es58x_core.h"
@@ -522,8 +523,8 @@ const struct es58x_parameters es58x_fd_param = {
522523
* Mbps work in an optimal environment but are not recommended
523524
* for production environment.
524525
*/
525-
.bitrate_max = 8 * CAN_MBPS,
526-
.clock = {.freq = 80 * CAN_MHZ},
526+
.bitrate_max = 8 * MEGA /* BPS */,
527+
.clock = {.freq = 80 * MEGA /* Hz */},
527528
.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY |
528529
CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_FD | CAN_CTRLMODE_FD_NON_ISO |
529530
CAN_CTRLMODE_CC_LEN8_DLC | CAN_CTRLMODE_TDC_AUTO,

include/linux/can/bittiming.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@
1212
#define CAN_SYNC_SEG 1
1313

1414

15-
/* Kilobits and Megabits per second */
16-
#define CAN_KBPS 1000UL
17-
#define CAN_MBPS 1000000UL
18-
19-
/* Megahertz */
20-
#define CAN_MHZ 1000000UL
21-
2215
#define CAN_CTRLMODE_TDC_MASK \
2316
(CAN_CTRLMODE_TDC_AUTO | CAN_CTRLMODE_TDC_MANUAL)
2417

0 commit comments

Comments
 (0)