1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2016-2018, 2020-2021 The Linux Foundation. All rights reserved.
4 * Copyright (C) 2013 Red Hat
5 * Author: Rob Clark <robdclark@gmail.com>
8 #include <linux/interconnect.h>
17 struct clk *msm_clk_bulk_get_clock(struct clk_bulk_data *bulk, int count,
23 snprintf(n, sizeof(n), "%s_clk", name);
25 for (i = 0; bulk && i < count; i++) {
26 if (!strcmp(bulk[i].id, name) || !strcmp(bulk[i].id, n))
34 struct clk *msm_clk_get(struct platform_device *pdev, const char *name)
39 clk = devm_clk_get(&pdev->dev, name);
40 if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
43 snprintf(name2, sizeof(name2), "%s_clk", name);
45 clk = devm_clk_get(&pdev->dev, name2);
47 dev_warn(&pdev->dev, "Using legacy clk name binding. Use "
48 "\"%s\" instead of \"%s\"\n", name, name2);
53 static void __iomem *_msm_ioremap(struct platform_device *pdev, const char *name,
54 bool quiet, phys_addr_t *psize)
61 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
63 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
67 DRM_DEV_ERROR(&pdev->dev, "failed to get memory resource: %s\n", name);
68 return ERR_PTR(-EINVAL);
71 size = resource_size(res);
73 ptr = devm_ioremap(&pdev->dev, res->start, size);
76 DRM_DEV_ERROR(&pdev->dev, "failed to ioremap: %s\n", name);
77 return ERR_PTR(-ENOMEM);
86 void __iomem *msm_ioremap(struct platform_device *pdev, const char *name)
88 return _msm_ioremap(pdev, name, false, NULL);
91 void __iomem *msm_ioremap_quiet(struct platform_device *pdev, const char *name)
93 return _msm_ioremap(pdev, name, true, NULL);
96 void __iomem *msm_ioremap_size(struct platform_device *pdev, const char *name,
99 return _msm_ioremap(pdev, name, false, psize);
102 static enum hrtimer_restart msm_hrtimer_worktimer(struct hrtimer *t)
104 struct msm_hrtimer_work *work = container_of(t,
105 struct msm_hrtimer_work, timer);
107 kthread_queue_work(work->worker, &work->work);
109 return HRTIMER_NORESTART;
112 void msm_hrtimer_queue_work(struct msm_hrtimer_work *work,
114 enum hrtimer_mode mode)
116 hrtimer_start(&work->timer, wakeup_time, mode);
119 void msm_hrtimer_work_init(struct msm_hrtimer_work *work,
120 struct kthread_worker *worker,
121 kthread_work_func_t fn,
123 enum hrtimer_mode mode)
125 hrtimer_init(&work->timer, clock_id, mode);
126 work->timer.function = msm_hrtimer_worktimer;
127 work->worker = worker;
128 kthread_init_work(&work->work, fn);
131 struct icc_path *msm_icc_get(struct device *dev, const char *name)
133 struct device *mdss_dev = dev->parent;
134 struct icc_path *path;
136 path = of_icc_get(dev, name);
141 * If there are no interconnects attached to the corresponding device
142 * node, of_icc_get() will return NULL.
144 * If the MDP5/DPU device node doesn't have interconnects, lookup the
145 * path in the parent (MDSS) device.
147 return of_icc_get(mdss_dev, name);