/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

/*
 * SDIO-Abstraction-Layer Module.
 *
 * To be used with Qualcomm's SDIO-Client connected to this host.
 */
#include <sdio_al_private.h>

#include <linux/module.h>
#include <linux/scatterlist.h>
#include <linux/workqueue.h>
#include <linux/wait.h>
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/wakelock.h>
#include <linux/mmc/core.h>
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
#include <linux/mmc/mmc.h>
#include <linux/mmc/sdio.h>
#include <linux/mmc/sdio_func.h>
#include <linux/mmc/sdio_ids.h>
#include <linux/gpio.h>
#include <linux/dma-mapping.h>
#include <linux/earlysuspend.h>
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#include <linux/syscalls.h>
#include <linux/time.h>
#include <linux/spinlock.h>

#include <mach/dma.h>
#include <mach/gpio.h>
#include <mach/subsystem_notif.h>

#include "../../../drivers/mmc/host/msm_sdcc.h"

/**
 *  Func#0 has SDIO standard registers
 *  Func#1 is for Mailbox.
 *  Functions 2..7 are for channels.
 *  Currently only functions 2..5 are active due to SDIO-Client
 *  number of pipes.
 *
 */
#define SDIO_AL_MAX_CHANNELS 6

/** Func 1..5 */
#define SDIO_AL_MAX_FUNCS    (SDIO_AL_MAX_CHANNELS+1)
#define SDIO_AL_WAKEUP_FUNC  6

/** Number of SDIO-Client pipes */
#define SDIO_AL_MAX_PIPES    16
#define SDIO_AL_ACTIVE_PIPES 8

/** CMD53/CMD54 Block size */
#define SDIO_AL_BLOCK_SIZE   256

/** Func#1 hardware Mailbox base address	 */
#define HW_MAILBOX_ADDR			0x1000

/** Func#1 peer sdioc software version.
 *  The header is duplicated also to the mailbox of the other
 *  functions. It can be used before other functions are enabled. */
#define SDIOC_SW_HEADER_ADDR		0x0400

/** Func#2..7 software Mailbox base address at 16K */
#define SDIOC_SW_MAILBOX_ADDR			0x4000

/** Some Mailbox registers address, written by host for
 control */
#define PIPES_THRESHOLD_ADDR		0x01000

#define PIPES_0_7_IRQ_MASK_ADDR 	0x01048

#define PIPES_8_15_IRQ_MASK_ADDR	0x0104C

#define FUNC_1_4_MASK_IRQ_ADDR		0x01040
#define FUNC_5_7_MASK_IRQ_ADDR		0x01044
#define FUNC_1_4_USER_IRQ_ADDR		0x01050
#define FUNC_5_7_USER_IRQ_ADDR		0x01054

#define EOT_PIPES_ENABLE		0x00

/** Maximum read/write data available is SDIO-Client limitation */
#define MAX_DATA_AVAILABLE   		(16*1024)
#define INVALID_DATA_AVAILABLE  	(0x8000)

/** SDIO-Client HW threshold to generate interrupt to the
 *  SDIO-Host on write available bytes.
 */
#define DEFAULT_WRITE_THRESHOLD 	(1024)

/** SDIO-Client HW threshold to generate interrupt to the
 *  SDIO-Host on read available bytes, for streaming (non
 *  packet) rx data.
 */
#define DEFAULT_READ_THRESHOLD  	(1024)

/* Extra bytes to ensure getting the rx threshold interrupt on stream channels
   when restoring the threshold after sleep */
#define THRESHOLD_CHANGE_EXTRA_BYTES (100)

/** SW threshold to trigger reading the mailbox. */
#define DEFAULT_MIN_WRITE_THRESHOLD 	(1024)
#define DEFAULT_MIN_WRITE_THRESHOLD_STREAMING	(1600)

#define THRESHOLD_DISABLE_VAL  		(0xFFFFFFFF)


/** Mailbox polling time for packet channels */
#define DEFAULT_POLL_DELAY_MSEC		10
/** Mailbox polling time for streaming channels */
#define DEFAULT_POLL_DELAY_NOPACKET_MSEC 30

/** The SDIO-Client prepares N buffers of size X per Tx pipe.
 *  Even when the transfer fills a partial buffer,
 *  that buffer becomes unusable for the next transfer. */
#define DEFAULT_PEER_TX_BUF_SIZE	(128)

#define ROUND_UP(x, n) (((x + n - 1) / n) * n)

/** Func#2..7 FIFOs are r/w via
 sdio_readsb() & sdio_writesb(),when inc_addr=0 */
#define PIPE_RX_FIFO_ADDR   0x00
#define PIPE_TX_FIFO_ADDR   0x00

/** Inactivity time to go to sleep in mseconds */
#define INACTIVITY_TIME_MSEC 30
#define INITIAL_INACTIVITY_TIME_MSEC 5000

/** Context validity check */
#define SDIO_AL_SIGNATURE 0xAABBCCDD

/* Vendor Specific Command */
#define SD_IO_RW_EXTENDED_QCOM 54

#define TIME_TO_WAIT_US 500
#define SDIO_CLOSE_FLUSH_TIMEOUT_MSEC   (10000)
#define RX_FLUSH_BUFFER_SIZE (16*1024)

#define SDIO_TEST_POSTFIX "_TEST"

#define DATA_DEBUG(x, y...)						\
	do {								\
		if (sdio_al->debug.debug_data_on)			\
			pr_info(y);					\
		sdio_al_log(x, y);					\
	} while (0)

#define LPM_DEBUG(x, y...)						\
	do {								\
		if (sdio_al->debug.debug_lpm_on)			\
			pr_info(y);					\
		sdio_al_log(x, y);					\
	} while (0)

#define sdio_al_loge(x, y...)						\
	do {								\
		pr_err(y);						\
		sdio_al_log(x, y);					\
	} while (0)

#define sdio_al_logi(x, y...)						\
	do {								\
		pr_info(y);						\
		sdio_al_log(x, y);					\
	} while (0)

#define CLOSE_DEBUG(x, y...)						\
	do {								\
		if (sdio_al->debug.debug_close_on)			\
			pr_info(y);					\
		sdio_al_log(x, y);					\
	} while (0)

/* The index of the SDIO card used for the sdio_al_dloader */
#define SDIO_BOOTLOADER_CARD_INDEX 1


/* SDIO card state machine */
enum sdio_al_device_state {
	CARD_INSERTED,
	CARD_REMOVED,
	MODEM_RESTART
};

struct sdio_al_debug {
	u8 debug_lpm_on;
	u8 debug_data_on;
	u8 debug_close_on;
	struct dentry *sdio_al_debug_root;
	struct dentry *sdio_al_debug_lpm_on;
	struct dentry *sdio_al_debug_data_on;
	struct dentry *sdio_al_debug_close_on;
	struct dentry *sdio_al_debug_info;
	struct dentry *sdio_al_debug_log_buffers[MAX_NUM_OF_SDIO_DEVICES + 1];
};

/* Polling time for the inactivity timer for devices that doesn't have
 * a streaming channel
 */
#define SDIO_AL_POLL_TIME_NO_STREAMING 30

#define CHAN_TO_FUNC(x) ((x) + 2 - 1)

/**
 *  Mailbox structure.
 *  The Mailbox is located on the SDIO-Client Function#1.
 *  The mailbox size is 128 bytes, which is one block.
 *  The mailbox allows the host ton:
 *  1. Get the number of available bytes on the pipes.
 *  2. Enable/Disable SDIO-Client interrupt, related to pipes.
 *  3. Set the Threshold for generating interrupt.
 *
 */
struct sdio_mailbox {
	u32 pipe_bytes_threshold[SDIO_AL_MAX_PIPES]; /* Addr 0x1000 */

	/* Mask USER interrupts generated towards host - Addr 0x1040 */
	u32 mask_irq_func_1:8; /* LSB */
	u32 mask_irq_func_2:8;
	u32 mask_irq_func_3:8;
	u32 mask_irq_func_4:8;

	u32 mask_irq_func_5:8;
	u32 mask_irq_func_6:8;
	u32 mask_irq_func_7:8;
	u32 mask_mutex_irq:8;

	/* Mask PIPE interrupts generated towards host - Addr 0x1048 */
	u32 mask_eot_pipe_0_7:8;
	u32 mask_thresh_above_limit_pipe_0_7:8;
	u32 mask_overflow_pipe_0_7:8;
	u32 mask_underflow_pipe_0_7:8;

	u32 mask_eot_pipe_8_15:8;
	u32 mask_thresh_above_limit_pipe_8_15:8;
	u32 mask_overflow_pipe_8_15:8;
	u32 mask_underflow_pipe_8_15:8;

	/* Status of User interrupts generated towards host - Addr 0x1050 */
	u32 user_irq_func_1:8;
	u32 user_irq_func_2:8;
	u32 user_irq_func_3:8;
	u32 user_irq_func_4:8;

	u32 user_irq_func_5:8;
	u32 user_irq_func_6:8;
	u32 user_irq_func_7:8;
	u32 user_mutex_irq:8;

	/* Status of PIPE interrupts generated towards host */
	/* Note: All sources are cleared once they read. - Addr 0x1058 */
	u32 eot_pipe_0_7:8;
	u32 thresh_above_limit_pipe_0_7:8;
	u32 overflow_pipe_0_7:8;
	u32 underflow_pipe_0_7:8;

	u32 eot_pipe_8_15:8;
	u32 thresh_above_limit_pipe_8_15:8;
	u32 overflow_pipe_8_15:8;
	u32 underflow_pipe_8_15:8;

	u16 pipe_bytes_avail[SDIO_AL_MAX_PIPES];
};

/** Track pending Rx Packet size */
struct rx_packet_size {
	u32 size; /* in bytes */
	struct list_head	list;
};

#define PEER_SDIOC_SW_MAILBOX_SIGNATURE 0xFACECAFE
#define PEER_SDIOC_SW_MAILBOX_UT_SIGNATURE 0x5D107E57
#define PEER_SDIOC_SW_MAILBOX_BOOT_SIGNATURE 0xDEADBEEF

/* Allow support in old sdio version */
#define PEER_SDIOC_OLD_VERSION_MAJOR	0x0002
#define INVALID_SDIO_CHAN		0xFF

/**
 * Peer SDIO-Client software header.
 */
struct peer_sdioc_sw_header {
	u32 signature;
	u32 version;
	u32 max_channels;
	char channel_names[SDIO_AL_MAX_CHANNELS][PEER_CHANNEL_NAME_SIZE];
	u32 reserved[23];
};

struct peer_sdioc_boot_sw_header {
	u32 signature;
	u32 version;
	u32 boot_ch_num;
	u32 reserved[29]; /* 32 - previous fields */
};

/**
 * Peer SDIO-Client software mailbox.
 */
struct peer_sdioc_sw_mailbox {
	struct peer_sdioc_sw_header sw_header;
	struct peer_sdioc_channel_config ch_config[SDIO_AL_MAX_CHANNELS];
};

#define SDIO_AL_DEBUG_LOG_SIZE 3000
struct sdio_al_local_log {
	char buffer[SDIO_AL_DEBUG_LOG_SIZE];
	unsigned int buf_cur_pos;
	spinlock_t log_lock;
};

#define SDIO_AL_DEBUG_TMP_LOG_SIZE 250
static int sdio_al_log(struct sdio_al_local_log *, const char *fmt, ...);

/**
 *  SDIO Abstraction Layer driver context.
 *
 *  @pdata -
 *  @debug -
 *  @devices - an array of the the devices claimed by sdio_al
 *  @unittest_mode - a flag to indicate if sdio_al is in
 *		   unittest mode
 *  @bootloader_dev - the device which is used for the
 *                 bootloader
 *  @subsys_notif_handle - handle for modem restart
 *                 notifications
 *
 */
struct sdio_al {
	struct sdio_al_local_log gen_log;
	struct sdio_al_local_log device_log[MAX_NUM_OF_SDIO_DEVICES];
	struct sdio_al_platform_data *pdata;
	struct sdio_al_debug debug;
	struct sdio_al_device *devices[MAX_NUM_OF_SDIO_DEVICES];
	int unittest_mode;
	struct sdio_al_device *bootloader_dev;
	void *subsys_notif_handle;
	int sdioc_major;
	int skip_print_info;
};

struct sdio_al_work {
	struct work_struct work;
	struct sdio_al_device *sdio_al_dev;
};


/**
 *  SDIO Abstraction Layer device context.
 *
 *  @card - card claimed.
 *
 *  @mailbox - A shadow of the SDIO-Client mailbox.
 *
 *  @channel - Channels context.
 *
 *  @workqueue - workqueue to read the mailbox and handle
 *     pending requests. Reading the mailbox should not happen
 *     in interrupt context.
 *
 *  @work - work to submit to workqueue.
 *
 *  @is_ready - driver is ready.
 *
 *  @ask_mbox - Flag to request reading the mailbox,
 *					  for different reasons.
 *
 *  @wake_lock - Lock when can't sleep.
 *
 *  @lpm_chan - Channel to use for LPM (low power mode)
 *            communication.
 *
 *  @is_ok_to_sleep - Mark if driver is OK with going to sleep
 * 			(no pending transactions).
 *
 *  @inactivity_time - time allowed to be in inactivity before
 * 		going to sleep
 *
 *  @timer - timer to use for polling the mailbox.
 *
 *  @poll_delay_msec - timer delay for polling the mailbox.
 *
 *  @is_err - error detected.
 *
 *  @signature - Context Validity Check.
 *
 *  @flashless_boot_on - flag to indicate if sdio_al is in
 *    flshless boot mode
 *
 */
struct sdio_al_device {
	struct sdio_al_local_log *dev_log;
	struct mmc_card *card;
	struct mmc_host *host;
	struct sdio_mailbox *mailbox;
	struct sdio_channel channel[SDIO_AL_MAX_CHANNELS];

	struct peer_sdioc_sw_header *sdioc_sw_header;
	struct peer_sdioc_boot_sw_header *sdioc_boot_sw_header;

	struct workqueue_struct *workqueue;
	struct sdio_al_work sdio_al_work;
	struct sdio_al_work boot_work;

	int is_ready;

	wait_queue_head_t   wait_mbox;
	int ask_mbox;
	int bootloader_done;

	struct wake_lock wake_lock;
	int lpm_chan;
	int is_ok_to_sleep;
	unsigned long inactivity_time;

	struct timer_list timer;
	u32 poll_delay_msec;
	int is_timer_initialized;

	int is_err;

	u32 signature;

	unsigned int is_suspended;

	int flashless_boot_on;
	int ch_close_supported;
	int state;
	int (*lpm_callback)(void *, int);

	int print_after_interrupt;

	u8 *rx_flush_buf;
};

/*
 * Host operation:
 *   lower 16bits are operation code
 *   upper 16bits are operation state
 */
#define PEER_OPERATION(op_code , op_state) ((op_code) | ((op_state) << 16))
#define GET_PEER_OPERATION_CODE(op) ((op) & 0xffff)
#define GET_PEER_OPERATION_STATE(op) ((op) >> 16)

enum peer_op_code {
	PEER_OP_CODE_CLOSE = 1
};

enum peer_op_state {
	PEER_OP_STATE_INIT = 0,
	PEER_OP_STATE_START = 1
};


/*
 * On the kernel command line specify
 * sdio_al.debug_lpm_on=1 to enable the LPM debug messages
 * By default the LPM debug messages are turned off
 */
static int debug_lpm_on;
module_param(debug_lpm_on, int, 0);

/*
 * On the kernel command line specify
 * sdio_al.debug_data_on=1 to enable the DATA debug messages
 * By default the DATA debug messages are turned off
 */
static int debug_data_on;
module_param(debug_data_on, int, 0);

/*
 * Enables / disables open close debug messages
 */
static int debug_close_on = 1;
module_param(debug_close_on, int, 0);

/** The driver context */
static struct sdio_al *sdio_al;

/* Static functions declaration */
static int enable_eot_interrupt(struct sdio_al_device *sdio_al_dev,
				int pipe_index, int enable);
static int enable_threshold_interrupt(struct sdio_al_device *sdio_al_dev,
				      int pipe_index, int enable);
static void sdio_func_irq(struct sdio_func *func);
static void sdio_al_timer_handler(unsigned long data);
static int get_min_poll_time_msec(struct sdio_al_device *sdio_al_dev);
static u32 check_pending_rx_packet(struct sdio_channel *ch, u32 eot);
static u32 remove_handled_rx_packet(struct sdio_channel *ch);
static int set_pipe_threshold(struct sdio_al_device *sdio_al_dev,
			      int pipe_index, int threshold);
static int sdio_al_wake_up(struct sdio_al_device *sdio_al_dev,
			   u32 not_from_int, struct sdio_channel *ch);
static int sdio_al_client_setup(struct sdio_al_device *sdio_al_dev);
static int enable_mask_irq(struct sdio_al_device *sdio_al_dev,
			   int func_num, int enable, u8 bit_offset);
static int sdio_al_enable_func_retry(struct sdio_func *func, const char *name);
static void sdio_al_print_info(void);
static int sdio_read_internal(struct sdio_channel *ch, void *data, int len);
static int sdio_read_from_closed_ch(struct sdio_channel *ch, int len);
static void stop_and_del_timer(struct sdio_al_device *sdio_al_dev);

#define SDIO_AL_ERR(func)					\
	do {							\
		printk_once(KERN_ERR MODULE_NAME		\
			":In Error state, ignore %s\n",		\
			func);					\
		sdio_al_print_info();				\
	} while (0)

#ifdef CONFIG_DEBUG_FS
static int debug_info_open(struct inode *inode, struct file *file)
{
	file->private_data = inode->i_private;
	return 0;
}

static ssize_t debug_info_write(struct file *file,
		const char __user *buf, size_t count, loff_t *ppos)
{
	sdio_al_print_info();
	return 1;
}

const struct file_operations debug_info_ops = {
	.open = debug_info_open,
	.write = debug_info_write,
};

struct debugfs_blob_wrapper sdio_al_dbgfs_log[MAX_NUM_OF_SDIO_DEVICES + 1];

/*
*
* Trigger on/off for debug messages
* for trigger off the data messages debug level use:
* echo 0 > /sys/kernel/debugfs/sdio_al/debug_data_on
* for trigger on the data messages debug level use:
* echo 1 > /sys/kernel/debugfs/sdio_al/debug_data_on
* for trigger off the lpm messages debug level use:
* echo 0 > /sys/kernel/debugfs/sdio_al/debug_lpm_on
* for trigger on the lpm messages debug level use:
* echo 1 > /sys/kernel/debugfs/sdio_al/debug_lpm_on
*/
static int sdio_al_debugfs_init(void)
{
	int i, blob_errs = 0;

	sdio_al->debug.sdio_al_debug_root = debugfs_create_dir("sdio_al", NULL);
	if (!sdio_al->debug.sdio_al_debug_root)
		return -ENOENT;

	sdio_al->debug.sdio_al_debug_lpm_on = debugfs_create_u8("debug_lpm_on",
					S_IRUGO | S_IWUGO,
					sdio_al->debug.sdio_al_debug_root,
					&sdio_al->debug.debug_lpm_on);

	sdio_al->debug.sdio_al_debug_data_on = debugfs_create_u8(
					"debug_data_on",
					S_IRUGO | S_IWUGO,
					sdio_al->debug.sdio_al_debug_root,
					&sdio_al->debug.debug_data_on);

	sdio_al->debug.sdio_al_debug_close_on = debugfs_create_u8(
					"debug_close_on",
					S_IRUGO | S_IWUGO,
					sdio_al->debug.sdio_al_debug_root,
					&sdio_al->debug.debug_close_on);

	sdio_al->debug.sdio_al_debug_info = debugfs_create_file(
					"sdio_debug_info",
					S_IRUGO | S_IWUGO,
					sdio_al->debug.sdio_al_debug_root,
					NULL,
					&debug_info_ops);

	for (i = 0; i < MAX_NUM_OF_SDIO_DEVICES; ++i) {
		char temp[18];

		scnprintf(temp, 18, "sdio_al_log_dev_%d", i + 1);
		sdio_al->debug.sdio_al_debug_log_buffers[i] =
			debugfs_create_blob(temp,
					S_IRUGO | S_IWUGO,
					sdio_al->debug.sdio_al_debug_root,
					&sdio_al_dbgfs_log[i]);
	}

	sdio_al->debug.sdio_al_debug_log_buffers[MAX_NUM_OF_SDIO_DEVICES] =
			debugfs_create_blob("sdio_al_gen_log",
				S_IRUGO | S_IWUGO,
				sdio_al->debug.sdio_al_debug_root,
				&sdio_al_dbgfs_log[MAX_NUM_OF_SDIO_DEVICES]);

	for (i = 0; i < (MAX_NUM_OF_SDIO_DEVICES + 1); ++i) {
		if (!sdio_al->debug.sdio_al_debug_log_buffers[i]) {
			pr_err(MODULE_NAME ": Failed to create debugfs buffer"
				   " entry for "
				   "sdio_al->debug.sdio_al_debug_log_buffers[%d]",
				   i);
			blob_errs = 1;
		}
	}

	if (blob_errs) {
		for (i = 0; i < (MAX_NUM_OF_SDIO_DEVICES + 1); ++i)
			if (sdio_al->debug.sdio_al_debug_log_buffers[i])
				debugfs_remove(
					sdio_al->
					debug.sdio_al_debug_log_buffers[i]);
	}


	if ((!sdio_al->debug.sdio_al_debug_data_on) &&
	    (!sdio_al->debug.sdio_al_debug_lpm_on) &&
	    (!sdio_al->debug.sdio_al_debug_close_on) &&
	    (!sdio_al->debug.sdio_al_debug_info) &&
		blob_errs) {
		debugfs_remove(sdio_al->debug.sdio_al_debug_root);
		sdio_al->debug.sdio_al_debug_root = NULL;
		return -ENOENT;
	}

	sdio_al_dbgfs_log[MAX_NUM_OF_SDIO_DEVICES].data =
						sdio_al->gen_log.buffer;
	sdio_al_dbgfs_log[MAX_NUM_OF_SDIO_DEVICES].size =
						SDIO_AL_DEBUG_LOG_SIZE;

	return 0;
}

static void sdio_al_debugfs_cleanup(void)
{
	int i;

	debugfs_remove(sdio_al->debug.sdio_al_debug_lpm_on);
	debugfs_remove(sdio_al->debug.sdio_al_debug_data_on);
	debugfs_remove(sdio_al->debug.sdio_al_debug_close_on);
	debugfs_remove(sdio_al->debug.sdio_al_debug_info);

	for (i = 0; i < (MAX_NUM_OF_SDIO_DEVICES + 1); ++i)
		debugfs_remove(sdio_al->debug.sdio_al_debug_log_buffers[i]);

	debugfs_remove(sdio_al->debug.sdio_al_debug_root);
}
#endif

static int sdio_al_log(struct sdio_al_local_log *log, const char *fmt, ...)
{
	va_list args;
	int r;
	char *tp, *log_buf;
	unsigned int *log_cur_pos;
	struct timeval kt;
	unsigned long flags;
	static char sdio_al_log_tmp[SDIO_AL_DEBUG_TMP_LOG_SIZE];

	spin_lock_irqsave(&log->log_lock, flags);

	kt = ktime_to_timeval(ktime_get());
	r = scnprintf(sdio_al_log_tmp, SDIO_AL_DEBUG_TMP_LOG_SIZE,
			"[%8ld.%6ld] ", kt.tv_sec, kt.tv_usec);

	va_start(args, fmt);
	r += vscnprintf(&sdio_al_log_tmp[r], (SDIO_AL_DEBUG_TMP_LOG_SIZE - r),
			fmt, args);
	va_end(args);

	log_buf = log->buffer;
	log_cur_pos = &(log->buf_cur_pos);

	for (tp = sdio_al_log_tmp; tp < (sdio_al_log_tmp + r); tp++) {
		log_buf[(*log_cur_pos)++] = *tp;
		if ((*log_cur_pos) == SDIO_AL_DEBUG_LOG_SIZE)
			*log_cur_pos = 0;
	}

	spin_unlock_irqrestore(&log->log_lock, flags);

	return r;
}

static int sdio_al_verify_func1(struct sdio_al_device *sdio_al_dev,
				char const *func)
{
	if (sdio_al_dev == NULL) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: NULL "
				"sdio_al_dev\n", func);
		return -ENODEV;
	}

	if (sdio_al_dev->signature != SDIO_AL_SIGNATURE) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": %s: Invalid "
				"signature\n", func);
		return -ENODEV;
	}

	if (!sdio_al_dev->card) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": %s: NULL "
				"card\n", func);
		return -ENODEV;
	}
	if (!sdio_al_dev->card->sdio_func[0]) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": %s: NULL "
				"func1\n", func);
		return -ENODEV;
	}
	return 0;
}

static int sdio_al_claim_mutex(struct sdio_al_device *sdio_al_dev,
			       char const *func)
{
	if (!sdio_al_dev) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: NULL "
					"device\n", func);
		return -ENODEV;
	}

	if (sdio_al_dev->signature != SDIO_AL_SIGNATURE) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": %s: Invalid "
					"device signature\n", func);
		return -ENODEV;
	}

	if (!sdio_al_dev->host) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": %s: NULL "
					"host\n", func);
		return -ENODEV;
	}

	mmc_claim_host(sdio_al_dev->host);

	return 0;
}

static int sdio_al_release_mutex(struct sdio_al_device *sdio_al_dev,
			       char const *func)
{
	if (!sdio_al_dev) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: NULL "
					"device\n", func);
		return -ENODEV;
	}

	if (sdio_al_dev->signature != SDIO_AL_SIGNATURE) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": %s: Invalid "
					"device signature\n", func);
		return -ENODEV;
	}

	if (!sdio_al_dev->host) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": %s: NULL "
					"host\n", func);
		return -ENODEV;
	}

	mmc_release_host(sdio_al_dev->host);

	return 0;
}

static int sdio_al_claim_mutex_and_verify_dev(
	struct sdio_al_device *sdio_al_dev,
	char const *func)
{
	if (sdio_al_claim_mutex(sdio_al_dev, __func__))
		return -ENODEV;

	if (sdio_al_dev->state != CARD_INSERTED) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": %s: Invalid "
				"device state %d\n", func, sdio_al_dev->state);
		sdio_al_release_mutex(sdio_al_dev, __func__);
		return -ENODEV;
	}

	return 0;
}

static void sdio_al_get_into_err_state(struct sdio_al_device *sdio_al_dev)
{
	if ((!sdio_al) || (!sdio_al_dev))
		return;

	sdio_al_dev->is_err = true;
	sdio_al->debug.debug_data_on = 0;
	sdio_al->debug.debug_lpm_on = 0;
	sdio_al_print_info();
}

void sdio_al_register_lpm_cb(void *device_handle,
				       int(*lpm_callback)(void *, int))
{
	struct sdio_al_device *sdio_al_dev =
		(struct sdio_al_device *) device_handle;

	if (!sdio_al_dev) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s - "
				"device_handle is NULL\n", __func__);
		return;
	}

	if (lpm_callback) {
		sdio_al_dev->lpm_callback = lpm_callback;
		lpm_callback((void *)sdio_al_dev,
					   sdio_al_dev->is_ok_to_sleep);
	}

	LPM_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ": %s - device %d "
			"registered for wakeup callback\n", __func__,
			sdio_al_dev->host->index);
}

void sdio_al_unregister_lpm_cb(void *device_handle)
{
	struct sdio_al_device *sdio_al_dev =
		(struct sdio_al_device *) device_handle;

	if (!sdio_al_dev) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s - "
				"device_handle is NULL\n", __func__);
		return;
	}

	sdio_al_dev->lpm_callback = NULL;
	LPM_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ": %s - device %d "
		"unregister for wakeup callback\n", __func__,
		sdio_al_dev->host->index);
}

static void sdio_al_vote_for_sleep(struct sdio_al_device *sdio_al_dev,
				   int is_vote_for_sleep)
{
	pr_debug(MODULE_NAME ": %s()", __func__);

	if (!sdio_al_dev) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s - sdio_al_dev"
				" is NULL\n", __func__);
		return;
	}

	if (is_vote_for_sleep) {
		pr_debug(MODULE_NAME ": %s - sdio vote for Sleep", __func__);
		wake_unlock(&sdio_al_dev->wake_lock);
	} else {
		pr_debug(MODULE_NAME ": %s - sdio vote against sleep",
			  __func__);
		wake_lock(&sdio_al_dev->wake_lock);
	}

	if (sdio_al_dev->lpm_callback != NULL) {
		LPM_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ": %s - "
				"is_vote_for_sleep=%d for card#%d, "
				"calling callback...", __func__,
				is_vote_for_sleep,
				sdio_al_dev->host->index);
		sdio_al_dev->lpm_callback((void *)sdio_al_dev,
					   is_vote_for_sleep);
	}
}

/**
 *  Write SDIO-Client lpm information
 *  Should only be called with host claimed.
 */
static int write_lpm_info(struct sdio_al_device *sdio_al_dev)
{
	struct sdio_func *lpm_func =
		sdio_al_dev->card->sdio_func[sdio_al_dev->lpm_chan+1];
	int offset = offsetof(struct peer_sdioc_sw_mailbox, ch_config)+
		sizeof(struct peer_sdioc_channel_config) *
		sdio_al_dev->lpm_chan+
		offsetof(struct peer_sdioc_channel_config, is_host_ok_to_sleep);
	int ret;

	if (sdio_al_dev->lpm_chan == INVALID_SDIO_CHAN) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":Invalid "
				"lpm_chan for card %d\n",
				sdio_al_dev->host->index);
		return -EINVAL;
	}

	pr_debug(MODULE_NAME ":write_lpm_info is_ok_to_sleep=%d, device %d\n",
		 sdio_al_dev->is_ok_to_sleep,
		 sdio_al_dev->host->index);

	ret = sdio_memcpy_toio(lpm_func, SDIOC_SW_MAILBOX_ADDR+offset,
				&sdio_al_dev->is_ok_to_sleep, sizeof(u32));
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":failed to "
				"write lpm info for card %d\n",
				sdio_al_dev->host->index);
		return ret;
	}

	return 0;
}

/* Set inactivity counter to intial value to allow clients come up */
static inline void start_inactive_time(struct sdio_al_device *sdio_al_dev)
{
	sdio_al_dev->inactivity_time = jiffies +
		msecs_to_jiffies(INITIAL_INACTIVITY_TIME_MSEC);
}

static inline void restart_inactive_time(struct sdio_al_device *sdio_al_dev)
{
	sdio_al_dev->inactivity_time = jiffies +
		msecs_to_jiffies(INACTIVITY_TIME_MSEC);
}

static inline int is_inactive_time_expired(struct sdio_al_device *sdio_al_dev)
{
	return time_after(jiffies, sdio_al_dev->inactivity_time);
}


static int is_user_irq_enabled(struct sdio_al_device *sdio_al_dev,
			       int func_num)
{
	int ret = 0;
	struct sdio_func *func1;
	u32 user_irq = 0;
	u32 addr = 0;
	u32 offset = 0;
	u32 masked_user_irq = 0;

	if (sdio_al_verify_func1(sdio_al_dev, __func__))
		return 0;
	func1 = sdio_al_dev->card->sdio_func[0];

	if (func_num < 4) {
		addr = FUNC_1_4_USER_IRQ_ADDR;
		offset = func_num * 8;
	} else {
		addr = FUNC_5_7_USER_IRQ_ADDR;
		offset = (func_num - 4) * 8;
	}

	user_irq = sdio_readl(func1, addr, &ret);
	if (ret) {
		pr_debug(MODULE_NAME ":read_user_irq fail\n");
		return 0;
	}

	masked_user_irq = (user_irq >> offset) && 0xFF;
	if (masked_user_irq == 0x1) {
		sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME ":user_irq "
				"enabled\n");
		return 1;
	}

	return 0;
}

static void sdio_al_sleep(struct sdio_al_device *sdio_al_dev,
			  struct mmc_host *host)
{
	int i;

	/* Go to sleep */
	pr_debug(MODULE_NAME  ":Inactivity timer expired."
		" Going to sleep\n");
	/* Stop mailbox timer */
	stop_and_del_timer(sdio_al_dev);
	/* Make sure we get interrupt for non-packet-mode right away */
	for (i = 0; i < SDIO_AL_MAX_CHANNELS; i++) {
		struct sdio_channel *ch = &sdio_al_dev->channel[i];
		if ((ch->state != SDIO_CHANNEL_STATE_OPEN) &&
		    (ch->state != SDIO_CHANNEL_STATE_CLOSED)) {
			pr_debug(MODULE_NAME  ":continue for channel %s in"
					" state %d\n", ch->name, ch->state);
			continue;
		}
		if (ch->is_packet_mode == false) {
			ch->read_threshold = 1;
			set_pipe_threshold(sdio_al_dev,
					   ch->rx_pipe_index,
					   ch->read_threshold);
		}
	}
	/* Prevent modem to go to sleep until we get the PROG_DONE on
	   the dummy CMD52 */
	msmsdcc_set_pwrsave(sdio_al_dev->host, 0);
	/* Mark HOST_OK_TOSLEEP */
	sdio_al_dev->is_ok_to_sleep = 1;
	write_lpm_info(sdio_al_dev);

	msmsdcc_lpm_enable(host);
	LPM_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ":Finished sleep sequence"
			" for card %d. Sleep now.\n",
		sdio_al_dev->host->index);
	/* Release wakelock */
	sdio_al_vote_for_sleep(sdio_al_dev, 1);
}


/**
 *  Read SDIO-Client Mailbox from Function#1.thresh_pipe
 *
 *  The mailbox contain the bytes available per pipe,
 *  and the End-Of-Transfer indication per pipe (if available).
 *
 * WARNING: Each time the Mailbox is read from the client, the
 * read_bytes_avail is incremented with another pending
 * transfer. Therefore, a pending rx-packet should be added to a
 * list before the next read of the mailbox.
 *
 * This function should run from a workqueue context since it
 * notifies the clients.
 *
 * This function assumes that sdio_al_claim_mutex was called before
 * calling it.
 *
 */
static int read_mailbox(struct sdio_al_device *sdio_al_dev, int from_isr)
{
	int ret;
	struct sdio_func *func1 = NULL;
	struct sdio_mailbox *mailbox = sdio_al_dev->mailbox;
	struct mmc_host *host = sdio_al_dev->host;
	u32 new_write_avail = 0;
	u32 old_write_avail = 0;
	u32 any_read_avail = 0;
	u32 any_write_pending = 0;
	int i;
	u32 rx_notify_bitmask = 0;
	u32 tx_notify_bitmask = 0;
	u32 eot_pipe = 0;
	u32 thresh_pipe = 0;
	u32 overflow_pipe = 0;
	u32 underflow_pipe = 0;
	u32 thresh_intr_mask = 0;
	int is_closing = 0;

	if (sdio_al_dev->is_err) {
		SDIO_AL_ERR(__func__);
		return 0;
	}

	if (sdio_al_verify_func1(sdio_al_dev, __func__))
		return -ENODEV;
	func1 = sdio_al_dev->card->sdio_func[0];

	pr_debug(MODULE_NAME ":start %s from_isr = %d for card %d.\n"
		 , __func__, from_isr, sdio_al_dev->host->index);

	pr_debug(MODULE_NAME ":before sdio_memcpy_fromio.\n");
	memset(mailbox, 0, sizeof(struct sdio_mailbox));
	ret = sdio_memcpy_fromio(func1, mailbox,
			HW_MAILBOX_ADDR, sizeof(*mailbox));
	pr_debug(MODULE_NAME ":after sdio_memcpy_fromio.\n");
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":Fail to read "
				"Mailbox for card %d, goto error state\n",
				sdio_al_dev->host->index);
		sdio_al_get_into_err_state(sdio_al_dev);
		goto exit_err;
	}

	eot_pipe =	(mailbox->eot_pipe_0_7) |
			(mailbox->eot_pipe_8_15<<8);
	thresh_pipe = 	(mailbox->thresh_above_limit_pipe_0_7) |
			(mailbox->thresh_above_limit_pipe_8_15<<8);

	overflow_pipe = (mailbox->overflow_pipe_0_7) |
			(mailbox->overflow_pipe_8_15<<8);
	underflow_pipe = mailbox->underflow_pipe_0_7 |
			(mailbox->underflow_pipe_8_15<<8);
	thresh_intr_mask =
		(mailbox->mask_thresh_above_limit_pipe_0_7) |
		(mailbox->mask_thresh_above_limit_pipe_8_15<<8);

	if (overflow_pipe || underflow_pipe)
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":Mailbox ERROR "
				"overflow=0x%x, underflow=0x%x\n",
				overflow_pipe, underflow_pipe);

	/* In case of modem reset we would like to read the daya from the modem
	   to clear the interrupts but do not process it */
	if (sdio_al_dev->state != CARD_INSERTED) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":sdio_al_device"
				" (card %d) is in invalid state %d\n",
				sdio_al_dev->host->index,
				sdio_al_dev->state);
		return -ENODEV;
	}

	pr_debug(MODULE_NAME ":card %d: eot=0x%x, thresh=0x%x\n",
			sdio_al_dev->host->index,
			eot_pipe, thresh_pipe);

	/* Scan for Rx Packets available and update read available bytes */
	for (i = 0; i < SDIO_AL_MAX_CHANNELS; i++) {
		struct sdio_channel *ch = &sdio_al_dev->channel[i];
		u32 old_read_avail;
		u32 read_avail;
		u32 new_packet_size = 0;

		if (ch->state == SDIO_CHANNEL_STATE_CLOSING)
			is_closing = true; /* used to prevent sleep */

		old_read_avail = ch->read_avail;
		read_avail = mailbox->pipe_bytes_avail[ch->rx_pipe_index];

		if ((ch->state == SDIO_CHANNEL_STATE_CLOSED) &&
			(read_avail > 0)) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
				 ":%s: Invalid read_avail 0x%x, for CLOSED ch %s\n",
				 __func__, read_avail, ch->name);
			sdio_read_from_closed_ch(ch, read_avail);
		}
		if ((ch->state != SDIO_CHANNEL_STATE_OPEN) &&
		    (ch->state != SDIO_CHANNEL_STATE_CLOSING))
			continue;

		if (read_avail > INVALID_DATA_AVAILABLE) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
				 ":Invalid read_avail 0x%x for pipe %d\n",
				 read_avail, ch->rx_pipe_index);
			continue;
		}
		any_read_avail |= read_avail | old_read_avail;
		ch->statistics.last_any_read_avail = any_read_avail;
		ch->statistics.last_read_avail = read_avail;
		ch->statistics.last_old_read_avail = old_read_avail;

		if (ch->is_packet_mode) {
			if ((eot_pipe & (1<<ch->rx_pipe_index)) &&
			    sdio_al_dev->print_after_interrupt) {
				LPM_DEBUG(sdio_al_dev->dev_log, MODULE_NAME
					":Interrupt on ch %s, "
					"card %d", ch->name,
					sdio_al_dev->host->index);
			}
			new_packet_size = check_pending_rx_packet(ch, eot_pipe);
		} else {
			if ((thresh_pipe & (1<<ch->rx_pipe_index)) &&
			    sdio_al_dev->print_after_interrupt) {
				LPM_DEBUG(sdio_al_dev->dev_log, MODULE_NAME
					":Interrupt on ch %s, "
					"card %d", ch->name,
					sdio_al_dev->host->index);
			}
			ch->read_avail = read_avail;
			/* Restore default thresh for non packet channels */
			if ((ch->read_threshold != ch->def_read_threshold) &&
			    (read_avail >= ch->threshold_change_cnt)) {
				ch->read_threshold = ch->def_read_threshold;
				set_pipe_threshold(sdio_al_dev,
						   ch->rx_pipe_index,
						   ch->read_threshold);
			}
		}

		if ((ch->is_packet_mode) && (new_packet_size > 0)) {
			rx_notify_bitmask |= (1<<ch->num);
			ch->statistics.total_notifs++;
		}

		if ((!ch->is_packet_mode) && (ch->read_avail > 0) &&
		    (old_read_avail == 0)) {
			rx_notify_bitmask |= (1<<ch->num);
			ch->statistics.total_notifs++;
		}
	}
	sdio_al_dev->print_after_interrupt = 0;

	/* Update Write available */
	for (i = 0; i < SDIO_AL_MAX_CHANNELS; i++) {
		struct sdio_channel *ch = &sdio_al_dev->channel[i];

		if ((ch->state != SDIO_CHANNEL_STATE_OPEN) &&
		    (ch->state != SDIO_CHANNEL_STATE_CLOSING))
			continue;

		new_write_avail = mailbox->pipe_bytes_avail[ch->tx_pipe_index];

		if (new_write_avail > INVALID_DATA_AVAILABLE) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
				 ":Invalid write_avail 0x%x for pipe %d\n",
				 new_write_avail, ch->tx_pipe_index);
			continue;
		}

		old_write_avail = ch->write_avail;
		ch->write_avail = new_write_avail;

		if ((old_write_avail <= ch->min_write_avail) &&
			(new_write_avail >= ch->min_write_avail))
			tx_notify_bitmask |= (1<<ch->num);

		/* There is not enough write avail for this channel.
		   We need to keep reading mailbox to wait for the appropriate
		   write avail and cannot sleep. Ignore SMEM channel that has
		   only one direction. */
		if (strcmp(ch->name, "SDIO_SMEM"))
			any_write_pending |=
			(new_write_avail < ch->ch_config.max_tx_threshold);
	}
	/* notify clients */
	for (i = 0; i < SDIO_AL_MAX_CHANNELS; i++) {
		struct sdio_channel *ch = &sdio_al_dev->channel[i];

		if ((ch->state != SDIO_CHANNEL_STATE_OPEN) ||
				(ch->notify == NULL))
			continue;

		if (rx_notify_bitmask & (1<<ch->num))
			ch->notify(ch->priv,
					   SDIO_EVENT_DATA_READ_AVAIL);

		if (tx_notify_bitmask & (1<<ch->num))
			ch->notify(ch->priv,
					   SDIO_EVENT_DATA_WRITE_AVAIL);
	}


	if ((rx_notify_bitmask == 0) && (tx_notify_bitmask == 0) &&
	    !any_read_avail && !any_write_pending) {
		DATA_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ":Nothing to "
				"Notify for card %d, is_closing=%d\n",
				sdio_al_dev->host->index, is_closing);
		if (is_closing)
			restart_inactive_time(sdio_al_dev);
		else if (is_inactive_time_expired(sdio_al_dev))
			sdio_al_sleep(sdio_al_dev, host);
	} else {
		DATA_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ":Notify bitmask"
				" for card %d rx=0x%x, tx=0x%x.\n",
				sdio_al_dev->host->index,
				rx_notify_bitmask, tx_notify_bitmask);
		/* Restart inactivity timer if any activity on the channel */
		restart_inactive_time(sdio_al_dev);
	}

	pr_debug(MODULE_NAME ":end %s.\n", __func__);

exit_err:
	return ret;
}

/**
 *  Check pending rx packet when reading the mailbox.
 */
static u32 check_pending_rx_packet(struct sdio_channel *ch, u32 eot)
{
	u32 rx_pending;
	u32 rx_avail;
	u32 new_packet_size = 0;
	struct sdio_al_device *sdio_al_dev = ch->sdio_al_dev;


	if (sdio_al_dev == NULL) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": NULL sdio_al_dev"
				" for channel %s\n", ch->name);
		return -EINVAL;
	}

	mutex_lock(&ch->ch_lock);

	rx_pending = ch->rx_pending_bytes;
	rx_avail = sdio_al_dev->mailbox->pipe_bytes_avail[ch->rx_pipe_index];

	pr_debug(MODULE_NAME ":pipe %d of card %d rx_avail=0x%x, "
			     "rx_pending=0x%x\n",
	   ch->rx_pipe_index, sdio_al_dev->host->index, rx_avail,
		 rx_pending);


	/* new packet detected */
	if (eot & (1<<ch->rx_pipe_index)) {
		struct rx_packet_size *p = NULL;
		new_packet_size = rx_avail - rx_pending;

		if ((rx_avail <= rx_pending)) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
					": Invalid new packet size."
					" rx_avail=%d.\n", rx_avail);
			new_packet_size = 0;
			goto exit_err;
		}

		p = kzalloc(sizeof(*p), GFP_KERNEL);
		if (p == NULL) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
					": failed to allocate item for "
					"rx_pending list. rx_avail=%d, "
					"rx_pending=%d.\n",
					rx_avail, rx_pending);
			new_packet_size = 0;
			goto exit_err;
		}
		p->size = new_packet_size;
		/* Add new packet as last */
		list_add_tail(&p->list, &ch->rx_size_list_head);
		ch->rx_pending_bytes += new_packet_size;

		if (ch->read_avail == 0)
			ch->read_avail = new_packet_size;
	}

exit_err:
	mutex_unlock(&ch->ch_lock);

	return new_packet_size;
}



/**
 *  Remove first pending packet from the list.
 */
static u32 remove_handled_rx_packet(struct sdio_channel *ch)
{
	struct rx_packet_size *p = NULL;

	mutex_lock(&ch->ch_lock);

	ch->rx_pending_bytes -= ch->read_avail;

	if (!list_empty(&ch->rx_size_list_head)) {
		p = list_first_entry(&ch->rx_size_list_head,
			struct rx_packet_size, list);
		list_del(&p->list);
		kfree(p);
	} else {
		sdio_al_loge(ch->sdio_al_dev->dev_log, MODULE_NAME ":%s: ch "
				"%s: unexpected empty list!!\n",
				__func__, ch->name);
	}

	if (list_empty(&ch->rx_size_list_head))	{
		ch->read_avail = 0;
	} else {
		p = list_first_entry(&ch->rx_size_list_head,
			struct rx_packet_size, list);
		ch->read_avail = p->size;
	}

	mutex_unlock(&ch->ch_lock);

	return ch->read_avail;
}


/**
 *  Bootloader worker function.
 *
 *  @note: clear the bootloader_done flag only after reading the
 *  mailbox, to ignore more requests while reading the mailbox.
 */
static void boot_worker(struct work_struct *work)
{
	int ret = 0;
	int func_num = 0;
	int i;
	struct sdio_al_device *sdio_al_dev = NULL;
	struct sdio_al_work *sdio_al_work = container_of(work,
							 struct sdio_al_work,
							 work);

	if (sdio_al_work == NULL) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: NULL "
				"sdio_al_work\n", __func__);
		return;
	}

	sdio_al_dev = sdio_al_work->sdio_al_dev;
	if (sdio_al_dev == NULL) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: NULL "
				"sdio_al_dev\n", __func__);
		return;
	}
	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ":Bootloader Worker Started"
			", wait for bootloader_done event..\n");
	wait_event(sdio_al_dev->wait_mbox,
		   sdio_al_dev->bootloader_done);
	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ":Got bootloader_done "
			"event..\n");
	/* Do polling until MDM is up */
	for (i = 0; i < 5000; ++i) {
		if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
			return;
		if (is_user_irq_enabled(sdio_al_dev, func_num)) {
			sdio_al_release_mutex(sdio_al_dev, __func__);
			sdio_al_dev->bootloader_done = 0;
			ret = sdio_al_client_setup(sdio_al_dev);
			if (ret) {
				sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
					": sdio_al_client_setup failed, "
					"for card %d ret=%d\n",
					sdio_al_dev->host->index, ret);
				sdio_al_get_into_err_state(sdio_al_dev);
			}
			goto done;
		}
		sdio_al_release_mutex(sdio_al_dev, __func__);
		msleep(100);
	}
	sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":Timeout waiting for "
			"user_irq for card %d\n",
			sdio_al_dev->host->index);
	sdio_al_get_into_err_state(sdio_al_dev);

done:
	pr_debug(MODULE_NAME ":Boot Worker for card %d Exit!\n",
		sdio_al_dev->host->index);
}

/**
 *  Worker function.
 *
 *  @note: clear the ask_mbox flag only after
 *  	 reading the mailbox, to ignore more requests while
 *  	 reading the mailbox.
 */
static void worker(struct work_struct *work)
{
	int ret = 0;
	struct sdio_al_device *sdio_al_dev = NULL;
	struct sdio_al_work *sdio_al_work = container_of(work,
							 struct sdio_al_work,
							 work);
	if (sdio_al_work == NULL) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": worker: NULL "
				"sdio_al_work\n");
		return;
	}

	sdio_al_dev = sdio_al_work->sdio_al_dev;
	if (sdio_al_dev == NULL) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": worker: NULL "
				"sdio_al_dev\n");
		return;
	}
	pr_debug(MODULE_NAME ":Worker Started..\n");
	while ((sdio_al_dev->is_ready) && (ret == 0)) {
		pr_debug(MODULE_NAME ":Wait for read mailbox request..\n");
		wait_event(sdio_al_dev->wait_mbox, sdio_al_dev->ask_mbox);
		if (!sdio_al_dev->is_ready)
			break;
		if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
			break;
		if (sdio_al_dev->is_ok_to_sleep) {
			ret = sdio_al_wake_up(sdio_al_dev, 1, NULL);
			if (ret) {
				sdio_al_release_mutex(sdio_al_dev, __func__);
				return;
			}
		}
		ret = read_mailbox(sdio_al_dev, false);
		sdio_al_release_mutex(sdio_al_dev, __func__);
		sdio_al_dev->ask_mbox = false;
	}

	pr_debug(MODULE_NAME ":Worker Exit!\n");
}

/**
 *  Write command using CMD54 rather than CMD53.
 *  Writing with CMD54 generate EOT interrupt at the
 *  SDIO-Client.
 *  Based on mmc_io_rw_extended()
 */
static int sdio_write_cmd54(struct mmc_card *card, unsigned fn,
	unsigned addr, const u8 *buf,
	unsigned blocks, unsigned blksz)
{
	struct mmc_request mrq;
	struct mmc_command cmd;
	struct mmc_data data;
	struct scatterlist sg;
	int incr_addr = 1; /* MUST */
	int write = 1;

	BUG_ON(!card);
	BUG_ON(fn > 7);
	BUG_ON(blocks == 1 && blksz > 512);
	WARN_ON(blocks == 0);
	WARN_ON(blksz == 0);

	write = true;
	pr_debug(MODULE_NAME ":sdio_write_cmd54()"
		"fn=%d,buf=0x%x,blocks=%d,blksz=%d\n",
		fn, (u32) buf, blocks, blksz);

	memset(&mrq, 0, sizeof(struct mmc_request));
	memset(&cmd, 0, sizeof(struct mmc_command));
	memset(&data, 0, sizeof(struct mmc_data));

	mrq.cmd = &cmd;
	mrq.data = &data;

	cmd.opcode = SD_IO_RW_EXTENDED_QCOM;

	cmd.arg = write ? 0x80000000 : 0x00000000;
	cmd.arg |= fn << 28;
	cmd.arg |= incr_addr ? 0x04000000 : 0x00000000;
	cmd.arg |= addr << 9;
	if (blocks == 1 && blksz <= 512)
		cmd.arg |= (blksz == 512) ? 0 : blksz;  /* byte mode */
	else
		cmd.arg |= 0x08000000 | blocks; 	/* block mode */
	cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;

	data.blksz = blksz;
	data.blocks = blocks;
	data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
	data.sg = &sg;
	data.sg_len = 1;

	sg_init_one(&sg, buf, blksz * blocks);

	mmc_set_data_timeout(&data, card);

	mmc_wait_for_req(card->host, &mrq);

	if (cmd.error)
		return cmd.error;
	if (data.error)
		return data.error;

	if (mmc_host_is_spi(card->host)) {
		/* host driver already reported errors */
	} else {
		if (cmd.resp[0] & R5_ERROR) {
			sdio_al_loge(&sdio_al->gen_log, MODULE_NAME
						":%s: R5_ERROR for card %d",
						__func__, card->host->index);
			return -EIO;
		}
		if (cmd.resp[0] & R5_FUNCTION_NUMBER) {
			sdio_al_loge(&sdio_al->gen_log, MODULE_NAME
						":%s: R5_FUNCTION_NUMBER for card %d",
						__func__, card->host->index);
			return -EINVAL;
		}
		if (cmd.resp[0] & R5_OUT_OF_RANGE) {
			sdio_al_loge(&sdio_al->gen_log, MODULE_NAME
						":%s: R5_OUT_OF_RANGE for card %d",
						__func__, card->host->index);
			return -ERANGE;
		}
	}

	return 0;
}


/**
 *  Write data to channel.
 *  Handle different data size types.
 *
 */
static int sdio_ch_write(struct sdio_channel *ch, const u8 *buf, u32 len)
{
	int ret = 0;
	unsigned blksz = ch->func->cur_blksize;
	int blocks = len / blksz;
	int remain_bytes = len % blksz;
	struct mmc_card *card = NULL;
	u32 fn = ch->func->num;

	if (!ch) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: NULL "
				"channel\n", __func__);
		return -ENODEV;
	}

	if (!ch->sdio_al_dev) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: NULL "
				"sdio_al_dev\n", __func__);
		return -ENODEV;
	}

	if (len == 0) {
		sdio_al_loge(ch->sdio_al_dev->dev_log, MODULE_NAME ":channel "
				"%s trying to write 0 bytes\n", ch->name);
		return -EINVAL;
	}

	card = ch->func->card;

	if (remain_bytes) {
		/* CMD53 */
		if (blocks) {
			ret = sdio_memcpy_toio(ch->func, PIPE_TX_FIFO_ADDR,
					       (void *) buf, blocks*blksz);
			if (ret != 0) {
				sdio_al_loge(ch->sdio_al_dev->dev_log,
					MODULE_NAME ":%s: sdio_memcpy_toio "
					"failed for channel %s\n",
					__func__, ch->name);
				sdio_al_get_into_err_state(ch->sdio_al_dev);
				return ret;
			}
		}

		buf += (blocks*blksz);

		ret = sdio_write_cmd54(card, fn, PIPE_TX_FIFO_ADDR,
				buf, 1, remain_bytes);
	} else {
		ret = sdio_write_cmd54(card, fn, PIPE_TX_FIFO_ADDR,
				buf, blocks, blksz);
	}

	if (ret != 0) {
		sdio_al_loge(ch->sdio_al_dev->dev_log, MODULE_NAME ":%s: "
				"sdio_write_cmd54 failed for channel %s\n",
				__func__, ch->name);
		ch->sdio_al_dev->is_err = true;
		return ret;
	}

	return ret;
}

static int sdio_al_bootloader_completed(void)
{
	int i;

	pr_debug(MODULE_NAME ":sdio_al_bootloader_completed was called\n");

	for (i = 0; i < MAX_NUM_OF_SDIO_DEVICES; ++i) {
		struct sdio_al_device *dev = NULL;
		if (sdio_al->devices[i] == NULL)
			continue;
		dev = sdio_al->devices[i];
		dev->bootloader_done = 1;
		wake_up(&dev->wait_mbox);
	}

	return 0;
}

static int sdio_al_wait_for_bootloader_comp(struct sdio_al_device *sdio_al_dev)
{
	int ret = 0;

	if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
		return -ENODEV;

	/*
	 * Enable function 0 interrupt mask to allow 9k to raise this interrupt
	 * in power-up. When sdio_downloader will notify its completion
	 * we will poll on this interrupt to wait for 9k power-up
	 */
	ret = enable_mask_irq(sdio_al_dev, 0, 1, 0);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
				": Enable_mask_irq for card %d failed, "
				"ret=%d\n",
				sdio_al_dev->host->index, ret);
		sdio_al_release_mutex(sdio_al_dev, __func__);
		return ret;
	}

	sdio_al_release_mutex(sdio_al_dev, __func__);

	/*
	 * Start bootloader worker that will wait for the bootloader
	 * completion
	 */
	sdio_al_dev->boot_work.sdio_al_dev = sdio_al_dev;
	INIT_WORK(&sdio_al_dev->boot_work.work, boot_worker);
	sdio_al_dev->bootloader_done = 0;
	queue_work(sdio_al_dev->workqueue, &sdio_al_dev->boot_work.work);

	return 0;
}

static int sdio_al_bootloader_setup(void)
{
	int ret = 0;
	struct sdio_al_device *bootloader_dev = sdio_al->bootloader_dev;
	struct sdio_func *func1 = NULL;

	if (sdio_al_claim_mutex_and_verify_dev(bootloader_dev, __func__))
		return -ENODEV;

	if (bootloader_dev->flashless_boot_on) {
		sdio_al_loge(bootloader_dev->dev_log, MODULE_NAME ":Already "
			"in boot process.\n");
		sdio_al_release_mutex(bootloader_dev, __func__);
		return 0;
	}

	bootloader_dev->sdioc_boot_sw_header
		= kzalloc(sizeof(*bootloader_dev->sdioc_boot_sw_header),
			  GFP_KERNEL);
	if (bootloader_dev->sdioc_boot_sw_header == NULL) {
		sdio_al_loge(bootloader_dev->dev_log, MODULE_NAME ":fail to "
			"allocate sdioc boot sw header.\n");
		sdio_al_release_mutex(bootloader_dev, __func__);
		return -ENOMEM;
	}

	if (sdio_al_verify_func1(bootloader_dev, __func__)) {
		sdio_al_release_mutex(bootloader_dev, __func__);
		goto exit_err;
	}
	func1 = bootloader_dev->card->sdio_func[0];

	ret = sdio_memcpy_fromio(func1,
				 bootloader_dev->sdioc_boot_sw_header,
				 SDIOC_SW_HEADER_ADDR,
				 sizeof(struct peer_sdioc_boot_sw_header));
	if (ret) {
		sdio_al_loge(bootloader_dev->dev_log, MODULE_NAME ":fail to "
			"read sdioc boot sw header.\n");
		sdio_al_release_mutex(bootloader_dev, __func__);
		goto exit_err;
	}

	if (bootloader_dev->sdioc_boot_sw_header->signature !=
	    (u32) PEER_SDIOC_SW_MAILBOX_BOOT_SIGNATURE) {
		sdio_al_loge(bootloader_dev->dev_log, MODULE_NAME ":invalid "
			"mailbox signature 0x%x.\n",
			bootloader_dev->sdioc_boot_sw_header->signature);
		sdio_al_release_mutex(bootloader_dev, __func__);
		ret = -EINVAL;
		goto exit_err;
	}

	/* Upper byte has to be equal - no backward compatibility for unequal */
	if ((bootloader_dev->sdioc_boot_sw_header->version >> 16) !=
	    (sdio_al->pdata->peer_sdioc_boot_version_major)) {
		sdio_al_loge(bootloader_dev->dev_log, MODULE_NAME ": HOST(0x%x)"
			" and CLIENT(0x%x) SDIO_AL BOOT VERSION don't match\n",
			((sdio_al->pdata->peer_sdioc_boot_version_major<<16)+
			sdio_al->pdata->peer_sdioc_boot_version_minor),
			bootloader_dev->sdioc_boot_sw_header->version);
		sdio_al_release_mutex(bootloader_dev, __func__);
		ret = -EIO;
		goto exit_err;
	}

	sdio_al_logi(bootloader_dev->dev_log, MODULE_NAME ": SDIOC BOOT SW "
			"version 0x%x\n",
			bootloader_dev->sdioc_boot_sw_header->version);

	bootloader_dev->flashless_boot_on = true;

	sdio_al_release_mutex(bootloader_dev, __func__);

	ret = sdio_al_wait_for_bootloader_comp(bootloader_dev);
	if (ret) {
		sdio_al_loge(bootloader_dev->dev_log, MODULE_NAME
				": sdio_al_wait_for_bootloader_comp failed, "
				"err=%d\n", ret);
		goto exit_err;
	}

	ret = sdio_downloader_setup(bootloader_dev->card, 1,
			bootloader_dev->sdioc_boot_sw_header->boot_ch_num,
			sdio_al_bootloader_completed);

	if (ret) {
		sdio_al_loge(bootloader_dev->dev_log, MODULE_NAME
			": sdio_downloader_setup failed, err=%d\n", ret);
		goto exit_err;
	}

	sdio_al_logi(bootloader_dev->dev_log, MODULE_NAME ":In Flashless boot,"
		" waiting for its completion\n");


exit_err:
	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ":free "
			"sdioc_boot_sw_header.\n");
	kfree(bootloader_dev->sdioc_boot_sw_header);
	bootloader_dev->sdioc_boot_sw_header = NULL;
	bootloader_dev = NULL;

	return ret;
}


/**
 *  Read SDIO-Client software header
 *
 */
static int read_sdioc_software_header(struct sdio_al_device *sdio_al_dev,
				      struct peer_sdioc_sw_header *header)
{
	int ret;
	int i;
	int test_version = 0;
	int sdioc_test_version = 0;
	struct sdio_func *func1 = NULL;

	pr_debug(MODULE_NAME ":reading sdioc sw header.\n");

	if (sdio_al_verify_func1(sdio_al_dev, __func__))
		return -ENODEV;

	func1 = sdio_al_dev->card->sdio_func[0];

	ret = sdio_memcpy_fromio(func1, header,
			SDIOC_SW_HEADER_ADDR, sizeof(*header));
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":fail to read "
				"sdioc sw header.\n");
		goto exit_err;
	}

	if (header->signature == (u32)PEER_SDIOC_SW_MAILBOX_UT_SIGNATURE) {
		sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME ":SDIOC SW "
				"unittest signature. 0x%x\n",
				header->signature);
		sdio_al->unittest_mode = true;
		/* Verify test code compatibility with the modem */
		sdioc_test_version = (header->version & 0xFF00) >> 8;
		test_version = sdio_al->pdata->peer_sdioc_version_minor >> 8;
		if (test_version != sdioc_test_version) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
				": HOST(0x%x) and CLIENT(0x%x) "
				"testing VERSION don't match\n",
				test_version,
				sdioc_test_version);
			msleep(500);
			BUG();
		}
	}

	if ((header->signature != (u32) PEER_SDIOC_SW_MAILBOX_SIGNATURE) &&
	    (header->signature != (u32) PEER_SDIOC_SW_MAILBOX_UT_SIGNATURE)) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":SDIOC SW "
				"invalid signature. 0x%x\n", header->signature);
		goto exit_err;
	}
	/* Upper byte has to be equal - no backward compatibility for unequal */
	sdio_al->sdioc_major = header->version >> 16;
	if (sdio_al->pdata->allow_sdioc_version_major_2) {
		if ((sdio_al->sdioc_major !=
		    sdio_al->pdata->peer_sdioc_version_major) &&
		    (sdio_al->sdioc_major != PEER_SDIOC_OLD_VERSION_MAJOR)) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
				": HOST(0x%x) and CLIENT(0x%x) "
				"SDIO_AL VERSION don't match\n",
				((sdio_al->pdata->peer_sdioc_version_major<<16)+
				sdio_al->pdata->peer_sdioc_version_minor),
				header->version);
			goto exit_err;
		}
	} else {
		if (sdio_al->sdioc_major !=
		    sdio_al->pdata->peer_sdioc_version_major) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
				": HOST(0x%x) and CLIENT(0x%x) "
				"SDIO_AL VERSION don't match\n",
				((sdio_al->pdata->peer_sdioc_version_major<<16)+
				sdio_al->pdata->peer_sdioc_version_minor),
				header->version);
			goto exit_err;
		}
	}
	sdio_al_dev->ch_close_supported = (header->version & 0x000F) >=
		(sdio_al->pdata->peer_sdioc_version_minor & 0xF);

	sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME ":SDIOC SW version 0x%x,"
			" sdio_al major 0x%x minor 0x%x\n", header->version,
			sdio_al->sdioc_major,
			sdio_al->pdata->peer_sdioc_version_minor);

	sdio_al_dev->flashless_boot_on = false;
	for (i = 0; i < SDIO_AL_MAX_CHANNELS; i++) {
		struct sdio_channel *ch = &sdio_al_dev->channel[i];

		/* Set default values */
		ch->read_threshold  = DEFAULT_READ_THRESHOLD;
		ch->write_threshold = DEFAULT_WRITE_THRESHOLD;
		ch->min_write_avail = DEFAULT_MIN_WRITE_THRESHOLD;
		ch->is_packet_mode = true;
		ch->peer_tx_buf_size = DEFAULT_PEER_TX_BUF_SIZE;
		ch->poll_delay_msec = 0;

		ch->num = i;

		ch->func = sdio_al_dev->card->sdio_func[ch->num+1];
		ch->rx_pipe_index = ch->num*2;
		ch->tx_pipe_index = ch->num*2+1;

		memset(ch->name, 0, sizeof(ch->name));

		if (header->channel_names[i][0]) {
			memcpy(ch->name, SDIO_PREFIX,
			       strlen(SDIO_PREFIX));
			memcpy(ch->name + strlen(SDIO_PREFIX),
			       header->channel_names[i],
			       PEER_CHANNEL_NAME_SIZE);

			ch->state = SDIO_CHANNEL_STATE_IDLE;
			ch->sdio_al_dev = sdio_al_dev;
		} else {
			ch->state = SDIO_CHANNEL_STATE_INVALID;
		}

		sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME ":Channel=%s, "
				"state=%d\n", ch->name,	ch->state);
	}

	return 0;

exit_err:
	sdio_al_get_into_err_state(sdio_al_dev);
	memset(header, 0, sizeof(*header));

	return -EIO;
}

/**
 *  Read SDIO-Client channel configuration
 *
 */
static int read_sdioc_channel_config(struct sdio_channel *ch)
{
	int ret;
	struct peer_sdioc_sw_mailbox *sw_mailbox = NULL;
	struct peer_sdioc_channel_config *ch_config = NULL;
	struct sdio_al_device *sdio_al_dev = ch->sdio_al_dev;

	if (sdio_al_dev == NULL) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": NULL sdio_al_dev"
				" for channel %s\n", ch->name);
		return -EINVAL;
	}

	if (sdio_al_dev->sdioc_sw_header->version == 0)
		return -1;

	pr_debug(MODULE_NAME ":reading sw mailbox %s channel.\n", ch->name);

	sw_mailbox = kzalloc(sizeof(*sw_mailbox), GFP_KERNEL);
	if (sw_mailbox == NULL)
		return -ENOMEM;

	ret = sdio_memcpy_fromio(ch->func, sw_mailbox,
			SDIOC_SW_MAILBOX_ADDR, sizeof(*sw_mailbox));
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":fail to read "
				"sw mailbox.\n");
		goto exit_err;
	}

	ch_config = &sw_mailbox->ch_config[ch->num];
	memcpy(&ch->ch_config, ch_config,
		sizeof(struct peer_sdioc_channel_config));

	if (!ch_config->is_ready) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":sw mailbox "
				"channel not ready.\n");
		goto exit_err;
	}

	/* Aggregation up to 90% of the maximum size */
	ch->read_threshold = (ch_config->max_rx_threshold * 9) / 10;
	/* Threshold on 50% of the maximum size , sdioc uses double-buffer */
	ch->write_threshold = (ch_config->max_tx_threshold * 5) / 10;
	ch->threshold_change_cnt = ch->ch_config.max_rx_threshold -
			ch->read_threshold + THRESHOLD_CHANGE_EXTRA_BYTES;

	ch->def_read_threshold = ch->read_threshold;
	ch->is_packet_mode = ch_config->is_packet_mode;
	if (!ch->is_packet_mode) {
		ch->poll_delay_msec = DEFAULT_POLL_DELAY_NOPACKET_MSEC;
		ch->min_write_avail = DEFAULT_MIN_WRITE_THRESHOLD_STREAMING;
	}
	/* The max_packet_size is set by the modem in version 3 and on */
	if (sdio_al->sdioc_major > PEER_SDIOC_OLD_VERSION_MAJOR)
		ch->min_write_avail = ch_config->max_packet_size;

	if (ch->min_write_avail > ch->write_threshold)
		ch->min_write_avail = ch->write_threshold;

	CLOSE_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ":ch %s "
			"read_threshold=%d, write_threshold=%d,"
			" min_write_avail=%d, max_rx_threshold=%d,"
			" max_tx_threshold=%d\n", ch->name, ch->read_threshold,
			ch->write_threshold, ch->min_write_avail,
			ch_config->max_rx_threshold,
			ch_config->max_tx_threshold);

	ch->peer_tx_buf_size = ch_config->tx_buf_size;

	kfree(sw_mailbox);

	return 0;

exit_err:
	sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME ":Reading SW Mailbox "
			"error.\n");
	kfree(sw_mailbox);

	return -1;
}


/**
 *  Enable/Disable EOT interrupt of a pipe.
 *
 */
static int enable_eot_interrupt(struct sdio_al_device *sdio_al_dev,
				int pipe_index, int enable)
{
	int ret = 0;
	struct sdio_func *func1;
	u32 mask;
	u32 pipe_mask;
	u32 addr;

	if (sdio_al_verify_func1(sdio_al_dev, __func__))
		return -ENODEV;
	func1 = sdio_al_dev->card->sdio_func[0];

	if (pipe_index < 8) {
		addr = PIPES_0_7_IRQ_MASK_ADDR;
		pipe_mask = (1<<pipe_index);
	} else {
		addr = PIPES_8_15_IRQ_MASK_ADDR;
		pipe_mask = (1<<(pipe_index-8));
	}

	mask = sdio_readl(func1, addr, &ret);
	if (ret) {
		pr_debug(MODULE_NAME ":enable_eot_interrupt fail\n");
		goto exit_err;
	}

	if (enable)
		mask &= (~pipe_mask); /* 0 = enable */
	else
		mask |= (pipe_mask);  /* 1 = disable */

	sdio_writel(func1, mask, addr, &ret);

exit_err:
	return ret;
}


/**
 *  Enable/Disable mask interrupt of a function.
 *
 */
static int enable_mask_irq(struct sdio_al_device *sdio_al_dev,
			   int func_num, int enable, u8 bit_offset)
{
	int ret = 0;
	struct sdio_func *func1 = NULL;
	u32 mask = 0;
	u32 func_mask = 0;
	u32 addr = 0;
	u32 offset = 0;

	if (sdio_al_verify_func1(sdio_al_dev, __func__))
		return -ENODEV;
	func1 = sdio_al_dev->card->sdio_func[0];

	if (func_num < 4) {
		addr = FUNC_1_4_MASK_IRQ_ADDR;
		offset = func_num * 8 + bit_offset;
	} else {
		addr = FUNC_5_7_MASK_IRQ_ADDR;
		offset = (func_num - 4) * 8 + bit_offset;
	}

	func_mask = 1<<offset;

	mask = sdio_readl(func1, addr, &ret);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": "
				"enable_mask_irq fail\n");
		goto exit_err;
	}

	if (enable)
		mask &= (~func_mask); /* 0 = enable */
	else
		mask |= (func_mask);  /* 1 = disable */

	pr_debug(MODULE_NAME ":enable_mask_irq,  writing mask = 0x%x\n", mask);

	sdio_writel(func1, mask, addr, &ret);

exit_err:
	return ret;
}

/**
 *  Enable/Disable Threshold interrupt of a pipe.
 *
 */
static int enable_threshold_interrupt(struct sdio_al_device *sdio_al_dev,
				      int pipe_index, int enable)
{
	int ret = 0;
	struct sdio_func *func1;
	u32 mask;
	u32 pipe_mask;
	u32 addr;

	if (sdio_al_verify_func1(sdio_al_dev, __func__))
		return -ENODEV;
	func1 = sdio_al_dev->card->sdio_func[0];

	if (pipe_index < 8) {
		addr = PIPES_0_7_IRQ_MASK_ADDR;
		pipe_mask = (1<<pipe_index);
	} else {
		addr = PIPES_8_15_IRQ_MASK_ADDR;
		pipe_mask = (1<<(pipe_index-8));
	}

	mask = sdio_readl(func1, addr, &ret);
	if (ret) {
		pr_debug(MODULE_NAME ":enable_threshold_interrupt fail\n");
		goto exit_err;
	}

	pipe_mask = pipe_mask<<8; /* Threshold bits 8..15 */
	if (enable)
		mask &= (~pipe_mask); /* 0 = enable */
	else
		mask |= (pipe_mask);  /* 1 = disable */

	sdio_writel(func1, mask, addr, &ret);

exit_err:
	return ret;
}

/**
 *  Set the threshold to trigger interrupt from SDIO-Card on
 *  pipe available bytes.
 *
 */
static int set_pipe_threshold(struct sdio_al_device *sdio_al_dev,
			      int pipe_index, int threshold)
{
	int ret = 0;
	struct sdio_func *func1;

	if (sdio_al_verify_func1(sdio_al_dev, __func__))
		return -ENODEV;
	func1 = sdio_al_dev->card->sdio_func[0];

	sdio_writel(func1, threshold,
			PIPES_THRESHOLD_ADDR+pipe_index*4, &ret);
	if (ret)
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": "
				"set_pipe_threshold err=%d\n", -ret);

	return ret;
}

/**
 *  Enable func w/ retries
 *
 */
static int sdio_al_enable_func_retry(struct sdio_func *func, const char *name)
{
	int ret, i;
	for (i = 0; i < 200; i++) {
		ret = sdio_enable_func(func);
		if (ret) {
			pr_debug(MODULE_NAME ":retry enable %s func#%d "
					     "ret=%d\n",
					 name, func->num, ret);
			msleep(10);
		} else
			break;
	}

	return ret;
}

/**
 *  Open Channel
 *
 *  1. Init Channel Context.
 *  2. Init the Channel SDIO-Function.
 *  3. Init the Channel Pipes on Mailbox.
 */
static int open_channel(struct sdio_channel *ch)
{
	int ret = 0;
	struct sdio_al_device *sdio_al_dev = ch->sdio_al_dev;

	if (sdio_al_dev == NULL) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": NULL "
				"sdio_al_dev for channel %s\n", ch->name);
		return -EINVAL;
	}

	/* Init channel Context */
	/** Func#1 is reserved for mailbox */
	ch->func = sdio_al_dev->card->sdio_func[ch->num+1];
	ch->rx_pipe_index = ch->num*2;
	ch->tx_pipe_index = ch->num*2+1;
	ch->signature = SDIO_AL_SIGNATURE;

	ch->total_rx_bytes = 0;
	ch->total_tx_bytes = 0;

	ch->write_avail = 0;
	ch->read_avail = 0;
	ch->rx_pending_bytes = 0;

	mutex_init(&ch->ch_lock);

	pr_debug(MODULE_NAME ":open_channel %s func#%d\n",
			 ch->name, ch->func->num);

	INIT_LIST_HEAD(&(ch->rx_size_list_head));

	/* Init SDIO Function */
	ret = sdio_al_enable_func_retry(ch->func, ch->name);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": "
				"sdio_enable_func() err=%d\n", -ret);
		goto exit_err;
	}

	/* Note: Patch Func CIS tuple issue */
	ret = sdio_set_block_size(ch->func, SDIO_AL_BLOCK_SIZE);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": "
				"sdio_set_block_size()failed, err=%d\n", -ret);
		goto exit_err;
	}

	ch->func->max_blksize = SDIO_AL_BLOCK_SIZE;

	sdio_set_drvdata(ch->func, ch);

	/* Get channel parameters from the peer SDIO-Client */
	read_sdioc_channel_config(ch);

	/* Set Pipes Threshold on Mailbox */
	ret = set_pipe_threshold(sdio_al_dev,
				 ch->rx_pipe_index, ch->read_threshold);
	if (ret)
		goto exit_err;
	ret = set_pipe_threshold(sdio_al_dev,
				 ch->tx_pipe_index, ch->write_threshold);
	if (ret)
		goto exit_err;

	/* Set flag before interrupts are enabled to allow notify */
	ch->state = SDIO_CHANNEL_STATE_OPEN;
	pr_debug(MODULE_NAME ":channel %s is in OPEN state now\n", ch->name);

	sdio_al_dev->poll_delay_msec = get_min_poll_time_msec(sdio_al_dev);

	/* lpm mechanism lives under the assumption there is always a timer */
	/* Check if need to start the timer */
	if  ((sdio_al_dev->poll_delay_msec) &&
	     (sdio_al_dev->is_timer_initialized == false)) {

		init_timer(&sdio_al_dev->timer);
		sdio_al_dev->timer.data = (unsigned long) sdio_al_dev;
		sdio_al_dev->timer.function = sdio_al_timer_handler;
		sdio_al_dev->timer.expires = jiffies +
			msecs_to_jiffies(sdio_al_dev->poll_delay_msec);
		add_timer(&sdio_al_dev->timer);
		sdio_al_dev->is_timer_initialized = true;
	}

	/* Enable Pipes Interrupts */
	enable_eot_interrupt(sdio_al_dev, ch->rx_pipe_index, true);
	enable_eot_interrupt(sdio_al_dev, ch->tx_pipe_index, true);

	enable_threshold_interrupt(sdio_al_dev, ch->rx_pipe_index, true);
	enable_threshold_interrupt(sdio_al_dev, ch->tx_pipe_index, true);

exit_err:

	return ret;
}

/**
 *  Ask the worker to read the mailbox.
 */
static void ask_reading_mailbox(struct sdio_al_device *sdio_al_dev)
{
	if (!sdio_al_dev->ask_mbox) {
		pr_debug(MODULE_NAME ":ask_reading_mailbox for card %d\n",
			 sdio_al_dev->host->index);
		sdio_al_dev->ask_mbox = true;
		wake_up(&sdio_al_dev->wait_mbox);
	}
}

/**
 *  Start the timer
 */
static void start_timer(struct sdio_al_device *sdio_al_dev)
{
	if ((sdio_al_dev->poll_delay_msec)  &&
		(sdio_al_dev->state == CARD_INSERTED)) {
		sdio_al_dev->timer.expires = jiffies +
			msecs_to_jiffies(sdio_al_dev->poll_delay_msec);
		add_timer(&sdio_al_dev->timer);
	}
}

/**
 *  Restart(postpone) the already working timer
 */
static void restart_timer(struct sdio_al_device *sdio_al_dev)
{
	if ((sdio_al_dev->poll_delay_msec) &&
		(sdio_al_dev->state == CARD_INSERTED)) {
		ulong expires =	jiffies +
			msecs_to_jiffies(sdio_al_dev->poll_delay_msec);
		mod_timer(&sdio_al_dev->timer, expires);
	}
}

/**
 *  Stop and delete the timer
 */
static void stop_and_del_timer(struct sdio_al_device *sdio_al_dev)
{
	if (sdio_al_dev->is_timer_initialized) {
		sdio_al_dev->poll_delay_msec = 0;
		del_timer_sync(&sdio_al_dev->timer);
	}
}

/**
 *  Do the wakup sequence.
 *  This function should be called after claiming the host!
 *  The caller is responsible for releasing the host.
 *
 *  Wake up sequence
 *  1. Get lock
 *  2. Enable wake up function if needed
 *  3. Mark NOT OK to sleep and write it
 *  4. Restore default thresholds
 *  5. Start the mailbox and inactivity timer again
 */
static int sdio_al_wake_up(struct sdio_al_device *sdio_al_dev,
			   u32 not_from_int, struct sdio_channel *ch)
{
	int ret = 0;
	struct sdio_func *wk_func = NULL;
	unsigned long time_to_wait;
	struct mmc_host *host = sdio_al_dev->host;

	if (sdio_al_dev->is_err) {
		SDIO_AL_ERR(__func__);
		return -ENODEV;
	}

	if (!sdio_al_dev->is_ok_to_sleep) {
		LPM_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ":card %d "
				"already awake, no need to wake up\n",
				sdio_al_dev->host->index);
		return 0;
	}

	/* Wake up sequence */
	if (not_from_int) {
		if (ch) {
			LPM_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ": Wake up"
					" card %d (not by interrupt), ch %s",
					sdio_al_dev->host->index,
					ch->name);
		} else {
			LPM_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ": Wake up"
					  " card %d (not	by interrupt)",
					  sdio_al_dev->host->index);
		}
	} else {
		LPM_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ": Wake up card "
				"%d by interrupt",
				sdio_al_dev->host->index);
		sdio_al_dev->print_after_interrupt = 1;
	}

	sdio_al_vote_for_sleep(sdio_al_dev, 0);

	msmsdcc_lpm_disable(host);
	msmsdcc_set_pwrsave(host, 0);
	/* Poll the GPIO */
	time_to_wait = jiffies + msecs_to_jiffies(1000);
	while (time_before(jiffies, time_to_wait)) {
		if (sdio_al->pdata->get_mdm2ap_status())
			break;
		udelay(TIME_TO_WAIT_US);
	}

	pr_debug(MODULE_NAME ":GPIO mdm2ap_status=%d\n",
		       sdio_al->pdata->get_mdm2ap_status());

	/* Here get_mdm2ap_status() returning 0 is not an error condition */
	if (sdio_al->pdata->get_mdm2ap_status() == 0)
		LPM_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ": "
				"get_mdm2ap_status() is 0\n");

	/* Enable Wake up Function */
	if (!sdio_al_dev->card ||
	    !sdio_al_dev->card->sdio_func[SDIO_AL_WAKEUP_FUNC-1]) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
				": NULL card or wk_func\n");
		return -ENODEV;
	}
	wk_func = sdio_al_dev->card->sdio_func[SDIO_AL_WAKEUP_FUNC-1];
	ret = sdio_al_enable_func_retry(wk_func, "wakeup func");
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": "
				"sdio_enable_func() err=%d\n", -ret);
		goto error_exit;
	}
	/* Mark NOT OK_TOSLEEP */
	sdio_al_dev->is_ok_to_sleep = 0;
	ret = write_lpm_info(sdio_al_dev);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": "
				"write_lpm_info() failed, err=%d\n", -ret);
		sdio_al_dev->is_ok_to_sleep = 1;
		sdio_disable_func(wk_func);
		goto error_exit;
	}
	sdio_disable_func(wk_func);

	/* Start the timer again*/
	restart_inactive_time(sdio_al_dev);
	sdio_al_dev->poll_delay_msec = get_min_poll_time_msec(sdio_al_dev);
	start_timer(sdio_al_dev);

	LPM_DEBUG(sdio_al_dev->dev_log, MODULE_NAME "Finished Wake up sequence"
			" for card %d", sdio_al_dev->host->index);

	msmsdcc_set_pwrsave(host, 1);
	pr_debug(MODULE_NAME ":Turn clock off\n");

	return ret;
error_exit:
	sdio_al_vote_for_sleep(sdio_al_dev, 1);
	msmsdcc_set_pwrsave(host, 1);
	WARN_ON(ret);
	sdio_al_get_into_err_state(sdio_al_dev);
	return ret;
}


/**
 *  SDIO Function Interrupt handler.
 *
 *  Interrupt shall be triggered by SDIO-Client when:
 *  1. End-Of-Transfer (EOT) detected in packet mode.
 *  2. Bytes-available reached the threshold.
 *
 *  Reading the mailbox clears the EOT/Threshold interrupt
 *  source.
 *  The interrupt source should be cleared before this ISR
 *  returns. This ISR is called from IRQ Thread and not
 *  interrupt, so it may sleep.
 *
 */
static void sdio_func_irq(struct sdio_func *func)
{
	struct sdio_al_device *sdio_al_dev = sdio_get_drvdata(func);

	pr_debug(MODULE_NAME ":start %s.\n", __func__);

	if (sdio_al_dev == NULL) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": NULL device");
		return;
	}

	if (sdio_al_dev->is_ok_to_sleep)
		sdio_al_wake_up(sdio_al_dev, 0, NULL);
	else
		restart_timer(sdio_al_dev);

	read_mailbox(sdio_al_dev, true);

	pr_debug(MODULE_NAME ":end %s.\n", __func__);
}

/**
 *  Timer Expire Handler
 *
 */
static void sdio_al_timer_handler(unsigned long data)
{
	struct sdio_al_device *sdio_al_dev = (struct sdio_al_device *)data;
	if (sdio_al_dev == NULL) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": NULL "
				"sdio_al_dev for data %lu\n", data);
		return;
	}
	if (sdio_al_dev->state != CARD_INSERTED) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": sdio_al_dev "
				"is in invalid state %d\n", sdio_al_dev->state);
		return;
	}
	pr_debug(MODULE_NAME " Timer Expired\n");

	ask_reading_mailbox(sdio_al_dev);

	restart_timer(sdio_al_dev);
}

/**
 *  Driver Setup.
 *
 */
static int sdio_al_setup(struct sdio_al_device *sdio_al_dev)
{
	int ret = 0;
	struct mmc_card *card = sdio_al_dev->card;
	struct sdio_func *func1 = NULL;
	int i = 0;
	int fn = 0;

	if (sdio_al_verify_func1(sdio_al_dev, __func__))
		return -ENODEV;
	func1 = card->sdio_func[0];

	sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME ":sdio_al_setup for "
			"card %d\n", sdio_al_dev->host->index);

	ret = sdio_al->pdata->config_mdm2ap_status(1);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME "Could not "
				"request GPIO\n");
		return ret;
	}

	INIT_WORK(&sdio_al_dev->sdio_al_work.work, worker);
	/* disable all pipes interrupts before claim irq.
	   since all are enabled by default. */
	for (i = 0 ; i < SDIO_AL_MAX_PIPES; i++) {
		enable_eot_interrupt(sdio_al_dev, i, false);
		enable_threshold_interrupt(sdio_al_dev, i, false);
	}

	/* Disable all SDIO Functions before claim irq. */
	for (fn = 1 ; fn <= card->sdio_funcs; fn++)
		sdio_disable_func(card->sdio_func[fn-1]);

	sdio_set_drvdata(func1, sdio_al_dev);
	sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME ":claim IRQ for card "
			"%d\n",	sdio_al_dev->host->index);

	ret = sdio_claim_irq(func1, sdio_func_irq);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":Fail to claim"
				" IRQ for card %d\n",
				sdio_al_dev->host->index);
		return ret;
	}

	sdio_al_dev->is_ready = true;

	/* Start worker before interrupt might happen */
	queue_work(sdio_al_dev->workqueue, &sdio_al_dev->sdio_al_work.work);

	start_inactive_time(sdio_al_dev);

	pr_debug(MODULE_NAME ":Ready.\n");

	return 0;
}

/**
 *  Driver Tear-Down.
 *
 */
static void sdio_al_tear_down(void)
{
	int i, j;
	struct sdio_al_device *sdio_al_dev = NULL;
	struct sdio_func *func1;

	for (i = 0; i < MAX_NUM_OF_SDIO_DEVICES; ++i) {
		if (sdio_al->devices[i] == NULL)
			continue;
		sdio_al_dev = sdio_al->devices[i];

		if (sdio_al_dev->is_ready) {
			sdio_al_dev->is_ready = false; /* Flag worker to exit */
			sdio_al_dev->ask_mbox = false;
			ask_reading_mailbox(sdio_al_dev); /* Wakeup worker */
			/* allow gracefully exit of the worker thread */
			msleep(100);

			flush_workqueue(sdio_al_dev->workqueue);
			destroy_workqueue(sdio_al_dev->workqueue);

			sdio_al_vote_for_sleep(sdio_al_dev, 1);

			if (!sdio_al_claim_mutex_and_verify_dev(sdio_al_dev,
								__func__)) {
				if (!sdio_al_dev->card ||
				    !sdio_al_dev->card->sdio_func[0]) {
					sdio_al_loge(sdio_al_dev->dev_log,
						     MODULE_NAME
							": %s: Invalid func1",
							__func__);
					return;
				}
				func1 = sdio_al_dev->card->sdio_func[0];
				sdio_release_irq(func1);
				sdio_disable_func(func1);
				sdio_al_release_mutex(sdio_al_dev, __func__);
			}
		}

		for (j = 0; j < SDIO_AL_MAX_CHANNELS; j++)
			sdio_al_dev->channel[j].signature = 0x0;
		sdio_al_dev->signature = 0;

		kfree(sdio_al_dev->sdioc_sw_header);
		kfree(sdio_al_dev->mailbox);
		kfree(sdio_al_dev->rx_flush_buf);
		kfree(sdio_al_dev);
	}

	sdio_al->pdata->config_mdm2ap_status(0);
}

/**
 *  Find channel by name.
 *
 */
static struct sdio_channel *find_channel_by_name(const char *name)
{
	struct sdio_channel *ch = NULL;
	int i, j;
	struct sdio_al_device *sdio_al_dev = NULL;

	for (j = 0; j < MAX_NUM_OF_SDIO_DEVICES; ++j) {
		if (sdio_al->devices[j] == NULL)
			continue;
		sdio_al_dev = sdio_al->devices[j];
		for (i = 0; i < SDIO_AL_MAX_CHANNELS; i++) {
			if (sdio_al_dev->channel[i].state ==
					SDIO_CHANNEL_STATE_INVALID)
				continue;
			if (strcmp(sdio_al_dev->channel[i].name, name) == 0) {
				ch = &sdio_al_dev->channel[i];
				break;
			}
		}
		if (ch != NULL)
			break;
	}

	return ch;
}

/**
 *  Find the minimal poll time.
 *
 */
static int get_min_poll_time_msec(struct sdio_al_device *sdio_sl_dev)
{
	int i;
	int poll_delay_msec = 0x0FFFFFFF;

	for (i = 0; i < SDIO_AL_MAX_CHANNELS; i++)
		if ((sdio_sl_dev->channel[i].state ==
					SDIO_CHANNEL_STATE_OPEN) &&
		(sdio_sl_dev->channel[i].poll_delay_msec > 0) &&
		(sdio_sl_dev->channel[i].poll_delay_msec < poll_delay_msec))
			poll_delay_msec =
				sdio_sl_dev->channel[i].poll_delay_msec;

	if (poll_delay_msec == 0x0FFFFFFF)
		poll_delay_msec = SDIO_AL_POLL_TIME_NO_STREAMING;

	pr_debug(MODULE_NAME ":poll delay time is %d msec\n", poll_delay_msec);

	return poll_delay_msec;
}

/**
 *  Open SDIO Channel.
 *
 *  Enable the channel.
 *  Set the channel context.
 *  Trigger reading the mailbox to check available bytes.
 *
 */
int sdio_open(const char *name, struct sdio_channel **ret_ch, void *priv,
		 void (*notify)(void *priv, unsigned ch_event))
{
	int ret = 0;
	struct sdio_channel *ch = NULL;
	struct sdio_al_device *sdio_al_dev = NULL;

	*ret_ch = NULL; /* default */

	ch = find_channel_by_name(name);
	if (ch == NULL) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":Can't find "
			"channel name %s\n", name);
		return -EINVAL;
	}

	sdio_al_dev = ch->sdio_al_dev;
	if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
		return -ENODEV;

	if ((ch->state != SDIO_CHANNEL_STATE_IDLE) &&
		(ch->state != SDIO_CHANNEL_STATE_CLOSED)) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":Wrong ch %s "
				"state %d\n", name, ch->state);
		ret = -EPERM;
		goto exit_err;
	}

	if (sdio_al_dev->is_err) {
		SDIO_AL_ERR(__func__);
		ret = -ENODEV;
		goto exit_err;
	}

	ret = sdio_al_wake_up(sdio_al_dev, 1, ch);
	if (ret)
		goto exit_err;

	ch->notify = notify;
	ch->priv = priv;

	/* Note: Set caller returned context before interrupts are enabled */
	*ret_ch = ch;

	ret = open_channel(ch);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":sdio_open %s "
				"err=%d\n", name, -ret);
		goto exit_err;
	}

	CLOSE_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ":sdio_open %s "
							"completed OK\n", name);
	if (sdio_al_dev->lpm_chan == INVALID_SDIO_CHAN) {
		if (sdio_al->sdioc_major == PEER_SDIOC_OLD_VERSION_MAJOR) {
			if (!ch->is_packet_mode) {
				sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME
						":setting channel %s as "
						"lpm_chan\n", name);
				sdio_al_dev->lpm_chan = ch->num;
			}
		} else {
			sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME ": "
					"setting channel %s as lpm_chan\n",
					name);
			sdio_al_dev->lpm_chan = ch->num;
		}
	}

exit_err:
	sdio_al_release_mutex(sdio_al_dev, __func__);
	return ret;
}
EXPORT_SYMBOL(sdio_open);

/**
 *  Request peer operation
 *  note: sanity checks of parameters done by caller
 *        called under bus locked
 */
static int peer_set_operation(u32 opcode,
		struct sdio_al_device *sdio_al_dev,
		struct sdio_channel *ch)
{
	int ret;
	int offset;
	struct sdio_func *wk_func;
	u32 peer_operation;
	int loop_count = 0;

	wk_func = sdio_al_dev->card->sdio_func[SDIO_AL_WAKEUP_FUNC-1];
	if (!wk_func) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":%s: NULL "
				"wakeup func:%d\n", __func__,
				SDIO_AL_WAKEUP_FUNC);
		ret = -ENODEV;
		goto exit;
	}
	/* calculate offset of peer_operation field in sw mailbox struct */
	offset = offsetof(struct peer_sdioc_sw_mailbox, ch_config) +
		sizeof(struct peer_sdioc_channel_config) * ch->num +
		offsetof(struct peer_sdioc_channel_config, peer_operation);

	ret = sdio_al_wake_up(sdio_al_dev, 1, ch);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":Fail to "
				"wake up\n");
		goto exit;
	}
	/* request operation from MDM peer */
	peer_operation = PEER_OPERATION(opcode, PEER_OP_STATE_INIT);
	ret = sdio_memcpy_toio(ch->func, SDIOC_SW_MAILBOX_ADDR+offset,
			&peer_operation, sizeof(u32));
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":failed to "
				"request close operation\n");
		goto exit;
	}
	ret = sdio_al_enable_func_retry(wk_func, "wk_func");
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":Fail to enable"
				" Func#%d\n", wk_func->num);
		goto exit;
	}
	pr_debug(MODULE_NAME ":%s: wk_func enabled on ch %s\n",
			__func__, ch->name);
	/* send "start" operation to MDM */
	peer_operation = PEER_OPERATION(opcode, PEER_OP_STATE_START);
	ret  =  sdio_memcpy_toio(ch->func, SDIOC_SW_MAILBOX_ADDR+offset,
			&peer_operation, sizeof(u32));
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":failed to "
				"send start close operation\n");
		goto exit;
	}
	ret = sdio_disable_func(wk_func);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":Fail to "
				"disable Func#%d\n", wk_func->num);
		goto exit;
	}
	/* poll for peer operation ack */
	while (peer_operation != 0) {
		ret  =  sdio_memcpy_fromio(ch->func,
				&peer_operation,
				SDIOC_SW_MAILBOX_ADDR+offset,
				sizeof(u32));
		if (ret) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
					":failed to request ack on close"
					" operation, loop_count = %d\n",
					loop_count);
			goto exit;
		}
		loop_count++;
		if (loop_count > 10) {
			sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME ":%s: "
					"peer_operation=0x%x wait loop"
					" %d on ch %s\n", __func__,
					peer_operation, loop_count, ch->name);
		}
	}
exit:
	return ret;
}

static int channel_close(struct sdio_channel *ch, int flush_flag)
{
	int ret;
	struct sdio_al_device *sdio_al_dev = NULL;
	int flush_len;
	ulong flush_expires;

	if (!ch) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":%s: NULL "
				"channel\n",  __func__);
		return -ENODEV;
	}

	if (!ch->func) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":%s: NULL func"
				" on channel:%d\n", __func__, ch->num);
		return -ENODEV;
	}

	sdio_al_dev = ch->sdio_al_dev;
	if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
		return -ENODEV;

	if (!sdio_al_dev->ch_close_supported) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":%s: Not "
			"supported by mdm, ch %s\n",
			__func__, ch->name);
		ret = -ENOTSUPP;
		goto error_exit;
	}

	if (sdio_al_dev->is_err) {
		SDIO_AL_ERR(__func__);
		ret = -ENODEV;
		goto error_exit;
	}
	if (ch->state != SDIO_CHANNEL_STATE_OPEN) {
		sdio_al_loge(sdio_al_dev->dev_log,
				MODULE_NAME ":%s: ch %s is not in "
				"open state (%d)\n",
				__func__, ch->name, ch->state);
		ret = -ENODEV;
		goto error_exit;
	}
	ch->state = SDIO_CHANNEL_STATE_CLOSING;
	ret = peer_set_operation(PEER_OP_CODE_CLOSE, sdio_al_dev, ch);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":%s: "
				"peer_set_operation() failed: %d\n",
				__func__, ret);
		ret = -ENODEV;
		goto error_exit;
	}
	/* udate poll time for opened channels */
	if  (ch->poll_delay_msec > 0) {
		sdio_al_dev->poll_delay_msec =
			get_min_poll_time_msec(sdio_al_dev);
	}
	sdio_al_release_mutex(ch->sdio_al_dev, __func__);

	flush_expires = jiffies +
		msecs_to_jiffies(SDIO_CLOSE_FLUSH_TIMEOUT_MSEC);
	/* flush rx packets of the channel */
	if (flush_flag) {
		do {
			while (ch->read_avail > 0) {
				flush_len = ch->read_avail;
				ret = sdio_read_internal(ch,
						sdio_al_dev->rx_flush_buf,
						flush_len);
				if (ret) {
					sdio_al_loge(&sdio_al->gen_log,
						MODULE_NAME ":%s sdio_read"
						" failed: %d, ch %s\n",
						__func__, ret,
						ch->name);
					return ret;
				}

				if (time_after(jiffies, flush_expires) != 0) {
					sdio_al_loge(&sdio_al->gen_log,
						MODULE_NAME ":%s flush rx "
						"packets timeout: ch %s\n",
						__func__, ch->name);
					sdio_al_get_into_err_state(sdio_al_dev);
					return -EBUSY;
				}
			}
			msleep(100);
			if (ch->signature != SDIO_AL_SIGNATURE) {
					sdio_al_loge(&sdio_al->gen_log,
						MODULE_NAME ":%s: after sleep,"
						" invalid signature"
						" 0x%x\n", __func__,
						ch->signature);
				return -ENODEV;
			}
			if (sdio_al_claim_mutex_and_verify_dev(ch->sdio_al_dev,
							       __func__))
				return -ENODEV;

			ret = read_mailbox(sdio_al_dev, false);
			if (ret) {
				sdio_al_loge(&sdio_al->gen_log,
						MODULE_NAME ":%s: failed to"
						" read mailbox", __func__);
				goto error_exit;
			}
			sdio_al_release_mutex(ch->sdio_al_dev, __func__);
		} while (ch->read_avail > 0);
	}
	if (sdio_al_claim_mutex_and_verify_dev(ch->sdio_al_dev,
					       __func__))
		return -ENODEV;
	/* disable function to be able to open the channel again */
	ret = sdio_disable_func(ch->func);
	if (ret) {
		sdio_al_loge(&sdio_al->gen_log,
			MODULE_NAME ":Fail to disable Func#%d\n",
			ch->func->num);
		goto error_exit;
	}
	ch->state = SDIO_CHANNEL_STATE_CLOSED;
	CLOSE_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ":%s: Ch %s closed "
				"successfully\n", __func__, ch->name);

error_exit:
	sdio_al_release_mutex(ch->sdio_al_dev, __func__);

	return ret;
}

/**
 *  Close SDIO Channel.
 *
 */
int sdio_close(struct sdio_channel *ch)
{
	return channel_close(ch, true);
}
EXPORT_SYMBOL(sdio_close);

/**
 *  Get the number of available bytes to write.
 *
 */
int sdio_write_avail(struct sdio_channel *ch)
{
	if (!ch) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":%s: NULL "
				"channel\n", __func__);
		return -ENODEV;
	}
	if (ch->signature != SDIO_AL_SIGNATURE) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":%s: "
				"Invalid signature 0x%x\n",  __func__,
				ch->signature);
		return -ENODEV;
	}
	if (ch->state != SDIO_CHANNEL_STATE_OPEN) {
		sdio_al_loge(ch->sdio_al_dev->dev_log, MODULE_NAME ":%s: "
				"channel %s state is not open (%d)\n",
				__func__, ch->name, ch->state);
		return -ENODEV;
	}
	pr_debug(MODULE_NAME ":sdio_write_avail %s 0x%x\n",
			 ch->name, ch->write_avail);

	return ch->write_avail;
}
EXPORT_SYMBOL(sdio_write_avail);

/**
 *  Get the number of available bytes to read.
 *
 */
int sdio_read_avail(struct sdio_channel *ch)
{
	if (!ch) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":%s: NULL "
				"channel\n", __func__);
		return -ENODEV;
	}
	if (ch->signature != SDIO_AL_SIGNATURE) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":%s: "
				"Invalid signature 0x%x\n",  __func__,
				ch->signature);
		return -ENODEV;
	}
	if (ch->state != SDIO_CHANNEL_STATE_OPEN) {
		sdio_al_loge(ch->sdio_al_dev->dev_log, MODULE_NAME ":%s: "
				"channel %s state is not open (%d)\n",
				__func__, ch->name, ch->state);
		return -ENODEV;
	}
	pr_debug(MODULE_NAME ":sdio_read_avail %s 0x%x\n",
			 ch->name, ch->read_avail);

	return ch->read_avail;
}
EXPORT_SYMBOL(sdio_read_avail);

static int sdio_read_from_closed_ch(struct sdio_channel *ch, int len)
{
	int ret = 0;
	struct sdio_al_device *sdio_al_dev = NULL;

	if (!ch) {
		sdio_al_loge(ch->sdio_al_dev->dev_log,
			MODULE_NAME ":%s: NULL channel\n",  __func__);
		return -ENODEV;
	}

	sdio_al_dev = ch->sdio_al_dev;
	if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
		return -ENODEV;

	ret = sdio_memcpy_fromio(ch->func, sdio_al_dev->rx_flush_buf,
				 PIPE_RX_FIFO_ADDR, len);

	if (ret) {
		sdio_al_loge(ch->sdio_al_dev->dev_log,
				MODULE_NAME ":ch %s: %s err=%d, len=%d\n",
				ch->name, __func__, -ret, len);
		sdio_al_dev->is_err = true;
		sdio_al_release_mutex(sdio_al_dev, __func__);
		return ret;
	}

	restart_inactive_time(sdio_al_dev);

	sdio_al_release_mutex(sdio_al_dev, __func__);

	return 0;
}

/**
 *  Internal read from SDIO Channel.
 *
 *  Reading from the pipe will trigger interrupt if there are
 *  other pending packets on the SDIO-Client.
 *
 */
static int sdio_read_internal(struct sdio_channel *ch, void *data, int len)
{
	int ret = 0;
	struct sdio_al_device *sdio_al_dev = NULL;

	if (!ch) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":%s: NULL "
				"channel\n",  __func__);
		return -ENODEV;
	}
	if (!data) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":%s: NULL data\n",
				__func__);
		return -ENODEV;
	}
	if (len == 0) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":channel %s trying"
				" to read 0 bytes\n", ch->name);
		return -EINVAL;
	}

	if (ch->signature != SDIO_AL_SIGNATURE) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":%s: Invalid "
				"signature 0x%x\n",  __func__, ch->signature);
		return -ENODEV;
	}

	sdio_al_dev = ch->sdio_al_dev;
	if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
		return -ENODEV;

	if (sdio_al_dev->is_err) {
		SDIO_AL_ERR(__func__);
		ret = -ENODEV;
		goto exit;
	}

	/* lpm policy says we can't go to sleep when we have pending rx data,
	   so either we had rx interrupt and woken up, or we never went to
	   sleep */
	if (sdio_al_dev->is_ok_to_sleep) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":%s: called "
				"when is_ok_to_sleep is set for ch %s, len=%d,"
				" last_any_read_avail=%d, last_read_avail=%d, "
				"last_old_read_avail=%d", __func__, ch->name,
				len, ch->statistics.last_any_read_avail,
				ch->statistics.last_read_avail,
				ch->statistics.last_old_read_avail);
	}
	BUG_ON(sdio_al_dev->is_ok_to_sleep);

	if ((ch->state != SDIO_CHANNEL_STATE_OPEN) &&
			(ch->state != SDIO_CHANNEL_STATE_CLOSING)) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":%s wrong "
				"channel %s state %d\n",
				__func__, ch->name, ch->state);
		ret = -EINVAL;
		goto exit;
	}

	DATA_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ":start ch %s read %d "
			"avail %d.\n", ch->name, len, ch->read_avail);

	restart_inactive_time(sdio_al_dev);

	if ((ch->is_packet_mode) && (len != ch->read_avail)) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":sdio_read ch "
				"%s len != read_avail\n", ch->name);
		ret = -EINVAL;
		goto exit;
	}

	if (len > ch->read_avail) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":ERR ch %s: "
				"reading more bytes (%d) than the avail(%d).\n",
				ch->name, len, ch->read_avail);
		ret = -ENOMEM;
		goto exit;
	}

	ret = sdio_memcpy_fromio(ch->func, data, PIPE_RX_FIFO_ADDR, len);

	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":ch %s: "
				"sdio_read err=%d, len=%d, read_avail=%d, "
				"last_read_avail=%d, last_old_read_avail=%d\n",
				ch->name, -ret, len, ch->read_avail,
				ch->statistics.last_read_avail,
				ch->statistics.last_old_read_avail);
		sdio_al_get_into_err_state(sdio_al_dev);
		goto exit;
	}

	ch->statistics.total_read_times++;

	/* Remove handled packet from the list regardless if ret is ok */
	if (ch->is_packet_mode)
		remove_handled_rx_packet(ch);
	else
		ch->read_avail -= len;

	ch->total_rx_bytes += len;
	DATA_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ":end ch %s read %d "
			"avail %d total %d.\n", ch->name, len,
			ch->read_avail, ch->total_rx_bytes);

	if ((ch->read_avail == 0) && !(ch->is_packet_mode))
		ask_reading_mailbox(sdio_al_dev);

exit:
	sdio_al_release_mutex(sdio_al_dev, __func__);

	return ret;
}

/**
 *  Read from SDIO Channel.
 *
 *  Reading from the pipe will trigger interrupt if there are
 *  other pending packets on the SDIO-Client.
 *
 */
int sdio_read(struct sdio_channel *ch, void *data, int len)
{
	if (!ch) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":%s: NULL "
				"channel\n", __func__);
		return -ENODEV;
	}
	if (ch->signature != SDIO_AL_SIGNATURE) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":%s: "
			"Invalid signature 0x%x\n",  __func__, ch->signature);
		return -ENODEV;
	}
	if (ch->state == SDIO_CHANNEL_STATE_OPEN) {
		return sdio_read_internal(ch, data, len);
	} else {
		sdio_al_loge(ch->sdio_al_dev->dev_log, MODULE_NAME
				":%s: Invalid channel %s state %d\n",
				__func__, ch->name, ch->state);
	}
	return -ENODEV;
}
EXPORT_SYMBOL(sdio_read);

/**
 *  Write to SDIO Channel.
 *
 */
int sdio_write(struct sdio_channel *ch, const void *data, int len)
{
	int ret = 0;
	struct sdio_al_device *sdio_al_dev = NULL;

	if (!ch) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":%s: NULL "
				"channel\n",  __func__);
		return -ENODEV;
	}
	if (!data) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":%s: NULL data\n",
				__func__);
		return -ENODEV;
	}
	if (len == 0) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":channel %s trying"
				" to write 0 bytes\n", ch->name);
		return -EINVAL;
	}

	if (ch->signature != SDIO_AL_SIGNATURE) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":%s: Invalid "
				"signature 0x%x\n",  __func__, ch->signature);
		return -ENODEV;
	}

	sdio_al_dev = ch->sdio_al_dev;
	if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
		return -ENODEV;

	WARN_ON(len > ch->write_avail);

	if (sdio_al_dev->is_err) {
		SDIO_AL_ERR(__func__);
		ret = -ENODEV;
		goto exit;
	}

	if (ch->state != SDIO_CHANNEL_STATE_OPEN) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":writing to "
				"closed channel %s\n", ch->name);
		ret = -EINVAL;
		goto exit;
	}

	if (sdio_al_dev->is_ok_to_sleep) {
		ret = sdio_al_wake_up(sdio_al_dev, 1, ch);
		if (ret)
			goto exit;
	} else {
		restart_inactive_time(sdio_al_dev);
	}

	DATA_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ":start ch %s write %d "
			"avail %d.\n", ch->name, len, ch->write_avail);

	if (len > ch->write_avail) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":ERR ch %s: "
				"write more bytes (%d) than  available %d.\n",
				ch->name, len, ch->write_avail);
		ret = -ENOMEM;
		goto exit;
	}

	ret = sdio_ch_write(ch, data, len);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":sdio_write "
				"on channel %s err=%d\n", ch->name, -ret);
		goto exit;
	}

	ch->total_tx_bytes += len;
	DATA_DEBUG(sdio_al_dev->dev_log, MODULE_NAME ":end ch %s write %d "
			"avail %d total %d.\n", ch->name, len,
			ch->write_avail, ch->total_tx_bytes);

	/* Round up to whole buffer size */
	len = ROUND_UP(len, ch->peer_tx_buf_size);
	/* Protect from wraparound */
	len = min(len, (int) ch->write_avail);
	ch->write_avail -= len;

	if (ch->write_avail < ch->min_write_avail)
		ask_reading_mailbox(sdio_al_dev);

exit:
	sdio_al_release_mutex(sdio_al_dev, __func__);

	return ret;
}
EXPORT_SYMBOL(sdio_write);

static int __devinit msm_sdio_al_probe(struct platform_device *pdev)
{
	if (!sdio_al) {
		pr_err(MODULE_NAME ": %s: NULL sdio_al\n", __func__);
		return -ENODEV;
	}

	sdio_al->pdata = pdev->dev.platform_data;
	return 0;
}

static int __devexit msm_sdio_al_remove(struct platform_device *pdev)
{
	return 0;
}

static void sdio_al_close_all_channels(struct sdio_al_device *sdio_al_dev)
{
	int j;
	int ret;
	struct sdio_channel *ch = NULL;

	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ": %s", __func__);

	if (!sdio_al_dev) {
		sdio_al_loge(sdio_al_dev->dev_log,
			MODULE_NAME ": %s: NULL device", __func__);
		return;
	}
	for (j = 0; j < SDIO_AL_MAX_CHANNELS; j++) {
		ch = &sdio_al_dev->channel[j];

		if (ch->state == SDIO_CHANNEL_STATE_OPEN) {
			sdio_al_loge(sdio_al_dev->dev_log,
				MODULE_NAME ": %s: Call to sdio_close() for"
				" ch %s\n", __func__, ch->name);
			ret = channel_close(ch, false);
			if (ret) {
				sdio_al_loge(sdio_al_dev->dev_log,
					MODULE_NAME ": %s: failed sdio_close()"
					" for ch %s (%d)\n",
					__func__, ch->name, ret);
			}
		} else {
			pr_debug(MODULE_NAME ": %s: skip sdio_close() ch %s"
					" (state=%d)\n", __func__,
					ch->name, ch->state);
		}
	}
}

static void sdio_al_invalidate_sdio_clients(struct sdio_al_device *sdio_al_dev,
					    struct platform_device **pdev_arr)
{
	int j;

	pr_debug(MODULE_NAME ": %s: Notifying SDIO clients for card %d",
			__func__, sdio_al_dev->host->index);
	for (j = 0; j < SDIO_AL_MAX_CHANNELS; ++j) {
		if (sdio_al_dev->channel[j].state ==
			SDIO_CHANNEL_STATE_INVALID)
			continue;
		pdev_arr[j] = sdio_al_dev->channel[j].pdev;
		sdio_al_dev->channel[j].signature = 0x0;
		sdio_al_dev->channel[j].state =
			SDIO_CHANNEL_STATE_INVALID;
	}
}

static void sdio_al_modem_reset_operations(struct sdio_al_device
							*sdio_al_dev)
{
	int ret = 0;
	struct sdio_func *func1 = NULL;
	struct platform_device *pdev_arr[SDIO_AL_MAX_CHANNELS];
	int j;

	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ": %s", __func__);

	if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
		return;

	if (!sdio_al_dev->card || !sdio_al_dev->card->sdio_func[0]) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: "
			"NULL func1 for card %d", __func__,
			sdio_al_dev->host->index);
		goto exit_err;
	}

	if (sdio_al_dev->state == CARD_REMOVED) {
		sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ": %s: "
			"card %d is already removed", __func__,
			sdio_al_dev->host->index);
		goto exit_err;
	}

	if (sdio_al_dev->state == MODEM_RESTART) {
		sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME ": %s: "
			"card %d was already notified for modem reset",
			__func__, sdio_al_dev->host->index);
		goto exit_err;
	}

	sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME ": %s: Set the "
		"state to MODEM_RESTART for card %d",
		__func__, sdio_al_dev->host->index);
	sdio_al_dev->state = MODEM_RESTART;
	sdio_al_dev->is_ready = false;

	/* Stop mailbox timer */
	stop_and_del_timer(sdio_al_dev);

	if ((sdio_al_dev->is_ok_to_sleep) &&
	    (!sdio_al_dev->is_err)) {
		pr_debug(MODULE_NAME ": %s: wakeup modem for "
				    "card %d", __func__,
			sdio_al_dev->host->index);
		ret = sdio_al_wake_up(sdio_al_dev, 1, NULL);
	}

	if (!ret && (!sdio_al_dev->is_err)) {
		sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME
			": %s: sdio_release_irq for card %d",
			__func__,
			sdio_al_dev->host->index);
		func1 = sdio_al_dev->card->sdio_func[0];
		sdio_release_irq(sdio_al_dev->card->sdio_func[0]);
	}

	memset(pdev_arr, 0, sizeof(pdev_arr));
	sdio_al_invalidate_sdio_clients(sdio_al_dev, pdev_arr);

	sdio_al_release_mutex(sdio_al_dev, __func__);

	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ": %s: Notifying SDIO "
						    "clients for card %d",
			__func__, sdio_al_dev->host->index);
	for (j = 0; j < SDIO_AL_MAX_CHANNELS; j++) {
		if (!pdev_arr[j])
			continue;
		platform_device_unregister(pdev_arr[j]);
	}
	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ": %s: Finished Notifying "
						    "SDIO clients for card %d",
			__func__, sdio_al_dev->host->index);

	return;

exit_err:
	sdio_al_release_mutex(sdio_al_dev, __func__);
	return;
}

#ifdef CONFIG_MSM_SUBSYSTEM_RESTART
static void sdio_al_reset(void)
{
	int i;
	struct sdio_al_device *sdio_al_dev;

	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ": %s", __func__);

	for (i = 0; i < MAX_NUM_OF_SDIO_DEVICES; i++) {
		if (sdio_al->devices[i] == NULL) {
			pr_debug(MODULE_NAME ": %s: NULL device in index %d",
					__func__, i);
			continue;
		}
		sdio_al_dev = sdio_al->devices[i];
		sdio_al_modem_reset_operations(sdio_al->devices[i]);
	}

	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ": %s completed", __func__);
}
#endif

static void msm_sdio_al_shutdown(struct platform_device *pdev)
{
	int i;
	struct sdio_al_device *sdio_al_dev;

	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME
			"Initiating msm_sdio_al_shutdown...");

	for (i = 0; i < MAX_NUM_OF_SDIO_DEVICES; i++) {
		if (sdio_al->devices[i] == NULL) {
			pr_debug(MODULE_NAME ": %s: NULL device in index %d",
					__func__, i);
			continue;
		}
		sdio_al_dev = sdio_al->devices[i];

		if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
			return;

		if (sdio_al_dev->ch_close_supported)
			sdio_al_close_all_channels(sdio_al_dev);

		sdio_al_release_mutex(sdio_al_dev, __func__);

		sdio_al_modem_reset_operations(sdio_al_dev);
	}
	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ": %s: "
		"msm_sdio_al_shutdown complete.", __func__);
}

static struct platform_driver msm_sdio_al_driver = {
	.probe          = msm_sdio_al_probe,
	.remove         = __exit_p(msm_sdio_al_remove),
	.shutdown	= msm_sdio_al_shutdown,
	.driver         = {
		.name   = "msm_sdio_al",
	},
};

/**
 *  Initialize SDIO_AL channels.
 *
 */
static int init_channels(struct sdio_al_device *sdio_al_dev)
{
	int ret = 0;
	int i;

	if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
		return -ENODEV;

	ret = read_sdioc_software_header(sdio_al_dev,
					 sdio_al_dev->sdioc_sw_header);
	if (ret)
		goto exit;

	ret = sdio_al_setup(sdio_al_dev);
	if (ret)
		goto exit;

	for (i = 0; i < SDIO_AL_MAX_CHANNELS; i++) {
		int ch_name_size;
		if (sdio_al_dev->channel[i].state == SDIO_CHANNEL_STATE_INVALID)
			continue;
		if (sdio_al->unittest_mode) {
			memset(sdio_al_dev->channel[i].ch_test_name, 0,
				sizeof(sdio_al_dev->channel[i].ch_test_name));
			ch_name_size = strnlen(sdio_al_dev->channel[i].name,
				       CHANNEL_NAME_SIZE);
			strncpy(sdio_al_dev->channel[i].ch_test_name,
			       sdio_al_dev->channel[i].name,
			       ch_name_size);
			strncat(sdio_al_dev->channel[i].ch_test_name +
			       ch_name_size,
			       SDIO_TEST_POSTFIX,
			       SDIO_TEST_POSTFIX_SIZE);
			pr_debug(MODULE_NAME ":pdev.name = %s\n",
				sdio_al_dev->channel[i].ch_test_name);
			sdio_al_dev->channel[i].pdev = platform_device_alloc(
				sdio_al_dev->channel[i].ch_test_name, -1);
		} else {
			pr_debug(MODULE_NAME ":pdev.name = %s\n",
				sdio_al_dev->channel[i].name);
			sdio_al_dev->channel[i].pdev = platform_device_alloc(
				sdio_al_dev->channel[i].name, -1);
		}
		if (!sdio_al_dev->channel[i].pdev) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
					":NULL platform device for ch %s",
					sdio_al_dev->channel[i].name);
			sdio_al_dev->channel[i].state =
				SDIO_CHANNEL_STATE_INVALID;
			continue;
		}
		ret = platform_device_add(sdio_al_dev->channel[i].pdev);
		if (ret) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
					":platform_device_add failed, "
					"ret=%d\n", ret);
			sdio_al_dev->channel[i].state =
				SDIO_CHANNEL_STATE_INVALID;
		}
	}

exit:
	sdio_al_release_mutex(sdio_al_dev, __func__);
	return ret;
}

/**
 *  Initialize SDIO_AL channels according to the client setup.
 *  This function also check if the client is in boot mode and
 *  flashless boot is required to be activated or the client is
 *  up and running.
 *
 */
static int sdio_al_client_setup(struct sdio_al_device *sdio_al_dev)
{
	int ret = 0;
	struct sdio_func *func1;
	int signature = 0;

	if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
		return -ENODEV;

	if (!sdio_al_dev->card || !sdio_al_dev->card->sdio_func[0]) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":NULL card or "
							       "func1\n");
		sdio_al_release_mutex(sdio_al_dev, __func__);
		return -ENODEV;
	}
	func1 = sdio_al_dev->card->sdio_func[0];

	/* Read the header signature to determine the status of the MDM
	 * SDIO Client
	 */
	signature = sdio_readl(func1, SDIOC_SW_HEADER_ADDR, &ret);
	sdio_al_release_mutex(sdio_al_dev, __func__);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":fail to read "
				"signature from sw header.\n");
		return ret;
	}

	switch (signature) {
	case PEER_SDIOC_SW_MAILBOX_BOOT_SIGNATURE:
		if (sdio_al_dev == sdio_al->bootloader_dev) {
			sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME ":setup "
					"bootloader on card %d\n",
					sdio_al_dev->host->index);
			return sdio_al_bootloader_setup();
		} else {
			sdio_al_logi(sdio_al_dev->dev_log, MODULE_NAME ":wait "
					"for bootloader completion "
					"on card %d\n",
					sdio_al_dev->host->index);
			return sdio_al_wait_for_bootloader_comp(sdio_al_dev);
		}
	case PEER_SDIOC_SW_MAILBOX_SIGNATURE:
	case PEER_SDIOC_SW_MAILBOX_UT_SIGNATURE:
		return init_channels(sdio_al_dev);
	default:
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":Invalid "
				"signature 0x%x\n", signature);
		return -EINVAL;
	}

	return 0;
}

static void clean_sdio_al_device_data(struct sdio_al_device *sdio_al_dev)
{
	sdio_al_dev->is_ready = 0;
	sdio_al_dev->bootloader_done = 0;
	sdio_al_dev->lpm_chan = 0;
	sdio_al_dev->is_ok_to_sleep = 0;
	sdio_al_dev->inactivity_time = 0;
	sdio_al_dev->poll_delay_msec = 0;
	sdio_al_dev->is_timer_initialized = 0;
	sdio_al_dev->is_err = 0;
	sdio_al_dev->is_suspended = 0;
	sdio_al_dev->flashless_boot_on = 0;
	sdio_al_dev->ch_close_supported = 0;
	sdio_al_dev->print_after_interrupt = 0;
	memset(sdio_al_dev->sdioc_sw_header, 0,
	       sizeof(*sdio_al_dev->sdioc_sw_header));
	memset(sdio_al_dev->mailbox, 0, sizeof(*sdio_al_dev->mailbox));
	memset(sdio_al_dev->rx_flush_buf, 0,
	       sizeof(*sdio_al_dev->rx_flush_buf));
}

/*
 * SDIO driver functions
 */
static int sdio_al_sdio_probe(struct sdio_func *func,
		const struct sdio_device_id *sdio_dev_id)
{
	int ret = 0;
	struct sdio_al_device *sdio_al_dev = NULL;
	int i;
	struct mmc_card *card = NULL;

	if (!func) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: NULL func\n",
				__func__);
		return -ENODEV;
	}
	card = func->card;

	if (!card) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: NULL card\n",
				__func__);
		return -ENODEV;
	}

	if (!card->sdio_func[0]) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: NULL "
							    "func1\n",
				__func__);
		return -ENODEV;
	}

	if (card->sdio_funcs < SDIO_AL_MAX_FUNCS) {
		dev_info(&card->dev,
			 "SDIO-functions# %d less than expected.\n",
			 card->sdio_funcs);
		return -ENODEV;
	}

	/* Check if there is already a device for this card */
	for (i = 0; i < MAX_NUM_OF_SDIO_DEVICES; ++i) {
		if (sdio_al->devices[i] == NULL)
			continue;
		if (sdio_al->devices[i]->host == card->host) {
			sdio_al_dev = sdio_al->devices[i];
			if (sdio_al_dev->state == CARD_INSERTED)
				return 0;
			clean_sdio_al_device_data(sdio_al_dev);
			break;
		}
	}

	if (!sdio_al_dev) {
		sdio_al_dev = kzalloc(sizeof(struct sdio_al_device),
				      GFP_KERNEL);
		if (sdio_al_dev == NULL)
			return -ENOMEM;

		for (i = 0; i < MAX_NUM_OF_SDIO_DEVICES ; ++i)
			if (sdio_al->devices[i] == NULL) {
				sdio_al->devices[i] = sdio_al_dev;
				sdio_al_dev->dev_log = &sdio_al->device_log[i];
				spin_lock_init(&sdio_al_dev->dev_log->log_lock);
	#ifdef CONFIG_DEBUG_FS
				sdio_al_dbgfs_log[i].data =
						sdio_al_dev->dev_log->buffer;
				sdio_al_dbgfs_log[i].size =
					SDIO_AL_DEBUG_LOG_SIZE;
	#endif
				break;
			}
		if (i == MAX_NUM_OF_SDIO_DEVICES) {
			sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ":No space "
					"in devices array for the device\n");
			return -ENOMEM;
		}
	}

	dev_info(&card->dev, "SDIO Card claimed.\n");
	sdio_al->skip_print_info = 0;

	sdio_al_dev->state = CARD_INSERTED;

	if (card->host->index == SDIO_BOOTLOADER_CARD_INDEX)
		sdio_al->bootloader_dev = sdio_al_dev;

	sdio_al_dev->is_ready = false;

	sdio_al_dev->signature = SDIO_AL_SIGNATURE;

	sdio_al_dev->is_suspended = 0;
	sdio_al_dev->is_timer_initialized = false;

	sdio_al_dev->lpm_chan = INVALID_SDIO_CHAN;

	sdio_al_dev->card = card;
	sdio_al_dev->host = card->host;

	if (!sdio_al_dev->mailbox) {
		sdio_al_dev->mailbox = kzalloc(sizeof(struct sdio_mailbox),
					       GFP_KERNEL);
		if (sdio_al_dev->mailbox == NULL)
			return -ENOMEM;
	}

	if (!sdio_al_dev->sdioc_sw_header) {
		sdio_al_dev->sdioc_sw_header
			= kzalloc(sizeof(*sdio_al_dev->sdioc_sw_header),
				  GFP_KERNEL);
		if (sdio_al_dev->sdioc_sw_header == NULL)
			return -ENOMEM;
	}

	if (!sdio_al_dev->rx_flush_buf) {
		sdio_al_dev->rx_flush_buf = kzalloc(RX_FLUSH_BUFFER_SIZE,
						    GFP_KERNEL);
		if (sdio_al_dev->rx_flush_buf == NULL) {
			sdio_al_loge(&sdio_al->gen_log,
					MODULE_NAME ":Fail to allocate "
					   "rx_flush_buf for card %d\n",
			       card->host->index);
			return -ENOMEM;
		}
	}

	sdio_al_dev->timer.data = (unsigned long)sdio_al_dev;

	wake_lock_init(&sdio_al_dev->wake_lock, WAKE_LOCK_SUSPEND, MODULE_NAME);
	/* Don't allow sleep until all required clients register */
	sdio_al_vote_for_sleep(sdio_al_dev, 0);

	if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
		return -ENODEV;

	/* Init Func#1 */
	ret = sdio_al_enable_func_retry(card->sdio_func[0], "Init Func#1");
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":Fail to "
				"enable Func#%d\n", card->sdio_func[0]->num);
		goto exit;
	}

	/* Patch Func CIS tuple issue */
	ret = sdio_set_block_size(card->sdio_func[0], SDIO_AL_BLOCK_SIZE);
	if (ret) {
		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ":Fail to set "
			"block size, Func#%d\n", card->sdio_func[0]->num);
		goto exit;
	}
	sdio_al_dev->card->sdio_func[0]->max_blksize = SDIO_AL_BLOCK_SIZE;

	sdio_al_dev->workqueue = create_singlethread_workqueue("sdio_al_wq");
	sdio_al_dev->sdio_al_work.sdio_al_dev = sdio_al_dev;
	init_waitqueue_head(&sdio_al_dev->wait_mbox);

	ret = sdio_al_client_setup(sdio_al_dev);

exit:
	sdio_al_release_mutex(sdio_al_dev, __func__);
	return ret;
}

static void sdio_al_sdio_remove(struct sdio_func *func)
{
	struct sdio_al_device *sdio_al_dev = NULL;
	int i;
	struct mmc_card *card = NULL;
	struct platform_device *pdev_arr[SDIO_AL_MAX_CHANNELS];

	if (!func) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: NULL func\n",
				__func__);
		return;
	}
	card = func->card;

	if (!card) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: NULL card\n",
				__func__);
		return;
	}

	/* Find the sdio_al_device of this card */
	for (i = 0; i < MAX_NUM_OF_SDIO_DEVICES; ++i) {
		if (sdio_al->devices[i] == NULL)
			continue;
		if (sdio_al->devices[i]->card == card) {
			sdio_al_dev = sdio_al->devices[i];
			break;
		}
	}
	if (sdio_al_dev == NULL) {
		pr_debug(MODULE_NAME ":%s :NULL sdio_al_dev for card %d\n",
				 __func__, card->host->index);
		return;
	}

	if (sdio_al_claim_mutex(sdio_al_dev, __func__))
		return;

	if (sdio_al_dev->state == CARD_REMOVED) {
		sdio_al_release_mutex(sdio_al_dev, __func__);
		return;
	}

	if (!card->sdio_func[0]) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: NULL "
						"func1\n", __func__);
		sdio_al_release_mutex(sdio_al_dev, __func__);
		return;
	}

	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ":%s for card %d\n",
			 __func__, card->host->index);

	sdio_al_dev->state = CARD_REMOVED;

	memset(pdev_arr, 0, sizeof(pdev_arr));
	sdio_al_invalidate_sdio_clients(sdio_al_dev, pdev_arr);

	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ":%s: ask_reading_mailbox "
			"for card %d\n", __func__, card->host->index);
	sdio_al_dev->is_ready = false; /* Flag worker to exit */
	sdio_al_dev->ask_mbox = false;
	ask_reading_mailbox(sdio_al_dev); /* Wakeup worker */

	stop_and_del_timer(sdio_al_dev);

	sdio_al_release_mutex(sdio_al_dev, __func__);

	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ": %s: Notifying SDIO "
						    "clients for card %d",
			__func__, sdio_al_dev->host->index);
	for (i = 0; i < SDIO_AL_MAX_CHANNELS; i++) {
		if (!pdev_arr[i])
			continue;
		platform_device_unregister(pdev_arr[i]);
	}
	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ": %s: Finished Notifying "
						    "SDIO clients for card %d",
			__func__, sdio_al_dev->host->index);

	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ":%s: vote for sleep for "
			"card %d\n", __func__, card->host->index);
	sdio_al_vote_for_sleep(sdio_al_dev, 1);

	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ":%s: flush_workqueue for "
			"card %d\n", __func__, card->host->index);
	flush_workqueue(sdio_al_dev->workqueue);
	destroy_workqueue(sdio_al_dev->workqueue);
	wake_lock_destroy(&sdio_al_dev->wake_lock);

	sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ":%s: sdio card %d removed."
			"\n", __func__,	card->host->index);
}

static void sdio_print_mailbox(char *prefix_str, struct sdio_mailbox *mailbox)
{
	int k = 0;
	char buf[256];
	char buf1[10];

	if (!mailbox) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": mailbox is "
				"NULL\n");
		return;
	}

	sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s: pipes 0_7: eot=0x%x,"
		" thresh=0x%x, overflow=0x%x, "
		"underflow=0x%x, mask_thresh=0x%x\n",
		 prefix_str, mailbox->eot_pipe_0_7,
		 mailbox->thresh_above_limit_pipe_0_7,
		 mailbox->overflow_pipe_0_7,
		 mailbox->underflow_pipe_0_7,
		 mailbox->mask_thresh_above_limit_pipe_0_7);

	memset(buf, 0, sizeof(buf));
	strncat(buf, ": bytes_avail:", sizeof(buf));

	for (k = 0 ; k < SDIO_AL_ACTIVE_PIPES ; ++k) {
		snprintf(buf1, sizeof(buf1), "%d, ",
			 mailbox->pipe_bytes_avail[k]);
		strncat(buf, buf1, sizeof(buf));
	}

	sdio_al_loge(&sdio_al->gen_log, MODULE_NAME "%s", buf);
}

static void sdio_al_print_info(void)
{
	int i = 0;
	int j = 0;
	int ret = 0;
	struct sdio_mailbox *mailbox = NULL;
	struct sdio_mailbox *hw_mailbox = NULL;
	struct peer_sdioc_channel_config *ch_config = NULL;
	struct sdio_func *func1 = NULL;
	struct sdio_func *lpm_func = NULL;
	int offset = 0;
	int is_ok_to_sleep = 0;
	char buf[50];

	if (sdio_al->skip_print_info == 1)
		return;

	sdio_al->skip_print_info = 1;

	sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s - SDIO DEBUG INFO\n",
			__func__);

	if (!sdio_al) {
		sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": %s - ERROR - "
				"sdio_al is NULL\n",  __func__);
		return;
	}

	sdio_al_loge(&sdio_al->gen_log, MODULE_NAME ": GPIO mdm2ap_status=%d\n",
				sdio_al->pdata->get_mdm2ap_status());

	for (j = 0 ; j < MAX_NUM_OF_SDIO_DEVICES ; ++j) {
		struct sdio_al_device *sdio_al_dev = sdio_al->devices[j];

		if (sdio_al_dev == NULL) {
			continue;
		}

		if (!sdio_al_dev->host) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": Host"
					" is NULL\n);");
			continue;
		}

		snprintf(buf, sizeof(buf), "Card#%d: Shadow HW MB",
		       sdio_al_dev->host->index);

		/* printing Shadowing HW Mailbox*/
		mailbox = sdio_al_dev->mailbox;
		sdio_print_mailbox(buf, mailbox);

		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": Card#%d: "
			"is_ok_to_sleep=%d\n",
			sdio_al_dev->host->index,
			sdio_al_dev->is_ok_to_sleep);


		sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME ": Card#%d: "
				   "Shadow channels SW MB:",
		       sdio_al_dev->host->index);

		/* printing Shadowing SW Mailbox per channel*/
		for (i = 0 ; i < SDIO_AL_MAX_CHANNELS ; ++i) {
			struct sdio_channel *ch = &sdio_al_dev->channel[i];

			if (ch == NULL) {
				continue;
			}

			if (ch->state == SDIO_CHANNEL_STATE_INVALID)
				continue;

			ch_config = &sdio_al_dev->channel[i].ch_config;

			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
				": Ch %s: max_rx_thres=0x%x, "
				"max_tx_thres=0x%x, tx_buf=0x%x, "
				"is_packet_mode=%d, "
				"max_packet=0x%x, min_write=0x%x",
				ch->name, ch_config->max_rx_threshold,
				ch_config->max_tx_threshold,
				ch_config->tx_buf_size,
				ch_config->is_packet_mode,
				ch_config->max_packet_size,
				ch->min_write_avail);

			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
				": total_rx=0x%x, total_tx=0x%x, "
				"read_avail=0x%x, write_avail=0x%x, "
				"rx_pending=0x%x, num_reads=0x%x, "
				"num_notifs=0x%x", ch->total_rx_bytes,
				ch->total_tx_bytes, ch->read_avail,
				ch->write_avail, ch->rx_pending_bytes,
				ch->statistics.total_read_times,
				ch->statistics.total_notifs);
		} /* end loop over all channels */

	} /* end loop over all devices */

	/* reading from client and printing is_host_ok_to_sleep per device */
	for (j = 0 ; j < MAX_NUM_OF_SDIO_DEVICES ; ++j) {
		struct sdio_al_device *sdio_al_dev = sdio_al->devices[j];

		if (sdio_al_verify_func1(sdio_al_dev, __func__))
			continue;

		if (!sdio_al_dev->host) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
					": Host is NULL");
			continue;
		}

		if (sdio_al_dev->lpm_chan == INVALID_SDIO_CHAN) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
				": %s - for Card#%d, is lpm_chan=="
				"INVALID_SDIO_CHAN. continuing...",
				__func__, sdio_al_dev->host->index);
			continue;
		}

		offset = offsetof(struct peer_sdioc_sw_mailbox, ch_config)+
		sizeof(struct peer_sdioc_channel_config) *
		sdio_al_dev->lpm_chan+
		offsetof(struct peer_sdioc_channel_config, is_host_ok_to_sleep);

		lpm_func = sdio_al_dev->card->sdio_func[sdio_al_dev->
								lpm_chan+1];
		if (!lpm_func) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
					": %s - lpm_func is NULL for card#%d"
					" continuing...\n", __func__,
					sdio_al_dev->host->index);
			continue;
		}

		if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
			return;
		ret  =  sdio_memcpy_fromio(lpm_func,
					    &is_ok_to_sleep,
					    SDIOC_SW_MAILBOX_ADDR+offset,
					    sizeof(int));
		sdio_al_release_mutex(sdio_al_dev, __func__);

		if (ret)
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
					": %s - fail to read "
				"is_HOST_ok_to_sleep from mailbox for card %d",
				__func__, sdio_al_dev->host->index);
		else
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
					": Card#%d: "
				"is_HOST_ok_to_sleep=%d\n",
				sdio_al_dev->host->index,
				is_ok_to_sleep);
	}

	for (j = 0 ; j < MAX_NUM_OF_SDIO_DEVICES ; ++j) {
		struct sdio_al_device *sdio_al_dev = sdio_al->devices[j];

		if (!sdio_al_dev)
			continue;

		/* Reading HW Mailbox */
		hw_mailbox = sdio_al_dev->mailbox;

		if (sdio_al_claim_mutex_and_verify_dev(sdio_al_dev, __func__))
			return;

		if (!sdio_al_dev->card || !sdio_al_dev->card->sdio_func[0]) {
			sdio_al_release_mutex(sdio_al_dev, __func__);
			return;
		}
		func1 = sdio_al_dev->card->sdio_func[0];
		ret = sdio_memcpy_fromio(func1, hw_mailbox,
			HW_MAILBOX_ADDR, sizeof(*hw_mailbox));
		sdio_al_release_mutex(sdio_al_dev, __func__);

		if (ret) {
			sdio_al_loge(sdio_al_dev->dev_log, MODULE_NAME
					": fail to read "
			       "mailbox for card#%d. "
			       "continuing...\n",
			       sdio_al_dev->host->index);
			continue;
		}

		snprintf(buf, sizeof(buf), "Card#%d: Current HW MB",
		       sdio_al_dev->host->index);

		/* Printing HW Mailbox */
		sdio_print_mailbox(buf, hw_mailbox);
	}
}

static struct sdio_device_id sdio_al_sdioid[] = {
    {.class = 0, .vendor = 0x70, .device = 0x2460},
    {.class = 0, .vendor = 0x70, .device = 0x0460},
    {.class = 0, .vendor = 0x70, .device = 0x23F1},
    {.class = 0, .vendor = 0x70, .device = 0x23F0},
    {}
};

static struct sdio_driver sdio_al_sdiofn_driver = {
    .name      = "sdio_al_sdiofn",
    .id_table  = sdio_al_sdioid,
    .probe     = sdio_al_sdio_probe,
    .remove    = sdio_al_sdio_remove,
};

#ifdef CONFIG_MSM_SUBSYSTEM_RESTART
/*
 *  Callback for notifications from restart mudule.
 *  This function handles only the BEFORE_RESTART notification.
 *  Stop all the activity on the card and notify our clients.
 */
static int sdio_al_subsys_notifier_cb(struct notifier_block *this,
				  unsigned long notif_type,
				  void *data)
{
	if (notif_type != SUBSYS_BEFORE_SHUTDOWN) {
		sdio_al_logi(&sdio_al->gen_log, MODULE_NAME ": %s: got "
				"notification %ld", __func__, notif_type);
		return NOTIFY_DONE;
	}

	sdio_al_reset();
	return NOTIFY_OK;
}

static struct notifier_block sdio_al_nb = {
	.notifier_call = sdio_al_subsys_notifier_cb,
};
#endif

/**
 *  Module Init.
 *
 *  @warn: allocate sdio_al context before registering driver.
 *
 */
static int __init sdio_al_init(void)
{
	int ret = 0;
	int i;

	pr_debug(MODULE_NAME ":sdio_al_init\n");

	pr_info(MODULE_NAME ":SDIO-AL SW version %s\n",
		DRV_VERSION);

	sdio_al = kzalloc(sizeof(struct sdio_al), GFP_KERNEL);
	if (sdio_al == NULL)
		return -ENOMEM;

	for (i = 0; i < MAX_NUM_OF_SDIO_DEVICES ; ++i)
		sdio_al->devices[i] = NULL;

	sdio_al->unittest_mode = false;

	sdio_al->debug.debug_lpm_on = debug_lpm_on;
	sdio_al->debug.debug_data_on = debug_data_on;
	sdio_al->debug.debug_close_on = debug_close_on;

#ifdef CONFIG_DEBUG_FS
	sdio_al_debugfs_init();
#endif


#ifdef CONFIG_MSM_SUBSYSTEM_RESTART
	sdio_al->subsys_notif_handle = subsys_notif_register_notifier(
		"external_modem", &sdio_al_nb);
#endif

	ret = platform_driver_register(&msm_sdio_al_driver);
	if (ret) {
		pr_err(MODULE_NAME ": platform_driver_register failed: %d\n",
		       ret);
		goto exit;
	}

	sdio_register_driver(&sdio_al_sdiofn_driver);

	spin_lock_init(&sdio_al->gen_log.log_lock);

exit:
	if (ret)
		kfree(sdio_al);
	return ret;
}

/**
 *  Module Exit.
 *
 *  Free allocated memory.
 *  Disable SDIO-Card.
 *  Unregister driver.
 *
 */
static void __exit sdio_al_exit(void)
{
	if (sdio_al == NULL)
		return;

	pr_debug(MODULE_NAME ":sdio_al_exit\n");

#ifdef CONFIG_MSM_SUBSYSTEM_RESTART
	subsys_notif_unregister_notifier(
		sdio_al->subsys_notif_handle, &sdio_al_nb);
#endif

	sdio_al_tear_down();

	sdio_unregister_driver(&sdio_al_sdiofn_driver);

	kfree(sdio_al);

#ifdef CONFIG_DEBUG_FS
	sdio_al_debugfs_cleanup();
#endif

	platform_driver_unregister(&msm_sdio_al_driver);

	pr_debug(MODULE_NAME ":sdio_al_exit complete\n");
}

module_init(sdio_al_init);
module_exit(sdio_al_exit);

MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("SDIO Abstraction Layer");
MODULE_AUTHOR("Amir Samuelov <amirs@codeaurora.org>");
MODULE_VERSION(DRV_VERSION);

