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 struct udevice *clk_dev; 64 int ret = 0; 65 66 /* find SCU base address from clock device */ 67 ret = uclass_get_device_by_driver(UCLASS_CLK, DM_GET_DRIVER(aspeed_scu), 68 &clk_dev); 69 if (ret) { 70 debug("clock device not found\n"); 71 return ret; 72 } 73 74 priv->scu = devfdt_get_addr_ptr(clk_dev); 75 if (IS_ERR(priv->scu)) { 76 debug("%s(): can't get SCU\n", __func__); 77 return PTR_ERR(priv->scu); 78 } 79 80 return 0; 81 } 82 83 static int aspeed_ofdata_to_platdata(struct udevice *dev) 84 { 85 struct ast2600_reset_priv *priv = dev_get_priv(dev); 86 int ret; 87 88 ret = uclass_get_device_by_phandle(UCLASS_WDT, dev, "aspeed,wdt", 89 &priv->wdt); 90 if (ret) { 91 debug("%s: can't find WDT for reset controller", __func__); 92 return ret; 93 } 94 95 return 0; 96 } 97 98 static const struct udevice_id aspeed_reset_ids[] = { 99 { .compatible = "aspeed,ast2600-reset" }, 100 { } 101 }; 102 103 struct reset_ops aspeed_reset_ops = { 104 .rst_assert = ast2600_reset_assert, 105 .rst_deassert = ast2600_reset_deassert, 106 .request = ast2600_reset_request, 107 }; 108 109 U_BOOT_DRIVER(aspeed_reset) = { 110 .name = "aspeed_reset", 111 .id = UCLASS_RESET, 112 .of_match = aspeed_reset_ids, 113 .probe = ast2600_reset_probe, 114 .ops = &aspeed_reset_ops, 115 .ofdata_to_platdata = aspeed_ofdata_to_platdata, 116 .priv_auto_alloc_size = sizeof(struct ast2600_reset_priv), 117 }; 118