4
4
5
5
#include " nb_smu_ops.h"
6
6
7
- u32 smu_service_req (nb_t nb ,u32 id ,smu_service_args_t *args)
7
+ u32 smu_service_req (smu_t *smu ,u32 id ,smu_service_args_t *args)
8
8
{
9
9
u32 response = 0x0 ;
10
10
DBG (" SMU_SERVICE REQ_ID:0x%x\n " , id);
11
11
DBG (" SMU_SERVICE REQ: arg0: 0x%x, arg1:0x%x, arg2:0x%x, arg3:0x%x, arg4: 0x%x, arg5: 0x%x\n " , \
12
12
args->arg0 , args->arg1 , args->arg2 , args->arg3 , args->arg4 , args->arg5 );
13
13
14
14
/* Clear the response */
15
- nb_reg_write (nb, MP1_C2PMSG_RESPONSE_ADDR , 0x0 );
15
+ nb_reg_write (smu-> nb , smu-> rep , 0x0 );
16
16
/* Pass arguments */
17
- nb_reg_write (nb, MP1_C2PMSG_ARGx_ADDR ( 0 ), args->arg0 );
18
- nb_reg_write (nb, MP1_C2PMSG_ARGx_ADDR ( 1 ), args->arg1 );
19
- nb_reg_write (nb, MP1_C2PMSG_ARGx_ADDR ( 2 ), args->arg2 );
20
- nb_reg_write (nb, MP1_C2PMSG_ARGx_ADDR ( 3 ), args->arg3 );
21
- nb_reg_write (nb, MP1_C2PMSG_ARGx_ADDR ( 4 ), args->arg4 );
22
- nb_reg_write (nb, MP1_C2PMSG_ARGx_ADDR ( 5 ), args->arg5 );
17
+ nb_reg_write (smu-> nb , C2PMSG_ARGx_ADDR (smu-> arg_base , 0 ), args->arg0 );
18
+ nb_reg_write (smu-> nb , C2PMSG_ARGx_ADDR (smu-> arg_base , 1 ), args->arg1 );
19
+ nb_reg_write (smu-> nb , C2PMSG_ARGx_ADDR (smu-> arg_base , 2 ), args->arg2 );
20
+ nb_reg_write (smu-> nb , C2PMSG_ARGx_ADDR (smu-> arg_base , 3 ), args->arg3 );
21
+ nb_reg_write (smu-> nb , C2PMSG_ARGx_ADDR (smu-> arg_base , 4 ), args->arg4 );
22
+ nb_reg_write (smu-> nb , C2PMSG_ARGx_ADDR (smu-> arg_base , 5 ), args->arg5 );
23
23
/* Send message ID */
24
- nb_reg_write (nb, MP1_C2PMSG_MESSAGE_ADDR , id);
24
+ nb_reg_write (smu-> nb , smu-> msg , id);
25
25
/* Wait until reponse changed */
26
26
while (response == 0x0 ) {
27
- response = nb_reg_read (nb, MP1_C2PMSG_RESPONSE_ADDR );
27
+ response = nb_reg_read (smu-> nb , smu-> rep );
28
28
}
29
29
/* Read back arguments */
30
- args->arg0 = nb_reg_read (nb, MP1_C2PMSG_ARGx_ADDR ( 0 ));
31
- args->arg1 = nb_reg_read (nb, MP1_C2PMSG_ARGx_ADDR ( 1 ));
32
- args->arg2 = nb_reg_read (nb, MP1_C2PMSG_ARGx_ADDR ( 2 ));
33
- args->arg3 = nb_reg_read (nb, MP1_C2PMSG_ARGx_ADDR ( 3 ));
34
- args->arg4 = nb_reg_read (nb, MP1_C2PMSG_ARGx_ADDR ( 4 ));
35
- args->arg5 = nb_reg_read (nb, MP1_C2PMSG_ARGx_ADDR ( 5 ));
30
+ args->arg0 = nb_reg_read (smu-> nb , C2PMSG_ARGx_ADDR (smu-> arg_base , 0 ));
31
+ args->arg1 = nb_reg_read (smu-> nb , C2PMSG_ARGx_ADDR (smu-> arg_base , 1 ));
32
+ args->arg2 = nb_reg_read (smu-> nb , C2PMSG_ARGx_ADDR (smu-> arg_base , 2 ));
33
+ args->arg3 = nb_reg_read (smu-> nb , C2PMSG_ARGx_ADDR (smu-> arg_base , 3 ));
34
+ args->arg4 = nb_reg_read (smu-> nb , C2PMSG_ARGx_ADDR (smu-> arg_base , 4 ));
35
+ args->arg5 = nb_reg_read (smu-> nb , C2PMSG_ARGx_ADDR (smu-> arg_base , 5 ));
36
36
37
37
DBG (" SMU_SERVICE REP: REP: 0x%x, arg0: 0x%x, arg1:0x%x, arg2:0x%x, arg3:0x%x, arg4: 0x%x, arg5: 0x%x\n " , \
38
38
response, args->arg0 , args->arg1 , args->arg2 , args->arg3 , args->arg4 , args->arg5 );
39
39
40
40
return response;
41
+ }
42
+
43
+ smu_t *get_smu (nb_t nb, int smu_type) {
44
+ smu_t *smu;
45
+ uint32_t rep; /* REP of test message */
46
+ smu_service_args_t arg = {0 , 0 , 0 , 0 , 0 , 0 }; /* Test message shuld have no arguments */
47
+
48
+ smu = (smu_t *)malloc ((sizeof (smu_t )));
49
+ smu->nb = nb;
50
+ /* Fill SMU information */
51
+ switch (smu_type){
52
+ case TYPE_MP1:
53
+ smu->msg = MP1_C2PMSG_MESSAGE_ADDR;
54
+ smu->rep = MP1_C2PMSG_RESPONSE_ADDR;
55
+ smu->arg_base = MP1_C2PMSG_ARG_BASE;
56
+ break ;
57
+ case TYPE_PSMU:
58
+ smu->msg = PSMU_C2PMSG_MESSAGE_ADDR;
59
+ smu->rep = PSMU_C2PMSG_RESPONSE_ADDR;
60
+ smu->arg_base = PSMU_C2PMSG_ARG_BASE;
61
+ break ;
62
+ default :
63
+ DBG (" Failed to get SMU, unknown SMU_TYPE: %s\n " , smu_type);
64
+ goto err;
65
+ break ;
66
+ }
67
+ /* Try to send a test message*/
68
+ rep = smu_service_req (smu, SMU_TEST_MSG, &arg);
69
+ if (rep == REP_MSG_OK){
70
+ return smu;
71
+ } else {
72
+ DBG (" Faild to get SMU: %s, test message REP: %x\n " , smu_type, rep);
73
+ goto err;
74
+ }
75
+ err:
76
+ free_smu (smu);
77
+ return NULL ;
78
+ }
79
+
80
+ void free_smu (smu_t *smu) {
81
+ free ((void *)smu);
41
82
}
0 commit comments