linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Gmeiner <christian.gmeiner@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Mark Brown <broonie@kernel.org>, linux-spi@vger.kernel.org
Subject: Re: [PATCH] spidev: add platform driver support
Date: Wed, 16 Jun 2021 21:16:44 +0200	[thread overview]
Message-ID: <CAH9NwWfh9-2+kLoTXJgkVSStb1cHHvC-He5jnfFxMpUngMeAtA@mail.gmail.com> (raw)
In-Reply-To: <20210527084531.18989-1-christian.gmeiner@gmail.com>

ping

Am Do., 27. Mai 2021 um 10:45 Uhr schrieb Christian Gmeiner
<christian.gmeiner@gmail.com>:
>
> This makes it possible to use spidev in combination with the
> MFD subsystem. The MFD subsystem add platform_driver devices.
>
> Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
> ---
>  drivers/spi/spidev.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
>
> diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
> index f56e0e975a46..fb7b483ff70d 100644
> --- a/drivers/spi/spidev.c
> +++ b/drivers/spi/spidev.c
> @@ -25,6 +25,8 @@
>  #include <linux/spi/spi.h>
>  #include <linux/spi/spidev.h>
>
> +#include <linux/platform_device.h>
> +
>  #include <linux/uaccess.h>
>
>
> @@ -827,6 +829,40 @@ static struct spi_driver spidev_spi_driver = {
>          */
>  };
>
> +static int spidev_platform_probe(struct platform_device *pdev)
> +{
> +       struct device *parent = pdev->dev.parent;
> +       struct spi_device *spi;
> +
> +       if (strcmp(parent->bus->name, "spi"))
> +               return -ENODEV;
> +
> +       spi = to_spi_device(parent);
> +
> +       /* This only works if no drvdata is stored */
> +       if (spi_get_drvdata(spi)) {
> +               dev_err(&pdev->dev, "drvdata is not NULL\n");
> +               return -EOPNOTSUPP;
> +       }
> +
> +       return spidev_probe(spi);
> +}
> +
> +static int spidev_platform_remove(struct platform_device *pdev)
> +{
> +       struct spi_device *spi = to_spi_device(pdev->dev.parent);
> +
> +       return spidev_remove(spi);
> +}
> +
> +static struct platform_driver spidev_platfoem_driver = {
> +       .probe = spidev_platform_probe,
> +       .remove = spidev_platform_remove,
> +       .driver = {
> +               .name = "spidev",
> +       },
> +};
> +
>  /*-------------------------------------------------------------------------*/
>
>  static int __init spidev_init(void)
> @@ -853,12 +889,21 @@ static int __init spidev_init(void)
>                 class_destroy(spidev_class);
>                 unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
>         }
> +
> +       status = platform_driver_register(&spidev_platfoem_driver);
> +       if (status < 0) {
> +               spi_unregister_driver(&spidev_spi_driver);
> +               class_destroy(spidev_class);
> +               unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
> +       }
> +
>         return status;
>  }
>  module_init(spidev_init);
>
>  static void __exit spidev_exit(void)
>  {
> +       platform_driver_unregister(&spidev_platfoem_driver);
>         spi_unregister_driver(&spidev_spi_driver);
>         class_destroy(spidev_class);
>         unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
> --
> 2.31.1
>


-- 
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info/privacypolicy

  parent reply	other threads:[~2021-06-16 19:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-27  8:45 [PATCH] spidev: add platform driver support Christian Gmeiner
2021-05-27 10:10 ` Mark Brown
2021-06-16 19:16 ` Christian Gmeiner [this message]
2021-06-16 19:43   ` Mark Brown
2021-06-21 13:57     ` Christian Gmeiner
2021-06-21 14:41       ` Mark Brown

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=CAH9NwWfh9-2+kLoTXJgkVSStb1cHHvC-He5jnfFxMpUngMeAtA@mail.gmail.com \
    --to=christian.gmeiner@gmail.com \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    /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).