Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2023 Chris Morgan <macromorgan@hotmail.com> |
| 4 | */ |
| 5 | |
| 6 | #include <abuf.h> |
| 7 | #include <adc.h> |
| 8 | #include <asm/io.h> |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 9 | #include <display.h> |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 10 | #include <dm.h> |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 11 | #include <dm/lists.h> |
| 12 | #include <env.h> |
| 13 | #include <fdt_support.h> |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 14 | #include <linux/delay.h> |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 15 | #include <mipi_dsi.h> |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 16 | #include <mmc.h> |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 17 | #include <panel.h> |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 18 | #include <pwm.h> |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 19 | #include <stdlib.h> |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 20 | #include <video_bridge.h> |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 21 | |
| 22 | #define GPIO0_BASE 0xfdd60000 |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 23 | #define GPIO4_BASE 0xfe770000 |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 24 | #define GPIO_SWPORT_DR_L 0x0000 |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 25 | #define GPIO_SWPORT_DR_H 0x0004 |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 26 | #define GPIO_SWPORT_DDR_L 0x0008 |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 27 | #define GPIO_SWPORT_DDR_H 0x000c |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 28 | #define GPIO_A0 BIT(0) |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 29 | #define GPIO_C5 BIT(5) |
| 30 | #define GPIO_C6 BIT(6) |
| 31 | #define GPIO_C7 BIT(7) |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 32 | |
| 33 | #define GPIO_WRITEMASK(bits) ((bits) << 16) |
| 34 | |
| 35 | #define DTB_DIR "rockchip/" |
| 36 | |
| 37 | struct rg3xx_model { |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 38 | const u16 adc_value; |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 39 | const char *board; |
| 40 | const char *board_name; |
| 41 | const char *fdtfile; |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 42 | const bool detect_panel; |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | enum rgxx3_device_id { |
| 46 | RG353M, |
| 47 | RG353P, |
| 48 | RG353V, |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 49 | RG503, |
Chris Morgan | 95db0c0 | 2024-01-02 09:46:53 -0600 | [diff] [blame] | 50 | RGB30, |
| 51 | RK2023, |
| 52 | RGARCD, |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 53 | /* Devices with duplicate ADC value */ |
| 54 | RG353PS, |
| 55 | RG353VS, |
Chris Morgan | 95db0c0 | 2024-01-02 09:46:53 -0600 | [diff] [blame] | 56 | RGARCS, |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | static const struct rg3xx_model rg3xx_model_details[] = { |
| 60 | [RG353M] = { |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 61 | .adc_value = 517, /* Observed average from device */ |
| 62 | .board = "rk3566-anbernic-rg353m", |
| 63 | .board_name = "RG353M", |
| 64 | /* Device is identical to RG353P. */ |
| 65 | .fdtfile = DTB_DIR "rk3566-anbernic-rg353p.dtb", |
| 66 | .detect_panel = 1, |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 67 | }, |
| 68 | [RG353P] = { |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 69 | .adc_value = 860, /* Documented value of 860 */ |
| 70 | .board = "rk3566-anbernic-rg353p", |
| 71 | .board_name = "RG353P", |
| 72 | .fdtfile = DTB_DIR "rk3566-anbernic-rg353p.dtb", |
| 73 | .detect_panel = 1, |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 74 | }, |
| 75 | [RG353V] = { |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 76 | .adc_value = 695, /* Observed average from device */ |
| 77 | .board = "rk3566-anbernic-rg353v", |
| 78 | .board_name = "RG353V", |
| 79 | .fdtfile = DTB_DIR "rk3566-anbernic-rg353v.dtb", |
| 80 | .detect_panel = 1, |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 81 | }, |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 82 | [RG503] = { |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 83 | .adc_value = 1023, /* Observed average from device */ |
| 84 | .board = "rk3566-anbernic-rg503", |
| 85 | .board_name = "RG503", |
| 86 | .fdtfile = DTB_DIR "rk3566-anbernic-rg503.dtb", |
| 87 | .detect_panel = 0, |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 88 | }, |
Chris Morgan | 95db0c0 | 2024-01-02 09:46:53 -0600 | [diff] [blame] | 89 | [RGB30] = { |
| 90 | .adc_value = 383, /* Gathered from second hand information */ |
| 91 | .board = "rk3566-powkiddy-rgb30", |
| 92 | .board_name = "RGB30", |
| 93 | .fdtfile = DTB_DIR "rk3566-powkiddy-rgb30.dtb", |
| 94 | .detect_panel = 0, |
| 95 | }, |
| 96 | [RK2023] = { |
| 97 | .adc_value = 635, /* Observed average from device */ |
| 98 | .board = "rk3566-powkiddy-rk2023", |
| 99 | .board_name = "RK2023", |
| 100 | .fdtfile = DTB_DIR "rk3566-powkiddy-rk2023.dtb", |
| 101 | .detect_panel = 0, |
| 102 | }, |
| 103 | [RGARCD] = { |
| 104 | .adc_value = 183, /* Observed average from device */ |
| 105 | .board = "rk3566-anbernic-rg-arc-d", |
| 106 | .board_name = "Anbernic RG ARC-D", |
| 107 | .fdtfile = DTB_DIR "rk3566-anbernic-rg-arc-d.dtb", |
| 108 | .detect_panel = 0, |
| 109 | }, |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 110 | /* Devices with duplicate ADC value */ |
| 111 | [RG353PS] = { |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 112 | .adc_value = 860, /* Observed average from device */ |
| 113 | .board = "rk3566-anbernic-rg353ps", |
| 114 | .board_name = "RG353PS", |
| 115 | .fdtfile = DTB_DIR "rk3566-anbernic-rg353ps.dtb", |
| 116 | .detect_panel = 1, |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 117 | }, |
| 118 | [RG353VS] = { |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 119 | .adc_value = 695, /* Gathered from second hand information */ |
| 120 | .board = "rk3566-anbernic-rg353vs", |
| 121 | .board_name = "RG353VS", |
| 122 | .fdtfile = DTB_DIR "rk3566-anbernic-rg353vs.dtb", |
| 123 | .detect_panel = 1, |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 124 | }, |
Chris Morgan | 95db0c0 | 2024-01-02 09:46:53 -0600 | [diff] [blame] | 125 | [RGARCS] = { |
| 126 | .adc_value = 183, /* Observed average from device */ |
| 127 | .board = "rk3566-anbernic-rg-arc-s", |
| 128 | .board_name = "Anbernic RG ARC-S", |
| 129 | .fdtfile = DTB_DIR "rk3566-anbernic-rg-arc-s.dtb", |
| 130 | .detect_panel = 0, |
| 131 | }, |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 132 | }; |
| 133 | |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 134 | struct rg353_panel { |
| 135 | const u16 id; |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 136 | const char *panel_compat[2]; |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | static const struct rg353_panel rg353_panel_details[] = { |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 140 | { |
| 141 | .id = 0x3052, |
| 142 | .panel_compat[0] = "anbernic,rg353p-panel", |
| 143 | .panel_compat[1] = "newvision,nv3051d", |
| 144 | }, |
| 145 | { |
| 146 | .id = 0x3821, |
| 147 | .panel_compat[0] = "anbernic,rg353v-panel-v2", |
| 148 | .panel_compat[1] = NULL, |
| 149 | }, |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 150 | }; |
| 151 | |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 152 | /* |
| 153 | * Start LED very early so user knows device is on. Set color |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 154 | * to red. |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 155 | */ |
| 156 | void spl_board_init(void) |
| 157 | { |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 158 | /* Set GPIO0_C5, GPIO0_C6, and GPIO0_C7 to output. */ |
| 159 | writel(GPIO_WRITEMASK(GPIO_C7 | GPIO_C6 | GPIO_C5) | \ |
| 160 | (GPIO_C7 | GPIO_C6 | GPIO_C5), |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 161 | (GPIO0_BASE + GPIO_SWPORT_DDR_H)); |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 162 | /* Set GPIO0_C5 and GPIO_C6 to 0 and GPIO0_C7 to 1. */ |
| 163 | writel(GPIO_WRITEMASK(GPIO_C7 | GPIO_C6 | GPIO_C5) | GPIO_C7, |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 164 | (GPIO0_BASE + GPIO_SWPORT_DR_H)); |
| 165 | } |
| 166 | |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 167 | /* |
| 168 | * Buzz the buzzer so the user knows something is going on. Make it |
| 169 | * optional in case PWM is disabled. |
| 170 | */ |
| 171 | void __maybe_unused startup_buzz(void) |
| 172 | { |
| 173 | struct udevice *dev; |
| 174 | int err; |
| 175 | |
| 176 | err = uclass_get_device(UCLASS_PWM, 0, &dev); |
| 177 | if (err) |
| 178 | printf("pwm not found\n"); |
| 179 | |
| 180 | pwm_set_enable(dev, 0, 1); |
| 181 | mdelay(200); |
| 182 | pwm_set_enable(dev, 0, 0); |
| 183 | } |
| 184 | |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 185 | /* |
| 186 | * Provide the bare minimum to identify the panel for the RG353 |
| 187 | * series. Since we don't have a working framebuffer device, no |
| 188 | * need to init the panel; just identify it and provide the |
| 189 | * clocks so we know what to set the different clock values to. |
| 190 | */ |
| 191 | |
| 192 | static const struct display_timing rg353_default_timing = { |
| 193 | .pixelclock.typ = 24150000, |
| 194 | .hactive.typ = 640, |
| 195 | .hfront_porch.typ = 40, |
| 196 | .hback_porch.typ = 80, |
| 197 | .hsync_len.typ = 2, |
| 198 | .vactive.typ = 480, |
| 199 | .vfront_porch.typ = 18, |
| 200 | .vback_porch.typ = 28, |
| 201 | .vsync_len.typ = 2, |
| 202 | .flags = DISPLAY_FLAGS_HSYNC_HIGH | |
| 203 | DISPLAY_FLAGS_VSYNC_HIGH, |
| 204 | }; |
| 205 | |
| 206 | static int anbernic_rg353_panel_get_timing(struct udevice *dev, |
| 207 | struct display_timing *timings) |
| 208 | { |
| 209 | memcpy(timings, &rg353_default_timing, sizeof(*timings)); |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | static int anbernic_rg353_panel_probe(struct udevice *dev) |
| 215 | { |
| 216 | struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); |
| 217 | |
| 218 | plat->lanes = 4; |
| 219 | plat->format = MIPI_DSI_FMT_RGB888; |
| 220 | plat->mode_flags = MIPI_DSI_MODE_VIDEO | |
| 221 | MIPI_DSI_MODE_VIDEO_BURST | |
| 222 | MIPI_DSI_MODE_EOT_PACKET | |
| 223 | MIPI_DSI_MODE_LPM; |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | static const struct panel_ops anbernic_rg353_panel_ops = { |
| 229 | .get_display_timing = anbernic_rg353_panel_get_timing, |
| 230 | }; |
| 231 | |
| 232 | U_BOOT_DRIVER(anbernic_rg353_panel) = { |
| 233 | .name = "anbernic_rg353_panel", |
| 234 | .id = UCLASS_PANEL, |
| 235 | .ops = &anbernic_rg353_panel_ops, |
| 236 | .probe = anbernic_rg353_panel_probe, |
| 237 | .plat_auto = sizeof(struct mipi_dsi_panel_plat), |
| 238 | }; |
| 239 | |
| 240 | int rgxx3_detect_display(void) |
| 241 | { |
| 242 | struct udevice *dev; |
| 243 | struct mipi_dsi_device *dsi; |
| 244 | struct mipi_dsi_panel_plat *mplat; |
| 245 | const struct rg353_panel *panel; |
| 246 | int ret = 0; |
| 247 | int i; |
| 248 | u8 panel_id[2]; |
| 249 | |
| 250 | /* |
| 251 | * Take panel out of reset status. |
| 252 | * Set GPIO4_A0 to output. |
| 253 | */ |
| 254 | writel(GPIO_WRITEMASK(GPIO_A0) | GPIO_A0, |
| 255 | (GPIO4_BASE + GPIO_SWPORT_DDR_L)); |
| 256 | /* Set GPIO4_A0 to 1. */ |
| 257 | writel(GPIO_WRITEMASK(GPIO_A0) | GPIO_A0, |
| 258 | (GPIO4_BASE + GPIO_SWPORT_DR_L)); |
| 259 | |
| 260 | /* Probe the DSI controller. */ |
| 261 | ret = uclass_get_device_by_name(UCLASS_VIDEO_BRIDGE, |
| 262 | "dsi@fe060000", &dev); |
| 263 | if (ret) { |
| 264 | printf("DSI host not probed: %d\n", ret); |
| 265 | return ret; |
| 266 | } |
| 267 | |
| 268 | /* Probe the DSI panel. */ |
| 269 | ret = device_bind_driver_to_node(dev, "anbernic_rg353_panel", |
| 270 | "anbernic_rg353_panel", |
| 271 | dev_ofnode(dev), NULL); |
| 272 | if (ret) { |
| 273 | printf("Failed to probe RG353 panel: %d\n", ret); |
| 274 | return ret; |
| 275 | } |
| 276 | |
| 277 | /* |
| 278 | * Attach the DSI controller which will also probe and attach |
| 279 | * the DSIDPHY. |
| 280 | */ |
| 281 | ret = video_bridge_attach(dev); |
| 282 | if (ret) { |
| 283 | printf("Failed to attach DSI controller: %d\n", ret); |
| 284 | return ret; |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | * Get the panel which should have already been probed by the |
| 289 | * video_bridge_attach() function. |
| 290 | */ |
| 291 | ret = uclass_first_device_err(UCLASS_PANEL, &dev); |
| 292 | if (ret) { |
| 293 | printf("Panel device error: %d\n", ret); |
| 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | /* Now call the panel via DSI commands to get the panel ID. */ |
| 298 | mplat = dev_get_plat(dev); |
| 299 | dsi = mplat->device; |
| 300 | mipi_dsi_set_maximum_return_packet_size(dsi, sizeof(panel_id)); |
| 301 | ret = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_DISPLAY_ID, &panel_id, |
| 302 | sizeof(panel_id)); |
| 303 | if (ret < 0) { |
| 304 | printf("Unable to read panel ID: %d\n", ret); |
| 305 | return ret; |
| 306 | } |
| 307 | |
| 308 | /* Get the correct panel compatible from the table. */ |
| 309 | for (i = 0; i < ARRAY_SIZE(rg353_panel_details); i++) { |
| 310 | if (rg353_panel_details[i].id == ((panel_id[0] << 8) | |
| 311 | panel_id[1])) { |
| 312 | panel = &rg353_panel_details[i]; |
| 313 | break; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | if (!panel) { |
| 318 | printf("Unable to identify panel_id %x\n", |
| 319 | (panel_id[0] << 8) | panel_id[1]); |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 320 | return -EINVAL; |
| 321 | } |
| 322 | |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 323 | env_set("panel", panel->panel_compat[0]); |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 324 | |
| 325 | return 0; |
| 326 | } |
| 327 | |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 328 | /* Detect which Anbernic RGXX3 device we are using so as to load the |
| 329 | * correct devicetree for Linux. Set an environment variable once |
| 330 | * found. The detection depends on the value of ADC channel 1, the |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 331 | * presence of an eMMC on mmc0, and querying the DSI panel. |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 332 | */ |
| 333 | int rgxx3_detect_device(void) |
| 334 | { |
| 335 | u32 adc_info; |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 336 | int ret, i; |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 337 | int board_id = -ENXIO; |
| 338 | struct mmc *mmc; |
| 339 | |
| 340 | ret = adc_channel_single_shot("saradc@fe720000", 1, &adc_info); |
| 341 | if (ret) { |
| 342 | printf("Read SARADC failed with error %d\n", ret); |
| 343 | return ret; |
| 344 | } |
| 345 | |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 346 | /* |
| 347 | * Get the correct device from the table. The ADC value is |
| 348 | * determined by a resistor on ADC channel 0. The hardware |
| 349 | * design calls for no more than a 1% variance on the |
| 350 | * resistor, so assume a +- value of 15 should be enough. |
| 351 | */ |
| 352 | for (i = 0; i < ARRAY_SIZE(rg3xx_model_details); i++) { |
| 353 | u32 adc_min = rg3xx_model_details[i].adc_value - 15; |
| 354 | u32 adc_max = rg3xx_model_details[i].adc_value + 15; |
| 355 | |
| 356 | if (adc_min < adc_info && adc_max > adc_info) { |
| 357 | board_id = i; |
| 358 | break; |
| 359 | } |
| 360 | } |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 361 | |
| 362 | /* |
Chris Morgan | 95db0c0 | 2024-01-02 09:46:53 -0600 | [diff] [blame] | 363 | * Try to access the eMMC on an RG353V, RG353P, or RG Arc D. |
| 364 | * If it's missing, it's an RG353VS, RG353PS, or RG Arc S. |
| 365 | * Note we could also check for a touchscreen at 0x1a on i2c2. |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 366 | */ |
Chris Morgan | 95db0c0 | 2024-01-02 09:46:53 -0600 | [diff] [blame] | 367 | if (board_id == RG353V || board_id == RG353P || board_id == RGARCD) { |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 368 | mmc = find_mmc_device(0); |
| 369 | if (mmc) { |
| 370 | ret = mmc_init(mmc); |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 371 | if (ret) { |
| 372 | if (board_id == RG353V) |
| 373 | board_id = RG353VS; |
Chris Morgan | 95db0c0 | 2024-01-02 09:46:53 -0600 | [diff] [blame] | 374 | else if (board_id == RG353P) |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 375 | board_id = RG353PS; |
Chris Morgan | 95db0c0 | 2024-01-02 09:46:53 -0600 | [diff] [blame] | 376 | else |
| 377 | board_id = RGARCS; |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 378 | } |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
| 382 | if (board_id < 0) |
| 383 | return board_id; |
| 384 | |
| 385 | env_set("board", rg3xx_model_details[board_id].board); |
| 386 | env_set("board_name", |
| 387 | rg3xx_model_details[board_id].board_name); |
| 388 | env_set("fdtfile", rg3xx_model_details[board_id].fdtfile); |
| 389 | |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 390 | /* Skip panel detection for when it is not needed. */ |
| 391 | if (!rg3xx_model_details[board_id].detect_panel) |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 392 | return 0; |
| 393 | |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 394 | /* Warn but don't fail for errors in auto-detection of the panel. */ |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 395 | ret = rgxx3_detect_display(); |
| 396 | if (ret) |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 397 | printf("Failed to detect panel type\n"); |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 398 | |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | int rk_board_late_init(void) |
| 403 | { |
| 404 | int ret; |
| 405 | |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 406 | ret = rgxx3_detect_device(); |
| 407 | if (ret) { |
| 408 | printf("Unable to detect device type: %d\n", ret); |
| 409 | return ret; |
| 410 | } |
| 411 | |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 412 | /* Turn off red LED and turn on orange LED. */ |
| 413 | writel(GPIO_WRITEMASK(GPIO_C7 | GPIO_C6 | GPIO_C5) | GPIO_C6, |
| 414 | (GPIO0_BASE + GPIO_SWPORT_DR_H)); |
| 415 | |
Chris Morgan | 8c4e304 | 2023-04-21 10:59:19 -0500 | [diff] [blame] | 416 | if (IS_ENABLED(CONFIG_DM_PWM)) |
| 417 | startup_buzz(); |
| 418 | |
| 419 | return 0; |
| 420 | } |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 421 | |
| 422 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 423 | { |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 424 | const struct rg353_panel *panel = NULL; |
| 425 | int node, ret, i; |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 426 | char *env; |
| 427 | |
| 428 | /* No fixups necessary for the RG503 */ |
| 429 | env = env_get("board_name"); |
| 430 | if (env && (!strcmp(env, rg3xx_model_details[RG503].board_name))) |
| 431 | return 0; |
| 432 | |
| 433 | /* Change the model name of the RG353M */ |
| 434 | if (env && (!strcmp(env, rg3xx_model_details[RG353M].board_name))) |
| 435 | fdt_setprop(blob, 0, "model", |
| 436 | rg3xx_model_details[RG353M].board_name, |
| 437 | sizeof(rg3xx_model_details[RG353M].board_name)); |
| 438 | |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 439 | env = env_get("panel"); |
| 440 | if (!env) { |
| 441 | printf("Can't get panel env\n"); |
| 442 | return 0; |
| 443 | } |
| 444 | |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 445 | /* |
| 446 | * Check if the environment variable doesn't equal the panel. |
| 447 | * If it doesn't, update the devicetree to the correct panel. |
| 448 | */ |
| 449 | node = fdt_path_offset(blob, "/dsi@fe060000/panel@0"); |
| 450 | if (!(node > 0)) { |
| 451 | printf("Can't find the DSI node\n"); |
| 452 | return -ENODEV; |
| 453 | } |
| 454 | |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 455 | ret = fdt_node_check_compatible(blob, node, env); |
| 456 | if (ret < 0) |
| 457 | return -ENODEV; |
| 458 | |
| 459 | /* Panels match, return 0. */ |
| 460 | if (!ret) |
| 461 | return 0; |
| 462 | |
Chris Morgan | a63ff50 | 2024-01-02 09:46:48 -0600 | [diff] [blame] | 463 | /* Panels don't match, search by first compatible value. */ |
| 464 | for (i = 0; i < ARRAY_SIZE(rg353_panel_details); i++) { |
| 465 | if (!strcmp(env, rg353_panel_details[i].panel_compat[0])) { |
| 466 | panel = &rg353_panel_details[i]; |
| 467 | break; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | if (!panel) { |
| 472 | printf("Unable to identify panel by compat string\n"); |
| 473 | return -ENODEV; |
| 474 | } |
| 475 | |
| 476 | /* Set the compatible with the auto-detected values */ |
| 477 | fdt_setprop_string(blob, node, "compatible", panel->panel_compat[0]); |
| 478 | if (panel->panel_compat[1]) |
| 479 | fdt_appendprop_string(blob, node, "compatible", |
| 480 | panel->panel_compat[1]); |
Chris Morgan | 3db220e | 2023-05-15 11:00:30 -0500 | [diff] [blame] | 481 | |
Chris Morgan | a824aa6 | 2023-05-15 11:00:29 -0500 | [diff] [blame] | 482 | return 0; |
| 483 | } |