]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/staging/greybus/sdio.c
greybus: gbphy: Remove protocol specific version handling
[karo-tx-linux.git] / drivers / staging / greybus / sdio.c
index d4cbcb972e94c7e875237fa689704a77b14f1389..a270517c90c87d9fd54c0f2c2f10aefde2b8a41b 100644 (file)
 #include <linux/workqueue.h>
 
 #include "greybus.h"
-#include "gpbridge.h"
+#include "gbphy.h"
 
 struct gb_sdio_host {
        struct gb_connection    *connection;
+       struct gbphy_device     *gbphy_dev;
        struct mmc_host         *mmc;
        struct mmc_request      *mrq;
        struct mutex            lock;   /* lock for this host */
@@ -199,11 +200,12 @@ static int _gb_sdio_process_events(struct gb_sdio_host *host, u8 event)
        return 0;
 }
 
-static int gb_sdio_event_recv(u8 type, struct gb_operation *op)
+static int gb_sdio_request_handler(struct gb_operation *op)
 {
        struct gb_sdio_host *host = gb_connection_get_data(op->connection);
        struct gb_message *request;
        struct gb_sdio_event_request *payload;
+       u8 type = op->type;
        int ret =  0;
        u8 event;
 
@@ -682,9 +684,12 @@ static int gb_mmc_get_ro(struct mmc_host *mmc)
        struct gb_sdio_host *host = mmc_priv(mmc);
 
        mutex_lock(&host->lock);
-       if (host->removed)
+       if (host->removed) {
+               mutex_unlock(&host->lock);
                return -ESHUTDOWN;
+       }
        mutex_unlock(&host->lock);
+
        return host->read_only;
 }
 
@@ -693,9 +698,12 @@ static int gb_mmc_get_cd(struct mmc_host *mmc)
        struct gb_sdio_host *host = mmc_priv(mmc);
 
        mutex_lock(&host->lock);
-       if (host->removed)
+       if (host->removed) {
+               mutex_unlock(&host->lock);
                return -ESHUTDOWN;
+       }
        mutex_unlock(&host->lock);
+
        return host->card_present;
 }
 
@@ -706,27 +714,43 @@ static const struct mmc_host_ops gb_sdio_ops = {
        .get_cd         = gb_mmc_get_cd,
 };
 
-static int gb_sdio_connection_init(struct gb_connection *connection)
+static int gb_sdio_probe(struct gbphy_device *gbphy_dev,
+                        const struct gbphy_device_id *id)
 {
+       struct gb_connection *connection;
        struct mmc_host *mmc;
        struct gb_sdio_host *host;
        size_t max_buffer;
        int ret = 0;
 
-       mmc = mmc_alloc_host(sizeof(*host), &connection->bundle->dev);
+       mmc = mmc_alloc_host(sizeof(*host), &gbphy_dev->dev);
        if (!mmc)
                return -ENOMEM;
 
+       connection = gb_connection_create(gbphy_dev->bundle,
+                                         le16_to_cpu(gbphy_dev->cport_desc->id),
+                                         gb_sdio_request_handler);
+       if (IS_ERR(connection)) {
+               ret = PTR_ERR(connection);
+               goto exit_mmc_free;
+       }
+
        host = mmc_priv(mmc);
        host->mmc = mmc;
        host->removed = true;
 
        host->connection = connection;
        gb_connection_set_data(connection, host);
+       host->gbphy_dev = gbphy_dev;
+       gb_gbphy_set_data(gbphy_dev, host);
+
+       ret = gb_connection_enable_tx(connection);
+       if (ret)
+               goto exit_connection_destroy;
 
        ret = gb_sdio_get_caps(host);
        if (ret < 0)
-               goto free_mmc;
+               goto exit_connection_disable;
 
        mmc->ops = &gb_sdio_ops;
 
@@ -740,45 +764,50 @@ static int gb_sdio_connection_init(struct gb_connection *connection)
        host->xfer_buffer = kzalloc(max_buffer, GFP_KERNEL);
        if (!host->xfer_buffer) {
                ret = -ENOMEM;
-               goto free_mmc;
+               goto exit_connection_disable;
        }
        mutex_init(&host->lock);
        spin_lock_init(&host->xfer);
        host->mrq_workqueue = alloc_workqueue("mmc-%s", 0, 1,
-                                             dev_name(&connection->bundle->dev));
+                                             dev_name(&gbphy_dev->dev));
        if (!host->mrq_workqueue) {
                ret = -ENOMEM;
-               goto free_buffer;
+               goto exit_buf_free;
        }
        INIT_WORK(&host->mrqwork, gb_sdio_mrq_work);
 
+       ret = gb_connection_enable(connection);
+       if (ret)
+               goto exit_wq_destroy;
+
        ret = mmc_add_host(mmc);
        if (ret < 0)
-               goto free_work;
+               goto exit_wq_destroy;
        host->removed = false;
        ret = _gb_sdio_process_events(host, host->queued_events);
        host->queued_events = 0;
 
        return ret;
 
-free_work:
+exit_wq_destroy:
        destroy_workqueue(host->mrq_workqueue);
-free_buffer:
+exit_buf_free:
        kfree(host->xfer_buffer);
-free_mmc:
-       gb_connection_set_data(connection, NULL);
+exit_connection_disable:
+       gb_connection_disable(connection);
+exit_connection_destroy:
+       gb_connection_destroy(connection);
+exit_mmc_free:
        mmc_free_host(mmc);
 
        return ret;
 }
 
-static void gb_sdio_connection_exit(struct gb_connection *connection)
+static void gb_sdio_remove(struct gbphy_device *gbphy_dev)
 {
+       struct gb_sdio_host *host = gb_gbphy_get_data(gbphy_dev);
+       struct gb_connection *connection = host->connection;
        struct mmc_host *mmc;
-       struct gb_sdio_host *host = gb_connection_get_data(connection);
-
-       if (!host)
-               return;
 
        mutex_lock(&host->lock);
        host->removed = true;
@@ -788,19 +817,26 @@ static void gb_sdio_connection_exit(struct gb_connection *connection)
 
        flush_workqueue(host->mrq_workqueue);
        destroy_workqueue(host->mrq_workqueue);
+       gb_connection_disable_rx(connection);
        mmc_remove_host(mmc);
+       gb_connection_disable(connection);
+       gb_connection_destroy(connection);
        kfree(host->xfer_buffer);
        mmc_free_host(mmc);
 }
 
-static struct gb_protocol sdio_protocol = {
-       .name                   = "sdio",
-       .id                     = GREYBUS_PROTOCOL_SDIO,
-       .major                  = GB_SDIO_VERSION_MAJOR,
-       .minor                  = GB_SDIO_VERSION_MINOR,
-       .connection_init        = gb_sdio_connection_init,
-       .connection_exit        = gb_sdio_connection_exit,
-       .request_recv           = gb_sdio_event_recv,
+static const struct gbphy_device_id gb_sdio_id_table[] = {
+       { GBPHY_PROTOCOL(GREYBUS_PROTOCOL_SDIO) },
+       { },
+};
+MODULE_DEVICE_TABLE(gbphy, gb_sdio_id_table);
+
+static struct gbphy_driver sdio_driver = {
+       .name           = "sdio",
+       .probe          = gb_sdio_probe,
+       .remove         = gb_sdio_remove,
+       .id_table       = gb_sdio_id_table,
 };
 
-gb_builtin_protocol_driver(sdio_protocol);
+module_gbphy_driver(sdio_driver);
+MODULE_LICENSE("GPL v2");