Skip to content

Commit 5bd4853

Browse files
abdelalkuorgregkh
authored andcommitted
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>
1 parent 8f999ce commit 5bd4853

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

drivers/usb/typec/tipd/core.c

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ static const char *const modes[] = {
8282
/* Unrecognized commands will be replaced with "!CMD" */
8383
#define INVALID_CMD(_cmd_) (_cmd_ == 0x444d4321)
8484

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+
8594
struct tps6598x {
8695
struct device *dev;
8796
struct regmap *regmap;
@@ -101,7 +110,8 @@ struct tps6598x {
101110
int wakeup;
102111
u16 pwr_status;
103112
struct delayed_work wq_poll;
104-
irq_handler_t irq_handler;
113+
114+
const struct tipd_data *data;
105115
};
106116

107117
static enum power_supply_property tps6598x_psy_props[] = {
@@ -432,7 +442,9 @@ static bool tps6598x_read_status(struct tps6598x *tps, u32 *status)
432442
dev_err(tps->dev, "%s: failed to read status\n", __func__);
433443
return false;
434444
}
435-
trace_tps6598x_status(*status);
445+
446+
if (tps->data->trace_status)
447+
tps->data->trace_status(*status);
436448

437449
return true;
438450
}
@@ -463,7 +475,9 @@ static bool tps6598x_read_power_status(struct tps6598x *tps)
463475
return false;
464476
}
465477
tps->pwr_status = pwr_status;
466-
trace_tps6598x_power_status(pwr_status);
478+
479+
if (tps->data->trace_power_status)
480+
tps->data->trace_power_status(pwr_status);
467481

468482
return true;
469483
}
@@ -581,7 +595,7 @@ static void tps6598x_poll_work(struct work_struct *work)
581595
struct tps6598x *tps = container_of(to_delayed_work(work),
582596
struct tps6598x, wq_poll);
583597

584-
tps->irq_handler(0, tps);
598+
tps->data->irq_handler(0, tps);
585599
queue_delayed_work(system_power_efficient_wq,
586600
&tps->wq_poll, msecs_to_jiffies(POLL_INTERVAL));
587601
}
@@ -765,7 +779,6 @@ tps6598x_register_port(struct tps6598x *tps, struct fwnode_handle *fwnode)
765779

766780
static int tps6598x_probe(struct i2c_client *client)
767781
{
768-
irq_handler_t irq_handler = tps6598x_interrupt;
769782
struct device_node *np = client->dev.of_node;
770783
struct tps6598x *tps;
771784
struct fwnode_handle *fwnode;
@@ -807,15 +820,17 @@ static int tps6598x_probe(struct i2c_client *client)
807820
APPLE_CD_REG_INT_DATA_STATUS_UPDATE |
808821
APPLE_CD_REG_INT_PLUG_EVENT;
809822

810-
irq_handler = cd321x_interrupt;
811823
} else {
812824
/* Enable power status, data status and plug event interrupts */
813825
mask1 = TPS_REG_INT_POWER_STATUS_UPDATE |
814826
TPS_REG_INT_DATA_STATUS_UPDATE |
815827
TPS_REG_INT_PLUG_EVENT;
816828
}
817829

818-
tps->irq_handler = irq_handler;
830+
tps->data = device_get_match_data(tps->dev);
831+
if (!tps->data)
832+
return -EINVAL;
833+
819834
/* Make sure the controller has application firmware running */
820835
ret = tps6598x_check_mode(tps);
821836
if (ret)
@@ -825,10 +840,10 @@ static int tps6598x_probe(struct i2c_client *client)
825840
if (ret)
826841
return ret;
827842

828-
ret = tps6598x_read32(tps, TPS_REG_STATUS, &status);
829-
if (ret < 0)
843+
if (!tps6598x_read_status(tps, &status)) {
844+
ret = -ENODEV;
830845
goto err_clear_mask;
831-
trace_tps6598x_status(status);
846+
}
832847

833848
/*
834849
* This fwnode has a "compatible" property, but is never populated as a
@@ -851,7 +866,7 @@ static int tps6598x_probe(struct i2c_client *client)
851866
if (ret)
852867
goto err_role_put;
853868

854-
ret = tps6598x_register_port(tps, fwnode);
869+
ret = tps->data->register_port(tps, fwnode);
855870
if (ret)
856871
goto err_role_put;
857872

@@ -868,7 +883,7 @@ static int tps6598x_probe(struct i2c_client *client)
868883

869884
if (client->irq) {
870885
ret = devm_request_threaded_irq(&client->dev, client->irq, NULL,
871-
irq_handler,
886+
tps->data->irq_handler,
872887
IRQF_SHARED | IRQF_ONESHOT,
873888
dev_name(&client->dev), tps);
874889
} else {
@@ -954,9 +969,23 @@ static const struct dev_pm_ops tps6598x_pm_ops = {
954969
SET_SYSTEM_SLEEP_PM_OPS(tps6598x_suspend, tps6598x_resume)
955970
};
956971

972+
static const struct tipd_data cd321x_data = {
973+
.irq_handler = cd321x_interrupt,
974+
.register_port = tps6598x_register_port,
975+
.trace_power_status = trace_tps6598x_power_status,
976+
.trace_status = trace_tps6598x_status,
977+
};
978+
979+
static const struct tipd_data tps6598x_data = {
980+
.irq_handler = tps6598x_interrupt,
981+
.register_port = tps6598x_register_port,
982+
.trace_power_status = trace_tps6598x_power_status,
983+
.trace_status = trace_tps6598x_status,
984+
};
985+
957986
static const struct of_device_id tps6598x_of_match[] = {
958-
{ .compatible = "ti,tps6598x", },
959-
{ .compatible = "apple,cd321x", },
987+
{ .compatible = "ti,tps6598x", &tps6598x_data},
988+
{ .compatible = "apple,cd321x", &cd321x_data},
960989
{}
961990
};
962991
MODULE_DEVICE_TABLE(of, tps6598x_of_match);

0 commit comments

Comments
 (0)