Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1400899imm; Thu, 5 Jul 2018 22:37:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpda6BefbUtl+/f6ayOhGgOZWk+Bd+w0yV7s1E+YLj3ZcfGGALfL+VBNTxCZpxYAwjIZ61k+ X-Received: by 2002:a65:594b:: with SMTP id g11-v6mr2125490pgu.260.1530855443756; Thu, 05 Jul 2018 22:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530855443; cv=none; d=google.com; s=arc-20160816; b=DvT0ZiEbhsu5qduUIQiSphjz0sAUZ2Yx4+0yl25GlD76R5jTG1vG+eUMVaMfkVeXUm mVED/7RBzR0bU377IYZiSOF5Ks9jntft0LV7B7Av5Et3Jh9p5PV1eeCVWOdbt8sXHAaG RmkTeR1S9X+uvDq4nenmhaklp0qcSSxNDo9eM5lEVP8lm/F9f3j3zILqqFcNHcanfRIn yil2mkeKUljId1gOAtNRpPO1quxSwi2ONaFPLiA/4bm7mjWGSzzP1k8koA9rpZNHj9St HQyostETmHQaFFDEgW0JsrQiJP9rok/sAnGlaG1jojNdkEpUTGBbby/tcQ4K7F5ueLeW 6IBw== 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=IlTmVQifTlvNq0lpHwjyV7OhdphsfjXpZQBOGGAOWTA=; b=yX36vnVEyIG4ne0yHcovUDju0sIJN8vGaqaz1SrM+ku0GplkONKvj/bEz6br3nINZ3 16dTN95XtZ7nCiij7svz553ytCppffw98jc/sGn+G8UM4Xx++VcoSDKlMlv9MousXEEo EqR88JJpFeo53laOQ2ss1YArBO6o1DBt1jgM0oQ8wDBzmM4a9ky7MHeKn3Hr6Qqz7UZl icafqk3JQ2XKB7f2l30iBqhlM0LoiAHVHxKrKxgzR9aQRRj/E22lpBWAkExAVILs4TVW qktHsRpaEXTHO5+OmdkcuGy/supxN2PFTNQEY81k+QpJBHwiIJNWSoEq9uFGztG4D6Q/ yuJA== 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 l5-v6si7722144pls.360.2018.07.05.22.37.09; Thu, 05 Jul 2018 22:37:23 -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 S932650AbeGFFgT (ORCPT + 99 others); Fri, 6 Jul 2018 01:36:19 -0400 Received: from mail.bugwerft.de ([46.23.86.59]:37648 "EHLO mail.bugwerft.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932205AbeGFFgH (ORCPT ); Fri, 6 Jul 2018 01:36:07 -0400 Received: from localhost.localdomain (pD95EF57F.dip0.t-ipconnect.de [217.94.245.127]) by mail.bugwerft.de (Postfix) with ESMTPSA id 37C0F28DBF7; Fri, 6 Jul 2018 05:36:02 +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 v4 5/5] power: supply: ds2760_battery: add devicetree probing Date: Fri, 6 Jul 2018 07:35:52 +0200 Message-Id: <20180706053552.11438-6-daniel@zonque.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180706053552.11438-1-daniel@zonque.org> References: <20180706053552.11438-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 | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/ds2760_battery.c b/drivers/power/supply/ds2760_battery.c index aa406a7c65a1..11bed88a89fa 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,24 @@ 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-ms", &tmp)) + cache_time = tmp; + + if (!of_property_read_u32(dev->of_node, + "rated-capacity-microamp-hours", + &tmp)) + rated_capacity = tmp / 10; /* property is in mAh */ + } + di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; sl->family_data = di; @@ -719,7 +738,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 +788,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 +804,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