Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp378054imm; Tue, 3 Jul 2018 21:45:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdzovASshYiEoBbZ5hdrBDKK8OtwTQw/r1Pz8pAZYL3pkGQts1hFL4KL430XxsPsXDORZQa X-Received: by 2002:a17:902:76c4:: with SMTP id j4-v6mr536351plt.19.1530679519038; Tue, 03 Jul 2018 21:45:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530679519; cv=none; d=google.com; s=arc-20160816; b=tHB53Cs7eHo1G32g5Eqi87mMHx49MZCnFqk2RLqIKnvQ3HflPChZh2pEylhTej3KQ0 1XZc+DxdsGRUexeLouI6+WuUISl1hfnOZStKon+U/ATcrAzsHwvm/ImiR9wLBW/ns9Ai GmIMyUCuMu4s7wr/tsACho6AnIIC00CnAizqcJYSyy+MRVJZPZ/RZj5D+EDHneVDdszm X6ycYrVVMcC72GqpH4XtwnxyTUjlho68xYW9CNbOvoBGMxJ+mxINGQaiOcU+VZItVc3+ o996gXLksCvIzmkBbcWaC+lzjGde6JF/GfurUdM9+Qr9xCeyQA5WCHmbAERZevfXVuWU IiWg== 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=naUQE/75dt2qL89FEkfjPNrT6B+ER18t3D6JQ7bg9xdMPd+Umk4JmHmt3e28zxhRcq 94oXPEfakGoETuTTcc4Rf3aE7VbR8odFExZXbx2Hk1NaRxtJDkFmEINf3VaKKtnFo/0p /r8zB1D5nnitq8kvkqIMMpKCbEDYhxDIGylFvk4b3E1bDpqgcIy4XcjfP5KvocMa2d1Y Dsam2oIac2XC1xOHEoJur2kYU1i9cHzrXhxOR3DiTznH3+sf0CGZmjvzlSpAuy0QuIkN ZkWi7mrsYUMNpQjMmi5ycGagDoy7A0ORcK35ut2zFZ6x4I+83NKQNXP9wG04S76eODrG BW7A== 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 a5-v6si2304313pgu.119.2018.07.03.21.45.04; Tue, 03 Jul 2018 21:45:19 -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 S933238AbeGDEo0 (ORCPT + 99 others); Wed, 4 Jul 2018 00:44:26 -0400 Received: from mail.bugwerft.de ([46.23.86.59]:41038 "EHLO mail.bugwerft.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933056AbeGDEoY (ORCPT ); Wed, 4 Jul 2018 00:44:24 -0400 Received: from localhost.localdomain (pD95EF712.dip0.t-ipconnect.de [217.94.247.18]) by mail.bugwerft.de (Postfix) with ESMTPSA id A973128D3F3; Wed, 4 Jul 2018 04:41:01 +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: Wed, 4 Jul 2018 06:44:11 +0200 Message-Id: <20180704044411.2693-5-daniel@zonque.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180704044411.2693-1-daniel@zonque.org> References: <20180704044411.2693-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