mirror of
https://github.com/armbian/linux.git
synced 2026-01-06 10:13:00 -08:00
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/drzeus/mmc
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/drzeus/mmc: (46 commits) mmc-omap: Clean up omap set_ios and make MMC_POWER_ON work mmc-omap: Fix omap to use MMC_POWER_ON mmc-omap: add missing '\n' mmc: make tifm_sd_set_dma_data() static mmc: remove old card states mmc: support unsafe resume of cards mmc: separate out reading EXT_CSD mmc: break apart switch function MMC: Fix handling of low-voltage cards MMC: Consolidate voltage definitions mmc: add bus handler wbsd: check for data opcode earlier mmc: Separate out protocol ops mmc: Move core functions to subdir mmc: deprecate mmc bus topology mmc: remove card upon suspend mmc: allow suspended block driver to be removed mmc: Flush pending detects on host removal mmc: Move host and card drivers to subdirs mmc: Move queue functions to mmc_block ...
This commit is contained in:
@@ -11,10 +11,20 @@
|
||||
|
||||
#include <linux/tifm.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/freezer.h>
|
||||
|
||||
#define DRIVER_NAME "tifm_7xx1"
|
||||
#define DRIVER_VERSION "0.7"
|
||||
#define DRIVER_VERSION "0.8"
|
||||
|
||||
#define TIFM_IRQ_ENABLE 0x80000000
|
||||
#define TIFM_IRQ_SOCKMASK(x) (x)
|
||||
#define TIFM_IRQ_CARDMASK(x) ((x) << 8)
|
||||
#define TIFM_IRQ_FIFOMASK(x) ((x) << 16)
|
||||
#define TIFM_IRQ_SETALL 0xffffffff
|
||||
|
||||
static void tifm_7xx1_dummy_eject(struct tifm_adapter *fm,
|
||||
struct tifm_dev *sock)
|
||||
{
|
||||
}
|
||||
|
||||
static void tifm_7xx1_eject(struct tifm_adapter *fm, struct tifm_dev *sock)
|
||||
{
|
||||
@@ -22,7 +32,7 @@ static void tifm_7xx1_eject(struct tifm_adapter *fm, struct tifm_dev *sock)
|
||||
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
fm->socket_change_set |= 1 << sock->socket_id;
|
||||
wake_up_all(&fm->change_set_notify);
|
||||
tifm_queue_work(&fm->media_switcher);
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
}
|
||||
|
||||
@@ -30,8 +40,7 @@ static irqreturn_t tifm_7xx1_isr(int irq, void *dev_id)
|
||||
{
|
||||
struct tifm_adapter *fm = dev_id;
|
||||
struct tifm_dev *sock;
|
||||
unsigned int irq_status;
|
||||
unsigned int sock_irq_status, cnt;
|
||||
unsigned int irq_status, cnt;
|
||||
|
||||
spin_lock(&fm->lock);
|
||||
irq_status = readl(fm->addr + FM_INTERRUPT_STATUS);
|
||||
@@ -45,12 +54,12 @@ static irqreturn_t tifm_7xx1_isr(int irq, void *dev_id)
|
||||
|
||||
for (cnt = 0; cnt < fm->num_sockets; cnt++) {
|
||||
sock = fm->sockets[cnt];
|
||||
sock_irq_status = (irq_status >> cnt)
|
||||
& (TIFM_IRQ_FIFOMASK(1)
|
||||
| TIFM_IRQ_CARDMASK(1));
|
||||
|
||||
if (sock && sock_irq_status)
|
||||
sock->signal_irq(sock, sock_irq_status);
|
||||
if (sock) {
|
||||
if ((irq_status >> cnt) & TIFM_IRQ_FIFOMASK(1))
|
||||
sock->data_event(sock);
|
||||
if ((irq_status >> cnt) & TIFM_IRQ_CARDMASK(1))
|
||||
sock->card_event(sock);
|
||||
}
|
||||
}
|
||||
|
||||
fm->socket_change_set |= irq_status
|
||||
@@ -58,57 +67,57 @@ static irqreturn_t tifm_7xx1_isr(int irq, void *dev_id)
|
||||
}
|
||||
writel(irq_status, fm->addr + FM_INTERRUPT_STATUS);
|
||||
|
||||
if (!fm->socket_change_set)
|
||||
if (fm->finish_me)
|
||||
complete_all(fm->finish_me);
|
||||
else if (!fm->socket_change_set)
|
||||
writel(TIFM_IRQ_ENABLE, fm->addr + FM_SET_INTERRUPT_ENABLE);
|
||||
else
|
||||
wake_up_all(&fm->change_set_notify);
|
||||
tifm_queue_work(&fm->media_switcher);
|
||||
|
||||
spin_unlock(&fm->lock);
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static tifm_media_id tifm_7xx1_toggle_sock_power(char __iomem *sock_addr,
|
||||
int is_x2)
|
||||
static unsigned char tifm_7xx1_toggle_sock_power(char __iomem *sock_addr)
|
||||
{
|
||||
unsigned int s_state;
|
||||
int cnt;
|
||||
|
||||
writel(0x0e00, sock_addr + SOCK_CONTROL);
|
||||
|
||||
for (cnt = 0; cnt < 100; cnt++) {
|
||||
for (cnt = 16; cnt <= 256; cnt <<= 1) {
|
||||
if (!(TIFM_SOCK_STATE_POWERED
|
||||
& readl(sock_addr + SOCK_PRESENT_STATE)))
|
||||
break;
|
||||
msleep(10);
|
||||
|
||||
msleep(cnt);
|
||||
}
|
||||
|
||||
s_state = readl(sock_addr + SOCK_PRESENT_STATE);
|
||||
if (!(TIFM_SOCK_STATE_OCCUPIED & s_state))
|
||||
return FM_NULL;
|
||||
return 0;
|
||||
|
||||
if (is_x2) {
|
||||
writel((s_state & 7) | 0x0c00, sock_addr + SOCK_CONTROL);
|
||||
} else {
|
||||
// SmartMedia cards need extra 40 msec
|
||||
if (((readl(sock_addr + SOCK_PRESENT_STATE) >> 4) & 7) == 1)
|
||||
msleep(40);
|
||||
writel(readl(sock_addr + SOCK_CONTROL) | TIFM_CTRL_LED,
|
||||
sock_addr + SOCK_CONTROL);
|
||||
msleep(10);
|
||||
writel((s_state & 0x7) | 0x0c00 | TIFM_CTRL_LED,
|
||||
sock_addr + SOCK_CONTROL);
|
||||
}
|
||||
writel(readl(sock_addr + SOCK_CONTROL) | TIFM_CTRL_LED,
|
||||
sock_addr + SOCK_CONTROL);
|
||||
|
||||
for (cnt = 0; cnt < 100; cnt++) {
|
||||
/* xd needs some extra time before power on */
|
||||
if (((readl(sock_addr + SOCK_PRESENT_STATE) >> 4) & 7)
|
||||
== TIFM_TYPE_XD)
|
||||
msleep(40);
|
||||
|
||||
writel((s_state & 7) | 0x0c00, sock_addr + SOCK_CONTROL);
|
||||
/* wait for power to stabilize */
|
||||
msleep(20);
|
||||
for (cnt = 16; cnt <= 256; cnt <<= 1) {
|
||||
if ((TIFM_SOCK_STATE_POWERED
|
||||
& readl(sock_addr + SOCK_PRESENT_STATE)))
|
||||
break;
|
||||
msleep(10);
|
||||
|
||||
msleep(cnt);
|
||||
}
|
||||
|
||||
if (!is_x2)
|
||||
writel(readl(sock_addr + SOCK_CONTROL) & (~TIFM_CTRL_LED),
|
||||
sock_addr + SOCK_CONTROL);
|
||||
writel(readl(sock_addr + SOCK_CONTROL) & (~TIFM_CTRL_LED),
|
||||
sock_addr + SOCK_CONTROL);
|
||||
|
||||
return (readl(sock_addr + SOCK_PRESENT_STATE) >> 4) & 7;
|
||||
}
|
||||
@@ -119,127 +128,77 @@ tifm_7xx1_sock_addr(char __iomem *base_addr, unsigned int sock_num)
|
||||
return base_addr + ((sock_num + 1) << 10);
|
||||
}
|
||||
|
||||
static int tifm_7xx1_switch_media(void *data)
|
||||
static void tifm_7xx1_switch_media(struct work_struct *work)
|
||||
{
|
||||
struct tifm_adapter *fm = data;
|
||||
unsigned long flags;
|
||||
tifm_media_id media_id;
|
||||
char *card_name = "xx";
|
||||
int cnt, rc;
|
||||
struct tifm_adapter *fm = container_of(work, struct tifm_adapter,
|
||||
media_switcher);
|
||||
struct tifm_dev *sock;
|
||||
unsigned int socket_change_set;
|
||||
unsigned long flags;
|
||||
unsigned char media_id;
|
||||
unsigned int socket_change_set, cnt;
|
||||
|
||||
while (1) {
|
||||
rc = wait_event_interruptible(fm->change_set_notify,
|
||||
fm->socket_change_set);
|
||||
if (rc == -ERESTARTSYS)
|
||||
try_to_freeze();
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
socket_change_set = fm->socket_change_set;
|
||||
fm->socket_change_set = 0;
|
||||
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
socket_change_set = fm->socket_change_set;
|
||||
fm->socket_change_set = 0;
|
||||
dev_dbg(fm->cdev.dev, "checking media set %x\n",
|
||||
socket_change_set);
|
||||
|
||||
dev_dbg(fm->dev, "checking media set %x\n",
|
||||
socket_change_set);
|
||||
if (!socket_change_set) {
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
return;
|
||||
}
|
||||
|
||||
for (cnt = 0; cnt < fm->num_sockets; cnt++) {
|
||||
if (!(socket_change_set & (1 << cnt)))
|
||||
continue;
|
||||
sock = fm->sockets[cnt];
|
||||
if (sock) {
|
||||
printk(KERN_INFO
|
||||
"%s : demand removing card from socket %u:%u\n",
|
||||
fm->cdev.class_id, fm->id, cnt);
|
||||
fm->sockets[cnt] = NULL;
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
device_unregister(&sock->dev);
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
writel(0x0e00, tifm_7xx1_sock_addr(fm->addr, cnt)
|
||||
+ SOCK_CONTROL);
|
||||
}
|
||||
|
||||
if (kthread_should_stop())
|
||||
socket_change_set = (1 << fm->num_sockets) - 1;
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
|
||||
if (!socket_change_set)
|
||||
continue;
|
||||
media_id = tifm_7xx1_toggle_sock_power(
|
||||
tifm_7xx1_sock_addr(fm->addr, cnt));
|
||||
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
for (cnt = 0; cnt < fm->num_sockets; cnt++) {
|
||||
if (!(socket_change_set & (1 << cnt)))
|
||||
continue;
|
||||
sock = fm->sockets[cnt];
|
||||
if (sock) {
|
||||
printk(KERN_INFO DRIVER_NAME
|
||||
": demand removing card from socket %d\n",
|
||||
cnt);
|
||||
fm->sockets[cnt] = NULL;
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
device_unregister(&sock->dev);
|
||||
// tifm_alloc_device will check if media_id is valid
|
||||
sock = tifm_alloc_device(fm, cnt, media_id);
|
||||
if (sock) {
|
||||
sock->addr = tifm_7xx1_sock_addr(fm->addr, cnt);
|
||||
|
||||
if (!device_register(&sock->dev)) {
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
writel(0x0e00,
|
||||
tifm_7xx1_sock_addr(fm->addr, cnt)
|
||||
+ SOCK_CONTROL);
|
||||
}
|
||||
if (kthread_should_stop())
|
||||
continue;
|
||||
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
media_id = tifm_7xx1_toggle_sock_power(
|
||||
tifm_7xx1_sock_addr(fm->addr, cnt),
|
||||
fm->num_sockets == 2);
|
||||
if (media_id) {
|
||||
sock = tifm_alloc_device(fm);
|
||||
if (sock) {
|
||||
sock->addr = tifm_7xx1_sock_addr(fm->addr,
|
||||
cnt);
|
||||
sock->media_id = media_id;
|
||||
sock->socket_id = cnt;
|
||||
switch (media_id) {
|
||||
case 1:
|
||||
card_name = "xd";
|
||||
break;
|
||||
case 2:
|
||||
card_name = "ms";
|
||||
break;
|
||||
case 3:
|
||||
card_name = "sd";
|
||||
break;
|
||||
default:
|
||||
tifm_free_device(&sock->dev);
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
continue;
|
||||
}
|
||||
snprintf(sock->dev.bus_id, BUS_ID_SIZE,
|
||||
"tifm_%s%u:%u", card_name,
|
||||
fm->id, cnt);
|
||||
printk(KERN_INFO DRIVER_NAME
|
||||
": %s card detected in socket %d\n",
|
||||
card_name, cnt);
|
||||
if (!device_register(&sock->dev)) {
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
if (!fm->sockets[cnt]) {
|
||||
fm->sockets[cnt] = sock;
|
||||
sock = NULL;
|
||||
}
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
}
|
||||
if (sock)
|
||||
tifm_free_device(&sock->dev);
|
||||
if (!fm->sockets[cnt]) {
|
||||
fm->sockets[cnt] = sock;
|
||||
sock = NULL;
|
||||
}
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
}
|
||||
}
|
||||
|
||||
if (!kthread_should_stop()) {
|
||||
writel(TIFM_IRQ_FIFOMASK(socket_change_set)
|
||||
| TIFM_IRQ_CARDMASK(socket_change_set),
|
||||
fm->addr + FM_CLEAR_INTERRUPT_ENABLE);
|
||||
writel(TIFM_IRQ_FIFOMASK(socket_change_set)
|
||||
| TIFM_IRQ_CARDMASK(socket_change_set),
|
||||
fm->addr + FM_SET_INTERRUPT_ENABLE);
|
||||
writel(TIFM_IRQ_ENABLE,
|
||||
fm->addr + FM_SET_INTERRUPT_ENABLE);
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
} else {
|
||||
for (cnt = 0; cnt < fm->num_sockets; cnt++) {
|
||||
if (fm->sockets[cnt])
|
||||
fm->socket_change_set |= 1 << cnt;
|
||||
}
|
||||
if (!fm->socket_change_set) {
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
return 0;
|
||||
} else {
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
}
|
||||
if (sock)
|
||||
tifm_free_device(&sock->dev);
|
||||
}
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
}
|
||||
return 0;
|
||||
|
||||
writel(TIFM_IRQ_FIFOMASK(socket_change_set)
|
||||
| TIFM_IRQ_CARDMASK(socket_change_set),
|
||||
fm->addr + FM_CLEAR_INTERRUPT_ENABLE);
|
||||
|
||||
writel(TIFM_IRQ_FIFOMASK(socket_change_set)
|
||||
| TIFM_IRQ_CARDMASK(socket_change_set),
|
||||
fm->addr + FM_SET_INTERRUPT_ENABLE);
|
||||
|
||||
writel(TIFM_IRQ_ENABLE, fm->addr + FM_SET_INTERRUPT_ENABLE);
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
@@ -258,9 +217,11 @@ static int tifm_7xx1_suspend(struct pci_dev *dev, pm_message_t state)
|
||||
static int tifm_7xx1_resume(struct pci_dev *dev)
|
||||
{
|
||||
struct tifm_adapter *fm = pci_get_drvdata(dev);
|
||||
int cnt, rc;
|
||||
int rc;
|
||||
unsigned int good_sockets = 0, bad_sockets = 0;
|
||||
unsigned long flags;
|
||||
tifm_media_id new_ids[fm->num_sockets];
|
||||
unsigned char new_ids[fm->num_sockets];
|
||||
DECLARE_COMPLETION_ONSTACK(finish_resume);
|
||||
|
||||
pci_set_power_state(dev, PCI_D0);
|
||||
pci_restore_state(dev);
|
||||
@@ -271,45 +232,49 @@ static int tifm_7xx1_resume(struct pci_dev *dev)
|
||||
|
||||
dev_dbg(&dev->dev, "resuming host\n");
|
||||
|
||||
for (cnt = 0; cnt < fm->num_sockets; cnt++)
|
||||
new_ids[cnt] = tifm_7xx1_toggle_sock_power(
|
||||
tifm_7xx1_sock_addr(fm->addr, cnt),
|
||||
fm->num_sockets == 2);
|
||||
for (rc = 0; rc < fm->num_sockets; rc++)
|
||||
new_ids[rc] = tifm_7xx1_toggle_sock_power(
|
||||
tifm_7xx1_sock_addr(fm->addr, rc));
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
fm->socket_change_set = 0;
|
||||
for (cnt = 0; cnt < fm->num_sockets; cnt++) {
|
||||
if (fm->sockets[cnt]) {
|
||||
if (fm->sockets[cnt]->media_id == new_ids[cnt])
|
||||
fm->socket_change_set |= 1 << cnt;
|
||||
|
||||
fm->sockets[cnt]->media_id = new_ids[cnt];
|
||||
for (rc = 0; rc < fm->num_sockets; rc++) {
|
||||
if (fm->sockets[rc]) {
|
||||
if (fm->sockets[rc]->type == new_ids[rc])
|
||||
good_sockets |= 1 << rc;
|
||||
else
|
||||
bad_sockets |= 1 << rc;
|
||||
}
|
||||
}
|
||||
|
||||
writel(TIFM_IRQ_ENABLE | TIFM_IRQ_SOCKMASK((1 << fm->num_sockets) - 1),
|
||||
fm->addr + FM_SET_INTERRUPT_ENABLE);
|
||||
if (!fm->socket_change_set) {
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
return 0;
|
||||
} else {
|
||||
fm->socket_change_set = 0;
|
||||
dev_dbg(&dev->dev, "change sets on resume: good %x, bad %x\n",
|
||||
good_sockets, bad_sockets);
|
||||
|
||||
fm->socket_change_set = 0;
|
||||
if (good_sockets) {
|
||||
fm->finish_me = &finish_resume;
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
rc = wait_for_completion_timeout(&finish_resume, HZ);
|
||||
dev_dbg(&dev->dev, "wait returned %d\n", rc);
|
||||
writel(TIFM_IRQ_FIFOMASK(good_sockets)
|
||||
| TIFM_IRQ_CARDMASK(good_sockets),
|
||||
fm->addr + FM_CLEAR_INTERRUPT_ENABLE);
|
||||
writel(TIFM_IRQ_FIFOMASK(good_sockets)
|
||||
| TIFM_IRQ_CARDMASK(good_sockets),
|
||||
fm->addr + FM_SET_INTERRUPT_ENABLE);
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
fm->finish_me = NULL;
|
||||
fm->socket_change_set ^= good_sockets & fm->socket_change_set;
|
||||
}
|
||||
|
||||
wait_event_timeout(fm->change_set_notify, fm->socket_change_set, HZ);
|
||||
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
writel(TIFM_IRQ_FIFOMASK(fm->socket_change_set)
|
||||
| TIFM_IRQ_CARDMASK(fm->socket_change_set),
|
||||
fm->addr + FM_CLEAR_INTERRUPT_ENABLE);
|
||||
writel(TIFM_IRQ_FIFOMASK(fm->socket_change_set)
|
||||
| TIFM_IRQ_CARDMASK(fm->socket_change_set),
|
||||
fm->addr + FM_SET_INTERRUPT_ENABLE);
|
||||
writel(TIFM_IRQ_ENABLE,
|
||||
fm->addr + FM_SET_INTERRUPT_ENABLE);
|
||||
fm->socket_change_set = 0;
|
||||
fm->socket_change_set |= bad_sockets;
|
||||
if (fm->socket_change_set)
|
||||
tifm_queue_work(&fm->media_switcher);
|
||||
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
writel(TIFM_IRQ_ENABLE,
|
||||
fm->addr + FM_SET_INTERRUPT_ENABLE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -345,20 +310,14 @@ static int tifm_7xx1_probe(struct pci_dev *dev,
|
||||
|
||||
pci_intx(dev, 1);
|
||||
|
||||
fm = tifm_alloc_adapter();
|
||||
fm = tifm_alloc_adapter(dev->device == PCI_DEVICE_ID_TI_XX21_XX11_FM
|
||||
? 4 : 2, &dev->dev);
|
||||
if (!fm) {
|
||||
rc = -ENOMEM;
|
||||
goto err_out_int;
|
||||
}
|
||||
|
||||
fm->dev = &dev->dev;
|
||||
fm->num_sockets = (dev->device == PCI_DEVICE_ID_TI_XX21_XX11_FM)
|
||||
? 4 : 2;
|
||||
fm->sockets = kzalloc(sizeof(struct tifm_dev*) * fm->num_sockets,
|
||||
GFP_KERNEL);
|
||||
if (!fm->sockets)
|
||||
goto err_out_free;
|
||||
|
||||
INIT_WORK(&fm->media_switcher, tifm_7xx1_switch_media);
|
||||
fm->eject = tifm_7xx1_eject;
|
||||
pci_set_drvdata(dev, fm);
|
||||
|
||||
@@ -367,19 +326,16 @@ static int tifm_7xx1_probe(struct pci_dev *dev,
|
||||
if (!fm->addr)
|
||||
goto err_out_free;
|
||||
|
||||
rc = request_irq(dev->irq, tifm_7xx1_isr, IRQF_SHARED, DRIVER_NAME, fm);
|
||||
rc = request_irq(dev->irq, tifm_7xx1_isr, SA_SHIRQ, DRIVER_NAME, fm);
|
||||
if (rc)
|
||||
goto err_out_unmap;
|
||||
|
||||
init_waitqueue_head(&fm->change_set_notify);
|
||||
rc = tifm_add_adapter(fm, tifm_7xx1_switch_media);
|
||||
rc = tifm_add_adapter(fm);
|
||||
if (rc)
|
||||
goto err_out_irq;
|
||||
|
||||
writel(TIFM_IRQ_SETALL, fm->addr + FM_CLEAR_INTERRUPT_ENABLE);
|
||||
writel(TIFM_IRQ_ENABLE | TIFM_IRQ_SOCKMASK((1 << fm->num_sockets) - 1),
|
||||
fm->addr + FM_SET_INTERRUPT_ENABLE);
|
||||
wake_up_process(fm->media_switcher);
|
||||
return 0;
|
||||
|
||||
err_out_irq:
|
||||
@@ -401,18 +357,12 @@ err_out:
|
||||
static void tifm_7xx1_remove(struct pci_dev *dev)
|
||||
{
|
||||
struct tifm_adapter *fm = pci_get_drvdata(dev);
|
||||
unsigned long flags;
|
||||
|
||||
fm->eject = tifm_7xx1_dummy_eject;
|
||||
writel(TIFM_IRQ_SETALL, fm->addr + FM_CLEAR_INTERRUPT_ENABLE);
|
||||
mmiowb();
|
||||
free_irq(dev->irq, fm);
|
||||
|
||||
spin_lock_irqsave(&fm->lock, flags);
|
||||
fm->socket_change_set = (1 << fm->num_sockets) - 1;
|
||||
spin_unlock_irqrestore(&fm->lock, flags);
|
||||
|
||||
kthread_stop(fm->media_switcher);
|
||||
|
||||
tifm_remove_adapter(fm);
|
||||
|
||||
pci_set_drvdata(dev, NULL);
|
||||
|
||||
@@ -14,71 +14,124 @@
|
||||
#include <linux/idr.h>
|
||||
|
||||
#define DRIVER_NAME "tifm_core"
|
||||
#define DRIVER_VERSION "0.7"
|
||||
#define DRIVER_VERSION "0.8"
|
||||
|
||||
static struct workqueue_struct *workqueue;
|
||||
static DEFINE_IDR(tifm_adapter_idr);
|
||||
static DEFINE_SPINLOCK(tifm_adapter_lock);
|
||||
|
||||
static tifm_media_id *tifm_device_match(tifm_media_id *ids,
|
||||
struct tifm_dev *dev)
|
||||
static const char *tifm_media_type_name(unsigned char type, unsigned char nt)
|
||||
{
|
||||
while (*ids) {
|
||||
if (dev->media_id == *ids)
|
||||
return ids;
|
||||
ids++;
|
||||
}
|
||||
return NULL;
|
||||
const char *card_type_name[3][3] = {
|
||||
{ "SmartMedia/xD", "MemoryStick", "MMC/SD" },
|
||||
{ "XD", "MS", "SD"},
|
||||
{ "xd", "ms", "sd"}
|
||||
};
|
||||
|
||||
if (nt > 2 || type < 1 || type > 3)
|
||||
return NULL;
|
||||
return card_type_name[nt][type - 1];
|
||||
}
|
||||
|
||||
static int tifm_match(struct device *dev, struct device_driver *drv)
|
||||
static int tifm_dev_match(struct tifm_dev *sock, struct tifm_device_id *id)
|
||||
{
|
||||
struct tifm_dev *fm_dev = container_of(dev, struct tifm_dev, dev);
|
||||
struct tifm_driver *fm_drv;
|
||||
|
||||
fm_drv = container_of(drv, struct tifm_driver, driver);
|
||||
if (!fm_drv->id_table)
|
||||
return -EINVAL;
|
||||
if (tifm_device_match(fm_drv->id_table, fm_dev))
|
||||
if (sock->type == id->type)
|
||||
return 1;
|
||||
return -ENODEV;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tifm_bus_match(struct device *dev, struct device_driver *drv)
|
||||
{
|
||||
struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
|
||||
struct tifm_driver *fm_drv = container_of(drv, struct tifm_driver,
|
||||
driver);
|
||||
struct tifm_device_id *ids = fm_drv->id_table;
|
||||
|
||||
if (ids) {
|
||||
while (ids->type) {
|
||||
if (tifm_dev_match(sock, ids))
|
||||
return 1;
|
||||
++ids;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tifm_uevent(struct device *dev, char **envp, int num_envp,
|
||||
char *buffer, int buffer_size)
|
||||
{
|
||||
struct tifm_dev *fm_dev;
|
||||
struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
|
||||
int i = 0;
|
||||
int length = 0;
|
||||
const char *card_type_name[] = {"INV", "SM", "MS", "SD"};
|
||||
|
||||
if (!dev || !(fm_dev = container_of(dev, struct tifm_dev, dev)))
|
||||
return -ENODEV;
|
||||
if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
|
||||
"TIFM_CARD_TYPE=%s", card_type_name[fm_dev->media_id]))
|
||||
"TIFM_CARD_TYPE=%s",
|
||||
tifm_media_type_name(sock->type, 1)))
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tifm_device_probe(struct device *dev)
|
||||
{
|
||||
struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
|
||||
struct tifm_driver *drv = container_of(dev->driver, struct tifm_driver,
|
||||
driver);
|
||||
int rc = -ENODEV;
|
||||
|
||||
get_device(dev);
|
||||
if (dev->driver && drv->probe) {
|
||||
rc = drv->probe(sock);
|
||||
if (!rc)
|
||||
return 0;
|
||||
}
|
||||
put_device(dev);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void tifm_dummy_event(struct tifm_dev *sock)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static int tifm_device_remove(struct device *dev)
|
||||
{
|
||||
struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
|
||||
struct tifm_driver *drv = container_of(dev->driver, struct tifm_driver,
|
||||
driver);
|
||||
|
||||
if (dev->driver && drv->remove) {
|
||||
sock->card_event = tifm_dummy_event;
|
||||
sock->data_event = tifm_dummy_event;
|
||||
drv->remove(sock);
|
||||
sock->dev.driver = NULL;
|
||||
}
|
||||
|
||||
put_device(dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
|
||||
static int tifm_device_suspend(struct device *dev, pm_message_t state)
|
||||
{
|
||||
struct tifm_dev *fm_dev = container_of(dev, struct tifm_dev, dev);
|
||||
struct tifm_driver *drv = fm_dev->drv;
|
||||
struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
|
||||
struct tifm_driver *drv = container_of(dev->driver, struct tifm_driver,
|
||||
driver);
|
||||
|
||||
if (drv && drv->suspend)
|
||||
return drv->suspend(fm_dev, state);
|
||||
if (dev->driver && drv->suspend)
|
||||
return drv->suspend(sock, state);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tifm_device_resume(struct device *dev)
|
||||
{
|
||||
struct tifm_dev *fm_dev = container_of(dev, struct tifm_dev, dev);
|
||||
struct tifm_driver *drv = fm_dev->drv;
|
||||
struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
|
||||
struct tifm_driver *drv = container_of(dev->driver, struct tifm_driver,
|
||||
driver);
|
||||
|
||||
if (drv && drv->resume)
|
||||
return drv->resume(fm_dev);
|
||||
if (dev->driver && drv->resume)
|
||||
return drv->resume(sock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -89,19 +142,33 @@ static int tifm_device_resume(struct device *dev)
|
||||
|
||||
#endif /* CONFIG_PM */
|
||||
|
||||
static ssize_t type_show(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
|
||||
return sprintf(buf, "%x", sock->type);
|
||||
}
|
||||
|
||||
static struct device_attribute tifm_dev_attrs[] = {
|
||||
__ATTR(type, S_IRUGO, type_show, NULL),
|
||||
__ATTR_NULL
|
||||
};
|
||||
|
||||
static struct bus_type tifm_bus_type = {
|
||||
.name = "tifm",
|
||||
.match = tifm_match,
|
||||
.uevent = tifm_uevent,
|
||||
.suspend = tifm_device_suspend,
|
||||
.resume = tifm_device_resume
|
||||
.name = "tifm",
|
||||
.dev_attrs = tifm_dev_attrs,
|
||||
.match = tifm_bus_match,
|
||||
.uevent = tifm_uevent,
|
||||
.probe = tifm_device_probe,
|
||||
.remove = tifm_device_remove,
|
||||
.suspend = tifm_device_suspend,
|
||||
.resume = tifm_device_resume
|
||||
};
|
||||
|
||||
static void tifm_free(struct class_device *cdev)
|
||||
{
|
||||
struct tifm_adapter *fm = container_of(cdev, struct tifm_adapter, cdev);
|
||||
|
||||
kfree(fm->sockets);
|
||||
kfree(fm);
|
||||
}
|
||||
|
||||
@@ -110,28 +177,25 @@ static struct class tifm_adapter_class = {
|
||||
.release = tifm_free
|
||||
};
|
||||
|
||||
struct tifm_adapter *tifm_alloc_adapter(void)
|
||||
struct tifm_adapter *tifm_alloc_adapter(unsigned int num_sockets,
|
||||
struct device *dev)
|
||||
{
|
||||
struct tifm_adapter *fm;
|
||||
|
||||
fm = kzalloc(sizeof(struct tifm_adapter), GFP_KERNEL);
|
||||
fm = kzalloc(sizeof(struct tifm_adapter)
|
||||
+ sizeof(struct tifm_dev*) * num_sockets, GFP_KERNEL);
|
||||
if (fm) {
|
||||
fm->cdev.class = &tifm_adapter_class;
|
||||
spin_lock_init(&fm->lock);
|
||||
fm->cdev.dev = dev;
|
||||
class_device_initialize(&fm->cdev);
|
||||
spin_lock_init(&fm->lock);
|
||||
fm->num_sockets = num_sockets;
|
||||
}
|
||||
return fm;
|
||||
}
|
||||
EXPORT_SYMBOL(tifm_alloc_adapter);
|
||||
|
||||
void tifm_free_adapter(struct tifm_adapter *fm)
|
||||
{
|
||||
class_device_put(&fm->cdev);
|
||||
}
|
||||
EXPORT_SYMBOL(tifm_free_adapter);
|
||||
|
||||
int tifm_add_adapter(struct tifm_adapter *fm,
|
||||
int (*mediathreadfn)(void *data))
|
||||
int tifm_add_adapter(struct tifm_adapter *fm)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -141,59 +205,80 @@ int tifm_add_adapter(struct tifm_adapter *fm,
|
||||
spin_lock(&tifm_adapter_lock);
|
||||
rc = idr_get_new(&tifm_adapter_idr, fm, &fm->id);
|
||||
spin_unlock(&tifm_adapter_lock);
|
||||
if (!rc) {
|
||||
snprintf(fm->cdev.class_id, BUS_ID_SIZE, "tifm%u", fm->id);
|
||||
fm->media_switcher = kthread_create(mediathreadfn,
|
||||
fm, "tifm/%u", fm->id);
|
||||
|
||||
if (!IS_ERR(fm->media_switcher))
|
||||
return class_device_add(&fm->cdev);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
snprintf(fm->cdev.class_id, BUS_ID_SIZE, "tifm%u", fm->id);
|
||||
rc = class_device_add(&fm->cdev);
|
||||
if (rc) {
|
||||
spin_lock(&tifm_adapter_lock);
|
||||
idr_remove(&tifm_adapter_idr, fm->id);
|
||||
spin_unlock(&tifm_adapter_lock);
|
||||
rc = -ENOMEM;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
EXPORT_SYMBOL(tifm_add_adapter);
|
||||
|
||||
void tifm_remove_adapter(struct tifm_adapter *fm)
|
||||
{
|
||||
class_device_del(&fm->cdev);
|
||||
unsigned int cnt;
|
||||
|
||||
flush_workqueue(workqueue);
|
||||
for (cnt = 0; cnt < fm->num_sockets; ++cnt) {
|
||||
if (fm->sockets[cnt])
|
||||
device_unregister(&fm->sockets[cnt]->dev);
|
||||
}
|
||||
|
||||
spin_lock(&tifm_adapter_lock);
|
||||
idr_remove(&tifm_adapter_idr, fm->id);
|
||||
spin_unlock(&tifm_adapter_lock);
|
||||
class_device_del(&fm->cdev);
|
||||
}
|
||||
EXPORT_SYMBOL(tifm_remove_adapter);
|
||||
|
||||
void tifm_free_adapter(struct tifm_adapter *fm)
|
||||
{
|
||||
class_device_put(&fm->cdev);
|
||||
}
|
||||
EXPORT_SYMBOL(tifm_free_adapter);
|
||||
|
||||
void tifm_free_device(struct device *dev)
|
||||
{
|
||||
struct tifm_dev *fm_dev = container_of(dev, struct tifm_dev, dev);
|
||||
kfree(fm_dev);
|
||||
struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
|
||||
kfree(sock);
|
||||
}
|
||||
EXPORT_SYMBOL(tifm_free_device);
|
||||
|
||||
static void tifm_dummy_signal_irq(struct tifm_dev *sock,
|
||||
unsigned int sock_irq_status)
|
||||
struct tifm_dev *tifm_alloc_device(struct tifm_adapter *fm, unsigned int id,
|
||||
unsigned char type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
struct tifm_dev *sock = NULL;
|
||||
|
||||
struct tifm_dev *tifm_alloc_device(struct tifm_adapter *fm)
|
||||
{
|
||||
struct tifm_dev *dev = kzalloc(sizeof(struct tifm_dev), GFP_KERNEL);
|
||||
if (!tifm_media_type_name(type, 0))
|
||||
return sock;
|
||||
|
||||
if (dev) {
|
||||
spin_lock_init(&dev->lock);
|
||||
sock = kzalloc(sizeof(struct tifm_dev), GFP_KERNEL);
|
||||
if (sock) {
|
||||
spin_lock_init(&sock->lock);
|
||||
sock->type = type;
|
||||
sock->socket_id = id;
|
||||
sock->card_event = tifm_dummy_event;
|
||||
sock->data_event = tifm_dummy_event;
|
||||
|
||||
dev->dev.parent = fm->dev;
|
||||
dev->dev.bus = &tifm_bus_type;
|
||||
dev->dev.release = tifm_free_device;
|
||||
dev->signal_irq = tifm_dummy_signal_irq;
|
||||
sock->dev.parent = fm->cdev.dev;
|
||||
sock->dev.bus = &tifm_bus_type;
|
||||
sock->dev.dma_mask = fm->cdev.dev->dma_mask;
|
||||
sock->dev.release = tifm_free_device;
|
||||
|
||||
snprintf(sock->dev.bus_id, BUS_ID_SIZE,
|
||||
"tifm_%s%u:%u", tifm_media_type_name(type, 2),
|
||||
fm->id, id);
|
||||
printk(KERN_INFO DRIVER_NAME
|
||||
": %s card detected in socket %u:%u\n",
|
||||
tifm_media_type_name(type, 0), fm->id, id);
|
||||
}
|
||||
return dev;
|
||||
return sock;
|
||||
}
|
||||
EXPORT_SYMBOL(tifm_alloc_device);
|
||||
|
||||
@@ -218,54 +303,15 @@ void tifm_unmap_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents,
|
||||
}
|
||||
EXPORT_SYMBOL(tifm_unmap_sg);
|
||||
|
||||
static int tifm_device_probe(struct device *dev)
|
||||
void tifm_queue_work(struct work_struct *work)
|
||||
{
|
||||
struct tifm_driver *drv;
|
||||
struct tifm_dev *fm_dev;
|
||||
int rc = 0;
|
||||
const tifm_media_id *id;
|
||||
|
||||
drv = container_of(dev->driver, struct tifm_driver, driver);
|
||||
fm_dev = container_of(dev, struct tifm_dev, dev);
|
||||
get_device(dev);
|
||||
if (!fm_dev->drv && drv->probe && drv->id_table) {
|
||||
rc = -ENODEV;
|
||||
id = tifm_device_match(drv->id_table, fm_dev);
|
||||
if (id)
|
||||
rc = drv->probe(fm_dev);
|
||||
if (rc >= 0) {
|
||||
rc = 0;
|
||||
fm_dev->drv = drv;
|
||||
}
|
||||
}
|
||||
if (rc)
|
||||
put_device(dev);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int tifm_device_remove(struct device *dev)
|
||||
{
|
||||
struct tifm_dev *fm_dev = container_of(dev, struct tifm_dev, dev);
|
||||
struct tifm_driver *drv = fm_dev->drv;
|
||||
|
||||
if (drv) {
|
||||
fm_dev->signal_irq = tifm_dummy_signal_irq;
|
||||
if (drv->remove)
|
||||
drv->remove(fm_dev);
|
||||
fm_dev->drv = NULL;
|
||||
}
|
||||
|
||||
put_device(dev);
|
||||
return 0;
|
||||
queue_work(workqueue, work);
|
||||
}
|
||||
EXPORT_SYMBOL(tifm_queue_work);
|
||||
|
||||
int tifm_register_driver(struct tifm_driver *drv)
|
||||
{
|
||||
drv->driver.bus = &tifm_bus_type;
|
||||
drv->driver.probe = tifm_device_probe;
|
||||
drv->driver.remove = tifm_device_remove;
|
||||
drv->driver.suspend = tifm_device_suspend;
|
||||
drv->driver.resume = tifm_device_resume;
|
||||
|
||||
return driver_register(&drv->driver);
|
||||
}
|
||||
@@ -279,13 +325,25 @@ EXPORT_SYMBOL(tifm_unregister_driver);
|
||||
|
||||
static int __init tifm_init(void)
|
||||
{
|
||||
int rc = bus_register(&tifm_bus_type);
|
||||
int rc;
|
||||
|
||||
if (!rc) {
|
||||
rc = class_register(&tifm_adapter_class);
|
||||
if (rc)
|
||||
bus_unregister(&tifm_bus_type);
|
||||
}
|
||||
workqueue = create_freezeable_workqueue("tifm");
|
||||
if (!workqueue)
|
||||
return -ENOMEM;
|
||||
|
||||
rc = bus_register(&tifm_bus_type);
|
||||
|
||||
if (rc)
|
||||
goto err_out_wq;
|
||||
|
||||
rc = class_register(&tifm_adapter_class);
|
||||
if (!rc)
|
||||
return 0;
|
||||
|
||||
bus_unregister(&tifm_bus_type);
|
||||
|
||||
err_out_wq:
|
||||
destroy_workqueue(workqueue);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -294,6 +352,7 @@ static void __exit tifm_exit(void)
|
||||
{
|
||||
class_unregister(&tifm_adapter_class);
|
||||
bus_unregister(&tifm_bus_type);
|
||||
destroy_workqueue(workqueue);
|
||||
}
|
||||
|
||||
subsys_initcall(tifm_init);
|
||||
|
||||
@@ -19,110 +19,10 @@ config MMC_DEBUG
|
||||
This is an option for use by developers; most people should
|
||||
say N here. This enables MMC core and driver debugging.
|
||||
|
||||
config MMC_BLOCK
|
||||
tristate "MMC block device driver"
|
||||
depends on MMC && BLOCK
|
||||
default y
|
||||
help
|
||||
Say Y here to enable the MMC block device driver support.
|
||||
This provides a block device driver, which you can use to
|
||||
mount the filesystem. Almost everyone wishing MMC support
|
||||
should say Y or M here.
|
||||
source "drivers/mmc/core/Kconfig"
|
||||
|
||||
config MMC_ARMMMCI
|
||||
tristate "ARM AMBA Multimedia Card Interface support"
|
||||
depends on ARM_AMBA && MMC
|
||||
help
|
||||
This selects the ARM(R) AMBA(R) PrimeCell Multimedia Card
|
||||
Interface (PL180 and PL181) support. If you have an ARM(R)
|
||||
platform with a Multimedia Card slot, say Y or M here.
|
||||
source "drivers/mmc/card/Kconfig"
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config MMC_PXA
|
||||
tristate "Intel PXA25x/26x/27x Multimedia Card Interface support"
|
||||
depends on ARCH_PXA && MMC
|
||||
help
|
||||
This selects the Intel(R) PXA(R) Multimedia card Interface.
|
||||
If you have a PXA(R) platform with a Multimedia Card slot,
|
||||
say Y or M here.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config MMC_SDHCI
|
||||
tristate "Secure Digital Host Controller Interface support (EXPERIMENTAL)"
|
||||
depends on PCI && MMC && EXPERIMENTAL
|
||||
help
|
||||
This select the generic Secure Digital Host Controller Interface.
|
||||
It is used by manufacturers such as Texas Instruments(R), Ricoh(R)
|
||||
and Toshiba(R). Most controllers found in laptops are of this type.
|
||||
If you have a controller with this interface, say Y or M here.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config MMC_OMAP
|
||||
tristate "TI OMAP Multimedia Card Interface support"
|
||||
depends on ARCH_OMAP && MMC
|
||||
select TPS65010 if MACH_OMAP_H2
|
||||
help
|
||||
This selects the TI OMAP Multimedia card Interface.
|
||||
If you have an OMAP board with a Multimedia Card slot,
|
||||
say Y or M here.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config MMC_WBSD
|
||||
tristate "Winbond W83L51xD SD/MMC Card Interface support"
|
||||
depends on MMC && ISA_DMA_API
|
||||
help
|
||||
This selects the Winbond(R) W83L51xD Secure digital and
|
||||
Multimedia card Interface.
|
||||
If you have a machine with a integrated W83L518D or W83L519D
|
||||
SD/MMC card reader, say Y or M here.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config MMC_AU1X
|
||||
tristate "Alchemy AU1XX0 MMC Card Interface support"
|
||||
depends on MMC && SOC_AU1200
|
||||
help
|
||||
This selects the AMD Alchemy(R) Multimedia card interface.
|
||||
If you have a Alchemy platform with a MMC slot, say Y or M here.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config MMC_AT91
|
||||
tristate "AT91 SD/MMC Card Interface support"
|
||||
depends on ARCH_AT91 && MMC
|
||||
help
|
||||
This selects the AT91 MCI controller.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config MMC_IMX
|
||||
tristate "Motorola i.MX Multimedia Card Interface support"
|
||||
depends on ARCH_IMX && MMC
|
||||
help
|
||||
This selects the Motorola i.MX Multimedia card Interface.
|
||||
If you have a i.MX platform with a Multimedia Card slot,
|
||||
say Y or M here.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config MMC_TIFM_SD
|
||||
tristate "TI Flash Media MMC/SD Interface support (EXPERIMENTAL)"
|
||||
depends on MMC && EXPERIMENTAL && PCI
|
||||
select TIFM_CORE
|
||||
help
|
||||
Say Y here if you want to be able to access MMC/SD cards with
|
||||
the Texas Instruments(R) Flash Media card reader, found in many
|
||||
laptops.
|
||||
This option 'selects' (turns on, enables) 'TIFM_CORE', but you
|
||||
probably also need appropriate card reader host adapter, such as
|
||||
'Misc devices: TI Flash Media PCI74xx/PCI76xx host adapter support
|
||||
(TIFM_7XX1)'.
|
||||
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called tifm_sd.
|
||||
source "drivers/mmc/host/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -2,32 +2,11 @@
|
||||
# Makefile for the kernel mmc device drivers.
|
||||
#
|
||||
|
||||
#
|
||||
# Core
|
||||
#
|
||||
obj-$(CONFIG_MMC) += mmc_core.o
|
||||
|
||||
#
|
||||
# Media drivers
|
||||
#
|
||||
obj-$(CONFIG_MMC_BLOCK) += mmc_block.o
|
||||
|
||||
#
|
||||
# Host drivers
|
||||
#
|
||||
obj-$(CONFIG_MMC_ARMMMCI) += mmci.o
|
||||
obj-$(CONFIG_MMC_PXA) += pxamci.o
|
||||
obj-$(CONFIG_MMC_IMX) += imxmmc.o
|
||||
obj-$(CONFIG_MMC_SDHCI) += sdhci.o
|
||||
obj-$(CONFIG_MMC_WBSD) += wbsd.o
|
||||
obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
|
||||
obj-$(CONFIG_MMC_OMAP) += omap.o
|
||||
obj-$(CONFIG_MMC_AT91) += at91_mci.o
|
||||
obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
|
||||
|
||||
mmc_core-y := mmc.o mmc_sysfs.o
|
||||
mmc_core-$(CONFIG_BLOCK) += mmc_queue.o
|
||||
|
||||
ifeq ($(CONFIG_MMC_DEBUG),y)
|
||||
EXTRA_CFLAGS += -DDEBUG
|
||||
EXTRA_CFLAGS += -DDEBUG
|
||||
endif
|
||||
|
||||
obj-$(CONFIG_MMC) += core/
|
||||
obj-$(CONFIG_MMC) += card/
|
||||
obj-$(CONFIG_MMC) += host/
|
||||
|
||||
|
||||
17
drivers/mmc/card/Kconfig
Normal file
17
drivers/mmc/card/Kconfig
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# MMC/SD card drivers
|
||||
#
|
||||
|
||||
comment "MMC/SD Card Drivers"
|
||||
depends MMC
|
||||
|
||||
config MMC_BLOCK
|
||||
tristate "MMC block device driver"
|
||||
depends on MMC && BLOCK
|
||||
default y
|
||||
help
|
||||
Say Y here to enable the MMC block device driver support.
|
||||
This provides a block device driver, which you can use to
|
||||
mount the filesystem. Almost everyone wishing MMC support
|
||||
should say Y or M here.
|
||||
|
||||
11
drivers/mmc/card/Makefile
Normal file
11
drivers/mmc/card/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
#
|
||||
# Makefile for MMC/SD card drivers
|
||||
#
|
||||
|
||||
ifeq ($(CONFIG_MMC_DEBUG),y)
|
||||
EXTRA_CFLAGS += -DDEBUG
|
||||
endif
|
||||
|
||||
obj-$(CONFIG_MMC_BLOCK) += mmc_block.o
|
||||
mmc_block-objs := block.o queue.o
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Block driver for media (i.e., flash cards)
|
||||
*
|
||||
* Copyright 2002 Hewlett-Packard Company
|
||||
* Copyright 2005-2007 Pierre Ossman
|
||||
*
|
||||
* Use consistent with the GNU GPL is permitted,
|
||||
* provided that this copyright notice is
|
||||
@@ -31,13 +32,13 @@
|
||||
|
||||
#include <linux/mmc/card.h>
|
||||
#include <linux/mmc/host.h>
|
||||
#include <linux/mmc/protocol.h>
|
||||
#include <linux/mmc/host.h>
|
||||
#include <linux/mmc/mmc.h>
|
||||
#include <linux/mmc/sd.h>
|
||||
|
||||
#include <asm/system.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#include "mmc_queue.h"
|
||||
#include "queue.h"
|
||||
|
||||
/*
|
||||
* max 8 partitions per card
|
||||
@@ -223,10 +224,9 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
|
||||
struct mmc_blk_data *md = mq->data;
|
||||
struct mmc_card *card = md->queue.card;
|
||||
struct mmc_blk_request brq;
|
||||
int ret = 1;
|
||||
int ret = 1, sg_pos, data_size;
|
||||
|
||||
if (mmc_card_claim_host(card))
|
||||
goto flush_queue;
|
||||
mmc_claim_host(card->host);
|
||||
|
||||
do {
|
||||
struct mmc_command cmd;
|
||||
@@ -283,6 +283,20 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
|
||||
brq.data.sg = mq->sg;
|
||||
brq.data.sg_len = blk_rq_map_sg(req->q, req, brq.data.sg);
|
||||
|
||||
if (brq.data.blocks !=
|
||||
(req->nr_sectors >> (md->block_bits - 9))) {
|
||||
data_size = brq.data.blocks * brq.data.blksz;
|
||||
for (sg_pos = 0; sg_pos < brq.data.sg_len; sg_pos++) {
|
||||
data_size -= mq->sg[sg_pos].length;
|
||||
if (data_size <= 0) {
|
||||
mq->sg[sg_pos].length += data_size;
|
||||
sg_pos++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
brq.data.sg_len = sg_pos;
|
||||
}
|
||||
|
||||
mmc_wait_for_req(card->host, &brq.mrq);
|
||||
if (brq.cmd.error) {
|
||||
printk(KERN_ERR "%s: error %d sending read/write command\n",
|
||||
@@ -342,7 +356,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
|
||||
spin_unlock_irq(&md->lock);
|
||||
} while (ret);
|
||||
|
||||
mmc_card_release_host(card);
|
||||
mmc_release_host(card->host);
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -378,9 +392,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
|
||||
spin_unlock_irq(&md->lock);
|
||||
}
|
||||
|
||||
flush_queue:
|
||||
|
||||
mmc_card_release_host(card);
|
||||
mmc_release_host(card->host);
|
||||
|
||||
spin_lock_irq(&md->lock);
|
||||
while (ret) {
|
||||
@@ -477,11 +489,20 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
|
||||
|
||||
blk_queue_hardsect_size(md->queue.queue, 1 << md->block_bits);
|
||||
|
||||
/*
|
||||
* The CSD capacity field is in units of read_blkbits.
|
||||
* set_capacity takes units of 512 bytes.
|
||||
*/
|
||||
set_capacity(md->disk, card->csd.capacity << (card->csd.read_blkbits - 9));
|
||||
if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) {
|
||||
/*
|
||||
* The EXT_CSD sector count is in number or 512 byte
|
||||
* sectors.
|
||||
*/
|
||||
set_capacity(md->disk, card->ext_csd.sectors);
|
||||
} else {
|
||||
/*
|
||||
* The CSD capacity field is in units of read_blkbits.
|
||||
* set_capacity takes units of 512 bytes.
|
||||
*/
|
||||
set_capacity(md->disk,
|
||||
card->csd.capacity << (card->csd.read_blkbits - 9));
|
||||
}
|
||||
return md;
|
||||
|
||||
err_putdisk:
|
||||
@@ -502,12 +523,12 @@ mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
|
||||
if (mmc_card_blockaddr(card))
|
||||
return 0;
|
||||
|
||||
mmc_card_claim_host(card);
|
||||
mmc_claim_host(card->host);
|
||||
cmd.opcode = MMC_SET_BLOCKLEN;
|
||||
cmd.arg = 1 << md->block_bits;
|
||||
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
|
||||
err = mmc_wait_for_cmd(card->host, &cmd, 5);
|
||||
mmc_card_release_host(card);
|
||||
mmc_release_host(card->host);
|
||||
|
||||
if (err) {
|
||||
printk(KERN_ERR "%s: unable to set block size to %d: %d\n",
|
||||
@@ -1,7 +1,8 @@
|
||||
/*
|
||||
* linux/drivers/mmc/mmc_queue.c
|
||||
* linux/drivers/mmc/queue.c
|
||||
*
|
||||
* Copyright (C) 2003 Russell King, All Rights Reserved.
|
||||
* Copyright 2006-2007 Pierre Ossman
|
||||
*
|
||||
* 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
|
||||
@@ -14,7 +15,7 @@
|
||||
|
||||
#include <linux/mmc/card.h>
|
||||
#include <linux/mmc/host.h>
|
||||
#include "mmc_queue.h"
|
||||
#include "queue.h"
|
||||
|
||||
#define MMC_QUEUE_SUSPENDED (1 << 0)
|
||||
|
||||
@@ -179,7 +180,6 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
|
||||
blk_cleanup_queue(mq->queue);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_init_queue);
|
||||
|
||||
void mmc_cleanup_queue(struct mmc_queue *mq)
|
||||
{
|
||||
@@ -191,6 +191,9 @@ void mmc_cleanup_queue(struct mmc_queue *mq)
|
||||
q->queuedata = NULL;
|
||||
spin_unlock_irqrestore(q->queue_lock, flags);
|
||||
|
||||
/* Make sure the queue isn't suspended, as that will deadlock */
|
||||
mmc_queue_resume(mq);
|
||||
|
||||
/* Then terminate our worker thread */
|
||||
kthread_stop(mq->thread);
|
||||
|
||||
@@ -226,7 +229,6 @@ void mmc_queue_suspend(struct mmc_queue *mq)
|
||||
down(&mq->thread_sem);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_queue_suspend);
|
||||
|
||||
/**
|
||||
* mmc_queue_resume - resume a previously suspended MMC request queue
|
||||
@@ -247,4 +249,4 @@ void mmc_queue_resume(struct mmc_queue *mq)
|
||||
spin_unlock_irqrestore(q->queue_lock, flags);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_queue_resume);
|
||||
|
||||
17
drivers/mmc/core/Kconfig
Normal file
17
drivers/mmc/core/Kconfig
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# MMC core configuration
|
||||
#
|
||||
|
||||
config MMC_UNSAFE_RESUME
|
||||
bool "Allow unsafe resume (DANGEROUS)"
|
||||
depends on MMC != n
|
||||
help
|
||||
If you say Y here, the MMC layer will assume that all cards
|
||||
stayed in their respective slots during the suspend. The
|
||||
normal behaviour is to remove them at suspend and
|
||||
redetecting them at resume. Breaking this assumption will
|
||||
in most cases result in data corruption.
|
||||
|
||||
This option is usually just for embedded systems which use
|
||||
a MMC/SD card for rootfs. Most people should say N here.
|
||||
|
||||
11
drivers/mmc/core/Makefile
Normal file
11
drivers/mmc/core/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
#
|
||||
# Makefile for the kernel mmc core.
|
||||
#
|
||||
|
||||
ifeq ($(CONFIG_MMC_DEBUG),y)
|
||||
EXTRA_CFLAGS += -DDEBUG
|
||||
endif
|
||||
|
||||
obj-$(CONFIG_MMC) += mmc_core.o
|
||||
mmc_core-y := core.o sysfs.o mmc.o mmc_ops.o sd.o sd_ops.o
|
||||
|
||||
727
drivers/mmc/core/core.c
Normal file
727
drivers/mmc/core/core.c
Normal file
File diff suppressed because it is too large
Load Diff
70
drivers/mmc/core/core.h
Normal file
70
drivers/mmc/core/core.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* linux/drivers/mmc/core/core.h
|
||||
*
|
||||
* Copyright (C) 2003 Russell King, All Rights Reserved.
|
||||
* Copyright 2007 Pierre Ossman
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef _MMC_CORE_CORE_H
|
||||
#define _MMC_CORE_CORE_H
|
||||
|
||||
#include <linux/delay.h>
|
||||
|
||||
#define MMC_CMD_RETRIES 3
|
||||
|
||||
struct mmc_bus_ops {
|
||||
void (*remove)(struct mmc_host *);
|
||||
void (*detect)(struct mmc_host *);
|
||||
void (*suspend)(struct mmc_host *);
|
||||
void (*resume)(struct mmc_host *);
|
||||
};
|
||||
|
||||
void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
|
||||
void mmc_detach_bus(struct mmc_host *host);
|
||||
|
||||
void __mmc_release_bus(struct mmc_host *host);
|
||||
|
||||
static inline void mmc_bus_get(struct mmc_host *host)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&host->lock, flags);
|
||||
host->bus_refs++;
|
||||
spin_unlock_irqrestore(&host->lock, flags);
|
||||
}
|
||||
|
||||
static inline void mmc_bus_put(struct mmc_host *host)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&host->lock, flags);
|
||||
host->bus_refs--;
|
||||
if ((host->bus_refs == 0) && host->bus_ops)
|
||||
__mmc_release_bus(host);
|
||||
spin_unlock_irqrestore(&host->lock, flags);
|
||||
}
|
||||
|
||||
void mmc_set_chip_select(struct mmc_host *host, int mode);
|
||||
void mmc_set_clock(struct mmc_host *host, unsigned int hz);
|
||||
void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
|
||||
void mmc_set_bus_width(struct mmc_host *host, unsigned int width);
|
||||
u32 mmc_select_voltage(struct mmc_host *host, u32 ocr);
|
||||
void mmc_set_timing(struct mmc_host *host, unsigned int timing);
|
||||
|
||||
struct mmc_card *mmc_alloc_card(struct mmc_host *host);
|
||||
|
||||
static inline void mmc_delay(unsigned int ms)
|
||||
{
|
||||
if (ms < 1000 / HZ) {
|
||||
cond_resched();
|
||||
mdelay(ms);
|
||||
} else {
|
||||
msleep(ms);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
537
drivers/mmc/core/mmc.c
Normal file
537
drivers/mmc/core/mmc.c
Normal file
File diff suppressed because it is too large
Load Diff
276
drivers/mmc/core/mmc_ops.c
Normal file
276
drivers/mmc/core/mmc_ops.c
Normal file
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* linux/drivers/mmc/mmc_ops.h
|
||||
*
|
||||
* Copyright 2006-2007 Pierre Ossman
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*/
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <asm/scatterlist.h>
|
||||
#include <linux/scatterlist.h>
|
||||
|
||||
#include <linux/mmc/host.h>
|
||||
#include <linux/mmc/card.h>
|
||||
#include <linux/mmc/mmc.h>
|
||||
|
||||
#include "core.h"
|
||||
#include "mmc_ops.h"
|
||||
|
||||
static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card)
|
||||
{
|
||||
int err;
|
||||
struct mmc_command cmd;
|
||||
|
||||
BUG_ON(!host);
|
||||
|
||||
memset(&cmd, 0, sizeof(struct mmc_command));
|
||||
|
||||
cmd.opcode = MMC_SELECT_CARD;
|
||||
|
||||
if (card) {
|
||||
cmd.arg = card->rca << 16;
|
||||
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
|
||||
} else {
|
||||
cmd.arg = 0;
|
||||
cmd.flags = MMC_RSP_NONE | MMC_CMD_AC;
|
||||
}
|
||||
|
||||
err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
|
||||
if (err != MMC_ERR_NONE)
|
||||
return err;
|
||||
|
||||
return MMC_ERR_NONE;
|
||||
}
|
||||
|
||||
int mmc_select_card(struct mmc_card *card)
|
||||
{
|
||||
BUG_ON(!card);
|
||||
|
||||
return _mmc_select_card(card->host, card);
|
||||
}
|
||||
|
||||
int mmc_deselect_cards(struct mmc_host *host)
|
||||
{
|
||||
return _mmc_select_card(host, NULL);
|
||||
}
|
||||
|
||||
int mmc_go_idle(struct mmc_host *host)
|
||||
{
|
||||
int err;
|
||||
struct mmc_command cmd;
|
||||
|
||||
mmc_set_chip_select(host, MMC_CS_HIGH);
|
||||
|
||||
mmc_delay(1);
|
||||
|
||||
memset(&cmd, 0, sizeof(struct mmc_command));
|
||||
|
||||
cmd.opcode = MMC_GO_IDLE_STATE;
|
||||
cmd.arg = 0;
|
||||
cmd.flags = MMC_RSP_NONE | MMC_CMD_BC;
|
||||
|
||||
err = mmc_wait_for_cmd(host, &cmd, 0);
|
||||
|
||||
mmc_delay(1);
|
||||
|
||||
mmc_set_chip_select(host, MMC_CS_DONTCARE);
|
||||
|
||||
mmc_delay(1);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
|
||||
{
|
||||
struct mmc_command cmd;
|
||||
int i, err = 0;
|
||||
|
||||
BUG_ON(!host);
|
||||
|
||||
memset(&cmd, 0, sizeof(struct mmc_command));
|
||||
|
||||
cmd.opcode = MMC_SEND_OP_COND;
|
||||
cmd.arg = ocr;
|
||||
cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR;
|
||||
|
||||
for (i = 100; i; i--) {
|
||||
err = mmc_wait_for_cmd(host, &cmd, 0);
|
||||
if (err != MMC_ERR_NONE)
|
||||
break;
|
||||
|
||||
if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0)
|
||||
break;
|
||||
|
||||
err = MMC_ERR_TIMEOUT;
|
||||
|
||||
mmc_delay(10);
|
||||
}
|
||||
|
||||
if (rocr)
|
||||
*rocr = cmd.resp[0];
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int mmc_all_send_cid(struct mmc_host *host, u32 *cid)
|
||||
{
|
||||
int err;
|
||||
struct mmc_command cmd;
|
||||
|
||||
BUG_ON(!host);
|
||||
BUG_ON(!cid);
|
||||
|
||||
memset(&cmd, 0, sizeof(struct mmc_command));
|
||||
|
||||
cmd.opcode = MMC_ALL_SEND_CID;
|
||||
cmd.arg = 0;
|
||||
cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR;
|
||||
|
||||
err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
|
||||
if (err != MMC_ERR_NONE)
|
||||
return err;
|
||||
|
||||
memcpy(cid, cmd.resp, sizeof(u32) * 4);
|
||||
|
||||
return MMC_ERR_NONE;
|
||||
}
|
||||
|
||||
int mmc_set_relative_addr(struct mmc_card *card)
|
||||
{
|
||||
int err;
|
||||
struct mmc_command cmd;
|
||||
|
||||
BUG_ON(!card);
|
||||
BUG_ON(!card->host);
|
||||
|
||||
memset(&cmd, 0, sizeof(struct mmc_command));
|
||||
|
||||
cmd.opcode = MMC_SET_RELATIVE_ADDR;
|
||||
cmd.arg = card->rca << 16;
|
||||
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
|
||||
|
||||
err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
|
||||
if (err != MMC_ERR_NONE)
|
||||
return err;
|
||||
|
||||
return MMC_ERR_NONE;
|
||||
}
|
||||
|
||||
int mmc_send_csd(struct mmc_card *card, u32 *csd)
|
||||
{
|
||||
int err;
|
||||
struct mmc_command cmd;
|
||||
|
||||
BUG_ON(!card);
|
||||
BUG_ON(!card->host);
|
||||
BUG_ON(!csd);
|
||||
|
||||
memset(&cmd, 0, sizeof(struct mmc_command));
|
||||
|
||||
cmd.opcode = MMC_SEND_CSD;
|
||||
cmd.arg = card->rca << 16;
|
||||
cmd.flags = MMC_RSP_R2 | MMC_CMD_AC;
|
||||
|
||||
err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
|
||||
if (err != MMC_ERR_NONE)
|
||||
return err;
|
||||
|
||||
memcpy(csd, cmd.resp, sizeof(u32) * 4);
|
||||
|
||||
return MMC_ERR_NONE;
|
||||
}
|
||||
|
||||
int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
|
||||
{
|
||||
struct mmc_request mrq;
|
||||
struct mmc_command cmd;
|
||||
struct mmc_data data;
|
||||
struct scatterlist sg;
|
||||
|
||||
BUG_ON(!card);
|
||||
BUG_ON(!card->host);
|
||||
BUG_ON(!ext_csd);
|
||||
|
||||
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 = MMC_SEND_EXT_CSD;
|
||||
cmd.arg = 0;
|
||||
cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
|
||||
|
||||
data.blksz = 512;
|
||||
data.blocks = 1;
|
||||
data.flags = MMC_DATA_READ;
|
||||
data.sg = &sg;
|
||||
data.sg_len = 1;
|
||||
|
||||
sg_init_one(&sg, ext_csd, 512);
|
||||
|
||||
mmc_set_data_timeout(&data, card, 0);
|
||||
|
||||
mmc_wait_for_req(card->host, &mrq);
|
||||
|
||||
if (cmd.error != MMC_ERR_NONE)
|
||||
return cmd.error;
|
||||
if (data.error != MMC_ERR_NONE)
|
||||
return data.error;
|
||||
|
||||
return MMC_ERR_NONE;
|
||||
}
|
||||
|
||||
int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value)
|
||||
{
|
||||
int err;
|
||||
struct mmc_command cmd;
|
||||
|
||||
BUG_ON(!card);
|
||||
BUG_ON(!card->host);
|
||||
|
||||
memset(&cmd, 0, sizeof(struct mmc_command));
|
||||
|
||||
cmd.opcode = MMC_SWITCH;
|
||||
cmd.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) |
|
||||
(index << 16) |
|
||||
(value << 8) |
|
||||
set;
|
||||
cmd.flags = MMC_RSP_R1B | MMC_CMD_AC;
|
||||
|
||||
err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
|
||||
if (err != MMC_ERR_NONE)
|
||||
return err;
|
||||
|
||||
return MMC_ERR_NONE;
|
||||
}
|
||||
|
||||
int mmc_send_status(struct mmc_card *card, u32 *status)
|
||||
{
|
||||
int err;
|
||||
struct mmc_command cmd;
|
||||
|
||||
BUG_ON(!card);
|
||||
BUG_ON(!card->host);
|
||||
|
||||
memset(&cmd, 0, sizeof(struct mmc_command));
|
||||
|
||||
cmd.opcode = MMC_SEND_STATUS;
|
||||
cmd.arg = card->rca << 16;
|
||||
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
|
||||
|
||||
err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
|
||||
if (err != MMC_ERR_NONE)
|
||||
return err;
|
||||
|
||||
if (status)
|
||||
*status = cmd.resp[0];
|
||||
|
||||
return MMC_ERR_NONE;
|
||||
}
|
||||
|
||||
27
drivers/mmc/core/mmc_ops.h
Normal file
27
drivers/mmc/core/mmc_ops.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* linux/drivers/mmc/mmc_ops.h
|
||||
*
|
||||
* Copyright 2006-2007 Pierre Ossman
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef _MMC_MMC_OPS_H
|
||||
#define _MMC_MMC_OPS_H
|
||||
|
||||
int mmc_select_card(struct mmc_card *card);
|
||||
int mmc_deselect_cards(struct mmc_host *host);
|
||||
int mmc_go_idle(struct mmc_host *host);
|
||||
int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr);
|
||||
int mmc_all_send_cid(struct mmc_host *host, u32 *cid);
|
||||
int mmc_set_relative_addr(struct mmc_card *card);
|
||||
int mmc_send_csd(struct mmc_card *card, u32 *csd);
|
||||
int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd);
|
||||
int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value);
|
||||
int mmc_send_status(struct mmc_card *card, u32 *status);
|
||||
|
||||
#endif
|
||||
|
||||
587
drivers/mmc/core/sd.c
Normal file
587
drivers/mmc/core/sd.c
Normal file
File diff suppressed because it is too large
Load Diff
316
drivers/mmc/core/sd_ops.c
Normal file
316
drivers/mmc/core/sd_ops.c
Normal file
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* linux/drivers/mmc/sd_ops.h
|
||||
*
|
||||
* Copyright 2006-2007 Pierre Ossman
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*/
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <asm/scatterlist.h>
|
||||
#include <linux/scatterlist.h>
|
||||
|
||||
#include <linux/mmc/host.h>
|
||||
#include <linux/mmc/card.h>
|
||||
#include <linux/mmc/mmc.h>
|
||||
#include <linux/mmc/sd.h>
|
||||
|
||||
#include "core.h"
|
||||
#include "sd_ops.h"
|
||||
|
||||
/**
|
||||
* mmc_wait_for_app_cmd - start an application command and wait for
|
||||
completion
|
||||
* @host: MMC host to start command
|
||||
* @rca: RCA to send MMC_APP_CMD to
|
||||
* @cmd: MMC command to start
|
||||
* @retries: maximum number of retries
|
||||
*
|
||||
* Sends a MMC_APP_CMD, checks the card response, sends the command
|
||||
* in the parameter and waits for it to complete. Return any error
|
||||
* that occurred while the command was executing. Do not attempt to
|
||||
* parse the response.
|
||||
*/
|
||||
int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
|
||||
struct mmc_command *cmd, int retries)
|
||||
{
|
||||
struct mmc_request mrq;
|
||||
|
||||
int i, err;
|
||||
|
||||
BUG_ON(!cmd);
|
||||
BUG_ON(retries < 0);
|
||||
|
||||
err = MMC_ERR_INVALID;
|
||||
|
||||
/*
|
||||
* We have to resend MMC_APP_CMD for each attempt so
|
||||
* we cannot use the retries field in mmc_command.
|
||||
*/
|
||||
for (i = 0;i <= retries;i++) {
|
||||
memset(&mrq, 0, sizeof(struct mmc_request));
|
||||
|
||||
err = mmc_app_cmd(host, card);
|
||||
if (err != MMC_ERR_NONE)
|
||||
continue;
|
||||
|
||||
memset(&mrq, 0, sizeof(struct mmc_request));
|
||||
|
||||
memset(cmd->resp, 0, sizeof(cmd->resp));
|
||||
cmd->retries = 0;
|
||||
|
||||
mrq.cmd = cmd;
|
||||
cmd->data = NULL;
|
||||
|
||||
mmc_wait_for_req(host, &mrq);
|
||||
|
||||
err = cmd->error;
|
||||
if (cmd->error == MMC_ERR_NONE)
|
||||
break;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(mmc_wait_for_app_cmd);
|
||||
|
||||
int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
|
||||
{
|
||||
int err;
|
||||
struct mmc_command cmd;
|
||||
|
||||
BUG_ON(!host);
|
||||
BUG_ON(card && (card->host != host));
|
||||
|
||||
cmd.opcode = MMC_APP_CMD;
|
||||
|
||||
if (card) {
|
||||
cmd.arg = card->rca << 16;
|
||||
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
|
||||
} else {
|
||||
cmd.arg = 0;
|
||||
cmd.flags = MMC_RSP_R1 | MMC_CMD_BCR;
|
||||
}
|
||||
|
||||
err = mmc_wait_for_cmd(host, &cmd, 0);
|
||||
if (err != MMC_ERR_NONE)
|
||||
return err;
|
||||
|
||||
/* Check that card supported application commands */
|
||||
if (!(cmd.resp[0] & R1_APP_CMD))
|
||||
return MMC_ERR_FAILED;
|
||||
|
||||
return MMC_ERR_NONE;
|
||||
}
|
||||
|
||||
int mmc_app_set_bus_width(struct mmc_card *card, int width)
|
||||
{
|
||||
int err;
|
||||
struct mmc_command cmd;
|
||||
|
||||
BUG_ON(!card);
|
||||
BUG_ON(!card->host);
|
||||
|
||||
memset(&cmd, 0, sizeof(struct mmc_command));
|
||||
|
||||
cmd.opcode = SD_APP_SET_BUS_WIDTH;
|
||||
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
|
||||
|
||||
switch (width) {
|
||||
case MMC_BUS_WIDTH_1:
|
||||
cmd.arg = SD_BUS_WIDTH_1;
|
||||
break;
|
||||
case MMC_BUS_WIDTH_4:
|
||||
cmd.arg = SD_BUS_WIDTH_4;
|
||||
break;
|
||||
default:
|
||||
return MMC_ERR_INVALID;
|
||||
}
|
||||
|
||||
err = mmc_wait_for_app_cmd(card->host, card, &cmd, MMC_CMD_RETRIES);
|
||||
if (err != MMC_ERR_NONE)
|
||||
return err;
|
||||
|
||||
return MMC_ERR_NONE;
|
||||
}
|
||||
|
||||
int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
|
||||
{
|
||||
struct mmc_command cmd;
|
||||
int i, err = 0;
|
||||
|
||||
BUG_ON(!host);
|
||||
|
||||
memset(&cmd, 0, sizeof(struct mmc_command));
|
||||
|
||||
cmd.opcode = SD_APP_OP_COND;
|
||||
cmd.arg = ocr;
|
||||
cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR;
|
||||
|
||||
for (i = 100; i; i--) {
|
||||
err = mmc_wait_for_app_cmd(host, NULL, &cmd, MMC_CMD_RETRIES);
|
||||
if (err != MMC_ERR_NONE)
|
||||
break;
|
||||
|
||||
if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0)
|
||||
break;
|
||||
|
||||
err = MMC_ERR_TIMEOUT;
|
||||
|
||||
mmc_delay(10);
|
||||
}
|
||||
|
||||
if (rocr)
|
||||
*rocr = cmd.resp[0];
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int mmc_send_if_cond(struct mmc_host *host, u32 ocr)
|
||||
{
|
||||
struct mmc_command cmd;
|
||||
int err;
|
||||
static const u8 test_pattern = 0xAA;
|
||||
|
||||
/*
|
||||
* To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND
|
||||
* before SD_APP_OP_COND. This command will harmlessly fail for
|
||||
* SD 1.0 cards.
|
||||
*/
|
||||
cmd.opcode = SD_SEND_IF_COND;
|
||||
cmd.arg = ((ocr & 0xFF8000) != 0) << 8 | test_pattern;
|
||||
cmd.flags = MMC_RSP_R7 | MMC_CMD_BCR;
|
||||
|
||||
err = mmc_wait_for_cmd(host, &cmd, 0);
|
||||
if (err != MMC_ERR_NONE)
|
||||
return err;
|
||||
|
||||
if ((cmd.resp[0] & 0xFF) != test_pattern)
|
||||
return MMC_ERR_FAILED;
|
||||
|
||||
return MMC_ERR_NONE;
|
||||
}
|
||||
|
||||
int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca)
|
||||
{
|
||||
int err;
|
||||
struct mmc_command cmd;
|
||||
|
||||
BUG_ON(!host);
|
||||
BUG_ON(!rca);
|
||||
|
||||
memset(&cmd, 0, sizeof(struct mmc_command));
|
||||
|
||||
cmd.opcode = SD_SEND_RELATIVE_ADDR;
|
||||
cmd.arg = 0;
|
||||
cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR;
|
||||
|
||||
err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
|
||||
if (err != MMC_ERR_NONE)
|
||||
return err;
|
||||
|
||||
*rca = cmd.resp[0] >> 16;
|
||||
|
||||
return MMC_ERR_NONE;
|
||||
}
|
||||
|
||||
int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
|
||||
{
|
||||
int err;
|
||||
struct mmc_request mrq;
|
||||
struct mmc_command cmd;
|
||||
struct mmc_data data;
|
||||
struct scatterlist sg;
|
||||
|
||||
BUG_ON(!card);
|
||||
BUG_ON(!card->host);
|
||||
BUG_ON(!scr);
|
||||
|
||||
err = mmc_app_cmd(card->host, card);
|
||||
if (err != MMC_ERR_NONE)
|
||||
return err;
|
||||
|
||||
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_APP_SEND_SCR;
|
||||
cmd.arg = 0;
|
||||
cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
|
||||
|
||||
data.blksz = 8;
|
||||
data.blocks = 1;
|
||||
data.flags = MMC_DATA_READ;
|
||||
data.sg = &sg;
|
||||
data.sg_len = 1;
|
||||
|
||||
sg_init_one(&sg, scr, 8);
|
||||
|
||||
mmc_set_data_timeout(&data, card, 0);
|
||||
|
||||
mmc_wait_for_req(card->host, &mrq);
|
||||
|
||||
if (cmd.error != MMC_ERR_NONE)
|
||||
return cmd.error;
|
||||
if (data.error != MMC_ERR_NONE)
|
||||
return data.error;
|
||||
|
||||
scr[0] = ntohl(scr[0]);
|
||||
scr[1] = ntohl(scr[1]);
|
||||
|
||||
return MMC_ERR_NONE;
|
||||
}
|
||||
|
||||
int mmc_sd_switch(struct mmc_card *card, int mode, int group,
|
||||
u8 value, u8 *resp)
|
||||
{
|
||||
struct mmc_request mrq;
|
||||
struct mmc_command cmd;
|
||||
struct mmc_data data;
|
||||
struct scatterlist sg;
|
||||
|
||||
BUG_ON(!card);
|
||||
BUG_ON(!card->host);
|
||||
|
||||
mode = !!mode;
|
||||
value &= 0xF;
|
||||
|
||||
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_SWITCH;
|
||||
cmd.arg = mode << 31 | 0x00FFFFFF;
|
||||
cmd.arg &= ~(0xF << (group * 4));
|
||||
cmd.arg |= value << (group * 4);
|
||||
cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
|
||||
|
||||
data.blksz = 64;
|
||||
data.blocks = 1;
|
||||
data.flags = MMC_DATA_READ;
|
||||
data.sg = &sg;
|
||||
data.sg_len = 1;
|
||||
|
||||
sg_init_one(&sg, resp, 64);
|
||||
|
||||
mmc_set_data_timeout(&data, card, 0);
|
||||
|
||||
mmc_wait_for_req(card->host, &mrq);
|
||||
|
||||
if (cmd.error != MMC_ERR_NONE)
|
||||
return cmd.error;
|
||||
if (data.error != MMC_ERR_NONE)
|
||||
return data.error;
|
||||
|
||||
return MMC_ERR_NONE;
|
||||
}
|
||||
|
||||
25
drivers/mmc/core/sd_ops.h
Normal file
25
drivers/mmc/core/sd_ops.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* linux/drivers/mmc/sd_ops.h
|
||||
*
|
||||
* Copyright 2006-2007 Pierre Ossman
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef _MMC_SD_OPS_H
|
||||
#define _MMC_SD_OPS_H
|
||||
|
||||
int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card);
|
||||
int mmc_app_set_bus_width(struct mmc_card *card, int width);
|
||||
int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr);
|
||||
int mmc_send_if_cond(struct mmc_host *host, u32 ocr);
|
||||
int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca);
|
||||
int mmc_app_send_scr(struct mmc_card *card, u32 *scr);
|
||||
int mmc_sd_switch(struct mmc_card *card, int mode, int group,
|
||||
u8 value, u8 *resp);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* linux/drivers/mmc/mmc_sysfs.c
|
||||
* linux/drivers/mmc/core/sysfs.c
|
||||
*
|
||||
* Copyright (C) 2003 Russell King, All Rights Reserved.
|
||||
*
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <linux/mmc/card.h>
|
||||
#include <linux/mmc/host.h>
|
||||
|
||||
#include "mmc.h"
|
||||
#include "sysfs.h"
|
||||
|
||||
#define dev_to_mmc_card(d) container_of(d, struct mmc_card, dev)
|
||||
#define to_mmc_driver(d) container_of(d, struct mmc_driver, drv)
|
||||
@@ -72,12 +72,11 @@ static void mmc_release_card(struct device *dev)
|
||||
/*
|
||||
* This currently matches any MMC driver to any MMC card - drivers
|
||||
* themselves make the decision whether to drive this card in their
|
||||
* probe method. However, we force "bad" cards to fail.
|
||||
* probe method.
|
||||
*/
|
||||
static int mmc_bus_match(struct device *dev, struct device_driver *drv)
|
||||
{
|
||||
struct mmc_card *card = dev_to_mmc_card(dev);
|
||||
return !mmc_card_bad(card);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -217,6 +216,8 @@ int mmc_register_card(struct mmc_card *card)
|
||||
device_del(&card->dev);
|
||||
}
|
||||
}
|
||||
if (ret == 0)
|
||||
mmc_card_set_present(card);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user