Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / phy / phy-nxp-ptn3222.c
blobc6179d8701e61d22be2cf9c7bec983c56564aad2
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2024, Linaro Limited
4 */
6 #include <linux/gpio/consumer.h>
7 #include <linux/i2c.h>
8 #include <linux/module.h>
9 #include <linux/of.h>
10 #include <linux/phy/phy.h>
11 #include <linux/regmap.h>
12 #include <linux/regulator/consumer.h>
14 #define NUM_SUPPLIES 2
16 struct ptn3222 {
17 struct i2c_client *client;
18 struct phy *phy;
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);
26 int ret;
28 ret = regulator_bulk_enable(NUM_SUPPLIES, ptn3222->supplies);
29 if (ret)
30 return ret;
32 gpiod_set_value_cansleep(ptn3222->reset_gpio, 0);
34 return 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 = {
47 .init = ptn3222_init,
48 .exit = ptn3222_exit,
49 .owner = THIS_MODULE,
52 static const struct regulator_bulk_data ptn3222_supplies[NUM_SUPPLIES] = {
54 .supply = "vdd3v3",
55 .init_load_uA = 11000,
56 }, {
57 .supply = "vdd1v8",
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;
67 int ret;
69 ptn3222 = devm_kzalloc(dev, sizeof(*ptn3222), GFP_KERNEL);
70 if (!ptn3222)
71 return -ENOMEM;
73 ptn3222->client = client;
75 ptn3222->reset_gpio = devm_gpiod_get_optional(dev, "reset",
76 GPIOD_OUT_HIGH);
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,
82 &ptn3222->supplies);
83 if (ret)
84 return ret;
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[] = {
100 { "ptn3222" },
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 = {
112 .driver = {
113 .name = "ptn3222",
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");