Skip to content

Commit 1112f04

Browse files
committed
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>
1 parent 366d45f commit 1112f04

File tree

6 files changed

+198
-0
lines changed

6 files changed

+198
-0
lines changed

drivers/mfd/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ zephyr_library_sources_ifdef(CONFIG_MFD_DS3231 mfd_ds3231.c)
2525
zephyr_library_sources_ifdef(CONFIG_MFD_MAX22017 mfd_max22017.c)
2626
zephyr_library_sources_ifdef(CONFIG_MFD_MCHP_SAM_FLEXCOM mfd_mchp_sam_flexcom.c)
2727
zephyr_library_sources_ifdef(CONFIG_MFD_PF1550 mfd_pf1550.c)
28+
zephyr_library_sources_ifdef(CONFIG_MFD_MOTOROLA_MC146818 mfd_mc146818.c)

drivers/mfd/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ source "drivers/mfd/Kconfig.pf1550"
3737
source "drivers/mfd/Kconfig.lpflexcomm"
3838
source "drivers/mfd/Kconfig.tle9104"
3939
source "drivers/mfd/Kconfig.it8801"
40+
source "drivers/mfd/Kconfig.mc146818"
4041

4142
endif # MFD

drivers/mfd/Kconfig.mc146818

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Intel SoC RTC configuration options
2+
3+
# Copyright (c) 2025 Intel Corporation
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
config MFD_MOTOROLA_MC146818
7+
bool "MOTOROLA MC146818 multi-function device driver"
8+
default y
9+
depends on DT_HAS_MOTOROLA_MC146818_MFD_ENABLED
10+
help
11+
common code required by bbram and rtc, which will likely be a locking mechanism
12+
so both RTC and BBRAM can set/get regs safely and independently.
13+
14+
config MFD_MOTOROLA_MC146818_INIT_PRIORITY
15+
int "Init priority of mc146818 MFD"
16+
depends on MFD_MOTOROLA_MC146818
17+
default 50
18+
help
19+
Initialization priority for the MOTOROLA MC146818 MFD driver.
20+
It must be greater than RTC, COUNTER and BBRAM driver init priority.

drivers/mfd/mfd_mc146818.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2025 Intel Corporation.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define DT_DRV_COMPAT motorola_mc146818_mfd
8+
9+
#include <zephyr/kernel.h>
10+
#include <zephyr/device.h>
11+
#include <zephyr/spinlock.h>
12+
#include <zephyr/drivers/mfd/mc146818.h>
13+
#include <zephyr/init.h>
14+
#include <zephyr/sys/util.h>
15+
#include <zephyr/devicetree.h>
16+
#include <zephyr/sys/sys_io.h>
17+
18+
#define RTC_STD_INDEX (DT_INST_REG_ADDR_BY_IDX(0, 0))
19+
#define RTC_STD_TARGET (DT_INST_REG_ADDR_BY_IDX(0, 1))
20+
#define RTC_EXT_INDEX (DT_INST_REG_ADDR_BY_IDX(0, 2))
21+
#define RTC_EXT_TARGET (DT_INST_REG_ADDR_BY_IDX(0, 3))
22+
23+
struct mfd_mc146818_data {
24+
struct k_spinlock lock;
25+
};
26+
27+
uint8_t mfd_mc146818_std_read(const struct device *dev, uint8_t offset)
28+
{
29+
struct mfd_mc146818_data *data = dev->data;
30+
uint8_t value;
31+
32+
k_spinlock_key_t key = k_spin_lock(&data->lock);
33+
34+
sys_out8(offset, RTC_STD_INDEX);
35+
value = sys_in8(RTC_STD_TARGET);
36+
37+
k_spin_unlock(&data->lock, key);
38+
return value;
39+
}
40+
41+
void mfd_mc146818_std_write(const struct device *dev, uint8_t offset, uint8_t value)
42+
{
43+
struct mfd_mc146818_data *data = dev->data;
44+
45+
k_spinlock_key_t key = k_spin_lock(&data->lock);
46+
47+
sys_out8(offset, RTC_STD_INDEX);
48+
sys_out8(value, RTC_STD_TARGET);
49+
50+
k_spin_unlock(&data->lock, key);
51+
}
52+
53+
uint8_t mfd_mc146818_ext_read(const struct device *dev, uint8_t offset)
54+
{
55+
struct mfd_mc146818_data *data = dev->data;
56+
uint8_t value;
57+
58+
k_spinlock_key_t key = k_spin_lock(&data->lock);
59+
60+
sys_out8(offset, RTC_EXT_INDEX);
61+
value = sys_in8(RTC_EXT_TARGET);
62+
63+
k_spin_unlock(&data->lock, key);
64+
return value;
65+
}
66+
67+
void mfd_mc146818_ext_write(const struct device *dev, uint8_t offset, uint8_t value)
68+
{
69+
struct mfd_mc146818_data *data = dev->data;
70+
71+
k_spinlock_key_t key = k_spin_lock(&data->lock);
72+
73+
sys_out8(offset, RTC_EXT_INDEX);
74+
sys_out8(value, RTC_EXT_TARGET);
75+
76+
k_spin_unlock(&data->lock, key);
77+
}
78+
79+
#define MFD_MC146818_DEFINE(inst) \
80+
static struct mfd_mc146818_data data##inst; \
81+
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &data##inst, NULL, \
82+
POST_KERNEL, \
83+
CONFIG_MFD_MOTOROLA_MC146818_INIT_PRIORITY, \
84+
NULL); \
85+
86+
DT_INST_FOREACH_STATUS_OKAY(MFD_MC146818_DEFINE)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (c) 2025, Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
description: |
6+
Motorola MC146818 MFD
7+
8+
The following example displays the node layout
9+
with every possible partial driver included.
10+
11+
mfd: mfd@70 {
12+
compatible = "motorola,mc146818-mfd";
13+
reg = <0x70 0x01 0x71 0x01 0x72 0x01 0x73 0x01>;
14+
rtc: counter: rtc {
15+
compatible = "motorola,mc146818";
16+
interrupts = <8 IRQ_TYPE_LOWEST_EDGE_RISING 3>;
17+
interrupt-parent = <&intc>;
18+
alarms-count = <1>;
19+
20+
status = "okay";
21+
};
22+
23+
bbram: bbram {
24+
compatible = "motorola,mc146818-bbram";
25+
size = <241>;
26+
status = "okay";
27+
};
28+
};
29+
30+
compatible: "motorola,mc146818-mfd"
31+
32+
include: base.yaml
33+
34+
bus: mc146818-mfd

include/zephyr/drivers/mfd/mc146818.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2025 Intel Corporation.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_DRIVERS_MFD_MC146818_H_
8+
#define ZEPHYR_INCLUDE_DRIVERS_MFD_MC146818_H_
9+
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
#include <zephyr/device.h>
15+
16+
/**
17+
* @brief Read the value at the given offset in standard memory bank.
18+
*
19+
* @param dev mc146818 mfd device
20+
* @param offset memory offset to be read.
21+
* @retval value at the offset
22+
*/
23+
uint8_t mfd_mc146818_std_read(const struct device *dev, uint8_t offset);
24+
25+
/**
26+
* @brief Write the value at the given offset in standard memory bank.
27+
*
28+
* @param dev mc146818 mfd device
29+
* @param offset memory offset to be written.
30+
* @param value to be written at the offset
31+
*/
32+
void mfd_mc146818_std_write(const struct device *dev, uint8_t offset, uint8_t value);
33+
34+
/**
35+
* @brief Read the value at the given offset in extended memory bank.
36+
*
37+
* @param dev mc146818 mfd device
38+
* @param offset memory offset to be read.
39+
* @retval value at the offset
40+
*/
41+
uint8_t mfd_mc146818_ext_read(const struct device *dev, uint8_t offset);
42+
43+
/**
44+
* @brief Write the value at the given offset in extended memory bank.
45+
*
46+
* @param dev mc146818 mfd device
47+
* @param offset memory offset to be written.
48+
* @param value to be written at the offset
49+
*/
50+
void mfd_mc146818_ext_write(const struct device *dev, uint8_t offset, uint8_t value);
51+
52+
#ifdef __cplusplus
53+
}
54+
#endif
55+
56+
#endif /* ZEPHYR_INCLUDE_DRIVERS_MFD_MC146818_H_ */

0 commit comments

Comments
 (0)