Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2403pxv; Thu, 24 Jun 2021 01:07:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCJpxvmHFTXK44aqQEk2uh7mpzwVTHt8hibcsdFUX2U5EcVsWAiHjmSdHVBLV3RLRBZYgo X-Received: by 2002:a17:906:94d1:: with SMTP id d17mr4171510ejy.460.1624522028242; Thu, 24 Jun 2021 01:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624522028; cv=none; d=google.com; s=arc-20160816; b=GbnL+gFsvoG/Alygz5kPqPTQf/Eke9sMm7xRRwJVogyQFNGRwcMe+6POMT5OMwTs34 ch5+uLsXoH8UKdbCp0LfAbx+0Wg4uhF0w80hq9tLoyuwxE4ZCPANTU0FiknNGW2MSMG/ x+3D5PfwkVL7BicyEQN6fiwnwpmU0Fs57Y67JZrhLp08LPOqy+SLqeLU6yCxGHuO7bx9 FZHrHjGauMUmryz7wrFcfX2I44SODr1k5gvtW31PgmtnKqNqdqOcnQI3D/gUY9wIRHn6 uMzB8gUJZeJz0DQVrN+Am3Dq7/mZg4f+bZYE34meXcKg5dfcFNHdv1NrBO4SAe1fQG1c EmWA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=umBwtkhrSHwFrljnPOuOKVRuZZ2n2cUtpGj8YFIOkIA=; b=fj9WQwVF96fzmRU5jufKjD4FxsPe2W5pW1ualnWGQ1+iGbVdkKiQcmOcbXY15F1mcd nqHBBsawHQOsGU5suop40lne+TS7aO2MIcE6SSmzhONo3fMVroXid0QpSzJzdZHmFVz7 IIMy0yujw9ZdPloVxtEXj/3xtF89h2LjCMc6zHftpMr4CH5n3V0TilF6NtbuWsIU9LrT udmH2p1uXO6Yv5ARsuc/rBlTozwtGS6I4K6MlyXP8DPdjoZsfnArFWm62/3R+xiAKIa5 ZNOw7v9ZZQG0zBYBFW9oF32p/RM7kKFhmVTCipSCQpG7GHhYy3e9nY3dkgjpEu0zTDfn xcvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=SKIPoc5i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id em22si2108850ejc.469.2021.06.24.01.06.44; Thu, 24 Jun 2021 01:07:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=SKIPoc5i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231824AbhFXIIC (ORCPT + 99 others); Thu, 24 Jun 2021 04:08:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231699AbhFXIIB (ORCPT ); Thu, 24 Jun 2021 04:08:01 -0400 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 CC25EC061756 for ; Thu, 24 Jun 2021 01:05:41 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id h17so7202920edw.11 for ; Thu, 24 Jun 2021 01:05:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=umBwtkhrSHwFrljnPOuOKVRuZZ2n2cUtpGj8YFIOkIA=; b=SKIPoc5iG3fG5SA7nspUWpIbsVLYK+y2Z8tpzc5T8g1shNPVxgDPcp9coziLuilLN4 0VrTM6heBFZzmR+QZNt1+KDjwUU0fWaWKFtwvXGw/WtWztdXKynH1ClKl1VLr9t/IAwC /I/+M3jFowOCx5TdigFfBmqXXpIjGUiSlIU3XzcO7q192C2CblXwfODT7a8i0WVD0Sfa zZtMQejZh6cwX2uv23TNwZTxlE5D1PEG7w8x7vVKgSVsgWUxQW5t0w7xaqhcWTPJ5h1/ 267OmKVKThlgwgE21nvP0lMEj/yH9tWKXYVKyxykGPa+Gdl3CU7jJcrs5oSKZJr0gx9I ScmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=umBwtkhrSHwFrljnPOuOKVRuZZ2n2cUtpGj8YFIOkIA=; b=Lhod38814mpDYYsVXE2dSEWR/RWt8KrVy5stasj0dsoqNibiGLWTrYE2kfUmgDXts9 Yz9U+QQH4ur+ovjCMeqZ41vjVpkRPNgfOrpEsFxVSkk7VbBPa8d+bWeqxtOAFVHkT7m3 SZr1Sj9IgvSBUp//Yt9M1XwOMRvnnumqKn126wKfu+PN1E6QOeIofbsduG1MBHLqQxxd rgXwMe0rtSrqxges43y+1Synx2tRa/20zmqbQ+nkq+pEUUepBsla0YdHLvNHjMS70GKg Ce/4TzoLpDPwkRCycrHIDG6Hh7XW/WiuzE5NPzc6Gxb77igHm3RcTd8zr8x/E7wsyYhN XxqA== X-Gm-Message-State: AOAM5301fp9qg9bU5oRGJaNAAZMa092MSEWTC5dBtqKwVP1BB2NdUodY zj7VXvxVB0vch3Q96Un+rOq9Sg== X-Received: by 2002:a05:6402:138c:: with SMTP id b12mr5498588edv.268.1624521938886; Thu, 24 Jun 2021 01:05:38 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id w10sm1405936edv.34.2021.06.24.01.05.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 01:05:38 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Alexandru Ardelean Subject: [PATCH] iio: light: tcs3414: convert probe to device-managed routines Date: Thu, 24 Jun 2021 11:05:34 +0300 Message-Id: <20210624080534.9209-1-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This change converts the driver to use only device-managed init routines in the probe function of the driver. This way, we no longer need the tcs3414_remove() hook. We still need to keep the i2c_set_clientdata() call, as that's being used for the PM routines. And lastly, a devm_add_action_or_reset() hook is added to call the powerdown handler when the chip is uninitialized or the probe fails. Signed-off-by: Alexandru Ardelean --- drivers/iio/light/tcs3414.c | 48 +++++++++++++++---------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/drivers/iio/light/tcs3414.c b/drivers/iio/light/tcs3414.c index 0593abd600ec..b87222141429 100644 --- a/drivers/iio/light/tcs3414.c +++ b/drivers/iio/light/tcs3414.c @@ -267,6 +267,18 @@ static const struct iio_buffer_setup_ops tcs3414_buffer_setup_ops = { .predisable = tcs3414_buffer_predisable, }; +static int tcs3414_powerdown(struct tcs3414_data *data) +{ + return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL, + data->control & ~(TCS3414_CONTROL_POWER | + TCS3414_CONTROL_ADC_EN)); +} + +static void tcs3414_powerdown_cleanup(void *data) +{ + tcs3414_powerdown(data); +} + static int tcs3414_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -309,6 +321,11 @@ static int tcs3414_probe(struct i2c_client *client, if (ret < 0) return ret; + ret = devm_add_action_or_reset(&client->dev, tcs3414_powerdown_cleanup, + data); + if (ret < 0) + return ret; + data->timing = TCS3414_INTEG_12MS; /* free running */ ret = i2c_smbus_write_byte_data(data->client, TCS3414_TIMING, data->timing); @@ -320,38 +337,12 @@ static int tcs3414_probe(struct i2c_client *client, return ret; data->gain = ret; - ret = iio_triggered_buffer_setup(indio_dev, NULL, + ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, tcs3414_trigger_handler, &tcs3414_buffer_setup_ops); if (ret < 0) return ret; - ret = iio_device_register(indio_dev); - if (ret < 0) - goto buffer_cleanup; - - return 0; - -buffer_cleanup: - iio_triggered_buffer_cleanup(indio_dev); - return ret; -} - -static int tcs3414_powerdown(struct tcs3414_data *data) -{ - return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL, - data->control & ~(TCS3414_CONTROL_POWER | - TCS3414_CONTROL_ADC_EN)); -} - -static int tcs3414_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - - iio_device_unregister(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); - tcs3414_powerdown(iio_priv(indio_dev)); - - return 0; + return devm_iio_device_register(&client->dev, indio_dev); } #ifdef CONFIG_PM_SLEEP @@ -385,7 +376,6 @@ static struct i2c_driver tcs3414_driver = { .pm = &tcs3414_pm_ops, }, .probe = tcs3414_probe, - .remove = tcs3414_remove, .id_table = tcs3414_id, }; module_i2c_driver(tcs3414_driver); -- 2.31.1