* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
/*
#include "arm_io.h"
#include <target/arm.h>
-struct nuc910_nand_controller
-{
- struct target *target;
+struct nuc910_nand_controller {
struct arm_nand_data io;
};
static int validate_target_state(struct nand_device *nand)
{
- struct nuc910_nand_controller *nuc910_nand = nand->controller_priv;
- struct target *target = nuc910_nand->target;
+ struct target *target = nand->target;
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
static int nuc910_nand_command(struct nand_device *nand, uint8_t command)
{
- struct nuc910_nand_controller *nuc910_nand = nand->controller_priv;
- struct target *target = nuc910_nand->target;
+ struct target *target = nand->target;
int result;
- if ((result = validate_target_state(nand)) != ERROR_OK)
+ result = validate_target_state(nand);
+ if (result != ERROR_OK)
return result;
target_write_u8(target, NUC910_SMCMD, command);
static int nuc910_nand_address(struct nand_device *nand, uint8_t address)
{
- struct nuc910_nand_controller *nuc910_nand = nand->controller_priv;
- struct target *target = nuc910_nand->target;
+ struct target *target = nand->target;
int result;
- if ((result = validate_target_state(nand)) != ERROR_OK)
+ result = validate_target_state(nand);
+ if (result != ERROR_OK)
return result;
target_write_u32(target, NUC910_SMADDR, ((address & 0xff) | NUC910_SMADDR_EOA));
static int nuc910_nand_read(struct nand_device *nand, void *data)
{
- struct nuc910_nand_controller *nuc910_nand = nand->controller_priv;
- struct target *target = nuc910_nand->target;
+ struct target *target = nand->target;
int result;
- if ((result = validate_target_state(nand)) != ERROR_OK)
+ result = validate_target_state(nand);
+ if (result != ERROR_OK)
return result;
target_read_u8(target, NUC910_SMDATA, data);
static int nuc910_nand_write(struct nand_device *nand, uint16_t data)
{
- struct nuc910_nand_controller *nuc910_nand = nand->controller_priv;
- struct target *target = nuc910_nand->target;
+ struct target *target = nand->target;
int result;
- if ((result = validate_target_state(nand)) != ERROR_OK)
+ result = validate_target_state(nand);
+ if (result != ERROR_OK)
return result;
target_write_u8(target, NUC910_SMDATA, data);
struct nuc910_nand_controller *nuc910_nand = nand->controller_priv;
int result;
- if ((result = validate_target_state(nand)) != ERROR_OK)
+ result = validate_target_state(nand);
+ if (result != ERROR_OK)
return result;
nuc910_nand->io.chunk_size = nand->page_size;
struct nuc910_nand_controller *nuc910_nand = nand->controller_priv;
int result;
- if ((result = validate_target_state(nand)) != ERROR_OK)
+ result = validate_target_state(nand);
+ if (result != ERROR_OK)
return result;
nuc910_nand->io.chunk_size = nand->page_size;
static int nuc910_nand_ready(struct nand_device *nand, int timeout)
{
- struct nuc910_nand_controller *nuc910_nand = nand->controller_priv;
- struct target *target = nuc910_nand->target;
+ struct target *target = nand->target;
uint32_t status;
do {
target_read_u32(target, NUC910_SMISR, &status);
- if (status & NUC910_SMISR_RB_) {
+ if (status & NUC910_SMISR_RB_)
return 1;
- }
alive_sleep(1);
} while (timeout-- > 0);
nuc910_nand = calloc(1, sizeof(struct nuc910_nand_controller));
if (!nuc910_nand) {
- LOG_ERROR("no memory for nand controller\n");
+ LOG_ERROR("no memory for nand controller");
return ERROR_NAND_DEVICE_INVALID;
}
nand->controller_priv = nuc910_nand;
- nuc910_nand->target = get_target(CMD_ARGV[1]);
- if (!nuc910_nand->target) {
- LOG_ERROR("target '%s' not defined", CMD_ARGV[1]);
- free(nuc910_nand);
- return ERROR_NAND_DEVICE_INVALID;
- }
-
return ERROR_OK;
}
static int nuc910_nand_init(struct nand_device *nand)
{
struct nuc910_nand_controller *nuc910_nand = nand->controller_priv;
- struct target *target = nuc910_nand->target;
- int bus_width = nand->bus_width ? : 8;
+ struct target *target = nand->target;
+ int bus_width = nand->bus_width ? nand->bus_width : 8;
int result;
- if ((result = validate_target_state(nand)) != ERROR_OK)
+ result = validate_target_state(nand);
+ if (result != ERROR_OK)
return result;
/* nuc910 only supports 8bit */
- if (bus_width != 8)
- {
+ if (bus_width != 8) {
LOG_ERROR("nuc910 only supports 8 bit bus width, not %i", bus_width);
return ERROR_NAND_OPERATION_NOT_SUPPORTED;
}
return ERROR_OK;
}
-struct nand_flash_controller nuc910_nand_controller =
-{
+struct nand_flash_controller nuc910_nand_controller = {
.name = "nuc910",
.command = nuc910_nand_command,
.address = nuc910_nand_address,