[PATCH 1/2] OMAP: VRFB: convert vrfb to platform device
This patch converts vrfb library into a platform device, in an effort to remove omap dependencies. The platform device is registered in arch/arm/plat-omap/fb.c and assigned resources depending on whether running on omap2 or omap3. The vrfb driver will parse those resources and use them to access vrfb configuration registers and the vrfb virtual rotation areas. Signed-off-by: Tomi Valkeinen Cc: Tony Lindgren --- arch/arm/plat-omap/fb.c| 53 +++ drivers/video/omap2/vrfb.c | 124 +--- 2 files changed, 157 insertions(+), 20 deletions(-) diff --git a/arch/arm/plat-omap/fb.c b/arch/arm/plat-omap/fb.c index dd6f92c..d231912 100644 --- a/arch/arm/plat-omap/fb.c +++ b/arch/arm/plat-omap/fb.c @@ -35,6 +35,59 @@ #include +#if defined(CONFIG_OMAP2_VRFB) +static const struct resource omap2_vrfb_resources[] = { + DEFINE_RES_MEM(0x68008000u, 0x40), + DEFINE_RES_MEM(0x7000u, 0x400), + DEFINE_RES_MEM(0x7400u, 0x400), + DEFINE_RES_MEM(0x7800u, 0x400), + DEFINE_RES_MEM(0x7c00u, 0x400), +}; + +static const struct resource omap3_vrfb_resources[] = { + DEFINE_RES_MEM(0x6C000180u, 0xc0), + DEFINE_RES_MEM(0x7000u, 0x400), + DEFINE_RES_MEM(0x7400u, 0x400), + DEFINE_RES_MEM(0x7800u, 0x400), + DEFINE_RES_MEM(0x7c00u, 0x400), + DEFINE_RES_MEM(0xe000u, 0x400), + DEFINE_RES_MEM(0xe400u, 0x400), + DEFINE_RES_MEM(0xe800u, 0x400), + DEFINE_RES_MEM(0xec00u, 0x400), + DEFINE_RES_MEM(0xf000u, 0x400), + DEFINE_RES_MEM(0xf400u, 0x400), + DEFINE_RES_MEM(0xf800u, 0x400), + DEFINE_RES_MEM(0xfc00u, 0x400), +}; + +static int __init omap_init_vrfb(void) +{ + struct platform_device *pdev; + const struct resource *res; + unsigned int num_res; + + if (cpu_is_omap24xx()) { + res = omap2_vrfb_resources; + num_res = ARRAY_SIZE(omap2_vrfb_resources); + } else if (cpu_is_omap34xx()) { + res = omap3_vrfb_resources; + num_res = ARRAY_SIZE(omap3_vrfb_resources); + } else { + return 0; + } + + pdev = platform_device_register_resndata(NULL, "omapvrfb", -1, + res, num_res, NULL, 0); + + if (IS_ERR(pdev)) + return PTR_ERR(pdev); + else + return 0; +} + +arch_initcall(omap_init_vrfb); +#endif + #if defined(CONFIG_FB_OMAP) || defined(CONFIG_FB_OMAP_MODULE) static bool omapfb_lcd_configured; diff --git a/drivers/video/omap2/vrfb.c b/drivers/video/omap2/vrfb.c index 7e99022..c072e37 100644 --- a/drivers/video/omap2/vrfb.c +++ b/drivers/video/omap2/vrfb.c @@ -26,9 +26,9 @@ #include #include #include +#include #include -#include #ifdef DEBUG #define DBG(format, ...) pr_debug("VRFB: " format, ## __VA_ARGS__) @@ -36,10 +36,10 @@ #define DBG(format, ...) #endif -#define SMS_ROT_VIRT_BASE(context, rot) \ - (((context >= 4) ? 0xD000 : 0x7000) \ -+ (0x400 * (context)) \ -+ (0x100 * (rot))) +#define SMS_ROT_CONTROL(context) (0x0 + 0x10 * context) +#define SMS_ROT_SIZE(context) (0x4 + 0x10 * context) +#define SMS_ROT_PHYSICAL_BA(context) (0x8 + 0x10 * context) +#define SMS_ROT_VIRT_BASE(rot) (0x100 * (rot)) #define OMAP_VRFB_SIZE (2048 * 2048 * 4) @@ -53,10 +53,16 @@ #define SMS_PW_OFFSET 4 #define SMS_PS_OFFSET 0 -#define VRFB_NUM_CTXS 12 /* bitmap of reserved contexts */ static unsigned long ctx_map; +struct vrfb_ctx { + u32 base; + u32 physical_ba; + u32 control; + u32 size; +}; + static DEFINE_MUTEX(ctx_lock); /* @@ -65,17 +71,32 @@ static DEFINE_MUTEX(ctx_lock); * we don't need locking, since no drivers will run until after the wake-up * has finished. */ -static struct { - u32 physical_ba; - u32 control; - u32 size; -} vrfb_hw_context[VRFB_NUM_CTXS]; + +static void __iomem *vrfb_base; + +static int num_ctxs; +static struct vrfb_ctx *ctxs; + +static void omap2_sms_write_rot_control(u32 val, unsigned ctx) +{ + __raw_writel(val, vrfb_base + SMS_ROT_CONTROL(ctx)); +} + +static void omap2_sms_write_rot_size(u32 val, unsigned ctx) +{ + __raw_writel(val, vrfb_base + SMS_ROT_SIZE(ctx)); +} + +static void omap2_sms_write_rot_physical_ba(u32 val, unsigned ctx) +{ + __raw_writel(val, vrfb_base + SMS_ROT_PHYSICAL_BA(ctx)); +} static inline void restore_hw_context(int ctx) { - omap2_sms_write_rot_control(vrfb_hw_context[ctx].control, ctx); - omap2_sms_write_rot_size(vrfb_hw_context[ctx].size, ctx); - omap2_sms_write_rot_physical_ba(vrfb_hw_context[ctx].physical_ba, ctx); + omap2_sms_write_rot_control(ctxs[ctx].control, ctx); + omap2_sms_write_rot_size(ctxs[ctx].size
Re: [PATCH 1/2] OMAP: VRFB: convert vrfb to platform device
* Tomi Valkeinen [121008 05:31]: > This patch converts vrfb library into a platform device, in an effort to > remove omap dependencies. > > The platform device is registered in arch/arm/plat-omap/fb.c and > assigned resources depending on whether running on omap2 or omap3. > > The vrfb driver will parse those resources and use them to access vrfb > configuration registers and the vrfb virtual rotation areas. > > Signed-off-by: Tomi Valkeinen > Cc: Tony Lindgren > --- > arch/arm/plat-omap/fb.c| 53 +++ > drivers/video/omap2/vrfb.c | 124 > +--- > 2 files changed, 157 insertions(+), 20 deletions(-) > > diff --git a/arch/arm/plat-omap/fb.c b/arch/arm/plat-omap/fb.c > index dd6f92c..d231912 100644 > --- a/arch/arm/plat-omap/fb.c > +++ b/arch/arm/plat-omap/fb.c > @@ -35,6 +35,59 @@ > > #include > > +#if defined(CONFIG_OMAP2_VRFB) > +static const struct resource omap2_vrfb_resources[] = { > + DEFINE_RES_MEM(0x68008000u, 0x40), > + DEFINE_RES_MEM(0x7000u, 0x400), > + DEFINE_RES_MEM(0x7400u, 0x400), > + DEFINE_RES_MEM(0x7800u, 0x400), > + DEFINE_RES_MEM(0x7c00u, 0x400), > +}; > + > +static const struct resource omap3_vrfb_resources[] = { > + DEFINE_RES_MEM(0x6C000180u, 0xc0), > + DEFINE_RES_MEM(0x7000u, 0x400), > + DEFINE_RES_MEM(0x7400u, 0x400), > + DEFINE_RES_MEM(0x7800u, 0x400), > + DEFINE_RES_MEM(0x7c00u, 0x400), > + DEFINE_RES_MEM(0xe000u, 0x400), > + DEFINE_RES_MEM(0xe400u, 0x400), > + DEFINE_RES_MEM(0xe800u, 0x400), > + DEFINE_RES_MEM(0xec00u, 0x400), > + DEFINE_RES_MEM(0xf000u, 0x400), > + DEFINE_RES_MEM(0xf400u, 0x400), > + DEFINE_RES_MEM(0xf800u, 0x400), > + DEFINE_RES_MEM(0xfc00u, 0x400), > +}; Maybe add comments describing what these register are in case we have a framework handling them at some point later on? > --- a/drivers/video/omap2/vrfb.c > +++ b/drivers/video/omap2/vrfb.c > +#define SMS_ROT_CONTROL(context) (0x0 + 0x10 * context) > +#define SMS_ROT_SIZE(context)(0x4 + 0x10 * context) > +#define SMS_ROT_PHYSICAL_BA(context) (0x8 + 0x10 * context) > +#define SMS_ROT_VIRT_BASE(rot) (0x100 * (rot)) Can you please also remove the old SMS defines and functions so other code won't start tinkering with them? > +static int __init vrfb_probe(struct platform_device *pdev) > +{ > + struct resource *mem; > + int i; > + > + /* first resource is the register res, the rest are vrfb contexts */ > + > + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + if (!mem) { > + dev_err(&pdev->dev, "can't get vrfb base address\n"); > + return -EINVAL; > + } Now that we assume vrfb is the only user of this, so you must do request_mem_region here as that's the only protection we have. If that fails here, then we know something is wrong. > + vrfb_base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); > + if (!vrfb_base) { > + dev_err(&pdev->dev, "can't ioremap vrfb memory\n"); > + return -ENOMEM; > + } > + > + num_ctxs = pdev->num_resources - 1; > + > + ctxs = devm_kzalloc(&pdev->dev, > + sizeof(struct vrfb_ctx) * num_ctxs, > + GFP_KERNEL); > + > + if (!ctxs) > + return -ENOMEM; > + > + for (i = 0; i < num_ctxs; ++i) { > + mem = platform_get_resource(pdev, IORESOURCE_MEM, 1 + i); > + if (!mem) { > + dev_err(&pdev->dev, "can't get vrfb ctx %d address\n", > + i); > + return -EINVAL; > + } > + > + ctxs[i].base = mem->start; > + } And request_mem_region must also be done for these registers to make sure no other code is using them. Again, if it fails, something is wrong. Regards, Tony -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/2] OMAP: VRFB: convert vrfb to platform device
On Mon, 2012-10-08 at 10:24 -0700, Tony Lindgren wrote: > * Tomi Valkeinen [121008 05:31]: > > This patch converts vrfb library into a platform device, in an effort to > > remove omap dependencies. > > > > The platform device is registered in arch/arm/plat-omap/fb.c and > > assigned resources depending on whether running on omap2 or omap3. > > > > The vrfb driver will parse those resources and use them to access vrfb > > configuration registers and the vrfb virtual rotation areas. > > > > Signed-off-by: Tomi Valkeinen > > Cc: Tony Lindgren > > --- > > arch/arm/plat-omap/fb.c| 53 +++ > > drivers/video/omap2/vrfb.c | 124 > > +--- > > 2 files changed, 157 insertions(+), 20 deletions(-) > > > > diff --git a/arch/arm/plat-omap/fb.c b/arch/arm/plat-omap/fb.c > > index dd6f92c..d231912 100644 > > --- a/arch/arm/plat-omap/fb.c > > +++ b/arch/arm/plat-omap/fb.c > > @@ -35,6 +35,59 @@ > > > > #include > > > > +#if defined(CONFIG_OMAP2_VRFB) > > +static const struct resource omap2_vrfb_resources[] = { > > + DEFINE_RES_MEM(0x68008000u, 0x40), > > + DEFINE_RES_MEM(0x7000u, 0x400), > > + DEFINE_RES_MEM(0x7400u, 0x400), > > + DEFINE_RES_MEM(0x7800u, 0x400), > > + DEFINE_RES_MEM(0x7c00u, 0x400), > > +}; > > + > > +static const struct resource omap3_vrfb_resources[] = { > > + DEFINE_RES_MEM(0x6C000180u, 0xc0), > > + DEFINE_RES_MEM(0x7000u, 0x400), > > + DEFINE_RES_MEM(0x7400u, 0x400), > > + DEFINE_RES_MEM(0x7800u, 0x400), > > + DEFINE_RES_MEM(0x7c00u, 0x400), > > + DEFINE_RES_MEM(0xe000u, 0x400), > > + DEFINE_RES_MEM(0xe400u, 0x400), > > + DEFINE_RES_MEM(0xe800u, 0x400), > > + DEFINE_RES_MEM(0xec00u, 0x400), > > + DEFINE_RES_MEM(0xf000u, 0x400), > > + DEFINE_RES_MEM(0xf400u, 0x400), > > + DEFINE_RES_MEM(0xf800u, 0x400), > > + DEFINE_RES_MEM(0xfc00u, 0x400), > > +}; > > Maybe add comments describing what these register are in case > we have a framework handling them at some point later on? Sure. > > --- a/drivers/video/omap2/vrfb.c > > +++ b/drivers/video/omap2/vrfb.c > > +#define SMS_ROT_CONTROL(context) (0x0 + 0x10 * context) > > +#define SMS_ROT_SIZE(context) (0x4 + 0x10 * context) > > +#define SMS_ROT_PHYSICAL_BA(context) (0x8 + 0x10 * context) > > +#define SMS_ROT_VIRT_BASE(rot) (0x100 * (rot)) > > Can you please also remove the old SMS defines and functions > so other code won't start tinkering with them? Ok. > > +static int __init vrfb_probe(struct platform_device *pdev) > > +{ > > + struct resource *mem; > > + int i; > > + > > + /* first resource is the register res, the rest are vrfb contexts */ > > + > > + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); > > + if (!mem) { > > + dev_err(&pdev->dev, "can't get vrfb base address\n"); > > + return -EINVAL; > > + } > > Now that we assume vrfb is the only user of this, so you must do > request_mem_region here as that's the only protection we have. > If that fails here, then we know something is wrong. Right, I'll add that. > > + vrfb_base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); > > + if (!vrfb_base) { > > + dev_err(&pdev->dev, "can't ioremap vrfb memory\n"); > > + return -ENOMEM; > > + } > > + > > + num_ctxs = pdev->num_resources - 1; > > + > > + ctxs = devm_kzalloc(&pdev->dev, > > + sizeof(struct vrfb_ctx) * num_ctxs, > > + GFP_KERNEL); > > + > > + if (!ctxs) > > + return -ENOMEM; > > + > > + for (i = 0; i < num_ctxs; ++i) { > > + mem = platform_get_resource(pdev, IORESOURCE_MEM, 1 + i); > > + if (!mem) { > > + dev_err(&pdev->dev, "can't get vrfb ctx %d address\n", > > + i); > > + return -EINVAL; > > + } > > + > > + ctxs[i].base = mem->start; > > + } > > And request_mem_region must also be done for these registers to make > sure no other code is using them. Again, if it fails, something is > wrong. There's already request_mem_region for the VRFB virtual areas, which is done later when omapfb or somebody else requests a vrfb context with omap_vrfb_request_ctx(). The memory areas (they are rotated framebuffers, not registers as such) are not used until then. Tomi signature.asc Description: This is a digitally signed message part