2016-03-10 10:46:15 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation.
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-03-10 10:46:15 +08:00
|
|
|
*/
|
|
|
|
|
2016-03-10 02:22:04 +08:00
|
|
|
#include <errno.h>
|
|
|
|
|
2016-03-10 10:46:15 +08:00
|
|
|
#include <stdio.h>
|
2016-11-11 03:37:51 +08:00
|
|
|
#include <kernel.h>
|
2016-03-10 10:46:15 +08:00
|
|
|
#include <board.h>
|
|
|
|
#include <device.h>
|
|
|
|
#include <init.h>
|
|
|
|
#include <aio_comparator.h>
|
|
|
|
|
|
|
|
#include "qm_comparator.h"
|
|
|
|
|
|
|
|
#define INT_COMPARATORS_MASK 0x7FFFF
|
|
|
|
#define AIO_QMSI_CMP_COUNT (19)
|
2016-10-29 00:56:01 +08:00
|
|
|
#if (QM_LAKEMONT)
|
|
|
|
#define CMP_INTR_ROUTER QM_INTERRUPT_ROUTER->comparator_0_host_int_mask
|
|
|
|
#else
|
|
|
|
#define CMP_INTR_ROUTER QM_INTERRUPT_ROUTER->comparator_0_ss_int_mask
|
|
|
|
#endif
|
2016-03-10 10:46:15 +08:00
|
|
|
|
|
|
|
struct aio_qmsi_cmp_cb {
|
|
|
|
aio_cmp_cb cb;
|
|
|
|
void *param;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct aio_qmsi_cmp_dev_data_t {
|
|
|
|
/** Number of total comparators */
|
2017-04-21 23:03:20 +08:00
|
|
|
u8_t num_cmp;
|
2016-03-10 10:46:15 +08:00
|
|
|
/** Callback for each comparator */
|
|
|
|
struct aio_qmsi_cmp_cb cb[AIO_QMSI_CMP_COUNT];
|
|
|
|
};
|
|
|
|
|
2016-05-18 19:09:16 +08:00
|
|
|
/* Shadow configuration to keep track of changes */
|
|
|
|
static qm_ac_config_t config;
|
|
|
|
|
2016-03-10 10:46:15 +08:00
|
|
|
static int aio_cmp_config(struct device *dev);
|
|
|
|
|
2017-04-21 23:03:20 +08:00
|
|
|
static int aio_qmsi_cmp_disable(struct device *dev, u8_t index)
|
2016-03-10 10:46:15 +08:00
|
|
|
{
|
|
|
|
if (index >= AIO_QMSI_CMP_COUNT) {
|
2016-03-10 02:22:04 +08:00
|
|
|
return -EINVAL;
|
2016-03-10 10:46:15 +08:00
|
|
|
}
|
|
|
|
|
2016-10-29 00:56:01 +08:00
|
|
|
/* Disable interrupt to current core */
|
|
|
|
CMP_INTR_ROUTER |= (1 << index);
|
2016-03-10 10:46:15 +08:00
|
|
|
|
|
|
|
/* Disable comparator according to index */
|
2017-02-02 09:12:34 +08:00
|
|
|
config.cmp_en &= ~(1 << index);
|
2016-03-10 10:46:15 +08:00
|
|
|
config.power &= ~(1 << index);
|
2016-11-22 19:59:29 +08:00
|
|
|
config.reference &= ~(1 << index);
|
|
|
|
config.polarity &= ~(1 << index);
|
2016-03-10 10:46:15 +08:00
|
|
|
|
2016-05-18 19:09:16 +08:00
|
|
|
if (qm_ac_set_config(&config) != 0) {
|
2016-03-10 02:22:04 +08:00
|
|
|
return -EINVAL;
|
2016-03-10 10:46:15 +08:00
|
|
|
}
|
|
|
|
|
2016-03-10 01:01:20 +08:00
|
|
|
return 0;
|
2016-03-10 10:46:15 +08:00
|
|
|
}
|
|
|
|
|
2017-04-21 23:03:20 +08:00
|
|
|
static int aio_qmsi_cmp_configure(struct device *dev, u8_t index,
|
2016-03-10 10:46:15 +08:00
|
|
|
enum aio_cmp_polarity polarity,
|
|
|
|
enum aio_cmp_ref refsel,
|
|
|
|
aio_cmp_cb cb, void *param)
|
|
|
|
{
|
|
|
|
struct aio_qmsi_cmp_dev_data_t *dev_data =
|
|
|
|
(struct aio_qmsi_cmp_dev_data_t *)dev->driver_data;
|
|
|
|
|
|
|
|
if (index >= AIO_QMSI_CMP_COUNT) {
|
2016-03-10 02:22:04 +08:00
|
|
|
return -EINVAL;
|
2016-03-10 10:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
aio_qmsi_cmp_disable(dev, index);
|
|
|
|
|
|
|
|
dev_data->cb[index].cb = cb;
|
|
|
|
dev_data->cb[index].param = param;
|
|
|
|
|
|
|
|
if (refsel == AIO_CMP_REF_A) {
|
|
|
|
config.reference &= ~(1 << index);
|
|
|
|
} else {
|
|
|
|
config.reference |= (1 << index);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (polarity == AIO_CMP_POL_RISE) {
|
|
|
|
config.polarity &= ~(1 << index);
|
|
|
|
} else {
|
|
|
|
config.polarity |= (1 << index);
|
|
|
|
}
|
|
|
|
/* The driver will not use QMSI callback mechanism */
|
|
|
|
config.callback = NULL;
|
|
|
|
/* Enable comparator */
|
2017-02-02 09:12:34 +08:00
|
|
|
config.cmp_en |= (1 << index);
|
2016-03-10 10:46:15 +08:00
|
|
|
config.power |= (1 << index);
|
|
|
|
|
2016-05-18 19:09:16 +08:00
|
|
|
if (qm_ac_set_config(&config) != 0) {
|
2016-03-10 02:22:04 +08:00
|
|
|
return -EINVAL;
|
2016-03-10 10:46:15 +08:00
|
|
|
}
|
|
|
|
|
2016-10-29 00:56:01 +08:00
|
|
|
/* Enable Interrupts to current core for an specific comparator */
|
|
|
|
CMP_INTR_ROUTER &= ~(1 << index);
|
2016-03-10 10:46:15 +08:00
|
|
|
|
2016-03-10 01:01:20 +08:00
|
|
|
return 0;
|
2016-03-10 10:46:15 +08:00
|
|
|
}
|
|
|
|
|
2017-04-21 23:03:20 +08:00
|
|
|
static u32_t aio_cmp_qmsi_get_pending_int(struct device *dev)
|
2016-10-27 21:31:19 +08:00
|
|
|
{
|
|
|
|
return QM_SCSS_CMP->cmp_stat_clr;
|
|
|
|
}
|
|
|
|
|
2016-10-24 15:17:37 +08:00
|
|
|
static const struct aio_cmp_driver_api aio_cmp_funcs = {
|
2016-03-10 10:46:15 +08:00
|
|
|
.disable = aio_qmsi_cmp_disable,
|
|
|
|
.configure = aio_qmsi_cmp_configure,
|
2016-10-27 21:31:19 +08:00
|
|
|
.get_pending_int = aio_cmp_qmsi_get_pending_int,
|
2016-03-10 10:46:15 +08:00
|
|
|
};
|
|
|
|
|
2016-10-26 05:38:03 +08:00
|
|
|
static int aio_qmsi_cmp_init(struct device *dev)
|
2016-03-10 10:46:15 +08:00
|
|
|
{
|
2017-04-21 23:03:20 +08:00
|
|
|
u8_t i;
|
2016-03-10 10:46:15 +08:00
|
|
|
struct aio_qmsi_cmp_dev_data_t *dev_data =
|
|
|
|
(struct aio_qmsi_cmp_dev_data_t *)dev->driver_data;
|
|
|
|
|
|
|
|
aio_cmp_config(dev);
|
|
|
|
|
|
|
|
/* Disable all comparator interrupts */
|
2016-10-29 00:56:01 +08:00
|
|
|
CMP_INTR_ROUTER |= INT_COMPARATORS_MASK;
|
2016-03-10 10:46:15 +08:00
|
|
|
|
|
|
|
/* Clear status and dissble all comparators */
|
|
|
|
QM_SCSS_CMP->cmp_stat_clr |= INT_COMPARATORS_MASK;
|
|
|
|
QM_SCSS_CMP->cmp_pwr &= ~INT_COMPARATORS_MASK;
|
|
|
|
QM_SCSS_CMP->cmp_en &= ~INT_COMPARATORS_MASK;
|
|
|
|
|
2016-05-18 19:09:16 +08:00
|
|
|
/* Don't use the QMSI callback */
|
|
|
|
config.callback = NULL;
|
|
|
|
/* Get Initial configuration from HW */
|
|
|
|
config.reference = QM_SCSS_CMP->cmp_ref_sel;
|
|
|
|
config.polarity = QM_SCSS_CMP->cmp_ref_pol;
|
|
|
|
config.power = QM_SCSS_CMP->cmp_pwr;
|
2017-02-02 09:12:34 +08:00
|
|
|
config.cmp_en = QM_SCSS_CMP->cmp_en;
|
2016-05-18 19:09:16 +08:00
|
|
|
|
2016-03-10 10:46:15 +08:00
|
|
|
/* Clear callback pointers */
|
|
|
|
for (i = 0; i < dev_data->num_cmp; i++) {
|
|
|
|
dev_data->cb[i].cb = NULL;
|
|
|
|
dev_data->cb[i].param = NULL;
|
|
|
|
}
|
|
|
|
|
2016-10-29 00:56:01 +08:00
|
|
|
irq_enable(IRQ_GET_NUMBER(QM_IRQ_COMPARATOR_0_INT));
|
2016-03-10 10:46:15 +08:00
|
|
|
|
2016-03-10 01:01:20 +08:00
|
|
|
return 0;
|
2016-03-10 10:46:15 +08:00
|
|
|
}
|
|
|
|
|
2016-10-29 00:56:01 +08:00
|
|
|
static void aio_qmsi_cmp_isr(void *data)
|
2016-03-10 10:46:15 +08:00
|
|
|
{
|
2017-04-21 23:03:20 +08:00
|
|
|
u8_t i;
|
2016-10-29 00:56:01 +08:00
|
|
|
struct device *dev = data;
|
2016-03-10 10:46:15 +08:00
|
|
|
struct aio_qmsi_cmp_dev_data_t *dev_data =
|
|
|
|
(struct aio_qmsi_cmp_dev_data_t *)dev->driver_data;
|
|
|
|
|
2017-04-21 23:03:20 +08:00
|
|
|
u32_t int_status = QM_SCSS_CMP->cmp_stat_clr;
|
2016-03-10 10:46:15 +08:00
|
|
|
|
|
|
|
for (i = 0; i < dev_data->num_cmp; i++) {
|
|
|
|
if (int_status & (1 << i)) {
|
|
|
|
if (dev_data->cb[i].cb != NULL) {
|
|
|
|
dev_data->cb[i].cb(dev_data->cb[i].param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear all pending interrupts */
|
|
|
|
QM_SCSS_CMP->cmp_stat_clr = int_status;
|
|
|
|
}
|
|
|
|
|
2016-11-18 23:08:29 +08:00
|
|
|
static struct aio_qmsi_cmp_dev_data_t aio_qmsi_cmp_dev_data = {
|
2016-03-10 10:46:15 +08:00
|
|
|
.num_cmp = AIO_QMSI_CMP_COUNT,
|
|
|
|
};
|
|
|
|
|
2016-05-08 00:06:09 +08:00
|
|
|
DEVICE_AND_API_INIT(aio_qmsi_cmp, CONFIG_AIO_COMPARATOR_0_NAME,
|
2016-04-28 06:28:45 +08:00
|
|
|
&aio_qmsi_cmp_init, &aio_qmsi_cmp_dev_data, NULL,
|
2016-11-09 03:06:55 +08:00
|
|
|
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
2016-04-28 06:28:45 +08:00
|
|
|
(void *)&aio_cmp_funcs);
|
2016-03-10 10:46:15 +08:00
|
|
|
|
|
|
|
static int aio_cmp_config(struct device *dev)
|
|
|
|
{
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
2016-10-29 00:56:01 +08:00
|
|
|
IRQ_CONNECT(IRQ_GET_NUMBER(QM_IRQ_COMPARATOR_0_INT),
|
|
|
|
CONFIG_AIO_COMPARATOR_0_IRQ_PRI, aio_qmsi_cmp_isr,
|
|
|
|
DEVICE_GET(aio_qmsi_cmp), 0);
|
2016-03-10 10:46:15 +08:00
|
|
|
|
2016-03-10 01:01:20 +08:00
|
|
|
return 0;
|
2016-03-10 10:46:15 +08:00
|
|
|
}
|