Merge branch 'origin' into for-linus
Conflicts: MAINTAINERS
This commit is contained in:
@@ -130,7 +130,7 @@ mmc_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct block_device_operations mmc_bdops = {
|
||||
static const struct block_device_operations mmc_bdops = {
|
||||
.open = mmc_blk_open,
|
||||
.release = mmc_blk_release,
|
||||
.getgeo = mmc_blk_getgeo,
|
||||
|
@@ -343,6 +343,101 @@ unsigned int mmc_align_data_size(struct mmc_card *card, unsigned int sz)
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_align_data_size);
|
||||
|
||||
/**
|
||||
* mmc_host_enable - enable a host.
|
||||
* @host: mmc host to enable
|
||||
*
|
||||
* Hosts that support power saving can use the 'enable' and 'disable'
|
||||
* methods to exit and enter power saving states. For more information
|
||||
* see comments for struct mmc_host_ops.
|
||||
*/
|
||||
int mmc_host_enable(struct mmc_host *host)
|
||||
{
|
||||
if (!(host->caps & MMC_CAP_DISABLE))
|
||||
return 0;
|
||||
|
||||
if (host->en_dis_recurs)
|
||||
return 0;
|
||||
|
||||
if (host->nesting_cnt++)
|
||||
return 0;
|
||||
|
||||
cancel_delayed_work_sync(&host->disable);
|
||||
|
||||
if (host->enabled)
|
||||
return 0;
|
||||
|
||||
if (host->ops->enable) {
|
||||
int err;
|
||||
|
||||
host->en_dis_recurs = 1;
|
||||
err = host->ops->enable(host);
|
||||
host->en_dis_recurs = 0;
|
||||
|
||||
if (err) {
|
||||
pr_debug("%s: enable error %d\n",
|
||||
mmc_hostname(host), err);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
host->enabled = 1;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_host_enable);
|
||||
|
||||
static int mmc_host_do_disable(struct mmc_host *host, int lazy)
|
||||
{
|
||||
if (host->ops->disable) {
|
||||
int err;
|
||||
|
||||
host->en_dis_recurs = 1;
|
||||
err = host->ops->disable(host, lazy);
|
||||
host->en_dis_recurs = 0;
|
||||
|
||||
if (err < 0) {
|
||||
pr_debug("%s: disable error %d\n",
|
||||
mmc_hostname(host), err);
|
||||
return err;
|
||||
}
|
||||
if (err > 0) {
|
||||
unsigned long delay = msecs_to_jiffies(err);
|
||||
|
||||
mmc_schedule_delayed_work(&host->disable, delay);
|
||||
}
|
||||
}
|
||||
host->enabled = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* mmc_host_disable - disable a host.
|
||||
* @host: mmc host to disable
|
||||
*
|
||||
* Hosts that support power saving can use the 'enable' and 'disable'
|
||||
* methods to exit and enter power saving states. For more information
|
||||
* see comments for struct mmc_host_ops.
|
||||
*/
|
||||
int mmc_host_disable(struct mmc_host *host)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (!(host->caps & MMC_CAP_DISABLE))
|
||||
return 0;
|
||||
|
||||
if (host->en_dis_recurs)
|
||||
return 0;
|
||||
|
||||
if (--host->nesting_cnt)
|
||||
return 0;
|
||||
|
||||
if (!host->enabled)
|
||||
return 0;
|
||||
|
||||
err = mmc_host_do_disable(host, 0);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_host_disable);
|
||||
|
||||
/**
|
||||
* __mmc_claim_host - exclusively claim a host
|
||||
* @host: mmc host to claim
|
||||
@@ -366,24 +461,110 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
|
||||
while (1) {
|
||||
set_current_state(TASK_UNINTERRUPTIBLE);
|
||||
stop = abort ? atomic_read(abort) : 0;
|
||||
if (stop || !host->claimed)
|
||||
if (stop || !host->claimed || host->claimer == current)
|
||||
break;
|
||||
spin_unlock_irqrestore(&host->lock, flags);
|
||||
schedule();
|
||||
spin_lock_irqsave(&host->lock, flags);
|
||||
}
|
||||
set_current_state(TASK_RUNNING);
|
||||
if (!stop)
|
||||
if (!stop) {
|
||||
host->claimed = 1;
|
||||
else
|
||||
host->claimer = current;
|
||||
host->claim_cnt += 1;
|
||||
} else
|
||||
wake_up(&host->wq);
|
||||
spin_unlock_irqrestore(&host->lock, flags);
|
||||
remove_wait_queue(&host->wq, &wait);
|
||||
if (!stop)
|
||||
mmc_host_enable(host);
|
||||
return stop;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(__mmc_claim_host);
|
||||
|
||||
/**
|
||||
* mmc_try_claim_host - try exclusively to claim a host
|
||||
* @host: mmc host to claim
|
||||
*
|
||||
* Returns %1 if the host is claimed, %0 otherwise.
|
||||
*/
|
||||
int mmc_try_claim_host(struct mmc_host *host)
|
||||
{
|
||||
int claimed_host = 0;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&host->lock, flags);
|
||||
if (!host->claimed || host->claimer == current) {
|
||||
host->claimed = 1;
|
||||
host->claimer = current;
|
||||
host->claim_cnt += 1;
|
||||
claimed_host = 1;
|
||||
}
|
||||
spin_unlock_irqrestore(&host->lock, flags);
|
||||
return claimed_host;
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_try_claim_host);
|
||||
|
||||
static void mmc_do_release_host(struct mmc_host *host)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&host->lock, flags);
|
||||
if (--host->claim_cnt) {
|
||||
/* Release for nested claim */
|
||||
spin_unlock_irqrestore(&host->lock, flags);
|
||||
} else {
|
||||
host->claimed = 0;
|
||||
host->claimer = NULL;
|
||||
spin_unlock_irqrestore(&host->lock, flags);
|
||||
wake_up(&host->wq);
|
||||
}
|
||||
}
|
||||
|
||||
void mmc_host_deeper_disable(struct work_struct *work)
|
||||
{
|
||||
struct mmc_host *host =
|
||||
container_of(work, struct mmc_host, disable.work);
|
||||
|
||||
/* If the host is claimed then we do not want to disable it anymore */
|
||||
if (!mmc_try_claim_host(host))
|
||||
return;
|
||||
mmc_host_do_disable(host, 1);
|
||||
mmc_do_release_host(host);
|
||||
}
|
||||
|
||||
/**
|
||||
* mmc_host_lazy_disable - lazily disable a host.
|
||||
* @host: mmc host to disable
|
||||
*
|
||||
* Hosts that support power saving can use the 'enable' and 'disable'
|
||||
* methods to exit and enter power saving states. For more information
|
||||
* see comments for struct mmc_host_ops.
|
||||
*/
|
||||
int mmc_host_lazy_disable(struct mmc_host *host)
|
||||
{
|
||||
if (!(host->caps & MMC_CAP_DISABLE))
|
||||
return 0;
|
||||
|
||||
if (host->en_dis_recurs)
|
||||
return 0;
|
||||
|
||||
if (--host->nesting_cnt)
|
||||
return 0;
|
||||
|
||||
if (!host->enabled)
|
||||
return 0;
|
||||
|
||||
if (host->disable_delay) {
|
||||
mmc_schedule_delayed_work(&host->disable,
|
||||
msecs_to_jiffies(host->disable_delay));
|
||||
return 0;
|
||||
} else
|
||||
return mmc_host_do_disable(host, 1);
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_host_lazy_disable);
|
||||
|
||||
/**
|
||||
* mmc_release_host - release a host
|
||||
* @host: mmc host to release
|
||||
@@ -393,15 +574,11 @@ EXPORT_SYMBOL(__mmc_claim_host);
|
||||
*/
|
||||
void mmc_release_host(struct mmc_host *host)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
WARN_ON(!host->claimed);
|
||||
|
||||
spin_lock_irqsave(&host->lock, flags);
|
||||
host->claimed = 0;
|
||||
spin_unlock_irqrestore(&host->lock, flags);
|
||||
mmc_host_lazy_disable(host);
|
||||
|
||||
wake_up(&host->wq);
|
||||
mmc_do_release_host(host);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(mmc_release_host);
|
||||
@@ -687,7 +864,13 @@ void mmc_set_timing(struct mmc_host *host, unsigned int timing)
|
||||
*/
|
||||
static void mmc_power_up(struct mmc_host *host)
|
||||
{
|
||||
int bit = fls(host->ocr_avail) - 1;
|
||||
int bit;
|
||||
|
||||
/* If ocr is set, we use it */
|
||||
if (host->ocr)
|
||||
bit = ffs(host->ocr) - 1;
|
||||
else
|
||||
bit = fls(host->ocr_avail) - 1;
|
||||
|
||||
host->ios.vdd = bit;
|
||||
if (mmc_host_is_spi(host)) {
|
||||
@@ -947,6 +1130,8 @@ void mmc_stop_host(struct mmc_host *host)
|
||||
spin_unlock_irqrestore(&host->lock, flags);
|
||||
#endif
|
||||
|
||||
if (host->caps & MMC_CAP_DISABLE)
|
||||
cancel_delayed_work(&host->disable);
|
||||
cancel_delayed_work(&host->detect);
|
||||
mmc_flush_scheduled_work();
|
||||
|
||||
@@ -958,6 +1143,8 @@ void mmc_stop_host(struct mmc_host *host)
|
||||
mmc_claim_host(host);
|
||||
mmc_detach_bus(host);
|
||||
mmc_release_host(host);
|
||||
mmc_bus_put(host);
|
||||
return;
|
||||
}
|
||||
mmc_bus_put(host);
|
||||
|
||||
@@ -966,6 +1153,80 @@ void mmc_stop_host(struct mmc_host *host)
|
||||
mmc_power_off(host);
|
||||
}
|
||||
|
||||
void mmc_power_save_host(struct mmc_host *host)
|
||||
{
|
||||
mmc_bus_get(host);
|
||||
|
||||
if (!host->bus_ops || host->bus_dead || !host->bus_ops->power_restore) {
|
||||
mmc_bus_put(host);
|
||||
return;
|
||||
}
|
||||
|
||||
if (host->bus_ops->power_save)
|
||||
host->bus_ops->power_save(host);
|
||||
|
||||
mmc_bus_put(host);
|
||||
|
||||
mmc_power_off(host);
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_power_save_host);
|
||||
|
||||
void mmc_power_restore_host(struct mmc_host *host)
|
||||
{
|
||||
mmc_bus_get(host);
|
||||
|
||||
if (!host->bus_ops || host->bus_dead || !host->bus_ops->power_restore) {
|
||||
mmc_bus_put(host);
|
||||
return;
|
||||
}
|
||||
|
||||
mmc_power_up(host);
|
||||
host->bus_ops->power_restore(host);
|
||||
|
||||
mmc_bus_put(host);
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_power_restore_host);
|
||||
|
||||
int mmc_card_awake(struct mmc_host *host)
|
||||
{
|
||||
int err = -ENOSYS;
|
||||
|
||||
mmc_bus_get(host);
|
||||
|
||||
if (host->bus_ops && !host->bus_dead && host->bus_ops->awake)
|
||||
err = host->bus_ops->awake(host);
|
||||
|
||||
mmc_bus_put(host);
|
||||
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_card_awake);
|
||||
|
||||
int mmc_card_sleep(struct mmc_host *host)
|
||||
{
|
||||
int err = -ENOSYS;
|
||||
|
||||
mmc_bus_get(host);
|
||||
|
||||
if (host->bus_ops && !host->bus_dead && host->bus_ops->awake)
|
||||
err = host->bus_ops->sleep(host);
|
||||
|
||||
mmc_bus_put(host);
|
||||
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_card_sleep);
|
||||
|
||||
int mmc_card_can_sleep(struct mmc_host *host)
|
||||
{
|
||||
struct mmc_card *card = host->card;
|
||||
|
||||
if (card && mmc_card_mmc(card) && card->ext_csd.rev >= 3)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_card_can_sleep);
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
|
||||
/**
|
||||
@@ -975,27 +1236,36 @@ void mmc_stop_host(struct mmc_host *host)
|
||||
*/
|
||||
int mmc_suspend_host(struct mmc_host *host, pm_message_t state)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
if (host->caps & MMC_CAP_DISABLE)
|
||||
cancel_delayed_work(&host->disable);
|
||||
cancel_delayed_work(&host->detect);
|
||||
mmc_flush_scheduled_work();
|
||||
|
||||
mmc_bus_get(host);
|
||||
if (host->bus_ops && !host->bus_dead) {
|
||||
if (host->bus_ops->suspend)
|
||||
host->bus_ops->suspend(host);
|
||||
if (!host->bus_ops->resume) {
|
||||
err = host->bus_ops->suspend(host);
|
||||
if (err == -ENOSYS || !host->bus_ops->resume) {
|
||||
/*
|
||||
* We simply "remove" the card in this case.
|
||||
* It will be redetected on resume.
|
||||
*/
|
||||
if (host->bus_ops->remove)
|
||||
host->bus_ops->remove(host);
|
||||
|
||||
mmc_claim_host(host);
|
||||
mmc_detach_bus(host);
|
||||
mmc_release_host(host);
|
||||
err = 0;
|
||||
}
|
||||
}
|
||||
mmc_bus_put(host);
|
||||
|
||||
mmc_power_off(host);
|
||||
if (!err)
|
||||
mmc_power_off(host);
|
||||
|
||||
return 0;
|
||||
return err;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(mmc_suspend_host);
|
||||
@@ -1006,12 +1276,26 @@ EXPORT_SYMBOL(mmc_suspend_host);
|
||||
*/
|
||||
int mmc_resume_host(struct mmc_host *host)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
mmc_bus_get(host);
|
||||
if (host->bus_ops && !host->bus_dead) {
|
||||
mmc_power_up(host);
|
||||
mmc_select_voltage(host, host->ocr);
|
||||
BUG_ON(!host->bus_ops->resume);
|
||||
host->bus_ops->resume(host);
|
||||
err = host->bus_ops->resume(host);
|
||||
if (err) {
|
||||
printk(KERN_WARNING "%s: error %d during resume "
|
||||
"(card was removed?)\n",
|
||||
mmc_hostname(host), err);
|
||||
if (host->bus_ops->remove)
|
||||
host->bus_ops->remove(host);
|
||||
mmc_claim_host(host);
|
||||
mmc_detach_bus(host);
|
||||
mmc_release_host(host);
|
||||
/* no need to bother upper layers */
|
||||
err = 0;
|
||||
}
|
||||
}
|
||||
mmc_bus_put(host);
|
||||
|
||||
@@ -1021,7 +1305,7 @@ int mmc_resume_host(struct mmc_host *host)
|
||||
*/
|
||||
mmc_detect_change(host, 1);
|
||||
|
||||
return 0;
|
||||
return err;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(mmc_resume_host);
|
||||
|
@@ -16,10 +16,14 @@
|
||||
#define MMC_CMD_RETRIES 3
|
||||
|
||||
struct mmc_bus_ops {
|
||||
int (*awake)(struct mmc_host *);
|
||||
int (*sleep)(struct mmc_host *);
|
||||
void (*remove)(struct mmc_host *);
|
||||
void (*detect)(struct mmc_host *);
|
||||
void (*suspend)(struct mmc_host *);
|
||||
void (*resume)(struct mmc_host *);
|
||||
int (*suspend)(struct mmc_host *);
|
||||
int (*resume)(struct mmc_host *);
|
||||
void (*power_save)(struct mmc_host *);
|
||||
void (*power_restore)(struct mmc_host *);
|
||||
};
|
||||
|
||||
void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
|
||||
|
@@ -83,6 +83,7 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
|
||||
spin_lock_init(&host->lock);
|
||||
init_waitqueue_head(&host->wq);
|
||||
INIT_DELAYED_WORK(&host->detect, mmc_rescan);
|
||||
INIT_DELAYED_WORK_DEFERRABLE(&host->disable, mmc_host_deeper_disable);
|
||||
|
||||
/*
|
||||
* By default, hosts do not support SGIO or large requests.
|
||||
|
@@ -14,5 +14,7 @@
|
||||
int mmc_register_host_class(void);
|
||||
void mmc_unregister_host_class(void);
|
||||
|
||||
void mmc_host_deeper_disable(struct work_struct *work);
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -160,7 +160,6 @@ static int mmc_read_ext_csd(struct mmc_card *card)
|
||||
{
|
||||
int err;
|
||||
u8 *ext_csd;
|
||||
unsigned int ext_csd_struct;
|
||||
|
||||
BUG_ON(!card);
|
||||
|
||||
@@ -180,11 +179,11 @@ static int mmc_read_ext_csd(struct mmc_card *card)
|
||||
|
||||
err = mmc_send_ext_csd(card, ext_csd);
|
||||
if (err) {
|
||||
/*
|
||||
* We all hosts that cannot perform the command
|
||||
* to fail more gracefully
|
||||
*/
|
||||
if (err != -EINVAL)
|
||||
/* If the host or the card can't do the switch,
|
||||
* fail more gracefully. */
|
||||
if ((err != -EINVAL)
|
||||
&& (err != -ENOSYS)
|
||||
&& (err != -EFAULT))
|
||||
goto out;
|
||||
|
||||
/*
|
||||
@@ -207,16 +206,16 @@ static int mmc_read_ext_csd(struct mmc_card *card)
|
||||
goto out;
|
||||
}
|
||||
|
||||
ext_csd_struct = ext_csd[EXT_CSD_REV];
|
||||
if (ext_csd_struct > 3) {
|
||||
card->ext_csd.rev = ext_csd[EXT_CSD_REV];
|
||||
if (card->ext_csd.rev > 3) {
|
||||
printk(KERN_ERR "%s: unrecognised EXT_CSD structure "
|
||||
"version %d\n", mmc_hostname(card->host),
|
||||
ext_csd_struct);
|
||||
card->ext_csd.rev);
|
||||
err = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (ext_csd_struct >= 2) {
|
||||
if (card->ext_csd.rev >= 2) {
|
||||
card->ext_csd.sectors =
|
||||
ext_csd[EXT_CSD_SEC_CNT + 0] << 0 |
|
||||
ext_csd[EXT_CSD_SEC_CNT + 1] << 8 |
|
||||
@@ -241,6 +240,15 @@ static int mmc_read_ext_csd(struct mmc_card *card)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (card->ext_csd.rev >= 3) {
|
||||
u8 sa_shift = ext_csd[EXT_CSD_S_A_TIMEOUT];
|
||||
|
||||
/* Sleep / awake timeout in 100ns units */
|
||||
if (sa_shift > 0 && sa_shift <= 0x17)
|
||||
card->ext_csd.sa_timeout =
|
||||
1 << ext_csd[EXT_CSD_S_A_TIMEOUT];
|
||||
}
|
||||
|
||||
out:
|
||||
kfree(ext_csd);
|
||||
|
||||
@@ -408,12 +416,17 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
|
||||
(host->caps & MMC_CAP_MMC_HIGHSPEED)) {
|
||||
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
|
||||
EXT_CSD_HS_TIMING, 1);
|
||||
if (err)
|
||||
if (err && err != -EBADMSG)
|
||||
goto free_card;
|
||||
|
||||
mmc_card_set_highspeed(card);
|
||||
|
||||
mmc_set_timing(card->host, MMC_TIMING_MMC_HS);
|
||||
if (err) {
|
||||
printk(KERN_WARNING "%s: switch to highspeed failed\n",
|
||||
mmc_hostname(card->host));
|
||||
err = 0;
|
||||
} else {
|
||||
mmc_card_set_highspeed(card);
|
||||
mmc_set_timing(card->host, MMC_TIMING_MMC_HS);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -448,10 +461,17 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
|
||||
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
|
||||
EXT_CSD_BUS_WIDTH, ext_csd_bit);
|
||||
|
||||
if (err)
|
||||
if (err && err != -EBADMSG)
|
||||
goto free_card;
|
||||
|
||||
mmc_set_bus_width(card->host, bus_width);
|
||||
if (err) {
|
||||
printk(KERN_WARNING "%s: switch to bus width %d "
|
||||
"failed\n", mmc_hostname(card->host),
|
||||
1 << bus_width);
|
||||
err = 0;
|
||||
} else {
|
||||
mmc_set_bus_width(card->host, bus_width);
|
||||
}
|
||||
}
|
||||
|
||||
if (!oldcard)
|
||||
@@ -507,12 +527,10 @@ static void mmc_detect(struct mmc_host *host)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MMC_UNSAFE_RESUME
|
||||
|
||||
/*
|
||||
* Suspend callback from host.
|
||||
*/
|
||||
static void mmc_suspend(struct mmc_host *host)
|
||||
static int mmc_suspend(struct mmc_host *host)
|
||||
{
|
||||
BUG_ON(!host);
|
||||
BUG_ON(!host->card);
|
||||
@@ -522,6 +540,8 @@ static void mmc_suspend(struct mmc_host *host)
|
||||
mmc_deselect_cards(host);
|
||||
host->card->state &= ~MMC_STATE_HIGHSPEED;
|
||||
mmc_release_host(host);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -530,7 +550,7 @@ static void mmc_suspend(struct mmc_host *host)
|
||||
* This function tries to determine if the same card is still present
|
||||
* and, if so, restore all state to it.
|
||||
*/
|
||||
static void mmc_resume(struct mmc_host *host)
|
||||
static int mmc_resume(struct mmc_host *host)
|
||||
{
|
||||
int err;
|
||||
|
||||
@@ -541,30 +561,99 @@ static void mmc_resume(struct mmc_host *host)
|
||||
err = mmc_init_card(host, host->ocr, host->card);
|
||||
mmc_release_host(host);
|
||||
|
||||
if (err) {
|
||||
mmc_remove(host);
|
||||
|
||||
mmc_claim_host(host);
|
||||
mmc_detach_bus(host);
|
||||
mmc_release_host(host);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#else
|
||||
static void mmc_power_restore(struct mmc_host *host)
|
||||
{
|
||||
host->card->state &= ~MMC_STATE_HIGHSPEED;
|
||||
mmc_claim_host(host);
|
||||
mmc_init_card(host, host->ocr, host->card);
|
||||
mmc_release_host(host);
|
||||
}
|
||||
|
||||
#define mmc_suspend NULL
|
||||
#define mmc_resume NULL
|
||||
static int mmc_sleep(struct mmc_host *host)
|
||||
{
|
||||
struct mmc_card *card = host->card;
|
||||
int err = -ENOSYS;
|
||||
|
||||
#endif
|
||||
if (card && card->ext_csd.rev >= 3) {
|
||||
err = mmc_card_sleepawake(host, 1);
|
||||
if (err < 0)
|
||||
pr_debug("%s: Error %d while putting card into sleep",
|
||||
mmc_hostname(host), err);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int mmc_awake(struct mmc_host *host)
|
||||
{
|
||||
struct mmc_card *card = host->card;
|
||||
int err = -ENOSYS;
|
||||
|
||||
if (card && card->ext_csd.rev >= 3) {
|
||||
err = mmc_card_sleepawake(host, 0);
|
||||
if (err < 0)
|
||||
pr_debug("%s: Error %d while awaking sleeping card",
|
||||
mmc_hostname(host), err);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MMC_UNSAFE_RESUME
|
||||
|
||||
static const struct mmc_bus_ops mmc_ops = {
|
||||
.awake = mmc_awake,
|
||||
.sleep = mmc_sleep,
|
||||
.remove = mmc_remove,
|
||||
.detect = mmc_detect,
|
||||
.suspend = mmc_suspend,
|
||||
.resume = mmc_resume,
|
||||
.power_restore = mmc_power_restore,
|
||||
};
|
||||
|
||||
static void mmc_attach_bus_ops(struct mmc_host *host)
|
||||
{
|
||||
mmc_attach_bus(host, &mmc_ops);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static const struct mmc_bus_ops mmc_ops = {
|
||||
.awake = mmc_awake,
|
||||
.sleep = mmc_sleep,
|
||||
.remove = mmc_remove,
|
||||
.detect = mmc_detect,
|
||||
.suspend = NULL,
|
||||
.resume = NULL,
|
||||
.power_restore = mmc_power_restore,
|
||||
};
|
||||
|
||||
static const struct mmc_bus_ops mmc_ops_unsafe = {
|
||||
.awake = mmc_awake,
|
||||
.sleep = mmc_sleep,
|
||||
.remove = mmc_remove,
|
||||
.detect = mmc_detect,
|
||||
.suspend = mmc_suspend,
|
||||
.resume = mmc_resume,
|
||||
.power_restore = mmc_power_restore,
|
||||
};
|
||||
|
||||
static void mmc_attach_bus_ops(struct mmc_host *host)
|
||||
{
|
||||
const struct mmc_bus_ops *bus_ops;
|
||||
|
||||
if (host->caps & MMC_CAP_NONREMOVABLE)
|
||||
bus_ops = &mmc_ops_unsafe;
|
||||
else
|
||||
bus_ops = &mmc_ops;
|
||||
mmc_attach_bus(host, bus_ops);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Starting point for MMC card init.
|
||||
*/
|
||||
@@ -575,7 +664,7 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr)
|
||||
BUG_ON(!host);
|
||||
WARN_ON(!host->claimed);
|
||||
|
||||
mmc_attach_bus(host, &mmc_ops);
|
||||
mmc_attach_bus_ops(host);
|
||||
|
||||
/*
|
||||
* We need to get OCR a different way for SPI.
|
||||
|
@@ -57,6 +57,42 @@ int mmc_deselect_cards(struct mmc_host *host)
|
||||
return _mmc_select_card(host, NULL);
|
||||
}
|
||||
|
||||
int mmc_card_sleepawake(struct mmc_host *host, int sleep)
|
||||
{
|
||||
struct mmc_command cmd;
|
||||
struct mmc_card *card = host->card;
|
||||
int err;
|
||||
|
||||
if (sleep)
|
||||
mmc_deselect_cards(host);
|
||||
|
||||
memset(&cmd, 0, sizeof(struct mmc_command));
|
||||
|
||||
cmd.opcode = MMC_SLEEP_AWAKE;
|
||||
cmd.arg = card->rca << 16;
|
||||
if (sleep)
|
||||
cmd.arg |= 1 << 15;
|
||||
|
||||
cmd.flags = MMC_RSP_R1B | MMC_CMD_AC;
|
||||
err = mmc_wait_for_cmd(host, &cmd, 0);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/*
|
||||
* If the host does not wait while the card signals busy, then we will
|
||||
* will have to wait the sleep/awake timeout. Note, we cannot use the
|
||||
* SEND_STATUS command to poll the status because that command (and most
|
||||
* others) is invalid while the card sleeps.
|
||||
*/
|
||||
if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY))
|
||||
mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000));
|
||||
|
||||
if (!sleep)
|
||||
err = mmc_select_card(card);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int mmc_go_idle(struct mmc_host *host)
|
||||
{
|
||||
int err;
|
||||
@@ -354,6 +390,7 @@ int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value)
|
||||
{
|
||||
int err;
|
||||
struct mmc_command cmd;
|
||||
u32 status;
|
||||
|
||||
BUG_ON(!card);
|
||||
BUG_ON(!card->host);
|
||||
@@ -371,6 +408,28 @@ int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value)
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* Must check status to be sure of no errors */
|
||||
do {
|
||||
err = mmc_send_status(card, &status);
|
||||
if (err)
|
||||
return err;
|
||||
if (card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
|
||||
break;
|
||||
if (mmc_host_is_spi(card->host))
|
||||
break;
|
||||
} while (R1_CURRENT_STATE(status) == 7);
|
||||
|
||||
if (mmc_host_is_spi(card->host)) {
|
||||
if (status & R1_SPI_ILLEGAL_COMMAND)
|
||||
return -EBADMSG;
|
||||
} else {
|
||||
if (status & 0xFDFFA000)
|
||||
printk(KERN_WARNING "%s: unexpected status %#x after "
|
||||
"switch", mmc_hostname(card->host), status);
|
||||
if (status & R1_SWITCH_ERROR)
|
||||
return -EBADMSG;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,7 @@ int mmc_send_status(struct mmc_card *card, u32 *status);
|
||||
int mmc_send_cid(struct mmc_host *host, u32 *cid);
|
||||
int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp);
|
||||
int mmc_spi_set_crc(struct mmc_host *host, int use_crc);
|
||||
int mmc_card_sleepawake(struct mmc_host *host, int sleep);
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -210,11 +210,11 @@ static int mmc_read_switch(struct mmc_card *card)
|
||||
|
||||
err = mmc_sd_switch(card, 0, 0, 1, status);
|
||||
if (err) {
|
||||
/*
|
||||
* We all hosts that cannot perform the command
|
||||
* to fail more gracefully
|
||||
*/
|
||||
if (err != -EINVAL)
|
||||
/* If the host or the card can't do the switch,
|
||||
* fail more gracefully. */
|
||||
if ((err != -EINVAL)
|
||||
&& (err != -ENOSYS)
|
||||
&& (err != -EFAULT))
|
||||
goto out;
|
||||
|
||||
printk(KERN_WARNING "%s: problem reading switch "
|
||||
@@ -561,12 +561,10 @@ static void mmc_sd_detect(struct mmc_host *host)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MMC_UNSAFE_RESUME
|
||||
|
||||
/*
|
||||
* Suspend callback from host.
|
||||
*/
|
||||
static void mmc_sd_suspend(struct mmc_host *host)
|
||||
static int mmc_sd_suspend(struct mmc_host *host)
|
||||
{
|
||||
BUG_ON(!host);
|
||||
BUG_ON(!host->card);
|
||||
@@ -576,6 +574,8 @@ static void mmc_sd_suspend(struct mmc_host *host)
|
||||
mmc_deselect_cards(host);
|
||||
host->card->state &= ~MMC_STATE_HIGHSPEED;
|
||||
mmc_release_host(host);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -584,7 +584,7 @@ static void mmc_sd_suspend(struct mmc_host *host)
|
||||
* This function tries to determine if the same card is still present
|
||||
* and, if so, restore all state to it.
|
||||
*/
|
||||
static void mmc_sd_resume(struct mmc_host *host)
|
||||
static int mmc_sd_resume(struct mmc_host *host)
|
||||
{
|
||||
int err;
|
||||
|
||||
@@ -595,30 +595,63 @@ static void mmc_sd_resume(struct mmc_host *host)
|
||||
err = mmc_sd_init_card(host, host->ocr, host->card);
|
||||
mmc_release_host(host);
|
||||
|
||||
if (err) {
|
||||
mmc_sd_remove(host);
|
||||
|
||||
mmc_claim_host(host);
|
||||
mmc_detach_bus(host);
|
||||
mmc_release_host(host);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#else
|
||||
static void mmc_sd_power_restore(struct mmc_host *host)
|
||||
{
|
||||
host->card->state &= ~MMC_STATE_HIGHSPEED;
|
||||
mmc_claim_host(host);
|
||||
mmc_sd_init_card(host, host->ocr, host->card);
|
||||
mmc_release_host(host);
|
||||
}
|
||||
|
||||
#define mmc_sd_suspend NULL
|
||||
#define mmc_sd_resume NULL
|
||||
|
||||
#endif
|
||||
#ifdef CONFIG_MMC_UNSAFE_RESUME
|
||||
|
||||
static const struct mmc_bus_ops mmc_sd_ops = {
|
||||
.remove = mmc_sd_remove,
|
||||
.detect = mmc_sd_detect,
|
||||
.suspend = mmc_sd_suspend,
|
||||
.resume = mmc_sd_resume,
|
||||
.power_restore = mmc_sd_power_restore,
|
||||
};
|
||||
|
||||
static void mmc_sd_attach_bus_ops(struct mmc_host *host)
|
||||
{
|
||||
mmc_attach_bus(host, &mmc_sd_ops);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static const struct mmc_bus_ops mmc_sd_ops = {
|
||||
.remove = mmc_sd_remove,
|
||||
.detect = mmc_sd_detect,
|
||||
.suspend = NULL,
|
||||
.resume = NULL,
|
||||
.power_restore = mmc_sd_power_restore,
|
||||
};
|
||||
|
||||
static const struct mmc_bus_ops mmc_sd_ops_unsafe = {
|
||||
.remove = mmc_sd_remove,
|
||||
.detect = mmc_sd_detect,
|
||||
.suspend = mmc_sd_suspend,
|
||||
.resume = mmc_sd_resume,
|
||||
.power_restore = mmc_sd_power_restore,
|
||||
};
|
||||
|
||||
static void mmc_sd_attach_bus_ops(struct mmc_host *host)
|
||||
{
|
||||
const struct mmc_bus_ops *bus_ops;
|
||||
|
||||
if (host->caps & MMC_CAP_NONREMOVABLE)
|
||||
bus_ops = &mmc_sd_ops_unsafe;
|
||||
else
|
||||
bus_ops = &mmc_sd_ops;
|
||||
mmc_attach_bus(host, bus_ops);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Starting point for SD card init.
|
||||
*/
|
||||
@@ -629,7 +662,7 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)
|
||||
BUG_ON(!host);
|
||||
WARN_ON(!host->claimed);
|
||||
|
||||
mmc_attach_bus(host, &mmc_sd_ops);
|
||||
mmc_sd_attach_bus_ops(host);
|
||||
|
||||
/*
|
||||
* We need to get OCR a different way for SPI.
|
||||
|
@@ -164,6 +164,29 @@ static int sdio_enable_wide(struct mmc_card *card)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* If desired, disconnect the pull-up resistor on CD/DAT[3] (pin 1)
|
||||
* of the card. This may be required on certain setups of boards,
|
||||
* controllers and embedded sdio device which do not need the card's
|
||||
* pull-up. As a result, card detection is disabled and power is saved.
|
||||
*/
|
||||
static int sdio_disable_cd(struct mmc_card *card)
|
||||
{
|
||||
int ret;
|
||||
u8 ctrl;
|
||||
|
||||
if (!card->cccr.disable_cd)
|
||||
return 0;
|
||||
|
||||
ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &ctrl);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ctrl |= SDIO_BUS_CD_DISABLE;
|
||||
|
||||
return mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test if the card supports high-speed mode and, if so, switch to it.
|
||||
*/
|
||||
@@ -194,6 +217,135 @@ static int sdio_enable_hs(struct mmc_card *card)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle the detection and initialisation of a card.
|
||||
*
|
||||
* In the case of a resume, "oldcard" will contain the card
|
||||
* we're trying to reinitialise.
|
||||
*/
|
||||
static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
|
||||
struct mmc_card *oldcard)
|
||||
{
|
||||
struct mmc_card *card;
|
||||
int err;
|
||||
|
||||
BUG_ON(!host);
|
||||
WARN_ON(!host->claimed);
|
||||
|
||||
/*
|
||||
* Inform the card of the voltage
|
||||
*/
|
||||
err = mmc_send_io_op_cond(host, host->ocr, &ocr);
|
||||
if (err)
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* For SPI, enable CRC as appropriate.
|
||||
*/
|
||||
if (mmc_host_is_spi(host)) {
|
||||
err = mmc_spi_set_crc(host, use_spi_crc);
|
||||
if (err)
|
||||
goto err;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate card structure.
|
||||
*/
|
||||
card = mmc_alloc_card(host, NULL);
|
||||
if (IS_ERR(card)) {
|
||||
err = PTR_ERR(card);
|
||||
goto err;
|
||||
}
|
||||
|
||||
card->type = MMC_TYPE_SDIO;
|
||||
|
||||
/*
|
||||
* For native busses: set card RCA and quit open drain mode.
|
||||
*/
|
||||
if (!mmc_host_is_spi(host)) {
|
||||
err = mmc_send_relative_addr(host, &card->rca);
|
||||
if (err)
|
||||
goto remove;
|
||||
|
||||
mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Select card, as all following commands rely on that.
|
||||
*/
|
||||
if (!mmc_host_is_spi(host)) {
|
||||
err = mmc_select_card(card);
|
||||
if (err)
|
||||
goto remove;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the common registers.
|
||||
*/
|
||||
err = sdio_read_cccr(card);
|
||||
if (err)
|
||||
goto remove;
|
||||
|
||||
/*
|
||||
* Read the common CIS tuples.
|
||||
*/
|
||||
err = sdio_read_common_cis(card);
|
||||
if (err)
|
||||
goto remove;
|
||||
|
||||
if (oldcard) {
|
||||
int same = (card->cis.vendor == oldcard->cis.vendor &&
|
||||
card->cis.device == oldcard->cis.device);
|
||||
mmc_remove_card(card);
|
||||
if (!same) {
|
||||
err = -ENOENT;
|
||||
goto err;
|
||||
}
|
||||
card = oldcard;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Switch to high-speed (if supported).
|
||||
*/
|
||||
err = sdio_enable_hs(card);
|
||||
if (err)
|
||||
goto remove;
|
||||
|
||||
/*
|
||||
* Change to the card's maximum speed.
|
||||
*/
|
||||
if (mmc_card_highspeed(card)) {
|
||||
/*
|
||||
* The SDIO specification doesn't mention how
|
||||
* the CIS transfer speed register relates to
|
||||
* high-speed, but it seems that 50 MHz is
|
||||
* mandatory.
|
||||
*/
|
||||
mmc_set_clock(host, 50000000);
|
||||
} else {
|
||||
mmc_set_clock(host, card->cis.max_dtr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Switch to wider bus (if supported).
|
||||
*/
|
||||
err = sdio_enable_wide(card);
|
||||
if (err)
|
||||
goto remove;
|
||||
|
||||
if (!oldcard)
|
||||
host->card = card;
|
||||
return 0;
|
||||
|
||||
remove:
|
||||
if (!oldcard)
|
||||
mmc_remove_card(card);
|
||||
|
||||
err:
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* Host is being removed. Free up the current card.
|
||||
*/
|
||||
@@ -243,10 +395,77 @@ static void mmc_sdio_detect(struct mmc_host *host)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* SDIO suspend. We need to suspend all functions separately.
|
||||
* Therefore all registered functions must have drivers with suspend
|
||||
* and resume methods. Failing that we simply remove the whole card.
|
||||
*/
|
||||
static int mmc_sdio_suspend(struct mmc_host *host)
|
||||
{
|
||||
int i, err = 0;
|
||||
|
||||
for (i = 0; i < host->card->sdio_funcs; i++) {
|
||||
struct sdio_func *func = host->card->sdio_func[i];
|
||||
if (func && sdio_func_present(func) && func->dev.driver) {
|
||||
const struct dev_pm_ops *pmops = func->dev.driver->pm;
|
||||
if (!pmops || !pmops->suspend || !pmops->resume) {
|
||||
/* force removal of entire card in that case */
|
||||
err = -ENOSYS;
|
||||
} else
|
||||
err = pmops->suspend(&func->dev);
|
||||
if (err)
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (err && --i >= 0) {
|
||||
struct sdio_func *func = host->card->sdio_func[i];
|
||||
if (func && sdio_func_present(func) && func->dev.driver) {
|
||||
const struct dev_pm_ops *pmops = func->dev.driver->pm;
|
||||
pmops->resume(&func->dev);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int mmc_sdio_resume(struct mmc_host *host)
|
||||
{
|
||||
int i, err;
|
||||
|
||||
BUG_ON(!host);
|
||||
BUG_ON(!host->card);
|
||||
|
||||
/* Basic card reinitialization. */
|
||||
mmc_claim_host(host);
|
||||
err = mmc_sdio_init_card(host, host->ocr, host->card);
|
||||
mmc_release_host(host);
|
||||
|
||||
/*
|
||||
* If the card looked to be the same as before suspending, then
|
||||
* we proceed to resume all card functions. If one of them returns
|
||||
* an error then we simply return that error to the core and the
|
||||
* card will be redetected as new. It is the responsibility of
|
||||
* the function driver to perform further tests with the extra
|
||||
* knowledge it has of the card to confirm the card is indeed the
|
||||
* same as before suspending (same MAC address for network cards,
|
||||
* etc.) and return an error otherwise.
|
||||
*/
|
||||
for (i = 0; !err && i < host->card->sdio_funcs; i++) {
|
||||
struct sdio_func *func = host->card->sdio_func[i];
|
||||
if (func && sdio_func_present(func) && func->dev.driver) {
|
||||
const struct dev_pm_ops *pmops = func->dev.driver->pm;
|
||||
err = pmops->resume(&func->dev);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static const struct mmc_bus_ops mmc_sdio_ops = {
|
||||
.remove = mmc_sdio_remove,
|
||||
.detect = mmc_sdio_detect,
|
||||
.suspend = mmc_sdio_suspend,
|
||||
.resume = mmc_sdio_resume,
|
||||
};
|
||||
|
||||
|
||||
@@ -275,13 +494,6 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
|
||||
ocr &= ~0x7F;
|
||||
}
|
||||
|
||||
if (ocr & MMC_VDD_165_195) {
|
||||
printk(KERN_WARNING "%s: SDIO card claims to support the "
|
||||
"incompletely defined 'low voltage range'. This "
|
||||
"will be ignored.\n", mmc_hostname(host));
|
||||
ocr &= ~MMC_VDD_165_195;
|
||||
}
|
||||
|
||||
host->ocr = mmc_select_voltage(host, ocr);
|
||||
|
||||
/*
|
||||
@@ -293,101 +505,23 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
|
||||
}
|
||||
|
||||
/*
|
||||
* Inform the card of the voltage
|
||||
* Detect and init the card.
|
||||
*/
|
||||
err = mmc_send_io_op_cond(host, host->ocr, &ocr);
|
||||
err = mmc_sdio_init_card(host, host->ocr, NULL);
|
||||
if (err)
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* For SPI, enable CRC as appropriate.
|
||||
*/
|
||||
if (mmc_host_is_spi(host)) {
|
||||
err = mmc_spi_set_crc(host, use_spi_crc);
|
||||
if (err)
|
||||
goto err;
|
||||
}
|
||||
card = host->card;
|
||||
|
||||
/*
|
||||
* The number of functions on the card is encoded inside
|
||||
* the ocr.
|
||||
*/
|
||||
funcs = (ocr & 0x70000000) >> 28;
|
||||
card->sdio_funcs = funcs = (ocr & 0x70000000) >> 28;
|
||||
|
||||
/*
|
||||
* Allocate card structure.
|
||||
* If needed, disconnect card detection pull-up resistor.
|
||||
*/
|
||||
card = mmc_alloc_card(host, NULL);
|
||||
if (IS_ERR(card)) {
|
||||
err = PTR_ERR(card);
|
||||
goto err;
|
||||
}
|
||||
|
||||
card->type = MMC_TYPE_SDIO;
|
||||
card->sdio_funcs = funcs;
|
||||
|
||||
host->card = card;
|
||||
|
||||
/*
|
||||
* For native busses: set card RCA and quit open drain mode.
|
||||
*/
|
||||
if (!mmc_host_is_spi(host)) {
|
||||
err = mmc_send_relative_addr(host, &card->rca);
|
||||
if (err)
|
||||
goto remove;
|
||||
|
||||
mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Select card, as all following commands rely on that.
|
||||
*/
|
||||
if (!mmc_host_is_spi(host)) {
|
||||
err = mmc_select_card(card);
|
||||
if (err)
|
||||
goto remove;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the common registers.
|
||||
*/
|
||||
err = sdio_read_cccr(card);
|
||||
if (err)
|
||||
goto remove;
|
||||
|
||||
/*
|
||||
* Read the common CIS tuples.
|
||||
*/
|
||||
err = sdio_read_common_cis(card);
|
||||
if (err)
|
||||
goto remove;
|
||||
|
||||
/*
|
||||
* Switch to high-speed (if supported).
|
||||
*/
|
||||
err = sdio_enable_hs(card);
|
||||
if (err)
|
||||
goto remove;
|
||||
|
||||
/*
|
||||
* Change to the card's maximum speed.
|
||||
*/
|
||||
if (mmc_card_highspeed(card)) {
|
||||
/*
|
||||
* The SDIO specification doesn't mention how
|
||||
* the CIS transfer speed register relates to
|
||||
* high-speed, but it seems that 50 MHz is
|
||||
* mandatory.
|
||||
*/
|
||||
mmc_set_clock(host, 50000000);
|
||||
} else {
|
||||
mmc_set_clock(host, card->cis.max_dtr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Switch to wider bus (if supported).
|
||||
*/
|
||||
err = sdio_enable_wide(card);
|
||||
err = sdio_disable_cd(card);
|
||||
if (err)
|
||||
goto remove;
|
||||
|
||||
|
@@ -20,9 +20,6 @@
|
||||
#include "sdio_cis.h"
|
||||
#include "sdio_bus.h"
|
||||
|
||||
#define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev)
|
||||
#define to_sdio_driver(d) container_of(d, struct sdio_driver, drv)
|
||||
|
||||
/* show configuration fields */
|
||||
#define sdio_config_attr(field, format_string) \
|
||||
static ssize_t \
|
||||
|
@@ -40,7 +40,7 @@ static int cistpl_vers_1(struct mmc_card *card, struct sdio_func *func,
|
||||
nr_strings++;
|
||||
}
|
||||
|
||||
if (buf[i-1] != '\0') {
|
||||
if (nr_strings < 4) {
|
||||
printk(KERN_WARNING "SDIO: ignoring broken CISTPL_VERS_1\n");
|
||||
return 0;
|
||||
}
|
||||
|
@@ -624,7 +624,7 @@ void sdio_f0_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
|
||||
|
||||
BUG_ON(!func);
|
||||
|
||||
if (addr < 0xF0 || addr > 0xFF) {
|
||||
if ((addr < 0xF0 || addr > 0xFF) && (!mmc_card_lenient_fn0(func->card))) {
|
||||
if (err_ret)
|
||||
*err_ret = -EINVAL;
|
||||
return;
|
||||
|
@@ -132,11 +132,11 @@ config MMC_OMAP
|
||||
|
||||
config MMC_OMAP_HS
|
||||
tristate "TI OMAP High Speed Multimedia Card Interface support"
|
||||
depends on ARCH_OMAP2430 || ARCH_OMAP3
|
||||
depends on ARCH_OMAP2430 || ARCH_OMAP3 || ARCH_OMAP4
|
||||
help
|
||||
This selects the TI OMAP High Speed Multimedia card Interface.
|
||||
If you have an OMAP2430 or OMAP3 board with a Multimedia Card slot,
|
||||
say Y or M here.
|
||||
If you have an OMAP2430 or OMAP3 board or OMAP4 board with a
|
||||
Multimedia Card slot, say Y or M here.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
@@ -160,6 +160,12 @@ config MMC_AU1X
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
choice
|
||||
prompt "Atmel SD/MMC Driver"
|
||||
default MMC_ATMELMCI if AVR32
|
||||
help
|
||||
Choose which driver to use for the Atmel MCI Silicon
|
||||
|
||||
config MMC_AT91
|
||||
tristate "AT91 SD/MMC Card Interface support"
|
||||
depends on ARCH_AT91
|
||||
@@ -170,17 +176,19 @@ config MMC_AT91
|
||||
|
||||
config MMC_ATMELMCI
|
||||
tristate "Atmel Multimedia Card Interface support"
|
||||
depends on AVR32
|
||||
depends on AVR32 || ARCH_AT91
|
||||
help
|
||||
This selects the Atmel Multimedia Card Interface driver. If
|
||||
you have an AT32 (AVR32) platform with a Multimedia Card
|
||||
slot, say Y or M here.
|
||||
you have an AT32 (AVR32) or AT91 platform with a Multimedia
|
||||
Card slot, say Y or M here.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
endchoice
|
||||
|
||||
config MMC_ATMELMCI_DMA
|
||||
bool "Atmel MCI DMA support (EXPERIMENTAL)"
|
||||
depends on MMC_ATMELMCI && DMA_ENGINE && EXPERIMENTAL
|
||||
depends on MMC_ATMELMCI && AVR32 && DMA_ENGINE && EXPERIMENTAL
|
||||
help
|
||||
Say Y here to have the Atmel MCI driver use a DMA engine to
|
||||
do data transfers and thus increase the throughput and
|
||||
@@ -199,6 +207,13 @@ config MMC_IMX
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config MMC_MSM7X00A
|
||||
tristate "Qualcomm MSM 7X00A SDCC Controller Support"
|
||||
depends on MMC && ARCH_MSM
|
||||
help
|
||||
This provides support for the SD/MMC cell found in the
|
||||
MSM 7X00A controllers from Qualcomm.
|
||||
|
||||
config MMC_MXC
|
||||
tristate "Freescale i.MX2/3 Multimedia Card Interface support"
|
||||
depends on ARCH_MXC
|
||||
|
@@ -23,6 +23,7 @@ obj-$(CONFIG_MMC_OMAP_HS) += omap_hsmmc.o
|
||||
obj-$(CONFIG_MMC_AT91) += at91_mci.o
|
||||
obj-$(CONFIG_MMC_ATMELMCI) += atmel-mci.o
|
||||
obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
|
||||
obj-$(CONFIG_MMC_MSM7X00A) += msm_sdcc.o
|
||||
obj-$(CONFIG_MMC_MVSDIO) += mvsdio.o
|
||||
obj-$(CONFIG_MMC_SPI) += mmc_spi.o
|
||||
ifeq ($(CONFIG_OF),y)
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include <asm/io.h>
|
||||
#include <asm/unaligned.h>
|
||||
|
||||
#include <mach/cpu.h>
|
||||
#include <mach/board.h>
|
||||
|
||||
#include "atmel-mci-regs.h"
|
||||
@@ -209,6 +210,18 @@ struct atmel_mci_slot {
|
||||
#define atmci_set_pending(host, event) \
|
||||
set_bit(event, &host->pending_events)
|
||||
|
||||
/*
|
||||
* Enable or disable features/registers based on
|
||||
* whether the processor supports them
|
||||
*/
|
||||
static bool mci_has_rwproof(void)
|
||||
{
|
||||
if (cpu_is_at91sam9261() || cpu_is_at91rm9200())
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* The debugfs stuff below is mostly optimized away when
|
||||
* CONFIG_DEBUG_FS is not set.
|
||||
@@ -276,8 +289,13 @@ static void atmci_show_status_reg(struct seq_file *s,
|
||||
[3] = "BLKE",
|
||||
[4] = "DTIP",
|
||||
[5] = "NOTBUSY",
|
||||
[6] = "ENDRX",
|
||||
[7] = "ENDTX",
|
||||
[8] = "SDIOIRQA",
|
||||
[9] = "SDIOIRQB",
|
||||
[12] = "SDIOWAIT",
|
||||
[14] = "RXBUFF",
|
||||
[15] = "TXBUFE",
|
||||
[16] = "RINDE",
|
||||
[17] = "RDIRE",
|
||||
[18] = "RCRCE",
|
||||
@@ -285,6 +303,11 @@ static void atmci_show_status_reg(struct seq_file *s,
|
||||
[20] = "RTOE",
|
||||
[21] = "DCRCE",
|
||||
[22] = "DTOE",
|
||||
[23] = "CSTOE",
|
||||
[24] = "BLKOVRE",
|
||||
[25] = "DMADONE",
|
||||
[26] = "FIFOEMPTY",
|
||||
[27] = "XFRDONE",
|
||||
[30] = "OVRE",
|
||||
[31] = "UNRE",
|
||||
};
|
||||
@@ -576,6 +599,7 @@ atmci_submit_data_dma(struct atmel_mci *host, struct mmc_data *data)
|
||||
struct scatterlist *sg;
|
||||
unsigned int i;
|
||||
enum dma_data_direction direction;
|
||||
unsigned int sglen;
|
||||
|
||||
/*
|
||||
* We don't do DMA on "complex" transfers, i.e. with
|
||||
@@ -605,11 +629,14 @@ atmci_submit_data_dma(struct atmel_mci *host, struct mmc_data *data)
|
||||
else
|
||||
direction = DMA_TO_DEVICE;
|
||||
|
||||
sglen = dma_map_sg(&host->pdev->dev, data->sg, data->sg_len, direction);
|
||||
if (sglen != data->sg_len)
|
||||
goto unmap_exit;
|
||||
desc = chan->device->device_prep_slave_sg(chan,
|
||||
data->sg, data->sg_len, direction,
|
||||
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
|
||||
if (!desc)
|
||||
return -ENOMEM;
|
||||
goto unmap_exit;
|
||||
|
||||
host->dma.data_desc = desc;
|
||||
desc->callback = atmci_dma_complete;
|
||||
@@ -620,6 +647,9 @@ atmci_submit_data_dma(struct atmel_mci *host, struct mmc_data *data)
|
||||
chan->device->device_issue_pending(chan);
|
||||
|
||||
return 0;
|
||||
unmap_exit:
|
||||
dma_unmap_sg(&host->pdev->dev, data->sg, sglen, direction);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
#else /* CONFIG_MMC_ATMELMCI_DMA */
|
||||
@@ -849,13 +879,15 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
|
||||
clkdiv = 255;
|
||||
}
|
||||
|
||||
host->mode_reg = MCI_MR_CLKDIV(clkdiv);
|
||||
|
||||
/*
|
||||
* WRPROOF and RDPROOF prevent overruns/underruns by
|
||||
* stopping the clock when the FIFO is full/empty.
|
||||
* This state is not expected to last for long.
|
||||
*/
|
||||
host->mode_reg = MCI_MR_CLKDIV(clkdiv) | MCI_MR_WRPROOF
|
||||
| MCI_MR_RDPROOF;
|
||||
if (mci_has_rwproof())
|
||||
host->mode_reg |= (MCI_MR_WRPROOF | MCI_MR_RDPROOF);
|
||||
|
||||
if (list_empty(&host->queue))
|
||||
mci_writel(host, MR, host->mode_reg);
|
||||
@@ -1648,8 +1680,10 @@ static int __init atmci_probe(struct platform_device *pdev)
|
||||
nr_slots++;
|
||||
}
|
||||
|
||||
if (!nr_slots)
|
||||
if (!nr_slots) {
|
||||
dev_err(&pdev->dev, "init failed: no slot defined\n");
|
||||
goto err_init_slot;
|
||||
}
|
||||
|
||||
dev_info(&pdev->dev,
|
||||
"Atmel MCI controller at 0x%08lx irq %d, %u slots\n",
|
||||
|
@@ -1562,3 +1562,4 @@ MODULE_AUTHOR("Mike Lavender, David Brownell, "
|
||||
"Hans-Peter Nilsson, Jan Nikitenko");
|
||||
MODULE_DESCRIPTION("SPI SD/MMC host driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS("spi:mmc_spi");
|
||||
|
1287
drivers/mmc/host/msm_sdcc.c
Normal file
1287
drivers/mmc/host/msm_sdcc.c
Normal file
File diff suppressed because it is too large
Load Diff
238
drivers/mmc/host/msm_sdcc.h
Normal file
238
drivers/mmc/host/msm_sdcc.h
Normal file
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* linux/drivers/mmc/host/msmsdcc.h - QCT MSM7K SDC Controller
|
||||
*
|
||||
* Copyright (C) 2008 Google, 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 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* - Based on mmci.h
|
||||
*/
|
||||
|
||||
#ifndef _MSM_SDCC_H
|
||||
#define _MSM_SDCC_H
|
||||
|
||||
#define MSMSDCC_CRCI_SDC1 6
|
||||
#define MSMSDCC_CRCI_SDC2 7
|
||||
#define MSMSDCC_CRCI_SDC3 12
|
||||
#define MSMSDCC_CRCI_SDC4 13
|
||||
|
||||
#define MMCIPOWER 0x000
|
||||
#define MCI_PWR_OFF 0x00
|
||||
#define MCI_PWR_UP 0x02
|
||||
#define MCI_PWR_ON 0x03
|
||||
#define MCI_OD (1 << 6)
|
||||
|
||||
#define MMCICLOCK 0x004
|
||||
#define MCI_CLK_ENABLE (1 << 8)
|
||||
#define MCI_CLK_PWRSAVE (1 << 9)
|
||||
#define MCI_CLK_WIDEBUS (1 << 10)
|
||||
#define MCI_CLK_FLOWENA (1 << 12)
|
||||
#define MCI_CLK_INVERTOUT (1 << 13)
|
||||
#define MCI_CLK_SELECTIN (1 << 14)
|
||||
|
||||
#define MMCIARGUMENT 0x008
|
||||
#define MMCICOMMAND 0x00c
|
||||
#define MCI_CPSM_RESPONSE (1 << 6)
|
||||
#define MCI_CPSM_LONGRSP (1 << 7)
|
||||
#define MCI_CPSM_INTERRUPT (1 << 8)
|
||||
#define MCI_CPSM_PENDING (1 << 9)
|
||||
#define MCI_CPSM_ENABLE (1 << 10)
|
||||
#define MCI_CPSM_PROGENA (1 << 11)
|
||||
#define MCI_CSPM_DATCMD (1 << 12)
|
||||
#define MCI_CSPM_MCIABORT (1 << 13)
|
||||
#define MCI_CSPM_CCSENABLE (1 << 14)
|
||||
#define MCI_CSPM_CCSDISABLE (1 << 15)
|
||||
|
||||
|
||||
#define MMCIRESPCMD 0x010
|
||||
#define MMCIRESPONSE0 0x014
|
||||
#define MMCIRESPONSE1 0x018
|
||||
#define MMCIRESPONSE2 0x01c
|
||||
#define MMCIRESPONSE3 0x020
|
||||
#define MMCIDATATIMER 0x024
|
||||
#define MMCIDATALENGTH 0x028
|
||||
|
||||
#define MMCIDATACTRL 0x02c
|
||||
#define MCI_DPSM_ENABLE (1 << 0)
|
||||
#define MCI_DPSM_DIRECTION (1 << 1)
|
||||
#define MCI_DPSM_MODE (1 << 2)
|
||||
#define MCI_DPSM_DMAENABLE (1 << 3)
|
||||
|
||||
#define MMCIDATACNT 0x030
|
||||
#define MMCISTATUS 0x034
|
||||
#define MCI_CMDCRCFAIL (1 << 0)
|
||||
#define MCI_DATACRCFAIL (1 << 1)
|
||||
#define MCI_CMDTIMEOUT (1 << 2)
|
||||
#define MCI_DATATIMEOUT (1 << 3)
|
||||
#define MCI_TXUNDERRUN (1 << 4)
|
||||
#define MCI_RXOVERRUN (1 << 5)
|
||||
#define MCI_CMDRESPEND (1 << 6)
|
||||
#define MCI_CMDSENT (1 << 7)
|
||||
#define MCI_DATAEND (1 << 8)
|
||||
#define MCI_DATABLOCKEND (1 << 10)
|
||||
#define MCI_CMDACTIVE (1 << 11)
|
||||
#define MCI_TXACTIVE (1 << 12)
|
||||
#define MCI_RXACTIVE (1 << 13)
|
||||
#define MCI_TXFIFOHALFEMPTY (1 << 14)
|
||||
#define MCI_RXFIFOHALFFULL (1 << 15)
|
||||
#define MCI_TXFIFOFULL (1 << 16)
|
||||
#define MCI_RXFIFOFULL (1 << 17)
|
||||
#define MCI_TXFIFOEMPTY (1 << 18)
|
||||
#define MCI_RXFIFOEMPTY (1 << 19)
|
||||
#define MCI_TXDATAAVLBL (1 << 20)
|
||||
#define MCI_RXDATAAVLBL (1 << 21)
|
||||
#define MCI_SDIOINTR (1 << 22)
|
||||
#define MCI_PROGDONE (1 << 23)
|
||||
#define MCI_ATACMDCOMPL (1 << 24)
|
||||
#define MCI_SDIOINTOPER (1 << 25)
|
||||
#define MCI_CCSTIMEOUT (1 << 26)
|
||||
|
||||
#define MMCICLEAR 0x038
|
||||
#define MCI_CMDCRCFAILCLR (1 << 0)
|
||||
#define MCI_DATACRCFAILCLR (1 << 1)
|
||||
#define MCI_CMDTIMEOUTCLR (1 << 2)
|
||||
#define MCI_DATATIMEOUTCLR (1 << 3)
|
||||
#define MCI_TXUNDERRUNCLR (1 << 4)
|
||||
#define MCI_RXOVERRUNCLR (1 << 5)
|
||||
#define MCI_CMDRESPENDCLR (1 << 6)
|
||||
#define MCI_CMDSENTCLR (1 << 7)
|
||||
#define MCI_DATAENDCLR (1 << 8)
|
||||
#define MCI_DATABLOCKENDCLR (1 << 10)
|
||||
|
||||
#define MMCIMASK0 0x03c
|
||||
#define MCI_CMDCRCFAILMASK (1 << 0)
|
||||
#define MCI_DATACRCFAILMASK (1 << 1)
|
||||
#define MCI_CMDTIMEOUTMASK (1 << 2)
|
||||
#define MCI_DATATIMEOUTMASK (1 << 3)
|
||||
#define MCI_TXUNDERRUNMASK (1 << 4)
|
||||
#define MCI_RXOVERRUNMASK (1 << 5)
|
||||
#define MCI_CMDRESPENDMASK (1 << 6)
|
||||
#define MCI_CMDSENTMASK (1 << 7)
|
||||
#define MCI_DATAENDMASK (1 << 8)
|
||||
#define MCI_DATABLOCKENDMASK (1 << 10)
|
||||
#define MCI_CMDACTIVEMASK (1 << 11)
|
||||
#define MCI_TXACTIVEMASK (1 << 12)
|
||||
#define MCI_RXACTIVEMASK (1 << 13)
|
||||
#define MCI_TXFIFOHALFEMPTYMASK (1 << 14)
|
||||
#define MCI_RXFIFOHALFFULLMASK (1 << 15)
|
||||
#define MCI_TXFIFOFULLMASK (1 << 16)
|
||||
#define MCI_RXFIFOFULLMASK (1 << 17)
|
||||
#define MCI_TXFIFOEMPTYMASK (1 << 18)
|
||||
#define MCI_RXFIFOEMPTYMASK (1 << 19)
|
||||
#define MCI_TXDATAAVLBLMASK (1 << 20)
|
||||
#define MCI_RXDATAAVLBLMASK (1 << 21)
|
||||
#define MCI_SDIOINTMASK (1 << 22)
|
||||
#define MCI_PROGDONEMASK (1 << 23)
|
||||
#define MCI_ATACMDCOMPLMASK (1 << 24)
|
||||
#define MCI_SDIOINTOPERMASK (1 << 25)
|
||||
#define MCI_CCSTIMEOUTMASK (1 << 26)
|
||||
|
||||
#define MMCIMASK1 0x040
|
||||
#define MMCIFIFOCNT 0x044
|
||||
#define MCICCSTIMER 0x058
|
||||
|
||||
#define MMCIFIFO 0x080 /* to 0x0bc */
|
||||
|
||||
#define MCI_IRQENABLE \
|
||||
(MCI_CMDCRCFAILMASK|MCI_DATACRCFAILMASK|MCI_CMDTIMEOUTMASK| \
|
||||
MCI_DATATIMEOUTMASK|MCI_TXUNDERRUNMASK|MCI_RXOVERRUNMASK| \
|
||||
MCI_CMDRESPENDMASK|MCI_CMDSENTMASK|MCI_DATAENDMASK)
|
||||
|
||||
/*
|
||||
* The size of the FIFO in bytes.
|
||||
*/
|
||||
#define MCI_FIFOSIZE (16*4)
|
||||
|
||||
#define MCI_FIFOHALFSIZE (MCI_FIFOSIZE / 2)
|
||||
|
||||
#define NR_SG 32
|
||||
|
||||
struct clk;
|
||||
|
||||
struct msmsdcc_nc_dmadata {
|
||||
dmov_box cmd[NR_SG];
|
||||
uint32_t cmdptr;
|
||||
};
|
||||
|
||||
struct msmsdcc_dma_data {
|
||||
struct msmsdcc_nc_dmadata *nc;
|
||||
dma_addr_t nc_busaddr;
|
||||
dma_addr_t cmd_busaddr;
|
||||
dma_addr_t cmdptr_busaddr;
|
||||
|
||||
struct msm_dmov_cmd hdr;
|
||||
enum dma_data_direction dir;
|
||||
|
||||
struct scatterlist *sg;
|
||||
int num_ents;
|
||||
|
||||
int channel;
|
||||
struct msmsdcc_host *host;
|
||||
int busy; /* Set if DM is busy */
|
||||
};
|
||||
|
||||
struct msmsdcc_pio_data {
|
||||
struct scatterlist *sg;
|
||||
unsigned int sg_len;
|
||||
unsigned int sg_off;
|
||||
};
|
||||
|
||||
struct msmsdcc_curr_req {
|
||||
struct mmc_request *mrq;
|
||||
struct mmc_command *cmd;
|
||||
struct mmc_data *data;
|
||||
unsigned int xfer_size; /* Total data size */
|
||||
unsigned int xfer_remain; /* Bytes remaining to send */
|
||||
unsigned int data_xfered; /* Bytes acked by BLKEND irq */
|
||||
int got_dataend;
|
||||
int got_datablkend;
|
||||
int user_pages;
|
||||
};
|
||||
|
||||
struct msmsdcc_stats {
|
||||
unsigned int reqs;
|
||||
unsigned int cmds;
|
||||
unsigned int cmdpoll_hits;
|
||||
unsigned int cmdpoll_misses;
|
||||
};
|
||||
|
||||
struct msmsdcc_host {
|
||||
struct resource *cmd_irqres;
|
||||
struct resource *pio_irqres;
|
||||
struct resource *memres;
|
||||
struct resource *dmares;
|
||||
void __iomem *base;
|
||||
int pdev_id;
|
||||
unsigned int stat_irq;
|
||||
|
||||
struct msmsdcc_curr_req curr;
|
||||
|
||||
struct mmc_host *mmc;
|
||||
struct clk *clk; /* main MMC bus clock */
|
||||
struct clk *pclk; /* SDCC peripheral bus clock */
|
||||
unsigned int clks_on; /* set if clocks are enabled */
|
||||
struct timer_list command_timer;
|
||||
|
||||
unsigned int eject; /* eject state */
|
||||
|
||||
spinlock_t lock;
|
||||
|
||||
unsigned int clk_rate; /* Current clock rate */
|
||||
unsigned int pclk_rate;
|
||||
|
||||
u32 pwr;
|
||||
u32 saved_irq0mask; /* MMCIMASK0 reg value */
|
||||
struct mmc_platform_data *plat;
|
||||
|
||||
struct timer_list timer;
|
||||
unsigned int oldstat;
|
||||
|
||||
struct msmsdcc_dma_data dma;
|
||||
struct msmsdcc_pio_data pio;
|
||||
int cmdpoll;
|
||||
struct msmsdcc_stats stats;
|
||||
};
|
||||
|
||||
#endif
|
@@ -512,7 +512,7 @@ static void mxcmci_cmd_done(struct mxcmci_host *host, unsigned int stat)
|
||||
}
|
||||
|
||||
/* For the DMA case the DMA engine handles the data transfer
|
||||
* automatically. For non DMA we have to to it ourselves.
|
||||
* automatically. For non DMA we have to do it ourselves.
|
||||
* Don't do it in interrupt context though.
|
||||
*/
|
||||
if (!mxcmci_use_dma(host) && host->data)
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -21,6 +21,7 @@
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/mmc/host.h>
|
||||
#include <asm/machdep.h>
|
||||
#include "sdhci.h"
|
||||
|
||||
struct sdhci_of_data {
|
||||
@@ -48,6 +49,8 @@ struct sdhci_of_host {
|
||||
#define ESDHC_CLOCK_HCKEN 0x00000002
|
||||
#define ESDHC_CLOCK_IPGEN 0x00000001
|
||||
|
||||
#define ESDHC_HOST_CONTROL_RES 0x05
|
||||
|
||||
static u32 esdhc_readl(struct sdhci_host *host, int reg)
|
||||
{
|
||||
return in_be32(host->ioaddr + reg);
|
||||
@@ -109,13 +112,17 @@ static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg)
|
||||
int base = reg & ~0x3;
|
||||
int shift = (reg & 0x3) * 8;
|
||||
|
||||
/* Prevent SDHCI core from writing reserved bits (e.g. HISPD). */
|
||||
if (reg == SDHCI_HOST_CONTROL)
|
||||
val &= ~ESDHC_HOST_CONTROL_RES;
|
||||
|
||||
clrsetbits_be32(host->ioaddr + base , 0xff << shift, val << shift);
|
||||
}
|
||||
|
||||
static void esdhc_set_clock(struct sdhci_host *host, unsigned int clock)
|
||||
{
|
||||
int div;
|
||||
int pre_div = 2;
|
||||
int div = 1;
|
||||
|
||||
clrbits32(host->ioaddr + ESDHC_SYSTEM_CONTROL, ESDHC_CLOCK_IPGEN |
|
||||
ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK);
|
||||
@@ -123,19 +130,17 @@ static void esdhc_set_clock(struct sdhci_host *host, unsigned int clock)
|
||||
if (clock == 0)
|
||||
goto out;
|
||||
|
||||
if (host->max_clk / 16 > clock) {
|
||||
for (; pre_div < 256; pre_div *= 2) {
|
||||
if (host->max_clk / pre_div < clock * 16)
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
|
||||
pre_div *= 2;
|
||||
|
||||
for (div = 1; div <= 16; div++) {
|
||||
if (host->max_clk / (div * pre_div) <= clock)
|
||||
break;
|
||||
}
|
||||
while (host->max_clk / pre_div / div > clock && div < 16)
|
||||
div++;
|
||||
|
||||
dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
|
||||
clock, host->max_clk / pre_div / div);
|
||||
|
||||
pre_div >>= 1;
|
||||
div--;
|
||||
|
||||
setbits32(host->ioaddr + ESDHC_SYSTEM_CONTROL, ESDHC_CLOCK_IPGEN |
|
||||
ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN |
|
||||
@@ -165,19 +170,12 @@ static unsigned int esdhc_get_min_clock(struct sdhci_host *host)
|
||||
return of_host->clock / 256 / 16;
|
||||
}
|
||||
|
||||
static unsigned int esdhc_get_timeout_clock(struct sdhci_host *host)
|
||||
{
|
||||
struct sdhci_of_host *of_host = sdhci_priv(host);
|
||||
|
||||
return of_host->clock / 1000;
|
||||
}
|
||||
|
||||
static struct sdhci_of_data sdhci_esdhc = {
|
||||
.quirks = SDHCI_QUIRK_FORCE_BLK_SZ_2048 |
|
||||
SDHCI_QUIRK_BROKEN_CARD_DETECTION |
|
||||
SDHCI_QUIRK_INVERTED_WRITE_PROTECT |
|
||||
SDHCI_QUIRK_NO_BUSY_IRQ |
|
||||
SDHCI_QUIRK_NONSTANDARD_CLOCK |
|
||||
SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
|
||||
SDHCI_QUIRK_PIO_NEEDS_DELAY |
|
||||
SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET |
|
||||
SDHCI_QUIRK_NO_CARD_NO_RESET,
|
||||
@@ -192,7 +190,6 @@ static struct sdhci_of_data sdhci_esdhc = {
|
||||
.enable_dma = esdhc_enable_dma,
|
||||
.get_max_clock = esdhc_get_max_clock,
|
||||
.get_min_clock = esdhc_get_min_clock,
|
||||
.get_timeout_clock = esdhc_get_timeout_clock,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -219,6 +216,15 @@ static int sdhci_of_resume(struct of_device *ofdev)
|
||||
|
||||
#endif
|
||||
|
||||
static bool __devinit sdhci_of_wp_inverted(struct device_node *np)
|
||||
{
|
||||
if (of_get_property(np, "sdhci,wp-inverted", NULL))
|
||||
return true;
|
||||
|
||||
/* Old device trees don't have the wp-inverted property. */
|
||||
return machine_is(mpc837x_rdb) || machine_is(mpc837x_mds);
|
||||
}
|
||||
|
||||
static int __devinit sdhci_of_probe(struct of_device *ofdev,
|
||||
const struct of_device_id *match)
|
||||
{
|
||||
@@ -261,6 +267,9 @@ static int __devinit sdhci_of_probe(struct of_device *ofdev,
|
||||
if (of_get_property(np, "sdhci,1-bit-only", NULL))
|
||||
host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA;
|
||||
|
||||
if (sdhci_of_wp_inverted(np))
|
||||
host->quirks |= SDHCI_QUIRK_INVERTED_WRITE_PROTECT;
|
||||
|
||||
clk = of_get_property(np, "clock-frequency", &size);
|
||||
if (clk && size == sizeof(*clk) && *clk)
|
||||
of_host->clock = *clk;
|
||||
|
@@ -83,7 +83,8 @@ static int ricoh_probe(struct sdhci_pci_chip *chip)
|
||||
if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
|
||||
chip->quirks |= SDHCI_QUIRK_CLOCK_BEFORE_RESET;
|
||||
|
||||
if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG)
|
||||
if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
|
||||
chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
|
||||
chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
|
||||
|
||||
return 0;
|
||||
@@ -395,7 +396,7 @@ static int sdhci_pci_enable_dma(struct sdhci_host *host)
|
||||
|
||||
if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
|
||||
((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
|
||||
(host->flags & SDHCI_USE_DMA)) {
|
||||
(host->flags & SDHCI_USE_SDMA)) {
|
||||
dev_warn(&pdev->dev, "Will use DMA mode even though HW "
|
||||
"doesn't fully claim to support it.\n");
|
||||
}
|
||||
|
@@ -591,6 +591,9 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_data *data)
|
||||
target_timeout = data->timeout_ns / 1000 +
|
||||
data->timeout_clks / host->clock;
|
||||
|
||||
if (host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)
|
||||
host->timeout_clk = host->clock / 1000;
|
||||
|
||||
/*
|
||||
* Figure out needed cycles.
|
||||
* We do this in steps in order to fit inside a 32 bit int.
|
||||
@@ -652,7 +655,7 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
|
||||
count = sdhci_calc_timeout(host, data);
|
||||
sdhci_writeb(host, count, SDHCI_TIMEOUT_CONTROL);
|
||||
|
||||
if (host->flags & SDHCI_USE_DMA)
|
||||
if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))
|
||||
host->flags |= SDHCI_REQ_USE_DMA;
|
||||
|
||||
/*
|
||||
@@ -991,8 +994,8 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
|
||||
clk |= SDHCI_CLOCK_INT_EN;
|
||||
sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
|
||||
|
||||
/* Wait max 10 ms */
|
||||
timeout = 10;
|
||||
/* Wait max 20 ms */
|
||||
timeout = 20;
|
||||
while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
|
||||
& SDHCI_CLOCK_INT_STABLE)) {
|
||||
if (timeout == 0) {
|
||||
@@ -1597,7 +1600,7 @@ int sdhci_resume_host(struct sdhci_host *host)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (host->flags & SDHCI_USE_DMA) {
|
||||
if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
|
||||
if (host->ops->enable_dma)
|
||||
host->ops->enable_dma(host);
|
||||
}
|
||||
@@ -1678,23 +1681,20 @@ int sdhci_add_host(struct sdhci_host *host)
|
||||
caps = sdhci_readl(host, SDHCI_CAPABILITIES);
|
||||
|
||||
if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
|
||||
host->flags |= SDHCI_USE_DMA;
|
||||
else if (!(caps & SDHCI_CAN_DO_DMA))
|
||||
DBG("Controller doesn't have DMA capability\n");
|
||||
host->flags |= SDHCI_USE_SDMA;
|
||||
else if (!(caps & SDHCI_CAN_DO_SDMA))
|
||||
DBG("Controller doesn't have SDMA capability\n");
|
||||
else
|
||||
host->flags |= SDHCI_USE_DMA;
|
||||
host->flags |= SDHCI_USE_SDMA;
|
||||
|
||||
if ((host->quirks & SDHCI_QUIRK_BROKEN_DMA) &&
|
||||
(host->flags & SDHCI_USE_DMA)) {
|
||||
(host->flags & SDHCI_USE_SDMA)) {
|
||||
DBG("Disabling DMA as it is marked broken\n");
|
||||
host->flags &= ~SDHCI_USE_DMA;
|
||||
host->flags &= ~SDHCI_USE_SDMA;
|
||||
}
|
||||
|
||||
if (host->flags & SDHCI_USE_DMA) {
|
||||
if ((host->version >= SDHCI_SPEC_200) &&
|
||||
(caps & SDHCI_CAN_DO_ADMA2))
|
||||
host->flags |= SDHCI_USE_ADMA;
|
||||
}
|
||||
if ((host->version >= SDHCI_SPEC_200) && (caps & SDHCI_CAN_DO_ADMA2))
|
||||
host->flags |= SDHCI_USE_ADMA;
|
||||
|
||||
if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
|
||||
(host->flags & SDHCI_USE_ADMA)) {
|
||||
@@ -1702,13 +1702,14 @@ int sdhci_add_host(struct sdhci_host *host)
|
||||
host->flags &= ~SDHCI_USE_ADMA;
|
||||
}
|
||||
|
||||
if (host->flags & SDHCI_USE_DMA) {
|
||||
if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
|
||||
if (host->ops->enable_dma) {
|
||||
if (host->ops->enable_dma(host)) {
|
||||
printk(KERN_WARNING "%s: No suitable DMA "
|
||||
"available. Falling back to PIO.\n",
|
||||
mmc_hostname(mmc));
|
||||
host->flags &= ~(SDHCI_USE_DMA | SDHCI_USE_ADMA);
|
||||
host->flags &=
|
||||
~(SDHCI_USE_SDMA | SDHCI_USE_ADMA);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1736,7 +1737,7 @@ int sdhci_add_host(struct sdhci_host *host)
|
||||
* mask, but PIO does not need the hw shim so we set a new
|
||||
* mask here in that case.
|
||||
*/
|
||||
if (!(host->flags & SDHCI_USE_DMA)) {
|
||||
if (!(host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))) {
|
||||
host->dma_mask = DMA_BIT_MASK(64);
|
||||
mmc_dev(host->mmc)->dma_mask = &host->dma_mask;
|
||||
}
|
||||
@@ -1757,13 +1758,15 @@ int sdhci_add_host(struct sdhci_host *host)
|
||||
host->timeout_clk =
|
||||
(caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
|
||||
if (host->timeout_clk == 0) {
|
||||
if (!host->ops->get_timeout_clock) {
|
||||
if (host->ops->get_timeout_clock) {
|
||||
host->timeout_clk = host->ops->get_timeout_clock(host);
|
||||
} else if (!(host->quirks &
|
||||
SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)) {
|
||||
printk(KERN_ERR
|
||||
"%s: Hardware doesn't specify timeout clock "
|
||||
"frequency.\n", mmc_hostname(mmc));
|
||||
return -ENODEV;
|
||||
}
|
||||
host->timeout_clk = host->ops->get_timeout_clock(host);
|
||||
}
|
||||
if (caps & SDHCI_TIMEOUT_CLK_UNIT)
|
||||
host->timeout_clk *= 1000;
|
||||
@@ -1772,7 +1775,8 @@ int sdhci_add_host(struct sdhci_host *host)
|
||||
* Set host parameters.
|
||||
*/
|
||||
mmc->ops = &sdhci_ops;
|
||||
if (host->ops->get_min_clock)
|
||||
if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK &&
|
||||
host->ops->set_clock && host->ops->get_min_clock)
|
||||
mmc->f_min = host->ops->get_min_clock(host);
|
||||
else
|
||||
mmc->f_min = host->max_clk / 256;
|
||||
@@ -1810,7 +1814,7 @@ int sdhci_add_host(struct sdhci_host *host)
|
||||
*/
|
||||
if (host->flags & SDHCI_USE_ADMA)
|
||||
mmc->max_hw_segs = 128;
|
||||
else if (host->flags & SDHCI_USE_DMA)
|
||||
else if (host->flags & SDHCI_USE_SDMA)
|
||||
mmc->max_hw_segs = 1;
|
||||
else /* PIO */
|
||||
mmc->max_hw_segs = 128;
|
||||
@@ -1893,10 +1897,10 @@ int sdhci_add_host(struct sdhci_host *host)
|
||||
|
||||
mmc_add_host(mmc);
|
||||
|
||||
printk(KERN_INFO "%s: SDHCI controller on %s [%s] using %s%s\n",
|
||||
printk(KERN_INFO "%s: SDHCI controller on %s [%s] using %s\n",
|
||||
mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
|
||||
(host->flags & SDHCI_USE_ADMA)?"A":"",
|
||||
(host->flags & SDHCI_USE_DMA)?"DMA":"PIO");
|
||||
(host->flags & SDHCI_USE_ADMA) ? "ADMA" :
|
||||
(host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
|
||||
|
||||
sdhci_enable_card_detection(host);
|
||||
|
||||
|
@@ -143,7 +143,7 @@
|
||||
#define SDHCI_CAN_DO_ADMA2 0x00080000
|
||||
#define SDHCI_CAN_DO_ADMA1 0x00100000
|
||||
#define SDHCI_CAN_DO_HISPD 0x00200000
|
||||
#define SDHCI_CAN_DO_DMA 0x00400000
|
||||
#define SDHCI_CAN_DO_SDMA 0x00400000
|
||||
#define SDHCI_CAN_VDD_330 0x01000000
|
||||
#define SDHCI_CAN_VDD_300 0x02000000
|
||||
#define SDHCI_CAN_VDD_180 0x04000000
|
||||
@@ -232,6 +232,8 @@ struct sdhci_host {
|
||||
#define SDHCI_QUIRK_FORCE_1_BIT_DATA (1<<22)
|
||||
/* Controller needs 10ms delay between applying power and clock */
|
||||
#define SDHCI_QUIRK_DELAY_AFTER_POWER (1<<23)
|
||||
/* Controller uses SDCLK instead of TMCLK for data timeouts */
|
||||
#define SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK (1<<24)
|
||||
|
||||
int irq; /* Device IRQ */
|
||||
void __iomem * ioaddr; /* Mapped address */
|
||||
@@ -250,7 +252,7 @@ struct sdhci_host {
|
||||
spinlock_t lock; /* Mutex */
|
||||
|
||||
int flags; /* Host attributes */
|
||||
#define SDHCI_USE_DMA (1<<0) /* Host is DMA capable */
|
||||
#define SDHCI_USE_SDMA (1<<0) /* Host is SDMA capable */
|
||||
#define SDHCI_USE_ADMA (1<<1) /* Host is ADMA capable */
|
||||
#define SDHCI_REQ_USE_DMA (1<<2) /* Use DMA for this req. */
|
||||
#define SDHCI_DEVICE_DEAD (1<<3) /* Device unresponsive */
|
||||
|
Reference in New Issue
Block a user