cdeed89e157cf56892d46ff06a23b6e24f208ca8
[openembedded.git] /
1 From 97e062a70c0b1ccc5b3f8236966c13b7b79e7c13 Mon Sep 17 00:00:00 2001
2 From: Hugo Villeneuve <hugo@hugovil.com>
3 Date: Fri, 6 Mar 2009 12:31:34 -0500
4 Subject: [PATCH 12/12] Update SFFSDR to support FPGA and lyrvpss drivers
5
6 Signed-off-by: Hugo Villeneuve <hugo@hugovil.com>
7 ---
8  arch/arm/configs/davinci_sffsdr_defconfig        |  157 +++++++++----
9  arch/arm/mach-davinci/Kconfig                    |   15 ++
10  arch/arm/mach-davinci/Makefile                   |    1 +
11  arch/arm/mach-davinci/board-sffsdr-fpga.c        |  283 ++++++++++++++++++++++
12  arch/arm/mach-davinci/board-sffsdr.c             |  195 ++++++++++++---
13  arch/arm/mach-davinci/include/mach/sffsdr-fpga.h |   54 ++++
14  6 files changed, 628 insertions(+), 77 deletions(-)
15  create mode 100644 arch/arm/mach-davinci/board-sffsdr-fpga.c
16  create mode 100644 arch/arm/mach-davinci/include/mach/sffsdr-fpga.h
17
18 diff --git a/arch/arm/configs/davinci_sffsdr_defconfig b/arch/arm/configs/davinci_sffsdr_defconfig
19 index 8c17858..91c01f9 100644
20 --- a/arch/arm/configs/davinci_sffsdr_defconfig
21 +++ b/arch/arm/configs/davinci_sffsdr_defconfig
22 @@ -1,7 +1,7 @@
23  #
24  # Automatically generated make config: don't edit
25  # Linux kernel version: 2.6.28-davinci1
26 -# Fri Jan 16 12:33:07 2009
27 +# Fri Mar  6 12:29:19 2009
28  #
29  CONFIG_ARM=y
30  CONFIG_SYS_SUPPORTS_APM_EMULATION=y
31 @@ -179,15 +179,11 @@ CONFIG_ARCH_DAVINCI_DM644x=y
32  #
33  # CONFIG_MACH_DAVINCI_EVM is not set
34  CONFIG_MACH_SFFSDR=y
35 +CONFIG_SFFSDR_FPGA=m
36  CONFIG_DAVINCI_MUX=y
37  # CONFIG_DAVINCI_MUX_DEBUG is not set
38  # CONFIG_DAVINCI_MUX_WARNINGS is not set
39  # CONFIG_DAVINCI_RESET_CLOCKS is not set
40 -CONFIG_DAVINCI_BOOT_TAG=y
41 -
42 -#
43 -# DaVinci Options
44 -#
45  
46  #
47  # Processor Type
48 @@ -206,7 +202,7 @@ CONFIG_CPU_CP15_MMU=y
49  #
50  # Processor Features
51  #
52 -CONFIG_ARM_THUMB=y
53 +# CONFIG_ARM_THUMB is not set
54  # CONFIG_CPU_ICACHE_DISABLE is not set
55  # CONFIG_CPU_DCACHE_DISABLE is not set
56  # CONFIG_CPU_DCACHE_WRITETHROUGH is not set
57 @@ -378,7 +374,84 @@ CONFIG_EXTRA_FIRMWARE=""
58  # CONFIG_DEBUG_DEVRES is not set
59  # CONFIG_SYS_HYPERVISOR is not set
60  # CONFIG_CONNECTOR is not set
61 -# CONFIG_MTD is not set
62 +CONFIG_MTD=y
63 +# CONFIG_MTD_DEBUG is not set
64 +# CONFIG_MTD_CONCAT is not set
65 +CONFIG_MTD_PARTITIONS=y
66 +# CONFIG_MTD_REDBOOT_PARTS is not set
67 +# CONFIG_MTD_CMDLINE_PARTS is not set
68 +# CONFIG_MTD_AFS_PARTS is not set
69 +# CONFIG_MTD_AR7_PARTS is not set
70 +
71 +#
72 +# User Modules And Translation Layers
73 +#
74 +CONFIG_MTD_CHAR=y
75 +# CONFIG_MTD_BLKDEVS is not set
76 +# CONFIG_MTD_BLOCK is not set
77 +# CONFIG_MTD_BLOCK_RO is not set
78 +# CONFIG_FTL is not set
79 +# CONFIG_NFTL is not set
80 +# CONFIG_INFTL is not set
81 +# CONFIG_RFD_FTL is not set
82 +# CONFIG_SSFDC is not set
83 +# CONFIG_MTD_OOPS is not set
84 +
85 +#
86 +# RAM/ROM/Flash chip drivers
87 +#
88 +# CONFIG_MTD_CFI is not set
89 +# CONFIG_MTD_JEDECPROBE is not set
90 +CONFIG_MTD_MAP_BANK_WIDTH_1=y
91 +CONFIG_MTD_MAP_BANK_WIDTH_2=y
92 +CONFIG_MTD_MAP_BANK_WIDTH_4=y
93 +# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
94 +# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
95 +# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
96 +CONFIG_MTD_CFI_I1=y
97 +CONFIG_MTD_CFI_I2=y
98 +# CONFIG_MTD_CFI_I4 is not set
99 +# CONFIG_MTD_CFI_I8 is not set
100 +# CONFIG_MTD_RAM is not set
101 +# CONFIG_MTD_ROM is not set
102 +# CONFIG_MTD_ABSENT is not set
103 +
104 +#
105 +# Mapping drivers for chip access
106 +#
107 +# CONFIG_MTD_COMPLEX_MAPPINGS is not set
108 +# CONFIG_MTD_PLATRAM is not set
109 +
110 +#
111 +# Self-contained MTD device drivers
112 +#
113 +# CONFIG_MTD_SLRAM is not set
114 +# CONFIG_MTD_PHRAM is not set
115 +# CONFIG_MTD_MTDRAM is not set
116 +# CONFIG_MTD_BLOCK2MTD is not set
117 +
118 +#
119 +# Disk-On-Chip Device Drivers
120 +#
121 +# CONFIG_MTD_DOC2000 is not set
122 +# CONFIG_MTD_DOC2001 is not set
123 +# CONFIG_MTD_DOC2001PLUS is not set
124 +CONFIG_MTD_NAND=y
125 +# CONFIG_MTD_NAND_VERIFY_WRITE is not set
126 +# CONFIG_MTD_NAND_ECC_SMC is not set
127 +# CONFIG_MTD_NAND_MUSEUM_IDS is not set
128 +# CONFIG_MTD_NAND_GPIO is not set
129 +CONFIG_MTD_NAND_IDS=y
130 +# CONFIG_MTD_NAND_DISKONCHIP is not set
131 +# CONFIG_MTD_NAND_NANDSIM is not set
132 +# CONFIG_MTD_NAND_PLATFORM is not set
133 +CONFIG_MTD_NAND_DAVINCI=y
134 +# CONFIG_MTD_ONENAND is not set
135 +
136 +#
137 +# UBI - Unsorted block images
138 +#
139 +# CONFIG_MTD_UBI is not set
140  # CONFIG_PARPORT is not set
141  CONFIG_BLK_DEV=y
142  # CONFIG_BLK_DEV_COW_COMMON is not set
143 @@ -387,7 +460,13 @@ CONFIG_BLK_DEV=y
144  # CONFIG_BLK_DEV_RAM is not set
145  # CONFIG_CDROM_PKTCDVD is not set
146  # CONFIG_ATA_OVER_ETH is not set
147 -# CONFIG_MISC_DEVICES is not set
148 +CONFIG_MISC_DEVICES=y
149 +# CONFIG_EEPROM_93CX6 is not set
150 +# CONFIG_ICS932S401 is not set
151 +# CONFIG_ENCLOSURE_SERVICES is not set
152 +CONFIG_FPGADL=m
153 +CONFIG_FPGADL_PAR=m
154 +# CONFIG_C2PORT is not set
155  CONFIG_HAVE_IDE=y
156  # CONFIG_IDE is not set
157  
158 @@ -499,6 +578,10 @@ CONFIG_UNIX98_PTYS=y
159  # CONFIG_R3964 is not set
160  # CONFIG_RAW_DRIVER is not set
161  # CONFIG_TCG_TPM is not set
162 +CONFIG_LYRTECH_VPSS=y
163 +CONFIG_LYRTECH_VPFE=m
164 +# CONFIG_LYRTECH_VPBE is not set
165 +CONFIG_LYRVPSS_DEBUG=y
166  CONFIG_I2C=y
167  CONFIG_I2C_BOARDINFO=y
168  CONFIG_I2C_CHARDEV=y
169 @@ -628,11 +711,11 @@ CONFIG_SSB_POSSIBLE=y
170  # Display device support
171  #
172  # CONFIG_DISPLAY_SUPPORT is not set
173 -CONFIG_SOUND=y
174 +CONFIG_SOUND=m
175  # CONFIG_SOUND_OSS_CORE is not set
176 -CONFIG_SND=y
177 -CONFIG_SND_TIMER=y
178 -CONFIG_SND_PCM=y
179 +CONFIG_SND=m
180 +CONFIG_SND_TIMER=m
181 +CONFIG_SND_PCM=m
182  # CONFIG_SND_SEQUENCER is not set
183  # CONFIG_SND_MIXER_OSS is not set
184  # CONFIG_SND_PCM_OSS is not set
185 @@ -643,38 +726,14 @@ CONFIG_SND_DYNAMIC_MINORS=y
186  # CONFIG_SND_DEBUG is not set
187  # CONFIG_SND_DRIVERS is not set
188  # CONFIG_SND_ARM is not set
189 -CONFIG_SND_SOC=y
190 +CONFIG_SND_SOC=m
191  CONFIG_SND_DAVINCI_SOC=m
192 -# CONFIG_SND_DAVINCI_SOC_SFFSDR is not set
193 +CONFIG_SND_DAVINCI_SOC_I2S=m
194 +CONFIG_SND_DAVINCI_SOC_SFFSDR=m
195  # CONFIG_SND_SOC_ALL_CODECS is not set
196 +CONFIG_SND_SOC_PCM3008=m
197  # CONFIG_SOUND_PRIME is not set
198  # CONFIG_USB_SUPPORT is not set
199 -# CONFIG_USB_MUSB_HOST is not set
200 -# CONFIG_USB_MUSB_PERIPHERAL is not set
201 -# CONFIG_USB_MUSB_OTG is not set
202 -# CONFIG_USB_GADGET_MUSB_HDRC is not set
203 -# CONFIG_USB_GADGET_AT91 is not set
204 -# CONFIG_USB_GADGET_ATMEL_USBA is not set
205 -# CONFIG_USB_GADGET_FSL_USB2 is not set
206 -# CONFIG_USB_GADGET_LH7A40X is not set
207 -# CONFIG_USB_GADGET_OMAP is not set
208 -# CONFIG_USB_GADGET_PXA25X is not set
209 -# CONFIG_USB_GADGET_PXA27X is not set
210 -# CONFIG_USB_GADGET_S3C2410 is not set
211 -# CONFIG_USB_GADGET_M66592 is not set
212 -# CONFIG_USB_GADGET_AMD5536UDC is not set
213 -# CONFIG_USB_GADGET_FSL_QE is not set
214 -# CONFIG_USB_GADGET_NET2280 is not set
215 -# CONFIG_USB_GADGET_GOKU is not set
216 -# CONFIG_USB_GADGET_DUMMY_HCD is not set
217 -# CONFIG_USB_ZERO is not set
218 -# CONFIG_USB_ETH is not set
219 -# CONFIG_USB_GADGETFS is not set
220 -# CONFIG_USB_FILE_STORAGE is not set
221 -# CONFIG_USB_G_SERIAL is not set
222 -# CONFIG_USB_MIDI_GADGET is not set
223 -# CONFIG_USB_G_PRINTER is not set
224 -# CONFIG_USB_CDC_COMPOSITE is not set
225  CONFIG_MMC=m
226  # CONFIG_MMC_DEBUG is not set
227  # CONFIG_MMC_UNSAFE_RESUME is not set
228 @@ -766,6 +825,17 @@ CONFIG_TMPFS=y
229  # CONFIG_BEFS_FS is not set
230  # CONFIG_BFS_FS is not set
231  # CONFIG_EFS_FS is not set
232 +CONFIG_JFFS2_FS=y
233 +CONFIG_JFFS2_FS_DEBUG=0
234 +CONFIG_JFFS2_FS_WRITEBUFFER=y
235 +# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
236 +# CONFIG_JFFS2_SUMMARY is not set
237 +# CONFIG_JFFS2_FS_XATTR is not set
238 +# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
239 +CONFIG_JFFS2_ZLIB=y
240 +# CONFIG_JFFS2_LZO is not set
241 +CONFIG_JFFS2_RTIME=y
242 +# CONFIG_JFFS2_RUBIN is not set
243  # CONFIG_CRAMFS is not set
244  # CONFIG_VXFS_FS is not set
245  # CONFIG_MINIX_FS is not set
246 @@ -1020,13 +1090,16 @@ CONFIG_CRYPTO=y
247  #
248  # Library routines
249  #
250 +CONFIG_BITREVERSE=y
251  # CONFIG_CRC_CCITT is not set
252  # CONFIG_CRC16 is not set
253  # CONFIG_CRC_T10DIF is not set
254  # CONFIG_CRC_ITU_T is not set
255 -# CONFIG_CRC32 is not set
256 +CONFIG_CRC32=y
257  # CONFIG_CRC7 is not set
258  # CONFIG_LIBCRC32C is not set
259 +CONFIG_ZLIB_INFLATE=y
260 +CONFIG_ZLIB_DEFLATE=y
261  CONFIG_PLIST=y
262  CONFIG_HAS_IOMEM=y
263  CONFIG_HAS_IOPORT=y
264 diff --git a/arch/arm/mach-davinci/Kconfig b/arch/arm/mach-davinci/Kconfig
265 index 0010f2d..769cd6c 100644
266 --- a/arch/arm/mach-davinci/Kconfig
267 +++ b/arch/arm/mach-davinci/Kconfig
268 @@ -50,6 +50,21 @@ config MACH_SFFSDR
269           Say Y here to select the Lyrtech Small Form Factor
270           Software Defined Radio (SFFSDR) board.
271  
272 +config SFFSDR_FPGA
273 +       tristate "SFFSDR SX-35 FPGA support"
274 +       default n
275 +       depends on MACH_SFFSDR
276 +       select FPGADL
277 +       select FW_LOADER
278 +       help
279 +         This driver supports the SX-35 FPGA on the Lyrtech SFFSDR board.
280 +         The FPGA is mainly used to generate the clocks for the audio
281 +         codec and for transferring data to/from the other stacked boards
282 +         (using the EMIF or VPSS ports).
283 +
284 +         To compile this driver as a module, choose M here: the
285 +         module will be called sffsdr-fpga.
286 +
287  config DAVINCI_MUX
288         bool "DAVINCI multiplexing support"
289         depends on ARCH_DAVINCI
290 diff --git a/arch/arm/mach-davinci/Makefile b/arch/arm/mach-davinci/Makefile
291 index 6783681..8a7b3c2 100644
292 --- a/arch/arm/mach-davinci/Makefile
293 +++ b/arch/arm/mach-davinci/Makefile
294 @@ -19,3 +19,4 @@ obj-$(CONFIG_MACH_DAVINCI_EVM)        += board-dm644x-evm.o
295  obj-$(CONFIG_MACH_DAVINCI_DM646X_EVM)  += board-dm646x-evm.o
296  obj-$(CONFIG_MACH_DAVINCI_DM355_EVM)   += board-dm355-evm.o
297  obj-$(CONFIG_MACH_SFFSDR)              += board-sffsdr.o
298 +obj-$(CONFIG_SFFSDR_FPGA)              += board-sffsdr-fpga.o
299 diff --git a/arch/arm/mach-davinci/board-sffsdr-fpga.c b/arch/arm/mach-davinci/board-sffsdr-fpga.c
300 new file mode 100644
301 index 0000000..b6a64dd
302 --- /dev/null
303 +++ b/arch/arm/mach-davinci/board-sffsdr-fpga.c
304 @@ -0,0 +1,283 @@
305 +/*
306 + * SFFSDR-board specific FPGA driver
307 + *
308 + * Copyright (C) 2008 Lyrtech <www.lyrtech.com>
309 + *
310 + * This program is free software; you can redistribute it and/or modify
311 + * it under the terms of the GNU General Public License as published by
312 + * the Free Software Foundation; either version 2 of the License, or
313 + * (at your option) any later version.
314 + *
315 + * This program is distributed in the hope that it will be useful,
316 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
317 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
318 + * GNU General Public License for more details.
319 + *
320 + * You should have received a copy of the GNU General Public License
321 + * along with this program; if not, write to the Free Software
322 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
323 + */
324 +
325 +#include <linux/kernel.h>
326 +#include <linux/module.h>
327 +#include <linux/init.h>
328 +#include <linux/device.h>
329 +#include <linux/string.h>
330 +#include <linux/platform_device.h>
331 +#include <linux/err.h>
332 +#include <linux/io.h>
333 +#include <linux/cdev.h>
334 +#include <linux/fs.h>
335 +#include <linux/fpgadl.h>
336 +
337 +#include <asm/gpio.h>
338 +
339 +#include <mach/sffsdr-fpga.h>
340 +
341 +#define MODULE_NAME "sffsdr_fpga"
342 +
343 +/* Used to determine if the bitstream is loaded. */
344 +#define FPGA_DEVICE_NAME "fpgadl_par0"
345 +
346 +/* Define this to have verbose debug messages. */
347 +#define SFFSDR_FPGA_DEBUG 1
348 +
349 +#ifdef SFFSDR_FPGA_DEBUG
350 +#define DBGMSG(fmt, args...)                                   \
351 +       printk(KERN_INFO "%s: "fmt"\n" , MODULE_NAME, ## args)
352 +#define FAILMSG(fmt, args...)                                  \
353 +       printk(KERN_ERR "%s: "fmt"\n" , MODULE_NAME, ## args)
354 +#else
355 +#define DBGMSG(fmt, args...)
356 +#define FAILMSG(fmt, args...)
357 +#endif
358 +
359 +#define FPGA_FULL_RESET_VAL    3
360 +#define FPGA_PARTIAL_RESET_VAL 2
361 +
362 +#define FPGA_DS2_ON            (1<<0)
363 +#define FPGA_DS3_ON            (1<<1)
364 +#define FPGA_DS4_ON            (1<<2)
365 +#define FPGA_DS5_ON            (1<<3)
366 +#define FPGA_DS6_ON            (1<<4)
367 +
368 +/* Sampling frequency divider, bits 5:4 */
369 +#define FPGA_FS_DIV_BY_1       (0<<4)
370 +#define FPGA_FS_DIV_BY_2       (1<<4)
371 +#define FPGA_FS_DIV_BY_4       (2<<4)
372 +#define FPGA_FS_DIV_RSV                (3<<4)
373 +
374 +/* Sampling rate selection, bit 2 */
375 +#define FPGA_SR_STANDARD       (0<<2) /* Standard sampling rate, default */
376 +#define FPGA_SR_DOUBLE         (1<<2) /* Double sampling rate */
377 +
378 +/* Sampling frequency selection, bits 1:0 */
379 +#define FPGA_FS_48000          (0<<0) /* 48.0 kHz (PLL 12.288 MHz) */
380 +#define FPGA_FS_44100          (1<<0) /* 44.1 kHz (PLL 11.2896 MHz) */
381 +#define FPGA_FS_32000          (2<<0) /* 32.0 kHz (PLL 8.192 MHz) */
382 +#define FPGA_FS_RSV            (3<<0) /* Reserved */
383 +
384 +struct sffsdr_fpga_dev_t {
385 +       int bitstream_mode;
386 +       u16 *regs;
387 +};
388 +
389 +static enum {
390 +       SFFSDR_FPGA_STATE_START,
391 +       SFFSDR_FPGA_STATE_DRV_STRUCT_ALLOCATED,
392 +       SFFSDR_FPGA_STATE_REGS_MAPPED,
393 +} sffsdr_fpga_state;
394 +
395 +struct sffsdr_fpga_dev_t *sffsdr_fpga_dev;
396 +
397 +/* The EMIF address lines A0 to A2 are not routed to the
398 + * FPGA. Therefore, the upper 16 bits are never valid. */
399 +u16 sffsdr_fpga_regread(int offset)
400 +{
401 +       return sffsdr_fpga_dev->regs[offset / 2];
402 +}
403 +EXPORT_SYMBOL(sffsdr_fpga_regread);
404 +
405 +void sffsdr_fpga_regwrite(int offset, u16 value)
406 +{
407 +       sffsdr_fpga_dev->regs[offset / 2] = value;
408 +}
409 +EXPORT_SYMBOL(sffsdr_fpga_regwrite);
410 +
411 +/* Reset the inside logic of the FPGA according to the
412 + * bitstream mode. This is done when the bitstream has
413 + * been programmed and is Lyrtech SFF-SDR specific. */
414 +static void sffsdr_fpga_reset(int bitstream_mode)
415 +{
416 +       u32 value;
417 +
418 +       if (bitstream_mode == BITSTREAM_MODE_FULL)
419 +               value = FPGA_FULL_RESET_VAL;
420 +       else
421 +               value = FPGA_PARTIAL_RESET_VAL;
422 +
423 +       sffsdr_fpga_regwrite(SFFSDR_FPGA_GLOBAL_CTRL, value);
424 +       sffsdr_fpga_regwrite(SFFSDR_FPGA_GLOBAL_CTRL, 0);
425 +}
426 +
427 +static int sffsdr_fpga_post_load(int bitstream_mode)
428 +{
429 +       DBGMSG("sffsdr_fpga_post_load()");
430 +
431 +       if (fpgadl_is_bitstream_loaded(FPGA_DEVICE_NAME) < 1) {
432 +               FAILMSG("  FPGA is not programmed");
433 +               return -ENODEV;
434 +       }
435 +
436 +       sffsdr_fpga_reset(bitstream_mode);
437 +
438 +       DBGMSG("FPGA Revision: %d",
439 +              sffsdr_fpga_regread(SFFSDR_FPGA_REVISION));
440 +
441 +       /* Light some LEDs to indicate success. */
442 +       sffsdr_fpga_regwrite(SFFSDR_FPGA_LED_CONTROL, FPGA_DS2_ON |
443 +                            FPGA_DS3_ON | FPGA_DS4_ON | FPGA_DS5_ON |
444 +                            FPGA_DS6_ON);
445 +
446 +       /* Set default CODEC clock values. */
447 +       sffsdr_fpga_regwrite(SFFSDR_FPGA_PLL_CODEC, FPGA_FS_DIV_BY_1 |
448 +                            FPGA_FS_44100 | FPGA_SR_STANDARD);
449 +
450 +       return 0;
451 +}
452 +
453 +int sffsdr_fpga_set_codec_fs(int fs)
454 +{
455 +       u16 fs_mask;
456 +
457 +       if (fpgadl_is_bitstream_loaded(FPGA_DEVICE_NAME) < 1) {
458 +               FAILMSG("FPGA is not programmed");
459 +               return -ENODEV;
460 +       }
461 +
462 +       switch (fs) {
463 +       case 32000:
464 +               fs_mask = FPGA_FS_32000;
465 +               break;
466 +       case 44100:
467 +               fs_mask = FPGA_FS_44100;
468 +               break;
469 +       case 48000:
470 +               fs_mask = FPGA_FS_48000;
471 +               break;
472 +       default:
473 +               FAILMSG("Unsupported sampling frequency");
474 +               return -EFAULT;
475 +               break;
476 +       }
477 +
478 +       sffsdr_fpga_regwrite(SFFSDR_FPGA_PLL_CODEC, FPGA_FS_DIV_BY_1 |
479 +                            fs_mask | FPGA_SR_STANDARD);
480 +
481 +       return 0;
482 +}
483 +EXPORT_SYMBOL(sffsdr_fpga_set_codec_fs);
484 +
485 +static void sffsdr_fpga_cleanup(void)
486 +{
487 +       switch (sffsdr_fpga_state) {
488 +       case SFFSDR_FPGA_STATE_REGS_MAPPED:
489 +               iounmap(sffsdr_fpga_dev->regs);
490 +       case SFFSDR_FPGA_STATE_DRV_STRUCT_ALLOCATED:
491 +               kfree(sffsdr_fpga_dev);
492 +       case SFFSDR_FPGA_STATE_START:
493 +               /* Nothing to do. */
494 +               break;
495 +       }
496 +}
497 +
498 +static int __devinit sffsdr_fpga_probe(struct platform_device *pdev)
499 +{
500 +       struct resource *fpgaregs_res;
501 +       int len;
502 +       int result;
503 +
504 +       DBGMSG("sffsdr_fpga_probe()");
505 +
506 +       sffsdr_fpga_state = SFFSDR_FPGA_STATE_START;
507 +
508 +       sffsdr_fpga_dev = kzalloc(sizeof(*sffsdr_fpga_dev), GFP_KERNEL);
509 +       if (!sffsdr_fpga_dev) {
510 +               FAILMSG("Failed to allocate device structure");
511 +               result = -ENOMEM;
512 +               goto error;
513 +       }
514 +       sffsdr_fpga_state = SFFSDR_FPGA_STATE_DRV_STRUCT_ALLOCATED;
515 +
516 +       pdev->dev.driver_data = sffsdr_fpga_dev; /* Private driver data */
517 +
518 +       /* Assign virtual addresses to FPGAREGS I/O memory regions. */
519 +       fpgaregs_res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
520 +                                                   "sffsdr_regs");
521 +       if (!fpgaregs_res) {
522 +               FAILMSG("Error getting fpgaregs ressource");
523 +               result = -ENODEV;
524 +               goto error;
525 +       }
526 +       len = fpgaregs_res->end - fpgaregs_res->start;
527 +       sffsdr_fpga_dev->regs = ioremap(fpgaregs_res->start, len);
528 +       if (!sffsdr_fpga_dev->regs) {
529 +               FAILMSG("Can't remap fpgaregs registers");
530 +               result = -ENXIO;
531 +               goto error;
532 +       }
533 +       sffsdr_fpga_state = SFFSDR_FPGA_STATE_REGS_MAPPED;
534 +
535 +       /* Temporary... */
536 +       sffsdr_fpga_post_load(BITSTREAM_MODE_FULL);
537 +
538 +       return 0;
539 +
540 +error:
541 +       sffsdr_fpga_cleanup();
542 +       return result;
543 +}
544 +
545 +static int __devexit sffsdr_fpga_remove(struct platform_device *pdev)
546 +{
547 +       DBGMSG("sffsdr_fpga_remove()");
548 +       sffsdr_fpga_cleanup();
549 +
550 +       return 0;
551 +}
552 +
553 +static struct platform_driver sffsdr_fpga_platform_driver = {
554 +       .driver         = {
555 +               .name   = MODULE_NAME,
556 +               .owner  = THIS_MODULE,
557 +       },
558 +       .remove = sffsdr_fpga_remove,
559 +};
560 +
561 +static int __init sffsdr_fpga_init(void)
562 +{
563 +       int res;
564 +
565 +       DBGMSG("sffsdr_fpga_init()");
566 +
567 +       res = platform_driver_probe(&sffsdr_fpga_platform_driver,
568 +                                   sffsdr_fpga_probe);
569 +       if (res) {
570 +               DBGMSG("platform_driver_probe() failed");
571 +               return res;
572 +       }
573 +
574 +       return 0;
575 +}
576 +module_init(sffsdr_fpga_init);
577 +
578 +static void __exit sffsdr_fpga_exit(void)
579 +{
580 +       DBGMSG("sffsdr_fpga_exit()");
581 +       platform_driver_unregister(&sffsdr_fpga_platform_driver);
582 +}
583 +module_exit(sffsdr_fpga_exit);
584 +
585 +MODULE_AUTHOR("Hugo Villeneuve <hvilleneuve@lyrtech.com>");
586 +MODULE_DESCRIPTION("Lyrtech SFFSDR SX-35 FPGA driver");
587 +MODULE_LICENSE("GPL");
588 diff --git a/arch/arm/mach-davinci/board-sffsdr.c b/arch/arm/mach-davinci/board-sffsdr.c
589 index 0d83cb0..aee4472 100644
590 --- a/arch/arm/mach-davinci/board-sffsdr.c
591 +++ b/arch/arm/mach-davinci/board-sffsdr.c
592 @@ -5,8 +5,7 @@
593   * Copyright (C) 2008 Lyrtech <www.lyrtech.com>
594   *
595   * Based on DV-EVM platform, original copyright follows:
596 - *
597 - * Copyright (C) 2007 MontaVista Software, Inc.
598 + *   Copyright (C) 2007 MontaVista Software, Inc.
599   *
600   * This program is free software; you can redistribute it and/or modify
601   * it under the terms of the GNU General Public License as published by
602 @@ -29,7 +28,6 @@
603  #include <linux/dma-mapping.h>
604  #include <linux/platform_device.h>
605  #include <linux/gpio.h>
606 -
607  #include <linux/i2c.h>
608  #include <linux/i2c/at24.h>
609  #include <linux/etherdevice.h>
610 @@ -38,10 +36,10 @@
611  #include <linux/mtd/partitions.h>
612  #include <linux/mtd/physmap.h>
613  #include <linux/io.h>
614 +#include <linux/fpgadl.h>
615  
616  #include <asm/setup.h>
617  #include <asm/mach-types.h>
618 -
619  #include <asm/mach/arch.h>
620  #include <asm/mach/map.h>
621  #include <asm/mach/flash.h>
622 @@ -51,11 +49,28 @@
623  #include <mach/emac.h>
624  #include <mach/i2c.h>
625  #include <mach/serial.h>
626 +#include <mach/mmc.h>
627  #include <mach/psc.h>
628  #include <mach/mux.h>
629 +#include <mach/nand.h>
630 +#include <mach/mmc.h>
631 +#include <mach/sffsdr-lyrvpfe.h>
632 +
633 +#define XC4VSX35_PAYLOAD_SIZE  (1707240)
634 +
635 +#define DAVINCI_ASYNC_EMIF_CONTROL_BASE                0x01e00000
636 +#define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE       0x02000000
637 +
638 +#define DAVINCI_VPSS_REGS_BASE                 0x01C70000
639 +
640 +#define FPGA_SELECTMAP_BASE                    0x04000000
641 +#define FPGA_SFFSDR_REGS_BASE                  0x04008000
642 +
643 +/* DDR2 memory is 256 Mbytes */
644 +#define DDR2_BASE              0x80000000
645  
646 -#define DAVINCI_ASYNC_EMIF_CONTROL_BASE   0x01e00000
647 -#define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE  0x02000000
648 +#define SFFSDR_MMC_CD_PIN      GPIO(51)
649 +#define SFFSDR_MMC_RO_PIN      GPIO(50)
650  
651  struct mtd_partition davinci_sffsdr_nandflash_partition[] = {
652         /* U-Boot Environment: Block 0
653 @@ -78,9 +93,10 @@ struct mtd_partition davinci_sffsdr_nandflash_partition[] = {
654         },
655  };
656  
657 -static struct flash_platform_data davinci_sffsdr_nandflash_data = {
658 +static struct davinci_nand_pdata davinci_sffsdr_nandflash_data = {
659         .parts          = davinci_sffsdr_nandflash_partition,
660         .nr_parts       = ARRAY_SIZE(davinci_sffsdr_nandflash_partition),
661 +       .ecc_mode       = NAND_ECC_HW,
662  };
663  
664  static struct resource davinci_sffsdr_nandflash_resource[] = {
665 @@ -105,9 +121,6 @@ static struct platform_device davinci_sffsdr_nandflash_device = {
666         .resource       = davinci_sffsdr_nandflash_resource,
667  };
668  
669 -/* Get Ethernet address from kernel boot params */
670 -static u8 davinci_sffsdr_mac_addr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
671 -
672  static struct at24_platform_data eeprom_info = {
673         .byte_len       = (64*1024) / 8,
674         .page_size      = 32,
675 @@ -137,12 +150,126 @@ static void __init sffsdr_init_i2c(void)
676         i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
677  }
678  
679 +static int sffsdr_mmc_get_cd(int module)
680 +{
681 +       return gpio_get_value(SFFSDR_MMC_CD_PIN);
682 +}
683 +
684 +static int sffsdr_mmc_get_ro(int module)
685 +{
686 +       return gpio_get_value(SFFSDR_MMC_RO_PIN);
687 +}
688 +
689 +static struct davinci_mmc_config sffsdr_mmc_config = {
690 +       .get_cd         = sffsdr_mmc_get_cd,
691 +       .get_ro         = sffsdr_mmc_get_ro,
692 +       .wires          = 4
693 +};
694 +
695 +/*
696 + * The FPGA is loaded using the SelectMAP mode through
697 + * the EMIF interface and some dedicated control signals:
698 + *
699 + *   FPGA          DM6446
700 + *   --------------------
701 + *   PROGRAM_B     GPIO37
702 + *   DONE          GPIO39
703 + *   INIT          GPIO40
704 + *   DOUT_BUSY     GPIO42 (Not used)
705 + *   CS_B          EMIF_A13 OR CS3n
706 + */
707 +static struct fpgadl_pdata_t fpgadl_par_pdata = {
708 +       .fpga_family            = FPGA_FAMILY_XILINX_XC4V,
709 +       .payload_full_size      = XC4VSX35_PAYLOAD_SIZE,
710 +       .program_b              = GPIO(37),
711 +       .done                   = GPIO(39),
712 +       .init_b                 = GPIO(40),
713 +       .bitstream_name         = "fpga.bit",
714 +       .check_init_low         = 0,
715 +};
716 +
717 +/* FPGA physical EMIF register resources. */
718 +static struct resource davinci_fpgadl_par_resources[] = {
719 +       {
720 +               .name           = "selectmap",
721 +               .start          = FPGA_SELECTMAP_BASE,
722 +               .end            = FPGA_SELECTMAP_BASE + 4 - 1,
723 +               .flags          = IORESOURCE_MEM,
724 +       },
725 +};
726 +
727 +static struct platform_device davinci_fpgadl_par_device = {
728 +       .name           = "fpgadl_par", /* Name of driver */
729 +       .id             = 0,
730 +       .dev            = {
731 +               .platform_data  = &fpgadl_par_pdata,
732 +       },
733 +       .num_resources  = ARRAY_SIZE(davinci_fpgadl_par_resources),
734 +       .resource       = davinci_fpgadl_par_resources,
735 +};
736 +
737 +/* SFFSDR specific FPGA registers. */
738 +static struct resource davinci_sffsdr_fpga_resources[] = {
739 +       {
740 +               .name           = "sffsdr_regs",
741 +               .start          = FPGA_SFFSDR_REGS_BASE,
742 +               .end            = FPGA_SFFSDR_REGS_BASE + SZ_1K - 1,
743 +               .flags          = IORESOURCE_MEM,
744 +       },
745 +};
746 +
747 +static struct platform_device davinci_sffsdr_fpga_device = {
748 +       .name           = "sffsdr_fpga", /* Name of driver */
749 +       .id             = -1, /* Only one instance = -1 */
750 +       .num_resources  = ARRAY_SIZE(davinci_sffsdr_fpga_resources),
751 +       .resource       = davinci_sffsdr_fpga_resources,
752 +};
753 +
754 +static struct lyrvpfe_platform_data lyrvpfe_pdata = {
755 +       /*
756 +        * GPIO(1) for DSP  to FPGA (VPBE)
757 +        * GPIO(0) for FPGA to DSP  (VPFE)
758 +        */
759 +       .ready_gpio = GPIO(0), /* DSP to FPGA (VPFE) */
760 +};
761 +
762 +static struct resource lyrvpfe_resources[] = {
763 +       {
764 +               .name           = "regs",
765 +               .start          = DAVINCI_VPSS_REGS_BASE,
766 +               .end            = DAVINCI_VPSS_REGS_BASE + SZ_16K - 1,
767 +               .flags          = IORESOURCE_MEM,
768 +       },
769 +       {
770 +               .name           = "irq",
771 +               .start          = IRQ_VDINT0,
772 +               .end            = IRQ_VDINT0,
773 +               .flags          = IORESOURCE_IRQ,
774 +       },
775 +};
776 +
777 +static struct platform_device lyrvpfe_pdev = {
778 +       .name           = "lyrvpfe",
779 +       .id             = 0,
780 +       .dev            = {
781 +               .platform_data  = &lyrvpfe_pdata,
782 +       },
783 +       .resource       = lyrvpfe_resources,
784 +       .num_resources  = ARRAY_SIZE(lyrvpfe_resources),
785 +};
786 +
787  static struct platform_device *davinci_sffsdr_devices[] __initdata = {
788 -       &davinci_sffsdr_nandflash_device,
789 +       &davinci_fpgadl_par_device, /* Bitstream loading - parallel */
790 +       &davinci_sffsdr_fpga_device, /* Application functionality */
791 +       &lyrvpfe_pdev,
792  };
793  
794 +/*
795 + * UART0: console
796 + * UART1: FPGA
797 + */
798  static struct davinci_uart_config uart_config __initdata = {
799 -       .enabled_uarts = (1 << 0),
800 +       .enabled_uarts = DAVINCI_UART0_ENA | DAVINCI_UART1_ENA,
801  };
802  
803  static void __init davinci_sffsdr_map_io(void)
804 @@ -151,39 +278,37 @@ static void __init davinci_sffsdr_map_io(void)
805         dm644x_init();
806  }
807  
808 -static __init void davinci_sffsdr_init(void)
809 +static void __init davinci_sffsdr_init(void)
810  {
811 +       gpio_request(SFFSDR_MMC_CD_PIN, "MMC CD");
812 +       gpio_direction_input(SFFSDR_MMC_CD_PIN);
813 +       gpio_request(SFFSDR_MMC_RO_PIN, "MMC RO");
814 +       gpio_direction_input(SFFSDR_MMC_RO_PIN);
815 +
816 +       /* Turn UART1 MUX ON. */
817 +       davinci_cfg_reg(DM644X_UART1);
818 +
819         platform_add_devices(davinci_sffsdr_devices,
820                              ARRAY_SIZE(davinci_sffsdr_devices));
821         sffsdr_init_i2c();
822 -       davinci_serial_init(&uart_config);
823 -       davinci_init_emac(davinci_sffsdr_mac_addr);
824 -       setup_usb(0, 0); /* We support only peripheral mode. */
825  
826 -       /* mux VLYNQ pins */
827 -       davinci_cfg_reg(DM644X_VLYNQEN);
828 -       davinci_cfg_reg(DM644X_VLYNQWD);
829 -}
830 +       davinci_serial_init(&uart_config);
831  
832 -static int davinci_cpmac_eth_setup(char *str)
833 -{
834 -       int i;
835 +#if defined(CONFIG_MTD_NAND_DAVINCI) || \
836 +    defined(CONFIG_MTD_NAND_DAVINCI_MODULE)
837 +       davinci_cfg_reg(DM644X_HPIEN_DISABLE);
838 +       davinci_cfg_reg(DM644X_ATAEN_DISABLE);
839 +       platform_device_register(&davinci_sffsdr_nandflash_device);
840 +#endif
841  
842 -       if (str == NULL)
843 -               return 0;
844 +       davinci_setup_mmc(0, &sffsdr_mmc_config);
845  
846 -       /* Conversion of a MAC address from a string (AA:BB:CC:DD:EE:FF)
847 -        * to a 6 bytes array. */
848 -       for (i = 0; i < 6; i++)
849 -               davinci_sffsdr_mac_addr[i] = simple_strtol(&str[i*3],
850 -                                                          (char **)NULL, 16);
851 +       davinci_init_emac(NULL);
852  
853 -       return 1;
854 +       setup_usb(0, 0); /* We support only peripheral mode. */
855  }
856 -/* Get MAC address from kernel boot parameter eth=AA:BB:CC:DD:EE:FF */
857 -__setup("eth=", davinci_cpmac_eth_setup);
858  
859 -static __init void davinci_sffsdr_irq_init(void)
860 +static void __init davinci_sffsdr_irq_init(void)
861  {
862         davinci_irq_init();
863  }
864 @@ -195,6 +320,6 @@ MACHINE_START(SFFSDR, "Lyrtech SFFSDR")
865         .boot_params  = (DAVINCI_DDR_BASE + 0x100),
866         .map_io       = davinci_sffsdr_map_io,
867         .init_irq     = davinci_sffsdr_irq_init,
868 -       .timer        = &davinci_timer,
869         .init_machine = davinci_sffsdr_init,
870 +       .timer        = &davinci_timer,
871  MACHINE_END
872 diff --git a/arch/arm/mach-davinci/include/mach/sffsdr-fpga.h b/arch/arm/mach-davinci/include/mach/sffsdr-fpga.h
873 new file mode 100644
874 index 0000000..6607ac0
875 --- /dev/null
876 +++ b/arch/arm/mach-davinci/include/mach/sffsdr-fpga.h
877 @@ -0,0 +1,54 @@
878 +/*
879 + * sffsdr_fpga.h
880 + *
881 + * This program is free software; you can redistribute it and/or modify it
882 + * under the terms of the GNU General Public License as published by the
883 + * Free Software Foundation; either version 2 of the License, or (at your
884 + * option) any later version.
885 + *
886 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
887 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
888 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
889 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
890 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
891 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
892 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
893 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
894 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
895 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
896 + *
897 + * You should have received a copy of the  GNU General Public License along
898 + * with this program; if not, write  to the Free Software Foundation, Inc.,
899 + * 675 Mass Ave, Cambridge, MA 02139, USA.
900 + */
901 +
902 +#ifndef __SFFSDR_FPGA_H
903 +#define __SFFSDR_FPGA_H
904 +
905 +#define SFFSDR_FPGA_REVISION                   0x000
906 +#define SFFSDR_FPGA_GLOBAL_CTRL                        0x040
907 +#define SFFSDR_FPGA_LED_CONTROL                        0x300
908 +#define SFFSDR_FPGA_PLL_CODEC                  0x800
909 +
910 +/* VPSS configuration register */
911 +#define SFFSDR_FPGA_VPSS_CONTROL               0xA00
912 +
913 +/* VPSS, VPBE packet size configuration register */
914 +#define SFFSDR_FPGA_VPSS_FROM_DSP_FIFO         0xA40
915 +
916 +/* VPSS, VPFE packet size configuration register */
917 +#define SFFSDR_FPGA_VPSS_TO_DSP_FIFO           0xA80
918 +
919 +/* VPSS, VPFE number of lines configuration register */
920 +#define SFFSDR_FPGA_VPSS_LINES_PER_FRAME       0xAC0
921 +
922 +#define SFFSDR_FPGA_CUSTOM_REG0_LSB            0xC00
923 +#define SFFSDR_FPGA_CUSTOM_REG0_MSB            0xC20
924 +
925 +u16 sffsdr_fpga_regread(int offset);
926 +
927 +void sffsdr_fpga_regwrite(int offset, u16 value);
928 +
929 +int sffsdr_fpga_set_codec_fs(int fs);
930 +
931 +#endif /* __SFFSDR_FPGA_H */
932 -- 
933 1.5.4.5
934