PageRenderTime 329ms CodeModel.GetById 103ms RepoModel.GetById 19ms app.codeStats 0ms

/release/src-rt/linux/linux-2.6/drivers/mtd/maps/ixp2000.c

https://gitlab.com/envieidoc/advancedtomato2
C | 273 lines | 185 code | 50 blank | 38 comment | 17 complexity | cbe851a101f59d99c70a16ace1703719 MD5 | raw file
  1. /*
  2. * $Id: ixp2000.c,v 1.9 2005/11/07 11:14:27 gleixner 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/slab.h>
  25. #include <linux/ioport.h>
  26. #include <linux/device.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/mtd/mtd.h>
  29. #include <linux/mtd/map.h>
  30. #include <linux/mtd/partitions.h>
  31. #include <asm/io.h>
  32. #include <asm/hardware.h>
  33. #include <asm/mach/flash.h>
  34. #include <linux/reboot.h>
  35. struct ixp2000_flash_info {
  36. struct mtd_info *mtd;
  37. struct map_info map;
  38. struct mtd_partition *partitions;
  39. struct resource *res;
  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 platform_device *dev)
  97. {
  98. struct flash_platform_data *plat = dev->dev.platform_data;
  99. struct ixp2000_flash_info *info = platform_get_drvdata(dev);
  100. platform_set_drvdata(dev, NULL);
  101. if(!info)
  102. return 0;
  103. if (info->mtd) {
  104. del_mtd_partitions(info->mtd);
  105. map_destroy(info->mtd);
  106. }
  107. if (info->map.map_priv_1)
  108. iounmap((void *) info->map.map_priv_1);
  109. kfree(info->partitions);
  110. if (info->res) {
  111. release_resource(info->res);
  112. kfree(info->res);
  113. }
  114. if (plat->exit)
  115. plat->exit();
  116. return 0;
  117. }
  118. static int ixp2000_flash_probe(struct platform_device *dev)
  119. {
  120. static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
  121. struct ixp2000_flash_data *ixp_data = dev->dev.platform_data;
  122. struct flash_platform_data *plat;
  123. struct ixp2000_flash_info *info;
  124. unsigned long window_size;
  125. int err = -1;
  126. if (!ixp_data)
  127. return -ENODEV;
  128. plat = ixp_data->platform_data;
  129. if (!plat)
  130. return -ENODEV;
  131. window_size = dev->resource->end - dev->resource->start + 1;
  132. dev_info(&dev->dev, "Probe of IXP2000 flash(%d banks x %dMiB)\n",
  133. ixp_data->nr_banks, ((u32)window_size >> 20));
  134. if (plat->width != 1) {
  135. dev_err(&dev->dev, "IXP2000 MTD map only supports 8-bit mode, asking for %d\n",
  136. plat->width * 8);
  137. return -EIO;
  138. }
  139. info = kmalloc(sizeof(struct ixp2000_flash_info), GFP_KERNEL);
  140. if(!info) {
  141. err = -ENOMEM;
  142. goto Error;
  143. }
  144. memzero(info, sizeof(struct ixp2000_flash_info));
  145. platform_set_drvdata(dev, info);
  146. /*
  147. * Tell the MTD layer we're not 1:1 mapped so that it does
  148. * not attempt to do a direct access on us.
  149. */
  150. info->map.phys = NO_XIP;
  151. info->map.size = ixp_data->nr_banks * window_size;
  152. info->map.bankwidth = 1;
  153. /*
  154. * map_priv_2 is used to store a ptr to to the bank_setup routine
  155. */
  156. info->map.map_priv_2 = (unsigned long) ixp_data->bank_setup;
  157. info->map.name = dev->dev.bus_id;
  158. info->map.read = ixp2000_flash_read8;
  159. info->map.write = ixp2000_flash_write8;
  160. info->map.copy_from = ixp2000_flash_copy_from;
  161. info->map.copy_to = ixp2000_flash_copy_to;
  162. info->res = request_mem_region(dev->resource->start,
  163. dev->resource->end - dev->resource->start + 1,
  164. dev->dev.bus_id);
  165. if (!info->res) {
  166. dev_err(&dev->dev, "Could not reserve memory region\n");
  167. err = -ENOMEM;
  168. goto Error;
  169. }
  170. info->map.map_priv_1 = (unsigned long) ioremap(dev->resource->start,
  171. dev->resource->end - dev->resource->start + 1);
  172. if (!info->map.map_priv_1) {
  173. dev_err(&dev->dev, "Failed to ioremap flash region\n");
  174. err = -EIO;
  175. goto Error;
  176. }
  177. #if defined(__ARMEB__)
  178. /*
  179. * Enable erratum 44 workaround for NPUs with broken slowport
  180. */
  181. erratum44_workaround = ixp2000_has_broken_slowport();
  182. dev_info(&dev->dev, "Erratum 44 workaround %s\n",
  183. erratum44_workaround ? "enabled" : "disabled");
  184. #endif
  185. info->mtd = do_map_probe(plat->map_name, &info->map);
  186. if (!info->mtd) {
  187. dev_err(&dev->dev, "map_probe failed\n");
  188. err = -ENXIO;
  189. goto Error;
  190. }
  191. info->mtd->owner = THIS_MODULE;
  192. err = parse_mtd_partitions(info->mtd, probes, &info->partitions, 0);
  193. if (err > 0) {
  194. err = add_mtd_partitions(info->mtd, info->partitions, err);
  195. if(err)
  196. dev_err(&dev->dev, "Could not parse partitions\n");
  197. }
  198. if (err)
  199. goto Error;
  200. return 0;
  201. Error:
  202. ixp2000_flash_remove(dev);
  203. return err;
  204. }
  205. static struct platform_driver ixp2000_flash_driver = {
  206. .probe = ixp2000_flash_probe,
  207. .remove = ixp2000_flash_remove,
  208. .driver = {
  209. .name = "IXP2000-Flash",
  210. },
  211. };
  212. static int __init ixp2000_flash_init(void)
  213. {
  214. return platform_driver_register(&ixp2000_flash_driver);
  215. }
  216. static void __exit ixp2000_flash_exit(void)
  217. {
  218. platform_driver_unregister(&ixp2000_flash_driver);
  219. }
  220. module_init(ixp2000_flash_init);
  221. module_exit(ixp2000_flash_exit);
  222. MODULE_LICENSE("GPL");
  223. MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");