blob: 6f52f31a75695ec507d689f452ac16733f9458f1 [file] [log] [blame]
Narendra Muppalla1b0b3352015-09-29 10:16:51 -07001/* 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 Ip1ba45fe2016-09-02 17:46:25 -040012#define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
Clarence Ip4ce59322016-06-26 22:27:51 -040013#include "msm_drv.h"
Clarence Ip1ba45fe2016-09-02 17:46:25 -040014#include "sde_kms.h"
Clarence Ip4ce59322016-06-26 22:27:51 -040015#include "sde_hw_mdss.h"
Clarence Ipc475b082016-06-26 09:27:23 -040016#include "sde_hw_util.h"
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070017
Clarence Ip4ce59322016-06-26 22:27:51 -040018/* using a file static variables for debugfs access */
19static u32 sde_hw_util_log_mask = SDE_DBG_MASK_NONE;
20
Lloyd Atkinson7a7c4312016-05-30 13:49:12 -040021void sde_reg_write(struct sde_hw_blk_reg_map *c,
22 u32 reg_off,
23 u32 val,
24 const char *name)
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070025{
Clarence Ip4ce59322016-06-26 22:27:51 -040026 /* don't need to mutex protect this */
27 if (c->log_mask & sde_hw_util_log_mask)
Clarence Ip1ba45fe2016-09-02 17:46:25 -040028 SDE_DEBUG_DRIVER("[%s:0x%X] <= 0x%X\n",
29 name, c->blk_off + reg_off, val);
Clarence Ip4ce59322016-06-26 22:27:51 -040030 writel_relaxed(val, c->base_off + c->blk_off + reg_off);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070031}
32
Lloyd Atkinson7a7c4312016-05-30 13:49:12 -040033int sde_reg_read(struct sde_hw_blk_reg_map *c, u32 reg_off)
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070034{
Clarence Ip4ce59322016-06-26 22:27:51 -040035 return readl_relaxed(c->base_off + c->blk_off + reg_off);
36}
37
38u32 *sde_hw_util_get_log_mask_ptr(void)
39{
40 return &sde_hw_util_log_mask;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070041}
42
Clarence Ip373f8592016-05-26 00:58:42 -040043void sde_hw_csc_setup(struct sde_hw_blk_reg_map *c,
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070044 u32 csc_reg_off,
45 struct sde_csc_cfg *data)
46{
Clarence Ip373f8592016-05-26 00:58:42 -040047 static const u32 matrix_shift = 7;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070048 u32 val;
49
Clarence Ip373f8592016-05-26 00:58:42 -040050 /* 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 Muppalla1b0b3352015-09-29 10:16:51 -070056 SDE_REG_WRITE(c, csc_reg_off + 0x4, val);
Clarence Ip373f8592016-05-26 00:58:42 -040057 val = ((data->csc_mv[4] >> matrix_shift) & 0x1FFF) |
58 (((data->csc_mv[5] >> matrix_shift) & 0x1FFF) << 16);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070059 SDE_REG_WRITE(c, csc_reg_off + 0x8, val);
Clarence Ip373f8592016-05-26 00:58:42 -040060 val = ((data->csc_mv[6] >> matrix_shift) & 0x1FFF) |
61 (((data->csc_mv[7] >> matrix_shift) & 0x1FFF) << 16);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070062 SDE_REG_WRITE(c, csc_reg_off + 0xc, val);
Clarence Ip373f8592016-05-26 00:58:42 -040063 val = (data->csc_mv[8] >> matrix_shift) & 0x1FFF;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070064 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 Ip373f8592016-05-26 00:58:42 -040068 SDE_REG_WRITE(c, csc_reg_off + 0x14, val);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070069 val = (data->csc_pre_lv[2] << 8) | data->csc_pre_lv[3];
Clarence Ip373f8592016-05-26 00:58:42 -040070 SDE_REG_WRITE(c, csc_reg_off + 0x18, val);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070071 val = (data->csc_pre_lv[4] << 8) | data->csc_pre_lv[5];
Clarence Ip373f8592016-05-26 00:58:42 -040072 SDE_REG_WRITE(c, csc_reg_off + 0x1c, val);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070073
74 /* Post clamp */
75 val = (data->csc_post_lv[0] << 8) | data->csc_post_lv[1];
Clarence Ip373f8592016-05-26 00:58:42 -040076 SDE_REG_WRITE(c, csc_reg_off + 0x20, val);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070077 val = (data->csc_post_lv[2] << 8) | data->csc_post_lv[3];
Clarence Ip373f8592016-05-26 00:58:42 -040078 SDE_REG_WRITE(c, csc_reg_off + 0x24, val);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070079 val = (data->csc_post_lv[4] << 8) | data->csc_post_lv[5];
Clarence Ip373f8592016-05-26 00:58:42 -040080 SDE_REG_WRITE(c, csc_reg_off + 0x28, val);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070081
82 /* Pre-Bias */
Clarence Ip373f8592016-05-26 00:58:42 -040083 SDE_REG_WRITE(c, csc_reg_off + 0x2c, data->csc_pre_bv[0]);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070084 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 Ip373f8592016-05-26 00:58:42 -040088 SDE_REG_WRITE(c, csc_reg_off + 0x38, data->csc_post_bv[0]);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070089 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