g2d-hw.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Samsung S5P G2D - 2D Graphics Accelerator Driver
  3. *
  4. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  5. * Kamil Debski, <k.debski@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the
  10. * License, or (at your option) any later version
  11. */
  12. #include <linux/io.h>
  13. #include "g2d.h"
  14. #include "g2d-regs.h"
  15. #define w(x, a) writel((x), d->regs + (a))
  16. #define r(a) readl(d->regs + (a))
  17. /* g2d_reset clears all g2d registers */
  18. void g2d_reset(struct g2d_dev *d)
  19. {
  20. w(1, SOFT_RESET_REG);
  21. }
  22. void g2d_set_src_size(struct g2d_dev *d, struct g2d_frame *f)
  23. {
  24. u32 n;
  25. w(0, SRC_SELECT_REG);
  26. w(f->stride & 0xFFFF, SRC_STRIDE_REG);
  27. n = f->o_height & 0xFFF;
  28. n <<= 16;
  29. n |= f->o_width & 0xFFF;
  30. w(n, SRC_LEFT_TOP_REG);
  31. n = f->bottom & 0xFFF;
  32. n <<= 16;
  33. n |= f->right & 0xFFF;
  34. w(n, SRC_RIGHT_BOTTOM_REG);
  35. w(f->fmt->hw, SRC_COLOR_MODE_REG);
  36. }
  37. void g2d_set_src_addr(struct g2d_dev *d, dma_addr_t a)
  38. {
  39. w(a, SRC_BASE_ADDR_REG);
  40. }
  41. void g2d_set_dst_size(struct g2d_dev *d, struct g2d_frame *f)
  42. {
  43. u32 n;
  44. w(0, DST_SELECT_REG);
  45. w(f->stride & 0xFFFF, DST_STRIDE_REG);
  46. n = f->o_height & 0xFFF;
  47. n <<= 16;
  48. n |= f->o_width & 0xFFF;
  49. w(n, DST_LEFT_TOP_REG);
  50. n = f->bottom & 0xFFF;
  51. n <<= 16;
  52. n |= f->right & 0xFFF;
  53. w(n, DST_RIGHT_BOTTOM_REG);
  54. w(f->fmt->hw, DST_COLOR_MODE_REG);
  55. }
  56. void g2d_set_dst_addr(struct g2d_dev *d, dma_addr_t a)
  57. {
  58. w(a, DST_BASE_ADDR_REG);
  59. }
  60. void g2d_set_rop4(struct g2d_dev *d, u32 r)
  61. {
  62. w(r, ROP4_REG);
  63. }
  64. void g2d_set_flip(struct g2d_dev *d, u32 r)
  65. {
  66. w(r, SRC_MSK_DIRECT_REG);
  67. }
  68. void g2d_set_v41_stretch(struct g2d_dev *d, struct g2d_frame *src,
  69. struct g2d_frame *dst)
  70. {
  71. w(DEFAULT_SCALE_MODE, SRC_SCALE_CTRL_REG);
  72. /* inversed scaling factor: src is numerator */
  73. w((src->c_width << 16) / dst->c_width, SRC_XSCALE_REG);
  74. w((src->c_height << 16) / dst->c_height, SRC_YSCALE_REG);
  75. }
  76. void g2d_set_cmd(struct g2d_dev *d, u32 c)
  77. {
  78. w(c, BITBLT_COMMAND_REG);
  79. }
  80. void g2d_start(struct g2d_dev *d)
  81. {
  82. /* Clear cache */
  83. if (d->variant->hw_rev == TYPE_G2D_3X)
  84. w(0x7, CACHECTL_REG);
  85. /* Enable interrupt */
  86. w(1, INTEN_REG);
  87. /* Start G2D engine */
  88. w(1, BITBLT_START_REG);
  89. }
  90. void g2d_clear_int(struct g2d_dev *d)
  91. {
  92. w(1, INTC_PEND_REG);
  93. }