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 debug("ast2600_reset_assert reset_ctl->id %ld \n", reset_ctl->id); 28 29 if(reset_ctl->id >= 32) 30 writel(BIT(reset_ctl->id - 32), &scu->sysreset_clr_ctrl2); 31 else 32 writel(BIT(reset_ctl->id), &scu->sysreset_clr_ctrl1); 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 debug("ast2600_reset_assert reset_ctl->id %ld \n", reset_ctl->id); 43 44 if(reset_ctl->id >= 32) 45 writel(BIT(reset_ctl->id - 32), &scu->sysreset_ctrl2); 46 else 47 writel(BIT(reset_ctl->id), &scu->sysreset_ctrl1); 48 49 return 0; 50 } 51 52 static int ast2600_reset_request(struct reset_ctl *reset_ctl) 53 { 54 debug("%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 ast2600_ofdata_to_platdata(struct udevice *dev) 84 { 85 // struct ast2600_reset_priv *priv = dev_get_priv(dev); 86 // int ret; 87 88 #if 0 89 ret = uclass_get_device_by_phandle(UCLASS_WDT, dev, "aspeed,ast2600-wdt", 90 &priv->wdt); 91 if (ret) { 92 printf("%s: can't find WDT for reset controller", __func__); 93 return ret; 94 } 95 #endif 96 97 return 0; 98 } 99 100 static const struct udevice_id aspeed_reset_ids[] = { 101 { .compatible = "aspeed,ast2600-reset" }, 102 { } 103 }; 104 105 struct reset_ops aspeed_reset_ops = { 106 .rst_assert = ast2600_reset_assert, 107 .rst_deassert = ast2600_reset_deassert, 108 .request = ast2600_reset_request, 109 }; 110 111 U_BOOT_DRIVER(aspeed_reset) = { 112 .name = "aspeed_reset", 113 .id = UCLASS_RESET, 114 .of_match = aspeed_reset_ids, 115 .probe = ast2600_reset_probe, 116 .ops = &aspeed_reset_ops, 117 .ofdata_to_platdata = ast2600_ofdata_to_platdata, 118 .priv_auto_alloc_size = sizeof(struct ast2600_reset_priv), 119 }; 120