Merge tag 'pwm/for-4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry...
[sfrench/cifs-2.6.git] / arch / arm / mach-ep93xx / snappercl15.c
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/platnand.h>
27
28 #include <mach/hardware.h>
29 #include <linux/platform_data/video-ep93xx.h>
30 #include <mach/gpio-ep93xx.h>
31
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34
35 #include "soc.h"
36
37 #define SNAPPERCL15_NAND_BASE   (EP93XX_CS7_PHYS_BASE + SZ_16M)
38
39 #define SNAPPERCL15_NAND_WPN    (1 << 8)  /* Write protect (active low) */
40 #define SNAPPERCL15_NAND_ALE    (1 << 9)  /* Address latch */
41 #define SNAPPERCL15_NAND_CLE    (1 << 10) /* Command latch */
42 #define SNAPPERCL15_NAND_CEN    (1 << 11) /* Chip enable (active low) */
43 #define SNAPPERCL15_NAND_RDY    (1 << 14) /* Device ready */
44
45 #define NAND_CTRL_ADDR(chip)    (chip->legacy.IO_ADDR_W + 0x40)
46
47 static void snappercl15_nand_cmd_ctrl(struct nand_chip *chip, int cmd,
48                                       unsigned int ctrl)
49 {
50         static u16 nand_state = SNAPPERCL15_NAND_WPN;
51         u16 set;
52
53         if (ctrl & NAND_CTRL_CHANGE) {
54                 set = SNAPPERCL15_NAND_CEN | SNAPPERCL15_NAND_WPN;
55
56                 if (ctrl & NAND_NCE)
57                         set &= ~SNAPPERCL15_NAND_CEN;
58                 if (ctrl & NAND_CLE)
59                         set |= SNAPPERCL15_NAND_CLE;
60                 if (ctrl & NAND_ALE)
61                         set |= SNAPPERCL15_NAND_ALE;
62
63                 nand_state &= ~(SNAPPERCL15_NAND_CEN |
64                                 SNAPPERCL15_NAND_CLE |
65                                 SNAPPERCL15_NAND_ALE);
66                 nand_state |= set;
67                 __raw_writew(nand_state, NAND_CTRL_ADDR(chip));
68         }
69
70         if (cmd != NAND_CMD_NONE)
71                 __raw_writew((cmd & 0xff) | nand_state,
72                              chip->legacy.IO_ADDR_W);
73 }
74
75 static int snappercl15_nand_dev_ready(struct nand_chip *chip)
76 {
77         return !!(__raw_readw(NAND_CTRL_ADDR(chip)) & SNAPPERCL15_NAND_RDY);
78 }
79
80 static struct mtd_partition snappercl15_nand_parts[] = {
81         {
82                 .name           = "Kernel",
83                 .offset         = 0,
84                 .size           = SZ_2M,
85         },
86         {
87                 .name           = "Filesystem",
88                 .offset         = MTDPART_OFS_APPEND,
89                 .size           = MTDPART_SIZ_FULL,
90         },
91 };
92
93 static struct platform_nand_data snappercl15_nand_data = {
94         .chip = {
95                 .nr_chips               = 1,
96                 .partitions             = snappercl15_nand_parts,
97                 .nr_partitions          = ARRAY_SIZE(snappercl15_nand_parts),
98                 .chip_delay             = 25,
99         },
100         .ctrl = {
101                 .dev_ready              = snappercl15_nand_dev_ready,
102                 .cmd_ctrl               = snappercl15_nand_cmd_ctrl,
103         },
104 };
105
106 static struct resource snappercl15_nand_resource[] = {
107         {
108                 .start          = SNAPPERCL15_NAND_BASE,
109                 .end            = SNAPPERCL15_NAND_BASE + SZ_4K - 1,
110                 .flags          = IORESOURCE_MEM,
111         },
112 };
113
114 static struct platform_device snappercl15_nand_device = {
115         .name                   = "gen_nand",
116         .id                     = -1,
117         .dev.platform_data      = &snappercl15_nand_data,
118         .resource               = snappercl15_nand_resource,
119         .num_resources          = ARRAY_SIZE(snappercl15_nand_resource),
120 };
121
122 static struct ep93xx_eth_data __initdata snappercl15_eth_data = {
123         .phy_id                 = 1,
124 };
125
126 static struct i2c_board_info __initdata snappercl15_i2c_data[] = {
127         {
128                 /* Audio codec */
129                 I2C_BOARD_INFO("tlv320aic23", 0x1a),
130         },
131 };
132
133 static struct ep93xxfb_mach_info __initdata snappercl15_fb_info = {
134 };
135
136 static struct platform_device snappercl15_audio_device = {
137         .name           = "snappercl15-audio",
138         .id             = -1,
139 };
140
141 static void __init snappercl15_register_audio(void)
142 {
143         ep93xx_register_i2s();
144         platform_device_register(&snappercl15_audio_device);
145 }
146
147 static void __init snappercl15_init_machine(void)
148 {
149         ep93xx_init_devices();
150         ep93xx_register_eth(&snappercl15_eth_data, 1);
151         ep93xx_register_i2c(snappercl15_i2c_data,
152                             ARRAY_SIZE(snappercl15_i2c_data));
153         ep93xx_register_fb(&snappercl15_fb_info);
154         snappercl15_register_audio();
155         platform_device_register(&snappercl15_nand_device);
156 }
157
158 MACHINE_START(SNAPPER_CL15, "Bluewater Systems Snapper CL15")
159         /* Maintainer: Ryan Mallon */
160         .atag_offset    = 0x100,
161         .map_io         = ep93xx_map_io,
162         .init_irq       = ep93xx_init_irq,
163         .init_time      = ep93xx_timer_init,
164         .init_machine   = snappercl15_init_machine,
165         .init_late      = ep93xx_init_late,
166         .restart        = ep93xx_restart,
167 MACHINE_END