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