2 * SPI bridge PHY driver.
4 * Copyright 2014-2016 Google Inc.
5 * Copyright 2014-2016 Linaro Ltd.
7 * Released under the GPLv2 only.
10 #include <linux/module.h>
16 #ifndef SPI_CORE_SUPPORT_PM
17 static int gbphy_spi_prepare_transfer_hardware(struct device *dev)
19 return gbphy_runtime_get_sync(to_gbphy_dev(dev));
22 static void gbphy_spi_unprepare_transfer_hardware(struct device *dev)
24 gbphy_runtime_put_autosuspend(to_gbphy_dev(dev));
27 static struct spilib_ops __spilib_ops = {
28 .prepare_transfer_hardware = gbphy_spi_prepare_transfer_hardware,
29 .unprepare_transfer_hardware = gbphy_spi_unprepare_transfer_hardware,
32 static struct spilib_ops *spilib_ops = &__spilib_ops;
34 static struct spilib_ops *spilib_ops = NULL;
37 static int gb_spi_probe(struct gbphy_device *gbphy_dev,
38 const struct gbphy_device_id *id)
40 struct gb_connection *connection;
43 connection = gb_connection_create(gbphy_dev->bundle,
44 le16_to_cpu(gbphy_dev->cport_desc->id),
46 if (IS_ERR(connection))
47 return PTR_ERR(connection);
49 ret = gb_connection_enable(connection);
51 goto exit_connection_destroy;
53 ret = gb_spilib_master_init(connection, &gbphy_dev->dev, spilib_ops);
55 goto exit_connection_disable;
57 gb_gbphy_set_data(gbphy_dev, connection);
59 gbphy_runtime_put_autosuspend(gbphy_dev);
62 exit_connection_disable:
63 gb_connection_disable(connection);
64 exit_connection_destroy:
65 gb_connection_destroy(connection);
70 static void gb_spi_remove(struct gbphy_device *gbphy_dev)
72 struct gb_connection *connection = gb_gbphy_get_data(gbphy_dev);
75 ret = gbphy_runtime_get_sync(gbphy_dev);
77 gbphy_runtime_get_noresume(gbphy_dev);
79 gb_spilib_master_exit(connection);
80 gb_connection_disable(connection);
81 gb_connection_destroy(connection);
84 static const struct gbphy_device_id gb_spi_id_table[] = {
85 { GBPHY_PROTOCOL(GREYBUS_PROTOCOL_SPI) },
88 MODULE_DEVICE_TABLE(gbphy, gb_spi_id_table);
90 static struct gbphy_driver spi_driver = {
92 .probe = gb_spi_probe,
93 .remove = gb_spi_remove,
94 .id_table = gb_spi_id_table,
97 module_gbphy_driver(spi_driver);
98 MODULE_LICENSE("GPL v2");