Lines Matching +full:gpio +full:- +full:pol

1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2015 - 2023 Beijing WangXun Technology Co., Ltd. */
4 #include <linux/gpio/machine.h>
5 #include <linux/gpio/driver.h>
6 #include <linux/gpio/property.h>
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()
39 /* GPIO 0: tx fault in txgbe_swnodes_register()
40 * GPIO 1: tx disable in txgbe_swnodes_register()
41 * GPIO 2: sfp module absent in txgbe_swnodes_register()
42 * GPIO 3: rx signal lost in txgbe_swnodes_register()
43 * GPIO 4: rate select, 1G(0) 10G(1) in txgbe_swnodes_register()
44 * GPIO 5: rate select, 1G(0) 10G(1) 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->xpcs = xpcs; in txgbe_mdio_pcs_init()
163 struct txgbe *txgbe = wx->priv; in txgbe_phylink_mac_select()
166 return &txgbe->xpcs->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->xpcs->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 raw_spin_lock_irqsave(&wx->gpio_lock, flags); in txgbe_gpio_irq_ack()
370 raw_spin_unlock_irqrestore(&wx->gpio_lock, flags); in txgbe_gpio_irq_ack()
382 raw_spin_lock_irqsave(&wx->gpio_lock, flags); in txgbe_gpio_irq_mask()
384 raw_spin_unlock_irqrestore(&wx->gpio_lock, flags); in txgbe_gpio_irq_mask()
396 raw_spin_lock_irqsave(&wx->gpio_lock, flags); in txgbe_gpio_irq_unmask()
398 raw_spin_unlock_irqrestore(&wx->gpio_lock, flags); in txgbe_gpio_irq_unmask()
404 u32 pol, val; in txgbe_toggle_trigger() local
406 pol = rd32(wx, WX_GPIO_POLARITY); in txgbe_toggle_trigger()
410 pol &= ~BIT(offset); in txgbe_toggle_trigger()
412 pol |= BIT(offset); in txgbe_toggle_trigger()
414 wr32(wx, WX_GPIO_POLARITY, pol); in txgbe_toggle_trigger()
440 raw_spin_lock_irqsave(&wx->gpio_lock, flags); in txgbe_gpio_set_type()
449 raw_spin_unlock_irqrestore(&wx->gpio_lock, flags); in txgbe_gpio_set_type()
455 .name = "txgbe-gpio-irq",
467 struct wx *wx = txgbe->wx; in txgbe_gpio_irq_handler()
475 gc = txgbe->gpio; in txgbe_gpio_irq_handler()
476 for_each_set_bit(hwirq, &gpioirq, gc->ngpio) { in txgbe_gpio_irq_handler()
477 int gpio = irq_find_mapping(gc->irq.domain, hwirq); in txgbe_gpio_irq_handler() local
478 struct irq_data *d = irq_get_irq_data(gpio); in txgbe_gpio_irq_handler()
479 u32 irq_type = irq_get_trigger_type(gpio); in txgbe_gpio_irq_handler()
482 handle_nested_irq(gpio); in txgbe_gpio_irq_handler()
485 raw_spin_lock_irqsave(&wx->gpio_lock, flags); in txgbe_gpio_irq_handler()
487 raw_spin_unlock_irqrestore(&wx->gpio_lock, flags); in txgbe_gpio_irq_handler()
496 struct txgbe *txgbe = wx->priv; in txgbe_reinit_gpio_intr()
502 /* for gpio interrupt pending before irq enable */ in txgbe_reinit_gpio_intr()
505 gc = txgbe->gpio; in txgbe_reinit_gpio_intr()
506 for_each_set_bit(hwirq, &gpioirq, gc->ngpio) { in txgbe_reinit_gpio_intr()
507 int gpio = irq_find_mapping(gc->irq.domain, hwirq); in txgbe_reinit_gpio_intr() local
508 struct irq_data *d = irq_get_irq_data(gpio); in txgbe_reinit_gpio_intr()
509 u32 irq_type = irq_get_trigger_type(gpio); in txgbe_reinit_gpio_intr()
514 raw_spin_lock_irqsave(&wx->gpio_lock, flags); in txgbe_reinit_gpio_intr()
516 raw_spin_unlock_irqrestore(&wx->gpio_lock, flags); in txgbe_reinit_gpio_intr()
529 wx = txgbe->wx; in txgbe_gpio_init()
530 dev = &wx->pdev->dev; in txgbe_gpio_init()
532 raw_spin_lock_init(&wx->gpio_lock); in txgbe_gpio_init()
536 return -ENOMEM; in txgbe_gpio_init()
538 gc->label = devm_kasprintf(dev, GFP_KERNEL, "txgbe_gpio-%x", in txgbe_gpio_init()
539 pci_dev_id(wx->pdev)); in txgbe_gpio_init()
540 if (!gc->label) in txgbe_gpio_init()
541 return -ENOMEM; in txgbe_gpio_init()
543 gc->base = -1; in txgbe_gpio_init()
544 gc->ngpio = 6; in txgbe_gpio_init()
545 gc->owner = THIS_MODULE; in txgbe_gpio_init()
546 gc->parent = dev; in txgbe_gpio_init()
547 gc->fwnode = software_node_fwnode(txgbe->nodes.group[SWNODE_GPIO]); in txgbe_gpio_init()
548 gc->get = txgbe_gpio_get; in txgbe_gpio_init()
549 gc->get_direction = txgbe_gpio_get_direction; in txgbe_gpio_init()
550 gc->direction_input = txgbe_gpio_direction_in; in txgbe_gpio_init()
551 gc->direction_output = txgbe_gpio_direction_out; in txgbe_gpio_init()
553 girq = &gc->irq; in txgbe_gpio_init()
555 girq->default_type = IRQ_TYPE_NONE; in txgbe_gpio_init()
556 girq->handler = handle_bad_irq; in txgbe_gpio_init()
562 txgbe->gpio = gc; in txgbe_gpio_init()
569 struct pci_dev *pdev = txgbe->wx->pdev; in txgbe_clock_register()
584 return -ENOMEM; in txgbe_clock_register()
587 txgbe->clk = clk; in txgbe_clock_register()
588 txgbe->clock = clock; in txgbe_clock_register()
627 wx = txgbe->wx; in txgbe_i2c_register()
628 pdev = wx->pdev; in txgbe_i2c_register()
629 i2c_regmap = devm_regmap_init(&pdev->dev, NULL, wx, &i2c_regmap_config); in txgbe_i2c_register()
635 info.parent = &pdev->dev; in txgbe_i2c_register()
636 info.fwnode = software_node_fwnode(txgbe->nodes.group[SWNODE_I2C]); in txgbe_i2c_register()
640 info.res = &DEFINE_RES_IRQ(pdev->irq); in txgbe_i2c_register()
646 txgbe->i2c_dev = i2c_dev; in txgbe_i2c_register()
653 struct pci_dev *pdev = txgbe->wx->pdev; in txgbe_sfp_register()
657 info.parent = &pdev->dev; in txgbe_sfp_register()
658 info.fwnode = software_node_fwnode(txgbe->nodes.group[SWNODE_SFP]); in txgbe_sfp_register()
665 txgbe->sfp_dev = sfp_dev; in txgbe_sfp_register()
678 wx = txgbe->wx; in txgbe_ext_phy_init()
679 pdev = wx->pdev; in txgbe_ext_phy_init()
681 mii_bus = devm_mdiobus_alloc(&pdev->dev); in txgbe_ext_phy_init()
683 return -ENOMEM; in txgbe_ext_phy_init()
685 mii_bus->name = "txgbe_mii_bus"; in txgbe_ext_phy_init()
686 mii_bus->read_c45 = &wx_phy_read_reg_mdi_c45; in txgbe_ext_phy_init()
687 mii_bus->write_c45 = &wx_phy_write_reg_mdi_c45; in txgbe_ext_phy_init()
688 mii_bus->parent = &pdev->dev; in txgbe_ext_phy_init()
689 mii_bus->phy_mask = GENMASK(31, 1); in txgbe_ext_phy_init()
690 mii_bus->priv = wx; in txgbe_ext_phy_init()
691 snprintf(mii_bus->id, MII_BUS_ID_SIZE, "txgbe-%x", pci_dev_id(pdev)); in txgbe_ext_phy_init()
693 ret = devm_mdiobus_register(&pdev->dev, mii_bus); in txgbe_ext_phy_init()
702 return -ENODEV; in txgbe_ext_phy_init()
707 wx->link = 0; in txgbe_ext_phy_init()
708 wx->speed = 0; in txgbe_ext_phy_init()
709 wx->duplex = 0; in txgbe_ext_phy_init()
710 wx->phydev = phydev; in txgbe_ext_phy_init()
723 struct wx *wx = txgbe->wx; in txgbe_init_phy()
726 if (txgbe->wx->media_type == sp_media_copper) in txgbe_init_phy()
749 wx_err(wx, "failed to init gpio\n"); in txgbe_init_phy()
774 platform_device_unregister(txgbe->i2c_dev); in txgbe_init_phy()
776 clkdev_drop(txgbe->clock); in txgbe_init_phy()
777 clk_unregister(txgbe->clk); in txgbe_init_phy()
779 phylink_destroy(wx->phylink); in txgbe_init_phy()
781 xpcs_destroy(txgbe->xpcs); in txgbe_init_phy()
783 software_node_unregister_node_group(txgbe->nodes.group); in txgbe_init_phy()
790 if (txgbe->wx->media_type == sp_media_copper) { in txgbe_remove_phy()
791 phylink_disconnect_phy(txgbe->wx->phylink); in txgbe_remove_phy()
792 phylink_destroy(txgbe->wx->phylink); in txgbe_remove_phy()
796 platform_device_unregister(txgbe->sfp_dev); in txgbe_remove_phy()
797 platform_device_unregister(txgbe->i2c_dev); in txgbe_remove_phy()
798 clkdev_drop(txgbe->clock); in txgbe_remove_phy()
799 clk_unregister(txgbe->clk); in txgbe_remove_phy()
800 phylink_destroy(txgbe->wx->phylink); in txgbe_remove_phy()
801 xpcs_destroy(txgbe->xpcs); in txgbe_remove_phy()
802 software_node_unregister_node_group(txgbe->nodes.group); in txgbe_remove_phy()