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

Configure Feed

Select the types of activity you want to include in your feed.

USB: typec: tps6598x: Add device data to of_device_id

Part of tps6598x refactoring, we need to move the following functions
to device data as tps25750 has different implementation than tps6598x
and cd321x:
- interrupt handler
- port registration
- power status trace
- status trace

Signed-off-by: Abdel Alkuor <abdelalkuor@geotab.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20231003155842.57313-6-alkuor@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Abdel Alkuor and committed by
Greg Kroah-Hartman
5bd4853d 8f999ce6

+43 -14
+43 -14
drivers/usb/typec/tipd/core.c
··· 82 82 /* Unrecognized commands will be replaced with "!CMD" */ 83 83 #define INVALID_CMD(_cmd_) (_cmd_ == 0x444d4321) 84 84 85 + struct tps6598x; 86 + 87 + struct tipd_data { 88 + irq_handler_t irq_handler; 89 + int (*register_port)(struct tps6598x *tps, struct fwnode_handle *node); 90 + void (*trace_power_status)(u16 status); 91 + void (*trace_status)(u32 status); 92 + }; 93 + 85 94 struct tps6598x { 86 95 struct device *dev; 87 96 struct regmap *regmap; ··· 110 101 int wakeup; 111 102 u16 pwr_status; 112 103 struct delayed_work wq_poll; 113 - irq_handler_t irq_handler; 104 + 105 + const struct tipd_data *data; 114 106 }; 115 107 116 108 static enum power_supply_property tps6598x_psy_props[] = { ··· 442 432 dev_err(tps->dev, "%s: failed to read status\n", __func__); 443 433 return false; 444 434 } 445 - trace_tps6598x_status(*status); 435 + 436 + if (tps->data->trace_status) 437 + tps->data->trace_status(*status); 446 438 447 439 return true; 448 440 } ··· 475 463 return false; 476 464 } 477 465 tps->pwr_status = pwr_status; 478 - trace_tps6598x_power_status(pwr_status); 466 + 467 + if (tps->data->trace_power_status) 468 + tps->data->trace_power_status(pwr_status); 479 469 480 470 return true; 481 471 } ··· 595 581 struct tps6598x *tps = container_of(to_delayed_work(work), 596 582 struct tps6598x, wq_poll); 597 583 598 - tps->irq_handler(0, tps); 584 + tps->data->irq_handler(0, tps); 599 585 queue_delayed_work(system_power_efficient_wq, 600 586 &tps->wq_poll, msecs_to_jiffies(POLL_INTERVAL)); 601 587 } ··· 779 765 780 766 static int tps6598x_probe(struct i2c_client *client) 781 767 { 782 - irq_handler_t irq_handler = tps6598x_interrupt; 783 768 struct device_node *np = client->dev.of_node; 784 769 struct tps6598x *tps; 785 770 struct fwnode_handle *fwnode; ··· 820 807 APPLE_CD_REG_INT_DATA_STATUS_UPDATE | 821 808 APPLE_CD_REG_INT_PLUG_EVENT; 822 809 823 - irq_handler = cd321x_interrupt; 824 810 } else { 825 811 /* Enable power status, data status and plug event interrupts */ 826 812 mask1 = TPS_REG_INT_POWER_STATUS_UPDATE | ··· 827 815 TPS_REG_INT_PLUG_EVENT; 828 816 } 829 817 830 - tps->irq_handler = irq_handler; 818 + tps->data = device_get_match_data(tps->dev); 819 + if (!tps->data) 820 + return -EINVAL; 821 + 831 822 /* Make sure the controller has application firmware running */ 832 823 ret = tps6598x_check_mode(tps); 833 824 if (ret) ··· 840 825 if (ret) 841 826 return ret; 842 827 843 - ret = tps6598x_read32(tps, TPS_REG_STATUS, &status); 844 - if (ret < 0) 828 + if (!tps6598x_read_status(tps, &status)) { 829 + ret = -ENODEV; 845 830 goto err_clear_mask; 846 - trace_tps6598x_status(status); 831 + } 847 832 848 833 /* 849 834 * This fwnode has a "compatible" property, but is never populated as a ··· 866 851 if (ret) 867 852 goto err_role_put; 868 853 869 - ret = tps6598x_register_port(tps, fwnode); 854 + ret = tps->data->register_port(tps, fwnode); 870 855 if (ret) 871 856 goto err_role_put; 872 857 ··· 883 868 884 869 if (client->irq) { 885 870 ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, 886 - irq_handler, 871 + tps->data->irq_handler, 887 872 IRQF_SHARED | IRQF_ONESHOT, 888 873 dev_name(&client->dev), tps); 889 874 } else { ··· 969 954 SET_SYSTEM_SLEEP_PM_OPS(tps6598x_suspend, tps6598x_resume) 970 955 }; 971 956 957 + static const struct tipd_data cd321x_data = { 958 + .irq_handler = cd321x_interrupt, 959 + .register_port = tps6598x_register_port, 960 + .trace_power_status = trace_tps6598x_power_status, 961 + .trace_status = trace_tps6598x_status, 962 + }; 963 + 964 + static const struct tipd_data tps6598x_data = { 965 + .irq_handler = tps6598x_interrupt, 966 + .register_port = tps6598x_register_port, 967 + .trace_power_status = trace_tps6598x_power_status, 968 + .trace_status = trace_tps6598x_status, 969 + }; 970 + 972 971 static const struct of_device_id tps6598x_of_match[] = { 973 - { .compatible = "ti,tps6598x", }, 974 - { .compatible = "apple,cd321x", }, 972 + { .compatible = "ti,tps6598x", &tps6598x_data}, 973 + { .compatible = "apple,cd321x", &cd321x_data}, 975 974 {} 976 975 }; 977 976 MODULE_DEVICE_TABLE(of, tps6598x_of_match);