phy-tusb1210.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * tusb1210.c - TUSB1210 USB ULPI PHY driver
  3. *
  4. * Copyright (C) 2015 Intel Corporation
  5. *
  6. * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/ulpi/driver.h>
  14. #include <linux/gpio/consumer.h>
  15. #include "ulpi_phy.h"
  16. #define TUSB1210_VENDOR_SPECIFIC2 0x80
  17. #define TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT 0
  18. #define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT 4
  19. #define TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT 6
  20. struct tusb1210 {
  21. struct ulpi *ulpi;
  22. struct phy *phy;
  23. struct gpio_desc *gpio_reset;
  24. struct gpio_desc *gpio_cs;
  25. u8 vendor_specific2;
  26. };
  27. static int tusb1210_power_on(struct phy *phy)
  28. {
  29. struct tusb1210 *tusb = phy_get_drvdata(phy);
  30. gpiod_set_value_cansleep(tusb->gpio_reset, 1);
  31. gpiod_set_value_cansleep(tusb->gpio_cs, 1);
  32. /* Restore the optional eye diagram optimization value */
  33. if (tusb->vendor_specific2)
  34. ulpi_write(tusb->ulpi, TUSB1210_VENDOR_SPECIFIC2,
  35. tusb->vendor_specific2);
  36. return 0;
  37. }
  38. static int tusb1210_power_off(struct phy *phy)
  39. {
  40. struct tusb1210 *tusb = phy_get_drvdata(phy);
  41. gpiod_set_value_cansleep(tusb->gpio_reset, 0);
  42. gpiod_set_value_cansleep(tusb->gpio_cs, 0);
  43. return 0;
  44. }
  45. static const struct phy_ops phy_ops = {
  46. .power_on = tusb1210_power_on,
  47. .power_off = tusb1210_power_off,
  48. .owner = THIS_MODULE,
  49. };
  50. static int tusb1210_probe(struct ulpi *ulpi)
  51. {
  52. struct tusb1210 *tusb;
  53. u8 val, reg;
  54. tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL);
  55. if (!tusb)
  56. return -ENOMEM;
  57. tusb->gpio_reset = devm_gpiod_get_optional(&ulpi->dev, "reset",
  58. GPIOD_OUT_LOW);
  59. if (IS_ERR(tusb->gpio_reset))
  60. return PTR_ERR(tusb->gpio_reset);
  61. gpiod_set_value_cansleep(tusb->gpio_reset, 1);
  62. tusb->gpio_cs = devm_gpiod_get_optional(&ulpi->dev, "cs",
  63. GPIOD_OUT_LOW);
  64. if (IS_ERR(tusb->gpio_cs))
  65. return PTR_ERR(tusb->gpio_cs);
  66. gpiod_set_value_cansleep(tusb->gpio_cs, 1);
  67. /*
  68. * VENDOR_SPECIFIC2 register in TUSB1210 can be used for configuring eye
  69. * diagram optimization and DP/DM swap.
  70. */
  71. /* High speed output drive strength configuration */
  72. device_property_read_u8(&ulpi->dev, "ihstx", &val);
  73. reg = val << TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT;
  74. /* High speed output impedance configuration */
  75. device_property_read_u8(&ulpi->dev, "zhsdrv", &val);
  76. reg |= val << TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT;
  77. /* DP/DM swap control */
  78. device_property_read_u8(&ulpi->dev, "datapolarity", &val);
  79. reg |= val << TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT;
  80. if (reg) {
  81. ulpi_write(ulpi, TUSB1210_VENDOR_SPECIFIC2, reg);
  82. tusb->vendor_specific2 = reg;
  83. }
  84. tusb->phy = ulpi_phy_create(ulpi, &phy_ops);
  85. if (IS_ERR(tusb->phy))
  86. return PTR_ERR(tusb->phy);
  87. tusb->ulpi = ulpi;
  88. phy_set_drvdata(tusb->phy, tusb);
  89. ulpi_set_drvdata(ulpi, tusb);
  90. return 0;
  91. }
  92. static void tusb1210_remove(struct ulpi *ulpi)
  93. {
  94. struct tusb1210 *tusb = ulpi_get_drvdata(ulpi);
  95. ulpi_phy_destroy(ulpi, tusb->phy);
  96. }
  97. #define TI_VENDOR_ID 0x0451
  98. static const struct ulpi_device_id tusb1210_ulpi_id[] = {
  99. { TI_VENDOR_ID, 0x1507, },
  100. { },
  101. };
  102. MODULE_DEVICE_TABLE(ulpi, tusb1210_ulpi_id);
  103. static struct ulpi_driver tusb1210_driver = {
  104. .id_table = tusb1210_ulpi_id,
  105. .probe = tusb1210_probe,
  106. .remove = tusb1210_remove,
  107. .driver = {
  108. .name = "tusb1210",
  109. .owner = THIS_MODULE,
  110. },
  111. };
  112. module_ulpi_driver(tusb1210_driver);
  113. MODULE_AUTHOR("Intel Corporation");
  114. MODULE_LICENSE("GPL v2");
  115. MODULE_DESCRIPTION("TUSB1210 ULPI PHY driver");