From patchwork Mon Jul 31 11:02:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Svyatoslav Ryhel X-Patchwork-Id: 13334409 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05AB4C001E0 for ; Mon, 31 Jul 2023 11:03:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230394AbjGaLDN (ORCPT ); Mon, 31 Jul 2023 07:03:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232433AbjGaLDF (ORCPT ); Mon, 31 Jul 2023 07:03:05 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BB16129; Mon, 31 Jul 2023 04:03:04 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2b9db1de50cso25442301fa.3; Mon, 31 Jul 2023 04:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690801382; x=1691406182; 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=1VbuOesFY8jgrwRNfOH6TH6GpPlQAQeFgnVpyaXLhy0=; b=NYA+jcorU61v4iXcDDJEPRNT7gO9w1yrLMAr5FWtCaHkz78BGEWVxa4ZY4D6824oH5 6VIOJK8OrP0OXoAy9hf8OykiN1DMgfSOThVv+evF9JoZxB1NaLldeZ7oNz0DwEvVJ2TQ o20Gt1Gf7U2Ucz2KiQixp85pX8OivoGyFrdJqnC09eHMA1LliIQ+LgRoSgc9t5aURtqs lVqq5hnaisSRpByj7+gZU8SBi0adebwvb0F16KBAZqotd7jpO6JqpAgYujo3oQ4N3a1V e6QvK/ARiuMwTwqPl4OuRtL05dzjsYiLx14PK0CRHfS7j2dreA3KmpV7mgbHLKXni3SW VrnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690801382; x=1691406182; 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=1VbuOesFY8jgrwRNfOH6TH6GpPlQAQeFgnVpyaXLhy0=; b=StKyxOvmBr6X8QQYq7j5/kXt1KeVqqbS5rXNN7daAKVm5NRp2qGkiPmL5SBSNRnzHQ RmoeYfOymCi7ZP1aRYeS/3mrLwZoJb3VX+UeOJe9M6c0I4tQg/Byk/BJKK4ZuMr+i/wp i81hn3nSWP2xdGoWnRWvevJAvWEpkFjild1aqYCazjW6qYBt1LMZqpDcVxi0p6dXblZp 4PGVeJ517ntRLbgubFi3KN9nERJUup7cH8FHsskIyreo8u0GxNhM+xrLEJ3GXnbrzpxV CC+BpSROqf1Exc8OF0s8lZzV4qLJeSusTpOaHWwPmty00FXtF4ZXKUf3/je7cqyvKLXK kDMQ== X-Gm-Message-State: ABy/qLZreHN8y/3VDOT5pKi+XRx9Erj0+8jS3gOpda/AU90u1fsoBR1v +5T4mpq2GslsFzVYf2MYsJ4= X-Google-Smtp-Source: APBJJlE9CLief85Q66abBBrZuGY9xYj2+K7h86HSzXoeuo0Pijv+5vETfPXq9VR5K72gnQvF+GFjdQ== X-Received: by 2002:a2e:6e14:0:b0:2b9:dfd1:3808 with SMTP id j20-20020a2e6e14000000b002b9dfd13808mr2984934ljc.25.1690801382092; Mon, 31 Jul 2023 04:03:02 -0700 (PDT) Received: from xeon.. ([188.163.112.48]) by smtp.gmail.com with ESMTPSA id p2-20020a2e8042000000b002b9bf5b071bsm74607ljg.20.2023.07.31.04.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 04:03:01 -0700 (PDT) From: Svyatoslav Ryhel To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Arnd Bergmann , Greg Kroah-Hartman , Svyatoslav Ryhel , Samu Onkalo Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/2] dt-bindings: iio: light: add apds990x binding Date: Mon, 31 Jul 2023 14:02:38 +0300 Message-Id: <20230731110239.107086-2-clamor95@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230731110239.107086-1-clamor95@gmail.com> References: <20230731110239.107086-1-clamor95@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add dt-binding for apds990x ambient light/proximity sensor. Signed-off-by: Svyatoslav Ryhel --- .../bindings/iio/light/avago,apds990x.yaml | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/avago,apds990x.yaml diff --git a/Documentation/devicetree/bindings/iio/light/avago,apds990x.yaml b/Documentation/devicetree/bindings/iio/light/avago,apds990x.yaml new file mode 100644 index 000000000000..89a061643de5 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/avago,apds990x.yaml @@ -0,0 +1,87 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/avago,apds990x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Avago APDS990x ambient light and proximity sensor + +maintainers: + - Samu Onkalo + +description: + APDS990x is a combined ambient light and proximity sensor. ALS and + proximity functionality are highly connected. ALS measurement path + must be running while the proximity functionality is enabled. + Datasheet at https://docs.broadcom.com/doc/AV02-2867EN + +properties: + compatible: + const: avago,apds990x + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: true + vled-supply: true + + avago,pdrive: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 3 + description: + The LED drive current is controlled by a regulated current + sink on the LDR pin. This feature eliminates the need to use + a current limiting resistor to control LED current. The LED + drive current can be configured for 12.5 mA (pdrive = 3), + 25 mA (2), 50 mA (1) or 100 mA (0). For higher LED drive + requirements, an external P type transistor can be used to + control the LED current. + + avago,ppcount: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + maximum: 255 + description: + The number of LED pulses can be programmed to a value of 1 to + 255 pulses as needed. Increasing the number of LED pulses at a + given current will increase the sensor sensitivity. Sensitivity + grows by the square root of the number of pulses. Each pulse + has a 16 mS period. + +additionalProperties: false + +required: + - compatible + - reg + - interrupts + - vdd-supply + - vled-supply + - avago,pdrive + - avago,ppcount + +examples: + - | + #include + i2c { + #address-cells = <1>; + #size-cells = <0>; + + light-sensor@39 { + compatible = "avago,apds990x"; + reg = <0x39>; + + interrupt-parent = <&gpio>; + interrupts = <82 IRQ_TYPE_EDGE_RISING>; + + vdd-supply = <&vdd_3v0_proxi>; + vled-supply = <&vdd_1v8_sen>; + + avago,pdrive = <0>; + avago,ppcount = <3>; + }; + }; +... From patchwork Mon Jul 31 11:02:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Svyatoslav Ryhel X-Patchwork-Id: 13334407 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B844C001DC for ; Mon, 31 Jul 2023 11:03:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230222AbjGaLDN (ORCPT ); Mon, 31 Jul 2023 07:03:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232453AbjGaLDG (ORCPT ); Mon, 31 Jul 2023 07:03:06 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CE00EB; Mon, 31 Jul 2023 04:03:05 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2b9b904bb04so66261251fa.1; Mon, 31 Jul 2023 04:03:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690801383; x=1691406183; 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=pOfsPdADwq8SeaOVLGoXbhR/yvpsism3LrFhqiy9z/0=; b=NGgK+Ss1tH+8XRHzYUj6iMA2ydeitDSPEbmb469Rwkw27f2iUr4Gex5DIW0eJ6AilF B0L9V4QAy8G99A42tQlNaU7DJwFTLGzop7sz5f3b8RDihpVxxk+Lft1ydRHN57rZdJjq gDvb6xL0jSlqM3pcaEsVCygT9LVdB+Zc+P53fUK8eKitFuLbfXn6n3Jjvx9RuKTYFe10 QAew5nQvqQRhhWPfJsSqZwGzBTCnS82EUhIu25WT08mUBt4jOF3M3XiqwSnvnBK6Hvoj DqcE38hNp6OPaoN7P9GGrNOtluS7faBvkYfGYOsHL9GbwFhHns9+H787LCR2yXwyVaxy BFfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690801383; x=1691406183; 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=pOfsPdADwq8SeaOVLGoXbhR/yvpsism3LrFhqiy9z/0=; b=OhwqoP8EVnUOkLhTe6ElLfq++s774CPuJnX4EW895h/A8Z5Ufv+y7qzEqWidTmBYGj LzRm1U+5sUr+T3cFlvRjEv53boi+ZpQb6ehcCmli+tAHuHW6WPWLfWHokyhFg4pfTnYD VW9y0G8psVkMrBR/rebpSmy6iZ5syR54IjbjEp4cTaSLVrIOp7q7xT2cLtSai0iS1WP0 qBJ6G1v2oBNtxGA3sodQjCeS5CfNkLWxTBCjDlILlGs/3RI+BZkLignBPBtILDNXRc1T schlTeb1evTOIyayqqYrUe9RNGoowvlZSN8bYPd0trbsuOcT09wUdo2EGTdIIHtil5TB 8Gvg== X-Gm-Message-State: ABy/qLbhM4FiFvVYq3m8LzBPdFi34ax/ek5KYNYJ7clA8ahHEccctp8s wpBk6bEn+SwYZDj2A8Gg5RA= X-Google-Smtp-Source: APBJJlFR5Chknpd2vgyeFK2PwvZ0Kv4oh4HUHN0mZtCsRWNSlmDAlXwNcA+8fBUo3kBPMZMdaD521Q== X-Received: by 2002:a05:651c:21a:b0:2b9:cd3d:4136 with SMTP id y26-20020a05651c021a00b002b9cd3d4136mr6195416ljn.2.1690801383203; Mon, 31 Jul 2023 04:03:03 -0700 (PDT) Received: from xeon.. ([188.163.112.48]) by smtp.gmail.com with ESMTPSA id p2-20020a2e8042000000b002b9bf5b071bsm74607ljg.20.2023.07.31.04.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 04:03:02 -0700 (PDT) From: Svyatoslav Ryhel To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Arnd Bergmann , Greg Kroah-Hartman , Svyatoslav Ryhel , Samu Onkalo Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/2] misc: adps990x: convert to OF Date: Mon, 31 Jul 2023 14:02:39 +0300 Message-Id: <20230731110239.107086-3-clamor95@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230731110239.107086-1-clamor95@gmail.com> References: <20230731110239.107086-1-clamor95@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add ability to use device tree bindings keeping existing setup. Signed-off-by: Svyatoslav Ryhel --- drivers/misc/apds990x.c | 55 +++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/drivers/misc/apds990x.c b/drivers/misc/apds990x.c index 0024503ea6db..cf56d68c938a 100644 --- a/drivers/misc/apds990x.c +++ b/drivers/misc/apds990x.c @@ -1051,6 +1051,37 @@ static const struct attribute_group apds990x_attribute_group[] = { {.attrs = sysfs_attrs_ctrl }, }; +static int apds990x_fw_probe(struct i2c_client *client, + struct apds990x_chip *chip) +{ + struct apds990x_platform_data *pdata; + u32 ret, val; + + pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + ret = device_property_read_u32(&client->dev, "avago,pdrive", &val); + if (ret) + return dev_err_probe(&client->dev, ret, + "pdrive property is missing\n"); + pdata->pdrive = val; + + ret = device_property_read_u32(&client->dev, "avago,ppcount", &val); + if (ret) + return dev_err_probe(&client->dev, ret, + "ppcount property is missing\n"); + pdata->ppcount = val; + + chip->pdata = pdata; + + /* set regulator names which fit device tree entries */ + chip->regs[0].supply = "vdd"; + chip->regs[1].supply = "vled"; + + return 0; +} + static int apds990x_probe(struct i2c_client *client) { struct apds990x_chip *chip; @@ -1065,12 +1096,12 @@ static int apds990x_probe(struct i2c_client *client) init_waitqueue_head(&chip->wait); mutex_init(&chip->mutex); - chip->pdata = client->dev.platform_data; - if (chip->pdata == NULL) { - dev_err(&client->dev, "platform data is mandatory\n"); - err = -EINVAL; - goto fail1; + chip->pdata = client->dev.platform_data; + if (!chip->pdata) { + err = apds990x_fw_probe(client, chip); + if (err) + return err; } if (chip->pdata->cf.ga == 0) { @@ -1111,8 +1142,11 @@ static int apds990x_probe(struct i2c_client *client) chip->prox_persistence = APDS_DEFAULT_PROX_PERS; chip->prox_continuous_mode = false; - chip->regs[0].supply = reg_vcc; - chip->regs[1].supply = reg_vled; + if (!chip->regs[0].supply) + chip->regs[0].supply = reg_vcc; + + if (!chip->regs[1].supply) + chip->regs[1].supply = reg_vled; err = regulator_bulk_get(&client->dev, ARRAY_SIZE(chip->regs), chip->regs); @@ -1252,6 +1286,12 @@ static int apds990x_runtime_resume(struct device *dev) #endif +static const struct of_device_id apds990x_match_table[] = { + { .compatible = "avago,apds990x" }, + { }, +}; +MODULE_DEVICE_TABLE(of, apds990x_match_table); + static const struct i2c_device_id apds990x_id[] = { {"apds990x", 0 }, {} @@ -1270,6 +1310,7 @@ static struct i2c_driver apds990x_driver = { .driver = { .name = "apds990x", .pm = &apds990x_pm_ops, + .of_match_table = apds990x_match_table, }, .probe_new = apds990x_probe, .remove = apds990x_remove,