xref: /rk3399_ARM-atf/drivers/st/ddr/phy/phyinit/src/ddrphy_phyinit_softsetmb.c (revision eaaf26e3e6ac347cbfda00b6ba7d327e715d68f0)
1*79629b1aSNicolas Le Bayon /*
2*79629b1aSNicolas Le Bayon  * Copyright (C) 2021-2024, STMicroelectronics - All Rights Reserved
3*79629b1aSNicolas Le Bayon  *
4*79629b1aSNicolas Le Bayon  * SPDX-License-Identifier: BSD-3-Clause
5*79629b1aSNicolas Le Bayon  */
6*79629b1aSNicolas Le Bayon 
7*79629b1aSNicolas Le Bayon #include <assert.h>
8*79629b1aSNicolas Le Bayon #include <string.h>
9*79629b1aSNicolas Le Bayon 
10*79629b1aSNicolas Le Bayon #include <common/debug.h>
11*79629b1aSNicolas Le Bayon 
12*79629b1aSNicolas Le Bayon #include <ddrphy_phyinit.h>
13*79629b1aSNicolas Le Bayon 
14*79629b1aSNicolas Le Bayon /*
15*79629b1aSNicolas Le Bayon  * Set messageBlock variable only if not set by user
16*79629b1aSNicolas Le Bayon  *
17*79629b1aSNicolas Le Bayon  * This function is used by ddrphy_phyinit_calcmb() to set calculated
18*79629b1aSNicolas Le Bayon  * messageBlock variables only when the user has not directly programmed them.
19*79629b1aSNicolas Le Bayon  *
20*79629b1aSNicolas Le Bayon  * @param[in]   field   A string representing the messageBlock field to be programed.
21*79629b1aSNicolas Le Bayon  * @param[in]   value   filed value
22*79629b1aSNicolas Le Bayon  *
23*79629b1aSNicolas Le Bayon  * @return 0 on success.
24*79629b1aSNicolas Le Bayon  * On error  returns the following values based on error:
25*79629b1aSNicolas Le Bayon  * - -1 : message block field specified by the input \c field string is not
26*79629b1aSNicolas Le Bayon  * found in the message block data structure.
27*79629b1aSNicolas Le Bayon  */
ddrphy_phyinit_softsetmb(struct pmu_smb_ddr_1d * mb_ddr_1d,enum message_block_field field,uint32_t value)28*79629b1aSNicolas Le Bayon int ddrphy_phyinit_softsetmb(struct pmu_smb_ddr_1d *mb_ddr_1d, enum message_block_field field,
29*79629b1aSNicolas Le Bayon 			     uint32_t value)
30*79629b1aSNicolas Le Bayon {
31*79629b1aSNicolas Le Bayon 	int ret = 0;
32*79629b1aSNicolas Le Bayon 
33*79629b1aSNicolas Le Bayon 	if (field == MB_FIELD_DRAMFREQ) {
34*79629b1aSNicolas Le Bayon 		assert(value <= UINT16_MAX);
35*79629b1aSNicolas Le Bayon 	} else {
36*79629b1aSNicolas Le Bayon 		assert(value <= UINT8_MAX);
37*79629b1aSNicolas Le Bayon 	}
38*79629b1aSNicolas Le Bayon 
39*79629b1aSNicolas Le Bayon 	switch (field) {
40*79629b1aSNicolas Le Bayon 	case MB_FIELD_PSTATE:
41*79629b1aSNicolas Le Bayon 		mb_ddr_1d->pstate = (uint8_t)value;
42*79629b1aSNicolas Le Bayon 		break;
43*79629b1aSNicolas Le Bayon 	case MB_FIELD_PLLBYPASSEN:
44*79629b1aSNicolas Le Bayon 		mb_ddr_1d->pllbypassen = (uint8_t)value;
45*79629b1aSNicolas Le Bayon 		break;
46*79629b1aSNicolas Le Bayon 	case MB_FIELD_DRAMFREQ:
47*79629b1aSNicolas Le Bayon 		mb_ddr_1d->dramfreq = (uint16_t)value;
48*79629b1aSNicolas Le Bayon 		break;
49*79629b1aSNicolas Le Bayon 	case MB_FIELD_DFIFREQRATIO:
50*79629b1aSNicolas Le Bayon 		mb_ddr_1d->dfifreqratio = (uint8_t)value;
51*79629b1aSNicolas Le Bayon 		break;
52*79629b1aSNicolas Le Bayon 	case MB_FIELD_BPZNRESVAL:
53*79629b1aSNicolas Le Bayon 		mb_ddr_1d->bpznresval = (uint8_t)value;
54*79629b1aSNicolas Le Bayon 		break;
55*79629b1aSNicolas Le Bayon 	case MB_FIELD_PHYODTIMPEDANCE:
56*79629b1aSNicolas Le Bayon 		mb_ddr_1d->phyodtimpedance = (uint8_t)value;
57*79629b1aSNicolas Le Bayon 		break;
58*79629b1aSNicolas Le Bayon 	case MB_FIELD_PHYDRVIMPEDANCE:
59*79629b1aSNicolas Le Bayon 		mb_ddr_1d->phydrvimpedance = (uint8_t)value;
60*79629b1aSNicolas Le Bayon 		break;
61*79629b1aSNicolas Le Bayon #if STM32MP_DDR3_TYPE || STM32MP_DDR4_TYPE
62*79629b1aSNicolas Le Bayon 	case MB_FIELD_DRAMTYPE:
63*79629b1aSNicolas Le Bayon 		mb_ddr_1d->dramtype = (uint8_t)value;
64*79629b1aSNicolas Le Bayon 		break;
65*79629b1aSNicolas Le Bayon 	case MB_FIELD_DISABLEDDBYTE:
66*79629b1aSNicolas Le Bayon 		mb_ddr_1d->disableddbyte = (uint8_t)value;
67*79629b1aSNicolas Le Bayon 		break;
68*79629b1aSNicolas Le Bayon 	case MB_FIELD_ENABLEDDQS:
69*79629b1aSNicolas Le Bayon 		mb_ddr_1d->enableddqs = (uint8_t)value;
70*79629b1aSNicolas Le Bayon 		break;
71*79629b1aSNicolas Le Bayon 	case MB_FIELD_PHYCFG:
72*79629b1aSNicolas Le Bayon 		mb_ddr_1d->phycfg = (uint8_t)value;
73*79629b1aSNicolas Le Bayon 		break;
74*79629b1aSNicolas Le Bayon #if STM32MP_DDR4_TYPE
75*79629b1aSNicolas Le Bayon 	case MB_FIELD_X16PRESENT:
76*79629b1aSNicolas Le Bayon 		mb_ddr_1d->x16present = (uint8_t)value;
77*79629b1aSNicolas Le Bayon 		break;
78*79629b1aSNicolas Le Bayon #endif /* STM32MP_DDR4_TYPE */
79*79629b1aSNicolas Le Bayon #else /* STM32MP_LPDDR4_TYPE */
80*79629b1aSNicolas Le Bayon 	case MB_FIELD_ENABLEDDQSCHA:
81*79629b1aSNicolas Le Bayon 		mb_ddr_1d->enableddqscha = (uint8_t)value;
82*79629b1aSNicolas Le Bayon 		break;
83*79629b1aSNicolas Le Bayon 	case MB_FIELD_CSPRESENTCHA:
84*79629b1aSNicolas Le Bayon 		mb_ddr_1d->cspresentcha = (uint8_t)value;
85*79629b1aSNicolas Le Bayon 		break;
86*79629b1aSNicolas Le Bayon 	case MB_FIELD_ENABLEDDQSCHB:
87*79629b1aSNicolas Le Bayon 		mb_ddr_1d->enableddqschb = (uint8_t)value;
88*79629b1aSNicolas Le Bayon 		break;
89*79629b1aSNicolas Le Bayon 	case MB_FIELD_CSPRESENTCHB:
90*79629b1aSNicolas Le Bayon 		mb_ddr_1d->cspresentchb = (uint8_t)value;
91*79629b1aSNicolas Le Bayon 		break;
92*79629b1aSNicolas Le Bayon #endif /* STM32MP_DDR3_TYPE || STM32MP_DDR4_TYPE */
93*79629b1aSNicolas Le Bayon 	default:
94*79629b1aSNicolas Le Bayon 		ERROR("unknown message block field %u\n", field);
95*79629b1aSNicolas Le Bayon 		ret = -1;
96*79629b1aSNicolas Le Bayon 		break;
97*79629b1aSNicolas Le Bayon 	}
98*79629b1aSNicolas Le Bayon 
99*79629b1aSNicolas Le Bayon 	return ret;
100*79629b1aSNicolas Le Bayon }
101