xref: /openbmc/u-boot/drivers/clk/sunxi/clk_a10.c (revision 82111469)
16590bd8cSJagan Teki // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
26590bd8cSJagan Teki /*
36590bd8cSJagan Teki  * Copyright (C) 2018 Amarula Solutions.
46590bd8cSJagan Teki  * Author: Jagan Teki <jagan@amarulasolutions.com>
56590bd8cSJagan Teki  */
66590bd8cSJagan Teki 
76590bd8cSJagan Teki #include <common.h>
86590bd8cSJagan Teki #include <clk-uclass.h>
96590bd8cSJagan Teki #include <dm.h>
106590bd8cSJagan Teki #include <errno.h>
116590bd8cSJagan Teki #include <asm/arch/ccu.h>
126590bd8cSJagan Teki #include <dt-bindings/clock/sun4i-a10-ccu.h>
136590bd8cSJagan Teki #include <dt-bindings/reset/sun4i-a10-ccu.h>
146590bd8cSJagan Teki 
156590bd8cSJagan Teki static struct ccu_clk_gate a10_gates[] = {
166590bd8cSJagan Teki 	[CLK_AHB_OTG]		= GATE(0x060, BIT(0)),
176590bd8cSJagan Teki 	[CLK_AHB_EHCI0]		= GATE(0x060, BIT(1)),
186590bd8cSJagan Teki 	[CLK_AHB_OHCI0]		= GATE(0x060, BIT(2)),
196590bd8cSJagan Teki 	[CLK_AHB_EHCI1]		= GATE(0x060, BIT(3)),
206590bd8cSJagan Teki 	[CLK_AHB_OHCI1]		= GATE(0x060, BIT(4)),
21bb3e5aa2SAndre Przywara 	[CLK_AHB_MMC0]		= GATE(0x060, BIT(8)),
22bb3e5aa2SAndre Przywara 	[CLK_AHB_MMC1]		= GATE(0x060, BIT(9)),
23bb3e5aa2SAndre Przywara 	[CLK_AHB_MMC2]		= GATE(0x060, BIT(10)),
24bb3e5aa2SAndre Przywara 	[CLK_AHB_MMC3]		= GATE(0x060, BIT(11)),
25*82111469SJagan Teki 	[CLK_AHB_SPI0]		= GATE(0x060, BIT(20)),
26*82111469SJagan Teki 	[CLK_AHB_SPI1]		= GATE(0x060, BIT(21)),
27*82111469SJagan Teki 	[CLK_AHB_SPI2]		= GATE(0x060, BIT(22)),
28*82111469SJagan Teki 	[CLK_AHB_SPI3]		= GATE(0x060, BIT(23)),
296590bd8cSJagan Teki 
304acc7119SJagan Teki 	[CLK_APB1_UART0]	= GATE(0x06c, BIT(16)),
314acc7119SJagan Teki 	[CLK_APB1_UART1]	= GATE(0x06c, BIT(17)),
324acc7119SJagan Teki 	[CLK_APB1_UART2]	= GATE(0x06c, BIT(18)),
334acc7119SJagan Teki 	[CLK_APB1_UART3]	= GATE(0x06c, BIT(19)),
344acc7119SJagan Teki 	[CLK_APB1_UART4]	= GATE(0x06c, BIT(20)),
354acc7119SJagan Teki 	[CLK_APB1_UART5]	= GATE(0x06c, BIT(21)),
364acc7119SJagan Teki 	[CLK_APB1_UART6]	= GATE(0x06c, BIT(22)),
374acc7119SJagan Teki 	[CLK_APB1_UART7]	= GATE(0x06c, BIT(23)),
384acc7119SJagan Teki 
39*82111469SJagan Teki 	[CLK_SPI0]		= GATE(0x0a0, BIT(31)),
40*82111469SJagan Teki 	[CLK_SPI1]		= GATE(0x0a4, BIT(31)),
41*82111469SJagan Teki 	[CLK_SPI2]		= GATE(0x0a8, BIT(31)),
42*82111469SJagan Teki 
436590bd8cSJagan Teki 	[CLK_USB_OHCI0]		= GATE(0x0cc, BIT(6)),
446590bd8cSJagan Teki 	[CLK_USB_OHCI1]		= GATE(0x0cc, BIT(7)),
456590bd8cSJagan Teki 	[CLK_USB_PHY]		= GATE(0x0cc, BIT(8)),
46*82111469SJagan Teki 
47*82111469SJagan Teki 	[CLK_SPI3]		= GATE(0x0d4, BIT(31)),
486590bd8cSJagan Teki };
496590bd8cSJagan Teki 
506590bd8cSJagan Teki static struct ccu_reset a10_resets[] = {
516590bd8cSJagan Teki 	[RST_USB_PHY0]		= RESET(0x0cc, BIT(0)),
526590bd8cSJagan Teki 	[RST_USB_PHY1]		= RESET(0x0cc, BIT(1)),
536590bd8cSJagan Teki 	[RST_USB_PHY2]		= RESET(0x0cc, BIT(2)),
546590bd8cSJagan Teki };
556590bd8cSJagan Teki 
566590bd8cSJagan Teki static const struct ccu_desc a10_ccu_desc = {
576590bd8cSJagan Teki 	.gates = a10_gates,
586590bd8cSJagan Teki 	.resets = a10_resets,
596590bd8cSJagan Teki };
606590bd8cSJagan Teki 
616590bd8cSJagan Teki static int a10_clk_bind(struct udevice *dev)
626590bd8cSJagan Teki {
636590bd8cSJagan Teki 	return sunxi_reset_bind(dev, ARRAY_SIZE(a10_resets));
646590bd8cSJagan Teki }
656590bd8cSJagan Teki 
666590bd8cSJagan Teki static const struct udevice_id a10_ccu_ids[] = {
676590bd8cSJagan Teki 	{ .compatible = "allwinner,sun4i-a10-ccu",
686590bd8cSJagan Teki 	  .data = (ulong)&a10_ccu_desc },
696590bd8cSJagan Teki 	{ .compatible = "allwinner,sun7i-a20-ccu",
706590bd8cSJagan Teki 	  .data = (ulong)&a10_ccu_desc },
716590bd8cSJagan Teki 	{ }
726590bd8cSJagan Teki };
736590bd8cSJagan Teki 
746590bd8cSJagan Teki U_BOOT_DRIVER(clk_sun4i_a10) = {
756590bd8cSJagan Teki 	.name		= "sun4i_a10_ccu",
766590bd8cSJagan Teki 	.id		= UCLASS_CLK,
776590bd8cSJagan Teki 	.of_match	= a10_ccu_ids,
786590bd8cSJagan Teki 	.priv_auto_alloc_size	= sizeof(struct ccu_priv),
796590bd8cSJagan Teki 	.ops		= &sunxi_clk_ops,
806590bd8cSJagan Teki 	.probe		= sunxi_clk_probe,
816590bd8cSJagan Teki 	.bind		= a10_clk_bind,
826590bd8cSJagan Teki };
83