summaryrefslogtreecommitdiff
path: root/drivers/mtd/nand/lba/lba.h
blob: 4ad37ecbc44ffde24829c876bbcd254dba3f1c2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Freescale STMP37XX/STMP378X LBA interface
 *
 * Author: Dmitrij Frasenyak <sed@embeddedalley.com>
 *
 * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
 * Copyright 2009 Embedded Alley Solutions, Inc All Rights Reserved.
 */

/*
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

#ifndef __INCLUDE_LBA_H__
#define __INCLUDE_LBA_H__


#include <linux/spinlock.h>
#include <linux/kthread.h>
#include "gpmi.h"

struct lba_cmd {
	uint8_t len;
#define F_MASK       0x0f
#define F_ALE        0x01
#define F_CMD        0x02
#define F_DATA_READ  0x04
#define F_DATA_WRITE 0x08

#define FE_W4R        0x10
#define FE_CMD_INC    0x20
#define FE_END        0x40

	uint8_t flag;
};

#define LBA_P_READ_A 0
#define LBA_P_READ_B 2
#define LBA_P_READ_C 3
#define LBA_P_WRITE_A 0
#define LBA_P_WRITE_B 4
#define LBA_T_SIZE1 1
#define LBA_T_SIZE4 2
#define LBA_T_SIZE8 4
#define LBA_T_CRC   (1 << 6)
#define LBA_T_ECC_CHECK (2 << 6)
#define LBA_T_ECC_CORRECT (3 << 6)

struct lba_data {
	void __iomem *io_base;
	struct clk *clk;
	int irq;

	spinlock_t lock;
	int use_count;
	int mode;
	struct semaphore mode_lock;
#define LBA_MODE_MASK       0x0000ffff
#define LBA_FLAG_MASK       0xffff0000
#define LBA_MODE_RST        0
#define LBA_MODE_PNR        1
#define LBA_MODE_BCM        2
#define LBA_MODE_MDP        3
#define LBA_MODE_VFP        4
#define LBA_MODE_SUSP       5
#define LBA_MODE_SELFPM     0x80000000
	wait_queue_head_t	suspend_q;
	wait_queue_head_t	selfpm_q;
	struct task_struct	*thread;
	long long last_access;
	/* PNR specific */
	/* BCM specific */
	/* VFP specific */
	uint8_t pass[2];

	/* Size of the partiotions: pages for PNP; sectors for others */
	unsigned int   pnp_size;
	unsigned int   vfp_size;
	long long      mdp_size;
	void *priv;
	/*should be last*/
	struct gpmi_perchip_data nand[0];

};

extern struct lba_data *g_data;

void stmp37cc_dma_print_chain(struct stmp37xx_circ_dma_chain *chain);

int lba_blk_init(struct lba_data *data);
int lba_blk_remove(struct lba_data *data);
int lba_blk_suspend(struct platform_device *pdev, struct lba_data *data);
int lba_blk_resume(struct platform_device *pdev, struct lba_data *data);


int lba_core_init(struct lba_data *data);
int lba_core_remove(struct lba_data *data);
int lba_core_suspend(struct platform_device *pdev, struct lba_data *data);
int lba_core_resume(struct platform_device *pdev, struct lba_data *data);
int lba_core_lock_mode(struct lba_data *data, int mode);
int lba_core_unlock_mode(struct lba_data *data);

int lba_write_sectors(void *priv, unsigned int sector,	unsigned int count,
		      void *buffer, dma_addr_t handle);
int lba_read_sectors(void *priv, unsigned int sector,	unsigned int count,
		      void *buffer, dma_addr_t handle);
void lba_protocol1_set(void *priv, uint8_t param);
uint8_t lba_protocol1_get(void *priv);
uint8_t lba_get_status1(void *priv);
uint8_t lba_get_status2(void *priv);

uint8_t lba_get_id1(void *priv, uint8_t *ret_buffer);
uint8_t lba_get_id2(void *priv, uint8_t *);


int queue_cmd(void *priv,
	      uint8_t *cmd_buf, dma_addr_t cmd_handle, int cmd_len,
	      dma_addr_t data, int data_len,
	      struct lba_cmd *cmd_flags);

int queue_run(void *priv);

dma_addr_t queue_get_cmd_handle(void *priv);

uint8_t *queue_get_cmd_ptr(void *priv);

dma_addr_t queue_get_data_handle(void *priv);

uint8_t *queue_get_data_ptr(void *priv);

void queue_plug(struct lba_data *data);
void queue_release(struct lba_data *data);


#endif