Skip to content

Commit

Permalink
fby35: ji: Dynamic set spi frequency (#2040)
Browse files Browse the repository at this point in the history
Summary:
- Support dynamic set spi frequency function in driver. Note that re-init(**spi_nor_re_init**) action is needed after frequency-set(**spi_nor_set_freq**).
- Set spi1-cs0 default frequency from 50M to 5M.
- Modify spi1-cs0 from 5M to 50M in runtime only if using PVT2 system.

TestPlan:
- BuildCode: PASS
- Measure PVT1 and PVT2 BIOS update frequency: PASS

Pull Request resolved: #2040

Reviewed By: jagpalgill

Differential Revision: D64942542

fbshipit-source-id: f19931ef50ca7f71784bed53083491042702e9c7
  • Loading branch information
MouchenHung-QUANTA authored and facebook-github-bot committed Oct 29, 2024
1 parent 58c436e commit dda7c9e
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
From 4187e66745fd164a85a9b5b1f2a64a639f5ae2ef Mon Sep 17 00:00:00 2001
From: MouchenHung <[email protected]>
Date: Fri, 25 Oct 2024 10:36:47 +0800
Subject: [PATCH] spi: Support dynamic set spi frequency

---
drivers/flash/spi_nor_multi_dev.c | 8 ++++++++
include/drivers/spi_nor.h | 1 +
2 files changed, 9 insertions(+)

diff --git a/drivers/flash/spi_nor_multi_dev.c b/drivers/flash/spi_nor_multi_dev.c
index 6595161c07..5dae866362 100644
--- a/drivers/flash/spi_nor_multi_dev.c
+++ b/drivers/flash/spi_nor_multi_dev.c
@@ -1713,6 +1713,14 @@ int spi_nor_re_init(const struct device *dev)
return spi_nor_configure(dev);
}

+int spi_nor_set_freq(const struct device *dev, uint32_t freq)
+{
+ struct spi_nor_data *data = dev->data;
+ data->spi_cfg.frequency = freq;
+
+ return 0;
+}
+
/**
* @brief Initialize and configure the flash
*
diff --git a/include/drivers/spi_nor.h b/include/drivers/spi_nor.h
index 42e13a9cff..aea16b6f96 100644
--- a/include/drivers/spi_nor.h
+++ b/include/drivers/spi_nor.h
@@ -141,6 +141,7 @@ struct spi_nor_op_info {

int spi_nor_config_4byte_mode(const struct device *dev, bool en4b);
int spi_nor_re_init(const struct device *dev);
+int spi_nor_set_freq(const struct device *dev, uint32_t freq);
int spi_nor_erase_by_cmd(const struct device *dev, off_t addr,
size_t size, uint8_t cmd);
int spi_nor_get_erase_sz(const struct device *dev, uint8_t cmd);
--
2.17.1

2 changes: 1 addition & 1 deletion meta-facebook/yv35-ji/boards/ast1030_evb.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
&spi1_cs0 {
status = "okay";
spi-max-buswidth = <4>;
spi-max-frequency = <50000000>;
spi-max-frequency = <5000000>;
re-init-support;
};

Expand Down
18 changes: 18 additions & 0 deletions meta-facebook/yv35-ji/src/lib/plat_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "hal_i2c.h"
#include "plat_gpio.h"
#include "plat_i2c.h"
#include "plat_class.h"
#include "util_spi.h"
#include <logging/log.h>

Expand Down Expand Up @@ -49,3 +50,20 @@ bool pal_switch_bios_spi_mux(int gpio_status)

return true;
}

#define BIOS_SPI_DRIVER "spi1_cs0"
#define SPI_FREQ_50M 50000000
void switch_spi_freq()
{
const struct device *flash_dev;
flash_dev = device_get_binding(BIOS_SPI_DRIVER);
if (!flash_dev) {
LOG_ERR("Can't find any binding device with label %s", BIOS_SPI_DRIVER);
}
if (get_board_revision() != SYS_BOARD_PVT2) {
spi_nor_set_freq(flash_dev, SPI_FREQ_50M);
LOG_INF("Try to set SPI frequency to 50MHz");
} else {
LOG_INF("Use default SPI frequency 5MHz");
}
}
22 changes: 22 additions & 0 deletions meta-facebook/yv35-ji/src/lib/plat_spi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* 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.
*/

#ifndef PLAT_SPI_H
#define PLAT_SPI_H

void switch_spi_freq();

#endif
2 changes: 2 additions & 0 deletions meta-facebook/yv35-ji/src/platform/plat_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ enum BIC_BOARD_REVISION {
SYS_BOARD_DVT,
SYS_BOARD_PVT,
SYS_BOARD_PVT2,
SYS_BOARD_PVT2_5,
SYS_BOARD_MP,
};

typedef struct _CARD_STATUS_ {
Expand Down
3 changes: 3 additions & 0 deletions meta-facebook/yv35-ji/src/platform/plat_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "plat_sensor_table.h"
#include "plat_power_status.h"
#include "plat_fru.h"
#include "plat_spi.h"
#include "util_worker.h"
#include "power_status.h"
#include <stdio.h>
Expand Down Expand Up @@ -74,6 +75,8 @@ void pal_post_init()
LOG_INF("Try to access SatMC...");
satmc_status_update();
}

switch_spi_freq();
}

void pal_device_init()
Expand Down

0 comments on commit dda7c9e

Please sign in to comment.