2008-04-11 08:51:27 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 by Michael Sevakis
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2008-04-11 08:51:27 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "system.h"
|
|
|
|
#include "cpu.h"
|
2017-01-28 19:43:35 +00:00
|
|
|
#define DEFINE_MC13783_VECTOR_TABLE
|
2010-05-07 10:53:19 +00:00
|
|
|
#include "mc13783-target.h"
|
2017-01-28 19:43:35 +00:00
|
|
|
#include "gpio-target.h"
|
2008-04-11 08:51:27 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
/* Extend the basic SPI transfer descriptor with our own fields */
|
|
|
|
struct mc13783_transfer_desc
|
2010-05-04 10:07:53 +00:00
|
|
|
{
|
2011-12-18 10:41:43 +00:00
|
|
|
struct spi_transfer_desc xfer;
|
|
|
|
union
|
|
|
|
{
|
2017-01-28 19:43:35 +00:00
|
|
|
/* Pick _either_ data or semaphore */
|
2011-12-18 10:41:43 +00:00
|
|
|
struct semaphore sema;
|
2017-01-28 19:43:35 +00:00
|
|
|
uint32_t data[4];
|
2011-12-18 10:41:43 +00:00
|
|
|
};
|
2010-05-04 10:07:53 +00:00
|
|
|
};
|
|
|
|
|
2017-01-28 19:43:35 +00:00
|
|
|
static uint32_t pmic_int_enb[2]; /* Enabled ints */
|
|
|
|
static uint32_t pmic_int_sense_enb[2]; /* Enabled sense reading */
|
|
|
|
static struct mc13783_transfer_desc int_xfers[2]; /* ISR transfer descriptor */
|
|
|
|
static const struct mc13783_event *current_event; /* Current event in callback */
|
|
|
|
static bool int_restore; /* Prevent SPI callback from
|
|
|
|
unmasking GPIO interrupt
|
|
|
|
(lockout) */
|
2012-01-02 18:32:35 +00:00
|
|
|
|
2017-01-28 19:43:35 +00:00
|
|
|
static const struct mc13783_event * event_from_id(enum mc13783_int_ids id)
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < mc13783_event_vector_tbl_len; i++)
|
|
|
|
{
|
|
|
|
if (mc13783_event_vector_tbl[i].id == id)
|
|
|
|
return &mc13783_event_vector_tbl[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called when a transfer is finished and data is ready/written */
|
|
|
|
static void mc13783_xfer_complete_cb(struct spi_transfer_desc *xfer)
|
|
|
|
{
|
|
|
|
semaphore_release(&((struct mc13783_transfer_desc *)xfer)->sema);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool wait_for_transfer_complete(struct mc13783_transfer_desc *xfer)
|
|
|
|
{
|
|
|
|
return semaphore_wait(&xfer->sema, TIMEOUT_BLOCK)
|
|
|
|
== OBJ_WAIT_SUCCEEDED && xfer->xfer.count == 0;
|
|
|
|
}
|
2012-01-02 18:32:35 +00:00
|
|
|
|
|
|
|
static inline bool mc13783_transfer(struct spi_transfer_desc *xfer,
|
|
|
|
uint32_t *txbuf,
|
|
|
|
uint32_t *rxbuf,
|
|
|
|
int count,
|
|
|
|
spi_transfer_cb_fn_type callback)
|
|
|
|
{
|
|
|
|
xfer->node = &mc13783_spi;
|
|
|
|
xfer->txbuf = txbuf;
|
|
|
|
xfer->rxbuf = rxbuf;
|
|
|
|
xfer->count = count;
|
|
|
|
xfer->callback = callback;
|
|
|
|
xfer->next = NULL;
|
|
|
|
|
|
|
|
return spi_transfer(xfer);
|
|
|
|
}
|
|
|
|
|
2017-01-28 19:43:35 +00:00
|
|
|
static inline void sync_transfer_init(struct mc13783_transfer_desc *xfer)
|
2010-05-04 10:07:53 +00:00
|
|
|
{
|
2017-01-28 19:43:35 +00:00
|
|
|
semaphore_init(&xfer->sema, 1, 0);
|
2010-05-04 10:07:53 +00:00
|
|
|
}
|
|
|
|
|
2017-01-28 19:43:35 +00:00
|
|
|
static inline bool mc13783_sync_transfer(struct mc13783_transfer_desc *xfer,
|
|
|
|
uint32_t *txbuf,
|
|
|
|
uint32_t *rxbuf,
|
|
|
|
int count)
|
2010-05-04 10:07:53 +00:00
|
|
|
{
|
2017-01-28 19:43:35 +00:00
|
|
|
sync_transfer_init(xfer);
|
|
|
|
return mc13783_transfer(&xfer->xfer, txbuf, rxbuf, count, mc13783_xfer_complete_cb);
|
2010-05-04 10:07:53 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 18:32:35 +00:00
|
|
|
/* Efficient interrupt status and acking */
|
|
|
|
static void mc13783_int_svc_complete_callback(struct spi_transfer_desc *xfer)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2017-01-28 19:43:35 +00:00
|
|
|
struct mc13783_transfer_desc *desc1 = (struct mc13783_transfer_desc *)xfer;
|
|
|
|
uint32_t pnd0 = desc1->data[0], pnd1 = desc1->data[1];
|
|
|
|
|
2012-01-02 18:32:35 +00:00
|
|
|
/* Restore PMIC interrupt events */
|
2017-01-28 19:43:35 +00:00
|
|
|
if (int_restore)
|
|
|
|
gpio_int_enable(MC13783_EVENT_ID);
|
2008-04-13 20:03:08 +00:00
|
|
|
|
2012-01-02 18:32:35 +00:00
|
|
|
/* Call handlers */
|
2017-01-28 19:43:35 +00:00
|
|
|
const struct mc13783_event *event = mc13783_event_vector_tbl;
|
|
|
|
while (pnd0 | pnd1)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2017-01-28 19:43:35 +00:00
|
|
|
uint32_t id = event->id;
|
|
|
|
uint32_t set = id / 32;
|
|
|
|
uint32_t bit = 1 << (id % 32);
|
2008-04-13 20:03:08 +00:00
|
|
|
|
2017-01-28 19:43:35 +00:00
|
|
|
uint32_t pnd = set == 0 ? pnd0 : pnd1;
|
|
|
|
if (pnd & bit)
|
2012-01-02 18:32:35 +00:00
|
|
|
{
|
2017-01-28 19:43:35 +00:00
|
|
|
current_event = event;
|
2012-01-02 18:32:35 +00:00
|
|
|
event->callback();
|
2017-01-28 19:43:35 +00:00
|
|
|
set == 0 ? (pnd0 &= ~bit) : (pnd1 &= ~bit);
|
2012-01-02 18:32:35 +00:00
|
|
|
}
|
2008-04-13 10:04:21 +00:00
|
|
|
|
2017-01-28 19:43:35 +00:00
|
|
|
event++;
|
|
|
|
}
|
2012-01-02 18:32:35 +00:00
|
|
|
}
|
2009-02-02 02:38:21 +00:00
|
|
|
|
2012-01-02 18:32:35 +00:00
|
|
|
static void mc13783_int_svc_callback(struct spi_transfer_desc *xfer)
|
|
|
|
{
|
|
|
|
/* Only clear interrupts with handlers */
|
2017-01-28 19:43:35 +00:00
|
|
|
struct mc13783_transfer_desc *desc0 = (struct mc13783_transfer_desc *)xfer;
|
|
|
|
struct mc13783_transfer_desc *desc1 = &int_xfers[1];
|
2008-04-18 16:42:50 +00:00
|
|
|
|
2017-01-28 19:43:35 +00:00
|
|
|
uint32_t pnd0 = desc0->data[0] & pmic_int_enb[0];
|
|
|
|
uint32_t pnd1 = desc0->data[1] & pmic_int_enb[1];
|
|
|
|
|
|
|
|
desc1->data[0] = pnd0;
|
|
|
|
desc1->data[1] = pnd1;
|
2008-05-21 08:42:11 +00:00
|
|
|
|
2012-01-02 18:32:35 +00:00
|
|
|
/* Setup the write packets with status(es) to clear */
|
2017-01-28 19:43:35 +00:00
|
|
|
desc0->data[0] = (1 << 31) | (MC13783_INTERRUPT_STATUS0 << 25) | pnd0;
|
|
|
|
desc0->data[1] = (1 << 31) | (MC13783_INTERRUPT_STATUS1 << 25) | pnd1;
|
|
|
|
|
|
|
|
/* Only read sense if any pending interrupts have them enabled */
|
|
|
|
if ((pnd0 & pmic_int_sense_enb[0]) || (pnd1 & pmic_int_sense_enb[1]))
|
|
|
|
{
|
|
|
|
desc0->data[2] = MC13783_INTERRUPT_SENSE0 << 25;
|
|
|
|
desc0->data[3] = MC13783_INTERRUPT_SENSE1 << 25;
|
|
|
|
desc1->xfer.rxbuf = desc0->data;
|
|
|
|
desc1->xfer.count = 4;
|
|
|
|
}
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 16:56:45 +00:00
|
|
|
/* GPIO interrupt handler for mc13783 */
|
2017-01-28 19:43:35 +00:00
|
|
|
void INT_MC13783(void)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2012-01-02 18:32:35 +00:00
|
|
|
/* Mask the interrupt (unmasked after final read services it). */
|
2017-01-28 19:43:35 +00:00
|
|
|
gpio_int_disable(MC13783_EVENT_ID);
|
|
|
|
gpio_int_clear(MC13783_EVENT_ID);
|
2012-01-02 18:32:35 +00:00
|
|
|
|
|
|
|
/* Setup the read packets */
|
2017-01-28 19:43:35 +00:00
|
|
|
int_xfers[0].data[0] = MC13783_INTERRUPT_STATUS0 << 25;
|
|
|
|
int_xfers[0].data[1] = MC13783_INTERRUPT_STATUS1 << 25;
|
2012-01-02 18:32:35 +00:00
|
|
|
|
|
|
|
unsigned long cpsr = disable_irq_save();
|
|
|
|
|
|
|
|
/* Do these without intervening transfers */
|
2017-01-28 19:43:35 +00:00
|
|
|
if (mc13783_transfer(&int_xfers[0].xfer, int_xfers[0].data,
|
|
|
|
int_xfers[0].data, 2, mc13783_int_svc_callback))
|
2012-01-02 18:32:35 +00:00
|
|
|
{
|
|
|
|
/* Start this provisionally and fill-in actual values during the
|
|
|
|
first transfer's callback - set whatever could be known */
|
2017-01-28 19:43:35 +00:00
|
|
|
mc13783_transfer(&int_xfers[1].xfer, int_xfers[0].data, NULL, 2,
|
2012-01-02 18:32:35 +00:00
|
|
|
mc13783_int_svc_complete_callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
restore_irq(cpsr);
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 14:39:35 +00:00
|
|
|
void INIT_ATTR mc13783_init(void)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
|
|
|
/* Serial interface must have been initialized first! */
|
|
|
|
|
|
|
|
/* Enable the PMIC SPI module */
|
2011-12-26 15:43:11 +00:00
|
|
|
spi_enable_node(&mc13783_spi, true);
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2008-05-21 08:42:11 +00:00
|
|
|
/* Mask any PMIC interrupts for now - modules will enable them as
|
|
|
|
* required */
|
2008-04-12 16:56:45 +00:00
|
|
|
mc13783_write(MC13783_INTERRUPT_MASK0, 0xffffff);
|
|
|
|
mc13783_write(MC13783_INTERRUPT_MASK1, 0xffffff);
|
|
|
|
|
2017-01-28 19:43:35 +00:00
|
|
|
gpio_int_clear(MC13783_EVENT_ID);
|
|
|
|
gpio_enable_event(MC13783_EVENT_ID, true);
|
2008-05-10 18:00:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void mc13783_close(void)
|
|
|
|
{
|
2017-01-28 19:43:35 +00:00
|
|
|
int_restore = false;
|
|
|
|
gpio_int_disable(MC13783_EVENT_ID);
|
|
|
|
gpio_enable_event(MC13783_EVENT_ID, false);
|
2011-12-26 15:43:11 +00:00
|
|
|
spi_enable_node(&mc13783_spi, false);
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
2008-05-21 08:42:11 +00:00
|
|
|
|
2017-01-28 19:43:35 +00:00
|
|
|
void mc13783_enable_event(enum mc13783_int_ids id, bool enable)
|
2008-05-21 08:42:11 +00:00
|
|
|
{
|
2012-01-02 18:32:35 +00:00
|
|
|
static const unsigned char pmic_intm_regs[2] =
|
|
|
|
{ MC13783_INTERRUPT_MASK0, MC13783_INTERRUPT_MASK1 };
|
|
|
|
|
2017-01-28 19:43:35 +00:00
|
|
|
const struct mc13783_event * const event = event_from_id(id);
|
|
|
|
if (event == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned int set = id / 32;
|
|
|
|
uint32_t mask = 1 << (id % 32);
|
|
|
|
uint32_t bit = enable ? mask : 0;
|
2008-05-21 08:42:11 +00:00
|
|
|
|
2012-01-02 18:32:35 +00:00
|
|
|
/* Mask GPIO while changing bits around */
|
2017-01-28 19:43:35 +00:00
|
|
|
int_restore = false;
|
|
|
|
gpio_int_disable(MC13783_EVENT_ID);
|
|
|
|
mc13783_write_masked(pmic_intm_regs[set], bit ^ mask, mask);
|
|
|
|
bitmod32(&pmic_int_sense_enb[set], event->sense ? bit : 0, mask);
|
|
|
|
bitmod32(&pmic_int_enb[set], bit, mask);
|
|
|
|
int_restore = true;
|
|
|
|
gpio_int_enable(MC13783_EVENT_ID);
|
2008-05-21 08:42:11 +00:00
|
|
|
}
|
|
|
|
|
2017-01-28 19:43:35 +00:00
|
|
|
uint32_t mc13783_event_sense(void)
|
2008-05-21 08:42:11 +00:00
|
|
|
{
|
2017-01-28 19:43:35 +00:00
|
|
|
const struct mc13783_event *event = current_event;
|
|
|
|
return int_xfers[0].data[2 + event->id / 32] & event->sense;
|
2011-12-18 10:41:43 +00:00
|
|
|
}
|
2008-04-12 16:56:45 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
uint32_t mc13783_set(unsigned address, uint32_t bits)
|
|
|
|
{
|
|
|
|
return mc13783_write_masked(address, bits, bits);
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 16:56:45 +00:00
|
|
|
uint32_t mc13783_clear(unsigned address, uint32_t bits)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2011-12-18 10:41:43 +00:00
|
|
|
return mc13783_write_masked(address, 0, bits);
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
/* Called when the first transfer of mc13783_write_masked is complete */
|
|
|
|
static void mc13783_write_masked_cb(struct spi_transfer_desc *xfer)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2011-12-18 10:41:43 +00:00
|
|
|
struct mc13783_transfer_desc *desc = (struct mc13783_transfer_desc *)xfer;
|
2017-01-28 19:43:35 +00:00
|
|
|
desc->data[1] |= desc->data[0] & desc->data[2]; /* & ~mask */
|
2011-12-18 10:41:43 +00:00
|
|
|
}
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
uint32_t mc13783_write_masked(unsigned address, uint32_t data, uint32_t mask)
|
|
|
|
{
|
2008-04-11 08:51:27 +00:00
|
|
|
if (address >= MC13783_NUM_REGS)
|
2011-12-18 10:41:43 +00:00
|
|
|
return MC13783_DATA_ERROR;
|
|
|
|
|
|
|
|
mask &= 0xffffff;
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
struct mc13783_transfer_desc xfers[2];
|
2017-01-28 19:43:35 +00:00
|
|
|
xfers[0].data[0] = address << 25;
|
|
|
|
xfers[0].data[1] = (1 << 31) | (address << 25) | (data & mask);
|
|
|
|
xfers[0].data[2] = ~mask;
|
2010-05-04 10:07:53 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
unsigned long cpsr = disable_irq_save();
|
2010-05-04 10:07:53 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
/* Queue up two transfers in a row */
|
2017-01-28 19:43:35 +00:00
|
|
|
bool ok = mc13783_transfer(&xfers[0].xfer,
|
|
|
|
&xfers[0].data[0], &xfers[0].data[0], 1,
|
2011-12-18 10:41:43 +00:00
|
|
|
mc13783_write_masked_cb) &&
|
2017-01-28 19:43:35 +00:00
|
|
|
mc13783_sync_transfer(&xfers[1], &xfers[0].data[1], NULL, 1);
|
2010-05-04 10:07:53 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
restore_irq(cpsr);
|
2010-05-04 10:07:53 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
if (ok && wait_for_transfer_complete(&xfers[1]))
|
2017-01-28 19:43:35 +00:00
|
|
|
return xfers[0].data[0];
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
return MC13783_DATA_ERROR;
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
uint32_t mc13783_read(unsigned address)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2011-12-18 10:41:43 +00:00
|
|
|
if (address >= MC13783_NUM_REGS)
|
|
|
|
return MC13783_DATA_ERROR;
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
uint32_t packet = address << 25;
|
2008-11-18 02:19:50 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
struct mc13783_transfer_desc xfer;
|
2017-01-28 19:43:35 +00:00
|
|
|
if (mc13783_sync_transfer(&xfer, &packet, &packet, 1) &&
|
2011-12-18 10:41:43 +00:00
|
|
|
wait_for_transfer_complete(&xfer))
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2011-12-18 10:41:43 +00:00
|
|
|
return packet;
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
return MC13783_DATA_ERROR;
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
int mc13783_write(unsigned address, uint32_t data)
|
2008-04-12 16:56:45 +00:00
|
|
|
{
|
2010-05-04 10:07:53 +00:00
|
|
|
if (address >= MC13783_NUM_REGS)
|
2011-12-18 10:41:43 +00:00
|
|
|
return -1;
|
2010-05-04 10:07:53 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
uint32_t packet = (1 << 31) | (address << 25) | (data & 0xffffff);
|
2010-05-04 10:07:53 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
struct mc13783_transfer_desc xfer;
|
2017-01-28 19:43:35 +00:00
|
|
|
if (mc13783_sync_transfer(&xfer, &packet, NULL, 1) &&
|
2011-12-18 10:41:43 +00:00
|
|
|
wait_for_transfer_complete(&xfer))
|
|
|
|
{
|
|
|
|
return 1 - xfer.xfer.count;
|
|
|
|
}
|
2010-05-04 10:07:53 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
return -1;
|
2010-05-04 10:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int mc13783_read_regs(const unsigned char *regs, uint32_t *buffer,
|
|
|
|
int count)
|
|
|
|
{
|
2011-12-18 10:41:43 +00:00
|
|
|
struct mc13783_transfer_desc xfer;
|
2017-01-28 19:43:35 +00:00
|
|
|
sync_transfer_init(&xfer);
|
2008-04-12 16:56:45 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
if (mc13783_read_async(&xfer.xfer, regs, buffer, count,
|
|
|
|
mc13783_xfer_complete_cb) &&
|
|
|
|
wait_for_transfer_complete(&xfer))
|
2008-04-12 16:56:45 +00:00
|
|
|
{
|
2011-12-18 10:41:43 +00:00
|
|
|
return count - xfer.xfer.count;
|
2008-04-12 16:56:45 +00:00
|
|
|
}
|
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
return -1;
|
2008-04-12 16:56:45 +00:00
|
|
|
}
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
int mc13783_write_regs(const unsigned char *regs, uint32_t *buffer,
|
|
|
|
int count)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2011-12-18 10:41:43 +00:00
|
|
|
struct mc13783_transfer_desc xfer;
|
2017-01-28 19:43:35 +00:00
|
|
|
sync_transfer_init(&xfer);
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
if (mc13783_write_async(&xfer.xfer, regs, buffer, count,
|
|
|
|
mc13783_xfer_complete_cb) &&
|
|
|
|
wait_for_transfer_complete(&xfer))
|
2010-05-04 10:07:53 +00:00
|
|
|
{
|
2011-12-18 10:41:43 +00:00
|
|
|
return count - xfer.xfer.count;
|
2010-05-04 10:07:53 +00:00
|
|
|
}
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
return -1;
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
bool mc13783_read_async(struct spi_transfer_desc *xfer,
|
|
|
|
const unsigned char *regs, uint32_t *buffer,
|
|
|
|
int count, spi_transfer_cb_fn_type callback)
|
2008-04-12 16:56:45 +00:00
|
|
|
{
|
2011-12-18 10:41:43 +00:00
|
|
|
for (int i = 0; i < count; i++)
|
2008-04-12 16:56:45 +00:00
|
|
|
{
|
|
|
|
unsigned reg = regs[i];
|
|
|
|
|
|
|
|
if (reg >= MC13783_NUM_REGS)
|
2010-05-04 10:07:53 +00:00
|
|
|
return false;
|
2008-04-12 16:56:45 +00:00
|
|
|
|
|
|
|
buffer[i] = reg << 25;
|
|
|
|
}
|
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
return mc13783_transfer(xfer, buffer, buffer, count, callback);
|
2010-05-04 10:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool mc13783_write_async(struct spi_transfer_desc *xfer,
|
|
|
|
const unsigned char *regs, uint32_t *buffer,
|
|
|
|
int count, spi_transfer_cb_fn_type callback)
|
|
|
|
{
|
2011-12-18 10:41:43 +00:00
|
|
|
for (int i = 0; i < count; i++)
|
2010-05-04 10:07:53 +00:00
|
|
|
{
|
|
|
|
unsigned reg = regs[i];
|
|
|
|
|
|
|
|
if (reg >= MC13783_NUM_REGS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
buffer[i] = (1 << 31) | (reg << 25) | (buffer[i] & 0xffffff);
|
|
|
|
}
|
|
|
|
|
2011-12-18 10:41:43 +00:00
|
|
|
return mc13783_transfer(xfer, buffer, NULL, count, callback);
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|