static inline int spi_xmit_rx(u8 *in_buf, size_t len) { int ret; u8 read_out_buf[2]; struct spi_message msg; struct spi_transfer xfer = { .tx_buf = read_out_buf, .rx_buf = in_buf, .len = len, .cs_change = 0, }; spi_message_init(&msg); spi_message_add_tail(&xfer, &msg); ret = spi_sync(g_spi, &msg); if (ret < 0) dev_err(&g_spi->dev, "%s - error %d\n", __func__, ret); return ret; } int s5c73m3_spi_read(u8 *buf, size_t len, const int rxSize) { int k; int ret = 0; u32 count = len/rxSize; u32 extra = len%rxSize; for (k = 0; k < count; k++) { ret = spi_xmit_rx(&buf[rxSize*k], rxSize); if (ret < 0) return -EINVAL; } if (extra != 0) { ret = spi_xmit_rx(&buf[rxSize*k], extra); if (ret < 0) return -EINVAL; } return 0; }
static inline int spi_xmit(const u8 *addr, const int len) { int ret; #if defined(CHANGE_ENDIAN) u8 buf[8] = {0}; #endif struct spi_message msg; struct spi_transfer xfer = { .len = len, #if !defined(CHANGE_ENDIAN) .tx_buf = addr, /*QCTK ALRAN QUP_CONFIG 0-4 bits BIG ENDIAN*/ .bits_per_word = 32, #else .tx_buf = buf, #endif }; #if defined(CHANGE_ENDIAN) buf[0] = addr[3]; buf[1] = addr[2]; buf[2] = addr[1]; buf[3] = addr[0]; buf[4] = addr[7]; buf[5] = addr[6]; buf[6] = addr[5]; buf[7] = addr[4]; #endif spi_message_init(&msg); spi_message_add_tail(&xfer, &msg); ret = spi_sync(g_spi, &msg); if (ret < 0) cam_err("error %d\n", ret); return ret; } static inline int spi_xmit_rx(u8 *in_buf, size_t len) { int ret; u8 read_out_buf[2]; struct spi_message msg; struct spi_transfer xfer = { .tx_buf = read_out_buf, .rx_buf = in_buf, .len = len, .cs_change = 0, }; spi_message_init(&msg); spi_message_add_tail(&xfer, &msg); ret = spi_sync(g_spi, &msg); if (ret < 0) cam_err("%s - error %d\n", __func__, ret); return ret; } int s5c73m3_spi_read(u8 *buf, size_t len, const int rxSize) { int k; int ret = 0; int z = 0; u8 paddingData[32]; u8 temp_buf[4] = {0}; u32 count = len/rxSize; u32 extra = len%rxSize; for (k = 0; k < count; k++) { ret = spi_xmit_rx(&buf[rxSize*k], rxSize); if (ret < 0) { cam_err("%s - error %d\n", __func__, ret); return -EINVAL; } } if (extra != 0) { ret = spi_xmit_rx(&buf[rxSize*k], extra); if (ret < 0) { cam_err("%s - error %d\n", __func__, ret); return -EINVAL; } } for (k = 0; k < len-3; k += 4) { memcpy(temp_buf, (char *)&buf[k], sizeof(temp_buf)); buf[k] = temp_buf[3]; buf[k+1] = temp_buf[2]; buf[k+2] = temp_buf[1]; buf[k+3] = temp_buf[0]; } return 0; }
static inline int spi_xmit(struct spi_device *spi, const u8 *addr, const int len) { int ret; struct spi_message msg; struct spi_transfer xfer = { .len = len, .tx_buf = addr, .bits_per_word = 32, }; spi_message_init(&msg); spi_message_add_tail(&xfer, &msg); ret = spi_sync(spi, &msg); if (ret < 0) dev_err(&spi->dev, "error %d\n", ret); return ret; } static inline int spi_xmit_rx(struct spi_device *spi, u8 *in_buf, size_t len) { int ret; u8 read_out_buf[2]; struct spi_message msg; struct spi_transfer xfer = { .tx_buf = read_out_buf, .rx_buf = in_buf, .len = len, .cs_change = 0, }; spi_message_init(&msg); spi_message_add_tail(&xfer, &msg); ret = spi_sync(spi, &msg); if (ret < 0) dev_err(&spi->dev, "%s - error %d\n", __func__, ret); return ret; } /* TDB: Not tested */ int m10mo_spi_read(struct spi_device *spi, u8 *buf, size_t len, const int rxSize) { int k; int ret = 0; u8 temp_buf[4] = {0}; u32 count = len / rxSize; u32 extra = len % rxSize; for (k = 0; k < count; k++) { ret = spi_xmit_rx(spi, &buf[rxSize * k], rxSize); if (ret < 0) { dev_err(&spi->dev, "%s - error %d\n", __func__, ret); return -EINVAL; } } if (extra != 0) { ret = spi_xmit_rx(spi, &buf[rxSize * k], extra); if (ret < 0) { dev_err(&spi->dev, "%s - error %d\n", __func__, ret); return -EINVAL; } } for (k = 0; k < len - 3; k += 4) { memcpy(temp_buf, (char *)&buf[k], sizeof(temp_buf)); buf[k] = temp_buf[3]; buf[k+1] = temp_buf[2]; buf[k+2] = temp_buf[1]; buf[k+3] = temp_buf[0]; } return 0; }