From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755531AbbIBSAp (ORCPT ); Wed, 2 Sep 2015 14:00:45 -0400 Received: from mail-gw2-out.broadcom.com ([216.31.210.63]:43378 "EHLO mail-gw2-out.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755206AbbIBSAo (ORCPT ); Wed, 2 Sep 2015 14:00:44 -0400 X-IronPort-AV: E=Sophos;i="5.17,455,1437462000"; d="scan'208";a="74085180" From: Justin Chen To: CC: , , , , Justin Chen Subject: [PATCH] watchdog_dev: Use device tree alias for naming watchdogs Date: Wed, 2 Sep 2015 11:00:17 -0700 Message-ID: <1441216817-25095-1-git-send-email-justinpopo6@gmail.com> X-Mailer: git-send-email 2.1.0 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently there is no way to easily differentiate multiple watchdog devices. The watchdogs are named by the order they are probed. 1st probed watchdog: /dev/watchdog0 2nd probed watchdog: /dev/watchdog1 ... This change uses the alias of the watchdog device node for the name of the watchdog. aliases { watchdog0 = "/...../...." watchdog3 = "/..../....." watchdog2 = "/..../....." ... } This will translate to... /dev/watchdog0 /dev/watchdog3 /dev/watchdog2 v2 Assign alias number to id in watchdog_core instead of watchdog_dev. If failed to get id, fallback to original ida_simple_get call. Signed-off-by: Justin Chen --- drivers/watchdog/watchdog_core.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c index 1a80594..873f139 100644 --- a/drivers/watchdog/watchdog_core.c +++ b/drivers/watchdog/watchdog_core.c @@ -139,7 +139,7 @@ EXPORT_SYMBOL_GPL(watchdog_init_timeout); static int __watchdog_register_device(struct watchdog_device *wdd) { - int ret, id, devno; + int ret, id = -1, devno; if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL) return -EINVAL; @@ -157,7 +157,18 @@ static int __watchdog_register_device(struct watchdog_device *wdd) */ mutex_init(&wdd->lock); - id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KERNEL); + + /* Use alias for watchdog id if possible */ + if (wdd->parent) { + ret = of_alias_get_id(wdd->parent->of_node, "watchdog"); + if (ret >= 0) + id = ida_simple_get(&watchdog_ida, ret, + ret + 1, GFP_KERNEL); + } + + if (id < 0) + id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KERNEL); + if (id < 0) return id; wdd->id = id; -- 2.1.0