Merge tag 'riscv-for-linus-4.15-rc2_cleanups' of git://git.kernel.org/pub/scm/linux...
[linux/fpc-iii.git] / drivers / soc / actions / owl-sps.c
blob875225bfa21c2e77fd0d791a24a921c6b1469c34
1 /*
2 * Actions Semi Owl Smart Power System (SPS)
4 * Copyright 2012 Actions Semi Inc.
5 * Author: Actions Semi, Inc.
7 * Copyright (c) 2017 Andreas Färber
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
15 #include <linux/of_address.h>
16 #include <linux/of_platform.h>
17 #include <linux/pm_domain.h>
18 #include <linux/soc/actions/owl-sps.h>
19 #include <dt-bindings/power/owl-s500-powergate.h>
21 struct owl_sps_domain_info {
22 const char *name;
23 int pwr_bit;
24 int ack_bit;
25 unsigned int genpd_flags;
28 struct owl_sps_info {
29 unsigned num_domains;
30 const struct owl_sps_domain_info *domains;
33 struct owl_sps {
34 struct device *dev;
35 const struct owl_sps_info *info;
36 void __iomem *base;
37 struct genpd_onecell_data genpd_data;
38 struct generic_pm_domain *domains[];
41 #define to_owl_pd(gpd) container_of(gpd, struct owl_sps_domain, genpd)
43 struct owl_sps_domain {
44 struct generic_pm_domain genpd;
45 const struct owl_sps_domain_info *info;
46 struct owl_sps *sps;
49 static int owl_sps_set_power(struct owl_sps_domain *pd, bool enable)
51 u32 pwr_mask, ack_mask;
53 ack_mask = BIT(pd->info->ack_bit);
54 pwr_mask = BIT(pd->info->pwr_bit);
56 return owl_sps_set_pg(pd->sps->base, pwr_mask, ack_mask, enable);
59 static int owl_sps_power_on(struct generic_pm_domain *domain)
61 struct owl_sps_domain *pd = to_owl_pd(domain);
63 dev_dbg(pd->sps->dev, "%s power on", pd->info->name);
65 return owl_sps_set_power(pd, true);
68 static int owl_sps_power_off(struct generic_pm_domain *domain)
70 struct owl_sps_domain *pd = to_owl_pd(domain);
72 dev_dbg(pd->sps->dev, "%s power off", pd->info->name);
74 return owl_sps_set_power(pd, false);
77 static int owl_sps_init_domain(struct owl_sps *sps, int index)
79 struct owl_sps_domain *pd;
81 pd = devm_kzalloc(sps->dev, sizeof(*pd), GFP_KERNEL);
82 if (!pd)
83 return -ENOMEM;
85 pd->info = &sps->info->domains[index];
86 pd->sps = sps;
88 pd->genpd.name = pd->info->name;
89 pd->genpd.power_on = owl_sps_power_on;
90 pd->genpd.power_off = owl_sps_power_off;
91 pd->genpd.flags = pd->info->genpd_flags;
92 pm_genpd_init(&pd->genpd, NULL, false);
94 sps->genpd_data.domains[index] = &pd->genpd;
96 return 0;
99 static int owl_sps_probe(struct platform_device *pdev)
101 const struct of_device_id *match;
102 const struct owl_sps_info *sps_info;
103 struct owl_sps *sps;
104 int i, ret;
106 if (!pdev->dev.of_node) {
107 dev_err(&pdev->dev, "no device node\n");
108 return -ENODEV;
111 match = of_match_device(pdev->dev.driver->of_match_table, &pdev->dev);
112 if (!match || !match->data) {
113 dev_err(&pdev->dev, "unknown compatible or missing data\n");
114 return -EINVAL;
117 sps_info = match->data;
119 sps = devm_kzalloc(&pdev->dev, sizeof(*sps) +
120 sps_info->num_domains * sizeof(sps->domains[0]),
121 GFP_KERNEL);
122 if (!sps)
123 return -ENOMEM;
125 sps->base = of_io_request_and_map(pdev->dev.of_node, 0, "owl-sps");
126 if (IS_ERR(sps->base)) {
127 dev_err(&pdev->dev, "failed to map sps registers\n");
128 return PTR_ERR(sps->base);
131 sps->dev = &pdev->dev;
132 sps->info = sps_info;
133 sps->genpd_data.domains = sps->domains;
134 sps->genpd_data.num_domains = sps_info->num_domains;
136 for (i = 0; i < sps_info->num_domains; i++) {
137 ret = owl_sps_init_domain(sps, i);
138 if (ret)
139 return ret;
142 ret = of_genpd_add_provider_onecell(pdev->dev.of_node, &sps->genpd_data);
143 if (ret) {
144 dev_err(&pdev->dev, "failed to add provider (%d)", ret);
145 return ret;
148 return 0;
151 static const struct owl_sps_domain_info s500_sps_domains[] = {
152 [S500_PD_VDE] = {
153 .name = "VDE",
154 .pwr_bit = 0,
155 .ack_bit = 16,
157 [S500_PD_VCE_SI] = {
158 .name = "VCE_SI",
159 .pwr_bit = 1,
160 .ack_bit = 17,
162 [S500_PD_USB2_1] = {
163 .name = "USB2_1",
164 .pwr_bit = 2,
165 .ack_bit = 18,
167 [S500_PD_CPU2] = {
168 .name = "CPU2",
169 .pwr_bit = 5,
170 .ack_bit = 21,
171 .genpd_flags = GENPD_FLAG_ALWAYS_ON,
173 [S500_PD_CPU3] = {
174 .name = "CPU3",
175 .pwr_bit = 6,
176 .ack_bit = 22,
177 .genpd_flags = GENPD_FLAG_ALWAYS_ON,
179 [S500_PD_DMA] = {
180 .name = "DMA",
181 .pwr_bit = 8,
182 .ack_bit = 12,
184 [S500_PD_DS] = {
185 .name = "DS",
186 .pwr_bit = 9,
187 .ack_bit = 13,
189 [S500_PD_USB3] = {
190 .name = "USB3",
191 .pwr_bit = 10,
192 .ack_bit = 14,
194 [S500_PD_USB2_0] = {
195 .name = "USB2_0",
196 .pwr_bit = 11,
197 .ack_bit = 15,
201 static const struct owl_sps_info s500_sps_info = {
202 .num_domains = ARRAY_SIZE(s500_sps_domains),
203 .domains = s500_sps_domains,
206 static const struct of_device_id owl_sps_of_matches[] = {
207 { .compatible = "actions,s500-sps", .data = &s500_sps_info },
211 static struct platform_driver owl_sps_platform_driver = {
212 .probe = owl_sps_probe,
213 .driver = {
214 .name = "owl-sps",
215 .of_match_table = owl_sps_of_matches,
216 .suppress_bind_attrs = true,
220 static int __init owl_sps_init(void)
222 return platform_driver_register(&owl_sps_platform_driver);
224 postcore_initcall(owl_sps_init);