WIP FPC-III support
[linux/fpc-iii.git] / drivers / staging / greybus / spi.c
blob68e8d272db6dc8b22cfa66e6b28fec57a0ebf5a3
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * SPI bridge PHY driver.
5 * Copyright 2014-2016 Google Inc.
6 * Copyright 2014-2016 Linaro Ltd.
7 */
9 #include <linux/module.h>
10 #include <linux/greybus.h>
12 #include "gbphy.h"
13 #include "spilib.h"
15 static struct spilib_ops *spilib_ops;
17 static int gb_spi_probe(struct gbphy_device *gbphy_dev,
18 const struct gbphy_device_id *id)
20 struct gb_connection *connection;
21 int ret;
23 connection = gb_connection_create(gbphy_dev->bundle,
24 le16_to_cpu(gbphy_dev->cport_desc->id),
25 NULL);
26 if (IS_ERR(connection))
27 return PTR_ERR(connection);
29 ret = gb_connection_enable(connection);
30 if (ret)
31 goto exit_connection_destroy;
33 ret = gb_spilib_master_init(connection, &gbphy_dev->dev, spilib_ops);
34 if (ret)
35 goto exit_connection_disable;
37 gb_gbphy_set_data(gbphy_dev, connection);
39 gbphy_runtime_put_autosuspend(gbphy_dev);
40 return 0;
42 exit_connection_disable:
43 gb_connection_disable(connection);
44 exit_connection_destroy:
45 gb_connection_destroy(connection);
47 return ret;
50 static void gb_spi_remove(struct gbphy_device *gbphy_dev)
52 struct gb_connection *connection = gb_gbphy_get_data(gbphy_dev);
53 int ret;
55 ret = gbphy_runtime_get_sync(gbphy_dev);
56 if (ret)
57 gbphy_runtime_get_noresume(gbphy_dev);
59 gb_spilib_master_exit(connection);
60 gb_connection_disable(connection);
61 gb_connection_destroy(connection);
64 static const struct gbphy_device_id gb_spi_id_table[] = {
65 { GBPHY_PROTOCOL(GREYBUS_PROTOCOL_SPI) },
66 { },
68 MODULE_DEVICE_TABLE(gbphy, gb_spi_id_table);
70 static struct gbphy_driver spi_driver = {
71 .name = "spi",
72 .probe = gb_spi_probe,
73 .remove = gb_spi_remove,
74 .id_table = gb_spi_id_table,
77 module_gbphy_driver(spi_driver);
78 MODULE_LICENSE("GPL v2");