From patchwork Mon Sep 9 15:39:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 1982631 X-Patchwork-Delegate: andi.shyti@kernel.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=mAkKvtI3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-i2c+bounces-6415-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X2WGq2tVkz1y1p for ; Tue, 10 Sep 2024 01:39:31 +1000 (AEST) 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 6FEABB23464 for ; Mon, 9 Sep 2024 15:39:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A151A4779D; Mon, 9 Sep 2024 15:39:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="mAkKvtI3" X-Original-To: linux-i2c@vger.kernel.org Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3692F481B4 for ; Mon, 9 Sep 2024 15:39:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725896362; cv=none; b=bXszqKJQ9lJRTnZw15z/vClFSXnzS21zvjeZnHUl6MdXDXdZdmpl8RBDrw2MT+qEwJvNhyGxBswIs2fN0jtkMcbLkCx69sIkVTwDlWP+9I4B1Jl6yXDcxreZ8y8ykoWzlQKE8xYrT5kQLJr3Zae9yxbGF6BooE9Bi8k14QmmgJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725896362; c=relaxed/simple; bh=MbQam2qxm3Rqs7R5Unkd0xpWMZCqWsf25GFP4NDn8YY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H2VbI7AEM2WsTazZjXPJ9ywglEzuWbyLntJcSZCw6rSxagl3iyE7zZikrMLgb0eU73MRn29czGX+UbvsCGG0a7VJbOmYzKI2SVaN1p1BeL3qYcawBpu/L7cKinE7JEVT19XWHs+u5dvj80HdrUlF/hW5/WJjEQgSd5d3KdLwmUQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=mAkKvtI3; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-42ca4e0299eso22053645e9.2 for ; Mon, 09 Sep 2024 08:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725896358; x=1726501158; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Q1CCslGvH+cEKiqCreHe62tX9+GxMbBnRRD70n4wPSQ=; b=mAkKvtI3KTAlgMeDtq+wGbNZ6id1FuY0/ZbL/5kGxQAtjMJk3jH8IkRPZQKFMfpnCT Q1HjgvY5iilVHGq40nK9M6YxLODbm3bOilaWEHIar5xmI5t8zVoegHnLEC8sJL0/fpQ2 oth/Bq5Ria5rUN613/FrarDVaS4asm+ACA0stMFJEadAXr2u6/SWbbDAlkeyaO62+6O0 R8cd+gLD7R2Q+WM80HzM/19GUC9+mc+WQNfW3a6Lfw8ek6BMsokdB3uYsmw8HlJoJkkZ xIQS00rz7iThfNNYT/7CZCT+ajoFyGxk9XwhNLw4Yr+JL9TiR+5Qhl9tw5ef0LYGGZ6H N9yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725896358; x=1726501158; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q1CCslGvH+cEKiqCreHe62tX9+GxMbBnRRD70n4wPSQ=; b=OClPJ2zE7k83+mJerCsJ4AdNbng7ECRjpj3VXL7CwI+7qxGy2DKGiqepNMkdsZqhIc FjjdRXkv/C7YNFZh7/s9+bSgWgFtmw/7xCw0ruEZe9A6i6aAkkv0708FcdQzhOxChOyf wdek/hQiTB+MZTb+9ziBcfZpHbEiKSDgmaSv4+RlFJH5NOM/fsBxG0LBTKf1xbY59tov Z+y7z0y0b5Efjz9v7aknnAaqCB8GvtaSd4yD3ybgsdPLFzYHD1k4Zgm511ywUjeRRbXX 98UqSbTcZdYOa2N9LxiPF/DZJfJU/2qHD417rAZXzKrpnHW66qjecFyT5H85TR2vG00u dwfQ== X-Forwarded-Encrypted: i=1; AJvYcCWxv4SwRLQCqW5u0ocjTd4I+Nvp/L5pDJ+REdhvIyJjUopknXrsCav4TE5Woj3DgB5LJp1mqqpgPM0=@vger.kernel.org X-Gm-Message-State: AOJu0YzZqA1CYDFAEcFVIspYrwH3HI+mkaoTA+nWE+7JiXihxQGsAiFL yby6g9SmE12FFxtF9ORQEX6g4a1yqZxn85iONkukq8nAljBveTJ6QIK9qYCcivU4QOOFTlkUdBK W X-Google-Smtp-Source: AGHT+IFMwpVD9rZcOmHzGbymeIWKFLLsAnXiyFTa8tkM95t4s2kgxxLmeLfwoD9X32FksjzSqR2wNg== X-Received: by 2002:a5d:5547:0:b0:374:c31e:971a with SMTP id ffacd0b85a97d-378922b81f4mr4759396f8f.0.1725896358378; Mon, 09 Sep 2024 08:39:18 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:788a:4542:ae86:67f4]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3789564af1asm6305145f8f.18.2024.09.09.08.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 08:39:17 -0700 (PDT) From: Jerome Brunet Date: Mon, 09 Sep 2024 17:39:03 +0200 Subject: [PATCH 1/3] dt-bindings: hwmon: pmbus: add ti tps25990 documentation Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240909-tps25990-v1-1-39b37e43e795@baylibre.com> References: <20240909-tps25990-v1-0-39b37e43e795@baylibre.com> In-Reply-To: <20240909-tps25990-v1-0-39b37e43e795@baylibre.com> To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jerome Brunet , Jonathan Corbet , Delphine CC Chiu Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-i2c@vger.kernel.org X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2319; i=jbrunet@baylibre.com; h=from:subject:message-id; bh=MbQam2qxm3Rqs7R5Unkd0xpWMZCqWsf25GFP4NDn8YY=; b=owEBbQKS/ZANAwAKAeb8Dxw38tqFAcsmYgBm3xahmW3hnq9FSBBkKIx7xDnCI6AofwQtzIjcD 7ySiMZRekyJAjMEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZt8WoQAKCRDm/A8cN/La hSOpD/4xMK9dZ851o6Q01h8xpWmPdIxDZFzaL3tNEuyOKJbskvL8PjZHD2y2J+MrtkkEoFxvnlw nZDbfzjlpEI+QAhNrOpA+xzogiKryYIytJWOVEdl4LkTvzHpqyoudMHlW10aWXGmB2v6MLPxQyE 4FEdbhXWPY1GOLB//Z8rr7Akx0sYonvu82QVHo90wS1UFD4eNtDGRrfwXVzwWbbGmXO/bphmj4e QVkI7o3Ef3XqT3A/Xu4jcdCEfGO5MNjxKEdk5iSz7hDIDxxWj/DTBKAkmO9MEeRgOVIRUIGkJY1 USo0HShLwu1HvYtW0AjlC3MYLAXhmMhJE0+q2EWP9rKePCQjIZLd9l0pyLHxxn1oO++c1jmLm44 AaARV5lMHMFGFmeTOKQAdbfBGrkaZ2zHXPHkxUQ+GSzmbHhZSbFbu6qGOv96r3QjNGBcttpBanX ijw63q33Rbp/qXyRmz2fxFcqAV1uuVjqS5YLPUCzxayo7DOo6xsk/XXjP3/o5B45V4ymvMqwOBB 55C+pP1PQE0aOFUOSrIbgNI4mlfRQfsuy2Q4OcrBNxgc/HinI+gLGsLBK9+Q8qJMjtFkxWw3r9B 4XwyO4n5JwSNopVyGwiqjBej+nNX9FxwqiFX4Qr7gbbybG/eqHrHgBQaKRvYxursY+aiQxTHDpb DzCaJ0eRkfB4Oug== X-Developer-Key: i=jbrunet@baylibre.com; a=openpgp; fpr=F29F26CF27BAE1A9719AE6BDC3C92AAF3E60AED9 Add DT binding documentation for the Texas Instruments TPS25990 eFuse Signed-off-by: Jerome Brunet --- .../bindings/hwmon/pmbus/ti,tps25990.yaml | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/pmbus/ti,tps25990.yaml b/Documentation/devicetree/bindings/hwmon/pmbus/ti,tps25990.yaml new file mode 100644 index 000000000000..e717942b3598 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/pmbus/ti,tps25990.yaml @@ -0,0 +1,73 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- + +$id: http://devicetree.org/schemas/hwmon/pmbus/ti,tps25990.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Texas Instruments TPS25990 Stackable eFuse + +maintainers: + - Jerome Brunet + +description: | + The TI TPS25990 is an integrated, high-current circuit + protection and power management device with PMBUS interface + +properties: + compatible: + const: ti,tps25990 + + reg: + maxItems: 1 + + ti,rimon-milli-ohms: + description: + milli Ohms value of the resistance installed between the Imon pin + and the ground reference. + + interrupts: + description: PMBUS SMB Alert Interrupt. + maxItems: 1 + + regulators: + type: object + description: + list of regulators provided by this controller. + + properties: + vout: + $ref: /schemas/regulator/regulator.yaml# + type: object + unevaluatedProperties: false + additionalProperties: false + +required: + - compatible + - reg + - ti,rimon-milli-ohms + +additionalProperties: false + +examples: + - | + #include + i2c { + #address-cells = <1>; + #size-cells = <0>; + + hw-monitor@46 { + compatible = "ti,tps25990"; + reg = <0x46>; + + interrupt-parent = <&gpio>; + interrupts = <42 IRQ_TYPE_LEVEL_LOW>; + ti,rimon-milli-ohms = <1370000>; + + regulators { + cpu0_vout: vout { + regulator-name = "main_cpu0"; + }; + }; + }; + }; From patchwork Mon Sep 9 15:39:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 1982635 X-Patchwork-Delegate: andi.shyti@kernel.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=3btQtouZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-i2c+bounces-6417-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X2WHZ2QbPz1y1D for ; Tue, 10 Sep 2024 01:40:10 +1000 (AEST) 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 am.mirrors.kernel.org (Postfix) with ESMTPS id C86021F2421D for ; Mon, 9 Sep 2024 15:40:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D4ABB13A894; Mon, 9 Sep 2024 15:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="3btQtouZ" X-Original-To: linux-i2c@vger.kernel.org Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C660150288 for ; Mon, 9 Sep 2024 15:39:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725896365; cv=none; b=riPw1OvV7MM6/stYOzHkL34RS9AHe8+lRdRqv4DovN+hWEPpfjgUpYkQnorKqoCOz8J2+v8/JT03yYoxQTtjqM86YXPKuDHYk7HIu1f7MvLgBNrUs/xn2WKd/D2TtA8dFRz7rypEDuB51pv9l1/rdP+TDtIUwTj4H2rzYUCvUlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725896365; c=relaxed/simple; bh=vJ4BQU0XZIcK8J00Oopy9XQQFvb4Ue39E+Oh6NKsto8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rOQJT19u9K5NK7XT5h4n5c89L/eDlplxdRv5KWngfW8ZlHFpPGH1nZFd9jctnePyk1RPfdBoCC7h9pmMcZ+BD6tNvc4YsbYARykrto0q5km08UBSULthq97dA8bhg7uxqtMlOm47eWbyMPDv9zgediasv4yaFmXAIqJH24jKYtg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=3btQtouZ; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-374c7e64b60so2635724f8f.2 for ; Mon, 09 Sep 2024 08:39:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725896360; x=1726501160; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=MhtRCE6PbFntlTL0HxjwIxBidPbr+PaAQPsqAyH1vys=; b=3btQtouZjSEFEJhEddG4Hj8fI2+k7OH9YwCXiRTo/W7VDen/Uf8Sfx/bx3vEDxHgTE W1OuqNYmCcXxunfLDwjyDzK8fkJ1++KU3/3RnAll2O5l31LZ9CkURsELvwu6tn1Z24OG 5nifKFfUVebXABpkMf0dz4IXRUrS1HhpHSOLxlXwcPqKP/yl5j0JV9aEj43ojmk3Mr0e /Kel3EzaykHvm/7JmFedq/c8Bj5YXWBUYo6CD9D14i2anaINwJapAOwcqtnYdaZm4Cuq A8xpMp6t2JZ+9cPTYF/l4oWFonvkp0DaUdiIdVNMRaNDSjjah0Ue5mKj+1aOQA6UxkLN 0pXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725896360; x=1726501160; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MhtRCE6PbFntlTL0HxjwIxBidPbr+PaAQPsqAyH1vys=; b=mkxaPua4UkqvB+PIYZ5wFgjMEp1qb+wukOrid2Sb/Yhs/DPgdbhimgbtu7SwDAnxE7 yqEZEtXBr4fipauGcfoXbGXdxcsIziH9o89RGmfSN3p+8pj3xISdsFT21whL4xxhmLIx I6O6ykVS1M5XDnxhhl3LCCnr5iTyOnChReC+f28LEy9c+QTGEr6u6+DMS2NoWgA+jWMq 7MXbXCo6sem4p5jZvK20NWoK3osuSJHmSE4kq9/mqBU7AtPEhw+LTexZDzdvZOCt2NmD QkPBmpFk6S8slp2hcXkAIQbIMxLTYAXtB3YCLALu/5N2RaLNMYIzxCUJTSEYQ9G3jmzT boOw== X-Forwarded-Encrypted: i=1; AJvYcCW9nGpNU6ydv62HlYZdXpeabUtMvGEhCT4VpwsrW6hfsNCDamSeUv5RmxlUkEbXhrImL4oKzMmJSCM=@vger.kernel.org X-Gm-Message-State: AOJu0YxqoqD/PJ2FlsOBKMdGH3HbTCHfqX+w9NzYPiH5U7Rq2TcJ8WcG WggWCP1mmudQguxhPmWiR0/S1aTwH0KziDbfjUcCFMexknb5JQ0Z8xu5aq4nZbT+JiuFq0VRIQe B X-Google-Smtp-Source: AGHT+IEJgxPHK8MMMPe3LUlF7ZdETXabJsvUYuGFTUOiVywij0WZCN5KQkmE2azknuKxQLLKoQwBnQ== X-Received: by 2002:adf:f206:0:b0:371:8ca4:1b76 with SMTP id ffacd0b85a97d-378896121f2mr7228196f8f.32.1725896359182; Mon, 09 Sep 2024 08:39:19 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:788a:4542:ae86:67f4]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3789564af1asm6305145f8f.18.2024.09.09.08.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 08:39:18 -0700 (PDT) From: Jerome Brunet Date: Mon, 09 Sep 2024 17:39:04 +0200 Subject: [PATCH 2/3] hwmon: (pmbus/core) add POWER_GOOD signal limits support Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240909-tps25990-v1-2-39b37e43e795@baylibre.com> References: <20240909-tps25990-v1-0-39b37e43e795@baylibre.com> In-Reply-To: <20240909-tps25990-v1-0-39b37e43e795@baylibre.com> To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jerome Brunet , Jonathan Corbet , Delphine CC Chiu Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-i2c@vger.kernel.org X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1966; i=jbrunet@baylibre.com; h=from:subject:message-id; bh=vJ4BQU0XZIcK8J00Oopy9XQQFvb4Ue39E+Oh6NKsto8=; b=owEBbQKS/ZANAwAKAeb8Dxw38tqFAcsmYgBm3xairYSGGaLEKh/WnARwotxDj4C2L/d3Tc/6d XGKzwAM2g2JAjMEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZt8WogAKCRDm/A8cN/La hTWrD/sH/ZzBTCRaI5fuZQnDD53t6rP5XdAGe//eiiyh0tbtCh+pDxadxfodQU3qq5nDnVCAvXN aL5SPFf9V//nKQ6cc2z5OsLTkZ0LgQsKWiad2LAuh9o2vTkM8D48Kwd2DEZWs1z4rxcqD05JtFK cJzC47s3Lpu9YsDmkGVbG18lsNiYLMaN7LeqpkVSWfPyo/OBv+PzlILrQ4YOt+9xb+HjkshEj0q 8yc0bhBOT6gku0d4au/aAkkpTyVZ/AWMUjLn28yG0FpKXY86bmBrVRkX3pTSIphmB/gP7ZIAJgE qT8B1KWLajtWj612KdAYlXeJmQellE/vBpqL6EoVfvNDqrJmE7T0T8qf3k5mLdqISHMc+zq5fTY 3nfb/ahqgVbnr6dqYPDgWnDOZp7NKlNJ5+rN+sOXA6ucZbS27vIvOPk6hZM5RsFsryULFmR/wei /gvpr/DQLt8+8l7mbD9TanXkcBGqKySK+MpHhR31nE5h7m7f0HTWcUTdI4IgqI/DroSAbB+i8Hz a09NrA4s7XGzsl2BW5p/TRLIXlX0ITIMYudIr8ArWi8a6GfU2fLpGvUj6IQp+IC6LGqvEv+5WM4 WfWTnzNzCdV9ij4jCEVwVmEv+1j1pDZqQGEbEPyld+O3lsKhvNd7bm6lcZv4n2gHLtcGMjkIBuf WHdzx7vbPcc9N8Q== X-Developer-Key: i=jbrunet@baylibre.com; a=openpgp; fpr=F29F26CF27BAE1A9719AE6BDC3C92AAF3E60AED9 Add support for POWER_GOOD_ON and POWER_GOOD_OFF standard PMBus commands. For PMBus devices that offer a POWER_GOOD signal, these commands are used for setting the output voltage at which a power good signal should be asserted and negated. Power Good signals are device and manufacturer specific. Many factors other than output voltage may be used to determine whether or not the POWER_GOOD signal is to be asserted. PMBus device users are instructed to consult the device manufacturer’s product literature for the specifics of the device they are using. Note that depending on the choice of the device manufacturer that a device may drive a POWER_GOOD signal high or low to indicate that the signal is asserted. Signed-off-by: Jerome Brunet --- drivers/hwmon/pmbus/pmbus.h | 3 +++ drivers/hwmon/pmbus/pmbus_core.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h index 5d5dc774187b..e322d2dd9fb7 100644 --- a/drivers/hwmon/pmbus/pmbus.h +++ b/drivers/hwmon/pmbus/pmbus.h @@ -78,6 +78,9 @@ enum pmbus_regs { PMBUS_IIN_OC_FAULT_LIMIT = 0x5B, PMBUS_IIN_OC_WARN_LIMIT = 0x5D, + PMBUS_POWER_GOOD_ON = 0x5E, + PMBUS_POWER_GOOD_OFF = 0x5F, + PMBUS_POUT_OP_FAULT_LIMIT = 0x68, PMBUS_POUT_OP_WARN_LIMIT = 0x6A, PMBUS_PIN_OP_WARN_LIMIT = 0x6B, diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 0ea6fe7eb17c..94ddf0166770 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -1768,6 +1768,12 @@ static const struct pmbus_limit_attr vout_limit_attrs[] = { .attr = "crit", .alarm = "crit_alarm", .sbit = PB_VOLTAGE_OV_FAULT, + }, { + .reg = PMBUS_POWER_GOOD_ON, + .attr = "good_on", + }, { + .reg = PMBUS_POWER_GOOD_OFF, + .attr = "good_off", }, { .reg = PMBUS_VIRT_READ_VOUT_AVG, .update = true, From patchwork Mon Sep 9 15:39:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 1982634 X-Patchwork-Delegate: andi.shyti@kernel.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=uEq1gNe3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-i2c+bounces-6416-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X2WHS0ZCXz1y1S for ; Tue, 10 Sep 2024 01:40:04 +1000 (AEST) 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8AF1B1F241B0 for ; Mon, 9 Sep 2024 15:40:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6930813A244; Mon, 9 Sep 2024 15:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="uEq1gNe3" X-Original-To: linux-i2c@vger.kernel.org Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 484D25589C for ; Mon, 9 Sep 2024 15:39:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725896365; cv=none; b=i1TMaU1KzVL2F0iM+J2vC+3F5jjxmCYaXMsigQrHk9XgPOdMK+tUP7EHkyva6VPTih962s6YgLWkeihfa2LNraAUQKHILP8RqINcA/6EX1LNPTyYHCW/TG4VAQC8Fmg7nY5XyLWnU2kCRFblSH4ii5Ew7n9gVp4z+DMlCpWhSPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725896365; c=relaxed/simple; bh=3cxZUkMWB3bWChq69hrIXMPl+uSIw7UJ+pAYSdFQZ4I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ktCDeEOpcYfXJVSaYZ1C6p2g5TM/JzN59DQAkBoJqu0zlow/CbdA+46TQEC4D5PFGAzCC6Gdn8KSXuuwPv3KbkxYgtQSEHw4mlUK1VJgAUlmkDbTodFwgp68a3vXrpC/3TMVDU4SGP/ySPA7IjUm9vGEfAgC81o5Np27NlXiQek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=uEq1gNe3; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-371941bbfb0so2716549f8f.0 for ; Mon, 09 Sep 2024 08:39:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725896360; x=1726501160; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=VkiOCELnHFizmB6BxFn0pXWtV/LlXwXBPgn4A4PXdjU=; b=uEq1gNe3kSbm7U/rQwZuqzh+gU5jXLMxFEFTpQKi2hShVh8AIL2pOlXwvKSFp7HWew MyJ/YXRZXHtw1oPoU7GYNZG0jGYBf7ugcV1ed4xE7Gp18KjaV6rSo5zigNAxLYMl+T1O txJDDypEF2LXxyqJtZwx7AqNLD09OduUiu5MAlsBUr7IGPG//eaD9flFUUGQqQnqBe1o OhRag+5PJcNmo0qFDDs09hI89op+PvQUMt+CEctmHlAagAELR8vFAaob+MrmJO4e0PLv PzC4huz8Ko0nwaIpY38D4GWbB6CQNbttrBvMUEptjuZYA7HRM6FM+dgPPXsxK2WzEMme lskA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725896360; x=1726501160; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VkiOCELnHFizmB6BxFn0pXWtV/LlXwXBPgn4A4PXdjU=; b=u6SFaHl6MQ9jBjmBNRj3RerPcFfmym0a9FFNFbIlqCVVUww5HhCuMeWR1H7Qvaz98r shCNuZxS9W+x0t1KbC7yf5oWX1MT4PwirdbgLTN6o7r3QiLTPn5LgsQ9qCKO12VZcDGu ZOOaIeGtRJloW0ZEQosno8Rav6F1CKYppH+tSK5FHweNWuumimUkQjsW3UQONWG0uTJA VYr29PVRZqNYWckgVcKVngu37JYoVikR3AGhsubdsbh2L2pVmrquqoOKD1d/OoKw08mf VC7JsIwTGBMzuTdwN7QIQ6EwBUZoImk6WFuurspXLwBywyqiTy7CHQjO9LaUNsYbNg3x Eizg== X-Forwarded-Encrypted: i=1; AJvYcCVKmceR/VvkmzeEasMso7cDzgp0CR2J94dKgs8E/tExPO5wleySWeUFzBF+T6EL7jpRBX1bAmWl8h8=@vger.kernel.org X-Gm-Message-State: AOJu0YyZUhO9M56hutU68zMlOWHj4jD3O2qCSwknF2CJT3ZeWFzLXM41 ZKL1y91nF+6ZRZiBnnYYPtfPRh/QIPfGCETkGfsf+9oe0rZWQTHfOmBLaYrosbwVE1DSeb9Jhf+ t X-Google-Smtp-Source: AGHT+IFVbo8ijk5oT9KYsYnpWCU4bxAYBABqwUuRrMkySBYEGnpvzzRCmHlnNm1qY9hSLsU2quh1yw== X-Received: by 2002:a5d:4145:0:b0:376:27b7:da81 with SMTP id ffacd0b85a97d-3789268f0b1mr4879745f8f.22.1725896360103; Mon, 09 Sep 2024 08:39:20 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:788a:4542:ae86:67f4]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3789564af1asm6305145f8f.18.2024.09.09.08.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 08:39:19 -0700 (PDT) From: Jerome Brunet Date: Mon, 09 Sep 2024 17:39:05 +0200 Subject: [PATCH 3/3] hwmon: (pmbus/tps25990): add initial support Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240909-tps25990-v1-3-39b37e43e795@baylibre.com> References: <20240909-tps25990-v1-0-39b37e43e795@baylibre.com> In-Reply-To: <20240909-tps25990-v1-0-39b37e43e795@baylibre.com> To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jerome Brunet , Jonathan Corbet , Delphine CC Chiu Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-i2c@vger.kernel.org X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=18094; i=jbrunet@baylibre.com; h=from:subject:message-id; bh=3cxZUkMWB3bWChq69hrIXMPl+uSIw7UJ+pAYSdFQZ4I=; b=owEBbQKS/ZANAwAKAeb8Dxw38tqFAcsmYgBm3xajcVfsdJeOvsgNEqArovAPg4f8v/N/6AKWW BS8VGfc8yWJAjMEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZt8WowAKCRDm/A8cN/La hdijD/4paWJye299vD6SIKS0R8Dj39eW9h1CeQZPmV2NOWzKCVTjOaGZ672pAxinyXMwdY4Rday dMcsrqjrjYxXH46vB18tZkDyRJiR5saR3xs+CRfxg818ReedyoXaMJD4hLDl7uyiU4AABSrATKj +4hUX9Q4hgAyhLLZZA6mqYXrulox/shamITjF8fPqSgtG/R0NjQmtQVsjDx1kDKql5K/lnhkAfm Z1HmmJrXMOlJri0/6cU2i3afpHnylbom+7Sj8mUw6k10mOS4qz+sNFy/LOreFloja5eyYsTgdbg 5oOjA2a4HfyY9zHSu5r0YlnQf+jISNXjIWIhkNASPNjc18ile0u+IOmwQGRySaUF9CLqVgnjogz mOUMb++/n/CNRHou2DyOiP6ajZnWmFHnU6Oqt587AxdZiquqpa6PcEXWWXMl+KVcKqjT2vEB9UZ s0JNzGNIVk/gyvlx10qgSVWS54OcqjjvCXqnO+GyRYL2JOQxUeeywxKp9ffcweJUM/XIapqCjNy lPbOdCiDtsVzIyFmdgEmvBTFFLiPV4SrpAlM9x0G1IENhgOEVwbdKYMo5G5kiXHUwUu/TX3pt/R 9feCEVnxgkqaMphODgau1qTBdpc153G2rVqSnDPZfVw2JcT6JbIlWvvgGPAO/ufTmHc/Bb1qb3q 91ZP8xDu1Koh+Gg== X-Developer-Key: i=jbrunet@baylibre.com; a=openpgp; fpr=F29F26CF27BAE1A9719AE6BDC3C92AAF3E60AED9 Add initial support for the Texas Instruments TPS25990 eFuse. This adds the basic PMBUS telemetry support for the device. Signed-off-by: Jerome Brunet --- Documentation/hwmon/tps25990.rst | 141 ++++++++++++ drivers/hwmon/pmbus/Kconfig | 17 ++ drivers/hwmon/pmbus/Makefile | 1 + drivers/hwmon/pmbus/tps25990.c | 474 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 633 insertions(+) diff --git a/Documentation/hwmon/tps25990.rst b/Documentation/hwmon/tps25990.rst new file mode 100644 index 000000000000..7b3ef724008a --- /dev/null +++ b/Documentation/hwmon/tps25990.rst @@ -0,0 +1,141 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Kernel driver tps25990 +====================== + +Supported chips: + + * TI TPS25990 + + Prefix: 'tps25990' + + * Datasheet + + Publicly available at Texas Instruments website: https://www.ti.com/lit/gpn/tps25990 + +Author: + + Jerome Brunet + +Description +----------- + +This driver implements support for TI TPS25990 eFuse. +This is an integrated, high-current circuit protection and power +management device with PMBUS interface + +Device compliant with: + +- PMBus rev 1.3 interface. + +Device supports direct format for reading input voltages, +output voltage, input current, input power and temperature. + +The driver exports the following attributes via the 'sysfs' files +for input current: + +**curr1_average** + +**curr1_crit** + +**curr1_crit_alarm** + +**curr1_highest** + +**curr1_input** + +**curr1_label** + +**curr1_max** + +**curr1_max_alarm** + +The driver provides the following attributes for main input voltage: + +**in1_average** + +**in1_crit** + +**in1_crit_alarm** + +**in1_highest** + +**in1_input** + +**in1_label** + +**in1_lcrit** + +**in1_lcrit_alarm** + +**in1_lowest** + +**in1_max** + +**in1_max_alarm** + +**in1_min** + +**in1_min_alarm** + +The driver provides the following attributes for auxiliary input voltage: + +**in2_input** + +**in2_label** + +The driver provides the following attributes for output voltage: + +**in3_average** + +**in3_good_off** + +**in3_input** + +**in3_label** + +**in3_lowest** + +**in3_min** + +**in3_min_alarm** + +The driver provides the following attributes for input power: + +**power1_alarm** + +**power1_average** + +**power1_input** + +**power1_input_highest** + +**power1_label** + +**power1_max** + +The driver provides the following attributes for temperature: + +**temp1_average** + +**temp1_crit** + +**temp1_crit_alarm** + +**temp1_highest** + +**temp1_input** + +**temp1_max** + +**temp1_max_alarm** + +The driver provides the following attributes for history: + +**samples** + +**average_history_reset** + +**highest_history_reset** + +**lowest_history_reset** diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig index a4f02cad92fd..3559864e232d 100644 --- a/drivers/hwmon/pmbus/Kconfig +++ b/drivers/hwmon/pmbus/Kconfig @@ -510,6 +510,23 @@ config SENSORS_TDA38640_REGULATOR If you say yes here you get regulator support for Infineon TDA38640 as regulator. +config SENSORS_TPS25990 + tristate "TI TPS25990" + help + If you say yes here you get hardware monitoring support for TI + TPS25990. + + This driver can also be built as a module. If so, the module will + be called tps25990. + +config SENSORS_TPS25990_REGULATOR + bool "Regulator support for TPS25990 and compatibles" + depends on SENSORS_TPS25990 && REGULATOR + default SENSORS_TPS2599 + help + If you say yes here you get regulator support for Texas Instruments + TPS25990. + config SENSORS_TPS40422 tristate "TI TPS40422" help diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile index d00bcc758b97..3d3183f8d2a7 100644 --- a/drivers/hwmon/pmbus/Makefile +++ b/drivers/hwmon/pmbus/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_SENSORS_PXE1610) += pxe1610.o obj-$(CONFIG_SENSORS_Q54SJ108A2) += q54sj108a2.o obj-$(CONFIG_SENSORS_STPDDC60) += stpddc60.o obj-$(CONFIG_SENSORS_TDA38640) += tda38640.o +obj-$(CONFIG_SENSORS_TPS25990) += tps25990.o obj-$(CONFIG_SENSORS_TPS40422) += tps40422.o obj-$(CONFIG_SENSORS_TPS53679) += tps53679.o obj-$(CONFIG_SENSORS_TPS546D24) += tps546d24.o diff --git a/drivers/hwmon/pmbus/tps25990.c b/drivers/hwmon/pmbus/tps25990.c new file mode 100644 index 000000000000..14290c4c71dd --- /dev/null +++ b/drivers/hwmon/pmbus/tps25990.c @@ -0,0 +1,474 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (c) 2024 BayLibre, SAS. +// Author: Jerome Brunet + +#include +#include +#include +#include +#include +#include +#include + +#include "pmbus.h" + +#define TPS25990_READ_VAUX 0xd0 +#define TPS25990_READ_VIN_MIN 0xd1 +#define TPS25990_READ_VIN_PEAK 0xd2 +#define TPS25990_READ_IIN_PEAK 0xd4 +#define TPS25990_READ_PIN_PEAK 0xd5 +#define TPS25990_READ_TEMP_AVG 0xd6 +#define TPS25990_READ_TEMP_PEAK 0xd7 +#define TPS25990_READ_VOUT_MIN 0xda +#define TPS25990_READ_VIN_AVG 0xdc +#define TPS25990_READ_VOUT_AVG 0xdd +#define TPS25990_READ_IIN_AVG 0xde +#define TPS25990_READ_PIN_AVG 0xdf +#define TPS25990_VIREF 0xe0 +#define TPS25990_PK_MIN_AVG 0xea +#define PK_MIN_AVG_RST_PEAK BIT(7) +#define PK_MIN_AVG_RST_AVG BIT(6) +#define PK_MIN_AVG_RST_MIN BIT(5) +#define PK_MIN_AVG_AVG_CNT GENMASK(2, 0) +#define TPS25990_MFR_WRITE_PROTECT 0xf8 +#define TPS25990_UNLOCKED BIT(7) + +#define TPS25990_8B_SHIFT 2 +#define TPS25990_VIN_OVF_NUM 525100 +#define TPS25990_VIN_OVF_DIV 10163 +#define TPS25990_VIN_OVF_OFF 155 +#define TPS25990_IIN_OCF_NUM 953800 +#define TPS25990_IIN_OCF_DIV 129278 +#define TPS25990_IIN_OCF_OFF 157 + +#define TPS25990_DEFAULT_RIMON 910000 + +static int tps25990_mfr_write_protect(struct i2c_client *client, bool protect) +{ + return pmbus_write_byte_data(client, -1, TPS25990_MFR_WRITE_PROTECT, + protect ? 0x0 : 0xa2); +} + +static int tps25990_mfr_write_protect_active(struct i2c_client *client) +{ + int ret = pmbus_read_byte_data(client, -1, TPS25990_MFR_WRITE_PROTECT); + + if (ret < 0) + return ret; + + return !(ret & TPS25990_UNLOCKED); +} + +#if IS_ENABLED(CONFIG_DEBUG_FS) +static int tps25990_write_protect_get(void *data, u64 *val) +{ + struct i2c_client *client = data; + + return tps25990_mfr_write_protect_active(client); +} + +static int tps25990_write_protect_set(void *data, u64 val) +{ + struct i2c_client *client = data; + + if (val > 1) + return -EINVAL; + + return tps25990_mfr_write_protect(client, val); +} + +DEFINE_DEBUGFS_ATTRIBUTE(tps25990_write_protect_fops, + tps25990_write_protect_get, + tps25990_write_protect_set, + "%llu\n"); + +static int tps25990_init_debugfs(struct i2c_client *client) +{ + struct dentry *dir; + + dir = pmbus_get_debugfs_dir(client); + if (!dir) + return -ENOENT; + + debugfs_create_file("write_protect", 0644, dir, + client, &tps25990_write_protect_fops); + + return 0; +} + +#else +static inline int tps25990_init_debugfs(struct i2c_client *client) +{ + return 0; +} +#endif + +/* + * TPS25990 has history reset based on MIN/AVG/PEAK instead of per sensor type + * Emulate the behaviour a pmbus limit_attr would have for consistency + * - Read: Do nothing and emit 0 + * - Write: Check the input is a number and reset + */ +static ssize_t tps25990_history_reset_show(struct device *dev, + struct device_attribute *devattr, + char *buf) +{ + return sysfs_emit(buf, "0\n"); +} + +static ssize_t tps25990_history_reset_store(struct device *dev, + struct device_attribute *devattr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev->parent); + s64 val; + int ret; + + if (kstrtos64(buf, 10, &val) < 0) + return -EINVAL; + + ret = pmbus_update_byte_data(client, 0, TPS25990_PK_MIN_AVG, + BIT(attr->index), BIT(attr->index)); + if (ret < 0) + return ret; + + return count; +} + +static SENSOR_DEVICE_ATTR_RW(highest_history_reset, tps25990_history_reset, 7); +static SENSOR_DEVICE_ATTR_RW(average_history_reset, tps25990_history_reset, 6); +static SENSOR_DEVICE_ATTR_RW(lowest_history_reset, tps25990_history_reset, 5); + +static struct attribute *tps25990_attrs[] = { + &sensor_dev_attr_highest_history_reset.dev_attr.attr, + &sensor_dev_attr_average_history_reset.dev_attr.attr, + &sensor_dev_attr_lowest_history_reset.dev_attr.attr, + NULL, +}; + +ATTRIBUTE_GROUPS(tps25990); + +static int tps25990_get_addr(int reg) +{ + switch (reg) { + case PMBUS_SMBALERT_MASK: + /* + * Note: PMBUS_SMBALERT_MASK is not implemented on this chip + * Writing to this address raises CML errors. + * Instead it provides ALERT_MASK which allows to set the mask + * for each of the status registers, but not the specific bits + * in them. + * The default setup assert SMBA# if any bit is set in any of the + * status registers the chip has. This is as close as we can get + * to what pmbus_irq_setup() would set, sooo ... do nothing. + */ + return -ENXIO; + case PMBUS_IIN_OC_FAULT_LIMIT: + /* + * VIREF directly sets the over-current limit at which the eFuse + * will turn the FET off and trigger a fault. Expose it through + * this generic property instead of a manufacturer specific one. + */ + return TPS25990_VIREF; + case PMBUS_VIRT_READ_VIN_MAX: + return TPS25990_READ_VIN_PEAK; + case PMBUS_VIRT_READ_VIN_MIN: + return TPS25990_READ_VIN_MIN; + case PMBUS_VIRT_READ_VIN_AVG: + return TPS25990_READ_VIN_AVG; + case PMBUS_VIRT_READ_VOUT_MIN: + return TPS25990_READ_VOUT_MIN; + case PMBUS_VIRT_READ_VOUT_AVG: + return TPS25990_READ_VOUT_AVG; + case PMBUS_VIRT_READ_IIN_AVG: + return TPS25990_READ_IIN_AVG; + case PMBUS_VIRT_READ_IIN_MAX: + return TPS25990_READ_IIN_PEAK; + case PMBUS_VIRT_READ_TEMP_AVG: + return TPS25990_READ_TEMP_AVG; + case PMBUS_VIRT_READ_TEMP_MAX: + return TPS25990_READ_TEMP_PEAK; + case PMBUS_VIRT_READ_PIN_AVG: + return TPS25990_READ_PIN_AVG; + case PMBUS_VIRT_READ_PIN_MAX: + return TPS25990_READ_PIN_PEAK; + case PMBUS_VIRT_READ_VMON: + return TPS25990_READ_VAUX; + case PMBUS_VIRT_SAMPLES: + return TPS25990_PK_MIN_AVG; + } + + /* Let the register check do its job */ + if (reg < PMBUS_VIRT_BASE) + return reg; + + return -ENXIO; +} + +/* + * Some registers use a different scale than the one registered with + * pmbus_driver_info. An extra conversion step is necessary to adapt + * the register value to the conversion on the sensor type + */ +static int tps25990_read_adapt_value(int reg, int val) +{ + switch (reg) { + case PMBUS_VIN_UV_WARN_LIMIT: + case PMBUS_VIN_UV_FAULT_LIMIT: + case PMBUS_VIN_OV_WARN_LIMIT: + case PMBUS_VOUT_UV_WARN_LIMIT: + case PMBUS_IIN_OC_WARN_LIMIT: + case PMBUS_OT_WARN_LIMIT: + case PMBUS_OT_FAULT_LIMIT: + case PMBUS_PIN_OP_WARN_LIMIT: + case PMBUS_POWER_GOOD_OFF: + /* + * These registers provide an 8 bits value instead of a + * 10bits one. Just shifting twice the register value is + * enough to make the sensor type conversion work, even + * if the datasheet provides different m, b and R for + * those. + */ + val <<= TPS25990_8B_SHIFT; + break; + + case PMBUS_VIN_OV_FAULT_LIMIT: + val = DIV_ROUND_CLOSEST(val * TPS25990_VIN_OVF_NUM, TPS25990_VIN_OVF_DIV); + val += TPS25990_VIN_OVF_OFF; + break; + + case PMBUS_IIN_OC_FAULT_LIMIT: + val = DIV_ROUND_CLOSEST(val * TPS25990_IIN_OCF_NUM, TPS25990_IIN_OCF_DIV); + val += TPS25990_IIN_OCF_OFF; + break; + + case PMBUS_VIRT_SAMPLES: + val = 1 << val; + break; + } + + return val; +} + +static int tps25990_read_word(struct i2c_client *client, + int page, int phase, int reg) +{ + int ret, addr; + + addr = tps25990_get_addr(reg); + if (addr < 0) + return addr; + + switch (reg) { + case PMBUS_VIRT_SAMPLES: + ret = pmbus_read_byte_data(client, page, addr); + ret = FIELD_GET(PK_MIN_AVG_AVG_CNT, ret); + break; + + case PMBUS_IIN_OC_FAULT_LIMIT: + ret = pmbus_read_byte_data(client, page, addr); + break; + + default: + ret = pmbus_read_word_data(client, page, -1, addr); + break; + } + + if (ret >= 0) + ret = tps25990_read_adapt_value(reg, ret); + + return ret; +} + +static int tps25990_write_adapt_value(int reg, int val) +{ + switch (reg) { + case PMBUS_VIN_UV_WARN_LIMIT: + case PMBUS_VIN_UV_FAULT_LIMIT: + case PMBUS_VIN_OV_WARN_LIMIT: + case PMBUS_VOUT_UV_WARN_LIMIT: + case PMBUS_IIN_OC_WARN_LIMIT: + case PMBUS_OT_WARN_LIMIT: + case PMBUS_OT_FAULT_LIMIT: + case PMBUS_PIN_OP_WARN_LIMIT: + case PMBUS_POWER_GOOD_OFF: + val >>= TPS25990_8B_SHIFT; + val = clamp(val, 0, 0xff); + break; + + case PMBUS_VIN_OV_FAULT_LIMIT: + val -= TPS25990_VIN_OVF_OFF; + val = DIV_ROUND_CLOSEST(val * TPS25990_VIN_OVF_DIV, TPS25990_VIN_OVF_NUM); + val = clamp_val(val, 0, 0xf); + break; + + case PMBUS_IIN_OC_FAULT_LIMIT: + val -= TPS25990_IIN_OCF_OFF; + val = DIV_ROUND_CLOSEST(val * TPS25990_IIN_OCF_DIV, TPS25990_IIN_OCF_NUM); + val = clamp_val(val, 0, 0x3f); + break; + + case PMBUS_VIRT_SAMPLES: + val = clamp_val(val, 1, 1 << PK_MIN_AVG_AVG_CNT); + val = ilog2(val); + break; + } + + return val; +} + +static int tps25990_write_word(struct i2c_client *client, + int page, int reg, u16 value) +{ + int addr, ret; + + addr = tps25990_get_addr(reg); + if (addr < 0) + return addr; + + value = tps25990_write_adapt_value(reg, value); + + switch (reg) { + case PMBUS_VIRT_SAMPLES: + ret = pmbus_update_byte_data(client, page, addr, + PK_MIN_AVG_AVG_CNT, + FIELD_PREP(PK_MIN_AVG_AVG_CNT, value)); + break; + + case PMBUS_IIN_OC_FAULT_LIMIT: + ret = pmbus_write_byte_data(client, page, addr, + value); + break; + + default: + ret = pmbus_write_word_data(client, page, addr, value); + break; + } + + return ret; +} + +#if IS_ENABLED(CONFIG_SENSORS_TPS25990_REGULATOR) +static const struct regulator_desc tps25990_reg_desc[] = { + PMBUS_REGULATOR_ONE("vout"), +}; +#endif + +static const struct pmbus_driver_info tps25990_base_info = { + .pages = 1, + .format[PSC_VOLTAGE_IN] = direct, + .m[PSC_VOLTAGE_IN] = 5251, + .b[PSC_VOLTAGE_IN] = 0, + .R[PSC_VOLTAGE_IN] = -2, + .format[PSC_VOLTAGE_OUT] = direct, + .m[PSC_VOLTAGE_OUT] = 5251, + .b[PSC_VOLTAGE_OUT] = 0, + .R[PSC_VOLTAGE_OUT] = -2, + .format[PSC_TEMPERATURE] = direct, + .m[PSC_TEMPERATURE] = 140, + .b[PSC_TEMPERATURE] = 32100, + .R[PSC_TEMPERATURE] = -2, + /* + * Current and Power measurement depends on the ohm value + * of Rimon. m is multiplied by 1000 below to have an integer + * and -3 is added to R to compensate. + */ + .format[PSC_CURRENT_IN] = direct, + .m[PSC_CURRENT_IN] = 9538, + .b[PSC_CURRENT_IN] = 0, + .R[PSC_CURRENT_IN] = -6, + .format[PSC_POWER] = direct, + .m[PSC_POWER] = 4901, + .b[PSC_POWER] = 0, + .R[PSC_POWER] = -7, + .func[0] = (PMBUS_HAVE_VIN | + PMBUS_HAVE_VOUT | + PMBUS_HAVE_VMON | + PMBUS_HAVE_IIN | + PMBUS_HAVE_PIN | + PMBUS_HAVE_TEMP | + PMBUS_HAVE_STATUS_VOUT | + PMBUS_HAVE_STATUS_IOUT | + PMBUS_HAVE_STATUS_INPUT | + PMBUS_HAVE_STATUS_TEMP | + PMBUS_HAVE_SAMPLES), + .read_word_data = tps25990_read_word, + .write_word_data = tps25990_write_word, + .groups = tps25990_groups, + +#if IS_ENABLED(CONFIG_SENSORS_TPS25990_REGULATOR) + .reg_desc = tps25990_reg_desc, + .num_regulators = ARRAY_SIZE(tps25990_reg_desc), +#endif +}; + +static const struct i2c_device_id tps25990_i2c_id[] = { + { "tps25990" }, + {} +}; +MODULE_DEVICE_TABLE(i2c, tps25990_i2c_id); + +static const struct of_device_id tps25990_of_match[] = { + { .compatible = "ti,tps25990" }, + {} +}; +MODULE_DEVICE_TABLE(of, tps25990_of_match); + +static int tps25990_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct pmbus_driver_info *info; + u32 rimon = TPS25990_DEFAULT_RIMON; + int ret; + + ret = device_property_read_u32(dev, "ti,rimon-milli-ohms", &rimon); + if (ret == -EINVAL) { + dev_warn(dev, + "using default rimon: current and power scale possibly wrong\n"); + } else if (ret < 0) { + return dev_err_probe(dev, ret, "failed get rimon\n"); + } + + /* + * TPS25990 may be stacked with several TPS25895, allowing a higher + * current. The higher the allowed current is, the lower rimon + * will be. How low it can realistically get is unknown. + * To avoid problems with precision later on, rimon is provided in + * milli Ohms. This is a precaution to keep a stable ABI. + * At the moment, doing the calculation with rimon in milli Ohms + * would overflow the s32 'm' in the direct conversion. Convert it + * back to Ohms until greater precision is actually needed. + */ + rimon /= 1000; + + info = devm_kmemdup(dev, &tps25990_base_info, sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + /* Adapt the current and power scale for each instance */ + info->m[PSC_CURRENT_IN] *= rimon; + info->m[PSC_POWER] *= rimon; + + ret = pmbus_do_probe(client, info); + if (ret < 0) + return ret; + + return tps25990_init_debugfs(client); +} + +static struct i2c_driver tps25990_driver = { + .driver = { + .name = "tps25990", + .of_match_table = tps25990_of_match, + }, + .probe = tps25990_probe, + .id_table = tps25990_i2c_id, +}; +module_i2c_driver(tps25990_driver); + +MODULE_AUTHOR("Jerome Brunet "); +MODULE_DESCRIPTION("PMBUS driver for TPS25990 eFuse"); +MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS(PMBUS);