1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (C) ASPEED Technology Inc. 4 */ 5 6 #include <common.h> 7 #include <dm.h> 8 #include <misc.h> 9 #include <reset.h> 10 #include <reset-uclass.h> 11 #include <wdt.h> 12 #include <asm/io.h> 13 #include <asm/arch/wdt.h> 14 #include <asm/arch/scu_ast2600.h> 15 16 struct ast2600_reset_priv { 17 /* WDT used to perform resets. */ 18 struct udevice *wdt; 19 struct ast2600_scu *scu; 20 }; 21 22 static int ast2600_reset_deassert(struct reset_ctl *reset_ctl) 23 { 24 struct ast2600_reset_priv *priv = dev_get_priv(reset_ctl->dev); 25 struct ast2600_scu *scu = priv->scu; 26 27 printf("ast2600_reset_assert reset_ctl->id %ld \n", reset_ctl->id); 28 29 if(reset_ctl->id >= 32) 30 writel(scu->sysreset_clr_ctrl2 , BIT(reset_ctl->id - 32)); 31 else 32 writel(scu->sysreset_clr_ctrl1 , BIT(reset_ctl->id)); 33 34 return 0; 35 } 36 37 static int ast2600_reset_assert(struct reset_ctl *reset_ctl) 38 { 39 struct ast2600_reset_priv *priv = dev_get_priv(reset_ctl->dev); 40 struct ast2600_scu *scu = priv->scu; 41 42 printf("ast2600_reset_assert reset_ctl->id %ld \n", reset_ctl->id); 43 44 if(reset_ctl->id >= 32) 45 writel(scu->sysreset_ctrl2 , BIT(reset_ctl->id - 32)); 46 else 47 writel(scu->sysreset_ctrl1 , BIT(reset_ctl->id)); 48 49 return 0; 50 } 51 52 static int ast2600_reset_request(struct reset_ctl *reset_ctl) 53 { 54 printf("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl, 55 reset_ctl->dev, reset_ctl->id); 56 57 return 0; 58 } 59 60 static int ast2600_reset_probe(struct udevice *dev) 61 { 62 struct ast2600_reset_priv *priv = dev_get_priv(dev); 63 64 priv->scu = ast_get_scu(); 65 66 return 0; 67 } 68 69 static int aspeed_ofdata_to_platdata(struct udevice *dev) 70 { 71 struct ast2600_reset_priv *priv = dev_get_priv(dev); 72 int ret; 73 74 ret = uclass_get_device_by_phandle(UCLASS_WDT, dev, "aspeed,wdt", 75 &priv->wdt); 76 if (ret) { 77 debug("%s: can't find WDT for reset controller", __func__); 78 return ret; 79 } 80 81 return 0; 82 } 83 84 85 static const struct udevice_id aspeed_reset_ids[] = { 86 { .compatible = "aspeed,ast2600-reset" }, 87 { } 88 }; 89 90 struct reset_ops aspeed_reset_ops = { 91 .rst_assert = ast2600_reset_assert, 92 .rst_deassert = ast2600_reset_deassert, 93 .request = ast2600_reset_request, 94 }; 95 96 U_BOOT_DRIVER(aspeed_reset) = { 97 .name = "aspeed_reset", 98 .id = UCLASS_RESET, 99 .of_match = aspeed_reset_ids, 100 .probe = ast2600_reset_probe, 101 .ops = &aspeed_reset_ops, 102 .ofdata_to_platdata = aspeed_ofdata_to_platdata, 103 .priv_auto_alloc_size = sizeof(struct ast2600_reset_priv), 104 }; 105