Blame view

drivers/mtd/maps/pxa2xx-flash.c 3.86 KB
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
1
2
3
4
5
6
7
8
9
10
11
12
13
  /*
   * Map driver for Intel XScale PXA2xx platforms.
   *
   * Author:	Nicolas Pitre
   * Copyright:	(C) 2001 MontaVista Software Inc.
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   */
  
  #include <linux/module.h>
  #include <linux/types.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
14
  #include <linux/slab.h>
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
15
16
17
  #include <linux/kernel.h>
  #include <linux/init.h>
  #include <linux/platform_device.h>
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
18
19
20
21
22
  #include <linux/mtd/mtd.h>
  #include <linux/mtd/map.h>
  #include <linux/mtd/partitions.h>
  
  #include <asm/io.h>
a09e64fbc   Russell King   [ARM] Move includ...
23
  #include <mach/hardware.h>
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
24
25
  
  #include <asm/mach/flash.h>
ccaf5f05b   Nicolas Pitre   ARM: 5848/1: kill...
26
  #define CACHELINESIZE	32
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
27
28
29
  static void pxa2xx_map_inval_cache(struct map_info *map, unsigned long from,
  				      ssize_t len)
  {
ccaf5f05b   Nicolas Pitre   ARM: 5848/1: kill...
30
31
32
33
34
35
36
37
38
  	unsigned long start = (unsigned long)map->cached + from;
  	unsigned long end = start + len;
  
  	start &= ~(CACHELINESIZE - 1);
  	while (start < end) {
  		/* invalidate D cache line */
  		asm volatile ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
  		start += CACHELINESIZE;
  	}
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
39
40
41
  }
  
  struct pxa2xx_flash_info {
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
42
43
44
45
46
47
  	struct mtd_info		*mtd;
  	struct map_info		map;
  };
  
  
  static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
f9d1bf755   Marek Vasut   ARM: pxa: fix pxa...
48
  static int __devinit pxa2xx_flash_probe(struct platform_device *pdev)
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
49
  {
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
50
51
  	struct flash_platform_data *flash = pdev->dev.platform_data;
  	struct pxa2xx_flash_info *info;
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
52
  	struct resource *res;
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
53
54
55
56
  
  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  	if (!res)
  		return -ENODEV;
2bfefa4c9   Julia Lawall   drivers/mtd: Use ...
57
  	info = kzalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL);
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
58
59
  	if (!info)
  		return -ENOMEM;
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
60
61
62
  	info->map.name = (char *) flash->name;
  	info->map.bankwidth = flash->width;
  	info->map.phys = res->start;
28f65c11f   Joe Perches   treewide: Convert...
63
  	info->map.size = resource_size(res);
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  
  	info->map.virt = ioremap(info->map.phys, info->map.size);
  	if (!info->map.virt) {
  		printk(KERN_WARNING "Failed to ioremap %s
  ",
  		       info->map.name);
  		return -ENOMEM;
  	}
  	info->map.cached =
  		ioremap_cached(info->map.phys, info->map.size);
  	if (!info->map.cached)
  		printk(KERN_WARNING "Failed to ioremap cached %s
  ",
  		       info->map.name);
  	info->map.inval_cache = pxa2xx_map_inval_cache;
  	simple_map_init(&info->map);
  
  	printk(KERN_NOTICE
  	       "Probing %s at physical address 0x%08lx"
  	       " (%d-bit bankwidth)
  ",
  	       info->map.name, (unsigned long)info->map.phys,
  	       info->map.bankwidth * 8);
  
  	info->mtd = do_map_probe(flash->map_name, &info->map);
  
  	if (!info->mtd) {
  		iounmap((void *)info->map.virt);
  		if (info->map.cached)
  			iounmap(info->map.cached);
  		return -EIO;
  	}
  	info->mtd->owner = THIS_MODULE;
7148b7999   Jonathan Cameron   mtd: pxa2xx-flash...
97
  	mtd_device_parse_register(info->mtd, probes, 0, flash->parts, flash->nr_parts);
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
98

7a192ec33   Ming Lei   platform driver: ...
99
  	platform_set_drvdata(pdev, info);
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
100
101
  	return 0;
  }
67a52bb90   Russell King   [ARM] fix build-b...
102
  static int __devexit pxa2xx_flash_remove(struct platform_device *dev)
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
103
  {
7a192ec33   Ming Lei   platform driver: ...
104
  	struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
105

7a192ec33   Ming Lei   platform driver: ...
106
  	platform_set_drvdata(dev, NULL);
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
107

3dfad123e   Jamie Iles   mtd: pxa: convert...
108
  	mtd_device_unregister(info->mtd);
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
109
110
111
112
113
  
  	map_destroy(info->mtd);
  	iounmap(info->map.virt);
  	if (info->map.cached)
  		iounmap(info->map.cached);
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
114
115
116
117
118
  	kfree(info);
  	return 0;
  }
  
  #ifdef CONFIG_PM
7a192ec33   Ming Lei   platform driver: ...
119
  static void pxa2xx_flash_shutdown(struct platform_device *dev)
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
120
  {
7a192ec33   Ming Lei   platform driver: ...
121
  	struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
122
123
124
125
126
  
  	if (info && info->mtd->suspend(info->mtd) == 0)
  		info->mtd->resume(info->mtd);
  }
  #else
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
127
128
  #define pxa2xx_flash_shutdown NULL
  #endif
7a192ec33   Ming Lei   platform driver: ...
129
130
131
132
133
  static struct platform_driver pxa2xx_flash_driver = {
  	.driver = {
  		.name		= "pxa2xx-flash",
  		.owner		= THIS_MODULE,
  	},
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
134
  	.probe		= pxa2xx_flash_probe,
7a192ec33   Ming Lei   platform driver: ...
135
  	.remove		= __devexit_p(pxa2xx_flash_remove),
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
136
137
138
139
140
  	.shutdown	= pxa2xx_flash_shutdown,
  };
  
  static int __init init_pxa2xx_flash(void)
  {
7a192ec33   Ming Lei   platform driver: ...
141
  	return platform_driver_register(&pxa2xx_flash_driver);
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
142
143
144
145
  }
  
  static void __exit cleanup_pxa2xx_flash(void)
  {
7a192ec33   Ming Lei   platform driver: ...
146
  	platform_driver_unregister(&pxa2xx_flash_driver);
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
147
148
149
150
151
152
  }
  
  module_init(init_pxa2xx_flash);
  module_exit(cleanup_pxa2xx_flash);
  
  MODULE_LICENSE("GPL");
2f82af08f   Nicolas Pitre   Nicolas Pitre has...
153
  MODULE_AUTHOR("Nicolas Pitre <nico@fluxnic.net>");
e644f7d62   Todd Poynor   [MTD] MAPS: Merge...
154
  MODULE_DESCRIPTION("MTD map driver for Intel XScale PXA2xx");