Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: phy-can-transceiver: Add support for setting mux

On some boards, for routing CAN signals from controller to transceiver,
muxes might need to be set. Therefore, add support for setting the mux by
reading the mux-states property from the device tree node.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Link: https://lore.kernel.org/r/20220408111316.21189-1-a-govindraju@ti.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Aswath Govindraju and committed by
Vinod Koul
e4d43712 31231092

+23
+1
drivers/phy/Kconfig
··· 64 64 config PHY_CAN_TRANSCEIVER 65 65 tristate "CAN transceiver PHY" 66 66 select GENERIC_PHY 67 + select MULTIPLEXER 67 68 help 68 69 This option enables support for CAN transceivers as a PHY. This 69 70 driver provides function for putting the transceivers in various
+22
drivers/phy/phy-can-transceiver.c
··· 10 10 #include<linux/module.h> 11 11 #include<linux/gpio.h> 12 12 #include<linux/gpio/consumer.h> 13 + #include <linux/mux/consumer.h> 13 14 14 15 struct can_transceiver_data { 15 16 u32 flags; ··· 22 21 struct phy *generic_phy; 23 22 struct gpio_desc *standby_gpio; 24 23 struct gpio_desc *enable_gpio; 24 + struct mux_state *mux_state; 25 25 }; 26 26 27 27 /* Power on function */ 28 28 static int can_transceiver_phy_power_on(struct phy *phy) 29 29 { 30 30 struct can_transceiver_phy *can_transceiver_phy = phy_get_drvdata(phy); 31 + int ret; 31 32 33 + if (can_transceiver_phy->mux_state) { 34 + ret = mux_state_select(can_transceiver_phy->mux_state); 35 + if (ret) { 36 + dev_err(&phy->dev, "Failed to select CAN mux: %d\n", ret); 37 + return ret; 38 + } 39 + } 32 40 if (can_transceiver_phy->standby_gpio) 33 41 gpiod_set_value_cansleep(can_transceiver_phy->standby_gpio, 0); 34 42 if (can_transceiver_phy->enable_gpio) ··· 55 45 gpiod_set_value_cansleep(can_transceiver_phy->standby_gpio, 1); 56 46 if (can_transceiver_phy->enable_gpio) 57 47 gpiod_set_value_cansleep(can_transceiver_phy->enable_gpio, 0); 48 + if (can_transceiver_phy->mux_state) 49 + mux_state_deselect(can_transceiver_phy->mux_state); 58 50 59 51 return 0; 60 52 } ··· 106 94 107 95 match = of_match_node(can_transceiver_phy_ids, pdev->dev.of_node); 108 96 drvdata = match->data; 97 + 98 + if (of_property_read_bool(dev->of_node, "mux-states")) { 99 + struct mux_state *mux_state; 100 + 101 + mux_state = devm_mux_state_get(dev, NULL); 102 + if (IS_ERR(mux_state)) 103 + return dev_err_probe(&pdev->dev, PTR_ERR(mux_state), 104 + "failed to get mux\n"); 105 + can_transceiver_phy->mux_state = mux_state; 106 + } 109 107 110 108 phy = devm_phy_create(dev, dev->of_node, 111 109 &can_transceiver_phy_ops);