1 // SPDX-License-Identifier: GPL-2.0+
3 * Actions Semi Owl Smart Power System (SPS)
5 * Copyright 2012 Actions Semi Inc.
6 * Author: Actions Semi, Inc.
8 * Copyright (c) 2017 Andreas Färber
11 #include <linux/mod_devicetable.h>
12 #include <linux/of_address.h>
13 #include <linux/platform_device.h>
14 #include <linux/property.h>
15 #include <linux/pm_domain.h>
16 #include <linux/soc/actions/owl-sps.h>
17 #include <dt-bindings/power/owl-s500-powergate.h>
18 #include <dt-bindings/power/owl-s700-powergate.h>
19 #include <dt-bindings/power/owl-s900-powergate.h>
21 struct owl_sps_domain_info
{
25 unsigned int genpd_flags
;
30 const struct owl_sps_domain_info
*domains
;
35 const struct owl_sps_info
*info
;
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
;
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
);
85 pd
->info
= &sps
->info
->domains
[index
];
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
;
99 static int owl_sps_probe(struct platform_device
*pdev
)
101 const struct owl_sps_info
*sps_info
;
105 sps_info
= device_get_match_data(&pdev
->dev
);
107 dev_err(&pdev
->dev
, "unknown compatible or missing data\n");
111 sps
= devm_kzalloc(&pdev
->dev
,
112 struct_size(sps
, domains
, sps_info
->num_domains
),
117 sps
->base
= of_io_request_and_map(pdev
->dev
.of_node
, 0, "owl-sps");
118 if (IS_ERR(sps
->base
)) {
119 dev_err(&pdev
->dev
, "failed to map sps registers\n");
120 return PTR_ERR(sps
->base
);
123 sps
->dev
= &pdev
->dev
;
124 sps
->info
= sps_info
;
125 sps
->genpd_data
.domains
= sps
->domains
;
126 sps
->genpd_data
.num_domains
= sps_info
->num_domains
;
128 for (i
= 0; i
< sps_info
->num_domains
; i
++) {
129 ret
= owl_sps_init_domain(sps
, i
);
134 ret
= of_genpd_add_provider_onecell(pdev
->dev
.of_node
, &sps
->genpd_data
);
136 dev_err(&pdev
->dev
, "failed to add provider (%d)", ret
);
143 static const struct owl_sps_domain_info s500_sps_domains
[] = {
163 .genpd_flags
= GENPD_FLAG_ALWAYS_ON
,
169 .genpd_flags
= GENPD_FLAG_ALWAYS_ON
,
193 static const struct owl_sps_info s500_sps_info
= {
194 .num_domains
= ARRAY_SIZE(s500_sps_domains
),
195 .domains
= s500_sps_domains
,
198 static const struct owl_sps_domain_info s700_sps_domains
[] = {
233 static const struct owl_sps_info s700_sps_info
= {
234 .num_domains
= ARRAY_SIZE(s700_sps_domains
),
235 .domains
= s700_sps_domains
,
238 static const struct owl_sps_domain_info s900_sps_domains
[] = {
279 [S900_PD_USB2_H0
] = {
283 [S900_PD_USB2_H1
] = {
289 static const struct owl_sps_info s900_sps_info
= {
290 .num_domains
= ARRAY_SIZE(s900_sps_domains
),
291 .domains
= s900_sps_domains
,
294 static const struct of_device_id owl_sps_of_matches
[] = {
295 { .compatible
= "actions,s500-sps", .data
= &s500_sps_info
},
296 { .compatible
= "actions,s700-sps", .data
= &s700_sps_info
},
297 { .compatible
= "actions,s900-sps", .data
= &s900_sps_info
},
301 static struct platform_driver owl_sps_platform_driver
= {
302 .probe
= owl_sps_probe
,
305 .of_match_table
= owl_sps_of_matches
,
306 .suppress_bind_attrs
= true,
310 static int __init
owl_sps_init(void)
312 return platform_driver_register(&owl_sps_platform_driver
);
314 postcore_initcall(owl_sps_init
);