cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

board-htcherald.c (16726B)


      1// SPDX-License-Identifier: GPL-2.0-or-later
      2/*
      3 * HTC Herald board configuration
      4 * Copyright (C) 2009 Cory Maccarrone <darkstar6262@gmail.com>
      5 * Copyright (C) 2009 Wing Linux
      6 *
      7 * Based on the board-htcwizard.c file from the linwizard project:
      8 * Copyright (C) 2006 Unai Uribarri
      9 * Copyright (C) 2008 linwizard.sourceforge.net
     10 */
     11#include <linux/kernel.h>
     12#include <linux/init.h>
     13#include <linux/platform_device.h>
     14#include <linux/input.h>
     15#include <linux/delay.h>
     16#include <linux/gpio.h>
     17#include <linux/gpio_keys.h>
     18#include <linux/i2c.h>
     19#include <linux/platform_data/i2c-gpio.h>
     20#include <linux/htcpld.h>
     21#include <linux/leds.h>
     22#include <linux/spi/spi.h>
     23#include <linux/spi/ads7846.h>
     24#include <linux/omapfb.h>
     25#include <linux/platform_data/keypad-omap.h>
     26#include <linux/soc/ti/omap1-io.h>
     27
     28#include <asm/mach-types.h>
     29#include <asm/mach/arch.h>
     30
     31#include "hardware.h"
     32#include "omap7xx.h"
     33#include "mmc.h"
     34#include "irqs.h"
     35#include "usb.h"
     36#include "common.h"
     37
     38/* LCD register definition */
     39#define       OMAP_LCDC_CONTROL               (0xfffec000 + 0x00)
     40#define       OMAP_LCDC_STATUS                (0xfffec000 + 0x10)
     41#define       OMAP_DMA_LCD_CCR                (0xfffee300 + 0xc2)
     42#define       OMAP_DMA_LCD_CTRL               (0xfffee300 + 0xc4)
     43#define       OMAP_LCDC_CTRL_LCD_EN           (1 << 0)
     44#define       OMAP_LCDC_STAT_DONE             (1 << 0)
     45
     46/* GPIO definitions for the power button and keyboard slide switch */
     47#define HTCHERALD_GPIO_POWER 139
     48#define HTCHERALD_GPIO_SLIDE 174
     49#define HTCHERALD_GIRQ_BTNS 141
     50
     51/* GPIO definitions for the touchscreen */
     52#define HTCHERALD_GPIO_TS 76
     53
     54/* HTCPLD definitions */
     55
     56/*
     57 * CPLD Logic
     58 *
     59 * Chip 3 - 0x03
     60 *
     61 * Function            7 6 5 4  3 2 1 0
     62 * ------------------------------------
     63 * DPAD light          x x x x  x x x 1
     64 * SoundDev            x x x x  1 x x x
     65 * Screen white        1 x x x  x x x x
     66 * MMC power on        x x x x  x 1 x x
     67 * Happy times (n)     0 x x x  x 1 x x
     68 *
     69 * Chip 4 - 0x04
     70 *
     71 * Function            7 6 5 4  3 2 1 0
     72 * ------------------------------------
     73 * Keyboard light      x x x x  x x x 1
     74 * LCD Bright (4)      x x x x  x 1 1 x
     75 * LCD Bright (3)      x x x x  x 0 1 x
     76 * LCD Bright (2)      x x x x  x 1 0 x
     77 * LCD Bright (1)      x x x x  x 0 0 x
     78 * LCD Off             x x x x  0 x x x
     79 * LCD image (fb)      1 x x x  x x x x
     80 * LCD image (white)   0 x x x  x x x x
     81 * Caps lock LED       x x 1 x  x x x x
     82 *
     83 * Chip 5 - 0x05
     84 *
     85 * Function            7 6 5 4  3 2 1 0
     86 * ------------------------------------
     87 * Red (solid)         x x x x  x 1 x x
     88 * Red (flash)         x x x x  x x 1 x
     89 * Green (GSM flash)   x x x x  1 x x x
     90 * Green (GSM solid)   x x x 1  x x x x
     91 * Green (wifi flash)  x x 1 x  x x x x
     92 * Blue (bt flash)     x 1 x x  x x x x
     93 * DPAD Int Enable     1 x x x  x x x 0
     94 *
     95 * (Combinations of the above can be made for different colors.)
     96 * The direction pad interrupt enable must be set each time the
     97 * interrupt is handled.
     98 *
     99 * Chip 6 - 0x06
    100 *
    101 * Function            7 6 5 4  3 2 1 0
    102 * ------------------------------------
    103 * Vibrator            x x x x  1 x x x
    104 * Alt LED             x x x 1  x x x x
    105 * Screen white        1 x x x  x x x x
    106 * Screen white        x x 1 x  x x x x
    107 * Screen white        x 0 x x  x x x x
    108 * Enable kbd dpad     x x x x  x x 0 x
    109 * Happy Times         0 1 0 x  x x 0 x
    110 */
    111
    112/*
    113 * HTCPLD GPIO lines start 16 after OMAP_MAX_GPIO_LINES to account
    114 * for the 16 MPUIO lines.
    115 */
    116#define HTCPLD_GPIO_START_OFFSET	(OMAP_MAX_GPIO_LINES + 16)
    117#define HTCPLD_IRQ(chip, offset)	(OMAP_IRQ_END + 8 * (chip) + (offset))
    118#define HTCPLD_BASE(chip, offset)	\
    119	(HTCPLD_GPIO_START_OFFSET + 8 * (chip) + (offset))
    120
    121#define HTCPLD_GPIO_LED_DPAD		HTCPLD_BASE(0, 0)
    122#define HTCPLD_GPIO_LED_KBD		HTCPLD_BASE(1, 0)
    123#define HTCPLD_GPIO_LED_CAPS		HTCPLD_BASE(1, 5)
    124#define HTCPLD_GPIO_LED_RED_FLASH	HTCPLD_BASE(2, 1)
    125#define HTCPLD_GPIO_LED_RED_SOLID	HTCPLD_BASE(2, 2)
    126#define HTCPLD_GPIO_LED_GREEN_FLASH	HTCPLD_BASE(2, 3)
    127#define HTCPLD_GPIO_LED_GREEN_SOLID	HTCPLD_BASE(2, 4)
    128#define HTCPLD_GPIO_LED_WIFI		HTCPLD_BASE(2, 5)
    129#define HTCPLD_GPIO_LED_BT		HTCPLD_BASE(2, 6)
    130#define HTCPLD_GPIO_LED_VIBRATE		HTCPLD_BASE(3, 3)
    131#define HTCPLD_GPIO_LED_ALT		HTCPLD_BASE(3, 4)
    132
    133#define HTCPLD_GPIO_RIGHT_KBD		HTCPLD_BASE(6, 7)
    134#define HTCPLD_GPIO_UP_KBD		HTCPLD_BASE(6, 6)
    135#define HTCPLD_GPIO_LEFT_KBD		HTCPLD_BASE(6, 5)
    136#define HTCPLD_GPIO_DOWN_KBD		HTCPLD_BASE(6, 4)
    137
    138#define HTCPLD_GPIO_RIGHT_DPAD		HTCPLD_BASE(7, 7)
    139#define HTCPLD_GPIO_UP_DPAD		HTCPLD_BASE(7, 6)
    140#define HTCPLD_GPIO_LEFT_DPAD		HTCPLD_BASE(7, 5)
    141#define HTCPLD_GPIO_DOWN_DPAD		HTCPLD_BASE(7, 4)
    142#define HTCPLD_GPIO_ENTER_DPAD		HTCPLD_BASE(7, 3)
    143
    144/*
    145 * The htcpld chip requires a gpio write to a specific line
    146 * to re-enable interrupts after one has occurred.
    147 */
    148#define HTCPLD_GPIO_INT_RESET_HI	HTCPLD_BASE(2, 7)
    149#define HTCPLD_GPIO_INT_RESET_LO	HTCPLD_BASE(2, 0)
    150
    151/* Chip 5 */
    152#define HTCPLD_IRQ_RIGHT_KBD		HTCPLD_IRQ(0, 7)
    153#define HTCPLD_IRQ_UP_KBD		HTCPLD_IRQ(0, 6)
    154#define HTCPLD_IRQ_LEFT_KBD		HTCPLD_IRQ(0, 5)
    155#define HTCPLD_IRQ_DOWN_KBD		HTCPLD_IRQ(0, 4)
    156
    157/* Chip 6 */
    158#define HTCPLD_IRQ_RIGHT_DPAD		HTCPLD_IRQ(1, 7)
    159#define HTCPLD_IRQ_UP_DPAD		HTCPLD_IRQ(1, 6)
    160#define HTCPLD_IRQ_LEFT_DPAD		HTCPLD_IRQ(1, 5)
    161#define HTCPLD_IRQ_DOWN_DPAD		HTCPLD_IRQ(1, 4)
    162#define HTCPLD_IRQ_ENTER_DPAD		HTCPLD_IRQ(1, 3)
    163
    164/* Keyboard definition */
    165
    166static const unsigned int htc_herald_keymap[] = {
    167	KEY(0, 0, KEY_RECORD), /* Mail button */
    168	KEY(1, 0, KEY_CAMERA), /* Camera */
    169	KEY(2, 0, KEY_PHONE), /* Send key */
    170	KEY(3, 0, KEY_VOLUMEUP), /* Volume up */
    171	KEY(4, 0, KEY_F2),  /* Right bar (landscape) */
    172	KEY(5, 0, KEY_MAIL), /* Win key (portrait) */
    173	KEY(6, 0, KEY_DIRECTORY), /* Right bar (portrait) */
    174	KEY(0, 1, KEY_LEFTCTRL), /* Windows key */
    175	KEY(1, 1, KEY_COMMA),
    176	KEY(2, 1, KEY_M),
    177	KEY(3, 1, KEY_K),
    178	KEY(4, 1, KEY_SLASH), /* OK key */
    179	KEY(5, 1, KEY_I),
    180	KEY(6, 1, KEY_U),
    181	KEY(0, 2, KEY_LEFTALT),
    182	KEY(1, 2, KEY_TAB),
    183	KEY(2, 2, KEY_N),
    184	KEY(3, 2, KEY_J),
    185	KEY(4, 2, KEY_ENTER),
    186	KEY(5, 2, KEY_H),
    187	KEY(6, 2, KEY_Y),
    188	KEY(0, 3, KEY_SPACE),
    189	KEY(1, 3, KEY_L),
    190	KEY(2, 3, KEY_B),
    191	KEY(3, 3, KEY_V),
    192	KEY(4, 3, KEY_BACKSPACE),
    193	KEY(5, 3, KEY_G),
    194	KEY(6, 3, KEY_T),
    195	KEY(0, 4, KEY_CAPSLOCK), /* Shift */
    196	KEY(1, 4, KEY_C),
    197	KEY(2, 4, KEY_F),
    198	KEY(3, 4, KEY_R),
    199	KEY(4, 4, KEY_O),
    200	KEY(5, 4, KEY_E),
    201	KEY(6, 4, KEY_D),
    202	KEY(0, 5, KEY_X),
    203	KEY(1, 5, KEY_Z),
    204	KEY(2, 5, KEY_S),
    205	KEY(3, 5, KEY_W),
    206	KEY(4, 5, KEY_P),
    207	KEY(5, 5, KEY_Q),
    208	KEY(6, 5, KEY_A),
    209	KEY(0, 6, KEY_CONNECT), /* Voice button */
    210	KEY(2, 6, KEY_CANCEL), /* End key */
    211	KEY(3, 6, KEY_VOLUMEDOWN), /* Volume down */
    212	KEY(4, 6, KEY_F1), /* Left bar (landscape) */
    213	KEY(5, 6, KEY_WWW), /* OK button (portrait) */
    214	KEY(6, 6, KEY_CALENDAR), /* Left bar (portrait) */
    215};
    216
    217static const struct matrix_keymap_data htc_herald_keymap_data = {
    218	.keymap		= htc_herald_keymap,
    219	.keymap_size	= ARRAY_SIZE(htc_herald_keymap),
    220};
    221
    222static struct omap_kp_platform_data htcherald_kp_data = {
    223	.rows	= 7,
    224	.cols	= 7,
    225	.delay = 20,
    226	.rep = true,
    227	.keymap_data = &htc_herald_keymap_data,
    228};
    229
    230static struct resource kp_resources[] = {
    231	[0] = {
    232		.start	= INT_7XX_MPUIO_KEYPAD,
    233		.end	= INT_7XX_MPUIO_KEYPAD,
    234		.flags	= IORESOURCE_IRQ,
    235	},
    236};
    237
    238static struct platform_device kp_device = {
    239	.name		= "omap-keypad",
    240	.id		= -1,
    241	.dev		= {
    242		.platform_data = &htcherald_kp_data,
    243	},
    244	.num_resources	= ARRAY_SIZE(kp_resources),
    245	.resource	= kp_resources,
    246};
    247
    248/* GPIO buttons for keyboard slide and power button */
    249static struct gpio_keys_button herald_gpio_keys_table[] = {
    250	{BTN_0,  HTCHERALD_GPIO_POWER, 1, "POWER", EV_KEY, 1, 20},
    251	{SW_LID, HTCHERALD_GPIO_SLIDE, 0, "SLIDE", EV_SW,  1, 20},
    252
    253	{KEY_LEFT,  HTCPLD_GPIO_LEFT_KBD,  1, "LEFT",  EV_KEY, 1, 20},
    254	{KEY_RIGHT, HTCPLD_GPIO_RIGHT_KBD, 1, "RIGHT", EV_KEY, 1, 20},
    255	{KEY_UP,    HTCPLD_GPIO_UP_KBD,    1, "UP",    EV_KEY, 1, 20},
    256	{KEY_DOWN,  HTCPLD_GPIO_DOWN_KBD,  1, "DOWN",  EV_KEY, 1, 20},
    257
    258	{KEY_LEFT,  HTCPLD_GPIO_LEFT_DPAD,   1, "DLEFT",  EV_KEY, 1, 20},
    259	{KEY_RIGHT, HTCPLD_GPIO_RIGHT_DPAD,  1, "DRIGHT", EV_KEY, 1, 20},
    260	{KEY_UP,    HTCPLD_GPIO_UP_DPAD,     1, "DUP",    EV_KEY, 1, 20},
    261	{KEY_DOWN,  HTCPLD_GPIO_DOWN_DPAD,   1, "DDOWN",  EV_KEY, 1, 20},
    262	{KEY_ENTER, HTCPLD_GPIO_ENTER_DPAD,  1, "DENTER", EV_KEY, 1, 20},
    263};
    264
    265static struct gpio_keys_platform_data herald_gpio_keys_data = {
    266	.buttons	= herald_gpio_keys_table,
    267	.nbuttons	= ARRAY_SIZE(herald_gpio_keys_table),
    268	.rep		= true,
    269};
    270
    271static struct platform_device herald_gpiokeys_device = {
    272	.name      = "gpio-keys",
    273	.id		= -1,
    274	.dev = {
    275		.platform_data = &herald_gpio_keys_data,
    276	},
    277};
    278
    279/* LEDs for the Herald.  These connect to the HTCPLD GPIO device. */
    280static const struct gpio_led gpio_leds[] = {
    281	{"dpad",        NULL, HTCPLD_GPIO_LED_DPAD,        0, 0, LEDS_GPIO_DEFSTATE_OFF},
    282	{"kbd",         NULL, HTCPLD_GPIO_LED_KBD,         0, 0, LEDS_GPIO_DEFSTATE_OFF},
    283	{"vibrate",     NULL, HTCPLD_GPIO_LED_VIBRATE,     0, 0, LEDS_GPIO_DEFSTATE_OFF},
    284	{"green_solid", NULL, HTCPLD_GPIO_LED_GREEN_SOLID, 0, 0, LEDS_GPIO_DEFSTATE_OFF},
    285	{"green_flash", NULL, HTCPLD_GPIO_LED_GREEN_FLASH, 0, 0, LEDS_GPIO_DEFSTATE_OFF},
    286	{"red_solid",   "mmc0", HTCPLD_GPIO_LED_RED_SOLID, 0, 0, LEDS_GPIO_DEFSTATE_OFF},
    287	{"red_flash",   NULL, HTCPLD_GPIO_LED_RED_FLASH,   0, 0, LEDS_GPIO_DEFSTATE_OFF},
    288	{"wifi",        NULL, HTCPLD_GPIO_LED_WIFI,        0, 0, LEDS_GPIO_DEFSTATE_OFF},
    289	{"bt",          NULL, HTCPLD_GPIO_LED_BT,          0, 0, LEDS_GPIO_DEFSTATE_OFF},
    290	{"caps",        NULL, HTCPLD_GPIO_LED_CAPS,        0, 0, LEDS_GPIO_DEFSTATE_OFF},
    291	{"alt",         NULL, HTCPLD_GPIO_LED_ALT,         0, 0, LEDS_GPIO_DEFSTATE_OFF},
    292};
    293
    294static struct gpio_led_platform_data gpio_leds_data = {
    295	.leds		= gpio_leds,
    296	.num_leds	= ARRAY_SIZE(gpio_leds),
    297};
    298
    299static struct platform_device gpio_leds_device = {
    300	.name		= "leds-gpio",
    301	.id		= 0,
    302	.dev	= {
    303		.platform_data	= &gpio_leds_data,
    304	},
    305};
    306
    307/* HTC PLD chips */
    308
    309static struct resource htcpld_resources[] = {
    310	[0] = {
    311		.flags  = IORESOURCE_IRQ,
    312	},
    313};
    314
    315static struct htcpld_chip_platform_data htcpld_chips[] = {
    316	[0] = {
    317		.addr		= 0x03,
    318		.reset		= 0x04,
    319		.num_gpios	= 8,
    320		.gpio_out_base	= HTCPLD_BASE(0, 0),
    321		.gpio_in_base	= HTCPLD_BASE(4, 0),
    322	},
    323	[1] = {
    324		.addr		= 0x04,
    325		.reset		= 0x8e,
    326		.num_gpios	= 8,
    327		.gpio_out_base	= HTCPLD_BASE(1, 0),
    328		.gpio_in_base	= HTCPLD_BASE(5, 0),
    329	},
    330	[2] = {
    331		.addr		= 0x05,
    332		.reset		= 0x80,
    333		.num_gpios	= 8,
    334		.gpio_out_base	= HTCPLD_BASE(2, 0),
    335		.gpio_in_base	= HTCPLD_BASE(6, 0),
    336		.irq_base	= HTCPLD_IRQ(0, 0),
    337		.num_irqs	= 8,
    338	},
    339	[3] = {
    340		.addr		= 0x06,
    341		.reset		= 0x40,
    342		.num_gpios	= 8,
    343		.gpio_out_base	= HTCPLD_BASE(3, 0),
    344		.gpio_in_base	= HTCPLD_BASE(7, 0),
    345		.irq_base	= HTCPLD_IRQ(1, 0),
    346		.num_irqs	= 8,
    347	},
    348};
    349
    350static struct htcpld_core_platform_data htcpld_pfdata = {
    351	.int_reset_gpio_hi = HTCPLD_GPIO_INT_RESET_HI,
    352	.int_reset_gpio_lo = HTCPLD_GPIO_INT_RESET_LO,
    353	.i2c_adapter_id	   = 1,
    354
    355	.chip		   = htcpld_chips,
    356	.num_chip	   = ARRAY_SIZE(htcpld_chips),
    357};
    358
    359static struct platform_device htcpld_device = {
    360	.name		= "i2c-htcpld",
    361	.id		= -1,
    362	.resource	= htcpld_resources,
    363	.num_resources	= ARRAY_SIZE(htcpld_resources),
    364	.dev	= {
    365		.platform_data	= &htcpld_pfdata,
    366	},
    367};
    368
    369/* USB Device */
    370static struct omap_usb_config htcherald_usb_config __initdata = {
    371	.otg = 0,
    372	.register_host = 0,
    373	.register_dev  = 1,
    374	.hmc_mode = 4,
    375	.pins[0] = 2,
    376};
    377
    378/* LCD Device resources */
    379static const struct omap_lcd_config htcherald_lcd_config __initconst = {
    380	.ctrl_name	= "internal",
    381};
    382
    383static struct platform_device lcd_device = {
    384	.name           = "lcd_htcherald",
    385	.id             = -1,
    386};
    387
    388/* MMC Card */
    389#if IS_ENABLED(CONFIG_MMC_OMAP)
    390static struct omap_mmc_platform_data htc_mmc1_data = {
    391	.nr_slots                       = 1,
    392	.switch_slot                    = NULL,
    393	.slots[0]       = {
    394		.ocr_mask               = MMC_VDD_32_33 | MMC_VDD_33_34,
    395		.name                   = "mmcblk",
    396		.nomux                  = 1,
    397		.wires                  = 4,
    398		.switch_pin             = -1,
    399	},
    400};
    401
    402static struct omap_mmc_platform_data *htc_mmc_data[1];
    403#endif
    404
    405
    406/* Platform devices for the Herald */
    407static struct platform_device *devices[] __initdata = {
    408	&kp_device,
    409	&lcd_device,
    410	&htcpld_device,
    411	&gpio_leds_device,
    412	&herald_gpiokeys_device,
    413};
    414
    415/*
    416 * Touchscreen
    417 */
    418static const struct ads7846_platform_data htcherald_ts_platform_data = {
    419	.model			= 7846,
    420	.keep_vref_on		= 1,
    421	.x_plate_ohms		= 496,
    422	.gpio_pendown		= HTCHERALD_GPIO_TS,
    423	.pressure_max		= 10000,
    424	.pressure_min		= 5000,
    425	.x_min			= 528,
    426	.x_max			= 3760,
    427	.y_min			= 624,
    428	.y_max			= 3760,
    429};
    430
    431static struct spi_board_info __initdata htcherald_spi_board_info[] = {
    432	{
    433		.modalias		= "ads7846",
    434		.platform_data		= &htcherald_ts_platform_data,
    435		.max_speed_hz		= 2500000,
    436		.bus_num		= 2,
    437		.chip_select		= 1,
    438	}
    439};
    440
    441/*
    442 * Init functions from here on
    443 */
    444
    445static void __init htcherald_lcd_init(void)
    446{
    447	u32 reg;
    448	unsigned int tries = 200;
    449
    450	/* disable controller if active */
    451	reg = omap_readl(OMAP_LCDC_CONTROL);
    452	if (reg & OMAP_LCDC_CTRL_LCD_EN) {
    453		reg &= ~OMAP_LCDC_CTRL_LCD_EN;
    454		omap_writel(reg, OMAP_LCDC_CONTROL);
    455
    456		/* wait for end of frame */
    457		while (!(omap_readl(OMAP_LCDC_STATUS) & OMAP_LCDC_STAT_DONE)) {
    458			tries--;
    459			if (!tries)
    460				break;
    461		}
    462		if (!tries)
    463			pr_err("Timeout waiting for end of frame -- LCD may not be available\n");
    464
    465		/* turn off DMA */
    466		reg = omap_readw(OMAP_DMA_LCD_CCR);
    467		reg &= ~(1 << 7);
    468		omap_writew(reg, OMAP_DMA_LCD_CCR);
    469
    470		reg = omap_readw(OMAP_DMA_LCD_CTRL);
    471		reg &= ~(1 << 8);
    472		omap_writew(reg, OMAP_DMA_LCD_CTRL);
    473	}
    474}
    475
    476static void __init htcherald_map_io(void)
    477{
    478	omap7xx_map_io();
    479
    480	/*
    481	 * The LCD panel must be disabled and DMA turned off here, as doing
    482	 * it later causes the LCD never to reinitialize.
    483	 */
    484	htcherald_lcd_init();
    485
    486	printk(KERN_INFO "htcherald_map_io done.\n");
    487}
    488
    489static void __init htcherald_disable_watchdog(void)
    490{
    491	/* Disable watchdog if running */
    492	if (omap_readl(OMAP_WDT_TIMER_MODE) & 0x8000) {
    493		/*
    494		 * disable a potentially running watchdog timer before
    495		 * it kills us.
    496		 */
    497		printk(KERN_WARNING "OMAP850 Watchdog seems to be activated, disabling it for now.\n");
    498		omap_writel(0xF5, OMAP_WDT_TIMER_MODE);
    499		omap_writel(0xA0, OMAP_WDT_TIMER_MODE);
    500	}
    501}
    502
    503#define HTCHERALD_GPIO_USB_EN1 33
    504#define HTCHERALD_GPIO_USB_EN2 73
    505#define HTCHERALD_GPIO_USB_DM  35
    506#define HTCHERALD_GPIO_USB_DP  36
    507
    508static void __init htcherald_usb_enable(void)
    509{
    510	unsigned int tries = 20;
    511	unsigned int value = 0;
    512
    513	/* Request the GPIOs we need to control here */
    514	if (gpio_request(HTCHERALD_GPIO_USB_EN1, "herald_usb") < 0)
    515		goto err1;
    516
    517	if (gpio_request(HTCHERALD_GPIO_USB_EN2, "herald_usb") < 0)
    518		goto err2;
    519
    520	if (gpio_request(HTCHERALD_GPIO_USB_DM, "herald_usb") < 0)
    521		goto err3;
    522
    523	if (gpio_request(HTCHERALD_GPIO_USB_DP, "herald_usb") < 0)
    524		goto err4;
    525
    526	/* force USB_EN GPIO to 0 */
    527	do {
    528		/* output low */
    529		gpio_direction_output(HTCHERALD_GPIO_USB_EN1, 0);
    530	} while ((value = gpio_get_value(HTCHERALD_GPIO_USB_EN1)) == 1 &&
    531			--tries);
    532
    533	if (value == 1)
    534		printk(KERN_WARNING "Unable to reset USB, trying to continue\n");
    535
    536	gpio_direction_output(HTCHERALD_GPIO_USB_EN2, 0); /* output low */
    537	gpio_direction_input(HTCHERALD_GPIO_USB_DM); /* input */
    538	gpio_direction_input(HTCHERALD_GPIO_USB_DP); /* input */
    539
    540	goto done;
    541
    542err4:
    543	gpio_free(HTCHERALD_GPIO_USB_DM);
    544err3:
    545	gpio_free(HTCHERALD_GPIO_USB_EN2);
    546err2:
    547	gpio_free(HTCHERALD_GPIO_USB_EN1);
    548err1:
    549	printk(KERN_ERR "Unabled to request GPIO for USB\n");
    550done:
    551	printk(KERN_INFO "USB setup complete.\n");
    552}
    553
    554static void __init htcherald_init(void)
    555{
    556	printk(KERN_INFO "HTC Herald init.\n");
    557
    558	/* Do board initialization before we register all the devices */
    559	htcpld_resources[0].start = gpio_to_irq(HTCHERALD_GIRQ_BTNS);
    560	htcpld_resources[0].end = gpio_to_irq(HTCHERALD_GIRQ_BTNS);
    561	platform_add_devices(devices, ARRAY_SIZE(devices));
    562
    563	htcherald_disable_watchdog();
    564
    565	htcherald_usb_enable();
    566	omap1_usb_init(&htcherald_usb_config);
    567
    568	htcherald_spi_board_info[0].irq = gpio_to_irq(HTCHERALD_GPIO_TS);
    569	spi_register_board_info(htcherald_spi_board_info,
    570		ARRAY_SIZE(htcherald_spi_board_info));
    571
    572	omap_register_i2c_bus(1, 100, NULL, 0);
    573
    574#if IS_ENABLED(CONFIG_MMC_OMAP)
    575	htc_mmc_data[0] = &htc_mmc1_data;
    576	omap1_init_mmc(htc_mmc_data, 1);
    577#endif
    578
    579	omapfb_set_lcd_config(&htcherald_lcd_config);
    580}
    581
    582MACHINE_START(HERALD, "HTC Herald")
    583	/* Maintainer: Cory Maccarrone <darkstar6262@gmail.com> */
    584	/* Maintainer: wing-linux.sourceforge.net */
    585	.atag_offset    = 0x100,
    586	.map_io         = htcherald_map_io,
    587	.init_early     = omap1_init_early,
    588	.init_irq       = omap1_init_irq,
    589	.handle_irq	= omap1_handle_irq,
    590	.init_machine   = htcherald_init,
    591	.init_late	= omap1_init_late,
    592	.init_time	= omap1_timer_init,
    593	.restart	= omap1_restart,
    594MACHINE_END