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 | */ |
Clarence Ip | 1ba45fe | 2016-09-02 17:46:25 -0400 | [diff] [blame] | 12 | #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__ |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 13 | #include "msm_drv.h" |
Clarence Ip | 1ba45fe | 2016-09-02 17:46:25 -0400 | [diff] [blame] | 14 | #include "sde_kms.h" |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 15 | #include "sde_hw_mdss.h" |
Clarence Ip | c475b08 | 2016-06-26 09:27:23 -0400 | [diff] [blame] | 16 | #include "sde_hw_util.h" |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 17 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 18 | /* using a file static variables for debugfs access */ |
| 19 | static u32 sde_hw_util_log_mask = SDE_DBG_MASK_NONE; |
| 20 | |
Lloyd Atkinson | 7a7c431 | 2016-05-30 13:49:12 -0400 | [diff] [blame] | 21 | void sde_reg_write(struct sde_hw_blk_reg_map *c, |
| 22 | u32 reg_off, |
| 23 | u32 val, |
| 24 | const char *name) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 25 | { |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 26 | /* don't need to mutex protect this */ |
| 27 | if (c->log_mask & sde_hw_util_log_mask) |
Clarence Ip | 1ba45fe | 2016-09-02 17:46:25 -0400 | [diff] [blame] | 28 | SDE_DEBUG_DRIVER("[%s:0x%X] <= 0x%X\n", |
| 29 | name, c->blk_off + reg_off, val); |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 30 | writel_relaxed(val, c->base_off + c->blk_off + reg_off); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Lloyd Atkinson | 7a7c431 | 2016-05-30 13:49:12 -0400 | [diff] [blame] | 33 | int sde_reg_read(struct sde_hw_blk_reg_map *c, u32 reg_off) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 34 | { |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 35 | return readl_relaxed(c->base_off + c->blk_off + reg_off); |
| 36 | } |
| 37 | |
| 38 | u32 *sde_hw_util_get_log_mask_ptr(void) |
| 39 | { |
| 40 | return &sde_hw_util_log_mask; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 43 | void sde_hw_csc_setup(struct sde_hw_blk_reg_map *c, |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 44 | u32 csc_reg_off, |
| 45 | struct sde_csc_cfg *data) |
| 46 | { |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 47 | static const u32 matrix_shift = 7; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 48 | u32 val; |
| 49 | |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 50 | /* matrix coeff - convert S15.16 to S4.9 */ |
| 51 | val = ((data->csc_mv[0] >> matrix_shift) & 0x1FFF) | |
| 52 | (((data->csc_mv[1] >> matrix_shift) & 0x1FFF) << 16); |
| 53 | SDE_REG_WRITE(c, csc_reg_off, val); |
| 54 | val = ((data->csc_mv[2] >> matrix_shift) & 0x1FFF) | |
| 55 | (((data->csc_mv[3] >> matrix_shift) & 0x1FFF) << 16); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 56 | SDE_REG_WRITE(c, csc_reg_off + 0x4, val); |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 57 | val = ((data->csc_mv[4] >> matrix_shift) & 0x1FFF) | |
| 58 | (((data->csc_mv[5] >> matrix_shift) & 0x1FFF) << 16); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 59 | SDE_REG_WRITE(c, csc_reg_off + 0x8, val); |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 60 | val = ((data->csc_mv[6] >> matrix_shift) & 0x1FFF) | |
| 61 | (((data->csc_mv[7] >> matrix_shift) & 0x1FFF) << 16); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 62 | SDE_REG_WRITE(c, csc_reg_off + 0xc, val); |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 63 | val = (data->csc_mv[8] >> matrix_shift) & 0x1FFF; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 64 | SDE_REG_WRITE(c, csc_reg_off + 0x10, val); |
| 65 | |
| 66 | /* Pre clamp */ |
| 67 | val = (data->csc_pre_lv[0] << 8) | data->csc_pre_lv[1]; |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 68 | SDE_REG_WRITE(c, csc_reg_off + 0x14, val); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 69 | val = (data->csc_pre_lv[2] << 8) | data->csc_pre_lv[3]; |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 70 | SDE_REG_WRITE(c, csc_reg_off + 0x18, val); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 71 | val = (data->csc_pre_lv[4] << 8) | data->csc_pre_lv[5]; |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 72 | SDE_REG_WRITE(c, csc_reg_off + 0x1c, val); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 73 | |
| 74 | /* Post clamp */ |
| 75 | val = (data->csc_post_lv[0] << 8) | data->csc_post_lv[1]; |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 76 | SDE_REG_WRITE(c, csc_reg_off + 0x20, val); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 77 | val = (data->csc_post_lv[2] << 8) | data->csc_post_lv[3]; |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 78 | SDE_REG_WRITE(c, csc_reg_off + 0x24, val); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 79 | val = (data->csc_post_lv[4] << 8) | data->csc_post_lv[5]; |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 80 | SDE_REG_WRITE(c, csc_reg_off + 0x28, val); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 81 | |
| 82 | /* Pre-Bias */ |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 83 | SDE_REG_WRITE(c, csc_reg_off + 0x2c, data->csc_pre_bv[0]); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 84 | SDE_REG_WRITE(c, csc_reg_off + 0x30, data->csc_pre_bv[1]); |
| 85 | SDE_REG_WRITE(c, csc_reg_off + 0x34, data->csc_pre_bv[2]); |
| 86 | |
| 87 | /* Post-Bias */ |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 88 | SDE_REG_WRITE(c, csc_reg_off + 0x38, data->csc_post_bv[0]); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 89 | SDE_REG_WRITE(c, csc_reg_off + 0x3c, data->csc_post_bv[1]); |
| 90 | SDE_REG_WRITE(c, csc_reg_off + 0x40, data->csc_post_bv[2]); |
| 91 | } |
| 92 | |