1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2024, Linaro Limited
6 #include <linux/gpio/consumer.h>
8 #include <linux/module.h>
10 #include <linux/phy/phy.h>
11 #include <linux/regmap.h>
12 #include <linux/regulator/consumer.h>
14 #define NUM_SUPPLIES 2
17 struct i2c_client
*client
;
19 struct gpio_desc
*reset_gpio
;
20 struct regulator_bulk_data
*supplies
;
23 static int ptn3222_init(struct phy
*phy
)
25 struct ptn3222
*ptn3222
= phy_get_drvdata(phy
);
28 ret
= regulator_bulk_enable(NUM_SUPPLIES
, ptn3222
->supplies
);
32 gpiod_set_value_cansleep(ptn3222
->reset_gpio
, 0);
37 static int ptn3222_exit(struct phy
*phy
)
39 struct ptn3222
*ptn3222
= phy_get_drvdata(phy
);
41 gpiod_set_value_cansleep(ptn3222
->reset_gpio
, 1);
43 return regulator_bulk_disable(NUM_SUPPLIES
, ptn3222
->supplies
);
46 static const struct phy_ops ptn3222_ops
= {
52 static const struct regulator_bulk_data ptn3222_supplies
[NUM_SUPPLIES
] = {
55 .init_load_uA
= 11000,
58 .init_load_uA
= 55000,
62 static int ptn3222_probe(struct i2c_client
*client
)
64 struct device
*dev
= &client
->dev
;
65 struct phy_provider
*phy_provider
;
66 struct ptn3222
*ptn3222
;
69 ptn3222
= devm_kzalloc(dev
, sizeof(*ptn3222
), GFP_KERNEL
);
73 ptn3222
->client
= client
;
75 ptn3222
->reset_gpio
= devm_gpiod_get_optional(dev
, "reset",
77 if (IS_ERR(ptn3222
->reset_gpio
))
78 return dev_err_probe(dev
, PTR_ERR(ptn3222
->reset_gpio
),
79 "unable to acquire reset gpio\n");
81 ret
= devm_regulator_bulk_get_const(dev
, NUM_SUPPLIES
, ptn3222_supplies
,
86 ptn3222
->phy
= devm_phy_create(dev
, dev
->of_node
, &ptn3222_ops
);
87 if (IS_ERR(ptn3222
->phy
)) {
88 dev_err(dev
, "failed to create PHY: %d\n", ret
);
89 return PTR_ERR(ptn3222
->phy
);
92 phy_set_drvdata(ptn3222
->phy
, ptn3222
);
94 phy_provider
= devm_of_phy_provider_register(dev
, of_phy_simple_xlate
);
96 return PTR_ERR_OR_ZERO(phy_provider
);
99 static const struct i2c_device_id ptn3222_table
[] = {
103 MODULE_DEVICE_TABLE(i2c
, ptn3222_table
);
105 static const struct of_device_id ptn3222_of_table
[] = {
106 { .compatible
= "nxp,ptn3222" },
109 MODULE_DEVICE_TABLE(of
, ptn3222_of_table
);
111 static struct i2c_driver ptn3222_driver
= {
114 .of_match_table
= ptn3222_of_table
,
116 .probe
= ptn3222_probe
,
117 .id_table
= ptn3222_table
,
120 module_i2c_driver(ptn3222_driver
);
122 MODULE_DESCRIPTION("NXP PTN3222 eUSB2 Redriver driver");
123 MODULE_LICENSE("GPL");