Skip to content

Commit c4f1d98

Browse files
nandojvembolivar-nordic
authored andcommitted
drivers: i2c: sam: Update to use clock control
This update Atmel SAM twi, twihs and twim drivers to use clock control driver. Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent 6d4c0da commit c4f1d98

File tree

11 files changed

+38
-36
lines changed

11 files changed

+38
-36
lines changed

drivers/i2c/i2c_sam4l_twim.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2017 Piotr Mienkowski
3-
* Copyright (c) 2020 Gerson Fernando Budke <[email protected]>
3+
* Copyright (c) 2020-2023 Gerson Fernando Budke <[email protected]>
44
*
55
* SPDX-License-Identifier: Apache-2.0
66
*/
@@ -23,6 +23,7 @@
2323
#include <soc.h>
2424
#include <zephyr/drivers/i2c.h>
2525
#include <zephyr/drivers/pinctrl.h>
26+
#include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
2627

2728
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
2829
#include <zephyr/logging/log.h>
@@ -66,8 +67,8 @@ struct i2c_sam_twim_dev_cfg {
6667
Twim *regs;
6768
void (*irq_config)(void);
6869
uint32_t bitrate;
70+
const struct atmel_sam_pmc_config clock_cfg;
6971
const struct pinctrl_dev_config *pcfg;
70-
uint8_t periph_id;
7172
uint8_t irq_id;
7273

7374
uint8_t std_clk_slew_lim;
@@ -558,8 +559,9 @@ static int i2c_sam_twim_initialize(const struct device *dev)
558559
return ret;
559560
}
560561

561-
/* Enable module's clock */
562-
soc_pmc_peripheral_enable(cfg->periph_id);
562+
/* Enable TWIM clock in PM */
563+
(void)clock_control_on(SAM_DT_PMC_CONTROLLER,
564+
(clock_control_subsys_t *)&cfg->clock_cfg);
563565

564566
/* Enable the module*/
565567
twim->CR = TWIM_CR_MEN;
@@ -614,7 +616,7 @@ static const struct i2c_driver_api i2c_sam_twim_driver_api = {
614616
static const struct i2c_sam_twim_dev_cfg i2c##n##_sam_config = {\
615617
.regs = (Twim *)DT_INST_REG_ADDR(n), \
616618
.irq_config = i2c##n##_sam_irq_config, \
617-
.periph_id = DT_INST_PROP(n, peripheral_id), \
619+
.clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \
618620
.irq_id = DT_INST_IRQN(n), \
619621
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
620622
.bitrate = DT_INST_PROP(n, clock_frequency), \

drivers/i2c/i2c_sam_twi.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2017 Piotr Mienkowski
3+
* Copyright (c) 2023 Gerson Fernando Budke
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -23,6 +24,7 @@
2324
#include <soc.h>
2425
#include <zephyr/drivers/i2c.h>
2526
#include <zephyr/drivers/pinctrl.h>
27+
#include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
2628

2729
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
2830
#include <zephyr/logging/log.h>
@@ -43,8 +45,8 @@ struct i2c_sam_twi_dev_cfg {
4345
Twi *regs;
4446
void (*irq_config)(void);
4547
uint32_t bitrate;
48+
const struct atmel_sam_pmc_config clock_cfg;
4649
const struct pinctrl_dev_config *pcfg;
47-
uint8_t periph_id;
4850
uint8_t irq_id;
4951
};
5052

@@ -325,8 +327,9 @@ static int i2c_sam_twi_initialize(const struct device *dev)
325327
return ret;
326328
}
327329

328-
/* Enable module's clock */
329-
soc_pmc_peripheral_enable(dev_cfg->periph_id);
330+
/* Enable TWI clock in PMC */
331+
(void)clock_control_on(SAM_DT_PMC_CONTROLLER,
332+
(clock_control_subsys_t *)&dev_cfg->clock_cfg);
330333

331334
/* Reset TWI module */
332335
twi->TWI_CR = TWI_CR_SWRST;
@@ -364,7 +367,7 @@ static const struct i2c_driver_api i2c_sam_twi_driver_api = {
364367
static const struct i2c_sam_twi_dev_cfg i2c##n##_sam_config = { \
365368
.regs = (Twi *)DT_INST_REG_ADDR(n), \
366369
.irq_config = i2c##n##_sam_irq_config, \
367-
.periph_id = DT_INST_PROP(n, peripheral_id), \
370+
.clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \
368371
.irq_id = DT_INST_IRQN(n), \
369372
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
370373
.bitrate = DT_INST_PROP(n, clock_frequency), \

drivers/i2c/i2c_sam_twihs.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2017 Piotr Mienkowski
3+
* Copyright (c) 2023 Gerson Fernando Budke
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -21,6 +22,7 @@
2122
#include <soc.h>
2223
#include <zephyr/drivers/i2c.h>
2324
#include <zephyr/drivers/pinctrl.h>
25+
#include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
2426

2527
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
2628
#include <zephyr/logging/log.h>
@@ -43,8 +45,8 @@ struct i2c_sam_twihs_dev_cfg {
4345
Twihs *regs;
4446
void (*irq_config)(void);
4547
uint32_t bitrate;
48+
const struct atmel_sam_pmc_config clock_cfg;
4649
const struct pinctrl_dev_config *pcfg;
47-
uint8_t periph_id;
4850
uint8_t irq_id;
4951
};
5052

@@ -296,8 +298,9 @@ static int i2c_sam_twihs_initialize(const struct device *dev)
296298
return ret;
297299
}
298300

299-
/* Enable module's clock */
300-
soc_pmc_peripheral_enable(dev_cfg->periph_id);
301+
/* Enable TWIHS clock in PMC */
302+
(void)clock_control_on(SAM_DT_PMC_CONTROLLER,
303+
(clock_control_subsys_t *)&dev_cfg->clock_cfg);
301304

302305
/* Reset the module */
303306
twihs->TWIHS_CR = TWIHS_CR_SWRST;
@@ -335,7 +338,7 @@ static const struct i2c_driver_api i2c_sam_twihs_driver_api = {
335338
static const struct i2c_sam_twihs_dev_cfg i2c##n##_sam_config = {\
336339
.regs = (Twihs *)DT_INST_REG_ADDR(n), \
337340
.irq_config = i2c##n##_sam_irq_config, \
338-
.periph_id = DT_INST_PROP(n, peripheral_id), \
341+
.clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \
339342
.irq_id = DT_INST_IRQN(n), \
340343
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
341344
.bitrate = DT_INST_PROP(n, clock_frequency), \

dts/arm/atmel/sam3x.dtsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
clock-frequency = <I2C_BITRATE_STANDARD>;
8080
reg = <0x4008c000 0x128>;
8181
interrupts = <22 0>;
82-
peripheral-id = <22>;
82+
clocks = <&pmc PMC_TYPE_PERIPHERAL 22>;
8383
status = "disabled";
8484
#address-cells = <1>;
8585
#size-cells = <0>;
@@ -90,7 +90,7 @@
9090
clock-frequency = <I2C_BITRATE_STANDARD>;
9191
reg = <0x40090000 0x128>;
9292
interrupts = <23 0>;
93-
peripheral-id = <23>;
93+
clocks = <&pmc PMC_TYPE_PERIPHERAL 23>;
9494
status = "disabled";
9595
#address-cells = <1>;
9696
#size-cells = <0>;

dts/arm/atmel/sam4e.dtsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
clock-frequency = <I2C_BITRATE_STANDARD>;
8080
reg = <0x400a8000 0x4000>;
8181
interrupts = <17 0>;
82-
peripheral-id = <17>;
82+
clocks = <&pmc PMC_TYPE_PERIPHERAL 17>;
8383
status = "disabled";
8484
#address-cells = <1>;
8585
#size-cells = <0>;
@@ -90,7 +90,7 @@
9090
clock-frequency = <I2C_BITRATE_STANDARD>;
9191
reg = <0x400ac000 0x4000>;
9292
interrupts = <18 0>;
93-
peripheral-id = <18>;
93+
clocks = <&pmc PMC_TYPE_PERIPHERAL 18>;
9494
status = "disabled";
9595
#address-cells = <1>;
9696
#size-cells = <0>;

dts/arm/atmel/sam4l.dtsi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
clock-frequency = <I2C_BITRATE_STANDARD>;
8585
reg = <0x40018000 0x4000>;
8686
interrupts = <61 0>;
87-
peripheral-id = <4>;
87+
clocks = <&pmc PMC_TYPE_PERIPHERAL 4>;
8888
status = "disabled";
8989
#address-cells = <1>;
9090
#size-cells = <0>;
@@ -94,7 +94,7 @@
9494
clock-frequency = <I2C_BITRATE_STANDARD>;
9595
reg = <0x4001c000 0x4000>;
9696
interrupts = <63 0>;
97-
peripheral-id = <6>;
97+
clocks = <&pmc PMC_TYPE_PERIPHERAL 6>;
9898
status = "disabled";
9999
#address-cells = <1>;
100100
#size-cells = <0>;
@@ -104,7 +104,7 @@
104104
clock-frequency = <I2C_BITRATE_STANDARD>;
105105
reg = <0x40078000 0x4000>;
106106
interrupts = <77 0>;
107-
peripheral-id = <21>;
107+
clocks = <&pmc PMC_TYPE_PERIPHERAL 21>;
108108
status = "disabled";
109109
#address-cells = <1>;
110110
#size-cells = <0>;
@@ -114,7 +114,7 @@
114114
clock-frequency = <I2C_BITRATE_STANDARD>;
115115
reg = <0x4007c000 0x4000>;
116116
interrupts = <78 0>;
117-
peripheral-id = <22>;
117+
clocks = <&pmc PMC_TYPE_PERIPHERAL 22>;
118118
status = "disabled";
119119
#address-cells = <1>;
120120
#size-cells = <0>;

dts/arm/atmel/sam4s.dtsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
clock-frequency = <I2C_BITRATE_STANDARD>;
8282
reg = <0x40018000 0x128>;
8383
interrupts = <19 0>;
84-
peripheral-id = <19>;
84+
clocks = <&pmc PMC_TYPE_PERIPHERAL 19>;
8585
status = "disabled";
8686
#address-cells = <1>;
8787
#size-cells = <0>;
@@ -92,7 +92,7 @@
9292
clock-frequency = <I2C_BITRATE_STANDARD>;
9393
reg = <0x4001c000 0x128>;
9494
interrupts = <20 0>;
95-
peripheral-id = <20>;
95+
clocks = <&pmc PMC_TYPE_PERIPHERAL 20>;
9696
status = "disabled";
9797
#address-cells = <1>;
9898
#size-cells = <0>;

dts/arm/atmel/same70.dtsi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
#size-cells = <0>;
9090
reg = <0x40018000 0x12B>;
9191
interrupts = <19 0>;
92-
peripheral-id = <19>;
92+
clocks = <&pmc PMC_TYPE_PERIPHERAL 19>;
9393
status = "disabled";
9494
};
9595

@@ -100,7 +100,7 @@
100100
#size-cells = <0>;
101101
reg = <0x4001c000 0x12B>;
102102
interrupts = <20 0>;
103-
peripheral-id = <20>;
103+
clocks = <&pmc PMC_TYPE_PERIPHERAL 20>;
104104
status = "disabled";
105105
};
106106

@@ -111,7 +111,7 @@
111111
#size-cells = <0>;
112112
reg = <0x40060000 0x12B>;
113113
interrupts = <41 0>;
114-
peripheral-id = <41>;
114+
clocks = <&pmc PMC_TYPE_PERIPHERAL 41>;
115115
status = "disabled";
116116
};
117117

dts/bindings/i2c/atmel,sam-i2c-twi.yaml

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

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

dts/bindings/i2c/atmel,sam-i2c-twihs.yaml

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

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

0 commit comments

Comments
 (0)