From patchwork Wed Mar 8 09:02:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Svyatoslav Ryhel X-Patchwork-Id: 66124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp229414wrd; Wed, 8 Mar 2023 01:30:03 -0800 (PST) X-Google-Smtp-Source: AK7set9TsyL+S3laQfJQUfAZ0FWddzAlF+UgAhEWvFzeXVvyMZQ04qozKc80hAOj2ZFfXSFQFLfh X-Received: by 2002:a17:907:6d91:b0:878:58e6:f1eb with SMTP id sb17-20020a1709076d9100b0087858e6f1ebmr21536468ejc.23.1678267803699; Wed, 08 Mar 2023 01:30:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678267803; cv=none; d=google.com; s=arc-20160816; b=sUc4qepg9kW8kVMUhmDYWdhnEYxlVbdeAigrfx6RRaHMkn5rqFIZMohTMJYQvj5S2C qXoSK0WkOv4s1h0YkD0p7+oD3CiklbIsPvanGcOWFyV8DAHLm8b17za+rs/oBHBL6eb4 FnKCHBceME4YwwuZ/sTHWFtw66UDb/15754Q5ndz3hhb0UuUzm9uF4+LT1ibttG9txdT ot6nGV4DtVLHILwa7jWSdi952cX+pLcODj42bL5UwCdJmN8abeWRZ3eeWV4rRQKIfgSG g8cLNtBejnJfciUFcqcvAokAvrGVWkZkZXhv7OkJ6aB5ob/nPVTAwDuA/hGZmYwsfzph 972Q== 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=pEL5i+l5uJgUeWQVuHHqsyYYkfIaU6CMwZkdIb7+3Eo=; b=wnBdnL7tq1DO/BAcreFDv8Dt2AZifqVq9OHuRfUSMU6TZYyMxNaX44zM1G8w/Nfzgq ybbJ/M+fK7BFLNQxNZKZuTQe9Sxc7Rg02bg7HFhYEYR3KOK3FIyAqnmilbyDczQn/JU3 SF2OlLv1G4EWhI9nGuxqty6jfZGUSYrG58mF24tKJOeK2Nm6WpOjBodjIpQT0xkpva8Q fqPh1WpUX+2OWmlfgH/5J0zEBRkEpaK23a2wCScp7skgMxokHxOM+xvjuyg1//nekwWk lwrJPVxD+7M1o3MZ8oSgEyhpQrbYG/6zh8KrFvstgcKATAh63sV/RD5D3V+Hsj9H2lAi d1zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HcERTqYK; 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 f3-20020a05640214c300b004be3964ffdcsi15258902edx.517.2023.03.08.01.29.40; Wed, 08 Mar 2023 01:30:03 -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=HcERTqYK; 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 S230124AbjCHJCp (ORCPT + 99 others); Wed, 8 Mar 2023 04:02:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229809AbjCHJCd (ORCPT ); Wed, 8 Mar 2023 04:02:33 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09A8995E2E; Wed, 8 Mar 2023 01:02:31 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id o12so62712222edb.9; Wed, 08 Mar 2023 01:02:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678266149; 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=pEL5i+l5uJgUeWQVuHHqsyYYkfIaU6CMwZkdIb7+3Eo=; b=HcERTqYKjrUqYLYOThQfCLeydPrBYa/Wj5A1D8Q2PYj/5MMPtCnDCYIB5Y7AndyFHG T9jRhZ159tegwOhWRZXJ5FGj12/B6Iwr0zU5AE+eIUY1kf6QyHsm7OcAWiDOa1kk+f8l kKkjebrwIhay65THKbPPIHUFYDl0bXYGNytWGLbnIvYvadUNgccu1sk1TijyORw/JVtC k3/GQnhYEnhWgbGRfwSTcDLuk0uOQhHwQxZtHX6kNCC6PfPszAj6wYR6fsBdwPNnKYqU gJxxhK2IxQp3c1kezVY9SGFbFlnZ6a7N8lvtzJGW0adkc21jo0LVJj/Gr9Qq9WZQVdCX uGog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678266149; 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=pEL5i+l5uJgUeWQVuHHqsyYYkfIaU6CMwZkdIb7+3Eo=; b=LQXY5wW3MYMCkWEZbO4rF2JYfjZwunZu0v8GeVq1iF2NDaeIgVySE5GAKDOBBW2JQH 4IhXlOvy/XHa5PsEFMQbIXcoXgqTKzQdnGn04mHJAtly+44etFUsTCU7lHTAWxsRnUXz P/67VRonWK2HYysdZtC1bF4iYH+NsLGFlc46rV9tTWubmiPvgfCLUZS911eBi1Vg4xCl nk44+AdKH9Z8388eFUvFNZm5lkyMcHdHhBtZAcELRURRuF5clgQHHXtPLGWwKKOFW0iW UhZmA5AAyoElyF2hy9xfKb7/MBVgETbRWSfDYeHC0ZW1EZYdyF36zZk6RTelbpg2Z/NP /8Qg== X-Gm-Message-State: AO0yUKX9AE90ETXSXb4b3MtJcXmMp4Jnkx91WOrNHNTY9wpSrrEsX8Wf Ap1H6wLDJXxeu1wvj6qupu8= X-Received: by 2002:a17:906:ca5a:b0:8b2:abc7:1ef9 with SMTP id jx26-20020a170906ca5a00b008b2abc71ef9mr17204205ejb.68.1678266149422; Wed, 08 Mar 2023 01:02:29 -0800 (PST) Received: from xeon.. ([188.163.112.76]) by smtp.gmail.com with ESMTPSA id j7-20020a17090643c700b008caaae1f1e1sm7153709ejn.110.2023.03.08.01.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Mar 2023 01:02:29 -0800 (PST) From: Svyatoslav Ryhel To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Svyatoslav Ryhel , Dmitry Osipenko Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/4] misc: adps990x: convert to OF Date: Wed, 8 Mar 2023 11:02:17 +0200 Message-Id: <20230308090219.12710-3-clamor95@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230308090219.12710-1-clamor95@gmail.com> References: <20230308090219.12710-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?1759791340530938556?= X-GMAIL-MSGID: =?utf-8?q?1759791340530938556?= Add ability to get essential values from device tree. Signed-off-by: Svyatoslav Ryhel --- drivers/misc/apds990x.c | 56 +++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/drivers/misc/apds990x.c b/drivers/misc/apds990x.c index 0024503ea6db..c53ead5a575d 100644 --- a/drivers/misc/apds990x.c +++ b/drivers/misc/apds990x.c @@ -180,8 +180,8 @@ static const u16 arates_hz[] = {10, 5, 2, 1}; static const u8 apersis[] = {1, 2, 4, 5}; /* Regulators */ -static const char reg_vcc[] = "Vdd"; -static const char reg_vled[] = "Vled"; +static const char reg_vcc[] = "vdd"; +static const char reg_vled[] = "vled"; static int apds990x_read_byte(struct apds990x_chip *chip, u8 reg, u8 *data) { @@ -1048,9 +1048,38 @@ static struct attribute *sysfs_attrs_ctrl[] = { }; static const struct attribute_group apds990x_attribute_group[] = { - {.attrs = sysfs_attrs_ctrl }, + { .attrs = sysfs_attrs_ctrl }, }; +static int apds990x_of_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) { + dev_info(&client->dev, "pdrive property is missing: ret %d\n", ret); + return ret; + } + pdata->pdrive = val; + + ret = device_property_read_u32(&client->dev, "avago,ppcount", &val); + if (ret) { + dev_info(&client->dev, "ppcount property is missing: ret %d\n", ret); + return ret; + } + pdata->ppcount = val; + + chip->pdata = pdata; + + return 0; +} + static int apds990x_probe(struct i2c_client *client) { struct apds990x_chip *chip; @@ -1065,13 +1094,10 @@ 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) + apds990x_of_probe(client, chip); if (chip->pdata->cf.ga == 0) { /* set uncovered sensor default parameters */ @@ -1160,8 +1186,7 @@ static int apds990x_probe(struct i2c_client *client) err = request_threaded_irq(client->irq, NULL, apds990x_irq, - IRQF_TRIGGER_FALLING | IRQF_TRIGGER_LOW | - IRQF_ONESHOT, + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "apds990x", chip); if (err) { dev_err(&client->dev, "could not get IRQ %d\n", @@ -1252,11 +1277,16 @@ 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 }, {} }; - MODULE_DEVICE_TABLE(i2c, apds990x_id); static const struct dev_pm_ops apds990x_pm_ops = { @@ -1270,12 +1300,12 @@ 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, .id_table = apds990x_id, }; - module_i2c_driver(apds990x_driver); MODULE_DESCRIPTION("APDS990X combined ALS and proximity sensor");