blob: 689ac8f8c6f7f5bdc7e6c3fb970360863a587ee3 [file] [log] [blame]
Simon Glass881c8862021-07-18 19:02:40 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2021 Google LLC
4 */
5
6#define LOG_CATEGORY UCLASS_ETH
7
Simon Glass881c8862021-07-18 19:02:40 -06008#include <dm.h>
9#include <log.h>
10#include <asm/arch/pinmux.h>
11#include <asm/arch/sromc.h>
12
13enum {
14 FDT_SROM_PMC,
15 FDT_SROM_TACP,
16 FDT_SROM_TAH,
17 FDT_SROM_TCOH,
18 FDT_SROM_TACC,
19 FDT_SROM_TCOS,
20 FDT_SROM_TACS,
21
22 FDT_SROM_TIMING_COUNT,
23};
24
25static int exyno5_sromc_probe(struct udevice *dev)
26{
27 u32 timing[FDT_SROM_TIMING_COUNT]; /* timing parameters */
28 u32 smc_bw_conf, smc_bc_conf;
29 int bank; /* srom bank number */
30 int width; /* bus width in bytes */
31 int ret;
32
33 if (!IS_ENABLED(CONFIG_SMC911X))
34 return 0;
35
36 bank = dev_read_s32_default(dev, "bank", 0);
37 width = dev_read_s32_default(dev, "width", 2);
38
39 /* Ethernet needs data bus width of 16 bits */
40 if (width != 2) {
41 log_debug("Unsupported bus width %d\n", width);
42 return log_msg_ret("width", -EINVAL);
43 }
44 ret = dev_read_u32_array(dev, "srom-timing", timing,
45 FDT_SROM_TIMING_COUNT);
46 if (ret)
47 return log_msg_ret("sromc", -EINVAL);
48
49 smc_bw_conf = SROMC_DATA16_WIDTH(bank) | SROMC_BYTE_ENABLE(bank);
50 smc_bc_conf = SROMC_BC_TACS(timing[FDT_SROM_TACS]) |
51 SROMC_BC_TCOS(timing[FDT_SROM_TCOS]) |
52 SROMC_BC_TACC(timing[FDT_SROM_TACC]) |
53 SROMC_BC_TCOH(timing[FDT_SROM_TCOH]) |
54 SROMC_BC_TAH(timing[FDT_SROM_TAH]) |
55 SROMC_BC_TACP(timing[FDT_SROM_TACP]) |
56 SROMC_BC_PMC(timing[FDT_SROM_PMC]);
57
58 /* Select and configure the SROMC bank */
59 exynos_pinmux_config(PERIPH_ID_SROMC, bank);
60 s5p_config_sromc(bank, smc_bw_conf, smc_bc_conf);
61
62 return 0;
63}
64
65static const struct udevice_id exyno5_sromc_ids[] = {
66 { .compatible = "samsung,exynos5-sromc" },
67 {}
68};
69
70U_BOOT_DRIVER(exyno5_sromc) = {
71 .name = "exyno5_sromc",
72 .id = UCLASS_SIMPLE_BUS,
73 .of_match = exyno5_sromc_ids,
74 .probe = exyno5_sromc_probe,
75};