Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include "sde_hw_mdss.h" |
| 14 | #include "sde_hwio.h" |
| 15 | #include "sde_hw_catalog.h" |
| 16 | #include "sde_hw_pingpong.h" |
| 17 | |
| 18 | #define PP_TEAR_CHECK_EN 0x000 |
| 19 | #define PP_SYNC_CONFIG_VSYNC 0x004 |
| 20 | #define PP_SYNC_CONFIG_HEIGHT 0x008 |
| 21 | #define PP_SYNC_WRCOUNT 0x00C |
| 22 | #define PP_VSYNC_INIT_VAL 0x010 |
| 23 | #define PP_INT_COUNT_VAL 0x014 |
| 24 | #define PP_SYNC_THRESH 0x018 |
| 25 | #define PP_START_POS 0x01C |
| 26 | #define PP_RD_PTR_IRQ 0x020 |
| 27 | #define PP_WR_PTR_IRQ 0x024 |
| 28 | #define PP_OUT_LINE_COUNT 0x028 |
| 29 | #define PP_LINE_COUNT 0x02C |
| 30 | #define PP_AUTOREFRESH_CONFIG 0x030 |
| 31 | |
| 32 | #define PP_FBC_MODE 0x034 |
| 33 | #define PP_FBC_BUDGET_CTL 0x038 |
| 34 | #define PP_FBC_LOSSY_MODE 0x03C |
| 35 | #define PP_DSC_MODE 0x0a0 |
| 36 | #define PP_DCE_DATA_IN_SWAP 0x0ac |
| 37 | #define PP_DCE_DATA_OUT_SWAP 0x0c8 |
| 38 | |
| 39 | static struct sde_pingpong_cfg *_pingpong_offset(enum sde_pingpong pp, |
| 40 | struct sde_mdss_cfg *m, |
| 41 | void __iomem *addr, |
| 42 | struct sde_hw_blk_reg_map *b) |
| 43 | { |
| 44 | int i; |
| 45 | |
| 46 | for (i = 0; i < m->pingpong_count; i++) { |
| 47 | if (pp == m->pingpong[i].id) { |
| 48 | b->base_off = addr; |
| 49 | b->blk_off = m->pingpong[i].base; |
| 50 | b->hwversion = m->hwversion; |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 51 | b->log_mask = SDE_DBG_MASK_PINGPONG; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 52 | return &m->pingpong[i]; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return ERR_PTR(-EINVAL); |
| 57 | } |
| 58 | |
| 59 | static int sde_hw_pp_setup_te_config(struct sde_hw_pingpong *pp, |
| 60 | struct sde_hw_tear_check *te) |
| 61 | { |
| 62 | struct sde_hw_blk_reg_map *c = &pp->hw; |
| 63 | int cfg; |
| 64 | |
| 65 | cfg = BIT(19); /*VSYNC_COUNTER_EN */ |
| 66 | if (te->hw_vsync_mode) |
| 67 | cfg |= BIT(20); |
| 68 | |
| 69 | cfg |= te->vsync_count; |
| 70 | |
| 71 | SDE_REG_WRITE(c, PP_SYNC_CONFIG_VSYNC, cfg); |
| 72 | SDE_REG_WRITE(c, PP_SYNC_CONFIG_HEIGHT, te->sync_cfg_height); |
| 73 | SDE_REG_WRITE(c, PP_VSYNC_INIT_VAL, te->vsync_init_val); |
| 74 | SDE_REG_WRITE(c, PP_RD_PTR_IRQ, te->rd_ptr_irq); |
| 75 | SDE_REG_WRITE(c, PP_START_POS, te->start_pos); |
| 76 | SDE_REG_WRITE(c, PP_SYNC_THRESH, |
| 77 | ((te->sync_threshold_continue << 16) | |
| 78 | te->sync_threshold_start)); |
| 79 | SDE_REG_WRITE(c, PP_SYNC_WRCOUNT, |
| 80 | (te->start_pos + te->sync_threshold_start + 1)); |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | int sde_hw_pp_setup_autorefresh_config(struct sde_hw_pingpong *pp, |
| 86 | struct sde_hw_autorefresh *cfg) |
| 87 | { |
| 88 | struct sde_hw_blk_reg_map *c = &pp->hw; |
| 89 | u32 refresh_cfg; |
| 90 | |
| 91 | if (cfg->enable) |
| 92 | refresh_cfg = BIT(31) | cfg->frame_count; |
| 93 | else |
| 94 | refresh_cfg = 0; |
| 95 | |
| 96 | SDE_REG_WRITE(c, PP_AUTOREFRESH_CONFIG, |
| 97 | refresh_cfg); |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | int sde_hw_pp_setup_dsc_compression(struct sde_hw_pingpong *pp, |
| 103 | struct sde_hw_dsc_cfg *cfg) |
| 104 | { |
| 105 | return 0; |
| 106 | } |
| 107 | int sde_hw_pp_enable_te(struct sde_hw_pingpong *pp, bool enable) |
| 108 | { |
| 109 | struct sde_hw_blk_reg_map *c = &pp->hw; |
| 110 | |
| 111 | SDE_REG_WRITE(c, PP_TEAR_CHECK_EN, enable); |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | int sde_hw_pp_get_vsync_info(struct sde_hw_pingpong *pp, |
| 116 | struct sde_hw_pp_vsync_info *info) |
| 117 | { |
| 118 | struct sde_hw_blk_reg_map *c = &pp->hw; |
Lloyd Atkinson | 3127a09 | 2016-05-30 13:46:55 -0400 | [diff] [blame] | 119 | u32 val; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 120 | |
Lloyd Atkinson | 3127a09 | 2016-05-30 13:46:55 -0400 | [diff] [blame] | 121 | val = SDE_REG_READ(c, PP_VSYNC_INIT_VAL); |
| 122 | info->init_val = val & 0xffff; |
| 123 | |
| 124 | val = SDE_REG_READ(c, PP_INT_COUNT_VAL); |
| 125 | info->vsync_count = (val & 0xffff0000) >> 16; |
| 126 | info->line_count = val & 0xffff; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | static void _setup_pingpong_ops(struct sde_hw_pingpong_ops *ops, |
| 132 | unsigned long cap) |
| 133 | { |
| 134 | ops->setup_tearcheck = sde_hw_pp_setup_te_config; |
| 135 | ops->enable_tearcheck = sde_hw_pp_enable_te; |
| 136 | ops->get_vsync_info = sde_hw_pp_get_vsync_info; |
| 137 | ops->setup_autorefresh = sde_hw_pp_setup_autorefresh_config; |
| 138 | ops->setup_dsc = sde_hw_pp_setup_dsc_compression; |
| 139 | }; |
| 140 | |
| 141 | struct sde_hw_pingpong *sde_hw_pingpong_init(enum sde_pingpong idx, |
| 142 | void __iomem *addr, |
| 143 | struct sde_mdss_cfg *m) |
| 144 | { |
| 145 | struct sde_hw_pingpong *c; |
| 146 | struct sde_pingpong_cfg *cfg; |
| 147 | |
| 148 | c = kzalloc(sizeof(*c), GFP_KERNEL); |
| 149 | if (!c) |
| 150 | return ERR_PTR(-ENOMEM); |
| 151 | |
| 152 | cfg = _pingpong_offset(idx, m, addr, &c->hw); |
| 153 | if (IS_ERR_OR_NULL(cfg)) { |
| 154 | kfree(c); |
| 155 | return ERR_PTR(-EINVAL); |
| 156 | } |
| 157 | |
| 158 | c->idx = idx; |
| 159 | c->pingpong_hw_cap = cfg; |
| 160 | _setup_pingpong_ops(&c->ops, c->pingpong_hw_cap->features); |
| 161 | |
| 162 | return c; |
| 163 | } |
| 164 | |
Lloyd Atkinson | 3127a09 | 2016-05-30 13:46:55 -0400 | [diff] [blame] | 165 | void sde_hw_pingpong_destroy(struct sde_hw_pingpong *pp) |
| 166 | { |
| 167 | kfree(pp); |
| 168 | } |