Lines Matching +full:init +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2015 - 2023 Beijing WangXun Technology Co., Ltd. */
7 #include <linux/clk-provider.h>
13 #include <linux/pcs/pcs-xpcs.h>
25 struct txgbe_nodes *nodes = &txgbe->nodes; in txgbe_swnodes_register()
26 struct pci_dev *pdev = txgbe->wx->pdev; in txgbe_swnodes_register()
32 snprintf(nodes->gpio_name, sizeof(nodes->gpio_name), "txgbe_gpio-%x", id); in txgbe_swnodes_register()
33 snprintf(nodes->i2c_name, sizeof(nodes->i2c_name), "txgbe_i2c-%x", id); in txgbe_swnodes_register()
34 snprintf(nodes->sfp_name, sizeof(nodes->sfp_name), "txgbe_sfp-%x", id); in txgbe_swnodes_register()
35 snprintf(nodes->phylink_name, sizeof(nodes->phylink_name), "txgbe_phylink-%x", id); in txgbe_swnodes_register()
37 swnodes = nodes->swnodes; in txgbe_swnodes_register()
46 nodes->gpio_props[0] = PROPERTY_ENTRY_STRING("pinctrl-names", "default"); in txgbe_swnodes_register()
47 swnodes[SWNODE_GPIO] = NODE_PROP(nodes->gpio_name, nodes->gpio_props); in txgbe_swnodes_register()
48 nodes->gpio0_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], 0, GPIO_ACTIVE_HIGH); in txgbe_swnodes_register()
49 nodes->gpio1_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], 1, GPIO_ACTIVE_HIGH); in txgbe_swnodes_register()
50 nodes->gpio2_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], 2, GPIO_ACTIVE_LOW); in txgbe_swnodes_register()
51 nodes->gpio3_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], 3, GPIO_ACTIVE_HIGH); in txgbe_swnodes_register()
52 nodes->gpio4_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], 4, GPIO_ACTIVE_HIGH); in txgbe_swnodes_register()
53 nodes->gpio5_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], 5, GPIO_ACTIVE_HIGH); in txgbe_swnodes_register()
55 nodes->i2c_props[0] = PROPERTY_ENTRY_STRING("compatible", "snps,designware-i2c"); in txgbe_swnodes_register()
56 nodes->i2c_props[1] = PROPERTY_ENTRY_BOOL("wx,i2c-snps-model"); in txgbe_swnodes_register()
57 nodes->i2c_props[2] = PROPERTY_ENTRY_U32("clock-frequency", I2C_MAX_STANDARD_MODE_FREQ); in txgbe_swnodes_register()
58 swnodes[SWNODE_I2C] = NODE_PROP(nodes->i2c_name, nodes->i2c_props); in txgbe_swnodes_register()
59 nodes->i2c_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_I2C]); in txgbe_swnodes_register()
61 nodes->sfp_props[0] = PROPERTY_ENTRY_STRING("compatible", "sff,sfp"); in txgbe_swnodes_register()
62 nodes->sfp_props[1] = PROPERTY_ENTRY_REF_ARRAY("i2c-bus", nodes->i2c_ref); in txgbe_swnodes_register()
63 nodes->sfp_props[2] = PROPERTY_ENTRY_REF_ARRAY("tx-fault-gpios", nodes->gpio0_ref); in txgbe_swnodes_register()
64 nodes->sfp_props[3] = PROPERTY_ENTRY_REF_ARRAY("tx-disable-gpios", nodes->gpio1_ref); in txgbe_swnodes_register()
65 nodes->sfp_props[4] = PROPERTY_ENTRY_REF_ARRAY("mod-def0-gpios", nodes->gpio2_ref); in txgbe_swnodes_register()
66 nodes->sfp_props[5] = PROPERTY_ENTRY_REF_ARRAY("los-gpios", nodes->gpio3_ref); in txgbe_swnodes_register()
67 nodes->sfp_props[6] = PROPERTY_ENTRY_REF_ARRAY("rate-select1-gpios", nodes->gpio4_ref); in txgbe_swnodes_register()
68 nodes->sfp_props[7] = PROPERTY_ENTRY_REF_ARRAY("rate-select0-gpios", nodes->gpio5_ref); in txgbe_swnodes_register()
69 swnodes[SWNODE_SFP] = NODE_PROP(nodes->sfp_name, nodes->sfp_props); in txgbe_swnodes_register()
70 nodes->sfp_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_SFP]); in txgbe_swnodes_register()
72 nodes->phylink_props[0] = PROPERTY_ENTRY_STRING("managed", "in-band-status"); in txgbe_swnodes_register()
73 nodes->phylink_props[1] = PROPERTY_ENTRY_REF_ARRAY("sfp", nodes->sfp_ref); in txgbe_swnodes_register()
74 swnodes[SWNODE_PHYLINK] = NODE_PROP(nodes->phylink_name, nodes->phylink_props); in txgbe_swnodes_register()
76 nodes->group[SWNODE_GPIO] = &swnodes[SWNODE_GPIO]; in txgbe_swnodes_register()
77 nodes->group[SWNODE_I2C] = &swnodes[SWNODE_I2C]; in txgbe_swnodes_register()
78 nodes->group[SWNODE_SFP] = &swnodes[SWNODE_SFP]; in txgbe_swnodes_register()
79 nodes->group[SWNODE_PHYLINK] = &swnodes[SWNODE_PHYLINK]; in txgbe_swnodes_register()
81 return software_node_register_node_group(nodes->group); in txgbe_swnodes_register()
86 struct wx *wx = bus->priv; in txgbe_pcs_read()
90 return -EOPNOTSUPP; in txgbe_pcs_read()
105 struct wx *wx = bus->priv; in txgbe_pcs_write()
109 return -EOPNOTSUPP; in txgbe_pcs_write()
130 wx = txgbe->wx; in txgbe_mdio_pcs_init()
131 pdev = wx->pdev; in txgbe_mdio_pcs_init()
133 mii_bus = devm_mdiobus_alloc(&pdev->dev); in txgbe_mdio_pcs_init()
135 return -ENOMEM; in txgbe_mdio_pcs_init()
137 mii_bus->name = "txgbe_pcs_mdio_bus"; in txgbe_mdio_pcs_init()
138 mii_bus->read_c45 = &txgbe_pcs_read; in txgbe_mdio_pcs_init()
139 mii_bus->write_c45 = &txgbe_pcs_write; in txgbe_mdio_pcs_init()
140 mii_bus->parent = &pdev->dev; in txgbe_mdio_pcs_init()
141 mii_bus->phy_mask = ~0; in txgbe_mdio_pcs_init()
142 mii_bus->priv = wx; in txgbe_mdio_pcs_init()
143 snprintf(mii_bus->id, MII_BUS_ID_SIZE, "txgbe_pcs-%x", in txgbe_mdio_pcs_init()
146 ret = devm_mdiobus_register(&pdev->dev, mii_bus); in txgbe_mdio_pcs_init()
154 txgbe->pcs = pcs; in txgbe_mdio_pcs_init()
163 struct txgbe *txgbe = wx->priv; in txgbe_phylink_mac_select()
165 if (wx->media_type != sp_media_copper) in txgbe_phylink_mac_select()
166 return txgbe->pcs; in txgbe_phylink_mac_select()
255 struct wx *wx = txgbe->wx; in txgbe_phylink_init()
259 config = &wx->phylink_config; in txgbe_phylink_init()
260 config->dev = &wx->netdev->dev; in txgbe_phylink_init()
261 config->type = PHYLINK_NETDEV; in txgbe_phylink_init()
262 config->mac_capabilities = MAC_10000FD | MAC_1000FD | MAC_100FD | in txgbe_phylink_init()
265 if (wx->media_type == sp_media_copper) { in txgbe_phylink_init()
267 __set_bit(PHY_INTERFACE_MODE_XAUI, config->supported_interfaces); in txgbe_phylink_init()
270 fwnode = software_node_fwnode(txgbe->nodes.group[SWNODE_PHYLINK]); in txgbe_phylink_init()
271 __set_bit(PHY_INTERFACE_MODE_10GBASER, config->supported_interfaces); in txgbe_phylink_init()
272 __set_bit(PHY_INTERFACE_MODE_1000BASEX, config->supported_interfaces); in txgbe_phylink_init()
273 __set_bit(PHY_INTERFACE_MODE_SGMII, config->supported_interfaces); in txgbe_phylink_init()
280 if (wx->phydev) { in txgbe_phylink_init()
283 ret = phylink_connect_phy(phylink, wx->phydev); in txgbe_phylink_init()
290 wx->phylink = phylink; in txgbe_phylink_init()
298 struct wx *wx = txgbe->wx; in txgbe_link_irq_handler()
305 phylink_pcs_change(txgbe->pcs, up); in txgbe_link_irq_handler()
337 raw_spin_lock_irqsave(&wx->gpio_lock, flags); in txgbe_gpio_direction_in()
339 raw_spin_unlock_irqrestore(&wx->gpio_lock, flags); in txgbe_gpio_direction_in()
353 raw_spin_lock_irqsave(&wx->gpio_lock, flags); in txgbe_gpio_direction_out()
356 raw_spin_unlock_irqrestore(&wx->gpio_lock, flags); in txgbe_gpio_direction_out()
368 wx = txgbe->wx; in txgbe_gpio_init()
369 dev = &wx->pdev->dev; in txgbe_gpio_init()
371 raw_spin_lock_init(&wx->gpio_lock); in txgbe_gpio_init()
375 return -ENOMEM; in txgbe_gpio_init()
377 gc->label = devm_kasprintf(dev, GFP_KERNEL, "txgbe_gpio-%x", in txgbe_gpio_init()
378 pci_dev_id(wx->pdev)); in txgbe_gpio_init()
379 if (!gc->label) in txgbe_gpio_init()
380 return -ENOMEM; in txgbe_gpio_init()
382 gc->base = -1; in txgbe_gpio_init()
383 gc->ngpio = 6; in txgbe_gpio_init()
384 gc->owner = THIS_MODULE; in txgbe_gpio_init()
385 gc->parent = dev; in txgbe_gpio_init()
386 gc->fwnode = software_node_fwnode(txgbe->nodes.group[SWNODE_GPIO]); in txgbe_gpio_init()
387 gc->get = txgbe_gpio_get; in txgbe_gpio_init()
388 gc->get_direction = txgbe_gpio_get_direction; in txgbe_gpio_init()
389 gc->direction_input = txgbe_gpio_direction_in; in txgbe_gpio_init()
390 gc->direction_output = txgbe_gpio_direction_out; in txgbe_gpio_init()
396 txgbe->gpio = gc; in txgbe_gpio_init()
403 struct pci_dev *pdev = txgbe->wx->pdev; in txgbe_clock_register()
418 return -ENOMEM; in txgbe_clock_register()
421 txgbe->clk = clk; in txgbe_clock_register()
422 txgbe->clock = clock; in txgbe_clock_register()
461 wx = txgbe->wx; in txgbe_i2c_register()
462 pdev = wx->pdev; in txgbe_i2c_register()
463 i2c_regmap = devm_regmap_init(&pdev->dev, NULL, wx, &i2c_regmap_config); in txgbe_i2c_register()
465 wx_err(wx, "failed to init I2C regmap\n"); in txgbe_i2c_register()
469 info.parent = &pdev->dev; in txgbe_i2c_register()
470 info.fwnode = software_node_fwnode(txgbe->nodes.group[SWNODE_I2C]); in txgbe_i2c_register()
474 info.res = &DEFINE_RES_IRQ(pdev->irq); in txgbe_i2c_register()
480 txgbe->i2c_dev = i2c_dev; in txgbe_i2c_register()
487 struct pci_dev *pdev = txgbe->wx->pdev; in txgbe_sfp_register()
491 info.parent = &pdev->dev; in txgbe_sfp_register()
492 info.fwnode = software_node_fwnode(txgbe->nodes.group[SWNODE_SFP]); in txgbe_sfp_register()
499 txgbe->sfp_dev = sfp_dev; in txgbe_sfp_register()
512 wx = txgbe->wx; in txgbe_ext_phy_init()
513 pdev = wx->pdev; in txgbe_ext_phy_init()
515 mii_bus = devm_mdiobus_alloc(&pdev->dev); in txgbe_ext_phy_init()
517 return -ENOMEM; in txgbe_ext_phy_init()
519 mii_bus->name = "txgbe_mii_bus"; in txgbe_ext_phy_init()
520 mii_bus->read_c45 = &wx_phy_read_reg_mdi_c45; in txgbe_ext_phy_init()
521 mii_bus->write_c45 = &wx_phy_write_reg_mdi_c45; in txgbe_ext_phy_init()
522 mii_bus->parent = &pdev->dev; in txgbe_ext_phy_init()
523 mii_bus->phy_mask = GENMASK(31, 1); in txgbe_ext_phy_init()
524 mii_bus->priv = wx; in txgbe_ext_phy_init()
525 snprintf(mii_bus->id, MII_BUS_ID_SIZE, "txgbe-%x", pci_dev_id(pdev)); in txgbe_ext_phy_init()
527 ret = devm_mdiobus_register(&pdev->dev, mii_bus); in txgbe_ext_phy_init()
536 return -ENODEV; in txgbe_ext_phy_init()
541 wx->link = 0; in txgbe_ext_phy_init()
542 wx->speed = 0; in txgbe_ext_phy_init()
543 wx->duplex = 0; in txgbe_ext_phy_init()
544 wx->phydev = phydev; in txgbe_ext_phy_init()
548 wx_err(wx, "failed to init phylink: %d\n", ret); in txgbe_ext_phy_init()
557 struct wx *wx = txgbe->wx; in txgbe_init_phy()
560 if (txgbe->wx->media_type == sp_media_copper) in txgbe_init_phy()
571 wx_err(wx, "failed to init mdio pcs: %d\n", ret); in txgbe_init_phy()
577 wx_err(wx, "failed to init phylink\n"); in txgbe_init_phy()
583 wx_err(wx, "failed to init gpio\n"); in txgbe_init_phy()
595 wx_err(wx, "failed to init i2c interface: %d\n", ret); in txgbe_init_phy()
608 platform_device_unregister(txgbe->i2c_dev); in txgbe_init_phy()
610 clkdev_drop(txgbe->clock); in txgbe_init_phy()
611 clk_unregister(txgbe->clk); in txgbe_init_phy()
613 phylink_destroy(wx->phylink); in txgbe_init_phy()
615 xpcs_destroy_pcs(txgbe->pcs); in txgbe_init_phy()
617 software_node_unregister_node_group(txgbe->nodes.group); in txgbe_init_phy()
624 if (txgbe->wx->media_type == sp_media_copper) { in txgbe_remove_phy()
625 phylink_disconnect_phy(txgbe->wx->phylink); in txgbe_remove_phy()
626 phylink_destroy(txgbe->wx->phylink); in txgbe_remove_phy()
630 platform_device_unregister(txgbe->sfp_dev); in txgbe_remove_phy()
631 platform_device_unregister(txgbe->i2c_dev); in txgbe_remove_phy()
632 clkdev_drop(txgbe->clock); in txgbe_remove_phy()
633 clk_unregister(txgbe->clk); in txgbe_remove_phy()
634 phylink_destroy(txgbe->wx->phylink); in txgbe_remove_phy()
635 xpcs_destroy_pcs(txgbe->pcs); in txgbe_remove_phy()
636 software_node_unregister_node_group(txgbe->nodes.group); in txgbe_remove_phy()