Skip to content

Commit d85a2d6

Browse files
committed
ARM: OMAP2+: Populate legacy resources for dma and smartreflex
We can populate the legacy resources needed by dma and smartreflex from device tree in omap_device_build(). There should be no need to do this for other devices, and eventually these two remaining users will be gone too. The legacy dma will be dropped when the remaining users have been converted to use the dmaengine driver, and smartreflex can now become just a regular device driver with a few pdata callbacks. This is needed in order to remove remaining device dma, irq and io resources from the interconnect code. And while at it, let's simplify things by removing otherwise unused omap_device_build_ss() as we will never call it for more than one hwmod. Cc: "Benoît Cousson" <[email protected]> Cc: Lokesh Vutla <[email protected]> Cc: Nishanth Menon <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Tero Kristo <[email protected]> Signed-off-by: Tony Lindgren <[email protected]>
1 parent 6c72b35 commit d85a2d6

File tree

2 files changed

+106
-35
lines changed

2 files changed

+106
-35
lines changed

arch/arm/mach-omap2/omap_device.c

Lines changed: 106 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include <linux/pm_domain.h>
3636
#include <linux/pm_runtime.h>
3737
#include <linux/of.h>
38+
#include <linux/of_address.h>
39+
#include <linux/of_irq.h>
3840
#include <linux/notifier.h>
3941

4042
#include "common.h"
@@ -521,6 +523,91 @@ void omap_device_delete(struct omap_device *od)
521523
kfree(od);
522524
}
523525

526+
/**
527+
* omap_device_copy_resources - Add legacy IO and IRQ resources
528+
* @oh: interconnect target module
529+
* @pdev: platform device to copy resources to
530+
*
531+
* We still have legacy DMA and smartreflex needing resources.
532+
* Let's populate what they need until we can eventually just
533+
* remove this function. Note that there should be no need to
534+
* call this from omap_device_build_from_dt(), nor should there
535+
* be any need to call it for other devices.
536+
*/
537+
static int
538+
omap_device_copy_resources(struct omap_hwmod *oh,
539+
struct platform_device *pdev)
540+
{
541+
struct device_node *np, *child;
542+
struct property *prop;
543+
struct resource *res;
544+
const char *name;
545+
int error, irq = 0;
546+
547+
if (!oh || !oh->od || !oh->od->pdev) {
548+
error = -EINVAL;
549+
goto error;
550+
}
551+
552+
np = oh->od->pdev->dev.of_node;
553+
if (!np) {
554+
error = -ENODEV;
555+
goto error;
556+
}
557+
558+
res = kzalloc(sizeof(*res) * 2, GFP_KERNEL);
559+
if (!res)
560+
return -ENOMEM;
561+
562+
/* Do we have a dts range for the interconnect target module? */
563+
error = omap_hwmod_parse_module_range(oh, np, res);
564+
565+
/* No ranges, rely on device reg entry */
566+
if (error)
567+
error = of_address_to_resource(np, 0, res);
568+
if (error)
569+
goto free;
570+
571+
/* SmartReflex needs first IO resource name to be "mpu" */
572+
res[0].name = "mpu";
573+
574+
/*
575+
* We may have a configured "ti,sysc" interconnect target with a
576+
* dts child with the interrupt. If so use the first child's
577+
* first interrupt for "ti-hwmods" legacy support.
578+
*/
579+
of_property_for_each_string(np, "compatible", prop, name)
580+
if (!strncmp("ti,sysc-", name, 8))
581+
break;
582+
583+
child = of_get_next_available_child(np, NULL);
584+
585+
if (name)
586+
irq = irq_of_parse_and_map(child, 0);
587+
if (!irq)
588+
irq = irq_of_parse_and_map(np, 0);
589+
if (!irq)
590+
goto free;
591+
592+
/* Legacy DMA code needs interrupt name to be "0" */
593+
res[1].start = irq;
594+
res[1].end = irq;
595+
res[1].flags = IORESOURCE_IRQ;
596+
res[1].name = "0";
597+
598+
error = platform_device_add_resources(pdev, res, 2);
599+
600+
free:
601+
kfree(res);
602+
603+
error:
604+
WARN(error, "%s: %s device %s failed: %i\n",
605+
__func__, oh->name, dev_name(&pdev->dev),
606+
error);
607+
608+
return error;
609+
}
610+
524611
/**
525612
* omap_device_build - build and register an omap_device with one omap_hwmod
526613
* @pdev_name: name of the platform_device driver to use
@@ -539,46 +626,25 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
539626
int pdev_id,
540627
struct omap_hwmod *oh,
541628
void *pdata, int pdata_len)
542-
{
543-
struct omap_hwmod *ohs[] = { oh };
544-
545-
if (!oh)
546-
return ERR_PTR(-EINVAL);
547-
548-
return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
549-
pdata_len);
550-
}
551-
552-
/**
553-
* omap_device_build_ss - build and register an omap_device with multiple hwmods
554-
* @pdev_name: name of the platform_device driver to use
555-
* @pdev_id: this platform_device's connection ID
556-
* @oh: ptr to the single omap_hwmod that backs this omap_device
557-
* @pdata: platform_data ptr to associate with the platform_device
558-
* @pdata_len: amount of memory pointed to by @pdata
559-
*
560-
* Convenience function for building and registering an omap_device
561-
* subsystem record. Subsystem records consist of multiple
562-
* omap_hwmods. This function in turn builds and registers a
563-
* platform_device record. Returns an ERR_PTR() on error, or passes
564-
* along the return value of omap_device_register().
565-
*/
566-
struct platform_device __init *omap_device_build_ss(const char *pdev_name,
567-
int pdev_id,
568-
struct omap_hwmod **ohs,
569-
int oh_cnt, void *pdata,
570-
int pdata_len)
571629
{
572630
int ret = -ENOMEM;
573631
struct platform_device *pdev;
574632
struct omap_device *od;
575633

576-
if (!ohs || oh_cnt == 0 || !pdev_name)
634+
if (!oh || !pdev_name)
577635
return ERR_PTR(-EINVAL);
578636

579637
if (!pdata && pdata_len > 0)
580638
return ERR_PTR(-EINVAL);
581639

640+
if (strncmp(oh->name, "smartreflex", 11) &&
641+
strncmp(oh->name, "dma", 3)) {
642+
pr_warn("%s need to update %s to probe with dt\na",
643+
__func__, pdev_name);
644+
ret = -ENODEV;
645+
goto odbs_exit;
646+
}
647+
582648
pdev = platform_device_alloc(pdev_name, pdev_id);
583649
if (!pdev) {
584650
ret = -ENOMEM;
@@ -591,7 +657,16 @@ struct platform_device __init *omap_device_build_ss(const char *pdev_name,
591657
else
592658
dev_set_name(&pdev->dev, "%s", pdev->name);
593659

594-
od = omap_device_alloc(pdev, ohs, oh_cnt);
660+
/*
661+
* Must be called before omap_device_alloc() as oh->od
662+
* only contains the currently registered omap_device
663+
* and will get overwritten by omap_device_alloc().
664+
*/
665+
ret = omap_device_copy_resources(oh, pdev);
666+
if (ret)
667+
goto odbs_exit1;
668+
669+
od = omap_device_alloc(pdev, &oh, 1);
595670
if (IS_ERR(od))
596671
goto odbs_exit1;
597672

arch/arm/mach-omap2/omap_device.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
7575
struct omap_hwmod *oh, void *pdata,
7676
int pdata_len);
7777

78-
struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
79-
struct omap_hwmod **oh, int oh_cnt,
80-
void *pdata, int pdata_len);
81-
8278
struct omap_device *omap_device_alloc(struct platform_device *pdev,
8379
struct omap_hwmod **ohs, int oh_cnt);
8480
void omap_device_delete(struct omap_device *od);

0 commit comments

Comments
 (0)