Advertisement
Guest User

Ankur Patel

a guest
May 24th, 2011
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.51 KB | None | 0 0
  1. /*
  2.  *  Board-specific setup code for the AT91SAM9M10G45 Evaluation Kit family
  3.  *
  4.  *  Covers: * AT91SAM9G45-EKES  board
  5.  *          * AT91SAM9M10G45-EK board
  6.  *
  7.  *  Copyright (C) 2009 Atmel Corporation.
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  */
  15.  
  16. #include <linux/types.h>
  17. #include <linux/init.h>
  18. #include <linux/mm.h>
  19. #include <linux/module.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/spi/spi.h>
  22. #include <linux/spi/ads7846.h>
  23. #include <linux/fb.h>
  24. #include <linux/gpio_keys.h>
  25. #include <linux/input.h>
  26. #include <linux/leds.h>
  27. #include <linux/clk.h>
  28. #include <linux/i2c/pcf857x.h>
  29.  
  30. #include <mach/hardware.h>
  31. #include <video/atmel_lcdc.h>
  32. #include <asm/setup.h>
  33. #include <linux/i2c/at24.h>
  34. #include <asm/mach-types.h>
  35. #include <asm/irq.h>
  36.  
  37. #include <asm/mach/arch.h>
  38. #include <asm/mach/map.h>
  39. #include <asm/mach/irq.h>
  40.  
  41. #include <mach/hardware.h>
  42. #include <mach/board.h>
  43. #include <mach/gpio.h>
  44. #include <mach/at91sam9_smc.h>
  45. #include <mach/at91_shdwc.h>
  46. #include <linux/i2c/tsc2007.h>
  47. #include <linux/w1-gpio.h>
  48.  
  49. #include "sam9_smc.h"
  50. #include "generic.h"
  51.  
  52. static struct w1_gpio_platform_data sn_w1_gpio_pdata = {
  53.         .pin            = AT91_PIN_PD12,
  54.         .is_open_drain  = 1,
  55. };
  56.  
  57. static struct platform_device sn_w1_device = {
  58.         .name                   = "w1-gpio",
  59.         .id                     = -1,
  60.         .dev.platform_data      = &sn_w1_gpio_pdata,
  61. };
  62.  
  63. static void __init ek_map_io(void)
  64. {
  65.     /* Initialize processor: 12.000 MHz crystal */
  66.     at91sam9g45_initialize(12000000);
  67.  
  68.     /* DGBU on ttyS0. (Rx & Tx only) */
  69.     at91_register_uart(0, 0, 0);
  70.  
  71.     // For RS485 you might enable ATMEL_UART_RTS instead of 0
  72. //  at91_register_uart(AT91SAM9G45_ID_US0, 1, 0);
  73.     at91_register_uart(AT91SAM9G45_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS);
  74.     at91_register_uart(AT91SAM9G45_ID_US2, 3, ATMEL_UART_CTS | ATMEL_UART_RTS);
  75.     at91_register_uart(AT91SAM9G45_ID_US3, 4, ATMEL_UART_CTS | ATMEL_UART_RTS);
  76.  
  77.     /* set serial console to ttyS0 (ie, DBGU) */
  78.     at91_set_serial_console(0);
  79. }
  80.  
  81. static void __init ek_init_irq(void)
  82. {
  83.     at91sam9g45_init_interrupts(NULL);
  84. }
  85.  
  86.  
  87. /*
  88.  * USB HS Host port (common to OHCI & EHCI)
  89.  */
  90. static struct at91_usbh_data __initdata ek_usbh_hs_data = {
  91.     .ports      = 2,
  92. //  .vbus_pin   = {AT91_PIN_PB12, AT91_PIN_PB13, },
  93. };
  94.  
  95. /*
  96.  * I2C devices
  97.  */
  98. static struct tsc2007_platform_data tsc2007_info = {
  99. .model                  = 2007,
  100. .x_plate_ohms           = 180,
  101. //.get_pendown_state      = ts_get_pendown_state,
  102. };
  103.  
  104. static struct at24_platform_data at24c32 = {
  105.         .byte_len       = SZ_32K / 8,
  106.         .page_size      = 32,
  107.         .flags          = AT24_FLAG_ADDR16,
  108. };
  109.  
  110.  
  111. static struct i2c_board_info icnova_i2c[] = {
  112.    
  113.     { I2C_BOARD_INFO("m41t82", 0x68) },
  114.     { I2C_BOARD_INFO("tsc2007", 0x49),
  115.       .type           = "tsc2007",
  116.       .platform_data  = &tsc2007_info,   
  117.     },
  118.    
  119. };
  120. static struct pcf857x_platform_data pcf23_pdata = {
  121.     .gpio_base = NR_BUILTIN_GPIO,
  122.     .n_latch = 0,
  123.     .setup = NULL,
  124.     .teardown = NULL,
  125.     .context = NULL,
  126. };
  127.  
  128.  
  129. static struct i2c_board_info icnova_i2c2[] = {
  130.     { I2C_BOARD_INFO("apds9300", 0x39) },
  131.     { I2C_BOARD_INFO("tmp102", 0x48),
  132.         .irq = AT91_PIN_PD27,
  133.     },
  134.     { I2C_BOARD_INFO("isl12022", 0x6f),
  135.         .irq = AT91_PIN_PA26,
  136.     },
  137.     { I2C_BOARD_INFO("24c32", 0x50),
  138.         .platform_data = &at24c32,
  139.     },
  140.     { I2C_BOARD_INFO("pcf8574", 0x22),
  141.         .platform_data = &pcf23_pdata,
  142.     },
  143. };
  144.  
  145. /*
  146.  * SPI devices.
  147.  */
  148.  
  149. #define CONFIG_BOARD_ICNOVA_ADS7846_IRQ AT91_PIN_PC30
  150. #define CONFIG_BOARD_ICNOVA_ADS7846_CS  1
  151. static struct ads7846_platform_data ads_info = {
  152.     .model                  = 7846,
  153.     .vref_delay_usecs       = 100,
  154.     .gpio_pendown           = CONFIG_BOARD_ICNOVA_ADS7846_IRQ,
  155.     .x_min                  = 180,//330,
  156.     .y_min                  = 3827,//3700,
  157.     .x_max                  = 3900,//3700,
  158.     .y_max                  = 150,//330,
  159.     .xy_fuzz        = 40,
  160.     .pressure_max       = 0xFFF0,
  161.     .pressure_min       = 0xF100,
  162.     .settle_delay_usecs     = 200,
  163.     .debounce_rep       = 4,
  164.     .debounce_tol       = 40,
  165.     .debounce_max       = 10,
  166. };
  167.  
  168. static struct spi_board_info ek_spi_devices[] = {
  169.     {
  170.         .modalias       = "ads7846",
  171.         .max_speed_hz   = 125000 * 26,
  172.         .chip_select    = CONFIG_BOARD_ICNOVA_ADS7846_CS,
  173.         .platform_data  = &ads_info,
  174.         .bus_num        = 0,
  175.         .controller_data = (void *) AT91_PIN_PD24,
  176.     },
  177.     {
  178.         .modalias       = "supervisor",
  179.         .max_speed_hz   = 550000,
  180.         .chip_select    = 0,
  181.         .platform_data  = NULL,
  182.         .bus_num        = 0,
  183.     },
  184.  
  185. };
  186.  
  187.  
  188. /*
  189.  * MACB Ethernet device
  190.  */
  191. static struct at91_eth_data __initdata ek_macb_data = {
  192.     .phy_irq_pin    = AT91_PIN_PA27,
  193. };
  194.  
  195.  
  196. /*
  197.  * NAND flash
  198.  */
  199. static struct mtd_partition __initdata ek_nand_partition[] = {
  200.     {
  201.         .name   = "Kernel",
  202.         .offset = 0,
  203.         .size   = SZ_4M,
  204.     },
  205.     {
  206.         .name   = "Data",
  207.         .offset = MTDPART_OFS_NXTBLK,
  208.         .size   = MTDPART_SIZ_FULL,
  209.     },
  210. };
  211.  
  212. static struct mtd_partition * __init nand_partitions(int size, int *num_partitions)
  213. {
  214.     *num_partitions = ARRAY_SIZE(ek_nand_partition);
  215.     return ek_nand_partition;
  216. }
  217.  
  218. /* det_pin is not connected */
  219. static struct atmel_nand_data __initdata ek_nand_data = {
  220.     .ale        = 21,
  221.     .cle        = 22,
  222.     .rdy_pin    = AT91_PIN_PC8,
  223.     .enable_pin = AT91_PIN_PC14,
  224.     .partition_info = nand_partitions,
  225.     .bus_width_16   = 0,
  226. };
  227.  
  228. static struct sam9_smc_config __initdata ek_nand_smc_config = {
  229.     .ncs_read_setup     = 0,
  230.     .nrd_setup      = 10,
  231.     .ncs_write_setup    = 0,
  232.     .nwe_setup      = 10,
  233.  
  234.     .ncs_read_pulse     = 50,
  235.     .nrd_pulse      = 30,
  236.     .ncs_write_pulse    = 50,
  237.     .nwe_pulse      = 30,
  238.  
  239.     .read_cycle     = 60,
  240.     .write_cycle        = 60,
  241.  
  242.     .mode           = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
  243.     .tdf_cycles     = 4,
  244. };
  245.  
  246. static void __init ek_add_device_nand(void)
  247. {
  248.     /* configure chip-select 3 (NAND) */
  249.     sam9_smc_configure(3, &ek_nand_smc_config);
  250.  
  251.     at91_add_device_nand(&ek_nand_data);
  252. }
  253.  
  254. /*
  255.  * MCI (SD/MMC)
  256.  */
  257. static struct mci_platform_data __initdata ek_mmc_data = {
  258.     .slot[0] = {
  259.         .bus_width  = 4,
  260.         .detect_pin = AT91_PIN_PC6,
  261.         .wp_pin     = -1,
  262.     },
  263. };
  264.  
  265. static struct mci_platform_data __initdata ek_mmc_data1 = {
  266.     .slot[0] = {
  267.         .bus_width  = 4,
  268.         .detect_pin = AT91_PIN_PC7,
  269.         .wp_pin     = -1,
  270.     },
  271. };
  272.  
  273.  
  274. /*
  275.  * LCD Controller
  276.  */
  277. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  278. static struct fb_videomode at91_tft_vga_modes[] = {
  279.     {
  280.         .name           = "VGA",
  281.         .refresh    = 50,
  282.         .xres       = 800,      .yres       = 480,
  283.         .pixclock   = 25000,
  284.  
  285.         .left_margin    = 178,      .right_margin   = 38,
  286.         .upper_margin   = 35,       .lower_margin   = 8,
  287.         .hsync_len  = 40,       .vsync_len  = 2,
  288.  
  289.         .vmode      = FB_VMODE_NONINTERLACED,
  290.     }
  291. };
  292.  
  293. static struct fb_monspecs at91fb_default_monspecs = {
  294.     .manufacturer   = "Hita",
  295.     .monitor        = "TX20D26VM0APA",
  296.  
  297.     .modedb     = at91_tft_vga_modes,
  298.     .modedb_len = ARRAY_SIZE(at91_tft_vga_modes),
  299.     .hfmin      = 16700,
  300.     .hfmax      = 41700,
  301.     .vfmin      = 47,
  302.     .vfmax      = 75,
  303. };
  304.  
  305. #define AT91SAM9G45_DEFAULT_LCDCON2     (ATMEL_LCDC_MEMOR_LITTLE \
  306.                     | ATMEL_LCDC_DISTYPE_TFT \
  307.                     | ATMEL_LCDC_INVCLK \
  308.                     | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE)
  309.                     //| ATMEL_LCDC_INVDVAL
  310.  
  311. /* Driver datas */
  312. static struct atmel_lcdfb_info __initdata ek_lcdc_data = {
  313.     .lcdcon_is_backlight        = true,
  314.     .default_bpp            = /*24*/16,
  315.     .default_dmacon         = ATMEL_LCDC_DMAEN | ATMEL_LCDC_DMA2DEN,
  316.     .default_lcdcon2        = AT91SAM9G45_DEFAULT_LCDCON2,
  317.     .default_monspecs       = &at91fb_default_monspecs,
  318.     .guard_time         = 9,
  319.     .lcd_wiring_mode        = ATMEL_LCDC_WIRING_RGB,
  320. };
  321.  
  322. #else
  323. static struct atmel_lcdfb_info __initdata ek_lcdc_data;
  324. #endif
  325.  
  326. #if 0
  327. static struct platform_device icnova_pwmdev = {
  328.     .name = "atmel-pwm-hwmon",
  329.     .id = 0,
  330. };
  331. #endif
  332.  
  333. /*
  334.  * Btns
  335.  */
  336. static struct gpio_keys_button buttons[] = {
  337. #ifdef CONFIG_SUPERVISOR_IRQ
  338.     {
  339.         .code       = KEY_BACK,
  340.         .gpio       = 240,
  341.         .active_low = 1,
  342.         .desc       = "back",
  343.         .wakeup     = 1,
  344.     },
  345.     {
  346.         .code       = KEY_HOME,
  347.         .gpio       = 241,
  348.         .active_low = 1,
  349.         .desc       = "home",
  350.         .wakeup     = 1,
  351.     },
  352.     {
  353.         .code       = KEY_MENU,
  354.         .gpio       = 242,
  355.         .active_low = 1,
  356.         .desc       = "menu",
  357.         .wakeup     = 1,
  358.     },
  359. #endif
  360. };
  361.  
  362. static struct gpio_keys_platform_data button_data = {
  363.     .buttons    = buttons,
  364.     .nbuttons   = ARRAY_SIZE(buttons),
  365. };
  366.  
  367. static struct platform_device button_device = {
  368.     .name       = "gpio-keys",
  369.     .id     = -1,
  370.     .num_resources  = 0,
  371.     .dev        = {
  372.         .platform_data  = &button_data,
  373.         },
  374. };
  375. #if 1
  376. static struct platform_device at91_adc_device = {
  377.     .name       = "at91_adc_test",
  378.     .id     = -1,
  379.     .num_resources  = 0,
  380. };
  381.  
  382. void __init at91_add_device_adc()
  383. {
  384.     at91_set_gpio_input(AT91_PIN_PD24, 0);  /* ADC channel 5 *//* 1-4 used for Touch*/
  385.    
  386.     platform_device_register(&at91_adc_device);
  387. //  printk("ANKUR: Under at91_add_device_adc \n");
  388. }
  389. #endif
  390. static void __init ek_board_init(void)
  391. {
  392.     /* Serial */
  393.     at91_add_device_serial();
  394.     /* USB HS Host */
  395.     gpio_request(AT91_PIN_PB8, "usbhub.reset");
  396.     gpio_direction_output(AT91_PIN_PB8, 1);
  397.     at91_add_device_usbh_ehci(&ek_usbh_hs_data);
  398.     at91_add_device_usbh_ohci(&ek_usbh_hs_data);
  399.     /* USB HS Device */
  400.     at91_add_device_usba(NULL);
  401.  
  402.     /* Ethernet */
  403.     at91_add_device_eth(&ek_macb_data);
  404.     /* NAND */
  405.     ek_add_device_nand();
  406.     /* I2C */
  407.     at91_set_gpio_input(AT91_PIN_PD4, 0);
  408.     at91_add_device_i2c(0, icnova_i2c, ARRAY_SIZE(icnova_i2c));
  409.     at91_add_device_i2c(1, icnova_i2c2, ARRAY_SIZE(icnova_i2c2));
  410.     /* LCD Controller */
  411.     gpio_request(AT91_PIN_PE1, "lcdc.mode");
  412.     gpio_direction_output(AT91_PIN_PE1, 1);
  413.     gpio_request(AT91_PIN_PE0, "lcdc.pwr");
  414.     gpio_direction_output(AT91_PIN_PE0, 1);
  415.  
  416.     at91_add_device_lcdc(&ek_lcdc_data);
  417.  
  418.     /* BTN */
  419.     platform_device_register(&button_device);
  420.  
  421.     /* W1 */
  422.     at91_set_GPIO_periph(sn_w1_gpio_pdata.pin, 1);
  423.     at91_set_multi_drive(sn_w1_gpio_pdata.pin, 1);
  424.     platform_device_register(&sn_w1_device);
  425.    
  426.     /* PWM */
  427.     at91_add_device_pwm(4);
  428.     setup_atmel_pwm_bl();
  429.    
  430.     /* RTC INTERRUPT */
  431.     at91_set_gpio_input(AT91_PIN_PA26, 0); 
  432.     at91_set_deglitch(AT91_PIN_PA26, 1);  
  433.    
  434.     /* Temperature Sensor INTERRUPT */
  435.     at91_set_gpio_input(AT91_PIN_PD27, 0); 
  436.     at91_set_deglitch(AT91_PIN_PD27, 1);  
  437.    
  438. //  printk("ABOVE ADCDEVICE \n");
  439.     /*ADC Controller */
  440.     at91_add_device_adc();
  441. }
  442.  
  443. MACHINE_START(AT91SAM9G45EKES, "In-Circuit ICnova SAM9G45 SO-DIMM")
  444.     /* Maintainer: Atmel */
  445.     .phys_io    = AT91_BASE_SYS,
  446.     .io_pg_offst    = (AT91_VA_BASE_SYS >> 18) & 0xfffc,
  447.     .boot_params    = AT91_SDRAM_BASE + 0x100,
  448.     .timer      = &at91sam926x_timer,
  449.     .map_io     = ek_map_io,
  450.     .init_irq   = ek_init_irq,
  451.     .init_machine   = ek_board_init,
  452. MACHINE_END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement