X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fspi%2Ffsl_espi.c;h=7c845827627bc2a276e326f7119fab2c485fffc9;hb=3f56795635ab419d3378451a9291490cfa47f472;hp=a1ebd330d7bae5c2cc5a0e1c82da06ac68bae50c;hpb=606a76f8ef479e42ae4d06f8f3ce87e9a1c72acf;p=u-boot diff --git a/drivers/spi/fsl_espi.c b/drivers/spi/fsl_espi.c index a1ebd330d7..7c84582762 100644 --- a/drivers/spi/fsl_espi.c +++ b/drivers/spi/fsl_espi.c @@ -4,20 +4,7 @@ * Copyright 2010-2011 Freescale Semiconductor, Inc. * Author: Mingkai Hu (Mingkai.hu@freescale.com) * - * 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 @@ -79,18 +66,16 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, if (!spi_cs_is_valid(bus, cs)) return NULL; - fsl = malloc(sizeof(struct fsl_spi_slave)); + fsl = spi_alloc_slave(struct fsl_spi_slave, bus, cs); if (!fsl) return NULL; - fsl->slave.bus = bus; - fsl->slave.cs = cs; fsl->mode = mode; fsl->max_transfer_length = ESPI_MAX_DATA_TRANSFER_LEN; /* Set eSPI BRG clock source */ get_sys_info(&sysinfo); - spibrg = sysinfo.freqSystemBus / 2; + spibrg = sysinfo.freq_systembus / 2; fsl->div16 = 0; if ((spibrg / max_hz) > 32) { fsl->div16 = ESPI_CSMODE_DIV16; @@ -216,10 +201,8 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *data_out, return 1; } memcpy(buffer, cmd_buf, cmd_len); - if (cmd_len != 1) { - if (data_in == NULL) - memcpy(buffer + cmd_len, data_out, data_len); - } + if (data_in == NULL) + memcpy(buffer + cmd_len, data_out, data_len); break; case SPI_XFER_BEGIN | SPI_XFER_END: len = data_len; @@ -238,15 +221,13 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *data_out, slave->bus, slave->cs, *(uint *) dout, dout, *(uint *) din, din, len); - num_chunks = data_len / max_tran_len + - (data_len % max_tran_len ? 1 : 0); + num_chunks = DIV_ROUND_UP(data_len, max_tran_len); while (num_chunks--) { if (data_in) din = buffer + rx_offset; dout = buffer; tran_len = min(data_len , max_tran_len); - num_blks = (tran_len + cmd_len) / 4 + - ((tran_len + cmd_len) % 4 ? 1 : 0); + num_blks = DIV_ROUND_UP(tran_len + cmd_len, 4); num_bytes = (tran_len + cmd_len) % 4; fsl->data_len = tran_len + cmd_len; spi_cs_activate(slave);