Commit 4c75f741 authored by Linus Torvalds's avatar Linus Torvalds

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:
  mmc: at91_mci: fix hanging and rework to match flowcharts
  mmc: at91_mci typo
  sdhci: Fix "Unexpected interrupt" handling
  mmc: fix silly copy-and-paste error
  mmc: move layer init and workqueue to core file
  mmc: refactor host class handling
  mmc: refactor bus operations
  sdhci: add ene controller id
  mmc: bounce requests for simple hosts
parents 6ed911fb ed99c541
...@@ -14,3 +14,21 @@ config MMC_BLOCK ...@@ -14,3 +14,21 @@ config MMC_BLOCK
mount the filesystem. Almost everyone wishing MMC support mount the filesystem. Almost everyone wishing MMC support
should say Y or M here. should say Y or M here.
config MMC_BLOCK_BOUNCE
bool "Use bounce buffer for simple hosts"
depends on MMC_BLOCK
default y
help
SD/MMC is a high latency protocol where it is crucial to
send large requests in order to get high performance. Many
controllers, however, are restricted to continuous memory
(i.e. they can't do scatter-gather), something the kernel
rarely can provide.
Say Y here to help these restricted hosts by bouncing
requests back and forth from a large buffer. You will get
a big performance gain at the cost of up to 64 KiB of
physical memory.
If unsure, say Y here.
...@@ -262,7 +262,9 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) ...@@ -262,7 +262,9 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
} }
brq.data.sg = mq->sg; brq.data.sg = mq->sg;
brq.data.sg_len = blk_rq_map_sg(req->q, req, brq.data.sg); brq.data.sg_len = mmc_queue_map_sg(mq);
mmc_queue_bounce_pre(mq);
if (brq.data.blocks != if (brq.data.blocks !=
(req->nr_sectors >> (md->block_bits - 9))) { (req->nr_sectors >> (md->block_bits - 9))) {
...@@ -279,6 +281,9 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) ...@@ -279,6 +281,9 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
} }
mmc_wait_for_req(card->host, &brq.mrq); mmc_wait_for_req(card->host, &brq.mrq);
mmc_queue_bounce_post(mq);
if (brq.cmd.error) { if (brq.cmd.error) {
printk(KERN_ERR "%s: error %d sending read/write command\n", printk(KERN_ERR "%s: error %d sending read/write command\n",
req->rq_disk->disk_name, brq.cmd.error); req->rq_disk->disk_name, brq.cmd.error);
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <linux/mmc/host.h> #include <linux/mmc/host.h>
#include "queue.h" #include "queue.h"
#define MMC_QUEUE_BOUNCESZ 65536
#define MMC_QUEUE_SUSPENDED (1 << 0) #define MMC_QUEUE_SUSPENDED (1 << 0)
/* /*
...@@ -118,6 +120,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock ...@@ -118,6 +120,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
struct mmc_host *host = card->host; struct mmc_host *host = card->host;
u64 limit = BLK_BOUNCE_HIGH; u64 limit = BLK_BOUNCE_HIGH;
int ret; int ret;
unsigned int bouncesz;
if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask) if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
limit = *mmc_dev(host)->dma_mask; limit = *mmc_dev(host)->dma_mask;
...@@ -127,21 +130,61 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock ...@@ -127,21 +130,61 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
if (!mq->queue) if (!mq->queue)
return -ENOMEM; return -ENOMEM;
blk_queue_prep_rq(mq->queue, mmc_prep_request);
blk_queue_bounce_limit(mq->queue, limit);
blk_queue_max_sectors(mq->queue, host->max_req_size / 512);
blk_queue_max_phys_segments(mq->queue, host->max_phys_segs);
blk_queue_max_hw_segments(mq->queue, host->max_hw_segs);
blk_queue_max_segment_size(mq->queue, host->max_seg_size);
mq->queue->queuedata = mq; mq->queue->queuedata = mq;
mq->req = NULL; mq->req = NULL;
mq->sg = kmalloc(sizeof(struct scatterlist) * host->max_phys_segs, blk_queue_prep_rq(mq->queue, mmc_prep_request);
GFP_KERNEL);
if (!mq->sg) { #ifdef CONFIG_MMC_BLOCK_BOUNCE
ret = -ENOMEM; if (host->max_hw_segs == 1) {
goto cleanup_queue; bouncesz = MMC_QUEUE_BOUNCESZ;
if (bouncesz > host->max_req_size)
bouncesz = host->max_req_size;
if (bouncesz > host->max_seg_size)
bouncesz = host->max_seg_size;
mq->bounce_buf = kmalloc(bouncesz, GFP_KERNEL);
if (!mq->bounce_buf) {
printk(KERN_WARNING "%s: unable to allocate "
"bounce buffer\n", mmc_card_name(card));
} else {
blk_queue_bounce_limit(mq->queue, BLK_BOUNCE_HIGH);
blk_queue_max_sectors(mq->queue, bouncesz / 512);
blk_queue_max_phys_segments(mq->queue, bouncesz / 512);
blk_queue_max_hw_segments(mq->queue, bouncesz / 512);
blk_queue_max_segment_size(mq->queue, bouncesz);
mq->sg = kmalloc(sizeof(struct scatterlist),
GFP_KERNEL);
if (!mq->sg) {
ret = -ENOMEM;
goto free_bounce_buf;
}
mq->bounce_sg = kmalloc(sizeof(struct scatterlist) *
bouncesz / 512, GFP_KERNEL);
if (!mq->bounce_sg) {
ret = -ENOMEM;
goto free_sg;
}
}
}
#endif
if (!mq->bounce_buf) {
blk_queue_bounce_limit(mq->queue, limit);
blk_queue_max_sectors(mq->queue, host->max_req_size / 512);
blk_queue_max_phys_segments(mq->queue, host->max_phys_segs);
blk_queue_max_hw_segments(mq->queue, host->max_hw_segs);
blk_queue_max_segment_size(mq->queue, host->max_seg_size);
mq->sg = kmalloc(sizeof(struct scatterlist) *
host->max_phys_segs, GFP_KERNEL);
if (!mq->sg) {
ret = -ENOMEM;
goto cleanup_queue;
}
} }
init_MUTEX(&mq->thread_sem); init_MUTEX(&mq->thread_sem);
...@@ -149,14 +192,21 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock ...@@ -149,14 +192,21 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
mq->thread = kthread_run(mmc_queue_thread, mq, "mmcqd"); mq->thread = kthread_run(mmc_queue_thread, mq, "mmcqd");
if (IS_ERR(mq->thread)) { if (IS_ERR(mq->thread)) {
ret = PTR_ERR(mq->thread); ret = PTR_ERR(mq->thread);
goto free_sg; goto free_bounce_sg;
} }
return 0; return 0;
free_bounce_sg:
if (mq->bounce_sg)
kfree(mq->bounce_sg);
mq->bounce_sg = NULL;
free_sg: free_sg:
kfree(mq->sg); kfree(mq->sg);
mq->sg = NULL; mq->sg = NULL;
free_bounce_buf:
if (mq->bounce_buf)
kfree(mq->bounce_buf);
mq->bounce_buf = NULL;
cleanup_queue: cleanup_queue:
blk_cleanup_queue(mq->queue); blk_cleanup_queue(mq->queue);
return ret; return ret;
...@@ -178,9 +228,17 @@ void mmc_cleanup_queue(struct mmc_queue *mq) ...@@ -178,9 +228,17 @@ void mmc_cleanup_queue(struct mmc_queue *mq)
/* Then terminate our worker thread */ /* Then terminate our worker thread */
kthread_stop(mq->thread); kthread_stop(mq->thread);
if (mq->bounce_sg)
kfree(mq->bounce_sg);
mq->bounce_sg = NULL;
kfree(mq->sg); kfree(mq->sg);
mq->sg = NULL; mq->sg = NULL;
if (mq->bounce_buf)
kfree(mq->bounce_buf);
mq->bounce_buf = NULL;
blk_cleanup_queue(mq->queue); blk_cleanup_queue(mq->queue);
mq->card = NULL; mq->card = NULL;
...@@ -231,3 +289,108 @@ void mmc_queue_resume(struct mmc_queue *mq) ...@@ -231,3 +289,108 @@ void mmc_queue_resume(struct mmc_queue *mq)
} }
} }
static void copy_sg(struct scatterlist *dst, unsigned int dst_len,
struct scatterlist *src, unsigned int src_len)
{
unsigned int chunk;
char *dst_buf, *src_buf;
unsigned int dst_size, src_size;
dst_buf = NULL;
src_buf = NULL;
dst_size = 0;
src_size = 0;
while (src_len) {
BUG_ON(dst_len == 0);
if (dst_size == 0) {
dst_buf = page_address(dst->page) + dst->offset;
dst_size = dst->length;
}
if (src_size == 0) {
src_buf = page_address(src->page) + src->offset;
src_size = src->length;
}
chunk = min(dst_size, src_size);
memcpy(dst_buf, src_buf, chunk);
dst_buf += chunk;
src_buf += chunk;
dst_size -= chunk;
src_size -= chunk;
if (dst_size == 0) {
dst++;
dst_len--;
}
if (src_size == 0) {
src++;
src_len--;
}
}
}
unsigned int mmc_queue_map_sg(struct mmc_queue *mq)
{
unsigned int sg_len;
if (!mq->bounce_buf)
return blk_rq_map_sg(mq->queue, mq->req, mq->sg);
BUG_ON(!mq->bounce_sg);
sg_len = blk_rq_map_sg(mq->queue, mq->req, mq->bounce_sg);
mq->bounce_sg_len = sg_len;
/*
* Shortcut in the event we only get a single entry.
*/
if (sg_len == 1) {
memcpy(mq->sg, mq->bounce_sg, sizeof(struct scatterlist));
return 1;
}
mq->sg[0].page = virt_to_page(mq->bounce_buf);
mq->sg[0].offset = offset_in_page(mq->bounce_buf);
mq->sg[0].length = 0;
while (sg_len) {
mq->sg[0].length += mq->bounce_sg[sg_len - 1].length;
sg_len--;
}
return 1;
}
void mmc_queue_bounce_pre(struct mmc_queue *mq)
{
if (!mq->bounce_buf)
return;
if (mq->bounce_sg_len == 1)
return;
if (rq_data_dir(mq->req) != WRITE)
return;
copy_sg(mq->sg, 1, mq->bounce_sg, mq->bounce_sg_len);
}
void mmc_queue_bounce_post(struct mmc_queue *mq)
{
if (!mq->bounce_buf)
return;
if (mq->bounce_sg_len == 1)
return;
if (rq_data_dir(mq->req) != READ)
return;
copy_sg(mq->bounce_sg, mq->bounce_sg_len, mq->sg, 1);
}
...@@ -14,6 +14,9 @@ struct mmc_queue { ...@@ -14,6 +14,9 @@ struct mmc_queue {
void *data; void *data;
struct request_queue *queue; struct request_queue *queue;
struct scatterlist *sg; struct scatterlist *sg;
char *bounce_buf;
struct scatterlist *bounce_sg;
unsigned int bounce_sg_len;
}; };
extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *); extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *);
...@@ -21,4 +24,8 @@ extern void mmc_cleanup_queue(struct mmc_queue *); ...@@ -21,4 +24,8 @@ extern void mmc_cleanup_queue(struct mmc_queue *);
extern void mmc_queue_suspend(struct mmc_queue *); extern void mmc_queue_suspend(struct mmc_queue *);
extern void mmc_queue_resume(struct mmc_queue *); extern void mmc_queue_resume(struct mmc_queue *);
extern unsigned int mmc_queue_map_sg(struct mmc_queue *);
extern void mmc_queue_bounce_pre(struct mmc_queue *);
extern void mmc_queue_bounce_post(struct mmc_queue *);
#endif #endif
...@@ -7,5 +7,6 @@ ifeq ($(CONFIG_MMC_DEBUG),y) ...@@ -7,5 +7,6 @@ ifeq ($(CONFIG_MMC_DEBUG),y)
endif endif
obj-$(CONFIG_MMC) += mmc_core.o obj-$(CONFIG_MMC) += mmc_core.o
mmc_core-y := core.o sysfs.o mmc.o mmc_ops.o sd.o sd_ops.o mmc_core-y := core.o sysfs.o bus.o host.o \
mmc.o mmc_ops.o sd.o sd_ops.o
/*
* linux/drivers/mmc/core/bus.c
*
* Copyright (C) 2003 Russell King, All Rights Reserved.
* Copyright (C) 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.
*
* MMC card bus driver model
*/
#include <linux/device.h>
#include <linux/err.h>
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
#include "sysfs.h"
#include "core.h"
#include "bus.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)
static ssize_t mmc_type_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct mmc_card *card = dev_to_mmc_card(dev);
switch (card->type) {
case MMC_TYPE_MMC:
return sprintf(buf, "MMC\n");
case MMC_TYPE_SD:
return sprintf(buf, "SD\n");
default:
return -EFAULT;
}
}
static struct device_attribute mmc_dev_attrs[] = {
MMC_ATTR_RO(type),
__ATTR_NULL,
};
/*
* This currently matches any MMC driver to any MMC card - drivers
* themselves make the decision whether to drive this card in their
* probe method.
*/
static int mmc_bus_match(struct device *dev, struct device_driver *drv)
{
return 1;
}
static int
mmc_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
int buf_size)
{
struct mmc_card *card = dev_to_mmc_card(dev);
int retval = 0, i = 0, length = 0;
#define add_env(fmt,val) do { \
retval = add_uevent_var(envp, num_envp, &i, \
buf, buf_size, &length, \
fmt, val); \
if (retval) \
return retval; \
} while (0);
switch (card->type) {
case MMC_TYPE_MMC:
add_env("MMC_TYPE=%s", "MMC");
break;
case MMC_TYPE_SD:
add_env("MMC_TYPE=%s", "SD");
break;
}
add_env("MMC_NAME=%s", mmc_card_name(card));
#undef add_env
envp[i] = NULL;
return 0;
}
static int mmc_bus_probe(struct device *dev)
{
struct mmc_driver *drv = to_mmc_driver(dev->driver);
struct mmc_card *card = dev_to_mmc_card(dev);
return drv->probe(card);
}
static int mmc_bus_remove(struct device *dev)
{
struct mmc_driver *drv = to_mmc_driver(dev->driver);
struct mmc_card *card = dev_to_mmc_card(dev);
drv->remove(card);
return 0;
}
static int mmc_bus_suspend(struct device *dev, pm_message_t state)
{
struct mmc_driver *drv = to_mmc_driver(dev->driver);
struct mmc_card *card = dev_to_mmc_card(dev);
int ret = 0;
if (dev->driver && drv->suspend)
ret = drv->suspend(card, state);
return ret;
}
static int mmc_bus_resume(struct device *dev)
{
struct mmc_driver *drv = to_mmc_driver(dev->driver);
struct mmc_card *card = dev_to_mmc_card(dev);
int ret = 0;
if (dev->driver && drv->resume)
ret = drv->resume(card);
return ret;
}
static struct bus_type mmc_bus_type = {
.name = "mmc",
.dev_attrs = mmc_dev_attrs,
.match = mmc_bus_match,
.uevent = mmc_bus_uevent,
.probe = mmc_bus_probe,
.remove = mmc_bus_remove,
.suspend = mmc_bus_suspend,
.resume = mmc_bus_resume,
};
int mmc_register_bus(void)
{
return bus_register(&mmc_bus_type);
}
void mmc_unregister_bus(void)
{
bus_unregister(&mmc_bus_type);
}
/**
* mmc_register_driver - register a media driver
* @drv: MMC media driver
*/
int mmc_register_driver(struct mmc_driver *drv)
{
drv->drv.bus = &mmc_bus_type;
return driver_register(&drv->drv);
}
EXPORT_SYMBOL(mmc_register_driver);
/**
* mmc_unregister_driver - unregister a media driver
* @drv: MMC media driver
*/
void mmc_unregister_driver(struct mmc_driver *drv)
{
drv->drv.bus = &mmc_bus_type;
driver_unregister(&drv->drv);
}
EXPORT_SYMBOL(mmc_unregister_driver);
static void mmc_release_card(struct device *dev)
{
struct mmc_card *card = dev_to_mmc_card(dev);
kfree(card);
}
/*
* Allocate and initialise a new MMC card structure.
*/
struct mmc_card *mmc_alloc_card(struct mmc_host *host)
{
struct mmc_card *card;
card = kmalloc(sizeof(struct mmc_card), GFP_KERNEL);
if (!card)
return ERR_PTR(-ENOMEM);
memset(card, 0, sizeof(struct mmc_card));
card->host = host;
device_initialize(&card->dev);
card->dev.parent = mmc_classdev(host);
card->dev.bus = &mmc_bus_type;
card->dev.release = mmc_release_card;
return card;
}
/*
* Register a new MMC card with the driver model.
*/
int mmc_add_card(struct mmc_card *card)
{
int ret;
snprintf(card->dev.bus_id, sizeof(card->dev.bus_id),
"%s:%04x", mmc_hostname(card->host), card->rca);
card->dev.uevent_suppress = 1;
ret = device_add(&card->dev);
if (ret)
return ret;
if (card->host->bus_ops->sysfs_add) {
ret = card->host->bus_ops->sysfs_add(card->host, card);
if (ret) {
device_del(&card->dev);
return ret;
}
}
card->dev.uevent_suppress = 0;
kobject_uevent(&card->dev.kobj, KOBJ_ADD);
mmc_card_set_present(card);
return 0;
}
/*
* Unregister a new MMC card with the driver model, and
* (eventually) free it.
*/
void mmc_remove_card(struct mmc_card *card)
{
if (mmc_card_present(card)) {
if (card->host->bus_ops->sysfs_remove)
card->host->bus_ops->sysfs_remove(card->host, card);
device_del(&card->dev);
}
put_device(&card->dev);
}
/*
* linux/drivers/mmc/core/bus.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_BUS_H
#define _MMC_CORE_BUS_H
struct mmc_card *mmc_alloc_card(struct mmc_host *host);
int mmc_add_card(struct mmc_card *card);
void mmc_remove_card(struct mmc_card *card);
int mmc_register_bus(void);
void mmc_unregister_bus(void);
#endif
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
#include <linux/mmc/sd.h> #include <linux/mmc/sd.h>
#include "core.h" #include "core.h"
#include "sysfs.h" #include "bus.h"
#include "host.h"
#include "mmc_ops.h" #include "mmc_ops.h"
#include "sd_ops.h" #include "sd_ops.h"
...@@ -35,6 +36,25 @@ ...@@ -35,6 +36,25 @@
extern int mmc_attach_mmc(struct mmc_host *host, u32 ocr); extern int mmc_attach_mmc(struct mmc_host *host, u32 ocr);
extern int mmc_attach_sd(struct mmc_host *host, u32 ocr); extern int mmc_attach_sd(struct mmc_host *host, u32 ocr);
static struct workqueue_struct *workqueue;
/*
* Internal function. Schedule delayed work in the MMC work queue.
*/
static int mmc_schedule_delayed_work(struct delayed_work *work,
unsigned long delay)
{
return queue_delayed_work(workqueue, work, delay);
}
/*
* Internal function. Flush all scheduled work from the MMC work queue.
*/
static void mmc_flush_scheduled_work(void)
{
flush_workqueue(workqueue);
}
/** /**
* mmc_request_done - finish processing an MMC request * mmc_request_done - finish processing an MMC request
* @host: MMC host which completed request * @host: MMC host which completed request
...@@ -368,22 +388,6 @@ void mmc_set_timing(struct mmc_host *host, unsigned int timing) ...@@ -368,22 +388,6 @@ void mmc_set_timing(struct mmc_host *host, unsigned int timing)
mmc_set_ios(host); mmc_set_ios(host);
} }
/*
* Allocate a new MMC card
*/
struct mmc_card *mmc_alloc_card(struct mmc_host *host)
{
struct mmc_card *card;
card = kmalloc(sizeof(struct mmc_card), GFP_KERNEL);
if (!card)
return ERR_PTR(-ENOMEM);
mmc_init_card(card, host);
return card;
}
/* /*
* Apply power to the MMC stack. This is a two-stage process. * Apply power to the MMC stack. This is a two-stage process.
* First, we enable power to the card without the clock running. * First, we enable power to the card without the clock running.
...@@ -512,7 +516,7 @@ void mmc_detect_change(struct mmc_host *host, unsigned long delay) ...@@ -512,7 +516,7 @@ void mmc_detect_change(struct mmc_host *host, unsigned long delay)
EXPORT_SYMBOL(mmc_detect_change); EXPORT_SYMBOL(mmc_detect_change);
static void mmc_rescan(struct work_struct *work) void mmc_rescan(struct work_struct *work)
{ {
struct mmc_host *host = struct mmc_host *host =
container_of(work, struct mmc_host, detect.work); container_of(work, struct mmc_host, detect.work);
...@@ -561,69 +565,13 @@ static void mmc_rescan(struct work_struct *work) ...@@ -561,69 +565,13 @@ static void mmc_rescan(struct work_struct *work)
} }
} }
void mmc_start_host(struct mmc_host *host)
/**
* mmc_alloc_host - initialise the per-host structure.
* @extra: sizeof private data structure
* @dev: pointer to host device model structure
*
* Initialise the per-host structure.
*/
struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
{ {
struct mmc_host *host; mmc_power_off(host);
mmc_detect_change(host, 0);
host = mmc_alloc_host_sysfs(extra, dev);
if (host) {
spin_lock_init(&host->lock);
init_waitqueue_head(&host->wq);
INIT_DELAYED_WORK(&host->detect, mmc_rescan);
/*
* By default, hosts do not support SGIO or large requests.
* They have to set these according to their abilities.
*/
host->max_hw_segs = 1;
host->max_phys_segs = 1;
host->max_seg_size = PAGE_CACHE_SIZE;
host->max_req_size = PAGE_CACHE_SIZE;
host->max_blk_size = 512;
host->max_blk_count = PAGE_CACHE_SIZE / 512;
}
return host;
}
EXPORT_SYMBOL(mmc_alloc_host);
/**
* mmc_add_host - initialise host hardware
* @host: mmc host
*/
int mmc_add_host(struct mmc_host *host)
{
int ret;
ret = mmc_add_host_sysfs(host);
if (ret == 0) {
mmc_power_off(host);
mmc_detect_change(host, 0);
}
return ret;
} }
EXPORT_SYMBOL(mmc_add_host); void mmc_stop_host(struct mmc_host *host)
/**
* mmc_remove_host - remove host hardware
* @host: mmc host
*
* Unregister and remove all cards associated with this host,
* and power down the MMC bus.
*/
void mmc_remove_host(struct mmc_host *host)
{ {
#ifdef CONFIG_MMC_DEBUG #ifdef CONFIG_MMC_DEBUG
unsigned long flags; unsigned long flags;
...@@ -648,24 +596,8 @@ void mmc_remove_host(struct mmc_host *host) ...@@ -648,24 +596,8 @@ void mmc_remove_host(struct mmc_host *host)
BUG_ON(host->card); BUG_ON(host->card);
mmc_power_off(host); mmc_power_off(host);
mmc_remove_host_sysfs(host);
} }
EXPORT_SYMBOL(mmc_remove_host);
/**
* mmc_free_host - free the host structure
* @host: mmc host
*
* Free the host once all references to it have been dropped.
*/
void mmc_free_host(struct mmc_host *host)
{
mmc_free_host_sysfs(host);
}
EXPORT_SYMBOL(mmc_free_host);
#ifdef CONFIG_PM #ifdef CONFIG_PM
/** /**
...@@ -726,4 +658,31 @@ EXPORT_SYMBOL(mmc_resume_host); ...@@ -726,4 +658,31 @@ EXPORT_SYMBOL(mmc_resume_host);
#endif #endif
static int __init mmc_init(void)
{
int ret;
workqueue = create_singlethread_workqueue("kmmcd");
if (!workqueue)
return -ENOMEM;
ret = mmc_register_bus();
if (ret == 0) {
ret = mmc_register_host_class();
if (ret)
mmc_unregister_bus();
}
return ret;
}
static void __exit mmc_exit(void)
{
mmc_unregister_host_class();
mmc_unregister_bus();
destroy_workqueue(workqueue);
}
module_init(mmc_init);
module_exit(mmc_exit);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
struct mmc_bus_ops { struct mmc_bus_ops {
void (*remove)(struct mmc_host *); void (*remove)(struct mmc_host *);
void (*detect)(struct mmc_host *); void (*detect)(struct mmc_host *);
int (*sysfs_add)(struct mmc_host *, struct mmc_card *card);
void (*sysfs_remove)(struct mmc_host *, struct mmc_card *card);
void (*suspend)(struct mmc_host *); void (*suspend)(struct mmc_host *);
void (*resume)(struct mmc_host *); void (*resume)(struct mmc_host *);
}; };
...@@ -54,8 +56,6 @@ void mmc_set_bus_width(struct mmc_host *host, unsigned int width); ...@@ -54,8 +56,6 @@ void mmc_set_bus_width(struct mmc_host *host, unsigned int width);
u32 mmc_select_voltage(struct mmc_host *host, u32 ocr); u32 mmc_select_voltage(struct mmc_host *host, u32 ocr);
void mmc_set_timing(struct mmc_host *host, unsigned int timing); 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) static inline void mmc_delay(unsigned int ms)
{ {
if (ms < 1000 / HZ) { if (ms < 1000 / HZ) {
...@@ -66,5 +66,9 @@ static inline void mmc_delay(unsigned int ms) ...@@ -66,5 +66,9 @@ static inline void mmc_delay(unsigned int ms)
} }
} }
void mmc_rescan(struct work_struct *work);
void mmc_start_host(struct mmc_host *host);
void mmc_stop_host(struct mmc_host *host);
#endif #endif
/*
* linux/drivers/mmc/core/host.c
*
* Copyright (C) 2003 Russell King, All Rights Reserved.
* Copyright (C) 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.
*
* MMC host class device management
*/
#include <linux/device.h>
#include <linux/err.h>
#include <linux/idr.h>
#include <linux/pagemap.h>
#include <linux/mmc/host.h>
#include "core.h"
#include "host.h"
#define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
static void mmc_host_classdev_release(struct device *dev)
{
struct mmc_host *host = cls_dev_to_mmc_host(dev);
kfree(host);
}
static struct class mmc_host_class = {
.name = "mmc_host",
.dev_release = mmc_host_classdev_release,
};
int mmc_register_host_class(void)
{
return class_register(&mmc_host_class);
}
void mmc_unregister_host_class(void)
{
class_unregister(&mmc_host_class);
}
static DEFINE_IDR(mmc_host_idr);
static DEFINE_SPINLOCK(mmc_host_lock);
/**
* mmc_alloc_host - initialise the per-host structure.
* @extra: sizeof private data structure
* @dev: pointer to host device model structure
*
* Initialise the per-host structure.
*/
struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
{
struct mmc_host *host;
host = kmalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
if (!host)
return NULL;
memset(host, 0, sizeof(struct mmc_host) + extra);
host->parent = dev;
host->class_dev.parent = dev;
host->class_dev.class = &mmc_host_class;
device_initialize(&host->class_dev);
spin_lock_init(&host->lock);
init_waitqueue_head(&host->wq);
INIT_DELAYED_WORK(&host->detect, mmc_rescan);
/*
* By default, hosts do not support SGIO or large requests.
* They have to set these according to their abilities.
*/
host->max_hw_segs = 1;
host->max_phys_segs = 1;
host->max_seg_size = PAGE_CACHE_SIZE;
host->max_req_size = PAGE_CACHE_SIZE;
host->max_blk_size = 512;
host->max_blk_count = PAGE_CACHE_SIZE / 512;
return host;
}
EXPORT_SYMBOL(mmc_alloc_host);
/**
* mmc_add_host - initialise host hardware
* @host: mmc host
*/
int mmc_add_host(struct mmc_host *host)
{
int err;
if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL))
return -ENOMEM;
spin_lock(&mmc_host_lock);
err = idr_get_new(&mmc_host_idr, host, &host->index);
spin_unlock(&mmc_host_lock);
if (err)
return err;
snprintf(host->class_dev.bus_id, BUS_ID_SIZE,
"mmc%d", host->index);
err = device_add(&host->class_dev);
if (err)
return err;
mmc_start_host(host);
return 0;
}
EXPORT_SYMBOL(mmc_add_host);
/**
* mmc_remove_host - remove host hardware
* @host: mmc host
*
* Unregister and remove all cards associated with this host,
* and power down the MMC bus.
*/
void mmc_remove_host(struct mmc_host *host)
{
mmc_stop_host(host);
device_del(&host->class_dev);
spin_lock(&mmc_host_lock);
idr_remove(&mmc_host_idr, host->index);
spin_unlock(&mmc_host_lock);
}
EXPORT_SYMBOL(mmc_remove_host);
/**
* mmc_free_host - free the host structure
* @host: mmc host
*
* Free the host once all references to it have been dropped.
*/
void mmc_free_host(struct mmc_host *host)
{
put_device(&host->class_dev);
}
EXPORT_SYMBOL(mmc_free_host);
/*
* linux/drivers/mmc/core/host.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_HOST_H
#define _MMC_CORE_HOST_H
int mmc_register_host_class(void);
void mmc_unregister_host_class(void);
#endif
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "core.h" #include "core.h"
#include "sysfs.h" #include "sysfs.h"
#include "bus.h"
#include "mmc_ops.h" #include "mmc_ops.h"
static const unsigned int tran_exp[] = { static const unsigned int tran_exp[] = {
...@@ -236,7 +237,7 @@ static int mmc_read_ext_csd(struct mmc_card *card) ...@@ -236,7 +237,7 @@ static int mmc_read_ext_csd(struct mmc_card *card)
* In the case of a resume, "curcard" will contain the card * In the case of a resume, "curcard" will contain the card
* we're trying to reinitialise. * we're trying to reinitialise.
*/ */
static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, static int mmc_init_card(struct mmc_host *host, u32 ocr,
struct mmc_card *oldcard) struct mmc_card *oldcard)
{ {
struct mmc_card *card; struct mmc_card *card;
...@@ -413,8 +414,7 @@ static void mmc_detect(struct mmc_host *host) ...@@ -413,8 +414,7 @@ static void mmc_detect(struct mmc_host *host)
mmc_release_host(host); mmc_release_host(host);
if (err != MMC_ERR_NONE) { if (err != MMC_ERR_NONE) {
mmc_remove_card(host->card); mmc_remove(host);
host->card = NULL;
mmc_claim_host(host); mmc_claim_host(host);
mmc_detach_bus(host); mmc_detach_bus(host);
...@@ -422,6 +422,53 @@ static void mmc_detect(struct mmc_host *host) ...@@ -422,6 +422,53 @@ static void mmc_detect(struct mmc_host *host)
} }
} }
MMC_ATTR_FN(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
card->raw_cid[2], card->raw_cid[3]);
MMC_ATTR_FN(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
card->raw_csd[2], card->raw_csd[3]);
MMC_ATTR_FN(date, "%02d/%04d\n", card->cid.month, card->cid.year);
MMC_ATTR_FN(fwrev, "0x%x\n", card->cid.fwrev);
MMC_ATTR_FN(hwrev, "0x%x\n", card->cid.hwrev);
MMC_ATTR_FN(manfid, "0x%06x\n", card->cid.manfid);
MMC_ATTR_FN(name, "%s\n", card->cid.prod_name);
MMC_ATTR_FN(oemid, "0x%04x\n", card->cid.oemid);
MMC_ATTR_FN(serial, "0x%08x\n", card->cid.serial);
static struct device_attribute mmc_dev_attrs[] = {
MMC_ATTR_RO(cid),
MMC_ATTR_RO(csd),
MMC_ATTR_RO(date),
MMC_ATTR_RO(fwrev),
MMC_ATTR_RO(hwrev),
MMC_ATTR_RO(manfid),
MMC_ATTR_RO(name),
MMC_ATTR_RO(oemid),
MMC_ATTR_RO(serial),
__ATTR_NULL,
};
/*
* Adds sysfs entries as relevant.
*/
static int mmc_sysfs_add(struct mmc_host *host, struct mmc_card *card)
{
int ret;
ret = mmc_add_attrs(card, mmc_dev_attrs);
if (ret < 0)
return ret;
return 0;
}
/*
* Removes the sysfs entries added by mmc_sysfs_add().
*/
static void mmc_sysfs_remove(struct mmc_host *host, struct mmc_card *card)
{
mmc_remove_attrs(card, mmc_dev_attrs);
}
#ifdef CONFIG_MMC_UNSAFE_RESUME #ifdef CONFIG_MMC_UNSAFE_RESUME
/* /*
...@@ -453,11 +500,9 @@ static void mmc_resume(struct mmc_host *host) ...@@ -453,11 +500,9 @@ static void mmc_resume(struct mmc_host *host)
mmc_claim_host(host); mmc_claim_host(host);
err = mmc_sd_init_card(host, host->ocr, host->card); err = mmc_init_card(host, host->ocr, host->card);
if (err != MMC_ERR_NONE) { if (err != MMC_ERR_NONE) {
mmc_remove_card(host->card); mmc_remove(host);
host->card = NULL;
mmc_detach_bus(host); mmc_detach_bus(host);
} }
...@@ -474,6 +519,8 @@ static void mmc_resume(struct mmc_host *host) ...@@ -474,6 +519,8 @@ static void mmc_resume(struct mmc_host *host)
static const struct mmc_bus_ops mmc_ops = { static const struct mmc_bus_ops mmc_ops = {
.remove = mmc_remove, .remove = mmc_remove,
.detect = mmc_detect, .detect = mmc_detect,
.sysfs_add = mmc_sysfs_add,
.sysfs_remove = mmc_sysfs_remove,
.suspend = mmc_suspend, .suspend = mmc_suspend,
.resume = mmc_resume, .resume = mmc_resume,
}; };
...@@ -512,13 +559,13 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr) ...@@ -512,13 +559,13 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr)
/* /*
* Detect and init the card. * Detect and init the card.
*/ */
err = mmc_sd_init_card(host, host->ocr, NULL); err = mmc_init_card(host, host->ocr, NULL);
if (err != MMC_ERR_NONE) if (err != MMC_ERR_NONE)
goto err; goto err;
mmc_release_host(host); mmc_release_host(host);
err = mmc_register_card(host->card); err = mmc_add_card(host->card);
if (err) if (err)
goto reclaim_host; goto reclaim_host;
......
...@@ -19,11 +19,10 @@ ...@@ -19,11 +19,10 @@
#include "core.h" #include "core.h"
#include "sysfs.h" #include "sysfs.h"
#include "bus.h"
#include "mmc_ops.h" #include "mmc_ops.h"
#include "sd_ops.h" #include "sd_ops.h"
#include "core.h"
static const unsigned int tran_exp[] = { static const unsigned int tran_exp[] = {
10000, 100000, 1000000, 10000000, 10000, 100000, 1000000, 10000000,
0, 0, 0, 0 0, 0, 0, 0
...@@ -487,8 +486,7 @@ static void mmc_sd_detect(struct mmc_host *host) ...@@ -487,8 +486,7 @@ static void mmc_sd_detect(struct mmc_host *host)
mmc_release_host(host); mmc_release_host(host);
if (err != MMC_ERR_NONE) { if (err != MMC_ERR_NONE) {
mmc_remove_card(host->card); mmc_sd_remove(host);
host->card = NULL;
mmc_claim_host(host); mmc_claim_host(host);
mmc_detach_bus(host); mmc_detach_bus(host);
...@@ -496,6 +494,55 @@ static void mmc_sd_detect(struct mmc_host *host) ...@@ -496,6 +494,55 @@ static void mmc_sd_detect(struct mmc_host *host)
} }
} }
MMC_ATTR_FN(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
card->raw_cid[2], card->raw_cid[3]);
MMC_ATTR_FN(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
card->raw_csd[2], card->raw_csd[3]);
MMC_ATTR_FN(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]);
MMC_ATTR_FN(date, "%02d/%04d\n", card->cid.month, card->cid.year);
MMC_ATTR_FN(fwrev, "0x%x\n", card->cid.fwrev);
MMC_ATTR_FN(hwrev, "0x%x\n", card->cid.hwrev);
MMC_ATTR_FN(manfid, "0x%06x\n", card->cid.manfid);
MMC_ATTR_FN(name, "%s\n", card->cid.prod_name);
MMC_ATTR_FN(oemid, "0x%04x\n", card->cid.oemid);
MMC_ATTR_FN(serial, "0x%08x\n", card->cid.serial);
static struct device_attribute mmc_sd_dev_attrs[] = {
MMC_ATTR_RO(cid),
MMC_ATTR_RO(csd),
MMC_ATTR_RO(scr),
MMC_ATTR_RO(date),
MMC_ATTR_RO(fwrev),
MMC_ATTR_RO(hwrev),
MMC_ATTR_RO(manfid),
MMC_ATTR_RO(name),
MMC_ATTR_RO(oemid),
MMC_ATTR_RO(serial),
__ATTR_NULL,
};
/*
* Adds sysfs entries as relevant.
*/
static int mmc_sd_sysfs_add(struct mmc_host *host, struct mmc_card *card)
{
int ret;
ret = mmc_add_attrs(card, mmc_sd_dev_attrs);
if (ret < 0)
return ret;
return 0;
}
/*
* Removes the sysfs entries added by mmc_sysfs_add().
*/
static void mmc_sd_sysfs_remove(struct mmc_host *host, struct mmc_card *card)
{
mmc_remove_attrs(card, mmc_sd_dev_attrs);
}
#ifdef CONFIG_MMC_UNSAFE_RESUME #ifdef CONFIG_MMC_UNSAFE_RESUME
/* /*
...@@ -529,9 +576,7 @@ static void mmc_sd_resume(struct mmc_host *host) ...@@ -529,9 +576,7 @@ static void mmc_sd_resume(struct mmc_host *host)
err = mmc_sd_init_card(host, host->ocr, host->card); err = mmc_sd_init_card(host, host->ocr, host->card);
if (err != MMC_ERR_NONE) { if (err != MMC_ERR_NONE) {
mmc_remove_card(host->card); mmc_sd_remove(host);
host->card = NULL;
mmc_detach_bus(host); mmc_detach_bus(host);
} }
...@@ -548,6 +593,8 @@ static void mmc_sd_resume(struct mmc_host *host) ...@@ -548,6 +593,8 @@ static void mmc_sd_resume(struct mmc_host *host)
static const struct mmc_bus_ops mmc_sd_ops = { static const struct mmc_bus_ops mmc_sd_ops = {
.remove = mmc_sd_remove, .remove = mmc_sd_remove,
.detect = mmc_sd_detect, .detect = mmc_sd_detect,
.sysfs_add = mmc_sd_sysfs_add,
.sysfs_remove = mmc_sd_sysfs_remove,
.suspend = mmc_sd_suspend, .suspend = mmc_sd_suspend,
.resume = mmc_sd_resume, .resume = mmc_sd_resume,
}; };
...@@ -599,7 +646,7 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr) ...@@ -599,7 +646,7 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)
mmc_release_host(host); mmc_release_host(host);
err = mmc_register_card(host->card); err = mmc_add_card(host->card);
if (err) if (err)
goto reclaim_host; goto reclaim_host;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* linux/drivers/mmc/core/sysfs.c * linux/drivers/mmc/core/sysfs.c
* *
* Copyright (C) 2003 Russell King, All Rights Reserved. * Copyright (C) 2003 Russell King, All Rights Reserved.
* Copyright 2007 Pierre Ossman
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License version 2 as
...@@ -9,352 +10,34 @@ ...@@ -9,352 +10,34 @@
* *
* MMC sysfs/driver model support. * MMC sysfs/driver model support.
*/ */
#include <linux/module.h>
#include <linux/init.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/idr.h>
#include <linux/workqueue.h>
#include <linux/mmc/card.h> #include <linux/mmc/card.h>
#include <linux/mmc/host.h>
#include "sysfs.h" #include "sysfs.h"
#define dev_to_mmc_card(d) container_of(d, struct mmc_card, dev) int mmc_add_attrs(struct mmc_card *card, struct device_attribute *attrs)
#define to_mmc_driver(d) container_of(d, struct mmc_driver, drv)
#define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
#define MMC_ATTR(name, fmt, args...) \
static ssize_t mmc_##name##_show (struct device *dev, struct device_attribute *attr, char *buf) \
{ \
struct mmc_card *card = dev_to_mmc_card(dev); \
return sprintf(buf, fmt, args); \
}
MMC_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
card->raw_cid[2], card->raw_cid[3]);
MMC_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
card->raw_csd[2], card->raw_csd[3]);
MMC_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]);
MMC_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
MMC_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
MMC_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
MMC_ATTR(manfid, "0x%06x\n", card->cid.manfid);
MMC_ATTR(name, "%s\n", card->cid.prod_name);
MMC_ATTR(oemid, "0x%04x\n", card->cid.oemid);
MMC_ATTR(serial, "0x%08x\n", card->cid.serial);
#define MMC_ATTR_RO(name) __ATTR(name, S_IRUGO, mmc_##name##_show, NULL)
static struct device_attribute mmc_dev_attrs[] = {
MMC_ATTR_RO(cid),
MMC_ATTR_RO(csd),
MMC_ATTR_RO(date),
MMC_ATTR_RO(fwrev),
MMC_ATTR_RO(hwrev),
MMC_ATTR_RO(manfid),
MMC_ATTR_RO(name),
MMC_ATTR_RO(oemid),
MMC_ATTR_RO(serial),
__ATTR_NULL
};
static struct device_attribute mmc_dev_attr_scr = MMC_ATTR_RO(scr);
static void mmc_release_card(struct device *dev)
{
struct mmc_card *card = dev_to_mmc_card(dev);
kfree(card);
}
/*
* This currently matches any MMC driver to any MMC card - drivers
* themselves make the decision whether to drive this card in their
* probe method.
*/
static int mmc_bus_match(struct device *dev, struct device_driver *drv)
{
return 1;
}
static int
mmc_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
int buf_size)
{
struct mmc_card *card = dev_to_mmc_card(dev);
char ccc[13];
int retval = 0, i = 0, length = 0;
#define add_env(fmt,val) do { \
retval = add_uevent_var(envp, num_envp, &i, \
buf, buf_size, &length, \
fmt, val); \
if (retval) \
return retval; \
} while (0);
for (i = 0; i < 12; i++)
ccc[i] = card->csd.cmdclass & (1 << i) ? '1' : '0';
ccc[12] = '\0';
add_env("MMC_CCC=%s", ccc);
add_env("MMC_MANFID=%06x", card->cid.manfid);
add_env("MMC_NAME=%s", mmc_card_name(card));
add_env("MMC_OEMID=%04x", card->cid.oemid);
#undef add_env
envp[i] = NULL;
return 0;
}
static int mmc_bus_suspend(struct device *dev, pm_message_t state)
{
struct mmc_driver *drv = to_mmc_driver(dev->driver);
struct mmc_card *card = dev_to_mmc_card(dev);
int ret = 0;
if (dev->driver && drv->suspend)
ret = drv->suspend(card, state);
return ret;
}
static int mmc_bus_resume(struct device *dev)
{
struct mmc_driver *drv = to_mmc_driver(dev->driver);
struct mmc_card *card = dev_to_mmc_card(dev);
int ret = 0;
if (dev->driver && drv->resume)
ret = drv->resume(card);
return ret;
}
static int mmc_bus_probe(struct device *dev)
{
struct mmc_driver *drv = to_mmc_driver(dev->driver);
struct mmc_card *card = dev_to_mmc_card(dev);
return drv->probe(card);
}
static int mmc_bus_remove(struct device *dev)
{
struct mmc_driver *drv = to_mmc_driver(dev->driver);
struct mmc_card *card = dev_to_mmc_card(dev);
drv->remove(card);
return 0;
}
static struct bus_type mmc_bus_type = {
.name = "mmc",
.dev_attrs = mmc_dev_attrs,
.match = mmc_bus_match,
.uevent = mmc_bus_uevent,
.probe = mmc_bus_probe,
.remove = mmc_bus_remove,
.suspend = mmc_bus_suspend,
.resume = mmc_bus_resume,
};
/**
* mmc_register_driver - register a media driver
* @drv: MMC media driver
*/
int mmc_register_driver(struct mmc_driver *drv)
{
drv->drv.bus = &mmc_bus_type;
return driver_register(&drv->drv);
}
EXPORT_SYMBOL(mmc_register_driver);
/**
* mmc_unregister_driver - unregister a media driver
* @drv: MMC media driver
*/
void mmc_unregister_driver(struct mmc_driver *drv)
{
drv->drv.bus = &mmc_bus_type;
driver_unregister(&drv->drv);
}
EXPORT_SYMBOL(mmc_unregister_driver);
/*
* Internal function. Initialise a MMC card structure.
*/
void mmc_init_card(struct mmc_card *card, struct mmc_host *host)
{
memset(card, 0, sizeof(struct mmc_card));
card->host = host;
device_initialize(&card->dev);
card->dev.parent = mmc_classdev(host);
card->dev.bus = &mmc_bus_type;
card->dev.release = mmc_release_card;
}
/*
* Internal function. Register a new MMC card with the driver model.
*/
int mmc_register_card(struct mmc_card *card)
{ {
int ret; int error = 0;
int i;
snprintf(card->dev.bus_id, sizeof(card->dev.bus_id), for (i = 0; attr_name(attrs[i]); i++) {
"%s:%04x", mmc_hostname(card->host), card->rca); error = device_create_file(&card->dev, &attrs[i]);
if (error) {
ret = device_add(&card->dev); while (--i >= 0)
if (ret == 0) { device_remove_file(&card->dev, &attrs[i]);
if (mmc_card_sd(card)) { break;
ret = device_create_file(&card->dev, &mmc_dev_attr_scr);
if (ret)
device_del(&card->dev);
} }
} }
if (ret == 0)
mmc_card_set_present(card);
return ret;
}
/*
* Internal function. Unregister a new MMC card with the
* driver model, and (eventually) free it.
*/
void mmc_remove_card(struct mmc_card *card)
{
if (mmc_card_present(card)) {
if (mmc_card_sd(card))
device_remove_file(&card->dev, &mmc_dev_attr_scr);
device_del(&card->dev);
}
put_device(&card->dev);
}
static void mmc_host_classdev_release(struct device *dev)
{
struct mmc_host *host = cls_dev_to_mmc_host(dev);
kfree(host);
}
static struct class mmc_host_class = {
.name = "mmc_host",
.dev_release = mmc_host_classdev_release,
};
static DEFINE_IDR(mmc_host_idr);
static DEFINE_SPINLOCK(mmc_host_lock);
/*
* Internal function. Allocate a new MMC host.
*/
struct mmc_host *mmc_alloc_host_sysfs(int extra, struct device *dev)
{
struct mmc_host *host;
host = kmalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
if (host) {
memset(host, 0, sizeof(struct mmc_host) + extra);
host->parent = dev;
host->class_dev.parent = dev;
host->class_dev.class = &mmc_host_class;
device_initialize(&host->class_dev);
}
return host; return error;
} }
/* void mmc_remove_attrs(struct mmc_card *card, struct device_attribute *attrs)
* Internal function. Register a new MMC host with the MMC class.
*/
int mmc_add_host_sysfs(struct mmc_host *host)
{ {
int err; int i;
if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL))
return -ENOMEM;
spin_lock(&mmc_host_lock);
err = idr_get_new(&mmc_host_idr, host, &host->index);
spin_unlock(&mmc_host_lock);
if (err)
return err;
snprintf(host->class_dev.bus_id, BUS_ID_SIZE,
"mmc%d", host->index);
return device_add(&host->class_dev);
}
/* for (i = 0; attr_name(attrs[i]); i++)
* Internal function. Unregister a MMC host with the MMC class. device_remove_file(&card->dev, &attrs[i]);
*/
void mmc_remove_host_sysfs(struct mmc_host *host)
{
device_del(&host->class_dev);
spin_lock(&mmc_host_lock);
idr_remove(&mmc_host_idr, host->index);
spin_unlock(&mmc_host_lock);
}
/*
* Internal function. Free a MMC host.
*/
void mmc_free_host_sysfs(struct mmc_host *host)
{
put_device(&host->class_dev);
}
static struct workqueue_struct *workqueue;
/*
* Internal function. Schedule delayed work in the MMC work queue.
*/
int mmc_schedule_delayed_work(struct delayed_work *work, unsigned long delay)
{
return queue_delayed_work(workqueue, work, delay);
}
/*
* Internal function. Flush all scheduled work from the MMC work queue.
*/
void mmc_flush_scheduled_work(void)
{
flush_workqueue(workqueue);
}
static int __init mmc_init(void)
{
int ret;
workqueue = create_singlethread_workqueue("kmmcd");
if (!workqueue)
return -ENOMEM;
ret = bus_register(&mmc_bus_type);
if (ret == 0) {
ret = class_register(&mmc_host_class);
if (ret)
bus_unregister(&mmc_bus_type);
}
return ret;
}
static void __exit mmc_exit(void)
{
class_unregister(&mmc_host_class);
bus_unregister(&mmc_bus_type);
destroy_workqueue(workqueue);
} }
module_init(mmc_init);
module_exit(mmc_exit);
...@@ -11,17 +11,16 @@ ...@@ -11,17 +11,16 @@
#ifndef _MMC_CORE_SYSFS_H #ifndef _MMC_CORE_SYSFS_H
#define _MMC_CORE_SYSFS_H #define _MMC_CORE_SYSFS_H
void mmc_init_card(struct mmc_card *card, struct mmc_host *host); #define MMC_ATTR_FN(name, fmt, args...) \
int mmc_register_card(struct mmc_card *card); static ssize_t mmc_##name##_show (struct device *dev, struct device_attribute *attr, char *buf) \
void mmc_remove_card(struct mmc_card *card); { \
struct mmc_card *card = container_of(dev, struct mmc_card, dev);\
return sprintf(buf, fmt, args); \
}
struct mmc_host *mmc_alloc_host_sysfs(int extra, struct device *dev); #define MMC_ATTR_RO(name) __ATTR(name, S_IRUGO, mmc_##name##_show, NULL)
int mmc_add_host_sysfs(struct mmc_host *host);
void mmc_remove_host_sysfs(struct mmc_host *host);
void mmc_free_host_sysfs(struct mmc_host *host);
int mmc_schedule_work(struct work_struct *work); int mmc_add_attrs(struct mmc_card *card, struct device_attribute *attrs);
int mmc_schedule_delayed_work(struct delayed_work *work, unsigned long delay); void mmc_remove_attrs(struct mmc_card *card, struct device_attribute *attrs);
void mmc_flush_scheduled_work(void);
#endif #endif
This diff is collapsed.
...@@ -70,6 +70,14 @@ static const struct pci_device_id pci_ids[] __devinitdata = { ...@@ -70,6 +70,14 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
.driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE, .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE,
}, },
{
.vendor = PCI_VENDOR_ID_ENE,
.device = PCI_DEVICE_ID_ENE_CB712_SD_2,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
.driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE,
},
{ /* Generic SD host controller */ { /* Generic SD host controller */
PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00) PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
}, },
...@@ -1022,7 +1030,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) ...@@ -1022,7 +1030,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
writel(SDHCI_INT_BUS_POWER, host->ioaddr + SDHCI_INT_STATUS); writel(SDHCI_INT_BUS_POWER, host->ioaddr + SDHCI_INT_STATUS);
} }
intmask &= SDHCI_INT_BUS_POWER; intmask &= ~SDHCI_INT_BUS_POWER;
if (intmask) { if (intmask) {
printk(KERN_ERR "%s: Unexpected interrupt 0x%08x.\n", printk(KERN_ERR "%s: Unexpected interrupt 0x%08x.\n",
......
...@@ -2000,6 +2000,7 @@ ...@@ -2000,6 +2000,7 @@
#define PCI_VENDOR_ID_ENE 0x1524 #define PCI_VENDOR_ID_ENE 0x1524
#define PCI_DEVICE_ID_ENE_CB712_SD 0x0550 #define PCI_DEVICE_ID_ENE_CB712_SD 0x0550
#define PCI_DEVICE_ID_ENE_CB712_SD_2 0x0551
#define PCI_DEVICE_ID_ENE_1211 0x1211 #define PCI_DEVICE_ID_ENE_1211 0x1211
#define PCI_DEVICE_ID_ENE_1225 0x1225 #define PCI_DEVICE_ID_ENE_1225 0x1225
#define PCI_DEVICE_ID_ENE_1410 0x1410 #define PCI_DEVICE_ID_ENE_1410 0x1410
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment