PageRenderTime 59ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/linux-2.6.11.12-hmwk5/drivers/mtd/maps/ixp2000.c

https://github.com/huitebe/fuck_reuben
C | 280 lines | 189 code | 50 blank | 41 comment | 18 complexity | c26e5587f5188f2a75ed68ee2ca45f72 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * $Id: ixp2000.c,v 1.5 2004/11/16 17:15:48 dsaxena Exp $
  3. *
  4. * drivers/mtd/maps/ixp2000.c
  5. *
  6. * Mapping for the Intel XScale IXP2000 based systems
  7. *
  8. * Copyright (C) 2002 Intel Corp.
  9. * Copyright (C) 2003-2004 MontaVista Software, Inc.
  10. *
  11. * Original Author: Naeem M Afzal <naeem.m.afzal@intel.com>
  12. * Maintainer: Deepak Saxena <dsaxena@plexity.net>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. *
  18. */
  19. #include <linux/module.h>
  20. #include <linux/types.h>
  21. #include <linux/init.h>
  22. #include <linux/kernel.h>
  23. #include <linux/string.h>
  24. #include <linux/mtd/mtd.h>
  25. #include <linux/mtd/map.h>
  26. #include <linux/mtd/partitions.h>
  27. #include <linux/ioport.h>
  28. #include <linux/device.h>
  29. #include <asm/io.h>
  30. #include <asm/hardware.h>
  31. #include <asm/mach-types.h>
  32. #include <asm/mach/flash.h>
  33. #include <linux/reboot.h>
  34. struct ixp2000_flash_info {
  35. struct mtd_info *mtd;
  36. struct map_info map;
  37. struct mtd_partition *partitions;
  38. struct resource *res;
  39. int nr_banks;
  40. };
  41. static inline unsigned long flash_bank_setup(struct map_info *map, unsigned long ofs)
  42. {
  43. unsigned long (*set_bank)(unsigned long) =
  44. (unsigned long(*)(unsigned long))map->map_priv_2;
  45. return (set_bank ? set_bank(ofs) : ofs);
  46. }
  47. #ifdef __ARMEB__
  48. /*
  49. * Rev A0 and A1 of IXP2400 silicon have a broken addressing unit which
  50. * causes the lower address bits to be XORed with 0x11 on 8 bit accesses
  51. * and XORed with 0x10 on 16 bit accesses. See the spec update, erratum 44.
  52. */
  53. static int erratum44_workaround = 0;
  54. static inline unsigned long address_fix8_write(unsigned long addr)
  55. {
  56. if (erratum44_workaround) {
  57. return (addr ^ 3);
  58. }
  59. return addr;
  60. }
  61. #else
  62. #define address_fix8_write(x) (x)
  63. #endif
  64. static map_word ixp2000_flash_read8(struct map_info *map, unsigned long ofs)
  65. {
  66. map_word val;
  67. val.x[0] = *((u8 *)(map->map_priv_1 + flash_bank_setup(map, ofs)));
  68. return val;
  69. }
  70. /*
  71. * We can't use the standard memcpy due to the broken SlowPort
  72. * address translation on rev A0 and A1 silicon and the fact that
  73. * we have banked flash.
  74. */
  75. static void ixp2000_flash_copy_from(struct map_info *map, void *to,
  76. unsigned long from, ssize_t len)
  77. {
  78. from = flash_bank_setup(map, from);
  79. while(len--)
  80. *(__u8 *) to++ = *(__u8 *)(map->map_priv_1 + from++);
  81. }
  82. static void ixp2000_flash_write8(struct map_info *map, map_word d, unsigned long ofs)
  83. {
  84. *(__u8 *) (address_fix8_write(map->map_priv_1 +
  85. flash_bank_setup(map, ofs))) = d.x[0];
  86. }
  87. static void ixp2000_flash_copy_to(struct map_info *map, unsigned long to,
  88. const void *from, ssize_t len)
  89. {
  90. to = flash_bank_setup(map, to);
  91. while(len--) {
  92. unsigned long tmp = address_fix8_write(map->map_priv_1 + to++);
  93. *(__u8 *)(tmp) = *(__u8 *)(from++);
  94. }
  95. }
  96. static int ixp2000_flash_remove(struct device *_dev)
  97. {
  98. struct platform_device *dev = to_platform_device(_dev);
  99. struct flash_platform_data *plat = dev->dev.platform_data;
  100. struct ixp2000_flash_info *info = dev_get_drvdata(&dev->dev);
  101. dev_set_drvdata(&dev->dev, NULL);
  102. if(!info)
  103. return 0;
  104. if (info->mtd) {
  105. del_mtd_partitions(info->mtd);
  106. map_destroy(info->mtd);
  107. }
  108. if (info->map.map_priv_1)
  109. iounmap((void *) info->map.map_priv_1);
  110. if (info->partitions) {
  111. kfree(info->partitions); }
  112. if (info->res) {
  113. release_resource(info->res);
  114. kfree(info->res);
  115. }
  116. if (plat->exit)
  117. plat->exit();
  118. return 0;
  119. }
  120. static int ixp2000_flash_probe(struct device *_dev)
  121. {
  122. static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
  123. struct platform_device *dev = to_platform_device(_dev);
  124. struct ixp2000_flash_data *ixp_data = dev->dev.platform_data;
  125. struct flash_platform_data *plat;
  126. struct ixp2000_flash_info *info;
  127. unsigned long window_size;
  128. int err = -1;
  129. if (!ixp_data)
  130. return -ENODEV;
  131. plat = ixp_data->platform_data;
  132. if (!plat)
  133. return -ENODEV;
  134. window_size = dev->resource->end - dev->resource->start + 1;
  135. dev_info(_dev, "Probe of IXP2000 flash(%d banks x %dMiB)\n",
  136. ixp_data->nr_banks, ((u32)window_size >> 20));
  137. if (plat->width != 1) {
  138. dev_err(_dev, "IXP2000 MTD map only supports 8-bit mode, asking for %d\n",
  139. plat->width * 8);
  140. return -EIO;
  141. }
  142. info = kmalloc(sizeof(struct ixp2000_flash_info), GFP_KERNEL);
  143. if(!info) {
  144. err = -ENOMEM;
  145. goto Error;
  146. }
  147. memzero(info, sizeof(struct ixp2000_flash_info));
  148. dev_set_drvdata(&dev->dev, info);
  149. /*
  150. * Tell the MTD layer we're not 1:1 mapped so that it does
  151. * not attempt to do a direct access on us.
  152. */
  153. info->map.phys = NO_XIP;
  154. info->nr_banks = ixp_data->nr_banks;
  155. info->map.size = ixp_data->nr_banks * window_size;
  156. info->map.bankwidth = 1;
  157. /*
  158. * map_priv_2 is used to store a ptr to to the bank_setup routine
  159. */
  160. info->map.map_priv_2 = (void __iomem *) ixp_data->bank_setup;
  161. info->map.name = dev->dev.bus_id;
  162. info->map.read = ixp2000_flash_read8;
  163. info->map.write = ixp2000_flash_write8;
  164. info->map.copy_from = ixp2000_flash_copy_from;
  165. info->map.copy_to = ixp2000_flash_copy_to;
  166. info->res = request_mem_region(dev->resource->start,
  167. dev->resource->end - dev->resource->start + 1,
  168. dev->dev.bus_id);
  169. if (!info->res) {
  170. dev_err(_dev, "Could not reserve memory region\n");
  171. err = -ENOMEM;
  172. goto Error;
  173. }
  174. info->map.map_priv_1 = ioremap(dev->resource->start,
  175. dev->resource->end - dev->resource->start + 1);
  176. if (!info->map.map_priv_1) {
  177. dev_err(_dev, "Failed to ioremap flash region\n");
  178. err = -EIO;
  179. goto Error;
  180. }
  181. /*
  182. * Setup read mode for FLASH
  183. */
  184. *IXP2000_SLOWPORT_FRM = 1;
  185. #if defined(__ARMEB__)
  186. /*
  187. * Enable erratum 44 workaround for NPUs with broken slowport
  188. */
  189. erratum44_workaround = ixp2000_has_broken_slowport();
  190. dev_info(_dev, "Erratum 44 workaround %s\n",
  191. erratum44_workaround ? "enabled" : "disabled");
  192. #endif
  193. info->mtd = do_map_probe(plat->map_name, &info->map);
  194. if (!info->mtd) {
  195. dev_err(_dev, "map_probe failed\n");
  196. err = -ENXIO;
  197. goto Error;
  198. }
  199. info->mtd->owner = THIS_MODULE;
  200. err = parse_mtd_partitions(info->mtd, probes, &info->partitions, 0);
  201. if (err > 0) {
  202. err = add_mtd_partitions(info->mtd, info->partitions, err);
  203. if(err)
  204. dev_err(_dev, "Could not parse partitions\n");
  205. }
  206. if (err)
  207. goto Error;
  208. return 0;
  209. Error:
  210. ixp2000_flash_remove(_dev);
  211. return err;
  212. }
  213. static struct device_driver ixp2000_flash_driver = {
  214. .name = "IXP2000-Flash",
  215. .bus = &platform_bus_type,
  216. .probe = &ixp2000_flash_probe,
  217. .remove = &ixp2000_flash_remove
  218. };
  219. static int __init ixp2000_flash_init(void)
  220. {
  221. return driver_register(&ixp2000_flash_driver);
  222. }
  223. static void __exit ixp2000_flash_exit(void)
  224. {
  225. driver_unregister(&ixp2000_flash_driver);
  226. }
  227. module_init(ixp2000_flash_init);
  228. module_exit(ixp2000_flash_exit);
  229. MODULE_LICENSE("GPL");
  230. MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");