0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/module.h>
0010 #include <linux/greybus.h>
0011
0012 #include "gbphy.h"
0013 #include "spilib.h"
0014
0015 static struct spilib_ops *spilib_ops;
0016
0017 static int gb_spi_probe(struct gbphy_device *gbphy_dev,
0018 const struct gbphy_device_id *id)
0019 {
0020 struct gb_connection *connection;
0021 int ret;
0022
0023 connection = gb_connection_create(gbphy_dev->bundle,
0024 le16_to_cpu(gbphy_dev->cport_desc->id),
0025 NULL);
0026 if (IS_ERR(connection))
0027 return PTR_ERR(connection);
0028
0029 ret = gb_connection_enable(connection);
0030 if (ret)
0031 goto exit_connection_destroy;
0032
0033 ret = gb_spilib_master_init(connection, &gbphy_dev->dev, spilib_ops);
0034 if (ret)
0035 goto exit_connection_disable;
0036
0037 gb_gbphy_set_data(gbphy_dev, connection);
0038
0039 gbphy_runtime_put_autosuspend(gbphy_dev);
0040 return 0;
0041
0042 exit_connection_disable:
0043 gb_connection_disable(connection);
0044 exit_connection_destroy:
0045 gb_connection_destroy(connection);
0046
0047 return ret;
0048 }
0049
0050 static void gb_spi_remove(struct gbphy_device *gbphy_dev)
0051 {
0052 struct gb_connection *connection = gb_gbphy_get_data(gbphy_dev);
0053 int ret;
0054
0055 ret = gbphy_runtime_get_sync(gbphy_dev);
0056 if (ret)
0057 gbphy_runtime_get_noresume(gbphy_dev);
0058
0059 gb_spilib_master_exit(connection);
0060 gb_connection_disable(connection);
0061 gb_connection_destroy(connection);
0062 }
0063
0064 static const struct gbphy_device_id gb_spi_id_table[] = {
0065 { GBPHY_PROTOCOL(GREYBUS_PROTOCOL_SPI) },
0066 { },
0067 };
0068 MODULE_DEVICE_TABLE(gbphy, gb_spi_id_table);
0069
0070 static struct gbphy_driver spi_driver = {
0071 .name = "spi",
0072 .probe = gb_spi_probe,
0073 .remove = gb_spi_remove,
0074 .id_table = gb_spi_id_table,
0075 };
0076
0077 module_gbphy_driver(spi_driver);
0078 MODULE_LICENSE("GPL v2");