OpenOCD
s3c24xx.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2007, 2008 by Ben Dooks *
5  * ben@fluff.org *
6  ***************************************************************************/
7 
8 /*
9  * S3C24XX Series OpenOCD NAND Flash controller support.
10  *
11  * Many thanks to Simtec Electronics for sponsoring this work.
12  */
13 
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17 
18 #include "s3c24xx.h"
19 
21 {
22  *info = NULL;
23 
24  struct s3c24xx_nand_controller *s3c24xx_info;
25  s3c24xx_info = malloc(sizeof(struct s3c24xx_nand_controller));
26  if (!s3c24xx_info) {
27  LOG_ERROR("no memory for nand controller");
28  return -ENOMEM;
29  }
30 
31  nand->controller_priv = s3c24xx_info;
32  *info = s3c24xx_info;
33 
34  return ERROR_OK;
35 }
36 
37 int s3c24xx_reset(struct nand_device *nand)
38 {
39  struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
40  struct target *target = nand->target;
41 
42  if (target->state != TARGET_HALTED) {
43  LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
45  }
46 
47  target_write_u32(target, s3c24xx_info->cmd, 0xff);
48 
49  return ERROR_OK;
50 }
51 
52 int s3c24xx_command(struct nand_device *nand, uint8_t command)
53 {
54  struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
55  struct target *target = nand->target;
56 
57  if (target->state != TARGET_HALTED) {
58  LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
60  }
61 
62  target_write_u16(target, s3c24xx_info->cmd, command);
63  return ERROR_OK;
64 }
65 
66 int s3c24xx_address(struct nand_device *nand, uint8_t address)
67 {
68  struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
69  struct target *target = nand->target;
70 
71  if (target->state != TARGET_HALTED) {
72  LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
74  }
75 
76  target_write_u16(target, s3c24xx_info->addr, address);
77  return ERROR_OK;
78 }
79 
80 int s3c24xx_write_data(struct nand_device *nand, uint16_t data)
81 {
82  struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
83  struct target *target = nand->target;
84 
85  if (target->state != TARGET_HALTED) {
86  LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
88  }
89 
90  target_write_u8(target, s3c24xx_info->data, data);
91  return ERROR_OK;
92 }
93 
94 int s3c24xx_read_data(struct nand_device *nand, void *data)
95 {
96  struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
97  struct target *target = nand->target;
98 
99  if (target->state != TARGET_HALTED) {
100  LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
102  }
103 
104  target_read_u8(target, s3c24xx_info->data, data);
105  return ERROR_OK;
106 }
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define ERROR_OK
Definition: log.h:164
#define ERROR_NAND_OPERATION_FAILED
Definition: nand/core.h:217
int s3c24xx_write_data(struct nand_device *nand, uint16_t data)
Definition: s3c24xx.c:80
int s3c24xx_reset(struct nand_device *nand)
Definition: s3c24xx.c:37
int s3c24xx_address(struct nand_device *nand, uint8_t address)
Definition: s3c24xx.c:66
int s3c24xx_command(struct nand_device *nand, uint8_t command)
Definition: s3c24xx.c:52
int s3c24xx_read_data(struct nand_device *nand, void *data)
Definition: s3c24xx.c:94
S3C24XX_DEVICE_COMMAND()
Definition: s3c24xx.c:20
void * controller_priv
Definition: nand/core.h:51
struct target * target
Definition: nand/core.h:49
Definition: target.h:116
enum target_state state
Definition: target.h:157
int target_write_u8(struct target *target, target_addr_t address, uint8_t value)
Definition: target.c:2683
int target_write_u16(struct target *target, target_addr_t address, uint16_t value)
Definition: target.c:2662
int target_read_u8(struct target *target, target_addr_t address, uint8_t *value)
Definition: target.c:2598
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
Definition: target.c:2641
@ TARGET_HALTED
Definition: target.h:56
static struct ublast_lowlevel_priv info
#define NULL
Definition: usb.h:16