Jagan Teki | 6901aab | 2019-01-11 15:41:46 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2018 Amarula Solutions. |
| 4 | * Author: Jagan Teki <jagan@amarulasolutions.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <clk-uclass.h> |
| 9 | #include <dm.h> |
| 10 | #include <errno.h> |
Samuel Holland | 21d314a | 2021-09-12 11:48:43 -0500 | [diff] [blame] | 11 | #include <clk/sunxi.h> |
Jagan Teki | 6901aab | 2019-01-11 15:41:46 +0530 | [diff] [blame] | 12 | #include <dt-bindings/clock/sun9i-a80-ccu.h> |
| 13 | #include <dt-bindings/reset/sun9i-a80-ccu.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 14 | #include <linux/bitops.h> |
Jagan Teki | 6901aab | 2019-01-11 15:41:46 +0530 | [diff] [blame] | 15 | |
| 16 | static const struct ccu_clk_gate a80_gates[] = { |
Jagan Teki | 8211146 | 2019-02-27 20:02:06 +0530 | [diff] [blame] | 17 | [CLK_SPI0] = GATE(0x430, BIT(31)), |
| 18 | [CLK_SPI1] = GATE(0x434, BIT(31)), |
| 19 | [CLK_SPI2] = GATE(0x438, BIT(31)), |
| 20 | [CLK_SPI3] = GATE(0x43c, BIT(31)), |
| 21 | |
Andre Przywara | bb3e5aa | 2019-01-29 15:54:09 +0000 | [diff] [blame] | 22 | [CLK_BUS_MMC] = GATE(0x580, BIT(8)), |
Jagan Teki | 8211146 | 2019-02-27 20:02:06 +0530 | [diff] [blame] | 23 | [CLK_BUS_SPI0] = GATE(0x580, BIT(20)), |
| 24 | [CLK_BUS_SPI1] = GATE(0x580, BIT(21)), |
| 25 | [CLK_BUS_SPI2] = GATE(0x580, BIT(22)), |
| 26 | [CLK_BUS_SPI3] = GATE(0x580, BIT(23)), |
Andre Przywara | bb3e5aa | 2019-01-29 15:54:09 +0000 | [diff] [blame] | 27 | |
Andre Przywara | 444ab35 | 2022-05-04 22:10:28 +0100 | [diff] [blame] | 28 | [CLK_BUS_PIO] = GATE(0x590, BIT(5)), |
| 29 | |
Samuel Holland | c61897b | 2021-09-12 09:47:24 -0500 | [diff] [blame] | 30 | [CLK_BUS_I2C0] = GATE(0x594, BIT(0)), |
| 31 | [CLK_BUS_I2C1] = GATE(0x594, BIT(1)), |
| 32 | [CLK_BUS_I2C2] = GATE(0x594, BIT(2)), |
| 33 | [CLK_BUS_I2C3] = GATE(0x594, BIT(3)), |
| 34 | [CLK_BUS_I2C4] = GATE(0x594, BIT(4)), |
Jagan Teki | 6901aab | 2019-01-11 15:41:46 +0530 | [diff] [blame] | 35 | [CLK_BUS_UART0] = GATE(0x594, BIT(16)), |
| 36 | [CLK_BUS_UART1] = GATE(0x594, BIT(17)), |
| 37 | [CLK_BUS_UART2] = GATE(0x594, BIT(18)), |
| 38 | [CLK_BUS_UART3] = GATE(0x594, BIT(19)), |
| 39 | [CLK_BUS_UART4] = GATE(0x594, BIT(20)), |
| 40 | [CLK_BUS_UART5] = GATE(0x594, BIT(21)), |
| 41 | }; |
| 42 | |
| 43 | static const struct ccu_reset a80_resets[] = { |
Andre Przywara | bb3e5aa | 2019-01-29 15:54:09 +0000 | [diff] [blame] | 44 | [RST_BUS_MMC] = RESET(0x5a0, BIT(8)), |
Jagan Teki | 8211146 | 2019-02-27 20:02:06 +0530 | [diff] [blame] | 45 | [RST_BUS_SPI0] = RESET(0x5a0, BIT(20)), |
| 46 | [RST_BUS_SPI1] = RESET(0x5a0, BIT(21)), |
| 47 | [RST_BUS_SPI2] = RESET(0x5a0, BIT(22)), |
| 48 | [RST_BUS_SPI3] = RESET(0x5a0, BIT(23)), |
Andre Przywara | bb3e5aa | 2019-01-29 15:54:09 +0000 | [diff] [blame] | 49 | |
Samuel Holland | c61897b | 2021-09-12 09:47:24 -0500 | [diff] [blame] | 50 | [RST_BUS_I2C0] = RESET(0x5b4, BIT(0)), |
| 51 | [RST_BUS_I2C1] = RESET(0x5b4, BIT(1)), |
| 52 | [RST_BUS_I2C2] = RESET(0x5b4, BIT(2)), |
| 53 | [RST_BUS_I2C3] = RESET(0x5b4, BIT(3)), |
| 54 | [RST_BUS_I2C4] = RESET(0x5b4, BIT(4)), |
Jagan Teki | 6901aab | 2019-01-11 15:41:46 +0530 | [diff] [blame] | 55 | [RST_BUS_UART0] = RESET(0x5b4, BIT(16)), |
| 56 | [RST_BUS_UART1] = RESET(0x5b4, BIT(17)), |
| 57 | [RST_BUS_UART2] = RESET(0x5b4, BIT(18)), |
| 58 | [RST_BUS_UART3] = RESET(0x5b4, BIT(19)), |
| 59 | [RST_BUS_UART4] = RESET(0x5b4, BIT(20)), |
| 60 | [RST_BUS_UART5] = RESET(0x5b4, BIT(21)), |
| 61 | }; |
| 62 | |
Andre Przywara | e0c7ce7 | 2019-01-29 15:54:10 +0000 | [diff] [blame] | 63 | static const struct ccu_clk_gate a80_mmc_gates[] = { |
| 64 | [0] = GATE(0x0, BIT(16)), |
| 65 | [1] = GATE(0x4, BIT(16)), |
| 66 | [2] = GATE(0x8, BIT(16)), |
| 67 | [3] = GATE(0xc, BIT(16)), |
| 68 | }; |
| 69 | |
| 70 | static const struct ccu_reset a80_mmc_resets[] = { |
| 71 | [0] = GATE(0x0, BIT(18)), |
| 72 | [1] = GATE(0x4, BIT(18)), |
| 73 | [2] = GATE(0x8, BIT(18)), |
| 74 | [3] = GATE(0xc, BIT(18)), |
| 75 | }; |
| 76 | |
Jagan Teki | 6901aab | 2019-01-11 15:41:46 +0530 | [diff] [blame] | 77 | static const struct ccu_desc a80_ccu_desc = { |
| 78 | .gates = a80_gates, |
| 79 | .resets = a80_resets, |
| 80 | }; |
| 81 | |
Andre Przywara | e0c7ce7 | 2019-01-29 15:54:10 +0000 | [diff] [blame] | 82 | static const struct ccu_desc a80_mmc_clk_desc = { |
| 83 | .gates = a80_mmc_gates, |
| 84 | .resets = a80_mmc_resets, |
| 85 | }; |
| 86 | |
Jagan Teki | 6901aab | 2019-01-11 15:41:46 +0530 | [diff] [blame] | 87 | static int a80_clk_bind(struct udevice *dev) |
| 88 | { |
Andre Przywara | e0c7ce7 | 2019-01-29 15:54:10 +0000 | [diff] [blame] | 89 | ulong count = ARRAY_SIZE(a80_resets); |
| 90 | |
| 91 | if (device_is_compatible(dev, "allwinner,sun9i-a80-mmc-config-clk")) |
| 92 | count = ARRAY_SIZE(a80_mmc_resets); |
| 93 | |
| 94 | return sunxi_reset_bind(dev, count); |
Jagan Teki | 6901aab | 2019-01-11 15:41:46 +0530 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static const struct udevice_id a80_ccu_ids[] = { |
| 98 | { .compatible = "allwinner,sun9i-a80-ccu", |
| 99 | .data = (ulong)&a80_ccu_desc }, |
Andre Przywara | e0c7ce7 | 2019-01-29 15:54:10 +0000 | [diff] [blame] | 100 | { .compatible = "allwinner,sun9i-a80-mmc-config-clk", |
| 101 | .data = (ulong)&a80_mmc_clk_desc }, |
Jagan Teki | 6901aab | 2019-01-11 15:41:46 +0530 | [diff] [blame] | 102 | { } |
| 103 | }; |
| 104 | |
| 105 | U_BOOT_DRIVER(clk_sun9i_a80) = { |
| 106 | .name = "sun9i_a80_ccu", |
| 107 | .id = UCLASS_CLK, |
| 108 | .of_match = a80_ccu_ids, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 109 | .priv_auto = sizeof(struct ccu_priv), |
Jagan Teki | 6901aab | 2019-01-11 15:41:46 +0530 | [diff] [blame] | 110 | .ops = &sunxi_clk_ops, |
| 111 | .probe = sunxi_clk_probe, |
| 112 | .bind = a80_clk_bind, |
| 113 | }; |