Skip to content

Commit 4f59d50

Browse files
nandojvembolivar-nordic
authored andcommitted
drivers: spi: sam: Update to use clock control
This update Atmel SAM spi driver to use clock control driver. Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent 91e219c commit 4f59d50

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

drivers/spi/spi_sam.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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 */
2830
struct 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)), ()) \

dts/arm/atmel/sam4e.dtsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
#size-cells = <0>;
103103
reg = <0x40088000 0x4000>;
104104
interrupts = <19 0>;
105-
peripheral-id = <19>;
105+
clocks = <&pmc PMC_TYPE_PERIPHERAL 19>;
106106
status = "disabled";
107107
};
108108

dts/arm/atmel/sam4l.dtsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
compatible = "atmel,sam-spi";
125125
reg = <0x40008000 0x4000>;
126126
interrupts = <54 0>;
127-
peripheral-id = <1>;
127+
clocks = <&pmc PMC_TYPE_PERIPHERAL 1>;
128128
status = "disabled";
129129
#address-cells = <1>;
130130
#size-cells = <0>;

dts/arm/atmel/sam4s.dtsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
#size-cells = <0>;
105105
reg = <0x40008000 0x4000>;
106106
interrupts = <21 0>;
107-
peripheral-id = <21>;
107+
clocks = <&pmc PMC_TYPE_PERIPHERAL 21>;
108108
status = "disabled";
109109
};
110110

dts/arm/atmel/same70.dtsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
#size-cells = <0>;
122122
reg = <0x40008000 0x4000>;
123123
interrupts = <21 0>;
124-
peripheral-id = <21>;
124+
clocks = <&pmc PMC_TYPE_PERIPHERAL 21>;
125125
status = "disabled";
126126
};
127127

@@ -131,7 +131,7 @@
131131
#size-cells = <0>;
132132
reg = <0x40058000 0x4000>;
133133
interrupts = <42 0>;
134-
peripheral-id = <42>;
134+
clocks = <&pmc PMC_TYPE_PERIPHERAL 42>;
135135
status = "disabled";
136136
};
137137

dts/bindings/spi/atmel,sam-spi.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ properties:
1616
interrupts:
1717
required: true
1818

19-
peripheral-id:
20-
type: int
21-
description: peripheral ID
19+
clocks:
2220
required: true
2321

2422
loopback:

0 commit comments

Comments
 (0)