Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The Chromium OS Authors. |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <malloc.h> |
| 9 | #include <spi.h> |
| 10 | |
Nikita Kiryanov | 5753d09 | 2013-10-16 17:23:25 +0300 | [diff] [blame] | 11 | int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen) |
| 12 | { |
| 13 | if (wordlen == 0 || wordlen > 32) { |
| 14 | printf("spi: invalid wordlen %d\n", wordlen); |
| 15 | return -1; |
| 16 | } |
| 17 | |
| 18 | slave->wordlen = wordlen; |
| 19 | |
| 20 | return 0; |
| 21 | } |
| 22 | |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 23 | void *spi_do_alloc_slave(int offset, int size, unsigned int bus, |
| 24 | unsigned int cs) |
| 25 | { |
| 26 | struct spi_slave *slave; |
| 27 | void *ptr; |
| 28 | |
| 29 | ptr = malloc(size); |
| 30 | if (ptr) { |
| 31 | memset(ptr, '\0', size); |
| 32 | slave = (struct spi_slave *)(ptr + offset); |
| 33 | slave->bus = bus; |
| 34 | slave->cs = cs; |
Nikita Kiryanov | 5753d09 | 2013-10-16 17:23:25 +0300 | [diff] [blame] | 35 | slave->wordlen = SPI_DEFAULT_WORDLEN; |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | return ptr; |
| 39 | } |