uboot/drivers/spi/spi.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * Copyright (c) 2011 The Chromium OS Authors.
   4 */
   5
   6#include <common.h>
   7#include <fdtdec.h>
   8#include <malloc.h>
   9#include <spi.h>
  10
  11int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen)
  12{
  13        if (wordlen == 0 || wordlen > 32) {
  14                printf("spi: invalid wordlen %u\n", wordlen);
  15                return -1;
  16        }
  17
  18        slave->wordlen = wordlen;
  19
  20        return 0;
  21}
  22
  23void *spi_do_alloc_slave(int offset, int size, unsigned int bus,
  24                         unsigned int cs)
  25{
  26        u8 *ptr;
  27
  28        ptr = malloc(size);
  29        if (ptr) {
  30                struct spi_slave *slave;
  31
  32                memset(ptr, '\0', size);
  33                slave = (struct spi_slave *)(ptr + offset);
  34                slave->bus = bus;
  35                slave->cs = cs;
  36                slave->wordlen = SPI_DEFAULT_WORDLEN;
  37        }
  38
  39        return ptr;
  40}
  41