-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers: rtc: maxim,ds3231: RTC driver
This is a squash of all the groundwork needed to get a functioning driver for the DS3231 with the RTC API. (cherry picked from commit 2759ada) Original-Signed-off-by: Gergo Vari <work@gergovari.com> GitOrigin-RevId: 2759ada Cr-Build-Id: 8726362737952124785 Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8726362737952124785 Copybot-Job-Name: zephyr-main-copybot-downstream Change-Id: Idf14862d682179c0c1c50e3a8761c5e62cd97956 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/6154244 Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com> Bot-Commit: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com> Commit-Queue: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
- Loading branch information
Gergo Vari
authored and
Chromeos LUCI
committed
Jan 8, 2025
1 parent
3a31f7c
commit f254c77
Showing
20 changed files
with
1,520 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright (c) 2024 Gergo Vari <work@gergovari.com> | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config MFD_DS3231 | ||
bool "DS3231 multi-function device driver" | ||
default y | ||
depends on DT_HAS_MAXIM_DS3231_MFD_ENABLED | ||
select I2C | ||
help | ||
Enable the Maxim DS3231 multi-function device driver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2024 Gergo Vari <work@gergovari.com> | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/drivers/mfd/ds3231.h> | ||
|
||
#include <zephyr/kernel.h> | ||
#include <zephyr/drivers/i2c.h> | ||
|
||
#include <zephyr/sys/util.h> | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(mfd_ds3231, CONFIG_MFD_LOG_LEVEL); | ||
|
||
#define DT_DRV_COMPAT maxim_ds3231_mfd | ||
|
||
struct mfd_ds3231_data { | ||
struct k_sem lock; | ||
const struct device *dev; | ||
}; | ||
|
||
struct mfd_ds3231_conf { | ||
struct i2c_dt_spec i2c_bus; | ||
}; | ||
|
||
int mfd_ds3231_i2c_get_registers(const struct device *dev, uint8_t start_reg, uint8_t *buf, | ||
const size_t buf_size) | ||
{ | ||
struct mfd_ds3231_data *data = dev->data; | ||
const struct mfd_ds3231_conf *config = dev->config; | ||
|
||
/* FIXME: bad start_reg/buf_size values break i2c for that run */ | ||
|
||
(void)k_sem_take(&data->lock, K_FOREVER); | ||
int err = i2c_burst_read_dt(&config->i2c_bus, start_reg, buf, buf_size); | ||
|
||
k_sem_give(&data->lock); | ||
|
||
return err; | ||
} | ||
|
||
int mfd_ds3231_i2c_set_registers(const struct device *dev, uint8_t start_reg, const uint8_t *buf, | ||
const size_t buf_size) | ||
{ | ||
struct mfd_ds3231_data *data = dev->data; | ||
const struct mfd_ds3231_conf *config = dev->config; | ||
|
||
(void)k_sem_take(&data->lock, K_FOREVER); | ||
int err = i2c_burst_write_dt(&config->i2c_bus, start_reg, buf, buf_size); | ||
|
||
k_sem_give(&data->lock); | ||
|
||
return err; | ||
} | ||
|
||
static int mfd_ds3231_init(const struct device *dev) | ||
{ | ||
struct mfd_ds3231_data *data = dev->data; | ||
const struct mfd_ds3231_conf *config = (struct mfd_ds3231_conf *)(dev->config); | ||
|
||
k_sem_init(&data->lock, 1, 1); | ||
if (!i2c_is_ready_dt(&(config->i2c_bus))) { | ||
LOG_ERR("I2C bus not ready."); | ||
return -ENODEV; | ||
} | ||
return 0; | ||
} | ||
|
||
#define MFD_DS3231_DEFINE(inst) \ | ||
static const struct mfd_ds3231_conf config##inst = {.i2c_bus = \ | ||
I2C_DT_SPEC_INST_GET(inst)}; \ | ||
static struct mfd_ds3231_data data##inst; \ | ||
DEVICE_DT_INST_DEFINE(inst, &mfd_ds3231_init, NULL, &data##inst, &config##inst, \ | ||
POST_KERNEL, CONFIG_MFD_INIT_PRIORITY, NULL); | ||
|
||
DT_INST_FOREACH_STATUS_OKAY(MFD_DS3231_DEFINE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2024, Gergo Vari <work@gergovari.com> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
config RTC_DS3231 | ||
bool "Maxim DS3231 RTC/TCXO" | ||
default y | ||
depends on DT_HAS_MAXIM_DS3231_MFD_ENABLED | ||
depends on DT_HAS_MAXIM_DS3231_RTC_ENABLED | ||
select I2C | ||
select MFD | ||
help | ||
Enable RTC driver based on Maxim DS3231 I2C device. | ||
|
||
config RTC_DS3231_INIT_PRIORITY | ||
int "DS3231 RTC driver initialization priority" | ||
depends on RTC_DS3231 | ||
default 86 | ||
help | ||
Initialization priority for the DS3231 RTC driver. It must be | ||
greater than the I2C controller init priority and the mfd driver | ||
init priority. |
Oops, something went wrong.