ato.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2022 Aidan MacDonald
  4. *
  5. * Author: Aidan MacDonald <[email protected]>
  6. */
  7. #include <linux/device.h>
  8. #include <linux/kernel.h>
  9. #include <linux/mtd/spinand.h>
  10. #define SPINAND_MFR_ATO 0x9b
  11. static SPINAND_OP_VARIANTS(read_cache_variants,
  12. SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  13. SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
  14. SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
  15. static SPINAND_OP_VARIANTS(write_cache_variants,
  16. SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
  17. SPINAND_PROG_LOAD(true, 0, NULL, 0));
  18. static SPINAND_OP_VARIANTS(update_cache_variants,
  19. SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
  20. SPINAND_PROG_LOAD(false, 0, NULL, 0));
  21. static int ato25d1ga_ooblayout_ecc(struct mtd_info *mtd, int section,
  22. struct mtd_oob_region *region)
  23. {
  24. if (section > 3)
  25. return -ERANGE;
  26. region->offset = (16 * section) + 8;
  27. region->length = 8;
  28. return 0;
  29. }
  30. static int ato25d1ga_ooblayout_free(struct mtd_info *mtd, int section,
  31. struct mtd_oob_region *region)
  32. {
  33. if (section > 3)
  34. return -ERANGE;
  35. if (section) {
  36. region->offset = (16 * section);
  37. region->length = 8;
  38. } else {
  39. /* first byte of section 0 is reserved for the BBM */
  40. region->offset = 1;
  41. region->length = 7;
  42. }
  43. return 0;
  44. }
  45. static const struct mtd_ooblayout_ops ato25d1ga_ooblayout = {
  46. .ecc = ato25d1ga_ooblayout_ecc,
  47. .free = ato25d1ga_ooblayout_free,
  48. };
  49. static const struct spinand_info ato_spinand_table[] = {
  50. SPINAND_INFO("ATO25D1GA",
  51. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x12),
  52. NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
  53. NAND_ECCREQ(1, 512),
  54. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  55. &write_cache_variants,
  56. &update_cache_variants),
  57. SPINAND_HAS_QE_BIT,
  58. SPINAND_ECCINFO(&ato25d1ga_ooblayout, NULL)),
  59. };
  60. static const struct spinand_manufacturer_ops ato_spinand_manuf_ops = {
  61. };
  62. const struct spinand_manufacturer ato_spinand_manufacturer = {
  63. .id = SPINAND_MFR_ATO,
  64. .name = "ATO",
  65. .chips = ato_spinand_table,
  66. .nchips = ARRAY_SIZE(ato_spinand_table),
  67. .ops = &ato_spinand_manuf_ops,
  68. };