1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) STMicroelectronics 2016
4 * Author: Benjamin Gaignard <benjamin.gaignard@st.com>
7 #include <linux/mfd/stm32-timers.h>
8 #include <linux/module.h>
9 #include <linux/of_platform.h>
10 #include <linux/reset.h>
12 static const struct regmap_config stm32_timers_regmap_cfg
= {
15 .reg_stride
= sizeof(u32
),
16 .max_register
= 0x3fc,
19 static void stm32_timers_get_arr_size(struct stm32_timers
*ddata
)
22 * Only the available bits will be written so when readback
23 * we get the maximum value of auto reload register
25 regmap_write(ddata
->regmap
, TIM_ARR
, ~0L);
26 regmap_read(ddata
->regmap
, TIM_ARR
, &ddata
->max_arr
);
27 regmap_write(ddata
->regmap
, TIM_ARR
, 0x0);
30 static int stm32_timers_probe(struct platform_device
*pdev
)
32 struct device
*dev
= &pdev
->dev
;
33 struct stm32_timers
*ddata
;
37 ddata
= devm_kzalloc(dev
, sizeof(*ddata
), GFP_KERNEL
);
41 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
42 mmio
= devm_ioremap_resource(dev
, res
);
46 ddata
->regmap
= devm_regmap_init_mmio_clk(dev
, "int", mmio
,
47 &stm32_timers_regmap_cfg
);
48 if (IS_ERR(ddata
->regmap
))
49 return PTR_ERR(ddata
->regmap
);
51 ddata
->clk
= devm_clk_get(dev
, NULL
);
52 if (IS_ERR(ddata
->clk
))
53 return PTR_ERR(ddata
->clk
);
55 stm32_timers_get_arr_size(ddata
);
57 platform_set_drvdata(pdev
, ddata
);
59 return devm_of_platform_populate(&pdev
->dev
);
62 static const struct of_device_id stm32_timers_of_match
[] = {
63 { .compatible
= "st,stm32-timers", },
66 MODULE_DEVICE_TABLE(of
, stm32_timers_of_match
);
68 static struct platform_driver stm32_timers_driver
= {
69 .probe
= stm32_timers_probe
,
71 .name
= "stm32-timers",
72 .of_match_table
= stm32_timers_of_match
,
75 module_platform_driver(stm32_timers_driver
);
77 MODULE_DESCRIPTION("STMicroelectronics STM32 Timers");
78 MODULE_LICENSE("GPL v2");