Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | aaca776 | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. |
Simon Glass | aaca776 | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 49e9d2c | 2013-12-03 16:43:24 -0700 | [diff] [blame] | 6 | #include <fdtdec.h> |
Simon Glass | aaca776 | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 7 | #include <malloc.h> |
| 8 | #include <spi.h> |
| 9 | |
Nikita Kiryanov | 18dd07c | 2013-10-16 17:23:25 +0300 | [diff] [blame] | 10 | int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen) |
| 11 | { |
| 12 | if (wordlen == 0 || wordlen > 32) { |
Mario Six | 2eb66c2 | 2018-01-15 11:08:35 +0100 | [diff] [blame] | 13 | printf("spi: invalid wordlen %u\n", wordlen); |
Nikita Kiryanov | 18dd07c | 2013-10-16 17:23:25 +0300 | [diff] [blame] | 14 | return -1; |
| 15 | } |
| 16 | |
| 17 | slave->wordlen = wordlen; |
| 18 | |
| 19 | return 0; |
| 20 | } |
| 21 | |
Simon Glass | aaca776 | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 22 | void *spi_do_alloc_slave(int offset, int size, unsigned int bus, |
| 23 | unsigned int cs) |
| 24 | { |
Mario Six | 2eb66c2 | 2018-01-15 11:08:35 +0100 | [diff] [blame] | 25 | u8 *ptr; |
Simon Glass | aaca776 | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 26 | |
| 27 | ptr = malloc(size); |
| 28 | if (ptr) { |
Mario Six | 2eb66c2 | 2018-01-15 11:08:35 +0100 | [diff] [blame] | 29 | struct spi_slave *slave; |
| 30 | |
Simon Glass | aaca776 | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 31 | memset(ptr, '\0', size); |
| 32 | slave = (struct spi_slave *)(ptr + offset); |
| 33 | slave->bus = bus; |
| 34 | slave->cs = cs; |
Nikita Kiryanov | 18dd07c | 2013-10-16 17:23:25 +0300 | [diff] [blame] | 35 | slave->wordlen = SPI_DEFAULT_WORDLEN; |
Simon Glass | aaca776 | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | return ptr; |
| 39 | } |