/*------------------------------------------------------------------------------------------*\ * * Copyright (C) 2014 AVM GmbH * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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 \*------------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------------*\ * Quick'n'dirty hack to access SPI flash for TFFS in panic mode \*------------------------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include #define FLASH_SUCCESS 0 #define FLASH_INVAL_ADDR 0x8002 #define FLASH_ID_FAILED 0x8003 #define FLASH_QUERY_FAILED 0x8004 #define FLASH_ERASE_REGIONS 0x8005 #define FLASH_MX_BOTTOM_FAILED 0x8006 extern int vx185_snor_panic_reinit(void); extern struct mtd_info *fusiv_tffs_mtd[2]; static unsigned int init_done = 0; int tffs_spi_read(unsigned int address, unsigned int mtd_id, unsigned char *pdata, unsigned int len) { struct mtd_info *mtd; size_t retlen; int result; mtd = fusiv_tffs_mtd[mtd_id]; retlen = 0; result = mtd->read(mtd, address, len, &retlen, pdata); return retlen; } /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ int tffs_spi_write(unsigned int address, unsigned int mtd_id, unsigned char *pdata, unsigned int len) { struct mtd_info *mtd; size_t retlen; int result; mtd = fusiv_tffs_mtd[mtd_id]; retlen = 0; result = mtd->write(mtd, address, len, &retlen, pdata); return retlen; } int tffs_spi_init(void) { int result = 0; if(!init_done){ if(fusiv_tffs_mtd[0] == NULL || fusiv_tffs_mtd[1] == NULL){ result = -ENODEV; } else { result = vx185_snor_panic_reinit(); } } return result; }