Home | History | Annotate | Line # | Download | only in rockchip
      1  1.3  msaitoh /*	$NetBSD: rk_eqos.c,v 1.3 2024/02/07 04:20:27 msaitoh Exp $	*/
      2  1.1      ryo 
      3  1.1      ryo /*-
      4  1.3  msaitoh  * Copyright (c) 2022 Ryo Shimizu
      5  1.1      ryo  * All rights reserved.
      6  1.1      ryo  *
      7  1.1      ryo  * Redistribution and use in source and binary forms, with or without
      8  1.1      ryo  * modification, are permitted provided that the following conditions
      9  1.1      ryo  * are met:
     10  1.1      ryo  * 1. Redistributions of source code must retain the above copyright
     11  1.1      ryo  *    notice, this list of conditions and the following disclaimer.
     12  1.1      ryo  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1      ryo  *    notice, this list of conditions and the following disclaimer in the
     14  1.1      ryo  *    documentation and/or other materials provided with the distribution.
     15  1.1      ryo  *
     16  1.1      ryo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     17  1.1      ryo  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18  1.1      ryo  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.1      ryo  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     20  1.1      ryo  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21  1.1      ryo  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22  1.1      ryo  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.1      ryo  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     24  1.1      ryo  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     25  1.1      ryo  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1      ryo  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1      ryo  */
     28  1.1      ryo 
     29  1.1      ryo #include <sys/cdefs.h>
     30  1.3  msaitoh __KERNEL_RCSID(0, "$NetBSD: rk_eqos.c,v 1.3 2024/02/07 04:20:27 msaitoh Exp $");
     31  1.1      ryo 
     32  1.1      ryo #include <sys/param.h>
     33  1.1      ryo #include <sys/bus.h>
     34  1.1      ryo #include <sys/device.h>
     35  1.1      ryo #include <sys/rndsource.h>
     36  1.1      ryo 
     37  1.1      ryo #include <net/if_ether.h>
     38  1.1      ryo #include <net/if_media.h>
     39  1.1      ryo 
     40  1.1      ryo #include <dev/fdt/fdtvar.h>
     41  1.1      ryo #include <dev/fdt/syscon.h>
     42  1.1      ryo 
     43  1.1      ryo #include <dev/mii/miivar.h>
     44  1.1      ryo #include <dev/ic/dwc_eqos_var.h>
     45  1.1      ryo 
     46  1.1      ryo struct rk_eqos_softc {
     47  1.1      ryo 	struct eqos_softc sc_base;
     48  1.1      ryo 
     49  1.1      ryo 	struct syscon *sc_grf;
     50  1.1      ryo 	struct syscon *sc_php_grf;
     51  1.1      ryo 	int sc_id;	/* ethernet0 or 1? */
     52  1.1      ryo };
     53  1.1      ryo 
     54  1.1      ryo static int rk_eqos_match(device_t, cfdata_t, void *);
     55  1.1      ryo static void rk_eqos_attach(device_t, device_t, void *);
     56  1.1      ryo 
     57  1.1      ryo struct rk_eqos_ops {
     58  1.1      ryo 	void (*set_mode_rgmii)(struct rk_eqos_softc *, int, int);
     59  1.1      ryo 	void (*set_speed_rgmii)(struct rk_eqos_softc *, int);
     60  1.1      ryo 	void (*clock_selection)(struct rk_eqos_softc *, int);
     61  1.1      ryo 	int (*get_unit)(struct rk_eqos_softc *, int);
     62  1.1      ryo };
     63  1.1      ryo 
     64  1.1      ryo CFATTACH_DECL_NEW(rk_eqos, sizeof(struct rk_eqos_softc),
     65  1.1      ryo     rk_eqos_match, rk_eqos_attach, NULL, NULL);
     66  1.1      ryo 
     67  1.1      ryo /*
     68  1.1      ryo  * RK3588 specific
     69  1.1      ryo  */
     70  1.1      ryo #define RK3588_ETHERNET1_ADDR			0xfe1c0000
     71  1.1      ryo 
     72  1.1      ryo /* grf */
     73  1.1      ryo #define RK3588_GRF_GMAC_TXRXCLK_DELAY_EN_REG	(0x0300 + (4 * 7))
     74  1.1      ryo #define  RK3588_GMAC_RXCLK_DELAY_EN(id)		__BIT(3 + 2 * (id))
     75  1.1      ryo #define   RK3588_GMAC_RXCLK_DELAY_DISABLE	0
     76  1.1      ryo #define   RK3588_GMAC_RXCLK_DELAY_ENABLE	1
     77  1.1      ryo #define  RK3588_GMAC_TXCLK_DELAY_EN(id)		__BIT(2 + 2 * (id))
     78  1.1      ryo #define   RK3588_GMAC_TXCLK_DELAY_DISABLE	0
     79  1.1      ryo #define   RK3588_GMAC_TXCLK_DELAY_ENABLE	1
     80  1.1      ryo #define RK3588_GRF_GMAC_TXRX_DELAY_CFG_REG(id)	(0x0300 + (4 * 8) + (4 * (id)))
     81  1.1      ryo #define  RK3588_GMAC_RXCLK_DELAY_CFG		__BITS(15,8)
     82  1.1      ryo #define  RK3588_GMAC_TXCLK_DELAY_CFG		__BITS(7,0)
     83  1.1      ryo 
     84  1.1      ryo /* grf_php */
     85  1.1      ryo #define RK3588_GRF_GMAC_PHY_REG			0x0008
     86  1.1      ryo #define  RK3588_GMAC_PHY_IFACE_SEL(id)		(__BITS(5,3) << ((id) * 6))
     87  1.1      ryo #define   RK3588_GMAC_PHY_IFACE_SEL_RGMII	1
     88  1.1      ryo #define   RK3588_GMAC_PHY_IFACE_SEL_RMII	4
     89  1.1      ryo #define RK3588_GRF_CLK_CON1			0x0070
     90  1.1      ryo #define RK3588_GRF_GMAC_CLK_REG			0x0070
     91  1.1      ryo #define  RK3588_GMAC_CLK_SELECT(id)		__BIT(4 + 5 * (id))
     92  1.1      ryo #define   RK3588_GMAC_CLK_SELECT_IO		0
     93  1.1      ryo #define   RK3588_GMAC_CLK_SELECT_CRU		1
     94  1.1      ryo #define  RK3588_GMAC_CLK_RMII_DIV(id)		__BIT(2 + 5 * (id))
     95  1.1      ryo #define   RK3588_GMA_CLK_RMII_DIV_DIV20		0
     96  1.1      ryo #define   RK3588_GMA_CLK_RMII_DIV_DIV2		1
     97  1.1      ryo #define  RK3588_GMAC_CLK_RGMII_DIV(id)		(__BITS(3,2) << ((id) * 5))
     98  1.1      ryo #define   RK3588_GMAC_CLK_RGMII_DIV_DIV1	1
     99  1.1      ryo #define   RK3588_GMAC_CLK_RGMII_DIV_DIV50	2
    100  1.1      ryo #define   RK3588_GMAC_CLK_RGMII_DIV_DIV5	3
    101  1.1      ryo #define  RK3588_GMAC_CLK_RMII_GATE_EN(id)	__BIT(1 + (id) * 5)
    102  1.1      ryo #define   RK3588_GMAC_CLK_RMII_GATE_DISABLE	0
    103  1.1      ryo #define   RK3588_GMAC_CLK_RMII_GATE_ENABLE	1
    104  1.1      ryo #define  RK3588_GMAC_CLK_MODE(id)		__BIT(0 + (id) * 5)
    105  1.1      ryo #define   RK3588_GMAC_CLK_MODE_RGMII		0
    106  1.1      ryo #define   RK3588_GMAC_CLK_MODE_RMII		1
    107  1.1      ryo 
    108  1.1      ryo static void
    109  1.1      ryo rk3588_eqos_set_mode_rgmii(struct rk_eqos_softc *rk_sc,
    110  1.1      ryo     int tx_delay, int rx_delay)
    111  1.1      ryo {
    112  1.1      ryo 	const int id = rk_sc->sc_id;
    113  1.1      ryo 	uint32_t txen, rxen;
    114  1.1      ryo 
    115  1.1      ryo 	if (tx_delay >= 0) {
    116  1.1      ryo 		txen = RK3588_GMAC_TXCLK_DELAY_ENABLE;
    117  1.1      ryo 	} else {
    118  1.1      ryo 		txen = RK3588_GMAC_TXCLK_DELAY_DISABLE;
    119  1.1      ryo 		tx_delay = 0;
    120  1.1      ryo 	}
    121  1.1      ryo 	if (rx_delay >= 0) {
    122  1.1      ryo 		rxen = RK3588_GMAC_RXCLK_DELAY_ENABLE;
    123  1.1      ryo 	} else {
    124  1.1      ryo 		rxen = RK3588_GMAC_RXCLK_DELAY_DISABLE;
    125  1.1      ryo 		rx_delay = 0;
    126  1.1      ryo 	}
    127  1.1      ryo 
    128  1.1      ryo 	syscon_lock(rk_sc->sc_grf);
    129  1.1      ryo 	syscon_write_4(rk_sc->sc_grf, RK3588_GRF_GMAC_TXRXCLK_DELAY_EN_REG,
    130  1.1      ryo 	    RK3588_GMAC_TXCLK_DELAY_EN(id) << 16 |		/* masks */
    131  1.1      ryo 	    RK3588_GMAC_RXCLK_DELAY_EN(id) << 16 |
    132  1.1      ryo 	    __SHIFTIN(txen, RK3588_GMAC_TXCLK_DELAY_EN(id)) |	/* values */
    133  1.1      ryo 	    __SHIFTIN(rxen, RK3588_GMAC_RXCLK_DELAY_EN(id)));
    134  1.1      ryo 	syscon_write_4(rk_sc->sc_grf, RK3588_GRF_GMAC_TXRX_DELAY_CFG_REG(id),
    135  1.1      ryo 	    RK3588_GMAC_TXCLK_DELAY_CFG << 16 |			/* masks */
    136  1.1      ryo 	    RK3588_GMAC_RXCLK_DELAY_CFG << 16 |
    137  1.1      ryo 	    __SHIFTIN(tx_delay, RK3588_GMAC_TXCLK_DELAY_CFG) |	/* values */
    138  1.1      ryo 	    __SHIFTIN(rx_delay, RK3588_GMAC_RXCLK_DELAY_CFG));
    139  1.1      ryo 	syscon_unlock(rk_sc->sc_grf);
    140  1.1      ryo 
    141  1.1      ryo 	syscon_lock(rk_sc->sc_php_grf);
    142  1.1      ryo 	syscon_write_4(rk_sc->sc_php_grf, RK3588_GRF_GMAC_PHY_REG,
    143  1.1      ryo 	    RK3588_GMAC_PHY_IFACE_SEL(id) << 16 |		/* mask */
    144  1.1      ryo 	    __SHIFTIN(RK3588_GMAC_PHY_IFACE_SEL_RGMII,		/* value */
    145  1.1      ryo 	    RK3588_GMAC_PHY_IFACE_SEL(id)));
    146  1.1      ryo 	syscon_write_4(rk_sc->sc_php_grf, RK3588_GRF_GMAC_CLK_REG,
    147  1.1      ryo 	    RK3588_GMAC_CLK_MODE(id) << 16 |			/* mask */
    148  1.1      ryo 	    __SHIFTIN(RK3588_GMAC_CLK_MODE_RGMII,		/* value */
    149  1.1      ryo 	    RK3588_GMAC_CLK_MODE(id)));
    150  1.1      ryo 	syscon_unlock(rk_sc->sc_php_grf);
    151  1.1      ryo }
    152  1.1      ryo 
    153  1.1      ryo static void
    154  1.1      ryo rk3588_eqos_set_speed_rgmii(struct rk_eqos_softc *rk_sc, int speed)
    155  1.1      ryo {
    156  1.1      ryo 	const int id = rk_sc->sc_id;
    157  1.1      ryo 	u_int clksel;
    158  1.1      ryo 
    159  1.1      ryo 	switch (speed) {
    160  1.1      ryo 	case IFM_10_T:
    161  1.1      ryo 		clksel = RK3588_GMAC_CLK_RGMII_DIV_DIV50;
    162  1.1      ryo 		break;
    163  1.1      ryo 	case IFM_100_TX:
    164  1.1      ryo 		clksel = RK3588_GMAC_CLK_RGMII_DIV_DIV5;
    165  1.1      ryo 		break;
    166  1.1      ryo 	case IFM_1000_T:
    167  1.1      ryo 	default:
    168  1.1      ryo 		clksel = RK3588_GMAC_CLK_RGMII_DIV_DIV1;
    169  1.1      ryo 		break;
    170  1.1      ryo 	}
    171  1.1      ryo 
    172  1.1      ryo 	syscon_lock(rk_sc->sc_php_grf);
    173  1.1      ryo 	syscon_write_4(rk_sc->sc_php_grf, RK3588_GRF_GMAC_CLK_REG,
    174  1.1      ryo 	    RK3588_GMAC_CLK_RGMII_DIV(id) << 16 |		/* mask */
    175  1.1      ryo 	    __SHIFTIN(clksel, RK3588_GMAC_CLK_RGMII_DIV(id)));	/* value */
    176  1.1      ryo 	syscon_unlock(rk_sc->sc_php_grf);
    177  1.1      ryo }
    178  1.1      ryo 
    179  1.1      ryo static void
    180  1.1      ryo rk3588_eqos_clock_selection(struct rk_eqos_softc *rk_sc, int phandle)
    181  1.1      ryo {
    182  1.1      ryo 	const int id = rk_sc->sc_id;
    183  1.1      ryo 	const char *clock_in_out;
    184  1.1      ryo 
    185  1.1      ryo 	clock_in_out = fdtbus_get_string(phandle, "clock_in_out");
    186  1.1      ryo 	if (clock_in_out != NULL) {
    187  1.1      ryo 		bool input = (strcmp(clock_in_out, "input") == 0) ?
    188  1.1      ryo 		    true : false;
    189  1.1      ryo 		uint32_t clksel, gate;
    190  1.1      ryo 
    191  1.1      ryo 		if (input) {
    192  1.1      ryo 			clksel = RK3588_GMAC_CLK_SELECT_IO;
    193  1.1      ryo 			gate = RK3588_GMAC_CLK_RMII_GATE_DISABLE;
    194  1.1      ryo 		} else {
    195  1.1      ryo 			clksel = RK3588_GMAC_CLK_SELECT_CRU;
    196  1.1      ryo 			gate = RK3588_GMAC_CLK_RMII_GATE_ENABLE;
    197  1.1      ryo 		}
    198  1.1      ryo 
    199  1.1      ryo 		syscon_lock(rk_sc->sc_php_grf);
    200  1.1      ryo 		syscon_write_4(rk_sc->sc_php_grf, RK3588_GRF_GMAC_CLK_REG,
    201  1.1      ryo 		    /* masks */
    202  1.1      ryo 		    RK3588_GMAC_CLK_SELECT(id) << 16 |
    203  1.1      ryo 		    RK3588_GMAC_CLK_RMII_GATE_EN(id) << 16 |
    204  1.1      ryo 		    /* values */
    205  1.1      ryo 		    __SHIFTIN(clksel, RK3588_GMAC_CLK_SELECT(id)) |
    206  1.1      ryo 		    __SHIFTIN(gate, RK3588_GMAC_CLK_RMII_GATE_EN(id)));
    207  1.1      ryo 		syscon_unlock(rk_sc->sc_php_grf);
    208  1.1      ryo 	}
    209  1.1      ryo }
    210  1.1      ryo 
    211  1.1      ryo static int
    212  1.1      ryo rk3588_eqos_get_unit(struct rk_eqos_softc *rk_sc, int phandle)
    213  1.1      ryo {
    214  1.1      ryo 	bus_addr_t addr;
    215  1.1      ryo 	bus_size_t size;
    216  1.1      ryo 
    217  1.1      ryo 	fdtbus_get_reg(phandle, 0, &addr, &size);
    218  1.1      ryo 	if (addr == RK3588_ETHERNET1_ADDR)
    219  1.1      ryo 		return 1;
    220  1.1      ryo 	return 0;
    221  1.1      ryo }
    222  1.1      ryo 
    223  1.1      ryo static const struct rk_eqos_ops rk3588_ops = {
    224  1.1      ryo 	.set_mode_rgmii = rk3588_eqos_set_mode_rgmii,
    225  1.1      ryo 	.set_speed_rgmii = rk3588_eqos_set_speed_rgmii,
    226  1.1      ryo 	.clock_selection = rk3588_eqos_clock_selection,
    227  1.1      ryo 	.get_unit = rk3588_eqos_get_unit
    228  1.1      ryo };
    229  1.1      ryo 
    230  1.1      ryo static const struct device_compatible_entry compat_data[] = {
    231  1.1      ryo 	{ .compat = "rockchip,rk3588-gmac", .value = (uintptr_t)&rk3588_ops },
    232  1.1      ryo 	DEVICE_COMPAT_EOL
    233  1.1      ryo };
    234  1.1      ryo 
    235  1.1      ryo static int
    236  1.1      ryo rk_eqos_reset_gpio(const int phandle)
    237  1.1      ryo {
    238  1.1      ryo 	struct fdtbus_gpio_pin *pin_reset;
    239  1.1      ryo 	const u_int *reset_delay_us;
    240  1.1      ryo 	bool reset_active_low;
    241  1.1      ryo 	int len;
    242  1.1      ryo 
    243  1.1      ryo 	if (!of_hasprop(phandle, "snps,reset-gpio"))
    244  1.1      ryo 		return 0;
    245  1.1      ryo 
    246  1.1      ryo 	pin_reset = fdtbus_gpio_acquire(phandle, "snps,reset-gpio",
    247  1.1      ryo 	    GPIO_PIN_OUTPUT);
    248  1.1      ryo 	if (pin_reset == NULL)
    249  1.1      ryo 		return ENOENT;
    250  1.1      ryo 
    251  1.1      ryo 	reset_delay_us = fdtbus_get_prop(phandle, "snps,reset-delays-us", &len);
    252  1.1      ryo 	if (reset_delay_us == NULL || len != 12)
    253  1.1      ryo 		return ENXIO;
    254  1.1      ryo 
    255  1.1      ryo 	reset_active_low = of_hasprop(phandle, "snps,reset-active-low");
    256  1.1      ryo 
    257  1.1      ryo 	fdtbus_gpio_write_raw(pin_reset, reset_active_low ? 1 : 0);
    258  1.1      ryo 	delay(be32toh(reset_delay_us[0]));
    259  1.1      ryo 	fdtbus_gpio_write_raw(pin_reset, reset_active_low ? 0 : 1);
    260  1.1      ryo 	delay(be32toh(reset_delay_us[1]));
    261  1.1      ryo 	fdtbus_gpio_write_raw(pin_reset, reset_active_low ? 1 : 0);
    262  1.1      ryo 	delay(be32toh(reset_delay_us[2]));
    263  1.1      ryo 
    264  1.1      ryo 	return 0;
    265  1.1      ryo }
    266  1.1      ryo 
    267  1.1      ryo static void
    268  1.1      ryo rk_eqos_init_props(struct eqos_softc *sc, int phandle)
    269  1.1      ryo {
    270  1.1      ryo 	prop_dictionary_t prop = device_properties(sc->sc_dev);
    271  1.1      ryo 
    272  1.1      ryo 	/* Defaults */
    273  1.1      ryo 	prop_dictionary_set_uint(prop, "snps,wr_osr_lmt", 4);
    274  1.1      ryo 	prop_dictionary_set_uint(prop, "snps,rd_osr_lmt", 8);
    275  1.1      ryo 
    276  1.1      ryo 	if (of_hasprop(phandle, "snps,mixed-burst"))
    277  1.1      ryo 		prop_dictionary_set_bool(prop, "snps,mixed-burst", true);
    278  1.1      ryo 	if (of_hasprop(phandle, "snps,tso"))
    279  1.1      ryo 		prop_dictionary_set_bool(prop, "snps,tso", true);
    280  1.1      ryo }
    281  1.1      ryo 
    282  1.1      ryo static int
    283  1.1      ryo rk_eqos_match(device_t parent, cfdata_t cf, void *aux)
    284  1.1      ryo {
    285  1.1      ryo 	struct fdt_attach_args * const faa = aux;
    286  1.1      ryo 
    287  1.1      ryo 	return of_compatible_match(faa->faa_phandle, compat_data);
    288  1.1      ryo }
    289  1.1      ryo 
    290  1.1      ryo static void
    291  1.1      ryo rk_eqos_attach(device_t parent, device_t self, void *aux)
    292  1.1      ryo {
    293  1.1      ryo 	struct rk_eqos_softc * const rk_sc = device_private(self);
    294  1.1      ryo 	struct eqos_softc * const sc = &rk_sc->sc_base;
    295  1.1      ryo 	struct fdt_attach_args * const faa = aux;
    296  1.1      ryo 	const int phandle = faa->faa_phandle;
    297  1.1      ryo 	const char *phy_mode;
    298  1.1      ryo 	char intrstr[128];
    299  1.1      ryo 	bus_addr_t addr;
    300  1.1      ryo 	bus_size_t size;
    301  1.1      ryo 	u_int tx_delay, rx_delay;
    302  1.1      ryo 	int n;
    303  1.1      ryo 
    304  1.1      ryo 	struct rk_eqos_ops *ops = (struct rk_eqos_ops *)
    305  1.1      ryo 	    of_compatible_lookup(phandle, compat_data)->value;
    306  1.1      ryo 
    307  1.1      ryo 	/* multiple ethernet? */
    308  1.1      ryo 	if (ops->get_unit != NULL)
    309  1.1      ryo 		rk_sc->sc_id = ops->get_unit(rk_sc, phandle);
    310  1.1      ryo 
    311  1.1      ryo 	if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
    312  1.1      ryo 		aprint_error(": couldn't get registers\n");
    313  1.1      ryo 		return;
    314  1.1      ryo 	}
    315  1.1      ryo 
    316  1.1      ryo 	rk_sc->sc_grf = fdtbus_syscon_acquire(phandle, "rockchip,grf");
    317  1.1      ryo 	if (rk_sc->sc_grf == NULL) {
    318  1.1      ryo 		aprint_error(": couldn't get grf syscon\n");
    319  1.1      ryo 		return;
    320  1.1      ryo 	}
    321  1.1      ryo 	rk_sc->sc_php_grf = fdtbus_syscon_acquire(phandle, "rockchip,php_grf");
    322  1.1      ryo 	if (rk_sc->sc_php_grf == NULL) {
    323  1.1      ryo 		aprint_error(": couldn't get php_grf syscon\n");
    324  1.1      ryo 		return;
    325  1.1      ryo 	}
    326  1.1      ryo 
    327  1.1      ryo 	sc->sc_dev = self;
    328  1.1      ryo 	sc->sc_bst = faa->faa_bst;
    329  1.1      ryo 	if (bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh) != 0) {
    330  1.1      ryo 		aprint_error(": couldn't map registers\n");
    331  1.1      ryo 		return;
    332  1.1      ryo 	}
    333  1.1      ryo 	sc->sc_dmat = faa->faa_dmat;
    334  1.1      ryo 
    335  1.1      ryo 	if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
    336  1.1      ryo 		aprint_error(": failed to decode interrupt\n");
    337  1.1      ryo 		return;
    338  1.1      ryo 	}
    339  1.1      ryo 
    340  1.1      ryo 	/* enable clocks */
    341  1.1      ryo 	struct clk *clk;
    342  1.1      ryo 	fdtbus_clock_assign(phandle);
    343  1.1      ryo 	for (n = 0; (clk = fdtbus_clock_get_index(phandle, n)) != NULL; n++) {
    344  1.1      ryo 		if (clk_enable(clk) != 0) {
    345  1.1      ryo 			aprint_error(": couldn't enable clock #%d\n", n);
    346  1.1      ryo 			return;
    347  1.1      ryo 		}
    348  1.1      ryo 	}
    349  1.1      ryo 	/* de-assert resets */
    350  1.1      ryo 	struct fdtbus_reset *rst;
    351  1.1      ryo 	for (n = 0; (rst = fdtbus_reset_get_index(phandle, n)) != NULL; n++) {
    352  1.1      ryo 		if (fdtbus_reset_deassert(rst) != 0) {
    353  1.1      ryo 			aprint_error(": couldn't de-assert reset #%d\n", n);
    354  1.1      ryo 			return;
    355  1.1      ryo 		}
    356  1.1      ryo 	}
    357  1.1      ryo 	if (rk_eqos_reset_gpio(phandle) != 0)
    358  1.1      ryo 		aprint_error(": GPIO reset failed\n");	/* ignore */
    359  1.1      ryo 
    360  1.1      ryo 	if (ops->clock_selection != NULL)
    361  1.1      ryo 		ops->clock_selection(rk_sc, phandle);
    362  1.1      ryo 
    363  1.1      ryo 	if (of_getprop_uint32(phandle, "tx_delay", &tx_delay) != 0)
    364  1.1      ryo 		tx_delay = -1;
    365  1.1      ryo 	if (of_getprop_uint32(phandle, "rx_delay", &rx_delay) != 0)
    366  1.1      ryo 		rx_delay = -1;
    367  1.1      ryo 
    368  1.1      ryo 	phy_mode = fdtbus_get_string(phandle, "phy-mode");
    369  1.1      ryo 	if (phy_mode == NULL)
    370  1.1      ryo 		phy_mode = "rgmii";	/* default: RGMII */
    371  1.1      ryo 
    372  1.1      ryo 	if (strncmp(phy_mode, "rgmii", 5) == 0) {
    373  1.1      ryo 		ops->set_mode_rgmii(rk_sc, tx_delay, rx_delay);
    374  1.1      ryo 		if (ops->set_speed_rgmii != NULL) {
    375  1.1      ryo 			/*
    376  1.1      ryo 			 * XXX: should be called back from
    377  1.1      ryo 			 *  sys/dev/ic/dwc_eqos.c:eqos_update_link() ?
    378  1.1      ryo 			 */
    379  1.1      ryo 			ops->set_speed_rgmii(rk_sc, IFM_1000_T);
    380  1.1      ryo 		}
    381  1.1      ryo 	} else {
    382  1.1      ryo 		aprint_error(": unsupported phy-mode '%s'\n", phy_mode);
    383  1.1      ryo 		return;
    384  1.1      ryo 	}
    385  1.1      ryo 
    386  1.1      ryo 	rk_eqos_init_props(sc, phandle);
    387  1.1      ryo 	sc->sc_phy_id = MII_PHY_ANY;
    388  1.1      ryo #define CSR_RATE_RGMII	125000000	/* default */
    389  1.1      ryo 	sc->sc_csr_clock = CSR_RATE_RGMII;
    390  1.1      ryo 
    391  1.1      ryo 	if (eqos_attach(sc) != 0)
    392  1.1      ryo 		return;
    393  1.1      ryo 
    394  1.2    skrll 	if (fdtbus_intr_establish_xname(phandle, 0, IPL_NET, FDT_INTR_MPSAFE,
    395  1.1      ryo 	    eqos_intr, sc, device_xname(self)) == NULL) {
    396  1.1      ryo 		aprint_error_dev(self, "failed to establish interrupt on %s\n",
    397  1.1      ryo 		    intrstr);
    398  1.1      ryo 		return;
    399  1.1      ryo 	}
    400  1.1      ryo 	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
    401  1.1      ryo }
    402