sitecom.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Sitecom RDC321x platform devices
  3. *
  4. * Copyright (C) 2007-2009 OpenWrt.org
  5. * Copyright (C) 2007 Florian Fainelli <[email protected]>
  6. * Copyright (C) 2008-2009 Daniel Gimpelevich <[email protected]>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301, USA.
  22. *
  23. */
  24. #include <linux/init.h>
  25. #include <linux/mtd/physmap.h>
  26. #include <linux/input.h>
  27. #include <asm/rdc_boards.h>
  28. struct image_header {
  29. char magic[4];
  30. u32 kernel_length;
  31. u32 ramdisk_length;
  32. char magic2[4];
  33. u32 kernel_length2;
  34. };
  35. static struct gpio_led sitecom_leds[] = {
  36. { .name = "rdc321x:power", .gpio = 15, .active_low = 1},
  37. { .name = "rdc321x:usb0", .gpio = 0, .active_low = 1},
  38. { .name = "rdc321x:usb1", .gpio = 1, .active_low = 1},
  39. };
  40. static struct gpio_button sitecom_btns[] = {
  41. {
  42. .gpio = 6,
  43. .code = BTN_0,
  44. .desc = "Reset",
  45. .active_low = 1,
  46. }
  47. };
  48. static int __init parse_sitecom_partitions(struct mtd_info *master, struct mtd_partition **pparts, unsigned long plat_data)
  49. {
  50. struct image_header header;
  51. int res;
  52. size_t len;
  53. struct mtd_partition *rdc_flash_parts;
  54. struct rdc_platform_data *pdata = (struct rdc_platform_data *) plat_data;
  55. if (master->size != 0x400000) //4MB
  56. return -ENOSYS;
  57. res = master->read(master, 0x8000, sizeof(header), &len, (char *)&header);
  58. if (res)
  59. return res;
  60. if (strncmp(header.magic, "CSYS", 4) || strncmp(header.magic2, "WRRM", 4))
  61. return -ENOSYS;
  62. rdc_flash_parts = kzalloc(sizeof(struct mtd_partition) * 5, GFP_KERNEL);
  63. rdc_flash_parts[0].name = "firmware";
  64. rdc_flash_parts[0].offset = 0x8000;
  65. rdc_flash_parts[0].size = 0x3F0000;
  66. rdc_flash_parts[1].name = "config";
  67. rdc_flash_parts[1].offset = 0;
  68. rdc_flash_parts[1].size = 0x8000;
  69. rdc_flash_parts[2].name = "kernel";
  70. rdc_flash_parts[2].offset = 0x8014;
  71. rdc_flash_parts[2].size = header.kernel_length;
  72. rdc_flash_parts[3].name = "rootfs";
  73. rdc_flash_parts[3].offset = 0x8014 + header.kernel_length;
  74. rdc_flash_parts[3].size = 0x3F0000 - rdc_flash_parts[3].offset;
  75. rdc_flash_parts[4].name = "bootloader";
  76. rdc_flash_parts[4].offset = 0x3F0000;
  77. rdc_flash_parts[4].size = 0x10000;
  78. *pparts = rdc_flash_parts;
  79. pdata->led_data.num_leds = ARRAY_SIZE(sitecom_leds);
  80. pdata->led_data.leds = sitecom_leds;
  81. pdata->button_data.nbuttons = ARRAY_SIZE(sitecom_btns);
  82. pdata->button_data.buttons = sitecom_btns;
  83. return 5;
  84. }
  85. struct mtd_part_parser __initdata sitecom_parser = {
  86. .owner = THIS_MODULE,
  87. .parse_fn = parse_sitecom_partitions,
  88. .name = "Sitecom",
  89. };
  90. static int __init sitecom_setup(void)
  91. {
  92. return register_mtd_parser(&sitecom_parser);
  93. }
  94. arch_initcall(sitecom_setup);