22
33#include "adt.h"
44#include "dart.h"
5+ #include "firmware.h"
56#include "pmgr.h"
7+ #include "soc.h"
68#include "utils.h"
79
10+ #define ISP_ASC_VERSION 0x1800000
11+
12+ #define ISP_VER_T8103 0xb0090
13+ #define ISP_VER_T6000 0xb3091
14+ #define ISP_VER_T8112 0xc1090
15+ #define ISP_VER_T6020 0xc3091
16+
17+ // PMGR offset to enable to get the version info to work
18+ #define ISP_PMGR_T8103 0x4018
19+ #define ISP_PMGR_T6000 0x8
20+ #define ISP_PMGR_T6020 0x4008
21+
822/* ISP DART has some quirks we must work around */
923
1024#define DART_T8020_ENABLED_STREAMS 0xfc
@@ -66,18 +80,34 @@ static void isp_ctrr_init_t6000(u64 base, const struct dart_tunables *config, u3
6680 write32 (base + 0x13c , val );
6781}
6882
83+ static bool isp_initialized = false;
84+ static u64 heap_phys , heap_iova , heap_size , heap_top ;
85+
86+ int isp_get_heap (u64 * phys , u64 * iova , u64 * size )
87+ {
88+ if (!isp_initialized )
89+ return -1 ;
90+
91+ * phys = heap_phys ;
92+ * iova = heap_iova ;
93+ * size = heap_size ;
94+ return 0 ;
95+ }
96+
6997int isp_init (void )
7098{
7199 int err = 0 ;
72100
73101 const char * isp_path = "/arm-io/isp" ;
74102 const char * dart_path = "/arm-io/dart-isp" ;
75103
76- int adt_path [8 ];
104+ int adt_path [8 ], adt_isp_path [8 ];
105+ int isp_node = adt_path_offset_trace (adt , isp_path , adt_isp_path );
77106 int node = adt_path_offset_trace (adt , dart_path , adt_path );
78- if (node < 0 ) {
107+ if (node < 0 || isp_node < 0 ) {
79108 isp_path = "/arm-io/isp0" ;
80109 dart_path = "/arm-io/dart-isp0" ;
110+ isp_node = adt_path_offset_trace (adt , isp_path , adt_isp_path );
81111 node = adt_path_offset_trace (adt , dart_path , adt_path );
82112 }
83113 if (node < 0 )
@@ -86,6 +116,100 @@ int isp_init(void)
86116 if (pmgr_adt_power_enable (isp_path ) < 0 )
87117 return -1 ;
88118
119+ u64 isp_base ;
120+ u64 pmgr_base ;
121+ err = adt_get_reg (adt , adt_isp_path , "reg" , 0 , & isp_base , NULL );
122+ if (err )
123+ return err ;
124+
125+ err = adt_get_reg (adt , adt_isp_path , "reg" , 1 , & pmgr_base , NULL );
126+ if (err )
127+ return err ;
128+
129+ u32 pmgr_off ;
130+ switch (chip_id ) {
131+ case T8103 :
132+ case T8112 :
133+ pmgr_off = ISP_PMGR_T8103 ;
134+ break ;
135+ case T6000 ... T6002 :
136+ pmgr_off = ISP_PMGR_T6000 ;
137+ break ;
138+ case T6020 ... T6022 :
139+ pmgr_off = ISP_PMGR_T6020 ;
140+ break ;
141+ default :
142+ printf ("isp: Unsupported SoC\n" );
143+ return -1 ;
144+ }
145+
146+ err = pmgr_set_mode (pmgr_base + pmgr_off , PMGR_PS_ACTIVE );
147+ if (err ) {
148+ printf ("isp: Failed to power on\n" );
149+ return err ;
150+ }
151+
152+ u32 ver_rev = read32 (isp_base + ISP_ASC_VERSION );
153+ printf ("isp: Version 0x%x\n" , ver_rev );
154+
155+ pmgr_set_mode (pmgr_base + pmgr_off , PMGR_PS_PWRGATE );
156+
157+ /* TODO: confirm versions */
158+ switch (ver_rev ) {
159+ case ISP_VER_T8103 :
160+ case ISP_VER_T8112 :
161+ switch (os_firmware .version ) {
162+ case V12_3 ... V12_4 :
163+ heap_top = 0x1800000 ;
164+ break ;
165+ case V13_5 :
166+ heap_top = 0x1000000 ;
167+ break ;
168+ default :
169+ printf ("isp: unsupported firmware\n" );
170+ return -1 ;
171+ }
172+ break ;
173+ case ISP_VER_T6000 :
174+ switch (os_firmware .version ) {
175+ case V12_3 :
176+ heap_top = 0xe00000 ;
177+ break ;
178+ case V13_5 :
179+ heap_top = 0xf00000 ;
180+ break ;
181+ default :
182+ printf ("isp: unsupported firmware\n" );
183+ return -1 ;
184+ }
185+ break ;
186+ case ISP_VER_T6020 :
187+ switch (os_firmware .version ) {
188+ case V13_5 :
189+ heap_top = 0xf00000 ;
190+ break ;
191+ default :
192+ printf ("isp: unsupported firmware\n" );
193+ return -1 ;
194+ }
195+ break ;
196+ default :
197+ printf ("isp: unknown revision 0x%x\n" , ver_rev );
198+ return -1 ;
199+ }
200+
201+ const struct adt_segment_ranges * seg ;
202+ u32 segments_len ;
203+
204+ seg = adt_getprop (adt , isp_node , "segment-ranges" , & segments_len );
205+ unsigned int count = segments_len / sizeof (* seg );
206+
207+ heap_iova = seg [count - 1 ].iova + seg [count - 1 ].size ;
208+ heap_size = heap_top - heap_iova ;
209+ heap_phys = top_of_memory_alloc (heap_size );
210+
211+ printf ("isp: Heap: 0x%lx..0x%lx (0x%lx @ 0x%lx)\n" , heap_iova , heap_top , heap_size , heap_phys );
212+
89213 enum dart_type_t type ;
90214 const char * type_s ;
91215 if (adt_is_compatible (adt , node , "dart,t8020" )) {
@@ -137,6 +261,8 @@ int isp_init(void)
137261 }
138262 }
139263
264+ isp_initialized = true;
265+
140266out :
141267 pmgr_adt_power_disable (isp_path );
142268 return err ;
0 commit comments