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> |
Simon Glass | 0efc024 | 2013-12-03 16:43:24 -0700 | [diff] [blame] | 8 | #include <fdtdec.h> |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 9 | #include <malloc.h> |
| 10 | #include <spi.h> |
| 11 | |
Nikita Kiryanov | 5753d09 | 2013-10-16 17:23:25 +0300 | [diff] [blame] | 12 | int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen) |
| 13 | { |
| 14 | if (wordlen == 0 || wordlen > 32) { |
Mario Six | 547bcc3 | 2018-01-15 11:08:35 +0100 | [diff] [blame] | 15 | printf("spi: invalid wordlen %u\n", wordlen); |
Nikita Kiryanov | 5753d09 | 2013-10-16 17:23:25 +0300 | [diff] [blame] | 16 | return -1; |
| 17 | } |
| 18 | |
| 19 | slave->wordlen = wordlen; |
| 20 | |
| 21 | return 0; |
| 22 | } |
| 23 | |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 24 | void *spi_do_alloc_slave(int offset, int size, unsigned int bus, |
| 25 | unsigned int cs) |
| 26 | { |
Mario Six | 547bcc3 | 2018-01-15 11:08:35 +0100 | [diff] [blame] | 27 | u8 *ptr; |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 28 | |
| 29 | ptr = malloc(size); |
| 30 | if (ptr) { |
Mario Six | 547bcc3 | 2018-01-15 11:08:35 +0100 | [diff] [blame] | 31 | struct spi_slave *slave; |
| 32 | |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 33 | memset(ptr, '\0', size); |
| 34 | slave = (struct spi_slave *)(ptr + offset); |
| 35 | slave->bus = bus; |
| 36 | slave->cs = cs; |
Nikita Kiryanov | 5753d09 | 2013-10-16 17:23:25 +0300 | [diff] [blame] | 37 | slave->wordlen = SPI_DEFAULT_WORDLEN; |
Simon Glass | ba6c3ce | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | return ptr; |
| 41 | } |