Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1920pxv; Thu, 24 Jun 2021 01:06:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqmXrk0JsZkPOvqoU/S07NUb0Zq2BamFVmtzSyZ9C1de9r0s4VnfTkQyXlf2HnmBr+ucaO X-Received: by 2002:a17:906:3c42:: with SMTP id i2mr4163438ejg.39.1624521986156; Thu, 24 Jun 2021 01:06:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624521986; cv=none; d=google.com; s=arc-20160816; b=H6wZNa8AHJs2LrAgEOA66wTds7OeX8Gq7hTrtuytlRe8f54W9+j47x56FeUiYGbF61 rFSI2WBWHjvoaO7s9TnTVr1lqubGfSqE6jC7gXx686tCukYlneUQI1F644O2pRXjZgx7 YS6F/JfUnh/VQbM5l24O9fqPglJAFll/RPxzfu32+w428bFrE3GX3q66VRmI2/QHbiqD SdtU1YLxCLBX6BDzk15Akc0TEIe6EXHwH18dM8q+2S/8BT+xZ+8Jm5kxOIIwFf1vKuYm KfK/Ska7vzo84NGWkaqHoF/JAco43aCpzMTmV/4W5YIAVq/okEVhsQ0IHATkgHuR1G8G V/Iw== 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=97Lb3vGMIjKXqd/UtI7VBtf2c74YiMaSq0XnAt5KpaE=; b=gZt2N0sV1OjtWST+6lPzgEjVU1JFjWcV40WbUiu24ufvAMicVzkn225lSIYaxSOCoc WKfxt6njDfoDBkU+IumfvZRmznxHpVbrKHysOD6wusEs04jIDX1EN4QisO/iYpA1LJsk 4aphRVhqtSML/RVp2Hz7hoV/3gt5nFlBNtrTJUTEOcc03ty54Fflb+mtIAWn9VjiemSn Um8f+QILCAYRWQyszb/ZNCahopaQ8eXYHAsyMCaF7fsP08/1eVKYGiNqUr/p9xsi1d1i 6eTT/PE7hJVSJzmJLIl7gR+hqpNfh3PWD+hwoP4lvWdF/SEPh2O6tSsVb/P/i+HlHsaB HKOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b="bL/1IMGn"; 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 s20si2170272ejb.555.2021.06.24.01.06.03; Thu, 24 Jun 2021 01:06:26 -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="bL/1IMGn"; 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 S231804AbhFXIH0 (ORCPT + 99 others); Thu, 24 Jun 2021 04:07:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231788AbhFXIHZ (ORCPT ); Thu, 24 Jun 2021 04:07:25 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3FE5C061574 for ; Thu, 24 Jun 2021 01:05:05 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id gn32so8143494ejc.2 for ; Thu, 24 Jun 2021 01:05:05 -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=97Lb3vGMIjKXqd/UtI7VBtf2c74YiMaSq0XnAt5KpaE=; b=bL/1IMGnIaFaBMD4p6YgIIScJ5++Psz7wzCNg3iFNlr3zcAQbsgNib2eXdXTDnC7SL WpgHL9hUR3rBbtLw0SjKk4DEvgNdg/6XOzV2VCZ2hQmMyhj8VNGDUr6hhLlQ0zIe4QEK Aj/9q86Irg+Hbm2869gETRNyNQZRD0nXpWkQtAmwdEj2roO0/YP+raCyTOiKuFZy7dJk mhvBxgi66I6YM5HvuhgVn2kb7Ww+lEu/HzLDdW4yQrUEYjxVHqsAhQCRHpaGH0qY88tc sYRzLI6lCz48oWqZEHSF0g8iQIsDCHkSNXThkss/XoSxqWH9Rv/l3IklYjl8E1CRLEau SsGw== 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=97Lb3vGMIjKXqd/UtI7VBtf2c74YiMaSq0XnAt5KpaE=; b=YX9tNOCZePgiMm3zVKRb6/iGxu8eMGm9WOg1RQoebBM8qciRg3ODKWpfUQkuPkVipW ss6xr7ESpxd8h4ZA8czbRPH37EBR346hFHhYCVQAY0JRvHbH4x8zSWhWk7C8A0R2u65Y vANuwkLBnhks2/FxrzSvFn8HDzdS404Y/ZPlo3agQP8dKBA03++7UHR6bKSp1eYJ4Nzz dD5WrhQH0re1fNtisL6fZbwSRAvBO8muQAtMpWbwaBRHfz1d9j2UKRFH21jzqp8ibrLG NNBAkUmvSXh2FPCdDGS1Qnl22HSJH7XuHbWDLuFegIlH4G2NZxqD+LXKAcXWPRvDwW8D hdfA== X-Gm-Message-State: AOAM530/SFsqrXjmehKnkp8gpPszZXG0w/rOZ9MqKCYB1u8ZYtHAi+xS ncBeN3bscikVM+nHvNUWvWK4lQ== X-Received: by 2002:a17:907:1b22:: with SMTP id mp34mr4079709ejc.408.1624521904372; Thu, 24 Jun 2021 01:05:04 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id j19sm1390060edw.43.2021.06.24.01.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 01:05:03 -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: accel: adxl345: convert probe to device-managed functions Date: Thu, 24 Jun 2021 11:04:40 +0300 Message-Id: <20210624080441.8710-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 driver has two parts, one for i2c and one for spi, since the chip can operate with both wire protocols. The core file has a common adxl345_core_remove() function which puts the chip into a powerdown state. This can be implemented with a devm_add_action_or_reset() hook. Doing that means we can register the IIO device with devm_iio_device_register() and get rid of the adxl345_core_remove() function. The dev_set_drvdata() call can be removed as there is no other user of this private data anymore. Signed-off-by: Alexandru Ardelean --- drivers/iio/accel/adxl345.h | 1 - drivers/iio/accel/adxl345_core.c | 29 +++++++++-------------------- drivers/iio/accel/adxl345_i2c.c | 6 ------ drivers/iio/accel/adxl345_spi.c | 6 ------ 4 files changed, 9 insertions(+), 33 deletions(-) diff --git a/drivers/iio/accel/adxl345.h b/drivers/iio/accel/adxl345.h index 384497776b67..af0fdd02c4f2 100644 --- a/drivers/iio/accel/adxl345.h +++ b/drivers/iio/accel/adxl345.h @@ -15,6 +15,5 @@ enum adxl345_device_type { int adxl345_core_probe(struct device *dev, struct regmap *regmap, enum adxl345_device_type type, const char *name); -int adxl345_core_remove(struct device *dev); #endif /* _ADXL345_H_ */ diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 312866530065..4b275051ef61 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -208,6 +208,11 @@ static const struct iio_info adxl345_info = { .write_raw_get_fmt = adxl345_write_raw_get_fmt, }; +static void adxl345_powerdown(void *regmap) +{ + regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_STANDBY); +} + int adxl345_core_probe(struct device *dev, struct regmap *regmap, enum adxl345_device_type type, const char *name) { @@ -233,7 +238,6 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, return -ENOMEM; data = iio_priv(indio_dev); - dev_set_drvdata(dev, indio_dev); data->regmap = regmap; data->type = type; /* Enable full-resolution mode */ @@ -260,29 +264,14 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, return ret; } - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(dev, "iio_device_register failed: %d\n", ret); - regmap_write(data->regmap, ADXL345_REG_POWER_CTL, - ADXL345_POWER_CTL_STANDBY); - } + ret = devm_add_action_or_reset(dev, adxl345_powerdown, data->regmap); + if (ret < 0) + return ret; - return ret; + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_GPL(adxl345_core_probe); -int adxl345_core_remove(struct device *dev) -{ - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct adxl345_data *data = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - - return regmap_write(data->regmap, ADXL345_REG_POWER_CTL, - ADXL345_POWER_CTL_STANDBY); -} -EXPORT_SYMBOL_GPL(adxl345_core_remove); - MODULE_AUTHOR("Eva Rachel Retuya "); MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer core driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/accel/adxl345_i2c.c b/drivers/iio/accel/adxl345_i2c.c index 1561364ae296..a431cba216e6 100644 --- a/drivers/iio/accel/adxl345_i2c.c +++ b/drivers/iio/accel/adxl345_i2c.c @@ -38,11 +38,6 @@ static int adxl345_i2c_probe(struct i2c_client *client, id->name); } -static int adxl345_i2c_remove(struct i2c_client *client) -{ - return adxl345_core_remove(&client->dev); -} - static const struct i2c_device_id adxl345_i2c_id[] = { { "adxl345", ADXL345 }, { "adxl375", ADXL375 }, @@ -65,7 +60,6 @@ static struct i2c_driver adxl345_i2c_driver = { .of_match_table = adxl345_of_match, }, .probe = adxl345_i2c_probe, - .remove = adxl345_i2c_remove, .id_table = adxl345_i2c_id, }; diff --git a/drivers/iio/accel/adxl345_spi.c b/drivers/iio/accel/adxl345_spi.c index da4591c7ef23..ea559ac2e87d 100644 --- a/drivers/iio/accel/adxl345_spi.c +++ b/drivers/iio/accel/adxl345_spi.c @@ -42,11 +42,6 @@ static int adxl345_spi_probe(struct spi_device *spi) return adxl345_core_probe(&spi->dev, regmap, id->driver_data, id->name); } -static int adxl345_spi_remove(struct spi_device *spi) -{ - return adxl345_core_remove(&spi->dev); -} - static const struct spi_device_id adxl345_spi_id[] = { { "adxl345", ADXL345 }, { "adxl375", ADXL375 }, @@ -69,7 +64,6 @@ static struct spi_driver adxl345_spi_driver = { .of_match_table = adxl345_of_match, }, .probe = adxl345_spi_probe, - .remove = adxl345_spi_remove, .id_table = adxl345_spi_id, }; -- 2.31.1