From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Rodolfo Giometti <giometti@enneenne.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-kernel@vger.kernel.org
Cc: Ryan Govostes <rgovostes@whoi.edu>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH v2 6/7] pps: clients: gpio: Use struct device pointer directly
Date: Thu, 18 Mar 2021 15:03:20 +0200 [thread overview]
Message-ID: <20210318130321.24227-6-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20210318130321.24227-1-andriy.shevchenko@linux.intel.com>
In most parts of the code the platform device is not used.
Use struct device pointer directly to reduce code size and
increase readability.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Rodolfo Giometti <giometti@enneenne.com>
---
drivers/pps/clients/pps-gpio.c | 42 +++++++++++++++-------------------
1 file changed, 19 insertions(+), 23 deletions(-)
diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
index c6db3a3b257b..b097da5a659a 100644
--- a/drivers/pps/clients/pps-gpio.c
+++ b/drivers/pps/clients/pps-gpio.c
@@ -99,45 +99,39 @@ static void pps_gpio_echo_timer_callback(struct timer_list *t)
gpiod_set_value(info->echo_pin, 0);
}
-static int pps_gpio_setup(struct platform_device *pdev)
+static int pps_gpio_setup(struct device *dev)
{
- struct pps_gpio_device_data *data = platform_get_drvdata(pdev);
+ struct pps_gpio_device_data *data = dev_get_drvdata(dev);
int ret;
u32 value;
- data->gpio_pin = devm_gpiod_get(&pdev->dev,
- NULL, /* request "gpios" */
- GPIOD_IN);
+ data->gpio_pin = devm_gpiod_get(dev, NULL, GPIOD_IN);
if (IS_ERR(data->gpio_pin))
- return dev_err_probe(&pdev->dev, PTR_ERR(data->gpio_pin),
+ return dev_err_probe(dev, PTR_ERR(data->gpio_pin),
"failed to request PPS GPIO\n");
- data->echo_pin = devm_gpiod_get_optional(&pdev->dev,
- "echo",
- GPIOD_OUT_LOW);
+ data->echo_pin = devm_gpiod_get_optional(dev, "echo", GPIOD_OUT_LOW);
if (IS_ERR(data->echo_pin))
- return dev_err_probe(&pdev->dev, PTR_ERR(data->echo_pin),
+ return dev_err_probe(dev, PTR_ERR(data->echo_pin),
"failed to request ECHO GPIO\n");
if (data->echo_pin) {
- ret = device_property_read_u32(&pdev->dev, "echo-active-ms", &value);
+ ret = device_property_read_u32(dev, "echo-active-ms", &value);
if (ret) {
- dev_err(&pdev->dev,
- "failed to get echo-active-ms from FW\n");
+ dev_err(dev, "failed to get echo-active-ms from FW\n");
return ret;
}
data->echo_active_ms = value;
/* sanity check on echo_active_ms */
if (!data->echo_active_ms || data->echo_active_ms > 999) {
- dev_err(&pdev->dev,
- "echo-active-ms: %u - bad value from FW\n",
+ dev_err(dev, "echo-active-ms: %u - bad value from FW\n",
data->echo_active_ms);
return -EINVAL;
}
}
data->assert_falling_edge =
- device_property_read_bool(&pdev->dev, "assert-falling-edge");
+ device_property_read_bool(dev, "assert-falling-edge");
return 0;
}
@@ -158,24 +152,26 @@ get_irqf_trigger_flags(const struct pps_gpio_device_data *data)
static int pps_gpio_probe(struct platform_device *pdev)
{
struct pps_gpio_device_data *data;
+ struct device *dev = &pdev->dev;
int ret;
int pps_default_params;
/* allocate space for device info */
- data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+ data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
- platform_set_drvdata(pdev, data);
+
+ dev_set_drvdata(dev, data);
/* GPIO setup */
- ret = pps_gpio_setup(pdev);
+ ret = pps_gpio_setup(dev);
if (ret)
return -EINVAL;
/* IRQ setup */
ret = gpiod_to_irq(data->gpio_pin);
if (ret < 0) {
- dev_err(&pdev->dev, "failed to map GPIO to IRQ: %d\n", ret);
+ dev_err(dev, "failed to map GPIO to IRQ: %d\n", ret);
return -EINVAL;
}
data->irq = ret;
@@ -201,17 +197,17 @@ static int pps_gpio_probe(struct platform_device *pdev)
pps_default_params |= PPS_CAPTURECLEAR | PPS_OFFSETCLEAR;
data->pps = pps_register_source(&data->info, pps_default_params);
if (IS_ERR(data->pps)) {
- dev_err(&pdev->dev, "failed to register IRQ %d as PPS source\n",
+ dev_err(dev, "failed to register IRQ %d as PPS source\n",
data->irq);
return PTR_ERR(data->pps);
}
/* register IRQ interrupt handler */
- ret = devm_request_irq(&pdev->dev, data->irq, pps_gpio_irq_handler,
+ ret = devm_request_irq(dev, data->irq, pps_gpio_irq_handler,
get_irqf_trigger_flags(data), data->info.name, data);
if (ret) {
pps_unregister_source(data->pps);
- dev_err(&pdev->dev, "failed to acquire IRQ %d\n", data->irq);
+ dev_err(dev, "failed to acquire IRQ %d\n", data->irq);
return -EINVAL;
}
--
2.30.2
next prev parent reply other threads:[~2021-03-18 13:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-18 13:03 [PATCH v2 1/7] pps: clients: gpio: Bail out on error when requesting GPIO echo line Andy Shevchenko
2021-03-18 13:03 ` [PATCH v2 2/7] pps: clients: gpio: Use dev_err_probe() to avoid log noise Andy Shevchenko
2021-03-18 13:03 ` [PATCH v2 3/7] pps: clients: gpio: Remove redundant condition in ->remove() Andy Shevchenko
2021-03-18 13:03 ` [PATCH v2 4/7] pps: clients: gpio: Get rid of legacy platform data Andy Shevchenko
2021-03-18 13:03 ` [PATCH v2 5/7] pps: clients: gpio: Make use of device properties Andy Shevchenko
2021-03-18 13:03 ` Andy Shevchenko [this message]
2021-03-18 13:03 ` [PATCH v2 7/7] pps: clients: gpio: Rearrange optional stuff in pps_gpio_setup() Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210318130321.24227-6-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=giometti@enneenne.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rgovostes@whoi.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).