blob: 2012fa8c28cfed7796a5ba28f47f6e0bea977051 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/arch/arm/mach-sa1100/assabet.c
4 *
5 * Author: Nicolas Pitre
6 *
7 * This file contains all Assabet-specific tweaks.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/init.h>
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/errno.h>
Russell Kingb9551532016-08-31 08:49:45 +010013#include <linux/gpio/gpio-reg.h>
Russell King29786e92016-08-31 08:49:47 +010014#include <linux/gpio/machine.h>
Russell King17c7f4f2016-08-31 08:49:50 +010015#include <linux/gpio_keys.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/ioport.h>
Russell King6920b5a2012-09-21 10:18:58 +010017#include <linux/platform_data/sa11x0-serial.h>
Russell King29786e92016-08-31 08:49:47 +010018#include <linux/regulator/fixed.h>
19#include <linux/regulator/machine.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/serial_core.h>
Arnd Bergmann7f206d42013-02-14 23:26:50 +010021#include <linux/platform_device.h>
Russell King69dde862012-01-20 22:18:06 +000022#include <linux/mfd/ucb1x00.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/mtd/mtd.h>
24#include <linux/mtd/partitions.h>
25#include <linux/delay.h>
26#include <linux/mm.h>
Bryan Wu18775a72012-03-14 02:22:03 +080027#include <linux/leds.h>
28#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Russell Kinge1b7a722012-01-14 11:50:04 +000030#include <video/sa1100fb.h>
31
Russell Kinga09e64f2008-08-05 16:14:15 +010032#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/setup.h>
35#include <asm/page.h>
Russell King74945c82006-03-16 14:44:36 +000036#include <asm/pgtable-hwdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/tlbflush.h>
38
39#include <asm/mach/arch.h>
40#include <asm/mach/flash.h>
Dmitry Eremin-Solenikovdd450772014-12-24 01:14:14 +030041#include <linux/platform_data/irda-sa11x0.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/mach/map.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010043#include <mach/assabet.h>
Arnd Bergmanna1fd8442012-08-24 15:17:38 +020044#include <linux/platform_data/mfd-mcp-sa11x0.h>
Rob Herringf314f332012-02-24 00:06:51 +010045#include <mach/irqs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47#include "generic.h"
48
49#define ASSABET_BCR_DB1110 \
Russell King7186fb92012-01-21 21:17:06 +000050 (ASSABET_BCR_SPK_OFF | \
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 ASSABET_BCR_LED_GREEN | ASSABET_BCR_LED_RED | \
52 ASSABET_BCR_RS232EN | ASSABET_BCR_LCD_12RGB | \
53 ASSABET_BCR_IRDA_MD0)
54
55#define ASSABET_BCR_DB1111 \
Russell King7186fb92012-01-21 21:17:06 +000056 (ASSABET_BCR_SPK_OFF | \
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 ASSABET_BCR_LED_GREEN | ASSABET_BCR_LED_RED | \
58 ASSABET_BCR_RS232EN | ASSABET_BCR_LCD_12RGB | \
59 ASSABET_BCR_CF_BUS_OFF | ASSABET_BCR_STEREO_LB | \
60 ASSABET_BCR_IRDA_MD0 | ASSABET_BCR_CF_RST)
61
62unsigned long SCR_value = ASSABET_SCR_INIT;
63EXPORT_SYMBOL(SCR_value);
64
Russell Kingb9551532016-08-31 08:49:45 +010065static struct gpio_chip *assabet_bcr_gc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Russell Kingb9551532016-08-31 08:49:45 +010067static const char *assabet_names[] = {
68 "cf_pwr", "cf_gfx_reset", "nsoft_reset", "irda_fsel",
69 "irda_md0", "irda_md1", "stereo_loopback", "ncf_bus_on",
70 "audio_pwr_on", "light_pwr_on", "lcd16data", "lcd_pwr_on",
71 "rs232_on", "nred_led", "ngreen_led", "vib_on",
72 "com_dtr", "com_rts", "radio_wake_mod", "i2c_enab",
73 "tvir_enab", "qmute", "radio_pwr_on", "spkr_off",
74 "rs232_valid", "com_dcd", "com_cts", "com_dsr",
75 "radio_cts", "radio_dsr", "radio_dcd", "radio_ri",
76};
77
78/* The old deprecated interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -070079void ASSABET_BCR_frob(unsigned int mask, unsigned int val)
80{
Russell Kingb9551532016-08-31 08:49:45 +010081 unsigned long m = mask, v = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Russell Kingb9551532016-08-31 08:49:45 +010083 assabet_bcr_gc->set_multiple(assabet_bcr_gc, &m, &v);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
Linus Torvalds1da177e2005-04-16 15:20:36 -070085EXPORT_SYMBOL(ASSABET_BCR_frob);
86
Russell Kingb9551532016-08-31 08:49:45 +010087static int __init assabet_init_gpio(void __iomem *reg, u32 def_val)
88{
89 struct gpio_chip *gc;
90
91 writel_relaxed(def_val, reg);
92
93 gc = gpio_reg_init(NULL, reg, -1, 32, "assabet", 0xff000000, def_val,
94 assabet_names, NULL, NULL);
95
96 if (IS_ERR(gc))
97 return PTR_ERR(gc);
98
99 assabet_bcr_gc = gc;
100
Russell King59b23ea2016-08-31 08:49:50 +0100101 return gc->base;
Russell Kingb9551532016-08-31 08:49:45 +0100102}
103
Russell King7dde0c02013-07-09 10:27:12 +0100104/*
105 * The codec reset goes to three devices, so we need to release
106 * the rest when any one of these requests it. However, that
107 * causes the ADV7171 to consume around 100mA - more than half
108 * the LCD-blanked power.
109 *
110 * With the ADV7171, LCD and backlight enabled, we go over
111 * budget on the MAX846 Li-Ion charger, and if no Li-Ion battery
112 * is connected, the Assabet crashes.
113 */
114#define RST_UCB1X00 (1 << 0)
115#define RST_UDA1341 (1 << 1)
116#define RST_ADV7171 (1 << 2)
117
118#define SDA GPIO_GPIO(15)
119#define SCK GPIO_GPIO(18)
120#define MOD GPIO_GPIO(17)
121
122static void adv7171_start(void)
123{
124 GPSR = SCK;
125 udelay(1);
126 GPSR = SDA;
127 udelay(2);
128 GPCR = SDA;
129}
130
131static void adv7171_stop(void)
132{
133 GPSR = SCK;
134 udelay(2);
135 GPSR = SDA;
136 udelay(1);
137}
138
139static void adv7171_send(unsigned byte)
140{
141 unsigned i;
142
143 for (i = 0; i < 8; i++, byte <<= 1) {
144 GPCR = SCK;
145 udelay(1);
146 if (byte & 0x80)
147 GPSR = SDA;
148 else
149 GPCR = SDA;
150 udelay(1);
151 GPSR = SCK;
152 udelay(1);
153 }
154 GPCR = SCK;
155 udelay(1);
156 GPSR = SDA;
157 udelay(1);
158 GPDR &= ~SDA;
159 GPSR = SCK;
160 udelay(1);
161 if (GPLR & SDA)
162 printk(KERN_WARNING "No ACK from ADV7171\n");
163 udelay(1);
164 GPCR = SCK | SDA;
165 udelay(1);
166 GPDR |= SDA;
167 udelay(1);
168}
169
170static void adv7171_write(unsigned reg, unsigned val)
171{
172 unsigned gpdr = GPDR;
173 unsigned gplr = GPLR;
174
Russell Kingb9551532016-08-31 08:49:45 +0100175 ASSABET_BCR_frob(ASSABET_BCR_AUDIO_ON, ASSABET_BCR_AUDIO_ON);
Russell King7dde0c02013-07-09 10:27:12 +0100176 udelay(100);
177
178 GPCR = SDA | SCK | MOD; /* clear L3 mode to ensure UDA1341 doesn't respond */
179 GPDR = (GPDR | SCK | MOD) & ~SDA;
180 udelay(10);
181 if (!(GPLR & SDA))
182 printk(KERN_WARNING "Something dragging SDA down?\n");
183 GPDR |= SDA;
184
185 adv7171_start();
186 adv7171_send(0x54);
187 adv7171_send(reg);
188 adv7171_send(val);
189 adv7171_stop();
190
191 /* Restore GPIO state for L3 bus */
192 GPSR = gplr & (SDA | SCK | MOD);
193 GPCR = (~gplr) & (SDA | SCK | MOD);
194 GPDR = gpdr;
195}
196
197static void adv7171_sleep(void)
198{
199 /* Put the ADV7171 into sleep mode */
200 adv7171_write(0x04, 0x40);
201}
202
203static unsigned codec_nreset;
204
205static void assabet_codec_reset(unsigned mask, int set)
206{
207 unsigned long flags;
208 bool old;
209
210 local_irq_save(flags);
211 old = !codec_nreset;
212 if (set)
213 codec_nreset &= ~mask;
214 else
215 codec_nreset |= mask;
216
217 if (old != !codec_nreset) {
218 if (codec_nreset) {
219 ASSABET_BCR_set(ASSABET_BCR_NCODEC_RST);
220 adv7171_sleep();
221 } else {
222 ASSABET_BCR_clear(ASSABET_BCR_NCODEC_RST);
223 }
224 }
225 local_irq_restore(flags);
226}
227
Russell King6ed3e2a2012-01-22 19:23:33 +0000228static void assabet_ucb1x00_reset(enum ucb1x00_reset state)
229{
Russell King7dde0c02013-07-09 10:27:12 +0100230 int set = state == UCB_RST_REMOVE || state == UCB_RST_SUSPEND ||
231 state == UCB_RST_PROBE_FAIL;
232 assabet_codec_reset(RST_UCB1X00, set);
Russell King6ed3e2a2012-01-22 19:23:33 +0000233}
234
Russell King7dde0c02013-07-09 10:27:12 +0100235void assabet_uda1341_reset(int set)
236{
237 assabet_codec_reset(RST_UDA1341, set);
238}
239EXPORT_SYMBOL(assabet_uda1341_reset);
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242/*
243 * Assabet flash support code.
244 */
245
246#ifdef ASSABET_REV_4
247/*
248 * Phase 4 Assabet has two 28F160B3 flash parts in bank 0:
249 */
250static struct mtd_partition assabet_partitions[] = {
251 {
252 .name = "bootloader",
253 .size = 0x00020000,
254 .offset = 0,
255 .mask_flags = MTD_WRITEABLE,
256 }, {
257 .name = "bootloader params",
258 .size = 0x00020000,
259 .offset = MTDPART_OFS_APPEND,
260 .mask_flags = MTD_WRITEABLE,
261 }, {
262 .name = "jffs",
263 .size = MTDPART_SIZ_FULL,
264 .offset = MTDPART_OFS_APPEND,
265 }
266};
267#else
268/*
269 * Phase 5 Assabet has two 28F128J3A flash parts in bank 0:
270 */
271static struct mtd_partition assabet_partitions[] = {
272 {
273 .name = "bootloader",
274 .size = 0x00040000,
275 .offset = 0,
276 .mask_flags = MTD_WRITEABLE,
277 }, {
278 .name = "bootloader params",
279 .size = 0x00040000,
280 .offset = MTDPART_OFS_APPEND,
281 .mask_flags = MTD_WRITEABLE,
282 }, {
283 .name = "jffs",
284 .size = MTDPART_SIZ_FULL,
285 .offset = MTDPART_OFS_APPEND,
286 }
287};
288#endif
289
290static struct flash_platform_data assabet_flash_data = {
291 .map_name = "cfi_probe",
292 .parts = assabet_partitions,
293 .nr_parts = ARRAY_SIZE(assabet_partitions),
294};
295
296static struct resource assabet_flash_resources[] = {
Russell Kinga1810992012-01-12 10:25:29 +0000297 DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_32M),
298 DEFINE_RES_MEM(SA1100_CS1_PHYS, SZ_32M),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299};
300
301
302/*
303 * Assabet IrDA support code.
304 */
305
306static int assabet_irda_set_power(struct device *dev, unsigned int state)
307{
308 static unsigned int bcr_state[4] = {
309 ASSABET_BCR_IRDA_MD0,
310 ASSABET_BCR_IRDA_MD1|ASSABET_BCR_IRDA_MD0,
311 ASSABET_BCR_IRDA_MD1,
312 0
313 };
314
Russell King22564bd2013-07-09 10:32:30 +0100315 if (state < 4)
316 ASSABET_BCR_frob(ASSABET_BCR_IRDA_MD1 | ASSABET_BCR_IRDA_MD0,
317 bcr_state[state]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 return 0;
319}
320
321static void assabet_irda_set_speed(struct device *dev, unsigned int speed)
322{
323 if (speed < 4000000)
324 ASSABET_BCR_clear(ASSABET_BCR_IRDA_FSEL);
325 else
326 ASSABET_BCR_set(ASSABET_BCR_IRDA_FSEL);
327}
328
329static struct irda_platform_data assabet_irda_data = {
330 .set_power = assabet_irda_set_power,
331 .set_speed = assabet_irda_set_speed,
332};
333
Russell King69dde862012-01-20 22:18:06 +0000334static struct ucb1x00_plat_data assabet_ucb1x00_data = {
Russell King6ed3e2a2012-01-22 19:23:33 +0000335 .reset = assabet_ucb1x00_reset,
Russell King69dde862012-01-20 22:18:06 +0000336 .gpio_base = -1,
Russell Kingc8857752013-07-09 10:31:20 +0100337 .can_wakeup = 1,
Russell King69dde862012-01-20 22:18:06 +0000338};
339
Russell King323cdfc2005-08-18 10:10:46 +0100340static struct mcp_plat_data assabet_mcp_data = {
341 .mccr0 = MCCR0_ADM,
342 .sclk_rate = 11981000,
Russell King69dde862012-01-20 22:18:06 +0000343 .codec_pdata = &assabet_ucb1x00_data,
Russell King323cdfc2005-08-18 10:10:46 +0100344};
345
Russell King086ada52012-01-14 12:03:22 +0000346static void assabet_lcd_set_visual(u32 visual)
347{
348 u_int is_true_color = visual == FB_VISUAL_TRUECOLOR;
349
350 if (machine_is_assabet()) {
351#if 1 // phase 4 or newer Assabet's
352 if (is_true_color)
353 ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
354 else
355 ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
356#else
357 // older Assabet's
358 if (is_true_color)
359 ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
360 else
361 ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
362#endif
363 }
364}
365
Russell Kinge1b7a722012-01-14 11:50:04 +0000366#ifndef ASSABET_PAL_VIDEO
Russell King086ada52012-01-14 12:03:22 +0000367static void assabet_lcd_backlight_power(int on)
368{
369 if (on)
370 ASSABET_BCR_set(ASSABET_BCR_LIGHT_ON);
371 else
372 ASSABET_BCR_clear(ASSABET_BCR_LIGHT_ON);
373}
374
375/*
376 * Turn on/off the backlight. When turning the backlight on, we wait
377 * 500us after turning it on so we don't cause the supplies to droop
378 * when we enable the LCD controller (and cause a hard reset.)
379 */
380static void assabet_lcd_power(int on)
381{
382 if (on) {
383 ASSABET_BCR_set(ASSABET_BCR_LCD_ON);
384 udelay(500);
385 } else
386 ASSABET_BCR_clear(ASSABET_BCR_LCD_ON);
387}
388
Russell Kinge1b7a722012-01-14 11:50:04 +0000389/*
390 * The assabet uses a sharp LQ039Q2DS54 LCD module. It is actually
391 * takes an RGB666 signal, but we provide it with an RGB565 signal
392 * instead (def_rgb_16).
393 */
394static struct sa1100fb_mach_info lq039q2ds54_info = {
395 .pixclock = 171521, .bpp = 16,
396 .xres = 320, .yres = 240,
397
398 .hsync_len = 5, .vsync_len = 1,
399 .left_margin = 61, .upper_margin = 3,
400 .right_margin = 9, .lower_margin = 0,
401
402 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
403
404 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
405 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
Russell King086ada52012-01-14 12:03:22 +0000406
407 .backlight_power = assabet_lcd_backlight_power,
408 .lcd_power = assabet_lcd_power,
409 .set_visual = assabet_lcd_set_visual,
Russell Kinge1b7a722012-01-14 11:50:04 +0000410};
411#else
Russell King086ada52012-01-14 12:03:22 +0000412static void assabet_pal_backlight_power(int on)
413{
414 ASSABET_BCR_clear(ASSABET_BCR_LIGHT_ON);
415}
416
417static void assabet_pal_power(int on)
418{
419 ASSABET_BCR_clear(ASSABET_BCR_LCD_ON);
420}
421
Russell Kinge1b7a722012-01-14 11:50:04 +0000422static struct sa1100fb_mach_info pal_info = {
423 .pixclock = 67797, .bpp = 16,
424 .xres = 640, .yres = 512,
425
426 .hsync_len = 64, .vsync_len = 6,
427 .left_margin = 125, .upper_margin = 70,
428 .right_margin = 115, .lower_margin = 36,
429
430 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
431 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(512),
Russell King086ada52012-01-14 12:03:22 +0000432
433 .backlight_power = assabet_pal_backlight_power,
434 .lcd_power = assabet_pal_power,
435 .set_visual = assabet_lcd_set_visual,
Russell Kinge1b7a722012-01-14 11:50:04 +0000436};
437#endif
438
Russell Kingbab50a32012-01-26 11:50:23 +0000439#ifdef CONFIG_ASSABET_NEPONSET
440static struct resource neponset_resources[] = {
441 DEFINE_RES_MEM(0x10000000, 0x08000000),
442 DEFINE_RES_MEM(0x18000000, 0x04000000),
443 DEFINE_RES_MEM(0x40000000, SZ_8K),
444 DEFINE_RES_IRQ(IRQ_GPIO25),
445};
446#endif
447
Russell King29786e92016-08-31 08:49:47 +0100448static struct gpiod_lookup_table assabet_cf_gpio_table = {
449 .dev_id = "sa11x0-pcmcia.1",
450 .table = {
451 GPIO_LOOKUP("gpio", 21, "ready", GPIO_ACTIVE_HIGH),
452 GPIO_LOOKUP("gpio", 22, "detect", GPIO_ACTIVE_LOW),
453 GPIO_LOOKUP("gpio", 24, "bvd2", GPIO_ACTIVE_HIGH),
454 GPIO_LOOKUP("gpio", 25, "bvd1", GPIO_ACTIVE_HIGH),
455 GPIO_LOOKUP("assabet", 1, "reset", GPIO_ACTIVE_HIGH),
456 GPIO_LOOKUP("assabet", 7, "bus-enable", GPIO_ACTIVE_LOW),
457 { },
458 },
459};
460
461static struct regulator_consumer_supply assabet_cf_vcc_consumers[] = {
462 REGULATOR_SUPPLY("vcc", "sa11x0-pcmcia.1"),
463};
464
465static struct fixed_voltage_config assabet_cf_vcc_pdata __initdata = {
466 .supply_name = "cf-power",
467 .microvolts = 3300000,
Russell King29786e92016-08-31 08:49:47 +0100468};
469
Linus Walleijefdfeb02018-09-06 14:24:36 +0200470static struct gpiod_lookup_table assabet_cf_vcc_gpio_table = {
471 .dev_id = "reg-fixed-voltage.0",
472 .table = {
473 GPIO_LOOKUP("assabet", 0, NULL, GPIO_ACTIVE_HIGH),
474 { },
475 },
476};
477
Russell King59b23ea2016-08-31 08:49:50 +0100478static struct gpio_led assabet_leds[] __initdata = {
479 {
480 .name = "assabet:red",
481 .default_trigger = "cpu0",
482 .active_low = 1,
483 .default_state = LEDS_GPIO_DEFSTATE_KEEP,
484 }, {
485 .name = "assabet:green",
486 .default_trigger = "heartbeat",
487 .active_low = 1,
488 .default_state = LEDS_GPIO_DEFSTATE_KEEP,
489 },
490};
491
492static const struct gpio_led_platform_data assabet_leds_pdata __initconst = {
493 .num_leds = ARRAY_SIZE(assabet_leds),
494 .leds = assabet_leds,
495};
496
Russell King17c7f4f2016-08-31 08:49:50 +0100497static struct gpio_keys_button assabet_keys_buttons[] = {
498 {
499 .gpio = 0,
500 .irq = IRQ_GPIO0,
501 .desc = "gpio0",
502 .wakeup = 1,
503 .can_disable = 1,
504 .debounce_interval = 5,
505 }, {
506 .gpio = 1,
507 .irq = IRQ_GPIO1,
508 .desc = "gpio1",
509 .wakeup = 1,
510 .can_disable = 1,
511 .debounce_interval = 5,
512 },
513};
514
515static const struct gpio_keys_platform_data assabet_keys_pdata = {
516 .buttons = assabet_keys_buttons,
517 .nbuttons = ARRAY_SIZE(assabet_keys_buttons),
518 .rep = 0,
519};
520
Russell King59f06d62016-08-31 08:49:52 +0100521static struct gpiod_lookup_table assabet_uart1_gpio_table = {
522 .dev_id = "sa11x0-uart.1",
523 .table = {
524 GPIO_LOOKUP("assabet", 16, "dtr", GPIO_ACTIVE_LOW),
525 GPIO_LOOKUP("assabet", 17, "rts", GPIO_ACTIVE_LOW),
526 GPIO_LOOKUP("assabet", 25, "dcd", GPIO_ACTIVE_LOW),
527 GPIO_LOOKUP("assabet", 26, "cts", GPIO_ACTIVE_LOW),
528 GPIO_LOOKUP("assabet", 27, "dsr", GPIO_ACTIVE_LOW),
529 { },
530 },
531};
532
533static struct gpiod_lookup_table assabet_uart3_gpio_table = {
534 .dev_id = "sa11x0-uart.3",
535 .table = {
536 GPIO_LOOKUP("assabet", 28, "cts", GPIO_ACTIVE_LOW),
537 GPIO_LOOKUP("assabet", 29, "dsr", GPIO_ACTIVE_LOW),
538 GPIO_LOOKUP("assabet", 30, "dcd", GPIO_ACTIVE_LOW),
539 GPIO_LOOKUP("assabet", 31, "rng", GPIO_ACTIVE_LOW),
540 { },
541 },
542};
543
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544static void __init assabet_init(void)
545{
546 /*
547 * Ensure that the power supply is in "high power" mode.
548 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 GPSR = GPIO_GPIO16;
Russell King4f592e62012-01-24 09:23:19 +0000550 GPDR |= GPIO_GPIO16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
552 /*
553 * Ensure that these pins are set as outputs and are driving
554 * logic 0. This ensures that we won't inadvertently toggle
555 * the WS latch in the CPLD, and we don't float causing
556 * excessive power drain. --rmk
557 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 GPCR = GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM;
Russell King4f592e62012-01-24 09:23:19 +0000559 GPDR |= GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
561 /*
Russell King49e01e32012-01-24 09:25:57 +0000562 * Also set GPIO27 as an output; this is used to clock UART3
563 * via the FPGA and as otherwise has no pullups or pulldowns,
564 * so stop it floating.
565 */
566 GPCR = GPIO_GPIO27;
567 GPDR |= GPIO_GPIO27;
568
569 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 * Set up registers for sleep mode.
571 */
572 PWER = PWER_GPIO0;
573 PGSR = 0;
574 PCFR = 0;
575 PSDR = 0;
576 PPDR |= PPC_TXD3 | PPC_TXD1;
577 PPSR |= PPC_TXD3 | PPC_TXD1;
578
Russell Kinge36e26a2012-01-20 22:24:07 +0000579 sa11x0_ppc_configure_mcp();
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 if (machine_has_neponset()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582#ifndef CONFIG_ASSABET_NEPONSET
583 printk( "Warning: Neponset detected but full support "
584 "hasn't been configured in the kernel\n" );
Russell Kingbab50a32012-01-26 11:50:23 +0000585#else
586 platform_device_register_simple("neponset", 0,
587 neponset_resources, ARRAY_SIZE(neponset_resources));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#endif
Russell King29786e92016-08-31 08:49:47 +0100589 } else {
Russell King59f06d62016-08-31 08:49:52 +0100590 gpiod_add_lookup_table(&assabet_uart1_gpio_table);
591 gpiod_add_lookup_table(&assabet_uart3_gpio_table);
Linus Walleijefdfeb02018-09-06 14:24:36 +0200592 gpiod_add_lookup_table(&assabet_cf_vcc_gpio_table);
Russell King59f06d62016-08-31 08:49:52 +0100593
Russell King29786e92016-08-31 08:49:47 +0100594 sa11x0_register_fixed_regulator(0, &assabet_cf_vcc_pdata,
Linus Walleijefdfeb02018-09-06 14:24:36 +0200595 assabet_cf_vcc_consumers,
596 ARRAY_SIZE(assabet_cf_vcc_consumers),
597 true);
Russell King29786e92016-08-31 08:49:47 +0100598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
600
Russell King17c7f4f2016-08-31 08:49:50 +0100601 platform_device_register_resndata(NULL, "gpio-keys", 0,
602 NULL, 0,
603 &assabet_keys_pdata,
604 sizeof(assabet_keys_pdata));
605
Russell King59b23ea2016-08-31 08:49:50 +0100606 gpio_led_register_device(-1, &assabet_leds_pdata);
607
Russell Kinge1b7a722012-01-14 11:50:04 +0000608#ifndef ASSABET_PAL_VIDEO
609 sa11x0_register_lcd(&lq039q2ds54_info);
610#else
611 sa11x0_register_lcd(&pal_video);
612#endif
Russell King7a5b4e12009-10-06 14:55:53 +0100613 sa11x0_register_mtd(&assabet_flash_data, assabet_flash_resources,
614 ARRAY_SIZE(assabet_flash_resources));
615 sa11x0_register_irda(&assabet_irda_data);
616 sa11x0_register_mcp(&assabet_mcp_data);
Russell King29786e92016-08-31 08:49:47 +0100617
618 if (!machine_has_neponset())
619 sa11x0_register_pcmcia(1, &assabet_cf_gpio_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620}
621
622/*
623 * On Assabet, we must probe for the Neponset board _before_
624 * paging_init() has occurred to actually determine the amount
625 * of RAM available. To do so, we map the appropriate IO section
626 * in the page table here in order to access GPIO registers.
627 */
628static void __init map_sa1100_gpio_regs( void )
629{
630 unsigned long phys = __PREG(GPLR) & PMD_MASK;
Russell King31696632012-06-06 11:42:36 +0100631 unsigned long virt = (unsigned long)io_p2v(phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 int prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_DOMAIN(DOMAIN_IO);
633 pmd_t *pmd;
634
Mike Rapoporte05c7b12020-06-08 21:33:05 -0700635 pmd = pmd_off_k(virt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 *pmd = __pmd(phys | prot);
637 flush_pmd_entry(pmd);
638}
639
640/*
641 * Read System Configuration "Register"
642 * (taken from "Intel StrongARM SA-1110 Microprocessor Development Board
643 * User's Guide", section 4.4.1)
644 *
645 * This same scan is performed in arch/arm/boot/compressed/head-sa1100.S
646 * to set up the serial port for decompression status messages. We
647 * repeat it here because the kernel may not be loaded as a zImage, and
648 * also because it's a hassle to communicate the SCR value to the kernel
649 * from the decompressor.
650 *
651 * Note that IRQs are guaranteed to be disabled.
652 */
653static void __init get_assabet_scr(void)
654{
Kees Cook3f649ab2020-06-03 13:09:38 -0700655 unsigned long scr, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
657 GPDR |= 0x3fc; /* Configure GPIO 9:2 as outputs */
658 GPSR = 0x3fc; /* Write 0xFF to GPIO 9:2 */
659 GPDR &= ~(0x3fc); /* Configure GPIO 9:2 as inputs */
Russell King2f3eca82005-11-21 17:01:13 +0000660 for(i = 100; i--; ) /* Read GPIO 9:2 */
661 scr = GPLR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 GPDR |= 0x3fc; /* restore correct pin direction */
663 scr &= 0x3fc; /* save as system configuration byte. */
664 SCR_value = scr;
665}
666
667static void __init
Laura Abbott1c2f87c2014-04-13 22:54:58 +0100668fixup_assabet(struct tag *tags, char **cmdline)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669{
670 /* This must be done before any call to machine_has_neponset() */
671 map_sa1100_gpio_regs();
672 get_assabet_scr();
673
674 if (machine_has_neponset())
675 printk("Neponset expansion board detected\n");
676}
677
678
679static void assabet_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
680{
681 if (port->mapbase == _Ser1UTCR0) {
682 if (state)
Russell King59f06d62016-08-31 08:49:52 +0100683 ASSABET_BCR_clear(ASSABET_BCR_RS232EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 else
Russell King59f06d62016-08-31 08:49:52 +0100685 ASSABET_BCR_set(ASSABET_BCR_RS232EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
687}
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689static struct sa1100_port_fns assabet_port_fns __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 .pm = assabet_uart_pm,
691};
692
693static struct map_desc assabet_io_desc[] __initdata = {
Deepak Saxena92519d82005-10-28 15:19:04 +0100694 { /* Board Control Register */
695 .virtual = 0xf1000000,
696 .pfn = __phys_to_pfn(0x12000000),
697 .length = 0x00100000,
698 .type = MT_DEVICE
699 }, { /* MQ200 */
700 .virtual = 0xf2800000,
701 .pfn = __phys_to_pfn(0x4b800000),
702 .length = 0x00800000,
703 .type = MT_DEVICE
704 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705};
706
707static void __init assabet_map_io(void)
708{
709 sa1100_map_io();
710 iotable_init(assabet_io_desc, ARRAY_SIZE(assabet_io_desc));
711
712 /*
713 * Set SUS bit in SDCR0 so serial port 1 functions.
714 * Its called GPCLKR0 in my SA1110 manual.
715 */
716 Ser1SDCR0 |= SDCR0_SUS;
Russell Kingf3964fe2013-10-16 00:09:02 +0100717 MSC1 = (MSC1 & ~0xffff) |
718 MSC_NonBrst | MSC_32BitStMem |
719 MSC_RdAcc(2) | MSC_WrAcc(2) | MSC_Rec(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Russell King374da9d2012-03-25 23:54:16 +0100721 if (!machine_has_neponset())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 sa1100_register_uart_fns(&assabet_port_fns);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724 /*
725 * When Neponset is attached, the first UART should be
726 * UART3. That's what Angel is doing and many documents
727 * are stating this.
728 *
729 * We do the Neponset mapping even if Neponset support
730 * isn't compiled in so the user will still get something on
731 * the expected physical serial port.
732 *
733 * We no longer do this; not all boot loaders support it,
734 * and UART3 appears to be somewhat unreliable with blob.
735 */
736 sa1100_register_uart(0, 1);
737 sa1100_register_uart(2, 3);
738}
739
Russell Kingb9551532016-08-31 08:49:45 +0100740void __init assabet_init_irq(void)
741{
Russell King59b23ea2016-08-31 08:49:50 +0100742 unsigned int assabet_gpio_base;
Russell Kingb9551532016-08-31 08:49:45 +0100743 u32 def_val;
744
745 sa1100_init_irq();
746
747 if (machine_has_neponset())
748 def_val = ASSABET_BCR_DB1111;
749 else
750 def_val = ASSABET_BCR_DB1110;
751
752 /*
753 * Angel sets this, but other bootloaders may not.
754 *
755 * This must precede any driver calls to BCR_set() or BCR_clear().
756 */
Russell King59b23ea2016-08-31 08:49:50 +0100757 assabet_gpio_base = assabet_init_gpio((void *)&ASSABET_BCR, def_val);
758
759 assabet_leds[0].gpio = assabet_gpio_base + 13;
760 assabet_leds[1].gpio = assabet_gpio_base + 14;
Russell Kingb9551532016-08-31 08:49:45 +0100761}
762
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763MACHINE_START(ASSABET, "Intel-Assabet")
Nicolas Pitre17f44252011-07-05 22:38:17 -0400764 .atag_offset = 0x100,
Russell Kinge9dea0c2005-07-03 17:38:58 +0100765 .fixup = fixup_assabet,
766 .map_io = assabet_map_io,
Rob Herringf314f332012-02-24 00:06:51 +0100767 .nr_irqs = SA1100_NR_IRQS,
Russell Kingb9551532016-08-31 08:49:45 +0100768 .init_irq = assabet_init_irq,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700769 .init_time = sa1100_timer_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 .init_machine = assabet_init,
Shawn Guo7fea1ba2012-04-26 21:22:45 +0800771 .init_late = sa11x0_init_late,
Nicolas Pitree9107ab2011-07-05 22:28:09 -0400772#ifdef CONFIG_SA1111
773 .dma_zone_size = SZ_1M,
774#endif
Russell Kingd9ca5832011-11-05 10:28:50 +0000775 .restart = sa11x0_restart,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776MACHINE_END