From patchwork Mon Aug 12 13:29:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 11089865 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6312F13B1 for ; Mon, 12 Aug 2019 13:29:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53B2F28405 for ; Mon, 12 Aug 2019 13:29:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47A6A28455; Mon, 12 Aug 2019 13:29:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4544928405 for ; Mon, 12 Aug 2019 13:29:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728813AbfHLN3v (ORCPT ); Mon, 12 Aug 2019 09:29:51 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35914 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728812AbfHLN3s (ORCPT ); Mon, 12 Aug 2019 09:29:48 -0400 Received: by mail-wr1-f68.google.com with SMTP id r3so10829283wrt.3 for ; Mon, 12 Aug 2019 06:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id; bh=JzKOQ5mHteEnLA3+yRVnS5bSf+ysPwr2I6LlVQ1trvk=; b=pzLtY8G2u2/YII4gwwFRhcLQv7ubDho6IeAvFlIPIiH33bEq1k+YrhsW5qreW0lcGu L8H/7jxTlCtE75v4uGJMXzTyAYnqsKESIRyU1jB0U7ym/F7mmhSp5BVEuO/DH8YSeROJ Dc09BPlQNUtirekVi4fIOejsDxaRLtS8mZE7wCpdo5j3Bo8oxBepPRqFCJW1Binat5hE 5za6BeXQ+pd9wwO9PzFuAdc4BM9RVXMes78v2npvz+0UN+xMG2P5u5pIjbSGtzGJG8DL m/RTpwiDSM7MSXoIHZ6J/00igHnxLlvu3FGtWKTFAAgwcJCUqLpY4j0wDuevn0vIjLvh 0csg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=JzKOQ5mHteEnLA3+yRVnS5bSf+ysPwr2I6LlVQ1trvk=; b=p6Rl4rW/AZKVdThiqrQLdDh4IH4WRof4grAfgea1wRpr/tA/fB8j6gwD7SNc8KwcfH zCTAQXwoZK1Y5su+QrtybLtzgImOhOZ5SZiePMHHmg1WdPKP+l8YFHZkxQUPrpJdQSh9 CtMyKVjOxLsmU3ePjLKT6WID4JTMJz/zUcfmU1BTbYhrDrGlJeYE2FvXPCZYtl5pkFm/ WG/qFgvhpJJMy1scvJKJmmJ9oHMThSLj7cw+j5nRWbihzGR2llMHylphHLwT6YAMvQfi yuS2b8+eHND0JQhWEfMB75oMk4QmubiE5RZLoMK84XAg85E+VwH/RqFBxsixUMie1o0/ 5Y2w== X-Gm-Message-State: APjAAAXJVZeOCZlikMOf7e+AkhSJKXr8/6pBVW9n1MrsSJFMdUfhK1Y4 5Hh0E2Wf36eq6luCdl2f7K07BA== X-Google-Smtp-Source: APXvYqwaEf6WuwVVerQyI89ctyrQfAdB2zFMlbGgzZgdebonBeQNWlY4URBWmb2S8aG6AGspzUC0+Q== X-Received: by 2002:a05:6000:148:: with SMTP id r8mr13154631wrx.312.1565616586205; Mon, 12 Aug 2019 06:29:46 -0700 (PDT) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id r4sm70346111wrq.82.2019.08.12.06.29.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 06:29:45 -0700 (PDT) From: Michal Simek To: linux-kernel@vger.kernel.org, monstr@monstr.eu, michal.simek@xilinx.com Cc: linux-hwmon@vger.kernel.org, Guenter Roeck , Jean Delvare Subject: [RFC PATCH] hwmon: (iio_hwmon) Enable power exporting from IIO Date: Mon, 12 Aug 2019 15:29:41 +0200 Message-Id: <71aec0191e0e5f32cc760f95844d8ee215b48c7f.1565616579.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.17.1 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is no reason why power channel shouldn't be exported as is done for voltage, current, temperature and humidity. Power channel is available on iio ina226 driver. Tested on Xilinx ZCU102 board. Signed-off-by: Michal Simek --- But I don't think values are properly converted. Voltage1 is fine but the rest is IMHO wrong. But this patch should enable power channel to be shown which looks good. root@zynqmp-debian:~# iio_info -a && sensors -u Library version: 0.16 (git tag: v0.16) Compiled with backends: local xml ip usb serial Using auto-detected IIO context at URI "local:" IIO context created with local backend. Backend version: 0.16 (git tag: v0.16) Backend description string: Linux zynqmp-debian 5.3.0-rc4-00004-ga7ca33daed22-dirty #41 SMP PREEMPT Mon Aug 12 15:06:58 CEST 2019 aarch64 IIO context has 1 attributes: local,kernel: 5.3.0-rc4-00004-ga7ca33daed22-dirty IIO context has 1 devices: iio:device0: ina226 (buffer capable) 9 channels found: voltage0: (input, index: 0, format: le:U16/16>>0) 3 channel-specific attributes found: attr 0: integration_time value: 0.001100 attr 1: raw value: 70 attr 2: scale value: 0.002500000 voltage1: (input, index: 1, format: le:U16/16>>0) 3 channel-specific attributes found: attr 0: integration_time value: 0.001100 attr 1: raw value: 958 attr 2: scale value: 1.250000000 power2: (input, index: 2, format: le:U16/16>>0) 2 channel-specific attributes found: attr 0: raw value: 3 attr 1: scale value: 0.006250000 current3: (input, index: 3, format: le:U16/16>>0) 2 channel-specific attributes found: attr 0: raw value: 70 attr 1: scale value: 0.000250000 timestamp: (input, index: 4, format: le:S64/64>>0) allow: (input) 1 channel-specific attributes found: attr 0: async_readout value: 0 oversampling: (input) 1 channel-specific attributes found: attr 0: ratio value: 4 sampling: (input) 1 channel-specific attributes found: attr 0: frequency value: 114 shunt: (input) 1 channel-specific attributes found: attr 0: resistor value: 10.000000000 2 device-specific attributes found: attr 0: current_timestamp_clock value: realtime attr 1: integration_time_available value: 0.000140 0.000204 0.000332 0.000588 0.001100 0.002116 0.004156 0.008244 2 buffer-specific attributes found: attr 0: data_available value: 0 attr 1: watermark value: 1 1 debug attributes found: debug attr 0: direct_reg_access value: 0x4327 ina226_fourth-isa-0000 Adapter: ISA adapter in1: in1_input: 0.000 in2: in2_input: 1.198 power1: power1_input: 0.000 curr1: curr1_input: 0.000 --- drivers/hwmon/iio_hwmon.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c index f1c2d5faedf0..aedb95fa24e3 100644 --- a/drivers/hwmon/iio_hwmon.c +++ b/drivers/hwmon/iio_hwmon.c @@ -59,7 +59,7 @@ static int iio_hwmon_probe(struct platform_device *pdev) struct iio_hwmon_state *st; struct sensor_device_attribute *a; int ret, i; - int in_i = 1, temp_i = 1, curr_i = 1, humidity_i = 1; + int in_i = 1, temp_i = 1, curr_i = 1, humidity_i = 1, power_i = 1; enum iio_chan_type type; struct iio_channel *channels; struct device *hwmon_dev; @@ -114,6 +114,10 @@ static int iio_hwmon_probe(struct platform_device *pdev) n = curr_i++; prefix = "curr"; break; + case IIO_POWER: + n = power_i++; + prefix = "power"; + break; case IIO_HUMIDITYRELATIVE: n = humidity_i++; prefix = "humidity";