You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

120 lines
3.9 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2007, 2008 by Ben Dooks *
  3. * ben@fluff.org *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
  19. ***************************************************************************/
  20. /*
  21. * S3C24XX Series OpenOCD NAND Flash controller support.
  22. *
  23. * Many thanks to Simtec Electronics for sponsoring this work.
  24. */
  25. #ifdef HAVE_CONFIG_H
  26. #include "config.h"
  27. #endif
  28. #include "s3c24xx.h"
  29. S3C24XX_DEVICE_COMMAND()
  30. {
  31. *info = NULL;
  32. struct s3c24xx_nand_controller *s3c24xx_info;
  33. s3c24xx_info = malloc(sizeof(struct s3c24xx_nand_controller));
  34. if (s3c24xx_info == NULL) {
  35. LOG_ERROR("no memory for nand controller");
  36. return -ENOMEM;
  37. }
  38. nand->controller_priv = s3c24xx_info;
  39. *info = s3c24xx_info;
  40. return ERROR_OK;
  41. }
  42. int s3c24xx_reset(struct nand_device *nand)
  43. {
  44. struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
  45. struct target *target = nand->target;
  46. if (target->state != TARGET_HALTED) {
  47. LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
  48. return ERROR_NAND_OPERATION_FAILED;
  49. }
  50. target_write_u32(target, s3c24xx_info->cmd, 0xff);
  51. return ERROR_OK;
  52. }
  53. int s3c24xx_command(struct nand_device *nand, uint8_t command)
  54. {
  55. struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
  56. struct target *target = nand->target;
  57. if (target->state != TARGET_HALTED) {
  58. LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
  59. return ERROR_NAND_OPERATION_FAILED;
  60. }
  61. target_write_u16(target, s3c24xx_info->cmd, command);
  62. return ERROR_OK;
  63. }
  64. int s3c24xx_address(struct nand_device *nand, uint8_t address)
  65. {
  66. struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
  67. struct target *target = nand->target;
  68. if (target->state != TARGET_HALTED) {
  69. LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
  70. return ERROR_NAND_OPERATION_FAILED;
  71. }
  72. target_write_u16(target, s3c24xx_info->addr, address);
  73. return ERROR_OK;
  74. }
  75. int s3c24xx_write_data(struct nand_device *nand, uint16_t data)
  76. {
  77. struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
  78. struct target *target = nand->target;
  79. if (target->state != TARGET_HALTED) {
  80. LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
  81. return ERROR_NAND_OPERATION_FAILED;
  82. }
  83. target_write_u8(target, s3c24xx_info->data, data);
  84. return ERROR_OK;
  85. }
  86. int s3c24xx_read_data(struct nand_device *nand, void *data)
  87. {
  88. struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
  89. struct target *target = nand->target;
  90. if (target->state != TARGET_HALTED) {
  91. LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
  92. return ERROR_NAND_OPERATION_FAILED;
  93. }
  94. target_read_u8(target, s3c24xx_info->data, data);
  95. return ERROR_OK;
  96. }