From: Eric Anholt <eric@anholt.net> To: dri-devel@lists.freedesktop.org Cc: linux-arm-msm@vger.kernel.org, Seung-Woo Kim <sw0312.kim@samsung.com>, linux-kernel@vger.kernel.org, Kyungmin Park <kyungmin.park@samsung.com> Subject: [PATCH v2 3/4] drm: Move exynos "match_add all devices matching my drivers" to core. Date: Thu, 17 Sep 2015 10:57:57 -0400 [thread overview] Message-ID: <1442501878-9037-3-git-send-email-eric@anholt.net> (raw) In-Reply-To: <1442501878-9037-1-git-send-email-eric@anholt.net> This is a really nice way to handle the component setup. The subsystem driver knows that it's got a bunch of component drivers, and for any devices that matched its component drivers, it wants all of those to bind to it as master. Signed-off-by: Eric Anholt <eric@anholt.net> --- v2: Extend the kerneldoc. drivers/gpu/drm/drm_platform_helper.c | 40 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/exynos/exynos_drm_drv.c | 37 ++++++------------------------ include/drm/drmP.h | 5 +++++ 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/drivers/gpu/drm/drm_platform_helper.c b/drivers/gpu/drm/drm_platform_helper.c index 450846f..c4f03541 100644 --- a/drivers/gpu/drm/drm_platform_helper.c +++ b/drivers/gpu/drm/drm_platform_helper.c @@ -7,6 +7,7 @@ * option) any later version. */ +#include <linux/component.h> #include <drm/drmP.h> /** @@ -51,3 +52,42 @@ void drm_platform_unregister_drivers(struct platform_driver *const *drv, platform_driver_unregister(drv[count]); } EXPORT_SYMBOL_GPL(drm_platform_unregister_drivers); + +static int compare_dev(struct device *dev, void *data) +{ + return dev == (struct device *)data; +} + +/** + * drm_platform_component_match_add_drivers - For each driver passed + * in, finds each device that probed with it and adds it as a component + * driver to the match list. + * @dev: master device for the components + * @match: pointer to the match structure pointer. For the first + * component_match_add(), this should be a pointer to a NULL + * pointer, which will get filled in by the call. + * @drivers: array of platform drivers whose devices should all be + * added to the match + * @count: number of platform drivers to match + */ +void drm_platform_component_match_add_drivers(struct device *dev, + struct component_match **match, + struct platform_driver *const *drivers, + int count) +{ + int i; + + for (i = 0; i < count; i++) { + struct device_driver *drv = &drivers[i]->driver; + struct device *p = NULL, *d; + + while ((d = bus_find_device(&platform_bus_type, p, drv, + (void *)platform_bus_type.match))) { + put_device(p); + component_match_add(dev, match, compare_dev, d); + p = d; + } + put_device(p); + } +} +EXPORT_SYMBOL_GPL(drm_platform_component_match_add_drivers); diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c index 83f829b..9151304 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c @@ -412,32 +412,6 @@ static struct platform_driver *const exynos_drm_drv_with_simple_dev[] = { }; #define PDEV_COUNT ARRAY_SIZE(exynos_drm_drv_with_simple_dev) -static int compare_dev(struct device *dev, void *data) -{ - return dev == (struct device *)data; -} - -static struct component_match *exynos_drm_match_add(struct device *dev) -{ - struct component_match *match = NULL; - int i; - - for (i = 0; i < ARRAY_SIZE(exynos_drm_kms_drivers); ++i) { - struct device_driver *drv = &exynos_drm_kms_drivers[i]->driver; - struct device *p = NULL, *d; - - while ((d = bus_find_device(&platform_bus_type, p, drv, - (void *)platform_bus_type.match))) { - put_device(p); - component_match_add(dev, &match, compare_dev, d); - p = d; - } - put_device(p); - } - - return match ?: ERR_PTR(-ENODEV); -} - static int exynos_drm_bind(struct device *dev) { return drm_platform_init(&exynos_drm_driver, to_platform_device(dev)); @@ -455,14 +429,17 @@ static const struct component_master_ops exynos_drm_ops = { static int exynos_drm_platform_probe(struct platform_device *pdev) { - struct component_match *match; + struct component_match *match = NULL; pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls); - match = exynos_drm_match_add(&pdev->dev); - if (IS_ERR(match)) - return PTR_ERR(match); + drm_platform_component_match_add_drivers(&pdev->dev, &match, + exynos_drm_kms_drivers, + ARRAY_SIZE(exynos_drm_kms_drivers)); + + if (!match) + return -ENODEV; return component_master_add_with_match(&pdev->dev, &exynos_drm_ops, match); diff --git a/include/drm/drmP.h b/include/drm/drmP.h index a774574..b65d886 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -88,6 +88,7 @@ struct device_node; struct videomode; struct reservation_object; struct dma_buf_attachment; +struct component_match; /* * 4 debug categories are defined: @@ -1091,6 +1092,10 @@ int drm_platform_register_drivers(struct platform_driver *const *drv, int count); void drm_platform_unregister_drivers(struct platform_driver *const *drv, int count); +void drm_platform_component_match_add_drivers(struct device *dev, + struct component_match **match, + struct platform_driver **drivers, + int count); /* returns true if currently okay to sleep */ static __inline__ bool drm_can_sleep(void) -- 2.1.4 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/dri-devel
WARNING: multiple messages have this Message-ID (diff)
From: Eric Anholt <eric@anholt.net> To: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, David Airlie <airlied@linux.ie>, Inki Dae <inki.dae@samsung.com>, Joonyoung Shim <jy0922.shim@samsung.com>, Seung-Woo Kim <sw0312.kim@samsung.com>, Kyungmin Park <kyungmin.park@samsung.com>, linux-arm-msm@vger.kernel.org, Rob Clark <robdclark@gmail.com>, Eric Anholt <eric@anholt.net> Subject: [PATCH v2 3/4] drm: Move exynos "match_add all devices matching my drivers" to core. Date: Thu, 17 Sep 2015 10:57:57 -0400 [thread overview] Message-ID: <1442501878-9037-3-git-send-email-eric@anholt.net> (raw) In-Reply-To: <1442501878-9037-1-git-send-email-eric@anholt.net> This is a really nice way to handle the component setup. The subsystem driver knows that it's got a bunch of component drivers, and for any devices that matched its component drivers, it wants all of those to bind to it as master. Signed-off-by: Eric Anholt <eric@anholt.net> --- v2: Extend the kerneldoc. drivers/gpu/drm/drm_platform_helper.c | 40 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/exynos/exynos_drm_drv.c | 37 ++++++------------------------ include/drm/drmP.h | 5 +++++ 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/drivers/gpu/drm/drm_platform_helper.c b/drivers/gpu/drm/drm_platform_helper.c index 450846f..c4f03541 100644 --- a/drivers/gpu/drm/drm_platform_helper.c +++ b/drivers/gpu/drm/drm_platform_helper.c @@ -7,6 +7,7 @@ * option) any later version. */ +#include <linux/component.h> #include <drm/drmP.h> /** @@ -51,3 +52,42 @@ void drm_platform_unregister_drivers(struct platform_driver *const *drv, platform_driver_unregister(drv[count]); } EXPORT_SYMBOL_GPL(drm_platform_unregister_drivers); + +static int compare_dev(struct device *dev, void *data) +{ + return dev == (struct device *)data; +} + +/** + * drm_platform_component_match_add_drivers - For each driver passed + * in, finds each device that probed with it and adds it as a component + * driver to the match list. + * @dev: master device for the components + * @match: pointer to the match structure pointer. For the first + * component_match_add(), this should be a pointer to a NULL + * pointer, which will get filled in by the call. + * @drivers: array of platform drivers whose devices should all be + * added to the match + * @count: number of platform drivers to match + */ +void drm_platform_component_match_add_drivers(struct device *dev, + struct component_match **match, + struct platform_driver *const *drivers, + int count) +{ + int i; + + for (i = 0; i < count; i++) { + struct device_driver *drv = &drivers[i]->driver; + struct device *p = NULL, *d; + + while ((d = bus_find_device(&platform_bus_type, p, drv, + (void *)platform_bus_type.match))) { + put_device(p); + component_match_add(dev, match, compare_dev, d); + p = d; + } + put_device(p); + } +} +EXPORT_SYMBOL_GPL(drm_platform_component_match_add_drivers); diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c index 83f829b..9151304 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c @@ -412,32 +412,6 @@ static struct platform_driver *const exynos_drm_drv_with_simple_dev[] = { }; #define PDEV_COUNT ARRAY_SIZE(exynos_drm_drv_with_simple_dev) -static int compare_dev(struct device *dev, void *data) -{ - return dev == (struct device *)data; -} - -static struct component_match *exynos_drm_match_add(struct device *dev) -{ - struct component_match *match = NULL; - int i; - - for (i = 0; i < ARRAY_SIZE(exynos_drm_kms_drivers); ++i) { - struct device_driver *drv = &exynos_drm_kms_drivers[i]->driver; - struct device *p = NULL, *d; - - while ((d = bus_find_device(&platform_bus_type, p, drv, - (void *)platform_bus_type.match))) { - put_device(p); - component_match_add(dev, &match, compare_dev, d); - p = d; - } - put_device(p); - } - - return match ?: ERR_PTR(-ENODEV); -} - static int exynos_drm_bind(struct device *dev) { return drm_platform_init(&exynos_drm_driver, to_platform_device(dev)); @@ -455,14 +429,17 @@ static const struct component_master_ops exynos_drm_ops = { static int exynos_drm_platform_probe(struct platform_device *pdev) { - struct component_match *match; + struct component_match *match = NULL; pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls); - match = exynos_drm_match_add(&pdev->dev); - if (IS_ERR(match)) - return PTR_ERR(match); + drm_platform_component_match_add_drivers(&pdev->dev, &match, + exynos_drm_kms_drivers, + ARRAY_SIZE(exynos_drm_kms_drivers)); + + if (!match) + return -ENODEV; return component_master_add_with_match(&pdev->dev, &exynos_drm_ops, match); diff --git a/include/drm/drmP.h b/include/drm/drmP.h index a774574..b65d886 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -88,6 +88,7 @@ struct device_node; struct videomode; struct reservation_object; struct dma_buf_attachment; +struct component_match; /* * 4 debug categories are defined: @@ -1091,6 +1092,10 @@ int drm_platform_register_drivers(struct platform_driver *const *drv, int count); void drm_platform_unregister_drivers(struct platform_driver *const *drv, int count); +void drm_platform_component_match_add_drivers(struct device *dev, + struct component_match **match, + struct platform_driver **drivers, + int count); /* returns true if currently okay to sleep */ static __inline__ bool drm_can_sleep(void) -- 2.1.4
next prev parent reply other threads:[~2015-09-17 14:57 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-09-17 14:57 [PATCH v2 1/4] drm: Put platform driver registration/unregistration loops in core Eric Anholt 2015-09-17 14:57 ` Eric Anholt 2015-09-17 14:57 ` [PATCH v2 2/4] drm/msm: Use drm_platform_register/unregister_drivers() Eric Anholt 2015-09-17 14:57 ` Eric Anholt [this message] 2015-09-17 14:57 ` [PATCH v2 3/4] drm: Move exynos "match_add all devices matching my drivers" to core Eric Anholt 2015-09-17 14:57 ` [PATCH v2 4/4] drm/msm: Use exynos's model for handling component driver matching Eric Anholt 2015-09-17 14:57 ` Eric Anholt 2015-09-17 19:19 ` Rob Clark
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=1442501878-9037-3-git-send-email-eric@anholt.net \ --to=eric@anholt.net \ --cc=dri-devel@lists.freedesktop.org \ --cc=kyungmin.park@samsung.com \ --cc=linux-arm-msm@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=sw0312.kim@samsung.com \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.