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>
20 #include <dt-bindings/power/owl-s700-powergate.h>
22 struct owl_sps_domain_info
{
26 unsigned int genpd_flags
;
31 const struct owl_sps_domain_info
*domains
;
36 const struct owl_sps_info
*info
;
38 struct genpd_onecell_data genpd_data
;
39 struct generic_pm_domain
*domains
[];
42 #define to_owl_pd(gpd) container_of(gpd, struct owl_sps_domain, genpd)
44 struct owl_sps_domain
{
45 struct generic_pm_domain genpd
;
46 const struct owl_sps_domain_info
*info
;
50 static int owl_sps_set_power(struct owl_sps_domain
*pd
, bool enable
)
52 u32 pwr_mask
, ack_mask
;
54 ack_mask
= BIT(pd
->info
->ack_bit
);
55 pwr_mask
= BIT(pd
->info
->pwr_bit
);
57 return owl_sps_set_pg(pd
->sps
->base
, pwr_mask
, ack_mask
, enable
);
60 static int owl_sps_power_on(struct generic_pm_domain
*domain
)
62 struct owl_sps_domain
*pd
= to_owl_pd(domain
);
64 dev_dbg(pd
->sps
->dev
, "%s power on", pd
->info
->name
);
66 return owl_sps_set_power(pd
, true);
69 static int owl_sps_power_off(struct generic_pm_domain
*domain
)
71 struct owl_sps_domain
*pd
= to_owl_pd(domain
);
73 dev_dbg(pd
->sps
->dev
, "%s power off", pd
->info
->name
);
75 return owl_sps_set_power(pd
, false);
78 static int owl_sps_init_domain(struct owl_sps
*sps
, int index
)
80 struct owl_sps_domain
*pd
;
82 pd
= devm_kzalloc(sps
->dev
, sizeof(*pd
), GFP_KERNEL
);
86 pd
->info
= &sps
->info
->domains
[index
];
89 pd
->genpd
.name
= pd
->info
->name
;
90 pd
->genpd
.power_on
= owl_sps_power_on
;
91 pd
->genpd
.power_off
= owl_sps_power_off
;
92 pd
->genpd
.flags
= pd
->info
->genpd_flags
;
93 pm_genpd_init(&pd
->genpd
, NULL
, false);
95 sps
->genpd_data
.domains
[index
] = &pd
->genpd
;
100 static int owl_sps_probe(struct platform_device
*pdev
)
102 const struct of_device_id
*match
;
103 const struct owl_sps_info
*sps_info
;
107 if (!pdev
->dev
.of_node
) {
108 dev_err(&pdev
->dev
, "no device node\n");
112 match
= of_match_device(pdev
->dev
.driver
->of_match_table
, &pdev
->dev
);
113 if (!match
|| !match
->data
) {
114 dev_err(&pdev
->dev
, "unknown compatible or missing data\n");
118 sps_info
= match
->data
;
120 sps
= devm_kzalloc(&pdev
->dev
,
121 struct_size(sps
, domains
, sps_info
->num_domains
),
126 sps
->base
= of_io_request_and_map(pdev
->dev
.of_node
, 0, "owl-sps");
127 if (IS_ERR(sps
->base
)) {
128 dev_err(&pdev
->dev
, "failed to map sps registers\n");
129 return PTR_ERR(sps
->base
);
132 sps
->dev
= &pdev
->dev
;
133 sps
->info
= sps_info
;
134 sps
->genpd_data
.domains
= sps
->domains
;
135 sps
->genpd_data
.num_domains
= sps_info
->num_domains
;
137 for (i
= 0; i
< sps_info
->num_domains
; i
++) {
138 ret
= owl_sps_init_domain(sps
, i
);
143 ret
= of_genpd_add_provider_onecell(pdev
->dev
.of_node
, &sps
->genpd_data
);
145 dev_err(&pdev
->dev
, "failed to add provider (%d)", ret
);
152 static const struct owl_sps_domain_info s500_sps_domains
[] = {
172 .genpd_flags
= GENPD_FLAG_ALWAYS_ON
,
178 .genpd_flags
= GENPD_FLAG_ALWAYS_ON
,
202 static const struct owl_sps_info s500_sps_info
= {
203 .num_domains
= ARRAY_SIZE(s500_sps_domains
),
204 .domains
= s500_sps_domains
,
207 static const struct owl_sps_domain_info s700_sps_domains
[] = {
242 static const struct owl_sps_info s700_sps_info
= {
243 .num_domains
= ARRAY_SIZE(s700_sps_domains
),
244 .domains
= s700_sps_domains
,
247 static const struct of_device_id owl_sps_of_matches
[] = {
248 { .compatible
= "actions,s500-sps", .data
= &s500_sps_info
},
249 { .compatible
= "actions,s700-sps", .data
= &s700_sps_info
},
253 static struct platform_driver owl_sps_platform_driver
= {
254 .probe
= owl_sps_probe
,
257 .of_match_table
= owl_sps_of_matches
,
258 .suppress_bind_attrs
= true,
262 static int __init
owl_sps_init(void)
264 return platform_driver_register(&owl_sps_platform_driver
);
266 postcore_initcall(owl_sps_init
);