From patchwork Wed Mar 8 09:52:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Svyatoslav Ryhel X-Patchwork-Id: 66134 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp243659wrd; Wed, 8 Mar 2023 02:11:05 -0800 (PST) X-Google-Smtp-Source: AK7set85SPrtz7kGevvjjf56iq6yVlUdZJp6710gPGIs6aTj8xUdCCqaD9fj2d1VqTrS/+jKPL0u X-Received: by 2002:a05:6a20:394c:b0:d0:61ff:8535 with SMTP id r12-20020a056a20394c00b000d061ff8535mr4076568pzg.4.1678270265536; Wed, 08 Mar 2023 02:11:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678270265; cv=none; d=google.com; s=arc-20160816; b=APUbEoFtFYhac3tbITk59xAFZiQrpZqPiRlhK5/i4or9+OT7SKetl5QV3bdYtoW/r6 k2yF6wfScEKTIFq6kigl9Q5yp772ev1w2z4o+7i5uSGZF4e0ECW/f9VNc2NCuV1sDHyu +7FhQR+MZm6OvoMpVhQgDcsv+7I3xzk8vRKR0+hFEfEa62IwGh7bX3oQavBU/yWBK6G7 8s38lH3t+R1Rs5tcei/uJXcDOCBmG+T6rJqeSRJDDslb2TajK1S/78HG2E0tzPbQtlGw +j5UENnl0MgtSmFG9SndjsgD+ZRecq7cxmPtls9QQoTsFSilgL3WQnib/MDS9HBS+j50 gbrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HvxrCA9BaAG+0IE8vbijjkrf+m1rC4XBRDE72BFYjMw=; b=UnB4Y2AYqtwVbce/F6JpLFXuD8PzM8wVzzYUGqBIW1AA289VY+N0YCoOb1qGrHaJcC O5GY/FVcucE5xUYlz5OqEGmsXvc4LU4TWq5Sixar3u0YHjWxGG2jIz2mWlP4kc4jKoWO SGab3A5GVGTcN1sEKyg6YCN3qisOXcGiZKAoEj1sO8mcT79QGvfR0bey+EHy6MR9pDxY IWisKolo6nQczHq+tQGQUqtUzG1c1/4Q7Wc/mlWux8JB4NcGtSxmrelaE4j+pXjXPk+j MEjLXG0hItFrJJrwvhnuInUkpn1oLZwt2ck6wPM1gxLubrxaY19ccmOchvlpHPqdy93u LDwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lWNkP1oo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a635709000000b00502f89f0d8dsi14750936pgb.167.2023.03.08.02.10.40; Wed, 08 Mar 2023 02:11:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lWNkP1oo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229923AbjCHJwZ (ORCPT + 99 others); Wed, 8 Mar 2023 04:52:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229549AbjCHJwV (ORCPT ); Wed, 8 Mar 2023 04:52:21 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63F7B9887E; Wed, 8 Mar 2023 01:52:20 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id a25so63523243edb.0; Wed, 08 Mar 2023 01:52:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678269139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HvxrCA9BaAG+0IE8vbijjkrf+m1rC4XBRDE72BFYjMw=; b=lWNkP1ooMPRZoylzLyqFWN3EMdv5XrHCnzoG0T39cM0EOVRFq9/TBoyEagUX4HvTfx 3WQ8Himlp0WLq4cGuJboNk5OyzuevKoDSzDG1Jkbt5bZ2fR1YVTUvvJ7s33eSsIADtW4 iYHUYU9PAgWjjV+qfDbNyAAjfKGmZTYUPJIlzSX75b/xqBa53fGneLmudo+CwWGXfyL7 AVZDeHn1FJA4AjA9wEM6mrSrJZDpM36x1IvkMALOPopK/Guf8ieTV//Z9OMGGPAiz0iL C7NNFU8LC8d7Q8e/v1oEEb+KNK3MijqYlfKIW23m9bwbA8kuN6uHP8GZ/PEHdeziOocO H+tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678269139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HvxrCA9BaAG+0IE8vbijjkrf+m1rC4XBRDE72BFYjMw=; b=WMDQnBYfCd3wo4zJIK2ZUbMKLtCqmMb/opCeM5pLHprEuf0YGGyvmJNIuPwcYJegFm sv+BpThZm0iYsdA6ztjuz5Qkpi8ruQs5roMTo1jWGPEvGLcSPwrx5o5u4uLZEizaZ2eK mRcHp/iAXNYnFURr4icFEUbK8QXahqPnFpjnPAEZjNpXMiHPiPA7KEdRc2HuhYYVVhSx Y8Qax74P2+pYEZUnmXlZH3DfZ4+uPa3cLnqBlKYWzO76OOzqWORFNWUhzxujUhUZe00U dzgNCwHuftAPfbrv8EOmyrzylUj9/BN3kkYAoHLtNox7894LmM2FjaWRz8LcNP4fj9yK /aog== X-Gm-Message-State: AO0yUKUSoWG4k3QZLZtjLm/TK77lXPH6irxWwyquq9T81C4LopgWEKck O+PzJMa1JRE/pLGnDLpXGyM= X-Received: by 2002:a17:907:6e15:b0:8b1:75a0:e5c6 with SMTP id sd21-20020a1709076e1500b008b175a0e5c6mr23039270ejc.18.1678269138924; Wed, 08 Mar 2023 01:52:18 -0800 (PST) Received: from xeon.. ([188.163.112.76]) by smtp.gmail.com with ESMTPSA id s15-20020a170906454f00b008d8f1b238fdsm7369177ejq.149.2023.03.08.01.52.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Mar 2023 01:52:18 -0800 (PST) From: Svyatoslav Ryhel To: Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Svyatoslav Ryhel , Hans Verkuil , Luca Ceresoli , Jean Delvare , Sebastian Reichel , Daniel Jeong , Ldd-Mlp Cc: linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/2] dt-bindings: media: i2c: add lm3560 binding Date: Wed, 8 Mar 2023 11:52:08 +0200 Message-Id: <20230308095209.14700-2-clamor95@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230308095209.14700-1-clamor95@gmail.com> References: <20230308095209.14700-1-clamor95@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759793922189678882?= X-GMAIL-MSGID: =?utf-8?q?1759793922189678882?= Signed-off-by: Svyatoslav Ryhel --- .../bindings/media/i2c/ti,lm3560.yaml | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/ti,lm3560.yaml diff --git a/Documentation/devicetree/bindings/media/i2c/ti,lm3560.yaml b/Documentation/devicetree/bindings/media/i2c/ti,lm3560.yaml new file mode 100644 index 000000000000..b3c2ccb83a30 --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/ti,lm3560.yaml @@ -0,0 +1,130 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/ti,lm3560.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: TI LM3560 Synchronous Boost Flash Driver + +maintainers: + - Daniel Jeong + - Ldd-Mlp + +description: | + The LM3560 is a 2-MHz fixed frequency synchronous boost + converter with two 1000-mA constant current drivers for + high-current white LEDs. The dual highside current sources + allow for grounded cathode LED operation and can be tied + together for providing flash currents at up to 2 A through + a single LED. An adaptive regulation method ensures the + current for each LED remains in regulation and maximizes + efficiency. + +properties: + compatible: + items: + - enum: + - ti,lm3559 + - ti,lm3560 + + reg: + maxItems: 1 + + enable-gpios: + maxItems: 1 + + ti,peak-current: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 0x20, 0x40, 0x60] + default: 0x60 + description: | + Peak current can be set to 4 values 1.6A (0x00), + 2.3A (0x20), 3.0A (0x40) and 3.6A (0x60). + + ti,max-flash-timeout: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 32 + maximum: 1024 + default: 1024 + description: | + Maximum flash timeout in ms with step 32ms. + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +required: + - compatible + - reg + - '#address-cells' + - '#size-cells' + +patternProperties: + "^led@[01]$": + type: object + description: | + Properties for a connected LEDs. + properties: + reg: + minimum: 0 + maximum: 1 + + ti,max-flash-current: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 62500 + maximum: 1000000 + default: 1000000 + description: | + Maximum current in flash mode in uA with step 62500uA. + + ti,max-torch-current: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 31250 + maximum: 250000 + default: 250000 + description: | + Maximum current in tourch mode in uA with step 31250uA. + + required: + - reg + + additionalProperties: false + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + flash-led@53 { + compatible = "ti,lm3559"; + reg = <0x53>; + + enable-gpios = <&gpio 219 GPIO_ACTIVE_HIGH>; + + ti,peak-current = <0>; + ti,max-flash-timeout = <1024>; + + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + + ti,max-flash-current = <562500>; + ti,max-torch-current = <156250>; + }; + + led@1 { + reg = <1>; + + ti,max-flash-current = <562500>; + ti,max-torch-current = <156250>; + }; + }; + }; +... From patchwork Wed Mar 8 09:52:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Svyatoslav Ryhel X-Patchwork-Id: 66135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp247531wrd; Wed, 8 Mar 2023 02:20:59 -0800 (PST) X-Google-Smtp-Source: AK7set+dwTAHorIyOL756b4CUjtfWB+NC1NG3uAOtWecmhNMMCw/d7A36W2Fxf7i0cTx59OGUHC5 X-Received: by 2002:a62:cf81:0:b0:5dd:3f84:8c15 with SMTP id b123-20020a62cf81000000b005dd3f848c15mr14718697pfg.24.1678270858780; Wed, 08 Mar 2023 02:20:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678270858; cv=none; d=google.com; s=arc-20160816; b=RdUGObrqgpwcNNH/3o436lSti08J8ruivVkdTtSnLzs5YV/hDeOC6dVn9/DwrDxQzi a7zfR38X0+a/g6v2x2vSIcn6rgZKaafBDVBDZhWCcM4mCm1j3M6ZsIhLKBIF57Qk377x GmS1P75ItghGU4i8hWB+UEX9+VAEnaCrj+OSrehhX/Thu+ZGMnaSmkvQy/RdBQmRjHKi BplSxzKzg48xvPoID5TqFGme7brmWDvZzLYQxApPiNPGI53uicbOQQ1CbhgJA4ihZL0Q GK3pFIah/TZbIVanXCH17WnyubzOygVz2u8LOa/jNvZFiyxXBgEmbsY85JGuwEtFE3yP ZhyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sXCB+oYW4zw2V6U49JxzpNXli13gSy/i91Jkb3XU6Fk=; b=w+aldOO2NrnkA5FSIfISdk/umK0iQz41bvS+aQ05t8PGJDJN1KBfKm/drnIgfSL75B 6UyceX1L5d+mevvOAdyp3/y8wSoODwRN2ChcBiqeSyp0iRJMfG/Ltld6NpLEM6UwY9OI xqbW9lkU88PB+drxmzitRXlgQmpjrCZL1PQyfCg5lO8jHGHIVynalJkMQx5Sk5aploB4 IXi6BKg+E5MfdNn3GEqRbIPREy/vgPHGx2aaDRGEFw5nKyhEa5YvG6/pRuq6tuMa36xO /E/39fp6kCAgBdTdhMKo1RUk3fX45c325U3MebEB/TuC236Xdmf6XuGoxQYdzCq68G5a 08Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EiJrP86d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l5-20020a622505000000b0058db4725798si5569223pfl.160.2023.03.08.02.20.46; Wed, 08 Mar 2023 02:20:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EiJrP86d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbjCHJwb (ORCPT + 99 others); Wed, 8 Mar 2023 04:52:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbjCHJwX (ORCPT ); Wed, 8 Mar 2023 04:52:23 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C535498873; Wed, 8 Mar 2023 01:52:21 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id i34so63283234eda.7; Wed, 08 Mar 2023 01:52:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678269140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sXCB+oYW4zw2V6U49JxzpNXli13gSy/i91Jkb3XU6Fk=; b=EiJrP86dqDxICaiHjpt0FwCpWlRiaNZglDtvcDTiGUoF4LhEGr3G6hEOy7AenHYMZX Ky4VBdYK9/49NcskdAZw9qTSQGBCYwwmoQRDpmKIBpoyhxpsD5Mkcrr+84ble/bSBvGh XLp6H9vFRNzmqUlMBzDsCVsdh/cZjVy7YCznA2kI5GBsQSEBG2TwMHRsx5ic+WHvyHeL bEOHJa36OLSVB0MYjrJPvJEvNlF8jqzARsAyg9GtC4UPWfljSVsimur8BIN66xUVPMJL Aw60EkHbdbhUbJf51T6wNa7nIztPMPeVLe1cgk407MQCehlBmaDruovoNtSV3u0m7WgU Mrfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678269140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sXCB+oYW4zw2V6U49JxzpNXli13gSy/i91Jkb3XU6Fk=; b=i9CrVgXuBsyHPFI2N0XFK1EJzX0lfpLQkt3V9tvE12Wo7BPBt9Yz9bF62NarW+LTu+ WCf75oUqxMVCBXNrFzo++nA9HMFE6+S0Wqh5vZA6g4nZ3SN6Ew9B5QhVinLz9XfdYmu8 KW72HYF9u1k8nDmMFkmJQi58BA+tTMMrtdzTDfbEQKBKVQpHrNr93KnaXYAyBjO8sWeR 7CeCZdZ+Y9xiAChF0UWkHBJDyXUTUF2lJJy24cLtF9C3Q9rUri29x9PBilwSBtC/Rg/g SDoNFJhJpQJXdjFiOUs6D7hfIeptJKJnSuRGv/YZrfTW+0XLXJdEJdl6h6wFy/1virFH w1lg== X-Gm-Message-State: AO0yUKXj6m0lcJJazB3Myoz4YVD5WpP6UJGsmqLZCNOCNKhLnjZQBaUR s15weKUUcsKHLYGzZHI9dlo= X-Received: by 2002:a17:907:e8d:b0:8af:5752:691f with SMTP id ho13-20020a1709070e8d00b008af5752691fmr21189100ejc.76.1678269139972; Wed, 08 Mar 2023 01:52:19 -0800 (PST) Received: from xeon.. ([188.163.112.76]) by smtp.gmail.com with ESMTPSA id s15-20020a170906454f00b008d8f1b238fdsm7369177ejq.149.2023.03.08.01.52.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Mar 2023 01:52:19 -0800 (PST) From: Svyatoslav Ryhel To: Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Svyatoslav Ryhel , Hans Verkuil , Luca Ceresoli , Jean Delvare , Sebastian Reichel , Daniel Jeong , Ldd-Mlp Cc: linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/2] media: lm3560: convent to OF Date: Wed, 8 Mar 2023 11:52:09 +0200 Message-Id: <20230308095209.14700-3-clamor95@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230308095209.14700-1-clamor95@gmail.com> References: <20230308095209.14700-1-clamor95@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759794544205850962?= X-GMAIL-MSGID: =?utf-8?q?1759794544205850962?= If no pdata is available, try to read from device tree. Signed-off-by: Svyatoslav Ryhel --- drivers/media/i2c/lm3560.c | 128 +++++++++++++++++++++++++++---------- 1 file changed, 93 insertions(+), 35 deletions(-) diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c index 5ef613604be7..5541051616b7 100644 --- a/drivers/media/i2c/lm3560.c +++ b/drivers/media/i2c/lm3560.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -22,16 +23,16 @@ /* registers definitions */ #define REG_ENABLE 0x10 -#define REG_TORCH_BR 0xa0 -#define REG_FLASH_BR 0xb0 -#define REG_FLASH_TOUT 0xc0 +#define REG_TORCH_BR 0xa0 +#define REG_FLASH_BR 0xb0 +#define REG_FLASH_TOUT 0xc0 #define REG_FLAG 0xd0 #define REG_CONFIG1 0xe0 /* fault mask */ -#define FAULT_TIMEOUT (1<<0) -#define FAULT_OVERTEMP (1<<1) -#define FAULT_SHORT_CIRCUIT (1<<2) +#define FAULT_TIMEOUT BIT(0) +#define FAULT_OVERTEMP BIT(1) +#define FAULT_SHORT_CIRCUIT BIT(2) enum led_enable { MODE_SHDN = 0x0, @@ -54,6 +55,7 @@ struct lm3560_flash { struct device *dev; struct lm3560_platform_data *pdata; struct regmap *regmap; + struct gpio_desc *hwen_gpio; struct mutex lock; enum v4l2_flash_led_mode led_mode; @@ -356,12 +358,19 @@ static int lm3560_subdev_init(struct lm3560_flash *flash, flash->subdev_led[led_no].flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; strscpy(flash->subdev_led[led_no].name, led_name, sizeof(flash->subdev_led[led_no].name)); + rval = lm3560_init_controls(flash, led_no); - if (rval) + if (rval) { + dev_err(flash->dev, "failed to init controls: %d\n", rval); goto err_out; + } + rval = media_entity_pads_init(&flash->subdev_led[led_no].entity, 0, NULL); - if (rval < 0) + if (rval < 0) { + dev_err(flash->dev, "failed to init media entity pads: %d\n", rval); goto err_out; + } + flash->subdev_led[led_no].entity.function = MEDIA_ENT_F_FLASH; return rval; @@ -391,6 +400,49 @@ static int lm3560_init_device(struct lm3560_flash *flash) return rval; } +static int lm3560_of_probe(struct lm3560_flash *flash) +{ + struct lm3560_platform_data *pdata; + struct fwnode_handle *node; + int ret, reg; + + pdata = devm_kzalloc(flash->dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return -ENODEV; + + ret = device_property_read_u32(flash->dev, + "ti,peak-current", &pdata->peak); + if (ret) + pdata->peak = LM3560_PEAK_3600mA; + + ret = device_property_read_u32(flash->dev, + "ti,max-flash-timeout", + &pdata->max_flash_timeout); + if (ret) + pdata->max_flash_timeout = LM3560_FLASH_TOUT_MAX; + + device_for_each_child_node(flash->dev, node) { + fwnode_property_read_u32(node, "reg", ®); + + if (reg == LM3560_LED0 || reg == LM3560_LED1) { + ret = device_property_read_u32(flash->dev, + "ti,max-flash-current", + &pdata->max_flash_brt[reg]); + if (ret) + pdata->max_flash_brt[reg] = LM3560_FLASH_TOUT_MAX; + + ret = device_property_read_u32(flash->dev, + "ti,max-torch-current", + &pdata->max_torch_brt[reg]); + if (ret) + pdata->max_torch_brt[reg] = LM3560_TORCH_BRT_MAX; + } + } + flash->pdata = pdata; + + return 0; +} + static int lm3560_probe(struct i2c_client *client) { struct lm3560_flash *flash; @@ -398,44 +450,41 @@ static int lm3560_probe(struct i2c_client *client) int rval; flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); - if (flash == NULL) + if (!flash) return -ENOMEM; flash->regmap = devm_regmap_init_i2c(client, &lm3560_regmap); - if (IS_ERR(flash->regmap)) { - rval = PTR_ERR(flash->regmap); - return rval; - } + if (IS_ERR(flash->regmap)) + return dev_err_probe(&client->dev, PTR_ERR(flash->regmap), + "failed to init regmap\n"); - /* if there is no platform data, use chip default value */ - if (pdata == NULL) { - pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); - if (pdata == NULL) - return -ENODEV; - pdata->peak = LM3560_PEAK_3600mA; - pdata->max_flash_timeout = LM3560_FLASH_TOUT_MAX; - /* led 1 */ - pdata->max_flash_brt[LM3560_LED0] = LM3560_FLASH_BRT_MAX; - pdata->max_torch_brt[LM3560_LED0] = LM3560_TORCH_BRT_MAX; - /* led 2 */ - pdata->max_flash_brt[LM3560_LED1] = LM3560_FLASH_BRT_MAX; - pdata->max_torch_brt[LM3560_LED1] = LM3560_TORCH_BRT_MAX; - } - flash->pdata = pdata; flash->dev = &client->dev; mutex_init(&flash->lock); + /* if there is no platform data, try to read from device tree */ + if (!pdata) + lm3560_of_probe(flash); + + flash->hwen_gpio = devm_gpiod_get_optional(flash->dev, "enable", + GPIOD_OUT_HIGH); + if (IS_ERR(flash->hwen_gpio)) + return dev_err_probe(&client->dev, PTR_ERR(flash->hwen_gpio), + "failed to get hwen gpio\n"); + rval = lm3560_subdev_init(flash, LM3560_LED0, "lm3560-led0"); if (rval < 0) - return rval; + return dev_err_probe(&client->dev, rval, + "failed to init led0 subdev\n"); rval = lm3560_subdev_init(flash, LM3560_LED1, "lm3560-led1"); if (rval < 0) - return rval; + return dev_err_probe(&client->dev, rval, + "failed to init led1 subdev\n"); rval = lm3560_init_device(flash); if (rval < 0) - return rval; + return dev_err_probe(&client->dev, rval, + "failed to init device\n"); i2c_set_clientdata(client, flash); @@ -452,21 +501,30 @@ static void lm3560_remove(struct i2c_client *client) v4l2_ctrl_handler_free(&flash->ctrls_led[i]); media_entity_cleanup(&flash->subdev_led[i].entity); } + + gpiod_set_value_cansleep(flash->hwen_gpio, 0); } +static const struct of_device_id lm3560_match[] = { + { .compatible = "ti,lm3559" }, + { .compatible = "ti,lm3560" }, + { } +}; +MODULE_DEVICE_TABLE(of, lm3560_match); + static const struct i2c_device_id lm3560_id_table[] = { {LM3559_NAME, 0}, {LM3560_NAME, 0}, {} }; - MODULE_DEVICE_TABLE(i2c, lm3560_id_table); static struct i2c_driver lm3560_i2c_driver = { .driver = { - .name = LM3560_NAME, - .pm = NULL, - }, + .name = LM3560_NAME, + .pm = NULL, + .of_match_table = lm3560_match, + }, .probe_new = lm3560_probe, .remove = lm3560_remove, .id_table = lm3560_id_table,