blob: e9f54d0ccd6baedfcaa3b55618a7fb379e40538c [file] [log] [blame]
Lloyd Atkinson77158732016-10-23 13:02:00 -04001/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
Alan Kwong5d324e42016-07-28 22:56:18 -04002 *
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_hwio.h"
14#include "sde_hw_catalog.h"
15#include "sde_hw_vbif.h"
Lloyd Atkinson113aefd2016-10-23 13:15:18 -040016#include "sde_dbg.h"
Alan Kwong5d324e42016-07-28 22:56:18 -040017
18#define VBIF_VERSION 0x0000
19#define VBIF_CLK_FORCE_CTRL0 0x0008
20#define VBIF_CLK_FORCE_CTRL1 0x000C
21#define VBIF_QOS_REMAP_00 0x0020
22#define VBIF_QOS_REMAP_01 0x0024
23#define VBIF_QOS_REMAP_10 0x0028
24#define VBIF_QOS_REMAP_11 0x002C
25#define VBIF_WRITE_GATHTER_EN 0x00AC
26#define VBIF_IN_RD_LIM_CONF0 0x00B0
27#define VBIF_IN_RD_LIM_CONF1 0x00B4
28#define VBIF_IN_RD_LIM_CONF2 0x00B8
29#define VBIF_IN_WR_LIM_CONF0 0x00C0
30#define VBIF_IN_WR_LIM_CONF1 0x00C4
31#define VBIF_IN_WR_LIM_CONF2 0x00C8
32#define VBIF_OUT_RD_LIM_CONF0 0x00D0
33#define VBIF_OUT_WR_LIM_CONF0 0x00D4
34#define VBIF_XIN_HALT_CTRL0 0x0200
35#define VBIF_XIN_HALT_CTRL1 0x0204
36
37static void sde_hw_set_limit_conf(struct sde_hw_vbif *vbif,
38 u32 xin_id, bool rd, u32 limit)
39{
40 struct sde_hw_blk_reg_map *c = &vbif->hw;
41 u32 reg_val;
42 u32 reg_off;
43 u32 bit_off;
44
45 if (rd)
46 reg_off = VBIF_IN_RD_LIM_CONF0;
47 else
48 reg_off = VBIF_IN_WR_LIM_CONF0;
49
50 reg_off += (xin_id / 4) * 4;
51 bit_off = (xin_id % 4) * 8;
52 reg_val = SDE_REG_READ(c, reg_off);
53 reg_val &= ~(0xFF << bit_off);
54 reg_val |= (limit) << bit_off;
55 SDE_REG_WRITE(c, reg_off, reg_val);
56}
57
58static u32 sde_hw_get_limit_conf(struct sde_hw_vbif *vbif,
59 u32 xin_id, bool rd)
60{
61 struct sde_hw_blk_reg_map *c = &vbif->hw;
62 u32 reg_val;
63 u32 reg_off;
64 u32 bit_off;
65 u32 limit;
66
67 if (rd)
68 reg_off = VBIF_IN_RD_LIM_CONF0;
69 else
70 reg_off = VBIF_IN_WR_LIM_CONF0;
71
72 reg_off += (xin_id / 4) * 4;
73 bit_off = (xin_id % 4) * 8;
74 reg_val = SDE_REG_READ(c, reg_off);
75 limit = (reg_val >> bit_off) & 0xFF;
76
77 return limit;
78}
79
80static void sde_hw_set_halt_ctrl(struct sde_hw_vbif *vbif,
81 u32 xin_id, bool enable)
82{
83 struct sde_hw_blk_reg_map *c = &vbif->hw;
84 u32 reg_val;
85
86 reg_val = SDE_REG_READ(c, VBIF_XIN_HALT_CTRL0);
87
88 if (enable)
89 reg_val |= BIT(xin_id);
90 else
91 reg_val &= ~BIT(xin_id);
92
93 SDE_REG_WRITE(c, VBIF_XIN_HALT_CTRL0, reg_val);
94}
95
96static bool sde_hw_get_halt_ctrl(struct sde_hw_vbif *vbif,
97 u32 xin_id)
98{
99 struct sde_hw_blk_reg_map *c = &vbif->hw;
100 u32 reg_val;
101
102 reg_val = SDE_REG_READ(c, VBIF_XIN_HALT_CTRL1);
103
104 return (reg_val & BIT(xin_id)) ? true : false;
105}
106
107static void _setup_vbif_ops(struct sde_hw_vbif_ops *ops,
108 unsigned long cap)
109{
110 ops->set_limit_conf = sde_hw_set_limit_conf;
111 ops->get_limit_conf = sde_hw_get_limit_conf;
112 ops->set_halt_ctrl = sde_hw_set_halt_ctrl;
113 ops->get_halt_ctrl = sde_hw_get_halt_ctrl;
114}
115
116static const struct sde_vbif_cfg *_top_offset(enum sde_vbif vbif,
117 const struct sde_mdss_cfg *m,
118 void __iomem *addr,
119 struct sde_hw_blk_reg_map *b)
120{
121 int i;
122
123 for (i = 0; i < m->vbif_count; i++) {
124 if (vbif == m->vbif[i].id) {
125 b->base_off = addr;
126 b->blk_off = m->vbif[i].base;
Lloyd Atkinson77158732016-10-23 13:02:00 -0400127 b->length = m->vbif[i].len;
Alan Kwong5d324e42016-07-28 22:56:18 -0400128 b->hwversion = m->hwversion;
129 b->log_mask = SDE_DBG_MASK_VBIF;
130 return &m->vbif[i];
131 }
132 }
133
134 return ERR_PTR(-EINVAL);
135}
136
137struct sde_hw_vbif *sde_hw_vbif_init(enum sde_vbif idx,
138 void __iomem *addr,
139 const struct sde_mdss_cfg *m)
140{
141 struct sde_hw_vbif *c;
142 const struct sde_vbif_cfg *cfg;
143
144 c = kzalloc(sizeof(*c), GFP_KERNEL);
145 if (!c)
146 return ERR_PTR(-ENOMEM);
147
148 cfg = _top_offset(idx, m, addr, &c->hw);
149 if (IS_ERR_OR_NULL(cfg)) {
150 kfree(c);
151 return ERR_PTR(-EINVAL);
152 }
153
154 /*
155 * Assign ops
156 */
157 c->idx = idx;
158 c->cap = cfg;
159 _setup_vbif_ops(&c->ops, c->cap->features);
160
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400161 sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
162 c->hw.blk_off + c->hw.length, c->hw.xin_id);
163
Alan Kwong5d324e42016-07-28 22:56:18 -0400164 return c;
165}
166
167void sde_hw_vbif_destroy(struct sde_hw_vbif *vbif)
168{
169 kfree(vbif);
170}