summaryrefslogtreecommitdiff
path: root/arch/arm/mach-omap2/board-omap3h1.c
blob: 7915962e45bdb836730a1490fa831138b2d52fa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
/*
 * Copyright (C) 2014 Olio Devices, Inc.
 * Authors: Evan Wilson <evan@oliodevices.com>
 *			Mattis Fjallstrom <mattis@oliodevices.com>
 *
 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
 *
 * Modified from the original mach-omap/omap2/board-generic.c did by Paul
 * to support the OMAP2+ device tree boards with an unique board file.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/opp.h>
#include <linux/cpu.h>
#include <linux/mpu.h>
#include <linux/spi/spi.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/mtd/nand.h>

#include <linux/usb/musb.h>
#include <linux/usb/phy.h>
#include <linux/usb/nop-usb-xceiv.h>

#include <linux/platform_data/atmel_mxt_ts.h>
#include <linux/gpio.h>

#include <linux/regulator/machine.h>
#include <linux/regulator/fixed.h>
#include <linux/mfd/tps65910.h>

#include <linux/wakelock.h> /* used in interrupt, waking up.  */
#include <linux/debugfs.h>

#include <linux/led-lm3530.h>

#include <asm/mach-types.h>
#include <asm/mach/arch.h>
#include <asm/mach/map.h>
#include <asm/mach/flash.h>

#include <video/omapdss.h>
#include <video/omap-panel-data.h>
#include <linux/platform_data/mtd-nand-omap2.h>
#include <linux/platform_data/serial-omap.h>
#include <linux/interrupt.h>

#include <linux/of_irq.h>
#include <linux/of_platform.h>
#include <linux/power/bq27x00_battery.h>

#include "common.h"
#include "omap_device.h"
#include "gpmc.h"
#include "soc.h"
#include "mux.h"
#include "pm.h"
#include "board-flash.h"
#include "common-board-devices.h"
#include "board-omap3h1.h"
#include "prm2xxx_3xxx.h"
#include "prm-regbits-34xx.h"

#include "sdram-micron-mt29c8g96m-48.h"

#define NAND_CS 0

#define MPUIRQ_GPIO 31
#define ATMEL_MXT_GPIO 105
#define TPS_SYS_NIRQ 0
#define USB_IRQ 124
#define USB_CS 17
#define CHG_GPOUT 10

#define DEFAULT_RXDMA_POLLRATE		1	/* RX DMA polling rate (us) */
#define DEFAULT_RXDMA_BUFSIZE		4096	/* RX DMA buffer size */
#define DEFAULT_RXDMA_TIMEOUT		(3 * HZ)/* RX DMA timeout (jiffies) */

#if defined(CONFIG_MACH_OMAP3_H1_DVT1) || defined(CONFIG_MACH_OMAP3_H1_DVT2) || defined (CONFIG_MACH_OMAP3_H1_PV)
#define LCD_RESET_GPIO 94
#else 
#define LCD_RESET_GPIO 122
#endif


#define BACKLIGHT_PWM_GPIO    128

static struct of_device_id omap_dt_match_table[] __initdata = {
	{ .compatible = "olio,omap3-h1", },
	{ .compatible = "simple-bus", },
	{ .compatible = "ti,omap-infra", },
	{ }
};

static struct mtd_partition omap3h1_nand_partitions[] = {
/* All the partition sizes are listed in terms of NAND block size */
	{
		.name       = "X-Loader",
		.offset	    = 0,
		.size       = 4 * NAND_BLOCK_SIZE,  /* 512Kb */
		.mask_flags	= MTD_WRITEABLE,        /* force read-only */
	},
	{
		.name       = "U-Boot",
		.offset	    = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
		.size	    = 15 * NAND_BLOCK_SIZE, /* ~2Mb */
		.mask_flags	= MTD_WRITEABLE,        /* force read-only */
	},
	{
		.name   = "U-Boot Env",
		.offset = MTDPART_OFS_APPEND,  /* Offset = 0x260000 */
		.size   = 1 * NAND_BLOCK_SIZE, /* 128Kb */
	},
	{
		.name   = "kernel",
		.offset = MTDPART_OFS_APPEND,	/* Offset = 0x280000 */
		.size   = 40 * NAND_BLOCK_SIZE, /* ~5Mb */
	},
	{
		.name   = "initramfs",
		.offset = MTDPART_OFS_APPEND,   /* Offset = 0x780000 */
		.size   = 80 * NAND_BLOCK_SIZE, /* ~10Mb */
	},
	{
		.name   = "devicetree",
		.offset	= MTDPART_OFS_APPEND,	/* Offset = 0x1180000 */
		.size   = 4 * NAND_BLOCK_SIZE,  /* 512Kb */
	},
	{
		.name   = "ramdisk",  /* For Android's ramdisk */
		.offset	= MTDPART_OFS_APPEND,	 /* Offset = 0x1200000 */
		.size   = 100 * NAND_BLOCK_SIZE, /* ~12Mb */
	},
	{
		.name   = "system",
		.offset = MTDPART_OFS_APPEND,	  /* Offset = 0x1E80000 */
		.size   = 2048 * NAND_BLOCK_SIZE, /* 0x7D0*0x20000 = ~256Mb */
	},
	{
		.name   = "cache",
		.offset = MTDPART_OFS_APPEND,	  /* Offset = 0x11E80000 */
		.size   = 400 * NAND_BLOCK_SIZE,  /* 0x190*0x20000 = ~50Mb */
	},
	{
		.name   = "recovery",
		.offset = MTDPART_OFS_APPEND,     /* Offset = 0x14A80000 */
		.size   = 200 * NAND_BLOCK_SIZE,  /* C8*20000 = ~26Mb */
	},
	{
		.name   = "userdata",
		.offset = MTDPART_OFS_APPEND,   /* Offset = 0x16380000 */
		.size   = MTDPART_SIZ_FULL,     /* the rest */
	},
};

static struct omap_dss_device omap3h1_lcd_device = {
	.type				= OMAP_DISPLAY_TYPE_DPI,
	.name				= "olio_h1_panel",
	.driver_name 		= "ili9342_panel",
	.phy.dpi.data_lines = 18,
	.reset_gpio			= LCD_RESET_GPIO,
};

static struct omap_dss_device *omap3h1_dss_devices[] = {
	&omap3h1_lcd_device,
};

static struct omap_dss_board_info omap3h1_dss_data = {
	.num_devices 	= 1,
	.devices = omap3h1_dss_devices,
	.default_device = &omap3h1_lcd_device,
};

static struct spi_board_info omap3h1_spi_board_info[] __initdata = {
	{
		.modalias		= "ili9342-spi",
		.bus_num		= 1,
		.chip_select 	= 1,
		.max_speed_hz 	= 375000,
		.platform_data	= &omap3h1_lcd_device,
		.mode			= SPI_MODE_0,
	}
};

static int __init omap3h1_spi_init(void) {
	spi_register_board_info(omap3h1_spi_board_info,
				ARRAY_SIZE(omap3h1_spi_board_info));
	return 0;
}


/* 
 * int_config is interrupt config, INT_ENABLE register. To enable _all_ 
 * interrupts, set to 0x59. I think. --mfj
 * 
 * Level shifter seems to set power rail between two options - 1 means VDD.
 * (0 means VLogic, which I'm not sure what it is).
 */

#ifndef CONFIG_MACH_OMAP3_H1_PV2 
static struct mpu_platform_data mpu_data = {
	.int_config  = 0x00,
	.level_shifter = 1,
	.orientation = {  0, -1,  0,
			  -1,  0,  0,
			  0,  0,  1 },
};
#endif


static struct bq27x00_platform_data bq_platform_data = {
	.charger_name = "3-0049",
};

static struct lm3530_platform_data omap3h1_backlight_platform_data = {
	.mode = LM3530_BL_MODE_SIMPLE_MANUAL,
	//.als_input_mode = LM3530_INPUT_ALS1,
	.max_current = LM3530_FS_CURR_29mA,
	//.pwm_pol_hi = true,
	//.als_avrg_time = LM3530_ALS_AVRG_TIME_512ms,
	.brt_ramp_law = 0,
	.brt_ramp_fall = LM3530_RAMP_TIME_1ms, /* LM3530_RAMP_TIME_1s, */
	.brt_ramp_rise = LM3530_RAMP_TIME_1ms, /* LM3530_RAMP_TIME_1s, */
	//.als1_resistor_sel = LM3530_ALS_IMPD_13_53kOhm,
	//.als2_resistor_sel = LM3530_ALS_IMPD_Z,
	//.als_vmin = 730,	    /* mV */
	//.als_vmax = 10a20,	/* mV */
	.brt_val = 0x64,	/* initial brightness */
	.pwm_gpio = BACKLIGHT_PWM_GPIO,
};

static struct mxt_platform_data mxt_data = {
	.irqflags	= IRQF_TRIGGER_FALLING,
	.suspend_mode = MXT_SUSPEND_DEEP_SLEEP
}; 


static struct platform_device bcm20702_bluetooth_device = {
	.name = "bcm20702_bluetooth",
	.id   = -1,
};

static struct platform_device omap3h1_dmic_codec = {
	.name = "dmic-codec",
	.id = -1,
};

static struct platform_device omap3h1_bt_codec = {
		.name = "omap3h1_bt_sco",
		.id = -1,
};

/* --------------------------------------------------------------------------- */
/* USB settings 
 */



static struct omap_musb_board_data musb_board_data = {
	.interface_type		= MUSB_INTERFACE_ULPI,
	.mode   			= MUSB_OTG,
	.power	    		= 100,
};

static struct nop_usb_xceiv_platform_data nop_plat_data = {
	.type     = USB_PHY_TYPE_USB2,
	.clk_rate = 60000000, /* 60 MHz */
	.needs_vcc = 0,
	.needs_reset = 0,
};

static struct platform_device nop_phy_device = {
	.name = "nop_usb_xceiv",
	.id   = -1,
	.dev  = {
		.platform_data = &nop_plat_data,
	},
};


/* static struct usbhs_omap_platform_data usbhs_bdata __initdata = { */
/* 	.port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, */
/* }; */




/* ====================================================================== */


static struct i2c_board_info __initdata omap3h1_i2c1_board_info[] = {
	{
	},
#if defined (CONFIG_MACH_OMAP3_H1_DVT2) || defined (CONFIG_MACH_OMAP3_H1_PV)
};
static struct i2c_board_info __initdata omap3h1_i2c2_board_info[] = {
#endif
	{
#ifdef CONFIG_MACH_OMAP3_H1_PV2
		I2C_BOARD_INFO("lsm6ds3", 0x6a),
#else
		I2C_BOARD_INFO("mpu6515", 0x68),
		.platform_data = &mpu_data,
#endif
	},
	{
		/* Backlight */
		I2C_BOARD_INFO("lm3530-led", 0x38),
		.platform_data = &omap3h1_backlight_platform_data,
	},
	{
		I2C_BOARD_INFO("mXT224", 0x4a),
		.platform_data = &mxt_data,
	},
	{
		I2C_BOARD_INFO("cm3391", 0x10),
	},
#ifdef CONFIG_MACH_OMAP3_H1_EVT1
};
static struct i2c_board_info __initdata omap3h1_i2c3_board_info[] = {
#endif
	{
		I2C_BOARD_INFO("bq274xx", 0x55),
		.platform_data = &bq_platform_data,
	},
};

#ifdef CONFIG_MACH_OMAP3_H1_PV2
static struct i2c_board_info __initdata omap3h1_i2c3_board_info[] = {
	{
		I2C_BOARD_INFO("ts81001", 0x49),
	},
};
#endif

/***************************************************************************
 * omap_uart data 
 */

/* Some notes:
   .dma_enabled	= false,
   .dma_rx_buf_size = DEFAULT_RXDMA_BUFSIZE,
   .dma_rx_poll_rate = DEFAULT_RXDMA_POLLRATE,
   .dma_rx_timeout = DEFAULT_RXDMA_TIMEOUT,
   This one sets runtime pm autosuspend timeout - -1 disables runtime
   pm (that is, pm that's done while running, not sleeping).
   .autosuspend_timeout = DEFAULT_AUTOSUSPEND_DELAY, ( -1 or X ms. )
        
   Wakelock timeout: If there's an interrupt on the serial port, this is
   how long we expect to wait before the system is functional.
   .wakelock_timeout - for minnow, this is 150 (BT) or 50 (M4 debug).
   Can be left out.

   .DTR_* -> can be left out. I can't find anyone using it.

   int			    DTR_gpio;
   int			    DTR_inverted;
   int			    DTR_present;
   bool			wakeup_capable;
        
   bool			open_close_pm; - Minnow uses this for c55 only
   unsigned int	rx_trig;  Minnow, BT & debug only

   The flags field is not used (it's hardcoded in omap_serial_init_port).
*/

static struct omap_uart_port_info omap_uart_ports[] = {
	{
		.dma_enabled = false,	/* To specify DMA Mode */
		.dma_rx_buf_size  = DEFAULT_RXDMA_BUFSIZE,
		.dma_rx_timeout   = DEFAULT_RXDMA_TIMEOUT,
		.dma_rx_poll_rate = DEFAULT_RXDMA_POLLRATE,
		.autosuspend_timeout = 100,
		.wakelock_timeout = 150,
		.wake_peer = bcm_bt_lpm_exit_lpm_locked,
		.wakeup_capable = true,
		.rx_trig = 32,
        
		/* OLIO: make sure RTS isn't enabled before we're ready */

		.rts_wait    = true,
		.rts_enable_fn  = rts_exit_sleep_mode,
		.rts_disable_fn = rts_enter_sleep_mode,
	},
	{
		.dma_enabled = false,	/* To specify DMA Mode */
		.dma_rx_buf_size  = DEFAULT_RXDMA_BUFSIZE,
		.dma_rx_timeout   = DEFAULT_RXDMA_TIMEOUT,
		.dma_rx_poll_rate = DEFAULT_RXDMA_POLLRATE,
		.autosuspend_timeout = 0,
		.wakeup_capable = false,
		.rts_wait = false,
		.rts_enable_fn = NULL,
		.rts_disable_fn = NULL,
	},
	{
		.dma_enabled = false,	/* To specify DMA Mode */
		.dma_rx_buf_size  = DEFAULT_RXDMA_BUFSIZE,
		.dma_rx_timeout   = DEFAULT_RXDMA_TIMEOUT,
		.dma_rx_poll_rate = DEFAULT_RXDMA_POLLRATE,
		.autosuspend_timeout = -1,
		.wakeup_capable = true,
		.rts_wait = false,
		.rts_enable_fn = NULL,
		.rts_disable_fn = NULL,
	},
	{
		.dma_enabled = false,	/* To specify DMA Mode */
		.dma_rx_buf_size  = DEFAULT_RXDMA_BUFSIZE,
		.dma_rx_timeout   = DEFAULT_RXDMA_TIMEOUT,
		.dma_rx_poll_rate = DEFAULT_RXDMA_POLLRATE,
		.autosuspend_timeout = 0,
		.wakeup_capable = false,
		.rts_wait = false,
		.rts_enable_fn = NULL,
		.rts_disable_fn = NULL,
	},
};


/***************************************************************************
 * omap3_h1_i2c_init - init the i2c buses 
 *
 */

static int __init omap3_h1_i2c_init(void)
{
	int acc_irq;

	/* In Linux 3.10 we need to request an IRQ through
	 * gpio_to_irq. This means it can't be set at compile time, and
	 * must be done at runtime. In other words, here.
	 */
    
	gpio_request_one(ATMEL_MXT_GPIO, GPIOF_IN, "atmel_mxt_ts CHG");
	gpio_request_one(MPUIRQ_GPIO, GPIOF_IN, "Accl IRQ pin");

	acc_irq = gpio_to_irq(MPUIRQ_GPIO);

#if defined (CONFIG_MACH_OMAP3_H1_DVT2) || defined (CONFIG_MACH_OMAP3_H1_PV)
	omap3h1_i2c2_board_info[2].irq = gpio_to_irq(ATMEL_MXT_GPIO);
	omap3h1_i2c2_board_info[0].irq = acc_irq;
#else
	omap3h1_i2c1_board_info[3].irq = gpio_to_irq(ATMEL_MXT_GPIO);
	omap3h1_i2c1_board_info[1].irq = acc_irq;
#endif

#if defined (CONFIG_MACH_OMAP3_H1_PV)
	omap3h1_i2c2_board_info[4].irq = gpio_to_irq(CHG_GPOUT);
#endif

	gpio_request_one(USB_CS, GPIOF_OUT_INIT_HIGH, "USB on");
    
	/* Register buses */

	// omap_register_i2c_bus(1, 400, omap3h1_i2c1_board_info, ARRAY_SIZE(omap3h1_i2c1_board_info));
#if defined (CONFIG_MACH_OMAP3_H1_DVT2) || defined (CONFIG_MACH_OMAP3_H1_PV)
	omap_register_i2c_bus(2, 400, omap3h1_i2c2_board_info,
			      ARRAY_SIZE(omap3h1_i2c2_board_info));
#else
	omap_register_i2c_bus(2, 400, NULL, 0);
#endif
	omap_register_i2c_bus(3, 100, omap3h1_i2c3_board_info,
			      ARRAY_SIZE(omap3h1_i2c3_board_info));

	return 0;
}


static struct platform_device *omap3h1_devices[] __initdata = {
        &bcm20702_bluetooth_device,
        &nop_phy_device,
	&omap3h1_dmic_codec,
	&omap3h1_bt_codec,
};

static void __init omap3_h1_init(void)
{

	/* Read what we can from the device tree */

	of_platform_populate(NULL, omap_dt_match_table, NULL, NULL);

#ifdef CONFIG_MACH_OMAP3_H1_PV
	/* The PV units need reversed polarity for the sysclkreq pin. */

	omap2_prm_rmw_mod_reg_bits(OMAP3430_CLKREQ_POL_MASK,
				   0, OMAP3430_GR_MOD,
				   OMAP3_PRM_POLCTRL_OFFSET);
#endif 

	board_nand_init(omap3h1_nand_partitions,
			ARRAY_SIZE(omap3h1_nand_partitions), NAND_CS,
			NAND_BUSWIDTH_16, NULL);

	omap_sdrc_init(mt29c8g96_sdrc_params, mt29c8g96_sdrc_params);

	omap3_h1_i2c_init();

	platform_add_devices(omap3h1_devices, ARRAY_SIZE(omap3h1_devices));

	omap3h1_spi_init();

	omap_serial_board_init(omap_uart_ports);

	omap_display_init(&omap3h1_dss_data);

	usb_bind_phy("musb-hdrc.0.auto", 0, "nop_usb_xceiv"); /* "tusb-usb-h1" */

	usb_musb_init(&musb_board_data);
}

static const char *omap3_h1_boards_compat[] __initdata = {
	"olio,omap3-h1",
	NULL,
};

DT_MACHINE_START(OMAP3_H1, "Olio OMAP3 H1 (Flattened Device Tree)")
.atag_offset = 0x100,
	.reserve	= omap_reserve,
	.map_io		= omap3_map_io,
	.init_early	= omap3630_init_early,
/* .init_irq		= omap3_init_irq, */
	.init_irq	= omap_intc_of_init,
	.handle_irq	= omap3_intc_handle_irq,
	.init_machine	= omap3_h1_init,
	.init_late	= omap3630_init_late,
	.init_time  = omap3_sync32k_timer_init,
/* .init_time	= omap3_secure_sync32k_timer_init, */
	.dt_compat	= omap3_h1_boards_compat,
	.restart	= omap3xxx_restart,
	MACHINE_END

#if 0 /* removing ... for now */
	MACHINE_START(OMAP3_H1, "Olio OMAP3 H1 Board")
	.atag_offset	= 0x100,
	.reserve		= omap_reserve,
	.map_io			= omap3_map_io,
	.init_early		= omap3630_init_early,
	.init_irq		= omap3_init_irq,
	.handle_irq		= omap3_intc_handle_irq,
	.init_machine	= omap3_h1_init,
	.init_late		= omap3630_init_late,
	.init_time      = omap3_sync32k_timer_init,
/* .init_time		= omap3_secure_sync32k_timer_init, */
/* .dt_compat		= omap3_h1_boards_compat, */
	.restart		= omap3xxx_restart,
	MACHINE_END
#endif