diff options
Diffstat (limited to 'drivers')
30 files changed, 3083 insertions, 86 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig index b86877bdc7ac..3a0e3549739f 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig | |||
@@ -80,6 +80,8 @@ source "drivers/usb/Kconfig" | |||
80 | 80 | ||
81 | source "drivers/mmc/Kconfig" | 81 | source "drivers/mmc/Kconfig" |
82 | 82 | ||
83 | source "drivers/memstick/Kconfig" | ||
84 | |||
83 | source "drivers/leds/Kconfig" | 85 | source "drivers/leds/Kconfig" |
84 | 86 | ||
85 | source "drivers/infiniband/Kconfig" | 87 | source "drivers/infiniband/Kconfig" |
diff --git a/drivers/Makefile b/drivers/Makefile index 30ba97ec5eb5..e5e394a7e6c0 100644 --- a/drivers/Makefile +++ b/drivers/Makefile | |||
@@ -78,6 +78,7 @@ obj-y += lguest/ | |||
78 | obj-$(CONFIG_CPU_FREQ) += cpufreq/ | 78 | obj-$(CONFIG_CPU_FREQ) += cpufreq/ |
79 | obj-$(CONFIG_CPU_IDLE) += cpuidle/ | 79 | obj-$(CONFIG_CPU_IDLE) += cpuidle/ |
80 | obj-$(CONFIG_MMC) += mmc/ | 80 | obj-$(CONFIG_MMC) += mmc/ |
81 | obj-$(CONFIG_MEMSTICK) += memstick/ | ||
81 | obj-$(CONFIG_NEW_LEDS) += leds/ | 82 | obj-$(CONFIG_NEW_LEDS) += leds/ |
82 | obj-$(CONFIG_INFINIBAND) += infiniband/ | 83 | obj-$(CONFIG_INFINIBAND) += infiniband/ |
83 | obj-$(CONFIG_SGI_SN) += sn/ | 84 | obj-$(CONFIG_SGI_SN) += sn/ |
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index f29812a86533..40b0fcae4c78 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile | |||
@@ -60,5 +60,5 @@ obj-$(CONFIG_ACPI_ASUS) += asus_acpi.o | |||
60 | obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o | 60 | obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o |
61 | obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o | 61 | obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o |
62 | obj-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o | 62 | obj-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o |
63 | obj-$(CONFIG_ACPI_SBS) += sbs.o | ||
64 | obj-$(CONFIG_ACPI_SBS) += sbshc.o | 63 | obj-$(CONFIG_ACPI_SBS) += sbshc.o |
64 | obj-$(CONFIG_ACPI_SBS) += sbs.o | ||
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c index 1194105cc3ca..585ae3c9c8ea 100644 --- a/drivers/acpi/sbs.c +++ b/drivers/acpi/sbs.c | |||
@@ -827,7 +827,7 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id) | |||
827 | #endif | 827 | #endif |
828 | printk(KERN_INFO PREFIX "%s [%s]: Battery Slot [%s] (battery %s)\n", | 828 | printk(KERN_INFO PREFIX "%s [%s]: Battery Slot [%s] (battery %s)\n", |
829 | ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), | 829 | ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), |
830 | battery->name, sbs->battery->present ? "present" : "absent"); | 830 | battery->name, battery->present ? "present" : "absent"); |
831 | return result; | 831 | return result; |
832 | } | 832 | } |
833 | 833 | ||
diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c index ae9a90438e2f..a2cf3008ce6c 100644 --- a/drivers/acpi/sbshc.c +++ b/drivers/acpi/sbshc.c | |||
@@ -117,6 +117,11 @@ static int acpi_smbus_transaction(struct acpi_smb_hc *hc, u8 protocol, | |||
117 | int ret = -EFAULT, i; | 117 | int ret = -EFAULT, i; |
118 | u8 temp, sz = 0; | 118 | u8 temp, sz = 0; |
119 | 119 | ||
120 | if (!hc) { | ||
121 | printk(KERN_ERR PREFIX "host controller is not configured\n"); | ||
122 | return ret; | ||
123 | } | ||
124 | |||
120 | mutex_lock(&hc->lock); | 125 | mutex_lock(&hc->lock); |
121 | if (smb_hc_read(hc, ACPI_SMB_PROTOCOL, &temp)) | 126 | if (smb_hc_read(hc, ACPI_SMB_PROTOCOL, &temp)) |
122 | goto end; | 127 | goto end; |
@@ -292,6 +297,7 @@ static int acpi_smbus_hc_remove(struct acpi_device *device, int type) | |||
292 | hc = acpi_driver_data(device); | 297 | hc = acpi_driver_data(device); |
293 | acpi_ec_remove_query_handler(hc->ec, hc->query_bit); | 298 | acpi_ec_remove_query_handler(hc->ec, hc->query_bit); |
294 | kfree(hc); | 299 | kfree(hc); |
300 | acpi_driver_data(device) = NULL; | ||
295 | return 0; | 301 | return 0; |
296 | } | 302 | } |
297 | 303 | ||
diff --git a/drivers/block/ub.c b/drivers/block/ub.c index a70c1c29a7aa..c452e2d355ee 100644 --- a/drivers/block/ub.c +++ b/drivers/block/ub.c | |||
@@ -657,7 +657,6 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq) | |||
657 | if ((cmd = ub_get_cmd(lun)) == NULL) | 657 | if ((cmd = ub_get_cmd(lun)) == NULL) |
658 | return -1; | 658 | return -1; |
659 | memset(cmd, 0, sizeof(struct ub_scsi_cmd)); | 659 | memset(cmd, 0, sizeof(struct ub_scsi_cmd)); |
660 | sg_init_table(cmd->sgv, UB_MAX_REQ_SG); | ||
661 | 660 | ||
662 | blkdev_dequeue_request(rq); | 661 | blkdev_dequeue_request(rq); |
663 | 662 | ||
@@ -668,6 +667,7 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq) | |||
668 | /* | 667 | /* |
669 | * get scatterlist from block layer | 668 | * get scatterlist from block layer |
670 | */ | 669 | */ |
670 | sg_init_table(&urq->sgv[0], UB_MAX_REQ_SG); | ||
671 | n_elem = blk_rq_map_sg(lun->disk->queue, rq, &urq->sgv[0]); | 671 | n_elem = blk_rq_map_sg(lun->disk->queue, rq, &urq->sgv[0]); |
672 | if (n_elem < 0) { | 672 | if (n_elem < 0) { |
673 | /* Impossible, because blk_rq_map_sg should not hit ENOMEM. */ | 673 | /* Impossible, because blk_rq_map_sg should not hit ENOMEM. */ |
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index f01ac9a07bf5..47c6be84fc84 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig | |||
@@ -875,7 +875,7 @@ config SONYPI | |||
875 | Device which can be found in many (all ?) Sony Vaio laptops. | 875 | Device which can be found in many (all ?) Sony Vaio laptops. |
876 | 876 | ||
877 | If you have one of those laptops, read | 877 | If you have one of those laptops, read |
878 | <file:Documentation/sonypi.txt>, and say Y or M here. | 878 | <file:Documentation/laptops/sonypi.txt>, and say Y or M here. |
879 | 879 | ||
880 | To compile this driver as a module, choose M here: the | 880 | To compile this driver as a module, choose M here: the |
881 | module will be called sonypi. | 881 | module will be called sonypi. |
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 2c4b2d47973e..60f71e6345e3 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c | |||
@@ -27,6 +27,17 @@ static void (*pm_idle_old)(void); | |||
27 | 27 | ||
28 | static int enabled_devices; | 28 | static int enabled_devices; |
29 | 29 | ||
30 | #if defined(CONFIG_ARCH_HAS_CPU_IDLE_WAIT) | ||
31 | static void cpuidle_kick_cpus(void) | ||
32 | { | ||
33 | cpu_idle_wait(); | ||
34 | } | ||
35 | #elif defined(CONFIG_SMP) | ||
36 | # error "Arch needs cpu_idle_wait() equivalent here" | ||
37 | #else /* !CONFIG_ARCH_HAS_CPU_IDLE_WAIT && !CONFIG_SMP */ | ||
38 | static void cpuidle_kick_cpus(void) {} | ||
39 | #endif | ||
40 | |||
30 | /** | 41 | /** |
31 | * cpuidle_idle_call - the main idle loop | 42 | * cpuidle_idle_call - the main idle loop |
32 | * | 43 | * |
@@ -83,7 +94,7 @@ void cpuidle_uninstall_idle_handler(void) | |||
83 | { | 94 | { |
84 | if (enabled_devices && (pm_idle != pm_idle_old)) { | 95 | if (enabled_devices && (pm_idle != pm_idle_old)) { |
85 | pm_idle = pm_idle_old; | 96 | pm_idle = pm_idle_old; |
86 | cpu_idle_wait(); | 97 | cpuidle_kick_cpus(); |
87 | } | 98 | } |
88 | } | 99 | } |
89 | 100 | ||
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig index ab8fb257528e..043c34ad0a05 100644 --- a/drivers/ide/Kconfig +++ b/drivers/ide/Kconfig | |||
@@ -4,10 +4,14 @@ | |||
4 | # Andre Hedrick <andre@linux-ide.org> | 4 | # Andre Hedrick <andre@linux-ide.org> |
5 | # | 5 | # |
6 | 6 | ||
7 | # Select HAVE_IDE if IDE is supported | ||
8 | config HAVE_IDE | ||
9 | def_bool n | ||
10 | |||
7 | menuconfig IDE | 11 | menuconfig IDE |
8 | tristate "ATA/ATAPI/MFM/RLL support" | 12 | tristate "ATA/ATAPI/MFM/RLL support" |
13 | depends on HAVE_IDE | ||
9 | depends on BLOCK | 14 | depends on BLOCK |
10 | depends on HAS_IOMEM | ||
11 | ---help--- | 15 | ---help--- |
12 | If you say Y here, your kernel will be able to manage low cost mass | 16 | If you say Y here, your kernel will be able to manage low cost mass |
13 | storage units such as ATA/(E)IDE and ATAPI units. The most common | 17 | storage units such as ATA/(E)IDE and ATAPI units. The most common |
diff --git a/drivers/memstick/Kconfig b/drivers/memstick/Kconfig new file mode 100644 index 000000000000..1093fdb07297 --- /dev/null +++ b/drivers/memstick/Kconfig | |||
@@ -0,0 +1,26 @@ | |||
1 | # | ||
2 | # MemoryStick subsystem configuration | ||
3 | # | ||
4 | |||
5 | menuconfig MEMSTICK | ||
6 | tristate "Sony MemoryStick card support (EXPERIMENTAL)" | ||
7 | help | ||
8 | Sony MemoryStick is a proprietary storage/extension card protocol. | ||
9 | |||
10 | If you want MemoryStick support, you should say Y here and also | ||
11 | to the specific driver for your MMC interface. | ||
12 | |||
13 | if MEMSTICK | ||
14 | |||
15 | config MEMSTICK_DEBUG | ||
16 | bool "MemoryStick debugging" | ||
17 | help | ||
18 | This is an option for use by developers; most people should | ||
19 | say N here. This enables MemoryStick core and driver debugging. | ||
20 | |||
21 | |||
22 | source "drivers/memstick/core/Kconfig" | ||
23 | |||
24 | source "drivers/memstick/host/Kconfig" | ||
25 | |||
26 | endif # MEMSTICK | ||
diff --git a/drivers/memstick/Makefile b/drivers/memstick/Makefile new file mode 100644 index 000000000000..dc160fb43515 --- /dev/null +++ b/drivers/memstick/Makefile | |||
@@ -0,0 +1,11 @@ | |||
1 | # | ||
2 | # Makefile for the kernel MemoryStick device drivers. | ||
3 | # | ||
4 | |||
5 | ifeq ($(CONFIG_MEMSTICK_DEBUG),y) | ||
6 | EXTRA_CFLAGS += -DDEBUG | ||
7 | endif | ||
8 | |||
9 | obj-$(CONFIG_MEMSTICK) += core/ | ||
10 | obj-$(CONFIG_MEMSTICK) += host/ | ||
11 | |||
diff --git a/drivers/memstick/core/Kconfig b/drivers/memstick/core/Kconfig new file mode 100644 index 000000000000..95f1814b5368 --- /dev/null +++ b/drivers/memstick/core/Kconfig | |||
@@ -0,0 +1,26 @@ | |||
1 | # | ||
2 | # MemoryStick core configuration | ||
3 | # | ||
4 | |||
5 | comment "MemoryStick drivers" | ||
6 | |||
7 | config MEMSTICK_UNSAFE_RESUME | ||
8 | bool "Allow unsafe resume (DANGEROUS)" | ||
9 | help | ||
10 | If you say Y here, the MemoryStick layer will assume that all | ||
11 | cards stayed in their respective slots during the suspend. The | ||
12 | normal behaviour is to remove them at suspend and | ||
13 | redetecting them at resume. Breaking this assumption will | ||
14 | in most cases result in data corruption. | ||
15 | |||
16 | This option is usually just for embedded systems which use | ||
17 | a MemoryStick card for rootfs. Most people should say N here. | ||
18 | |||
19 | config MSPRO_BLOCK | ||
20 | tristate "MemoryStick Pro block device driver" | ||
21 | depends on BLOCK | ||
22 | help | ||
23 | Say Y here to enable the MemoryStick Pro block device driver | ||
24 | support. This provides a block device driver, which you can use | ||
25 | to mount the filesystem. Almost everyone wishing MemoryStick | ||
26 | support should say Y or M here. | ||
diff --git a/drivers/memstick/core/Makefile b/drivers/memstick/core/Makefile new file mode 100644 index 000000000000..8b2b5293877e --- /dev/null +++ b/drivers/memstick/core/Makefile | |||
@@ -0,0 +1,11 @@ | |||
1 | # | ||
2 | # Makefile for the kernel MemoryStick core. | ||
3 | # | ||
4 | |||
5 | ifeq ($(CONFIG_MEMSTICK_DEBUG),y) | ||
6 | EXTRA_CFLAGS += -DDEBUG | ||
7 | endif | ||
8 | |||
9 | obj-$(CONFIG_MEMSTICK) += memstick.o | ||
10 | |||
11 | obj-$(CONFIG_MSPRO_BLOCK) += mspro_block.o | ||
diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c new file mode 100644 index 000000000000..bba467fe4bce --- /dev/null +++ b/drivers/memstick/core/memstick.c | |||
@@ -0,0 +1,614 @@ | |||
1 | /* | ||
2 | * Sony MemoryStick support | ||
3 | * | ||
4 | * Copyright (C) 2007 Alex Dubov <oakad@yahoo.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * Special thanks to Carlos Corbacho for providing various MemoryStick cards | ||
11 | * that made this driver possible. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/memstick.h> | ||
16 | #include <linux/idr.h> | ||
17 | #include <linux/fs.h> | ||
18 | #include <linux/delay.h> | ||
19 | |||
20 | #define DRIVER_NAME "memstick" | ||
21 | #define DRIVER_VERSION "0.2" | ||
22 | |||
23 | static unsigned int cmd_retries = 3; | ||
24 | module_param(cmd_retries, uint, 0644); | ||
25 | |||
26 | static struct workqueue_struct *workqueue; | ||
27 | static DEFINE_IDR(memstick_host_idr); | ||
28 | static DEFINE_SPINLOCK(memstick_host_lock); | ||
29 | |||
30 | static int memstick_dev_match(struct memstick_dev *card, | ||
31 | struct memstick_device_id *id) | ||
32 | { | ||
33 | if (id->match_flags & MEMSTICK_MATCH_ALL) { | ||
34 | if ((id->type == card->id.type) | ||
35 | && (id->category == card->id.category) | ||
36 | && (id->class == card->id.class)) | ||
37 | return 1; | ||
38 | } | ||
39 | |||
40 | return 0; | ||
41 | } | ||
42 | |||
43 | static int memstick_bus_match(struct device *dev, struct device_driver *drv) | ||
44 | { | ||
45 | struct memstick_dev *card = container_of(dev, struct memstick_dev, | ||
46 | dev); | ||
47 | struct memstick_driver *ms_drv = container_of(drv, | ||
48 | struct memstick_driver, | ||
49 | driver); | ||
50 | struct memstick_device_id *ids = ms_drv->id_table; | ||
51 | |||
52 | if (ids) { | ||
53 | while (ids->match_flags) { | ||
54 | if (memstick_dev_match(card, ids)) | ||
55 | return 1; | ||
56 | ++ids; | ||
57 | } | ||
58 | } | ||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | static int memstick_uevent(struct device *dev, struct kobj_uevent_env *env) | ||
63 | { | ||
64 | struct memstick_dev *card = container_of(dev, struct memstick_dev, | ||
65 | dev); | ||
66 | |||
67 | if (add_uevent_var(env, "MEMSTICK_TYPE=%02X", card->id.type)) | ||
68 | return -ENOMEM; | ||
69 | |||
70 | if (add_uevent_var(env, "MEMSTICK_CATEGORY=%02X", card->id.category)) | ||
71 | return -ENOMEM; | ||
72 | |||
73 | if (add_uevent_var(env, "MEMSTICK_CLASS=%02X", card->id.class)) | ||
74 | return -ENOMEM; | ||
75 | |||
76 | return 0; | ||
77 | } | ||
78 | |||
79 | static int memstick_device_probe(struct device *dev) | ||
80 | { | ||
81 | struct memstick_dev *card = container_of(dev, struct memstick_dev, | ||
82 | dev); | ||
83 | struct memstick_driver *drv = container_of(dev->driver, | ||
84 | struct memstick_driver, | ||
85 | driver); | ||
86 | int rc = -ENODEV; | ||
87 | |||
88 | if (dev->driver && drv->probe) { | ||
89 | rc = drv->probe(card); | ||
90 | if (!rc) | ||
91 | get_device(dev); | ||
92 | } | ||
93 | return rc; | ||
94 | } | ||
95 | |||
96 | static int memstick_device_remove(struct device *dev) | ||
97 | { | ||
98 | struct memstick_dev *card = container_of(dev, struct memstick_dev, | ||
99 | dev); | ||
100 | struct memstick_driver *drv = container_of(dev->driver, | ||
101 | struct memstick_driver, | ||
102 | driver); | ||
103 | |||
104 | if (dev->driver && drv->remove) { | ||
105 | drv->remove(card); | ||
106 | card->dev.driver = NULL; | ||
107 | } | ||
108 | |||
109 | put_device(dev); | ||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | #ifdef CONFIG_PM | ||
114 | |||
115 | static int memstick_device_suspend(struct device *dev, pm_message_t state) | ||
116 | { | ||
117 | struct memstick_dev *card = container_of(dev, struct memstick_dev, | ||
118 | dev); | ||
119 | struct memstick_driver *drv = container_of(dev->driver, | ||
120 | struct memstick_driver, | ||
121 | driver); | ||
122 | |||
123 | if (dev->driver && drv->suspend) | ||
124 | return drv->suspend(card, state); | ||
125 | return 0; | ||
126 | } | ||
127 | |||
128 | static int memstick_device_resume(struct device *dev) | ||
129 | { | ||
130 | struct memstick_dev *card = container_of(dev, struct memstick_dev, | ||
131 | dev); | ||
132 | struct memstick_driver *drv = container_of(dev->driver, | ||
133 | struct memstick_driver, | ||
134 | driver); | ||
135 | |||
136 | if (dev->driver && drv->resume) | ||
137 | return drv->resume(card); | ||
138 | return 0; | ||
139 | } | ||
140 | |||
141 | #else | ||
142 | |||
143 | #define memstick_device_suspend NULL | ||
144 | #define memstick_device_resume NULL | ||
145 | |||
146 | #endif /* CONFIG_PM */ | ||
147 | |||
148 | #define MEMSTICK_ATTR(name, format) \ | ||
149 | static ssize_t name##_show(struct device *dev, struct device_attribute *attr, \ | ||
150 | char *buf) \ | ||
151 | { \ | ||
152 | struct memstick_dev *card = container_of(dev, struct memstick_dev, \ | ||
153 | dev); \ | ||
154 | return sprintf(buf, format, card->id.name); \ | ||
155 | } | ||
156 | |||
157 | MEMSTICK_ATTR(type, "%02X"); | ||
158 | MEMSTICK_ATTR(category, "%02X"); | ||
159 | MEMSTICK_ATTR(class, "%02X"); | ||
160 | |||
161 | #define MEMSTICK_ATTR_RO(name) __ATTR(name, S_IRUGO, name##_show, NULL) | ||
162 | |||
163 | static struct device_attribute memstick_dev_attrs[] = { | ||
164 | MEMSTICK_ATTR_RO(type), | ||
165 | MEMSTICK_ATTR_RO(category), | ||
166 | MEMSTICK_ATTR_RO(class), | ||
167 | __ATTR_NULL | ||
168 | }; | ||
169 | |||
170 | static struct bus_type memstick_bus_type = { | ||
171 | .name = "memstick", | ||
172 | .dev_attrs = memstick_dev_attrs, | ||
173 | .match = memstick_bus_match, | ||
174 | .uevent = memstick_uevent, | ||
175 | .probe = memstick_device_probe, | ||
176 | .remove = memstick_device_remove, | ||
177 | .suspend = memstick_device_suspend, | ||
178 | .resume = memstick_device_resume | ||
179 | }; | ||
180 | |||
181 | static void memstick_free(struct class_device *cdev) | ||
182 | { | ||
183 | struct memstick_host *host = container_of(cdev, struct memstick_host, | ||
184 | cdev); | ||
185 | kfree(host); | ||
186 | } | ||
187 | |||
188 | static struct class memstick_host_class = { | ||
189 | .name = "memstick_host", | ||
190 | .release = memstick_free | ||
191 | }; | ||
192 | |||
193 | static void memstick_free_card(struct device *dev) | ||
194 | { | ||
195 | struct memstick_dev *card = container_of(dev, struct memstick_dev, | ||
196 | dev); | ||
197 | kfree(card); | ||
198 | } | ||
199 | |||
200 | static int memstick_dummy_check(struct memstick_dev *card) | ||
201 | { | ||
202 | return 0; | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * memstick_detect_change - schedule media detection on memstick host | ||
207 | * @host - host to use | ||
208 | */ | ||
209 | void memstick_detect_change(struct memstick_host *host) | ||
210 | { | ||
211 | queue_work(workqueue, &host->media_checker); | ||
212 | } | ||
213 | EXPORT_SYMBOL(memstick_detect_change); | ||
214 | |||
215 | /** | ||
216 | * memstick_next_req - called by host driver to obtain next request to process | ||
217 | * @host - host to use | ||
218 | * @mrq - pointer to stick the request to | ||
219 | * | ||
220 | * Host calls this function from idle state (*mrq == NULL) or after finishing | ||
221 | * previous request (*mrq should point to it). If previous request was | ||
222 | * unsuccessful, it is retried for predetermined number of times. Return value | ||
223 | * of 0 means that new request was assigned to the host. | ||
224 | */ | ||
225 | int memstick_next_req(struct memstick_host *host, struct memstick_request **mrq) | ||
226 | { | ||
227 | int rc = -ENXIO; | ||
228 | |||
229 | if ((*mrq) && (*mrq)->error && host->retries) { | ||
230 | (*mrq)->error = rc; | ||
231 | host->retries--; | ||
232 | return 0; | ||
233 | } | ||
234 | |||
235 | if (host->card && host->card->next_request) | ||
236 | rc = host->card->next_request(host->card, mrq); | ||
237 | |||
238 | if (!rc) | ||
239 | host->retries = cmd_retries; | ||
240 | else | ||
241 | *mrq = NULL; | ||
242 | |||
243 | return rc; | ||
244 | } | ||
245 | EXPORT_SYMBOL(memstick_next_req); | ||
246 | |||
247 | /** | ||
248 | * memstick_new_req - notify the host that some requests are pending | ||
249 | * @host - host to use | ||
250 | */ | ||
251 | void memstick_new_req(struct memstick_host *host) | ||
252 | { | ||
253 | host->retries = cmd_retries; | ||
254 | host->request(host); | ||
255 | } | ||
256 | EXPORT_SYMBOL(memstick_new_req); | ||
257 | |||
258 | /** | ||
259 | * memstick_init_req_sg - set request fields needed for bulk data transfer | ||
260 | * @mrq - request to use | ||
261 | * @tpc - memstick Transport Protocol Command | ||
262 | * @sg - TPC argument | ||
263 | */ | ||
264 | void memstick_init_req_sg(struct memstick_request *mrq, unsigned char tpc, | ||
265 | struct scatterlist *sg) | ||
266 | { | ||
267 | mrq->tpc = tpc; | ||
268 | if (tpc & 8) | ||
269 | mrq->data_dir = WRITE; | ||
270 | else | ||
271 | mrq->data_dir = READ; | ||
272 | |||
273 | mrq->sg = *sg; | ||
274 | mrq->io_type = MEMSTICK_IO_SG; | ||
275 | |||
276 | if (tpc == MS_TPC_SET_CMD || tpc == MS_TPC_EX_SET_CMD) | ||
277 | mrq->need_card_int = 1; | ||
278 | else | ||
279 | mrq->need_card_int = 0; | ||
280 | |||
281 | mrq->get_int_reg = 0; | ||
282 | } | ||
283 | EXPORT_SYMBOL(memstick_init_req_sg); | ||
284 | |||
285 | /** | ||
286 | * memstick_init_req - set request fields needed for short data transfer | ||
287 | * @mrq - request to use | ||
288 | * @tpc - memstick Transport Protocol Command | ||
289 | * @buf - TPC argument buffer | ||
290 | * @length - TPC argument size | ||
291 | * | ||
292 | * The intended use of this function (transfer of data items several bytes | ||
293 | * in size) allows us to just copy the value between request structure and | ||
294 | * user supplied buffer. | ||
295 | */ | ||
296 | void memstick_init_req(struct memstick_request *mrq, unsigned char tpc, | ||
297 | void *buf, size_t length) | ||
298 | { | ||
299 | mrq->tpc = tpc; | ||
300 | if (tpc & 8) | ||
301 | mrq->data_dir = WRITE; | ||
302 | else | ||
303 | mrq->data_dir = READ; | ||
304 | |||
305 | mrq->data_len = length > sizeof(mrq->data) ? sizeof(mrq->data) : length; | ||
306 | if (mrq->data_dir == WRITE) | ||
307 | memcpy(mrq->data, buf, mrq->data_len); | ||
308 | |||
309 | mrq->io_type = MEMSTICK_IO_VAL; | ||
310 | |||
311 | if (tpc == MS_TPC_SET_CMD || tpc == MS_TPC_EX_SET_CMD) | ||
312 | mrq->need_card_int = 1; | ||
313 | else | ||
314 | mrq->need_card_int = 0; | ||
315 | |||
316 | mrq->get_int_reg = 0; | ||
317 | } | ||
318 | EXPORT_SYMBOL(memstick_init_req); | ||
319 | |||
320 | /* | ||
321 | * Functions prefixed with "h_" are protocol callbacks. They can be called from | ||
322 | * interrupt context. Return value of 0 means that request processing is still | ||
323 | * ongoing, while special error value of -EAGAIN means that current request is | ||
324 | * finished (and request processor should come back some time later). | ||
325 | */ | ||
326 | |||
327 | static int h_memstick_read_dev_id(struct memstick_dev *card, | ||
328 | struct memstick_request **mrq) | ||
329 | { | ||
330 | struct ms_id_register id_reg; | ||
331 | |||
332 | if (!(*mrq)) { | ||
333 | memstick_init_req(&card->current_mrq, MS_TPC_READ_REG, NULL, | ||
334 | sizeof(struct ms_id_register)); | ||
335 | *mrq = &card->current_mrq; | ||
336 | return 0; | ||
337 | } else { | ||
338 | if (!(*mrq)->error) { | ||
339 | memcpy(&id_reg, (*mrq)->data, sizeof(id_reg)); | ||
340 | card->id.match_flags = MEMSTICK_MATCH_ALL; | ||
341 | card->id.type = id_reg.type; | ||
342 | card->id.category = id_reg.category; | ||
343 | card->id.class = id_reg.class; | ||
344 | } | ||
345 | complete(&card->mrq_complete); | ||
346 | return -EAGAIN; | ||
347 | } | ||
348 | } | ||
349 | |||
350 | static int h_memstick_set_rw_addr(struct memstick_dev *card, | ||
351 | struct memstick_request **mrq) | ||
352 | { | ||
353 | if (!(*mrq)) { | ||
354 | memstick_init_req(&card->current_mrq, MS_TPC_SET_RW_REG_ADRS, | ||
355 | (char *)&card->reg_addr, | ||
356 | sizeof(card->reg_addr)); | ||
357 | *mrq = &card->current_mrq; | ||
358 | return 0; | ||
359 | } else { | ||
360 | complete(&card->mrq_complete); | ||
361 | return -EAGAIN; | ||
362 | } | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * memstick_set_rw_addr - issue SET_RW_REG_ADDR request and wait for it to | ||
367 | * complete | ||
368 | * @card - media device to use | ||
369 | */ | ||
370 | int memstick_set_rw_addr(struct memstick_dev *card) | ||
371 | { | ||
372 | card->next_request = h_memstick_set_rw_addr; | ||
373 | memstick_new_req(card->host); | ||
374 | wait_for_completion(&card->mrq_complete); | ||
375 | |||
376 | return card->current_mrq.error; | ||
377 | } | ||
378 | EXPORT_SYMBOL(memstick_set_rw_addr); | ||
379 | |||
380 | static struct memstick_dev *memstick_alloc_card(struct memstick_host *host) | ||
381 | { | ||
382 | struct memstick_dev *card = kzalloc(sizeof(struct memstick_dev), | ||
383 | GFP_KERNEL); | ||
384 | struct memstick_dev *old_card = host->card; | ||
385 | struct ms_id_register id_reg; | ||
386 | |||
387 | if (card) { | ||
388 | card->host = host; | ||
389 | snprintf(card->dev.bus_id, sizeof(card->dev.bus_id), | ||
390 | "%s", host->cdev.class_id); | ||
391 | card->dev.parent = host->cdev.dev; | ||
392 | card->dev.bus = &memstick_bus_type; | ||
393 | card->dev.release = memstick_free_card; | ||
394 | card->check = memstick_dummy_check; | ||
395 | |||
396 | card->reg_addr.r_offset = offsetof(struct ms_register, id); | ||
397 | card->reg_addr.r_length = sizeof(id_reg); | ||
398 | card->reg_addr.w_offset = offsetof(struct ms_register, id); | ||
399 | card->reg_addr.w_length = sizeof(id_reg); | ||
400 | |||
401 | init_completion(&card->mrq_complete); | ||
402 | |||
403 | host->card = card; | ||
404 | if (memstick_set_rw_addr(card)) | ||
405 | goto err_out; | ||
406 | |||
407 | card->next_request = h_memstick_read_dev_id; | ||
408 | memstick_new_req(host); | ||
409 | wait_for_completion(&card->mrq_complete); | ||
410 | |||
411 | if (card->current_mrq.error) | ||
412 | goto err_out; | ||
413 | } | ||
414 | host->card = old_card; | ||
415 | return card; | ||
416 | err_out: | ||
417 | host->card = old_card; | ||
418 | kfree(card); | ||
419 | return NULL; | ||
420 | } | ||
421 | |||
422 | static void memstick_power_on(struct memstick_host *host) | ||
423 | { | ||
424 | host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_ON); | ||
425 | host->set_param(host, MEMSTICK_INTERFACE, MEMSTICK_SERIAL); | ||
426 | msleep(1); | ||
427 | } | ||
428 | |||
429 | static void memstick_check(struct work_struct *work) | ||
430 | { | ||
431 | struct memstick_host *host = container_of(work, struct memstick_host, | ||
432 | media_checker); | ||
433 | struct memstick_dev *card; | ||
434 | |||
435 | dev_dbg(host->cdev.dev, "memstick_check started\n"); | ||
436 | mutex_lock(&host->lock); | ||
437 | if (!host->card) | ||
438 | memstick_power_on(host); | ||
439 | |||
440 | card = memstick_alloc_card(host); | ||
441 | |||
442 | if (!card) { | ||
443 | if (host->card) { | ||
444 | device_unregister(&host->card->dev); | ||
445 | host->card = NULL; | ||
446 | } | ||
447 | } else { | ||
448 | dev_dbg(host->cdev.dev, "new card %02x, %02x, %02x\n", | ||
449 | card->id.type, card->id.category, card->id.class); | ||
450 | if (host->card) { | ||
451 | if (memstick_set_rw_addr(host->card) | ||
452 | || !memstick_dev_match(host->card, &card->id) | ||
453 | || !(host->card->check(host->card))) { | ||
454 | device_unregister(&host->card->dev); | ||
455 | host->card = NULL; | ||
456 | } | ||
457 | } | ||
458 | |||
459 | if (!host->card) { | ||
460 | host->card = card; | ||
461 | if (device_register(&card->dev)) { | ||
462 | kfree(host->card); | ||
463 | host->card = NULL; | ||
464 | } | ||
465 | } else | ||
466 | kfree(card); | ||
467 | } | ||
468 | |||
469 | if (!host->card) | ||
470 | host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF); | ||
471 | |||
472 | mutex_unlock(&host->lock); | ||
473 | dev_dbg(host->cdev.dev, "memstick_check finished\n"); | ||
474 | } | ||
475 | |||
476 | /** | ||
477 | * memstick_alloc_host - allocate a memstick_host structure | ||
478 | * @extra: size of the user private data to allocate | ||
479 | * @dev: parent device of the host | ||
480 | */ | ||
481 | struct memstick_host *memstick_alloc_host(unsigned int extra, | ||
482 | struct device *dev) | ||
483 | { | ||
484 | struct memstick_host *host; | ||
485 | |||
486 | host = kzalloc(sizeof(struct memstick_host) + extra, GFP_KERNEL); | ||
487 | if (host) { | ||
488 | mutex_init(&host->lock); | ||
489 | INIT_WORK(&host->media_checker, memstick_check); | ||
490 | host->cdev.class = &memstick_host_class; | ||
491 | host->cdev.dev = dev; | ||
492 | class_device_initialize(&host->cdev); | ||
493 | } | ||
494 | return host; | ||
495 | } | ||
496 | EXPORT_SYMBOL(memstick_alloc_host); | ||
497 | |||
498 | /** | ||
499 | * memstick_add_host - start request processing on memstick host | ||
500 | * @host - host to use | ||
501 | */ | ||
502 | int memstick_add_host(struct memstick_host *host) | ||
503 | { | ||
504 | int rc; | ||
505 | |||
506 | if (!idr_pre_get(&memstick_host_idr, GFP_KERNEL)) | ||
507 | return -ENOMEM; | ||
508 | |||
509 | spin_lock(&memstick_host_lock); | ||
510 | rc = idr_get_new(&memstick_host_idr, host, &host->id); | ||
511 | spin_unlock(&memstick_host_lock); | ||
512 | if (rc) | ||
513 | return rc; | ||
514 | |||
515 | snprintf(host->cdev.class_id, BUS_ID_SIZE, | ||
516 | "memstick%u", host->id); | ||
517 | |||
518 | rc = class_device_add(&host->cdev); | ||
519 | if (rc) { | ||
520 | spin_lock(&memstick_host_lock); | ||
521 | idr_remove(&memstick_host_idr, host->id); | ||
522 | spin_unlock(&memstick_host_lock); | ||
523 | return rc; | ||
524 | } | ||
525 | |||
526 | host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF); | ||
527 | memstick_detect_change(host); | ||
528 | return 0; | ||
529 | } | ||
530 | EXPORT_SYMBOL(memstick_add_host); | ||
531 | |||
532 | /** | ||
533 | * memstick_remove_host - stop request processing on memstick host | ||
534 | * @host - host to use | ||
535 | */ | ||
536 | void memstick_remove_host(struct memstick_host *host) | ||
537 | { | ||
538 | flush_workqueue(workqueue); | ||
539 | mutex_lock(&host->lock); | ||
540 | if (host->card) | ||
541 | device_unregister(&host->card->dev); | ||
542 | host->card = NULL; | ||
543 | host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF); | ||
544 | mutex_unlock(&host->lock); | ||
545 | |||
546 | spin_lock(&memstick_host_lock); | ||
547 | idr_remove(&memstick_host_idr, host->id); | ||
548 | spin_unlock(&memstick_host_lock); | ||
549 | class_device_del(&host->cdev); | ||
550 | } | ||
551 | EXPORT_SYMBOL(memstick_remove_host); | ||
552 | |||
553 | /** | ||
554 | * memstick_free_host - free memstick host | ||
555 | * @host - host to use | ||
556 | */ | ||
557 | void memstick_free_host(struct memstick_host *host) | ||
558 | { | ||
559 | mutex_destroy(&host->lock); | ||
560 | class_device_put(&host->cdev); | ||
561 | } | ||
562 | EXPORT_SYMBOL(memstick_free_host); | ||
563 | |||
564 | int memstick_register_driver(struct memstick_driver *drv) | ||
565 | { | ||
566 | drv->driver.bus = &memstick_bus_type; | ||
567 | |||
568 | return driver_register(&drv->driver); | ||
569 | } | ||
570 | EXPORT_SYMBOL(memstick_register_driver); | ||
571 | |||
572 | void memstick_unregister_driver(struct memstick_driver *drv) | ||
573 | { | ||
574 | driver_unregister(&drv->driver); | ||
575 | } | ||
576 | EXPORT_SYMBOL(memstick_unregister_driver); | ||
577 | |||
578 | |||
579 | static int __init memstick_init(void) | ||
580 | { | ||
581 | int rc; | ||
582 | |||
583 | workqueue = create_freezeable_workqueue("kmemstick"); | ||
584 | if (!workqueue) | ||
585 | return -ENOMEM; | ||
586 | |||
587 | rc = bus_register(&memstick_bus_type); | ||
588 | if (!rc) | ||
589 | rc = class_register(&memstick_host_class); | ||
590 | |||
591 | if (!rc) | ||
592 | return 0; | ||
593 | |||
594 | bus_unregister(&memstick_bus_type); | ||
595 | destroy_workqueue(workqueue); | ||
596 | |||
597 | return rc; | ||
598 | } | ||
599 | |||
600 | static void __exit memstick_exit(void) | ||
601 | { | ||
602 | class_unregister(&memstick_host_class); | ||
603 | bus_unregister(&memstick_bus_type); | ||
604 | destroy_workqueue(workqueue); | ||
605 | idr_destroy(&memstick_host_idr); | ||
606 | } | ||
607 | |||
608 | module_init(memstick_init); | ||
609 | module_exit(memstick_exit); | ||
610 | |||
611 | MODULE_AUTHOR("Alex Dubov"); | ||
612 | MODULE_LICENSE("GPL"); | ||
613 | MODULE_DESCRIPTION("Sony MemoryStick core driver"); | ||
614 | MODULE_VERSION(DRIVER_VERSION); | ||
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c new file mode 100644 index 000000000000..423ad8cf4bb9 --- /dev/null +++ b/drivers/memstick/core/mspro_block.c | |||
@@ -0,0 +1,1351 @@ | |||
1 | /* | ||
2 | * Sony MemoryStick Pro storage support | ||
3 | * | ||
4 | * Copyright (C) 2007 Alex Dubov <oakad@yahoo.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * Special thanks to Carlos Corbacho for providing various MemoryStick cards | ||
11 | * that made this driver possible. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/blkdev.h> | ||
16 | #include <linux/idr.h> | ||
17 | #include <linux/hdreg.h> | ||
18 | #include <linux/kthread.h> | ||
19 | #include <linux/memstick.h> | ||
20 | |||
21 | #define DRIVER_NAME "mspro_block" | ||
22 | #define DRIVER_VERSION "0.2" | ||
23 | |||
24 | static int major; | ||
25 | module_param(major, int, 0644); | ||
26 | |||
27 | #define MSPRO_BLOCK_MAX_SEGS 32 | ||
28 | #define MSPRO_BLOCK_MAX_PAGES ((2 << 16) - 1) | ||
29 | |||
30 | #define MSPRO_BLOCK_SIGNATURE 0xa5c3 | ||
31 | #define MSPRO_BLOCK_MAX_ATTRIBUTES 41 | ||
32 | |||
33 | enum { | ||
34 | MSPRO_BLOCK_ID_SYSINFO = 0x10, | ||
35 | MSPRO_BLOCK_ID_MODELNAME = 0x15, | ||
36 | MSPRO_BLOCK_ID_MBR = 0x20, | ||
37 | MSPRO_BLOCK_ID_PBR16 = 0x21, | ||
38 | MSPRO_BLOCK_ID_PBR32 = 0x22, | ||
39 | MSPRO_BLOCK_ID_SPECFILEVALUES1 = 0x25, | ||
40 | MSPRO_BLOCK_ID_SPECFILEVALUES2 = 0x26, | ||
41 | MSPRO_BLOCK_ID_DEVINFO = 0x30 | ||
42 | }; | ||
43 | |||
44 | struct mspro_sys_attr { | ||
45 | size_t size; | ||
46 | void *data; | ||
47 | unsigned char id; | ||
48 | char name[32]; | ||
49 | struct device_attribute dev_attr; | ||
50 | }; | ||
51 | |||
52 | struct mspro_attr_entry { | ||
53 | unsigned int address; | ||
54 | unsigned int size; | ||
55 | unsigned char id; | ||
56 | unsigned char reserved[3]; | ||
57 | } __attribute__((packed)); | ||
58 | |||
59 | struct mspro_attribute { | ||
60 | unsigned short signature; | ||
61 | unsigned short version; | ||
62 | unsigned char count; | ||
63 | unsigned char reserved[11]; | ||
64 | struct mspro_attr_entry entries[]; | ||
65 | } __attribute__((packed)); | ||
66 | |||
67 | struct mspro_sys_info { | ||
68 | unsigned char class; | ||
69 | unsigned char reserved0; | ||
70 | unsigned short block_size; | ||
71 | unsigned short block_count; | ||
72 | unsigned short user_block_count; | ||
73 | unsigned short page_size; | ||
74 | unsigned char reserved1[2]; | ||
75 | unsigned char assembly_date[8]; | ||
76 | unsigned int serial_number; | ||
77 | unsigned char assembly_maker_code; | ||
78 | unsigned char assembly_model_code[3]; | ||
79 | unsigned short memory_maker_code; | ||
80 | unsigned short memory_model_code; | ||
81 | unsigned char reserved2[4]; | ||
82 | unsigned char vcc; | ||
83 | unsigned char vpp; | ||
84 | unsigned short controller_number; | ||
85 | unsigned short controller_function; | ||
86 | unsigned short start_sector; | ||
87 | unsigned short unit_size; | ||
88 | unsigned char ms_sub_class; | ||
89 | unsigned char reserved3[4]; | ||
90 | unsigned char interface_type; | ||
91 | unsigned short controller_code; | ||
92 | unsigned char format_type; | ||
93 | unsigned char reserved4; | ||
94 | unsigned char device_type; | ||
95 | unsigned char reserved5[7]; | ||
96 | unsigned char mspro_id[16]; | ||
97 | unsigned char reserved6[16]; | ||
98 | } __attribute__((packed)); | ||
99 | |||
100 | struct mspro_mbr { | ||
101 | unsigned char boot_partition; | ||
102 | unsigned char start_head; | ||
103 | unsigned char start_sector; | ||
104 | unsigned char start_cylinder; | ||
105 | unsigned char partition_type; | ||
106 | unsigned char end_head; | ||
107 | unsigned char end_sector; | ||
108 | unsigned char end_cylinder; | ||
109 | unsigned int start_sectors; | ||
110 | unsigned int sectors_per_partition; | ||
111 | } __attribute__((packed)); | ||
112 | |||
113 | struct mspro_devinfo { | ||
114 | unsigned short cylinders; | ||
115 | unsigned short heads; | ||
116 | unsigned short bytes_per_track; | ||
117 | unsigned short bytes_per_sector; | ||
118 | unsigned short sectors_per_track; | ||
119 | unsigned char reserved[6]; | ||
120 | } __attribute__((packed)); | ||
121 | |||
122 | struct mspro_block_data { | ||
123 | struct memstick_dev *card; | ||
124 | unsigned int usage_count; | ||
125 | struct gendisk *disk; | ||
126 | struct request_queue *queue; | ||
127 | spinlock_t q_lock; | ||
128 | wait_queue_head_t q_wait; | ||
129 | struct task_struct *q_thread; | ||
130 | |||
131 | unsigned short page_size; | ||
132 | unsigned short cylinders; | ||
133 | unsigned short heads; | ||
134 | unsigned short sectors_per_track; | ||
135 | |||
136 | unsigned char system; | ||
137 | unsigned char read_only:1, | ||
138 | active:1, | ||
139 | has_request:1, | ||
140 | data_dir:1; | ||
141 | unsigned char transfer_cmd; | ||
142 | |||
143 | int (*mrq_handler)(struct memstick_dev *card, | ||
144 | struct memstick_request **mrq); | ||
145 | |||
146 | struct attribute_group attr_group; | ||
147 | |||
148 | struct scatterlist req_sg[MSPRO_BLOCK_MAX_SEGS]; | ||
149 | unsigned int seg_count; | ||
150 | unsigned int current_seg; | ||
151 | unsigned short current_page; | ||
152 | }; | ||
153 | |||
154 | static DEFINE_IDR(mspro_block_disk_idr); | ||
155 | static DEFINE_MUTEX(mspro_block_disk_lock); | ||
156 | |||
157 | /*** Block device ***/ | ||
158 | |||
159 | static int mspro_block_bd_open(struct inode *inode, struct file *filp) | ||
160 | { | ||
161 | struct gendisk *disk = inode->i_bdev->bd_disk; | ||
162 | struct mspro_block_data *msb = disk->private_data; | ||
163 | int rc = -ENXIO; | ||
164 | |||
165 | mutex_lock(&mspro_block_disk_lock); | ||
166 | |||
167 | if (msb && msb->card) { | ||
168 | msb->usage_count++; | ||
169 | if ((filp->f_mode & FMODE_WRITE) && msb->read_only) | ||
170 | rc = -EROFS; | ||
171 | else | ||
172 | rc = 0; | ||
173 | } | ||
174 | |||
175 | mutex_unlock(&mspro_block_disk_lock); | ||
176 | |||
177 | return rc; | ||
178 | } | ||
179 | |||
180 | |||
181 | static int mspro_block_disk_release(struct gendisk *disk) | ||
182 | { | ||
183 | struct mspro_block_data *msb = disk->private_data; | ||
184 | int disk_id = disk->first_minor >> MEMSTICK_PART_SHIFT; | ||
185 | |||
186 | mutex_lock(&mspro_block_disk_lock); | ||
187 | |||
188 | if (msb->usage_count) { | ||
189 | msb->usage_count--; | ||
190 | if (!msb->usage_count) { | ||
191 | kfree(msb); | ||
192 | disk->private_data = NULL; | ||
193 | idr_remove(&mspro_block_disk_idr, disk_id); | ||
194 | put_disk(disk); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | mutex_unlock(&mspro_block_disk_lock); | ||
199 | |||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | static int mspro_block_bd_release(struct inode *inode, struct file *filp) | ||
204 | { | ||
205 | struct gendisk *disk = inode->i_bdev->bd_disk; | ||
206 | return mspro_block_disk_release(disk); | ||
207 | } | ||
208 | |||
209 | static int mspro_block_bd_getgeo(struct block_device *bdev, | ||
210 | struct hd_geometry *geo) | ||
211 | { | ||
212 | struct mspro_block_data *msb = bdev->bd_disk->private_data; | ||
213 | |||
214 | geo->heads = msb->heads; | ||
215 | geo->sectors = msb->sectors_per_track; | ||
216 | geo->cylinders = msb->cylinders; | ||
217 | |||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | static struct block_device_operations ms_block_bdops = { | ||
222 | .open = mspro_block_bd_open, | ||
223 | .release = mspro_block_bd_release, | ||
224 | .getgeo = mspro_block_bd_getgeo, | ||
225 | .owner = THIS_MODULE | ||
226 | }; | ||
227 | |||
228 | /*** Information ***/ | ||
229 | |||
230 | static struct mspro_sys_attr *mspro_from_sysfs_attr(struct attribute *attr) | ||
231 | { | ||
232 | struct device_attribute *dev_attr | ||
233 | = container_of(attr, struct device_attribute, attr); | ||
234 | return container_of(dev_attr, struct mspro_sys_attr, dev_attr); | ||
235 | } | ||
236 | |||
237 | static const char *mspro_block_attr_name(unsigned char tag) | ||
238 | { | ||
239 | switch (tag) { | ||
240 | case MSPRO_BLOCK_ID_SYSINFO: | ||
241 | return "attr_sysinfo"; | ||
242 | case MSPRO_BLOCK_ID_MODELNAME: | ||
243 | return "attr_modelname"; | ||
244 | case MSPRO_BLOCK_ID_MBR: | ||
245 | return "attr_mbr"; | ||
246 | case MSPRO_BLOCK_ID_PBR16: | ||
247 | return "attr_pbr16"; | ||
248 | case MSPRO_BLOCK_ID_PBR32: | ||
249 | return "attr_pbr32"; | ||
250 | case MSPRO_BLOCK_ID_SPECFILEVALUES1: | ||
251 | return "attr_specfilevalues1"; | ||
252 | case MSPRO_BLOCK_ID_SPECFILEVALUES2: | ||
253 | return "attr_specfilevalues2"; | ||
254 | case MSPRO_BLOCK_ID_DEVINFO: | ||
255 | return "attr_devinfo"; | ||
256 | default: | ||
257 | return NULL; | ||
258 | }; | ||
259 | } | ||
260 | |||
261 | typedef ssize_t (*sysfs_show_t)(struct device *dev, | ||
262 | struct device_attribute *attr, | ||
263 | char *buffer); | ||
264 | |||
265 | static ssize_t mspro_block_attr_show_default(struct device *dev, | ||
266 | struct device_attribute *attr, | ||
267 | char *buffer) | ||
268 | { | ||
269 | struct mspro_sys_attr *s_attr = container_of(attr, | ||
270 | struct mspro_sys_attr, | ||
271 | dev_attr); | ||
272 | |||
273 | ssize_t cnt, rc = 0; | ||
274 | |||
275 | for (cnt = 0; cnt < s_attr->size; cnt++) { | ||
276 | if (cnt && !(cnt % 16)) { | ||
277 | if (PAGE_SIZE - rc) | ||
278 | buffer[rc++] = '\n'; | ||
279 | } | ||
280 | |||
281 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "%02x ", | ||
282 | ((unsigned char *)s_attr->data)[cnt]); | ||
283 | } | ||
284 | return rc; | ||
285 | } | ||
286 | |||
287 | static ssize_t mspro_block_attr_show_sysinfo(struct device *dev, | ||
288 | struct device_attribute *attr, | ||
289 | char *buffer) | ||
290 | { | ||
291 | struct mspro_sys_attr *x_attr = container_of(attr, | ||
292 | struct mspro_sys_attr, | ||
293 | dev_attr); | ||
294 | struct mspro_sys_info *x_sys = x_attr->data; | ||
295 | ssize_t rc = 0; | ||
296 | |||
297 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "class: %x\n", | ||
298 | x_sys->class); | ||
299 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "block size: %x\n", | ||
300 | be16_to_cpu(x_sys->block_size)); | ||
301 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "block count: %x\n", | ||
302 | be16_to_cpu(x_sys->block_count)); | ||
303 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "user block count: %x\n", | ||
304 | be16_to_cpu(x_sys->user_block_count)); | ||
305 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "page size: %x\n", | ||
306 | be16_to_cpu(x_sys->page_size)); | ||
307 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "assembly date: " | ||
308 | "%d %04u-%02u-%02u %02u:%02u:%02u\n", | ||
309 | x_sys->assembly_date[0], | ||
310 | be16_to_cpu(*(unsigned short *) | ||
311 | &x_sys->assembly_date[1]), | ||
312 | x_sys->assembly_date[3], x_sys->assembly_date[4], | ||
313 | x_sys->assembly_date[5], x_sys->assembly_date[6], | ||
314 | x_sys->assembly_date[7]); | ||
315 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "serial number: %x\n", | ||
316 | be32_to_cpu(x_sys->serial_number)); | ||
317 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, | ||
318 | "assembly maker code: %x\n", | ||
319 | x_sys->assembly_maker_code); | ||
320 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "assembly model code: " | ||
321 | "%02x%02x%02x\n", x_sys->assembly_model_code[0], | ||
322 | x_sys->assembly_model_code[1], | ||
323 | x_sys->assembly_model_code[2]); | ||
324 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "memory maker code: %x\n", | ||
325 | be16_to_cpu(x_sys->memory_maker_code)); | ||
326 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "memory model code: %x\n", | ||
327 | be16_to_cpu(x_sys->memory_model_code)); | ||
328 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "vcc: %x\n", | ||
329 | x_sys->vcc); | ||
330 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "vpp: %x\n", | ||
331 | x_sys->vpp); | ||
332 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "controller number: %x\n", | ||
333 | be16_to_cpu(x_sys->controller_number)); | ||
334 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, | ||
335 | "controller function: %x\n", | ||
336 | be16_to_cpu(x_sys->controller_function)); | ||
337 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "start sector: %x\n", | ||
338 | be16_to_cpu(x_sys->start_sector)); | ||
339 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "unit size: %x\n", | ||
340 | be16_to_cpu(x_sys->unit_size)); | ||
341 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "sub class: %x\n", | ||
342 | x_sys->ms_sub_class); | ||
343 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "interface type: %x\n", | ||
344 | x_sys->interface_type); | ||
345 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "controller code: %x\n", | ||
346 | be16_to_cpu(x_sys->controller_code)); | ||
347 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "format type: %x\n", | ||
348 | x_sys->format_type); | ||
349 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "device type: %x\n", | ||
350 | x_sys->device_type); | ||
351 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "mspro id: %s\n", | ||
352 | x_sys->mspro_id); | ||
353 | return rc; | ||
354 | } | ||
355 | |||
356 | static ssize_t mspro_block_attr_show_modelname(struct device *dev, | ||
357 | struct device_attribute *attr, | ||
358 | char *buffer) | ||
359 | { | ||
360 | struct mspro_sys_attr *s_attr = container_of(attr, | ||
361 | struct mspro_sys_attr, | ||
362 | dev_attr); | ||
363 | |||
364 | return scnprintf(buffer, PAGE_SIZE, "%s", (char *)s_attr->data); | ||
365 | } | ||
366 | |||
367 | static ssize_t mspro_block_attr_show_mbr(struct device *dev, | ||
368 | struct device_attribute *attr, | ||
369 | char *buffer) | ||
370 | { | ||
371 | struct mspro_sys_attr *x_attr = container_of(attr, | ||
372 | struct mspro_sys_attr, | ||
373 | dev_attr); | ||
374 | struct mspro_mbr *x_mbr = x_attr->data; | ||
375 | ssize_t rc = 0; | ||
376 | |||
377 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "boot partition: %x\n", | ||
378 | x_mbr->boot_partition); | ||
379 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "start head: %x\n", | ||
380 | x_mbr->start_head); | ||
381 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "start sector: %x\n", | ||
382 | x_mbr->start_sector); | ||
383 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "start cylinder: %x\n", | ||
384 | x_mbr->start_cylinder); | ||
385 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "partition type: %x\n", | ||
386 | x_mbr->partition_type); | ||
387 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "end head: %x\n", | ||
388 | x_mbr->end_head); | ||
389 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "end sector: %x\n", | ||
390 | x_mbr->end_sector); | ||
391 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "end cylinder: %x\n", | ||
392 | x_mbr->end_cylinder); | ||
393 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "start sectors: %x\n", | ||
394 | x_mbr->start_sectors); | ||
395 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, | ||
396 | "sectors per partition: %x\n", | ||
397 | x_mbr->sectors_per_partition); | ||
398 | return rc; | ||
399 | } | ||
400 | |||
401 | static ssize_t mspro_block_attr_show_devinfo(struct device *dev, | ||
402 | struct device_attribute *attr, | ||
403 | char *buffer) | ||
404 | { | ||
405 | struct mspro_sys_attr *x_attr = container_of(attr, | ||
406 | struct mspro_sys_attr, | ||
407 | dev_attr); | ||
408 | struct mspro_devinfo *x_devinfo = x_attr->data; | ||
409 | ssize_t rc = 0; | ||
410 | |||
411 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "cylinders: %x\n", | ||
412 | be16_to_cpu(x_devinfo->cylinders)); | ||
413 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "heads: %x\n", | ||
414 | be16_to_cpu(x_devinfo->heads)); | ||
415 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "bytes per track: %x\n", | ||
416 | be16_to_cpu(x_devinfo->bytes_per_track)); | ||
417 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "bytes per sector: %x\n", | ||
418 | be16_to_cpu(x_devinfo->bytes_per_sector)); | ||
419 | rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "sectors per track: %x\n", | ||
420 | be16_to_cpu(x_devinfo->sectors_per_track)); | ||
421 | return rc; | ||
422 | } | ||
423 | |||
424 | static sysfs_show_t mspro_block_attr_show(unsigned char tag) | ||
425 | { | ||
426 | switch (tag) { | ||
427 | case MSPRO_BLOCK_ID_SYSINFO: | ||
428 | return mspro_block_attr_show_sysinfo; | ||
429 | case MSPRO_BLOCK_ID_MODELNAME: | ||
430 | return mspro_block_attr_show_modelname; | ||
431 | case MSPRO_BLOCK_ID_MBR: | ||
432 | return mspro_block_attr_show_mbr; | ||
433 | case MSPRO_BLOCK_ID_DEVINFO: | ||
434 | return mspro_block_attr_show_devinfo; | ||
435 | default: | ||
436 | return mspro_block_attr_show_default; | ||
437 | } | ||
438 | } | ||
439 | |||
440 | /*** Protocol handlers ***/ | ||
441 | |||
442 | /* | ||
443 | * Functions prefixed with "h_" are protocol callbacks. They can be called from | ||
444 | * interrupt context. Return value of 0 means that request processing is still | ||
445 | * ongoing, while special error value of -EAGAIN means that current request is | ||
446 | * finished (and request processor should come back some time later). | ||
447 | */ | ||
448 | |||
449 | static int h_mspro_block_req_init(struct memstick_dev *card, | ||
450 | struct memstick_request **mrq) | ||
451 | { | ||
452 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
453 | |||
454 | *mrq = &card->current_mrq; | ||
455 | card->next_request = msb->mrq_handler; | ||
456 | return 0; | ||
457 | } | ||
458 | |||
459 | static int h_mspro_block_default(struct memstick_dev *card, | ||
460 | struct memstick_request **mrq) | ||
461 | { | ||
462 | complete(&card->mrq_complete); | ||
463 | if (!(*mrq)->error) | ||
464 | return -EAGAIN; | ||
465 | else | ||
466 | return (*mrq)->error; | ||
467 | } | ||
468 | |||
469 | static int h_mspro_block_get_ro(struct memstick_dev *card, | ||
470 | struct memstick_request **mrq) | ||
471 | { | ||
472 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
473 | |||
474 | if ((*mrq)->error) { | ||
475 | complete(&card->mrq_complete); | ||
476 | return (*mrq)->error; | ||
477 | } | ||
478 | |||
479 | if ((*mrq)->data[offsetof(struct ms_status_register, status0)] | ||
480 | & MEMSTICK_STATUS0_WP) | ||
481 | msb->read_only = 1; | ||
482 | else | ||
483 | msb->read_only = 0; | ||
484 | |||
485 | complete(&card->mrq_complete); | ||
486 | return -EAGAIN; | ||
487 | } | ||
488 | |||
489 | static int h_mspro_block_wait_for_ced(struct memstick_dev *card, | ||
490 | struct memstick_request **mrq) | ||
491 | { | ||
492 | if ((*mrq)->error) { | ||
493 | complete(&card->mrq_complete); | ||
494 | return (*mrq)->error; | ||
495 | } | ||
496 | |||
497 | dev_dbg(&card->dev, "wait for ced: value %x\n", (*mrq)->data[0]); | ||
498 | |||
499 | if ((*mrq)->data[0] & (MEMSTICK_INT_CMDNAK | MEMSTICK_INT_ERR)) { | ||
500 | card->current_mrq.error = -EFAULT; | ||
501 | complete(&card->mrq_complete); | ||
502 | return card->current_mrq.error; | ||
503 | } | ||
504 | |||
505 | if (!((*mrq)->data[0] & MEMSTICK_INT_CED)) | ||
506 | return 0; | ||
507 | else { | ||
508 | card->current_mrq.error = 0; | ||
509 | complete(&card->mrq_complete); | ||
510 | return -EAGAIN; | ||
511 | } | ||
512 | } | ||
513 | |||
514 | static int h_mspro_block_transfer_data(struct memstick_dev *card, | ||
515 | struct memstick_request **mrq) | ||
516 | { | ||
517 | struct memstick_host *host = card->host; | ||
518 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
519 | unsigned char t_val = 0; | ||
520 | struct scatterlist t_sg = { 0 }; | ||
521 | size_t t_offset; | ||
522 | |||
523 | if ((*mrq)->error) { | ||
524 | complete(&card->mrq_complete); | ||
525 | return (*mrq)->error; | ||
526 | } | ||
527 | |||
528 | switch ((*mrq)->tpc) { | ||
529 | case MS_TPC_WRITE_REG: | ||
530 | memstick_init_req(*mrq, MS_TPC_SET_CMD, &msb->transfer_cmd, 1); | ||
531 | (*mrq)->get_int_reg = 1; | ||
532 | return 0; | ||
533 | case MS_TPC_SET_CMD: | ||
534 | t_val = (*mrq)->int_reg; | ||
535 | memstick_init_req(*mrq, MS_TPC_GET_INT, NULL, 1); | ||
536 | if (host->caps & MEMSTICK_CAP_AUTO_GET_INT) | ||
537 | goto has_int_reg; | ||
538 | return 0; | ||
539 | case MS_TPC_GET_INT: | ||
540 | t_val = (*mrq)->data[0]; | ||
541 | has_int_reg: | ||
542 | if (t_val & (MEMSTICK_INT_CMDNAK | MEMSTICK_INT_ERR)) { | ||
543 | t_val = MSPRO_CMD_STOP; | ||
544 | memstick_init_req(*mrq, MS_TPC_SET_CMD, &t_val, 1); | ||
545 | card->next_request = h_mspro_block_default; | ||
546 | return 0; | ||
547 | } | ||
548 | |||
549 | if (msb->current_page | ||
550 | == (msb->req_sg[msb->current_seg].length | ||
551 | / msb->page_size)) { | ||
552 | msb->current_page = 0; | ||
553 | msb->current_seg++; | ||
554 | |||
555 | if (msb->current_seg == msb->seg_count) { | ||
556 | if (t_val & MEMSTICK_INT_CED) { | ||
557 | complete(&card->mrq_complete); | ||
558 | return -EAGAIN; | ||
559 | } else { | ||
560 | card->next_request | ||
561 | = h_mspro_block_wait_for_ced; | ||
562 | memstick_init_req(*mrq, MS_TPC_GET_INT, | ||
563 | NULL, 1); | ||
564 | return 0; | ||
565 | } | ||
566 | } | ||
567 | } | ||
568 | |||
569 | if (!(t_val & MEMSTICK_INT_BREQ)) { | ||
570 | memstick_init_req(*mrq, MS_TPC_GET_INT, NULL, 1); | ||
571 | return 0; | ||
572 | } | ||
573 | |||
574 | t_offset = msb->req_sg[msb->current_seg].offset; | ||
575 | t_offset += msb->current_page * msb->page_size; | ||
576 | |||
577 | sg_set_page(&t_sg, | ||
578 | nth_page(sg_page(&(msb->req_sg[msb->current_seg])), | ||
579 | t_offset >> PAGE_SHIFT), | ||
580 | msb->page_size, offset_in_page(t_offset)); | ||
581 | |||
582 | memstick_init_req_sg(*mrq, msb->data_dir == READ | ||
583 | ? MS_TPC_READ_LONG_DATA | ||
584 | : MS_TPC_WRITE_LONG_DATA, | ||
585 | &t_sg); | ||
586 | (*mrq)->get_int_reg = 1; | ||
587 | return 0; | ||
588 | case MS_TPC_READ_LONG_DATA: | ||
589 | case MS_TPC_WRITE_LONG_DATA: | ||
590 | msb->current_page++; | ||
591 | if (host->caps & MEMSTICK_CAP_AUTO_GET_INT) { | ||
592 | t_val = (*mrq)->int_reg; | ||
593 | goto has_int_reg; | ||
594 | } else { | ||
595 | memstick_init_req(*mrq, MS_TPC_GET_INT, NULL, 1); | ||
596 | return 0; | ||
597 | } | ||
598 | |||
599 | default: | ||
600 | BUG(); | ||
601 | } | ||
602 | } | ||
603 | |||
604 | /*** Data transfer ***/ | ||
605 | |||
606 | static void mspro_block_process_request(struct memstick_dev *card, | ||
607 | struct request *req) | ||
608 | { | ||
609 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
610 | struct mspro_param_register param; | ||
611 | int rc, chunk, cnt; | ||
612 | unsigned short page_count; | ||
613 | sector_t t_sec; | ||
614 | unsigned long flags; | ||
615 | |||
616 | do { | ||
617 | page_count = 0; | ||
618 | msb->current_seg = 0; | ||
619 | msb->seg_count = blk_rq_map_sg(req->q, req, msb->req_sg); | ||
620 | |||
621 | if (msb->seg_count) { | ||
622 | msb->current_page = 0; | ||
623 | for (rc = 0; rc < msb->seg_count; rc++) | ||
624 | page_count += msb->req_sg[rc].length | ||
625 | / msb->page_size; | ||
626 | |||
627 | t_sec = req->sector; | ||
628 | sector_div(t_sec, msb->page_size >> 9); | ||
629 | param.system = msb->system; | ||
630 | param.data_count = cpu_to_be16(page_count); | ||
631 | param.data_address = cpu_to_be32((uint32_t)t_sec); | ||
632 | param.cmd_param = 0; | ||
633 | |||
634 | msb->data_dir = rq_data_dir(req); | ||
635 | msb->transfer_cmd = msb->data_dir == READ | ||
636 | ? MSPRO_CMD_READ_DATA | ||
637 | : MSPRO_CMD_WRITE_DATA; | ||
638 | |||
639 | dev_dbg(&card->dev, "data transfer: cmd %x, " | ||
640 | "lba %x, count %x\n", msb->transfer_cmd, | ||
641 | be32_to_cpu(param.data_address), | ||
642 | page_count); | ||
643 | |||
644 | card->next_request = h_mspro_block_req_init; | ||
645 | msb->mrq_handler = h_mspro_block_transfer_data; | ||
646 | memstick_init_req(&card->current_mrq, MS_TPC_WRITE_REG, | ||
647 | ¶m, sizeof(param)); | ||
648 | memstick_new_req(card->host); | ||
649 | wait_for_completion(&card->mrq_complete); | ||
650 | rc = card->current_mrq.error; | ||
651 | |||
652 | if (rc || (card->current_mrq.tpc == MSPRO_CMD_STOP)) { | ||
653 | for (cnt = 0; cnt < msb->current_seg; cnt++) | ||
654 | page_count += msb->req_sg[cnt].length | ||
655 | / msb->page_size; | ||
656 | |||
657 | if (msb->current_page) | ||
658 | page_count += msb->current_page - 1; | ||
659 | |||
660 | if (page_count && (msb->data_dir == READ)) | ||
661 | rc = msb->page_size * page_count; | ||
662 | else | ||
663 | rc = -EIO; | ||
664 | } else | ||
665 | rc = msb->page_size * page_count; | ||
666 | } else | ||
667 | rc = -EFAULT; | ||
668 | |||
669 | spin_lock_irqsave(&msb->q_lock, flags); | ||
670 | if (rc >= 0) | ||
671 | chunk = __blk_end_request(req, 0, rc); | ||
672 | else | ||
673 | chunk = __blk_end_request(req, rc, 0); | ||
674 | |||
675 | dev_dbg(&card->dev, "end chunk %d, %d\n", rc, chunk); | ||
676 | spin_unlock_irqrestore(&msb->q_lock, flags); | ||
677 | } while (chunk); | ||
678 | } | ||
679 | |||
680 | static int mspro_block_has_request(struct mspro_block_data *msb) | ||
681 | { | ||
682 | int rc = 0; | ||
683 | unsigned long flags; | ||
684 | |||
685 | spin_lock_irqsave(&msb->q_lock, flags); | ||
686 | if (kthread_should_stop() || msb->has_request) | ||
687 | rc = 1; | ||
688 | spin_unlock_irqrestore(&msb->q_lock, flags); | ||
689 | return rc; | ||
690 | } | ||
691 | |||
692 | static int mspro_block_queue_thread(void *data) | ||
693 | { | ||
694 | struct memstick_dev *card = data; | ||
695 | struct memstick_host *host = card->host; | ||
696 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
697 | struct request *req; | ||
698 | unsigned long flags; | ||
699 | |||
700 | while (1) { | ||
701 | wait_event(msb->q_wait, mspro_block_has_request(msb)); | ||
702 | dev_dbg(&card->dev, "thread iter\n"); | ||
703 | |||
704 | spin_lock_irqsave(&msb->q_lock, flags); | ||
705 | req = elv_next_request(msb->queue); | ||
706 | dev_dbg(&card->dev, "next req %p\n", req); | ||
707 | if (!req) { | ||
708 | msb->has_request = 0; | ||
709 | if (kthread_should_stop()) { | ||
710 | spin_unlock_irqrestore(&msb->q_lock, flags); | ||
711 | break; | ||
712 | } | ||
713 | } else | ||
714 | msb->has_request = 1; | ||
715 | spin_unlock_irqrestore(&msb->q_lock, flags); | ||
716 | |||
717 | if (req) { | ||
718 | mutex_lock(&host->lock); | ||
719 | mspro_block_process_request(card, req); | ||
720 | mutex_unlock(&host->lock); | ||
721 | } | ||
722 | } | ||
723 | dev_dbg(&card->dev, "thread finished\n"); | ||
724 | return 0; | ||
725 | } | ||
726 | |||
727 | static void mspro_block_request(struct request_queue *q) | ||
728 | { | ||
729 | struct memstick_dev *card = q->queuedata; | ||
730 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
731 | struct request *req = NULL; | ||
732 | |||
733 | if (msb->q_thread) { | ||
734 | msb->has_request = 1; | ||
735 | wake_up_all(&msb->q_wait); | ||
736 | } else { | ||
737 | while ((req = elv_next_request(q)) != NULL) | ||
738 | end_queued_request(req, -ENODEV); | ||
739 | } | ||
740 | } | ||
741 | |||
742 | /*** Initialization ***/ | ||
743 | |||
744 | static int mspro_block_wait_for_ced(struct memstick_dev *card) | ||
745 | { | ||
746 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
747 | |||
748 | card->next_request = h_mspro_block_req_init; | ||
749 | msb->mrq_handler = h_mspro_block_wait_for_ced; | ||
750 | memstick_init_req(&card->current_mrq, MS_TPC_GET_INT, NULL, 1); | ||
751 | memstick_new_req(card->host); | ||
752 | wait_for_completion(&card->mrq_complete); | ||
753 | return card->current_mrq.error; | ||
754 | } | ||
755 | |||
756 | static int mspro_block_switch_to_parallel(struct memstick_dev *card) | ||
757 | { | ||
758 | struct memstick_host *host = card->host; | ||
759 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
760 | struct mspro_param_register param = { | ||
761 | .system = 0, | ||
762 | .data_count = 0, | ||
763 | .data_address = 0, | ||
764 | .cmd_param = 0 | ||
765 | }; | ||
766 | |||
767 | card->next_request = h_mspro_block_req_init; | ||
768 | msb->mrq_handler = h_mspro_block_default; | ||
769 | memstick_init_req(&card->current_mrq, MS_TPC_WRITE_REG, ¶m, | ||
770 | sizeof(param)); | ||
771 | memstick_new_req(host); | ||
772 | wait_for_completion(&card->mrq_complete); | ||
773 | if (card->current_mrq.error) | ||
774 | return card->current_mrq.error; | ||
775 | |||
776 | msb->system = 0; | ||
777 | host->set_param(host, MEMSTICK_INTERFACE, MEMSTICK_PARALLEL); | ||
778 | |||
779 | card->next_request = h_mspro_block_req_init; | ||
780 | msb->mrq_handler = h_mspro_block_default; | ||
781 | memstick_init_req(&card->current_mrq, MS_TPC_GET_INT, NULL, 1); | ||
782 | memstick_new_req(card->host); | ||
783 | wait_for_completion(&card->mrq_complete); | ||
784 | |||
785 | if (card->current_mrq.error) { | ||
786 | msb->system = 0x80; | ||
787 | host->set_param(host, MEMSTICK_INTERFACE, MEMSTICK_SERIAL); | ||
788 | return -EFAULT; | ||
789 | } | ||
790 | |||
791 | return 0; | ||
792 | } | ||
793 | |||
794 | /* Memory allocated for attributes by this function should be freed by | ||
795 | * mspro_block_data_clear, no matter if the initialization process succeded | ||
796 | * or failed. | ||
797 | */ | ||
798 | static int mspro_block_read_attributes(struct memstick_dev *card) | ||
799 | { | ||
800 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
801 | struct mspro_param_register param = { | ||
802 | .system = msb->system, | ||
803 | .data_count = cpu_to_be16(1), | ||
804 | .data_address = 0, | ||
805 | .cmd_param = 0 | ||
806 | }; | ||
807 | struct mspro_attribute *attr = NULL; | ||
808 | struct mspro_sys_attr *s_attr = NULL; | ||
809 | unsigned char *buffer = NULL; | ||
810 | int cnt, rc, attr_count; | ||
811 | unsigned int addr; | ||
812 | unsigned short page_count; | ||
813 | |||
814 | attr = kmalloc(msb->page_size, GFP_KERNEL); | ||
815 | if (!attr) | ||
816 | return -ENOMEM; | ||
817 | |||
818 | sg_init_one(&msb->req_sg[0], attr, msb->page_size); | ||
819 | msb->seg_count = 1; | ||
820 | msb->current_seg = 0; | ||
821 | msb->current_page = 0; | ||
822 | msb->data_dir = READ; | ||
823 | msb->transfer_cmd = MSPRO_CMD_READ_ATRB; | ||
824 | |||
825 | card->next_request = h_mspro_block_req_init; | ||
826 | msb->mrq_handler = h_mspro_block_transfer_data; | ||
827 | memstick_init_req(&card->current_mrq, MS_TPC_WRITE_REG, ¶m, | ||
828 | sizeof(param)); | ||
829 | memstick_new_req(card->host); | ||
830 | wait_for_completion(&card->mrq_complete); | ||
831 | if (card->current_mrq.error) { | ||
832 | rc = card->current_mrq.error; | ||
833 | goto out_free_attr; | ||
834 | } | ||
835 | |||
836 | if (be16_to_cpu(attr->signature) != MSPRO_BLOCK_SIGNATURE) { | ||
837 | printk(KERN_ERR "%s: unrecognized device signature %x\n", | ||
838 | card->dev.bus_id, be16_to_cpu(attr->signature)); | ||
839 | rc = -ENODEV; | ||
840 | goto out_free_attr; | ||
841 | } | ||
842 | |||
843 | if (attr->count > MSPRO_BLOCK_MAX_ATTRIBUTES) { | ||
844 | printk(KERN_WARNING "%s: way too many attribute entries\n", | ||
845 | card->dev.bus_id); | ||
846 | attr_count = MSPRO_BLOCK_MAX_ATTRIBUTES; | ||
847 | } else | ||
848 | attr_count = attr->count; | ||
849 | |||
850 | msb->attr_group.attrs = kzalloc((attr_count + 1) | ||
851 | * sizeof(struct attribute), | ||
852 | GFP_KERNEL); | ||
853 | if (!msb->attr_group.attrs) { | ||
854 | rc = -ENOMEM; | ||
855 | goto out_free_attr; | ||
856 | } | ||
857 | msb->attr_group.name = "media_attributes"; | ||
858 | |||
859 | buffer = kmalloc(msb->page_size, GFP_KERNEL); | ||
860 | if (!buffer) { | ||
861 | rc = -ENOMEM; | ||
862 | goto out_free_attr; | ||
863 | } | ||
864 | memcpy(buffer, (char *)attr, msb->page_size); | ||
865 | page_count = 1; | ||
866 | |||
867 | for (cnt = 0; cnt < attr_count; ++cnt) { | ||
868 | s_attr = kzalloc(sizeof(struct mspro_sys_attr), GFP_KERNEL); | ||
869 | if (!s_attr) { | ||
870 | rc = -ENOMEM; | ||
871 | goto out_free_buffer; | ||
872 | } | ||
873 | |||
874 | msb->attr_group.attrs[cnt] = &s_attr->dev_attr.attr; | ||
875 | addr = be32_to_cpu(attr->entries[cnt].address); | ||
876 | rc = be32_to_cpu(attr->entries[cnt].size); | ||
877 | dev_dbg(&card->dev, "adding attribute %d: id %x, address %x, " | ||
878 | "size %x\n", cnt, attr->entries[cnt].id, addr, rc); | ||
879 | s_attr->id = attr->entries[cnt].id; | ||
880 | if (mspro_block_attr_name(s_attr->id)) | ||
881 | snprintf(s_attr->name, sizeof(s_attr->name), "%s", | ||
882 | mspro_block_attr_name(attr->entries[cnt].id)); | ||
883 | else | ||
884 | snprintf(s_attr->name, sizeof(s_attr->name), | ||
885 | "attr_x%02x", attr->entries[cnt].id); | ||
886 | |||
887 | s_attr->dev_attr.attr.name = s_attr->name; | ||
888 | s_attr->dev_attr.attr.mode = S_IRUGO; | ||
889 | s_attr->dev_attr.attr.owner = THIS_MODULE; | ||
890 | s_attr->dev_attr.show = mspro_block_attr_show(s_attr->id); | ||
891 | |||
892 | if (!rc) | ||
893 | continue; | ||
894 | |||
895 | s_attr->size = rc; | ||
896 | s_attr->data = kmalloc(rc, GFP_KERNEL); | ||
897 | if (!s_attr->data) { | ||
898 | rc = -ENOMEM; | ||
899 | goto out_free_buffer; | ||
900 | } | ||
901 | |||
902 | if (((addr / msb->page_size) | ||
903 | == be32_to_cpu(param.data_address)) | ||
904 | && (((addr + rc - 1) / msb->page_size) | ||
905 | == be32_to_cpu(param.data_address))) { | ||
906 | memcpy(s_attr->data, buffer + addr % msb->page_size, | ||
907 | rc); | ||
908 | continue; | ||
909 | } | ||
910 | |||
911 | if (page_count <= (rc / msb->page_size)) { | ||
912 | kfree(buffer); | ||
913 | page_count = (rc / msb->page_size) + 1; | ||
914 | buffer = kmalloc(page_count * msb->page_size, | ||
915 | GFP_KERNEL); | ||
916 | if (!buffer) { | ||
917 | rc = -ENOMEM; | ||
918 | goto out_free_attr; | ||
919 | } | ||
920 | } | ||
921 | |||
922 | param.system = msb->system; | ||
923 | param.data_count = cpu_to_be16((rc / msb->page_size) + 1); | ||
924 | param.data_address = cpu_to_be32(addr / msb->page_size); | ||
925 | param.cmd_param = 0; | ||
926 | |||
927 | sg_init_one(&msb->req_sg[0], buffer, | ||
928 | be16_to_cpu(param.data_count) * msb->page_size); | ||
929 | msb->seg_count = 1; | ||
930 | msb->current_seg = 0; | ||
931 | msb->current_page = 0; | ||
932 | msb->data_dir = READ; | ||
933 | msb->transfer_cmd = MSPRO_CMD_READ_ATRB; | ||
934 | |||
935 | dev_dbg(&card->dev, "reading attribute pages %x, %x\n", | ||
936 | be32_to_cpu(param.data_address), | ||
937 | be16_to_cpu(param.data_count)); | ||
938 | |||
939 | card->next_request = h_mspro_block_req_init; | ||
940 | msb->mrq_handler = h_mspro_block_transfer_data; | ||
941 | memstick_init_req(&card->current_mrq, MS_TPC_WRITE_REG, | ||
942 | (char *)¶m, sizeof(param)); | ||
943 | memstick_new_req(card->host); | ||
944 | wait_for_completion(&card->mrq_complete); | ||
945 | if (card->current_mrq.error) { | ||
946 | rc = card->current_mrq.error; | ||
947 | goto out_free_buffer; | ||
948 | } | ||
949 | |||
950 | memcpy(s_attr->data, buffer + addr % msb->page_size, rc); | ||
951 | } | ||
952 | |||
953 | rc = 0; | ||
954 | out_free_buffer: | ||
955 | kfree(buffer); | ||
956 | out_free_attr: | ||
957 | kfree(attr); | ||
958 | return rc; | ||
959 | } | ||
960 | |||
961 | static int mspro_block_init_card(struct memstick_dev *card) | ||
962 | { | ||
963 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
964 | struct memstick_host *host = card->host; | ||
965 | int rc = 0; | ||
966 | |||
967 | msb->system = 0x80; | ||
968 | card->reg_addr.r_offset = offsetof(struct mspro_register, status); | ||
969 | card->reg_addr.r_length = sizeof(struct ms_status_register); | ||
970 | card->reg_addr.w_offset = offsetof(struct mspro_register, param); | ||
971 | card->reg_addr.w_length = sizeof(struct mspro_param_register); | ||
972 | |||
973 | if (memstick_set_rw_addr(card)) | ||
974 | return -EIO; | ||
975 | |||
976 | if (host->caps & MEMSTICK_CAP_PARALLEL) { | ||
977 | if (mspro_block_switch_to_parallel(card)) | ||
978 | printk(KERN_WARNING "%s: could not switch to " | ||
979 | "parallel interface\n", card->dev.bus_id); | ||
980 | } | ||
981 | |||
982 | rc = mspro_block_wait_for_ced(card); | ||
983 | if (rc) | ||
984 | return rc; | ||
985 | dev_dbg(&card->dev, "card activated\n"); | ||
986 | |||
987 | card->next_request = h_mspro_block_req_init; | ||
988 | msb->mrq_handler = h_mspro_block_get_ro; | ||
989 | memstick_init_req(&card->current_mrq, MS_TPC_READ_REG, NULL, | ||
990 | sizeof(struct ms_status_register)); | ||
991 | memstick_new_req(card->host); | ||
992 | wait_for_completion(&card->mrq_complete); | ||
993 | if (card->current_mrq.error) | ||
994 | return card->current_mrq.error; | ||
995 | |||
996 | dev_dbg(&card->dev, "card r/w status %d\n", msb->read_only ? 0 : 1); | ||
997 | |||
998 | msb->page_size = 512; | ||
999 | rc = mspro_block_read_attributes(card); | ||
1000 | if (rc) | ||
1001 | return rc; | ||
1002 | |||
1003 | dev_dbg(&card->dev, "attributes loaded\n"); | ||
1004 | return 0; | ||
1005 | |||
1006 | } | ||
1007 | |||
1008 | static int mspro_block_init_disk(struct memstick_dev *card) | ||
1009 | { | ||
1010 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
1011 | struct memstick_host *host = card->host; | ||
1012 | struct mspro_devinfo *dev_info = NULL; | ||
1013 | struct mspro_sys_info *sys_info = NULL; | ||
1014 | struct mspro_sys_attr *s_attr = NULL; | ||
1015 | int rc, disk_id; | ||
1016 | u64 limit = BLK_BOUNCE_HIGH; | ||
1017 | unsigned long capacity; | ||
1018 | |||
1019 | if (host->cdev.dev->dma_mask && *(host->cdev.dev->dma_mask)) | ||
1020 | limit = *(host->cdev.dev->dma_mask); | ||
1021 | |||
1022 | for (rc = 0; msb->attr_group.attrs[rc]; ++rc) { | ||
1023 | s_attr = mspro_from_sysfs_attr(msb->attr_group.attrs[rc]); | ||
1024 | |||
1025 | if (s_attr->id == MSPRO_BLOCK_ID_DEVINFO) | ||
1026 | dev_info = s_attr->data; | ||
1027 | else if (s_attr->id == MSPRO_BLOCK_ID_SYSINFO) | ||
1028 | sys_info = s_attr->data; | ||
1029 | } | ||
1030 | |||
1031 | if (!dev_info || !sys_info) | ||
1032 | return -ENODEV; | ||
1033 | |||
1034 | msb->cylinders = be16_to_cpu(dev_info->cylinders); | ||
1035 | msb->heads = be16_to_cpu(dev_info->heads); | ||
1036 | msb->sectors_per_track = be16_to_cpu(dev_info->sectors_per_track); | ||
1037 | |||
1038 | msb->page_size = be16_to_cpu(sys_info->unit_size); | ||
1039 | |||
1040 | if (!idr_pre_get(&mspro_block_disk_idr, GFP_KERNEL)) | ||
1041 | return -ENOMEM; | ||
1042 | |||
1043 | mutex_lock(&mspro_block_disk_lock); | ||
1044 | rc = idr_get_new(&mspro_block_disk_idr, card, &disk_id); | ||
1045 | mutex_unlock(&mspro_block_disk_lock); | ||
1046 | |||
1047 | if (rc) | ||
1048 | return rc; | ||
1049 | |||
1050 | if ((disk_id << MEMSTICK_PART_SHIFT) > 255) { | ||
1051 | rc = -ENOSPC; | ||
1052 | goto out_release_id; | ||
1053 | } | ||
1054 | |||
1055 | msb->disk = alloc_disk(1 << MEMSTICK_PART_SHIFT); | ||
1056 | if (!msb->disk) { | ||
1057 | rc = -ENOMEM; | ||
1058 | goto out_release_id; | ||
1059 | } | ||
1060 | |||
1061 | spin_lock_init(&msb->q_lock); | ||
1062 | init_waitqueue_head(&msb->q_wait); | ||
1063 | |||
1064 | msb->queue = blk_init_queue(mspro_block_request, &msb->q_lock); | ||
1065 | if (!msb->queue) { | ||
1066 | rc = -ENOMEM; | ||
1067 | goto out_put_disk; | ||
1068 | } | ||
1069 | |||
1070 | msb->queue->queuedata = card; | ||
1071 | |||
1072 | blk_queue_bounce_limit(msb->queue, limit); | ||
1073 | blk_queue_max_sectors(msb->queue, MSPRO_BLOCK_MAX_PAGES); | ||
1074 | blk_queue_max_phys_segments(msb->queue, MSPRO_BLOCK_MAX_SEGS); | ||
1075 | blk_queue_max_hw_segments(msb->queue, MSPRO_BLOCK_MAX_SEGS); | ||
1076 | blk_queue_max_segment_size(msb->queue, | ||
1077 | MSPRO_BLOCK_MAX_PAGES * msb->page_size); | ||
1078 | |||
1079 | msb->disk->major = major; | ||
1080 | msb->disk->first_minor = disk_id << MEMSTICK_PART_SHIFT; | ||
1081 | msb->disk->fops = &ms_block_bdops; | ||
1082 | msb->usage_count = 1; | ||
1083 | msb->disk->private_data = msb; | ||
1084 | msb->disk->queue = msb->queue; | ||
1085 | msb->disk->driverfs_dev = &card->dev; | ||
1086 | |||
1087 | sprintf(msb->disk->disk_name, "mspblk%d", disk_id); | ||
1088 | |||
1089 | blk_queue_hardsect_size(msb->queue, msb->page_size); | ||
1090 | |||
1091 | capacity = be16_to_cpu(sys_info->user_block_count); | ||
1092 | capacity *= be16_to_cpu(sys_info->block_size); | ||
1093 | capacity *= msb->page_size >> 9; | ||
1094 | set_capacity(msb->disk, capacity); | ||
1095 | dev_dbg(&card->dev, "capacity set %ld\n", capacity); | ||
1096 | msb->q_thread = kthread_run(mspro_block_queue_thread, card, | ||
1097 | DRIVER_NAME"d"); | ||
1098 | if (IS_ERR(msb->q_thread)) | ||
1099 | goto out_put_disk; | ||
1100 | |||
1101 | mutex_unlock(&host->lock); | ||
1102 | add_disk(msb->disk); | ||
1103 | mutex_lock(&host->lock); | ||
1104 | msb->active = 1; | ||
1105 | return 0; | ||
1106 | |||
1107 | out_put_disk: | ||
1108 | put_disk(msb->disk); | ||
1109 | out_release_id: | ||
1110 | mutex_lock(&mspro_block_disk_lock); | ||
1111 | idr_remove(&mspro_block_disk_idr, disk_id); | ||
1112 | mutex_unlock(&mspro_block_disk_lock); | ||
1113 | return rc; | ||
1114 | } | ||
1115 | |||
1116 | static void mspro_block_data_clear(struct mspro_block_data *msb) | ||
1117 | { | ||
1118 | int cnt; | ||
1119 | struct mspro_sys_attr *s_attr; | ||
1120 | |||
1121 | if (msb->attr_group.attrs) { | ||
1122 | for (cnt = 0; msb->attr_group.attrs[cnt]; ++cnt) { | ||
1123 | s_attr = mspro_from_sysfs_attr(msb->attr_group | ||
1124 | .attrs[cnt]); | ||
1125 | kfree(s_attr->data); | ||
1126 | kfree(s_attr); | ||
1127 | } | ||
1128 | kfree(msb->attr_group.attrs); | ||
1129 | } | ||
1130 | |||
1131 | msb->card = NULL; | ||
1132 | } | ||
1133 | |||
1134 | static int mspro_block_check_card(struct memstick_dev *card) | ||
1135 | { | ||
1136 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
1137 | |||
1138 | return (msb->active == 1); | ||
1139 | } | ||
1140 | |||
1141 | static int mspro_block_probe(struct memstick_dev *card) | ||
1142 | { | ||
1143 | struct mspro_block_data *msb; | ||
1144 | int rc = 0; | ||
1145 | |||
1146 | msb = kzalloc(sizeof(struct mspro_block_data), GFP_KERNEL); | ||
1147 | if (!msb) | ||
1148 | return -ENOMEM; | ||
1149 | memstick_set_drvdata(card, msb); | ||
1150 | msb->card = card; | ||
1151 | |||
1152 | rc = mspro_block_init_card(card); | ||
1153 | |||
1154 | if (rc) | ||
1155 | goto out_free; | ||
1156 | |||
1157 | rc = sysfs_create_group(&card->dev.kobj, &msb->attr_group); | ||
1158 | if (rc) | ||
1159 | goto out_free; | ||
1160 | |||
1161 | rc = mspro_block_init_disk(card); | ||
1162 | if (!rc) { | ||
1163 | card->check = mspro_block_check_card; | ||
1164 | return 0; | ||
1165 | } | ||
1166 | |||
1167 | sysfs_remove_group(&card->dev.kobj, &msb->attr_group); | ||
1168 | out_free: | ||
1169 | memstick_set_drvdata(card, NULL); | ||
1170 | mspro_block_data_clear(msb); | ||
1171 | kfree(msb); | ||
1172 | return rc; | ||
1173 | } | ||
1174 | |||
1175 | static void mspro_block_remove(struct memstick_dev *card) | ||
1176 | { | ||
1177 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
1178 | struct task_struct *q_thread = NULL; | ||
1179 | unsigned long flags; | ||
1180 | |||
1181 | del_gendisk(msb->disk); | ||
1182 | dev_dbg(&card->dev, "mspro block remove\n"); | ||
1183 | spin_lock_irqsave(&msb->q_lock, flags); | ||
1184 | q_thread = msb->q_thread; | ||
1185 | msb->q_thread = NULL; | ||
1186 | msb->active = 0; | ||
1187 | spin_unlock_irqrestore(&msb->q_lock, flags); | ||
1188 | |||
1189 | if (q_thread) { | ||
1190 | mutex_unlock(&card->host->lock); | ||
1191 | kthread_stop(q_thread); | ||
1192 | mutex_lock(&card->host->lock); | ||
1193 | } | ||
1194 | |||
1195 | dev_dbg(&card->dev, "queue thread stopped\n"); | ||
1196 | |||
1197 | blk_cleanup_queue(msb->queue); | ||
1198 | |||
1199 | sysfs_remove_group(&card->dev.kobj, &msb->attr_group); | ||
1200 | |||
1201 | mutex_lock(&mspro_block_disk_lock); | ||
1202 | mspro_block_data_clear(msb); | ||
1203 | mutex_unlock(&mspro_block_disk_lock); | ||
1204 | |||
1205 | mspro_block_disk_release(msb->disk); | ||
1206 | memstick_set_drvdata(card, NULL); | ||
1207 | } | ||
1208 | |||
1209 | #ifdef CONFIG_PM | ||
1210 | |||
1211 | static int mspro_block_suspend(struct memstick_dev *card, pm_message_t state) | ||
1212 | { | ||
1213 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
1214 | struct task_struct *q_thread = NULL; | ||
1215 | unsigned long flags; | ||
1216 | |||
1217 | spin_lock_irqsave(&msb->q_lock, flags); | ||
1218 | q_thread = msb->q_thread; | ||
1219 | msb->q_thread = NULL; | ||
1220 | msb->active = 0; | ||
1221 | blk_stop_queue(msb->queue); | ||
1222 | spin_unlock_irqrestore(&msb->q_lock, flags); | ||
1223 | |||
1224 | if (q_thread) | ||
1225 | kthread_stop(q_thread); | ||
1226 | |||
1227 | return 0; | ||
1228 | } | ||
1229 | |||
1230 | static int mspro_block_resume(struct memstick_dev *card) | ||
1231 | { | ||
1232 | struct mspro_block_data *msb = memstick_get_drvdata(card); | ||
1233 | unsigned long flags; | ||
1234 | int rc = 0; | ||
1235 | |||
1236 | #ifdef CONFIG_MEMSTICK_UNSAFE_RESUME | ||
1237 | |||
1238 | struct mspro_block_data *new_msb; | ||
1239 | struct memstick_host *host = card->host; | ||
1240 | struct mspro_sys_attr *s_attr, *r_attr; | ||
1241 | unsigned char cnt; | ||
1242 | |||
1243 | mutex_lock(&host->lock); | ||
1244 | new_msb = kzalloc(sizeof(struct mspro_block_data), GFP_KERNEL); | ||
1245 | if (!new_msb) { | ||
1246 | rc = -ENOMEM; | ||
1247 | goto out_unlock; | ||
1248 | } | ||
1249 | |||
1250 | new_msb->card = card; | ||
1251 | memstick_set_drvdata(card, new_msb); | ||
1252 | if (mspro_block_init_card(card)) | ||
1253 | goto out_free; | ||
1254 | |||
1255 | for (cnt = 0; new_msb->attr_group.attrs[cnt] | ||
1256 | && msb->attr_group.attrs[cnt]; ++cnt) { | ||
1257 | s_attr = mspro_from_sysfs_attr(new_msb->attr_group.attrs[cnt]); | ||
1258 | r_attr = mspro_from_sysfs_attr(msb->attr_group.attrs[cnt]); | ||
1259 | |||
1260 | if (s_attr->id == MSPRO_BLOCK_ID_SYSINFO | ||
1261 | && r_attr->id == s_attr->id) { | ||
1262 | if (memcmp(s_attr->data, r_attr->data, s_attr->size)) | ||
1263 | break; | ||
1264 | |||
1265 | memstick_set_drvdata(card, msb); | ||
1266 | msb->q_thread = kthread_run(mspro_block_queue_thread, | ||
1267 | card, DRIVER_NAME"d"); | ||
1268 | if (IS_ERR(msb->q_thread)) | ||
1269 | msb->q_thread = NULL; | ||
1270 | else | ||
1271 | msb->active = 1; | ||
1272 | |||
1273 | break; | ||
1274 | } | ||
1275 | } | ||
1276 | |||
1277 | out_free: | ||
1278 | memstick_set_drvdata(card, msb); | ||
1279 | mspro_block_data_clear(new_msb); | ||
1280 | kfree(new_msb); | ||
1281 | out_unlock: | ||
1282 | mutex_unlock(&host->lock); | ||
1283 | |||
1284 | #endif /* CONFIG_MEMSTICK_UNSAFE_RESUME */ | ||
1285 | |||
1286 | spin_lock_irqsave(&msb->q_lock, flags); | ||
1287 | blk_start_queue(msb->queue); | ||
1288 | spin_unlock_irqrestore(&msb->q_lock, flags); | ||
1289 | return rc; | ||
1290 | } | ||
1291 | |||
1292 | #else | ||
1293 | |||
1294 | #define mspro_block_suspend NULL | ||
1295 | #define mspro_block_resume NULL | ||
1296 | |||
1297 | #endif /* CONFIG_PM */ | ||
1298 | |||
1299 | static struct memstick_device_id mspro_block_id_tbl[] = { | ||
1300 | {MEMSTICK_MATCH_ALL, MEMSTICK_TYPE_PRO, MEMSTICK_CATEGORY_STORAGE_DUO, | ||
1301 | MEMSTICK_CLASS_GENERIC_DUO}, | ||
1302 | {} | ||
1303 | }; | ||
1304 | |||
1305 | |||
1306 | static struct memstick_driver mspro_block_driver = { | ||
1307 | .driver = { | ||
1308 | .name = DRIVER_NAME, | ||
1309 | .owner = THIS_MODULE | ||
1310 | }, | ||
1311 | .id_table = mspro_block_id_tbl, | ||
1312 | .probe = mspro_block_probe, | ||
1313 | .remove = mspro_block_remove, | ||
1314 | .suspend = mspro_block_suspend, | ||
1315 | .resume = mspro_block_resume | ||
1316 | }; | ||
1317 | |||
1318 | static int __init mspro_block_init(void) | ||
1319 | { | ||
1320 | int rc = -ENOMEM; | ||
1321 | |||
1322 | rc = register_blkdev(major, DRIVER_NAME); | ||
1323 | if (rc < 0) { | ||
1324 | printk(KERN_ERR DRIVER_NAME ": failed to register " | ||
1325 | "major %d, error %d\n", major, rc); | ||
1326 | return rc; | ||
1327 | } | ||
1328 | if (!major) | ||
1329 | major = rc; | ||
1330 | |||
1331 | rc = memstick_register_driver(&mspro_block_driver); | ||
1332 | if (rc) | ||
1333 | unregister_blkdev(major, DRIVER_NAME); | ||
1334 | return rc; | ||
1335 | } | ||
1336 | |||
1337 | static void __exit mspro_block_exit(void) | ||
1338 | { | ||
1339 | memstick_unregister_driver(&mspro_block_driver); | ||
1340 | unregister_blkdev(major, DRIVER_NAME); | ||
1341 | idr_destroy(&mspro_block_disk_idr); | ||
1342 | } | ||
1343 | |||
1344 | module_init(mspro_block_init); | ||
1345 | module_exit(mspro_block_exit); | ||
1346 | |||
1347 | MODULE_LICENSE("GPL"); | ||
1348 | MODULE_AUTHOR("Alex Dubov"); | ||
1349 | MODULE_DESCRIPTION("Sony MemoryStickPro block device driver"); | ||
1350 | MODULE_DEVICE_TABLE(memstick, mspro_block_id_tbl); | ||
1351 | MODULE_VERSION(DRIVER_VERSION); | ||
diff --git a/drivers/memstick/host/Kconfig b/drivers/memstick/host/Kconfig new file mode 100644 index 000000000000..c002fcc3c879 --- /dev/null +++ b/drivers/memstick/host/Kconfig | |||
@@ -0,0 +1,22 @@ | |||
1 | # | ||
2 | # MemoryStick host controller drivers | ||
3 | # | ||
4 | |||
5 | comment "MemoryStick Host Controller Drivers" | ||
6 | |||
7 | config MEMSTICK_TIFM_MS | ||
8 | tristate "TI Flash Media MemoryStick Interface support (EXPERIMENTAL)" | ||
9 | depends on EXPERIMENTAL && PCI | ||
10 | select TIFM_CORE | ||
11 | help | ||
12 | Say Y here if you want to be able to access MemoryStick cards with | ||
13 | the Texas Instruments(R) Flash Media card reader, found in many | ||
14 | laptops. | ||
15 | This option 'selects' (turns on, enables) 'TIFM_CORE', but you | ||
16 | probably also need appropriate card reader host adapter, such as | ||
17 | 'Misc devices: TI Flash Media PCI74xx/PCI76xx host adapter support | ||
18 | (TIFM_7XX1)'. | ||
19 | |||
20 | To compile this driver as a module, choose M here: the | ||
21 | module will be called tifm_ms. | ||
22 | |||
diff --git a/drivers/memstick/host/Makefile b/drivers/memstick/host/Makefile new file mode 100644 index 000000000000..ee666380efa1 --- /dev/null +++ b/drivers/memstick/host/Makefile | |||
@@ -0,0 +1,10 @@ | |||
1 | # | ||
2 | # Makefile for MemoryStick host controller drivers | ||
3 | # | ||
4 | |||
5 | ifeq ($(CONFIG_MEMSTICK_DEBUG),y) | ||
6 | EXTRA_CFLAGS += -DDEBUG | ||
7 | endif | ||
8 | |||
9 | obj-$(CONFIG_MEMSTICK_TIFM_MS) += tifm_ms.o | ||
10 | |||
diff --git a/drivers/memstick/host/tifm_ms.c b/drivers/memstick/host/tifm_ms.c new file mode 100644 index 000000000000..f55b71a4337d --- /dev/null +++ b/drivers/memstick/host/tifm_ms.c | |||
@@ -0,0 +1,685 @@ | |||
1 | /* | ||
2 | * TI FlashMedia driver | ||
3 | * | ||
4 | * Copyright (C) 2007 Alex Dubov <oakad@yahoo.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * Special thanks to Carlos Corbacho for providing various MemoryStick cards | ||
11 | * that made this driver possible. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/tifm.h> | ||
16 | #include <linux/memstick.h> | ||
17 | #include <linux/highmem.h> | ||
18 | #include <linux/scatterlist.h> | ||
19 | #include <linux/log2.h> | ||
20 | #include <asm/io.h> | ||
21 | |||
22 | #define DRIVER_NAME "tifm_ms" | ||
23 | #define DRIVER_VERSION "0.1" | ||
24 | |||
25 | static int no_dma; | ||
26 | module_param(no_dma, bool, 0644); | ||
27 | |||
28 | #define TIFM_MS_TIMEOUT 0x00100 | ||
29 | #define TIFM_MS_BADCRC 0x00200 | ||
30 | #define TIFM_MS_EOTPC 0x01000 | ||
31 | #define TIFM_MS_INT 0x02000 | ||
32 | |||
33 | /* The meaning of the bit majority in this constant is unknown. */ | ||
34 | #define TIFM_MS_SERIAL 0x04010 | ||
35 | |||
36 | #define TIFM_MS_SYS_LATCH 0x00100 | ||
37 | #define TIFM_MS_SYS_NOT_RDY 0x00800 | ||
38 | #define TIFM_MS_SYS_DATA 0x10000 | ||
39 | |||
40 | /* Hardware flags */ | ||
41 | enum { | ||
42 | CMD_READY = 0x0001, | ||
43 | FIFO_READY = 0x0002, | ||
44 | CARD_READY = 0x0004, | ||
45 | DATA_CARRY = 0x0008 | ||
46 | }; | ||
47 | |||
48 | struct tifm_ms { | ||
49 | struct tifm_dev *dev; | ||
50 | unsigned short eject:1, | ||
51 | no_dma:1; | ||
52 | unsigned short cmd_flags; | ||
53 | unsigned int mode_mask; | ||
54 | unsigned int block_pos; | ||
55 | unsigned long timeout_jiffies; | ||
56 | |||
57 | struct timer_list timer; | ||
58 | struct memstick_request *req; | ||
59 | unsigned int io_word; | ||
60 | }; | ||
61 | |||
62 | static void tifm_ms_read_fifo(struct tifm_ms *host, unsigned int fifo_offset, | ||
63 | struct page *pg, unsigned int page_off, | ||
64 | unsigned int length) | ||
65 | { | ||
66 | struct tifm_dev *sock = host->dev; | ||
67 | unsigned int cnt = 0, off = 0; | ||
68 | unsigned char *buf = kmap_atomic(pg, KM_BIO_DST_IRQ) + page_off; | ||
69 | |||
70 | if (host->cmd_flags & DATA_CARRY) { | ||
71 | while ((fifo_offset & 3) && length) { | ||
72 | buf[off++] = host->io_word & 0xff; | ||
73 | host->io_word >>= 8; | ||
74 | length--; | ||
75 | fifo_offset++; | ||
76 | } | ||
77 | if (!(fifo_offset & 3)) | ||
78 | host->cmd_flags &= ~DATA_CARRY; | ||
79 | if (!length) | ||
80 | return; | ||
81 | } | ||
82 | |||
83 | do { | ||
84 | host->io_word = readl(sock->addr + SOCK_FIFO_ACCESS | ||
85 | + fifo_offset); | ||
86 | cnt = 4; | ||
87 | while (length && cnt) { | ||
88 | buf[off++] = (host->io_word >> 8) & 0xff; | ||
89 | cnt--; | ||
90 | length--; | ||
91 | } | ||
92 | fifo_offset += 4 - cnt; | ||
93 | } while (length); | ||
94 | |||
95 | if (cnt) | ||
96 | host->cmd_flags |= DATA_CARRY; | ||
97 | |||
98 | kunmap_atomic(buf - page_off, KM_BIO_DST_IRQ); | ||
99 | } | ||
100 | |||
101 | static void tifm_ms_write_fifo(struct tifm_ms *host, unsigned int fifo_offset, | ||
102 | struct page *pg, unsigned int page_off, | ||
103 | unsigned int length) | ||
104 | { | ||
105 | struct tifm_dev *sock = host->dev; | ||
106 | unsigned int cnt = 0, off = 0; | ||
107 | unsigned char *buf = kmap_atomic(pg, KM_BIO_SRC_IRQ) + page_off; | ||
108 | |||
109 | if (host->cmd_flags & DATA_CARRY) { | ||
110 | while (fifo_offset & 3) { | ||
111 | host->io_word |= buf[off++] << (8 * (fifo_offset & 3)); | ||
112 | length--; | ||
113 | fifo_offset++; | ||
114 | } | ||
115 | if (!(fifo_offset & 3)) { | ||
116 | writel(host->io_word, sock->addr + SOCK_FIFO_ACCESS | ||
117 | + fifo_offset - 4); | ||
118 | |||
119 | host->cmd_flags &= ~DATA_CARRY; | ||
120 | } | ||
121 | if (!length) | ||
122 | return; | ||
123 | } | ||
124 | |||
125 | do { | ||
126 | cnt = 4; | ||
127 | host->io_word = 0; | ||
128 | while (length && cnt) { | ||
129 | host->io_word |= buf[off++] << (4 - cnt); | ||
130 | cnt--; | ||
131 | length--; | ||
132 | } | ||
133 | fifo_offset += 4 - cnt; | ||
134 | if (!cnt) | ||
135 | writel(host->io_word, sock->addr + SOCK_FIFO_ACCESS | ||
136 | + fifo_offset - 4); | ||
137 | |||
138 | } while (length); | ||
139 | |||
140 | if (cnt) | ||
141 | host->cmd_flags |= DATA_CARRY; | ||
142 | |||
143 | kunmap_atomic(buf - page_off, KM_BIO_SRC_IRQ); | ||
144 | } | ||
145 | |||
146 | static void tifm_ms_move_block(struct tifm_ms *host, unsigned int length) | ||
147 | { | ||
148 | unsigned int t_size; | ||
149 | unsigned int off = host->req->sg.offset + host->block_pos; | ||
150 | unsigned int p_off, p_cnt; | ||
151 | struct page *pg; | ||
152 | unsigned long flags; | ||
153 | |||
154 | dev_dbg(&host->dev->dev, "moving block\n"); | ||
155 | local_irq_save(flags); | ||
156 | t_size = length; | ||
157 | while (t_size) { | ||
158 | pg = nth_page(sg_page(&host->req->sg), off >> PAGE_SHIFT); | ||
159 | p_off = offset_in_page(off); | ||
160 | p_cnt = PAGE_SIZE - p_off; | ||
161 | p_cnt = min(p_cnt, t_size); | ||
162 | |||
163 | if (host->req->data_dir == WRITE) | ||
164 | tifm_ms_write_fifo(host, length - t_size, | ||
165 | pg, p_off, p_cnt); | ||
166 | else | ||
167 | tifm_ms_read_fifo(host, length - t_size, | ||
168 | pg, p_off, p_cnt); | ||
169 | |||
170 | t_size -= p_cnt; | ||
171 | } | ||
172 | local_irq_restore(flags); | ||
173 | } | ||
174 | |||
175 | static int tifm_ms_transfer_data(struct tifm_ms *host, int skip) | ||
176 | { | ||
177 | struct tifm_dev *sock = host->dev; | ||
178 | unsigned int length = host->req->sg.length - host->block_pos; | ||
179 | |||
180 | if (!length) | ||
181 | return 1; | ||
182 | |||
183 | if (length > TIFM_FIFO_SIZE) | ||
184 | length = TIFM_FIFO_SIZE; | ||
185 | |||
186 | if (!skip) { | ||
187 | tifm_ms_move_block(host, length); | ||
188 | host->block_pos += length; | ||
189 | } | ||
190 | |||
191 | if ((host->req->data_dir == READ) | ||
192 | && (host->block_pos == host->req->sg.length)) | ||
193 | return 1; | ||
194 | |||
195 | writel(ilog2(length) - 2, sock->addr + SOCK_FIFO_PAGE_SIZE); | ||
196 | if (host->req->data_dir == WRITE) | ||
197 | writel((1 << 8) | TIFM_DMA_TX, sock->addr + SOCK_DMA_CONTROL); | ||
198 | else | ||
199 | writel((1 << 8), sock->addr + SOCK_DMA_CONTROL); | ||
200 | |||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | static int tifm_ms_issue_cmd(struct tifm_ms *host) | ||
205 | { | ||
206 | struct tifm_dev *sock = host->dev; | ||
207 | unsigned char *data; | ||
208 | unsigned int data_len = 0, cmd = 0, cmd_mask = 0, cnt, tval = 0; | ||
209 | |||
210 | host->cmd_flags = 0; | ||
211 | |||
212 | if (host->req->io_type == MEMSTICK_IO_SG) { | ||
213 | if (!host->no_dma) { | ||
214 | if (1 != tifm_map_sg(sock, &host->req->sg, 1, | ||
215 | host->req->data_dir == READ | ||
216 | ? PCI_DMA_FROMDEVICE | ||
217 | : PCI_DMA_TODEVICE)) { | ||
218 | host->req->error = -ENOMEM; | ||
219 | return host->req->error; | ||
220 | } | ||
221 | data_len = sg_dma_len(&host->req->sg); | ||
222 | } else | ||
223 | data_len = host->req->sg.length; | ||
224 | |||
225 | writel(TIFM_FIFO_INT_SETALL, | ||
226 | sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR); | ||
227 | writel(TIFM_FIFO_ENABLE, | ||
228 | sock->addr + SOCK_FIFO_CONTROL); | ||
229 | writel(TIFM_FIFO_INTMASK, | ||
230 | sock->addr + SOCK_DMA_FIFO_INT_ENABLE_SET); | ||
231 | |||
232 | if (!host->no_dma) { | ||
233 | writel(ilog2(data_len) - 2, | ||
234 | sock->addr + SOCK_FIFO_PAGE_SIZE); | ||
235 | writel(sg_dma_address(&host->req->sg), | ||
236 | sock->addr + SOCK_DMA_ADDRESS); | ||
237 | if (host->req->data_dir == WRITE) | ||
238 | writel((1 << 8) | TIFM_DMA_TX | TIFM_DMA_EN, | ||
239 | sock->addr + SOCK_DMA_CONTROL); | ||
240 | else | ||
241 | writel((1 << 8) | TIFM_DMA_EN, | ||
242 | sock->addr + SOCK_DMA_CONTROL); | ||
243 | } else { | ||
244 | tifm_ms_transfer_data(host, | ||
245 | host->req->data_dir == READ); | ||
246 | } | ||
247 | |||
248 | cmd_mask = readl(sock->addr + SOCK_MS_SYSTEM); | ||
249 | cmd_mask |= TIFM_MS_SYS_DATA | TIFM_MS_SYS_NOT_RDY; | ||
250 | writel(cmd_mask, sock->addr + SOCK_MS_SYSTEM); | ||
251 | } else if (host->req->io_type == MEMSTICK_IO_VAL) { | ||
252 | data = host->req->data; | ||
253 | data_len = host->req->data_len; | ||
254 | |||
255 | cmd_mask = host->mode_mask | 0x2607; /* unknown constant */ | ||
256 | |||
257 | if (host->req->data_dir == WRITE) { | ||
258 | cmd_mask |= TIFM_MS_SYS_LATCH; | ||
259 | writel(cmd_mask, sock->addr + SOCK_MS_SYSTEM); | ||
260 | for (cnt = 0; (data_len - cnt) >= 4; cnt += 4) { | ||
261 | writel(TIFM_MS_SYS_LATCH | ||
262 | | readl(sock->addr + SOCK_MS_SYSTEM), | ||
263 | sock->addr + SOCK_MS_SYSTEM); | ||
264 | __raw_writel(*(unsigned int *)(data + cnt), | ||
265 | sock->addr + SOCK_MS_DATA); | ||
266 | dev_dbg(&sock->dev, "writing %x\n", | ||
267 | *(int *)(data + cnt)); | ||
268 | } | ||
269 | switch (data_len - cnt) { | ||
270 | case 3: | ||
271 | tval |= data[cnt + 2] << 16; | ||
272 | case 2: | ||
273 | tval |= data[cnt + 1] << 8; | ||
274 | case 1: | ||
275 | tval |= data[cnt]; | ||
276 | writel(TIFM_MS_SYS_LATCH | ||
277 | | readl(sock->addr + SOCK_MS_SYSTEM), | ||
278 | sock->addr + SOCK_MS_SYSTEM); | ||
279 | writel(tval, sock->addr + SOCK_MS_DATA); | ||
280 | dev_dbg(&sock->dev, "writing %x\n", tval); | ||
281 | } | ||
282 | |||
283 | writel(TIFM_MS_SYS_LATCH | ||
284 | | readl(sock->addr + SOCK_MS_SYSTEM), | ||
285 | sock + SOCK_MS_SYSTEM); | ||
286 | writel(0, sock->addr + SOCK_MS_DATA); | ||
287 | dev_dbg(&sock->dev, "writing %x\n", 0); | ||
288 | |||
289 | } else | ||
290 | writel(cmd_mask, sock->addr + SOCK_MS_SYSTEM); | ||
291 | |||
292 | cmd_mask = readl(sock->addr + SOCK_MS_SYSTEM); | ||
293 | cmd_mask &= ~TIFM_MS_SYS_DATA; | ||
294 | cmd_mask |= TIFM_MS_SYS_NOT_RDY; | ||
295 | dev_dbg(&sock->dev, "mask %x\n", cmd_mask); | ||
296 | writel(cmd_mask, sock->addr + SOCK_MS_SYSTEM); | ||
297 | } else | ||
298 | BUG(); | ||
299 | |||
300 | mod_timer(&host->timer, jiffies + host->timeout_jiffies); | ||
301 | writel(TIFM_CTRL_LED | readl(sock->addr + SOCK_CONTROL), | ||
302 | sock->addr + SOCK_CONTROL); | ||
303 | host->req->error = 0; | ||
304 | |||
305 | cmd = (host->req->tpc & 0xf) << 12; | ||
306 | cmd |= data_len; | ||
307 | writel(cmd, sock->addr + SOCK_MS_COMMAND); | ||
308 | |||
309 | dev_dbg(&sock->dev, "executing TPC %x, %x\n", cmd, cmd_mask); | ||
310 | return 0; | ||
311 | } | ||
312 | |||
313 | static void tifm_ms_complete_cmd(struct tifm_ms *host) | ||
314 | { | ||
315 | struct tifm_dev *sock = host->dev; | ||
316 | struct memstick_host *msh = tifm_get_drvdata(sock); | ||
317 | unsigned int tval = 0, data_len; | ||
318 | unsigned char *data; | ||
319 | int rc; | ||
320 | |||
321 | del_timer(&host->timer); | ||
322 | if (host->req->io_type == MEMSTICK_IO_SG) { | ||
323 | if (!host->no_dma) | ||
324 | tifm_unmap_sg(sock, &host->req->sg, 1, | ||
325 | host->req->data_dir == READ | ||
326 | ? PCI_DMA_FROMDEVICE | ||
327 | : PCI_DMA_TODEVICE); | ||
328 | } else if (host->req->io_type == MEMSTICK_IO_VAL) { | ||
329 | writel(~TIFM_MS_SYS_DATA & readl(sock->addr + SOCK_MS_SYSTEM), | ||
330 | sock->addr + SOCK_MS_SYSTEM); | ||
331 | |||
332 | data = host->req->data; | ||
333 | data_len = host->req->data_len; | ||
334 | |||
335 | if (host->req->data_dir == READ) { | ||
336 | for (rc = 0; (data_len - rc) >= 4; rc += 4) | ||
337 | *(int *)(data + rc) | ||
338 | = __raw_readl(sock->addr | ||
339 | + SOCK_MS_DATA); | ||
340 | |||
341 | if (data_len - rc) | ||
342 | tval = readl(sock->addr + SOCK_MS_DATA); | ||
343 | switch (data_len - rc) { | ||
344 | case 3: | ||
345 | data[rc + 2] = (tval >> 16) & 0xff; | ||
346 | case 2: | ||
347 | data[rc + 1] = (tval >> 8) & 0xff; | ||
348 | case 1: | ||
349 | data[rc] = tval & 0xff; | ||
350 | } | ||
351 | readl(sock->addr + SOCK_MS_DATA); | ||
352 | } | ||
353 | } | ||
354 | |||
355 | writel((~TIFM_CTRL_LED) & readl(sock->addr + SOCK_CONTROL), | ||
356 | sock->addr + SOCK_CONTROL); | ||
357 | |||
358 | do { | ||
359 | rc = memstick_next_req(msh, &host->req); | ||
360 | } while (!rc && tifm_ms_issue_cmd(host)); | ||
361 | } | ||
362 | |||
363 | static int tifm_ms_check_status(struct tifm_ms *host) | ||
364 | { | ||
365 | if (!host->req->error) { | ||
366 | if (!(host->cmd_flags & CMD_READY)) | ||
367 | return 1; | ||
368 | if ((host->req->io_type == MEMSTICK_IO_SG) | ||
369 | && !(host->cmd_flags & FIFO_READY)) | ||
370 | return 1; | ||
371 | if (host->req->need_card_int | ||
372 | && !(host->cmd_flags & CARD_READY)) | ||
373 | return 1; | ||
374 | } | ||
375 | return 0; | ||
376 | } | ||
377 | |||
378 | /* Called from interrupt handler */ | ||
379 | static void tifm_ms_data_event(struct tifm_dev *sock) | ||
380 | { | ||
381 | struct tifm_ms *host; | ||
382 | unsigned int fifo_status = 0; | ||
383 | int rc = 1; | ||
384 | |||
385 | spin_lock(&sock->lock); | ||
386 | host = memstick_priv((struct memstick_host *)tifm_get_drvdata(sock)); | ||
387 | fifo_status = readl(sock->addr + SOCK_DMA_FIFO_STATUS); | ||
388 | dev_dbg(&sock->dev, "data event: fifo_status %x, flags %x\n", | ||
389 | fifo_status, host->cmd_flags); | ||
390 | |||
391 | if (host->req) { | ||
392 | if (fifo_status & TIFM_FIFO_READY) { | ||
393 | if (!host->no_dma || tifm_ms_transfer_data(host, 0)) { | ||
394 | host->cmd_flags |= FIFO_READY; | ||
395 | rc = tifm_ms_check_status(host); | ||
396 | } | ||
397 | } | ||
398 | } | ||
399 | |||
400 | writel(fifo_status, sock->addr + SOCK_DMA_FIFO_STATUS); | ||
401 | if (!rc) | ||
402 | tifm_ms_complete_cmd(host); | ||
403 | |||
404 | spin_unlock(&sock->lock); | ||
405 | } | ||
406 | |||
407 | |||
408 | /* Called from interrupt handler */ | ||
409 | static void tifm_ms_card_event(struct tifm_dev *sock) | ||
410 | { | ||
411 | struct tifm_ms *host; | ||
412 | unsigned int host_status = 0; | ||
413 | int rc = 1; | ||
414 | |||
415 | spin_lock(&sock->lock); | ||
416 | host = memstick_priv((struct memstick_host *)tifm_get_drvdata(sock)); | ||
417 | host_status = readl(sock->addr + SOCK_MS_STATUS); | ||
418 | dev_dbg(&sock->dev, "host event: host_status %x, flags %x\n", | ||
419 | host_status, host->cmd_flags); | ||
420 | |||
421 | if (host->req) { | ||
422 | if (host_status & TIFM_MS_TIMEOUT) | ||
423 | host->req->error = -ETIME; | ||
424 | else if (host_status & TIFM_MS_BADCRC) | ||
425 | host->req->error = -EILSEQ; | ||
426 | |||
427 | if (host->req->error) { | ||
428 | writel(TIFM_FIFO_INT_SETALL, | ||
429 | sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR); | ||
430 | writel(TIFM_DMA_RESET, sock->addr + SOCK_DMA_CONTROL); | ||
431 | } | ||
432 | |||
433 | if (host_status & TIFM_MS_EOTPC) | ||
434 | host->cmd_flags |= CMD_READY; | ||
435 | if (host_status & TIFM_MS_INT) | ||
436 | host->cmd_flags |= CARD_READY; | ||
437 | |||
438 | rc = tifm_ms_check_status(host); | ||
439 | |||
440 | } | ||
441 | |||
442 | writel(TIFM_MS_SYS_NOT_RDY | readl(sock->addr + SOCK_MS_SYSTEM), | ||
443 | sock->addr + SOCK_MS_SYSTEM); | ||
444 | writel((~TIFM_MS_SYS_DATA) & readl(sock->addr + SOCK_MS_SYSTEM), | ||
445 | sock->addr + SOCK_MS_SYSTEM); | ||
446 | |||
447 | if (!rc) | ||
448 | tifm_ms_complete_cmd(host); | ||
449 | |||
450 | spin_unlock(&sock->lock); | ||
451 | return; | ||
452 | } | ||
453 | |||
454 | static void tifm_ms_request(struct memstick_host *msh) | ||
455 | { | ||
456 | struct tifm_ms *host = memstick_priv(msh); | ||
457 | struct tifm_dev *sock = host->dev; | ||
458 | unsigned long flags; | ||
459 | int rc; | ||
460 | |||
461 | spin_lock_irqsave(&sock->lock, flags); | ||
462 | if (host->req) { | ||
463 | printk(KERN_ERR "%s : unfinished request detected\n", | ||
464 | sock->dev.bus_id); | ||
465 | spin_unlock_irqrestore(&sock->lock, flags); | ||
466 | tifm_eject(host->dev); | ||
467 | return; | ||
468 | } | ||
469 | |||
470 | if (host->eject) { | ||
471 | do { | ||
472 | rc = memstick_next_req(msh, &host->req); | ||
473 | if (!rc) | ||
474 | host->req->error = -ETIME; | ||
475 | } while (!rc); | ||
476 | spin_unlock_irqrestore(&sock->lock, flags); | ||
477 | return; | ||
478 | } | ||
479 | |||
480 | do { | ||
481 | rc = memstick_next_req(msh, &host->req); | ||
482 | } while (!rc && tifm_ms_issue_cmd(host)); | ||
483 | |||
484 | spin_unlock_irqrestore(&sock->lock, flags); | ||
485 | return; | ||
486 | } | ||
487 | |||
488 | static void tifm_ms_set_param(struct memstick_host *msh, | ||
489 | enum memstick_param param, | ||
490 | int value) | ||
491 | { | ||
492 | struct tifm_ms *host = memstick_priv(msh); | ||
493 | struct tifm_dev *sock = host->dev; | ||
494 | unsigned long flags; | ||
495 | |||
496 | spin_lock_irqsave(&sock->lock, flags); | ||
497 | |||
498 | switch (param) { | ||
499 | case MEMSTICK_POWER: | ||
500 | /* this is set by card detection mechanism */ | ||
501 | break; | ||
502 | case MEMSTICK_INTERFACE: | ||
503 | if (value == MEMSTICK_SERIAL) { | ||
504 | host->mode_mask = TIFM_MS_SERIAL; | ||
505 | writel((~TIFM_CTRL_FAST_CLK) | ||
506 | & readl(sock->addr + SOCK_CONTROL), | ||
507 | sock->addr + SOCK_CONTROL); | ||
508 | } else if (value == MEMSTICK_PARALLEL) { | ||
509 | host->mode_mask = 0; | ||
510 | writel(TIFM_CTRL_FAST_CLK | ||
511 | | readl(sock->addr + SOCK_CONTROL), | ||
512 | sock->addr + SOCK_CONTROL); | ||
513 | } | ||
514 | break; | ||
515 | }; | ||
516 | |||
517 | spin_unlock_irqrestore(&sock->lock, flags); | ||
518 | } | ||
519 | |||
520 | static void tifm_ms_abort(unsigned long data) | ||
521 | { | ||
522 | struct tifm_ms *host = (struct tifm_ms *)data; | ||
523 | |||
524 | dev_dbg(&host->dev->dev, "status %x\n", | ||
525 | readl(host->dev->addr + SOCK_MS_STATUS)); | ||
526 | printk(KERN_ERR | ||
527 | "%s : card failed to respond for a long period of time " | ||
528 | "(%x, %x)\n", | ||
529 | host->dev->dev.bus_id, host->req ? host->req->tpc : 0, | ||
530 | host->cmd_flags); | ||
531 | |||
532 | tifm_eject(host->dev); | ||
533 | } | ||
534 | |||
535 | static int tifm_ms_initialize_host(struct tifm_ms *host) | ||
536 | { | ||
537 | struct tifm_dev *sock = host->dev; | ||
538 | struct memstick_host *msh = tifm_get_drvdata(sock); | ||
539 | |||
540 | host->mode_mask = TIFM_MS_SERIAL; | ||
541 | writel(0x8000, sock->addr + SOCK_MS_SYSTEM); | ||
542 | writel(0x0200 | TIFM_MS_SYS_NOT_RDY, sock->addr + SOCK_MS_SYSTEM); | ||
543 | writel(0xffffffff, sock->addr + SOCK_MS_STATUS); | ||
544 | if (tifm_has_ms_pif(sock)) | ||
545 | msh->caps |= MEMSTICK_CAP_PARALLEL; | ||
546 | |||
547 | return 0; | ||
548 | } | ||
549 | |||
550 | static int tifm_ms_probe(struct tifm_dev *sock) | ||
551 | { | ||
552 | struct memstick_host *msh; | ||
553 | struct tifm_ms *host; | ||
554 | int rc = -EIO; | ||
555 | |||
556 | if (!(TIFM_SOCK_STATE_OCCUPIED | ||
557 | & readl(sock->addr + SOCK_PRESENT_STATE))) { | ||
558 | printk(KERN_WARNING "%s : card gone, unexpectedly\n", | ||
559 | sock->dev.bus_id); | ||
560 | return rc; | ||
561 | } | ||
562 | |||
563 | msh = memstick_alloc_host(sizeof(struct tifm_ms), &sock->dev); | ||
564 | if (!msh) | ||
565 | return -ENOMEM; | ||
566 | |||
567 | host = memstick_priv(msh); | ||
568 | tifm_set_drvdata(sock, msh); | ||
569 | host->dev = sock; | ||
570 | host->timeout_jiffies = msecs_to_jiffies(1000); | ||
571 | host->no_dma = no_dma; | ||
572 | |||
573 | setup_timer(&host->timer, tifm_ms_abort, (unsigned long)host); | ||
574 | |||
575 | msh->request = tifm_ms_request; | ||
576 | msh->set_param = tifm_ms_set_param; | ||
577 | sock->card_event = tifm_ms_card_event; | ||
578 | sock->data_event = tifm_ms_data_event; | ||
579 | rc = tifm_ms_initialize_host(host); | ||
580 | |||
581 | if (!rc) | ||
582 | rc = memstick_add_host(msh); | ||
583 | if (!rc) | ||
584 | return 0; | ||
585 | |||
586 | memstick_free_host(msh); | ||
587 | return rc; | ||
588 | } | ||
589 | |||
590 | static void tifm_ms_remove(struct tifm_dev *sock) | ||
591 | { | ||
592 | struct memstick_host *msh = tifm_get_drvdata(sock); | ||
593 | struct tifm_ms *host = memstick_priv(msh); | ||
594 | int rc = 0; | ||
595 | unsigned long flags; | ||
596 | |||
597 | spin_lock_irqsave(&sock->lock, flags); | ||
598 | host->eject = 1; | ||
599 | if (host->req) { | ||
600 | del_timer(&host->timer); | ||
601 | writel(TIFM_FIFO_INT_SETALL, | ||
602 | sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR); | ||
603 | writel(TIFM_DMA_RESET, sock->addr + SOCK_DMA_CONTROL); | ||
604 | if ((host->req->io_type == MEMSTICK_IO_SG) && !host->no_dma) | ||
605 | tifm_unmap_sg(sock, &host->req->sg, 1, | ||
606 | host->req->data_dir == READ | ||
607 | ? PCI_DMA_TODEVICE | ||
608 | : PCI_DMA_FROMDEVICE); | ||
609 | host->req->error = -ETIME; | ||
610 | |||
611 | do { | ||
612 | rc = memstick_next_req(msh, &host->req); | ||
613 | if (!rc) | ||
614 | host->req->error = -ETIME; | ||
615 | } while (!rc); | ||
616 | } | ||
617 | spin_unlock_irqrestore(&sock->lock, flags); | ||
618 | |||
619 | memstick_remove_host(msh); | ||
620 | |||
621 | writel(0x0200 | TIFM_MS_SYS_NOT_RDY, sock->addr + SOCK_MS_SYSTEM); | ||
622 | writel(0xffffffff, sock->addr + SOCK_MS_STATUS); | ||
623 | |||
624 | memstick_free_host(msh); | ||
625 | } | ||
626 | |||
627 | #ifdef CONFIG_PM | ||
628 | |||
629 | static int tifm_ms_suspend(struct tifm_dev *sock, pm_message_t state) | ||
630 | { | ||
631 | return 0; | ||
632 | } | ||
633 | |||
634 | static int tifm_ms_resume(struct tifm_dev *sock) | ||
635 | { | ||
636 | struct memstick_host *msh = tifm_get_drvdata(sock); | ||
637 | struct tifm_ms *host = memstick_priv(msh); | ||
638 | |||
639 | tifm_ms_initialize_host(host); | ||
640 | memstick_detect_change(msh); | ||
641 | |||
642 | return 0; | ||
643 | } | ||
644 | |||
645 | #else | ||
646 | |||
647 | #define tifm_ms_suspend NULL | ||
648 | #define tifm_ms_resume NULL | ||
649 | |||
650 | #endif /* CONFIG_PM */ | ||
651 | |||
652 | static struct tifm_device_id tifm_ms_id_tbl[] = { | ||
653 | { TIFM_TYPE_MS }, { 0 } | ||
654 | }; | ||
655 | |||
656 | static struct tifm_driver tifm_ms_driver = { | ||
657 | .driver = { | ||
658 | .name = DRIVER_NAME, | ||
659 | .owner = THIS_MODULE | ||
660 | }, | ||
661 | .id_table = tifm_ms_id_tbl, | ||
662 | .probe = tifm_ms_probe, | ||
663 | .remove = tifm_ms_remove, | ||
664 | .suspend = tifm_ms_suspend, | ||
665 | .resume = tifm_ms_resume | ||
666 | }; | ||
667 | |||
668 | static int __init tifm_ms_init(void) | ||
669 | { | ||
670 | return tifm_register_driver(&tifm_ms_driver); | ||
671 | } | ||
672 | |||
673 | static void __exit tifm_ms_exit(void) | ||
674 | { | ||
675 | tifm_unregister_driver(&tifm_ms_driver); | ||
676 | } | ||
677 | |||
678 | MODULE_AUTHOR("Alex Dubov"); | ||
679 | MODULE_DESCRIPTION("TI FlashMedia MemoryStick driver"); | ||
680 | MODULE_LICENSE("GPL"); | ||
681 | MODULE_DEVICE_TABLE(tifm, tifm_ms_id_tbl); | ||
682 | MODULE_VERSION(DRIVER_VERSION); | ||
683 | |||
684 | module_init(tifm_ms_init); | ||
685 | module_exit(tifm_ms_exit); | ||
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index c143a86c2ea6..1abc95ca9dfa 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig | |||
@@ -114,6 +114,9 @@ config ACER_WMI | |||
114 | wireless radio and bluetooth control, and on some laptops, | 114 | wireless radio and bluetooth control, and on some laptops, |
115 | exposes the mail LED and LCD backlight. | 115 | exposes the mail LED and LCD backlight. |
116 | 116 | ||
117 | For more information about this driver see | ||
118 | <file:Documentation/laptops/acer-wmi.txt> | ||
119 | |||
117 | If you have an ACPI-WMI compatible Acer/ Wistron laptop, say Y or M | 120 | If you have an ACPI-WMI compatible Acer/ Wistron laptop, say Y or M |
118 | here. | 121 | here. |
119 | 122 | ||
@@ -152,8 +155,9 @@ config FUJITSU_LAPTOP | |||
152 | If you have a Fujitsu laptop, say Y or M here. | 155 | If you have a Fujitsu laptop, say Y or M here. |
153 | 156 | ||
154 | config TC1100_WMI | 157 | config TC1100_WMI |
155 | tristate "HP Compaq TC1100 Tablet WMI Extras" | 158 | tristate "HP Compaq TC1100 Tablet WMI Extras (EXPERIMENTAL)" |
156 | depends on X86 && !X86_64 | 159 | depends on X86 && !X86_64 |
160 | depends on EXPERIMENTAL | ||
157 | depends on ACPI | 161 | depends on ACPI |
158 | select ACPI_WMI | 162 | select ACPI_WMI |
159 | ---help--- | 163 | ---help--- |
@@ -192,7 +196,7 @@ config SONY_LAPTOP | |||
192 | screen brightness control, Fn keys and allows powering on/off some | 196 | screen brightness control, Fn keys and allows powering on/off some |
193 | devices. | 197 | devices. |
194 | 198 | ||
195 | Read <file:Documentation/sony-laptop.txt> for more information. | 199 | Read <file:Documentation/laptops/sony-laptop.txt> for more information. |
196 | 200 | ||
197 | config SONYPI_COMPAT | 201 | config SONYPI_COMPAT |
198 | bool "Sonypi compatibility" | 202 | bool "Sonypi compatibility" |
@@ -211,8 +215,9 @@ config THINKPAD_ACPI | |||
211 | This is a driver for the IBM and Lenovo ThinkPad laptops. It adds | 215 | This is a driver for the IBM and Lenovo ThinkPad laptops. It adds |
212 | support for Fn-Fx key combinations, Bluetooth control, video | 216 | support for Fn-Fx key combinations, Bluetooth control, video |
213 | output switching, ThinkLight control, UltraBay eject and more. | 217 | output switching, ThinkLight control, UltraBay eject and more. |
214 | For more information about this driver see | 218 | For more information about this driver see |
215 | <file:Documentation/thinkpad-acpi.txt> and <http://ibm-acpi.sf.net/> . | 219 | <file:Documentation/laptops/thinkpad-acpi.txt> and |
220 | <http://ibm-acpi.sf.net/> . | ||
216 | 221 | ||
217 | This driver was formerly known as ibm-acpi. | 222 | This driver was formerly known as ibm-acpi. |
218 | 223 | ||
diff --git a/drivers/misc/acer-wmi.c b/drivers/misc/acer-wmi.c index a4d677504250..d7aea93081f2 100644 --- a/drivers/misc/acer-wmi.c +++ b/drivers/misc/acer-wmi.c | |||
@@ -428,11 +428,9 @@ static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface) | |||
428 | if (value > max_brightness) | 428 | if (value > max_brightness) |
429 | return AE_BAD_PARAMETER; | 429 | return AE_BAD_PARAMETER; |
430 | switch (quirks->brightness) { | 430 | switch (quirks->brightness) { |
431 | case 1: | ||
432 | return ec_write(0x83, value); | ||
433 | default: | 431 | default: |
434 | return AE_BAD_ADDRESS; | 432 | return ec_write(0x83, value); |
435 | break; | 433 | break; |
436 | } | 434 | } |
437 | default: | 435 | default: |
438 | return AE_BAD_ADDRESS; | 436 | return AE_BAD_ADDRESS; |
diff --git a/drivers/misc/tifm_7xx1.c b/drivers/misc/tifm_7xx1.c index 54380da343a5..63a089b29545 100644 --- a/drivers/misc/tifm_7xx1.c +++ b/drivers/misc/tifm_7xx1.c | |||
@@ -302,6 +302,21 @@ static int tifm_7xx1_resume(struct pci_dev *dev) | |||
302 | 302 | ||
303 | #endif /* CONFIG_PM */ | 303 | #endif /* CONFIG_PM */ |
304 | 304 | ||
305 | static int tifm_7xx1_dummy_has_ms_pif(struct tifm_adapter *fm, | ||
306 | struct tifm_dev *sock) | ||
307 | { | ||
308 | return 0; | ||
309 | } | ||
310 | |||
311 | static int tifm_7xx1_has_ms_pif(struct tifm_adapter *fm, struct tifm_dev *sock) | ||
312 | { | ||
313 | if (((fm->num_sockets == 4) && (sock->socket_id == 2)) | ||
314 | || ((fm->num_sockets == 2) && (sock->socket_id == 0))) | ||
315 | return 1; | ||
316 | |||
317 | return 0; | ||
318 | } | ||
319 | |||
305 | static int tifm_7xx1_probe(struct pci_dev *dev, | 320 | static int tifm_7xx1_probe(struct pci_dev *dev, |
306 | const struct pci_device_id *dev_id) | 321 | const struct pci_device_id *dev_id) |
307 | { | 322 | { |
@@ -336,6 +351,7 @@ static int tifm_7xx1_probe(struct pci_dev *dev, | |||
336 | 351 | ||
337 | INIT_WORK(&fm->media_switcher, tifm_7xx1_switch_media); | 352 | INIT_WORK(&fm->media_switcher, tifm_7xx1_switch_media); |
338 | fm->eject = tifm_7xx1_eject; | 353 | fm->eject = tifm_7xx1_eject; |
354 | fm->has_ms_pif = tifm_7xx1_has_ms_pif; | ||
339 | pci_set_drvdata(dev, fm); | 355 | pci_set_drvdata(dev, fm); |
340 | 356 | ||
341 | fm->addr = ioremap(pci_resource_start(dev, 0), | 357 | fm->addr = ioremap(pci_resource_start(dev, 0), |
@@ -377,6 +393,7 @@ static void tifm_7xx1_remove(struct pci_dev *dev) | |||
377 | int cnt; | 393 | int cnt; |
378 | 394 | ||
379 | fm->eject = tifm_7xx1_dummy_eject; | 395 | fm->eject = tifm_7xx1_dummy_eject; |
396 | fm->has_ms_pif = tifm_7xx1_dummy_has_ms_pif; | ||
380 | writel(TIFM_IRQ_SETALL, fm->addr + FM_CLEAR_INTERRUPT_ENABLE); | 397 | writel(TIFM_IRQ_SETALL, fm->addr + FM_CLEAR_INTERRUPT_ENABLE); |
381 | mmiowb(); | 398 | mmiowb(); |
382 | free_irq(dev->irq, fm); | 399 | free_irq(dev->irq, fm); |
diff --git a/drivers/misc/tifm_core.c b/drivers/misc/tifm_core.c index 97544052e768..82dc72a1484f 100644 --- a/drivers/misc/tifm_core.c +++ b/drivers/misc/tifm_core.c | |||
@@ -284,6 +284,13 @@ void tifm_eject(struct tifm_dev *sock) | |||
284 | } | 284 | } |
285 | EXPORT_SYMBOL(tifm_eject); | 285 | EXPORT_SYMBOL(tifm_eject); |
286 | 286 | ||
287 | int tifm_has_ms_pif(struct tifm_dev *sock) | ||
288 | { | ||
289 | struct tifm_adapter *fm = dev_get_drvdata(sock->dev.parent); | ||
290 | return fm->has_ms_pif(fm, sock); | ||
291 | } | ||
292 | EXPORT_SYMBOL(tifm_has_ms_pif); | ||
293 | |||
287 | int tifm_map_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents, | 294 | int tifm_map_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents, |
288 | int direction) | 295 | int direction) |
289 | { | 296 | { |
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig index 5fef6783c716..3b3cd0e74715 100644 --- a/drivers/mmc/host/Kconfig +++ b/drivers/mmc/host/Kconfig | |||
@@ -25,8 +25,8 @@ config MMC_PXA | |||
25 | If unsure, say N. | 25 | If unsure, say N. |
26 | 26 | ||
27 | config MMC_SDHCI | 27 | config MMC_SDHCI |
28 | tristate "Secure Digital Host Controller Interface support (EXPERIMENTAL)" | 28 | tristate "Secure Digital Host Controller Interface support" |
29 | depends on PCI && EXPERIMENTAL | 29 | depends on PCI |
30 | help | 30 | help |
31 | This select the generic Secure Digital Host Controller Interface. | 31 | This select the generic Secure Digital Host Controller Interface. |
32 | It is used by manufacturers such as Texas Instruments(R), Ricoh(R) | 32 | It is used by manufacturers such as Texas Instruments(R), Ricoh(R) |
@@ -118,8 +118,8 @@ config MMC_TIFM_SD | |||
118 | module will be called tifm_sd. | 118 | module will be called tifm_sd. |
119 | 119 | ||
120 | config MMC_SPI | 120 | config MMC_SPI |
121 | tristate "MMC/SD over SPI (EXPERIMENTAL)" | 121 | tristate "MMC/SD over SPI" |
122 | depends on MMC && SPI_MASTER && !HIGHMEM && EXPERIMENTAL | 122 | depends on MMC && SPI_MASTER && !HIGHMEM |
123 | select CRC7 | 123 | select CRC7 |
124 | select CRC_ITU_T | 124 | select CRC_ITU_T |
125 | help | 125 | help |
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c index b1edcefdd4f9..21acecc9fe3a 100644 --- a/drivers/mmc/host/at91_mci.c +++ b/drivers/mmc/host/at91_mci.c | |||
@@ -70,10 +70,11 @@ | |||
70 | 70 | ||
71 | #include <asm/io.h> | 71 | #include <asm/io.h> |
72 | #include <asm/irq.h> | 72 | #include <asm/irq.h> |
73 | #include <asm/gpio.h> | ||
74 | |||
73 | #include <asm/mach/mmc.h> | 75 | #include <asm/mach/mmc.h> |
74 | #include <asm/arch/board.h> | 76 | #include <asm/arch/board.h> |
75 | #include <asm/arch/cpu.h> | 77 | #include <asm/arch/cpu.h> |
76 | #include <asm/arch/gpio.h> | ||
77 | #include <asm/arch/at91_mci.h> | 78 | #include <asm/arch/at91_mci.h> |
78 | 79 | ||
79 | #define DRIVER_NAME "at91_mci" | 80 | #define DRIVER_NAME "at91_mci" |
@@ -659,11 +660,11 @@ static void at91_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
659 | if (host->board->vcc_pin) { | 660 | if (host->board->vcc_pin) { |
660 | switch (ios->power_mode) { | 661 | switch (ios->power_mode) { |
661 | case MMC_POWER_OFF: | 662 | case MMC_POWER_OFF: |
662 | at91_set_gpio_value(host->board->vcc_pin, 0); | 663 | gpio_set_value(host->board->vcc_pin, 0); |
663 | break; | 664 | break; |
664 | case MMC_POWER_UP: | 665 | case MMC_POWER_UP: |
665 | case MMC_POWER_ON: | 666 | case MMC_POWER_ON: |
666 | at91_set_gpio_value(host->board->vcc_pin, 1); | 667 | gpio_set_value(host->board->vcc_pin, 1); |
667 | break; | 668 | break; |
668 | } | 669 | } |
669 | } | 670 | } |
@@ -768,7 +769,7 @@ static irqreturn_t at91_mci_irq(int irq, void *devid) | |||
768 | static irqreturn_t at91_mmc_det_irq(int irq, void *_host) | 769 | static irqreturn_t at91_mmc_det_irq(int irq, void *_host) |
769 | { | 770 | { |
770 | struct at91mci_host *host = _host; | 771 | struct at91mci_host *host = _host; |
771 | int present = !at91_get_gpio_value(irq); | 772 | int present = !gpio_get_value(irq_to_gpio(irq)); |
772 | 773 | ||
773 | /* | 774 | /* |
774 | * we expect this irq on both insert and remove, | 775 | * we expect this irq on both insert and remove, |
@@ -793,7 +794,7 @@ static int at91_mci_get_ro(struct mmc_host *mmc) | |||
793 | struct at91mci_host *host = mmc_priv(mmc); | 794 | struct at91mci_host *host = mmc_priv(mmc); |
794 | 795 | ||
795 | if (host->board->wp_pin) { | 796 | if (host->board->wp_pin) { |
796 | read_only = at91_get_gpio_value(host->board->wp_pin); | 797 | read_only = gpio_get_value(host->board->wp_pin); |
797 | printk(KERN_WARNING "%s: card is %s\n", mmc_hostname(mmc), | 798 | printk(KERN_WARNING "%s: card is %s\n", mmc_hostname(mmc), |
798 | (read_only ? "read-only" : "read-write") ); | 799 | (read_only ? "read-only" : "read-write") ); |
799 | } | 800 | } |
@@ -820,8 +821,6 @@ static int __init at91_mci_probe(struct platform_device *pdev) | |||
820 | struct resource *res; | 821 | struct resource *res; |
821 | int ret; | 822 | int ret; |
822 | 823 | ||
823 | pr_debug("Probe MCI devices\n"); | ||
824 | |||
825 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 824 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
826 | if (!res) | 825 | if (!res) |
827 | return -ENXIO; | 826 | return -ENXIO; |
@@ -831,9 +830,9 @@ static int __init at91_mci_probe(struct platform_device *pdev) | |||
831 | 830 | ||
832 | mmc = mmc_alloc_host(sizeof(struct at91mci_host), &pdev->dev); | 831 | mmc = mmc_alloc_host(sizeof(struct at91mci_host), &pdev->dev); |
833 | if (!mmc) { | 832 | if (!mmc) { |
834 | pr_debug("Failed to allocate mmc host\n"); | 833 | ret = -ENOMEM; |
835 | release_mem_region(res->start, res->end - res->start + 1); | 834 | dev_dbg(&pdev->dev, "couldn't allocate mmc host\n"); |
836 | return -ENOMEM; | 835 | goto fail6; |
837 | } | 836 | } |
838 | 837 | ||
839 | mmc->ops = &at91_mci_ops; | 838 | mmc->ops = &at91_mci_ops; |
@@ -853,19 +852,44 @@ static int __init at91_mci_probe(struct platform_device *pdev) | |||
853 | if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) | 852 | if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) |
854 | mmc->caps |= MMC_CAP_4_BIT_DATA; | 853 | mmc->caps |= MMC_CAP_4_BIT_DATA; |
855 | else | 854 | else |
856 | printk("AT91 MMC: 4 wire bus mode not supported" | 855 | dev_warn(&pdev->dev, "4 wire bus mode not supported" |
857 | " - using 1 wire\n"); | 856 | " - using 1 wire\n"); |
858 | } | 857 | } |
859 | 858 | ||
860 | /* | 859 | /* |
860 | * Reserve GPIOs ... board init code makes sure these pins are set | ||
861 | * up as GPIOs with the right direction (input, except for vcc) | ||
862 | */ | ||
863 | if (host->board->det_pin) { | ||
864 | ret = gpio_request(host->board->det_pin, "mmc_detect"); | ||
865 | if (ret < 0) { | ||
866 | dev_dbg(&pdev->dev, "couldn't claim card detect pin\n"); | ||
867 | goto fail5; | ||
868 | } | ||
869 | } | ||
870 | if (host->board->wp_pin) { | ||
871 | ret = gpio_request(host->board->wp_pin, "mmc_wp"); | ||
872 | if (ret < 0) { | ||
873 | dev_dbg(&pdev->dev, "couldn't claim wp sense pin\n"); | ||
874 | goto fail4; | ||
875 | } | ||
876 | } | ||
877 | if (host->board->vcc_pin) { | ||
878 | ret = gpio_request(host->board->vcc_pin, "mmc_vcc"); | ||
879 | if (ret < 0) { | ||
880 | dev_dbg(&pdev->dev, "couldn't claim vcc switch pin\n"); | ||
881 | goto fail3; | ||
882 | } | ||
883 | } | ||
884 | |||
885 | /* | ||
861 | * Get Clock | 886 | * Get Clock |
862 | */ | 887 | */ |
863 | host->mci_clk = clk_get(&pdev->dev, "mci_clk"); | 888 | host->mci_clk = clk_get(&pdev->dev, "mci_clk"); |
864 | if (IS_ERR(host->mci_clk)) { | 889 | if (IS_ERR(host->mci_clk)) { |
865 | printk(KERN_ERR "AT91 MMC: no clock defined.\n"); | 890 | ret = -ENODEV; |
866 | mmc_free_host(mmc); | 891 | dev_dbg(&pdev->dev, "no mci_clk?\n"); |
867 | release_mem_region(res->start, res->end - res->start + 1); | 892 | goto fail2; |
868 | return -ENODEV; | ||
869 | } | 893 | } |
870 | 894 | ||
871 | /* | 895 | /* |
@@ -873,10 +897,8 @@ static int __init at91_mci_probe(struct platform_device *pdev) | |||
873 | */ | 897 | */ |
874 | host->baseaddr = ioremap(res->start, res->end - res->start + 1); | 898 | host->baseaddr = ioremap(res->start, res->end - res->start + 1); |
875 | if (!host->baseaddr) { | 899 | if (!host->baseaddr) { |
876 | clk_put(host->mci_clk); | 900 | ret = -ENOMEM; |
877 | mmc_free_host(mmc); | 901 | goto fail1; |
878 | release_mem_region(res->start, res->end - res->start + 1); | ||
879 | return -ENOMEM; | ||
880 | } | 902 | } |
881 | 903 | ||
882 | /* | 904 | /* |
@@ -890,15 +912,11 @@ static int __init at91_mci_probe(struct platform_device *pdev) | |||
890 | * Allocate the MCI interrupt | 912 | * Allocate the MCI interrupt |
891 | */ | 913 | */ |
892 | host->irq = platform_get_irq(pdev, 0); | 914 | host->irq = platform_get_irq(pdev, 0); |
893 | ret = request_irq(host->irq, at91_mci_irq, IRQF_SHARED, DRIVER_NAME, host); | 915 | ret = request_irq(host->irq, at91_mci_irq, IRQF_SHARED, |
916 | mmc_hostname(mmc), host); | ||
894 | if (ret) { | 917 | if (ret) { |
895 | printk(KERN_ERR "AT91 MMC: Failed to request MCI interrupt\n"); | 918 | dev_dbg(&pdev->dev, "request MCI interrupt failed\n"); |
896 | clk_disable(host->mci_clk); | 919 | goto fail0; |
897 | clk_put(host->mci_clk); | ||
898 | mmc_free_host(mmc); | ||
899 | iounmap(host->baseaddr); | ||
900 | release_mem_region(res->start, res->end - res->start + 1); | ||
901 | return ret; | ||
902 | } | 920 | } |
903 | 921 | ||
904 | platform_set_drvdata(pdev, mmc); | 922 | platform_set_drvdata(pdev, mmc); |
@@ -907,8 +925,7 @@ static int __init at91_mci_probe(struct platform_device *pdev) | |||
907 | * Add host to MMC layer | 925 | * Add host to MMC layer |
908 | */ | 926 | */ |
909 | if (host->board->det_pin) { | 927 | if (host->board->det_pin) { |
910 | host->present = !at91_get_gpio_value(host->board->det_pin); | 928 | host->present = !gpio_get_value(host->board->det_pin); |
911 | device_init_wakeup(&pdev->dev, 1); | ||
912 | } | 929 | } |
913 | else | 930 | else |
914 | host->present = -1; | 931 | host->present = -1; |
@@ -919,15 +936,38 @@ static int __init at91_mci_probe(struct platform_device *pdev) | |||
919 | * monitor card insertion/removal if we can | 936 | * monitor card insertion/removal if we can |
920 | */ | 937 | */ |
921 | if (host->board->det_pin) { | 938 | if (host->board->det_pin) { |
922 | ret = request_irq(host->board->det_pin, at91_mmc_det_irq, | 939 | ret = request_irq(gpio_to_irq(host->board->det_pin), |
923 | 0, DRIVER_NAME, host); | 940 | at91_mmc_det_irq, 0, mmc_hostname(mmc), host); |
924 | if (ret) | 941 | if (ret) |
925 | printk(KERN_ERR "AT91 MMC: Couldn't allocate MMC detect irq\n"); | 942 | dev_warn(&pdev->dev, "request MMC detect irq failed\n"); |
943 | else | ||
944 | device_init_wakeup(&pdev->dev, 1); | ||
926 | } | 945 | } |
927 | 946 | ||
928 | pr_debug("Added MCI driver\n"); | 947 | pr_debug("Added MCI driver\n"); |
929 | 948 | ||
930 | return 0; | 949 | return 0; |
950 | |||
951 | fail0: | ||
952 | clk_disable(host->mci_clk); | ||
953 | iounmap(host->baseaddr); | ||
954 | fail1: | ||
955 | clk_put(host->mci_clk); | ||
956 | fail2: | ||
957 | if (host->board->vcc_pin) | ||
958 | gpio_free(host->board->vcc_pin); | ||
959 | fail3: | ||
960 | if (host->board->wp_pin) | ||
961 | gpio_free(host->board->wp_pin); | ||
962 | fail4: | ||
963 | if (host->board->det_pin) | ||
964 | gpio_free(host->board->det_pin); | ||
965 | fail5: | ||
966 | mmc_free_host(mmc); | ||
967 | fail6: | ||
968 | release_mem_region(res->start, res->end - res->start + 1); | ||
969 | dev_err(&pdev->dev, "probe failed, err %d\n", ret); | ||
970 | return ret; | ||
931 | } | 971 | } |
932 | 972 | ||
933 | /* | 973 | /* |
@@ -945,9 +985,10 @@ static int __exit at91_mci_remove(struct platform_device *pdev) | |||
945 | host = mmc_priv(mmc); | 985 | host = mmc_priv(mmc); |
946 | 986 | ||
947 | if (host->board->det_pin) { | 987 | if (host->board->det_pin) { |
988 | if (device_can_wakeup(&pdev->dev)) | ||
989 | free_irq(gpio_to_irq(host->board->det_pin), host); | ||
948 | device_init_wakeup(&pdev->dev, 0); | 990 | device_init_wakeup(&pdev->dev, 0); |
949 | free_irq(host->board->det_pin, host); | 991 | gpio_free(host->board->det_pin); |
950 | cancel_delayed_work(&host->mmc->detect); | ||
951 | } | 992 | } |
952 | 993 | ||
953 | at91_mci_disable(host); | 994 | at91_mci_disable(host); |
@@ -957,6 +998,11 @@ static int __exit at91_mci_remove(struct platform_device *pdev) | |||
957 | clk_disable(host->mci_clk); /* Disable the peripheral clock */ | 998 | clk_disable(host->mci_clk); /* Disable the peripheral clock */ |
958 | clk_put(host->mci_clk); | 999 | clk_put(host->mci_clk); |
959 | 1000 | ||
1001 | if (host->board->vcc_pin) | ||
1002 | gpio_free(host->board->vcc_pin); | ||
1003 | if (host->board->wp_pin) | ||
1004 | gpio_free(host->board->wp_pin); | ||
1005 | |||
960 | iounmap(host->baseaddr); | 1006 | iounmap(host->baseaddr); |
961 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1007 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
962 | release_mem_region(res->start, res->end - res->start + 1); | 1008 | release_mem_region(res->start, res->end - res->start + 1); |
diff --git a/drivers/mmc/host/ricoh_mmc.c b/drivers/mmc/host/ricoh_mmc.c index 1e8704533bc5..a16d7609e4ee 100644 --- a/drivers/mmc/host/ricoh_mmc.c +++ b/drivers/mmc/host/ricoh_mmc.c | |||
@@ -41,10 +41,91 @@ static const struct pci_device_id pci_ids[] __devinitdata = { | |||
41 | 41 | ||
42 | MODULE_DEVICE_TABLE(pci, pci_ids); | 42 | MODULE_DEVICE_TABLE(pci, pci_ids); |
43 | 43 | ||
44 | static int ricoh_mmc_disable(struct pci_dev *fw_dev) | ||
45 | { | ||
46 | u8 write_enable; | ||
47 | u8 write_target; | ||
48 | u8 disable; | ||
49 | |||
50 | if (fw_dev->device == PCI_DEVICE_ID_RICOH_RL5C476) { | ||
51 | /* via RL5C476 */ | ||
52 | |||
53 | pci_read_config_byte(fw_dev, 0xB7, &disable); | ||
54 | if (disable & 0x02) { | ||
55 | printk(KERN_INFO DRIVER_NAME | ||
56 | ": Controller already disabled. " \ | ||
57 | "Nothing to do.\n"); | ||
58 | return -ENODEV; | ||
59 | } | ||
60 | |||
61 | pci_read_config_byte(fw_dev, 0x8E, &write_enable); | ||
62 | pci_write_config_byte(fw_dev, 0x8E, 0xAA); | ||
63 | pci_read_config_byte(fw_dev, 0x8D, &write_target); | ||
64 | pci_write_config_byte(fw_dev, 0x8D, 0xB7); | ||
65 | pci_write_config_byte(fw_dev, 0xB7, disable | 0x02); | ||
66 | pci_write_config_byte(fw_dev, 0x8E, write_enable); | ||
67 | pci_write_config_byte(fw_dev, 0x8D, write_target); | ||
68 | } else { | ||
69 | /* via R5C832 */ | ||
70 | |||
71 | pci_read_config_byte(fw_dev, 0xCB, &disable); | ||
72 | if (disable & 0x02) { | ||
73 | printk(KERN_INFO DRIVER_NAME | ||
74 | ": Controller already disabled. " \ | ||
75 | "Nothing to do.\n"); | ||
76 | return -ENODEV; | ||
77 | } | ||
78 | |||
79 | pci_read_config_byte(fw_dev, 0xCA, &write_enable); | ||
80 | pci_write_config_byte(fw_dev, 0xCA, 0x57); | ||
81 | pci_write_config_byte(fw_dev, 0xCB, disable | 0x02); | ||
82 | pci_write_config_byte(fw_dev, 0xCA, write_enable); | ||
83 | } | ||
84 | |||
85 | printk(KERN_INFO DRIVER_NAME | ||
86 | ": Controller is now disabled.\n"); | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | static int ricoh_mmc_enable(struct pci_dev *fw_dev) | ||
92 | { | ||
93 | u8 write_enable; | ||
94 | u8 write_target; | ||
95 | u8 disable; | ||
96 | |||
97 | if (fw_dev->device == PCI_DEVICE_ID_RICOH_RL5C476) { | ||
98 | /* via RL5C476 */ | ||
99 | |||
100 | pci_read_config_byte(fw_dev, 0x8E, &write_enable); | ||
101 | pci_write_config_byte(fw_dev, 0x8E, 0xAA); | ||
102 | pci_read_config_byte(fw_dev, 0x8D, &write_target); | ||
103 | pci_write_config_byte(fw_dev, 0x8D, 0xB7); | ||
104 | pci_read_config_byte(fw_dev, 0xB7, &disable); | ||
105 | pci_write_config_byte(fw_dev, 0xB7, disable & ~0x02); | ||
106 | pci_write_config_byte(fw_dev, 0x8E, write_enable); | ||
107 | pci_write_config_byte(fw_dev, 0x8D, write_target); | ||
108 | } else { | ||
109 | /* via R5C832 */ | ||
110 | |||
111 | pci_read_config_byte(fw_dev, 0xCA, &write_enable); | ||
112 | pci_read_config_byte(fw_dev, 0xCB, &disable); | ||
113 | pci_write_config_byte(fw_dev, 0xCA, 0x57); | ||
114 | pci_write_config_byte(fw_dev, 0xCB, disable & ~0x02); | ||
115 | pci_write_config_byte(fw_dev, 0xCA, write_enable); | ||
116 | } | ||
117 | |||
118 | printk(KERN_INFO DRIVER_NAME | ||
119 | ": Controller is now re-enabled.\n"); | ||
120 | |||
121 | return 0; | ||
122 | } | ||
123 | |||
44 | static int __devinit ricoh_mmc_probe(struct pci_dev *pdev, | 124 | static int __devinit ricoh_mmc_probe(struct pci_dev *pdev, |
45 | const struct pci_device_id *ent) | 125 | const struct pci_device_id *ent) |
46 | { | 126 | { |
47 | u8 rev; | 127 | u8 rev; |
128 | u8 ctrlfound = 0; | ||
48 | 129 | ||
49 | struct pci_dev *fw_dev = NULL; | 130 | struct pci_dev *fw_dev = NULL; |
50 | 131 | ||
@@ -58,34 +139,38 @@ static int __devinit ricoh_mmc_probe(struct pci_dev *pdev, | |||
58 | pci_name(pdev), (int)pdev->vendor, (int)pdev->device, | 139 | pci_name(pdev), (int)pdev->vendor, (int)pdev->device, |
59 | (int)rev); | 140 | (int)rev); |
60 | 141 | ||
61 | while ((fw_dev = pci_get_device(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, fw_dev))) { | 142 | while ((fw_dev = |
143 | pci_get_device(PCI_VENDOR_ID_RICOH, | ||
144 | PCI_DEVICE_ID_RICOH_RL5C476, fw_dev))) { | ||
62 | if (PCI_SLOT(pdev->devfn) == PCI_SLOT(fw_dev->devfn) && | 145 | if (PCI_SLOT(pdev->devfn) == PCI_SLOT(fw_dev->devfn) && |
63 | pdev->bus == fw_dev->bus) { | 146 | pdev->bus == fw_dev->bus) { |
64 | u8 write_enable; | 147 | if (ricoh_mmc_disable(fw_dev) != 0) |
65 | u8 disable; | ||
66 | |||
67 | pci_read_config_byte(fw_dev, 0xCB, &disable); | ||
68 | if (disable & 0x02) { | ||
69 | printk(KERN_INFO DRIVER_NAME | ||
70 | ": Controller already disabled. Nothing to do.\n"); | ||
71 | return -ENODEV; | 148 | return -ENODEV; |
72 | } | ||
73 | |||
74 | pci_read_config_byte(fw_dev, 0xCA, &write_enable); | ||
75 | pci_write_config_byte(fw_dev, 0xCA, 0x57); | ||
76 | pci_write_config_byte(fw_dev, 0xCB, disable | 0x02); | ||
77 | pci_write_config_byte(fw_dev, 0xCA, write_enable); | ||
78 | 149 | ||
79 | pci_set_drvdata(pdev, fw_dev); | 150 | pci_set_drvdata(pdev, fw_dev); |
80 | 151 | ||
81 | printk(KERN_INFO DRIVER_NAME | 152 | ++ctrlfound; |
82 | ": Controller is now disabled.\n"); | ||
83 | |||
84 | break; | 153 | break; |
85 | } | 154 | } |
86 | } | 155 | } |
87 | 156 | ||
88 | if (pci_get_drvdata(pdev) == NULL) { | 157 | fw_dev = NULL; |
158 | |||
159 | while (!ctrlfound && | ||
160 | (fw_dev = pci_get_device(PCI_VENDOR_ID_RICOH, | ||
161 | PCI_DEVICE_ID_RICOH_R5C832, fw_dev))) { | ||
162 | if (PCI_SLOT(pdev->devfn) == PCI_SLOT(fw_dev->devfn) && | ||
163 | pdev->bus == fw_dev->bus) { | ||
164 | if (ricoh_mmc_disable(fw_dev) != 0) | ||
165 | return -ENODEV; | ||
166 | |||
167 | pci_set_drvdata(pdev, fw_dev); | ||
168 | |||
169 | ++ctrlfound; | ||
170 | } | ||
171 | } | ||
172 | |||
173 | if (!ctrlfound) { | ||
89 | printk(KERN_WARNING DRIVER_NAME | 174 | printk(KERN_WARNING DRIVER_NAME |
90 | ": Main firewire function not found. Cannot disable controller.\n"); | 175 | ": Main firewire function not found. Cannot disable controller.\n"); |
91 | return -ENODEV; | 176 | return -ENODEV; |
@@ -96,30 +181,51 @@ static int __devinit ricoh_mmc_probe(struct pci_dev *pdev, | |||
96 | 181 | ||
97 | static void __devexit ricoh_mmc_remove(struct pci_dev *pdev) | 182 | static void __devexit ricoh_mmc_remove(struct pci_dev *pdev) |
98 | { | 183 | { |
99 | u8 write_enable; | ||
100 | u8 disable; | ||
101 | struct pci_dev *fw_dev = NULL; | 184 | struct pci_dev *fw_dev = NULL; |
102 | 185 | ||
103 | fw_dev = pci_get_drvdata(pdev); | 186 | fw_dev = pci_get_drvdata(pdev); |
104 | BUG_ON(fw_dev == NULL); | 187 | BUG_ON(fw_dev == NULL); |
105 | 188 | ||
106 | pci_read_config_byte(fw_dev, 0xCA, &write_enable); | 189 | ricoh_mmc_enable(fw_dev); |
107 | pci_read_config_byte(fw_dev, 0xCB, &disable); | ||
108 | pci_write_config_byte(fw_dev, 0xCA, 0x57); | ||
109 | pci_write_config_byte(fw_dev, 0xCB, disable & ~0x02); | ||
110 | pci_write_config_byte(fw_dev, 0xCA, write_enable); | ||
111 | |||
112 | printk(KERN_INFO DRIVER_NAME | ||
113 | ": Controller is now re-enabled.\n"); | ||
114 | 190 | ||
115 | pci_set_drvdata(pdev, NULL); | 191 | pci_set_drvdata(pdev, NULL); |
116 | } | 192 | } |
117 | 193 | ||
194 | static int ricoh_mmc_suspend(struct pci_dev *pdev, pm_message_t state) | ||
195 | { | ||
196 | struct pci_dev *fw_dev = NULL; | ||
197 | |||
198 | fw_dev = pci_get_drvdata(pdev); | ||
199 | BUG_ON(fw_dev == NULL); | ||
200 | |||
201 | printk(KERN_INFO DRIVER_NAME ": Suspending.\n"); | ||
202 | |||
203 | ricoh_mmc_enable(fw_dev); | ||
204 | |||
205 | return 0; | ||
206 | } | ||
207 | |||
208 | static int ricoh_mmc_resume(struct pci_dev *pdev) | ||
209 | { | ||
210 | struct pci_dev *fw_dev = NULL; | ||
211 | |||
212 | fw_dev = pci_get_drvdata(pdev); | ||
213 | BUG_ON(fw_dev == NULL); | ||
214 | |||
215 | printk(KERN_INFO DRIVER_NAME ": Resuming.\n"); | ||
216 | |||
217 | ricoh_mmc_disable(fw_dev); | ||
218 | |||
219 | return 0; | ||
220 | } | ||
221 | |||
118 | static struct pci_driver ricoh_mmc_driver = { | 222 | static struct pci_driver ricoh_mmc_driver = { |
119 | .name = DRIVER_NAME, | 223 | .name = DRIVER_NAME, |
120 | .id_table = pci_ids, | 224 | .id_table = pci_ids, |
121 | .probe = ricoh_mmc_probe, | 225 | .probe = ricoh_mmc_probe, |
122 | .remove = __devexit_p(ricoh_mmc_remove), | 226 | .remove = __devexit_p(ricoh_mmc_remove), |
227 | .suspend = ricoh_mmc_suspend, | ||
228 | .resume = ricoh_mmc_resume, | ||
123 | }; | 229 | }; |
124 | 230 | ||
125 | /*****************************************************************************\ | 231 | /*****************************************************************************\ |
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 785bbdcf4a58..4b673aa2dc3c 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c | |||
@@ -30,6 +30,10 @@ | |||
30 | 30 | ||
31 | static unsigned int debug_quirks = 0; | 31 | static unsigned int debug_quirks = 0; |
32 | 32 | ||
33 | /* For multi controllers in one platform case */ | ||
34 | static u16 chip_index = 0; | ||
35 | static spinlock_t index_lock; | ||
36 | |||
33 | /* | 37 | /* |
34 | * Different quirks to handle when the hardware deviates from a strict | 38 | * Different quirks to handle when the hardware deviates from a strict |
35 | * interpretation of the SDHCI specification. | 39 | * interpretation of the SDHCI specification. |
@@ -1320,7 +1324,7 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot) | |||
1320 | 1324 | ||
1321 | DBG("slot %d at 0x%08lx, irq %d\n", slot, host->addr, host->irq); | 1325 | DBG("slot %d at 0x%08lx, irq %d\n", slot, host->addr, host->irq); |
1322 | 1326 | ||
1323 | snprintf(host->slot_descr, 20, "sdhci:slot%d", slot); | 1327 | snprintf(host->slot_descr, 20, "sdhc%d:slot%d", chip->index, slot); |
1324 | 1328 | ||
1325 | ret = pci_request_region(pdev, host->bar, host->slot_descr); | 1329 | ret = pci_request_region(pdev, host->bar, host->slot_descr); |
1326 | if (ret) | 1330 | if (ret) |
@@ -1585,6 +1589,11 @@ static int __devinit sdhci_probe(struct pci_dev *pdev, | |||
1585 | chip->num_slots = slots; | 1589 | chip->num_slots = slots; |
1586 | pci_set_drvdata(pdev, chip); | 1590 | pci_set_drvdata(pdev, chip); |
1587 | 1591 | ||
1592 | /* Add for multi controller case */ | ||
1593 | spin_lock(&index_lock); | ||
1594 | chip->index = chip_index++; | ||
1595 | spin_unlock(&index_lock); | ||
1596 | |||
1588 | for (i = 0;i < slots;i++) { | 1597 | for (i = 0;i < slots;i++) { |
1589 | ret = sdhci_probe_slot(pdev, i); | 1598 | ret = sdhci_probe_slot(pdev, i); |
1590 | if (ret) { | 1599 | if (ret) { |
@@ -1645,6 +1654,8 @@ static int __init sdhci_drv_init(void) | |||
1645 | ": Secure Digital Host Controller Interface driver\n"); | 1654 | ": Secure Digital Host Controller Interface driver\n"); |
1646 | printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n"); | 1655 | printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n"); |
1647 | 1656 | ||
1657 | spin_lock_init(&index_lock); | ||
1658 | |||
1648 | return pci_register_driver(&sdhci_driver); | 1659 | return pci_register_driver(&sdhci_driver); |
1649 | } | 1660 | } |
1650 | 1661 | ||
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index e4d77b038bfa..d5a38f1b755a 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h | |||
@@ -208,6 +208,7 @@ struct sdhci_chip { | |||
208 | 208 | ||
209 | unsigned long quirks; | 209 | unsigned long quirks; |
210 | 210 | ||
211 | int index; /* Index for chip0, chip1 ...*/ | ||
211 | int num_slots; /* Slots on controller */ | 212 | int num_slots; /* Slots on controller */ |
212 | struct sdhci_host *hosts[0]; /* Pointers to hosts */ | 213 | struct sdhci_host *hosts[0]; /* Pointers to hosts */ |
213 | }; | 214 | }; |
diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c index 19e1594421a4..8dab69657b19 100644 --- a/drivers/mtd/nand/cs553x_nand.c +++ b/drivers/mtd/nand/cs553x_nand.c | |||
@@ -13,9 +13,12 @@ | |||
13 | * Overview: | 13 | * Overview: |
14 | * This is a device driver for the NAND flash controller found on | 14 | * This is a device driver for the NAND flash controller found on |
15 | * the AMD CS5535/CS5536 companion chipsets for the Geode processor. | 15 | * the AMD CS5535/CS5536 companion chipsets for the Geode processor. |
16 | * mtd-id for command line partitioning is cs553x_nand_cs[0-3] | ||
17 | * where 0-3 reflects the chip select for NAND. | ||
16 | * | 18 | * |
17 | */ | 19 | */ |
18 | 20 | ||
21 | #include <linux/kernel.h> | ||
19 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
20 | #include <linux/init.h> | 23 | #include <linux/init.h> |
21 | #include <linux/module.h> | 24 | #include <linux/module.h> |
@@ -244,6 +247,8 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr) | |||
244 | goto out_ior; | 247 | goto out_ior; |
245 | } | 248 | } |
246 | 249 | ||
250 | new_mtd->name = kasprintf(GFP_KERNEL, "cs553x_nand_cs%d", cs); | ||
251 | |||
247 | cs553x_mtd[cs] = new_mtd; | 252 | cs553x_mtd[cs] = new_mtd; |
248 | goto out; | 253 | goto out; |
249 | 254 | ||
@@ -272,12 +277,21 @@ static int is_geode(void) | |||
272 | return 0; | 277 | return 0; |
273 | } | 278 | } |
274 | 279 | ||
280 | |||
281 | #ifdef CONFIG_MTD_PARTITIONS | ||
282 | const char *part_probes[] = { "cmdlinepart", NULL }; | ||
283 | #endif | ||
284 | |||
285 | |||
275 | static int __init cs553x_init(void) | 286 | static int __init cs553x_init(void) |
276 | { | 287 | { |
277 | int err = -ENXIO; | 288 | int err = -ENXIO; |
278 | int i; | 289 | int i; |
279 | uint64_t val; | 290 | uint64_t val; |
280 | 291 | ||
292 | int mtd_parts_nb = 0; | ||
293 | struct mtd_partition *mtd_parts = NULL; | ||
294 | |||
281 | /* If the CPU isn't a Geode GX or LX, abort */ | 295 | /* If the CPU isn't a Geode GX or LX, abort */ |
282 | if (!is_geode()) | 296 | if (!is_geode()) |
283 | return -ENXIO; | 297 | return -ENXIO; |
@@ -290,7 +304,7 @@ static int __init cs553x_init(void) | |||
290 | 304 | ||
291 | /* If it doesn't have the NAND controller enabled, abort */ | 305 | /* If it doesn't have the NAND controller enabled, abort */ |
292 | rdmsrl(MSR_DIVIL_BALL_OPTS, val); | 306 | rdmsrl(MSR_DIVIL_BALL_OPTS, val); |
293 | if (val & 1) { | 307 | if (val & PIN_OPT_IDE) { |
294 | printk(KERN_INFO "CS553x NAND controller: Flash I/O not enabled in MSR_DIVIL_BALL_OPTS.\n"); | 308 | printk(KERN_INFO "CS553x NAND controller: Flash I/O not enabled in MSR_DIVIL_BALL_OPTS.\n"); |
295 | return -ENXIO; | 309 | return -ENXIO; |
296 | } | 310 | } |
@@ -306,9 +320,19 @@ static int __init cs553x_init(void) | |||
306 | do mtdconcat etc. if we want to. */ | 320 | do mtdconcat etc. if we want to. */ |
307 | for (i = 0; i < NR_CS553X_CONTROLLERS; i++) { | 321 | for (i = 0; i < NR_CS553X_CONTROLLERS; i++) { |
308 | if (cs553x_mtd[i]) { | 322 | if (cs553x_mtd[i]) { |
309 | add_mtd_device(cs553x_mtd[i]); | ||
310 | 323 | ||
311 | /* If any devices registered, return success. Else the last error. */ | 324 | /* If any devices registered, return success. Else the last error. */ |
325 | #ifdef CONFIG_MTD_PARTITIONS | ||
326 | mtd_parts_nb = parse_mtd_partitions(cs553x_mtd[i], part_probes, &mtd_parts, 0); | ||
327 | if (mtd_parts_nb > 0) { | ||
328 | printk(KERN_NOTICE "Using command line partition definition\n"); | ||
329 | add_mtd_partitions(cs553x_mtd[i], mtd_parts, mtd_parts_nb); | ||
330 | } else { | ||
331 | add_mtd_device(cs553x_mtd[i]); | ||
332 | } | ||
333 | #else | ||
334 | add_mtd_device(cs553x_mtd[i]); | ||
335 | #endif | ||
312 | err = 0; | 336 | err = 0; |
313 | } | 337 | } |
314 | } | 338 | } |
@@ -328,13 +352,14 @@ static void __exit cs553x_cleanup(void) | |||
328 | void __iomem *mmio_base; | 352 | void __iomem *mmio_base; |
329 | 353 | ||
330 | if (!mtd) | 354 | if (!mtd) |
331 | break; | 355 | continue; |
332 | 356 | ||
333 | this = cs553x_mtd[i]->priv; | 357 | this = cs553x_mtd[i]->priv; |
334 | mmio_base = this->IO_ADDR_R; | 358 | mmio_base = this->IO_ADDR_R; |
335 | 359 | ||
336 | /* Release resources, unregister device */ | 360 | /* Release resources, unregister device */ |
337 | nand_release(cs553x_mtd[i]); | 361 | nand_release(cs553x_mtd[i]); |
362 | kfree(cs553x_mtd[i]->name); | ||
338 | cs553x_mtd[i] = NULL; | 363 | cs553x_mtd[i] = NULL; |
339 | 364 | ||
340 | /* unmap physical address */ | 365 | /* unmap physical address */ |
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig index 519b4ff79f7f..8b22281b087f 100644 --- a/drivers/pcmcia/Kconfig +++ b/drivers/pcmcia/Kconfig | |||
@@ -38,6 +38,7 @@ config PCMCIA_DEBUG | |||
38 | config PCMCIA | 38 | config PCMCIA |
39 | tristate "16-bit PCMCIA support" | 39 | tristate "16-bit PCMCIA support" |
40 | select CRC32 | 40 | select CRC32 |
41 | select HAVE_IDE | ||
41 | default y | 42 | default y |
42 | ---help--- | 43 | ---help--- |
43 | This option enables support for 16-bit PCMCIA cards. Most older | 44 | This option enables support for 16-bit PCMCIA cards. Most older |
diff --git a/drivers/scsi/aic7xxx/Makefile b/drivers/scsi/aic7xxx/Makefile index 4c549540a35d..741d81861d17 100644 --- a/drivers/scsi/aic7xxx/Makefile +++ b/drivers/scsi/aic7xxx/Makefile | |||
@@ -44,8 +44,8 @@ clean-files += aic79xx_seq.h aic79xx_reg.h aic79xx_reg_print.c | |||
44 | 44 | ||
45 | # Dependencies for generated files need to be listed explicitly | 45 | # Dependencies for generated files need to be listed explicitly |
46 | 46 | ||
47 | $(addprefix $(src)/,$(aic7xxx-y:.o=.c)): $(obj)/aic7xxx_seq.h $(obj)/aic7xxx_reg.h | 47 | $(addprefix $(obj)/,$(aic7xxx-y)): $(obj)/aic7xxx_seq.h $(obj)/aic7xxx_reg.h |
48 | $(addprefix $(src)/,$(aic79xx-y:.o=.c)): $(obj)/aic79xx_seq.h $(obj)/aic79xx_reg.h | 48 | $(addprefix $(obj)/,$(aic79xx-y)): $(obj)/aic79xx_seq.h $(obj)/aic79xx_reg.h |
49 | 49 | ||
50 | aic7xxx-gen-$(CONFIG_AIC7XXX_BUILD_FIRMWARE) := $(obj)/aic7xxx_reg.h | 50 | aic7xxx-gen-$(CONFIG_AIC7XXX_BUILD_FIRMWARE) := $(obj)/aic7xxx_reg.h |
51 | aic7xxx-gen-$(CONFIG_AIC7XXX_REG_PRETTY_PRINT) += $(obj)/aic7xxx_reg_print.c | 51 | aic7xxx-gen-$(CONFIG_AIC7XXX_REG_PRETTY_PRINT) += $(obj)/aic7xxx_reg_print.c |