11/*
22 * Copyright (c) 2017 Google LLC.
33 * Copyright (c) 2018 qianfan Zhao.
4+ * Copyright (c) 2023 Gerson Fernando Budke.
45 *
56 * SPDX-License-Identifier: Apache-2.0
67 */
@@ -17,6 +18,7 @@ LOG_MODULE_REGISTER(spi_sam);
1718#include <zephyr/drivers/spi.h>
1819#include <zephyr/drivers/dma.h>
1920#include <zephyr/drivers/pinctrl.h>
21+ #include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
2022#include <soc.h>
2123
2224#define SAM_SPI_CHIP_SELECT_COUNT 4
@@ -27,7 +29,7 @@ LOG_MODULE_REGISTER(spi_sam);
2729/* Device constant configuration parameters */
2830struct spi_sam_config {
2931 Spi * regs ;
30- uint32_t periph_id ;
32+ const struct atmel_sam_pmc_config clock_cfg ;
3133 const struct pinctrl_dev_config * pcfg ;
3234 bool loopback ;
3335
@@ -680,7 +682,9 @@ static int spi_sam_init(const struct device *dev)
680682 const struct spi_sam_config * cfg = dev -> config ;
681683 struct spi_sam_data * data = dev -> data ;
682684
683- soc_pmc_peripheral_enable (cfg -> periph_id );
685+ /* Enable SPI clock in PMC */
686+ (void )clock_control_on (SAM_DT_PMC_CONTROLLER ,
687+ (clock_control_subsys_t * )& cfg -> clock_cfg );
684688
685689 err = pinctrl_apply_state (cfg -> pcfg , PINCTRL_STATE_DEFAULT );
686690 if (err < 0 ) {
@@ -729,7 +733,7 @@ static const struct spi_driver_api spi_sam_driver_api = {
729733#define SPI_SAM_DEFINE_CONFIG (n ) \
730734 static const struct spi_sam_config spi_sam_config_##n = { \
731735 .regs = (Spi *)DT_INST_REG_ADDR(n), \
732- .periph_id = DT_INST_PROP(n, peripheral_id ), \
736+ .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n ), \
733737 .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
734738 .loopback = DT_INST_PROP(n, loopback), \
735739 COND_CODE_1(SPI_SAM_USE_DMA(n), (SPI_DMA_INIT(n)), ()) \
0 commit comments