rtc: Introduce QMSI RTC device driver
This patch introduces the 'QMSI RTC device driver' which is simply a shim driver based on RTC driver provided by QMSI BSP. Some config options are independent of the driver implementation used, so use a consistent name for them. In this case RTC Interrupt number and Priority use the same config options for both the QMSI and DesignWare drivers. In order to enable this driver, the following options should be set: CONFIG_QMSI_DRIVERS=y CONFIG_QMSI_INSTALL_PATH="/path/to/libqmsi/directory" CONFIG_RTC=y CONFIG_RTC_QMSI=y Change-Id: I48292406e5472e5786f3b9abbeb71016a273bfec Signed-off-by: Andre Guedes <andre.guedes@intel.com> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
This commit is contained in:
parent
db2d48b66f
commit
7b0076a777
8 changed files with 150 additions and 32 deletions
103
drivers/rtc/rtc_qmsi.c
Normal file
103
drivers/rtc/rtc_qmsi.c
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <device.h>
|
||||
#include <drivers/ioapic.h>
|
||||
#include <init.h>
|
||||
#include <nanokernel.h>
|
||||
#include <rtc.h>
|
||||
|
||||
#include "qm_rtc.h"
|
||||
|
||||
IRQ_CONNECT_STATIC(rtc, CONFIG_RTC_IRQ, CONFIG_RTC_IRQ_PRI, qm_rtc_isr_0,
|
||||
0, IOAPIC_EDGE | IOAPIC_HIGH);
|
||||
|
||||
static struct device *rtc_qmsi_dev;
|
||||
|
||||
static void (*user_callback)(struct device *dev);
|
||||
|
||||
static void rtc_qmsi_enable(struct device *dev)
|
||||
{
|
||||
clk_periph_enable(CLK_PERIPH_RTC_REGISTER | CLK_PERIPH_CLK);
|
||||
}
|
||||
|
||||
static void rtc_qmsi_disable(struct device *dev)
|
||||
{
|
||||
clk_periph_disable(CLK_PERIPH_RTC_REGISTER);
|
||||
}
|
||||
|
||||
static void rtc_callback(void)
|
||||
{
|
||||
if (user_callback)
|
||||
user_callback(rtc_qmsi_dev);
|
||||
}
|
||||
|
||||
static int rtc_qmsi_set_config(struct device *dev, struct rtc_config *cfg)
|
||||
{
|
||||
qm_rtc_config_t qm_cfg;
|
||||
|
||||
qm_cfg.init_val = cfg->init_val;
|
||||
qm_cfg.alarm_en = cfg->alarm_enable;
|
||||
qm_cfg.alarm_val = cfg->alarm_val;
|
||||
qm_cfg.callback = rtc_callback;
|
||||
|
||||
user_callback = cfg->cb_fn;
|
||||
|
||||
if (qm_rtc_set_config(QM_RTC_0, &qm_cfg) != QM_RC_OK)
|
||||
return DEV_FAIL;
|
||||
|
||||
return DEV_OK;
|
||||
}
|
||||
|
||||
static int rtc_qmsi_set_alarm(struct device *dev, const uint32_t alarm_val)
|
||||
{
|
||||
return qm_rtc_set_alarm(QM_RTC_0, alarm_val) == QM_RC_OK ? DEV_OK : DEV_FAIL;
|
||||
}
|
||||
|
||||
static uint32_t rtc_qmsi_read(struct device *dev)
|
||||
{
|
||||
return QM_RTC[QM_RTC_0].rtc_ccvr;
|
||||
}
|
||||
|
||||
static struct rtc_driver_api api = {
|
||||
.enable = rtc_qmsi_enable,
|
||||
.disable = rtc_qmsi_disable,
|
||||
.read = rtc_qmsi_read,
|
||||
.set_config = rtc_qmsi_set_config,
|
||||
.set_alarm = rtc_qmsi_set_alarm,
|
||||
};
|
||||
|
||||
static int rtc_qmsi_init(struct device *dev)
|
||||
{
|
||||
IRQ_CONFIG(rtc, CONFIG_RTC_IRQ);
|
||||
|
||||
/* Unmask RTC interrupt */
|
||||
irq_enable(CONFIG_RTC_IRQ);
|
||||
|
||||
/* Route RTC interrupt to Lakemont */
|
||||
QM_SCSS_INT->int_rtc_mask &= ~BIT(0);
|
||||
|
||||
dev->driver_api = &api;
|
||||
return DEV_OK;
|
||||
}
|
||||
|
||||
DECLARE_DEVICE_INIT_CONFIG(rtc, CONFIG_RTC_DRV_NAME,
|
||||
&rtc_qmsi_init, NULL);
|
||||
|
||||
SYS_DEFINE_DEVICE(rtc, NULL, SECONDARY,
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
|
||||
|
||||
static struct device *rtc_qmsi_dev = SYS_GET_DEVICE(rtc);
|
Loading…
Add table
Add a link
Reference in a new issue