Skip to content

Commit cc944c8

Browse files
Merge branch 'can-add-support-for-rz-n1-sja1000-can-controller'
Biju Das says: ==================== Add support for RZ/N1 SJA1000 CAN controller This patch series aims to add support for RZ/N1 SJA1000 CAN controller. The SJA1000 CAN controller on RZ/N1 SoC has some differences compared to others like it has no clock divider register (CDR) support and it has no HW loopback (HW doesn't see tx messages on rx), so introduced a new compatible 'renesas,rzn1-sja1000' to handle these differences. v3->v4: * Updated bindings as per coding style used in example-schema. * Entire entry in properties compatible declared as enum. Also Descriptions do not bring any information,so removed it from compatible description. * Used decimal values in nxp,tx-output-mode enums. * Fixed indentaions in binding examples. * Removed clock-names from bindings, as it is single clock. * Optimized the code as per Vincent's suggestion. * Updated clock handling as per bindings. v2->v3: * Added reg-io-width is a required property for technologic,sja1000 & renesas,rzn1-sja1000 * Removed enum type from nxp,tx-output-config and updated the description for combination of TX0 and TX1. * Updated the example for technologic,sja1000 v1->v2: * Moved $ref: can-controller.yaml# to top along with if conditional to avoid multiple mapping issues with the if conditional in the subsequent patch. * Added an example for RZ/N1D SJA1000 usage. * Updated commit description for patch#2,#3 and #6 * Removed the quirk macro SJA1000_NO_HW_LOOPBACK_QUIRK * Added prefix SJA1000_QUIRK_* for quirk macro. * Replaced of_device_get_match_data->device_get_match_data. * Added error handling on clk error path * Started using "devm_clk_get_optional_enabled" for clk get,prepare and enable. Ref: [1] https://lore.kernel.org/linux-renesas-soc/[email protected]/T/#t ==================== Link: https://lore.kernel.org/all/[email protected] [mkl: applying patches 1...5 only, as 6 depends devm_clk_get_optional_enabled(), which is not in net-next/master, yet] Signed-off-by: Marc Kleine-Budde <[email protected]>
2 parents 8575f31 + 6d5fe10 commit cc944c8

File tree

5 files changed

+145
-76
lines changed

5 files changed

+145
-76
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/net/can/nxp,sja1000.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Memory mapped SJA1000 CAN controller from NXP (formerly Philips)
8+
9+
maintainers:
10+
- Wolfgang Grandegger <[email protected]>
11+
12+
properties:
13+
compatible:
14+
oneOf:
15+
- enum:
16+
- nxp,sja1000
17+
- technologic,sja1000
18+
- items:
19+
- enum:
20+
- renesas,r9a06g032-sja1000 # RZ/N1D
21+
- renesas,r9a06g033-sja1000 # RZ/N1S
22+
- const: renesas,rzn1-sja1000 # RZ/N1
23+
24+
reg:
25+
maxItems: 1
26+
27+
interrupts:
28+
maxItems: 1
29+
30+
clocks:
31+
maxItems: 1
32+
33+
reg-io-width:
34+
$ref: /schemas/types.yaml#/definitions/uint32
35+
description: I/O register width (in bytes) implemented by this device
36+
default: 1
37+
enum: [ 1, 2, 4 ]
38+
39+
nxp,external-clock-frequency:
40+
$ref: /schemas/types.yaml#/definitions/uint32
41+
default: 16000000
42+
description: |
43+
Frequency of the external oscillator clock in Hz.
44+
The internal clock frequency used by the SJA1000 is half of that value.
45+
46+
nxp,tx-output-mode:
47+
$ref: /schemas/types.yaml#/definitions/uint32
48+
enum: [ 0, 1, 2, 3 ]
49+
default: 1
50+
description: |
51+
operation mode of the TX output control logic. Valid values are:
52+
<0> : bi-phase output mode
53+
<1> : normal output mode (default)
54+
<2> : test output mode
55+
<3> : clock output mode
56+
57+
nxp,tx-output-config:
58+
$ref: /schemas/types.yaml#/definitions/uint32
59+
default: 0x02
60+
description: |
61+
TX output pin configuration. Valid values are any one of the below
62+
or combination of TX0 and TX1:
63+
<0x01> : TX0 invert
64+
<0x02> : TX0 pull-down (default)
65+
<0x04> : TX0 pull-up
66+
<0x06> : TX0 push-pull
67+
<0x08> : TX1 invert
68+
<0x10> : TX1 pull-down
69+
<0x20> : TX1 pull-up
70+
<0x30> : TX1 push-pull
71+
72+
nxp,clock-out-frequency:
73+
$ref: /schemas/types.yaml#/definitions/uint32
74+
description: |
75+
clock frequency in Hz on the CLKOUT pin.
76+
If not specified or if the specified value is 0, the CLKOUT pin
77+
will be disabled.
78+
79+
nxp,no-comparator-bypass:
80+
type: boolean
81+
description: Allows to disable the CAN input comparator.
82+
83+
required:
84+
- compatible
85+
- reg
86+
- interrupts
87+
88+
allOf:
89+
- $ref: can-controller.yaml#
90+
- if:
91+
properties:
92+
compatible:
93+
contains:
94+
enum:
95+
- technologic,sja1000
96+
- renesas,rzn1-sja1000
97+
then:
98+
required:
99+
- reg-io-width
100+
- if:
101+
properties:
102+
compatible:
103+
contains:
104+
const: renesas,rzn1-sja1000
105+
then:
106+
required:
107+
- clocks
108+
109+
unevaluatedProperties: false
110+
111+
examples:
112+
- |
113+
can@1a000 {
114+
compatible = "technologic,sja1000";
115+
reg = <0x1a000 0x100>;
116+
interrupts = <1>;
117+
reg-io-width = <2>;
118+
nxp,tx-output-config = <0x06>;
119+
nxp,external-clock-frequency = <24000000>;
120+
};
121+
122+
- |
123+
#include <dt-bindings/interrupt-controller/arm-gic.h>
124+
#include <dt-bindings/clock/r9a06g032-sysctrl.h>
125+
126+
can@52104000 {
127+
compatible = "renesas,r9a06g032-sja1000", "renesas,rzn1-sja1000";
128+
reg = <0x52104000 0x800>;
129+
reg-io-width = <4>;
130+
interrupts = <GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>;
131+
clocks = <&sysctrl R9A06G032_HCLK_CAN0>;
132+
};

Documentation/devicetree/bindings/net/can/sja1000.txt

Lines changed: 0 additions & 58 deletions
This file was deleted.

drivers/net/can/sja1000/sja1000.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ static void chipset_init(struct net_device *dev)
183183
{
184184
struct sja1000_priv *priv = netdev_priv(dev);
185185

186-
/* set clock divider and output control register */
187-
priv->write_reg(priv, SJA1000_CDR, priv->cdr | CDR_PELICAN);
186+
if (!(priv->flags & SJA1000_QUIRK_NO_CDR_REG))
187+
/* set clock divider and output control register */
188+
priv->write_reg(priv, SJA1000_CDR, priv->cdr | CDR_PELICAN);
188189

189190
/* set acceptance filter (accept all) */
190191
priv->write_reg(priv, SJA1000_ACCC0, 0x00);
@@ -209,7 +210,8 @@ static void sja1000_start(struct net_device *dev)
209210
set_reset_mode(dev);
210211

211212
/* Initialize chip if uninitialized at this stage */
212-
if (!(priv->read_reg(priv, SJA1000_CDR) & CDR_PELICAN))
213+
if (!(priv->flags & SJA1000_QUIRK_NO_CDR_REG ||
214+
priv->read_reg(priv, SJA1000_CDR) & CDR_PELICAN))
213215
chipset_init(dev);
214216

215217
/* Clear error counters and error code capture */

drivers/net/can/sja1000/sja1000.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@
145145
/*
146146
* Flags for sja1000priv.flags
147147
*/
148-
#define SJA1000_CUSTOM_IRQ_HANDLER 0x1
148+
#define SJA1000_CUSTOM_IRQ_HANDLER BIT(0)
149+
#define SJA1000_QUIRK_NO_CDR_REG BIT(1)
149150

150151
/*
151152
* SJA1000 private data structure

drivers/net/can/sja1000/sja1000_platform.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ MODULE_LICENSE("GPL v2");
3131

3232
struct sja1000_of_data {
3333
size_t priv_sz;
34-
int (*init)(struct sja1000_priv *priv, struct device_node *of);
34+
void (*init)(struct sja1000_priv *priv, struct device_node *of);
3535
};
3636

3737
struct technologic_priv {
@@ -94,15 +94,13 @@ static void sp_technologic_write_reg16(const struct sja1000_priv *priv,
9494
spin_unlock_irqrestore(&tp->io_lock, flags);
9595
}
9696

97-
static int sp_technologic_init(struct sja1000_priv *priv, struct device_node *of)
97+
static void sp_technologic_init(struct sja1000_priv *priv, struct device_node *of)
9898
{
9999
struct technologic_priv *tp = priv->priv;
100100

101101
priv->read_reg = sp_technologic_read_reg16;
102102
priv->write_reg = sp_technologic_write_reg16;
103103
spin_lock_init(&tp->io_lock);
104-
105-
return 0;
106104
}
107105

108106
static void sp_populate(struct sja1000_priv *priv,
@@ -210,7 +208,6 @@ static int sp_probe(struct platform_device *pdev)
210208
struct resource *res_mem, *res_irq = NULL;
211209
struct sja1000_platform_data *pdata;
212210
struct device_node *of = pdev->dev.of_node;
213-
const struct of_device_id *of_id;
214211
const struct sja1000_of_data *of_data = NULL;
215212
size_t priv_sz = 0;
216213

@@ -243,11 +240,9 @@ static int sp_probe(struct platform_device *pdev)
243240
return -ENODEV;
244241
}
245242

246-
of_id = of_match_device(sp_of_table, &pdev->dev);
247-
if (of_id && of_id->data) {
248-
of_data = of_id->data;
243+
of_data = device_get_match_data(&pdev->dev);
244+
if (of_data)
249245
priv_sz = of_data->priv_sz;
250-
}
251246

252247
dev = alloc_sja1000dev(priv_sz);
253248
if (!dev)
@@ -269,11 +264,8 @@ static int sp_probe(struct platform_device *pdev)
269264
if (of) {
270265
sp_populate_of(priv, of);
271266

272-
if (of_data && of_data->init) {
273-
err = of_data->init(priv, of);
274-
if (err)
275-
goto exit_free;
276-
}
267+
if (of_data && of_data->init)
268+
of_data->init(priv, of);
277269
} else {
278270
sp_populate(priv, pdata, res_mem->flags);
279271
}

0 commit comments

Comments
 (0)