blob: 22910de0dd93581d3cddfd4f32e6d98acb96c812 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassba6c3ce2013-03-11 06:08:00 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glassba6c3ce2013-03-11 06:08:00 +00004 */
5
6#include <common.h>
Simon Glass0efc0242013-12-03 16:43:24 -07007#include <fdtdec.h>
Simon Glassba6c3ce2013-03-11 06:08:00 +00008#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) {
Mario Six547bcc32018-01-15 11:08:35 +010014 printf("spi: invalid wordlen %u\n", wordlen);
Nikita Kiryanov5753d092013-10-16 17:23:25 +030015 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{
Mario Six547bcc32018-01-15 11:08:35 +010026 u8 *ptr;
Simon Glassba6c3ce2013-03-11 06:08:00 +000027
28 ptr = malloc(size);
29 if (ptr) {
Mario Six547bcc32018-01-15 11:08:35 +010030 struct spi_slave *slave;
31
Simon Glassba6c3ce2013-03-11 06:08:00 +000032 memset(ptr, '\0', size);
33 slave = (struct spi_slave *)(ptr + offset);
34 slave->bus = bus;
35 slave->cs = cs;
Nikita Kiryanov5753d092013-10-16 17:23:25 +030036 slave->wordlen = SPI_DEFAULT_WORDLEN;
Simon Glassba6c3ce2013-03-11 06:08:00 +000037 }
38
39 return ptr;
40}