drivers: mfd: Enabled motorola,mc146818 MFD
Enabled Motorola, mc146818 MFD, which implements RTC read/write operations and prevents data corruption by synchronizing these operations. Signed-off-by: Anisetti Avinash Krishna <anisetti.avinash.krishna@intel.com>
This commit is contained in:
committed by
Henrik Brix Andersen
parent
4c8419b992
commit
fbec41494d
@@ -26,3 +26,4 @@ zephyr_library_sources_ifdef(CONFIG_MFD_MAX22017 mfd_max22017.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_MFD_MCHP_SAM_FLEXCOM mfd_mchp_sam_flexcom.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_MFD_PF1550 mfd_pf1550.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_MFD_PCA9422 mfd_pca9422.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_MFD_MOTOROLA_MC146818 mfd_mc146818.c)
|
||||
|
||||
@@ -38,5 +38,6 @@ source "drivers/mfd/Kconfig.lpflexcomm"
|
||||
source "drivers/mfd/Kconfig.tle9104"
|
||||
source "drivers/mfd/Kconfig.it8801"
|
||||
source "drivers/mfd/Kconfig.pca9422"
|
||||
source "drivers/mfd/Kconfig.mc146818"
|
||||
|
||||
endif # MFD
|
||||
|
||||
20
drivers/mfd/Kconfig.mc146818
Normal file
20
drivers/mfd/Kconfig.mc146818
Normal file
@@ -0,0 +1,20 @@
|
||||
# Intel SoC RTC configuration options
|
||||
|
||||
# Copyright (c) 2025 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config MFD_MOTOROLA_MC146818
|
||||
bool "MOTOROLA MC146818 multi-function device driver"
|
||||
default y
|
||||
depends on DT_HAS_MOTOROLA_MC146818_MFD_ENABLED
|
||||
help
|
||||
common code required by bbram and rtc, which will likely be a locking mechanism
|
||||
so both RTC and BBRAM can set/get regs safely and independently.
|
||||
|
||||
config MFD_MOTOROLA_MC146818_INIT_PRIORITY
|
||||
int "Init priority of mc146818 MFD"
|
||||
depends on MFD_MOTOROLA_MC146818
|
||||
default 50
|
||||
help
|
||||
Initialization priority for the MOTOROLA MC146818 MFD driver.
|
||||
It must be greater than RTC, COUNTER and BBRAM driver init priority.
|
||||
86
drivers/mfd/mfd_mc146818.c
Normal file
86
drivers/mfd/mfd_mc146818.c
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT motorola_mc146818_mfd
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/spinlock.h>
|
||||
#include <zephyr/drivers/mfd/mc146818.h>
|
||||
#include <zephyr/init.h>
|
||||
#include <zephyr/sys/util.h>
|
||||
#include <zephyr/devicetree.h>
|
||||
#include <zephyr/sys/sys_io.h>
|
||||
|
||||
#define RTC_STD_INDEX (DT_INST_REG_ADDR_BY_IDX(0, 0))
|
||||
#define RTC_STD_TARGET (DT_INST_REG_ADDR_BY_IDX(0, 1))
|
||||
#define RTC_EXT_INDEX (DT_INST_REG_ADDR_BY_IDX(0, 2))
|
||||
#define RTC_EXT_TARGET (DT_INST_REG_ADDR_BY_IDX(0, 3))
|
||||
|
||||
struct mfd_mc146818_data {
|
||||
struct k_spinlock lock;
|
||||
};
|
||||
|
||||
uint8_t mfd_mc146818_std_read(const struct device *dev, uint8_t offset)
|
||||
{
|
||||
struct mfd_mc146818_data *data = dev->data;
|
||||
uint8_t value;
|
||||
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
sys_out8(offset, RTC_STD_INDEX);
|
||||
value = sys_in8(RTC_STD_TARGET);
|
||||
|
||||
k_spin_unlock(&data->lock, key);
|
||||
return value;
|
||||
}
|
||||
|
||||
void mfd_mc146818_std_write(const struct device *dev, uint8_t offset, uint8_t value)
|
||||
{
|
||||
struct mfd_mc146818_data *data = dev->data;
|
||||
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
sys_out8(offset, RTC_STD_INDEX);
|
||||
sys_out8(value, RTC_STD_TARGET);
|
||||
|
||||
k_spin_unlock(&data->lock, key);
|
||||
}
|
||||
|
||||
uint8_t mfd_mc146818_ext_read(const struct device *dev, uint8_t offset)
|
||||
{
|
||||
struct mfd_mc146818_data *data = dev->data;
|
||||
uint8_t value;
|
||||
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
sys_out8(offset, RTC_EXT_INDEX);
|
||||
value = sys_in8(RTC_EXT_TARGET);
|
||||
|
||||
k_spin_unlock(&data->lock, key);
|
||||
return value;
|
||||
}
|
||||
|
||||
void mfd_mc146818_ext_write(const struct device *dev, uint8_t offset, uint8_t value)
|
||||
{
|
||||
struct mfd_mc146818_data *data = dev->data;
|
||||
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
sys_out8(offset, RTC_EXT_INDEX);
|
||||
sys_out8(value, RTC_EXT_TARGET);
|
||||
|
||||
k_spin_unlock(&data->lock, key);
|
||||
}
|
||||
|
||||
#define MFD_MC146818_DEFINE(inst) \
|
||||
static struct mfd_mc146818_data data##inst; \
|
||||
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &data##inst, NULL, \
|
||||
POST_KERNEL, \
|
||||
CONFIG_MFD_MOTOROLA_MC146818_INIT_PRIORITY, \
|
||||
NULL); \
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(MFD_MC146818_DEFINE)
|
||||
34
dts/bindings/mfd/motorola,mc146818-mfd.yaml
Normal file
34
dts/bindings/mfd/motorola,mc146818-mfd.yaml
Normal file
@@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2025, Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: |
|
||||
Motorola MC146818 MFD
|
||||
|
||||
The following example displays the node layout
|
||||
with every possible partial driver included.
|
||||
|
||||
mfd: mfd@70 {
|
||||
compatible = "motorola,mc146818-mfd";
|
||||
reg = <0x70 0x01 0x71 0x01 0x72 0x01 0x73 0x01>;
|
||||
rtc: counter: rtc {
|
||||
compatible = "motorola,mc146818";
|
||||
interrupts = <8 IRQ_TYPE_LOWEST_EDGE_RISING 3>;
|
||||
interrupt-parent = <&intc>;
|
||||
alarms-count = <1>;
|
||||
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
bbram: bbram {
|
||||
compatible = "motorola,mc146818-bbram";
|
||||
size = <241>;
|
||||
status = "okay";
|
||||
};
|
||||
};
|
||||
|
||||
compatible: "motorola,mc146818-mfd"
|
||||
|
||||
include: base.yaml
|
||||
|
||||
bus: mc146818-mfd
|
||||
56
include/zephyr/drivers/mfd/mc146818.h
Normal file
56
include/zephyr/drivers/mfd/mc146818.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DRIVERS_MFD_MC146818_H_
|
||||
#define ZEPHYR_INCLUDE_DRIVERS_MFD_MC146818_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <zephyr/device.h>
|
||||
|
||||
/**
|
||||
* @brief Read the value at the given offset in standard memory bank.
|
||||
*
|
||||
* @param dev mc146818 mfd device
|
||||
* @param offset memory offset to be read.
|
||||
* @retval value at the offset
|
||||
*/
|
||||
uint8_t mfd_mc146818_std_read(const struct device *dev, uint8_t offset);
|
||||
|
||||
/**
|
||||
* @brief Write the value at the given offset in standard memory bank.
|
||||
*
|
||||
* @param dev mc146818 mfd device
|
||||
* @param offset memory offset to be written.
|
||||
* @param value to be written at the offset
|
||||
*/
|
||||
void mfd_mc146818_std_write(const struct device *dev, uint8_t offset, uint8_t value);
|
||||
|
||||
/**
|
||||
* @brief Read the value at the given offset in extended memory bank.
|
||||
*
|
||||
* @param dev mc146818 mfd device
|
||||
* @param offset memory offset to be read.
|
||||
* @retval value at the offset
|
||||
*/
|
||||
uint8_t mfd_mc146818_ext_read(const struct device *dev, uint8_t offset);
|
||||
|
||||
/**
|
||||
* @brief Write the value at the given offset in extended memory bank.
|
||||
*
|
||||
* @param dev mc146818 mfd device
|
||||
* @param offset memory offset to be written.
|
||||
* @param value to be written at the offset
|
||||
*/
|
||||
void mfd_mc146818_ext_write(const struct device *dev, uint8_t offset, uint8_t value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DRIVERS_MFD_MC146818_H_ */
|
||||
Reference in New Issue
Block a user