11/*
22 * Copyright (c) 2021, Piotr Mienkowski
3+ * Copyright (c) 2023, Gerson Fernando Budke
34 *
45 * SPDX-License-Identifier: Apache-2.0
56 */
3132#include <soc.h>
3233#include <zephyr/drivers/counter.h>
3334#include <zephyr/drivers/pinctrl.h>
35+ #include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
3436
3537#include <zephyr/logging/log.h>
3638#include <zephyr/irq.h>
@@ -51,11 +53,11 @@ struct counter_sam_dev_cfg {
5153 uint32_t reg_cmr ;
5254 uint32_t reg_rc ;
5355 void (* irq_config_func )(const struct device * dev );
56+ const struct atmel_sam_pmc_config clock_cfg [TCCHANNEL_NUMBER ];
5457 const struct pinctrl_dev_config * pcfg ;
5558 uint8_t clk_sel ;
5659 bool nodivclk ;
5760 uint8_t tc_chan_num ;
58- uint8_t periph_id [TCCHANNEL_NUMBER ];
5961};
6062
6163struct counter_sam_alarm_data {
@@ -322,7 +324,8 @@ static int counter_sam_initialize(const struct device *dev)
322324 }
323325
324326 /* Enable channel's clock */
325- soc_pmc_peripheral_enable (dev_cfg -> periph_id [dev_cfg -> tc_chan_num ]);
327+ (void )clock_control_on (SAM_DT_PMC_CONTROLLER ,
328+ (clock_control_subsys_t * )& dev_cfg -> clock_cfg [dev_cfg -> tc_chan_num ]);
326329
327330 /* Clock and Mode Selection */
328331 tc_ch -> TC_CMR = dev_cfg -> reg_cmr ;
@@ -384,7 +387,7 @@ static const struct counter_sam_dev_cfg counter_##n##_sam_config = { \
384387 .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
385388 .nodivclk = DT_INST_PROP(n, nodivclk), \
386389 .tc_chan_num = DT_INST_PROP_OR(n, channel, 0), \
387- .periph_id = DT_INST_PROP(n, peripheral_id ), \
390+ .clock_cfg = SAM_DT_INST_CLOCKS_PMC_CFG(n ), \
388391}; \
389392 \
390393static struct counter_sam_dev_data counter_##n##_sam_data; \
0 commit comments