summaryrefslogtreecommitdiff
path: root/arch/arm/mach-omap2/ipu_dev.c
blob: 8ffbfc409074035bc34fef3e5c62e1e094872574 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/**
 * linux/arch/arm/mach-omap2/ipu_dev.c
 *
 * Copyright (C) 2010 Texas Instruments, Inc.
 * Paul Hunt <hunt@ti.com>
 *
 * OMAP4 Image Processing Unit
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/err.h>

#include <mach/irqs.h>
#include <plat/omap_hwmod.h>
#include <plat/common.h>
#include <plat/omap_device.h>
#include <plat/omap-pm.h>
#include <linux/platform_device.h>
#include <plat/remoteproc.h>

#include <plat/ipu_dev.h>

#include "../../../drivers/dsp/syslink/ipu_pm/ipu_pm.h"

#define IPU_DRIVER_NAME "omap-ipu-pm"
#define ISS_IPU_BUS_ID 0
#define IVA_IPU_BUS_ID 1

struct omap_ipupm_mod_platform_data *ipupm_get_plat_data(void);

static char *hwmod_state_strings[] = {
	"_HWMOD_STATE_UNKNOWN",
	"_HWMOD_STATE_REGISTERED",
	"_HWMOD_STATE_CLKS_INITED",
	"_HWMOD_STATE_INITIALIZED",
	"_HWMOD_STATE_ENABLED",
	"_HWMOD_STATE_IDLE",
	"_HWMOD_STATE_DISABLED",
};
static void print_hwmod_state(struct omap_hwmod *oh, char *desc)
{
	u32 _state = (u32) oh->_state;
	pr_debug("HWMOD name = %s\n", oh->name);
	if (_state > _HWMOD_STATE_LAST)
		WARN(1, "Illegal hwmod _state = %d\n", _state);
	else
		pr_debug("%s state = %s\n", desc, hwmod_state_strings[_state]);
}

inline int ipu_pm_module_start(unsigned rsrc)
{
	int ret;
	struct omap_ipupm_mod_platform_data *pd;

	pd = ipupm_get_plat_data();

	print_hwmod_state(pd[rsrc].oh, "Previous");
	ret = omap_device_enable(pd[rsrc].pdev);
	if (ret)
		pr_err("device enable failed %s", pd[rsrc].oh_name);
	print_hwmod_state(pd[rsrc].oh, "New");
	return ret;
}
EXPORT_SYMBOL(ipu_pm_module_start);

inline int ipu_pm_module_stop(unsigned rsrc)
{
	int ret;
	struct omap_ipupm_mod_platform_data *pd;

	pd = ipupm_get_plat_data();

	print_hwmod_state(pd[rsrc].oh, "Previous");
	ret = omap_device_shutdown(pd[rsrc].pdev);
	print_hwmod_state(pd[rsrc].oh, "New");

	if (ret)
		pr_err("device disable failed %s", pd[rsrc].oh_name);

	return ret;
}
EXPORT_SYMBOL(ipu_pm_module_stop);

inline int ipu_pm_module_set_rate(unsigned rsrc,
				  unsigned target_rsrc,
				  unsigned rate)
{
	int ret = 0;
	unsigned target;
	struct device *dp;
	struct omap_ipupm_mod_platform_data *pd;

	pd = ipupm_get_plat_data();

	if (target_rsrc == IPU_PM_MPU)
		dp = omap2_get_mpuss_device();
	else if (target_rsrc == IPU_PM_CORE)
		dp = omap2_get_l3_device();
	else {
		if (target_rsrc == IPU_PM_SELF)
			target = rsrc;
		else
			target = target_rsrc;

		if ((pd[target].caps & IPUPM_CAPS_PERF) == 0) {
			pr_err("device set rate not supported for %s",
				pd[target].oh_name);
			ret = -EINVAL;
			goto err_ret;
		} else
			dp = pd[target].dev;
	}
#ifdef CONFIG_OMAP_PM
	ret = omap_device_set_rate(pd[rsrc].dev, dp, rate);
#endif
	if (ret)
		pr_err("device set rate failed %s", pd[target_rsrc].oh_name);
err_ret:
	return ret;
}
EXPORT_SYMBOL(ipu_pm_module_set_rate);

inline int ipu_pm_module_set_latency(unsigned rsrc,
				     unsigned target_rsrc,
				     int latency)
{
	int ret = 0;
	unsigned target;
	struct omap_ipupm_mod_platform_data *pd;

	pd = ipupm_get_plat_data();

	if (target_rsrc == IPU_PM_MPU) {
#ifdef CONFIG_OMAP_PM
		ret = omap_pm_set_max_mpu_wakeup_lat(&pd[rsrc].qos_request,
						     latency);
#endif
		if (ret)
			goto err_ret;
	} else if (target_rsrc == IPU_PM_CORE) {
#ifdef CONFIG_OMAP_PM
		ret = omap_pm_set_max_sdma_lat(&pd[rsrc].qos_request,
					       latency);
#endif
		if (ret)
			goto err_ret;
	} else {
		if (target_rsrc == IPU_PM_SELF)
			target = rsrc;
		else
			target = target_rsrc;

		if ((pd[target].caps & IPUPM_CAPS_LAT) == 0) {
			pr_err("device set latency not supported for %s",
				pd[target].oh_name);
			ret = -EINVAL;
		} else {
#ifdef CONFIG_OMAP_PM
			ret = omap_pm_set_max_dev_wakeup_lat(pd[rsrc].dev,
							     pd[target].dev,
							     latency);
#endif
		}
	}

	if (ret)
		pr_err("module set latency failed %s", pd[target].oh_name);
err_ret:
	return ret;
}
EXPORT_SYMBOL(ipu_pm_module_set_latency);

inline int ipu_pm_module_set_bandwidth(unsigned rsrc,
				       unsigned target_rsrc,
				       int bandwidth)
{
	int ret = 0;
	struct omap_ipupm_mod_platform_data *pd;

	pd = ipupm_get_plat_data();

	if ((pd[target_rsrc].caps & IPUPM_CAPS_BDW) == 0) {
		pr_err("device set bandwidth not supported for %s",
			pd[target_rsrc].oh_name);
		ret = -EINVAL;
	} else {
#ifdef CONFIG_OMAP_PM
		struct device *dp;
		dp = omap2_get_l3_device();
		ret = omap_pm_set_min_bus_tput(dp,
					       OCP_INITIATOR_AGENT,
					       bandwidth);
#endif
	}

	if (ret)
		pr_err("module set bandwidth failed %s",
						pd[target_rsrc].oh_name);
	return ret;
}
EXPORT_SYMBOL(ipu_pm_module_set_bandwidth);

/* FIXME: not in use now
 * static struct omap_ipupm_mod_ops omap_ipu_ops = {
 *	.start = NULL,
 *	.stop = NULL,
 * };
 *
 * static struct omap_ipupm_mod_ops omap_ipu0_ops = {
 *	.start = NULL,
 *	.stop = NULL,
 * };
 *
 * static struct omap_ipupm_mod_ops omap_ipu1_ops = {
 *	.start = NULL,
 *	.stop = NULL,
 * };
 */

/* ipupm generic operations */
static struct omap_ipupm_mod_ops omap_ipupm_ops = {
	.start = NULL,
	.stop = NULL,
};

static struct omap_ipupm_mod_platform_data omap_ipupm_data[] = {
	{
		.name = "omap-ipu-pm",
		.oh_name = "fdif",
		.caps = IPUPM_CAPS_START | IPUPM_CAPS_STOP
			| IPUPM_CAPS_PERF | IPUPM_CAPS_LAT,
		.ops = &omap_ipupm_ops,
	},
	{
		.name = "omap-ipu-pm",
		.oh_name = "ipu",
		.caps = IPUPM_CAPS_START | IPUPM_CAPS_STOP
			| IPUPM_CAPS_PERF | IPUPM_CAPS_LAT
			| IPUPM_CAPS_EXTINIT,
		.ops = &omap_ipupm_ops,
	},
	{
		.name = "omap-ipu-pm",
		.oh_name = "ipu_c0",
		.caps = IPUPM_CAPS_START | IPUPM_CAPS_STOP
			| IPUPM_CAPS_EXTINIT,
		.ops = &omap_ipupm_ops,
	},
	{
		.name = "omap-ipu-pm",
		.oh_name = "ipu_c1",
		.caps = IPUPM_CAPS_START | IPUPM_CAPS_STOP
			| IPUPM_CAPS_EXTINIT,
		.ops = &omap_ipupm_ops,
	},
	{
		.name = "omap-ipu-pm",
		.oh_name = "iss",
		.caps = IPUPM_CAPS_START | IPUPM_CAPS_STOP
			| IPUPM_CAPS_PERF | IPUPM_CAPS_LAT,
		.ops = &omap_ipupm_ops,
	},
	{
		.name = "omap-ipu-pm",
		.oh_name = "iva",
		.caps = IPUPM_CAPS_START | IPUPM_CAPS_STOP
			| IPUPM_CAPS_PERF | IPUPM_CAPS_LAT,
		.ops = &omap_ipupm_ops,
	},
	{
		.name = "omap-ipu-pm",
		.oh_name = "iva_seq0",
		.caps = IPUPM_CAPS_START | IPUPM_CAPS_STOP,
		.ops = &omap_ipupm_ops,
	},
	{
		.name = "omap-ipu-pm",
		.oh_name = "iva_seq1",
		.caps = IPUPM_CAPS_START | IPUPM_CAPS_STOP,
		.ops = &omap_ipupm_ops,
	},
	{
		.name = "omap-ipu-pm",
		.oh_name = "l3_main_1",
		.caps = IPUPM_CAPS_LAT | IPUPM_CAPS_BDW
			| IPUPM_CAPS_EXTINIT,
		.ops = &omap_ipupm_ops,
	},
	{
		.name = "omap-ipu-pm",
		.oh_name = "mpu",
		.caps = IPUPM_CAPS_PERF | IPUPM_CAPS_LAT
			| IPUPM_CAPS_EXTINIT,
		.ops = &omap_ipupm_ops,
	},
	{
		.name = "omap-ipu-pm",
		.oh_name = "sl2if",
		.caps = IPUPM_CAPS_START | IPUPM_CAPS_STOP,
		.ops = &omap_ipupm_ops,
	},
	{
		.name = "omap-ipu-pm",
		.oh_name = "dsp",
		.caps = IPUPM_CAPS_START | IPUPM_CAPS_STOP
			| IPUPM_CAPS_PERF | IPUPM_CAPS_LAT
			| IPUPM_CAPS_EXTINIT,
		.ops = &omap_ipupm_ops,
	},
};

struct omap_ipupm_mod_platform_data *ipupm_get_plat_data(void)
{
	return omap_ipupm_data;
}
EXPORT_SYMBOL(ipupm_get_plat_data);

static struct omap_device_pm_latency omap_ipupm_latency[] = {
	{
		.deactivate_func = omap_device_idle_hwmods,
		.activate_func	 = omap_device_enable_hwmods,
		.flags		 = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
	},
};

static int __init omap_ipussdev_init(void)
{
	int status = -ENODEV;
	int i;
	int first = 1;
	struct omap_hwmod *oh;
	struct omap_device *od;
	char *oh_name;
	char *pdev_name = IPU_DRIVER_NAME;
	struct omap_device_pm_latency *ohl = omap_ipupm_latency;
	int ohl_cnt = ARRAY_SIZE(omap_ipupm_latency);

	for (i = 0; i < ARRAY_SIZE(omap_ipupm_data); i++) {
		oh_name = omap_ipupm_data[i].oh_name;

		if (omap_ipupm_data[i].caps & IPUPM_CAPS_EXTINIT)
			continue;

		oh = omap_hwmod_lookup(oh_name);
		if (!oh) {
			pr_err("%s: could not look up %s\n", __func__, oh_name);

			continue; /* to allow init to continue with other IPs
			* we probably do not want to completely stop progress
			* due to one module anyway, but need to be able to
			* not try to use it if init fails
			* this was put in to handle disabled hwmods
			*/

			status = -ENODEV;
			goto err_init;
		}
		omap_ipupm_data[i].oh = oh;

		od = omap_device_build(pdev_name, IVA_IPU_BUS_ID+i, oh,
				    &omap_ipupm_data[i],
				    sizeof(struct omap_ipupm_mod_platform_data),
				    ohl, ohl_cnt, false);

		status = IS_ERR(od);
		WARN(status, "Could not build omap_device for %s %s\n",
							pdev_name, oh_name);
		if (!status) {
			/* Save the id of the first registered dev */
			if (first) {
				ipu_pm_first_dev = od->pdev.id;
				first = 0;
			}
			omap_ipupm_data[i].pdev = &od->pdev;
			omap_ipupm_data[i].dev = &od->pdev.dev;
		}
	}

err_init:
	return status;
}

arch_initcall(omap_ipussdev_init);