10376148fSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2d58603ccSBoris BREZILLON /*
3d58603ccSBoris BREZILLON * Copyright (C) 2014 Free Electrons
4d58603ccSBoris BREZILLON *
5d58603ccSBoris BREZILLON * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
6d58603ccSBoris BREZILLON *
7d58603ccSBoris BREZILLON * Allwinner PRCM (Power/Reset/Clock Management) driver
8d58603ccSBoris BREZILLON */
9d58603ccSBoris BREZILLON
10d58603ccSBoris BREZILLON #include <linux/mfd/core.h>
11391cd33aSPaul Gortmaker #include <linux/init.h>
12d58603ccSBoris BREZILLON #include <linux/of.h>
13d58603ccSBoris BREZILLON
14ea1628e8SChen-Yu Tsai #define SUN8I_CODEC_ANALOG_BASE 0x1c0
15ea1628e8SChen-Yu Tsai #define SUN8I_CODEC_ANALOG_SIZE 0x4
16ea1628e8SChen-Yu Tsai
17d58603ccSBoris BREZILLON struct prcm_data {
18d58603ccSBoris BREZILLON int nsubdevs;
19d58603ccSBoris BREZILLON const struct mfd_cell *subdevs;
20d58603ccSBoris BREZILLON };
21d58603ccSBoris BREZILLON
22d58603ccSBoris BREZILLON static const struct resource sun6i_a31_ar100_clk_res[] = {
23*223d2158SZhen Lei DEFINE_RES_MEM(0x0, 4)
24d58603ccSBoris BREZILLON };
25d58603ccSBoris BREZILLON
26d58603ccSBoris BREZILLON static const struct resource sun6i_a31_apb0_clk_res[] = {
27*223d2158SZhen Lei DEFINE_RES_MEM(0xc, 4)
28d58603ccSBoris BREZILLON };
29d58603ccSBoris BREZILLON
30d58603ccSBoris BREZILLON static const struct resource sun6i_a31_apb0_gates_clk_res[] = {
31*223d2158SZhen Lei DEFINE_RES_MEM(0x28, 4)
32d58603ccSBoris BREZILLON };
33d58603ccSBoris BREZILLON
346f262ecfSHans de Goede static const struct resource sun6i_a31_ir_clk_res[] = {
35*223d2158SZhen Lei DEFINE_RES_MEM(0x54, 4)
366f262ecfSHans de Goede };
376f262ecfSHans de Goede
38d58603ccSBoris BREZILLON static const struct resource sun6i_a31_apb0_rstc_res[] = {
39*223d2158SZhen Lei DEFINE_RES_MEM(0xb0, 4)
40d58603ccSBoris BREZILLON };
41d58603ccSBoris BREZILLON
42ea1628e8SChen-Yu Tsai static const struct resource sun8i_codec_analog_res[] = {
43ea1628e8SChen-Yu Tsai DEFINE_RES_MEM(SUN8I_CODEC_ANALOG_BASE, SUN8I_CODEC_ANALOG_SIZE),
44ea1628e8SChen-Yu Tsai };
45ea1628e8SChen-Yu Tsai
46d58603ccSBoris BREZILLON static const struct mfd_cell sun6i_a31_prcm_subdevs[] = {
47d58603ccSBoris BREZILLON {
48d58603ccSBoris BREZILLON .name = "sun6i-a31-ar100-clk",
49d58603ccSBoris BREZILLON .of_compatible = "allwinner,sun6i-a31-ar100-clk",
50d58603ccSBoris BREZILLON .num_resources = ARRAY_SIZE(sun6i_a31_ar100_clk_res),
51d58603ccSBoris BREZILLON .resources = sun6i_a31_ar100_clk_res,
52d58603ccSBoris BREZILLON },
53d58603ccSBoris BREZILLON {
54d58603ccSBoris BREZILLON .name = "sun6i-a31-apb0-clk",
55d58603ccSBoris BREZILLON .of_compatible = "allwinner,sun6i-a31-apb0-clk",
56d58603ccSBoris BREZILLON .num_resources = ARRAY_SIZE(sun6i_a31_apb0_clk_res),
57d58603ccSBoris BREZILLON .resources = sun6i_a31_apb0_clk_res,
58d58603ccSBoris BREZILLON },
59d58603ccSBoris BREZILLON {
60d58603ccSBoris BREZILLON .name = "sun6i-a31-apb0-gates-clk",
61d58603ccSBoris BREZILLON .of_compatible = "allwinner,sun6i-a31-apb0-gates-clk",
62d58603ccSBoris BREZILLON .num_resources = ARRAY_SIZE(sun6i_a31_apb0_gates_clk_res),
63d58603ccSBoris BREZILLON .resources = sun6i_a31_apb0_gates_clk_res,
64d58603ccSBoris BREZILLON },
65d58603ccSBoris BREZILLON {
666f262ecfSHans de Goede .name = "sun6i-a31-ir-clk",
676f262ecfSHans de Goede .of_compatible = "allwinner,sun4i-a10-mod0-clk",
686f262ecfSHans de Goede .num_resources = ARRAY_SIZE(sun6i_a31_ir_clk_res),
696f262ecfSHans de Goede .resources = sun6i_a31_ir_clk_res,
706f262ecfSHans de Goede },
716f262ecfSHans de Goede {
72d58603ccSBoris BREZILLON .name = "sun6i-a31-apb0-clock-reset",
73d58603ccSBoris BREZILLON .of_compatible = "allwinner,sun6i-a31-clock-reset",
74d58603ccSBoris BREZILLON .num_resources = ARRAY_SIZE(sun6i_a31_apb0_rstc_res),
75d58603ccSBoris BREZILLON .resources = sun6i_a31_apb0_rstc_res,
76d58603ccSBoris BREZILLON },
77d58603ccSBoris BREZILLON };
78d58603ccSBoris BREZILLON
794eb9560bSChen-Yu Tsai static const struct mfd_cell sun8i_a23_prcm_subdevs[] = {
804eb9560bSChen-Yu Tsai {
814eb9560bSChen-Yu Tsai .name = "sun8i-a23-apb0-clk",
824eb9560bSChen-Yu Tsai .of_compatible = "allwinner,sun8i-a23-apb0-clk",
834eb9560bSChen-Yu Tsai .num_resources = ARRAY_SIZE(sun6i_a31_apb0_clk_res),
844eb9560bSChen-Yu Tsai .resources = sun6i_a31_apb0_clk_res,
854eb9560bSChen-Yu Tsai },
864eb9560bSChen-Yu Tsai {
874eb9560bSChen-Yu Tsai .name = "sun6i-a31-apb0-gates-clk",
884eb9560bSChen-Yu Tsai .of_compatible = "allwinner,sun8i-a23-apb0-gates-clk",
894eb9560bSChen-Yu Tsai .num_resources = ARRAY_SIZE(sun6i_a31_apb0_gates_clk_res),
904eb9560bSChen-Yu Tsai .resources = sun6i_a31_apb0_gates_clk_res,
914eb9560bSChen-Yu Tsai },
924eb9560bSChen-Yu Tsai {
934eb9560bSChen-Yu Tsai .name = "sun6i-a31-apb0-clock-reset",
944eb9560bSChen-Yu Tsai .of_compatible = "allwinner,sun6i-a31-clock-reset",
954eb9560bSChen-Yu Tsai .num_resources = ARRAY_SIZE(sun6i_a31_apb0_rstc_res),
964eb9560bSChen-Yu Tsai .resources = sun6i_a31_apb0_rstc_res,
974eb9560bSChen-Yu Tsai },
98ea1628e8SChen-Yu Tsai {
99ea1628e8SChen-Yu Tsai .name = "sun8i-codec-analog",
100ea1628e8SChen-Yu Tsai .of_compatible = "allwinner,sun8i-a23-codec-analog",
101ea1628e8SChen-Yu Tsai .num_resources = ARRAY_SIZE(sun8i_codec_analog_res),
102ea1628e8SChen-Yu Tsai .resources = sun8i_codec_analog_res,
103ea1628e8SChen-Yu Tsai },
1044eb9560bSChen-Yu Tsai };
1054eb9560bSChen-Yu Tsai
106d58603ccSBoris BREZILLON static const struct prcm_data sun6i_a31_prcm_data = {
107d58603ccSBoris BREZILLON .nsubdevs = ARRAY_SIZE(sun6i_a31_prcm_subdevs),
108d58603ccSBoris BREZILLON .subdevs = sun6i_a31_prcm_subdevs,
109d58603ccSBoris BREZILLON };
110d58603ccSBoris BREZILLON
1114eb9560bSChen-Yu Tsai static const struct prcm_data sun8i_a23_prcm_data = {
1124eb9560bSChen-Yu Tsai .nsubdevs = ARRAY_SIZE(sun8i_a23_prcm_subdevs),
1134eb9560bSChen-Yu Tsai .subdevs = sun8i_a23_prcm_subdevs,
1144eb9560bSChen-Yu Tsai };
1154eb9560bSChen-Yu Tsai
116d58603ccSBoris BREZILLON static const struct of_device_id sun6i_prcm_dt_ids[] = {
117d58603ccSBoris BREZILLON {
118d58603ccSBoris BREZILLON .compatible = "allwinner,sun6i-a31-prcm",
119d58603ccSBoris BREZILLON .data = &sun6i_a31_prcm_data,
120d58603ccSBoris BREZILLON },
1214eb9560bSChen-Yu Tsai {
1224eb9560bSChen-Yu Tsai .compatible = "allwinner,sun8i-a23-prcm",
1234eb9560bSChen-Yu Tsai .data = &sun8i_a23_prcm_data,
1244eb9560bSChen-Yu Tsai },
125d58603ccSBoris BREZILLON { /* sentinel */ },
126d58603ccSBoris BREZILLON };
127d58603ccSBoris BREZILLON
sun6i_prcm_probe(struct platform_device * pdev)128d58603ccSBoris BREZILLON static int sun6i_prcm_probe(struct platform_device *pdev)
129d58603ccSBoris BREZILLON {
130d58603ccSBoris BREZILLON const struct of_device_id *match;
131d58603ccSBoris BREZILLON const struct prcm_data *data;
132d58603ccSBoris BREZILLON struct resource *res;
133d58603ccSBoris BREZILLON int ret;
134d58603ccSBoris BREZILLON
1358ca6ff16SArnd Bergmann match = of_match_node(sun6i_prcm_dt_ids, pdev->dev.of_node);
136d58603ccSBoris BREZILLON if (!match)
137d58603ccSBoris BREZILLON return -EINVAL;
138d58603ccSBoris BREZILLON
139d58603ccSBoris BREZILLON data = match->data;
140d58603ccSBoris BREZILLON
141d58603ccSBoris BREZILLON res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
142d58603ccSBoris BREZILLON if (!res) {
143d58603ccSBoris BREZILLON dev_err(&pdev->dev, "no prcm memory region provided\n");
144d58603ccSBoris BREZILLON return -ENOENT;
145d58603ccSBoris BREZILLON }
146d58603ccSBoris BREZILLON
147d58603ccSBoris BREZILLON ret = mfd_add_devices(&pdev->dev, 0, data->subdevs, data->nsubdevs,
148d58603ccSBoris BREZILLON res, -1, NULL);
149d58603ccSBoris BREZILLON if (ret) {
150d58603ccSBoris BREZILLON dev_err(&pdev->dev, "failed to add subdevices\n");
151d58603ccSBoris BREZILLON return ret;
152d58603ccSBoris BREZILLON }
153d58603ccSBoris BREZILLON
154d58603ccSBoris BREZILLON return 0;
155d58603ccSBoris BREZILLON }
156d58603ccSBoris BREZILLON
157d58603ccSBoris BREZILLON static struct platform_driver sun6i_prcm_driver = {
158d58603ccSBoris BREZILLON .driver = {
159d58603ccSBoris BREZILLON .name = "sun6i-prcm",
160d58603ccSBoris BREZILLON .of_match_table = sun6i_prcm_dt_ids,
161d58603ccSBoris BREZILLON },
162d58603ccSBoris BREZILLON .probe = sun6i_prcm_probe,
163d58603ccSBoris BREZILLON };
164391cd33aSPaul Gortmaker builtin_platform_driver(sun6i_prcm_driver);
165