Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1265878

Re: Grafting old platform drivers onto a new DT kernel

From Måns Rullgård <mans@mansr.com>
Newsgroups linux.kernel
Subject Re: Grafting old platform drivers onto a new DT kernel
Date 2015-11-09 18:20 +0100
Message-ID <qsYgP-UW-33@gated-at.bofh.it> (permalink)
References (3 earlier) <qsWoF-89v-5@gated-at.bofh.it> <qsWRI-8jE-9@gated-at.bofh.it> <qsXb4-dY-3@gated-at.bofh.it> <qsXkK-i7-39@gated-at.bofh.it> <qsY78-QC-19@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Mason <slash.tmp@free.fr> writes:

> On 09/11/2015 17:12, Måns Rullgård wrote:
>
>> Mason writes:
>> 
>>> On 09/11/2015 16:40, Måns Rullgård wrote:
>>>
>>>> The simplest solution for you is probably to add a quick and dirty DT
>>>> binding to the old driver.  If it doesn't use any driver-specific
>>>> platform data struct, you only need to set .of_match_table in the
>>>> struct platform_driver.  If there is a platform data struct, you'll also
>>>> need to write some code to populate it from DT properties.  It shouldn't
>>>> take more than a few minutes per driver in most cases.
>>>
>>> I'll try that approach, although I fear that "a few minutes per driver"
>>> is an optimistic assessment.
>> 
>> If the driver only needs an MMIO region and an IRQ, it is literally five
>> lines of code.
>
> It took me 7 days to figure out there were 2 lines missing in the
> interrupt controller driver.
>
> My problem is that I don't understand the platform API, nor the
> interaction with the DT API.
>
> Let me see...
>
> In arch/arm/mach-tangox/platform_dev.c
>
> static struct platform_device tangox_sdhci0_device = { ... };
> static struct platform_device tangox_sdhci1_device = { ... };
>
> static void tangox_init_sdhci(void)
> {
> 	if (tangox_sdio_enabled(0))
> 		platform_device_register(&tangox_sdhci0_device);
>
> 	if (tangox_sdio_enabled(1))
> 		platform_device_register(&tangox_sdhci1_device);
> }
>
> called from tangox_init_devices() which is marked arch_initcall.

Delete all of that.  The generic DT code will create the platform
devices based on the device tree.

> In the driver

Add something like this:

static const struct of_device_id tangox_sdio_dt_ids[] = {
	{ .compatible = "sigma,tangox-sdio" },
	{ }
};

> static struct platform_driver tangox_platform_sdio0 = {

	.probe		= sdhci_tangox_probe,

> 	.remove		= sdhci_tangox_remove,
> 	.suspend	= sdhci_tangox_suspend,
> 	.resume		= sdhci_tangox_resume,
> 	.driver		= {
> 		.name	= "tangox-sdhci",
> 		.owner	= THIS_MODULE,

		.of_match_table = tangox_sdio_dt_ids,

> 	},
> };

And that should be it.

> static int __init tangox_sdhci_drv_init(void) {
> 	return platform_driver_probe(&tangox_platform_sdio0, sdhci_tangox_probe);
> }
>
> static void __exit tangox_sdhci_drv_exit(void) {
> 	platform_driver_unregister(&tangox_platform_sdio0);
> }
>
> module_init(tangox_sdhci_drv_init);
> module_exit(tangox_sdhci_drv_exit);

You can replace those functions and module_init()/module_exit() with
module_platform_driver() if you want.

> The old way:
>
> 1) call platform_device_register() with a "struct platform_device"
> 2) call platform_driver_probe with a "struct platform_driver"
>
> The new way(?)
>
> The mess in 2) is hidden behind module_platform_driver?

module_platform_driver() is just a macro that creates standard driver
register/unregister functions much like the ones above.

> The platform_device_register() is done by the DT core?

Correct.

> The struct platform_driver requires a probe function?

That's the usual way.

-- 
Måns Rullgård
mans@mansr.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Grafting old platform drivers onto a new DT kernel Mason <slash.tmp@free.fr> - 2015-11-05 12:10 +0100
  Re: Grafting old platform drivers onto a new DT kernel Andrew Lunn <andrew@lunn.ch> - 2015-11-05 16:20 +0100
    Re: Grafting old platform drivers onto a new DT kernel Javier Martinez Canillas <javier@dowhile0.org> - 2015-11-05 16:50 +0100
      Re: Grafting old platform drivers onto a new DT kernel Mason <slash.tmp@free.fr> - 2015-11-09 16:20 +0100
        Re: Grafting old platform drivers onto a new DT kernel Marc Zyngier <marc.zyngier@arm.com> - 2015-11-09 16:40 +0100
        Re: Grafting old platform drivers onto a new DT kernel Måns Rullgård <mans@mansr.com> - 2015-11-09 16:50 +0100
          Re: Grafting old platform drivers onto a new DT kernel Mason <slash.tmp@free.fr> - 2015-11-09 17:10 +0100
            Re: Grafting old platform drivers onto a new DT kernel Måns Rullgård <mans@mansr.com> - 2015-11-09 17:20 +0100
              Re: Grafting old platform drivers onto a new DT kernel Mason <slash.tmp@free.fr> - 2015-11-09 18:10 +0100
                Re: Grafting old platform drivers onto a new DT kernel Måns Rullgård <mans@mansr.com> - 2015-11-09 18:20 +0100
                Re: Grafting old platform drivers onto a new DT kernel Mason <slash.tmp@free.fr> - 2015-11-10 13:50 +0100
                Re: Grafting old platform drivers onto a new DT kernel Arnd Bergmann <arnd@arndb.de> - 2015-11-10 14:00 +0100
        Re: Grafting old platform drivers onto a new DT kernel Russell King - ARM Linux <linux@arm.linux.org.uk> - 2015-11-09 17:30 +0100

csiph-web