dev-m25p80.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (C) 2009-2012 Gabor Juhos <juhosg@openwrt.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License version 2 as published
  6. * by the Free Software Foundation.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/spi/spi.h>
  10. #include <linux/spi/flash.h>
  11. #include <linux/mtd/mtd.h>
  12. #include <linux/mtd/partitions.h>
  13. #include <linux/mtd/concat.h>
  14. #include "dev-spi.h"
  15. #include "dev-m25p80.h"
  16. static struct ath79_spi_controller_data ath79_spi0_cdata =
  17. {
  18. .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
  19. .cs_line = 0,
  20. };
  21. static struct ath79_spi_controller_data ath79_spi1_cdata =
  22. {
  23. .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
  24. .cs_line = 1,
  25. };
  26. static struct spi_board_info ath79_spi_info[] = {
  27. {
  28. .bus_num = 0,
  29. .chip_select = 0,
  30. .max_speed_hz = 25000000,
  31. .modalias = "m25p80",
  32. .controller_data = &ath79_spi0_cdata,
  33. },
  34. {
  35. .bus_num = 0,
  36. .chip_select = 1,
  37. .max_speed_hz = 25000000,
  38. .modalias = "m25p80",
  39. .controller_data = &ath79_spi1_cdata,
  40. }
  41. };
  42. static struct ath79_spi_platform_data ath79_spi_data;
  43. void __init ath79_register_m25p80(struct flash_platform_data *pdata)
  44. {
  45. ath79_spi_data.bus_num = 0;
  46. ath79_spi_data.num_chipselect = 1;
  47. ath79_spi0_cdata.is_flash = true;
  48. ath79_spi_info[0].platform_data = pdata;
  49. ath79_register_spi(&ath79_spi_data, ath79_spi_info, 1);
  50. }
  51. static struct flash_platform_data *multi_pdata;
  52. static struct mtd_info *concat_devs[2] = { NULL, NULL };
  53. static struct work_struct mtd_concat_work;
  54. static void mtd_concat_add_work(struct work_struct *work)
  55. {
  56. struct mtd_info *mtd;
  57. mtd = mtd_concat_create(concat_devs, ARRAY_SIZE(concat_devs), "flash");
  58. mtd_device_register(mtd, multi_pdata->parts, multi_pdata->nr_parts);
  59. }
  60. static void mtd_concat_add(struct mtd_info *mtd)
  61. {
  62. static bool registered = false;
  63. if (registered)
  64. return;
  65. if (!strcmp(mtd->name, "spi0.0"))
  66. concat_devs[0] = mtd;
  67. else if (!strcmp(mtd->name, "spi0.1"))
  68. concat_devs[1] = mtd;
  69. else
  70. return;
  71. if (!concat_devs[0] || !concat_devs[1])
  72. return;
  73. registered = true;
  74. INIT_WORK(&mtd_concat_work, mtd_concat_add_work);
  75. schedule_work(&mtd_concat_work);
  76. }
  77. static void mtd_concat_remove(struct mtd_info *mtd)
  78. {
  79. }
  80. static void add_mtd_concat_notifier(void)
  81. {
  82. static struct mtd_notifier not = {
  83. .add = mtd_concat_add,
  84. .remove = mtd_concat_remove,
  85. };
  86. register_mtd_user(&not);
  87. }
  88. void __init ath79_register_m25p80_large(struct flash_platform_data *pdata)
  89. {
  90. ath79_spi_data.bus_num = 0;
  91. ath79_spi_data.num_chipselect = 1;
  92. ath79_spi0_cdata.is_flash = false;
  93. ath79_spi_info[0].platform_data = pdata;
  94. ath79_register_spi(&ath79_spi_data, ath79_spi_info, 1);
  95. }
  96. void __init ath79_register_m25p80_multi(struct flash_platform_data *pdata)
  97. {
  98. multi_pdata = pdata;
  99. add_mtd_concat_notifier();
  100. ath79_spi_data.bus_num = 0;
  101. ath79_spi_data.num_chipselect = 2;
  102. ath79_spi0_cdata.is_flash = true;
  103. ath79_register_spi(&ath79_spi_data, ath79_spi_info, 2);
  104. }