Commit 207656f7 authored by Arnd Bergmann's avatar Arnd Bergmann

Merge branch 'nuvoton/ma35d1' into soc/newsoc

This patchset adds initial support for the Nuvoton ma35d1 SoC, including
initial device tree, clock driver, reset driver, and serial driver.

This patchset cover letter is based from the initial support for Nuvoton
ma35d1 to keep tracking the version history.

This patchset had been applied to Linux kernel 6.4.0-rc5
and tested on the Nuvoton ma35d1 SOM evaluation board.

(ma35d1 information: https://www.nuvoton.com/products/microprocessors/arm-cortex-a35-mpus/)
MA35D1 porting on linux-5.10.y can be found at: https://github.com/OpenNuvoton/MPU-Family

Link: https://lore.kernel.org/linux-arm-kernel/20230605040749.67964-1-ychuang570808@gmail.com/

[arnd: merging everything aside from the serial port driver for now, as
 that is still waiting for an Ack]

* nuvoton/ma35d1:
  reset: Add Nuvoton ma35d1 reset driver support
  clk: nuvoton: Add clock driver for ma35d1 clock controller
  arm64: dts: nuvoton: Add initial ma35d1 device tree
  dt-bindings: serial: Document ma35d1 uart controller
  dt-bindings: arm: Add initial bindings for Nuvoton platform
  dt-bindings: reset: nuvoton: Document ma35d1 reset control
  dt-bindings: clock: nuvoton: add binding for ma35d1 clock controller
  arm64: defconfig: Add support for Nuvoton MA35 family SoCs
  arm64: Kconfig.platforms: Add config for Nuvoton MA35 platform
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
parents f1fcbaa1 e4bb55d6
# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
%YAML 1.2
---
$id: http://devicetree.org/schemas/arm/nuvoton/nuvoton,ma35d1.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Nuvoton MA35 series SoC based platforms
maintainers:
- Jacky Huang <ychuang3@nuvoton.com>
description: |
Boards with an ARMv8 based Nuvoton MA35 series SoC shall have
the following properties.
properties:
$nodename:
const: '/'
compatible:
oneOf:
- description: MA35D1 based boards
items:
- enum:
- nuvoton,ma35d1-iot
- nuvoton,ma35d1-som
- const: nuvoton,ma35d1
additionalProperties: true
...
# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
%YAML 1.2
---
$id: http://devicetree.org/schemas/arm/npcm/npcm.yaml#
$id: http://devicetree.org/schemas/arm/nuvoton/nuvoton,npcm.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: NPCM Platforms
......
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/clock/nuvoton,ma35d1-clk.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Nuvoton MA35D1 Clock Controller Module
maintainers:
- Chi-Fang Li <cfli0@nuvoton.com>
- Jacky Huang <ychuang3@nuvoton.com>
description: |
The MA35D1 clock controller generates clocks for the whole chip,
including system clocks and all peripheral clocks.
See also:
include/dt-bindings/clock/ma35d1-clk.h
properties:
compatible:
items:
- const: nuvoton,ma35d1-clk
reg:
maxItems: 1
"#clock-cells":
const: 1
clocks:
maxItems: 1
nuvoton,pll-mode:
description:
A list of PLL operation mode corresponding to CAPLL, DDRPLL, APLL,
EPLL, and VPLL in sequential.
maxItems: 5
items:
enum:
- integer
- fractional
- spread-spectrum
$ref: /schemas/types.yaml#/definitions/non-unique-string-array
required:
- compatible
- reg
- "#clock-cells"
- clocks
additionalProperties: false
examples:
- |
clock-controller@40460200 {
compatible = "nuvoton,ma35d1-clk";
reg = <0x40460200 0x100>;
#clock-cells = <1>;
clocks = <&clk_hxt>;
};
...
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/reset/nuvoton,ma35d1-reset.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Nuvoton MA35D1 Reset Controller
maintainers:
- Chi-Fang Li <cfli0@nuvoton.com>
- Jacky Huang <ychuang3@nuvoton.com>
description:
The system reset controller can be used to reset various peripheral
controllers in MA35D1 SoC.
properties:
compatible:
items:
- const: nuvoton,ma35d1-reset
reg:
maxItems: 1
'#reset-cells':
const: 1
required:
- compatible
- reg
- '#reset-cells'
additionalProperties: false
examples:
# system reset controller node:
- |
system-management@40460000 {
compatible = "nuvoton,ma35d1-reset";
reg = <0x40460000 0x200>;
#reset-cells = <1>;
};
...
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/serial/nuvoton,ma35d1-serial.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Nuvoton MA35D1 Universal Asynchronous Receiver/Transmitter (UART)
maintainers:
- Min-Jen Chen <mjchen@nuvoton.com>
- Jacky Huang <ychuang3@nuvoton.com>
allOf:
- $ref: serial.yaml
properties:
compatible:
const: nuvoton,ma35d1-uart
reg:
maxItems: 1
interrupts:
maxItems: 1
clocks:
maxItems: 1
required:
- compatible
- reg
- interrupts
- clocks
unevaluatedProperties: false
examples:
- |
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
serial@40700000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x40700000 0x100>;
interrupts = <GIC_SPI 59 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART0_GATE>;
};
...
# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
%YAML 1.2
---
$id: http://devicetree.org/schemas/arm/npcm/nuvoton,gcr.yaml#
$id: http://devicetree.org/schemas/soc/nuvoton/nuvoton,npcm-gcr.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Global Control Registers block in Nuvoton SoCs
......
......@@ -2502,6 +2502,18 @@ F: drivers/rtc/rtc-ab8500.c
F: drivers/rtc/rtc-pl031.c
F: drivers/soc/ux500/
ARM/NUVOTON MA35 ARCHITECTURE
M: Jacky Huang <ychuang3@nuvoton.com>
M: Shan-Chun Hung <schung@nuvoton.com>
L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
S: Supported
F: Documentation/devicetree/bindings/*/*/*ma35*
F: Documentation/devicetree/bindings/*/*ma35*
F: arch/arm64/boot/dts/nuvoton/*ma35*
F: drivers/*/*/*ma35*
F: drivers/*/*ma35*
K: ma35d1
ARM/NUVOTON NPCM ARCHITECTURE
M: Avi Fishman <avifishman70@gmail.com>
M: Tomer Maimon <tmaimon77@gmail.com>
......@@ -2513,7 +2525,6 @@ L: openbmc@lists.ozlabs.org (moderated for non-subscribers)
S: Supported
F: Documentation/devicetree/bindings/*/*/*npcm*
F: Documentation/devicetree/bindings/*/*npcm*
F: Documentation/devicetree/bindings/arm/npcm/*
F: Documentation/devicetree/bindings/rtc/nuvoton,nct3018y.yaml
F: arch/arm/boot/dts/nuvoton-npcm*
F: arch/arm/mach-npcm/
......
......@@ -225,6 +225,14 @@ config ARCH_S32
endif
config ARCH_MA35
bool "Nuvoton MA35 Architecture"
select GPIOLIB
select PINCTRL
select RESET_CONTROLLER
help
This enables support for the ARMv8 based Nuvoton MA35 series SoCs.
config ARCH_NPCM
bool "Nuvoton NPCM Architecture"
select PINCTRL
......
# SPDX-License-Identifier: GPL-2.0
dtb-$(CONFIG_ARCH_MA35) += ma35d1-iot-512m.dtb
dtb-$(CONFIG_ARCH_MA35) += ma35d1-som-256m.dtb
dtb-$(CONFIG_ARCH_NPCM) += nuvoton-npcm845-evb.dtb
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2023 Nuvoton Technology Corp.
* Author: Shan-Chun Hung <schung@nuvoton.com>
* Jacky huang <ychuang3@nuvoton.com>
*/
/dts-v1/;
#include "ma35d1.dtsi"
/ {
model = "Nuvoton MA35D1-IoT";
compatible = "nuvoton,ma35d1-iot", "nuvoton,ma35d1";
aliases {
serial0 = &uart0;
};
chosen {
stdout-path = "serial0:115200n8";
};
mem: memory@80000000 {
device_type = "memory";
reg = <0x00000000 0x80000000 0 0x20000000>; /* 512M DRAM */
};
clk_hxt: clock-hxt {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <24000000>;
clock-output-names = "clk_hxt";
};
};
&uart0 {
status = "okay";
};
&clk {
assigned-clocks = <&clk CAPLL>,
<&clk DDRPLL>,
<&clk APLL>,
<&clk EPLL>,
<&clk VPLL>;
assigned-clock-rates = <800000000>,
<266000000>,
<180000000>,
<500000000>,
<102000000>;
nuvoton,pll-mode = "integer",
"fractional",
"integer",
"integer",
"integer";
};
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2023 Nuvoton Technology Corp.
* Author: Shan-Chun Hung <schung@nuvoton.com>
* Jacky huang <ychuang3@nuvoton.com>
*/
/dts-v1/;
#include "ma35d1.dtsi"
/ {
model = "Nuvoton MA35D1-SOM";
compatible = "nuvoton,ma35d1-som", "nuvoton,ma35d1";
aliases {
serial0 = &uart0;
};
chosen {
stdout-path = "serial0:115200n8";
};
mem: memory@80000000 {
device_type = "memory";
reg = <0x00000000 0x80000000 0 0x10000000>; /* 256M DRAM */
};
clk_hxt: clock-hxt {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <24000000>;
clock-output-names = "clk_hxt";
};
};
&uart0 {
status = "okay";
};
&clk {
assigned-clocks = <&clk CAPLL>,
<&clk DDRPLL>,
<&clk APLL>,
<&clk EPLL>,
<&clk VPLL>;
assigned-clock-rates = <800000000>,
<266000000>,
<180000000>,
<500000000>,
<102000000>;
nuvoton,pll-mode = "integer",
"fractional",
"integer",
"integer",
"integer";
};
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2023 Nuvoton Technology Corp.
* Author: Shan-Chun Hung <schung@nuvoton.com>
* Jacky huang <ychuang3@nuvoton.com>
*/
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
#include <dt-bindings/reset/nuvoton,ma35d1-reset.h>
/ {
compatible = "nuvoton,ma35d1";
interrupt-parent = <&gic>;
#address-cells = <2>;
#size-cells = <2>;
cpus {
#address-cells = <2>;
#size-cells = <0>;
cpu0: cpu@0 {
device_type = "cpu";
compatible = "arm,cortex-a35";
reg = <0x0 0x0>;
enable-method = "psci";
next-level-cache = <&L2_0>;
};
cpu1: cpu@1 {
device_type = "cpu";
compatible = "arm,cortex-a35";
reg = <0x0 0x1>;
enable-method = "psci";
next-level-cache = <&L2_0>;
};
L2_0: l2-cache {
compatible = "cache";
cache-level = <2>;
cache-unified;
cache-size = <0x80000>;
};
};
psci {
compatible = "arm,psci-0.2";
method = "smc";
};
gic: interrupt-controller@50801000 {
compatible = "arm,gic-400";
reg = <0x0 0x50801000 0 0x1000>, /* GICD */
<0x0 0x50802000 0 0x2000>, /* GICC */
<0x0 0x50804000 0 0x2000>, /* GICH */
<0x0 0x50806000 0 0x2000>; /* GICV */
#interrupt-cells = <3>;
interrupt-parent = <&gic>;
interrupt-controller;
interrupts = <GIC_PPI 9 (GIC_CPU_MASK_RAW(0x13) |
IRQ_TYPE_LEVEL_HIGH)>;
};
timer {
compatible = "arm,armv8-timer";
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(4) |
IRQ_TYPE_LEVEL_LOW)>, /* Physical Secure */
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(4) |
IRQ_TYPE_LEVEL_LOW)>, /* Physical Non-Secure */
<GIC_PPI 11 (GIC_CPU_MASK_SIMPLE(4) |
IRQ_TYPE_LEVEL_LOW)>, /* Virtual */
<GIC_PPI 10 (GIC_CPU_MASK_SIMPLE(4) |
IRQ_TYPE_LEVEL_LOW)>; /* Hypervisor */
interrupt-parent = <&gic>;
};
soc {
compatible = "simple-bus";
#address-cells = <2>;
#size-cells = <2>;
ranges;
sys: system-management@40460000 {
compatible = "nuvoton,ma35d1-reset";
reg = <0x0 0x40460000 0x0 0x200>;
#reset-cells = <1>;
};
clk: clock-controller@40460200 {
compatible = "nuvoton,ma35d1-clk";
reg = <0x00000000 0x40460200 0x0 0x100>;
#clock-cells = <1>;
clocks = <&clk_hxt>;
};
uart0: serial@40700000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x40700000 0x0 0x100>;
interrupts = <GIC_SPI 59 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART0_GATE>;
status = "disabled";
};
uart1: serial@40710000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x40710000 0x0 0x100>;
interrupts = <GIC_SPI 60 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART1_GATE>;
status = "disabled";
};
uart2: serial@40720000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x40720000 0x0 0x100>;
interrupts = <GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART2_GATE>;
status = "disabled";
};
uart3: serial@40730000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x40730000 0x0 0x100>;
interrupts = <GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART3_GATE>;
status = "disabled";
};
uart4: serial@40740000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x40740000 0x0 0x100>;
interrupts = <GIC_SPI 63 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART4_GATE>;
status = "disabled";
};
uart5: serial@40750000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x40750000 0x0 0x100>;
interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART5_GATE>;
status = "disabled";
};
uart6: serial@40760000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x40760000 0x0 0x100>;
interrupts = <GIC_SPI 91 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART6_GATE>;
status = "disabled";
};
uart7: serial@40770000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x40770000 0x0 0x100>;
interrupts = <GIC_SPI 92 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART7_GATE>;
status = "disabled";
};
uart8: serial@40780000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x40780000 0x0 0x100>;
interrupts = <GIC_SPI 93 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART8_GATE>;
status = "disabled";
};
uart9: serial@40790000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x40790000 0x0 0x100>;
interrupts = <GIC_SPI 94 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART9_GATE>;
status = "disabled";
};
uart10: serial@407a0000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x407a0000 0x0 0x100>;
interrupts = <GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART10_GATE>;
status = "disabled";
};
uart11: serial@407b0000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x407b0000 0x0 0x100>;
interrupts = <GIC_SPI 96 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART11_GATE>;
status = "disabled";
};
uart12: serial@407c0000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x407c0000 0x0 0x100>;
interrupts = <GIC_SPI 118 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART12_GATE>;
status = "disabled";
};
uart13: serial@407d0000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x407d0000 0x0 0x100>;
interrupts = <GIC_SPI 119 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART13_GATE>;
status = "disabled";
};
uart14: serial@407e0000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x407e0000 0x0 0x100>;
interrupts = <GIC_SPI 120 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART14_GATE>;
status = "disabled";
};
uart15: serial@407f0000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x407f0000 0x0 0x100>;
interrupts = <GIC_SPI 121 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART15_GATE>;
status = "disabled";
};
uart16: serial@40880000 {
compatible = "nuvoton,ma35d1-uart";
reg = <0x0 0x40880000 0x0 0x100>;
interrupts = <GIC_SPI 122 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk UART16_GATE>;
status = "disabled";
};
};
};
......@@ -52,6 +52,7 @@ CONFIG_ARCH_NXP=y
CONFIG_ARCH_LAYERSCAPE=y
CONFIG_ARCH_MXC=y
CONFIG_ARCH_S32=y
CONFIG_ARCH_MA35=y
CONFIG_ARCH_NPCM=y
CONFIG_ARCH_QCOM=y
CONFIG_ARCH_RENESAS=y
......
......@@ -478,6 +478,7 @@ source "drivers/clk/meson/Kconfig"
source "drivers/clk/mstar/Kconfig"
source "drivers/clk/microchip/Kconfig"
source "drivers/clk/mvebu/Kconfig"
source "drivers/clk/nuvoton/Kconfig"
source "drivers/clk/pistachio/Kconfig"
source "drivers/clk/qcom/Kconfig"
source "drivers/clk/ralink/Kconfig"
......
......@@ -106,6 +106,7 @@ endif
obj-y += mstar/
obj-y += mvebu/
obj-$(CONFIG_ARCH_MXS) += mxs/
obj-$(CONFIG_ARCH_MA35) += nuvoton/
obj-$(CONFIG_COMMON_CLK_NXP) += nxp/
obj-$(CONFIG_COMMON_CLK_PISTACHIO) += pistachio/
obj-$(CONFIG_COMMON_CLK_PXA) += pxa/
......
# SPDX-License-Identifier: GPL-2.0
# common clock support for Nuvoton SoC family.
config COMMON_CLK_NUVOTON
bool "Nuvoton clock controller common support"
depends on ARCH_MA35 || COMPILE_TEST
default y
help
Say y here to enable common clock controller for Nuvoton platforms.
if COMMON_CLK_NUVOTON
config CLK_MA35D1
bool "Nuvoton MA35D1 clock controller support"
default y
help
Build the clock controller driver for MA35D1 SoC.
endif
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_CLK_MA35D1) += clk-ma35d1.o
obj-$(CONFIG_CLK_MA35D1) += clk-ma35d1-divider.o
obj-$(CONFIG_CLK_MA35D1) += clk-ma35d1-pll.o
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2023 Nuvoton Technology Corp.
* Author: Chi-Fang Li <cfli0@nuvoton.com>
*/
#include <linux/clk-provider.h>
#include <linux/device.h>
#include <linux/regmap.h>
#include <linux/spinlock.h>
struct ma35d1_adc_clk_div {
struct clk_hw hw;
void __iomem *reg;
u8 shift;
u8 width;
u32 mask;
const struct clk_div_table *table;
/* protects concurrent access to clock divider registers */
spinlock_t *lock;
};
struct clk_hw *ma35d1_reg_adc_clkdiv(struct device *dev, const char *name,
struct clk_hw *parent_hw, spinlock_t *lock,
unsigned long flags, void __iomem *reg,
u8 shift, u8 width, u32 mask_bit);
static inline struct ma35d1_adc_clk_div *to_ma35d1_adc_clk_div(struct clk_hw *_hw)
{
return container_of(_hw, struct ma35d1_adc_clk_div, hw);
}
static unsigned long ma35d1_clkdiv_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
{
unsigned int val;
struct ma35d1_adc_clk_div *dclk = to_ma35d1_adc_clk_div(hw);
val = readl_relaxed(dclk->reg) >> dclk->shift;
val &= clk_div_mask(dclk->width);
val += 1;
return divider_recalc_rate(hw, parent_rate, val, dclk->table,
CLK_DIVIDER_ROUND_CLOSEST, dclk->width);
}
static long ma35d1_clkdiv_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate)
{
struct ma35d1_adc_clk_div *dclk = to_ma35d1_adc_clk_div(hw);
return divider_round_rate(hw, rate, prate, dclk->table,
dclk->width, CLK_DIVIDER_ROUND_CLOSEST);
}
static int ma35d1_clkdiv_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate)
{
int value;
unsigned long flags = 0;
u32 data;
struct ma35d1_adc_clk_div *dclk = to_ma35d1_adc_clk_div(hw);
value = divider_get_val(rate, parent_rate, dclk->table,
dclk->width, CLK_DIVIDER_ROUND_CLOSEST);
spin_lock_irqsave(dclk->lock, flags);
data = readl_relaxed(dclk->reg);
data &= ~(clk_div_mask(dclk->width) << dclk->shift);
data |= (value - 1) << dclk->shift;
data |= dclk->mask;
writel_relaxed(data, dclk->reg);
spin_unlock_irqrestore(dclk->lock, flags);
return 0;
}
static const struct clk_ops ma35d1_adc_clkdiv_ops = {
.recalc_rate = ma35d1_clkdiv_recalc_rate,
.round_rate = ma35d1_clkdiv_round_rate,
.set_rate = ma35d1_clkdiv_set_rate,
};
struct clk_hw *ma35d1_reg_adc_clkdiv(struct device *dev, const char *name,
struct clk_hw *parent_hw, spinlock_t *lock,
unsigned long flags, void __iomem *reg,
u8 shift, u8 width, u32 mask_bit)
{
struct ma35d1_adc_clk_div *div;
struct clk_init_data init;
struct clk_div_table *table;
struct clk_parent_data pdata = { .index = 0 };
u32 max_div, min_div;
struct clk_hw *hw;
int ret;
int i;
div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL);
if (!div)
return ERR_PTR(-ENOMEM);
max_div = clk_div_mask(width) + 1;
min_div = 1;
table = devm_kcalloc(dev, max_div + 1, sizeof(*table), GFP_KERNEL);
if (!table)
return ERR_PTR(-ENOMEM);
for (i = 0; i < max_div; i++) {
table[i].val = min_div + i;
table[i].div = 2 * table[i].val;
}
table[max_div].val = 0;
table[max_div].div = 0;
memset(&init, 0, sizeof(init));
init.name = name;
init.ops = &ma35d1_adc_clkdiv_ops;
init.flags |= flags;
pdata.hw = parent_hw;
init.parent_data = &pdata;
init.num_parents = 1;
div->reg = reg;
div->shift = shift;
div->width = width;
div->mask = mask_bit ? BIT(mask_bit) : 0;
div->lock = lock;
div->hw.init = &init;
div->table = table;
hw = &div->hw;
ret = devm_clk_hw_register(dev, hw);
if (ret)
return ERR_PTR(ret);
return hw;
}
EXPORT_SYMBOL_GPL(ma35d1_reg_adc_clkdiv);
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2023 Nuvoton Technology Corp.
* Author: Chi-Fang Li <cfli0@nuvoton.com>
*/
#include <linux/bitfield.h>
#include <linux/clk-provider.h>
#include <linux/container_of.h>
#include <linux/device.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/math64.h>
#include <linux/slab.h>
#include <linux/units.h>
#include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
/* PLL frequency limits */
#define PLL_FREF_MAX_FREQ (200 * HZ_PER_MHZ)
#define PLL_FREF_MIN_FREQ (1 * HZ_PER_MHZ)
#define PLL_FREF_M_MAX_FREQ (40 * HZ_PER_MHZ)
#define PLL_FREF_M_MIN_FREQ (10 * HZ_PER_MHZ)
#define PLL_FCLK_MAX_FREQ (2400 * HZ_PER_MHZ)
#define PLL_FCLK_MIN_FREQ (600 * HZ_PER_MHZ)
#define PLL_FCLKO_MAX_FREQ (2400 * HZ_PER_MHZ)
#define PLL_FCLKO_MIN_FREQ (85700 * HZ_PER_KHZ)
#define PLL_SS_RATE 0x77
#define PLL_SLOPE 0x58CFA
#define REG_PLL_CTL0_OFFSET 0x0
#define REG_PLL_CTL1_OFFSET 0x4
#define REG_PLL_CTL2_OFFSET 0x8
/* bit fields for REG_CLK_PLL0CTL0, which is SMIC PLL design */
#define SPLL0_CTL0_FBDIV GENMASK(7, 0)
#define SPLL0_CTL0_INDIV GENMASK(11, 8)
#define SPLL0_CTL0_OUTDIV GENMASK(13, 12)
#define SPLL0_CTL0_PD BIT(16)
#define SPLL0_CTL0_BP BIT(17)
/* bit fields for REG_CLK_PLLxCTL0 ~ REG_CLK_PLLxCTL2, where x = 2 ~ 5 */
#define PLL_CTL0_FBDIV GENMASK(10, 0)
#define PLL_CTL0_INDIV GENMASK(17, 12)
#define PLL_CTL0_MODE GENMASK(19, 18)
#define PLL_CTL0_SSRATE GENMASK(30, 20)
#define PLL_CTL1_PD BIT(0)
#define PLL_CTL1_BP BIT(1)
#define PLL_CTL1_OUTDIV GENMASK(6, 4)
#define PLL_CTL1_FRAC GENMASK(31, 24)
#define PLL_CTL2_SLOPE GENMASK(23, 0)
#define INDIV_MIN 1
#define INDIV_MAX 63
#define FBDIV_MIN 16
#define FBDIV_MAX 2047
#define FBDIV_FRAC_MIN 1600
#define FBDIV_FRAC_MAX 204700
#define OUTDIV_MIN 1
#define OUTDIV_MAX 7
#define PLL_MODE_INT 0
#define PLL_MODE_FRAC 1
#define PLL_MODE_SS 2
struct ma35d1_clk_pll {
struct clk_hw hw;
u32 id;
u8 mode;
void __iomem *ctl0_base;
void __iomem *ctl1_base;
void __iomem *ctl2_base;
};
struct clk_hw *ma35d1_reg_clk_pll(struct device *dev, u32 id, u8 u8mode, const char *name,
struct clk_hw *parent_hw, void __iomem *base);
static inline struct ma35d1_clk_pll *to_ma35d1_clk_pll(struct clk_hw *_hw)
{
return container_of(_hw, struct ma35d1_clk_pll, hw);
}
static unsigned long ma35d1_calc_smic_pll_freq(u32 pll0_ctl0,
unsigned long parent_rate)
{
u32 m, n, p, outdiv;
u64 pll_freq;
if (pll0_ctl0 & SPLL0_CTL0_BP)
return parent_rate;
n = FIELD_GET(SPLL0_CTL0_FBDIV, pll0_ctl0);
m = FIELD_GET(SPLL0_CTL0_INDIV, pll0_ctl0);
p = FIELD_GET(SPLL0_CTL0_OUTDIV, pll0_ctl0);
outdiv = 1 << p;
pll_freq = (u64)parent_rate * n;
div_u64(pll_freq, m * outdiv);
return pll_freq;
}
static unsigned long ma35d1_calc_pll_freq(u8 mode, u32 *reg_ctl, unsigned long parent_rate)
{
unsigned long pll_freq, x;
u32 m, n, p;
if (reg_ctl[1] & PLL_CTL1_BP)
return parent_rate;
n = FIELD_GET(PLL_CTL0_FBDIV, reg_ctl[0]);
m = FIELD_GET(PLL_CTL0_INDIV, reg_ctl[0]);
p = FIELD_GET(PLL_CTL1_OUTDIV, reg_ctl[1]);
if (mode == PLL_MODE_INT) {
pll_freq = (u64)parent_rate * n;
div_u64(pll_freq, m * p);
} else {
x = FIELD_GET(PLL_CTL1_FRAC, reg_ctl[1]);
/* 2 decimal places floating to integer (ex. 1.23 to 123) */
n = n * 100 + ((x * 100) / FIELD_MAX(PLL_CTL1_FRAC));
pll_freq = div_u64(parent_rate * n, 100 * m * p);
}
return pll_freq;
}
static int ma35d1_pll_find_closest(struct ma35d1_clk_pll *pll, unsigned long rate,
unsigned long parent_rate, u32 *reg_ctl,
unsigned long *freq)
{
unsigned long min_diff = ULONG_MAX;
int fbdiv_min, fbdiv_max;
int p, m, n;
*freq = 0;
if (rate < PLL_FCLKO_MIN_FREQ || rate > PLL_FCLKO_MAX_FREQ)
return -EINVAL;
if (pll->mode == PLL_MODE_INT) {
fbdiv_min = FBDIV_MIN;
fbdiv_max = FBDIV_MAX;
} else {
fbdiv_min = FBDIV_FRAC_MIN;
fbdiv_max = FBDIV_FRAC_MAX;
}
for (m = INDIV_MIN; m <= INDIV_MAX; m++) {
for (n = fbdiv_min; n <= fbdiv_max; n++) {
for (p = OUTDIV_MIN; p <= OUTDIV_MAX; p++) {
unsigned long tmp, fout, fclk, diff;
tmp = div_u64(parent_rate, m);
if (tmp < PLL_FREF_M_MIN_FREQ ||
tmp > PLL_FREF_M_MAX_FREQ)
continue; /* constrain */
fclk = div_u64(parent_rate * n, m);
/* for 2 decimal places */
if (pll->mode != PLL_MODE_INT)
fclk = div_u64(fclk, 100);
if (fclk < PLL_FCLK_MIN_FREQ ||
fclk > PLL_FCLK_MAX_FREQ)
continue; /* constrain */
fout = div_u64(fclk, p);
if (fout < PLL_FCLKO_MIN_FREQ ||
fout > PLL_FCLKO_MAX_FREQ)
continue; /* constrain */
diff = abs(rate - fout);
if (diff < min_diff) {
reg_ctl[0] = FIELD_PREP(PLL_CTL0_INDIV, m) |
FIELD_PREP(PLL_CTL0_FBDIV, n);
reg_ctl[1] = FIELD_PREP(PLL_CTL1_OUTDIV, p);
*freq = fout;
min_diff = diff;
if (min_diff == 0)
break;
}
}
}
}
if (*freq == 0)
return -EINVAL; /* cannot find even one valid setting */
return 0;
}
static int ma35d1_clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
unsigned long parent_rate)
{
struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
u32 reg_ctl[3] = { 0 };
unsigned long pll_freq;
int ret;
if (parent_rate < PLL_FREF_MIN_FREQ || parent_rate > PLL_FREF_MAX_FREQ)
return -EINVAL;
ret = ma35d1_pll_find_closest(pll, rate, parent_rate, reg_ctl, &pll_freq);
if (ret != 0)
return ret;
switch (pll->mode) {
case PLL_MODE_INT:
reg_ctl[0] |= FIELD_PREP(PLL_CTL0_MODE, PLL_MODE_INT);
break;
case PLL_MODE_FRAC:
reg_ctl[0] |= FIELD_PREP(PLL_CTL0_MODE, PLL_MODE_FRAC);
break;
case PLL_MODE_SS:
reg_ctl[0] |= FIELD_PREP(PLL_CTL0_MODE, PLL_MODE_SS) |
FIELD_PREP(PLL_CTL0_SSRATE, PLL_SS_RATE);
reg_ctl[2] = FIELD_PREP(PLL_CTL2_SLOPE, PLL_SLOPE);
break;
}
reg_ctl[1] |= PLL_CTL1_PD;
writel_relaxed(reg_ctl[0], pll->ctl0_base);
writel_relaxed(reg_ctl[1], pll->ctl1_base);
writel_relaxed(reg_ctl[2], pll->ctl2_base);
return 0;
}
static unsigned long ma35d1_clk_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
{
struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
u32 reg_ctl[3];
unsigned long pll_freq;
if (parent_rate < PLL_FREF_MIN_FREQ || parent_rate > PLL_FREF_MAX_FREQ)
return 0;
switch (pll->id) {
case CAPLL:
reg_ctl[0] = readl_relaxed(pll->ctl0_base);
pll_freq = ma35d1_calc_smic_pll_freq(reg_ctl[0], parent_rate);
return pll_freq;
case DDRPLL:
case APLL:
case EPLL:
case VPLL:
reg_ctl[0] = readl_relaxed(pll->ctl0_base);
reg_ctl[1] = readl_relaxed(pll->ctl1_base);
pll_freq = ma35d1_calc_pll_freq(pll->mode, reg_ctl, parent_rate);
return pll_freq;
}
return 0;
}
static long ma35d1_clk_pll_round_rate(struct clk_hw *hw, unsigned long rate,
unsigned long *parent_rate)
{
struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
u32 reg_ctl[3] = { 0 };
unsigned long pll_freq;
long ret;
if (*parent_rate < PLL_FREF_MIN_FREQ || *parent_rate > PLL_FREF_MAX_FREQ)
return -EINVAL;
ret = ma35d1_pll_find_closest(pll, rate, *parent_rate, reg_ctl, &pll_freq);
if (ret < 0)
return ret;
switch (pll->id) {
case CAPLL:
reg_ctl[0] = readl_relaxed(pll->ctl0_base);
pll_freq = ma35d1_calc_smic_pll_freq(reg_ctl[0], *parent_rate);
return pll_freq;
case DDRPLL:
case APLL:
case EPLL:
case VPLL:
reg_ctl[0] = readl_relaxed(pll->ctl0_base);
reg_ctl[1] = readl_relaxed(pll->ctl1_base);
pll_freq = ma35d1_calc_pll_freq(pll->mode, reg_ctl, *parent_rate);
return pll_freq;
}
return 0;
}
static int ma35d1_clk_pll_is_prepared(struct clk_hw *hw)
{
struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
u32 val = readl_relaxed(pll->ctl1_base);
return !(val & PLL_CTL1_PD);
}
static int ma35d1_clk_pll_prepare(struct clk_hw *hw)
{
struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
u32 val;
val = readl_relaxed(pll->ctl1_base);
val &= ~PLL_CTL1_PD;
writel_relaxed(val, pll->ctl1_base);
return 0;
}
static void ma35d1_clk_pll_unprepare(struct clk_hw *hw)
{
struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
u32 val;
val = readl_relaxed(pll->ctl1_base);
val |= PLL_CTL1_PD;
writel_relaxed(val, pll->ctl1_base);
}
static const struct clk_ops ma35d1_clk_pll_ops = {
.is_prepared = ma35d1_clk_pll_is_prepared,
.prepare = ma35d1_clk_pll_prepare,
.unprepare = ma35d1_clk_pll_unprepare,
.set_rate = ma35d1_clk_pll_set_rate,
.recalc_rate = ma35d1_clk_pll_recalc_rate,
.round_rate = ma35d1_clk_pll_round_rate,
};
static const struct clk_ops ma35d1_clk_fixed_pll_ops = {
.recalc_rate = ma35d1_clk_pll_recalc_rate,
.round_rate = ma35d1_clk_pll_round_rate,
};
struct clk_hw *ma35d1_reg_clk_pll(struct device *dev, u32 id, u8 u8mode, const char *name,
struct clk_hw *parent_hw, void __iomem *base)
{
struct clk_parent_data pdata = { .index = 0 };
struct clk_init_data init = {};
struct ma35d1_clk_pll *pll;
struct clk_hw *hw;
int ret;
pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL);
if (!pll)
return ERR_PTR(-ENOMEM);
pll->id = id;
pll->mode = u8mode;
pll->ctl0_base = base + REG_PLL_CTL0_OFFSET;
pll->ctl1_base = base + REG_PLL_CTL1_OFFSET;
pll->ctl2_base = base + REG_PLL_CTL2_OFFSET;
init.name = name;
init.flags = 0;
pdata.hw = parent_hw;
init.parent_data = &pdata;
init.num_parents = 1;
if (id == CAPLL || id == DDRPLL)
init.ops = &ma35d1_clk_fixed_pll_ops;
else
init.ops = &ma35d1_clk_pll_ops;
pll->hw.init = &init;
hw = &pll->hw;
ret = devm_clk_hw_register(dev, hw);
if (ret)
return ERR_PTR(ret);
return hw;
}
EXPORT_SYMBOL_GPL(ma35d1_reg_clk_pll);
This diff is collapsed.
......@@ -143,6 +143,12 @@ config RESET_NPCM
This enables the reset controller driver for Nuvoton NPCM
BMC SoCs.
config RESET_NUVOTON_MA35D1
bool "Nuvton MA35D1 Reset Driver"
default ARCH_MA35 || COMPILE_TEST
help
This enables the reset controller driver for Nuvoton MA35D1 SoC.
config RESET_OXNAS
bool
......
......@@ -21,6 +21,7 @@ obj-$(CONFIG_RESET_MCHP_SPARX5) += reset-microchip-sparx5.o
obj-$(CONFIG_RESET_MESON) += reset-meson.o
obj-$(CONFIG_RESET_MESON_AUDIO_ARB) += reset-meson-audio-arb.o
obj-$(CONFIG_RESET_NPCM) += reset-npcm.o
obj-$(CONFIG_RESET_NUVOTON_MA35D1) += reset-ma35d1.o
obj-$(CONFIG_RESET_OXNAS) += reset-oxnas.o
obj-$(CONFIG_RESET_PISTACHIO) += reset-pistachio.o
obj-$(CONFIG_RESET_POLARFIRE_SOC) += reset-mpfs.o
......
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2023 Nuvoton Technology Corp.
* Author: Chi-Fang Li <cfli0@nuvoton.com>
*/
#include <linux/bits.h>
#include <linux/container_of.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/reboot.h>
#include <linux/reset-controller.h>
#include <linux/spinlock.h>
#include <dt-bindings/reset/nuvoton,ma35d1-reset.h>
struct ma35d1_reset_data {
struct reset_controller_dev rcdev;
struct notifier_block restart_handler;
void __iomem *base;
/* protect registers against concurrent read-modify-write */
spinlock_t lock;
};
static const struct {
u32 reg_ofs;
u32 bit;
} ma35d1_reset_map[] = {
[MA35D1_RESET_CHIP] = {0x20, 0},
[MA35D1_RESET_CA35CR0] = {0x20, 1},
[MA35D1_RESET_CA35CR1] = {0x20, 2},
[MA35D1_RESET_CM4] = {0x20, 3},
[MA35D1_RESET_PDMA0] = {0x20, 4},
[MA35D1_RESET_PDMA1] = {0x20, 5},
[MA35D1_RESET_PDMA2] = {0x20, 6},
[MA35D1_RESET_PDMA3] = {0x20, 7},
[MA35D1_RESET_DISP] = {0x20, 9},
[MA35D1_RESET_VCAP0] = {0x20, 10},
[MA35D1_RESET_VCAP1] = {0x20, 11},
[MA35D1_RESET_GFX] = {0x20, 12},
[MA35D1_RESET_VDEC] = {0x20, 13},
[MA35D1_RESET_WHC0] = {0x20, 14},
[MA35D1_RESET_WHC1] = {0x20, 15},
[MA35D1_RESET_GMAC0] = {0x20, 16},
[MA35D1_RESET_GMAC1] = {0x20, 17},
[MA35D1_RESET_HWSEM] = {0x20, 18},
[MA35D1_RESET_EBI] = {0x20, 19},
[MA35D1_RESET_HSUSBH0] = {0x20, 20},
[MA35D1_RESET_HSUSBH1] = {0x20, 21},
[MA35D1_RESET_HSUSBD] = {0x20, 22},
[MA35D1_RESET_USBHL] = {0x20, 23},
[MA35D1_RESET_SDH0] = {0x20, 24},
[MA35D1_RESET_SDH1] = {0x20, 25},
[MA35D1_RESET_NAND] = {0x20, 26},
[MA35D1_RESET_GPIO] = {0x20, 27},
[MA35D1_RESET_MCTLP] = {0x20, 28},
[MA35D1_RESET_MCTLC] = {0x20, 29},
[MA35D1_RESET_DDRPUB] = {0x20, 30},
[MA35D1_RESET_TMR0] = {0x24, 2},
[MA35D1_RESET_TMR1] = {0x24, 3},
[MA35D1_RESET_TMR2] = {0x24, 4},
[MA35D1_RESET_TMR3] = {0x24, 5},
[MA35D1_RESET_I2C0] = {0x24, 8},
[MA35D1_RESET_I2C1] = {0x24, 9},
[MA35D1_RESET_I2C2] = {0x24, 10},
[MA35D1_RESET_I2C3] = {0x24, 11},
[MA35D1_RESET_QSPI0] = {0x24, 12},
[MA35D1_RESET_SPI0] = {0x24, 13},
[MA35D1_RESET_SPI1] = {0x24, 14},
[MA35D1_RESET_SPI2] = {0x24, 15},
[MA35D1_RESET_UART0] = {0x24, 16},
[MA35D1_RESET_UART1] = {0x24, 17},
[MA35D1_RESET_UART2] = {0x24, 18},
[MA35D1_RESET_UART3] = {0x24, 19},
[MA35D1_RESET_UART4] = {0x24, 20},
[MA35D1_RESET_UART5] = {0x24, 21},
[MA35D1_RESET_UART6] = {0x24, 22},
[MA35D1_RESET_UART7] = {0x24, 23},
[MA35D1_RESET_CANFD0] = {0x24, 24},
[MA35D1_RESET_CANFD1] = {0x24, 25},
[MA35D1_RESET_EADC0] = {0x24, 28},
[MA35D1_RESET_I2S0] = {0x24, 29},
[MA35D1_RESET_SC0] = {0x28, 0},
[MA35D1_RESET_SC1] = {0x28, 1},
[MA35D1_RESET_QSPI1] = {0x28, 4},
[MA35D1_RESET_SPI3] = {0x28, 6},
[MA35D1_RESET_EPWM0] = {0x28, 16},
[MA35D1_RESET_EPWM1] = {0x28, 17},
[MA35D1_RESET_QEI0] = {0x28, 22},
[MA35D1_RESET_QEI1] = {0x28, 23},
[MA35D1_RESET_ECAP0] = {0x28, 26},
[MA35D1_RESET_ECAP1] = {0x28, 27},
[MA35D1_RESET_CANFD2] = {0x28, 28},
[MA35D1_RESET_ADC0] = {0x28, 31},
[MA35D1_RESET_TMR4] = {0x2C, 0},
[MA35D1_RESET_TMR5] = {0x2C, 1},
[MA35D1_RESET_TMR6] = {0x2C, 2},
[MA35D1_RESET_TMR7] = {0x2C, 3},
[MA35D1_RESET_TMR8] = {0x2C, 4},
[MA35D1_RESET_TMR9] = {0x2C, 5},
[MA35D1_RESET_TMR10] = {0x2C, 6},
[MA35D1_RESET_TMR11] = {0x2C, 7},
[MA35D1_RESET_UART8] = {0x2C, 8},
[MA35D1_RESET_UART9] = {0x2C, 9},
[MA35D1_RESET_UART10] = {0x2C, 10},
[MA35D1_RESET_UART11] = {0x2C, 11},
[MA35D1_RESET_UART12] = {0x2C, 12},
[MA35D1_RESET_UART13] = {0x2C, 13},
[MA35D1_RESET_UART14] = {0x2C, 14},
[MA35D1_RESET_UART15] = {0x2C, 15},
[MA35D1_RESET_UART16] = {0x2C, 16},
[MA35D1_RESET_I2S1] = {0x2C, 17},
[MA35D1_RESET_I2C4] = {0x2C, 18},
[MA35D1_RESET_I2C5] = {0x2C, 19},
[MA35D1_RESET_EPWM2] = {0x2C, 20},
[MA35D1_RESET_ECAP2] = {0x2C, 21},
[MA35D1_RESET_QEI2] = {0x2C, 22},
[MA35D1_RESET_CANFD3] = {0x2C, 23},
[MA35D1_RESET_KPI] = {0x2C, 24},
[MA35D1_RESET_GIC] = {0x2C, 28},
[MA35D1_RESET_SSMCC] = {0x2C, 30},
[MA35D1_RESET_SSPCC] = {0x2C, 31}
};
static int ma35d1_restart_handler(struct notifier_block *this, unsigned long mode, void *cmd)
{
struct ma35d1_reset_data *data =
container_of(this, struct ma35d1_reset_data, restart_handler);
u32 id = MA35D1_RESET_CHIP;
writel_relaxed(BIT(ma35d1_reset_map[id].bit),
data->base + ma35d1_reset_map[id].reg_ofs);
return 0;
}
static int ma35d1_reset_update(struct reset_controller_dev *rcdev, unsigned long id, bool assert)
{
struct ma35d1_reset_data *data = container_of(rcdev, struct ma35d1_reset_data, rcdev);
unsigned long flags;
u32 reg;
if (WARN_ON_ONCE(id >= ARRAY_SIZE(ma35d1_reset_map)))
return -EINVAL;
spin_lock_irqsave(&data->lock, flags);
reg = readl_relaxed(data->base + ma35d1_reset_map[id].reg_ofs);
if (assert)
reg |= BIT(ma35d1_reset_map[id].bit);
else
reg &= ~(BIT(ma35d1_reset_map[id].bit));
writel_relaxed(reg, data->base + ma35d1_reset_map[id].reg_ofs);
spin_unlock_irqrestore(&data->lock, flags);
return 0;
}
static int ma35d1_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
{
return ma35d1_reset_update(rcdev, id, true);
}
static int ma35d1_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id)
{
return ma35d1_reset_update(rcdev, id, false);
}
static int ma35d1_reset_status(struct reset_controller_dev *rcdev, unsigned long id)
{
struct ma35d1_reset_data *data = container_of(rcdev, struct ma35d1_reset_data, rcdev);
u32 reg;
if (WARN_ON_ONCE(id >= ARRAY_SIZE(ma35d1_reset_map)))
return -EINVAL;
reg = readl_relaxed(data->base + ma35d1_reset_map[id].reg_ofs);
return !!(reg & BIT(ma35d1_reset_map[id].bit));
}
static const struct reset_control_ops ma35d1_reset_ops = {
.assert = ma35d1_reset_assert,
.deassert = ma35d1_reset_deassert,
.status = ma35d1_reset_status,
};
static const struct of_device_id ma35d1_reset_dt_ids[] = {
{ .compatible = "nuvoton,ma35d1-reset" },
{ },
};
static int ma35d1_reset_probe(struct platform_device *pdev)
{
struct ma35d1_reset_data *reset_data;
struct device *dev = &pdev->dev;
int err;
if (!pdev->dev.of_node) {
dev_err(&pdev->dev, "Device tree node not found\n");
return -EINVAL;
}
reset_data = devm_kzalloc(dev, sizeof(*reset_data), GFP_KERNEL);
if (!reset_data)
return -ENOMEM;
reset_data->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(reset_data->base))
return PTR_ERR(reset_data->base);
reset_data->rcdev.owner = THIS_MODULE;
reset_data->rcdev.nr_resets = MA35D1_RESET_COUNT;
reset_data->rcdev.ops = &ma35d1_reset_ops;
reset_data->rcdev.of_node = dev->of_node;
reset_data->restart_handler.notifier_call = ma35d1_restart_handler;
reset_data->restart_handler.priority = 192;
spin_lock_init(&reset_data->lock);
err = register_restart_handler(&reset_data->restart_handler);
if (err)
dev_warn(&pdev->dev, "failed to register restart handler\n");
return devm_reset_controller_register(dev, &reset_data->rcdev);
}
static struct platform_driver ma35d1_reset_driver = {
.probe = ma35d1_reset_probe,
.driver = {
.name = "ma35d1-reset",
.of_match_table = ma35d1_reset_dt_ids,
},
};
builtin_platform_driver(ma35d1_reset_driver);
/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
/*
* Copyright (C) 2023 Nuvoton Technologies.
*/
#ifndef __DT_BINDINGS_CLOCK_NUVOTON_MA35D1_CLK_H
#define __DT_BINDINGS_CLOCK_NUVOTON_MA35D1_CLK_H
/* external and internal oscillator clocks */
#define HXT 0
#define HXT_GATE 1
#define LXT 2
#define LXT_GATE 3
#define HIRC 4
#define HIRC_GATE 5
#define LIRC 6
#define LIRC_GATE 7
/* PLLs */
#define CAPLL 8
#define SYSPLL 9
#define DDRPLL 10
#define APLL 11
#define EPLL 12
#define VPLL 13
/* EPLL divider */
#define EPLL_DIV2 14
#define EPLL_DIV4 15
#define EPLL_DIV8 16
/* CPU clock, system clock, AXI, HCLK and PCLK */
#define CA35CLK_MUX 17
#define AXICLK_DIV2 18
#define AXICLK_DIV4 19
#define AXICLK_MUX 20
#define SYSCLK0_MUX 21
#define SYSCLK1_MUX 22
#define SYSCLK1_DIV2 23
#define HCLK0 24
#define HCLK1 25
#define HCLK2 26
#define PCLK0 27
#define PCLK1 28
#define PCLK2 29
#define HCLK3 30
#define PCLK3 31
#define PCLK4 32
/* AXI and AHB peripheral clocks */
#define USBPHY0 33
#define USBPHY1 34
#define DDR0_GATE 35
#define DDR6_GATE 36
#define CAN0_MUX 37
#define CAN0_DIV 38
#define CAN0_GATE 39
#define CAN1_MUX 40
#define CAN1_DIV 41
#define CAN1_GATE 42
#define CAN2_MUX 43
#define CAN2_DIV 44
#define CAN2_GATE 45
#define CAN3_MUX 46
#define CAN3_DIV 47
#define CAN3_GATE 48
#define SDH0_MUX 49
#define SDH0_GATE 50
#define SDH1_MUX 51
#define SDH1_GATE 52
#define NAND_GATE 53
#define USBD_GATE 54
#define USBH_GATE 55
#define HUSBH0_GATE 56
#define HUSBH1_GATE 57
#define GFX_MUX 58
#define GFX_GATE 59
#define VC8K_GATE 60
#define DCU_MUX 61
#define DCU_GATE 62
#define DCUP_DIV 63
#define EMAC0_GATE 64
#define EMAC1_GATE 65
#define CCAP0_MUX 66
#define CCAP0_DIV 67
#define CCAP0_GATE 68
#define CCAP1_MUX 69
#define CCAP1_DIV 70
#define CCAP1_GATE 71
#define PDMA0_GATE 72
#define PDMA1_GATE 73
#define PDMA2_GATE 74
#define PDMA3_GATE 75
#define WH0_GATE 76
#define WH1_GATE 77
#define HWS_GATE 78
#define EBI_GATE 79
#define SRAM0_GATE 80
#define SRAM1_GATE 81
#define ROM_GATE 82
#define TRA_GATE 83
#define DBG_MUX 84
#define DBG_GATE 85
#define CKO_MUX 86
#define CKO_DIV 87
#define CKO_GATE 88
#define GTMR_GATE 89
#define GPA_GATE 90
#define GPB_GATE 91
#define GPC_GATE 92
#define GPD_GATE 93
#define GPE_GATE 94
#define GPF_GATE 95
#define GPG_GATE 96
#define GPH_GATE 97
#define GPI_GATE 98
#define GPJ_GATE 99
#define GPK_GATE 100
#define GPL_GATE 101
#define GPM_GATE 102
#define GPN_GATE 103
/* APB peripheral clocks */
#define TMR0_MUX 104
#define TMR0_GATE 105
#define TMR1_MUX 106
#define TMR1_GATE 107
#define TMR2_MUX 108
#define TMR2_GATE 109
#define TMR3_MUX 110
#define TMR3_GATE 111
#define TMR4_MUX 112
#define TMR4_GATE 113
#define TMR5_MUX 114
#define TMR5_GATE 115
#define TMR6_MUX 116
#define TMR6_GATE 117
#define TMR7_MUX 118
#define TMR7_GATE 119
#define TMR8_MUX 120
#define TMR8_GATE 121
#define TMR9_MUX 122
#define TMR9_GATE 123
#define TMR10_MUX 124
#define TMR10_GATE 125
#define TMR11_MUX 126
#define TMR11_GATE 127
#define UART0_MUX 128
#define UART0_DIV 129
#define UART0_GATE 130
#define UART1_MUX 131
#define UART1_DIV 132
#define UART1_GATE 133
#define UART2_MUX 134
#define UART2_DIV 135
#define UART2_GATE 136
#define UART3_MUX 137
#define UART3_DIV 138
#define UART3_GATE 139
#define UART4_MUX 140
#define UART4_DIV 141
#define UART4_GATE 142
#define UART5_MUX 143
#define UART5_DIV 144
#define UART5_GATE 145
#define UART6_MUX 146
#define UART6_DIV 147
#define UART6_GATE 148
#define UART7_MUX 149
#define UART7_DIV 150
#define UART7_GATE 151
#define UART8_MUX 152
#define UART8_DIV 153
#define UART8_GATE 154
#define UART9_MUX 155
#define UART9_DIV 156
#define UART9_GATE 157
#define UART10_MUX 158
#define UART10_DIV 159
#define UART10_GATE 160
#define UART11_MUX 161
#define UART11_DIV 162
#define UART11_GATE 163
#define UART12_MUX 164
#define UART12_DIV 165
#define UART12_GATE 166
#define UART13_MUX 167
#define UART13_DIV 168
#define UART13_GATE 169
#define UART14_MUX 170
#define UART14_DIV 171
#define UART14_GATE 172
#define UART15_MUX 173
#define UART15_DIV 174
#define UART15_GATE 175
#define UART16_MUX 176
#define UART16_DIV 177
#define UART16_GATE 178
#define RTC_GATE 179
#define DDR_GATE 180
#define KPI_MUX 181
#define KPI_DIV 182
#define KPI_GATE 183
#define I2C0_GATE 184
#define I2C1_GATE 185
#define I2C2_GATE 186
#define I2C3_GATE 187
#define I2C4_GATE 188
#define I2C5_GATE 189
#define QSPI0_MUX 190
#define QSPI0_GATE 191
#define QSPI1_MUX 192
#define QSPI1_GATE 193
#define SMC0_MUX 194
#define SMC0_DIV 195
#define SMC0_GATE 196
#define SMC1_MUX 197
#define SMC1_DIV 198
#define SMC1_GATE 199
#define WDT0_MUX 200
#define WDT0_GATE 201
#define WDT1_MUX 202
#define WDT1_GATE 203
#define WDT2_MUX 204
#define WDT2_GATE 205
#define WWDT0_MUX 206
#define WWDT1_MUX 207
#define WWDT2_MUX 208
#define EPWM0_GATE 209
#define EPWM1_GATE 210
#define EPWM2_GATE 211
#define I2S0_MUX 212
#define I2S0_GATE 213
#define I2S1_MUX 214
#define I2S1_GATE 215
#define SSMCC_GATE 216
#define SSPCC_GATE 217
#define SPI0_MUX 218
#define SPI0_GATE 219
#define SPI1_MUX 220
#define SPI1_GATE 221
#define SPI2_MUX 222
#define SPI2_GATE 223
#define SPI3_MUX 224
#define SPI3_GATE 225
#define ECAP0_GATE 226
#define ECAP1_GATE 227
#define ECAP2_GATE 228
#define QEI0_GATE 229
#define QEI1_GATE 230
#define QEI2_GATE 231
#define ADC_DIV 232
#define ADC_GATE 233
#define EADC_DIV 234
#define EADC_GATE 235
#define CLK_MAX_IDX 236
#endif /* __DT_BINDINGS_CLOCK_NUVOTON_MA35D1_CLK_H */
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
/*
* Copyright (C) 2023 Nuvoton Technologies.
* Author: Chi-Fen Li <cfli0@nuvoton.com>
*
* Device Tree binding constants for MA35D1 reset controller.
*/
#ifndef __DT_BINDINGS_RESET_MA35D1_H
#define __DT_BINDINGS_RESET_MA35D1_H
#define MA35D1_RESET_CHIP 0
#define MA35D1_RESET_CA35CR0 1
#define MA35D1_RESET_CA35CR1 2
#define MA35D1_RESET_CM4 3
#define MA35D1_RESET_PDMA0 4
#define MA35D1_RESET_PDMA1 5
#define MA35D1_RESET_PDMA2 6
#define MA35D1_RESET_PDMA3 7
#define MA35D1_RESET_DISP 8
#define MA35D1_RESET_VCAP0 9
#define MA35D1_RESET_VCAP1 10
#define MA35D1_RESET_GFX 11
#define MA35D1_RESET_VDEC 12
#define MA35D1_RESET_WHC0 13
#define MA35D1_RESET_WHC1 14
#define MA35D1_RESET_GMAC0 15
#define MA35D1_RESET_GMAC1 16
#define MA35D1_RESET_HWSEM 17
#define MA35D1_RESET_EBI 18
#define MA35D1_RESET_HSUSBH0 19
#define MA35D1_RESET_HSUSBH1 20
#define MA35D1_RESET_HSUSBD 21
#define MA35D1_RESET_USBHL 22
#define MA35D1_RESET_SDH0 23
#define MA35D1_RESET_SDH1 24
#define MA35D1_RESET_NAND 25
#define MA35D1_RESET_GPIO 26
#define MA35D1_RESET_MCTLP 27
#define MA35D1_RESET_MCTLC 28
#define MA35D1_RESET_DDRPUB 29
#define MA35D1_RESET_TMR0 30
#define MA35D1_RESET_TMR1 31
#define MA35D1_RESET_TMR2 32
#define MA35D1_RESET_TMR3 33
#define MA35D1_RESET_I2C0 34
#define MA35D1_RESET_I2C1 35
#define MA35D1_RESET_I2C2 36
#define MA35D1_RESET_I2C3 37
#define MA35D1_RESET_QSPI0 38
#define MA35D1_RESET_SPI0 39
#define MA35D1_RESET_SPI1 40
#define MA35D1_RESET_SPI2 41
#define MA35D1_RESET_UART0 42
#define MA35D1_RESET_UART1 43
#define MA35D1_RESET_UART2 44
#define MA35D1_RESET_UART3 45
#define MA35D1_RESET_UART4 46
#define MA35D1_RESET_UART5 47
#define MA35D1_RESET_UART6 48
#define MA35D1_RESET_UART7 49
#define MA35D1_RESET_CANFD0 50
#define MA35D1_RESET_CANFD1 51
#define MA35D1_RESET_EADC0 52
#define MA35D1_RESET_I2S0 53
#define MA35D1_RESET_SC0 54
#define MA35D1_RESET_SC1 55
#define MA35D1_RESET_QSPI1 56
#define MA35D1_RESET_SPI3 57
#define MA35D1_RESET_EPWM0 58
#define MA35D1_RESET_EPWM1 59
#define MA35D1_RESET_QEI0 60
#define MA35D1_RESET_QEI1 61
#define MA35D1_RESET_ECAP0 62
#define MA35D1_RESET_ECAP1 63
#define MA35D1_RESET_CANFD2 64
#define MA35D1_RESET_ADC0 65
#define MA35D1_RESET_TMR4 66
#define MA35D1_RESET_TMR5 67
#define MA35D1_RESET_TMR6 68
#define MA35D1_RESET_TMR7 69
#define MA35D1_RESET_TMR8 70
#define MA35D1_RESET_TMR9 71
#define MA35D1_RESET_TMR10 72
#define MA35D1_RESET_TMR11 73
#define MA35D1_RESET_UART8 74
#define MA35D1_RESET_UART9 75
#define MA35D1_RESET_UART10 76
#define MA35D1_RESET_UART11 77
#define MA35D1_RESET_UART12 78
#define MA35D1_RESET_UART13 79
#define MA35D1_RESET_UART14 80
#define MA35D1_RESET_UART15 81
#define MA35D1_RESET_UART16 82
#define MA35D1_RESET_I2S1 83
#define MA35D1_RESET_I2C4 84
#define MA35D1_RESET_I2C5 85
#define MA35D1_RESET_EPWM2 86
#define MA35D1_RESET_ECAP2 87
#define MA35D1_RESET_QEI2 88
#define MA35D1_RESET_CANFD3 89
#define MA35D1_RESET_KPI 90
#define MA35D1_RESET_GIC 91
#define MA35D1_RESET_SSMCC 92
#define MA35D1_RESET_SSPCC 93
#define MA35D1_RESET_COUNT 94
#endif
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