• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * arch/arm/mach-ep93xx/snappercl15.c
3  * Bluewater Systems Snapper CL15 system module
4  *
5  * Copyright (C) 2009 Bluewater Systems Ltd
6  * Author: Ryan Mallon
7  *
8  * NAND code adapted from driver by:
9  *   Andre Renaud <andre@bluewatersys.com>
10  *   James R. McKaskill
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or (at
15  * your option) any later version.
16  *
17  */
18 
19 #include <linux/platform_device.h>
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/io.h>
23 #include <linux/i2c.h>
24 #include <linux/fb.h>
25 
26 #include <linux/mtd/partitions.h>
27 #include <linux/mtd/rawnand.h>
28 
29 #include <mach/hardware.h>
30 #include <linux/platform_data/video-ep93xx.h>
31 #include <mach/gpio-ep93xx.h>
32 
33 #include <asm/mach-types.h>
34 #include <asm/mach/arch.h>
35 
36 #include "soc.h"
37 
38 #define SNAPPERCL15_NAND_BASE	(EP93XX_CS7_PHYS_BASE + SZ_16M)
39 
40 #define SNAPPERCL15_NAND_WPN	(1 << 8)  /* Write protect (active low) */
41 #define SNAPPERCL15_NAND_ALE	(1 << 9)  /* Address latch */
42 #define SNAPPERCL15_NAND_CLE	(1 << 10) /* Command latch */
43 #define SNAPPERCL15_NAND_CEN	(1 << 11) /* Chip enable (active low) */
44 #define SNAPPERCL15_NAND_RDY	(1 << 14) /* Device ready */
45 
46 #define NAND_CTRL_ADDR(chip) 	(chip->IO_ADDR_W + 0x40)
47 
snappercl15_nand_cmd_ctrl(struct mtd_info * mtd,int cmd,unsigned int ctrl)48 static void snappercl15_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
49 				      unsigned int ctrl)
50 {
51 	struct nand_chip *chip = mtd_to_nand(mtd);
52 	static u16 nand_state = SNAPPERCL15_NAND_WPN;
53 	u16 set;
54 
55 	if (ctrl & NAND_CTRL_CHANGE) {
56 		set = SNAPPERCL15_NAND_CEN | SNAPPERCL15_NAND_WPN;
57 
58 		if (ctrl & NAND_NCE)
59 			set &= ~SNAPPERCL15_NAND_CEN;
60 		if (ctrl & NAND_CLE)
61 			set |= SNAPPERCL15_NAND_CLE;
62 		if (ctrl & NAND_ALE)
63 			set |= SNAPPERCL15_NAND_ALE;
64 
65 		nand_state &= ~(SNAPPERCL15_NAND_CEN |
66 				SNAPPERCL15_NAND_CLE |
67 				SNAPPERCL15_NAND_ALE);
68 		nand_state |= set;
69 		__raw_writew(nand_state, NAND_CTRL_ADDR(chip));
70 	}
71 
72 	if (cmd != NAND_CMD_NONE)
73 		__raw_writew((cmd & 0xff) | nand_state, chip->IO_ADDR_W);
74 }
75 
snappercl15_nand_dev_ready(struct mtd_info * mtd)76 static int snappercl15_nand_dev_ready(struct mtd_info *mtd)
77 {
78 	struct nand_chip *chip = mtd_to_nand(mtd);
79 
80 	return !!(__raw_readw(NAND_CTRL_ADDR(chip)) & SNAPPERCL15_NAND_RDY);
81 }
82 
83 static struct mtd_partition snappercl15_nand_parts[] = {
84 	{
85 		.name		= "Kernel",
86 		.offset		= 0,
87 		.size		= SZ_2M,
88 	},
89 	{
90 		.name		= "Filesystem",
91 		.offset		= MTDPART_OFS_APPEND,
92 		.size		= MTDPART_SIZ_FULL,
93 	},
94 };
95 
96 static struct platform_nand_data snappercl15_nand_data = {
97 	.chip = {
98 		.nr_chips		= 1,
99 		.partitions		= snappercl15_nand_parts,
100 		.nr_partitions		= ARRAY_SIZE(snappercl15_nand_parts),
101 		.chip_delay		= 25,
102 	},
103 	.ctrl = {
104 		.dev_ready		= snappercl15_nand_dev_ready,
105 		.cmd_ctrl		= snappercl15_nand_cmd_ctrl,
106 	},
107 };
108 
109 static struct resource snappercl15_nand_resource[] = {
110 	{
111 		.start		= SNAPPERCL15_NAND_BASE,
112 		.end		= SNAPPERCL15_NAND_BASE + SZ_4K - 1,
113 		.flags		= IORESOURCE_MEM,
114 	},
115 };
116 
117 static struct platform_device snappercl15_nand_device = {
118 	.name			= "gen_nand",
119 	.id			= -1,
120 	.dev.platform_data	= &snappercl15_nand_data,
121 	.resource		= snappercl15_nand_resource,
122 	.num_resources		= ARRAY_SIZE(snappercl15_nand_resource),
123 };
124 
125 static struct ep93xx_eth_data __initdata snappercl15_eth_data = {
126 	.phy_id			= 1,
127 };
128 
129 static struct i2c_board_info __initdata snappercl15_i2c_data[] = {
130 	{
131 		/* Audio codec */
132 		I2C_BOARD_INFO("tlv320aic23", 0x1a),
133 	},
134 };
135 
136 static struct ep93xxfb_mach_info __initdata snappercl15_fb_info = {
137 };
138 
139 static struct platform_device snappercl15_audio_device = {
140 	.name		= "snappercl15-audio",
141 	.id		= -1,
142 };
143 
snappercl15_register_audio(void)144 static void __init snappercl15_register_audio(void)
145 {
146 	ep93xx_register_i2s();
147 	platform_device_register(&snappercl15_audio_device);
148 }
149 
snappercl15_init_machine(void)150 static void __init snappercl15_init_machine(void)
151 {
152 	ep93xx_init_devices();
153 	ep93xx_register_eth(&snappercl15_eth_data, 1);
154 	ep93xx_register_i2c(snappercl15_i2c_data,
155 			    ARRAY_SIZE(snappercl15_i2c_data));
156 	ep93xx_register_fb(&snappercl15_fb_info);
157 	snappercl15_register_audio();
158 	platform_device_register(&snappercl15_nand_device);
159 }
160 
161 MACHINE_START(SNAPPER_CL15, "Bluewater Systems Snapper CL15")
162 	/* Maintainer: Ryan Mallon */
163 	.atag_offset	= 0x100,
164 	.map_io		= ep93xx_map_io,
165 	.init_irq	= ep93xx_init_irq,
166 	.init_time	= ep93xx_timer_init,
167 	.init_machine	= snappercl15_init_machine,
168 	.init_late	= ep93xx_init_late,
169 	.restart	= ep93xx_restart,
170 MACHINE_END
171