blob: 50a076a98be6ef55fcdc6316762ec8508ca18945 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassaaca7762013-03-11 06:08:00 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glassaaca7762013-03-11 06:08:00 +00004 */
5
Simon Glass49e9d2c2013-12-03 16:43:24 -07006#include <fdtdec.h>
Simon Glassaaca7762013-03-11 06:08:00 +00007#include <malloc.h>
8#include <spi.h>
9
Nikita Kiryanov18dd07c2013-10-16 17:23:25 +030010int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen)
11{
12 if (wordlen == 0 || wordlen > 32) {
Mario Six2eb66c22018-01-15 11:08:35 +010013 printf("spi: invalid wordlen %u\n", wordlen);
Nikita Kiryanov18dd07c2013-10-16 17:23:25 +030014 return -1;
15 }
16
17 slave->wordlen = wordlen;
18
19 return 0;
20}
21
Simon Glassaaca7762013-03-11 06:08:00 +000022void *spi_do_alloc_slave(int offset, int size, unsigned int bus,
23 unsigned int cs)
24{
Mario Six2eb66c22018-01-15 11:08:35 +010025 u8 *ptr;
Simon Glassaaca7762013-03-11 06:08:00 +000026
27 ptr = malloc(size);
28 if (ptr) {
Mario Six2eb66c22018-01-15 11:08:35 +010029 struct spi_slave *slave;
30
Simon Glassaaca7762013-03-11 06:08:00 +000031 memset(ptr, '\0', size);
32 slave = (struct spi_slave *)(ptr + offset);
33 slave->bus = bus;
34 slave->cs = cs;
Nikita Kiryanov18dd07c2013-10-16 17:23:25 +030035 slave->wordlen = SPI_DEFAULT_WORDLEN;
Simon Glassaaca7762013-03-11 06:08:00 +000036 }
37
38 return ptr;
39}