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.
 
 
 
 
 
 

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