2017-11-07 13:58:41 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-08-11 09:27:22 +00:00
|
|
|
/*
|
|
|
|
* SD/MMC Greybus driver.
|
|
|
|
*
|
2015-06-22 13:03:52 +00:00
|
|
|
* Copyright 2014-2015 Google Inc.
|
|
|
|
* Copyright 2014-2015 Linaro Ltd.
|
2014-08-11 09:27:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2015-06-22 13:03:52 +00:00
|
|
|
#include <linux/mmc/core.h>
|
2014-08-11 09:27:22 +00:00
|
|
|
#include <linux/mmc/host.h>
|
2015-06-22 13:03:52 +00:00
|
|
|
#include <linux/mmc/mmc.h>
|
|
|
|
#include <linux/scatterlist.h>
|
|
|
|
#include <linux/workqueue.h>
|
2019-08-25 05:54:27 +00:00
|
|
|
#include <linux/greybus.h>
|
2014-10-02 02:54:11 +00:00
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
#include "gbphy.h"
|
2014-08-11 09:27:22 +00:00
|
|
|
|
2014-08-30 23:20:22 +00:00
|
|
|
struct gb_sdio_host {
|
2015-06-22 13:03:52 +00:00
|
|
|
struct gb_connection *connection;
|
2016-05-19 15:52:39 +00:00
|
|
|
struct gbphy_device *gbphy_dev;
|
2015-06-22 13:03:52 +00:00
|
|
|
struct mmc_host *mmc;
|
|
|
|
struct mmc_request *mrq;
|
|
|
|
struct mutex lock; /* lock for this host */
|
|
|
|
size_t data_max;
|
|
|
|
spinlock_t xfer; /* lock to cancel ongoing transfer */
|
|
|
|
bool xfer_stop;
|
2015-09-14 18:19:04 +00:00
|
|
|
struct workqueue_struct *mrq_workqueue;
|
2015-06-22 13:03:52 +00:00
|
|
|
struct work_struct mrqwork;
|
2015-07-02 18:11:31 +00:00
|
|
|
u8 queued_events;
|
2015-06-22 13:03:52 +00:00
|
|
|
bool removed;
|
|
|
|
bool card_present;
|
|
|
|
bool read_only;
|
2014-08-11 09:27:22 +00:00
|
|
|
};
|
|
|
|
|
2015-07-02 18:11:30 +00:00
|
|
|
#define GB_SDIO_RSP_R1_R5_R6_R7 (GB_SDIO_RSP_PRESENT | GB_SDIO_RSP_CRC | \
|
|
|
|
GB_SDIO_RSP_OPCODE)
|
|
|
|
#define GB_SDIO_RSP_R3_R4 (GB_SDIO_RSP_PRESENT)
|
|
|
|
#define GB_SDIO_RSP_R2 (GB_SDIO_RSP_PRESENT | GB_SDIO_RSP_CRC | \
|
|
|
|
GB_SDIO_RSP_136)
|
|
|
|
#define GB_SDIO_RSP_R1B (GB_SDIO_RSP_PRESENT | GB_SDIO_RSP_CRC | \
|
|
|
|
GB_SDIO_RSP_OPCODE | GB_SDIO_RSP_BUSY)
|
|
|
|
|
2016-07-19 14:41:29 +00:00
|
|
|
/* kernel vdd starts at 0x80 and we need to translate to greybus ones 0x01 */
|
|
|
|
#define GB_SDIO_VDD_SHIFT 8
|
|
|
|
|
2016-09-08 16:17:49 +00:00
|
|
|
#ifndef MMC_CAP2_CORE_RUNTIME_PM
|
|
|
|
#define MMC_CAP2_CORE_RUNTIME_PM 0
|
|
|
|
#endif
|
|
|
|
|
2015-07-02 18:11:35 +00:00
|
|
|
static inline bool single_op(struct mmc_command *cmd)
|
|
|
|
{
|
2017-01-25 17:38:01 +00:00
|
|
|
u32 opcode = cmd->opcode;
|
2015-07-02 18:11:35 +00:00
|
|
|
|
|
|
|
return opcode == MMC_WRITE_BLOCK ||
|
|
|
|
opcode == MMC_READ_SINGLE_BLOCK;
|
|
|
|
}
|
|
|
|
|
2015-06-22 13:03:52 +00:00
|
|
|
static void _gb_sdio_set_host_caps(struct gb_sdio_host *host, u32 r)
|
2014-08-11 09:27:22 +00:00
|
|
|
{
|
2015-06-22 13:03:52 +00:00
|
|
|
u32 caps = 0;
|
|
|
|
u32 caps2 = 0;
|
|
|
|
|
2015-10-08 11:10:54 +00:00
|
|
|
caps = ((r & GB_SDIO_CAP_NONREMOVABLE) ? MMC_CAP_NONREMOVABLE : 0) |
|
|
|
|
((r & GB_SDIO_CAP_4_BIT_DATA) ? MMC_CAP_4_BIT_DATA : 0) |
|
|
|
|
((r & GB_SDIO_CAP_8_BIT_DATA) ? MMC_CAP_8_BIT_DATA : 0) |
|
|
|
|
((r & GB_SDIO_CAP_MMC_HS) ? MMC_CAP_MMC_HIGHSPEED : 0) |
|
|
|
|
((r & GB_SDIO_CAP_SD_HS) ? MMC_CAP_SD_HIGHSPEED : 0) |
|
|
|
|
((r & GB_SDIO_CAP_1_2V_DDR) ? MMC_CAP_1_2V_DDR : 0) |
|
|
|
|
((r & GB_SDIO_CAP_1_8V_DDR) ? MMC_CAP_1_8V_DDR : 0) |
|
|
|
|
((r & GB_SDIO_CAP_POWER_OFF_CARD) ? MMC_CAP_POWER_OFF_CARD : 0) |
|
|
|
|
((r & GB_SDIO_CAP_UHS_SDR12) ? MMC_CAP_UHS_SDR12 : 0) |
|
|
|
|
((r & GB_SDIO_CAP_UHS_SDR25) ? MMC_CAP_UHS_SDR25 : 0) |
|
|
|
|
((r & GB_SDIO_CAP_UHS_SDR50) ? MMC_CAP_UHS_SDR50 : 0) |
|
|
|
|
((r & GB_SDIO_CAP_UHS_SDR104) ? MMC_CAP_UHS_SDR104 : 0) |
|
|
|
|
((r & GB_SDIO_CAP_UHS_DDR50) ? MMC_CAP_UHS_DDR50 : 0) |
|
|
|
|
((r & GB_SDIO_CAP_DRIVER_TYPE_A) ? MMC_CAP_DRIVER_TYPE_A : 0) |
|
|
|
|
((r & GB_SDIO_CAP_DRIVER_TYPE_C) ? MMC_CAP_DRIVER_TYPE_C : 0) |
|
|
|
|
((r & GB_SDIO_CAP_DRIVER_TYPE_D) ? MMC_CAP_DRIVER_TYPE_D : 0);
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2015-10-08 11:10:54 +00:00
|
|
|
caps2 = ((r & GB_SDIO_CAP_HS200_1_2V) ? MMC_CAP2_HS200_1_2V_SDR : 0) |
|
|
|
|
((r & GB_SDIO_CAP_HS400_1_2V) ? MMC_CAP2_HS400_1_2V : 0) |
|
|
|
|
((r & GB_SDIO_CAP_HS400_1_8V) ? MMC_CAP2_HS400_1_8V : 0) |
|
|
|
|
((r & GB_SDIO_CAP_HS200_1_8V) ? MMC_CAP2_HS200_1_8V_SDR : 0);
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2016-08-05 02:22:02 +00:00
|
|
|
host->mmc->caps = caps;
|
|
|
|
host->mmc->caps2 = caps2 | MMC_CAP2_CORE_RUNTIME_PM;
|
2015-06-22 13:03:52 +00:00
|
|
|
|
|
|
|
if (caps & MMC_CAP_NONREMOVABLE)
|
|
|
|
host->card_present = true;
|
2014-08-11 09:27:22 +00:00
|
|
|
}
|
|
|
|
|
2015-10-08 11:10:53 +00:00
|
|
|
static u32 _gb_sdio_get_host_ocr(u32 ocr)
|
|
|
|
{
|
|
|
|
return (((ocr & GB_SDIO_VDD_165_195) ? MMC_VDD_165_195 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_20_21) ? MMC_VDD_20_21 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_21_22) ? MMC_VDD_21_22 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_22_23) ? MMC_VDD_22_23 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_23_24) ? MMC_VDD_23_24 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_24_25) ? MMC_VDD_24_25 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_25_26) ? MMC_VDD_25_26 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_26_27) ? MMC_VDD_26_27 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_27_28) ? MMC_VDD_27_28 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_28_29) ? MMC_VDD_28_29 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_29_30) ? MMC_VDD_29_30 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_30_31) ? MMC_VDD_30_31 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_31_32) ? MMC_VDD_31_32 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_32_33) ? MMC_VDD_32_33 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_33_34) ? MMC_VDD_33_34 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_34_35) ? MMC_VDD_34_35 : 0) |
|
|
|
|
((ocr & GB_SDIO_VDD_35_36) ? MMC_VDD_35_36 : 0)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-06-22 13:03:52 +00:00
|
|
|
static int gb_sdio_get_caps(struct gb_sdio_host *host)
|
2014-08-11 09:27:22 +00:00
|
|
|
{
|
2015-06-22 13:03:52 +00:00
|
|
|
struct gb_sdio_get_caps_response response;
|
|
|
|
struct mmc_host *mmc = host->mmc;
|
|
|
|
u16 data_max;
|
|
|
|
u32 blksz;
|
2015-10-08 11:10:53 +00:00
|
|
|
u32 ocr;
|
2015-06-22 13:03:52 +00:00
|
|
|
u32 r;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = gb_operation_sync(host->connection, GB_SDIO_TYPE_GET_CAPABILITIES,
|
|
|
|
NULL, 0, &response, sizeof(response));
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
r = le32_to_cpu(response.caps);
|
|
|
|
|
|
|
|
_gb_sdio_set_host_caps(host, r);
|
|
|
|
|
|
|
|
/* get the max block size that could fit our payload */
|
|
|
|
data_max = gb_operation_get_payload_size_max(host->connection);
|
|
|
|
data_max = min(data_max - sizeof(struct gb_sdio_transfer_request),
|
|
|
|
data_max - sizeof(struct gb_sdio_transfer_response));
|
|
|
|
|
2016-09-08 14:10:50 +00:00
|
|
|
blksz = min_t(u16, le16_to_cpu(response.max_blk_size), data_max);
|
2015-06-22 13:03:52 +00:00
|
|
|
blksz = max_t(u32, 512, blksz);
|
|
|
|
|
|
|
|
mmc->max_blk_size = rounddown_pow_of_two(blksz);
|
|
|
|
mmc->max_blk_count = le16_to_cpu(response.max_blk_count);
|
|
|
|
host->data_max = data_max;
|
|
|
|
|
|
|
|
/* get ocr supported values */
|
2015-10-08 11:10:53 +00:00
|
|
|
ocr = _gb_sdio_get_host_ocr(le32_to_cpu(response.ocr));
|
|
|
|
mmc->ocr_avail = ocr;
|
2015-06-22 13:03:52 +00:00
|
|
|
mmc->ocr_avail_sdio = mmc->ocr_avail;
|
|
|
|
mmc->ocr_avail_sd = mmc->ocr_avail;
|
|
|
|
mmc->ocr_avail_mmc = mmc->ocr_avail;
|
|
|
|
|
2015-10-08 11:10:51 +00:00
|
|
|
/* get frequency range values */
|
|
|
|
mmc->f_min = le32_to_cpu(response.f_min);
|
|
|
|
mmc->f_max = le32_to_cpu(response.f_max);
|
|
|
|
|
2015-06-22 13:03:52 +00:00
|
|
|
return 0;
|
2014-08-11 09:27:22 +00:00
|
|
|
}
|
|
|
|
|
2015-07-02 18:11:31 +00:00
|
|
|
static void _gb_queue_event(struct gb_sdio_host *host, u8 event)
|
2014-08-11 09:27:22 +00:00
|
|
|
{
|
2015-07-02 18:11:31 +00:00
|
|
|
if (event & GB_SDIO_CARD_INSERTED)
|
|
|
|
host->queued_events &= ~GB_SDIO_CARD_REMOVED;
|
|
|
|
else if (event & GB_SDIO_CARD_REMOVED)
|
|
|
|
host->queued_events &= ~GB_SDIO_CARD_INSERTED;
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2015-07-02 18:11:31 +00:00
|
|
|
host->queued_events |= event;
|
|
|
|
}
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2015-07-02 18:11:31 +00:00
|
|
|
static int _gb_sdio_process_events(struct gb_sdio_host *host, u8 event)
|
|
|
|
{
|
|
|
|
u8 state_changed = 0;
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2015-07-02 18:11:31 +00:00
|
|
|
if (event & GB_SDIO_CARD_INSERTED) {
|
2015-10-08 11:10:52 +00:00
|
|
|
if (host->mmc->caps & MMC_CAP_NONREMOVABLE)
|
2015-06-22 13:03:52 +00:00
|
|
|
return 0;
|
|
|
|
if (host->card_present)
|
|
|
|
return 0;
|
|
|
|
host->card_present = true;
|
|
|
|
state_changed = 1;
|
2015-07-02 18:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (event & GB_SDIO_CARD_REMOVED) {
|
2015-10-08 11:10:52 +00:00
|
|
|
if (host->mmc->caps & MMC_CAP_NONREMOVABLE)
|
2015-06-22 13:03:52 +00:00
|
|
|
return 0;
|
|
|
|
if (!(host->card_present))
|
|
|
|
return 0;
|
|
|
|
host->card_present = false;
|
|
|
|
state_changed = 1;
|
2015-07-02 18:11:31 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 15:15:25 +00:00
|
|
|
if (event & GB_SDIO_WP)
|
2015-06-22 13:03:52 +00:00
|
|
|
host->read_only = true;
|
|
|
|
|
|
|
|
if (state_changed) {
|
|
|
|
dev_info(mmc_dev(host->mmc), "card %s now event\n",
|
|
|
|
(host->card_present ? "inserted" : "removed"));
|
|
|
|
mmc_detect_change(host->mmc, 0);
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:27:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-05 09:02:34 +00:00
|
|
|
static int gb_sdio_request_handler(struct gb_operation *op)
|
2015-07-02 18:11:31 +00:00
|
|
|
{
|
2016-03-22 18:30:35 +00:00
|
|
|
struct gb_sdio_host *host = gb_connection_get_data(op->connection);
|
2015-07-02 18:11:31 +00:00
|
|
|
struct gb_message *request;
|
|
|
|
struct gb_sdio_event_request *payload;
|
2016-05-05 09:02:34 +00:00
|
|
|
u8 type = op->type;
|
2015-07-02 18:11:31 +00:00
|
|
|
int ret = 0;
|
|
|
|
u8 event;
|
|
|
|
|
|
|
|
if (type != GB_SDIO_TYPE_EVENT) {
|
2016-03-22 18:30:35 +00:00
|
|
|
dev_err(mmc_dev(host->mmc),
|
2015-07-02 18:11:31 +00:00
|
|
|
"unsupported unsolicited event: %u\n", type);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
request = op->request;
|
|
|
|
|
2015-08-08 02:39:32 +00:00
|
|
|
if (request->payload_size < sizeof(*payload)) {
|
|
|
|
dev_err(mmc_dev(host->mmc), "wrong event size received (%zu < %zu)\n",
|
|
|
|
request->payload_size, sizeof(*payload));
|
2015-07-02 18:11:31 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
payload = request->payload;
|
|
|
|
event = payload->event;
|
|
|
|
|
|
|
|
if (host->removed)
|
|
|
|
_gb_queue_event(host, event);
|
|
|
|
else
|
|
|
|
ret = _gb_sdio_process_events(host, event);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-06-22 13:03:52 +00:00
|
|
|
static int gb_sdio_set_ios(struct gb_sdio_host *host,
|
|
|
|
struct gb_sdio_set_ios_request *request)
|
|
|
|
{
|
2016-08-05 02:22:02 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = gbphy_runtime_get_sync(host->gbphy_dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = gb_operation_sync(host->connection, GB_SDIO_TYPE_SET_IOS, request,
|
|
|
|
sizeof(*request), NULL, 0);
|
|
|
|
|
|
|
|
gbphy_runtime_put_autosuspend(host->gbphy_dev);
|
|
|
|
|
|
|
|
return ret;
|
2015-06-22 13:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int _gb_sdio_send(struct gb_sdio_host *host, struct mmc_data *data,
|
|
|
|
size_t len, u16 nblocks, off_t skip)
|
|
|
|
{
|
|
|
|
struct gb_sdio_transfer_request *request;
|
2016-06-21 15:56:16 +00:00
|
|
|
struct gb_sdio_transfer_response *response;
|
|
|
|
struct gb_operation *operation;
|
2015-06-22 13:03:52 +00:00
|
|
|
struct scatterlist *sg = data->sg;
|
|
|
|
unsigned int sg_len = data->sg_len;
|
|
|
|
size_t copied;
|
|
|
|
u16 send_blksz;
|
|
|
|
u16 send_blocks;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
WARN_ON(len > host->data_max);
|
|
|
|
|
2016-06-21 15:56:16 +00:00
|
|
|
operation = gb_operation_create(host->connection, GB_SDIO_TYPE_TRANSFER,
|
|
|
|
len + sizeof(*request),
|
|
|
|
sizeof(*response), GFP_KERNEL);
|
|
|
|
if (!operation)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
request = operation->request->payload;
|
2019-03-21 16:31:08 +00:00
|
|
|
request->data_flags = data->flags >> 8;
|
2015-06-22 13:03:52 +00:00
|
|
|
request->data_blocks = cpu_to_le16(nblocks);
|
|
|
|
request->data_blksz = cpu_to_le16(data->blksz);
|
|
|
|
|
2015-07-02 18:11:37 +00:00
|
|
|
copied = sg_pcopy_to_buffer(sg, sg_len, &request->data[0], len, skip);
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2016-06-21 15:56:16 +00:00
|
|
|
if (copied != len) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_put_operation;
|
|
|
|
}
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2016-06-21 15:56:16 +00:00
|
|
|
ret = gb_operation_request_send_sync(operation);
|
2015-06-22 13:03:52 +00:00
|
|
|
if (ret < 0)
|
2016-06-21 15:56:16 +00:00
|
|
|
goto err_put_operation;
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2016-06-21 15:56:16 +00:00
|
|
|
response = operation->response->payload;
|
|
|
|
|
|
|
|
send_blocks = le16_to_cpu(response->data_blocks);
|
|
|
|
send_blksz = le16_to_cpu(response->data_blksz);
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2015-07-02 18:11:37 +00:00
|
|
|
if (len != send_blksz * send_blocks) {
|
|
|
|
dev_err(mmc_dev(host->mmc), "send: size received: %zu != %d\n",
|
|
|
|
len, send_blksz * send_blocks);
|
2016-06-21 15:56:16 +00:00
|
|
|
ret = -EINVAL;
|
2015-07-02 18:11:37 +00:00
|
|
|
}
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2016-06-21 15:56:16 +00:00
|
|
|
err_put_operation:
|
|
|
|
gb_operation_put(operation);
|
|
|
|
|
2015-06-22 13:03:52 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _gb_sdio_recv(struct gb_sdio_host *host, struct mmc_data *data,
|
|
|
|
size_t len, u16 nblocks, off_t skip)
|
|
|
|
{
|
2016-06-21 15:56:16 +00:00
|
|
|
struct gb_sdio_transfer_request *request;
|
2015-06-22 13:03:52 +00:00
|
|
|
struct gb_sdio_transfer_response *response;
|
2016-06-21 15:56:16 +00:00
|
|
|
struct gb_operation *operation;
|
2015-06-22 13:03:52 +00:00
|
|
|
struct scatterlist *sg = data->sg;
|
|
|
|
unsigned int sg_len = data->sg_len;
|
|
|
|
size_t copied;
|
|
|
|
u16 recv_blksz;
|
|
|
|
u16 recv_blocks;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
WARN_ON(len > host->data_max);
|
|
|
|
|
2016-06-21 15:56:16 +00:00
|
|
|
operation = gb_operation_create(host->connection, GB_SDIO_TYPE_TRANSFER,
|
|
|
|
sizeof(*request),
|
|
|
|
len + sizeof(*response), GFP_KERNEL);
|
|
|
|
if (!operation)
|
|
|
|
return -ENOMEM;
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2016-06-21 15:56:16 +00:00
|
|
|
request = operation->request->payload;
|
2019-03-21 16:31:08 +00:00
|
|
|
request->data_flags = data->flags >> 8;
|
2016-06-21 15:56:16 +00:00
|
|
|
request->data_blocks = cpu_to_le16(nblocks);
|
|
|
|
request->data_blksz = cpu_to_le16(data->blksz);
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2016-06-21 15:56:16 +00:00
|
|
|
ret = gb_operation_request_send_sync(operation);
|
2015-06-22 13:03:52 +00:00
|
|
|
if (ret < 0)
|
2016-06-21 15:56:16 +00:00
|
|
|
goto err_put_operation;
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2016-06-21 15:56:16 +00:00
|
|
|
response = operation->response->payload;
|
2015-06-22 13:03:52 +00:00
|
|
|
recv_blocks = le16_to_cpu(response->data_blocks);
|
|
|
|
recv_blksz = le16_to_cpu(response->data_blksz);
|
|
|
|
|
2015-07-02 18:11:37 +00:00
|
|
|
if (len != recv_blksz * recv_blocks) {
|
|
|
|
dev_err(mmc_dev(host->mmc), "recv: size received: %d != %zu\n",
|
|
|
|
recv_blksz * recv_blocks, len);
|
2016-06-21 15:56:16 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_put_operation;
|
2015-07-02 18:11:37 +00:00
|
|
|
}
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2015-07-02 18:11:37 +00:00
|
|
|
copied = sg_pcopy_from_buffer(sg, sg_len, &response->data[0], len,
|
|
|
|
skip);
|
2015-06-22 13:03:52 +00:00
|
|
|
if (copied != len)
|
2016-06-21 15:56:16 +00:00
|
|
|
ret = -EINVAL;
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2016-06-21 15:56:16 +00:00
|
|
|
err_put_operation:
|
|
|
|
gb_operation_put(operation);
|
|
|
|
|
|
|
|
return ret;
|
2015-06-22 13:03:52 +00:00
|
|
|
}
|
|
|
|
|
2015-07-02 18:11:34 +00:00
|
|
|
static int gb_sdio_transfer(struct gb_sdio_host *host, struct mmc_data *data)
|
2015-06-22 13:03:52 +00:00
|
|
|
{
|
|
|
|
size_t left, len;
|
|
|
|
off_t skip = 0;
|
|
|
|
int ret = 0;
|
|
|
|
u16 nblocks;
|
|
|
|
|
2015-07-02 18:11:35 +00:00
|
|
|
if (single_op(data->mrq->cmd) && data->blocks > 1) {
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-06-22 13:03:52 +00:00
|
|
|
left = data->blksz * data->blocks;
|
|
|
|
|
|
|
|
while (left) {
|
|
|
|
/* check is a stop transmission is pending */
|
|
|
|
spin_lock(&host->xfer);
|
|
|
|
if (host->xfer_stop) {
|
|
|
|
host->xfer_stop = false;
|
|
|
|
spin_unlock(&host->xfer);
|
|
|
|
ret = -EINTR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
spin_unlock(&host->xfer);
|
|
|
|
len = min(left, host->data_max);
|
2015-07-02 18:11:37 +00:00
|
|
|
nblocks = len / data->blksz;
|
2015-06-22 13:03:52 +00:00
|
|
|
len = nblocks * data->blksz;
|
|
|
|
|
|
|
|
if (data->flags & MMC_DATA_READ) {
|
|
|
|
ret = _gb_sdio_recv(host, data, len, nblocks, skip);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
ret = _gb_sdio_send(host, data, len, nblocks, skip);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
data->bytes_xfered += len;
|
|
|
|
left -= len;
|
|
|
|
skip += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
data->error = ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gb_sdio_command(struct gb_sdio_host *host, struct mmc_command *cmd)
|
|
|
|
{
|
2015-10-15 22:56:51 +00:00
|
|
|
struct gb_sdio_command_request request = {0};
|
2015-06-22 13:03:52 +00:00
|
|
|
struct gb_sdio_command_response response;
|
2015-10-15 22:56:51 +00:00
|
|
|
struct mmc_data *data = host->mrq->data;
|
2020-04-14 16:14:13 +00:00
|
|
|
unsigned int timeout_ms;
|
2015-06-22 13:03:52 +00:00
|
|
|
u8 cmd_flags;
|
|
|
|
u8 cmd_type;
|
|
|
|
int i;
|
2015-10-15 22:56:52 +00:00
|
|
|
int ret;
|
2015-06-22 13:03:52 +00:00
|
|
|
|
|
|
|
switch (mmc_resp_type(cmd)) {
|
|
|
|
case MMC_RSP_NONE:
|
|
|
|
cmd_flags = GB_SDIO_RSP_NONE;
|
|
|
|
break;
|
|
|
|
case MMC_RSP_R1:
|
|
|
|
cmd_flags = GB_SDIO_RSP_R1_R5_R6_R7;
|
|
|
|
break;
|
|
|
|
case MMC_RSP_R1B:
|
|
|
|
cmd_flags = GB_SDIO_RSP_R1B;
|
|
|
|
break;
|
|
|
|
case MMC_RSP_R2:
|
|
|
|
cmd_flags = GB_SDIO_RSP_R2;
|
|
|
|
break;
|
|
|
|
case MMC_RSP_R3:
|
|
|
|
cmd_flags = GB_SDIO_RSP_R3_R4;
|
2015-07-02 18:11:35 +00:00
|
|
|
break;
|
2015-06-22 13:03:52 +00:00
|
|
|
default:
|
2015-12-04 16:00:10 +00:00
|
|
|
dev_err(mmc_dev(host->mmc), "cmd flag invalid 0x%04x\n",
|
2015-06-22 13:03:52 +00:00
|
|
|
mmc_resp_type(cmd));
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mmc_cmd_type(cmd)) {
|
|
|
|
case MMC_CMD_BC:
|
|
|
|
cmd_type = GB_SDIO_CMD_BC;
|
|
|
|
break;
|
|
|
|
case MMC_CMD_BCR:
|
|
|
|
cmd_type = GB_SDIO_CMD_BCR;
|
|
|
|
break;
|
|
|
|
case MMC_CMD_AC:
|
|
|
|
cmd_type = GB_SDIO_CMD_AC;
|
|
|
|
break;
|
|
|
|
case MMC_CMD_ADTC:
|
|
|
|
cmd_type = GB_SDIO_CMD_ADTC;
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-04 16:00:10 +00:00
|
|
|
dev_err(mmc_dev(host->mmc), "cmd type invalid 0x%04x\n",
|
2015-06-22 13:03:52 +00:00
|
|
|
mmc_cmd_type(cmd));
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
request.cmd = cmd->opcode;
|
|
|
|
request.cmd_flags = cmd_flags;
|
|
|
|
request.cmd_type = cmd_type;
|
|
|
|
request.cmd_arg = cpu_to_le32(cmd->arg);
|
2015-10-15 22:56:51 +00:00
|
|
|
/* some controllers need to know at command time data details */
|
|
|
|
if (data) {
|
|
|
|
request.data_blocks = cpu_to_le16(data->blocks);
|
|
|
|
request.data_blksz = cpu_to_le16(data->blksz);
|
|
|
|
}
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2020-04-14 16:14:13 +00:00
|
|
|
timeout_ms = cmd->busy_timeout ? cmd->busy_timeout :
|
|
|
|
GB_OPERATION_TIMEOUT_DEFAULT;
|
|
|
|
|
|
|
|
ret = gb_operation_sync_timeout(host->connection, GB_SDIO_TYPE_COMMAND,
|
|
|
|
&request, sizeof(request), &response,
|
|
|
|
sizeof(response), timeout_ms);
|
2015-06-22 13:03:52 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* no response expected */
|
2016-09-30 18:24:31 +00:00
|
|
|
if (cmd_flags == GB_SDIO_RSP_NONE)
|
2015-06-22 13:03:52 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* long response expected */
|
|
|
|
if (cmd_flags & GB_SDIO_RSP_R2)
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
cmd->resp[i] = le32_to_cpu(response.resp[i]);
|
|
|
|
else
|
|
|
|
cmd->resp[0] = le32_to_cpu(response.resp[0]);
|
|
|
|
|
|
|
|
out:
|
|
|
|
cmd->error = ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gb_sdio_mrq_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct gb_sdio_host *host;
|
|
|
|
struct mmc_request *mrq;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
host = container_of(work, struct gb_sdio_host, mrqwork);
|
|
|
|
|
2016-08-05 02:22:02 +00:00
|
|
|
ret = gbphy_runtime_get_sync(host->gbphy_dev);
|
|
|
|
if (ret)
|
|
|
|
return;
|
|
|
|
|
2015-06-22 13:03:52 +00:00
|
|
|
mutex_lock(&host->lock);
|
2015-06-26 14:05:13 +00:00
|
|
|
mrq = host->mrq;
|
|
|
|
if (!mrq) {
|
|
|
|
mutex_unlock(&host->lock);
|
2016-08-05 02:22:02 +00:00
|
|
|
gbphy_runtime_put_autosuspend(host->gbphy_dev);
|
2015-06-26 14:05:13 +00:00
|
|
|
dev_err(mmc_dev(host->mmc), "mmc request is NULL");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-22 13:03:52 +00:00
|
|
|
if (host->removed) {
|
|
|
|
mrq->cmd->error = -ESHUTDOWN;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mrq->sbc) {
|
|
|
|
ret = gb_sdio_command(host, mrq->sbc);
|
|
|
|
if (ret < 0)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gb_sdio_command(host, mrq->cmd);
|
|
|
|
if (ret < 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (mrq->data) {
|
2015-10-15 22:56:52 +00:00
|
|
|
ret = gb_sdio_transfer(host, mrq->data);
|
2015-06-22 13:03:52 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2015-07-02 18:11:33 +00:00
|
|
|
if (mrq->stop) {
|
|
|
|
ret = gb_sdio_command(host, mrq->stop);
|
2015-06-22 13:03:52 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2015-06-26 14:05:13 +00:00
|
|
|
host->mrq = NULL;
|
2015-06-22 13:03:52 +00:00
|
|
|
mutex_unlock(&host->lock);
|
|
|
|
mmc_request_done(host->mmc, mrq);
|
2016-08-05 02:22:02 +00:00
|
|
|
gbphy_runtime_put_autosuspend(host->gbphy_dev);
|
2015-06-22 13:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gb_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
|
|
|
|
{
|
|
|
|
struct gb_sdio_host *host = mmc_priv(mmc);
|
|
|
|
struct mmc_command *cmd = mrq->cmd;
|
|
|
|
|
|
|
|
/* Check if it is a cancel to ongoing transfer */
|
|
|
|
if (cmd->opcode == MMC_STOP_TRANSMISSION) {
|
|
|
|
spin_lock(&host->xfer);
|
|
|
|
host->xfer_stop = true;
|
|
|
|
spin_unlock(&host->xfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_lock(&host->lock);
|
|
|
|
|
|
|
|
WARN_ON(host->mrq);
|
|
|
|
host->mrq = mrq;
|
|
|
|
|
|
|
|
if (host->removed) {
|
|
|
|
mrq->cmd->error = -ESHUTDOWN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (!host->card_present) {
|
|
|
|
mrq->cmd->error = -ENOMEDIUM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-09-14 18:19:04 +00:00
|
|
|
queue_work(host->mrq_workqueue, &host->mrqwork);
|
2015-06-22 13:03:52 +00:00
|
|
|
|
|
|
|
mutex_unlock(&host->lock);
|
|
|
|
return;
|
|
|
|
|
|
|
|
out:
|
|
|
|
host->mrq = NULL;
|
|
|
|
mutex_unlock(&host->lock);
|
|
|
|
mmc_request_done(mmc, mrq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gb_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
|
|
|
|
{
|
|
|
|
struct gb_sdio_host *host = mmc_priv(mmc);
|
|
|
|
struct gb_sdio_set_ios_request request;
|
|
|
|
int ret;
|
|
|
|
u8 power_mode;
|
|
|
|
u8 bus_width;
|
|
|
|
u8 timing;
|
|
|
|
u8 signal_voltage;
|
|
|
|
u8 drv_type;
|
2016-07-19 14:41:29 +00:00
|
|
|
u32 vdd = 0;
|
2015-06-22 13:03:52 +00:00
|
|
|
|
|
|
|
mutex_lock(&host->lock);
|
|
|
|
request.clock = cpu_to_le32(ios->clock);
|
2016-07-19 14:41:29 +00:00
|
|
|
|
|
|
|
if (ios->vdd)
|
|
|
|
vdd = 1 << (ios->vdd - GB_SDIO_VDD_SHIFT);
|
|
|
|
request.vdd = cpu_to_le32(vdd);
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2019-03-21 16:31:08 +00:00
|
|
|
request.bus_mode = ios->bus_mode == MMC_BUSMODE_OPENDRAIN ?
|
2015-06-22 13:03:52 +00:00
|
|
|
GB_SDIO_BUSMODE_OPENDRAIN :
|
2019-03-21 16:31:08 +00:00
|
|
|
GB_SDIO_BUSMODE_PUSHPULL;
|
2015-06-22 13:03:52 +00:00
|
|
|
|
|
|
|
switch (ios->power_mode) {
|
|
|
|
case MMC_POWER_OFF:
|
2015-06-24 22:20:26 +00:00
|
|
|
default:
|
2015-06-22 13:03:52 +00:00
|
|
|
power_mode = GB_SDIO_POWER_OFF;
|
|
|
|
break;
|
|
|
|
case MMC_POWER_UP:
|
|
|
|
power_mode = GB_SDIO_POWER_UP;
|
|
|
|
break;
|
|
|
|
case MMC_POWER_ON:
|
|
|
|
power_mode = GB_SDIO_POWER_ON;
|
|
|
|
break;
|
|
|
|
case MMC_POWER_UNDEFINED:
|
|
|
|
power_mode = GB_SDIO_POWER_UNDEFINED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
request.power_mode = power_mode;
|
|
|
|
|
|
|
|
switch (ios->bus_width) {
|
|
|
|
case MMC_BUS_WIDTH_1:
|
|
|
|
bus_width = GB_SDIO_BUS_WIDTH_1;
|
|
|
|
break;
|
|
|
|
case MMC_BUS_WIDTH_4:
|
|
|
|
default:
|
|
|
|
bus_width = GB_SDIO_BUS_WIDTH_4;
|
|
|
|
break;
|
|
|
|
case MMC_BUS_WIDTH_8:
|
|
|
|
bus_width = GB_SDIO_BUS_WIDTH_8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
request.bus_width = bus_width;
|
|
|
|
|
|
|
|
switch (ios->timing) {
|
|
|
|
case MMC_TIMING_LEGACY:
|
|
|
|
default:
|
|
|
|
timing = GB_SDIO_TIMING_LEGACY;
|
|
|
|
break;
|
|
|
|
case MMC_TIMING_MMC_HS:
|
|
|
|
timing = GB_SDIO_TIMING_MMC_HS;
|
|
|
|
break;
|
|
|
|
case MMC_TIMING_SD_HS:
|
|
|
|
timing = GB_SDIO_TIMING_SD_HS;
|
|
|
|
break;
|
|
|
|
case MMC_TIMING_UHS_SDR12:
|
|
|
|
timing = GB_SDIO_TIMING_UHS_SDR12;
|
|
|
|
break;
|
|
|
|
case MMC_TIMING_UHS_SDR25:
|
|
|
|
timing = GB_SDIO_TIMING_UHS_SDR25;
|
|
|
|
break;
|
|
|
|
case MMC_TIMING_UHS_SDR50:
|
|
|
|
timing = GB_SDIO_TIMING_UHS_SDR50;
|
|
|
|
break;
|
|
|
|
case MMC_TIMING_UHS_SDR104:
|
|
|
|
timing = GB_SDIO_TIMING_UHS_SDR104;
|
|
|
|
break;
|
|
|
|
case MMC_TIMING_UHS_DDR50:
|
|
|
|
timing = GB_SDIO_TIMING_UHS_DDR50;
|
|
|
|
break;
|
|
|
|
case MMC_TIMING_MMC_DDR52:
|
|
|
|
timing = GB_SDIO_TIMING_MMC_DDR52;
|
|
|
|
break;
|
|
|
|
case MMC_TIMING_MMC_HS200:
|
|
|
|
timing = GB_SDIO_TIMING_MMC_HS200;
|
|
|
|
break;
|
|
|
|
case MMC_TIMING_MMC_HS400:
|
|
|
|
timing = GB_SDIO_TIMING_MMC_HS400;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
request.timing = timing;
|
|
|
|
|
|
|
|
switch (ios->signal_voltage) {
|
|
|
|
case MMC_SIGNAL_VOLTAGE_330:
|
|
|
|
signal_voltage = GB_SDIO_SIGNAL_VOLTAGE_330;
|
|
|
|
break;
|
|
|
|
case MMC_SIGNAL_VOLTAGE_180:
|
|
|
|
default:
|
|
|
|
signal_voltage = GB_SDIO_SIGNAL_VOLTAGE_180;
|
|
|
|
break;
|
|
|
|
case MMC_SIGNAL_VOLTAGE_120:
|
|
|
|
signal_voltage = GB_SDIO_SIGNAL_VOLTAGE_120;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
request.signal_voltage = signal_voltage;
|
|
|
|
|
|
|
|
switch (ios->drv_type) {
|
|
|
|
case MMC_SET_DRIVER_TYPE_A:
|
|
|
|
drv_type = GB_SDIO_SET_DRIVER_TYPE_A;
|
|
|
|
break;
|
|
|
|
case MMC_SET_DRIVER_TYPE_C:
|
|
|
|
drv_type = GB_SDIO_SET_DRIVER_TYPE_C;
|
|
|
|
break;
|
|
|
|
case MMC_SET_DRIVER_TYPE_D:
|
|
|
|
drv_type = GB_SDIO_SET_DRIVER_TYPE_D;
|
|
|
|
break;
|
|
|
|
case MMC_SET_DRIVER_TYPE_B:
|
|
|
|
default:
|
|
|
|
drv_type = GB_SDIO_SET_DRIVER_TYPE_B;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
request.drv_type = drv_type;
|
|
|
|
|
|
|
|
ret = gb_sdio_set_ios(host, &request);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
memcpy(&mmc->ios, ios, sizeof(mmc->ios));
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&host->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gb_mmc_get_ro(struct mmc_host *mmc)
|
|
|
|
{
|
|
|
|
struct gb_sdio_host *host = mmc_priv(mmc);
|
|
|
|
|
|
|
|
mutex_lock(&host->lock);
|
2016-05-24 18:34:48 +00:00
|
|
|
if (host->removed) {
|
|
|
|
mutex_unlock(&host->lock);
|
2015-06-22 13:03:52 +00:00
|
|
|
return -ESHUTDOWN;
|
2016-05-24 18:34:48 +00:00
|
|
|
}
|
2015-06-22 13:03:52 +00:00
|
|
|
mutex_unlock(&host->lock);
|
2016-05-24 18:34:48 +00:00
|
|
|
|
2015-07-02 18:11:32 +00:00
|
|
|
return host->read_only;
|
2015-06-22 13:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int gb_mmc_get_cd(struct mmc_host *mmc)
|
|
|
|
{
|
|
|
|
struct gb_sdio_host *host = mmc_priv(mmc);
|
|
|
|
|
|
|
|
mutex_lock(&host->lock);
|
2016-05-24 18:34:48 +00:00
|
|
|
if (host->removed) {
|
|
|
|
mutex_unlock(&host->lock);
|
2015-06-22 13:03:52 +00:00
|
|
|
return -ESHUTDOWN;
|
2016-05-24 18:34:48 +00:00
|
|
|
}
|
2015-06-22 13:03:52 +00:00
|
|
|
mutex_unlock(&host->lock);
|
2016-05-24 18:34:48 +00:00
|
|
|
|
2015-07-02 18:11:32 +00:00
|
|
|
return host->card_present;
|
2015-06-22 13:03:52 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 14:41:30 +00:00
|
|
|
static int gb_mmc_switch_voltage(struct mmc_host *mmc, struct mmc_ios *ios)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-22 13:03:52 +00:00
|
|
|
static const struct mmc_host_ops gb_sdio_ops = {
|
|
|
|
.request = gb_mmc_request,
|
|
|
|
.set_ios = gb_mmc_set_ios,
|
|
|
|
.get_ro = gb_mmc_get_ro,
|
|
|
|
.get_cd = gb_mmc_get_cd,
|
2016-07-19 14:41:30 +00:00
|
|
|
.start_signal_voltage_switch = gb_mmc_switch_voltage,
|
2014-08-11 09:27:22 +00:00
|
|
|
};
|
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
static int gb_sdio_probe(struct gbphy_device *gbphy_dev,
|
|
|
|
const struct gbphy_device_id *id)
|
2014-08-11 09:27:22 +00:00
|
|
|
{
|
2016-05-05 09:02:34 +00:00
|
|
|
struct gb_connection *connection;
|
2014-08-11 09:27:22 +00:00
|
|
|
struct mmc_host *mmc;
|
2014-08-30 23:20:22 +00:00
|
|
|
struct gb_sdio_host *host;
|
2015-06-22 13:03:52 +00:00
|
|
|
int ret = 0;
|
2014-08-11 09:27:22 +00:00
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
mmc = mmc_alloc_host(sizeof(*host), &gbphy_dev->dev);
|
2014-08-11 09:27:22 +00:00
|
|
|
if (!mmc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
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-05 09:02:34 +00:00
|
|
|
gb_sdio_request_handler);
|
|
|
|
if (IS_ERR(connection)) {
|
|
|
|
ret = PTR_ERR(connection);
|
|
|
|
goto exit_mmc_free;
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:27:22 +00:00
|
|
|
host = mmc_priv(mmc);
|
|
|
|
host->mmc = mmc;
|
2015-07-02 18:11:31 +00:00
|
|
|
host->removed = true;
|
2014-08-11 09:27:22 +00:00
|
|
|
|
2014-10-28 02:17:09 +00:00
|
|
|
host->connection = connection;
|
2016-03-22 18:30:35 +00:00
|
|
|
gb_connection_set_data(connection, host);
|
2016-05-19 15:52:39 +00:00
|
|
|
host->gbphy_dev = gbphy_dev;
|
|
|
|
gb_gbphy_set_data(gbphy_dev, host);
|
2016-05-05 09:02:34 +00:00
|
|
|
|
|
|
|
ret = gb_connection_enable_tx(connection);
|
|
|
|
if (ret)
|
|
|
|
goto exit_connection_destroy;
|
|
|
|
|
2015-06-22 13:03:52 +00:00
|
|
|
ret = gb_sdio_get_caps(host);
|
|
|
|
if (ret < 0)
|
2016-05-05 09:02:34 +00:00
|
|
|
goto exit_connection_disable;
|
2015-06-22 13:03:52 +00:00
|
|
|
|
|
|
|
mmc->ops = &gb_sdio_ops;
|
|
|
|
|
|
|
|
mmc->max_segs = host->mmc->max_blk_count;
|
|
|
|
|
2016-08-09 22:35:35 +00:00
|
|
|
/* for now we make a map 1:1 between max request and segment size */
|
2015-06-22 13:03:52 +00:00
|
|
|
mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
|
2016-08-09 22:35:35 +00:00
|
|
|
mmc->max_seg_size = mmc->max_req_size;
|
2015-06-22 13:03:52 +00:00
|
|
|
|
|
|
|
mutex_init(&host->lock);
|
|
|
|
spin_lock_init(&host->xfer);
|
2015-09-14 18:19:04 +00:00
|
|
|
host->mrq_workqueue = alloc_workqueue("mmc-%s", 0, 1,
|
2016-05-19 15:52:39 +00:00
|
|
|
dev_name(&gbphy_dev->dev));
|
2015-09-14 18:19:04 +00:00
|
|
|
if (!host->mrq_workqueue) {
|
|
|
|
ret = -ENOMEM;
|
2016-06-21 15:56:16 +00:00
|
|
|
goto exit_connection_disable;
|
2015-09-14 18:19:04 +00:00
|
|
|
}
|
2015-06-22 13:03:52 +00:00
|
|
|
INIT_WORK(&host->mrqwork, gb_sdio_mrq_work);
|
|
|
|
|
2016-05-05 09:02:34 +00:00
|
|
|
ret = gb_connection_enable(connection);
|
|
|
|
if (ret)
|
|
|
|
goto exit_wq_destroy;
|
|
|
|
|
2015-06-22 13:03:52 +00:00
|
|
|
ret = mmc_add_host(mmc);
|
|
|
|
if (ret < 0)
|
2016-05-05 09:02:34 +00:00
|
|
|
goto exit_wq_destroy;
|
2015-07-02 18:11:31 +00:00
|
|
|
host->removed = false;
|
|
|
|
ret = _gb_sdio_process_events(host, host->queued_events);
|
|
|
|
host->queued_events = 0;
|
2015-06-22 13:03:52 +00:00
|
|
|
|
2016-08-05 02:22:02 +00:00
|
|
|
gbphy_runtime_put_autosuspend(gbphy_dev);
|
|
|
|
|
2015-06-22 13:03:52 +00:00
|
|
|
return ret;
|
|
|
|
|
2016-05-05 09:02:34 +00:00
|
|
|
exit_wq_destroy:
|
2015-09-14 18:19:04 +00:00
|
|
|
destroy_workqueue(host->mrq_workqueue);
|
2016-05-05 09:02:34 +00:00
|
|
|
exit_connection_disable:
|
|
|
|
gb_connection_disable(connection);
|
|
|
|
exit_connection_destroy:
|
|
|
|
gb_connection_destroy(connection);
|
|
|
|
exit_mmc_free:
|
2015-06-22 13:03:52 +00:00
|
|
|
mmc_free_host(mmc);
|
|
|
|
|
|
|
|
return ret;
|
2014-08-11 09:27:22 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
static void gb_sdio_remove(struct gbphy_device *gbphy_dev)
|
2014-08-11 09:27:22 +00:00
|
|
|
{
|
2016-05-19 15:52:39 +00:00
|
|
|
struct gb_sdio_host *host = gb_gbphy_get_data(gbphy_dev);
|
2016-05-05 09:02:34 +00:00
|
|
|
struct gb_connection *connection = host->connection;
|
2014-08-11 09:27:22 +00:00
|
|
|
struct mmc_host *mmc;
|
2016-08-05 02:22:02 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = gbphy_runtime_get_sync(gbphy_dev);
|
|
|
|
if (ret)
|
|
|
|
gbphy_runtime_get_noresume(gbphy_dev);
|
2014-08-11 09:27:22 +00:00
|
|
|
|
2015-06-22 13:03:52 +00:00
|
|
|
mutex_lock(&host->lock);
|
|
|
|
host->removed = true;
|
2014-10-16 11:35:24 +00:00
|
|
|
mmc = host->mmc;
|
2016-03-22 18:30:35 +00:00
|
|
|
gb_connection_set_data(connection, NULL);
|
2015-06-22 13:03:52 +00:00
|
|
|
mutex_unlock(&host->lock);
|
|
|
|
|
2015-09-14 18:19:04 +00:00
|
|
|
destroy_workqueue(host->mrq_workqueue);
|
2016-05-05 09:02:34 +00:00
|
|
|
gb_connection_disable_rx(connection);
|
2015-06-22 13:03:52 +00:00
|
|
|
mmc_remove_host(mmc);
|
2016-05-05 09:02:34 +00:00
|
|
|
gb_connection_disable(connection);
|
|
|
|
gb_connection_destroy(connection);
|
2015-09-14 18:19:03 +00:00
|
|
|
mmc_free_host(mmc);
|
2014-08-11 09:27:22 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
static const struct gbphy_device_id gb_sdio_id_table[] = {
|
|
|
|
{ GBPHY_PROTOCOL(GREYBUS_PROTOCOL_SDIO) },
|
2016-05-05 09:02:34 +00:00
|
|
|
{ },
|
2014-11-05 22:12:53 +00:00
|
|
|
};
|
2016-05-19 15:52:39 +00:00
|
|
|
MODULE_DEVICE_TABLE(gbphy, gb_sdio_id_table);
|
2014-11-05 22:12:53 +00:00
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
static struct gbphy_driver sdio_driver = {
|
2016-05-05 09:02:34 +00:00
|
|
|
.name = "sdio",
|
|
|
|
.probe = gb_sdio_probe,
|
|
|
|
.remove = gb_sdio_remove,
|
|
|
|
.id_table = gb_sdio_id_table,
|
|
|
|
};
|
2016-05-09 12:45:09 +00:00
|
|
|
|
2016-05-19 15:52:39 +00:00
|
|
|
module_gbphy_driver(sdio_driver);
|
2016-05-09 12:45:09 +00:00
|
|
|
MODULE_LICENSE("GPL v2");
|