Commit baf8532a authored by Alex Dubov's avatar Alex Dubov Committed by Linus Torvalds

memstick: initial commit for Sony MemoryStick support

Sony MemoryStick cards are used in many products manufactured by Sony.
They are available both as storage and as IO expansion cards.  Currently,
only MemoryStick Pro storage cards are supported via TI FlashMedia
MemoryStick interface.

[mboton@gmail.com: biuld fix]
[akpm@linux-foundation.org: build fix]
Signed-off-by: default avatarAlex Dubov <oakad@yahoo.com>
Signed-off-by: default avatarMiguel Boton <mboton@gmail.co>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 941edd03
......@@ -3627,6 +3627,13 @@ L: linux-acpi@vger.kernel.org
W: http://www.linux.it/~malattia/wiki/index.php/Sony_drivers
S: Maintained
SONY MEMORYSTICK CARD SUPPORT
P: Alex Dubov
M: oakad@yahoo.com
L: linux-kernel@vger.kernel.org
W: http://tifmxx.berlios.de/
S: Maintained
SOUND
P: Jaroslav Kysela
M: perex@perex.cz
......
......@@ -80,6 +80,8 @@ source "drivers/usb/Kconfig"
source "drivers/mmc/Kconfig"
source "drivers/memstick/Kconfig"
source "drivers/leds/Kconfig"
source "drivers/infiniband/Kconfig"
......
......@@ -78,6 +78,7 @@ obj-y += lguest/
obj-$(CONFIG_CPU_FREQ) += cpufreq/
obj-$(CONFIG_CPU_IDLE) += cpuidle/
obj-$(CONFIG_MMC) += mmc/
obj-$(CONFIG_MEMSTICK) += memstick/
obj-$(CONFIG_NEW_LEDS) += leds/
obj-$(CONFIG_INFINIBAND) += infiniband/
obj-$(CONFIG_SGI_SN) += sn/
......
#
# MemoryStick subsystem configuration
#
menuconfig MEMSTICK
tristate "Sony MemoryStick card support (EXPERIMENTAL)"
help
Sony MemoryStick is a proprietary storage/extension card protocol.
If you want MemoryStick support, you should say Y here and also
to the specific driver for your MMC interface.
if MEMSTICK
config MEMSTICK_DEBUG
bool "MemoryStick debugging"
help
This is an option for use by developers; most people should
say N here. This enables MemoryStick core and driver debugging.
source "drivers/memstick/core/Kconfig"
source "drivers/memstick/host/Kconfig"
endif # MEMSTICK
#
# Makefile for the kernel MemoryStick device drivers.
#
ifeq ($(CONFIG_MEMSTICK_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG
endif
obj-$(CONFIG_MEMSTICK) += core/
obj-$(CONFIG_MEMSTICK) += host/
#
# MemoryStick core configuration
#
comment "MemoryStick drivers"
config MEMSTICK_UNSAFE_RESUME
bool "Allow unsafe resume (DANGEROUS)"
help
If you say Y here, the MemoryStick 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 MemoryStick card for rootfs. Most people should say N here.
config MSPRO_BLOCK
tristate "MemoryStick Pro block device driver"
depends on BLOCK
help
Say Y here to enable the MemoryStick Pro block device driver
support. This provides a block device driver, which you can use
to mount the filesystem. Almost everyone wishing MemoryStick
support should say Y or M here.
#
# Makefile for the kernel MemoryStick core.
#
ifeq ($(CONFIG_MEMSTICK_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG
endif
obj-$(CONFIG_MEMSTICK) += memstick.o
obj-$(CONFIG_MSPRO_BLOCK) += mspro_block.o
This diff is collapsed.
This diff is collapsed.
#
# MemoryStick host controller drivers
#
comment "MemoryStick Host Controller Drivers"
config MEMSTICK_TIFM_MS
tristate "TI Flash Media MemoryStick Interface support (EXPERIMENTAL)"
depends on EXPERIMENTAL && PCI
select TIFM_CORE
help
Say Y here if you want to be able to access MemoryStick 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_ms.
#
# Makefile for MemoryStick host controller drivers
#
ifeq ($(CONFIG_MEMSTICK_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG
endif
obj-$(CONFIG_MEMSTICK_TIFM_MS) += tifm_ms.o
This diff is collapsed.
......@@ -302,6 +302,21 @@ static int tifm_7xx1_resume(struct pci_dev *dev)
#endif /* CONFIG_PM */
static int tifm_7xx1_dummy_has_ms_pif(struct tifm_adapter *fm,
struct tifm_dev *sock)
{
return 0;
}
static int tifm_7xx1_has_ms_pif(struct tifm_adapter *fm, struct tifm_dev *sock)
{
if (((fm->num_sockets == 4) && (sock->socket_id == 2))
|| ((fm->num_sockets == 2) && (sock->socket_id == 0)))
return 1;
return 0;
}
static int tifm_7xx1_probe(struct pci_dev *dev,
const struct pci_device_id *dev_id)
{
......@@ -336,6 +351,7 @@ static int tifm_7xx1_probe(struct pci_dev *dev,
INIT_WORK(&fm->media_switcher, tifm_7xx1_switch_media);
fm->eject = tifm_7xx1_eject;
fm->has_ms_pif = tifm_7xx1_has_ms_pif;
pci_set_drvdata(dev, fm);
fm->addr = ioremap(pci_resource_start(dev, 0),
......@@ -377,6 +393,7 @@ static void tifm_7xx1_remove(struct pci_dev *dev)
int cnt;
fm->eject = tifm_7xx1_dummy_eject;
fm->has_ms_pif = tifm_7xx1_dummy_has_ms_pif;
writel(TIFM_IRQ_SETALL, fm->addr + FM_CLEAR_INTERRUPT_ENABLE);
mmiowb();
free_irq(dev->irq, fm);
......
......@@ -284,6 +284,13 @@ void tifm_eject(struct tifm_dev *sock)
}
EXPORT_SYMBOL(tifm_eject);
int tifm_has_ms_pif(struct tifm_dev *sock)
{
struct tifm_adapter *fm = dev_get_drvdata(sock->dev.parent);
return fm->has_ms_pif(fm, sock);
}
EXPORT_SYMBOL(tifm_has_ms_pif);
int tifm_map_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents,
int direction)
{
......
/*
* Sony MemoryStick support
*
* Copyright (C) 2007 Alex Dubov <oakad@yahoo.com>
*
* 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 _MEMSTICK_H
#define _MEMSTICK_H
#include <linux/workqueue.h>
#include <linux/scatterlist.h>
#include <linux/device.h>
/*** Hardware based structures ***/
struct ms_status_register {
unsigned char reserved;
unsigned char interrupt;
#define MEMSTICK_INT_CMDNAK 0x0001
#define MEMSTICK_INT_BREQ 0x0020
#define MEMSTICK_INT_ERR 0x0040
#define MEMSTICK_INT_CED 0x0080
unsigned char status0;
#define MEMSTICK_STATUS0_WP 0x0001
#define MEMSTICK_STATUS0_SL 0x0002
#define MEMSTICK_STATUS0_BF 0x0010
#define MEMSTICK_STATUS0_BE 0x0020
#define MEMSTICK_STATUS0_FB0 0x0040
#define MEMSTICK_STATUS0_MB 0x0080
unsigned char status1;
#define MEMSTICK_STATUS1_UCFG 0x0001
#define MEMSTICK_STATUS1_FGER 0x0002
#define MEMSTICK_STATUS1_UCEX 0x0004
#define MEMSTICK_STATUS1_EXER 0x0008
#define MEMSTICK_STATUS1_UCDT 0x0010
#define MEMSTICK_STATUS1_DTER 0x0020
#define MEMSTICK_STATUS1_FBI 0x0040
#define MEMSTICK_STATUS1_MB 0x0080
} __attribute__((packed));
struct ms_id_register {
unsigned char type;
unsigned char reserved;
unsigned char category;
unsigned char class;
} __attribute__((packed));
struct ms_param_register {
unsigned char system;
unsigned char block_address_msb;
unsigned short block_address;
unsigned char cp;
#define MEMSTICK_CP_BLOCK 0x0000
#define MEMSTICK_CP_PAGE 0x0020
#define MEMSTICK_CP_EXTRA 0x0040
#define MEMSTICK_CP_OVERWRITE 0x0080
unsigned char page_address;
} __attribute__((packed));
struct ms_extra_data_register {
unsigned char overwrite_flag;
#define MEMSTICK_OVERWRITE_UPDATA 0x0010
#define MEMSTICK_OVERWRITE_PAGE 0x0060
#define MEMSTICK_OVERWRITE_BLOCK 0x0080
unsigned char management_flag;
#define MEMSTICK_MANAGEMENT_SYSTEM 0x0004
#define MEMSTICK_MANAGEMENT_TRANS_TABLE 0x0008
#define MEMSTICK_MANAGEMENT_COPY 0x0010
#define MEMSTICK_MANAGEMENT_ACCESS 0x0020
unsigned short logical_address;
} __attribute__((packed));
struct ms_register {
struct ms_status_register status;
struct ms_id_register id;
unsigned char reserved[8];
struct ms_param_register param;
struct ms_extra_data_register extra_data;
} __attribute__((packed));
struct mspro_param_register {
unsigned char system;
unsigned short data_count;
unsigned int data_address;
unsigned char cmd_param;
} __attribute__((packed));
struct mspro_register {
struct ms_status_register status;
struct ms_id_register id;
unsigned char reserved[8];
struct mspro_param_register param;
} __attribute__((packed));
struct ms_register_addr {
unsigned char r_offset;
unsigned char r_length;
unsigned char w_offset;
unsigned char w_length;
} __attribute__((packed));
enum {
MS_TPC_READ_LONG_DATA = 0x02,
MS_TPC_READ_SHORT_DATA = 0x03,
MS_TPC_READ_REG = 0x04,
MS_TPC_READ_IO_DATA = 0x05, /* unverified */
MS_TPC_GET_INT = 0x07,
MS_TPC_SET_RW_REG_ADRS = 0x08,
MS_TPC_EX_SET_CMD = 0x09,
MS_TPC_WRITE_IO_DATA = 0x0a, /* unverified */
MS_TPC_WRITE_REG = 0x0b,
MS_TPC_WRITE_SHORT_DATA = 0x0c,
MS_TPC_WRITE_LONG_DATA = 0x0d,
MS_TPC_SET_CMD = 0x0e
};
enum {
MS_CMD_BLOCK_END = 0x33,
MS_CMD_RESET = 0x3c,
MS_CMD_BLOCK_WRITE = 0x55,
MS_CMD_SLEEP = 0x5a,
MS_CMD_BLOCK_ERASE = 0x99,
MS_CMD_BLOCK_READ = 0xaa,
MS_CMD_CLEAR_BUF = 0xc3,
MS_CMD_FLASH_STOP = 0xcc,
MSPRO_CMD_FORMAT = 0x10,
MSPRO_CMD_SLEEP = 0x11,
MSPRO_CMD_READ_DATA = 0x20,
MSPRO_CMD_WRITE_DATA = 0x21,
MSPRO_CMD_READ_ATRB = 0x24,
MSPRO_CMD_STOP = 0x25,
MSPRO_CMD_ERASE = 0x26,
MSPRO_CMD_SET_IBA = 0x46,
MSPRO_CMD_SET_IBD = 0x47
/*
MSPRO_CMD_RESET
MSPRO_CMD_WAKEUP
MSPRO_CMD_IN_IO_DATA
MSPRO_CMD_OUT_IO_DATA
MSPRO_CMD_READ_IO_ATRB
MSPRO_CMD_IN_IO_FIFO
MSPRO_CMD_OUT_IO_FIFO
MSPRO_CMD_IN_IOM
MSPRO_CMD_OUT_IOM
*/
};
/*** Driver structures and functions ***/
#define MEMSTICK_PART_SHIFT 3
enum memstick_param { MEMSTICK_POWER = 1, MEMSTICK_INTERFACE };
#define MEMSTICK_POWER_OFF 0
#define MEMSTICK_POWER_ON 1
#define MEMSTICK_SERIAL 0
#define MEMSTICK_PARALLEL 1
struct memstick_host;
struct memstick_driver;
#define MEMSTICK_MATCH_ALL 0x01
#define MEMSTICK_TYPE_LEGACY 0xff
#define MEMSTICK_TYPE_DUO 0x00
#define MEMSTICK_TYPE_PRO 0x01
#define MEMSTICK_CATEGORY_STORAGE 0xff
#define MEMSTICK_CATEGORY_STORAGE_DUO 0x00
#define MEMSTICK_CLASS_GENERIC 0xff
#define MEMSTICK_CLASS_GENERIC_DUO 0x00
struct memstick_device_id {
unsigned char match_flags;
unsigned char type;
unsigned char category;
unsigned char class;
};
struct memstick_request {
unsigned char tpc;
unsigned char data_dir:1,
need_card_int:1,
get_int_reg:1,
io_type:2;
#define MEMSTICK_IO_NONE 0
#define MEMSTICK_IO_VAL 1
#define MEMSTICK_IO_SG 2
unsigned char int_reg;
int error;
union {
struct scatterlist sg;
struct {
unsigned char data_len;
unsigned char data[15];
};
};
};
struct memstick_dev {
struct memstick_device_id id;
struct memstick_host *host;
struct ms_register_addr reg_addr;
struct completion mrq_complete;
struct memstick_request current_mrq;
/* Check that media driver is still willing to operate the device. */
int (*check)(struct memstick_dev *card);
/* Get next request from the media driver. */
int (*next_request)(struct memstick_dev *card,
struct memstick_request **mrq);
struct device dev;
};
struct memstick_host {
struct mutex lock;
unsigned int id;
unsigned int caps;
#define MEMSTICK_CAP_PARALLEL 1
#define MEMSTICK_CAP_AUTO_GET_INT 2
struct work_struct media_checker;
struct class_device cdev;
struct memstick_dev *card;
unsigned int retries;
/* Notify the host that some requests are pending. */
void (*request)(struct memstick_host *host);
/* Set host IO parameters (power, clock, etc). */
void (*set_param)(struct memstick_host *host,
enum memstick_param param,
int value);
unsigned long private[0] ____cacheline_aligned;
};
struct memstick_driver {
struct memstick_device_id *id_table;
int (*probe)(struct memstick_dev *card);
void (*remove)(struct memstick_dev *card);
int (*suspend)(struct memstick_dev *card,
pm_message_t state);
int (*resume)(struct memstick_dev *card);
struct device_driver driver;
};
int memstick_register_driver(struct memstick_driver *drv);
void memstick_unregister_driver(struct memstick_driver *drv);
struct memstick_host *memstick_alloc_host(unsigned int extra,
struct device *dev);
int memstick_add_host(struct memstick_host *host);
void memstick_remove_host(struct memstick_host *host);
void memstick_free_host(struct memstick_host *host);
void memstick_detect_change(struct memstick_host *host);
void memstick_init_req_sg(struct memstick_request *mrq, unsigned char tpc,
struct scatterlist *sg);
void memstick_init_req(struct memstick_request *mrq, unsigned char tpc,
void *buf, size_t length);
int memstick_next_req(struct memstick_host *host,
struct memstick_request **mrq);
void memstick_new_req(struct memstick_host *host);
int memstick_set_rw_addr(struct memstick_dev *card);
static inline void *memstick_priv(struct memstick_host *host)
{
return (void *)host->private;
}
static inline void *memstick_get_drvdata(struct memstick_dev *card)
{
return dev_get_drvdata(&card->dev);
}
static inline void memstick_set_drvdata(struct memstick_dev *card, void *data)
{
dev_set_drvdata(&card->dev, data);
}
#endif
......@@ -72,6 +72,7 @@ enum {
#define TIFM_FIFO_READY 0x00000001
#define TIFM_FIFO_INT_SETALL 0x0000ffff
#define TIFM_FIFO_INTMASK 0x00000005
#define TIFM_FIFO_SIZE 0x00000200
#define TIFM_DMA_RESET 0x00000002
#define TIFM_DMA_TX 0x00008000
......@@ -124,6 +125,8 @@ struct tifm_adapter {
void (*eject)(struct tifm_adapter *fm,
struct tifm_dev *sock);
int (*has_ms_pif)(struct tifm_adapter *fm,
struct tifm_dev *sock);
struct tifm_dev *sockets[0];
};
......@@ -141,6 +144,7 @@ struct tifm_dev *tifm_alloc_device(struct tifm_adapter *fm, unsigned int id,
int tifm_register_driver(struct tifm_driver *drv);
void tifm_unregister_driver(struct tifm_driver *drv);
void tifm_eject(struct tifm_dev *sock);
int tifm_has_ms_pif(struct tifm_dev *sock);
int tifm_map_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents,
int direction);
void tifm_unmap_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents,
......
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