Path: blob/master/arch/avr32/boards/favr-32/setup.c
10819 views
/*1* Favr-32 board-specific setup code.2*3* Copyright (C) 2008 Atmel Corporation4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License version 2 as7* published by the Free Software Foundation.8*/9#include <linux/clk.h>10#include <linux/etherdevice.h>11#include <linux/bootmem.h>12#include <linux/fb.h>13#include <linux/init.h>14#include <linux/platform_device.h>15#include <linux/types.h>16#include <linux/linkage.h>17#include <linux/gpio.h>18#include <linux/leds.h>19#include <linux/atmel-mci.h>20#include <linux/atmel-pwm-bl.h>21#include <linux/spi/spi.h>22#include <linux/spi/ads7846.h>2324#include <sound/atmel-abdac.h>2526#include <video/atmel_lcdc.h>2728#include <asm/setup.h>2930#include <mach/at32ap700x.h>31#include <mach/init.h>32#include <mach/board.h>33#include <mach/portmux.h>3435/* Oscillator frequencies. These are board-specific */36unsigned long at32_board_osc_rates[3] = {37[0] = 32768, /* 32.768 kHz on RTC osc */38[1] = 20000000, /* 20 MHz on osc0 */39[2] = 12000000, /* 12 MHz on osc1 */40};4142/* Initialized by bootloader-specific startup code. */43struct tag *bootloader_tags __initdata;4445static struct atmel_abdac_pdata __initdata abdac0_data = {46};4748struct eth_addr {49u8 addr[6];50};51static struct eth_addr __initdata hw_addr[1];52static struct eth_platform_data __initdata eth_data[1] = {53{54.phy_mask = ~(1U << 1),55},56};5758static int ads7843_get_pendown_state(void)59{60return !gpio_get_value(GPIO_PIN_PB(3));61}6263static struct ads7846_platform_data ads7843_data = {64.model = 7843,65.get_pendown_state = ads7843_get_pendown_state,66.pressure_max = 255,67/*68* Values below are for debounce filtering, these can be experimented69* with further.70*/71.debounce_max = 20,72.debounce_rep = 4,73.debounce_tol = 5,7475.keep_vref_on = true,76.settle_delay_usecs = 500,77.penirq_recheck_delay_usecs = 100,78};7980static struct spi_board_info __initdata spi1_board_info[] = {81{82/* ADS7843 touch controller */83.modalias = "ads7846",84.max_speed_hz = 2000000,85.chip_select = 0,86.bus_num = 1,87.platform_data = &ads7843_data,88},89};9091static struct mci_platform_data __initdata mci0_data = {92.slot[0] = {93.bus_width = 4,94.detect_pin = -ENODEV,95.wp_pin = -ENODEV,96},97};9899static struct fb_videomode __initdata lb104v03_modes[] = {100{101.name = "640x480 @ 50",102.refresh = 50,103.xres = 640, .yres = 480,104.pixclock = KHZ2PICOS(25100),105106.left_margin = 90, .right_margin = 70,107.upper_margin = 30, .lower_margin = 15,108.hsync_len = 12, .vsync_len = 2,109110.sync = 0,111.vmode = FB_VMODE_NONINTERLACED,112},113};114115static struct fb_monspecs __initdata favr32_default_monspecs = {116.manufacturer = "LG",117.monitor = "LB104V03",118.modedb = lb104v03_modes,119.modedb_len = ARRAY_SIZE(lb104v03_modes),120.hfmin = 27273,121.hfmax = 31111,122.vfmin = 45,123.vfmax = 60,124.dclkmax = 28000000,125};126127struct atmel_lcdfb_info __initdata favr32_lcdc_data = {128.default_bpp = 16,129.default_dmacon = ATMEL_LCDC_DMAEN | ATMEL_LCDC_DMA2DEN,130.default_lcdcon2 = (ATMEL_LCDC_DISTYPE_TFT131| ATMEL_LCDC_CLKMOD_ALWAYSACTIVE132| ATMEL_LCDC_MEMOR_BIG),133.default_monspecs = &favr32_default_monspecs,134.guard_time = 2,135};136137static struct gpio_led favr32_leds[] = {138{139.name = "green",140.gpio = GPIO_PIN_PE(19),141.default_trigger = "heartbeat",142.active_low = 1,143},144{145.name = "red",146.gpio = GPIO_PIN_PE(20),147.active_low = 1,148},149};150151static struct gpio_led_platform_data favr32_led_data = {152.num_leds = ARRAY_SIZE(favr32_leds),153.leds = favr32_leds,154};155156static struct platform_device favr32_led_dev = {157.name = "leds-gpio",158.id = 0,159.dev = {160.platform_data = &favr32_led_data,161},162};163164/*165* The next two functions should go away as the boot loader is166* supposed to initialize the macb address registers with a valid167* ethernet address. But we need to keep it around for a while until168* we can be reasonably sure the boot loader does this.169*170* The phy_id is ignored as the driver will probe for it.171*/172static int __init parse_tag_ethernet(struct tag *tag)173{174int i;175176i = tag->u.ethernet.mac_index;177if (i < ARRAY_SIZE(hw_addr))178memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,179sizeof(hw_addr[i].addr));180181return 0;182}183__tagtable(ATAG_ETHERNET, parse_tag_ethernet);184185static void __init set_hw_addr(struct platform_device *pdev)186{187struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);188const u8 *addr;189void __iomem *regs;190struct clk *pclk;191192if (!res)193return;194if (pdev->id >= ARRAY_SIZE(hw_addr))195return;196197addr = hw_addr[pdev->id].addr;198if (!is_valid_ether_addr(addr))199return;200201/*202* Since this is board-specific code, we'll cheat and use the203* physical address directly as we happen to know that it's204* the same as the virtual address.205*/206regs = (void __iomem __force *)res->start;207pclk = clk_get(&pdev->dev, "pclk");208if (IS_ERR(pclk))209return;210211clk_enable(pclk);212__raw_writel((addr[3] << 24) | (addr[2] << 16)213| (addr[1] << 8) | addr[0], regs + 0x98);214__raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);215clk_disable(pclk);216clk_put(pclk);217}218219void __init favr32_setup_leds(void)220{221unsigned i;222223for (i = 0; i < ARRAY_SIZE(favr32_leds); i++)224at32_select_gpio(favr32_leds[i].gpio, AT32_GPIOF_OUTPUT);225226platform_device_register(&favr32_led_dev);227}228229static struct atmel_pwm_bl_platform_data atmel_pwm_bl_pdata = {230.pwm_channel = 2,231.pwm_frequency = 200000,232.pwm_compare_max = 345,233.pwm_duty_max = 345,234.pwm_duty_min = 90,235.pwm_active_low = 1,236.gpio_on = GPIO_PIN_PA(28),237.on_active_low = 0,238};239240static struct platform_device atmel_pwm_bl_dev = {241.name = "atmel-pwm-bl",242.id = 0,243.dev = {244.platform_data = &atmel_pwm_bl_pdata,245},246};247248static void __init favr32_setup_atmel_pwm_bl(void)249{250platform_device_register(&atmel_pwm_bl_dev);251at32_select_gpio(atmel_pwm_bl_pdata.gpio_on, 0);252}253254void __init setup_board(void)255{256at32_map_usart(3, 0, 0); /* USART 3 => /dev/ttyS0 */257at32_setup_serial_console(0);258}259260static int __init set_abdac_rate(struct platform_device *pdev)261{262int retval;263struct clk *osc1;264struct clk *pll1;265struct clk *abdac;266267if (pdev == NULL)268return -ENXIO;269270osc1 = clk_get(NULL, "osc1");271if (IS_ERR(osc1)) {272retval = PTR_ERR(osc1);273goto out;274}275276pll1 = clk_get(NULL, "pll1");277if (IS_ERR(pll1)) {278retval = PTR_ERR(pll1);279goto out_osc1;280}281282abdac = clk_get(&pdev->dev, "sample_clk");283if (IS_ERR(abdac)) {284retval = PTR_ERR(abdac);285goto out_pll1;286}287288retval = clk_set_parent(pll1, osc1);289if (retval != 0)290goto out_abdac;291292/*293* Rate is 32000 to 50000 and ABDAC oversamples 256x. Multiply, in294* power of 2, to a value above 80 MHz. Power of 2 so it is possible295* for the generic clock to divide it down again and 80 MHz is the296* lowest frequency for the PLL.297*/298retval = clk_round_rate(pll1,299CONFIG_BOARD_FAVR32_ABDAC_RATE * 256 * 16);300if (retval < 0)301goto out_abdac;302303retval = clk_set_rate(pll1, retval);304if (retval != 0)305goto out_abdac;306307retval = clk_set_parent(abdac, pll1);308if (retval != 0)309goto out_abdac;310311out_abdac:312clk_put(abdac);313out_pll1:314clk_put(pll1);315out_osc1:316clk_put(osc1);317out:318return retval;319}320321static int __init favr32_init(void)322{323/*324* Favr-32 uses 32-bit SDRAM interface. Reserve the SDRAM-specific325* pins so that nobody messes with them.326*/327at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL);328329at32_select_gpio(GPIO_PIN_PB(3), 0); /* IRQ from ADS7843 */330331at32_add_device_usart(0);332333set_hw_addr(at32_add_device_eth(0, ð_data[0]));334335spi1_board_info[0].irq = gpio_to_irq(GPIO_PIN_PB(3));336337set_abdac_rate(at32_add_device_abdac(0, &abdac0_data));338339at32_add_device_pwm(1 << atmel_pwm_bl_pdata.pwm_channel);340at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));341at32_add_device_mci(0, &mci0_data);342at32_add_device_usba(0, NULL);343at32_add_device_lcdc(0, &favr32_lcdc_data, fbmem_start, fbmem_size, 0);344345favr32_setup_leds();346347favr32_setup_atmel_pwm_bl();348349return 0;350}351postcore_initcall(favr32_init);352353354