Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3522815ybi; Tue, 18 Jun 2019 02:07:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzhNZrPUcY8o5bA4aTGkhvJzOk8DffGFcy5CvQoj+lWrb+zaf7QMFTMjzKKBTisfiMiNyi7 X-Received: by 2002:a65:4342:: with SMTP id k2mr1718526pgq.218.1560848871929; Tue, 18 Jun 2019 02:07:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560848871; cv=none; d=google.com; s=arc-20160816; b=iHD1ekmxVaQQeIMJKUNcxkhHebIxAPPoB+bIpYQ75HvhFL4xo3fYkRgtcNXN2JK1dT /bncBHEkE8d+MeQ5Y4GyP9zaRL8uQLdkzn16SQViAq0Htx4EUuzZWOoKYKsXJf5DDhxI nxWqVo2SQndnrLBcPaqjwfBAExG/t9nFOBMFIuH03+Ags/x1xtiqw2has6u8/KYth7td FWBOiAEbzKJHl3Qt2GCz4fm6jR9aSE05liVAn0f/m7hBk4qvFBqRCQvk4yFQW9BDMmaF uuQFwuE+TXAHH6mvlvLkOfvP/hmVukAyABg+dUmlDlxsbRbU67AehQQaYmoEWxbmYLDv ik0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from; bh=wwoV7UXVD2F3zKhJ5NUyJYYGVVHIdQOnA0HTMhUnIiU=; b=hDYqFaVrUdYdoQJEVnYqb1RbxXMDv71yDw7irnFC2AY5+HWNjJ+yFVd2Zmhh5OUKxo EgK5pguYMXZyhU1Kwl3DRS02sYo4RNhOEHxIhMsSk/YhZ2CP1GtxiUMuZZ63qDT38DmM wjMSeYIFNF5Se2KsxHC9tqneTjkUYJ3UzmLfXvkW4TvKwpE0UgOQBkGyYjwYJCSsCP+P kI0Hs20ipxUG63TiWO1hjLz5Y8aAsZ7IDyQnxog06/3DADByQuX9iGxpU39KLQcQTOMp 4lk9IVnUP99fJeMBEOIH3R79/lHw1+r6Gh8/yqBz7GP7amCxAVLy/6zyXcUIzHJ4W79H mxCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o26si12888010pgv.311.2019.06.18.02.07.32; Tue, 18 Jun 2019 02:07:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729288AbfFRJHP (ORCPT + 99 others); Tue, 18 Jun 2019 05:07:15 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:60004 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728965AbfFRJHN (ORCPT ); Tue, 18 Jun 2019 05:07:13 -0400 Received: from laptop.home (unknown [IPv6:2a01:cb19:8ad6:900:42dd:dd1c:19ee:7c60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: aragua) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 7551F285312; Tue, 18 Jun 2019 10:07:11 +0100 (BST) From: Fabien Lahoudere Cc: kernel@collabora.com, Fabien Lahoudere , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/8] iio: common: cros_ec_sensors: move registration to core Date: Tue, 18 Jun 2019 11:06:34 +0200 Message-Id: <2edb6d26030dbde1952bc1b25b6ca666233adfac.1560848479.git.fabien.lahoudere@collabora.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to simplify derivated drivers from cros_ec_sensors_core, a new core function is created to registered IIO stricture. Signed-off-by: Fabien Lahoudere --- .../common/cros_ec_sensors/cros_ec_sensors.c | 9 +- .../cros_ec_sensors/cros_ec_sensors_core.c | 97 ++++++++++++------- drivers/iio/light/cros_ec_light_prox.c | 7 +- drivers/iio/pressure/cros_ec_baro.c | 7 +- .../linux/iio/common/cros_ec_sensors_core.h | 16 ++- 5 files changed, 72 insertions(+), 64 deletions(-) diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c index 897dc83a3355..c4bee9265246 100644 --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c @@ -14,7 +14,7 @@ #include #include #include -#include + #include #include #include @@ -233,12 +233,7 @@ static int cros_ec_sensors_probe(struct platform_device *pdev) else state->core.read_ec_sensors_data = cros_ec_sensors_read_cmd; - ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, - cros_ec_sensors_capture, NULL); - if (ret) - return ret; - - return devm_iio_device_register(dev, indio_dev); + return cros_ec_sensors_core_register(pdev, indio_dev); } static const struct platform_device_id cros_ec_sensors_ids[] = { diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c index e5181e007dd7..3880849c5cca 100644 --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -95,6 +96,67 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, } EXPORT_SYMBOL_GPL(cros_ec_sensors_core_init); +/** + * cros_ec_sensors_capture() - the trigger handler function + * @irq: the interrupt number. + * @p: a pointer to the poll function. + * + * On a trigger event occurring, if the pollfunc is attached then this + * handler is called as a threaded interrupt (and hence may sleep). It + * is responsible for grabbing data from the device and pushing it into + * the associated buffer. + * + * Return: IRQ_HANDLED + */ +static irqreturn_t cros_ec_sensors_capture(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct cros_ec_sensors_core_state *st = iio_priv(indio_dev); + int ret; + + mutex_lock(&st->cmd_lock); + + /* Clear capture data. */ + memset(st->samples, 0, indio_dev->scan_bytes); + + /* Read data based on which channels are enabled in scan mask. */ + ret = st->read_ec_sensors_data(indio_dev, + *indio_dev->active_scan_mask, + (s16 *)st->samples); + if (ret < 0) + goto done; + + iio_push_to_buffers_with_timestamp(indio_dev, st->samples, + iio_get_time_ns(indio_dev)); + +done: + /* + * Tell the core we are done with this trigger and ready for the + * next one. + */ + iio_trigger_notify_done(indio_dev->trig); + + mutex_unlock(&st->cmd_lock); + + return IRQ_HANDLED; +} + +int cros_ec_sensors_core_register(struct platform_device *pdev, + struct iio_dev *indio_dev) +{ + int ret; + struct device *dev = &pdev->dev; + + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, + cros_ec_sensors_capture, NULL); + if (ret) + return ret; + + return devm_iio_device_register(dev, indio_dev); +} +EXPORT_SYMBOL_GPL(cros_ec_sensors_core_register); + int cros_ec_motion_send_host_cmd(struct cros_ec_sensors_core_state *state, u16 opt_length) { @@ -380,41 +442,6 @@ int cros_ec_sensors_read_cmd(struct iio_dev *indio_dev, } EXPORT_SYMBOL_GPL(cros_ec_sensors_read_cmd); -irqreturn_t cros_ec_sensors_capture(int irq, void *p) -{ - struct iio_poll_func *pf = p; - struct iio_dev *indio_dev = pf->indio_dev; - struct cros_ec_sensors_core_state *st = iio_priv(indio_dev); - int ret; - - mutex_lock(&st->cmd_lock); - - /* Clear capture data. */ - memset(st->samples, 0, indio_dev->scan_bytes); - - /* Read data based on which channels are enabled in scan mask. */ - ret = st->read_ec_sensors_data(indio_dev, - *(indio_dev->active_scan_mask), - (s16 *)st->samples); - if (ret < 0) - goto done; - - iio_push_to_buffers_with_timestamp(indio_dev, st->samples, - iio_get_time_ns(indio_dev)); - -done: - /* - * Tell the core we are done with this trigger and ready for the - * next one. - */ - iio_trigger_notify_done(indio_dev->trig); - - mutex_unlock(&st->cmd_lock); - - return IRQ_HANDLED; -} -EXPORT_SYMBOL_GPL(cros_ec_sensors_capture); - int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st, struct iio_chan_spec const *chan, int *val, int *val2, long mask) diff --git a/drivers/iio/light/cros_ec_light_prox.c b/drivers/iio/light/cros_ec_light_prox.c index 32ea5afd495f..682dc19c2bf3 100644 --- a/drivers/iio/light/cros_ec_light_prox.c +++ b/drivers/iio/light/cros_ec_light_prox.c @@ -215,12 +215,7 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev) state->core.read_ec_sensors_data = cros_ec_sensors_read_cmd; - ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, - cros_ec_sensors_capture, NULL); - if (ret) - return ret; - - return devm_iio_device_register(dev, indio_dev); + return cros_ec_sensors_core_register(pdev, indio_dev); } static const struct platform_device_id cros_ec_light_prox_ids[] = { diff --git a/drivers/iio/pressure/cros_ec_baro.c b/drivers/iio/pressure/cros_ec_baro.c index 8718036d74d2..9d3745bc2fba 100644 --- a/drivers/iio/pressure/cros_ec_baro.c +++ b/drivers/iio/pressure/cros_ec_baro.c @@ -152,12 +152,7 @@ static int cros_ec_baro_probe(struct platform_device *pdev) state->core.read_ec_sensors_data = cros_ec_sensors_read_cmd; - ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, - cros_ec_sensors_capture, NULL); - if (ret) - return ret; - - return devm_iio_device_register(dev, indio_dev); + return cros_ec_sensors_core_register(pdev, indio_dev); } static const struct platform_device_id cros_ec_baro_ids[] = { diff --git a/include/linux/iio/common/cros_ec_sensors_core.h b/include/linux/iio/common/cros_ec_sensors_core.h index 485c649b421f..60f40d253f4a 100644 --- a/include/linux/iio/common/cros_ec_sensors_core.h +++ b/include/linux/iio/common/cros_ec_sensors_core.h @@ -116,18 +116,14 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, bool physical_device); /** - * cros_ec_sensors_capture() - the trigger handler function - * @irq: the interrupt number. - * @p: a pointer to the poll function. - * - * On a trigger event occurring, if the pollfunc is attached then this - * handler is called as a threaded interrupt (and hence may sleep). It - * is responsible for grabbing data from the device and pushing it into - * the associated buffer. + * cros_ec_sensors_core_register() - registration of the core structure + * @pdev: platform device created for the sensors + * @indio_dev: iio device structure of the device * - * Return: IRQ_HANDLED + * Return: 0 on success, -errno on failure. */ -irqreturn_t cros_ec_sensors_capture(int irq, void *p); +int cros_ec_sensors_core_register(struct platform_device *pdev, + struct iio_dev *indio_dev); /** * cros_ec_core_channel_init() - initialize channel -- 2.20.1