1a134789aSThierry Reding /*
2a134789aSThierry Reding  * Tegra host1x Register Offsets for Tegra210
3a134789aSThierry Reding  *
4a134789aSThierry Reding  * Copyright (c) 2015 NVIDIA Corporation.
5a134789aSThierry Reding  *
6a134789aSThierry Reding  * This program is free software; you can redistribute it and/or modify it
7a134789aSThierry Reding  * under the terms and conditions of the GNU General Public License,
8a134789aSThierry Reding  * version 2, as published by the Free Software Foundation.
9a134789aSThierry Reding  *
10a134789aSThierry Reding  * This program is distributed in the hope it will be useful, but WITHOUT
11a134789aSThierry Reding  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12a134789aSThierry Reding  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13a134789aSThierry Reding  * more details.
14a134789aSThierry Reding  *
15a134789aSThierry Reding  * You should have received a copy of the GNU General Public License
16a134789aSThierry Reding  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17a134789aSThierry Reding  */
18a134789aSThierry Reding 
19a134789aSThierry Reding #ifndef __HOST1X_HOST1X05_HARDWARE_H
20a134789aSThierry Reding #define __HOST1X_HOST1X05_HARDWARE_H
21a134789aSThierry Reding 
22a134789aSThierry Reding #include <linux/types.h>
23a134789aSThierry Reding #include <linux/bitops.h>
24a134789aSThierry Reding 
25a134789aSThierry Reding #include "hw_host1x05_channel.h"
26a134789aSThierry Reding #include "hw_host1x05_sync.h"
27a134789aSThierry Reding #include "hw_host1x05_uclass.h"
28a134789aSThierry Reding 
29a134789aSThierry Reding static inline u32 host1x_class_host_wait_syncpt(
30a134789aSThierry Reding 	unsigned indx, unsigned threshold)
31a134789aSThierry Reding {
32a134789aSThierry Reding 	return host1x_uclass_wait_syncpt_indx_f(indx)
33a134789aSThierry Reding 		| host1x_uclass_wait_syncpt_thresh_f(threshold);
34a134789aSThierry Reding }
35a134789aSThierry Reding 
36a134789aSThierry Reding static inline u32 host1x_class_host_load_syncpt_base(
37a134789aSThierry Reding 	unsigned indx, unsigned threshold)
38a134789aSThierry Reding {
39a134789aSThierry Reding 	return host1x_uclass_load_syncpt_base_base_indx_f(indx)
40a134789aSThierry Reding 		| host1x_uclass_load_syncpt_base_value_f(threshold);
41a134789aSThierry Reding }
42a134789aSThierry Reding 
43a134789aSThierry Reding static inline u32 host1x_class_host_wait_syncpt_base(
44a134789aSThierry Reding 	unsigned indx, unsigned base_indx, unsigned offset)
45a134789aSThierry Reding {
46a134789aSThierry Reding 	return host1x_uclass_wait_syncpt_base_indx_f(indx)
47a134789aSThierry Reding 		| host1x_uclass_wait_syncpt_base_base_indx_f(base_indx)
48a134789aSThierry Reding 		| host1x_uclass_wait_syncpt_base_offset_f(offset);
49a134789aSThierry Reding }
50a134789aSThierry Reding 
51a134789aSThierry Reding static inline u32 host1x_class_host_incr_syncpt_base(
52a134789aSThierry Reding 	unsigned base_indx, unsigned offset)
53a134789aSThierry Reding {
54a134789aSThierry Reding 	return host1x_uclass_incr_syncpt_base_base_indx_f(base_indx)
55a134789aSThierry Reding 		| host1x_uclass_incr_syncpt_base_offset_f(offset);
56a134789aSThierry Reding }
57a134789aSThierry Reding 
58a134789aSThierry Reding static inline u32 host1x_class_host_incr_syncpt(
59a134789aSThierry Reding 	unsigned cond, unsigned indx)
60a134789aSThierry Reding {
61a134789aSThierry Reding 	return host1x_uclass_incr_syncpt_cond_f(cond)
62a134789aSThierry Reding 		| host1x_uclass_incr_syncpt_indx_f(indx);
63a134789aSThierry Reding }
64a134789aSThierry Reding 
65a134789aSThierry Reding static inline u32 host1x_class_host_indoff_reg_write(
66a134789aSThierry Reding 	unsigned mod_id, unsigned offset, bool auto_inc)
67a134789aSThierry Reding {
68a134789aSThierry Reding 	u32 v = host1x_uclass_indoff_indbe_f(0xf)
69a134789aSThierry Reding 		| host1x_uclass_indoff_indmodid_f(mod_id)
70a134789aSThierry Reding 		| host1x_uclass_indoff_indroffset_f(offset);
71a134789aSThierry Reding 	if (auto_inc)
72a134789aSThierry Reding 		v |= host1x_uclass_indoff_autoinc_f(1);
73a134789aSThierry Reding 	return v;
74a134789aSThierry Reding }
75a134789aSThierry Reding 
76a134789aSThierry Reding static inline u32 host1x_class_host_indoff_reg_read(
77a134789aSThierry Reding 	unsigned mod_id, unsigned offset, bool auto_inc)
78a134789aSThierry Reding {
79a134789aSThierry Reding 	u32 v = host1x_uclass_indoff_indmodid_f(mod_id)
80a134789aSThierry Reding 		| host1x_uclass_indoff_indroffset_f(offset)
81a134789aSThierry Reding 		| host1x_uclass_indoff_rwn_read_v();
82a134789aSThierry Reding 	if (auto_inc)
83a134789aSThierry Reding 		v |= host1x_uclass_indoff_autoinc_f(1);
84a134789aSThierry Reding 	return v;
85a134789aSThierry Reding }
86a134789aSThierry Reding 
87a134789aSThierry Reding /* cdma opcodes */
88a134789aSThierry Reding static inline u32 host1x_opcode_setclass(
89a134789aSThierry Reding 	unsigned class_id, unsigned offset, unsigned mask)
90a134789aSThierry Reding {
91a134789aSThierry Reding 	return (0 << 28) | (offset << 16) | (class_id << 6) | mask;
92a134789aSThierry Reding }
93a134789aSThierry Reding 
94a134789aSThierry Reding static inline u32 host1x_opcode_incr(unsigned offset, unsigned count)
95a134789aSThierry Reding {
96a134789aSThierry Reding 	return (1 << 28) | (offset << 16) | count;
97a134789aSThierry Reding }
98a134789aSThierry Reding 
99a134789aSThierry Reding static inline u32 host1x_opcode_nonincr(unsigned offset, unsigned count)
100a134789aSThierry Reding {
101a134789aSThierry Reding 	return (2 << 28) | (offset << 16) | count;
102a134789aSThierry Reding }
103a134789aSThierry Reding 
104a134789aSThierry Reding static inline u32 host1x_opcode_mask(unsigned offset, unsigned mask)
105a134789aSThierry Reding {
106a134789aSThierry Reding 	return (3 << 28) | (offset << 16) | mask;
107a134789aSThierry Reding }
108a134789aSThierry Reding 
109a134789aSThierry Reding static inline u32 host1x_opcode_imm(unsigned offset, unsigned value)
110a134789aSThierry Reding {
111a134789aSThierry Reding 	return (4 << 28) | (offset << 16) | value;
112a134789aSThierry Reding }
113a134789aSThierry Reding 
114a134789aSThierry Reding static inline u32 host1x_opcode_imm_incr_syncpt(unsigned cond, unsigned indx)
115a134789aSThierry Reding {
116a134789aSThierry Reding 	return host1x_opcode_imm(host1x_uclass_incr_syncpt_r(),
117a134789aSThierry Reding 		host1x_class_host_incr_syncpt(cond, indx));
118a134789aSThierry Reding }
119a134789aSThierry Reding 
120a134789aSThierry Reding static inline u32 host1x_opcode_restart(unsigned address)
121a134789aSThierry Reding {
122a134789aSThierry Reding 	return (5 << 28) | (address >> 4);
123a134789aSThierry Reding }
124a134789aSThierry Reding 
125a134789aSThierry Reding static inline u32 host1x_opcode_gather(unsigned count)
126a134789aSThierry Reding {
127a134789aSThierry Reding 	return (6 << 28) | count;
128a134789aSThierry Reding }
129a134789aSThierry Reding 
130a134789aSThierry Reding static inline u32 host1x_opcode_gather_nonincr(unsigned offset,	unsigned count)
131a134789aSThierry Reding {
132a134789aSThierry Reding 	return (6 << 28) | (offset << 16) | BIT(15) | count;
133a134789aSThierry Reding }
134a134789aSThierry Reding 
135a134789aSThierry Reding static inline u32 host1x_opcode_gather_incr(unsigned offset, unsigned count)
136a134789aSThierry Reding {
137a134789aSThierry Reding 	return (6 << 28) | (offset << 16) | BIT(15) | BIT(14) | count;
138a134789aSThierry Reding }
139a134789aSThierry Reding 
140a134789aSThierry Reding #define HOST1X_OPCODE_NOP host1x_opcode_nonincr(0, 0)
141a134789aSThierry Reding 
142a134789aSThierry Reding #endif
143