Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 19c58cf | 2015-08-30 16:55:34 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | 19c58cf | 2015-08-30 16:55:34 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | 19c58cf | 2015-08-30 16:55:34 -0600 | [diff] [blame] | 7 | #include <dm.h> |
Johan Jonker | 6ba857d | 2023-03-13 01:30:57 +0100 | [diff] [blame] | 8 | #include <dt-structs.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Johan Jonker | 6ba857d | 2023-03-13 01:30:57 +0100 | [diff] [blame] | 10 | #include <malloc.h> |
| 11 | #include <regmap.h> |
Simon Glass | 19c58cf | 2015-08-30 16:55:34 -0600 | [diff] [blame] | 12 | #include <syscon.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 13 | #include <asm/arch-rockchip/clock.h> |
Simon Glass | 19c58cf | 2015-08-30 16:55:34 -0600 | [diff] [blame] | 14 | |
| 15 | static const struct udevice_id rk3288_syscon_ids[] = { |
| 16 | { .compatible = "rockchip,rk3288-noc", .data = ROCKCHIP_SYSCON_NOC }, |
| 17 | { .compatible = "rockchip,rk3288-grf", .data = ROCKCHIP_SYSCON_GRF }, |
| 18 | { .compatible = "rockchip,rk3288-sgrf", .data = ROCKCHIP_SYSCON_SGRF }, |
| 19 | { .compatible = "rockchip,rk3288-pmu", .data = ROCKCHIP_SYSCON_PMU }, |
| 20 | { } |
| 21 | }; |
| 22 | |
| 23 | U_BOOT_DRIVER(syscon_rk3288) = { |
| 24 | .name = "rk3288_syscon", |
| 25 | .id = UCLASS_SYSCON, |
| 26 | .of_match = rk3288_syscon_ids, |
| 27 | }; |
Simon Glass | d63ea43 | 2016-07-04 11:58:33 -0600 | [diff] [blame] | 28 | |
| 29 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
Johan Jonker | 6ba857d | 2023-03-13 01:30:57 +0100 | [diff] [blame] | 30 | #if IS_ENABLED(CONFIG_FDT_64BIT) |
| 31 | struct rockchip_rk3288_noc_plat { |
| 32 | struct dtd_rockchip_rk3288_noc dtplat; |
| 33 | }; |
| 34 | |
| 35 | struct rockchip_rk3288_grf_plat { |
| 36 | struct dtd_rockchip_rk3288_grf dtplat; |
| 37 | }; |
| 38 | |
| 39 | struct rockchip_rk3288_sgrf_plat { |
| 40 | struct dtd_rockchip_rk3288_sgrf dtplat; |
| 41 | }; |
| 42 | |
| 43 | struct rockchip_rk3288_pmu_plat { |
| 44 | struct dtd_rockchip_rk3288_pmu dtplat; |
| 45 | }; |
| 46 | |
| 47 | static int rk3288_noc_bind_of_plat(struct udevice *dev) |
| 48 | { |
| 49 | struct rockchip_rk3288_noc_plat *plat = dev_get_plat(dev); |
| 50 | struct syscon_uc_info *priv = dev_get_uclass_priv(dev); |
| 51 | int size = dev->uclass->uc_drv->per_device_auto; |
| 52 | |
| 53 | if (size && !priv) { |
| 54 | priv = calloc(1, size); |
| 55 | if (!priv) |
| 56 | return -ENOMEM; |
| 57 | dev_set_uclass_priv(dev, priv); |
| 58 | } |
| 59 | |
| 60 | dev->driver_data = dev->driver->of_match->data; |
| 61 | debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data); |
| 62 | |
| 63 | return regmap_init_mem_plat(dev, plat->dtplat.reg, sizeof(plat->dtplat.reg[0]), |
| 64 | ARRAY_SIZE(plat->dtplat.reg) / 2, &priv->regmap); |
| 65 | } |
| 66 | |
| 67 | static int rk3288_grf_bind_of_plat(struct udevice *dev) |
| 68 | { |
| 69 | struct rockchip_rk3288_grf_plat *plat = dev_get_plat(dev); |
| 70 | struct syscon_uc_info *priv = dev_get_uclass_priv(dev); |
| 71 | int size = dev->uclass->uc_drv->per_device_auto; |
| 72 | |
| 73 | if (size && !priv) { |
| 74 | priv = calloc(1, size); |
| 75 | if (!priv) |
| 76 | return -ENOMEM; |
| 77 | dev_set_uclass_priv(dev, priv); |
| 78 | } |
| 79 | |
| 80 | dev->driver_data = dev->driver->of_match->data; |
| 81 | debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data); |
| 82 | |
| 83 | return regmap_init_mem_plat(dev, plat->dtplat.reg, sizeof(plat->dtplat.reg[0]), |
| 84 | ARRAY_SIZE(plat->dtplat.reg) / 2, &priv->regmap); |
| 85 | } |
| 86 | |
| 87 | static int rk3288_sgrf_bind_of_plat(struct udevice *dev) |
| 88 | { |
| 89 | struct rockchip_rk3288_sgrf_plat *plat = dev_get_plat(dev); |
| 90 | struct syscon_uc_info *priv = dev_get_uclass_priv(dev); |
| 91 | int size = dev->uclass->uc_drv->per_device_auto; |
| 92 | |
| 93 | if (size && !priv) { |
| 94 | priv = calloc(1, size); |
| 95 | if (!priv) |
| 96 | return -ENOMEM; |
| 97 | dev_set_uclass_priv(dev, priv); |
| 98 | } |
| 99 | |
| 100 | dev->driver_data = dev->driver->of_match->data; |
| 101 | debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data); |
| 102 | |
| 103 | return regmap_init_mem_plat(dev, plat->dtplat.reg, sizeof(plat->dtplat.reg[0]), |
| 104 | ARRAY_SIZE(plat->dtplat.reg) / 2, &priv->regmap); |
| 105 | } |
| 106 | |
| 107 | static int rk3288_pmu_bind_of_plat(struct udevice *dev) |
| 108 | { |
| 109 | struct rockchip_rk3288_pmu_plat *plat = dev_get_plat(dev); |
| 110 | struct syscon_uc_info *priv = dev_get_uclass_priv(dev); |
| 111 | int size = dev->uclass->uc_drv->per_device_auto; |
| 112 | |
| 113 | if (size && !priv) { |
| 114 | priv = calloc(1, size); |
| 115 | if (!priv) |
| 116 | return -ENOMEM; |
| 117 | dev_set_uclass_priv(dev, priv); |
| 118 | } |
| 119 | |
| 120 | dev->driver_data = dev->driver->of_match->data; |
| 121 | debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data); |
| 122 | |
| 123 | return regmap_init_mem_plat(dev, plat->dtplat.reg, sizeof(plat->dtplat.reg[0]), |
| 124 | ARRAY_SIZE(plat->dtplat.reg) / 2, &priv->regmap); |
| 125 | } |
| 126 | #else |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 127 | static int rk3288_syscon_bind_of_plat(struct udevice *dev) |
Simon Glass | d63ea43 | 2016-07-04 11:58:33 -0600 | [diff] [blame] | 128 | { |
| 129 | dev->driver_data = dev->driver->of_match->data; |
| 130 | debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data); |
| 131 | |
| 132 | return 0; |
| 133 | } |
Johan Jonker | 6ba857d | 2023-03-13 01:30:57 +0100 | [diff] [blame] | 134 | #endif |
Simon Glass | d63ea43 | 2016-07-04 11:58:33 -0600 | [diff] [blame] | 135 | |
| 136 | U_BOOT_DRIVER(rockchip_rk3288_noc) = { |
| 137 | .name = "rockchip_rk3288_noc", |
| 138 | .id = UCLASS_SYSCON, |
| 139 | .of_match = rk3288_syscon_ids, |
Johan Jonker | 6ba857d | 2023-03-13 01:30:57 +0100 | [diff] [blame] | 140 | #if IS_ENABLED(CONFIG_FDT_64BIT) |
| 141 | .bind = rk3288_noc_bind_of_plat, |
| 142 | .plat_auto = sizeof(struct rockchip_rk3288_noc_plat), |
| 143 | #else |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 144 | .bind = rk3288_syscon_bind_of_plat, |
Johan Jonker | 6ba857d | 2023-03-13 01:30:57 +0100 | [diff] [blame] | 145 | #endif |
Simon Glass | d63ea43 | 2016-07-04 11:58:33 -0600 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | U_BOOT_DRIVER(rockchip_rk3288_grf) = { |
| 149 | .name = "rockchip_rk3288_grf", |
| 150 | .id = UCLASS_SYSCON, |
| 151 | .of_match = rk3288_syscon_ids + 1, |
Johan Jonker | 6ba857d | 2023-03-13 01:30:57 +0100 | [diff] [blame] | 152 | #if IS_ENABLED(CONFIG_FDT_64BIT) |
| 153 | .bind = rk3288_grf_bind_of_plat, |
| 154 | .plat_auto = sizeof(struct rockchip_rk3288_grf_plat), |
| 155 | #else |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 156 | .bind = rk3288_syscon_bind_of_plat, |
Johan Jonker | 6ba857d | 2023-03-13 01:30:57 +0100 | [diff] [blame] | 157 | #endif |
Simon Glass | d63ea43 | 2016-07-04 11:58:33 -0600 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | U_BOOT_DRIVER(rockchip_rk3288_sgrf) = { |
| 161 | .name = "rockchip_rk3288_sgrf", |
| 162 | .id = UCLASS_SYSCON, |
| 163 | .of_match = rk3288_syscon_ids + 2, |
Johan Jonker | 6ba857d | 2023-03-13 01:30:57 +0100 | [diff] [blame] | 164 | #if IS_ENABLED(CONFIG_FDT_64BIT) |
| 165 | .bind = rk3288_sgrf_bind_of_plat, |
| 166 | .plat_auto = sizeof(struct rockchip_rk3288_sgrf_plat), |
| 167 | #else |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 168 | .bind = rk3288_syscon_bind_of_plat, |
Johan Jonker | 6ba857d | 2023-03-13 01:30:57 +0100 | [diff] [blame] | 169 | #endif |
Simon Glass | d63ea43 | 2016-07-04 11:58:33 -0600 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | U_BOOT_DRIVER(rockchip_rk3288_pmu) = { |
| 173 | .name = "rockchip_rk3288_pmu", |
| 174 | .id = UCLASS_SYSCON, |
| 175 | .of_match = rk3288_syscon_ids + 3, |
Johan Jonker | 6ba857d | 2023-03-13 01:30:57 +0100 | [diff] [blame] | 176 | #if IS_ENABLED(CONFIG_FDT_64BIT) |
| 177 | .bind = rk3288_pmu_bind_of_plat, |
| 178 | .plat_auto = sizeof(struct rockchip_rk3288_pmu_plat), |
| 179 | #else |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 180 | .bind = rk3288_syscon_bind_of_plat, |
Johan Jonker | 6ba857d | 2023-03-13 01:30:57 +0100 | [diff] [blame] | 181 | #endif |
Simon Glass | d63ea43 | 2016-07-04 11:58:33 -0600 | [diff] [blame] | 182 | }; |
| 183 | #endif |