drivers/spi: Re-factor spi_crop_chunk

spi_crop_chunk is a property of the SPI controller since it depends
upon the maximum transfer size that is supported by the
controller. Also, it is possible to implement this within spi-generic
layer by obtaining following parameters from the controller:

1. max_xfer_size: Maximum transfer size supported by the controller
(Size of 0 indicates invalid size, and unlimited transfer size is
indicated by UINT32_MAX.)

2. deduct_cmd_len: Whether cmd_len needs to be deducted from the
max_xfer_size to determine max data size that can be
transferred. (This is used by the amd boards.)

Change-Id: I81c199413f879c664682088e93bfa3f91c6a46e5
Signed-off-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-on: https://review.coreboot.org/19386
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Tested-by: coreboot org <coreboot.org@gmail.com>
This commit is contained in:
Furquan Shaikh 2017-04-19 19:27:28 -07:00 committed by Martin Roth
parent f1db5fdb4d
commit de705fa1f4
37 changed files with 92 additions and 119 deletions

View File

@ -97,7 +97,7 @@ static int adesto_write(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) { for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size; byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr); chunk_len = min(len - actual, page_size - byte_addr);
chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len); chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_AT25DF_PP; cmd[0] = CMD_AT25DF_PP;
cmd[1] = (offset >> 16) & 0xff; cmd[1] = (offset >> 16) & 0xff;

View File

@ -79,7 +79,7 @@ static int amic_write(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) { for (actual = 0; actual < len; actual += chunk_len) {
chunk_len = min(len - actual, page_size - byte_addr); chunk_len = min(len - actual, page_size - byte_addr);
chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len); chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_A25_PP; cmd[0] = CMD_A25_PP;
cmd[1] = (offset >> 16) & 0xff; cmd[1] = (offset >> 16) & 0xff;

View File

@ -125,7 +125,7 @@ static int atmel_write(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) { for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size; byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr); chunk_len = min(len - actual, page_size - byte_addr);
chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len); chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_AT25_PP; cmd[0] = CMD_AT25_PP;
cmd[1] = (offset >> 16) & 0xff; cmd[1] = (offset >> 16) & 0xff;

View File

@ -95,7 +95,7 @@ static int eon_write(const struct spi_flash *flash,
for (actual = 0; actual < len; actual += chunk_len) { for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size; byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr); chunk_len = min(len - actual, page_size - byte_addr);
chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len); chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
ret = spi_flash_cmd(&flash->spi, CMD_EN25_WREN, NULL, 0); ret = spi_flash_cmd(&flash->spi, CMD_EN25_WREN, NULL, 0);
if (ret < 0) { if (ret < 0) {

View File

@ -136,7 +136,7 @@ static int gigadevice_write(const struct spi_flash *flash, u32 offset,
for (actual = 0; actual < len; actual += chunk_len) { for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size; byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr); chunk_len = min(len - actual, page_size - byte_addr);
chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len); chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
ret = spi_flash_cmd(&flash->spi, CMD_GD25_WREN, NULL, 0); ret = spi_flash_cmd(&flash->spi, CMD_GD25_WREN, NULL, 0);
if (ret < 0) { if (ret < 0) {

View File

@ -164,7 +164,7 @@ static int macronix_write(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) { for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size; byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr); chunk_len = min(len - actual, page_size - byte_addr);
chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len); chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_MX25XX_PP; cmd[0] = CMD_MX25XX_PP;
cmd[1] = (offset >> 16) & 0xff; cmd[1] = (offset >> 16) & 0xff;

View File

@ -217,7 +217,7 @@ static int spansion_write(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) { for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size; byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr); chunk_len = min(len - actual, page_size - byte_addr);
chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len); chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_S25FLXX_PP; cmd[0] = CMD_S25FLXX_PP;
cmd[1] = (offset >> 16) & 0xff; cmd[1] = (offset >> 16) & 0xff;

View File

@ -88,6 +88,25 @@ int spi_xfer(const struct spi_slave *slave, const void *dout, size_t bytesout,
return -1; return -1;
} }
unsigned int spi_crop_chunk(const struct spi_slave *slave, unsigned int cmd_len,
unsigned int buf_len)
{
const struct spi_ctrlr *ctrlr = slave->ctrlr;
unsigned int ctrlr_max;
if (!ctrlr)
return 0;
ctrlr_max = ctrlr->max_xfer_size;
assert (ctrlr_max != 0);
if (ctrlr->deduct_cmd_len && (ctrlr_max > cmd_len))
ctrlr_max -= cmd_len;
return min(ctrlr_max, buf_len);
}
void __attribute__((weak)) spi_init(void) void __attribute__((weak)) spi_init(void)
{ {
/* Default weak implementation - do nothing. */ /* Default weak implementation - do nothing. */

View File

@ -46,7 +46,7 @@ void spiconsole_tx_byte(unsigned char c) {
}; };
/* Verify the spi buffer is big enough to send even a single byte */ /* Verify the spi buffer is big enough to send even a single byte */
if (spi_crop_chunk(0,MAX_MSG_LENGTH) < if (spi_crop_chunk(&slave, 0, MAX_MSG_LENGTH) <
sizeof(struct em100_msg_header) + 1) sizeof(struct em100_msg_header) + 1)
return; return;
@ -55,7 +55,7 @@ void spiconsole_tx_byte(unsigned char c) {
/* Send the data on newline or when the max spi length is reached */ /* Send the data on newline or when the max spi length is reached */
if (c == '\n' || (sizeof(struct em100_msg_header) + if (c == '\n' || (sizeof(struct em100_msg_header) +
msg.header.msg_length == spi_crop_chunk(0, msg.header.msg_length == spi_crop_chunk(&slave, 0,
MAX_MSG_LENGTH))) { MAX_MSG_LENGTH))) {
spi_xfer(&slave, &msg, sizeof(struct em100_msg_header) + spi_xfer(&slave, &msg, sizeof(struct em100_msg_header) +
msg.header.msg_length, NULL, 0); msg.header.msg_length, NULL, 0);

View File

@ -194,7 +194,7 @@ static int sst_write_256(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) { for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size; byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr); chunk_len = min(len - actual, page_size - byte_addr);
chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len); chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_SST_BP; cmd[0] = CMD_SST_BP;
cmd[1] = (offset >> 16) & 0xff; cmd[1] = (offset >> 16) & 0xff;

View File

@ -193,7 +193,7 @@ static int stmicro_write(const struct spi_flash *flash,
for (actual = 0; actual < len; actual += chunk_len) { for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size; byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr); chunk_len = min(len - actual, page_size - byte_addr);
chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len); chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_M25PXX_PP; cmd[0] = CMD_M25PXX_PP;
cmd[1] = (offset >> 16) & 0xff; cmd[1] = (offset >> 16) & 0xff;

View File

@ -155,7 +155,7 @@ static int winbond_write(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) { for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size; byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr); chunk_len = min(len - actual, page_size - byte_addr);
chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len); chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_W25_PP; cmd[0] = CMD_W25_PP;
cmd[1] = (offset >> 16) & 0xff; cmd[1] = (offset >> 16) & 0xff;

View File

@ -87,14 +87,27 @@ struct spi_cfg {
unsigned int data_bit_length; unsigned int data_bit_length;
}; };
/*
* If there is no limit on the maximum transfer size for the controller,
* max_xfer_size can be set to SPI_CTRLR_DEFAULT_MAX_XFER_SIZE which is equal to
* UINT32_MAX.
*/
#define SPI_CTRLR_DEFAULT_MAX_XFER_SIZE (UINT32_MAX)
/*----------------------------------------------------------------------- /*-----------------------------------------------------------------------
* Representation of a SPI contoller. * Representation of a SPI controller.
* *
* claim_bus: Claim SPI bus and prepare for communication. * claim_bus: Claim SPI bus and prepare for communication.
* release_bus: Release SPI bus. * release_bus: Release SPI bus.
* setup: Setup given SPI device bus. * setup: Setup given SPI device bus.
* xfer: Perform one SPI transfer operation. * xfer: Perform one SPI transfer operation.
* xfer_vector: Vector of SPI transfer operations. * xfer_vector: Vector of SPI transfer operations.
* max_xfer_size: Maximum transfer size supported by the controller
* (0 = invalid,
* SPI_CTRLR_DEFAULT_MAX_XFER_SIZE = unlimited)
* deduct_cmd_len: Whether cmd_len should be deducted from max_xfer_size
* when calculating max_data_size
*
*/ */
struct spi_ctrlr { struct spi_ctrlr {
int (*claim_bus)(const struct spi_slave *slave); int (*claim_bus)(const struct spi_slave *slave);
@ -104,6 +117,8 @@ struct spi_ctrlr {
size_t bytesout, void *din, size_t bytesin); size_t bytesout, void *din, size_t bytesin);
int (*xfer_vector)(const struct spi_slave *slave, int (*xfer_vector)(const struct spi_slave *slave,
struct spi_op vectors[], size_t count); struct spi_op vectors[], size_t count);
uint32_t max_xfer_size;
bool deduct_cmd_len;
}; };
/*----------------------------------------------------------------------- /*-----------------------------------------------------------------------
@ -212,7 +227,14 @@ int spi_xfer(const struct spi_slave *slave, const void *dout, size_t bytesout,
int spi_xfer_vector(const struct spi_slave *slave, int spi_xfer_vector(const struct spi_slave *slave,
struct spi_op vectors[], size_t count); struct spi_op vectors[], size_t count);
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len); /*-----------------------------------------------------------------------
* Given command length and length of remaining data, return the maximum data
* that can be transferred in next spi_xfer.
*
* Returns: 0 on error, non-zero data size that can be xfered on success.
*/
unsigned int spi_crop_chunk(const struct spi_slave *slave, unsigned int cmd_len,
unsigned int buf_len);
/*----------------------------------------------------------------------- /*-----------------------------------------------------------------------
* Write 8 bits, then read 8 bits. * Write 8 bits, then read 8 bits.

View File

@ -280,6 +280,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.release_bus = spi_ctrlr_release_bus, .release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = 65535,
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
@ -318,8 +319,3 @@ int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
return 0; return 0;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(65535, buf_len);
}

View File

@ -538,6 +538,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.release_bus = spi_ctrlr_release_bus, .release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = IMGTEC_SPI_MAX_TRANSFER_SIZE,
}; };
/* Set up communications parameters for a SPI slave. */ /* Set up communications parameters for a SPI slave. */
@ -585,8 +586,3 @@ int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
return 0; return 0;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(IMGTEC_SPI_MAX_TRANSFER_SIZE, buf_len);
}

View File

@ -19,6 +19,7 @@
#include <bootstate.h> #include <bootstate.h>
#include <delay.h> #include <delay.h>
#include <arch/io.h> #include <arch/io.h>
#include <commonlib/helpers.h>
#include <console/console.h> #include <console/console.h>
#include <device/pci_ids.h> #include <device/pci_ids.h>
#include <spi_flash.h> #include <spi_flash.h>
@ -457,11 +458,6 @@ static int ich_status_poll(u16 bitmask, int wait_til_set)
return -1; return -1;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(cntlr.databytes, buf_len);
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin) size_t bytesout, void *din, size_t bytesin)
{ {
@ -613,6 +609,7 @@ static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
static const struct spi_ctrlr spi_ctrlr = { static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = member_size(ich9_spi_regs, fdata),
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -16,6 +16,7 @@
/* This file is derived from the flashrom project. */ /* This file is derived from the flashrom project. */
#include <arch/io.h> #include <arch/io.h>
#include <bootstate.h> #include <bootstate.h>
#include <commonlib/helpers.h>
#include <console/console.h> #include <console/console.h>
#include <delay.h> #include <delay.h>
#include <device/pci_ids.h> #include <device/pci_ids.h>
@ -438,11 +439,6 @@ static int ich_status_poll(u16 bitmask, int wait_til_set)
return -1; return -1;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(cntlr.databytes, buf_len);
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin) size_t bytesout, void *din, size_t bytesin)
{ {
@ -597,6 +593,7 @@ static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
static const struct spi_ctrlr spi_ctrlr = { static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = member_size(ich9_spi_regs, fdata),
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -16,6 +16,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <bootstate.h> #include <bootstate.h>
#include <commonlib/helpers.h>
#include <delay.h> #include <delay.h>
#include <arch/io.h> #include <arch/io.h>
#include <console/console.h> #include <console/console.h>
@ -454,11 +455,6 @@ static int ich_status_poll(u16 bitmask, int wait_til_set)
return -1; return -1;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(cntlr.databytes, buf_len);
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin) size_t bytesout, void *din, size_t bytesin)
{ {
@ -654,6 +650,7 @@ int spi_flash_protect(u32 start, u32 size)
static const struct spi_ctrlr spi_ctrlr = { static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = member_size(ich9_spi_regs, fdata),
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -364,4 +364,5 @@ static int fast_spi_flash_ctrlr_setup(const struct spi_slave *dev)
const struct spi_ctrlr fast_spi_flash_ctrlr = { const struct spi_ctrlr fast_spi_flash_ctrlr = {
.setup = fast_spi_flash_ctrlr_setup, .setup = fast_spi_flash_ctrlr_setup,
.max_xfer_size = SPI_CTRLR_DEFAULT_MAX_XFER_SIZE,
}; };

View File

@ -611,4 +611,5 @@ const struct spi_ctrlr gspi_ctrlr = {
.release_bus = gspi_cs_deassert, .release_bus = gspi_cs_deassert,
.setup = gspi_ctrlr_setup, .setup = gspi_ctrlr_setup,
.xfer = gspi_ctrlr_xfer, .xfer = gspi_ctrlr_xfer,
.max_xfer_size = SPI_CTRLR_DEFAULT_MAX_XFER_SIZE,
}; };

View File

@ -18,6 +18,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <commonlib/helpers.h>
#include <delay.h> #include <delay.h>
#include <arch/io.h> #include <arch/io.h>
#include <console/console.h> #include <console/console.h>
@ -438,11 +439,6 @@ static int ich_status_poll(uint16_t bitmask, int wait_til_set)
return -1; return -1;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(cntlr.databytes, buf_len);
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin) size_t bytesout, void *din, size_t bytesin)
{ {
@ -594,6 +590,7 @@ spi_xfer_exit:
static const struct spi_ctrlr spi_ctrlr = { static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = member_size(ich9_spi_regs, fdata),
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -19,6 +19,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <delay.h> #include <delay.h>
#include <commonlib/helpers.h>
#include <arch/io.h> #include <arch/io.h>
#include <console/console.h> #include <console/console.h>
#include <device/pci_ids.h> #include <device/pci_ids.h>
@ -452,11 +453,6 @@ static int ich_status_poll(uint16_t bitmask, int wait_til_set)
return -1; return -1;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(cntlr.databytes, buf_len);
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin) size_t bytesout, void *din, size_t bytesin)
{ {
@ -610,6 +606,7 @@ spi_xfer_exit:
static const struct spi_ctrlr spi_ctrlr = { static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = member_size(ich9_spi_regs, fdata),
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -454,11 +454,6 @@ static void spi_ctrlr_release_bus(const struct spi_slave *slave)
mv_spi_cs_deassert(slave->bus); mv_spi_cs_deassert(slave->bus);
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return buf_len;
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, static int spi_ctrlr_xfer(const struct spi_slave *slave,
const void *dout, const void *dout,
size_t out_bytes, size_t out_bytes,
@ -480,6 +475,7 @@ static const spi_ctrlr spi_ctrlr = {
.claim_bus = spi_ctrlr_claim_bus, .claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus, .release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.max_xfer_size = SPI_CTRLR_DEFAULT_MAX_XFER_SIZE,
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -19,8 +19,3 @@ int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{ {
return -1; return -1;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return buf_len;
}

View File

@ -108,11 +108,6 @@ static int sector_erase(int offset)
return 0; return 0;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(65535, buf_len);
}
static int dma_read(u32 addr, u8 *buf, u32 len, uintptr_t dma_buf, static int dma_read(u32 addr, u8 *buf, u32 len, uintptr_t dma_buf,
size_t dma_buf_len) size_t dma_buf_len)
{ {

View File

@ -294,6 +294,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.release_bus = spi_ctrlr_release_bus, .release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = 65535,
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -714,11 +714,6 @@ static int xfer_finish(struct tegra_spi_channel *spi)
return ret; return ret;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return buf_len;
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t out_bytes, void *din, size_t in_bytes) size_t out_bytes, void *din, size_t in_bytes)
{ {
@ -802,6 +797,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.claim_bus = spi_ctrlr_claim_bus, .claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus, .release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.max_xfer_size = SPI_CTRLR_DEFAULT_MAX_XFER_SIZE,
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -750,11 +750,6 @@ static int xfer_finish(struct tegra_spi_channel *spi)
return ret; return ret;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return buf_len;
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t out_bytes, void *din, size_t in_bytes) size_t out_bytes, void *din, size_t in_bytes)
{ {
@ -838,6 +833,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.claim_bus = spi_ctrlr_claim_bus, .claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus, .release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.max_xfer_size = SPI_CTRLR_DEFAULT_MAX_XFER_SIZE,
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -410,11 +410,6 @@ static void enable_io_config(struct ipq_spi_slave *ds,
return; return;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(MAX_PACKET_COUNT, buf_len);
}
/* /*
* Function to read bytes number of data from the Input FIFO * Function to read bytes number of data from the Input FIFO
*/ */
@ -657,6 +652,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.release_bus = spi_ctrlr_release_bus, .release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = MAX_PACKET_COUNT,
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -683,11 +683,6 @@ static int spi_xfer_rx_packet(struct ipq_spi_slave *ds,
return config_spi_state(ds, SPI_RESET_STATE); return config_spi_state(ds, SPI_RESET_STATE);
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(MAX_PACKET_COUNT, buf_len);
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t out_bytes, void *din, size_t in_bytes) size_t out_bytes, void *din, size_t in_bytes)
{ {
@ -761,6 +756,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.claim_bus = spi_ctrlr_claim_bus, .claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus, .release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.max_xfer_size = MAX_PACKET_COUNT,
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -251,11 +251,6 @@ static int do_xfer(struct rockchip_spi *regs, bool use_16bit, const void *dout,
return 0; return 0;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(65535, buf_len);
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytes_out, void *din, size_t bytes_in) size_t bytes_out, void *din, size_t bytes_in)
{ {
@ -332,6 +327,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.claim_bus = spi_ctrlr_claim_bus, .claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus, .release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.max_xfer_size = 65535,
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -212,6 +212,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.claim_bus = spi_ctrlr_claim_bus, .claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus, .release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.max_xfer_size = SPI_CTRLR_DEFAULT_MAX_XFER_SIZE,
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -85,11 +85,6 @@ void spi_init(void)
spibar = pci_read_config32(dev, 0xA0) & ~0x1F; spibar = pci_read_config32(dev, 0xA0) & ~0x1F;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(AMD_SB_SPI_TX_LEN - cmd_len, buf_len);
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin) size_t bytesout, void *din, size_t bytesin)
{ {
@ -168,6 +163,8 @@ int chipset_volatile_group_end(const struct spi_flash *flash)
static const struct spi_ctrlr spi_ctrlr = { static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = AMD_SB_SPI_TX_LEN,
.deduct_cmd_len = true,
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -54,11 +54,6 @@ void spi_init()
spibar = pci_read_config32(dev, 0xA0) & ~0x1F; spibar = pci_read_config32(dev, 0xA0) & ~0x1F;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(AMD_SB_SPI_TX_LEN - cmd_len, buf_len);
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin) size_t bytesout, void *din, size_t bytesin)
{ {
@ -159,6 +154,8 @@ int chipset_volatile_group_end(const struct spi_flash *flash)
static const struct spi_ctrlr spi_ctrlr = { static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = AMD_SB_SPI_TX_LEN,
.deduct_cmd_len = true,
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -40,11 +40,6 @@ void spi_init(void)
/* Not needed */ /* Not needed */
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(AMD_SB_SPI_TX_LEN - cmd_len, buf_len);
}
static void reset_internal_fifo_pointer(void) static void reset_internal_fifo_pointer(void)
{ {
uint32_t spibar = get_spi_bar(); uint32_t spibar = get_spi_bar();
@ -121,6 +116,8 @@ static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
static const struct spi_ctrlr spi_ctrlr = { static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = AMD_SB_SPI_TX_LEN,
.deduct_cmd_len = true,
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -19,6 +19,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <bootstate.h> #include <bootstate.h>
#include <commonlib/helpers.h>
#include <delay.h> #include <delay.h>
#include <arch/io.h> #include <arch/io.h>
#include <console/console.h> #include <console/console.h>
@ -504,11 +505,6 @@ static int spi_is_multichip (void)
return !!((cntlr.flmap0 >> 8) & 3); return !!((cntlr.flmap0 >> 8) & 3);
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(cntlr.databytes, buf_len);
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin) size_t bytesout, void *din, size_t bytesin)
{ {
@ -660,6 +656,7 @@ static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
static const struct spi_ctrlr spi_ctrlr = { static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = member_size(ich9_spi_regs, fdata),
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)

View File

@ -17,6 +17,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <commonlib/helpers.h>
#include <delay.h> #include <delay.h>
#include <arch/io.h> #include <arch/io.h>
#include <console/console.h> #include <console/console.h>
@ -569,11 +570,6 @@ static int ich_status_poll(u16 bitmask, int wait_til_set)
return -1; return -1;
} }
unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
{
return min(cntlr.databytes, buf_len);
}
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin) size_t bytesout, void *din, size_t bytesin)
{ {
@ -725,6 +721,7 @@ spi_xfer_exit:
static const struct spi_ctrlr spi_ctrlr = { static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer, .xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors, .xfer_vector = spi_xfer_two_vectors,
.max_xfer_size = member_size(ich10_spi_regs, fdata),
}; };
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)