^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * tsi108/109 device setup code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Maintained by Roy Zang < tie-fei.zang@freescale.com >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/of_net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/tsi108.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <mm/mmu_decl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #undef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define DBG(fmt...) do { printk(fmt); } while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define DBG(fmt...) do { } while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static phys_addr_t tsi108_csr_base = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) phys_addr_t get_csrbase(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct device_node *tsi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) if (tsi108_csr_base != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return tsi108_csr_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) tsi = of_find_node_by_type(NULL, "tsi-bridge");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (tsi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) unsigned int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) const void *prop = of_get_property(tsi, "reg", &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) tsi108_csr_base = of_translate_address(tsi, prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) of_node_put(tsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return tsi108_csr_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u32 get_vir_csrbase(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return (u32) (ioremap(get_csrbase(), 0x10000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) EXPORT_SYMBOL(get_csrbase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) EXPORT_SYMBOL(get_vir_csrbase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static int __init tsi108_eth_of_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) unsigned int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct platform_device *tsi_eth_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct resource res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) for_each_compatible_node(np, "network", "tsi108-ethernet") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct resource r[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct device_node *phy, *mdio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) hw_info tsi_eth_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) const unsigned int *phy_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) const void *mac_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) const phandle *ph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) memset(r, 0, sizeof(r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) memset(&tsi_eth_data, 0, sizeof(tsi_eth_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) ret = of_address_to_resource(np, 0, &r[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) DBG("%s: name:start->end = %s:%pR\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) __func__, r[0].name, &r[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) r[1].name = "tx";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) r[1].start = irq_of_parse_and_map(np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) r[1].end = irq_of_parse_and_map(np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) r[1].flags = IORESOURCE_IRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) DBG("%s: name:start->end = %s:%pR\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) __func__, r[1].name, &r[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) tsi_eth_dev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) platform_device_register_simple("tsi-ethernet", i++, &r[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (IS_ERR(tsi_eth_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) ret = PTR_ERR(tsi_eth_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) mac_addr = of_get_mac_address(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (!IS_ERR(mac_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ether_addr_copy(tsi_eth_data.mac_addr, mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ph = of_get_property(np, "mdio-handle", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) mdio = of_find_node_by_phandle(*ph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ret = of_address_to_resource(mdio, 0, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) of_node_put(mdio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) goto unreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) ph = of_get_property(np, "phy-handle", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) phy = of_find_node_by_phandle(*ph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (phy == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) goto unreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) phy_id = of_get_property(phy, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) tsi_eth_data.regs = r[0].start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) tsi_eth_data.phyregs = res.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) tsi_eth_data.phy = *phy_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) tsi_eth_data.irq_num = irq_of_parse_and_map(np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* Some boards with the TSI108 bridge (e.g. Holly)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * have a miswiring of the ethernet PHYs which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * requires a workaround. The special
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * "txc-rxc-delay-disable" property enables this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * workaround. FIXME: Need to port the tsi108_eth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * driver itself to phylib and use a non-misleading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * name for the workaround flag - it's not actually to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * do with the model of PHY in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (of_get_property(phy, "txc-rxc-delay-disable", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) tsi_eth_data.phy_type = TSI108_PHY_BCM54XX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) of_node_put(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ret =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) platform_device_add_data(tsi_eth_dev, &tsi_eth_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) sizeof(hw_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) goto unreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) unreg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) platform_device_unregister(tsi_eth_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) arch_initcall(tsi108_eth_of_init);