From patchwork Mon Jan 22 08:47:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: marius.cristea@microchip.com X-Patchwork-Id: 19238 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2442693dyb; Mon, 22 Jan 2024 00:53:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0s34lqTOReKZbiJ/qaErV5R44oFMjfIkkfHXqTjzxWxZREYwvKBPaogU3YMw1YZw3JYO8 X-Received: by 2002:a05:620a:60c3:b0:783:2a38:e751 with SMTP id dy3-20020a05620a60c300b007832a38e751mr2714813qkb.136.1705913627779; Mon, 22 Jan 2024 00:53:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705913627; cv=pass; d=google.com; s=arc-20160816; b=AqFBy2Q1jYJXnd/13s11VXc+fPFzU5Q8BnOhxfGUZlCNjGuM9dYHLDRyh4CdTv6+Zq c7/xIKRhuiK2Ywr23+/d++UORNPKWtr0Sx8q7Nu4axy/bgVvinszreiT2w+ULorywZ0M tJ3apJPbcPfoxipIe5EXFTeSna7lyKatDYiIF7sKXJ9oicL6nD9ru5dug0vwjZxeayCs 0erzqHNUKBVBwGK/UMvrqbrCZDmjHqDRyym6CtOSCTx+4j/Zzeg+MwY9XETyd2XnGoFx VzeOF5UI9u1wPB80CpEyCJFVNIF/ORJWhK37t9dP39CJcqtANF/yWzRGMqb3xg2UMj4R pgvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=FsWfUkt0fZHxyBtLfZOfJzjIPI7fynXWbBYW9jDgXio=; fh=nv5mPDyL+gn29yYCkp4H0xRtubiLqqseGw1hdBUIMrI=; b=QYmxgTg6Y8vIxlPTuWnT8zpTiXGkiPKyNQMNvPL6n3XIrNUN9yNGIovv/dB4TtW9iA VxKXhDE5aRhSkachDcUJnvbOdyeMs4oj2LE6yZCTVnPWaKR9SHiRDQkAMNSGTw8g9CZ2 fA2G22Cv5KXD80evGUMoLljHcFq6IfzG9CYzTVC/RZ+pjGaLsLxCJfC5bx1C+B3rDxoc VWf5gKUvi9aOgwqW6dTnfEublv4CAG++/0LtgEGd7m6j42N2egTpwHK8KTJbsqr8cIm5 Y8+IRnZFc9e1WnQwj4gnfz8MCHWSqPj/BbPoGDwRxnvDBFwUX46EVPkf/SN2yV5XSfvU 5BnQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=PbdD3Z0z; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-32566-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32566-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=microchip.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j13-20020a05620a000d00b007833db52999si4945893qki.583.2024.01.22.00.53.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 00:53:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32566-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=PbdD3Z0z; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-32566-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32566-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=microchip.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 92B061C222A1 for ; Mon, 22 Jan 2024 08:53:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B2E53D540; Mon, 22 Jan 2024 08:48:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="PbdD3Z0z" Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EFEF38F8F; Mon, 22 Jan 2024 08:48:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913307; cv=none; b=SaRdFkMcrxF92WaJcrHOmwNEQ7NWeVwPm+iKmRg/xoP8g48VSKNxDfzhI3aH/rByTy2/kBUg/K6T1A3JSFYXtE1YTLy4obdclZs1qBedheqjErJveEdU+VplkpM7bHfEXvq/0/iXEYP1oZg0B6cQIZ3SNStKj+T06EYnWqrAyk8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705913307; c=relaxed/simple; bh=WYvUJM6Lln/O7kMg7YLdb6gXjy+H8J71CclA1VdAyD8=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=kwVY7stdxYXdssnFfEbU/BrrR6Nq5nHBdKu3Byx0ZKfry1jiB4eTHfMn3mdv8+V5RdlYtFOoI1yZ8SZCS6AA3gduKvO94mCZaOEnXBh669ZT8pc7X1kc5Y/sfpkyOdHkC9DPbjXoPsVLkzJsQNKdoo9Uv62oc+/2+ytCwEbsZW0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=PbdD3Z0z; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1705913305; x=1737449305; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=WYvUJM6Lln/O7kMg7YLdb6gXjy+H8J71CclA1VdAyD8=; b=PbdD3Z0zZyqZPssJ1jRGUp97yERSto0Td81xnc+CujYHf/y/4XdEruqC E3hX38B2sidv5Y/FtUI954CdAZYJpCB/gCvf4/ldtpLUAUrlN1Yhm6JK5 rqp8983Hr71VEyKs8jZYygswKr4QyK53An3R6Lf9iu/Es/doHYnEdIfR7 BpWOohAmIfHI+IK584kVAOgac6wTMbxxCuNd7m2hVT09+m2QqFDU3GTc6 BBFNai0+fAL5tfSybnr2oa+kZxA8YkvzJ7jg7V0l3gNHr6UhL1IuL9ww6 2JEXWghXl8Q5bD10BZPUgbZ1UTMLhKsbJ9+erZwJrkEX1ysLr1t06DU/I g==; X-CSE-ConnectionGUID: 4ytLpERVSI+Hb+Gl/SsgFQ== X-CSE-MsgGUID: Bvw4fyzxTSmyLuJ1xX4WYw== X-IronPort-AV: E=Sophos;i="6.05,211,1701154800"; d="scan'208";a="15087208" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Jan 2024 01:48:24 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 22 Jan 2024 01:47:18 -0700 Received: from marius-VM.mshome.net (10.10.85.11) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Mon, 22 Jan 2024 01:47:15 -0700 From: To: , , , , , CC: , , , , , Subject: [PATCH v4 0/2] adding support for Microchip PAC193X Power Monitor Date: Mon, 22 Jan 2024 10:47:10 +0200 Message-ID: <20240122084712.11507-1-marius.cristea@microchip.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788780088372468498 X-GMAIL-MSGID: 1788780088372468498 From: Marius Cristea Adding support for Microchip PAC193X series of Power Monitor with Accumulator chip family. This driver covers the following part numbers: - PAC1931, PAC1932, PAC1933 and PAC1934 This device is at the boundary between IIO and HWMON (if you are looking just at the "shunt resistors, vsense, power, energy"). The device also has ADC internally that can measure voltages (up to 4 channels) and also currents (up to 4 channels). The current is measured as voltage across the shunt_resistor. I have started with a simple driver (this one that is more appropriate to be a HWMON) and willing to add more functionality later (like data buffering that is quite important for example if someone wants to profile power consumption of the processor itself, or a peripheral device, or a battery, this kind of functionality was requested by our customers). Differences related to previous patch: v4: - remove the "reset_accumulators" proprietary attribute - add enable/disable for energy channels - remove "reset_accumulators" attribute - remove unused/redundant defines - rename variable to be more relevant into a certain context - make "storagebits" naturally aligned power of 2 - fix coding style issues - use to_iio_dev_attr to access address field in the IIO_DEVICE_ATTR() - remove unnecesarry "break" from switch case - remove double increment and initialization of a variable - use address as index in IIO_DEVICE_ATTR - properly handle memory allocation failure v3: - this version was sent also to HWMON list - fix review comments: - drop redundant description from device tree bindings - reorder "patternProperties:" to follow "properties:" in device tree bindings - update comments to proper describe code - use numbers instead of defines for clarity in some part of the code - use the new "guard(mutex)" - use "clamp()" instead of duplicating code - remove extra layer of checking in some switch cases - use "i2c_get_match_data()" - replace while with for loops for the code to look cleaner - reverse the logic to reduce indent. - add comment related to channels numbering - remove memory duplicate when creating dynamic channels - add "devm_add_action_or_reset" to handle the "cancel_delayed_work_sync" - remove "pac1934_remove()" function v2: - fix review comments: - change the device tree bindings - use label property - fix coding style issues - remove unused headers - use get_unaligned_bexx instead of own functions - change to use a system work queue - use probe_new instead of old probe v1: - first version committed to review Marius Cristea (2): dt-bindings: iio: adc: adding support for PAC193X iio: adc: adding support for PAC193x .../ABI/testing/sysfs-bus-iio-adc-pac1934 | 9 + .../bindings/iio/adc/microchip,pac1934.yaml | 120 ++ MAINTAINERS | 7 + drivers/iio/adc/Kconfig | 12 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/pac1934.c | 1646 +++++++++++++++++ 6 files changed, 1795 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-adc-pac1934 create mode 100644 Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml create mode 100644 drivers/iio/adc/pac1934.c base-commit: b1a1eaf6183697b77f7243780a25f35c7c0c8bdf