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/of_address.h>
12 #include <linux/of_platform.h>
13 #include <linux/pm_domain.h>
14 #include <linux/soc/actions/owl-sps.h>
15 #include <dt-bindings/power/owl-s500-powergate.h>
16 #include <dt-bindings/power/owl-s700-powergate.h>
17 #include <dt-bindings/power/owl-s900-powergate.h>
19 struct owl_sps_domain_info
{
23 unsigned int genpd_flags
;
28 const struct owl_sps_domain_info
*domains
;
33 const struct owl_sps_info
*info
;
35 struct genpd_onecell_data genpd_data
;
36 struct generic_pm_domain
*domains
[];
39 #define to_owl_pd(gpd) container_of(gpd, struct owl_sps_domain, genpd)
41 struct owl_sps_domain
{
42 struct generic_pm_domain genpd
;
43 const struct owl_sps_domain_info
*info
;
47 static int owl_sps_set_power(struct owl_sps_domain
*pd
, bool enable
)
49 u32 pwr_mask
, ack_mask
;
51 ack_mask
= BIT(pd
->info
->ack_bit
);
52 pwr_mask
= BIT(pd
->info
->pwr_bit
);
54 return owl_sps_set_pg(pd
->sps
->base
, pwr_mask
, ack_mask
, enable
);
57 static int owl_sps_power_on(struct generic_pm_domain
*domain
)
59 struct owl_sps_domain
*pd
= to_owl_pd(domain
);
61 dev_dbg(pd
->sps
->dev
, "%s power on", pd
->info
->name
);
63 return owl_sps_set_power(pd
, true);
66 static int owl_sps_power_off(struct generic_pm_domain
*domain
)
68 struct owl_sps_domain
*pd
= to_owl_pd(domain
);
70 dev_dbg(pd
->sps
->dev
, "%s power off", pd
->info
->name
);
72 return owl_sps_set_power(pd
, false);
75 static int owl_sps_init_domain(struct owl_sps
*sps
, int index
)
77 struct owl_sps_domain
*pd
;
79 pd
= devm_kzalloc(sps
->dev
, sizeof(*pd
), GFP_KERNEL
);
83 pd
->info
= &sps
->info
->domains
[index
];
86 pd
->genpd
.name
= pd
->info
->name
;
87 pd
->genpd
.power_on
= owl_sps_power_on
;
88 pd
->genpd
.power_off
= owl_sps_power_off
;
89 pd
->genpd
.flags
= pd
->info
->genpd_flags
;
90 pm_genpd_init(&pd
->genpd
, NULL
, false);
92 sps
->genpd_data
.domains
[index
] = &pd
->genpd
;
97 static int owl_sps_probe(struct platform_device
*pdev
)
99 const struct of_device_id
*match
;
100 const struct owl_sps_info
*sps_info
;
104 if (!pdev
->dev
.of_node
) {
105 dev_err(&pdev
->dev
, "no device node\n");
109 match
= of_match_device(pdev
->dev
.driver
->of_match_table
, &pdev
->dev
);
110 if (!match
|| !match
->data
) {
111 dev_err(&pdev
->dev
, "unknown compatible or missing data\n");
115 sps_info
= match
->data
;
117 sps
= devm_kzalloc(&pdev
->dev
,
118 struct_size(sps
, domains
, sps_info
->num_domains
),
123 sps
->base
= of_io_request_and_map(pdev
->dev
.of_node
, 0, "owl-sps");
124 if (IS_ERR(sps
->base
)) {
125 dev_err(&pdev
->dev
, "failed to map sps registers\n");
126 return PTR_ERR(sps
->base
);
129 sps
->dev
= &pdev
->dev
;
130 sps
->info
= sps_info
;
131 sps
->genpd_data
.domains
= sps
->domains
;
132 sps
->genpd_data
.num_domains
= sps_info
->num_domains
;
134 for (i
= 0; i
< sps_info
->num_domains
; i
++) {
135 ret
= owl_sps_init_domain(sps
, i
);
140 ret
= of_genpd_add_provider_onecell(pdev
->dev
.of_node
, &sps
->genpd_data
);
142 dev_err(&pdev
->dev
, "failed to add provider (%d)", ret
);
149 static const struct owl_sps_domain_info s500_sps_domains
[] = {
169 .genpd_flags
= GENPD_FLAG_ALWAYS_ON
,
175 .genpd_flags
= GENPD_FLAG_ALWAYS_ON
,
199 static const struct owl_sps_info s500_sps_info
= {
200 .num_domains
= ARRAY_SIZE(s500_sps_domains
),
201 .domains
= s500_sps_domains
,
204 static const struct owl_sps_domain_info s700_sps_domains
[] = {
239 static const struct owl_sps_info s700_sps_info
= {
240 .num_domains
= ARRAY_SIZE(s700_sps_domains
),
241 .domains
= s700_sps_domains
,
244 static const struct owl_sps_domain_info s900_sps_domains
[] = {
285 [S900_PD_USB2_H0
] = {
289 [S900_PD_USB2_H1
] = {
295 static const struct owl_sps_info s900_sps_info
= {
296 .num_domains
= ARRAY_SIZE(s900_sps_domains
),
297 .domains
= s900_sps_domains
,
300 static const struct of_device_id owl_sps_of_matches
[] = {
301 { .compatible
= "actions,s500-sps", .data
= &s500_sps_info
},
302 { .compatible
= "actions,s700-sps", .data
= &s700_sps_info
},
303 { .compatible
= "actions,s900-sps", .data
= &s900_sps_info
},
307 static struct platform_driver owl_sps_platform_driver
= {
308 .probe
= owl_sps_probe
,
311 .of_match_table
= owl_sps_of_matches
,
312 .suppress_bind_attrs
= true,
316 static int __init
owl_sps_init(void)
318 return platform_driver_register(&owl_sps_platform_driver
);
320 postcore_initcall(owl_sps_init
);