11/* SPDX-License-Identifier: MIT */
22
33#include "adt.h"
4+ #include "dart.h"
45#include "pmgr.h"
56#include "utils.h"
67
@@ -21,19 +22,79 @@ struct dart_tunables {
2122 u64 set ;
2223};
2324
25+ static void isp_ctrr_init_t8020 (u64 base , const struct dart_tunables * config , u32 length )
26+ {
27+ /* DART error handler gets stuck w/o these */
28+ write32 (base + DART_T8020_ENABLED_STREAMS , 0x1 );
29+ write32 (base + 0x2f0 , 0x0 );
30+ write32 (base + DART_T8020_STREAM_SELECT , 0xffffffff );
31+ write32 (base + DART_T8020_STREAM_COMMAND , DART_T8020_STREAM_COMMAND_INVALIDATE );
32+
33+ /* I think these lock CTRR? Configurable __TEXT read-only region? */
34+ int count = length / sizeof (* config );
35+ for (int i = 0 ; i < count ; i ++ ) {
36+ u64 offset = config -> offset & 0xffff ;
37+ u32 set = config -> set & 0xffffffff ;
38+ mask32 (base + offset , read32 (base + offset ), set );
39+ config ++ ;
40+ }
41+
42+ write32 (base + DART_T8020_TCR_OFF , DART_T8020_TCR_TRANSLATE_ENABLE );
43+ write32 (base + 0x13c , 0x20000 );
44+ }
45+
46+ static void isp_ctrr_init_t6000 (u64 base , const struct dart_tunables * config , u32 length )
47+ {
48+ write32 (base + DART_T8020_ENABLED_STREAMS , 0x1 );
49+ write32 (base + 0x2f0 , 0x0 );
50+ write32 (base + DART_T8020_STREAM_SELECT , 0xffff ); // diff from t8020
51+ write32 (base + DART_T8020_STREAM_COMMAND , 0x0 );
52+
53+ int count = length / sizeof (* config );
54+ for (int i = 0 ; i < count ; i ++ ) {
55+ u64 offset = config -> offset & 0xffff ;
56+ u32 set = config -> set & 0xffffffff ;
57+ mask32 (base + offset , read32 (base + offset ), set );
58+ config ++ ;
59+ }
60+
61+ write32 (base + DART_T8020_TCR_OFF , DART_T8020_TCR_TRANSLATE_ENABLE );
62+ write32 (base + 0x13c , 0x20000 );
63+ }
64+
2465int isp_init (void )
2566{
2667 int err = 0 ;
27- const char * path = "/arm-io/isp" ;
28- const char * dart_path = "/arm-io/dart-isp" ;
2968
30- if ( pmgr_adt_power_enable ( path ) < 0 )
31- return -1 ;
69+ const char * isp_path = "/arm-io/isp" ;
70+ const char * dart_path = "/arm-io/dart-isp" ;
3271
3372 int adt_path [8 ];
3473 int node = adt_path_offset_trace (adt , dart_path , adt_path );
3574 if (node < 0 ) {
36- printf ("isp: Error getting node %s\n" , dart_path );
75+ isp_path = "/arm-io/isp0" ;
76+ dart_path = "/arm-io/dart-isp0" ;
77+ node = adt_path_offset_trace (adt , dart_path , adt_path );
78+ }
79+ if (node < 0 )
80+ return 0 ;
81+
82+ if (pmgr_adt_power_enable (isp_path ) < 0 )
83+ return -1 ;
84+
85+ enum dart_type_t type ;
86+ const char * type_s ;
87+ if (adt_is_compatible (adt , node , "dart,t8020" )) {
88+ type = DART_T8020 ;
89+ type_s = "t8020" ;
90+ } else if (adt_is_compatible (adt , node , "dart,t6000" )) {
91+ type = DART_T6000 ;
92+ type_s = "t6000" ;
93+ } else if (adt_is_compatible (adt , node , "dart,t8110" )) {
94+ type = DART_T8110 ;
95+ type_s = "t8110" ;
96+ } else {
97+ printf ("isp: dart %s is of an unknown type\n" , dart_path );
3798 return -1 ;
3899 }
39100
@@ -49,7 +110,7 @@ int isp_init(void)
49110 snprintf (prop , sizeof (prop ), "dart-tunables-instance-%u" , index );
50111 const struct dart_tunables * config = adt_getprop (adt , node , prop , & length );
51112 if (!config || !length ) {
52- printf ("isp: Error getting ADT node %s property %s.\n" , path , prop );
113+ printf ("isp: Error getting ADT node %s property %s.\n" , isp_path , prop );
53114 err = -1 ;
54115 goto out ;
55116 }
@@ -58,26 +119,21 @@ int isp_init(void)
58119 if (err < 0 )
59120 goto out ;
60121
61- /* DART error handler gets stuck w/o these */
62- write32 (base + DART_T8020_ENABLED_STREAMS , 0x1 );
63- write32 (base + 0x2f0 , 0x0 );
64- write32 (base + DART_T8020_STREAM_SELECT , 0xffffffff );
65- write32 (base + DART_T8020_STREAM_COMMAND , DART_T8020_STREAM_COMMAND_INVALIDATE );
66-
67- /* I think these lock CTRR? Coproc __TEXT read-only region? */
68- int count = length / sizeof (* config );
69- for (int i = 0 ; i < count ; i ++ ) {
70- u64 offset = config -> offset & 0xffff ;
71- u32 set = config -> set & 0xffffffff ;
72- mask32 (base + offset , read32 (base + offset ), set );
73- config ++ ;
122+ switch (type ) {
123+ case DART_T8020 :
124+ isp_ctrr_init_t8020 (base , config , length );
125+ break ;
126+ case DART_T6000 :
127+ isp_ctrr_init_t6000 (base , config , length );
128+ break ;
129+ case DART_T8110 :
130+ printf ("isp: warning: dart type %s not tested yet!\n" , type_s );
131+ isp_ctrr_init_t8020 (base , config , length );
132+ break ;
74133 }
75-
76- write32 (base + DART_T8020_TCR_OFF , DART_T8020_TCR_TRANSLATE_ENABLE );
77- write32 (base + 0x13c , 0x20000 );
78134 }
79135
80136out :
81- pmgr_adt_power_disable (path );
137+ pmgr_adt_power_disable (isp_path );
82138 return err ;
83139}
0 commit comments