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