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.
 
 
 
 
 
 

139 lines
4.4 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. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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_nand.h"
  29. s3c24xx_nand_controller_t *
  30. s3c24xx_nand_device_command(struct command_context_s *cmd_ctx, char *cmd,
  31. char **args, int argc,
  32. struct nand_device_s *device)
  33. {
  34. s3c24xx_nand_controller_t *s3c24xx_info;
  35. s3c24xx_info = malloc(sizeof(s3c24xx_nand_controller_t));
  36. if (s3c24xx_info == NULL) {
  37. LOG_ERROR("no memory for nand controller\n");
  38. return NULL;
  39. }
  40. device->controller_priv = s3c24xx_info;
  41. s3c24xx_info->target = get_target_by_num(strtoul(args[1], NULL, 0));
  42. if (s3c24xx_info->target == NULL) {
  43. LOG_ERROR("no target '%s' configured", args[1]);
  44. return NULL;
  45. }
  46. return s3c24xx_info;
  47. }
  48. int s3c24xx_register_commands(struct command_context_s *cmd_ctx)
  49. {
  50. return ERROR_OK;
  51. }
  52. int s3c24xx_reset(struct nand_device_s *device)
  53. {
  54. s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
  55. target_t *target = s3c24xx_info->target;
  56. if (target->state != TARGET_HALTED) {
  57. LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
  58. return ERROR_NAND_OPERATION_FAILED;
  59. }
  60. target_write_u32(target, s3c24xx_info->cmd, 0xff);
  61. return ERROR_OK;
  62. }
  63. int s3c24xx_command(struct nand_device_s *device, u8 command)
  64. {
  65. s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
  66. target_t *target = s3c24xx_info->target;
  67. if (target->state != TARGET_HALTED) {
  68. LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
  69. return ERROR_NAND_OPERATION_FAILED;
  70. }
  71. target_write_u16(target, s3c24xx_info->cmd, command);
  72. return ERROR_OK;
  73. }
  74. int s3c24xx_address(struct nand_device_s *device, u8 address)
  75. {
  76. s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
  77. target_t *target = s3c24xx_info->target;
  78. if (target->state != TARGET_HALTED) {
  79. LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
  80. return ERROR_NAND_OPERATION_FAILED;
  81. }
  82. target_write_u16(target, s3c24xx_info->addr, address);
  83. return ERROR_OK;
  84. }
  85. int s3c24xx_write_data(struct nand_device_s *device, u16 data)
  86. {
  87. s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
  88. target_t *target = s3c24xx_info->target;
  89. if (target->state != TARGET_HALTED) {
  90. LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
  91. return ERROR_NAND_OPERATION_FAILED;
  92. }
  93. target_write_u8(target, s3c24xx_info->data, data);
  94. return ERROR_OK;
  95. }
  96. int s3c24xx_read_data(struct nand_device_s *device, void *data)
  97. {
  98. s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
  99. target_t *target = s3c24xx_info->target;
  100. if (target->state != TARGET_HALTED) {
  101. LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
  102. return ERROR_NAND_OPERATION_FAILED;
  103. }
  104. target_read_u8(target, s3c24xx_info->data, data);
  105. return ERROR_OK;
  106. }
  107. int s3c24xx_controller_ready(struct nand_device_s *device, int timeout)
  108. {
  109. return 1;
  110. }