summaryrefslogtreecommitdiffstats
path: root/arch/mips/basler/excite/excite_device.c
blob: e00bc2d7f3018562b52a78e360cd559800af114f (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
/*
 *  Copyright (C) 2004 by Basler Vision Technologies AG
 *  Author: Thomas Koeller <thomas.koeller@baslerweb.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/ioport.h>
#include <linux/err.h>
#include <linux/jiffies.h>
#include <linux/sched.h>
#include <asm/types.h>
#include <asm/rm9k-ocd.h>

#include <excite.h>
#include <rm9k_eth.h>
#include <rm9k_wdt.h>
#include <rm9k_xicap.h>
#include <excite_nandflash.h>

#include "excite_iodev.h"

#define RM9K_GE_UNIT	0
#define XICAP_UNIT	0
#define NAND_UNIT	0

#define DLL_TIMEOUT	3		/* seconds */


#define RINIT(__start__, __end__, __name__, __parent__) {	\
	.name	= __name__ "_0",				\
	.start	= (__start__),					\
	.end	= (__end__),					\
	.flags	= 0,						\
	.parent	= (__parent__)					\
}

#define RINIT_IRQ(__irq__, __name__) {	\
	.name	= __name__ "_0",	\
	.start	= (__irq__),		\
	.end	= (__irq__),		\
	.flags	= IORESOURCE_IRQ,	\
	.parent	= NULL			\
}



enum {
	slice_xicap,
	slice_eth
};



static struct resource
	excite_ctr_resource __maybe_unused = {
		.name		= "GPI counters",
		.start		= 0,
		.end		= 5,
		.flags		= 0,
		.parent		= NULL,
		.sibling	= NULL,
		.child		= NULL
	},
	excite_gpislice_resource __maybe_unused = {
		.name		= "GPI slices",
		.start		= 0,
		.end		= 1,
		.flags		= 0,
		.parent		= NULL,
		.sibling	= NULL,
		.child		= NULL
	},
	excite_mdio_channel_resource __maybe_unused = {
		.name		= "MDIO channels",
		.start		= 0,
		.end		= 1,
		.flags		= 0,
		.parent		= NULL,
		.sibling	= NULL,
		.child		= NULL
	},
	excite_fifomem_resource __maybe_unused = {
		.name		= "FIFO memory",
		.start		= 0,
		.end		= 767,
		.flags		= 0,
		.parent		= NULL,
		.sibling	= NULL,
		.child		= NULL
	},
	excite_scram_resource __maybe_unused = {
		.name		= "Scratch RAM",
		.start		= EXCITE_PHYS_SCRAM,
		.end		= EXCITE_PHYS_SCRAM + EXCITE_SIZE_SCRAM - 1,
		.flags		= IORESOURCE_MEM,
		.parent		= NULL,
		.sibling	= NULL,
		.child		= NULL
	},
	excite_fpga_resource __maybe_unused = {
		.name		= "System FPGA",
		.start		= EXCITE_PHYS_FPGA,
		.end		= EXCITE_PHYS_FPGA + EXCITE_SIZE_FPGA - 1,
		.flags		= IORESOURCE_MEM,
		.parent		= NULL,
		.sibling	= NULL,
		.child		= NULL
	},
	excite_nand_resource __maybe_unused = {
		.name		= "NAND flash control",
		.start		= EXCITE_PHYS_NAND,
		.end		= EXCITE_PHYS_NAND + EXCITE_SIZE_NAND - 1,
		.flags		= IORESOURCE_MEM,
		.parent		= NULL,
		.sibling	= NULL,
		.child		= NULL
	},
	excite_titan_resource __maybe_unused = {
		.name		= "TITAN registers",
		.start		= EXCITE_PHYS_TITAN,
		.end		= EXCITE_PHYS_TITAN + EXCITE_SIZE_TITAN - 1,
		.flags		= IORESOURCE_MEM,
		.parent		= NULL,
		.sibling	= NULL,
		.child		= NULL
	};



static void adjust_resources(struct resource *res, unsigned int n)
{
	struct resource *p;
	const unsigned long mask = IORESOURCE_IO | IORESOURCE_MEM
				   | IORESOURCE_IRQ | IORESOURCE_DMA;

	for (p = res; p < res + n; p++) {
		const struct resource * const parent = p->parent;
		if (parent) {
			p->start += parent->start;
			p->end   += parent->start;
			p->flags =  parent->flags & mask;
		}
	}
}



#if defined(CONFIG_EXCITE_FCAP_GPI) || defined(CONFIG_EXCITE_FCAP_GPI_MODULE)
static struct resource xicap_rsrc[] = {
	RINIT(0x4840, 0x486f, XICAP_RESOURCE_FIFO_RX, &excite_titan_resource),
	RINIT(0x4940, 0x494b, XICAP_RESOURCE_FIFO_TX, &excite_titan_resource),
	RINIT(0x5040, 0x5127, XICAP_RESOURCE_XDMA, &excite_titan_resource),
	RINIT(0x1000, 0x112f, XICAP_RESOURCE_PKTPROC, &excite_titan_resource),
	RINIT(0x1100, 0x110f, XICAP_RESOURCE_PKT_STREAM, &excite_fpga_resource),
	RINIT(0x0800, 0x0bff, XICAP_RESOURCE_DMADESC, &excite_scram_resource),
	RINIT(slice_xicap, slice_xicap, XICAP_RESOURCE_GPI_SLICE, &excite_gpislice_resource),
	RINIT(0x0100, 0x02ff, XICAP_RESOURCE_FIFO_BLK, &excite_fifomem_resource),
	RINIT_IRQ(TITAN_IRQ,  XICAP_RESOURCE_IRQ)
};

static struct platform_device xicap_pdev = {
	.name		= XICAP_NAME,
	.id		= XICAP_UNIT,
	.num_resources	= ARRAY_SIZE(xicap_rsrc),
	.resource	= xicap_rsrc
};

/*
 * Create a platform device for the GPI port that receives the
 * image data from the embedded camera.
 */
static int __init xicap_devinit(void)
{
	unsigned long tend;
	u32 reg;
	int retval;

	adjust_resources(xicap_rsrc, ARRAY_SIZE(xicap_rsrc));

	/* Power up the slice and configure it. */
	reg = titan_readl(CPTC1R);
	reg &= ~(0x11100 << slice_xicap);
	titan_writel(reg, CPTC1R);

	/* Enable slice & DLL. */
	reg= titan_readl(CPRR);
	reg &= ~(0x00030003 << (slice_xicap * 2));
	titan_writel(reg, CPRR);

	/* Wait for DLLs to lock */
	tend = jiffies + DLL_TIMEOUT * HZ;
	while (time_before(jiffies, tend)) {
		if (!(~titan_readl(CPDSR) & (0x1 << (slice_xicap * 4))))
			break;
		yield();
	}

	if (~titan_readl(CPDSR) & (0x1 << (slice_xicap * 4))) {
		printk(KERN_ERR "%s: DLL not locked after %u seconds\n",
		       xicap_pdev.name, DLL_TIMEOUT);
		retval = -ETIME;
	} else {
		/* Register platform device */
		retval = platform_device_register(&xicap_pdev);
	}

	return retval;
}

device_initcall(xicap_devinit);
#endif /* defined(CONFIG_EXCITE_FCAP_GPI) || defined(CONFIG_EXCITE_FCAP_GPI_MODULE) */



#if defined(CONFIG_WDT_RM9K_GPI) || defined(CONFIG_WDT_RM9K_GPI_MODULE)
static struct resource wdt_rsrc[] = {
	RINIT(0, 0, WDT_RESOURCE_COUNTER, &excite_ctr_resource),
	RINIT(0x0084, 0x008f, WDT_RESOURCE_REGS, &excite_titan_resource),
	RINIT_IRQ(TITAN_IRQ,  WDT_RESOURCE_IRQ)
};

static struct platform_device wdt_pdev = {
	.name		= WDT_NAME,
	.id		= -1,
	.num_resources	= ARRAY_SIZE(wdt_rsrc),
	.resource	= wdt_rsrc
};

/*
 * Create a platform device for the GPI port that receives the
 * image data from the embedded camera.
 */
static int __init wdt_devinit(void)
{
	adjust_resources(wdt_rsrc, ARRAY_SIZE(wdt_rsrc));
	return platform_device_register(&wdt_pdev);
}

device_initcall(wdt_devinit);
#endif /* defined(CONFIG_WDT_RM9K_GPI) || defined(CONFIG_WDT_RM9K_GPI_MODULE) */



static struct resource excite_nandflash_rsrc[] = {
 	RINIT(0x2000, 0x201f, EXCITE_NANDFLASH_RESOURCE_REGS,  &excite_nand_resource)
};

static struct platform_device excite_nandflash_pdev = {
	.name		= "excite_nand",
	.id		= NAND_UNIT,
	.num_resources	= ARRAY_SIZE(excite_nandflash_rsrc),
	.resource	= excite_nandflash_rsrc
};

/*
 * Create a platform device for the access to the nand-flash
 * port
 */
static int __init excite_nandflash_devinit(void)
{
	adjust_resources(excite_nandflash_rsrc, ARRAY_SIZE(excite_nandflash_rsrc));

        /* nothing to be done here */

        /* Register platform device */
	return platform_device_register(&excite_nandflash_pdev);
}

device_initcall(excite_nandflash_devinit);



static struct resource iodev_rsrc[] = {
	RINIT_IRQ(FPGA1_IRQ,  IODEV_RESOURCE_IRQ)
};

static struct platform_device io_pdev = {
	.name		= IODEV_NAME,
	.id		= -1,
	.num_resources	= ARRAY_SIZE(iodev_rsrc),
	.resource	= iodev_rsrc
};

/*
 * Create a platform device for the external I/O ports.
 */
static int __init io_devinit(void)
{
	adjust_resources(iodev_rsrc, ARRAY_SIZE(iodev_rsrc));
	return platform_device_register(&io_pdev);
}

device_initcall(io_devinit);




#if defined(CONFIG_RM9K_GE) || defined(CONFIG_RM9K_GE_MODULE)
static struct resource rm9k_ge_rsrc[] = {
	RINIT(0x2200, 0x27ff, RM9K_GE_RESOURCE_MAC, &excite_titan_resource),
	RINIT(0x1800, 0x1fff, RM9K_GE_RESOURCE_MSTAT, &excite_titan_resource),
	RINIT(0x2000, 0x212f, RM9K_GE_RESOURCE_PKTPROC, &excite_titan_resource),
	RINIT(0x5140, 0x5227, RM9K_GE_RESOURCE_XDMA, &excite_titan_resource),
	RINIT(0x4870, 0x489f, RM9K_GE_RESOURCE_FIFO_RX, &excite_titan_resource),
	RINIT(0x494c, 0x4957, RM9K_GE_RESOURCE_FIFO_TX, &excite_titan_resource),
	RINIT(0x0000, 0x007f, RM9K_GE_RESOURCE_FIFOMEM_RX, &excite_fifomem_resource),
	RINIT(0x0080, 0x00ff, RM9K_GE_RESOURCE_FIFOMEM_TX, &excite_fifomem_resource),
	RINIT(0x0180, 0x019f, RM9K_GE_RESOURCE_PHY, &excite_titan_resource),
	RINIT(0x0000, 0x03ff, RM9K_GE_RESOURCE_DMADESC_RX, &excite_scram_resource),
	RINIT(0x0400, 0x07ff, RM9K_GE_RESOURCE_DMADESC_TX, &excite_scram_resource),
	RINIT(slice_eth, slice_eth, RM9K_GE_RESOURCE_GPI_SLICE, &excite_gpislice_resource),
	RINIT(0, 0, RM9K_GE_RESOURCE_MDIO_CHANNEL, &excite_mdio_channel_resource),
	RINIT_IRQ(TITAN_IRQ,  RM9K_GE_RESOURCE_IRQ_MAIN),
	RINIT_IRQ(PHY_IRQ, RM9K_GE_RESOURCE_IRQ_PHY)
};

static struct platform_device rm9k_ge_pdev = {
	.name		= RM9K_GE_NAME,
	.id		= RM9K_GE_UNIT,
	.num_resources	= ARRAY_SIZE(rm9k_ge_rsrc),
	.resource	= rm9k_ge_rsrc
};



/*
 * Create a platform device for the Ethernet port.
 */
static int __init rm9k_ge_devinit(void)
{
	u32 reg;

	adjust_resources(rm9k_ge_rsrc, ARRAY_SIZE(rm9k_ge_rsrc));

	/* Power up the slice and configure it. */
	reg = titan_readl(CPTC1R);
	reg &= ~(0x11000 << slice_eth);
	reg |= 0x100 << slice_eth;
	titan_writel(reg, CPTC1R);

	/* Take the MAC out of reset, reset the DLLs. */
	reg = titan_readl(CPRR);
	reg &= ~(0x00030000 << (slice_eth * 2));
	reg |= 0x3 << (slice_eth * 2);
	titan_writel(reg, CPRR);

	return platform_device_register(&rm9k_ge_pdev);
}

device_initcall(rm9k_ge_devinit);
#endif /* defined(CONFIG_RM9K_GE) || defined(CONFIG_RM9K_GE_MODULE) */



static int __init excite_setup_devs(void)
{
	int res;
	u32 reg;

	/* Enable xdma and fifo interrupts */
	reg = titan_readl(0x0050);
	titan_writel(reg | 0x18000000, 0x0050);

	res = request_resource(&iomem_resource, &excite_titan_resource);
	if (res)
		return res;
	res = request_resource(&iomem_resource, &excite_scram_resource);
	if (res)
		return res;
	res = request_resource(&iomem_resource, &excite_fpga_resource);
	if (res)
		return res;
	res = request_resource(&iomem_resource, &excite_nand_resource);
	if (res)
		return res;
	excite_fpga_resource.flags = excite_fpga_resource.parent->flags &
				   ( IORESOURCE_IO | IORESOURCE_MEM
				   | IORESOURCE_IRQ | IORESOURCE_DMA);
	excite_nand_resource.flags = excite_nand_resource.parent->flags &
				   ( IORESOURCE_IO | IORESOURCE_MEM
				   | IORESOURCE_IRQ | IORESOURCE_DMA);

	return 0;
}

arch_initcall(excite_setup_devs);

OpenPOWER on IntegriCloud