xref: /openbmc/u-boot/drivers/clk/sunxi/clk_h3.c (revision 2e8092d94f40a5692baf3ec768ce3216a7bf032a)
1e945816eSJagan Teki // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2e945816eSJagan Teki /*
3e945816eSJagan Teki  * Copyright (C) 2018 Amarula Solutions.
4e945816eSJagan Teki  * Author: Jagan Teki <jagan@amarulasolutions.com>
5e945816eSJagan Teki  */
6e945816eSJagan Teki 
7e945816eSJagan Teki #include <common.h>
8e945816eSJagan Teki #include <clk-uclass.h>
9e945816eSJagan Teki #include <dm.h>
10e945816eSJagan Teki #include <errno.h>
11e945816eSJagan Teki #include <asm/arch/ccu.h>
12e945816eSJagan Teki #include <dt-bindings/clock/sun8i-h3-ccu.h>
13e945816eSJagan Teki #include <dt-bindings/reset/sun8i-h3-ccu.h>
14e945816eSJagan Teki 
15e945816eSJagan Teki static struct ccu_clk_gate h3_gates[] = {
16bb3e5aa2SAndre Przywara 	[CLK_BUS_MMC0]		= GATE(0x060, BIT(8)),
17bb3e5aa2SAndre Przywara 	[CLK_BUS_MMC1]		= GATE(0x060, BIT(9)),
18bb3e5aa2SAndre Przywara 	[CLK_BUS_MMC2]		= GATE(0x060, BIT(10)),
1968620c96SJagan Teki 	[CLK_BUS_EMAC]		= GATE(0x060, BIT(17)),
2082111469SJagan Teki 	[CLK_BUS_SPI0]		= GATE(0x060, BIT(20)),
2182111469SJagan Teki 	[CLK_BUS_SPI1]		= GATE(0x060, BIT(21)),
22e945816eSJagan Teki 	[CLK_BUS_OTG]		= GATE(0x060, BIT(23)),
23e945816eSJagan Teki 	[CLK_BUS_EHCI0]		= GATE(0x060, BIT(24)),
24e945816eSJagan Teki 	[CLK_BUS_EHCI1]		= GATE(0x060, BIT(25)),
25e945816eSJagan Teki 	[CLK_BUS_EHCI2]		= GATE(0x060, BIT(26)),
26e945816eSJagan Teki 	[CLK_BUS_EHCI3]		= GATE(0x060, BIT(27)),
27e945816eSJagan Teki 	[CLK_BUS_OHCI0]		= GATE(0x060, BIT(28)),
28e945816eSJagan Teki 	[CLK_BUS_OHCI1]		= GATE(0x060, BIT(29)),
29e945816eSJagan Teki 	[CLK_BUS_OHCI2]		= GATE(0x060, BIT(30)),
30e945816eSJagan Teki 	[CLK_BUS_OHCI3]		= GATE(0x060, BIT(31)),
31e945816eSJagan Teki 
324acc7119SJagan Teki 	[CLK_BUS_UART0]		= GATE(0x06c, BIT(16)),
334acc7119SJagan Teki 	[CLK_BUS_UART1]		= GATE(0x06c, BIT(17)),
344acc7119SJagan Teki 	[CLK_BUS_UART2]		= GATE(0x06c, BIT(18)),
354acc7119SJagan Teki 	[CLK_BUS_UART3]		= GATE(0x06c, BIT(19)),
364acc7119SJagan Teki 
37*aefc0b7aSJagan Teki 	[CLK_BUS_EPHY]		= GATE(0x070, BIT(0)),
38*aefc0b7aSJagan Teki 
3982111469SJagan Teki 	[CLK_SPI0]		= GATE(0x0a0, BIT(31)),
4082111469SJagan Teki 	[CLK_SPI1]		= GATE(0x0a4, BIT(31)),
4182111469SJagan Teki 
42e945816eSJagan Teki 	[CLK_USB_PHY0]		= GATE(0x0cc, BIT(8)),
43e945816eSJagan Teki 	[CLK_USB_PHY1]		= GATE(0x0cc, BIT(9)),
44e945816eSJagan Teki 	[CLK_USB_PHY2]		= GATE(0x0cc, BIT(10)),
45e945816eSJagan Teki 	[CLK_USB_PHY3]		= GATE(0x0cc, BIT(11)),
46e945816eSJagan Teki 	[CLK_USB_OHCI0]		= GATE(0x0cc, BIT(16)),
47e945816eSJagan Teki 	[CLK_USB_OHCI1]		= GATE(0x0cc, BIT(17)),
48e945816eSJagan Teki 	[CLK_USB_OHCI2]		= GATE(0x0cc, BIT(18)),
49e945816eSJagan Teki 	[CLK_USB_OHCI3]		= GATE(0x0cc, BIT(19)),
50e945816eSJagan Teki };
51e945816eSJagan Teki 
52e945816eSJagan Teki static struct ccu_reset h3_resets[] = {
53e945816eSJagan Teki 	[RST_USB_PHY0]		= RESET(0x0cc, BIT(0)),
54e945816eSJagan Teki 	[RST_USB_PHY1]		= RESET(0x0cc, BIT(1)),
55e945816eSJagan Teki 	[RST_USB_PHY2]		= RESET(0x0cc, BIT(2)),
56e945816eSJagan Teki 	[RST_USB_PHY3]		= RESET(0x0cc, BIT(3)),
57e945816eSJagan Teki 
58bb3e5aa2SAndre Przywara 	[RST_BUS_MMC0]		= RESET(0x2c0, BIT(8)),
59bb3e5aa2SAndre Przywara 	[RST_BUS_MMC1]		= RESET(0x2c0, BIT(9)),
60bb3e5aa2SAndre Przywara 	[RST_BUS_MMC2]		= RESET(0x2c0, BIT(10)),
6168620c96SJagan Teki 	[RST_BUS_EMAC]		= RESET(0x2c0, BIT(17)),
6282111469SJagan Teki 	[RST_BUS_SPI0]		= RESET(0x2c0, BIT(20)),
6382111469SJagan Teki 	[RST_BUS_SPI1]		= RESET(0x2c0, BIT(21)),
64e945816eSJagan Teki 	[RST_BUS_OTG]		= RESET(0x2c0, BIT(23)),
65e945816eSJagan Teki 	[RST_BUS_EHCI0]		= RESET(0x2c0, BIT(24)),
66e945816eSJagan Teki 	[RST_BUS_EHCI1]		= RESET(0x2c0, BIT(25)),
67e945816eSJagan Teki 	[RST_BUS_EHCI2]		= RESET(0x2c0, BIT(26)),
68e945816eSJagan Teki 	[RST_BUS_EHCI3]		= RESET(0x2c0, BIT(27)),
69e945816eSJagan Teki 	[RST_BUS_OHCI0]		= RESET(0x2c0, BIT(28)),
70e945816eSJagan Teki 	[RST_BUS_OHCI1]		= RESET(0x2c0, BIT(29)),
71e945816eSJagan Teki 	[RST_BUS_OHCI2]		= RESET(0x2c0, BIT(30)),
72e945816eSJagan Teki 	[RST_BUS_OHCI3]		= RESET(0x2c0, BIT(31)),
738606f960SJagan Teki 
74*aefc0b7aSJagan Teki 	[RST_BUS_EPHY]		= RESET(0x2c8, BIT(2)),
75*aefc0b7aSJagan Teki 
768606f960SJagan Teki 	[RST_BUS_UART0]		= RESET(0x2d8, BIT(16)),
778606f960SJagan Teki 	[RST_BUS_UART1]		= RESET(0x2d8, BIT(17)),
788606f960SJagan Teki 	[RST_BUS_UART2]		= RESET(0x2d8, BIT(18)),
798606f960SJagan Teki 	[RST_BUS_UART3]		= RESET(0x2d8, BIT(19)),
80e945816eSJagan Teki };
81e945816eSJagan Teki 
82e945816eSJagan Teki static const struct ccu_desc h3_ccu_desc = {
83e945816eSJagan Teki 	.gates = h3_gates,
84e945816eSJagan Teki 	.resets = h3_resets,
85e945816eSJagan Teki };
86e945816eSJagan Teki 
h3_clk_bind(struct udevice * dev)87e945816eSJagan Teki static int h3_clk_bind(struct udevice *dev)
88e945816eSJagan Teki {
89e945816eSJagan Teki 	return sunxi_reset_bind(dev, ARRAY_SIZE(h3_resets));
90e945816eSJagan Teki }
91e945816eSJagan Teki 
92e945816eSJagan Teki static const struct udevice_id h3_ccu_ids[] = {
93e945816eSJagan Teki 	{ .compatible = "allwinner,sun8i-h3-ccu",
94e945816eSJagan Teki 	  .data = (ulong)&h3_ccu_desc },
95e945816eSJagan Teki 	{ .compatible = "allwinner,sun50i-h5-ccu",
96e945816eSJagan Teki 	  .data = (ulong)&h3_ccu_desc },
97e945816eSJagan Teki 	{ }
98e945816eSJagan Teki };
99e945816eSJagan Teki 
100e945816eSJagan Teki U_BOOT_DRIVER(clk_sun8i_h3) = {
101e945816eSJagan Teki 	.name		= "sun8i_h3_ccu",
102e945816eSJagan Teki 	.id		= UCLASS_CLK,
103e945816eSJagan Teki 	.of_match	= h3_ccu_ids,
104e945816eSJagan Teki 	.priv_auto_alloc_size	= sizeof(struct ccu_priv),
105e945816eSJagan Teki 	.ops		= &sunxi_clk_ops,
106e945816eSJagan Teki 	.probe		= sunxi_clk_probe,
107e945816eSJagan Teki 	.bind		= h3_clk_bind,
108e945816eSJagan Teki };
109