Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp340648rdb; Thu, 5 Oct 2023 07:31:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFh8HCd7PuNW6y+RKys4LiDxCQa99AQ29lRr1r/E97rky7Qb0fHvEIZ61Oo19I1njJKvK0X X-Received: by 2002:a17:902:db02:b0:1c5:634f:b36c with SMTP id m2-20020a170902db0200b001c5634fb36cmr5843256plx.30.1696516286575; Thu, 05 Oct 2023 07:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696516286; cv=none; d=google.com; s=arc-20160816; b=QI3JNS32svtpJB+cVjfZb3z4g4xaywULGdmLx4kq0wM3zFXg5b5WEsq9hP/hROd4ia Gb43wV0oZcE9o4yO9hjD8V147nxRE/Tn+Fj32Xz34Gqhj5ro69EXsyh2gRYlR4PLJuP3 xFNMUp0IEG/K4gjdFWDhGZr5ib4SjNPUIz1/Lt4w8OOgBVSsYeWkD9oJqplVQEuaGmOx lPI8lZIyI8m29i1VqU8Y+r3aYuiRTeaxiq2rr0sJ2ga4rDiRRHoMiKnsBB2Laay/wOmF GbayX6hovVxaebo20ail6eJ0fXqJPDNSC8eVX7QOIHxqh/yw7166dpsbCsDkq4rltBgL 8LpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xl5VP0Ue06tT2oZw2pmITNbqF1XXDB7xjU0jlwfhUG8=; fh=GdmkTvfKRRlOOfwJpZPKb2aCk8kgDyKB6mIkSpy8if8=; b=wMGPyTE/mNIx7oV6kCFvjVHhg1rTxSMBRSU6PcHsqQF5CQGlAdn/xi4gKLGbaIGFCZ bBH3ZmBcjcTPUc4NkJkcJTKeoV+dGfLwE0IQ4HaVnX3unrj5a3wGiLRobQdIWqIkqbD8 oxd0p86dI6Vn/QlrlSHApvuApddcXIQhQQHndFA+hhTwmUAIX9xSlCacsU01V1II1jof wPzFx0MYkbjdgMxZrzalUkeeUy+6TPS0MuPPdW3CZdZZa8mzijpIs/Dg+VLz7VlaUET3 MGqCZXPFj+Qyh3Z4PZ0sekKpxxL2Hif6fX1JggkSmWpnMTXLo5arx3scWWHTIcc74nOI xi9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Z7Y0jjl/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id b1-20020a170902d30100b001c4660cd474si1491330plc.634.2023.10.05.07.31.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 07:31:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Z7Y0jjl/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 18F5780608DB; Thu, 5 Oct 2023 07:30:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234111AbjJEO3s (ORCPT + 99 others); Thu, 5 Oct 2023 10:29:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233972AbjJEO1v (ORCPT ); Thu, 5 Oct 2023 10:27:51 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E557893D4; Thu, 5 Oct 2023 01:52:18 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-694ed847889so592865b3a.2; Thu, 05 Oct 2023 01:52:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696495938; x=1697100738; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xl5VP0Ue06tT2oZw2pmITNbqF1XXDB7xjU0jlwfhUG8=; b=Z7Y0jjl/BPXvAY2fmEa9YeYoa9tnw+P9lTgf733kjNIyWRwXZiuDz4D1L5gvyyW0at phZC9AZGudyrxYtSVbZwzYnI/r3xcOZWwb1oT8x3TpweotFDowuR9viWB5RfmICvJtum aLS9OPmtGlHsmmUl07fmLMFXjQ1/N5itzRGReCNsJd9QdaOyrKa5qoYA+YVa5eS3OgUf dBxm6BzvJEX/jsiTHzr6BfRaIXyo0zkStZo/Fsfy8IQtOX9mChikfEPTuZ3gl1PrXn7+ y/rMYLyuEvIBpkMm6wgSPOphKYUEEKtwAMoV5NalMlvhoxqWE45xCnq1BPnpkSCHX2uv f/aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696495938; x=1697100738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xl5VP0Ue06tT2oZw2pmITNbqF1XXDB7xjU0jlwfhUG8=; b=DkAfFEeFTAdxJvCoVI2WxBHJnap7Q+mVGjC32mjvmhPlfGGnBklXQASGfHwh8/qJzq k/wTslGs1BoKB1Ad1jYMDtblHoHOYLVqM3uk2ntEk+vDl9F1Tx1S/gcz07+s6jM8fvNp 2wUBHofE+hwQ6HQOQF0v5Vx9HgsNfUw1+jCynu68VqfHquqMY9TFk2Wflye6SbM4OutB YTvIwfggl9XWKYCxDsYCabQnqp3dsvge9Mqm/rJCZ+6zISr3zPPXkckTNNgWraLIyehN opXS6D9tBjyIw4ZYRWZJFoGPd0/YkgS6K10y7Yv9T+MAyAKm78jgKXQERCO3IbSZONNU V+7A== X-Gm-Message-State: AOJu0Yy2GlAzRMvaJ9vt+zmeBHFghpUGBpsvI0IBzZh7XxfioAxLkUIh BUOCyPAhN4EKD2IiKp7+Ox/btdeY3bH+Xw== X-Received: by 2002:a05:6a00:a08:b0:691:2d4:23a2 with SMTP id p8-20020a056a000a0800b0069102d423a2mr5430428pfh.31.1696495937915; Thu, 05 Oct 2023 01:52:17 -0700 (PDT) Received: from wenkaidev (118-163-147-182.hinet-ip.hinet.net. [118.163.147.182]) by smtp.gmail.com with ESMTPSA id p20-20020aa78614000000b006933f657db3sm872773pfn.21.2023.10.05.01.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 01:52:17 -0700 (PDT) From: advantech.susiteam@gmail.com To: advantech.susiteam@gmail.com Cc: wenkai.chung@advantech.com.tw, Susi.Driver@advantech.com, Wim Van Sebroeck , Guenter Roeck , linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org Subject: [PATCH 3/5] watchdog: eiois200_wdt: Implement basic watchdog functionalities Date: Thu, 5 Oct 2023 16:51:21 +0800 Message-Id: <61d7009003a08d47a3e5efc2906eb2e76d02cdb3.1696495372.git.advantech.susiteam@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 05 Oct 2023 07:30:25 -0700 (PDT) From: Wenkai In this patch, the driver has been extended to include basic watchdog functionality, allowing users to configure the watchdog timeout duration, start and stop the watchdog timer, and ping it to prevent system resets. The driver also reports the remaining time until a watchdog reset is triggered. Signed-off-by: Wenkai --- drivers/watchdog/eiois200_wdt.c | 64 ++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/drivers/watchdog/eiois200_wdt.c b/drivers/watchdog/eiois200_wdt.c index ce4435ac62f2..569e619448e5 100644 --- a/drivers/watchdog/eiois200_wdt.c +++ b/drivers/watchdog/eiois200_wdt.c @@ -106,6 +106,29 @@ static int get_time(u8 ctrl, u32 *val) return ret; } +static int set_time(u8 ctl, u32 time) +{ + /* sec to sec */ + time *= 1000; + + return PMC_WRITE(ctl, &time); +} + +static int wdt_set_config(void) +{ + int ret; + u32 reset_time = 0; + + reset_time = wddev.timeout; + + ret = set_time(REG_RESET_EVENT_TIME, reset_time); + if (ret) + return ret; + + dev_info(wdt.dev, "Config wdt reset time %d\n", reset_time); + + return ret; +} static int wdt_get_config(void) { @@ -123,24 +146,57 @@ static int wdt_get_config(void) return 0; } +static int set_ctrl(u8 data) +{ + return PMC_WRITE(REG_CONTROL, &data); +} + static int wdt_start(struct watchdog_device *dev) { - return 0; + int ret; + + ret = wdt_set_config(); + if (ret) + return ret; + + ret = set_ctrl(CTRL_START); + if (ret == 0) { + wdt.last_time = jiffies; + dev_dbg(wdt.dev, "Watchdog started\n"); + } + + return ret; } static int wdt_stop(struct watchdog_device *dev) { - return 0; + dev_dbg(wdt.dev, "Watchdog stopped\n"); + wdt.last_time = 0; + + return set_ctrl(CTRL_STOP); } static int wdt_ping(struct watchdog_device *dev) { - return 0; + int ret; + + dev_dbg(wdt.dev, "Watchdog pings\n"); + + ret = set_ctrl(CTRL_TRIGGER); + if (ret == 0) + wdt.last_time = jiffies; + + return ret; } static unsigned int wdt_get_timeleft(struct watchdog_device *dev) { - return 0; + unsigned int timeleft = 0; + + if (wdt.last_time != 0) + timeleft = wddev.timeout - ((jiffies - wdt.last_time) / HZ); + + return timeleft; } static int wdt_support(void) -- 2.34.1