spi.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * SPI bridge PHY driver.
  3. *
  4. * Copyright 2014-2016 Google Inc.
  5. * Copyright 2014-2016 Linaro Ltd.
  6. *
  7. * Released under the GPLv2 only.
  8. */
  9. #include <linux/module.h>
  10. #include "greybus.h"
  11. #include "gbphy.h"
  12. #include "spilib.h"
  13. static struct spilib_ops *spilib_ops;
  14. static int gb_spi_probe(struct gbphy_device *gbphy_dev,
  15. const struct gbphy_device_id *id)
  16. {
  17. struct gb_connection *connection;
  18. int ret;
  19. connection = gb_connection_create(gbphy_dev->bundle,
  20. le16_to_cpu(gbphy_dev->cport_desc->id),
  21. NULL);
  22. if (IS_ERR(connection))
  23. return PTR_ERR(connection);
  24. ret = gb_connection_enable(connection);
  25. if (ret)
  26. goto exit_connection_destroy;
  27. ret = gb_spilib_master_init(connection, &gbphy_dev->dev, spilib_ops);
  28. if (ret)
  29. goto exit_connection_disable;
  30. gb_gbphy_set_data(gbphy_dev, connection);
  31. gbphy_runtime_put_autosuspend(gbphy_dev);
  32. return 0;
  33. exit_connection_disable:
  34. gb_connection_disable(connection);
  35. exit_connection_destroy:
  36. gb_connection_destroy(connection);
  37. return ret;
  38. }
  39. static void gb_spi_remove(struct gbphy_device *gbphy_dev)
  40. {
  41. struct gb_connection *connection = gb_gbphy_get_data(gbphy_dev);
  42. int ret;
  43. ret = gbphy_runtime_get_sync(gbphy_dev);
  44. if (ret)
  45. gbphy_runtime_get_noresume(gbphy_dev);
  46. gb_spilib_master_exit(connection);
  47. gb_connection_disable(connection);
  48. gb_connection_destroy(connection);
  49. }
  50. static const struct gbphy_device_id gb_spi_id_table[] = {
  51. { GBPHY_PROTOCOL(GREYBUS_PROTOCOL_SPI) },
  52. { },
  53. };
  54. MODULE_DEVICE_TABLE(gbphy, gb_spi_id_table);
  55. static struct gbphy_driver spi_driver = {
  56. .name = "spi",
  57. .probe = gb_spi_probe,
  58. .remove = gb_spi_remove,
  59. .id_table = gb_spi_id_table,
  60. };
  61. module_gbphy_driver(spi_driver);
  62. MODULE_LICENSE("GPL v2");