From patchwork Mon Jul 29 07:47:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 817 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 0BD793F0E1 for ; Mon, 29 Jul 2019 09:47:57 +0200 (CEST) Received: by mail-pg1-f198.google.com with SMTP id q9sf37653982pgv.17 for ; Mon, 29 Jul 2019 00:47:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1564386475; cv=pass; d=google.com; s=arc-20160816; b=yTzHUqqqjO43GG3fq+P4hsVpjDDZwBYc094US0wuIrMs9N1tmPVFpCSBHxZiDf5HHU qM/M8WpLx7/WqsphhhtG8sCnW0qrqqSGE5IrqSS4zrPCfElaLwcj9fgQKuCYc/pIATjJ 1Agx8mArDqSh0nyxp/mmTiv1HdtmIcg30RJ2+DM0IBM0lDhTlgeFPh+fdqIgV29uBl+I 5VcZ1/yrnAaFSDIBj34UOfMIIX9uwGNp3nyNitr/GI5aXVIZtWjvuzG7YUPc2lz955um NXZO7v+P+dz7FXTkF+JwqON4QlClPFJppRItYiHVA7pkV5YSusxdUq2J7BkRylQc08ml buWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=GjJduHCf3pxt4wmAFjnOSd1Z5IwZ2IzbZ8zZXtZ4Gro=; b=fj8GT3TKXRh20R9vzrlfKErhilNzzlEFsCkx4r54AJd4mmERXgCoTKVJphEWCJMe3M JjE3OnyO232ehs7gkf0W0C1CjO0JzCwDBz6LBTUnfLLZSNG4hs2UWIqq6gDLv1YJTYkW dNxWbkGdAwVSTh3tM7NWc6ze9xhQXUry2GSnQpzg/0ytVevV3wJ58DGtPlwnn6Y/c2eO yfaYnKwKO1jlqlvOCr+dbH4t9U3zpXp566VbklVQUZybh2fRb+OWzTWqoesW1V3O0vVV XP9R/uq2OjkGmK95PxrXK1YhMo7M7/ovzMw/gCluGsE+zDbfZfAe4OUqGdahA8eg9Zlb KpnQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=UPGJPNGs; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=GjJduHCf3pxt4wmAFjnOSd1Z5IwZ2IzbZ8zZXtZ4Gro=; b=gKfY/gZDYU2rsqfqIt+3w/SYR+mFIYCMJkudYiMHPDLe3CHwsAbvW1dO1yIgzEgKm4 tiyrBlOOZWStnk6z+ia8euiRd6DvigN6xC7SyX7lJtM/2/VXN+ZA4yGvQqSdN8M6uOCb vuH/kcHYDwG5692Hi0U7rKHacsNhPvMjK2a90= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=GjJduHCf3pxt4wmAFjnOSd1Z5IwZ2IzbZ8zZXtZ4Gro=; b=VwssULLiq69i+voiWYZSd57mFEzJ2KuV2/guWo7GwhBxnToiFYn8fKVlBOJ6XKlaUl gEkQFWLjcxQ8yx/8A8nKMktcNrv+yV7pyuRZ+TfjbhKxP8/9mi9A/pr6ri2/lcxjkE7a OasC4q9ACY2q1KicffGgSWUAYKGXAA6hUtESJJN0HWD+77QZx/cBMAuyb7926JD8BzCM oS218TXJmGseJG3AgtFzssZQsmb8fFwfx6kcdoDhokllZ+KbvNF6uMd2SKziieCTuRo7 xaTol+asIgreEUUqPaTCoLc8/gywwLjp2K6jKwoc51Eg0SjHby+478qapkHxEW6UbBkB uxRw== X-Gm-Message-State: APjAAAVe1hLdQ3CojNGm9+8Ugm1TJSDmjroll5HqDLu/IdHvL6FDT54Y qLcy+VPQMKTE9+J51TQlppypF9Ou X-Google-Smtp-Source: APXvYqxBAr/FyunzsmhTRO2yLhAMo8mJS9jYGUoJ5UhKygOVIgYfTQZvxXScXCWs1VRgiegW//pjcw== X-Received: by 2002:a62:3283:: with SMTP id y125mr35751993pfy.83.1564386475681; Mon, 29 Jul 2019 00:47:55 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90b:905:: with SMTP id bo5ls20994424pjb.0.canary-gmail; Mon, 29 Jul 2019 00:47:55 -0700 (PDT) X-Received: by 2002:a17:90a:7148:: with SMTP id g8mr43969046pjs.51.1564386475259; Mon, 29 Jul 2019 00:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564386475; cv=none; d=google.com; s=arc-20160816; b=MpdDfRVh9jmAvdNDItSmWnWlaHsq8op8elZez0BHUnF/68UxzKkY87qGbMSWgukHpU lrH4xV8SrS/z7qmhxzKq+Gpz0hwCY91DnvoYMZcoV2gLFiynK6bBOLi4P8XQ9BYOM5hU kGrR4+87+ryxS5CcU3lGDfZjitGEcmstXMXFj8FHepLbaK97klN+P/WVQLCYCk2OzxTX AN/wZttngiiTCkhlZ2KJNIlfr6s4Bs1TW3rAYHLDU5ns77Vg+Sc9hirZIoX5wuUDZwHN jm6N9dA5ypG4YmpApERUlQM7Qn2jA0+zStMV+qrZCMDoh68e/HwCVLIVL1s2s5GZzJm4 6yeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=3hoUuQJVXo5vdHFLjFQWacOvMnFEqgMjS7FzAI1sCA8=; b=iDsAHCyz5RxwEeoARpnlM80ywSeT1zLjvvdeK1x14nUcnlbKeHuJMdYtTBVliQUgF7 Mtlyv5TK5L5sdNLeA0/6pk5BecwKFN/G+FOniPyehzu+ftyGHXqQrSgvHbhH/QJFXLA5 Qax3fA+bb0cPguQK1pUvh64B4SlZ4wpT9V9/PwH+q+YhPZskppQKzWdlvvIsvHDmJeXF JTLaZcaXOzW+fIZIaIw5d0Z11aIhtGW/1AkVeWU1ibgMjz87X6hpudAyPOP7qdbJihCF m311MP9KtjwGuwkF/mrFVU+fCihK5JxW73CU7E1BfMmRM9WL+0J1+1ePPWmEclWpl3bD ZI5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=UPGJPNGs; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id s14sor74140318pjb.11.2019.07.29.00.47.55 for (Google Transport Security); Mon, 29 Jul 2019 00:47:55 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:90a:b908:: with SMTP id p8mr23018965pjr.94.1564386474934; Mon, 29 Jul 2019 00:47:54 -0700 (PDT) Received: from localhost.localdomain ([49.206.203.41]) by smtp.gmail.com with ESMTPSA id h14sm75723348pfq.22.2019.07.29.00.47.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 00:47:54 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: Akash Gajjar , u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki , Chin Liang See , Andy Shevchenko Subject: [PATCH 08/15] wdt: dw: Add driver-model support Date: Mon, 29 Jul 2019 13:17:04 +0530 Message-Id: <20190729074711.16988-9-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20190729074711.16988-1-jagan@amarulasolutions.com> References: <20190729074711.16988-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=UPGJPNGs; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add driver-model code for designware watchdog. Cc: Chin Liang See Cc: Andy Shevchenko Signed-off-by: Jagan Teki --- drivers/watchdog/designware_wdt.c | 114 +++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c index 2979fda44e..4efbb25f86 100644 --- a/drivers/watchdog/designware_wdt.c +++ b/drivers/watchdog/designware_wdt.c @@ -4,7 +4,6 @@ */ #include -#include #include #include @@ -16,6 +15,117 @@ #define DW_WDT_CR_RMOD_OFFSET 0x01 #define DW_WDT_CRR_RESTART_VAL 0x76 +#ifdef CONFIG_WDT + +#include +#include +#include + +struct dw_wdt { + void __iomem *regs; + unsigned long clk_rate; +}; + +static inline int dw_wdt_is_enabled(struct dw_wdt *dw) +{ + return readl(dw->regs + DW_WDT_CR) & DW_WDT_CR_RMOD_OFFSET; +} + +/* + * Set the watchdog time interval. + * Counter is 32 bit. + */ +static int dw_wdt_set_timeout(struct dw_wdt *dw, unsigned int timeout) +{ + signed int i; + + /* calculate the timeout range value */ + i = (log_2_n_round_up(timeout * dw->clk_rate)) - 16; + if (i > 15) + i = 15; + if (i < 0) + i = 0; + + writel((i | (i << 4)), dw->regs + DW_WDT_TORR); + + return 0; +} + +static void dw_wdt_enable(struct dw_wdt *dw) +{ + u32 val = readl(dw->regs + DW_WDT_CR); + + /* Enable watchdog */ + val |= DW_WDT_CR_RMOD_OFFSET; + writel(val, dw->regs + DW_WDT_CR); +} + +static int dw_wdt_reset(struct udevice *dev) +{ + struct dw_wdt *dw = dev_get_priv(dev); + + if (dw_wdt_is_enabled(dw)) + writel(DW_WDT_CRR_RESTART_VAL, dw->regs + DW_WDT_CRR); + else + dw_wdt_enable(dw); + + return 0; +} + +static int dw_wdt_start(struct udevice *dev, u64 timeout, ulong flags) +{ + struct dw_wdt *dw = dev_get_priv(dev); + + dw_wdt_set_timeout(dw, timeout); + dw_wdt_enable(dw); + + return 0; +} + +static int dw_wdt_probe(struct udevice *dev) +{ + struct dw_wdt *dw = dev_get_priv(dev); + struct clk clk; + int ret; + + dw->regs = dev_remap_addr(dev); + if (!dw->regs) + return -EINVAL; + + ret = clk_get_by_index(dev, 0, &clk); + if (!ret) + dw->clk_rate = clk_get_rate(&clk); + else + return -EINVAL; + + dw_wdt_reset(dev); + + return 0; +} + +static const struct wdt_ops dw_wdt_ops = { + .reset = dw_wdt_reset, + .start = dw_wdt_start, +}; + +static const struct udevice_id dw_wdt_ids[] = { + { .compatible = "snps,dw-wdt" }, + { /* sentinel */ } +}; + +U_BOOT_DRIVER(dw_wdt) = { + .name = "dw_wdt", + .id = UCLASS_WDT, + .of_match = dw_wdt_ids, + .ops = &dw_wdt_ops, + .priv_auto_alloc_size = sizeof(struct dw_wdt), + .probe = dw_wdt_probe, +}; + +#else + +#include + /* * Set the watchdog time interval. * Counter is 32 bit. @@ -70,3 +180,5 @@ void hw_watchdog_init(void) hw_watchdog_reset(); } #endif + +#endif /* CONFIG_WDT */