Commit | Line | Data |
---|---|---|
8888b963 VK |
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 | ||
10 | #include <linux/module.h> | |
11 | ||
12 | #include "greybus.h" | |
e54b106d | 13 | #include "gbphy.h" |
8888b963 VK |
14 | #include "spilib.h" |
15 | ||
148e0b8f | 16 | static struct spilib_ops *spilib_ops; |
92bcadde | 17 | |
e54b106d SP |
18 | static int gb_spi_probe(struct gbphy_device *gbphy_dev, |
19 | const struct gbphy_device_id *id) | |
8888b963 VK |
20 | { |
21 | struct gb_connection *connection; | |
22 | int ret; | |
23 | ||
e54b106d SP |
24 | connection = gb_connection_create(gbphy_dev->bundle, |
25 | le16_to_cpu(gbphy_dev->cport_desc->id), | |
8888b963 VK |
26 | NULL); |
27 | if (IS_ERR(connection)) | |
28 | return PTR_ERR(connection); | |
29 | ||
30 | ret = gb_connection_enable(connection); | |
31 | if (ret) | |
32 | goto exit_connection_destroy; | |
33 | ||
92bcadde | 34 | ret = gb_spilib_master_init(connection, &gbphy_dev->dev, spilib_ops); |
8888b963 VK |
35 | if (ret) |
36 | goto exit_connection_disable; | |
37 | ||
e54b106d | 38 | gb_gbphy_set_data(gbphy_dev, connection); |
8888b963 | 39 | |
4c615dcc | 40 | gbphy_runtime_put_autosuspend(gbphy_dev); |
8888b963 VK |
41 | return 0; |
42 | ||
43 | exit_connection_disable: | |
44 | gb_connection_disable(connection); | |
45 | exit_connection_destroy: | |
46 | gb_connection_destroy(connection); | |
47 | ||
48 | return ret; | |
49 | } | |
50 | ||
e54b106d | 51 | static void gb_spi_remove(struct gbphy_device *gbphy_dev) |
8888b963 | 52 | { |
e54b106d | 53 | struct gb_connection *connection = gb_gbphy_get_data(gbphy_dev); |
4c615dcc AH |
54 | int ret; |
55 | ||
56 | ret = gbphy_runtime_get_sync(gbphy_dev); | |
57 | if (ret) | |
58 | gbphy_runtime_get_noresume(gbphy_dev); | |
8888b963 VK |
59 | |
60 | gb_spilib_master_exit(connection); | |
61 | gb_connection_disable(connection); | |
62 | gb_connection_destroy(connection); | |
63 | } | |
64 | ||
e54b106d SP |
65 | static const struct gbphy_device_id gb_spi_id_table[] = { |
66 | { GBPHY_PROTOCOL(GREYBUS_PROTOCOL_SPI) }, | |
8888b963 VK |
67 | { }, |
68 | }; | |
e54b106d | 69 | MODULE_DEVICE_TABLE(gbphy, gb_spi_id_table); |
8888b963 | 70 | |
e54b106d | 71 | static struct gbphy_driver spi_driver = { |
8888b963 VK |
72 | .name = "spi", |
73 | .probe = gb_spi_probe, | |
74 | .remove = gb_spi_remove, | |
75 | .id_table = gb_spi_id_table, | |
76 | }; | |
77 | ||
e54b106d | 78 | module_gbphy_driver(spi_driver); |
8888b963 | 79 | MODULE_LICENSE("GPL v2"); |