Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 0efc024 | 2013-12-03 16:43:24 -0700 | [diff] [blame] | 7 | #include <fdtdec.h> |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 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) { |
Mario Six | 547bcc3 | 2018-01-15 11:08:35 +0100 | [diff] [blame] | 14 | printf("spi: invalid wordlen %u\n", wordlen); |
Nikita Kiryanov | 5753d09 | 2013-10-16 17:23:25 +0300 | [diff] [blame] | 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 | { |
Mario Six | 547bcc3 | 2018-01-15 11:08:35 +0100 | [diff] [blame] | 26 | u8 *ptr; |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 27 | |
| 28 | ptr = malloc(size); |
| 29 | if (ptr) { |
Mario Six | 547bcc3 | 2018-01-15 11:08:35 +0100 | [diff] [blame] | 30 | struct spi_slave *slave; |
| 31 | |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 32 | memset(ptr, '\0', size); |
| 33 | slave = (struct spi_slave *)(ptr + offset); |
| 34 | slave->bus = bus; |
| 35 | slave->cs = cs; |
Nikita Kiryanov | 5753d09 | 2013-10-16 17:23:25 +0300 | [diff] [blame] | 36 | slave->wordlen = SPI_DEFAULT_WORDLEN; |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | return ptr; |
| 40 | } |