Patrick Wildt | d08a194 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright 2017 NXP |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <power-domain-uclass.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/power-domain.h> |
| 11 | #include <asm/mach-imx/sys_proto.h> |
| 12 | #include <dm/device-internal.h> |
| 13 | #include <dm/device.h> |
| 14 | #include <imx_sip.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | static int imx8m_power_domain_request(struct power_domain *power_domain) |
| 19 | { |
| 20 | return 0; |
| 21 | } |
| 22 | |
| 23 | static int imx8m_power_domain_free(struct power_domain *power_domain) |
| 24 | { |
| 25 | return 0; |
| 26 | } |
| 27 | |
| 28 | static int imx8m_power_domain_on(struct power_domain *power_domain) |
| 29 | { |
| 30 | struct udevice *dev = power_domain->dev; |
| 31 | struct imx8m_power_domain_platdata *pdata; |
| 32 | pdata = dev_get_platdata(dev); |
| 33 | |
| 34 | if (pdata->resource_id < 0) |
| 35 | return -EINVAL; |
| 36 | |
| 37 | if (pdata->has_pd) |
| 38 | power_domain_on(&pdata->pd); |
| 39 | |
| 40 | call_imx_sip(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN, pdata->resource_id, 1); |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static int imx8m_power_domain_off(struct power_domain *power_domain) |
| 46 | { |
| 47 | struct udevice *dev = power_domain->dev; |
| 48 | struct imx8m_power_domain_platdata *pdata; |
| 49 | pdata = dev_get_platdata(dev); |
| 50 | |
| 51 | if (pdata->resource_id < 0) |
| 52 | return -EINVAL; |
| 53 | |
| 54 | call_imx_sip(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN, pdata->resource_id, 0); |
| 55 | |
| 56 | if (pdata->has_pd) |
| 57 | power_domain_off(&pdata->pd); |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | static int imx8m_power_domain_of_xlate(struct power_domain *power_domain, |
| 63 | struct ofnode_phandle_args *args) |
| 64 | { |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static int imx8m_power_domain_bind(struct udevice *dev) |
| 69 | { |
| 70 | int offset; |
| 71 | const char *name; |
| 72 | int ret = 0; |
| 73 | |
| 74 | offset = dev_of_offset(dev); |
| 75 | for (offset = fdt_first_subnode(gd->fdt_blob, offset); offset > 0; |
| 76 | offset = fdt_next_subnode(gd->fdt_blob, offset)) { |
| 77 | /* Bind the subnode to this driver */ |
| 78 | name = fdt_get_name(gd->fdt_blob, offset, NULL); |
| 79 | |
| 80 | ret = device_bind_with_driver_data(dev, dev->driver, name, |
| 81 | dev->driver_data, |
| 82 | offset_to_ofnode(offset), |
| 83 | NULL); |
| 84 | |
| 85 | if (ret == -ENODEV) |
| 86 | printf("Driver '%s' refuses to bind\n", |
| 87 | dev->driver->name); |
| 88 | |
| 89 | if (ret) |
| 90 | printf("Error binding driver '%s': %d\n", |
| 91 | dev->driver->name, ret); |
| 92 | } |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static int imx8m_power_domain_probe(struct udevice *dev) |
| 98 | { |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static int imx8m_power_domain_ofdata_to_platdata(struct udevice *dev) |
| 103 | { |
| 104 | struct imx8m_power_domain_platdata *pdata = dev_get_platdata(dev); |
| 105 | |
| 106 | pdata->resource_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
| 107 | "reg", -1); |
| 108 | |
| 109 | if (!power_domain_get(dev, &pdata->pd)) |
| 110 | pdata->has_pd = 1; |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static const struct udevice_id imx8m_power_domain_ids[] = { |
| 116 | { .compatible = "fsl,imx8mq-gpc" }, |
| 117 | { } |
| 118 | }; |
| 119 | |
| 120 | struct power_domain_ops imx8m_power_domain_ops = { |
| 121 | .request = imx8m_power_domain_request, |
| 122 | .free = imx8m_power_domain_free, |
| 123 | .on = imx8m_power_domain_on, |
| 124 | .off = imx8m_power_domain_off, |
| 125 | .of_xlate = imx8m_power_domain_of_xlate, |
| 126 | }; |
| 127 | |
| 128 | U_BOOT_DRIVER(imx8m_power_domain) = { |
| 129 | .name = "imx8m_power_domain", |
| 130 | .id = UCLASS_POWER_DOMAIN, |
| 131 | .of_match = imx8m_power_domain_ids, |
| 132 | .bind = imx8m_power_domain_bind, |
| 133 | .probe = imx8m_power_domain_probe, |
| 134 | .ofdata_to_platdata = imx8m_power_domain_ofdata_to_platdata, |
| 135 | .platdata_auto_alloc_size = sizeof(struct imx8m_power_domain_platdata), |
| 136 | .ops = &imx8m_power_domain_ops, |
| 137 | }; |