Exemple #1
0
static s32 cyttsp4_spi_read_block_data(struct cyttsp4_spi *ts, u8 addr,
                                       size_t length, void *data)
{
    int rc = 0;
    struct device *dev = &ts->client->dev;

    dev_vdbg(dev, "%s: Enter\n", __func__);

    /* Write address */
    rc = cyttsp4_spi_xfer(CY_SPI_WR_OP, ts, addr, NULL, 0);
    if (rc < 0) {
        dev_err(dev, "%s: Fail write address r=%d\n", __func__, rc);
        return rc;
    }

    /* Read data */
    rc = cyttsp4_spi_xfer(CY_SPI_RD_OP, ts, addr, data, length);
    if (rc < 0) {
        dev_err(dev, "%s: Fail read r=%d\n", __func__, rc);
        /*
         * Do not print the above error if the data sync bytes
         * were not found.
         * This is a normal condition for the bootloader loader
         * startup and need to retry until data sync bytes are found.
         */
    } else if (rc > 0)
        /* Now signal fail; so retry can be done */
        rc = -EIO;

    return rc;
}
Exemple #2
0
static s32 cyttsp4_spi_read_block_data(void *handle, u16 addr,
	size_t length, void *data, int spi_addr, bool use_subaddr)
{
	struct cyttsp4_spi *ts =
		container_of(handle, struct cyttsp4_spi, bus_ops);
	int retval;

	retval = cyttsp4_spi_xfer(CY_SPI_WR_OP, ts, addr, NULL, 0);
	if (retval == 0)
		retval = cyttsp4_spi_xfer(CY_SPI_RD_OP, ts, addr, data, length);
	if (retval < 0)
		dev_err(ts->bus_ops.dev,
			"%s: cyttsp4_spi_read_block_data failed\n",
			__func__);

	/*
	 * Do not print the above error if the data sync bytes were not found.
	 * This is a normal condition for the bootloader loader startup and need
	 * to retry until data sync bytes are found.
	 */
	else if (retval > 0)
		retval = -EIO;	/* now signal fail; so retry can be done */

	return retval;
}
static s32 cyttsp4_spi_read_block_data(struct cyttsp4_spi *ts, u16 addr,
				int length, void *data, int max_xfer)
{
	int rc = -EINVAL;
	int retry = 0;
	int trans_len;
	struct device *dev = &ts->client->dev;

	dev_vdbg(dev, "%s: Enter\n", __func__);

	while (length > 0) {
		trans_len = min(length, max_xfer);

		/* Write address */
		rc = cyttsp4_spi_xfer(CY_SPI_WR_OP, ts, addr, NULL, 0);
		if (rc < 0) {
			dev_err(dev, "%s: Fail write address r=%d\n",
				__func__, rc);
			return rc;
		}

		/* Read data */
		rc = cyttsp4_spi_xfer(CY_SPI_RD_OP, ts, addr, data, trans_len);
		if (rc < 0) {
			dev_err(dev, "%s: Fail read r=%d\n", __func__, rc);
			goto exit;
		} else if (rc > 0) {
			/* Perform retry or fail */
			if (retry++ < CY_SPI_NUM_RETRY) {
				dev_dbg(dev, "%s: ACK error, retry %d\n",
					__func__, retry);
				continue;
			} else {
				dev_err(dev, "%s: ACK error\n", __func__);
				rc = -EIO;
				goto exit;
			}
		}

		length -= trans_len;
		data += trans_len;
		addr += trans_len;
	}
exit:
	return rc;
}