Skip to content
Snippets Groups Projects
Select Git revision
5 results Searching

net.c

Blame
  • Forked from Reform / reform-boundary-uboot
    Source project has a limited visibility.
    cros_ec_spi.c 5.93 KiB
    /*
     * Chromium OS cros_ec driver - SPI interface
     *
     * Copyright (c) 2012 The Chromium OS Authors.
     *
     * SPDX-License-Identifier:	GPL-2.0+
     */
    
    /*
     * The Matrix Keyboard Protocol driver handles talking to the keyboard
     * controller chip. Mostly this is for keyboard functions, but some other
     * things have slipped in, so we provide generic services to talk to the
     * KBC.
     */
    
    #include <common.h>
    #include <cros_ec.h>
    #include <dm.h>
    #include <errno.h>
    #include <spi.h>
    
    DECLARE_GLOBAL_DATA_PTR;
    
    #ifdef CONFIG_DM_CROS_EC
    int cros_ec_spi_packet(struct udevice *udev, int out_bytes, int in_bytes)
    {
    	struct cros_ec_dev *dev = udev->uclass_priv;
    #else
    int cros_ec_spi_packet(struct cros_ec_dev *dev, int out_bytes, int in_bytes)
    {
    #endif
    	struct spi_slave *slave = dev_get_parentdata(dev->dev);
    	int rv;
    
    	/* Do the transfer */
    	if (spi_claim_bus(slave)) {
    		debug("%s: Cannot claim SPI bus\n", __func__);
    		return -1;
    	}
    
    	rv = spi_xfer(slave, max(out_bytes, in_bytes) * 8,
    		      dev->dout, dev->din,
    		      SPI_XFER_BEGIN | SPI_XFER_END);
    
    	spi_release_bus(slave);
    
    	if (rv) {
    		debug("%s: Cannot complete SPI transfer\n", __func__);
    		return -1;
    	}
    
    	return in_bytes;
    }
    
    /**
     * Send a command to a LPC CROS_EC device and return the reply.
     *
     * The device's internal input/output buffers are used.
     *
     * @param dev		CROS_EC device
     * @param cmd		Command to send (EC_CMD_...)
     * @param cmd_version	Version of command to send (EC_VER_...)
     * @param dout		Output data (may be NULL If dout_len=0)
     * @param dout_len      Size of output data in bytes
     * @param dinp		Returns pointer to response data. This will be
     *			untouched unless we return a value > 0.
     * @param din_len	Maximum size of response in bytes
     * @return number of bytes in response, or -1 on error
     */
    #ifdef CONFIG_DM_CROS_EC