Linux 4.14.13
[linux-stable.git] / drivers / mfd / stm32-timers.c
bloba6675a44940958cc47533c866a27681dc6a9bdcd
1 /*
2 * Copyright (C) STMicroelectronics 2016
4 * Author: Benjamin Gaignard <benjamin.gaignard@st.com>
6 * License terms: GNU General Public License (GPL), version 2
7 */
9 #include <linux/mfd/stm32-timers.h>
10 #include <linux/module.h>
11 #include <linux/of_platform.h>
12 #include <linux/reset.h>
14 static const struct regmap_config stm32_timers_regmap_cfg = {
15 .reg_bits = 32,
16 .val_bits = 32,
17 .reg_stride = sizeof(u32),
18 .max_register = 0x3fc,
21 static void stm32_timers_get_arr_size(struct stm32_timers *ddata)
24 * Only the available bits will be written so when readback
25 * we get the maximum value of auto reload register
27 regmap_write(ddata->regmap, TIM_ARR, ~0L);
28 regmap_read(ddata->regmap, TIM_ARR, &ddata->max_arr);
29 regmap_write(ddata->regmap, TIM_ARR, 0x0);
32 static int stm32_timers_probe(struct platform_device *pdev)
34 struct device *dev = &pdev->dev;
35 struct stm32_timers *ddata;
36 struct resource *res;
37 void __iomem *mmio;
39 ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
40 if (!ddata)
41 return -ENOMEM;
43 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
44 mmio = devm_ioremap_resource(dev, res);
45 if (IS_ERR(mmio))
46 return PTR_ERR(mmio);
48 ddata->regmap = devm_regmap_init_mmio_clk(dev, "int", mmio,
49 &stm32_timers_regmap_cfg);
50 if (IS_ERR(ddata->regmap))
51 return PTR_ERR(ddata->regmap);
53 ddata->clk = devm_clk_get(dev, NULL);
54 if (IS_ERR(ddata->clk))
55 return PTR_ERR(ddata->clk);
57 stm32_timers_get_arr_size(ddata);
59 platform_set_drvdata(pdev, ddata);
61 return devm_of_platform_populate(&pdev->dev);
64 static const struct of_device_id stm32_timers_of_match[] = {
65 { .compatible = "st,stm32-timers", },
66 { /* end node */ },
68 MODULE_DEVICE_TABLE(of, stm32_timers_of_match);
70 static struct platform_driver stm32_timers_driver = {
71 .probe = stm32_timers_probe,
72 .driver = {
73 .name = "stm32-timers",
74 .of_match_table = stm32_timers_of_match,
77 module_platform_driver(stm32_timers_driver);
79 MODULE_DESCRIPTION("STMicroelectronics STM32 Timers");
80 MODULE_LICENSE("GPL v2");