summaryrefslogtreecommitdiff
path: root/arch/arm/mach-omap2/omap_hsi.c
blob: 72fdeb54c91ec3d684bc2e29435c39ae91165662 (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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
/*
 * arch/arm/mach-omap2/hsi.c
 *
 * HSI device definition
 *
 * Copyright (C) 2011 Texas Instruments, Inc.
 * Original Author: Sebastien JAN <s-jan@ti.com>
 * Original Author: Djamil ELAIDI <d-elaidi@ti.com>
 *
 * This package 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.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/err.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/gpio.h>
#include <linux/irq.h>
#include <linux/jiffies.h>
#include <linux/notifier.h>
#include <linux/hsi_driver_if.h>

#include <plat/omap_hsi.h>
#include <plat/omap_hwmod.h>
#include <plat/omap_device.h>
#include <plat/omap-pm.h>
#include <plat/dvfs.h>

#include <../drivers/omap_hsi/hsi_driver.h>
#include "clock.h"
#include "mux.h"
#include "control.h"
#include "pm.h"

#define OMAP_HSI_PLATFORM_DEVICE_DRIVER_NAME	"omap_hsi"
#define OMAP_HSI_PLATFORM_DEVICE_NAME		"omap_hsi.0"
#define OMAP_HSI_HWMOD_NAME			"hsi"
#define OMAP_HSI_HWMOD_CLASSNAME		"hsi"

#define HSI_SIGNALS_PER_PORT		8 /* 4 for C=>A and 4 for A=>C */

#ifdef CONFIG_OMAP_MUX
/* OMAP44xx MUX settings for HSI port 1 & 2 */
static struct omap_device_pad __initdata
			omap44xx_hsi_ports_pads[2][HSI_SIGNALS_PER_PORT] = {
	{
	/* OMAP44xx MUX settings for HSI port 1 */
		{
			.name = "hsi1_cawake",
			.flags  = OMAP_DEVICE_PAD_REMUX |
				  OMAP_DEVICE_PAD_WAKEUP,
			.enable = (OMAP_MUX_MODE1 | OMAP_PIN_INPUT_PULLDOWN) &
				  ~OMAP_WAKEUP_EN,
			.idle   = OMAP_MUX_MODE1 | OMAP_PIN_INPUT_PULLDOWN |
				  OMAP_WAKEUP_EN,
			.off    = OMAP_MUX_MODE1 | OMAP_PIN_OFF_NONE |
				  OMAP_WAKEUP_EN,
		},

		{
			.name = "hsi1_caflag",
			.enable = OMAP_MUX_MODE1 | \
				  OMAP_PIN_INPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi1_cadata",
			.enable = OMAP_MUX_MODE1 | \
				  OMAP_PIN_INPUT_PULLDOWN | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi1_acready",
			.enable = OMAP_MUX_MODE1 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_OUTPUT_LOW,
		},

		{
			.name = "hsi1_acwake",
			.enable = OMAP_MUX_MODE1 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi1_acdata",
			.enable = OMAP_MUX_MODE1 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi1_acflag",
			.enable = OMAP_MUX_MODE1 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi1_caready",
			.enable = OMAP_MUX_MODE1 | \
				  OMAP_PIN_INPUT | \
				  OMAP_PIN_OFF_NONE,
		},
	},

	/* OMAP44xx MUX settings for HSI port 2 */
	{
		{
			.name = "hsi2_cawake",
			.flags  = OMAP_DEVICE_PAD_REMUX |
				  OMAP_DEVICE_PAD_WAKEUP,
			.enable = (OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLDOWN) &
				  ~OMAP_WAKEUP_EN,
			.idle   = OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLDOWN |
				  OMAP_WAKEUP_EN,
			.off    = OMAP_MUX_MODE4 | OMAP_PIN_OFF_NONE |
				  OMAP_WAKEUP_EN,
		},

		{
			.name = "hsi2_caflag",
			.enable = OMAP_MUX_MODE4 | \
				  OMAP_PIN_INPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi2_cadata",
			.enable = OMAP_MUX_MODE4 | \
				  OMAP_PIN_INPUT_PULLDOWN | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi2_acready",
			.enable = OMAP_MUX_MODE4 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_OUTPUT_LOW,
		},

		{
			.name = "hsi2_acwake",
			.enable = OMAP_MUX_MODE4 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi2_acdata",
			.enable = OMAP_MUX_MODE4 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi2_acflag",
			.enable = OMAP_MUX_MODE4 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi2_caready",
			.enable = OMAP_MUX_MODE4 | \
				  OMAP_PIN_INPUT | \
				  OMAP_PIN_OFF_NONE,
		},
	},
};

/* OMAP54xx MUX settings for HSI port 1 & 2 */
/* CAUTION: Adding OMAP_DEVICE_PAD_REMUX flags for a pad will add it in the
 * dynamic pads list and will change the index of following cawake pads, so
 * increment the second parameter of the omap_hwmod_pad_route_irq() function
 * accordingly */
static struct omap_device_pad __initdata
			omap54xx_hsi_ports_pads[2][HSI_SIGNALS_PER_PORT] = {
	{
	/* OMAP54xx MUX settings for HSI port 1 */
		{
			.name = "hsi1_cawake",
			.flags  = OMAP_DEVICE_PAD_REMUX |
				  OMAP_DEVICE_PAD_WAKEUP,
			.enable = (OMAP_MUX_MODE0 | OMAP_PIN_INPUT_PULLDOWN) &
				  ~OMAP_WAKEUP_EN,
			.idle   = OMAP_MUX_MODE0 | OMAP_PIN_INPUT_PULLDOWN |
				  OMAP_WAKEUP_EN,
			.off    = OMAP_MUX_MODE0 | OMAP_PIN_OFF_NONE |
				  OMAP_WAKEUP_EN,
		},

		{
			.name = "hsi1_caflag",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_INPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi1_cadata",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_INPUT_PULLDOWN | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi1_acready",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_OUTPUT_LOW,
		},

		{
			.name = "hsi1_acwake",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi1_acdata",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi1_acflag",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi1_caready",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_INPUT | \
				  OMAP_PIN_OFF_NONE,
		},
	},

	/* OMAP54xx MUX settings for HSI port 2 */
	{
		{
			.name = "hsi2_cawake",
			.flags  = OMAP_DEVICE_PAD_REMUX |
				  OMAP_DEVICE_PAD_WAKEUP,
			.enable = (OMAP_MUX_MODE0 | OMAP_PIN_INPUT_PULLDOWN) &
				  ~OMAP_WAKEUP_EN,
			.idle   = OMAP_MUX_MODE0 | OMAP_PIN_INPUT_PULLDOWN |
				  OMAP_WAKEUP_EN,
			.off    = OMAP_MUX_MODE0 | OMAP_PIN_OFF_NONE |
				  OMAP_WAKEUP_EN,
		},

		{
			.name = "hsi2_caflag",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_INPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi2_cadata",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_INPUT_PULLDOWN | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi2_acready",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_OUTPUT_LOW,
		},

		{
			.name = "hsi2_acwake",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi2_acdata",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi2_acflag",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_OUTPUT | \
				  OMAP_PIN_OFF_NONE,
		},

		{
			.name = "hsi2_caready",
			.enable = OMAP_MUX_MODE0 | \
				  OMAP_PIN_INPUT | \
				  OMAP_PIN_OFF_NONE,
		},
	},
};

static struct omap_hwmod_mux_info * __init
omap_hsi_fill_default_pads(struct hsi_platform_data *pdata)
{
	struct omap_device_pad	*pads_to_mux;
	struct omap_device_pad	(*omap_pads)[HSI_SIGNALS_PER_PORT];

	if ((pdata->ctx->pctx[0].port_number > 2) ||
	    ((pdata->num_ports == 2) &&
	     (pdata->ctx->pctx[1].port_number > 2)) ||
	     (pdata->num_ports > 2)) {
		pr_err("%s: invalid port info\n", __func__);
		return NULL;
	}

	if (cpu_is_omap44xx())
		omap_pads = omap44xx_hsi_ports_pads;
	else if (cpu_is_omap54xx())
		omap_pads = omap54xx_hsi_ports_pads;
	else
		return NULL;

	if (pdata->num_ports == 1) {
		/* Mux only port corresponding to first index */
		pads_to_mux =
			&omap_pads[pdata->ctx->pctx[0].port_number - 1][0];
		pr_info("%s: Muxed hsi port %d\n", __func__,
			pdata->ctx->pctx[0].port_number);
	} else if (pdata->num_ports == 2) {
		/* Mux all ports */
		pads_to_mux = &omap_pads[0][0];
		pr_info("%s: Muxed hsi ports 1 & 2\n", __func__);
	} else {
		pr_err("%s: invalid port number %d\n", __func__,
			pdata->num_ports);
		return NULL;
	}

	return omap_hwmod_mux_init(pads_to_mux, pdata->num_ports * \
							HSI_SIGNALS_PER_PORT);
}
#else
static struct omap_hwmod_mux_info * __init
omap_hsi_fill_default_pads(struct hsi_platform_data *pdata)
{
	return NULL;
}
#endif

/*
 * NOTE: We abuse a little bit the struct port_ctx to use it also for
 * initialization.
 */
static struct hsi_port_ctx omap_hsi_port_ctx[] = {
	[0] = {
	       .port_number = 2,
	       .hst.mode = HSI_MODE_FRAME,
	       .hst.frame_size = HSI_FRAMESIZE_DEFAULT,
	       .hst.divisor = HSI_DIVISOR_DEFAULT,
	       .hst.channels = HSI_CHANNELS_DEFAULT,
	       .hst.arb_mode = HSI_ARBMODE_ROUNDROBIN,
	       .hsr.mode = HSI_MODE_FRAME,
	       .hsr.flow = HSI_FLOW_SYNCHRONIZED,
	       .hsr.frame_size = HSI_FRAMESIZE_DEFAULT,
	       .hsr.channels = HSI_CHANNELS_DEFAULT,
	       .hsr.divisor = HSI_DIVISOR_DEFAULT,
	       .hsr.counters = HSI_COUNTERS_FT_DEFAULT |
			       HSI_COUNTERS_TB_DEFAULT |
			       HSI_COUNTERS_FB_DEFAULT,
	       },
};

static struct hsi_ctrl_ctx omap_hsi_ctrl_ctx = {
		.sysconfig = 0,
		.gdd_gcr = 0,
		.pctx = omap_hsi_port_ctx,
};

static struct hsi_platform_data omap_hsi_platform_data = {
	.num_ports = ARRAY_SIZE(omap_hsi_port_ctx),
	.hsi_gdd_chan_count = HSI_HSI_DMA_CHANNEL_MAX,
	.default_hsi_fclk = HSI_DEFAULT_FCLK,
	.fifo_mapping_strategy = HSI_FIFO_MAPPING_ALL_PORT2,
	.ctx = &omap_hsi_ctrl_ctx,
	.ssi_cawake_gpio = -1, /* If using SSI, define CAWAKE GPIO used here */
	.device_enable = omap_device_enable,
	.device_idle = omap_device_idle,
	.device_shutdown = omap_device_shutdown,
	.device_scale = omap_device_scale,
	.get_context_loss_count = omap_pm_get_dev_context_loss_count,

};

static u32 omap_hsi_configure_errata(void)
{
	u32 errata = 0;

	if (cpu_is_omap44xx())
		SET_HSI_ERRATA(errata, HSI_ERRATUM_ixxx_3WIRES_NO_SWAKEUP);

	if (cpu_is_omap44xx() ||
	    (cpu_is_omap54xx() && (omap_rev() <= OMAP5430_REV_ES1_0))) {
		SET_HSI_ERRATA(errata, HSI_ERRATUM_i696_SW_RESET_FSM_STUCK);
		SET_HSI_ERRATA(errata, HSI_ERRATUM_i702_PM_HSI_SWAKEUP);
	}

	return errata;
}

/* HSI_TODO : This requires some fine tuning & completion of
 * activate/deactivate latency values
 */
static struct omap_device_pm_latency omap_hsi_latency[] = {
	[0] = {
	       .deactivate_func = omap_device_idle_hwmods,
	       .activate_func = omap_device_enable_hwmods,
	       .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
	       },
};

/* HSI device registration */
static int __init omap_hsi_register(struct omap_hwmod *oh, void *user)
{
	struct platform_device *od;
	struct hsi_platform_data *pdata = &omap_hsi_platform_data;
	int i, port, err;

	if (!oh) {
		pr_err("Could not look up %s omap_hwmod\n",
		       OMAP_HSI_HWMOD_NAME);
		return -EEXIST;
	}

	omap_hsi_platform_data.errata = omap_hsi_configure_errata();

	oh->mux = omap_hsi_fill_default_pads(pdata);

	for (i = 0; i < pdata->num_ports; i++) {
		port = pdata->ctx->pctx[i].port_number - 1;
		err = omap_hwmod_pad_route_irq(oh, i, port);
		if (err < 0) {
			pr_err("%s: Could not route the IO PAD wakeup event on IRQ %d for the port %d, error = %d\n",
				__func__, oh->mpu_irqs[i].irq, port + 1, err);
			return err;
		}
	}

	od = omap_device_build(OMAP_HSI_PLATFORM_DEVICE_DRIVER_NAME, 0, oh,
			       pdata, sizeof(*pdata), omap_hsi_latency,
			       ARRAY_SIZE(omap_hsi_latency), false);
	WARN(IS_ERR(od), "Can't build omap_device for %s:%s.\n",
	     OMAP_HSI_PLATFORM_DEVICE_DRIVER_NAME, oh->name);

	pr_info("HSI: device registered as omap_hwmod: %s\n", oh->name);
	return 0;
}

int __init omap_hsi_dev_init(void)
{
	/* Keep this for genericity, although there is only one hwmod for HSI */
	return omap_hwmod_for_each_by_class(OMAP_HSI_HWMOD_CLASSNAME,
					    omap_hsi_register, NULL);
}