X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fmtd%2Fspi%2Feeprom_m95xxx.c;h=a019939b8b926f8d0181160ffb6741bd27c167e4;hb=080d897585428d0fd42c237abfb6746908f4effc;hp=632db4e9e0a60c57ab94a4c54a2b2b9123cb42d0;hpb=83653121d7382fccfe329cb732f77f116341ef1d;p=u-boot diff --git a/drivers/mtd/spi/eeprom_m95xxx.c b/drivers/mtd/spi/eeprom_m95xxx.c index 632db4e9e0..a019939b8b 100644 --- a/drivers/mtd/spi/eeprom_m95xxx.c +++ b/drivers/mtd/spi/eeprom_m95xxx.c @@ -2,23 +2,7 @@ * Copyright (C) 2009 * Albin Tonnerre, Free Electrons * - * See file CREDITS for list of people who contributed to this - * project. - * - * 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 + * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -37,33 +21,37 @@ #define CONFIG_DEFAULT_SPI_MODE SPI_MODE_0 #endif -ssize_t spi_read (uchar *addr, int alen, uchar *buffer, int len) +#ifndef CONFIG_SYS_SPI_WRITE_TOUT +#define CONFIG_SYS_SPI_WRITE_TOUT (5 * CONFIG_SYS_HZ) +#endif + +ssize_t spi_read(uchar *addr, int alen, uchar *buffer, int len) { struct spi_slave *slave; u8 cmd = SPI_EEPROM_READ; slave = spi_setup_slave(CONFIG_DEFAULT_SPI_BUS, 1, 1000000, CONFIG_DEFAULT_SPI_MODE); - if(!slave) + if (!slave) return 0; spi_claim_bus(slave); /* command */ - if(spi_xfer(slave, 8, &cmd, NULL, SPI_XFER_BEGIN)) + if (spi_xfer(slave, 8, &cmd, NULL, SPI_XFER_BEGIN)) return -1; /* - * if alen == 3, addr[0] is the block number, we never use it here. All we - * need are the lower 16 bits + * if alen == 3, addr[0] is the block number, we never use it here. + * All we need are the lower 16 bits. */ if (alen == 3) addr++; /* address, and data */ - if(spi_xfer(slave, 16, addr, NULL, 0)) + if (spi_xfer(slave, 16, addr, NULL, 0)) return -1; - if(spi_xfer(slave, 8 * len, NULL, buffer, SPI_XFER_END)) + if (spi_xfer(slave, 8 * len, NULL, buffer, SPI_XFER_END)) return -1; spi_release_bus(slave); @@ -71,10 +59,11 @@ ssize_t spi_read (uchar *addr, int alen, uchar *buffer, int len) return len; } -ssize_t spi_write (uchar *addr, int alen, uchar *buffer, int len) +ssize_t spi_write(uchar *addr, int alen, uchar *buffer, int len) { struct spi_slave *slave; char buf[3]; + ulong start; slave = spi_setup_slave(CONFIG_DEFAULT_SPI_BUS, 1, 1000000, CONFIG_DEFAULT_SPI_MODE); @@ -84,7 +73,7 @@ ssize_t spi_write (uchar *addr, int alen, uchar *buffer, int len) spi_claim_bus(slave); buf[0] = SPI_EEPROM_WREN; - if(spi_xfer(slave, 8, buf, NULL, SPI_XFER_BEGIN | SPI_XFER_END)) + if (spi_xfer(slave, 8, buf, NULL, SPI_XFER_BEGIN | SPI_XFER_END)) return -1; buf[0] = SPI_EEPROM_WRITE; @@ -97,12 +86,12 @@ ssize_t spi_write (uchar *addr, int alen, uchar *buffer, int len) memcpy(buf + 1, addr, alen); /* command + addr, then data */ - if(spi_xfer(slave, 24, buf, NULL, SPI_XFER_BEGIN)) + if (spi_xfer(slave, 24, buf, NULL, SPI_XFER_BEGIN)) return -1; - if(spi_xfer(slave, len * 8, buffer, NULL, SPI_XFER_END)) + if (spi_xfer(slave, len * 8, buffer, NULL, SPI_XFER_END)) return -1; - reset_timer_masked(); + start = get_timer(0); do { buf[0] = SPI_EEPROM_RDSR; buf[1] = 0; @@ -111,10 +100,10 @@ ssize_t spi_write (uchar *addr, int alen, uchar *buffer, int len) if (!(buf[1] & 1)) break; - } while (get_timer_masked() < CONFIG_SYS_SPI_WRITE_TOUT); + } while (get_timer(start) < CONFIG_SYS_SPI_WRITE_TOUT); if (buf[1] & 1) - printf ("*** spi_write: Time out while writing!\n"); + printf("*** spi_write: Timeout while writing!\n"); spi_release_bus(slave); spi_free_slave(slave);