Path: blob/master/arch/arm/mach-omap2/board-n8x0.c
10817 views
/*1* linux/arch/arm/mach-omap2/board-n8x0.c2*3* Copyright (C) 2005-2009 Nokia Corporation4* Author: Juha Yrjola <[email protected]>5*6* Modified from mach-omap2/board-generic.c7*8* This program is free software; you can redistribute it and/or modify9* it under the terms of the GNU General Public License version 2 as10* published by the Free Software Foundation.11*/1213#include <linux/clk.h>14#include <linux/delay.h>15#include <linux/gpio.h>16#include <linux/init.h>17#include <linux/io.h>18#include <linux/stddef.h>19#include <linux/i2c.h>20#include <linux/spi/spi.h>21#include <linux/usb/musb.h>22#include <sound/tlv320aic3x.h>2324#include <asm/mach/arch.h>25#include <asm/mach-types.h>2627#include <plat/board.h>28#include <plat/common.h>29#include <plat/menelaus.h>30#include <mach/irqs.h>31#include <plat/mcspi.h>32#include <plat/onenand.h>33#include <plat/mmc.h>34#include <plat/serial.h>3536#include "mux.h"3738static int slot1_cover_open;39static int slot2_cover_open;40static struct device *mmc_device;4142#define TUSB6010_ASYNC_CS 143#define TUSB6010_SYNC_CS 444#define TUSB6010_GPIO_INT 5845#define TUSB6010_GPIO_ENABLE 046#define TUSB6010_DMACHAN 0x3f4748#ifdef CONFIG_USB_MUSB_TUSB601049/*50* Enable or disable power to TUSB6010. When enabling, turn on 3.3 V and51* 1.5 V voltage regulators of PM companion chip. Companion chip will then52* provide then PGOOD signal to TUSB6010 which will release it from reset.53*/54static int tusb_set_power(int state)55{56int i, retval = 0;5758if (state) {59gpio_set_value(TUSB6010_GPIO_ENABLE, 1);60msleep(1);6162/* Wait until TUSB6010 pulls INT pin down */63i = 100;64while (i && gpio_get_value(TUSB6010_GPIO_INT)) {65msleep(1);66i--;67}6869if (!i) {70printk(KERN_ERR "tusb: powerup failed\n");71retval = -ENODEV;72}73} else {74gpio_set_value(TUSB6010_GPIO_ENABLE, 0);75msleep(10);76}7778return retval;79}8081static struct musb_hdrc_config musb_config = {82.multipoint = 1,83.dyn_fifo = 1,84.num_eps = 16,85.ram_bits = 12,86};8788static struct musb_hdrc_platform_data tusb_data = {89#if defined(CONFIG_USB_MUSB_OTG)90.mode = MUSB_OTG,91#elif defined(CONFIG_USB_MUSB_PERIPHERAL)92.mode = MUSB_PERIPHERAL,93#else /* defined(CONFIG_USB_MUSB_HOST) */94.mode = MUSB_HOST,95#endif96.set_power = tusb_set_power,97.min_power = 25, /* x2 = 50 mA drawn from VBUS as peripheral */98.power = 100, /* Max 100 mA VBUS for host mode */99.config = &musb_config,100};101102static void __init n8x0_usb_init(void)103{104int ret = 0;105static char announce[] __initdata = KERN_INFO "TUSB 6010\n";106107/* PM companion chip power control pin */108ret = gpio_request_one(TUSB6010_GPIO_ENABLE, GPIOF_OUT_INIT_LOW,109"TUSB6010 enable");110if (ret != 0) {111printk(KERN_ERR "Could not get TUSB power GPIO%i\n",112TUSB6010_GPIO_ENABLE);113return;114}115tusb_set_power(0);116117ret = tusb6010_setup_interface(&tusb_data, TUSB6010_REFCLK_19, 2,118TUSB6010_ASYNC_CS, TUSB6010_SYNC_CS,119TUSB6010_GPIO_INT, TUSB6010_DMACHAN);120if (ret != 0)121goto err;122123printk(announce);124125return;126127err:128gpio_free(TUSB6010_GPIO_ENABLE);129}130#else131132static void __init n8x0_usb_init(void) {}133134#endif /*CONFIG_USB_MUSB_TUSB6010 */135136137static struct omap2_mcspi_device_config p54spi_mcspi_config = {138.turbo_mode = 0,139.single_channel = 1,140};141142static struct spi_board_info n800_spi_board_info[] __initdata = {143{144.modalias = "p54spi",145.bus_num = 2,146.chip_select = 0,147.max_speed_hz = 48000000,148.controller_data = &p54spi_mcspi_config,149},150};151152#if defined(CONFIG_MTD_ONENAND_OMAP2) || \153defined(CONFIG_MTD_ONENAND_OMAP2_MODULE)154155static struct mtd_partition onenand_partitions[] = {156{157.name = "bootloader",158.offset = 0,159.size = 0x20000,160.mask_flags = MTD_WRITEABLE, /* Force read-only */161},162{163.name = "config",164.offset = MTDPART_OFS_APPEND,165.size = 0x60000,166},167{168.name = "kernel",169.offset = MTDPART_OFS_APPEND,170.size = 0x200000,171},172{173.name = "initfs",174.offset = MTDPART_OFS_APPEND,175.size = 0x400000,176},177{178.name = "rootfs",179.offset = MTDPART_OFS_APPEND,180.size = MTDPART_SIZ_FULL,181},182};183184static struct omap_onenand_platform_data board_onenand_data[] = {185{186.cs = 0,187.gpio_irq = 26,188.parts = onenand_partitions,189.nr_parts = ARRAY_SIZE(onenand_partitions),190.flags = ONENAND_SYNC_READ,191}192};193#endif194195#if defined(CONFIG_MENELAUS) && \196(defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE))197198/*199* On both N800 and N810, only the first of the two MMC controllers is in use.200* The two MMC slots are multiplexed via Menelaus companion chip over I2C.201* On N800, both slots are powered via Menelaus. On N810, only one of the202* slots is powered via Menelaus. The N810 EMMC is powered via GPIO.203*204* VMMC slot 1 on both N800 and N810205* VDCDC3_APE and VMCS2_APE slot 2 on N800206* GPIO23 and GPIO9 slot 2 EMMC on N810207*208*/209#define N8X0_SLOT_SWITCH_GPIO 96210#define N810_EMMC_VSD_GPIO 23211#define N810_EMMC_VIO_GPIO 9212213static int n8x0_mmc_switch_slot(struct device *dev, int slot)214{215#ifdef CONFIG_MMC_DEBUG216dev_dbg(dev, "Choose slot %d\n", slot + 1);217#endif218gpio_set_value(N8X0_SLOT_SWITCH_GPIO, slot);219return 0;220}221222static int n8x0_mmc_set_power_menelaus(struct device *dev, int slot,223int power_on, int vdd)224{225int mV;226227#ifdef CONFIG_MMC_DEBUG228dev_dbg(dev, "Set slot %d power: %s (vdd %d)\n", slot + 1,229power_on ? "on" : "off", vdd);230#endif231if (slot == 0) {232if (!power_on)233return menelaus_set_vmmc(0);234switch (1 << vdd) {235case MMC_VDD_33_34:236case MMC_VDD_32_33:237case MMC_VDD_31_32:238mV = 3100;239break;240case MMC_VDD_30_31:241mV = 3000;242break;243case MMC_VDD_28_29:244mV = 2800;245break;246case MMC_VDD_165_195:247mV = 1850;248break;249default:250BUG();251}252return menelaus_set_vmmc(mV);253} else {254if (!power_on)255return menelaus_set_vdcdc(3, 0);256switch (1 << vdd) {257case MMC_VDD_33_34:258case MMC_VDD_32_33:259mV = 3300;260break;261case MMC_VDD_30_31:262case MMC_VDD_29_30:263mV = 3000;264break;265case MMC_VDD_28_29:266case MMC_VDD_27_28:267mV = 2800;268break;269case MMC_VDD_24_25:270case MMC_VDD_23_24:271mV = 2400;272break;273case MMC_VDD_22_23:274case MMC_VDD_21_22:275mV = 2200;276break;277case MMC_VDD_20_21:278mV = 2000;279break;280case MMC_VDD_165_195:281mV = 1800;282break;283default:284BUG();285}286return menelaus_set_vdcdc(3, mV);287}288return 0;289}290291static void n810_set_power_emmc(struct device *dev,292int power_on)293{294dev_dbg(dev, "Set EMMC power %s\n", power_on ? "on" : "off");295296if (power_on) {297gpio_set_value(N810_EMMC_VSD_GPIO, 1);298msleep(1);299gpio_set_value(N810_EMMC_VIO_GPIO, 1);300msleep(1);301} else {302gpio_set_value(N810_EMMC_VIO_GPIO, 0);303msleep(50);304gpio_set_value(N810_EMMC_VSD_GPIO, 0);305msleep(50);306}307}308309static int n8x0_mmc_set_power(struct device *dev, int slot, int power_on,310int vdd)311{312if (machine_is_nokia_n800() || slot == 0)313return n8x0_mmc_set_power_menelaus(dev, slot, power_on, vdd);314315n810_set_power_emmc(dev, power_on);316317return 0;318}319320static int n8x0_mmc_set_bus_mode(struct device *dev, int slot, int bus_mode)321{322int r;323324dev_dbg(dev, "Set slot %d bus mode %s\n", slot + 1,325bus_mode == MMC_BUSMODE_OPENDRAIN ? "open-drain" : "push-pull");326BUG_ON(slot != 0 && slot != 1);327slot++;328switch (bus_mode) {329case MMC_BUSMODE_OPENDRAIN:330r = menelaus_set_mmc_opendrain(slot, 1);331break;332case MMC_BUSMODE_PUSHPULL:333r = menelaus_set_mmc_opendrain(slot, 0);334break;335default:336BUG();337}338if (r != 0 && printk_ratelimit())339dev_err(dev, "MMC: unable to set bus mode for slot %d\n",340slot);341return r;342}343344static int n8x0_mmc_get_cover_state(struct device *dev, int slot)345{346slot++;347BUG_ON(slot != 1 && slot != 2);348if (slot == 1)349return slot1_cover_open;350else351return slot2_cover_open;352}353354static void n8x0_mmc_callback(void *data, u8 card_mask)355{356int bit, *openp, index;357358if (machine_is_nokia_n800()) {359bit = 1 << 1;360openp = &slot2_cover_open;361index = 1;362} else {363bit = 1;364openp = &slot1_cover_open;365index = 0;366}367368if (card_mask & bit)369*openp = 1;370else371*openp = 0;372373omap_mmc_notify_cover_event(mmc_device, index, *openp);374}375376static int n8x0_mmc_late_init(struct device *dev)377{378int r, bit, *openp;379int vs2sel;380381mmc_device = dev;382383r = menelaus_set_slot_sel(1);384if (r < 0)385return r;386387if (machine_is_nokia_n800())388vs2sel = 0;389else390vs2sel = 2;391392r = menelaus_set_mmc_slot(2, 0, vs2sel, 1);393if (r < 0)394return r;395396n8x0_mmc_set_power(dev, 0, MMC_POWER_ON, 16); /* MMC_VDD_28_29 */397n8x0_mmc_set_power(dev, 1, MMC_POWER_ON, 16);398399r = menelaus_set_mmc_slot(1, 1, 0, 1);400if (r < 0)401return r;402r = menelaus_set_mmc_slot(2, 1, vs2sel, 1);403if (r < 0)404return r;405406r = menelaus_get_slot_pin_states();407if (r < 0)408return r;409410if (machine_is_nokia_n800()) {411bit = 1 << 1;412openp = &slot2_cover_open;413} else {414bit = 1;415openp = &slot1_cover_open;416slot2_cover_open = 0;417}418419/* All slot pin bits seem to be inversed until first switch change */420if (r == 0xf || r == (0xf & ~bit))421r = ~r;422423if (r & bit)424*openp = 1;425else426*openp = 0;427428r = menelaus_register_mmc_callback(n8x0_mmc_callback, NULL);429430return r;431}432433static void n8x0_mmc_shutdown(struct device *dev)434{435int vs2sel;436437if (machine_is_nokia_n800())438vs2sel = 0;439else440vs2sel = 2;441442menelaus_set_mmc_slot(1, 0, 0, 0);443menelaus_set_mmc_slot(2, 0, vs2sel, 0);444}445446static void n8x0_mmc_cleanup(struct device *dev)447{448menelaus_unregister_mmc_callback();449450gpio_free(N8X0_SLOT_SWITCH_GPIO);451452if (machine_is_nokia_n810()) {453gpio_free(N810_EMMC_VSD_GPIO);454gpio_free(N810_EMMC_VIO_GPIO);455}456}457458/*459* MMC controller1 has two slots that are multiplexed via I2C.460* MMC controller2 is not in use.461*/462static struct omap_mmc_platform_data mmc1_data = {463.nr_slots = 2,464.switch_slot = n8x0_mmc_switch_slot,465.init = n8x0_mmc_late_init,466.cleanup = n8x0_mmc_cleanup,467.shutdown = n8x0_mmc_shutdown,468.max_freq = 24000000,469.dma_mask = 0xffffffff,470.slots[0] = {471.wires = 4,472.set_power = n8x0_mmc_set_power,473.set_bus_mode = n8x0_mmc_set_bus_mode,474.get_cover_state = n8x0_mmc_get_cover_state,475.ocr_mask = MMC_VDD_165_195 | MMC_VDD_30_31 |476MMC_VDD_32_33 | MMC_VDD_33_34,477.name = "internal",478},479.slots[1] = {480.set_power = n8x0_mmc_set_power,481.set_bus_mode = n8x0_mmc_set_bus_mode,482.get_cover_state = n8x0_mmc_get_cover_state,483.ocr_mask = MMC_VDD_165_195 | MMC_VDD_20_21 |484MMC_VDD_21_22 | MMC_VDD_22_23 |485MMC_VDD_23_24 | MMC_VDD_24_25 |486MMC_VDD_27_28 | MMC_VDD_28_29 |487MMC_VDD_29_30 | MMC_VDD_30_31 |488MMC_VDD_32_33 | MMC_VDD_33_34,489.name = "external",490},491};492493static struct omap_mmc_platform_data *mmc_data[OMAP24XX_NR_MMC];494495static struct gpio n810_emmc_gpios[] __initdata = {496{ N810_EMMC_VSD_GPIO, GPIOF_OUT_INIT_LOW, "MMC slot 2 Vddf" },497{ N810_EMMC_VIO_GPIO, GPIOF_OUT_INIT_LOW, "MMC slot 2 Vdd" },498};499500static void __init n8x0_mmc_init(void)501{502int err;503504if (machine_is_nokia_n810()) {505mmc1_data.slots[0].name = "external";506507/*508* Some Samsung Movinand chips do not like open-ended509* multi-block reads and fall to braind-dead state510* while doing so. Reducing the number of blocks in511* the transfer or delays in clock disable do not help512*/513mmc1_data.slots[1].name = "internal";514mmc1_data.slots[1].ban_openended = 1;515}516517err = gpio_request_one(N8X0_SLOT_SWITCH_GPIO, GPIOF_OUT_INIT_LOW,518"MMC slot switch");519if (err)520return;521522if (machine_is_nokia_n810()) {523err = gpio_request_array(n810_emmc_gpios,524ARRAY_SIZE(n810_emmc_gpios));525if (err) {526gpio_free(N8X0_SLOT_SWITCH_GPIO);527return;528}529}530531mmc_data[0] = &mmc1_data;532omap242x_init_mmc(mmc_data);533}534#else535536void __init n8x0_mmc_init(void)537{538}539#endif /* CONFIG_MMC_OMAP */540541#ifdef CONFIG_MENELAUS542543static int n8x0_auto_sleep_regulators(void)544{545u32 val;546int ret;547548val = EN_VPLL_SLEEP | EN_VMMC_SLEEP \549| EN_VAUX_SLEEP | EN_VIO_SLEEP \550| EN_VMEM_SLEEP | EN_DC3_SLEEP \551| EN_VC_SLEEP | EN_DC2_SLEEP;552553ret = menelaus_set_regulator_sleep(1, val);554if (ret < 0) {555printk(KERN_ERR "Could not set regulators to sleep on "556"menelaus: %u\n", ret);557return ret;558}559return 0;560}561562static int n8x0_auto_voltage_scale(void)563{564int ret;565566ret = menelaus_set_vcore_hw(1400, 1050);567if (ret < 0) {568printk(KERN_ERR "Could not set VCORE voltage on "569"menelaus: %u\n", ret);570return ret;571}572return 0;573}574575static int n8x0_menelaus_late_init(struct device *dev)576{577int ret;578579ret = n8x0_auto_voltage_scale();580if (ret < 0)581return ret;582ret = n8x0_auto_sleep_regulators();583if (ret < 0)584return ret;585return 0;586}587588#else589static int n8x0_menelaus_late_init(struct device *dev)590{591return 0;592}593#endif594595static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {596.late_init = n8x0_menelaus_late_init,597};598599static struct i2c_board_info __initdata n8x0_i2c_board_info_1[] __initdata = {600{601I2C_BOARD_INFO("menelaus", 0x72),602.irq = INT_24XX_SYS_NIRQ,603.platform_data = &n8x0_menelaus_platform_data,604},605};606607static struct aic3x_pdata n810_aic33_data __initdata = {608.gpio_reset = 118,609};610611static struct i2c_board_info n810_i2c_board_info_2[] __initdata = {612{613I2C_BOARD_INFO("tlv320aic3x", 0x18),614.platform_data = &n810_aic33_data,615},616};617618static void __init n8x0_map_io(void)619{620omap2_set_globals_242x();621omap242x_map_common_io();622}623624static void __init n8x0_init_early(void)625{626omap2_init_common_infrastructure();627omap2_init_common_devices(NULL, NULL);628}629630#ifdef CONFIG_OMAP_MUX631static struct omap_board_mux board_mux[] __initdata = {632/* I2S codec port pins for McBSP block */633OMAP2420_MUX(EAC_AC_SCLK, OMAP_MUX_MODE1 | OMAP_PIN_INPUT),634OMAP2420_MUX(EAC_AC_FS, OMAP_MUX_MODE1 | OMAP_PIN_INPUT),635OMAP2420_MUX(EAC_AC_DIN, OMAP_MUX_MODE1 | OMAP_PIN_INPUT),636OMAP2420_MUX(EAC_AC_DOUT, OMAP_MUX_MODE1 | OMAP_PIN_OUTPUT),637{ .reg_offset = OMAP_MUX_TERMINATOR },638};639640static struct omap_device_pad serial2_pads[] __initdata = {641{642.name = "uart3_rx_irrx.uart3_rx_irrx",643.flags = OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP,644.enable = OMAP_MUX_MODE0,645.idle = OMAP_MUX_MODE3 /* Mux as GPIO for idle */646},647};648649static inline void board_serial_init(void)650{651struct omap_board_data bdata;652653bdata.flags = 0;654bdata.pads = NULL;655bdata.pads_cnt = 0;656657bdata.id = 0;658omap_serial_init_port(&bdata);659660bdata.id = 1;661omap_serial_init_port(&bdata);662663bdata.id = 2;664bdata.pads = serial2_pads;665bdata.pads_cnt = ARRAY_SIZE(serial2_pads);666omap_serial_init_port(&bdata);667}668669#else670671static inline void board_serial_init(void)672{673omap_serial_init();674}675676#endif677678static void __init n8x0_init_machine(void)679{680omap2420_mux_init(board_mux, OMAP_PACKAGE_ZAC);681/* FIXME: add n810 spi devices */682spi_register_board_info(n800_spi_board_info,683ARRAY_SIZE(n800_spi_board_info));684omap_register_i2c_bus(1, 400, n8x0_i2c_board_info_1,685ARRAY_SIZE(n8x0_i2c_board_info_1));686omap_register_i2c_bus(2, 400, NULL, 0);687if (machine_is_nokia_n810())688i2c_register_board_info(2, n810_i2c_board_info_2,689ARRAY_SIZE(n810_i2c_board_info_2));690board_serial_init();691gpmc_onenand_init(board_onenand_data);692n8x0_mmc_init();693n8x0_usb_init();694}695696MACHINE_START(NOKIA_N800, "Nokia N800")697.boot_params = 0x80000100,698.reserve = omap_reserve,699.map_io = n8x0_map_io,700.init_early = n8x0_init_early,701.init_irq = omap_init_irq,702.init_machine = n8x0_init_machine,703.timer = &omap_timer,704MACHINE_END705706MACHINE_START(NOKIA_N810, "Nokia N810")707.boot_params = 0x80000100,708.reserve = omap_reserve,709.map_io = n8x0_map_io,710.init_early = n8x0_init_early,711.init_irq = omap_init_irq,712.init_machine = n8x0_init_machine,713.timer = &omap_timer,714MACHINE_END715716MACHINE_START(NOKIA_N810_WIMAX, "Nokia N810 WiMAX")717.boot_params = 0x80000100,718.reserve = omap_reserve,719.map_io = n8x0_map_io,720.init_early = n8x0_init_early,721.init_irq = omap_init_irq,722.init_machine = n8x0_init_machine,723.timer = &omap_timer,724MACHINE_END725726727