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