blob: d2df9351eaccd49637118fb921f383b6cc928d16 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Calvin Johnsonb2231452018-03-08 15:30:29 +05302/*
3 * Copyright 2015-2016 Freescale Semiconductor, Inc.
4 * Copyright 2017 NXP
Calvin Johnsonb2231452018-03-08 15:30:29 +05305 */
6
Tom Riniabb9a042024-05-18 20:20:43 -06007#include <common.h>
Calvin Johnsonb2231452018-03-08 15:30:29 +05308#include <dm.h>
Simon Glass0c364412019-12-28 10:44:48 -07009#include <net.h>
Calvin Johnsonb2231452018-03-08 15:30:29 +053010#include <asm/io.h>
11#include <netdev.h>
12#include <fm_eth.h>
13#include <fsl_mdio.h>
14#include <malloc.h>
15#include <asm/types.h>
16#include <fsl_dtsec.h>
17#include <asm/arch/soc.h>
18#include <asm/arch-fsl-layerscape/config.h>
19#include <asm/arch-fsl-layerscape/immap_lsch2.h>
20#include <asm/arch/fsl_serdes.h>
Simon Glassdbd79542020-05-10 11:40:11 -060021#include <linux/delay.h>
Calvin Johnsonb2231452018-03-08 15:30:29 +053022#include <net/pfe_eth/pfe_eth.h>
23#include <dm/platform_data/pfe_dm_eth.h>
24
25#define DEFAULT_PFE_MDIO_NAME "PFE_MDIO"
26#define DEFAULT_PFE_MDIO1_NAME "PFE_MDIO1"
27
28#define MASK_ETH_PHY_RST 0x00000100
29
30static inline void ls1012afrdm_reset_phy(void)
31{
32 unsigned int val;
33 struct ccsr_gpio *pgpio = (void *)(GPIO1_BASE_ADDR);
34
35 setbits_be32(&pgpio->gpdir, MASK_ETH_PHY_RST);
36
37 val = in_be32(&pgpio->gpdat);
38 setbits_be32(&pgpio->gpdat, val & ~MASK_ETH_PHY_RST);
39 mdelay(10);
40
41 val = in_be32(&pgpio->gpdat);
42 setbits_be32(&pgpio->gpdat, val | MASK_ETH_PHY_RST);
43 mdelay(50);
44}
45
46int pfe_eth_board_init(struct udevice *dev)
47{
48 static int init_done;
49 struct mii_dev *bus;
50 struct pfe_mdio_info mac_mdio_info;
51 struct pfe_eth_dev *priv = dev_get_priv(dev);
52
53 if (!init_done) {
54 ls1012afrdm_reset_phy();
55
56 mac_mdio_info.reg_base = (void *)EMAC1_BASE_ADDR;
57 mac_mdio_info.name = DEFAULT_PFE_MDIO_NAME;
58
59 bus = pfe_mdio_init(&mac_mdio_info);
60 if (!bus) {
61 printf("Failed to register mdio\n");
62 return -1;
63 }
64
65 init_done = 1;
66 }
67
68 if (priv->gemac_port) {
69 mac_mdio_info.reg_base = (void *)EMAC2_BASE_ADDR;
70 mac_mdio_info.name = DEFAULT_PFE_MDIO1_NAME;
71 bus = pfe_mdio_init(&mac_mdio_info);
72 if (!bus) {
73 printf("Failed to register mdio\n");
74 return -1;
75 }
76 }
77
78 pfe_set_mdio(priv->gemac_port,
79 miiphy_get_dev_by_name(DEFAULT_PFE_MDIO_NAME));
80 if (!priv->gemac_port)
81 /* MAC1 */
82 pfe_set_phy_address_mode(priv->gemac_port,
83 CONFIG_PFE_EMAC1_PHY_ADDR,
84 PHY_INTERFACE_MODE_SGMII);
85 else
86 /* MAC2 */
87 pfe_set_phy_address_mode(priv->gemac_port,
88 CONFIG_PFE_EMAC2_PHY_ADDR,
89 PHY_INTERFACE_MODE_SGMII);
90 return 0;
91}
92
93static struct pfe_eth_pdata pfe_pdata0 = {
94 .pfe_eth_pdata_mac = {
95 .iobase = (phys_addr_t)EMAC1_BASE_ADDR,
96 .phy_interface = 0,
97 },
98
99 .pfe_ddr_addr = {
100 .ddr_pfe_baseaddr = (void *)CONFIG_DDR_PFE_BASEADDR,
101 .ddr_pfe_phys_baseaddr = CONFIG_DDR_PFE_PHYS_BASEADDR,
102 },
103};
104
105static struct pfe_eth_pdata pfe_pdata1 = {
106 .pfe_eth_pdata_mac = {
107 .iobase = (phys_addr_t)EMAC2_BASE_ADDR,
108 .phy_interface = 1,
109 },
110
111 .pfe_ddr_addr = {
112 .ddr_pfe_baseaddr = (void *)CONFIG_DDR_PFE_BASEADDR,
113 .ddr_pfe_phys_baseaddr = CONFIG_DDR_PFE_PHYS_BASEADDR,
114 },
115};
116
Simon Glass1d8364a2020-12-28 20:34:54 -0700117U_BOOT_DRVINFO(ls1012a_pfe0) = {
Calvin Johnsonb2231452018-03-08 15:30:29 +0530118 .name = "pfe_eth",
Simon Glass71fa5b42020-12-03 16:55:18 -0700119 .plat = &pfe_pdata0,
Calvin Johnsonb2231452018-03-08 15:30:29 +0530120};
121
Simon Glass1d8364a2020-12-28 20:34:54 -0700122U_BOOT_DRVINFO(ls1012a_pfe1) = {
Calvin Johnsonb2231452018-03-08 15:30:29 +0530123 .name = "pfe_eth",
Simon Glass71fa5b42020-12-03 16:55:18 -0700124 .plat = &pfe_pdata1,
Calvin Johnsonb2231452018-03-08 15:30:29 +0530125};