dev-m25p80.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 spi_board_info ath79_spi_info[] = {
  17. {
  18. .bus_num = 0,
  19. .chip_select = 0,
  20. .max_speed_hz = 25000000,
  21. .modalias = "m25p80",
  22. },
  23. {
  24. .bus_num = 0,
  25. .chip_select = 1,
  26. .max_speed_hz = 25000000,
  27. .modalias = "m25p80",
  28. }
  29. };
  30. static struct ath79_spi_platform_data ath79_spi_data;
  31. void __init ath79_register_m25p80(struct flash_platform_data *pdata)
  32. {
  33. ath79_spi_data.bus_num = 0;
  34. ath79_spi_data.num_chipselect = 1;
  35. ath79_spi_info[0].platform_data = pdata;
  36. ath79_register_spi(&ath79_spi_data, ath79_spi_info, 1);
  37. }
  38. static struct flash_platform_data *multi_pdata;
  39. static struct mtd_info *concat_devs[2] = { NULL, NULL };
  40. static struct work_struct mtd_concat_work;
  41. static void mtd_concat_add_work(struct work_struct *work)
  42. {
  43. struct mtd_info *mtd;
  44. mtd = mtd_concat_create(concat_devs, ARRAY_SIZE(concat_devs), "flash");
  45. mtd_device_register(mtd, multi_pdata->parts, multi_pdata->nr_parts);
  46. }
  47. static void mtd_concat_add(struct mtd_info *mtd)
  48. {
  49. static bool registered = false;
  50. if (registered)
  51. return;
  52. if (!strcmp(mtd->name, "spi0.0"))
  53. concat_devs[0] = mtd;
  54. else if (!strcmp(mtd->name, "spi0.1"))
  55. concat_devs[1] = mtd;
  56. else
  57. return;
  58. if (!concat_devs[0] || !concat_devs[1])
  59. return;
  60. registered = true;
  61. INIT_WORK(&mtd_concat_work, mtd_concat_add_work);
  62. schedule_work(&mtd_concat_work);
  63. }
  64. static void mtd_concat_remove(struct mtd_info *mtd)
  65. {
  66. }
  67. static void add_mtd_concat_notifier(void)
  68. {
  69. static struct mtd_notifier not = {
  70. .add = mtd_concat_add,
  71. .remove = mtd_concat_remove,
  72. };
  73. register_mtd_user(&not);
  74. }
  75. void __init ath79_register_m25p80_multi(struct flash_platform_data *pdata)
  76. {
  77. multi_pdata = pdata;
  78. add_mtd_concat_notifier();
  79. ath79_spi_data.bus_num = 0;
  80. ath79_spi_data.num_chipselect = 2;
  81. ath79_register_spi(&ath79_spi_data, ath79_spi_info, 2);
  82. }