aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/sh_mobile_meram.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2012-03-15 07:40:47 -0400
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2012-07-18 20:05:21 -0400
commit4a2371772146b30113c9c837eb32b64f18376c0d (patch)
treeefb13c1f047b4a1cc6859fa93f74534d522aeb6a /drivers/video/sh_mobile_meram.c
parent6fcdbc0c3a683003a00f383fceac80da1b7852ff (diff)
sh_mobile_meram: Rename operations to cache_[alloc|free|update]
The MERAM operations meram_register, meram_unregister and meram_update handle LCDC cache. In preparation for "raw" MERAM allocation, rename them to more appropriate names. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'drivers/video/sh_mobile_meram.c')
-rw-r--r--drivers/video/sh_mobile_meram.c176
1 files changed, 86 insertions, 90 deletions
diff --git a/drivers/video/sh_mobile_meram.c b/drivers/video/sh_mobile_meram.c
index 82ba830bf95d..4aa3fcb87f17 100644
--- a/drivers/video/sh_mobile_meram.c
+++ b/drivers/video/sh_mobile_meram.c
@@ -194,13 +194,13 @@ static inline unsigned long meram_read_reg(void __iomem *base, unsigned int off)
194} 194}
195 195
196/* ----------------------------------------------------------------------------- 196/* -----------------------------------------------------------------------------
197 * Allocation 197 * LCDC cache planes allocation, init, cleanup and free
198 */ 198 */
199 199
200/* Allocate ICBs and MERAM for a plane. */ 200/* Allocate ICBs and MERAM for a plane. */
201static int __meram_alloc(struct sh_mobile_meram_priv *priv, 201static int meram_plane_alloc(struct sh_mobile_meram_priv *priv,
202 struct sh_mobile_meram_fb_plane *plane, 202 struct sh_mobile_meram_fb_plane *plane,
203 size_t size) 203 size_t size)
204{ 204{
205 unsigned long mem; 205 unsigned long mem;
206 unsigned long idx; 206 unsigned long idx;
@@ -229,8 +229,8 @@ static int __meram_alloc(struct sh_mobile_meram_priv *priv,
229} 229}
230 230
231/* Free ICBs and MERAM for a plane. */ 231/* Free ICBs and MERAM for a plane. */
232static void __meram_free(struct sh_mobile_meram_priv *priv, 232static void meram_plane_free(struct sh_mobile_meram_priv *priv,
233 struct sh_mobile_meram_fb_plane *plane) 233 struct sh_mobile_meram_fb_plane *plane)
234{ 234{
235 gen_pool_free(priv->pool, priv->meram + plane->marker->offset, 235 gen_pool_free(priv->pool, priv->meram + plane->marker->offset,
236 plane->marker->size * 1024); 236 plane->marker->size * 1024);
@@ -248,62 +248,6 @@ static int is_nvcolor(int cspace)
248 return 0; 248 return 0;
249} 249}
250 250
251/* Allocate memory for the ICBs and mark them as used. */
252static struct sh_mobile_meram_fb_cache *
253meram_alloc(struct sh_mobile_meram_priv *priv,
254 const struct sh_mobile_meram_cfg *cfg,
255 int pixelformat)
256{
257 struct sh_mobile_meram_fb_cache *cache;
258 unsigned int nplanes = is_nvcolor(pixelformat) ? 2 : 1;
259 int ret;
260
261 if (cfg->icb[0].meram_size == 0)
262 return ERR_PTR(-EINVAL);
263
264 if (nplanes == 2 && cfg->icb[1].meram_size == 0)
265 return ERR_PTR(-EINVAL);
266
267 cache = kzalloc(sizeof(*cache), GFP_KERNEL);
268 if (cache == NULL)
269 return ERR_PTR(-ENOMEM);
270
271 cache->nplanes = nplanes;
272
273 ret = __meram_alloc(priv, &cache->planes[0], cfg->icb[0].meram_size);
274 if (ret < 0)
275 goto error;
276
277 cache->planes[0].marker->current_reg = 1;
278 cache->planes[0].marker->pixelformat = pixelformat;
279
280 if (cache->nplanes == 1)
281 return cache;
282
283 ret = __meram_alloc(priv, &cache->planes[1], cfg->icb[1].meram_size);
284 if (ret < 0) {
285 __meram_free(priv, &cache->planes[0]);
286 goto error;
287 }
288
289 return cache;
290
291error:
292 kfree(cache);
293 return ERR_PTR(-ENOMEM);
294}
295
296/* Unmark the specified ICB as used. */
297static void meram_free(struct sh_mobile_meram_priv *priv,
298 struct sh_mobile_meram_fb_cache *cache)
299{
300 __meram_free(priv, &cache->planes[0]);
301 if (cache->nplanes == 2)
302 __meram_free(priv, &cache->planes[1]);
303
304 kfree(cache);
305}
306
307/* Set the next address to fetch. */ 251/* Set the next address to fetch. */
308static void meram_set_next_addr(struct sh_mobile_meram_priv *priv, 252static void meram_set_next_addr(struct sh_mobile_meram_priv *priv,
309 struct sh_mobile_meram_fb_cache *cache, 253 struct sh_mobile_meram_fb_cache *cache,
@@ -355,10 +299,10 @@ meram_get_next_icb_addr(struct sh_mobile_meram_info *pdata,
355 (((x) * (y) + (MERAM_LINE_WIDTH - 1)) & ~(MERAM_LINE_WIDTH - 1)) 299 (((x) * (y) + (MERAM_LINE_WIDTH - 1)) & ~(MERAM_LINE_WIDTH - 1))
356 300
357/* Initialize MERAM. */ 301/* Initialize MERAM. */
358static int meram_init(struct sh_mobile_meram_priv *priv, 302static int meram_plane_init(struct sh_mobile_meram_priv *priv,
359 struct sh_mobile_meram_fb_plane *plane, 303 struct sh_mobile_meram_fb_plane *plane,
360 unsigned int xres, unsigned int yres, 304 unsigned int xres, unsigned int yres,
361 unsigned int *out_pitch) 305 unsigned int *out_pitch)
362{ 306{
363 struct sh_mobile_meram_icb *marker = plane->marker; 307 struct sh_mobile_meram_icb *marker = plane->marker;
364 unsigned long total_byte_count = MERAM_CALC_BYTECOUNT(xres, yres); 308 unsigned long total_byte_count = MERAM_CALC_BYTECOUNT(xres, yres);
@@ -427,8 +371,8 @@ static int meram_init(struct sh_mobile_meram_priv *priv,
427 return 0; 371 return 0;
428} 372}
429 373
430static void meram_deinit(struct sh_mobile_meram_priv *priv, 374static void meram_plane_cleanup(struct sh_mobile_meram_priv *priv,
431 struct sh_mobile_meram_fb_plane *plane) 375 struct sh_mobile_meram_fb_plane *plane)
432{ 376{
433 /* disable ICB */ 377 /* disable ICB */
434 meram_write_icb(priv->base, plane->cache->index, MExxCTL, 378 meram_write_icb(priv->base, plane->cache->index, MExxCTL,
@@ -441,18 +385,60 @@ static void meram_deinit(struct sh_mobile_meram_priv *priv,
441} 385}
442 386
443/* ----------------------------------------------------------------------------- 387/* -----------------------------------------------------------------------------
444 * Registration/unregistration 388 * LCDC cache operations
445 */ 389 */
446 390
447static void *sh_mobile_meram_register(struct sh_mobile_meram_info *pdata, 391/* Allocate memory for the ICBs and mark them as used. */
448 const struct sh_mobile_meram_cfg *cfg, 392static struct sh_mobile_meram_fb_cache *
449 unsigned int xres, unsigned int yres, 393meram_cache_alloc(struct sh_mobile_meram_priv *priv,
450 unsigned int pixelformat, 394 const struct sh_mobile_meram_cfg *cfg,
451 unsigned int *pitch) 395 int pixelformat)
396{
397 unsigned int nplanes = is_nvcolor(pixelformat) ? 2 : 1;
398 struct sh_mobile_meram_fb_cache *cache;
399 int ret;
400
401 cache = kzalloc(sizeof(*cache), GFP_KERNEL);
402 if (cache == NULL)
403 return ERR_PTR(-ENOMEM);
404
405 cache->nplanes = nplanes;
406
407 ret = meram_plane_alloc(priv, &cache->planes[0],
408 cfg->icb[0].meram_size);
409 if (ret < 0)
410 goto error;
411
412 cache->planes[0].marker->current_reg = 1;
413 cache->planes[0].marker->pixelformat = pixelformat;
414
415 if (cache->nplanes == 1)
416 return cache;
417
418 ret = meram_plane_alloc(priv, &cache->planes[1],
419 cfg->icb[1].meram_size);
420 if (ret < 0) {
421 meram_plane_free(priv, &cache->planes[0]);
422 goto error;
423 }
424
425 return cache;
426
427error:
428 kfree(cache);
429 return ERR_PTR(-ENOMEM);
430}
431
432static void *sh_mobile_cache_alloc(struct sh_mobile_meram_info *pdata,
433 const struct sh_mobile_meram_cfg *cfg,
434 unsigned int xres, unsigned int yres,
435 unsigned int pixelformat,
436 unsigned int *pitch)
452{ 437{
453 struct sh_mobile_meram_fb_cache *cache; 438 struct sh_mobile_meram_fb_cache *cache;
454 struct sh_mobile_meram_priv *priv = pdata->priv; 439 struct sh_mobile_meram_priv *priv = pdata->priv;
455 struct platform_device *pdev = pdata->pdev; 440 struct platform_device *pdev = pdata->pdev;
441 unsigned int nplanes = is_nvcolor(pixelformat) ? 2 : 1;
456 unsigned int out_pitch; 442 unsigned int out_pitch;
457 443
458 if (pixelformat != SH_MOBILE_MERAM_PF_NV && 444 if (pixelformat != SH_MOBILE_MERAM_PF_NV &&
@@ -469,10 +455,16 @@ static void *sh_mobile_meram_register(struct sh_mobile_meram_info *pdata,
469 return ERR_PTR(-EINVAL); 455 return ERR_PTR(-EINVAL);
470 } 456 }
471 457
458 if (cfg->icb[0].meram_size == 0)
459 return ERR_PTR(-EINVAL);
460
461 if (nplanes == 2 && cfg->icb[1].meram_size == 0)
462 return ERR_PTR(-EINVAL);
463
472 mutex_lock(&priv->lock); 464 mutex_lock(&priv->lock);
473 465
474 /* We now register the ICBs and allocate the MERAM regions. */ 466 /* We now register the ICBs and allocate the MERAM regions. */
475 cache = meram_alloc(priv, cfg, pixelformat); 467 cache = meram_cache_alloc(priv, cfg, pixelformat);
476 if (IS_ERR(cache)) { 468 if (IS_ERR(cache)) {
477 dev_err(&pdev->dev, "MERAM allocation failed (%ld).", 469 dev_err(&pdev->dev, "MERAM allocation failed (%ld).",
478 PTR_ERR(cache)); 470 PTR_ERR(cache));
@@ -480,14 +472,14 @@ static void *sh_mobile_meram_register(struct sh_mobile_meram_info *pdata,
480 } 472 }
481 473
482 /* initialize MERAM */ 474 /* initialize MERAM */
483 meram_init(priv, &cache->planes[0], xres, yres, &out_pitch); 475 meram_plane_init(priv, &cache->planes[0], xres, yres, &out_pitch);
484 *pitch = out_pitch; 476 *pitch = out_pitch;
485 if (pixelformat == SH_MOBILE_MERAM_PF_NV) 477 if (pixelformat == SH_MOBILE_MERAM_PF_NV)
486 meram_init(priv, &cache->planes[1], xres, (yres + 1) / 2, 478 meram_plane_init(priv, &cache->planes[1],
487 &out_pitch); 479 xres, (yres + 1) / 2, &out_pitch);
488 else if (pixelformat == SH_MOBILE_MERAM_PF_NV24) 480 else if (pixelformat == SH_MOBILE_MERAM_PF_NV24)
489 meram_init(priv, &cache->planes[1], 2 * xres, (yres + 1) / 2, 481 meram_plane_init(priv, &cache->planes[1],
490 &out_pitch); 482 2 * xres, (yres + 1) / 2, &out_pitch);
491 483
492err: 484err:
493 mutex_unlock(&priv->lock); 485 mutex_unlock(&priv->lock);
@@ -495,25 +487,29 @@ err:
495} 487}
496 488
497static void 489static void
498sh_mobile_meram_unregister(struct sh_mobile_meram_info *pdata, void *data) 490sh_mobile_cache_free(struct sh_mobile_meram_info *pdata, void *data)
499{ 491{
500 struct sh_mobile_meram_fb_cache *cache = data; 492 struct sh_mobile_meram_fb_cache *cache = data;
501 struct sh_mobile_meram_priv *priv = pdata->priv; 493 struct sh_mobile_meram_priv *priv = pdata->priv;
502 494
503 mutex_lock(&priv->lock); 495 mutex_lock(&priv->lock);
504 496
505 /* deinit & free */ 497 /* Cleanup and free. */
506 meram_deinit(priv, &cache->planes[0]); 498 meram_plane_cleanup(priv, &cache->planes[0]);
507 if (cache->nplanes == 2) 499 meram_plane_free(priv, &cache->planes[0]);
508 meram_deinit(priv, &cache->planes[1]);
509 500
510 meram_free(priv, cache); 501 if (cache->nplanes == 2) {
502 meram_plane_cleanup(priv, &cache->planes[1]);
503 meram_plane_free(priv, &cache->planes[1]);
504 }
505
506 kfree(cache);
511 507
512 mutex_unlock(&priv->lock); 508 mutex_unlock(&priv->lock);
513} 509}
514 510
515static void 511static void
516sh_mobile_meram_update(struct sh_mobile_meram_info *pdata, void *data, 512sh_mobile_cache_update(struct sh_mobile_meram_info *pdata, void *data,
517 unsigned long base_addr_y, unsigned long base_addr_c, 513 unsigned long base_addr_y, unsigned long base_addr_c,
518 unsigned long *icb_addr_y, unsigned long *icb_addr_c) 514 unsigned long *icb_addr_y, unsigned long *icb_addr_c)
519{ 515{
@@ -530,9 +526,9 @@ sh_mobile_meram_update(struct sh_mobile_meram_info *pdata, void *data,
530 526
531static struct sh_mobile_meram_ops sh_mobile_meram_ops = { 527static struct sh_mobile_meram_ops sh_mobile_meram_ops = {
532 .module = THIS_MODULE, 528 .module = THIS_MODULE,
533 .meram_register = sh_mobile_meram_register, 529 .cache_alloc = sh_mobile_cache_alloc,
534 .meram_unregister = sh_mobile_meram_unregister, 530 .cache_free = sh_mobile_cache_free,
535 .meram_update = sh_mobile_meram_update, 531 .cache_update = sh_mobile_cache_update,
536}; 532};
537 533
538/* ----------------------------------------------------------------------------- 534/* -----------------------------------------------------------------------------