Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 1 | /* |
Anson Huang | 263475d | 2013-03-21 10:58:06 -0400 | [diff] [blame] | 2 | * Copyright 2011-2013 Freescale Semiconductor, Inc. |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 3 | * Copyright 2011 Linaro Ltd. |
| 4 | * |
| 5 | * The code contained herein is licensed under the GNU General Public |
| 6 | * License. You may obtain a copy of the GNU General Public License |
| 7 | * Version 2 or later at the following locations: |
| 8 | * |
| 9 | * http://www.opensource.org/licenses/gpl-license.html |
| 10 | * http://www.gnu.org/copyleft/gpl.html |
| 11 | */ |
| 12 | |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 13 | #include <linux/clk.h> |
| 14 | #include <linux/delay.h> |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 15 | #include <linux/io.h> |
| 16 | #include <linux/irq.h> |
Marc Zyngier | 0cc09e8 | 2015-10-16 15:21:10 +0100 | [diff] [blame] | 17 | #include <linux/irqchip.h> |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 18 | #include <linux/of.h> |
| 19 | #include <linux/of_address.h> |
| 20 | #include <linux/of_irq.h> |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/pm_domain.h> |
| 23 | #include <linux/regulator/consumer.h> |
Rob Herring | 520f7bd | 2012-12-27 13:10:24 -0600 | [diff] [blame] | 24 | #include <linux/irqchip/arm-gic.h> |
Fabio Estevam | 9a67a6f | 2013-03-25 09:20:42 -0300 | [diff] [blame] | 25 | #include "common.h" |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 26 | #include "hardware.h" |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 27 | |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 28 | #define GPC_CNTR 0x000 |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 29 | #define GPC_IMR1 0x008 |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 30 | #define GPC_PGC_GPU_PDN 0x260 |
| 31 | #define GPC_PGC_GPU_PUPSCR 0x264 |
| 32 | #define GPC_PGC_GPU_PDNSCR 0x268 |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 33 | #define GPC_PGC_CPU_PDN 0x2a0 |
Anson Huang | 05136f0 | 2014-12-17 12:24:12 +0800 | [diff] [blame] | 34 | #define GPC_PGC_CPU_PUPSCR 0x2a4 |
| 35 | #define GPC_PGC_CPU_PDNSCR 0x2a8 |
| 36 | #define GPC_PGC_SW2ISO_SHIFT 0x8 |
| 37 | #define GPC_PGC_SW_SHIFT 0x0 |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 38 | |
| 39 | #define IMR_NUM 4 |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 40 | #define GPC_MAX_IRQS (IMR_NUM * 32) |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 41 | |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 42 | #define GPU_VPU_PUP_REQ BIT(1) |
| 43 | #define GPU_VPU_PDN_REQ BIT(0) |
| 44 | |
| 45 | #define GPC_CLK_MAX 6 |
| 46 | |
| 47 | struct pu_domain { |
| 48 | struct generic_pm_domain base; |
| 49 | struct regulator *reg; |
| 50 | struct clk *clk[GPC_CLK_MAX]; |
| 51 | int num_clks; |
| 52 | }; |
| 53 | |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 54 | static void __iomem *gpc_base; |
| 55 | static u32 gpc_wake_irqs[IMR_NUM]; |
| 56 | static u32 gpc_saved_imrs[IMR_NUM]; |
| 57 | |
Anson Huang | 05136f0 | 2014-12-17 12:24:12 +0800 | [diff] [blame] | 58 | void imx_gpc_set_arm_power_up_timing(u32 sw2iso, u32 sw) |
| 59 | { |
| 60 | writel_relaxed((sw2iso << GPC_PGC_SW2ISO_SHIFT) | |
| 61 | (sw << GPC_PGC_SW_SHIFT), gpc_base + GPC_PGC_CPU_PUPSCR); |
| 62 | } |
| 63 | |
| 64 | void imx_gpc_set_arm_power_down_timing(u32 sw2iso, u32 sw) |
| 65 | { |
| 66 | writel_relaxed((sw2iso << GPC_PGC_SW2ISO_SHIFT) | |
| 67 | (sw << GPC_PGC_SW_SHIFT), gpc_base + GPC_PGC_CPU_PDNSCR); |
| 68 | } |
| 69 | |
| 70 | void imx_gpc_set_arm_power_in_lpm(bool power_off) |
| 71 | { |
| 72 | writel_relaxed(power_off, gpc_base + GPC_PGC_CPU_PDN); |
| 73 | } |
| 74 | |
Anson Huang | 80c0ecd | 2014-06-23 16:42:44 +0800 | [diff] [blame] | 75 | void imx_gpc_pre_suspend(bool arm_power_off) |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 76 | { |
| 77 | void __iomem *reg_imr1 = gpc_base + GPC_IMR1; |
| 78 | int i; |
| 79 | |
| 80 | /* Tell GPC to power off ARM core when suspend */ |
Anson Huang | 80c0ecd | 2014-06-23 16:42:44 +0800 | [diff] [blame] | 81 | if (arm_power_off) |
Anson Huang | 05136f0 | 2014-12-17 12:24:12 +0800 | [diff] [blame] | 82 | imx_gpc_set_arm_power_in_lpm(arm_power_off); |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 83 | |
| 84 | for (i = 0; i < IMR_NUM; i++) { |
| 85 | gpc_saved_imrs[i] = readl_relaxed(reg_imr1 + i * 4); |
| 86 | writel_relaxed(~gpc_wake_irqs[i], reg_imr1 + i * 4); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void imx_gpc_post_resume(void) |
| 91 | { |
| 92 | void __iomem *reg_imr1 = gpc_base + GPC_IMR1; |
| 93 | int i; |
| 94 | |
| 95 | /* Keep ARM core powered on for other low-power modes */ |
Anson Huang | 05136f0 | 2014-12-17 12:24:12 +0800 | [diff] [blame] | 96 | imx_gpc_set_arm_power_in_lpm(false); |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 97 | |
| 98 | for (i = 0; i < IMR_NUM; i++) |
| 99 | writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4); |
| 100 | } |
| 101 | |
| 102 | static int imx_gpc_irq_set_wake(struct irq_data *d, unsigned int on) |
| 103 | { |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 104 | unsigned int idx = d->hwirq / 32; |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 105 | u32 mask; |
| 106 | |
Marc Zyngier | e2fd06f | 2014-12-02 16:05:25 +0000 | [diff] [blame] | 107 | mask = 1 << d->hwirq % 32; |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 108 | gpc_wake_irqs[idx] = on ? gpc_wake_irqs[idx] | mask : |
| 109 | gpc_wake_irqs[idx] & ~mask; |
| 110 | |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 111 | /* |
| 112 | * Do *not* call into the parent, as the GIC doesn't have any |
| 113 | * wake-up facility... |
| 114 | */ |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
Anson Huang | 263475d | 2013-03-21 10:58:06 -0400 | [diff] [blame] | 118 | void imx_gpc_mask_all(void) |
| 119 | { |
| 120 | void __iomem *reg_imr1 = gpc_base + GPC_IMR1; |
| 121 | int i; |
| 122 | |
| 123 | for (i = 0; i < IMR_NUM; i++) { |
| 124 | gpc_saved_imrs[i] = readl_relaxed(reg_imr1 + i * 4); |
| 125 | writel_relaxed(~0, reg_imr1 + i * 4); |
| 126 | } |
| 127 | |
| 128 | } |
| 129 | |
| 130 | void imx_gpc_restore_all(void) |
| 131 | { |
| 132 | void __iomem *reg_imr1 = gpc_base + GPC_IMR1; |
| 133 | int i; |
| 134 | |
| 135 | for (i = 0; i < IMR_NUM; i++) |
| 136 | writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4); |
| 137 | } |
| 138 | |
Marc Zyngier | 65bb688 | 2014-12-02 16:05:26 +0000 | [diff] [blame] | 139 | void imx_gpc_hwirq_unmask(unsigned int hwirq) |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 140 | { |
| 141 | void __iomem *reg; |
| 142 | u32 val; |
| 143 | |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 144 | reg = gpc_base + GPC_IMR1 + hwirq / 32 * 4; |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 145 | val = readl_relaxed(reg); |
Marc Zyngier | 65bb688 | 2014-12-02 16:05:26 +0000 | [diff] [blame] | 146 | val &= ~(1 << hwirq % 32); |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 147 | writel_relaxed(val, reg); |
| 148 | } |
| 149 | |
Marc Zyngier | 65bb688 | 2014-12-02 16:05:26 +0000 | [diff] [blame] | 150 | void imx_gpc_hwirq_mask(unsigned int hwirq) |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 151 | { |
| 152 | void __iomem *reg; |
| 153 | u32 val; |
| 154 | |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 155 | reg = gpc_base + GPC_IMR1 + hwirq / 32 * 4; |
Marc Zyngier | 65bb688 | 2014-12-02 16:05:26 +0000 | [diff] [blame] | 156 | val = readl_relaxed(reg); |
| 157 | val |= 1 << (hwirq % 32); |
| 158 | writel_relaxed(val, reg); |
| 159 | } |
| 160 | |
| 161 | static void imx_gpc_irq_unmask(struct irq_data *d) |
| 162 | { |
Marc Zyngier | 65bb688 | 2014-12-02 16:05:26 +0000 | [diff] [blame] | 163 | imx_gpc_hwirq_unmask(d->hwirq); |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 164 | irq_chip_unmask_parent(d); |
Marc Zyngier | 65bb688 | 2014-12-02 16:05:26 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | static void imx_gpc_irq_mask(struct irq_data *d) |
| 168 | { |
Marc Zyngier | 65bb688 | 2014-12-02 16:05:26 +0000 | [diff] [blame] | 169 | imx_gpc_hwirq_mask(d->hwirq); |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 170 | irq_chip_mask_parent(d); |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 171 | } |
| 172 | |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 173 | static struct irq_chip imx_gpc_chip = { |
Marc Zyngier | e33b675 | 2015-03-12 08:40:37 +0000 | [diff] [blame] | 174 | .name = "GPC", |
| 175 | .irq_eoi = irq_chip_eoi_parent, |
| 176 | .irq_mask = imx_gpc_irq_mask, |
| 177 | .irq_unmask = imx_gpc_irq_unmask, |
| 178 | .irq_retrigger = irq_chip_retrigger_hierarchy, |
| 179 | .irq_set_wake = imx_gpc_irq_set_wake, |
Anson Huang | 4699ccb | 2015-10-20 18:44:19 +0800 | [diff] [blame] | 180 | .irq_set_type = irq_chip_set_type_parent, |
Marc Zyngier | e33b675 | 2015-03-12 08:40:37 +0000 | [diff] [blame] | 181 | #ifdef CONFIG_SMP |
| 182 | .irq_set_affinity = irq_chip_set_affinity_parent, |
| 183 | #endif |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 184 | }; |
| 185 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 186 | static int imx_gpc_domain_translate(struct irq_domain *d, |
| 187 | struct irq_fwspec *fwspec, |
| 188 | unsigned long *hwirq, |
| 189 | unsigned int *type) |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 190 | { |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 191 | if (is_of_node(fwspec->fwnode)) { |
| 192 | if (fwspec->param_count != 3) |
| 193 | return -EINVAL; |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 194 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 195 | /* No PPI should point to this domain */ |
| 196 | if (fwspec->param[0] != 0) |
| 197 | return -EINVAL; |
| 198 | |
| 199 | *hwirq = fwspec->param[1]; |
| 200 | *type = fwspec->param[2]; |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | return -EINVAL; |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static int imx_gpc_domain_alloc(struct irq_domain *domain, |
| 208 | unsigned int irq, |
| 209 | unsigned int nr_irqs, void *data) |
| 210 | { |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 211 | struct irq_fwspec *fwspec = data; |
| 212 | struct irq_fwspec parent_fwspec; |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 213 | irq_hw_number_t hwirq; |
Shawn Guo | 485863b | 2012-12-04 22:55:13 +0800 | [diff] [blame] | 214 | int i; |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 215 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 216 | if (fwspec->param_count != 3) |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 217 | return -EINVAL; /* Not GIC compliant */ |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 218 | if (fwspec->param[0] != 0) |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 219 | return -EINVAL; /* No PPI should point to this domain */ |
| 220 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 221 | hwirq = fwspec->param[1]; |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 222 | if (hwirq >= GPC_MAX_IRQS) |
| 223 | return -EINVAL; /* Can't deal with this */ |
| 224 | |
| 225 | for (i = 0; i < nr_irqs; i++) |
| 226 | irq_domain_set_hwirq_and_chip(domain, irq + i, hwirq + i, |
| 227 | &imx_gpc_chip, NULL); |
| 228 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 229 | parent_fwspec = *fwspec; |
| 230 | parent_fwspec.fwnode = domain->parent->fwnode; |
| 231 | return irq_domain_alloc_irqs_parent(domain, irq, nr_irqs, |
| 232 | &parent_fwspec); |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Krzysztof Kozlowski | 9b589a8 | 2015-04-27 21:51:39 +0900 | [diff] [blame] | 235 | static const struct irq_domain_ops imx_gpc_domain_ops = { |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 236 | .translate = imx_gpc_domain_translate, |
| 237 | .alloc = imx_gpc_domain_alloc, |
| 238 | .free = irq_domain_free_irqs_common, |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | static int __init imx_gpc_init(struct device_node *node, |
| 242 | struct device_node *parent) |
| 243 | { |
| 244 | struct irq_domain *parent_domain, *domain; |
| 245 | int i; |
| 246 | |
| 247 | if (!parent) { |
| 248 | pr_err("%s: no parent, giving up\n", node->full_name); |
| 249 | return -ENODEV; |
| 250 | } |
| 251 | |
| 252 | parent_domain = irq_find_host(parent); |
| 253 | if (!parent_domain) { |
| 254 | pr_err("%s: unable to obtain parent domain\n", node->full_name); |
| 255 | return -ENXIO; |
| 256 | } |
| 257 | |
| 258 | gpc_base = of_iomap(node, 0); |
| 259 | if (WARN_ON(!gpc_base)) |
| 260 | return -ENOMEM; |
| 261 | |
| 262 | domain = irq_domain_add_hierarchy(parent_domain, 0, GPC_MAX_IRQS, |
| 263 | node, &imx_gpc_domain_ops, |
| 264 | NULL); |
| 265 | if (!domain) { |
| 266 | iounmap(gpc_base); |
| 267 | return -ENOMEM; |
| 268 | } |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 269 | |
Shawn Guo | 485863b | 2012-12-04 22:55:13 +0800 | [diff] [blame] | 270 | /* Initially mask all interrupts */ |
| 271 | for (i = 0; i < IMR_NUM; i++) |
| 272 | writel_relaxed(~0, gpc_base + GPC_IMR1 + i * 4); |
| 273 | |
Philipp Zabel | 255c039 | 2016-08-09 16:18:52 +0200 | [diff] [blame] | 274 | /* |
| 275 | * Clear the OF_POPULATED flag set in of_irq_init so that |
| 276 | * later the GPC power domain driver will not be skipped. |
| 277 | */ |
| 278 | of_node_clear_flag(node, OF_POPULATED); |
| 279 | |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 280 | return 0; |
Shawn Guo | 9fbbe68 | 2011-09-06 14:39:44 +0800 | [diff] [blame] | 281 | } |
Marc Zyngier | 0cc09e8 | 2015-10-16 15:21:10 +0100 | [diff] [blame] | 282 | IRQCHIP_DECLARE(imx_gpc, "fsl,imx6q-gpc", imx_gpc_init); |
Marc Zyngier | b923ff6 | 2015-02-23 17:45:18 +0000 | [diff] [blame] | 283 | |
Marc Zyngier | 1451756 | 2015-03-13 16:05:37 +0000 | [diff] [blame] | 284 | void __init imx_gpc_check_dt(void) |
| 285 | { |
| 286 | struct device_node *np; |
| 287 | |
| 288 | np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-gpc"); |
Lucas Stach | 634a603 | 2015-05-26 18:43:36 +0200 | [diff] [blame] | 289 | if (WARN_ON(!np)) |
| 290 | return; |
| 291 | |
| 292 | if (WARN_ON(!of_find_property(np, "interrupt-controller", NULL))) { |
| 293 | pr_warn("Outdated DT detected, suspend/resume will NOT work\n"); |
| 294 | |
| 295 | /* map GPC, so that at least CPUidle and WARs keep working */ |
| 296 | gpc_base = of_iomap(np, 0); |
| 297 | } |
Marc Zyngier | 1451756 | 2015-03-13 16:05:37 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 300 | static void _imx6q_pm_pu_power_off(struct generic_pm_domain *genpd) |
| 301 | { |
| 302 | int iso, iso2sw; |
| 303 | u32 val; |
| 304 | |
| 305 | /* Read ISO and ISO2SW power down delays */ |
| 306 | val = readl_relaxed(gpc_base + GPC_PGC_GPU_PDNSCR); |
| 307 | iso = val & 0x3f; |
| 308 | iso2sw = (val >> 8) & 0x3f; |
| 309 | |
| 310 | /* Gate off PU domain when GPU/VPU when powered down */ |
| 311 | writel_relaxed(0x1, gpc_base + GPC_PGC_GPU_PDN); |
| 312 | |
| 313 | /* Request GPC to power down GPU/VPU */ |
| 314 | val = readl_relaxed(gpc_base + GPC_CNTR); |
| 315 | val |= GPU_VPU_PDN_REQ; |
| 316 | writel_relaxed(val, gpc_base + GPC_CNTR); |
| 317 | |
| 318 | /* Wait ISO + ISO2SW IPG clock cycles */ |
| 319 | ndelay((iso + iso2sw) * 1000 / 66); |
| 320 | } |
| 321 | |
| 322 | static int imx6q_pm_pu_power_off(struct generic_pm_domain *genpd) |
| 323 | { |
| 324 | struct pu_domain *pu = container_of(genpd, struct pu_domain, base); |
| 325 | |
| 326 | _imx6q_pm_pu_power_off(genpd); |
| 327 | |
| 328 | if (pu->reg) |
| 329 | regulator_disable(pu->reg); |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | static int imx6q_pm_pu_power_on(struct generic_pm_domain *genpd) |
| 335 | { |
| 336 | struct pu_domain *pu = container_of(genpd, struct pu_domain, base); |
| 337 | int i, ret, sw, sw2iso; |
| 338 | u32 val; |
| 339 | |
| 340 | if (pu->reg) |
| 341 | ret = regulator_enable(pu->reg); |
| 342 | if (pu->reg && ret) { |
| 343 | pr_err("%s: failed to enable regulator: %d\n", __func__, ret); |
| 344 | return ret; |
| 345 | } |
| 346 | |
| 347 | /* Enable reset clocks for all devices in the PU domain */ |
| 348 | for (i = 0; i < pu->num_clks; i++) |
| 349 | clk_prepare_enable(pu->clk[i]); |
| 350 | |
| 351 | /* Gate off PU domain when GPU/VPU when powered down */ |
| 352 | writel_relaxed(0x1, gpc_base + GPC_PGC_GPU_PDN); |
| 353 | |
| 354 | /* Read ISO and ISO2SW power down delays */ |
| 355 | val = readl_relaxed(gpc_base + GPC_PGC_GPU_PUPSCR); |
| 356 | sw = val & 0x3f; |
| 357 | sw2iso = (val >> 8) & 0x3f; |
| 358 | |
| 359 | /* Request GPC to power up GPU/VPU */ |
| 360 | val = readl_relaxed(gpc_base + GPC_CNTR); |
| 361 | val |= GPU_VPU_PUP_REQ; |
| 362 | writel_relaxed(val, gpc_base + GPC_CNTR); |
| 363 | |
| 364 | /* Wait ISO + ISO2SW IPG clock cycles */ |
| 365 | ndelay((sw + sw2iso) * 1000 / 66); |
| 366 | |
| 367 | /* Disable reset clocks for all devices in the PU domain */ |
| 368 | for (i = 0; i < pu->num_clks; i++) |
| 369 | clk_disable_unprepare(pu->clk[i]); |
| 370 | |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | static struct generic_pm_domain imx6q_arm_domain = { |
| 375 | .name = "ARM", |
| 376 | }; |
| 377 | |
| 378 | static struct pu_domain imx6q_pu_domain = { |
| 379 | .base = { |
| 380 | .name = "PU", |
| 381 | .power_off = imx6q_pm_pu_power_off, |
| 382 | .power_on = imx6q_pm_pu_power_on, |
Axel Haslam | eaa2d73 | 2016-02-15 11:10:52 +0100 | [diff] [blame] | 383 | .states = { |
| 384 | [0] = { |
| 385 | .power_off_latency_ns = 25000, |
| 386 | .power_on_latency_ns = 2000000, |
| 387 | }, |
| 388 | }, |
| 389 | .state_count = 1, |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 390 | }, |
| 391 | }; |
| 392 | |
| 393 | static struct generic_pm_domain imx6sl_display_domain = { |
| 394 | .name = "DISPLAY", |
| 395 | }; |
| 396 | |
| 397 | static struct generic_pm_domain *imx_gpc_domains[] = { |
| 398 | &imx6q_arm_domain, |
| 399 | &imx6q_pu_domain.base, |
| 400 | &imx6sl_display_domain, |
| 401 | }; |
| 402 | |
| 403 | static struct genpd_onecell_data imx_gpc_onecell_data = { |
| 404 | .domains = imx_gpc_domains, |
| 405 | .num_domains = ARRAY_SIZE(imx_gpc_domains), |
| 406 | }; |
| 407 | |
| 408 | static int imx_gpc_genpd_init(struct device *dev, struct regulator *pu_reg) |
| 409 | { |
| 410 | struct clk *clk; |
Fabio Estevam | f9d1f7a | 2016-10-22 10:20:56 -0200 | [diff] [blame] | 411 | int i, ret; |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 412 | |
| 413 | imx6q_pu_domain.reg = pu_reg; |
| 414 | |
| 415 | for (i = 0; ; i++) { |
| 416 | clk = of_clk_get(dev->of_node, i); |
| 417 | if (IS_ERR(clk)) |
| 418 | break; |
| 419 | if (i >= GPC_CLK_MAX) { |
| 420 | dev_err(dev, "more than %d clocks\n", GPC_CLK_MAX); |
| 421 | goto clk_err; |
| 422 | } |
| 423 | imx6q_pu_domain.clk[i] = clk; |
| 424 | } |
| 425 | imx6q_pu_domain.num_clks = i; |
| 426 | |
Lucas Stach | d438462 | 2015-06-30 14:48:24 +0200 | [diff] [blame] | 427 | /* Enable power always in case bootloader disabled it. */ |
| 428 | imx6q_pm_pu_power_on(&imx6q_pu_domain.base); |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 429 | |
Lucas Stach | d438462 | 2015-06-30 14:48:24 +0200 | [diff] [blame] | 430 | if (!IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS)) |
| 431 | return 0; |
| 432 | |
Fabio Estevam | eef0b28 | 2016-10-22 10:20:55 -0200 | [diff] [blame] | 433 | for (i = 0; i < ARRAY_SIZE(imx_gpc_domains); i++) |
| 434 | pm_genpd_init(imx_gpc_domains[i], NULL, false); |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 435 | |
Fabio Estevam | f9d1f7a | 2016-10-22 10:20:56 -0200 | [diff] [blame] | 436 | ret = of_genpd_add_provider_onecell(dev->of_node, |
| 437 | &imx_gpc_onecell_data); |
| 438 | if (ret) |
| 439 | goto power_off; |
| 440 | |
| 441 | return 0; |
| 442 | |
| 443 | power_off: |
| 444 | imx6q_pm_pu_power_off(&imx6q_pu_domain.base); |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 445 | clk_err: |
| 446 | while (i--) |
| 447 | clk_put(imx6q_pu_domain.clk[i]); |
Fabio Estevam | f9d1f7a | 2016-10-22 10:20:56 -0200 | [diff] [blame] | 448 | imx6q_pu_domain.reg = NULL; |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 449 | return -EINVAL; |
| 450 | } |
| 451 | |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 452 | static int imx_gpc_probe(struct platform_device *pdev) |
| 453 | { |
| 454 | struct regulator *pu_reg; |
| 455 | int ret; |
| 456 | |
Lucas Stach | b17c70c | 2015-05-27 10:10:26 +0200 | [diff] [blame] | 457 | /* bail out if DT too old and doesn't provide the necessary info */ |
| 458 | if (!of_property_read_bool(pdev->dev.of_node, "#power-domain-cells")) |
| 459 | return 0; |
| 460 | |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 461 | pu_reg = devm_regulator_get_optional(&pdev->dev, "pu"); |
| 462 | if (PTR_ERR(pu_reg) == -ENODEV) |
| 463 | pu_reg = NULL; |
| 464 | if (IS_ERR(pu_reg)) { |
| 465 | ret = PTR_ERR(pu_reg); |
| 466 | dev_err(&pdev->dev, "failed to get pu regulator: %d\n", ret); |
| 467 | return ret; |
| 468 | } |
| 469 | |
| 470 | return imx_gpc_genpd_init(&pdev->dev, pu_reg); |
| 471 | } |
| 472 | |
| 473 | static const struct of_device_id imx_gpc_dt_ids[] = { |
| 474 | { .compatible = "fsl,imx6q-gpc" }, |
| 475 | { .compatible = "fsl,imx6sl-gpc" }, |
| 476 | { } |
| 477 | }; |
| 478 | |
| 479 | static struct platform_driver imx_gpc_driver = { |
| 480 | .driver = { |
| 481 | .name = "imx-gpc", |
Philipp Zabel | 00eb60a8 | 2015-02-23 18:40:12 +0100 | [diff] [blame] | 482 | .of_match_table = imx_gpc_dt_ids, |
| 483 | }, |
| 484 | .probe = imx_gpc_probe, |
| 485 | }; |
| 486 | |
| 487 | static int __init imx_pgc_init(void) |
| 488 | { |
| 489 | return platform_driver_register(&imx_gpc_driver); |
| 490 | } |
| 491 | subsys_initcall(imx_pgc_init); |