2017-11-07 13:58:41 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-05-14 18:12:20 +00:00
|
|
|
/*
|
|
|
|
* SPI bridge PHY driver.
|
|
|
|
*
|
|
|
|
* Copyright 2014-2016 Google Inc.
|
|
|
|
* Copyright 2014-2016 Linaro Ltd.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
2019-08-25 05:54:27 +00:00
|
|
|
#include <linux/greybus.h>
|
2016-05-14 18:12:20 +00:00
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
#include "gbphy.h"
|
2016-05-14 18:12:20 +00:00
|
|
|
#include "spilib.h"
|
|
|
|
|
2016-09-08 14:06:27 +00:00
|
|
|
static struct spilib_ops *spilib_ops;
|
2016-07-21 21:45:06 +00:00
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
static int gb_spi_probe(struct gbphy_device *gbphy_dev,
|
|
|
|
const struct gbphy_device_id *id)
|
2016-05-14 18:12:20 +00:00
|
|
|
{
|
|
|
|
struct gb_connection *connection;
|
|
|
|
int ret;
|
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
connection = gb_connection_create(gbphy_dev->bundle,
|
|
|
|
le16_to_cpu(gbphy_dev->cport_desc->id),
|
2016-05-14 18:12:20 +00:00
|
|
|
NULL);
|
|
|
|
if (IS_ERR(connection))
|
|
|
|
return PTR_ERR(connection);
|
|
|
|
|
|
|
|
ret = gb_connection_enable(connection);
|
|
|
|
if (ret)
|
|
|
|
goto exit_connection_destroy;
|
|
|
|
|
2016-07-21 21:45:06 +00:00
|
|
|
ret = gb_spilib_master_init(connection, &gbphy_dev->dev, spilib_ops);
|
2016-05-14 18:12:20 +00:00
|
|
|
if (ret)
|
|
|
|
goto exit_connection_disable;
|
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
gb_gbphy_set_data(gbphy_dev, connection);
|
2016-05-14 18:12:20 +00:00
|
|
|
|
2016-07-14 20:13:00 +00:00
|
|
|
gbphy_runtime_put_autosuspend(gbphy_dev);
|
2016-05-14 18:12:20 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
exit_connection_disable:
|
|
|
|
gb_connection_disable(connection);
|
|
|
|
exit_connection_destroy:
|
|
|
|
gb_connection_destroy(connection);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
static void gb_spi_remove(struct gbphy_device *gbphy_dev)
|
2016-05-14 18:12:20 +00:00
|
|
|
{
|
2016-05-19 15:52:39 +00:00
|
|
|
struct gb_connection *connection = gb_gbphy_get_data(gbphy_dev);
|
2016-07-14 20:13:00 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = gbphy_runtime_get_sync(gbphy_dev);
|
|
|
|
if (ret)
|
|
|
|
gbphy_runtime_get_noresume(gbphy_dev);
|
2016-05-14 18:12:20 +00:00
|
|
|
|
|
|
|
gb_spilib_master_exit(connection);
|
|
|
|
gb_connection_disable(connection);
|
|
|
|
gb_connection_destroy(connection);
|
|
|
|
}
|
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
static const struct gbphy_device_id gb_spi_id_table[] = {
|
|
|
|
{ GBPHY_PROTOCOL(GREYBUS_PROTOCOL_SPI) },
|
2016-05-14 18:12:20 +00:00
|
|
|
{ },
|
|
|
|
};
|
2016-05-19 15:52:39 +00:00
|
|
|
MODULE_DEVICE_TABLE(gbphy, gb_spi_id_table);
|
2016-05-14 18:12:20 +00:00
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
static struct gbphy_driver spi_driver = {
|
2016-05-14 18:12:20 +00:00
|
|
|
.name = "spi",
|
|
|
|
.probe = gb_spi_probe,
|
|
|
|
.remove = gb_spi_remove,
|
|
|
|
.id_table = gb_spi_id_table,
|
|
|
|
};
|
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
module_gbphy_driver(spi_driver);
|
2016-05-14 18:12:20 +00:00
|
|
|
MODULE_LICENSE("GPL v2");
|