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
{
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 of_device_id
*match
;
102 const struct owl_sps_info
*sps_info
;
106 if (!pdev
->dev
.of_node
) {
107 dev_err(&pdev
->dev
, "no device node\n");
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");
117 sps_info
= match
->data
;
119 sps
= devm_kzalloc(&pdev
->dev
, sizeof(*sps
) +
120 sps_info
->num_domains
* sizeof(sps
->domains
[0]),
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
);
142 ret
= of_genpd_add_provider_onecell(pdev
->dev
.of_node
, &sps
->genpd_data
);
144 dev_err(&pdev
->dev
, "failed to add provider (%d)", ret
);
151 static const struct owl_sps_domain_info s500_sps_domains
[] = {
171 .genpd_flags
= GENPD_FLAG_ALWAYS_ON
,
177 .genpd_flags
= GENPD_FLAG_ALWAYS_ON
,
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
,
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
);