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 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 6 | #include <common.h> |
Simon Glass | 49e9d2c | 2013-12-03 16:43:24 -0700 | [diff] [blame] | 7 | #include <fdtdec.h> |
Simon Glass | aaca776 | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 8 | #include <malloc.h> |
| 9 | #include <spi.h> |
| 10 | |
Nikita Kiryanov | 18dd07c | 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 | 2eb66c2 | 2018-01-15 11:08:35 +0100 | [diff] [blame] | 14 | printf("spi: invalid wordlen %u\n", wordlen); |
Nikita Kiryanov | 18dd07c | 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 | aaca776 | 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 | 2eb66c2 | 2018-01-15 11:08:35 +0100 | [diff] [blame] | 26 | u8 *ptr; |
Simon Glass | aaca776 | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 27 | |
| 28 | ptr = malloc(size); |
| 29 | if (ptr) { |
Mario Six | 2eb66c2 | 2018-01-15 11:08:35 +0100 | [diff] [blame] | 30 | struct spi_slave *slave; |
| 31 | |
Simon Glass | aaca776 | 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 | 18dd07c | 2013-10-16 17:23:25 +0300 | [diff] [blame] | 36 | slave->wordlen = SPI_DEFAULT_WORDLEN; |
Simon Glass | aaca776 | 2013-03-11 06:08:00 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | return ptr; |
| 40 | } |