aml_m1_nand_base_operate.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /*
  2. * AMLOGIC NAND driver.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the named License,
  7. * or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
  17. *
  18. * Changelog:
  19. *
  20. * TODO:
  21. *
  22. */
  23. #include <linux/module.h>
  24. #include <linux/types.h>
  25. #include <linux/init.h>
  26. #include <linux/kernel.h>
  27. #include <linux/string.h>
  28. #include <linux/ioport.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/delay.h>
  31. #include <linux/err.h>
  32. #include <linux/slab.h>
  33. #include <linux/io.h>
  34. #include <linux/bitops.h>
  35. #include <linux/mtd/mtd.h>
  36. #include <linux/mtd/nand.h>
  37. #include <linux/mtd/nand_ecc.h>
  38. #include <linux/mtd/partitions.h>
  39. #include <mach/nand.h>
  40. #include <mach/pinmux.h>
  41. #include <linux/dma-mapping.h>
  42. #define MAX_INFO_LEN 4*8*2
  43. #define CM0 ((1<<29) | (1<<27) | (1<<25) | (1<<23))
  44. #define SM0 (1<<30) | (1<<28) | (1<<26) | (1<<24)
  45. #define CM7 ((1<<29) | (1<<27) | (1<<28) | (1<<26)|(1<<24))
  46. struct aml_m1_nand_info
  47. {
  48. struct nand_hw_control controller;
  49. struct mtd_info mtd;
  50. struct nand_chip chip;
  51. struct aml_m1_nand_platform* platform;
  52. struct device* device;
  53. // unsigned int nand_config;
  54. unsigned int bch_mode;
  55. unsigned int encode_size;
  56. unsigned int ce_sel;
  57. // unsigned int info_buf[32];
  58. uint8_t * aml_nand_dma_buf;
  59. uint8_t * info_buf;
  60. dma_addr_t aml_nand_info_dma_addr;
  61. };
  62. static unsigned int def_sparebytes = 0x6d616d61;
  63. static struct nand_ecclayout m1_ecclayout;
  64. //FIXME , nand.h
  65. extern int nand_get_device(struct nand_chip *chip, struct mtd_info *mtd,int new_state);
  66. extern void nand_release_device(struct mtd_info *mtd);
  67. static struct aml_m1_nand_info *mtd_to_nand_info(struct mtd_info *mtd)
  68. {
  69. return container_of(mtd, struct aml_m1_nand_info, mtd);
  70. }
  71. /*static struct aml_m1_nand_info *to_nand_info(struct platform_device *pdev){
  72. return platform_get_drvdata(pdev);
  73. }
  74. */
  75. static struct aml_m1_nand_platform *to_nand_plat(struct platform_device *pdev)
  76. {
  77. return pdev->dev.platform_data;
  78. }
  79. /*get_device also slect chip add pin mux here*/
  80. static void aml_m1_nand_select_chip(struct mtd_info *mtd, int chipnr)
  81. {
  82. struct nand_chip *chip = mtd->priv;
  83. struct aml_m1_nand_info * info=mtd_to_nand_info(mtd);
  84. clear_mio_mux(1,CM0);
  85. set_mio_mux(1,SM0);
  86. set_mio_mux(6,0x7ff);
  87. clear_mio_mux(7,CM7);
  88. switch (chipnr) {
  89. case -1:
  90. chip->cmd_ctrl(mtd, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE);
  91. set_mio_mux(1,CM0);
  92. clear_mio_mux(1,SM0);
  93. clear_mio_mux(6,0x7ff);
  94. set_mio_mux(7,CM7);
  95. break;
  96. case 0:
  97. info->ce_sel=CE0;
  98. break;
  99. case 1:
  100. info->ce_sel=CE1;
  101. break;
  102. case 2:
  103. info->ce_sel=CE2;
  104. break;
  105. case 3:
  106. info->ce_sel=CE3;
  107. break;
  108. default:
  109. BUG();
  110. }
  111. NFC_SEND_CMD(info->ce_sel|IDLE | 1);
  112. return ;
  113. }
  114. static void aml_m1_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  115. {
  116. struct aml_m1_nand_info * info=mtd_to_nand_info(mtd);
  117. volatile int val=0;
  118. unsigned int ce=info->ce_sel;
  119. if (cmd == NAND_CMD_NONE)
  120. return;
  121. if (ctrl & NAND_CLE){
  122. val=NFC_CMD_CLE(ce,cmd);
  123. NFC_SEND_CMD(val);
  124. }
  125. else
  126. {
  127. val=NFC_CMD_ALE(ce,cmd);
  128. NFC_SEND_CMD(val);
  129. }
  130. return ;
  131. }
  132. static int aml_m1_nand_devready(struct mtd_info *mtd)
  133. {
  134. struct aml_m1_nand_info * info=mtd_to_nand_info(mtd);
  135. volatile int ce;
  136. if(info->ce_sel==CE0)
  137. ce=1;
  138. else
  139. if(info->ce_sel==CE1)
  140. ce=2;
  141. else
  142. if(info->ce_sel==CE2)
  143. ce=4;
  144. else
  145. if(info->ce_sel==CE3)
  146. ce=8;
  147. else
  148. BUG();
  149. return (NFC_INFO_GET()>>26)&ce;
  150. }
  151. static void aml_m1_nand_enable_hwecc(struct mtd_info *mtd, int mode)
  152. {
  153. return;
  154. }
  155. static int aml_m1_nand_calculate_ecc(struct mtd_info *mtd,const u_char *dat, u_char *ecc_code)
  156. {
  157. return 0;
  158. }
  159. static int aml_m1_nand_correct_data(struct mtd_info *mtd, u_char *dat,u_char *read_ecc, u_char *calc_ecc)
  160. {
  161. return 0;
  162. }
  163. static uint8_t aml_m1_nand_read_byte(struct mtd_info *mtd)
  164. {
  165. uint8_t val;
  166. struct aml_m1_nand_info * info=mtd_to_nand_info(mtd);
  167. unsigned int ce=info->ce_sel;
  168. /* memset(&info->info_buf[1],0,sizeof(unsigned int));
  169. NFC_SET_DADDR(&info->info_buf[0]);
  170. NFC_SET_IADDR(&info->info_buf[1]);
  171. NFC_SEND_CMD_N2M(1,0);
  172. while(NAND_INFO_DONE(info->info_buf[1])==0);
  173. val=info->info_buf[0]&0xff;
  174. */
  175. NFC_SEND_CMD(ce|DRD | 0);
  176. NFC_SEND_CMD(ce|IDLE | 5);
  177. while(NFC_CMDFIFO_SIZE()>0);
  178. val=NFC_GET_BUF()&0xff;
  179. return val;
  180. }
  181. /*
  182. static void prepare_info_buf_before_read(struct mtd_info *mtd,int len)
  183. {
  184. struct aml_m1_nand_info * aml_info=mtd_to_nand_info(mtd);
  185. memset(aml_info->info_buf,0,32*sizeof(int));
  186. }*/
  187. static int transfer_info_buf_after_read(struct mtd_info *mtd,int len)
  188. {
  189. struct aml_m1_nand_info * aml_info=mtd_to_nand_info(mtd);
  190. struct nand_chip *chip = mtd->priv;
  191. volatile uint16_t *p=(uint16_t *)chip->oob_poi;
  192. volatile uint8_t *ptr=(uint8_t *)chip->oob_poi;
  193. volatile int * pinfobuf=(uint32_t *)aml_info->info_buf;
  194. int i;
  195. int res=0;
  196. for(i=0;i<len;i++)
  197. {
  198. if(NAND_ECC_FAIL(pinfobuf[i]))
  199. {
  200. mtd->ecc_stats.failed++;
  201. res=1; //FIXME -1 for err
  202. }
  203. else
  204. mtd->ecc_stats.corrected+=NAND_ECC_CNT(pinfobuf[i]);
  205. if(aml_info->bch_mode!=NAND_ECC_BCH9)
  206. p[i]=pinfobuf[i]&0xffff;
  207. // p[i]=aml_info->info_buf[i]&0xffff;
  208. else
  209. ptr[i]=pinfobuf[i]&0xff;
  210. // ptr[i]=aml_info->info_buf[i]&0xff;
  211. }
  212. return res;
  213. }
  214. /* for write oob use
  215. * */
  216. static void prepare_info_buf_before_write(struct mtd_info *mtd,int len, int ecc)
  217. {
  218. int i;
  219. struct aml_m1_nand_info *aml_info=mtd_to_nand_info(mtd);
  220. struct nand_chip *chip = mtd->priv;
  221. volatile uint16_t *p =(uint16_t *)chip->oob_poi;
  222. volatile uint8_t *ptr =(uint8_t *)chip->oob_poi;
  223. volatile uint32_t *pinfobuf=(uint32_t *)aml_info->info_buf;
  224. if(ecc!=AML_NAND_ECC_NONE)
  225. {
  226. for(i=0;i<len;i++)
  227. {
  228. if(aml_info->bch_mode!=NAND_ECC_BCH9)
  229. pinfobuf[i]=p[i];
  230. else
  231. pinfobuf[i]=ptr[i];
  232. }
  233. }
  234. else
  235. {
  236. for(i=0;i<len;i++)
  237. {
  238. pinfobuf[i]=def_sparebytes;
  239. }
  240. }
  241. }
  242. static int aml_m1_nand_dma_read(struct mtd_info *mtd, uint8_t *buf, int len,int ecc)
  243. {
  244. struct aml_m1_nand_info * aml_info=mtd_to_nand_info(mtd);
  245. volatile int res=0;
  246. dma_addr_t data_dma_addr=0;
  247. volatile unsigned int * pbuf=(unsigned int *)((unsigned char *)aml_info->info_buf+((len>>9)-1)*4);
  248. memset(aml_info->info_buf,0,32*sizeof(int));
  249. if(buf)
  250. {
  251. data_dma_addr=dma_map_single(aml_info->device,(void *)buf,len,DMA_FROM_DEVICE);
  252. // NFC_SEND_CMD_ADL(aml_info->aml_nand_dma_addr) ;
  253. // NFC_SEND_CMD_ADH(aml_info->aml_nand_dma_addr) ;
  254. NFC_SEND_CMD_ADL(data_dma_addr);
  255. NFC_SEND_CMD_ADH(data_dma_addr);
  256. }
  257. NFC_SEND_CMD_AIL(aml_info->aml_nand_info_dma_addr);
  258. NFC_SEND_CMD_AIH((aml_info->aml_nand_info_dma_addr));
  259. NFC_SEND_CMD_N2M(len,ecc);
  260. while(NFC_CMDFIFO_SIZE()>0);
  261. while(NAND_INFO_DONE(*pbuf)==0);
  262. if(buf)
  263. dma_unmap_single(aml_info->device,data_dma_addr,len,DMA_FROM_DEVICE);
  264. if(ecc!=AML_NAND_ECC_NONE)
  265. res=transfer_info_buf_after_read(mtd,(len+511)>>9);
  266. return res;
  267. }
  268. static void aml_m1_nand_dma_write(struct mtd_info *mtd, const uint8_t *buf, int len,int ecc)
  269. {
  270. struct aml_m1_nand_info * aml_info=mtd_to_nand_info(mtd);
  271. dma_addr_t data_dma_addr;
  272. prepare_info_buf_before_write(mtd,(len+511)>>9,ecc);
  273. // NFC_SET_DADDR(buf);
  274. // NFC_SET_IADDR(aml_info->info_buf);
  275. data_dma_addr=dma_map_single(aml_info->device,(void *)buf,len,DMA_TO_DEVICE);
  276. NFC_SEND_CMD_ADL(data_dma_addr);
  277. NFC_SEND_CMD_ADH(data_dma_addr);
  278. NFC_SEND_CMD_AIL(aml_info->aml_nand_info_dma_addr);
  279. NFC_SEND_CMD_AIH(aml_info->aml_nand_info_dma_addr);
  280. NFC_SEND_CMD_M2N(len,ecc);
  281. NFC_SEND_CMD_IDLE(aml_info->ce_sel,0);
  282. NFC_SEND_CMD_IDLE(aml_info->ce_sel,0);
  283. while(NFC_CMDFIFO_SIZE()>0);
  284. dma_unmap_single(aml_info->device,data_dma_addr,len,DMA_TO_DEVICE);
  285. }
  286. static void aml_m1_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
  287. {
  288. aml_m1_nand_dma_read(mtd,buf,len,AML_NAND_ECC_NONE);
  289. }
  290. static void aml_m1_nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
  291. {
  292. aml_m1_nand_dma_write(mtd,buf,len,AML_NAND_ECC_NONE);
  293. }
  294. static int aml_m1_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,uint8_t *buf,int page)
  295. {
  296. struct aml_m1_nand_info * aml_info=mtd_to_nand_info(mtd);
  297. return aml_m1_nand_dma_read(mtd,buf,mtd->writesize,aml_info->bch_mode);
  298. }
  299. static void aml_m1_nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, const uint8_t *buf)
  300. {
  301. struct aml_m1_nand_info * aml_info=mtd_to_nand_info(mtd);
  302. aml_m1_nand_dma_write(mtd,buf,mtd->writesize,aml_info->bch_mode);
  303. }
  304. static int aml_m1_nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,uint8_t *buf,int page)
  305. {
  306. BUG();
  307. return 0;
  308. }
  309. static int aml_m1_nand_read_oob(struct mtd_info *mtd, struct nand_chip *chip,int page, int sndcmd)
  310. {
  311. struct aml_m1_nand_info * aml_info=mtd_to_nand_info(mtd);
  312. int res=0;
  313. chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
  314. NFC_SET_SPARE_ONLY();
  315. res=aml_m1_nand_dma_read(mtd,aml_info->aml_nand_dma_buf,mtd->writesize,aml_info->bch_mode); //confilct chip->buffers?
  316. NFC_CLEAR_SPARE_ONLY();
  317. //BUG();
  318. return res;
  319. }
  320. static int aml_m1_nand_write_oob(struct mtd_info *mtd, struct nand_chip *chip,int page)
  321. {
  322. BUG();
  323. return -EIO;
  324. }
  325. static int aml_m1_nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
  326. {
  327. volatile int ret=0,chipnr;
  328. struct nand_chip * chip=mtd->priv;
  329. struct aml_m1_nand_info * aml_info=mtd_to_nand_info(mtd);
  330. volatile int page = (int)(ofs >> chip->page_shift)&chip->pagemask;
  331. volatile unsigned int size=((mtd->writesize+mtd->oobsize)/(aml_info->encode_size))<<9; //FIXME for boot!=normal
  332. if(getchip)
  333. {
  334. nand_get_device(chip,mtd,FL_READING);
  335. chipnr = (int)(ofs>>chip->chip_shift);
  336. chip->select_chip(mtd, chipnr);
  337. }
  338. NFC_SET_SPARE_ONLY();
  339. chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
  340. // ret=aml_m1_nand_dma_read(mtd,aml_info->aml_nand_dma_buf,size,aml_info->bch_mode); //confilct chip->buffers?
  341. ret=aml_m1_nand_dma_read(mtd,NULL,size,aml_info->bch_mode);
  342. NFC_CLEAR_SPARE_ONLY();
  343. if(getchip)
  344. nand_release_device(mtd);
  345. return ret;
  346. }
  347. static int aml_m1_nand_block_markbad(struct mtd_info *mtd, loff_t ofs)
  348. {
  349. printk(" MARK the BAD BLOCK , NOT IMPLENMENT\n");
  350. BUG();
  351. return 0;
  352. }
  353. static int aml_m1_nand_hw_init(struct aml_m1_nand_info *info)
  354. {
  355. struct aml_m1_nand_platform *plat = info->platform;
  356. volatile unsigned mode,cycles,adjust=0;
  357. volatile unsigned tmp=0xffff;
  358. mode=plat->timing_mode;
  359. if(mode==5){
  360. cycles= 3;
  361. }else if(mode==0)
  362. cycles=19;
  363. else if(mode==4){
  364. cycles=4;
  365. }else if(mode==3){
  366. cycles=5;
  367. }else if(mode==2){
  368. cycles=6;
  369. }else if(mode==1){
  370. cycles=9;
  371. }
  372. else{
  373. mode =0;
  374. cycles=19;
  375. }
  376. clear_mio_mux(1,( (1<<29) | (1<<27) | (1<<25) | (1<<23)));
  377. set_mio_mux(1,(1<<30) | (1<<28) | (1<<26) | (1<<24));
  378. set_mio_mux(6,0x7ff);
  379. clear_mio_mux(7,((1<<29) | (1<<27) | (1<<28) | (1<<26))|(1<<24));
  380. NFC_SET_CFG(0);
  381. NFC_SET_TIMING(0,19,0) ;
  382. NFC_SEND_CMD(1<<31);
  383. while (NFC_CMDFIFO_SIZE() > 0);
  384. if(plat->onfi_mode==1)
  385. {
  386. /* NFC_SEND_CMD_CLE(CE0,0xff);
  387. NFC_SEND_CMD_IDLE(CE0,10);
  388. while (!(NFC_INFO_GET()&(1<<26)));
  389. printk("NAND SET ONFI MODE %d \n",mode);
  390. NFC_SEND_CMD_CLE(CE0,0xef);
  391. NFC_SEND_CMD_ALE(CE0,0x1);
  392. NFC_SEND_CMD_IDLE(CE0,3);
  393. NFC_SEND_CMD_DWR(mode);
  394. NFC_SEND_CMD_DWR(0);
  395. NFC_SEND_CMD_DWR(0);
  396. NFC_SEND_CMD_DWR(0);
  397. NFC_SEND_CMD_IDLE(CE0,5);
  398. while (NFC_CMDFIFO_SIZE() > 0);
  399. while (!(NFC_INFO_GET()&(1<<26)));
  400. NFC_SEND_CMD_CLE(CE0,0xee);
  401. NFC_SEND_CMD_ALE(CE0,0x1);
  402. NFC_SEND_CMD_IDLE(CE0,3);
  403. // while (NFC_CMDFIFO_SIZE() > 0);
  404. while (!(NFC_INFO_GET()&(1<<26)));
  405. //NFC_SEND_CMD_IDLE(CE0,3);
  406. NFC_SEND_CMD(CE0|DRD | 3);
  407. // NFC_SEND_CMD(CE0|IDLE | 5);
  408. while(NFC_CMDFIFO_SIZE()>0);
  409. tmp=NFC_GET_BUF();
  410. printk("NAND GET ONFI MODE %d \n", tmp);
  411. */
  412. }
  413. NFC_SET_TIMING(mode,cycles,adjust);
  414. printk("NAND CONFIG IS 0x%4x \n",NFC_GET_CFG());
  415. NFC_SEND_CMD(1<<31);
  416. while (NFC_CMDFIFO_SIZE() > 0);
  417. return 0;
  418. }
  419. static int aml_m1_nand_add_partition(struct aml_m1_nand_info *info)
  420. {
  421. struct mtd_info *mtd = &info->mtd;
  422. #ifdef CONFIG_MTD_PARTITIONS
  423. struct mtd_partition *parts = info->platform->partitions;
  424. int nr = info->platform->nr_partitions;
  425. return add_mtd_partitions(mtd, parts, nr);
  426. #else
  427. return add_mtd_device(mtd);
  428. #endif
  429. }
  430. static int aml_m1_nand_probe(struct platform_device *pdev)
  431. {
  432. struct aml_m1_nand_platform *plat = to_nand_plat(pdev);
  433. struct aml_m1_nand_info *info = NULL;
  434. struct nand_chip *chip = NULL;
  435. struct mtd_info *mtd = NULL;
  436. int err = 0;
  437. dev_dbg(&pdev->dev, "(%p)\n", pdev);
  438. // printk("NAND probe \n");
  439. if (!plat)
  440. {
  441. dev_err(&pdev->dev, "no platform specific information\n");
  442. goto exit_error;
  443. }
  444. info = kzalloc(sizeof(*info), GFP_KERNEL);
  445. if (info == NULL)
  446. {
  447. dev_err(&pdev->dev, "no memory for flash info\n");
  448. err = -ENOMEM;
  449. goto exit_error;
  450. }
  451. platform_set_drvdata(pdev, info);
  452. spin_lock_init(&info->controller.lock);
  453. init_waitqueue_head(&info->controller.wq);
  454. pdev->dev.coherent_dma_mask =DMA_BIT_MASK(32);
  455. info->device = &pdev->dev;
  456. info->platform = plat;
  457. info->bch_mode = plat->bch_mode;
  458. info->encode_size= plat->encode_size;
  459. chip = &info->chip;
  460. chip->buffers = kmalloc(sizeof(struct nand_buffers), GFP_KERNEL);
  461. if (info->chip.buffers == NULL)
  462. {
  463. dev_err(&pdev->dev, "no memory for flash info\n");
  464. err = -ENOMEM;
  465. goto exit_error;
  466. }
  467. chip->options |= NAND_OWN_BUFFERS;
  468. chip->options |= NAND_SKIP_BBTSCAN;
  469. chip->options &= ~NAND_BUSWIDTH_16 ;
  470. chip->read_byte =aml_m1_nand_read_byte;
  471. chip->cmd_ctrl =aml_m1_nand_hwcontrol;
  472. chip->dev_ready =aml_m1_nand_devready;
  473. chip->block_bad =aml_m1_nand_block_bad;
  474. chip->block_markbad =aml_m1_nand_block_markbad;
  475. chip->priv =&info->mtd;
  476. chip->controller =&info->controller;
  477. chip->chip_delay = 20; //us unit
  478. chip->select_chip=aml_m1_nand_select_chip;
  479. mtd = &info->mtd;
  480. mtd->priv = chip;
  481. mtd->owner = THIS_MODULE;
  482. // nand_get_chip(); //pinmux chipnum
  483. err = aml_m1_nand_hw_init(info);
  484. if (err != 0)
  485. goto exit_error;
  486. if(plat->page_size!=512)
  487. {
  488. chip->ecc.steps = 1;
  489. chip->ecc.bytes = plat->spare_size; //for simple step 1
  490. chip->ecc.size = plat->page_size;
  491. chip->phys_erase_shift=ffs(plat->erase_size)-1;
  492. chip->read_buf = aml_m1_nand_read_buf;
  493. chip->write_buf = aml_m1_nand_write_buf;
  494. chip->ecc.read_page = aml_m1_nand_read_page;
  495. chip->ecc.write_page= aml_m1_nand_write_page;
  496. chip->ecc.read_oob = aml_m1_nand_read_oob;
  497. chip->ecc.write_oob = aml_m1_nand_write_oob;
  498. chip->ecc.calculate = aml_m1_nand_calculate_ecc;
  499. chip->ecc.correct = aml_m1_nand_correct_data;
  500. chip->ecc.mode = NAND_ECC_HW;
  501. chip->ecc.hwctl = aml_m1_nand_enable_hwecc;
  502. chip->ecc.read_page_raw=aml_m1_nand_read_page_raw;
  503. chip->ecc.layout = &m1_ecclayout;
  504. m1_ecclayout.oobavail =(plat->page_size/512)*((plat->bch_mode!=NAND_ECC_BCH9)?2:1);
  505. m1_ecclayout.oobfree[0].offset=0;
  506. m1_ecclayout.oobfree[0].length=m1_ecclayout.oobavail; //FIXME base 2960
  507. info->aml_nand_dma_buf = kzalloc(plat->page_size+plat->spare_size, GFP_KERNEL);
  508. if (info->aml_nand_dma_buf == NULL)
  509. {
  510. dev_err(&pdev->dev, "no memory for flash info\n");
  511. err = -ENOMEM;
  512. goto exit_error;
  513. }
  514. info->info_buf= dma_alloc_coherent(info->device,32*sizeof(int),&(info->aml_nand_info_dma_addr),GFP_KERNEL);
  515. if (info->info_buf== NULL)
  516. {
  517. dev_err(&pdev->dev, "no memory for flash info\n");
  518. err = -ENOMEM;
  519. goto exit_error;
  520. }
  521. //((unsigned)aml_nand_dma_buf_temp+ARC_DCACHE_LINE_LEN-1)&DCACHE_LINE_MASK;
  522. }
  523. else
  524. {
  525. BUG();
  526. }
  527. if (nand_scan(mtd, plat->chip_num)) //FIXME chip_num!=ce_num
  528. {
  529. err = -ENXIO;
  530. goto exit_error;
  531. }
  532. if(aml_m1_nand_add_partition(info)!=0)
  533. {
  534. err = -ENXIO;
  535. goto exit_error;
  536. }
  537. dev_dbg(&pdev->dev, "initialised ok\n");
  538. printk("NAND initialised ok\n");
  539. //nand_release_chip();
  540. return 0;
  541. exit_error:
  542. printk("NAND initialised err\n");
  543. kfree(info);
  544. if (err == 0)
  545. err = -EINVAL;
  546. return err;
  547. }
  548. #define DRV_NAME "aml_m1_nand"
  549. #define DRV_VERSION "0.1"
  550. #define DRV_AUTHOR "pfs"
  551. #define DRV_DESC "Amlogic M1 on-chip NAND FLash Controller Driver"
  552. static struct platform_driver aml_m1_nand_driver =
  553. {
  554. .probe = aml_m1_nand_probe,
  555. .driver =
  556. {
  557. .name = DRV_NAME,
  558. .owner = THIS_MODULE,
  559. },
  560. };
  561. static int __init aml_m1_nand_init(void)
  562. {
  563. // printk(KERN_INFO "%s, Version %s (c) 2010 Amlogic Inc.\n",DRV_DESC, DRV_VERSION);
  564. // asm("wfi");
  565. return platform_driver_register(&aml_m1_nand_driver);
  566. }
  567. static void __exit aml_m1_nand_exit(void)
  568. {
  569. platform_driver_unregister(&aml_m1_nand_driver);
  570. }
  571. module_init(aml_m1_nand_init);
  572. module_exit(aml_m1_nand_exit);
  573. MODULE_LICENSE("GPL");
  574. MODULE_AUTHOR(DRV_AUTHOR);
  575. MODULE_DESCRIPTION(DRV_DESC);