Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
Merge branch 'can-add-support-for-rz-n1-sja1000-can-controller'
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
marckleinebudde committed Jul 19, 2022
2 parents 8575f31 + 6d5fe10 commit cc944c8
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 76 deletions.
132 changes: 132 additions & 0 deletions Documentation/devicetree/bindings/net/can/nxp,sja1000.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/net/can/nxp,sja1000.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Memory mapped SJA1000 CAN controller from NXP (formerly Philips)

maintainers:
- Wolfgang Grandegger <[email protected]>

properties:
compatible:
oneOf:
- enum:
- nxp,sja1000
- technologic,sja1000
- items:
- enum:
- renesas,r9a06g032-sja1000 # RZ/N1D
- renesas,r9a06g033-sja1000 # RZ/N1S
- const: renesas,rzn1-sja1000 # RZ/N1

reg:
maxItems: 1

interrupts:
maxItems: 1

clocks:
maxItems: 1

reg-io-width:
$ref: /schemas/types.yaml#/definitions/uint32
description: I/O register width (in bytes) implemented by this device
default: 1
enum: [ 1, 2, 4 ]

nxp,external-clock-frequency:
$ref: /schemas/types.yaml#/definitions/uint32
default: 16000000
description: |
Frequency of the external oscillator clock in Hz.
The internal clock frequency used by the SJA1000 is half of that value.
nxp,tx-output-mode:
$ref: /schemas/types.yaml#/definitions/uint32
enum: [ 0, 1, 2, 3 ]
default: 1
description: |
operation mode of the TX output control logic. Valid values are:
<0> : bi-phase output mode
<1> : normal output mode (default)
<2> : test output mode
<3> : clock output mode
nxp,tx-output-config:
$ref: /schemas/types.yaml#/definitions/uint32
default: 0x02
description: |
TX output pin configuration. Valid values are any one of the below
or combination of TX0 and TX1:
<0x01> : TX0 invert
<0x02> : TX0 pull-down (default)
<0x04> : TX0 pull-up
<0x06> : TX0 push-pull
<0x08> : TX1 invert
<0x10> : TX1 pull-down
<0x20> : TX1 pull-up
<0x30> : TX1 push-pull
nxp,clock-out-frequency:
$ref: /schemas/types.yaml#/definitions/uint32
description: |
clock frequency in Hz on the CLKOUT pin.
If not specified or if the specified value is 0, the CLKOUT pin
will be disabled.
nxp,no-comparator-bypass:
type: boolean
description: Allows to disable the CAN input comparator.

required:
- compatible
- reg
- interrupts

allOf:
- $ref: can-controller.yaml#
- if:
properties:
compatible:
contains:
enum:
- technologic,sja1000
- renesas,rzn1-sja1000
then:
required:
- reg-io-width
- if:
properties:
compatible:
contains:
const: renesas,rzn1-sja1000
then:
required:
- clocks

unevaluatedProperties: false

examples:
- |
can@1a000 {
compatible = "technologic,sja1000";
reg = <0x1a000 0x100>;
interrupts = <1>;
reg-io-width = <2>;
nxp,tx-output-config = <0x06>;
nxp,external-clock-frequency = <24000000>;
};
- |
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include <dt-bindings/clock/r9a06g032-sysctrl.h>
can@52104000 {
compatible = "renesas,r9a06g032-sja1000", "renesas,rzn1-sja1000";
reg = <0x52104000 0x800>;
reg-io-width = <4>;
interrupts = <GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&sysctrl R9A06G032_HCLK_CAN0>;
};
58 changes: 0 additions & 58 deletions Documentation/devicetree/bindings/net/can/sja1000.txt

This file was deleted.

8 changes: 5 additions & 3 deletions drivers/net/can/sja1000/sja1000.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ static void chipset_init(struct net_device *dev)
{
struct sja1000_priv *priv = netdev_priv(dev);

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

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

/* Initialize chip if uninitialized at this stage */
if (!(priv->read_reg(priv, SJA1000_CDR) & CDR_PELICAN))
if (!(priv->flags & SJA1000_QUIRK_NO_CDR_REG ||
priv->read_reg(priv, SJA1000_CDR) & CDR_PELICAN))
chipset_init(dev);

/* Clear error counters and error code capture */
Expand Down
3 changes: 2 additions & 1 deletion drivers/net/can/sja1000/sja1000.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@
/*
* Flags for sja1000priv.flags
*/
#define SJA1000_CUSTOM_IRQ_HANDLER 0x1
#define SJA1000_CUSTOM_IRQ_HANDLER BIT(0)
#define SJA1000_QUIRK_NO_CDR_REG BIT(1)

/*
* SJA1000 private data structure
Expand Down
20 changes: 6 additions & 14 deletions drivers/net/can/sja1000/sja1000_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ MODULE_LICENSE("GPL v2");

struct sja1000_of_data {
size_t priv_sz;
int (*init)(struct sja1000_priv *priv, struct device_node *of);
void (*init)(struct sja1000_priv *priv, struct device_node *of);
};

struct technologic_priv {
Expand Down Expand Up @@ -94,15 +94,13 @@ static void sp_technologic_write_reg16(const struct sja1000_priv *priv,
spin_unlock_irqrestore(&tp->io_lock, flags);
}

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

priv->read_reg = sp_technologic_read_reg16;
priv->write_reg = sp_technologic_write_reg16;
spin_lock_init(&tp->io_lock);

return 0;
}

static void sp_populate(struct sja1000_priv *priv,
Expand Down Expand Up @@ -210,7 +208,6 @@ static int sp_probe(struct platform_device *pdev)
struct resource *res_mem, *res_irq = NULL;
struct sja1000_platform_data *pdata;
struct device_node *of = pdev->dev.of_node;
const struct of_device_id *of_id;
const struct sja1000_of_data *of_data = NULL;
size_t priv_sz = 0;

Expand Down Expand Up @@ -243,11 +240,9 @@ static int sp_probe(struct platform_device *pdev)
return -ENODEV;
}

of_id = of_match_device(sp_of_table, &pdev->dev);
if (of_id && of_id->data) {
of_data = of_id->data;
of_data = device_get_match_data(&pdev->dev);
if (of_data)
priv_sz = of_data->priv_sz;
}

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

if (of_data && of_data->init) {
err = of_data->init(priv, of);
if (err)
goto exit_free;
}
if (of_data && of_data->init)
of_data->init(priv, of);
} else {
sp_populate(priv, pdata, res_mem->flags);
}
Expand Down

0 comments on commit cc944c8

Please sign in to comment.