Commit fbec4149 authored by Anisetti Avinash Krishna's avatar Anisetti Avinash Krishna Committed by Henrik Brix Andersen
Browse files

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: default avatarAnisetti Avinash Krishna <anisetti.avinash.krishna@intel.com>
parent 4c8419b9
Loading
Loading
Loading
Loading
+1 −0
Changes for drivers/mfd/CMakeLists.txt: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -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)
+1 −0
Changes for drivers/mfd/Kconfig: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -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 −0
Changes for drivers/mfd/Kconfig.mc146818: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
# 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 −0
Changes for drivers/mfd/mfd_mc146818.c: 86 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
 * 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 −0
Changes for dts/bindings/mfd/motorola,mc146818-mfd.yaml: 34 added lines, 0 removed lines.
Original line number Diff line number Diff line
# 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
Loading