Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp469771rdb; Thu, 22 Feb 2024 09:07:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV33DGm062z5vBqxfhSWzVa3sQhlA+6J2d8VBCzMNp4UJzrfv8/wiv38xVTceV3z+kpL7UAPz8ufkoSzsGhttil5eD5gZMtUCqu8qUNlw== X-Google-Smtp-Source: AGHT+IHC6kLYp6+73EXk99Wi4dl6+zk+UGffN6GKQUmqdjFoDiap2PQ97YP+yx0kF+nnfiPtROJF X-Received: by 2002:a17:902:ec89:b0:1db:aa46:4923 with SMTP id x9-20020a170902ec8900b001dbaa464923mr22408479plg.40.1708621657305; Thu, 22 Feb 2024 09:07:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708621657; cv=pass; d=google.com; s=arc-20160816; b=vr74sHCcJpAwrDWdordrqp7z4ro4QExx6SZ9EbMw3LvLY1KMX/2w5+BoUk1DMO0lza o+5yB/CD2z64N+e9rbx/7RtuwSFLCHqvq/PYXkjxYuyv4MTKFXblNrUhdJHnCRVbD13W hRUDX/zk+0XvSVzP87A4l4pTGS5W47taefv3t9NPUa7+HzXmVjgucPJtIbESd4PvPyV5 st3u+5UikFm/VIcW9kbOb3Ere4vF1trxAunwH8MBA2pbUt2+p5TDCfKbgOqGS2Q5ikqJ aAgAn6t0PHmgbqjNvWhWVUdUnMPWE6O32mklmkrHNAEKzAaXCxhPFfjw82nL3zT5pqHT lcCQ== 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=+AJY1b/GkESE33VWpBLvTa4w6mY5SFbxhnlFHdlXWDg=; fh=nv5mPDyL+gn29yYCkp4H0xRtubiLqqseGw1hdBUIMrI=; b=dpbI3cDxmRHiVsZBurmFPs8863KBDGyem3RMov6iw0mFHmx1VkjYgqtXJh0gKNF9bH 2QF0vfOvlyfxm7VWyrwWESQu2pJGSBacXb3RJbXJrTqFSsblQQL7UasQT+I9FZO0Y//q +OOJFF1BxAm1i7wgwcz8sKlpBFDfi+3de0NWc7yvH8fSa7lAe1dHCYQ5GJmanWr/2XUx kSx2bw0m7b9q2t2SpvPZRBoxbFKH/4K01FesyqGLPtmoZJ7dqUmsPFgoSXk7jpoxFihh Z5rXutA6k4VdMhtfK1rpZoHyVFno1C5SglFqpRwjmh89Nd4aLvK0KVJD9ZkdvOCMbUUw RL/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="rk4yls/b"; 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-76891-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76891-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=microchip.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id c17-20020a170902d49100b001dc0693e526si6752439plg.620.2024.02.22.09.07.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 09:07:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76891-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="rk4yls/b"; 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-76891-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76891-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id F0931B26D20 for ; Thu, 22 Feb 2024 16:42:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 63017153BCA; Thu, 22 Feb 2024 16:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="rk4yls/b" Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (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 E6F961474B6; Thu, 22 Feb 2024 16:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708620144; cv=none; b=T7DMZ05pnLEmZn262Vukqz7dEn6qpy4cuyHBMokNPUa+SgaOCLJ+3wdfaUgh4rd4qzY3H6SxkKIaGVt9FvbWV+05M1LSCJH9m2wg5DMQnadfOJHqbROEC54TDVGYHlhKao3ZVxbCuf/wq3yEBCqrXUrti4MNHpjehlrL7gnvwFk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708620144; c=relaxed/simple; bh=TlsyCxsx6t2l1kb/1VF6kn77np7doIMVXGCQWbJ2Xl4=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=VCVtsUFtdCVWlyUIpqNL1Qc4kqMkhufziXxWxgq/4PEOtksZQNH9uqDnrt7qoL7vRyPr0ZegAag+RJow0mh2O7hPe195SR/FcB+EjrJ49c0+tlXhDfB6V1J/IH63IKy9ArMXzLTSNASpTExieFMqCnUtl7EqGyxGlQhv8ZeAH1w= 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=rk4yls/b; arc=none smtp.client-ip=68.232.153.233 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=1708620141; x=1740156141; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=TlsyCxsx6t2l1kb/1VF6kn77np7doIMVXGCQWbJ2Xl4=; b=rk4yls/byXnhC99PcxzM3AtN4pBh7csMBHI5Z6Ui2gQVw5yZ6NfBf87N egV4Z0vhKWqb2xq8u713BzFp7prhDoNIEFho1nFoRrIu6spxobkVD+X49 z7WyHoSqug8HamhR3FrOdgy9NlaIR0nAS9Gnacq3EzU8pP0g3xCrzkzMr WOHEdLjvebIANO5Iv2QcdaoIlpeeCyWRTPOQgsihfDsk9vzRG1wF04tjd sTFzKSK89R+f3RzBvjFEzh/96EOVhi1WUHrR6NpvddyI8hsG6cc4kfBuQ bwq1lZ79jupRKPiKuacm69/GUortAv5phdmYYVHXxtQQssqUhBKZ0vvfn w==; X-CSE-ConnectionGUID: OvPE6kvdT3CJBCGLPKRzYQ== X-CSE-MsgGUID: wQakEbkGSSSHtESXrSmXTA== X-IronPort-AV: E=Sophos;i="6.06,179,1705388400"; d="scan'208";a="18201586" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Feb 2024 09:42:20 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 22 Feb 2024 09:42:17 -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; Thu, 22 Feb 2024 09:42:14 -0700 From: To: , , , , , CC: , , , , , Subject: [PATCH v5 0/2] adding support for Microchip PAC193X Power Monitor Date: Thu, 22 Feb 2024 18:42:04 +0200 Message-ID: <20240222164206.65700-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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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). The above statement it's a left over comment / attempt to summarize the discussion of whether IIO or HWMON was a better home for a driver for this device. Based on current feature set that's not an obvious decision, but there are other planned features that fit better in IIO. Differences related to previous patch: v5: - fix review comments: - remove | from device tree binding (not needed because there is no formatting to preserve). - update in_shunt_resistor_X attribute to in_shunt_resistorX - use channel enable to reset the energy counter for each acctive channels - update values of IIO elements to be in naturally aligned power of 2 - use address in the attribute (IIO_DEVICE_ATTR) to extract address field - update the code to use mod_delayed_work - change from kfree to ACPI_FREE - fix "0-day" issue related to double counter increment - check functions return in case of errors (like devm_kzalloc that could fail) - fix coding style issues 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 | 11 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/pac1934.c | 1637 +++++++++++++++++ 6 files changed, 1785 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 -- 2.34.1