Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1062116imm; Fri, 29 Jun 2018 10:42:31 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIFt2Xt8D+7ZOJvNR1Vh1ZzgPJHmQn2yswyP4cBckeKurNRzy/IxtoxP3+jr9MbxSHdyl7k X-Received: by 2002:a17:902:3381:: with SMTP id b1-v6mr16121253plc.248.1530294151480; Fri, 29 Jun 2018 10:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530294151; cv=none; d=google.com; s=arc-20160816; b=t2oSt+pU4LnXMMslg2frb4OJ5CkLCsirWNK217s54SO7GlkRH+M9IKg+gFA6QJcb0x fl7Vv1PT5oXlgyLBFhcGieFkwp4W4eUPddH/cbp6bqJAcTwJ+sA7+iof06R5+SrjykIE Ky0GhPbnqhLg6Bn/wvRFvgIN2dUxoF7dhdrdZyo/dLrmZleGmSgEjs/mx6nS1XFDhC5s Lm6DyuvC2tC5waozlvbMIqKMZ1TJhABjuRjwLPTLegZ+Vp7FMAW5hGCp9SRSVfoWyzoF pGWlSkuTKE96e/Et65Tzzzvcr+eHuw1Z9irL6M++yH4XxKGHlFmI0uZpJ1qE7a62xN7w sPuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=nVs1mMqEUBqbZLrWC+aIIR+sdCfod8IDORNO9la4l2I=; b=ZW1nRKXFPpnGsQaBJkn/hhZxXPRikOVoGpF7ZwJbE/HNbKWjJRGMuKePccrXLiV1A3 Mk7MnKYyztXkrHWB3WNXOpmhmhPbfKGHVMHLGzUIvfIpa4sl6G1stiINKYgl1Nf7MMhP G+R5f4PSMAsSR8c5iwWu/BRW+UMp6gtnF1n9A17U9BZqCrsCCEWSqrf//pW+53FZB87J cBSFb/Kt007eLYO8bqpqvo7GMn20AGVGwxmaePaNTjxgHUBf1zf2NXatbfvP6/VMQ006 BxTHNzHMB7+M0MT99CLKGbgUWUWpimP6A1+wHni+dATcinec1zqriJwvFaQ4Pv9ygOa4 Szcg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4-v6si8185380pgs.299.2018.06.29.10.42.17; Fri, 29 Jun 2018 10:42:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934950AbeF2Rb6 (ORCPT + 99 others); Fri, 29 Jun 2018 13:31:58 -0400 Received: from mail.bugwerft.de ([46.23.86.59]:41224 "EHLO mail.bugwerft.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934472AbeF2Rbt (ORCPT ); Fri, 29 Jun 2018 13:31:49 -0400 Received: from localhost.localdomain (pD95EF0F3.dip0.t-ipconnect.de [217.94.240.243]) by mail.bugwerft.de (Postfix) with ESMTPSA id 5936A28C419; Fri, 29 Jun 2018 17:28:33 +0000 (UTC) From: Daniel Mack To: zbr@ioremap.net, robh+dt@kernel.org, mark.rutland@arm.com, szabolcs.gyurko@tlt.hu Cc: sre@kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, robert.jarzmik@free.fr, Daniel Mack Subject: [PATCH v3 4/4] power: supply: ds2760_battery: add devicetree probing Date: Fri, 29 Jun 2018 19:31:37 +0200 Message-Id: <20180629173137.12690-5-daniel@zonque.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180629173137.12690-1-daniel@zonque.org> References: <20180629173137.12690-1-daniel@zonque.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a matching table for devicetree probing, and optionally set the module parameter variables from DT properties. Signed-off-by: Daniel Mack --- drivers/power/supply/ds2760_battery.c | 32 ++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/ds2760_battery.c b/drivers/power/supply/ds2760_battery.c index aa406a7c65a1..921cbcfd8c99 100644 --- a/drivers/power/supply/ds2760_battery.c +++ b/drivers/power/supply/ds2760_battery.c @@ -29,6 +29,7 @@ #include #include #include +#include static unsigned int cache_time = 1000; module_param(cache_time, uint, 0644); @@ -705,6 +706,27 @@ static int w1_ds2760_add_slave(struct w1_slave *sl) psy_cfg.drv_data = di; + if (dev->of_node) { + u32 tmp; + + psy_cfg.of_node = dev->of_node; + + if (!of_property_read_bool(dev->of_node, "maxim,pmod-enabled")) + pmod_enabled = true; + + if (!of_property_read_u32(dev->of_node, + "maxim,cache-time", &tmp)) + cache_time = tmp; + + if (!of_property_read_u32(dev->of_node, + "maxim,rated-capacity", &tmp)) + rated_capacity = tmp / 10; /* property is in mAh */ + + if (!of_property_read_u32(dev->of_node, + "maxim,current-accumulator", &tmp)) + current_accum = tmp; + } + di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; sl->family_data = di; @@ -719,7 +741,7 @@ static int w1_ds2760_add_slave(struct w1_slave *sl) ds2760_battery_write_status(di, status); - /* set rated capacity from module param */ + /* set rated capacity from module param or device tree */ if (rated_capacity) ds2760_battery_write_rated_capacity(di, rated_capacity); @@ -769,6 +791,13 @@ static void w1_ds2760_remove_slave(struct w1_slave *sl) power_supply_unregister(di->bat); } +#ifdef CONFIG_OF +static const struct of_device_id w1_ds2760_of_ids[] = { + { .compatible = "maxim,ds2760" }, + {} +}; +#endif + static struct w1_family_ops w1_ds2760_fops = { .add_slave = w1_ds2760_add_slave, .remove_slave = w1_ds2760_remove_slave, @@ -778,6 +807,7 @@ static struct w1_family_ops w1_ds2760_fops = { static struct w1_family w1_ds2760_family = { .fid = W1_FAMILY_DS2760, .fops = &w1_ds2760_fops, + .of_match_table = of_match_ptr(w1_ds2760_of_ids), }; module_w1_family(w1_ds2760_family); -- 2.17.1