phy-nxp-ptn3222.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2024, Linaro Limited
  4. */
  5. #include <linux/gpio/consumer.h>
  6. #include <linux/i2c.h>
  7. #include <linux/module.h>
  8. #include <linux/of.h>
  9. #include <linux/phy/phy.h>
  10. #include <linux/regmap.h>
  11. #include <linux/regulator/consumer.h>
  12. #define NUM_SUPPLIES 2
  13. struct ptn3222 {
  14. struct i2c_client *client;
  15. struct phy *phy;
  16. struct gpio_desc *reset_gpio;
  17. struct regulator_bulk_data *supplies;
  18. };
  19. static int ptn3222_init(struct phy *phy)
  20. {
  21. struct ptn3222 *ptn3222 = phy_get_drvdata(phy);
  22. int ret;
  23. ret = regulator_bulk_enable(NUM_SUPPLIES, ptn3222->supplies);
  24. if (ret)
  25. return ret;
  26. gpiod_set_value_cansleep(ptn3222->reset_gpio, 0);
  27. return 0;
  28. }
  29. static int ptn3222_exit(struct phy *phy)
  30. {
  31. struct ptn3222 *ptn3222 = phy_get_drvdata(phy);
  32. gpiod_set_value_cansleep(ptn3222->reset_gpio, 1);
  33. return regulator_bulk_disable(NUM_SUPPLIES, ptn3222->supplies);
  34. }
  35. static const struct phy_ops ptn3222_ops = {
  36. .init = ptn3222_init,
  37. .exit = ptn3222_exit,
  38. .owner = THIS_MODULE,
  39. };
  40. static const struct regulator_bulk_data ptn3222_supplies[NUM_SUPPLIES] = {
  41. {
  42. .supply = "vdd3v3",
  43. .init_load_uA = 11000,
  44. }, {
  45. .supply = "vdd1v8",
  46. .init_load_uA = 55000,
  47. }
  48. };
  49. static int ptn3222_probe(struct i2c_client *client)
  50. {
  51. struct device *dev = &client->dev;
  52. struct phy_provider *phy_provider;
  53. struct ptn3222 *ptn3222;
  54. int ret;
  55. ptn3222 = devm_kzalloc(dev, sizeof(*ptn3222), GFP_KERNEL);
  56. if (!ptn3222)
  57. return -ENOMEM;
  58. ptn3222->client = client;
  59. ptn3222->reset_gpio = devm_gpiod_get_optional(dev, "reset",
  60. GPIOD_OUT_HIGH);
  61. if (IS_ERR(ptn3222->reset_gpio))
  62. return dev_err_probe(dev, PTR_ERR(ptn3222->reset_gpio),
  63. "unable to acquire reset gpio\n");
  64. ret = devm_regulator_bulk_get_const(dev, NUM_SUPPLIES, ptn3222_supplies,
  65. &ptn3222->supplies);
  66. if (ret)
  67. return ret;
  68. ptn3222->phy = devm_phy_create(dev, dev->of_node, &ptn3222_ops);
  69. if (IS_ERR(ptn3222->phy)) {
  70. dev_err(dev, "failed to create PHY: %d\n", ret);
  71. return PTR_ERR(ptn3222->phy);
  72. }
  73. phy_set_drvdata(ptn3222->phy, ptn3222);
  74. phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  75. return PTR_ERR_OR_ZERO(phy_provider);
  76. }
  77. static const struct i2c_device_id ptn3222_table[] = {
  78. { "ptn3222" },
  79. { }
  80. };
  81. MODULE_DEVICE_TABLE(i2c, ptn3222_table);
  82. static const struct of_device_id ptn3222_of_table[] = {
  83. { .compatible = "nxp,ptn3222" },
  84. { }
  85. };
  86. MODULE_DEVICE_TABLE(of, ptn3222_of_table);
  87. static struct i2c_driver ptn3222_driver = {
  88. .driver = {
  89. .name = "ptn3222",
  90. .of_match_table = ptn3222_of_table,
  91. },
  92. .probe = ptn3222_probe,
  93. .id_table = ptn3222_table,
  94. };
  95. module_i2c_driver(ptn3222_driver);
  96. MODULE_DESCRIPTION("NXP PTN3222 eUSB2 Redriver driver");
  97. MODULE_LICENSE("GPL");