meson_canvas.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (C) 2016 BayLibre, SAS
  3. * Author: Neil Armstrong <narmstrong@baylibre.com>
  4. * Copyright (C) 2015 Amlogic, Inc. All rights reserved.
  5. * Copyright (C) 2014 Endless Mobile
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include "meson_drv.h"
  23. #include "meson_canvas.h"
  24. #include "meson_registers.h"
  25. /*
  26. * CANVAS is a memory zone where physical memory frames information
  27. * are stored for the VIU to scanout.
  28. */
  29. /* DMC Registers */
  30. #define DMC_CAV_LUT_DATAL 0x48 /* 0x12 offset in data sheet */
  31. #define CANVAS_WIDTH_LBIT 29
  32. #define CANVAS_WIDTH_LWID 3
  33. #define DMC_CAV_LUT_DATAH 0x4c /* 0x13 offset in data sheet */
  34. #define CANVAS_WIDTH_HBIT 0
  35. #define CANVAS_HEIGHT_BIT 9
  36. #define CANVAS_BLKMODE_BIT 24
  37. #define DMC_CAV_LUT_ADDR 0x50 /* 0x14 offset in data sheet */
  38. #define CANVAS_LUT_WR_EN (0x2 << 8)
  39. #define CANVAS_LUT_RD_EN (0x1 << 8)
  40. void meson_canvas_setup(struct meson_drm *priv,
  41. uint32_t canvas_index, uint32_t addr,
  42. uint32_t stride, uint32_t height,
  43. unsigned int wrap,
  44. unsigned int blkmode)
  45. {
  46. unsigned int val;
  47. regmap_write(priv->dmc, DMC_CAV_LUT_DATAL,
  48. (((addr + 7) >> 3)) |
  49. (((stride + 7) >> 3) << CANVAS_WIDTH_LBIT));
  50. regmap_write(priv->dmc, DMC_CAV_LUT_DATAH,
  51. ((((stride + 7) >> 3) >> CANVAS_WIDTH_LWID) <<
  52. CANVAS_WIDTH_HBIT) |
  53. (height << CANVAS_HEIGHT_BIT) |
  54. (wrap << 22) |
  55. (blkmode << CANVAS_BLKMODE_BIT));
  56. regmap_write(priv->dmc, DMC_CAV_LUT_ADDR,
  57. CANVAS_LUT_WR_EN | canvas_index);
  58. /* Force a read-back to make sure everything is flushed. */
  59. regmap_read(priv->dmc, DMC_CAV_LUT_DATAH, &val);
  60. }