blob: b76a26cef053fea6528098db03172f113d87b007 [file] [log] [blame]
Simon Glassba6c3ce2013-03-11 06:08:00 +00001/*
2 * Copyright (c) 2011 The Chromium OS Authors.
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Simon Glassba6c3ce2013-03-11 06:08:00 +00005 */
6
7#include <common.h>
8#include <malloc.h>
9#include <spi.h>
10
Nikita Kiryanov5753d092013-10-16 17:23:25 +030011int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen)
12{
13 if (wordlen == 0 || wordlen > 32) {
14 printf("spi: invalid wordlen %d\n", wordlen);
15 return -1;
16 }
17
18 slave->wordlen = wordlen;
19
20 return 0;
21}
22
Simon Glassba6c3ce2013-03-11 06:08:00 +000023void *spi_do_alloc_slave(int offset, int size, unsigned int bus,
24 unsigned int cs)
25{
26 struct spi_slave *slave;
27 void *ptr;
28
29 ptr = malloc(size);
30 if (ptr) {
31 memset(ptr, '\0', size);
32 slave = (struct spi_slave *)(ptr + offset);
33 slave->bus = bus;
34 slave->cs = cs;
Nikita Kiryanov5753d092013-10-16 17:23:25 +030035 slave->wordlen = SPI_DEFAULT_WORDLEN;
Simon Glassba6c3ce2013-03-11 06:08:00 +000036 }
37
38 return ptr;
39}