| 1 |
/* |
| 2 |
* Copyright (C) 2021 Marvell International Ltd. |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: BSD-3-Clause |
| 5 |
* https://spdx.org/licenses |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "ddr_phy_access.h" |
| 9 |
#include <lib/mmio.h> |
| 10 |
#include <drivers/marvell/ccu.h> |
| 11 |
#include <errno.h> |
| 12 |
|
| 13 |
#define DDR_PHY_END_ADDRESS 0x100000 |
| 14 |
|
| 15 |
#ifdef DDR_PHY_DEBUG |
| 16 |
#define debug_printf(...) printf(__VA_ARGS__) |
| 17 |
#else |
| 18 |
#define debug_printf(...) |
| 19 |
#endif |
| 20 |
|
| 21 |
|
| 22 |
/* |
| 23 |
* This routine writes 'data' to specified 'address' offset, |
| 24 |
* with optional debug print support |
| 25 |
*/ |
| 26 |
int snps_fw_write(uintptr_t offset, uint16_t data) |
| 27 |
{ |
| 28 |
debug_printf("In %s\n", __func__); |
| 29 |
|
| 30 |
if (offset < DDR_PHY_END_ADDRESS) { |
| 31 |
mmio_write_16(DDR_PHY_BASE_ADDR + (2 * offset), data); |
| 32 |
return 0; |
| 33 |
} |
| 34 |
debug_printf("%s: illegal offset value: 0x%x\n", __func__, offset); |
| 35 |
return -EINVAL; |
| 36 |
} |
| 37 |
|
| 38 |
int snps_fw_read(uintptr_t offset, uint16_t *read) |
| 39 |
{ |
| 40 |
debug_printf("In %s\n", __func__); |
| 41 |
|
| 42 |
if (offset < DDR_PHY_END_ADDRESS) { |
| 43 |
*read = mmio_read_16(DDR_PHY_BASE_ADDR + (2 * offset)); |
| 44 |
return 0; |
| 45 |
} |
| 46 |
debug_printf("%s: illegal offset value: 0x%x\n", __func__, offset); |
| 47 |
return -EINVAL; |
| 48 |
} |
| 49 |
|
| 50 |
int mvebu_ddr_phy_write(uintptr_t offset, uint16_t data) |
| 51 |
{ |
| 52 |
return snps_fw_write(offset, data); |
| 53 |
} |
| 54 |
|
| 55 |
int mvebu_ddr_phy_read(uintptr_t offset, uint16_t *read) |
| 56 |
{ |
| 57 |
return snps_fw_read(offset, read); |
| 58 |
} |