Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * tsi108/109 device setup code
0004  *
0005  * Maintained by Roy Zang < tie-fei.zang@freescale.com >
0006  */
0007 
0008 #include <linux/stddef.h>
0009 #include <linux/kernel.h>
0010 #include <linux/init.h>
0011 #include <linux/errno.h>
0012 #include <linux/major.h>
0013 #include <linux/delay.h>
0014 #include <linux/irq.h>
0015 #include <linux/export.h>
0016 #include <linux/device.h>
0017 #include <linux/etherdevice.h>
0018 #include <linux/platform_device.h>
0019 #include <linux/of_address.h>
0020 #include <linux/of_irq.h>
0021 #include <linux/of_net.h>
0022 #include <asm/tsi108.h>
0023 
0024 #include <linux/atomic.h>
0025 #include <asm/io.h>
0026 #include <asm/irq.h>
0027 #include <mm/mmu_decl.h>
0028 
0029 #undef DEBUG
0030 
0031 #ifdef DEBUG
0032 #define DBG(fmt...) do { printk(fmt); } while(0)
0033 #else
0034 #define DBG(fmt...) do { } while(0)
0035 #endif
0036 
0037 static phys_addr_t tsi108_csr_base = -1;
0038 
0039 phys_addr_t get_csrbase(void)
0040 {
0041     struct device_node *tsi;
0042 
0043     if (tsi108_csr_base != -1)
0044         return tsi108_csr_base;
0045 
0046     tsi = of_find_node_by_type(NULL, "tsi-bridge");
0047     if (tsi) {
0048         unsigned int size;
0049         const void *prop = of_get_property(tsi, "reg", &size);
0050         tsi108_csr_base = of_translate_address(tsi, prop);
0051         of_node_put(tsi);
0052     }
0053     return tsi108_csr_base;
0054 }
0055 EXPORT_SYMBOL(get_csrbase);
0056 
0057 u32 get_vir_csrbase(void)
0058 {
0059     return (u32) (ioremap(get_csrbase(), 0x10000));
0060 }
0061 EXPORT_SYMBOL(get_vir_csrbase);
0062 
0063 static int __init tsi108_eth_of_init(void)
0064 {
0065     struct device_node *np;
0066     unsigned int i = 0;
0067     struct platform_device *tsi_eth_dev;
0068     struct resource res;
0069     int ret;
0070 
0071     for_each_compatible_node(np, "network", "tsi108-ethernet") {
0072         struct resource r[2];
0073         struct device_node *phy, *mdio;
0074         hw_info tsi_eth_data;
0075         const unsigned int *phy_id;
0076         const phandle *ph;
0077 
0078         memset(r, 0, sizeof(r));
0079         memset(&tsi_eth_data, 0, sizeof(tsi_eth_data));
0080 
0081         ret = of_address_to_resource(np, 0, &r[0]);
0082         DBG("%s: name:start->end = %s:%pR\n",
0083             __func__, r[0].name, &r[0]);
0084         if (ret)
0085             goto err;
0086 
0087         r[1].name = "tx";
0088         r[1].start = irq_of_parse_and_map(np, 0);
0089         r[1].end = irq_of_parse_and_map(np, 0);
0090         r[1].flags = IORESOURCE_IRQ;
0091         DBG("%s: name:start->end = %s:%pR\n",
0092             __func__, r[1].name, &r[1]);
0093 
0094         tsi_eth_dev =
0095             platform_device_register_simple("tsi-ethernet", i++, &r[0],
0096                             1);
0097 
0098         if (IS_ERR(tsi_eth_dev)) {
0099             ret = PTR_ERR(tsi_eth_dev);
0100             goto err;
0101         }
0102 
0103         of_get_mac_address(np, tsi_eth_data.mac_addr);
0104 
0105         ph = of_get_property(np, "mdio-handle", NULL);
0106         mdio = of_find_node_by_phandle(*ph);
0107         ret = of_address_to_resource(mdio, 0, &res);
0108         of_node_put(mdio);
0109         if (ret)
0110             goto unreg;
0111 
0112         ph = of_get_property(np, "phy-handle", NULL);
0113         phy = of_find_node_by_phandle(*ph);
0114 
0115         if (phy == NULL) {
0116             ret = -ENODEV;
0117             goto unreg;
0118         }
0119 
0120         phy_id = of_get_property(phy, "reg", NULL);
0121 
0122         tsi_eth_data.regs = r[0].start;
0123         tsi_eth_data.phyregs = res.start;
0124         tsi_eth_data.phy = *phy_id;
0125         tsi_eth_data.irq_num = irq_of_parse_and_map(np, 0);
0126 
0127         /* Some boards with the TSI108 bridge (e.g. Holly)
0128          * have a miswiring of the ethernet PHYs which
0129          * requires a workaround.  The special
0130          * "txc-rxc-delay-disable" property enables this
0131          * workaround.  FIXME: Need to port the tsi108_eth
0132          * driver itself to phylib and use a non-misleading
0133          * name for the workaround flag - it's not actually to
0134          * do with the model of PHY in use */
0135         if (of_get_property(phy, "txc-rxc-delay-disable", NULL))
0136             tsi_eth_data.phy_type = TSI108_PHY_BCM54XX;
0137         of_node_put(phy);
0138 
0139         ret =
0140             platform_device_add_data(tsi_eth_dev, &tsi_eth_data,
0141                          sizeof(hw_info));
0142         if (ret)
0143             goto unreg;
0144     }
0145     return 0;
0146 unreg:
0147     platform_device_unregister(tsi_eth_dev);
0148 err:
0149     of_node_put(np);
0150     return ret;
0151 }
0152 
0153 arch_initcall(tsi108_eth_of_init);