From patchwork Thu Nov 16 10:53:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Suligoi X-Patchwork-Id: 13457766 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=asem.it header.i=@asem.it header.b="UytH6+Zl" Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2078.outbound.protection.outlook.com [40.107.22.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0CF81B5; Thu, 16 Nov 2023 02:53:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i6dX/GRSQtb06Ykg8uhBHLel5PKR++fW3Q6V1QSEsHlRopSJFZdRuMFakR7CfAh9lL0cQ3dAkltfpvp5IgQcrXp94liJEMdmOEDuIe8kvQhZzXajaMm9/T9AXS9wmvl4NaAvuNh5/e+1AV6QG8NJZxrHgUsCF29N1vhaxMfNwLIFzSAbEJsiu4eeK2ippDm7e0a+FCkM0M0kEOyRoMRS1v5lmYkDjeXgLUtRMwkJa6YH1lRPPAAokc6EoYK5wISk9dysni0Ff7lYpFyI+xUvImzAlAOgOzWXZCzJHr/gTWDoH6a5g74uoV8FlxqoqkUdRtMO59685s6aK8XN/D4k7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XXGX5/3lV8ls++zZ8s81a873PdqAXsZCi8zrTLpHNn8=; b=UyYr4P/tFAxoRbp9CPUYO8K6JzTL+VSg7lEI04fUXBqGEdnUzBCPMpCeT4qXfi95OqzlSqqxMWsH88m8aqntTzGEgJR+D1Qh5PJE/VVf9f8ihMDTvlITa7yfvSIVP1lUCioiSss02YE7o0Twzo94M3HyC6nzDvPF5UBZ6uP+U5KXypuylc8ziMecJNOtbL2Ji3yPA+E4hYRM/FojaGztQ9M8jdYAYsQA1cCK1XF0UJN9IASzoTewsRHRNYd2KWAa5JAn7EnRgSV09TGjd+lc/feWqwzDA3LTibpsN93o+GiTRqP/Ci8MxeCnOuFjZAhPWuHIZlZdqSn1QSKMCMaTBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=softfail (sender ip is 151.1.184.193) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=asem.it; dmarc=fail (p=none sp=none pct=100) action=none header.from=asem.it; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asem.it; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XXGX5/3lV8ls++zZ8s81a873PdqAXsZCi8zrTLpHNn8=; b=UytH6+ZlMF3FwS2/ib7d5186NeA3iqiaSbzZln+4s3DMJSoYkbiTH8OgXikAG6iTrUV7fOJMWQwrGI912QtvVknWYF0B8OKYnPDlGPBmstiXM4V2b8nW/1QEYQeTC3qLCuQ31QnmwfHJa9Pl8oHgN7zZuNoO3Ef0fQNz+BbkFEA= Received: from AS4P189CA0030.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:5db::17) by VI1PR01MB6384.eurprd01.prod.exchangelabs.com (2603:10a6:800:15e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.18; Thu, 16 Nov 2023 10:53:29 +0000 Received: from AMS0EPF00000198.eurprd05.prod.outlook.com (2603:10a6:20b:5db:cafe::f3) by AS4P189CA0030.outlook.office365.com (2603:10a6:20b:5db::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.18 via Frontend Transport; Thu, 16 Nov 2023 10:53:29 +0000 X-MS-Exchange-Authentication-Results: spf=softfail (sender IP is 151.1.184.193) smtp.mailfrom=asem.it; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=asem.it; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning asem.it discourages use of 151.1.184.193 as permitted sender) Received: from asas054.asem.intra (151.1.184.193) by AMS0EPF00000198.mail.protection.outlook.com (10.167.16.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.19 via Frontend Transport; Thu, 16 Nov 2023 10:53:29 +0000 Received: from flavio-x.asem.intra ([172.16.18.47]) by asas054.asem.intra with Microsoft SMTPSVC(10.0.14393.4169); Thu, 16 Nov 2023 11:53:27 +0100 From: Flavio Suligoi To: Lee Jones , Daniel Thompson , Jingoo Han , Helge Deller , Pavel Machek , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: dri-devel@lists.freedesktop.org, linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, Flavio Suligoi , Conor Dooley Subject: [PATCH v7 1/2] dt-bindings: backlight: mp3309c: remove two required properties Date: Thu, 16 Nov 2023 11:53:18 +0100 Message-Id: <20231116105319.957600-2-f.suligoi@asem.it> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231116105319.957600-1-f.suligoi@asem.it> References: <20231116105319.957600-1-f.suligoi@asem.it> Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginalArrivalTime: 16 Nov 2023 10:53:27.0512 (UTC) FILETIME=[2108CD80:01DA187B] X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF00000198:EE_|VI1PR01MB6384:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ed9ce19-98ac-4ab8-91c0-08dbe692448a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hNEujeBblg5xvqNb8PW6EcI1AWyC5LMXig2cuiKnj5lx2fSyO7XDIFJJ0FVW4WVVqiDGpTV/57bEy7wLUIMdz+Q2ncwwxmtvzIvnyGJT1gDdSy2IsCm9CDlMsfgxkY75hy+PrVWUaxtTFynhos6+WtBENR4Oaon1vFfFZKvb81+nGb0NhhaQLdbfnTjbmjuUPzQlMgSRRBsLosBiWTRfSeuuauB9depm7/j0T9Z6vY6HfNzD4U94fodKgrK8HSCrC5wghgbeVcfmSUG8zZb41kqo2SVr9Ggyehh8UmGkA6VRLyGz0Mw8WzkdlNYCUT1NPENyTUulnGqTepNUWn++ZIN/cKA1jYQrOXQNWX5P1BQzvpRn9YVNbiH0gtT6K/7qH2BKEe6RgIW4nW5BaWLXz5ro9Sa7HWeImIDbuEDMb8eOmB2S/SiRu2LW1dYxcb/9XM+YndbvA3rDh1tRSYdxVKMpU/Tb6WyM66vvu3YhK81y5+6ztkAEnEzlRusf/9a4NCWl1Yutz6xuVTMgBfUFE9a/IfUb5XAEB5PFvBdjIqwxdxQUhiQ4f6l3S4JcNDyjueWmVBLbeJhz3BsQBZbnZY9x9LJDH9NgQTQrQt4eVD9qXtB4TKo2MDYRg83PExSVqmdX7XyRD73fuWiXKpye2QlrxF6FKvfBpiWuaRTzu3JGytxcRr0SXm2Y4AIqjaNQvwVhBu+TceSiexE5PsGtsK2s10YAT/3aZqgABTMaGrs= X-Forefront-Antispam-Report: CIP:151.1.184.193;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:asas054.asem.intra;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(136003)(396003)(376002)(39840400004)(346002)(230922051799003)(64100799003)(451199024)(1800799009)(82310400011)(186009)(36840700001)(46966006)(86362001)(70206006)(966005)(316002)(110136005)(54906003)(36756003)(70586007)(450100002)(8676002)(83380400001)(4326008)(8936002)(6666004)(336012)(2906002)(47076005)(26005)(1076003)(36860700001)(41300700001)(107886003)(2616005)(5660300002)(40480700001)(478600001)(356005)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: asem.it X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2023 10:53:29.0727 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ed9ce19-98ac-4ab8-91c0-08dbe692448a X-MS-Exchange-CrossTenant-Id: d0a766c6-7992-4344-a4a2-a467a7bb1ed2 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d0a766c6-7992-4344-a4a2-a467a7bb1ed2;Ip=[151.1.184.193];Helo=[asas054.asem.intra] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF00000198.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR01MB6384 The two properties: - max-brightness - default brightness are not really required, so they can be removed from the "required" section. The "max-brightness" is no longer used in the current version of the driver (it was used only in the first version). The "default-brightness", if omitted in the DT, is managed by the device driver, using a default value. This value depends on the dimming mode used: - for the "analog mode", via I2C commands, this value is fixed by hardware (=31) - while in case of pwm mode the default used is the last value of the brightness-levels array. Also the brightness-levels array is not required: - in "analog mode", via I2C commands, the brightness-level array is fixed by hardware (0..31).; - in pwm dimming mode, the driver uses a default array of 0..255 and the "default-brightness" is the last one, which is "255" NOTE: there are no compatibility problems with the previous version, since the device driver has not yet been included in any kernel. Only this dt-binding yaml file is already included in the current v6.7.0-rc1 kernel version. No developer may have used it. Other changes: - improve the backlight working mode description, in the "description" section - update the example, removing the "max-brightness" and introducing the "brightess-levels" property Signed-off-by: Flavio Suligoi Acked-by: Conor Dooley Reviewed-by: Daniel Thompson --- v7: - add missed patch history - add missed "Acked-by" added in one of the previous version v6: - check and resend for updated kernel 6.7.0-rc1 (nothing changed compared to the previous versions) - add this patch to the same patchset of the MP3309C device driver Note: the patch related to this file was previously a separate patch and sent in two versions (v1 and v2). It has now been included in this patchset, starting with the version v6. v5...v3: - non-existing versions (the last was v2, the next is v6) v2: - add more explanations in commit message, about the the non-existence of compatibility issues with the previous versions of the yaml file v1: - first version .../bindings/leds/backlight/mps,mp3309c.yaml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Documentation/devicetree/bindings/leds/backlight/mps,mp3309c.yaml b/Documentation/devicetree/bindings/leds/backlight/mps,mp3309c.yaml index 4191e33626f5..527a37368ed7 100644 --- a/Documentation/devicetree/bindings/leds/backlight/mps,mp3309c.yaml +++ b/Documentation/devicetree/bindings/leds/backlight/mps,mp3309c.yaml @@ -14,8 +14,8 @@ description: | programmable switching frequency to optimize efficiency. It supports two different dimming modes: - - analog mode, via I2C commands (default) - - PWM controlled mode. + - analog mode, via I2C commands, as default mode (32 dimming levels) + - PWM controlled mode (optional) The datasheet is available at: https://www.monolithicpower.com/en/mp3309c.html @@ -50,8 +50,6 @@ properties: required: - compatible - reg - - max-brightness - - default-brightness unevaluatedProperties: false @@ -66,8 +64,8 @@ examples: compatible = "mps,mp3309c"; reg = <0x17>; pwms = <&pwm1 0 3333333 0>; /* 300 Hz --> (1/f) * 1*10^9 */ - max-brightness = <100>; - default-brightness = <80>; + brightness-levels = <0 4 8 16 32 64 128 255>; + default-brightness = <6>; mps,overvoltage-protection-microvolt = <24000000>; }; }; From patchwork Thu Nov 16 10:53:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Suligoi X-Patchwork-Id: 13457767 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=asem.it header.i=@asem.it header.b="ctW3834m" Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2044.outbound.protection.outlook.com [40.107.6.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3008A1B9; Thu, 16 Nov 2023 02:53:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S8LnAHtqz5D4md4FzJeAmxM27ekzDPyFfOFLva2Y5JviR9Lv38M8BHQOeImztpQSDyOgtgbA6Ka2aeZqhBE5scLTYUVufdx+pRokMjIqAykNQdBJEgvWque1zmjmCTd14oU+OlD6NUl4ERl3NagFfmynHPy0dJmnIJyZP7lUvRzUe47tIa3ntDW8Gn/xnRv5NXxaurAdkn6c1FpoSkNxBjq20YHQNrsI9UufzPXSx2rDRJ2adlkCDz9cZ99TyoHmOJLYC37h/Xmeqp+KR479FRJN01w1nfo5JXDJ0qq89ebkQcKLZSnZridw0+RntD8eqhVCAPiK3YWMxHq/liIbMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ua/oqV5LCgOSfirxjjqLTqhFB905Hf/rwMjguAtE2wE=; b=gjzYHXPMmX6u+motQK2lMDw5GvdcLg4DD9n/qwMwPtWl0W2hfZ3bj9iEyNHk+ekaNguUbRM40WuxXdtIadjq85pFNVboSiqs6kJFb8+fdOy2BdpAOgHF4bKKbFTLSfJR0r0jpbH1yWugA+h5zzy9ITh8WxLGXmbMQ+N6k6UWYUvQ/LylamUkpBH9Nt2LsEQ5c6eYToO0TEDaFsLQ8frJBywc59r3fDZCS/2040Se6r5C7LbLsmno5SsgRmPyZAD5r2iY01wUr+PN1eNgYKij+cqvRpelf+fYa2DJ1KGrciQHO2vpFzbofgE2QDT6iU1asQOsR38MaQyshq5av2IRBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=softfail (sender ip is 151.1.184.193) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=asem.it; dmarc=fail (p=none sp=none pct=100) action=none header.from=asem.it; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asem.it; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ua/oqV5LCgOSfirxjjqLTqhFB905Hf/rwMjguAtE2wE=; b=ctW3834mgWtqG6FXL5/L4d7eXkpWXdUTZAqQMRdKVKIXEPQzs2YohD1woAhs5H4gVOJ0F9aLLT+NRrzjr2mEtOHreEib2IlKLbhHrRBI71fvUjjDJspPdQSfgA001P0L2ipaiD0cMiFubVu7lBA0iQRNnQfuiUH4E8QmLLWJssI= Received: from AS4P189CA0026.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:5db::13) by AS8PR01MB7382.eurprd01.prod.exchangelabs.com (2603:10a6:20b:254::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.20; Thu, 16 Nov 2023 10:53:30 +0000 Received: from AMS0EPF00000198.eurprd05.prod.outlook.com (2603:10a6:20b:5db:cafe::b7) by AS4P189CA0026.outlook.office365.com (2603:10a6:20b:5db::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.21 via Frontend Transport; Thu, 16 Nov 2023 10:53:29 +0000 X-MS-Exchange-Authentication-Results: spf=softfail (sender IP is 151.1.184.193) smtp.mailfrom=asem.it; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=asem.it; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning asem.it discourages use of 151.1.184.193 as permitted sender) Received: from asas054.asem.intra (151.1.184.193) by AMS0EPF00000198.mail.protection.outlook.com (10.167.16.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.19 via Frontend Transport; Thu, 16 Nov 2023 10:53:29 +0000 Received: from flavio-x.asem.intra ([172.16.18.47]) by asas054.asem.intra with Microsoft SMTPSVC(10.0.14393.4169); Thu, 16 Nov 2023 11:53:27 +0100 From: Flavio Suligoi To: Lee Jones , Daniel Thompson , Jingoo Han , Helge Deller , Pavel Machek , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: dri-devel@lists.freedesktop.org, linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, Flavio Suligoi Subject: [PATCH v7 2/2] backlight: mp3309c: Add support for MPS MP3309C Date: Thu, 16 Nov 2023 11:53:19 +0100 Message-Id: <20231116105319.957600-3-f.suligoi@asem.it> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231116105319.957600-1-f.suligoi@asem.it> References: <20231116105319.957600-1-f.suligoi@asem.it> Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginalArrivalTime: 16 Nov 2023 10:53:27.0606 (UTC) FILETIME=[21172560:01DA187B] X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF00000198:EE_|AS8PR01MB7382:EE_ X-MS-Office365-Filtering-Correlation-Id: 4576f98e-936e-4ca3-a030-08dbe69244fa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /17qNg7aqlCDVFWJE8xuNsfrOb4P3GPSRv6VLX93rQRfZYHwCIBjhMzmAMPrw9z0ZidbA43KpPqYtDXI1VuO+aL1oeayWRPWMQOtxniKny2ulec1ZH1d09L7/YcjVgk7B4/dgp+MRZ6Bb54RFJ3c3BWk/8WJQqWfnTj660WY3l0GTPjx9q+Fg4TjDvnHY9MK3xVVb+Lyu5pllCTeb7gz+pM04UcodVnhYBcyoi9jo4GBfMdvgzH2lSqIb1qy9szdg7PArYXCO5qPnHob1pYXb85gxUpU9fvZ5F05zwle4PUjDwcaKGuwY/2fS84m/l1/zpVAuzi+X5FLmOvxvqudT4bBZ2mW3LnbOQdVo6FDoHIWfX9ThMhc3z1RJNt8P/joVcVNuMJvGnCd80ksftTRJw1be89rRXOCXlVY4+owq3Wamjk2g/VjWUWE7Ukl+y0KDNyOxNIXFo1U2+sgl869OJc7mc/J+ls9/r/s4rSZ7bMXVj8EQKkv90N/hgym4sXxBRpYjeG8haVG7GqlChvnV3OBVjOkVEJWpkzVb4QUUZnwrCSjhWxkhlmLFIsuMCArElBfcK3kahUoEgY0qY5Mjan0syihnrOPbbjcoICZVVloQw98rzXQIl0Hxk+qs/LbcvNkLyfrh8ZZswZ1DmQKSKPzRSJ2q/tUeUQI3DK5aFndxYS6VDbfHGH1vMYzpp5dhe2dqSs82gBkc3Pokdx3PRcAjjkReJO9fsKinBd41aXUsycAnT+SbVJVO6Mrxf6KLlQK+tAnbrvYzGn5NMw+bQ== X-Forefront-Antispam-Report: CIP:151.1.184.193;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:asas054.asem.intra;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(376002)(396003)(346002)(136003)(39850400004)(230922051799003)(230173577357003)(230273577357003)(451199024)(64100799003)(1800799009)(186009)(82310400011)(36840700001)(46966006)(107886003)(1076003)(2616005)(336012)(26005)(6666004)(36860700001)(83380400001)(47076005)(4326008)(5660300002)(8676002)(30864003)(41300700001)(2906002)(966005)(478600001)(8936002)(316002)(450100002)(110136005)(70586007)(82740400003)(86362001)(70206006)(36756003)(81166007)(356005)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: asem.it X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2023 10:53:29.8071 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4576f98e-936e-4ca3-a030-08dbe69244fa X-MS-Exchange-CrossTenant-Id: d0a766c6-7992-4344-a4a2-a467a7bb1ed2 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d0a766c6-7992-4344-a4a2-a467a7bb1ed2;Ip=[151.1.184.193];Helo=[asas054.asem.intra] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF00000198.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR01MB7382 The Monolithic Power (MPS) MP3309C is a WLED step-up converter, featuring a programmable switching frequency to optimize efficiency. The brightness can be controlled either by I2C commands (called "analog" mode) or by a PWM input signal (PWM mode). This driver supports both modes. For DT configuration details, please refer to: - Documentation/devicetree/bindings/leds/backlight/mps,mp3309c.yaml The datasheet is available at: - https://www.monolithicpower.com/en/mp3309c.html Signed-off-by: Flavio Suligoi Reviewed-by: Daniel Thompson --- v7: - add missed patch history - add missed "Reviewed-by" added in one of the previous version v6: - check and resend for updated kernel 6.7.0-rc1 v5: - check and resend for updated kernel 6.6.0-rc1 v4: - add brightness-levels property - force fixed 32 brightness levels (0..31) in analog-i2c dimming mode - remove useless irq and reset_gpio from mp3309c_chip structure v3: - fix SPDX obsolete spelling - in mp3309c_bl_update_status, change from msleep_interruptible() to msleep() and improve the related comment v2: - fix dependecies in Kconfig - fix Kconfig MP3309C entry order - remove switch-on-delay-ms property - remove optional gpio property to reset external devices - remove dimming-mode property (the analog-i2c dimming mode is the default; the presence of the pwms property, in DT, selects automatically the pwm dimming mode) - substitute three boolean properties, used for the overvoltage-protection values, with a single enum property - drop simple tracing messages - use dev_err_probe() in probe function - change device name from mp3309c_bl to the simple mp3309c - remove shutdown function v1: - first version MAINTAINERS | 7 + drivers/video/backlight/Kconfig | 11 + drivers/video/backlight/Makefile | 1 + drivers/video/backlight/mp3309c.c | 443 ++++++++++++++++++++++++++++++ 4 files changed, 462 insertions(+) create mode 100644 drivers/video/backlight/mp3309c.c diff --git a/MAINTAINERS b/MAINTAINERS index 5c9f868e13b6..d033c2a2d120 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14657,6 +14657,13 @@ S: Maintained F: Documentation/driver-api/tty/moxa-smartio.rst F: drivers/tty/mxser.* +MP3309C BACKLIGHT DRIVER +M: Flavio Suligoi +L: dri-devel@lists.freedesktop.org +S: Maintained +F: Documentation/devicetree/bindings/leds/backlight/mps,mp3309c.yaml +F: drivers/video/backlight/mp3309c.c + MR800 AVERMEDIA USB FM RADIO DRIVER M: Alexey Klimov L: linux-media@vger.kernel.org diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig index 51387b1ef012..1144a54a35c0 100644 --- a/drivers/video/backlight/Kconfig +++ b/drivers/video/backlight/Kconfig @@ -402,6 +402,17 @@ config BACKLIGHT_LP8788 help This supports TI LP8788 backlight driver. +config BACKLIGHT_MP3309C + tristate "Backlight Driver for MPS MP3309C" + depends on I2C && PWM + select REGMAP_I2C + help + This supports MPS MP3309C backlight WLED driver in both PWM and + analog/I2C dimming modes. + + To compile this driver as a module, choose M here: the module will + be called mp3309c. + config BACKLIGHT_PANDORA tristate "Backlight driver for Pandora console" depends on TWL4030_CORE diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile index f72e1c3c59e9..1af583de665b 100644 --- a/drivers/video/backlight/Makefile +++ b/drivers/video/backlight/Makefile @@ -44,6 +44,7 @@ obj-$(CONFIG_BACKLIGHT_LP855X) += lp855x_bl.o obj-$(CONFIG_BACKLIGHT_LP8788) += lp8788_bl.o obj-$(CONFIG_BACKLIGHT_LV5207LP) += lv5207lp.o obj-$(CONFIG_BACKLIGHT_MAX8925) += max8925_bl.o +obj-$(CONFIG_BACKLIGHT_MP3309C) += mp3309c.o obj-$(CONFIG_BACKLIGHT_MT6370) += mt6370-backlight.o obj-$(CONFIG_BACKLIGHT_OMAP1) += omap1_bl.o obj-$(CONFIG_BACKLIGHT_PANDORA) += pandora_bl.o diff --git a/drivers/video/backlight/mp3309c.c b/drivers/video/backlight/mp3309c.c new file mode 100644 index 000000000000..3fe4469ef43f --- /dev/null +++ b/drivers/video/backlight/mp3309c.c @@ -0,0 +1,443 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Driver for MPS MP3309C White LED driver with I2C interface + * + * This driver support both analog (by I2C commands) and PWM dimming control + * modes. + * + * Copyright (C) 2023 ASEM Srl + * Author: Flavio Suligoi + * + * Based on pwm_bl.c + */ + +#include +#include +#include +#include +#include +#include + +#define REG_I2C_0 0x00 +#define REG_I2C_1 0x01 + +#define REG_I2C_0_EN 0x80 +#define REG_I2C_0_D0 0x40 +#define REG_I2C_0_D1 0x20 +#define REG_I2C_0_D2 0x10 +#define REG_I2C_0_D3 0x08 +#define REG_I2C_0_D4 0x04 +#define REG_I2C_0_RSRV1 0x02 +#define REG_I2C_0_RSRV2 0x01 + +#define REG_I2C_1_RSRV1 0x80 +#define REG_I2C_1_DIMS 0x40 +#define REG_I2C_1_SYNC 0x20 +#define REG_I2C_1_OVP0 0x10 +#define REG_I2C_1_OVP1 0x08 +#define REG_I2C_1_VOS 0x04 +#define REG_I2C_1_LEDO 0x02 +#define REG_I2C_1_OTP 0x01 + +#define ANALOG_I2C_NUM_LEVELS 32 /* 0..31 */ +#define ANALOG_I2C_REG_MASK 0x7c + +#define MP3309C_PWM_DEFAULT_NUM_LEVELS 256 /* 0..255 */ + +enum mp3309c_status_value { + FIRST_POWER_ON, + BACKLIGHT_OFF, + BACKLIGHT_ON, +}; + +enum mp3309c_dimming_mode_value { + DIMMING_PWM, + DIMMING_ANALOG_I2C, +}; + +struct mp3309c_platform_data { + unsigned int max_brightness; + unsigned int default_brightness; + unsigned int *levels; + u8 dimming_mode; + u8 over_voltage_protection; + bool sync_mode; + u8 status; +}; + +struct mp3309c_chip { + struct device *dev; + struct mp3309c_platform_data *pdata; + struct backlight_device *bl; + struct gpio_desc *enable_gpio; + struct regmap *regmap; + struct pwm_device *pwmd; +}; + +static const struct regmap_config mp3309c_regmap = { + .name = "mp3309c_regmap", + .reg_bits = 8, + .reg_stride = 1, + .val_bits = 8, + .max_register = REG_I2C_1, +}; + +static int mp3309c_enable_device(struct mp3309c_chip *chip) +{ + u8 reg_val; + int ret; + + /* I2C register #0 - Device enable */ + ret = regmap_update_bits(chip->regmap, REG_I2C_0, REG_I2C_0_EN, + REG_I2C_0_EN); + if (ret) + return ret; + + /* + * I2C register #1 - Set working mode: + * - set one of the two dimming mode: + * - PWM dimming using an external PWM dimming signal + * - analog dimming using I2C commands + * - enable/disable synchronous mode + * - set overvoltage protection (OVP) + */ + reg_val = 0x00; + if (chip->pdata->dimming_mode == DIMMING_PWM) + reg_val |= REG_I2C_1_DIMS; + if (chip->pdata->sync_mode) + reg_val |= REG_I2C_1_SYNC; + reg_val |= chip->pdata->over_voltage_protection; + ret = regmap_write(chip->regmap, REG_I2C_1, reg_val); + if (ret) + return ret; + + return 0; +} + +static int mp3309c_bl_update_status(struct backlight_device *bl) +{ + struct mp3309c_chip *chip = bl_get_data(bl); + int brightness = backlight_get_brightness(bl); + struct pwm_state pwmstate; + unsigned int analog_val, bits_val; + int i, ret; + + if (chip->pdata->dimming_mode == DIMMING_PWM) { + /* + * PWM control mode + */ + pwm_get_state(chip->pwmd, &pwmstate); + pwm_set_relative_duty_cycle(&pwmstate, + chip->pdata->levels[brightness], + chip->pdata->levels[chip->pdata->max_brightness]); + pwmstate.enabled = true; + ret = pwm_apply_state(chip->pwmd, &pwmstate); + if (ret) + return ret; + + switch (chip->pdata->status) { + case FIRST_POWER_ON: + case BACKLIGHT_OFF: + /* + * After 20ms of low pwm signal level, the chip turns + * off automatically. In this case, before enabling the + * chip again, we must wait about 10ms for pwm signal to + * stabilize. + */ + if (brightness > 0) { + msleep(10); + mp3309c_enable_device(chip); + chip->pdata->status = BACKLIGHT_ON; + } else { + chip->pdata->status = BACKLIGHT_OFF; + } + break; + case BACKLIGHT_ON: + if (brightness == 0) + chip->pdata->status = BACKLIGHT_OFF; + break; + } + } else { + /* + * Analog (by I2C command) control mode + * + * The first time, before setting brightness, we must enable the + * device + */ + if (chip->pdata->status == FIRST_POWER_ON) + mp3309c_enable_device(chip); + + /* + * Dimming mode I2C command (fixed dimming range 0..31) + * + * The 5 bits of the dimming analog value D4..D0 is allocated + * in the I2C register #0, in the following way: + * + * +--+--+--+--+--+--+--+--+ + * |EN|D0|D1|D2|D3|D4|XX|XX| + * +--+--+--+--+--+--+--+--+ + */ + analog_val = brightness; + bits_val = 0; + for (i = 0; i <= 5; i++) + bits_val += ((analog_val >> i) & 0x01) << (6 - i); + ret = regmap_update_bits(chip->regmap, REG_I2C_0, + ANALOG_I2C_REG_MASK, bits_val); + if (ret) + return ret; + + if (brightness > 0) + chip->pdata->status = BACKLIGHT_ON; + else + chip->pdata->status = BACKLIGHT_OFF; + } + + return 0; +} + +static const struct backlight_ops mp3309c_bl_ops = { + .update_status = mp3309c_bl_update_status, +}; + +static int pm3309c_parse_dt_node(struct mp3309c_chip *chip, + struct mp3309c_platform_data *pdata) +{ + struct device_node *node = chip->dev->of_node; + struct property *prop_pwms, *prop_levels; + int length = 0; + int ret, i; + unsigned int num_levels, tmp_value; + + if (!node) { + dev_err(chip->dev, "failed to get DT node\n"); + return -ENODEV; + } + + /* + * Dimming mode: the MP3309C provides two dimming control mode: + * + * - PWM mode + * - Analog by I2C control mode (default) + * + * I2C control mode is assumed as default but, if the pwms property is + * found in the backlight node, the mode switches to PWM mode. + */ + pdata->dimming_mode = DIMMING_ANALOG_I2C; + prop_pwms = of_find_property(node, "pwms", &length); + if (prop_pwms) { + chip->pwmd = devm_pwm_get(chip->dev, NULL); + if (IS_ERR(chip->pwmd)) + return dev_err_probe(chip->dev, PTR_ERR(chip->pwmd), + "error getting pwm data\n"); + pdata->dimming_mode = DIMMING_PWM; + pwm_apply_args(chip->pwmd); + } + + /* + * In I2C control mode the dimming levels (0..31) are fixed by the + * hardware, while in PWM control mode they can be chosen by the user, + * to allow nonlinear mappings. + */ + if (pdata->dimming_mode == DIMMING_ANALOG_I2C) { + /* + * Analog (by I2C commands) control mode: fixed 0..31 brightness + * levels + */ + num_levels = ANALOG_I2C_NUM_LEVELS; + + /* Enable GPIO used in I2C dimming mode only */ + chip->enable_gpio = devm_gpiod_get(chip->dev, "enable", + GPIOD_OUT_HIGH); + if (IS_ERR(chip->enable_gpio)) + return dev_err_probe(chip->dev, + PTR_ERR(chip->enable_gpio), + "error getting enable gpio\n"); + } else { + /* + * PWM control mode: check for brightness level in DT + */ + prop_levels = of_find_property(node, "brightness-levels", + &length); + if (prop_levels) { + /* Read brightness levels from DT */ + num_levels = length / sizeof(u32); + if (num_levels < 2) + return -EINVAL; + } else { + /* Use default brightness levels */ + num_levels = MP3309C_PWM_DEFAULT_NUM_LEVELS; + } + } + + /* Fill brightness levels array */ + pdata->levels = devm_kcalloc(chip->dev, num_levels, + sizeof(*pdata->levels), GFP_KERNEL); + if (!pdata->levels) + return -ENOMEM; + if (prop_levels) { + ret = of_property_read_u32_array(node, "brightness-levels", + pdata->levels, + num_levels); + if (ret < 0) + return ret; + } else { + for (i = 0; i < num_levels; i++) + pdata->levels[i] = i; + } + + pdata->max_brightness = num_levels - 1; + + ret = of_property_read_u32(node, "default-brightness", + &pdata->default_brightness); + if (ret) + pdata->default_brightness = pdata->max_brightness; + if (pdata->default_brightness > pdata->max_brightness) { + dev_err(chip->dev, + "default brightness exceeds max brightness\n"); + pdata->default_brightness = pdata->max_brightness; + } + + /* + * Over-voltage protection (OVP) + * + * This (optional) property values are: + * + * - 13.5V + * - 24V + * - 35.5V (hardware default setting) + * + * If missing, the default value for OVP is 35.5V + */ + pdata->over_voltage_protection = REG_I2C_1_OVP1; + if (!of_property_read_u32(node, "mps,overvoltage-protection-microvolt", + &tmp_value)) { + switch (tmp_value) { + case 13500000: + pdata->over_voltage_protection = 0x00; + break; + case 24000000: + pdata->over_voltage_protection = REG_I2C_1_OVP0; + break; + case 35500000: + pdata->over_voltage_protection = REG_I2C_1_OVP1; + break; + default: + return -EINVAL; + } + } + + /* Synchronous (default) and non-synchronous mode */ + pdata->sync_mode = true; + if (of_property_read_bool(node, "mps,no-sync-mode")) + pdata->sync_mode = false; + + return 0; +} + +static int mp3309c_probe(struct i2c_client *client) +{ + struct mp3309c_platform_data *pdata = dev_get_platdata(&client->dev); + struct mp3309c_chip *chip; + struct backlight_properties props; + struct pwm_state pwmstate; + int ret; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + dev_err(&client->dev, "failed to check i2c functionality\n"); + return -EOPNOTSUPP; + } + + chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + chip->dev = &client->dev; + + chip->regmap = devm_regmap_init_i2c(client, &mp3309c_regmap); + if (IS_ERR(chip->regmap)) + return dev_err_probe(&client->dev, PTR_ERR(chip->regmap), + "failed to allocate register map\n"); + + i2c_set_clientdata(client, chip); + + if (!pdata) { + pdata = devm_kzalloc(chip->dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + ret = pm3309c_parse_dt_node(chip, pdata); + if (ret) + return ret; + } + chip->pdata = pdata; + + /* Backlight properties */ + props.brightness = pdata->default_brightness; + props.max_brightness = pdata->max_brightness; + props.scale = BACKLIGHT_SCALE_LINEAR; + props.type = BACKLIGHT_RAW; + props.power = FB_BLANK_UNBLANK; + props.fb_blank = FB_BLANK_UNBLANK; + chip->bl = devm_backlight_device_register(chip->dev, "mp3309c", + chip->dev, chip, + &mp3309c_bl_ops, &props); + if (IS_ERR(chip->bl)) + return dev_err_probe(chip->dev, PTR_ERR(chip->bl), + "error registering backlight device\n"); + + /* In PWM dimming mode, enable pwm device */ + if (chip->pdata->dimming_mode == DIMMING_PWM) { + pwm_init_state(chip->pwmd, &pwmstate); + pwm_set_relative_duty_cycle(&pwmstate, + chip->pdata->default_brightness, + chip->pdata->max_brightness); + pwmstate.enabled = true; + ret = pwm_apply_state(chip->pwmd, &pwmstate); + if (ret) + return dev_err_probe(chip->dev, ret, + "error setting pwm device\n"); + } + + chip->pdata->status = FIRST_POWER_ON; + backlight_update_status(chip->bl); + + return 0; +} + +static void mp3309c_remove(struct i2c_client *client) +{ + struct mp3309c_chip *chip = i2c_get_clientdata(client); + struct backlight_device *bl = chip->bl; + + bl->props.power = FB_BLANK_POWERDOWN; + bl->props.brightness = 0; + backlight_update_status(chip->bl); +} + +static const struct of_device_id mp3309c_match_table[] = { + { .compatible = "mps,mp3309c", }, + { }, +}; +MODULE_DEVICE_TABLE(of, mp3309c_match_table); + +static const struct i2c_device_id mp3309c_id[] = { + { "mp3309c", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, mp3309c_id); + +static struct i2c_driver mp3309c_i2c_driver = { + .driver = { + .name = KBUILD_MODNAME, + .of_match_table = mp3309c_match_table, + }, + .probe = mp3309c_probe, + .remove = mp3309c_remove, + .id_table = mp3309c_id, +}; + +module_i2c_driver(mp3309c_i2c_driver); + +MODULE_DESCRIPTION("Backlight Driver for MPS MP3309C"); +MODULE_AUTHOR("Flavio Suligoi "); +MODULE_LICENSE("GPL");