14705b2e8SMagnus Damm /*
24705b2e8SMagnus Damm * sh7724 MMCIF loader
34705b2e8SMagnus Damm *
44705b2e8SMagnus Damm * Copyright (C) 2010 Magnus Damm
54705b2e8SMagnus Damm *
64705b2e8SMagnus Damm * This file is subject to the terms and conditions of the GNU General Public
74705b2e8SMagnus Damm * License. See the file "COPYING" in the main directory of this archive
84705b2e8SMagnus Damm * for more details.
94705b2e8SMagnus Damm */
104705b2e8SMagnus Damm
11*13acb62cSWolfram Sang #include <linux/platform_data/sh_mmcif.h>
124705b2e8SMagnus Damm #include <mach/romimage.h>
134705b2e8SMagnus Damm
144705b2e8SMagnus Damm #define MMCIF_BASE (void __iomem *)0xa4ca0000
154705b2e8SMagnus Damm
164705b2e8SMagnus Damm #define MSTPCR2 0xa4150038
174705b2e8SMagnus Damm #define PTWCR 0xa4050146
184705b2e8SMagnus Damm #define PTXCR 0xa4050148
194705b2e8SMagnus Damm #define PSELA 0xa405014e
204705b2e8SMagnus Damm #define PSELE 0xa4050156
214705b2e8SMagnus Damm #define HIZCRC 0xa405015c
224705b2e8SMagnus Damm #define DRVCRA 0xa405018a
234705b2e8SMagnus Damm
24608241f3SUlf Hansson enum {
25608241f3SUlf Hansson MMCIF_PROGRESS_ENTER,
26608241f3SUlf Hansson MMCIF_PROGRESS_INIT,
27608241f3SUlf Hansson MMCIF_PROGRESS_LOAD,
28608241f3SUlf Hansson MMCIF_PROGRESS_DONE
29608241f3SUlf Hansson };
30608241f3SUlf Hansson
314705b2e8SMagnus Damm /* SH7724 specific MMCIF loader
324705b2e8SMagnus Damm *
334705b2e8SMagnus Damm * loads the romImage from an MMC card starting from block 512
344705b2e8SMagnus Damm * use the following line to write the romImage to an MMC card
354705b2e8SMagnus Damm * # dd if=arch/sh/boot/romImage of=/dev/sdx bs=512 seek=512
364705b2e8SMagnus Damm */
mmcif_loader(unsigned char * buf,unsigned long no_bytes)374705b2e8SMagnus Damm asmlinkage void mmcif_loader(unsigned char *buf, unsigned long no_bytes)
384705b2e8SMagnus Damm {
39608241f3SUlf Hansson mmcif_update_progress(MMCIF_PROGRESS_ENTER);
404705b2e8SMagnus Damm
414705b2e8SMagnus Damm /* enable clock to the MMCIF hardware block */
424705b2e8SMagnus Damm __raw_writel(__raw_readl(MSTPCR2) & ~0x20000000, MSTPCR2);
434705b2e8SMagnus Damm
444705b2e8SMagnus Damm /* setup pins D7-D0 */
454705b2e8SMagnus Damm __raw_writew(0x0000, PTWCR);
464705b2e8SMagnus Damm
474705b2e8SMagnus Damm /* setup pins MMC_CLK, MMC_CMD */
484705b2e8SMagnus Damm __raw_writew(__raw_readw(PTXCR) & ~0x000f, PTXCR);
494705b2e8SMagnus Damm
504705b2e8SMagnus Damm /* select D3-D0 pin function */
514705b2e8SMagnus Damm __raw_writew(__raw_readw(PSELA) & ~0x2000, PSELA);
524705b2e8SMagnus Damm
534705b2e8SMagnus Damm /* select D7-D4 pin function */
544705b2e8SMagnus Damm __raw_writew(__raw_readw(PSELE) & ~0x3000, PSELE);
554705b2e8SMagnus Damm
564705b2e8SMagnus Damm /* disable Hi-Z for the MMC pins */
574705b2e8SMagnus Damm __raw_writew(__raw_readw(HIZCRC) & ~0x0620, HIZCRC);
584705b2e8SMagnus Damm
594705b2e8SMagnus Damm /* high drive capability for MMC pins */
604705b2e8SMagnus Damm __raw_writew(__raw_readw(DRVCRA) | 0x3000, DRVCRA);
614705b2e8SMagnus Damm
62608241f3SUlf Hansson mmcif_update_progress(MMCIF_PROGRESS_INIT);
634705b2e8SMagnus Damm
644705b2e8SMagnus Damm /* setup MMCIF hardware */
654705b2e8SMagnus Damm sh_mmcif_boot_init(MMCIF_BASE);
664705b2e8SMagnus Damm
67608241f3SUlf Hansson mmcif_update_progress(MMCIF_PROGRESS_LOAD);
684705b2e8SMagnus Damm
694705b2e8SMagnus Damm /* load kernel via MMCIF interface */
7054b38463SSimon Horman sh_mmcif_boot_do_read(MMCIF_BASE, 512,
7154b38463SSimon Horman (no_bytes + SH_MMCIF_BBS - 1) / SH_MMCIF_BBS,
7254b38463SSimon Horman buf);
734705b2e8SMagnus Damm
744705b2e8SMagnus Damm /* disable clock to the MMCIF hardware block */
754705b2e8SMagnus Damm __raw_writel(__raw_readl(MSTPCR2) | 0x20000000, MSTPCR2);
764705b2e8SMagnus Damm
77608241f3SUlf Hansson mmcif_update_progress(MMCIF_PROGRESS_DONE);
784705b2e8SMagnus Damm }
79