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"
|
2008-04-12 16:56:45 +00:00
|
|
|
#include "gpio-imx31.h"
|
2008-04-11 08:51:27 +00:00
|
|
|
#include "mc13783.h"
|
2010-05-07 10:53:19 +00:00
|
|
|
#include "mc13783-target.h"
|
2008-04-11 08:51:27 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
|
2010-05-07 10:53:19 +00:00
|
|
|
extern const struct mc13783_event mc13783_events[MC13783_NUM_EVENTS];
|
2010-04-10 09:24:06 +00:00
|
|
|
extern struct spi_node mc13783_spi;
|
2008-05-21 08:42:11 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
/* PMIC event service data */
|
2008-05-21 08:54:02 +00:00
|
|
|
static int mc13783_thread_stack[DEFAULT_STACK_SIZE/sizeof(int)];
|
2008-04-11 08:51:27 +00:00
|
|
|
static const char *mc13783_thread_name = "pmic";
|
2011-03-02 08:49:38 +00:00
|
|
|
static struct semaphore mc13783_svc_wake;
|
2010-05-04 10:07:53 +00:00
|
|
|
|
|
|
|
/* Synchronous thread communication objects */
|
|
|
|
static struct mutex mc13783_spi_mutex;
|
2011-03-02 08:49:38 +00:00
|
|
|
static struct semaphore mc13783_spi_complete;
|
2008-05-21 08:42:11 +00:00
|
|
|
|
|
|
|
/* Tracking for which interrupts are enabled */
|
|
|
|
static uint32_t pmic_int_enabled[2] =
|
|
|
|
{ 0x00000000, 0x00000000 };
|
|
|
|
|
|
|
|
static const unsigned char pmic_intm_regs[2] =
|
|
|
|
{ MC13783_INTERRUPT_MASK0, MC13783_INTERRUPT_MASK1 };
|
|
|
|
|
|
|
|
static const unsigned char pmic_ints_regs[2] =
|
|
|
|
{ MC13783_INTERRUPT_STATUS0, MC13783_INTERRUPT_STATUS1 };
|
|
|
|
|
2010-04-23 15:32:50 +00:00
|
|
|
static volatile unsigned int mc13783_thread_id = 0;
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
static void mc13783_xfer_complete_cb(struct spi_transfer_desc *trans);
|
|
|
|
|
|
|
|
/* Transfer descriptor for synchronous reads and writes */
|
|
|
|
static struct spi_transfer_desc mc13783_transfer =
|
|
|
|
{
|
|
|
|
.node = &mc13783_spi,
|
|
|
|
.txbuf = NULL,
|
|
|
|
.rxbuf = NULL,
|
|
|
|
.count = 0,
|
|
|
|
.callback = mc13783_xfer_complete_cb,
|
|
|
|
.next = NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Called when a transfer is finished and data is ready/written */
|
|
|
|
static void mc13783_xfer_complete_cb(struct spi_transfer_desc *xfer)
|
|
|
|
{
|
|
|
|
if (xfer->count != 0)
|
|
|
|
return;
|
|
|
|
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_release(&mc13783_spi_complete);
|
2010-05-04 10:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool wait_for_transfer_complete(void)
|
|
|
|
{
|
2011-03-02 08:49:38 +00:00
|
|
|
return semaphore_wait(&mc13783_spi_complete, HZ*2)
|
|
|
|
== OBJ_WAIT_SUCCEEDED && mc13783_transfer.count == 0;
|
2010-05-04 10:07:53 +00:00
|
|
|
}
|
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
static void mc13783_interrupt_thread(void)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2008-04-12 16:56:45 +00:00
|
|
|
uint32_t pending[2];
|
|
|
|
|
2008-05-21 08:42:11 +00:00
|
|
|
/* Enable mc13783 GPIO event */
|
|
|
|
gpio_enable_event(MC13783_EVENT_ID);
|
2008-04-13 20:03:08 +00:00
|
|
|
|
2008-04-11 08:51:27 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2008-05-21 08:42:11 +00:00
|
|
|
const struct mc13783_event *event, *event_last;
|
|
|
|
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_wait(&mc13783_svc_wake, TIMEOUT_BLOCK);
|
2008-04-12 16:56:45 +00:00
|
|
|
|
2010-04-23 15:32:50 +00:00
|
|
|
if (mc13783_thread_id == 0)
|
2008-05-21 08:42:11 +00:00
|
|
|
break;
|
2008-05-10 18:00:11 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mc13783_read_regs(pmic_ints_regs, pending, 2);
|
2008-04-12 16:56:45 +00:00
|
|
|
|
2008-05-21 08:42:11 +00:00
|
|
|
/* Only clear interrupts being dispatched */
|
|
|
|
pending[0] &= pmic_int_enabled[0];
|
|
|
|
pending[1] &= pmic_int_enabled[1];
|
2008-04-13 20:03:08 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mc13783_write_regs(pmic_ints_regs, pending, 2);
|
2008-04-13 10:04:21 +00:00
|
|
|
|
2009-02-02 02:38:21 +00:00
|
|
|
/* Whatever is going to be serviced in this loop has been
|
|
|
|
* acknowledged. Reenable interrupt and if anything was still
|
|
|
|
* pending or became pending again, another signal will be
|
|
|
|
* generated. */
|
2010-06-30 02:02:46 +00:00
|
|
|
bitset32(&MC13783_GPIO_IMR, 1ul << MC13783_GPIO_LINE);
|
2009-02-02 02:38:21 +00:00
|
|
|
|
2010-05-07 10:53:19 +00:00
|
|
|
event = mc13783_events;
|
|
|
|
event_last = event + MC13783_NUM_EVENTS;
|
2008-04-18 16:42:50 +00:00
|
|
|
|
2008-05-21 08:42:11 +00:00
|
|
|
/* .count is surely expected to be > 0 */
|
|
|
|
do
|
2008-04-12 16:56:45 +00:00
|
|
|
{
|
2008-05-21 08:42:11 +00:00
|
|
|
enum mc13783_event_sets set = event->set;
|
|
|
|
uint32_t pnd = pending[set];
|
|
|
|
uint32_t mask = event->mask;
|
2008-04-13 20:03:08 +00:00
|
|
|
|
2008-05-21 08:42:11 +00:00
|
|
|
if (pnd & mask)
|
2008-04-12 16:56:45 +00:00
|
|
|
{
|
2008-05-21 08:42:11 +00:00
|
|
|
event->callback();
|
|
|
|
pnd &= ~mask;
|
|
|
|
pending[set] = pnd;
|
2008-04-12 16:56:45 +00:00
|
|
|
}
|
2008-05-21 08:42:11 +00:00
|
|
|
|
|
|
|
if ((pending[0] | pending[1]) == 0)
|
2010-05-04 10:07:53 +00:00
|
|
|
break; /* Terminate early if nothing more to service */
|
2008-04-12 16:56:45 +00:00
|
|
|
}
|
2008-05-21 08:42:11 +00:00
|
|
|
while (++event < event_last);
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
2008-05-21 08:42:11 +00:00
|
|
|
|
|
|
|
gpio_disable_event(MC13783_EVENT_ID);
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 16:56:45 +00:00
|
|
|
/* GPIO interrupt handler for mc13783 */
|
2008-05-21 08:42:11 +00:00
|
|
|
void mc13783_event(void)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2009-02-02 02:38:21 +00:00
|
|
|
/* Mask the interrupt (unmasked when PMIC thread services it). */
|
2010-06-30 02:02:46 +00:00
|
|
|
bitclr32(&MC13783_GPIO_IMR, 1ul << MC13783_GPIO_LINE);
|
2008-04-12 16:56:45 +00:00
|
|
|
MC13783_GPIO_ISR = (1ul << MC13783_GPIO_LINE);
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_release(&mc13783_svc_wake);
|
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! */
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_init(&mc13783_svc_wake, 1, 0);
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_init(&mc13783_spi_mutex);
|
|
|
|
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_init(&mc13783_spi_complete, 1, 0);
|
2008-04-11 08:51:27 +00:00
|
|
|
|
|
|
|
/* Enable the PMIC SPI module */
|
|
|
|
spi_enable_module(&mc13783_spi);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
MC13783_GPIO_ISR = (1ul << MC13783_GPIO_LINE);
|
|
|
|
|
2008-12-10 08:57:10 +00:00
|
|
|
mc13783_thread_id =
|
2008-05-10 18:00:11 +00:00
|
|
|
create_thread(mc13783_interrupt_thread,
|
|
|
|
mc13783_thread_stack, sizeof(mc13783_thread_stack), 0,
|
|
|
|
mc13783_thread_name IF_PRIO(, PRIORITY_REALTIME) IF_COP(, CPU));
|
|
|
|
}
|
|
|
|
|
|
|
|
void mc13783_close(void)
|
|
|
|
{
|
2008-12-10 09:11:43 +00:00
|
|
|
unsigned int thread_id = mc13783_thread_id;
|
2008-05-10 18:00:11 +00:00
|
|
|
|
2008-12-10 08:57:10 +00:00
|
|
|
if (thread_id == 0)
|
2008-05-10 18:00:11 +00:00
|
|
|
return;
|
|
|
|
|
2008-12-10 08:57:10 +00:00
|
|
|
mc13783_thread_id = 0;
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_release(&mc13783_svc_wake);
|
2008-12-10 08:57:10 +00:00
|
|
|
thread_wait(thread_id);
|
2010-05-04 10:07:53 +00:00
|
|
|
spi_disable_module(&mc13783_spi);
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
2008-05-21 08:42:11 +00:00
|
|
|
|
|
|
|
bool mc13783_enable_event(enum mc13783_event_ids id)
|
|
|
|
{
|
2010-05-07 10:53:19 +00:00
|
|
|
const struct mc13783_event * const event = &mc13783_events[id];
|
2008-05-21 08:42:11 +00:00
|
|
|
int set = event->set;
|
|
|
|
uint32_t mask = event->mask;
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_lock(&mc13783_spi_mutex);
|
2008-05-21 08:42:11 +00:00
|
|
|
|
|
|
|
pmic_int_enabled[set] |= mask;
|
|
|
|
mc13783_clear(pmic_intm_regs[set], mask);
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_unlock(&mc13783_spi_mutex);
|
2008-05-21 08:42:11 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mc13783_disable_event(enum mc13783_event_ids id)
|
|
|
|
{
|
2010-05-07 10:53:19 +00:00
|
|
|
const struct mc13783_event * const event = &mc13783_events[id];
|
2008-05-21 08:42:11 +00:00
|
|
|
int set = event->set;
|
|
|
|
uint32_t mask = event->mask;
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_lock(&mc13783_spi_mutex);
|
2008-05-21 08:42:11 +00:00
|
|
|
|
|
|
|
pmic_int_enabled[set] &= ~mask;
|
|
|
|
mc13783_set(pmic_intm_regs[set], mask);
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_unlock(&mc13783_spi_mutex);
|
2008-05-21 08:42:11 +00:00
|
|
|
}
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2008-04-12 16:56:45 +00:00
|
|
|
uint32_t mc13783_set(unsigned address, uint32_t bits)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2010-05-04 10:07:53 +00:00
|
|
|
uint32_t data;
|
|
|
|
|
|
|
|
mutex_lock(&mc13783_spi_mutex);
|
2008-04-12 16:56:45 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
data = mc13783_read(address);
|
2008-04-12 16:56:45 +00:00
|
|
|
|
2008-11-18 02:19:50 +00:00
|
|
|
if (data != MC13783_DATA_ERROR)
|
2008-04-12 16:56:45 +00:00
|
|
|
mc13783_write(address, data | bits);
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_unlock(&mc13783_spi_mutex);
|
2008-04-12 16:56:45 +00:00
|
|
|
|
|
|
|
return data;
|
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
|
|
|
{
|
2010-05-04 10:07:53 +00:00
|
|
|
uint32_t data;
|
2008-04-12 16:56:45 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_lock(&mc13783_spi_mutex);
|
|
|
|
|
|
|
|
data = mc13783_read(address);
|
2008-04-12 16:56:45 +00:00
|
|
|
|
2008-11-18 02:19:50 +00:00
|
|
|
if (data != MC13783_DATA_ERROR)
|
2008-04-12 16:56:45 +00:00
|
|
|
mc13783_write(address, data & ~bits);
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_unlock(&mc13783_spi_mutex);
|
2008-04-12 16:56:45 +00:00
|
|
|
|
|
|
|
return data;
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int mc13783_write(unsigned address, uint32_t data)
|
|
|
|
{
|
|
|
|
uint32_t packet;
|
2010-05-04 10:07:53 +00:00
|
|
|
int i;
|
2008-04-11 08:51:27 +00:00
|
|
|
|
|
|
|
if (address >= MC13783_NUM_REGS)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
packet = (1 << 31) | (address << 25) | (data & 0xffffff);
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_lock(&mc13783_spi_mutex);
|
|
|
|
|
|
|
|
mc13783_transfer.txbuf = &packet;
|
|
|
|
mc13783_transfer.rxbuf = NULL;
|
|
|
|
mc13783_transfer.count = 1;
|
|
|
|
|
|
|
|
i = -1;
|
|
|
|
|
|
|
|
if (spi_transfer(&mc13783_transfer) && wait_for_transfer_complete())
|
|
|
|
i = 1 - mc13783_transfer.count;
|
|
|
|
|
|
|
|
mutex_unlock(&mc13783_spi_mutex);
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
return i;
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 02:19:50 +00:00
|
|
|
uint32_t mc13783_write_masked(unsigned address, uint32_t data, uint32_t mask)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2008-11-18 02:19:50 +00:00
|
|
|
uint32_t old;
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_lock(&mc13783_spi_mutex);
|
2008-11-18 02:19:50 +00:00
|
|
|
|
|
|
|
old = mc13783_read(address);
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2008-11-18 02:19:50 +00:00
|
|
|
if (old != MC13783_DATA_ERROR)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2008-11-18 02:19:50 +00:00
|
|
|
data = (old & ~mask) | (data & mask);
|
|
|
|
|
|
|
|
if (mc13783_write(address, data) != 1)
|
|
|
|
old = MC13783_DATA_ERROR;
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_unlock(&mc13783_spi_mutex);
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2008-11-18 02:19:50 +00:00
|
|
|
return old;
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
uint32_t mc13783_read(unsigned address)
|
2008-04-12 16:56:45 +00:00
|
|
|
{
|
2010-05-04 10:07:53 +00:00
|
|
|
uint32_t packet;
|
2008-04-12 16:56:45 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
if (address >= MC13783_NUM_REGS)
|
|
|
|
return MC13783_DATA_ERROR;
|
|
|
|
|
|
|
|
packet = address << 25;
|
|
|
|
|
|
|
|
mutex_lock(&mc13783_spi_mutex);
|
|
|
|
|
|
|
|
mc13783_transfer.txbuf = &packet;
|
|
|
|
mc13783_transfer.rxbuf = &packet;
|
|
|
|
mc13783_transfer.count = 1;
|
|
|
|
|
|
|
|
if (!spi_transfer(&mc13783_transfer) || !wait_for_transfer_complete())
|
|
|
|
packet = MC13783_DATA_ERROR;
|
|
|
|
|
|
|
|
mutex_unlock(&mc13783_spi_mutex);
|
|
|
|
|
|
|
|
return packet;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mc13783_read_regs(const unsigned char *regs, uint32_t *buffer,
|
|
|
|
int count)
|
|
|
|
{
|
|
|
|
int i;
|
2008-04-12 16:56:45 +00:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2010-05-04 10:07:53 +00:00
|
|
|
unsigned reg = regs[i];
|
2008-04-12 16:56:45 +00:00
|
|
|
|
|
|
|
if (reg >= MC13783_NUM_REGS)
|
|
|
|
return -1;
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
buffer[i] = reg << 25;
|
2008-04-12 16:56:45 +00:00
|
|
|
}
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_lock(&mc13783_spi_mutex);
|
2008-04-12 16:56:45 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mc13783_transfer.txbuf = buffer;
|
|
|
|
mc13783_transfer.rxbuf = buffer;
|
|
|
|
mc13783_transfer.count = count;
|
|
|
|
|
|
|
|
i = -1;
|
|
|
|
|
|
|
|
if (spi_transfer(&mc13783_transfer) && wait_for_transfer_complete())
|
|
|
|
i = count - mc13783_transfer.count;
|
2008-04-12 16:56:45 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_unlock(&mc13783_spi_mutex);
|
|
|
|
|
|
|
|
return i;
|
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
|
|
|
{
|
2010-05-04 10:07:53 +00:00
|
|
|
int i;
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
unsigned reg = regs[i];
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
if (reg >= MC13783_NUM_REGS)
|
|
|
|
return -1;
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
buffer[i] = (1 << 31) | (reg << 25) | (buffer[i] & 0xffffff);
|
|
|
|
}
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mutex_lock(&mc13783_spi_mutex);
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
mc13783_transfer.txbuf = buffer;
|
|
|
|
mc13783_transfer.rxbuf = NULL;
|
|
|
|
mc13783_transfer.count = count;
|
|
|
|
|
|
|
|
i = -1;
|
|
|
|
|
|
|
|
if (spi_transfer(&mc13783_transfer) && wait_for_transfer_complete())
|
|
|
|
i = count - mc13783_transfer.count;
|
|
|
|
|
|
|
|
mutex_unlock(&mc13783_spi_mutex);
|
|
|
|
|
|
|
|
return i;
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
#if 0 /* Not needed right now */
|
|
|
|
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
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
xfer->node = &mc13783_spi;
|
|
|
|
xfer->txbuf = buffer;
|
|
|
|
xfer->rxbuf = buffer;
|
|
|
|
xfer->count = count;
|
|
|
|
xfer->callback = callback;
|
2011-01-23 20:21:35 +00:00
|
|
|
xfer->next = NULL;
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
return spi_transfer(xfer);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool mc13783_write_async(struct spi_transfer_desc *xfer,
|
|
|
|
const unsigned char *regs, uint32_t *buffer,
|
|
|
|
int count, spi_transfer_cb_fn_type callback)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
unsigned reg = regs[i];
|
|
|
|
|
|
|
|
if (reg >= MC13783_NUM_REGS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
buffer[i] = (1 << 31) | (reg << 25) | (buffer[i] & 0xffffff);
|
|
|
|
}
|
|
|
|
|
|
|
|
xfer->node = &mc13783_spi;
|
|
|
|
xfer->txbuf = buffer;
|
|
|
|
xfer->rxbuf = NULL;
|
|
|
|
xfer->count = count;
|
|
|
|
xfer->callback = callback;
|
2011-01-23 20:21:35 +00:00
|
|
|
xfer->next = NULL;
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
return spi_transfer(xfer);
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|