Advertisement
Guest User

arch/arm/mach-s3c2440/mach-gta02.c

a guest
Jul 28th, 2012
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 36.10 KB | None | 0 0
  1. /*
  2.  * linux/arch/arm/mach-s3c2442/mach-gta02.c
  3.  *
  4.  * S3C2442 Machine Support for Openmoko GTA02 / FreeRunner.
  5.  *
  6.  * Copyright (C) 2006-2009 by Openmoko, Inc.
  7.  * Authors: Harald Welte <laforge@openmoko.org>
  8.  *          Andy Green <andy@openmoko.org>
  9.  *          Werner Almesberger <werner@openmoko.org>
  10.  * All rights reserved.
  11.  *
  12.  * This program is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU General Public License as
  14.  * published by the Free Software Foundation; either version 2 of
  15.  * the License, or (at your option) any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25.  * MA 02111-1307 USA
  26.  *
  27.  */
  28.  
  29. #include <linux/kernel.h>
  30. #include <linux/types.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/list.h>
  33. #include <linux/delay.h>
  34. #include <linux/timer.h>
  35. #include <linux/init.h>
  36. #include <linux/gpio.h>
  37. #include <linux/workqueue.h>
  38. #include <linux/platform_device.h>
  39. #include <linux/serial_core.h>
  40. #include <linux/spi/spi.h>
  41. #include <linux/spi/spi_gpio.h>
  42.  
  43. #include <linux/mmc/host.h>
  44.  
  45. #include <linux/mtd/mtd.h>
  46. #include <linux/mtd/nand.h>
  47. #include <linux/mtd/nand_ecc.h>
  48. #include <linux/mtd/partitions.h>
  49. #include <linux/mtd/physmap.h>
  50. #include <linux/io.h>
  51.  
  52. #include <linux/i2c.h>
  53. #include <linux/regulator/machine.h>
  54. #include <linux/regulator/fixed.h>
  55.  
  56. #include <linux/mfd/pcf50633/core.h>
  57. #include <linux/mfd/pcf50633/mbc.h>
  58. #include <linux/mfd/pcf50633/adc.h>
  59. #include <linux/mfd/pcf50633/gpio.h>
  60. #include <linux/mfd/pcf50633/pmic.h>
  61. #include <linux/mfd/pcf50633/backlight.h>
  62.  
  63. #include <linux/input.h>
  64. #include <linux/gpio_keys.h>
  65. #include <linux/lis302dl.h>
  66.  
  67. #include <linux/leds.h>
  68. #include <linux/leds_pwm.h>
  69.  
  70. #include <asm/mach/arch.h>
  71. #include <asm/mach/map.h>
  72. #include <asm/mach/irq.h>
  73.  
  74. #include <asm/irq.h>
  75. #include <asm/mach-types.h>
  76.  
  77. #include <mach/regs-irq.h>
  78. #include <mach/regs-gpio.h>
  79. #include <mach/regs-gpioj.h>
  80. #include <mach/fb.h>
  81.  
  82. #include <mach/spi.h>
  83. #include <mach/spi-gpio.h>
  84. #include <plat/usb-control.h>
  85. #include <mach/regs-mem.h>
  86. #include <mach/hardware.h>
  87.  
  88. #include <mach/gta02.h>
  89.  
  90. #include <plat/regs-serial.h>
  91. #include <plat/nand.h>
  92. #include <plat/devs.h>
  93. #include <plat/cpu.h>
  94. #include <plat/pm.h>
  95. #include <plat/udc.h>
  96. #include <plat/gpio-cfg.h>
  97. #include <plat/iic.h>
  98. #include <plat/ts.h>
  99.  
  100.  
  101. #include <mach/gta02-pm-gps.h>
  102. #include <mach/gta02-pm-wlan.h>
  103.  
  104. #include <mach/gta02-fiq.h>
  105.  
  106. #include <mach/gta02-hdq.h>
  107. #include <linux/power/bq27x00_battery.h>
  108. #include <linux/platform_battery.h>
  109.  
  110. #include <linux/jbt6k74.h>
  111. #include <linux/glamofb.h>
  112. #include <linux/mfd/glamo.h>
  113.  
  114. static struct pcf50633 *gta02_pcf;
  115.  
  116. /*
  117.  * This gets called frequently when we paniced.
  118.  */
  119.  
  120. static long gta02_panic_blink(int state)
  121. {
  122.     long delay = 0;
  123.     char led;
  124.  
  125.     led = (state) ? 1 : 0;
  126.     gpio_direction_output(GTA02_GPIO_AUX_LED, led);
  127.  
  128.     return delay;
  129. }
  130.  
  131. struct platform_device gta02_resume_reason_device = {
  132.     .name       = "neo1973-resume",
  133.     .num_resources  = 0,
  134. };
  135.  
  136. static struct map_desc gta02_iodesc[] __initdata = {
  137.     {
  138.         .virtual    = 0xe0000000,
  139.         .pfn        = __phys_to_pfn(S3C2410_CS3 + 0x01000000),
  140.         .length     = SZ_1M,
  141.         .type       = MT_DEVICE
  142.     },
  143. };
  144.  
  145. #define UCON (S3C2410_UCON_DEFAULT | S3C2443_UCON_RXERR_IRQEN)
  146. #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB)
  147. #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
  148.  
  149. static struct s3c2410_uartcfg gta02_uartcfgs[] = {
  150.     [0] = {
  151.         .hwport     = 0,
  152.         .flags      = 0,
  153.         .ucon       = UCON,
  154.         .ulcon      = ULCON,
  155.         .ufcon      = UFCON,
  156.     },
  157.     [1] = {
  158.         .hwport     = 1,
  159.         .flags      = 0,
  160.         .ucon       = UCON,
  161.         .ulcon      = ULCON,
  162.         .ufcon      = UFCON,
  163.     },
  164.     [2] = {
  165.         .hwport     = 2,
  166.         .flags      = 0,
  167.         .ucon       = UCON,
  168.         .ulcon      = ULCON,
  169.         .ufcon      = UFCON,
  170.     },
  171. };
  172.  
  173. static struct platform_device gta02_pm_bt_dev = {
  174.     .name = "gta02-pm-bt",
  175. };
  176.  
  177. static struct platform_device gta02_pm_gps_dev = {
  178.     .name = "gta02-pm-gps",
  179. };
  180.  
  181. static struct platform_device gta02_pm_gsm_dev = {
  182.     .name = "gta02-pm-gsm",
  183. };
  184.  
  185. static struct platform_device gta02_pm_usbhost_dev = {
  186.     .name = "gta02-pm-usbhost",
  187. };
  188.  
  189. static struct platform_device gta02_pm_wlan_dev = {
  190.     .name = "gta02-pm-wlan",
  191. };
  192.  
  193. static struct regulator_consumer_supply gsm_supply_consumer = {
  194.     .dev = &gta02_pm_gsm_dev.dev,
  195.     .supply = "GSM",
  196. };
  197.  
  198. static struct regulator_consumer_supply usbhost_supply_consumer = {
  199.     .dev = &gta02_pm_usbhost_dev.dev,
  200.     .supply = "USBHOST",
  201. };
  202.  
  203. static struct regulator_init_data gsm_supply_init_data = {
  204.     .constraints = {
  205.         .min_uV = 3700000,
  206.         .max_uV = 3700000,
  207.         .valid_modes_mask = REGULATOR_MODE_NORMAL,
  208.         .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  209.     },
  210.     .num_consumer_supplies = 1,
  211.     .consumer_supplies = &gsm_supply_consumer,
  212. };
  213.  
  214. static struct regulator_init_data usbhost_supply_init_data = {
  215.     .constraints = {
  216.         .min_uV = 3700000,
  217.         .max_uV = 3700000,
  218.         .valid_modes_mask = REGULATOR_MODE_NORMAL,
  219.         .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  220.     },
  221.     .num_consumer_supplies = 1,
  222.     .consumer_supplies = &usbhost_supply_consumer,
  223. };
  224.  
  225. static struct fixed_voltage_config gsm_supply_config = {
  226.     .supply_name = "GSM",
  227.     .microvolts = 3700000,
  228.     .gpio = GTA02_GPIO_PCF(PCF50633_GPIO2),
  229.     .enable_high = 1,
  230.     .init_data = &gsm_supply_init_data,
  231. };
  232.  
  233. static struct fixed_voltage_config usbhost_supply_config = {
  234.     .supply_name = "USBHOST",
  235.     .microvolts = 3700000,
  236.     .gpio = GTA02_GPIO_PCF(PCF50633_GPO),
  237.     .enable_high = 1,
  238.     .init_data = &usbhost_supply_init_data,
  239. };
  240.  
  241. static struct platform_device gta02_gsm_supply_device = {
  242.     .name = "reg-fixed-voltage",
  243.     .id = 1,
  244.     .dev = {
  245.         .platform_data = &gsm_supply_config,
  246.     },
  247. };
  248.  
  249. static struct platform_device gta02_usbhost_supply_device = {
  250.     .name = "reg-fixed-voltage",
  251.     .id = 2,
  252.     .dev = {
  253.         .platform_data = &usbhost_supply_config,
  254.     },
  255. };
  256.  
  257. /*
  258.  * we crank down SD Card clock dynamically when GPS is powered
  259.  */
  260.  
  261. static int gta02_glamo_mci_use_slow(void)
  262. {
  263.     return gta02_pm_gps_is_on();
  264. }
  265.  
  266. static void gta02_glamo_external_reset(int level)
  267. {
  268.     s3c2410_gpio_setpin(GTA02_GPIO_3D_RESET, level);
  269.     s3c2410_gpio_cfgpin(GTA02_GPIO_3D_RESET, S3C2410_GPIO_OUTPUT);
  270. }
  271.  
  272. struct spi_gpio_platform_data spigpio_platform_data = {
  273.     .sck = GTA02_GPIO_GLAMO(10),
  274.     .mosi = GTA02_GPIO_GLAMO(11),
  275.     .miso = GTA02_GPIO_GLAMO(5),
  276.     .num_chipselect = 1,
  277. };
  278.  
  279. static struct platform_device spigpio_device = {
  280.     .name = "spi_gpio",
  281.     .id   = 2,
  282.     .dev = {
  283.         .platform_data = &spigpio_platform_data,
  284.     },
  285. };
  286.  
  287. static struct fb_videomode gta02_glamo_modes[] = {
  288.     {
  289.         .name = "480x640",
  290.         .xres = 480,
  291.         .yres = 640,
  292.         .pixclock   = 40816,
  293.         .left_margin    = 8,
  294.         .right_margin   = 16,
  295.         .upper_margin   = 2,
  296.         .lower_margin   = 16,
  297.         .hsync_len  = 8,
  298.         .vsync_len  = 2,
  299.         .vmode = FB_VMODE_NONINTERLACED,
  300.     }, {
  301.         .name = "240x320",
  302.         .xres = 240,
  303.         .yres = 320,
  304.         .pixclock   = 40816,
  305.         .left_margin    = 8,
  306.         .right_margin   = 16,
  307.         .upper_margin   = 2,
  308.         .lower_margin   = 16,
  309.         .hsync_len  = 8,
  310.         .vsync_len  = 2,
  311.         .vmode = FB_VMODE_NONINTERLACED,
  312.     }
  313. };
  314.  
  315. static struct glamo_fb_platform_data gta02_glamo_fb_pdata = {
  316.     .width  = 43,
  317.     .height = 58,
  318.  
  319.     .num_modes = ARRAY_SIZE(gta02_glamo_modes),
  320.     .modes = gta02_glamo_modes,
  321. };
  322.  
  323. static struct glamo_mmc_platform_data gta02_glamo_mmc_pdata = {
  324.     .glamo_mmc_use_slow = gta02_glamo_mci_use_slow,
  325. };
  326.  
  327. static struct glamo_gpio_platform_data gta02_glamo_gpio_pdata = {
  328.     .base = GTA02_GPIO_GLAMO_BASE,
  329. };
  330.  
  331. static struct glamo_platform_data gta02_glamo_pdata = {
  332.     .fb_data    = &gta02_glamo_fb_pdata,
  333.     .mmc_data   = &gta02_glamo_mmc_pdata,
  334.     .gpio_data  = &gta02_glamo_gpio_pdata,
  335.  
  336.     .osci_clock_rate = 32768,
  337.  
  338.     .glamo_external_reset = gta02_glamo_external_reset,
  339. };
  340.  
  341. /* SPI: Accelerometers attached to SPI of s3c244x */
  342.  
  343. /*
  344.  * Situation is that Linux SPI can't work in an interrupt context, so we
  345.  * implement our own bitbang here.  Arbitration is needed because not only
  346.  * can this interrupt happen at any time even if foreground wants to use
  347.  * the bitbang API from Linux, but multiple motion sensors can be on the
  348.  * same SPI bus, and multiple interrupts can happen.
  349.  *
  350.  * Foreground / interrupt arbitration is okay because the interrupts are
  351.  * disabled around all the foreground SPI code.
  352.  *
  353.  * Interrupt / Interrupt arbitration is evidently needed, otherwise we
  354.  * lose edge-triggered service after a while due to the two sensors sharing
  355.  * the SPI bus having irqs at the same time eventually.
  356.  *
  357.  * Servicing is typ 75 - 100us at 400MHz.
  358.  */
  359.  
  360. /* #define DEBUG_SPEW_MS */
  361. #define MG_PER_SAMPLE 18
  362.  
  363. struct lis302dl_platform_data lis302_pdata_top;
  364. struct lis302dl_platform_data lis302_pdata_bottom;
  365.  
  366. /*
  367.  * generic SPI RX and TX bitbang
  368.  * only call with interrupts off!
  369.  */
  370.  
  371. static void __gta02_lis302dl_bitbang(struct lis302dl_info *lis, u8 *tx,
  372.                          int tx_bytes, u8 *rx, int rx_bytes)
  373. {
  374.     struct lis302dl_platform_data *pdata = lis->pdata;
  375.     int n;
  376.     u8 shifter = 0;
  377.     unsigned long other_cs;
  378.  
  379.     /*
  380.      * Huh... "quirk"... CS on this device is not really "CS" like you can
  381.      * expect.
  382.      *
  383.      * When it is 0 it selects SPI interface mode.
  384.      * When it is 1 it selects I2C interface mode.
  385.      *
  386.      * Because we have 2 devices on one interface we have to make sure
  387.      * that the "disabled" device (actually in I2C mode) don't think we're
  388.      * talking to it.
  389.      *
  390.      * When we talk to the "enabled" device, the "disabled" device sees
  391.      * the clocks as I2C clocks, creating havoc.
  392.      *
  393.      * I2C sees MOSI going LOW while CLK HIGH as a START action, thus we
  394.      * must ensure this is never issued.
  395.      */
  396.  
  397.     if (&lis302_pdata_top == pdata)
  398.         other_cs = lis302_pdata_bottom.pin_chip_select;
  399.     else
  400.         other_cs = lis302_pdata_top.pin_chip_select;
  401.  
  402.     s3c2410_gpio_setpin(other_cs, 1);
  403.     s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
  404.     s3c2410_gpio_setpin(pdata->pin_clk, 1);
  405.     s3c2410_gpio_setpin(pdata->pin_chip_select, 0);
  406.  
  407.     /* send the register index, r/w and autoinc bits */
  408.     for (n = 0; n < (tx_bytes << 3); n++) {
  409.         if (!(n & 7))
  410.             shifter = ~tx[n >> 3];
  411.         s3c2410_gpio_setpin(pdata->pin_clk, 0);
  412.         s3c2410_gpio_setpin(pdata->pin_mosi, !(shifter & 0x80));
  413.         s3c2410_gpio_setpin(pdata->pin_clk, 1);
  414.         shifter <<= 1;
  415.     }
  416.  
  417.     for (n = 0; n < (rx_bytes << 3); n++) { /* 8 bits each */
  418.         s3c2410_gpio_setpin(pdata->pin_clk, 0);
  419.         shifter <<= 1;
  420.         if (s3c2410_gpio_getpin(pdata->pin_miso))
  421.             shifter |= 1;
  422.         if ((n & 7) == 7)
  423.             rx[n >> 3] = shifter;
  424.         s3c2410_gpio_setpin(pdata->pin_clk, 1);
  425.     }
  426.     s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
  427.     s3c2410_gpio_setpin(other_cs, 1);
  428. }
  429.  
  430.  
  431. static int gta02_lis302dl_bitbang_read_reg(struct lis302dl_info *lis, u8 reg)
  432. {
  433.     u8 data = 0xc0 | reg; /* read, autoincrement */
  434.     unsigned long flags;
  435.  
  436.     local_irq_save(flags);
  437.  
  438.     __gta02_lis302dl_bitbang(lis, &data, 1, &data, 1);
  439.  
  440.     local_irq_restore(flags);
  441.  
  442.     return data;
  443. }
  444.  
  445. static void gta02_lis302dl_bitbang_write_reg(struct lis302dl_info *lis, u8 reg,
  446.                                      u8 val)
  447. {
  448.     u8 data[2] = { 0x00 | reg, val }; /* write, no autoincrement */
  449.     unsigned long flags;
  450.  
  451.     local_irq_save(flags);
  452.  
  453.     __gta02_lis302dl_bitbang(lis, &data[0], 2, NULL, 0);
  454.  
  455.     local_irq_restore(flags);
  456.  
  457. }
  458.  
  459.  
  460. void gta02_lis302dl_suspend_io(struct lis302dl_info *lis, int resume)
  461. {
  462.     struct lis302dl_platform_data *pdata = lis->pdata;
  463.  
  464.     if (!resume) {
  465.          /*
  466.          * we don't want to power them with a high level
  467.          * because GSENSOR_3V3 is not up during suspend
  468.          */
  469.         s3c2410_gpio_setpin(pdata->pin_chip_select, 0);
  470.         s3c2410_gpio_setpin(pdata->pin_clk, 0);
  471.         s3c2410_gpio_setpin(pdata->pin_mosi, 0);
  472.         /* misnomer: it is a pullDOWN in 2442 */
  473.         s3c2410_gpio_pullup(pdata->pin_miso, 1);
  474.         return;
  475.     }
  476.  
  477.     /* back to normal */
  478.     s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
  479.     s3c2410_gpio_setpin(pdata->pin_clk, 1);
  480.     /* misnomer: it is a pullDOWN in 2442 */
  481.     s3c2410_gpio_pullup(pdata->pin_miso, 0);
  482.  
  483.     s3c2410_gpio_cfgpin(pdata->pin_chip_select, S3C2410_GPIO_OUTPUT);
  484.     s3c2410_gpio_cfgpin(pdata->pin_clk, S3C2410_GPIO_OUTPUT);
  485.     s3c2410_gpio_cfgpin(pdata->pin_mosi, S3C2410_GPIO_OUTPUT);
  486.     s3c2410_gpio_cfgpin(pdata->pin_miso, S3C2410_GPIO_INPUT);
  487.  
  488. }
  489.  
  490.  
  491.  
  492. struct lis302dl_platform_data lis302_pdata_top = {
  493.         .name       = "lis302-1 (top)",
  494.         .pin_chip_select= S3C2410_GPD(12),
  495.         .pin_clk    = S3C2410_GPG(7),
  496.         .pin_mosi   = S3C2410_GPG(6),
  497.         .pin_miso   = S3C2410_GPG(5),
  498.         .interrupt  = GTA02_IRQ_GSENSOR_1,
  499.         .open_drain = 1, /* altered at runtime by PCB rev */
  500.         .lis302dl_bitbang = __gta02_lis302dl_bitbang,
  501.         .lis302dl_bitbang_reg_read = gta02_lis302dl_bitbang_read_reg,
  502.         .lis302dl_bitbang_reg_write = gta02_lis302dl_bitbang_write_reg,
  503.         .lis302dl_suspend_io = gta02_lis302dl_suspend_io,
  504. };
  505.  
  506. struct lis302dl_platform_data lis302_pdata_bottom = {
  507.         .name       = "lis302-2 (bottom)",
  508.         .pin_chip_select= S3C2410_GPD(13),
  509.         .pin_clk    = S3C2410_GPG(7),
  510.         .pin_mosi   = S3C2410_GPG(6),
  511.         .pin_miso   = S3C2410_GPG(5),
  512.         .interrupt  = GTA02_IRQ_GSENSOR_2,
  513.         .open_drain = 1, /* altered at runtime by PCB rev */
  514.         .lis302dl_bitbang = __gta02_lis302dl_bitbang,
  515.         .lis302dl_bitbang_reg_read = gta02_lis302dl_bitbang_read_reg,
  516.         .lis302dl_bitbang_reg_write = gta02_lis302dl_bitbang_write_reg,
  517.         .lis302dl_suspend_io = gta02_lis302dl_suspend_io,
  518. };
  519.  
  520.  
  521. static struct platform_device s3c_device_spi_acc1 = {
  522.     .name         = "lis302dl",
  523.     .id       = 1,
  524.     .dev = {
  525.         .platform_data = &lis302_pdata_top,
  526.     },
  527. };
  528.  
  529. static struct platform_device s3c_device_spi_acc2 = {
  530.     .name         = "lis302dl",
  531.     .id       = 2,
  532.     .dev = {
  533.         .platform_data = &lis302_pdata_bottom,
  534.     },
  535. };
  536.  
  537. /* JBT6k74 display controller */
  538. static void gta02_jbt6k74_probe_completed(struct device *dev)
  539. {
  540.     pcf50633_bl_set_brightness_limit(gta02_pcf, 0x3f);
  541. }
  542.  
  543. const static struct jbt6k74_platform_data jbt6k74_pdata = {
  544.     .gpio_reset = GTA02_GPIO_GLAMO(4),
  545. };
  546.  
  547. static struct spi_board_info gta02_spi_board_info[] = {
  548.     {
  549.         .modalias   = "jbt6k74",
  550.         .platform_data  = &jbt6k74_pdata,
  551.         .controller_data = (void *)GTA02_GPIO_GLAMO(12),
  552.         /* irq */
  553.         .max_speed_hz   = 100 * 1000,
  554.         .bus_num    = 2,
  555.         .chip_select    = 0
  556.     },
  557. };
  558.  
  559. static struct resource gta02_glamo_resources[] = {
  560.     [0] = {
  561.         .start  = S3C2410_CS1,
  562.         .end    = S3C2410_CS1 + 0x1000000 - 1,
  563.         .flags  = IORESOURCE_MEM,
  564.     },
  565.     [1] = {
  566.         .start  = GTA02_IRQ_3D,
  567.         .end    = GTA02_IRQ_3D,
  568.         .flags  = IORESOURCE_IRQ,
  569.     },
  570. };
  571.  
  572. static struct platform_device gta02_glamo_dev = {
  573.     .name       = "glamo3362",
  574.     .num_resources  = ARRAY_SIZE(gta02_glamo_resources),
  575.     .resource   = gta02_glamo_resources,
  576.     .dev        = {
  577.         .platform_data  = &gta02_glamo_pdata,
  578.     },
  579. };
  580.  
  581.  
  582. #ifdef CONFIG_CHARGER_PCF50633
  583. /*
  584.  * On GTA02 the 1A charger features a 48K resistor to 0V on the ID pin.
  585.  * We use this to recognize that we can pull 1A from the USB socket.
  586.  *
  587.  * These constants are the measured pcf50633 ADC levels with the 1A
  588.  * charger / 48K resistor, and with no pulldown resistor.
  589.  */
  590.  
  591. #define ADC_NOM_CHG_DETECT_1A 6
  592. #define ADC_NOM_CHG_DETECT_USB 43
  593.  
  594. static int gta02_get_charger_online_status(void)
  595. {
  596.     struct pcf50633 *pcf = gta02_pcf;
  597.  
  598.     return pcf50633_mbc_get_status(pcf) & PCF50633_MBC_USB_ONLINE;
  599. }
  600.  
  601. static int gta02_get_charger_active_status(void)
  602. {
  603.     struct pcf50633 *pcf = gta02_pcf;
  604.  
  605.     return pcf50633_mbc_get_status(pcf) & PCF50633_MBC_USB_ACTIVE;
  606. }
  607.  
  608. static void
  609. gta02_configure_pmu_for_charger(struct pcf50633 *pcf, void *unused, int res)
  610. {
  611.     int ma;
  612.  
  613.     if (res < ((ADC_NOM_CHG_DETECT_USB + ADC_NOM_CHG_DETECT_1A) / 2))
  614.         ma = 1000;
  615.     else
  616.         ma = 100;
  617.  
  618.     pcf50633_mbc_usb_curlim_set(pcf, ma);
  619. }
  620.  
  621. static struct delayed_work gta02_charger_work;
  622. static int gta02_usb_vbus_draw;
  623.  
  624. static void gta02_charger_worker(struct work_struct *work)
  625. {
  626.     if (gta02_usb_vbus_draw) {
  627.         pcf50633_mbc_usb_curlim_set(gta02_pcf, gta02_usb_vbus_draw);
  628.         return;
  629.     }
  630.  
  631. #ifdef CONFIG_PCF50633_ADC
  632.     pcf50633_adc_async_read(gta02_pcf,
  633.                 PCF50633_ADCC1_MUX_ADCIN1,
  634.                 PCF50633_ADCC1_AVERAGE_16,
  635.                 gta02_configure_pmu_for_charger,
  636.                 NULL);
  637. #else
  638.     /*
  639.      * If the PCF50633 ADC is disabled we fallback to a
  640.      * 100mA limit for safety.
  641.      */
  642.     pcf50633_mbc_usb_curlim_set(pcf, 100);
  643. #endif
  644. }
  645.  
  646. #define GTA02_CHARGER_CONFIGURE_TIMEOUT ((3000 * HZ) / 1000)
  647.  
  648. static void gta02_pmu_event_callback(struct pcf50633 *pcf, int irq)
  649. {
  650.     if (irq == PCF50633_IRQ_USBINS) {
  651.         schedule_delayed_work(&gta02_charger_work,
  652.                       GTA02_CHARGER_CONFIGURE_TIMEOUT);
  653.  
  654.         return;
  655.     }
  656.  
  657.     if (irq == PCF50633_IRQ_USBREM) {
  658.         cancel_delayed_work_sync(&gta02_charger_work);
  659.         gta02_usb_vbus_draw = 0;
  660.     }
  661. }
  662.  
  663. static void gta02_udc_vbus_draw(unsigned int ma)
  664. {
  665.     if (!gta02_pcf)
  666.         return;
  667.  
  668.     gta02_usb_vbus_draw = ma;
  669.  
  670.     schedule_delayed_work(&gta02_charger_work,
  671.                   GTA02_CHARGER_CONFIGURE_TIMEOUT);
  672. }
  673. #else /* !CONFIG_CHARGER_PCF50633 */
  674. #define gta02_pmu_event_callback    NULL
  675. #define gta02_udc_vbus_draw     NULL
  676. #define gta02_get_charger_online_status NULL
  677. #define gta02_get_charger_active_status NULL
  678. #endif
  679.  
  680. /*
  681.  * This is called when pc50633 is probed, unfortunately quite late in the
  682.  * day since it is an I2C bus device. Here we can belatedly define some
  683.  * platform devices with the advantage that we can mark the pcf50633 as the
  684.  * parent. This makes them get suspended and resumed with their parent
  685.  * the pcf50633 still around.
  686.  */
  687.  
  688. static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf);
  689.  
  690.  
  691. static char *gta02_batteries[] = {
  692.     "battery",
  693. };
  694.  
  695. static struct pcf50633_bl_platform_data gta02_backlight_data = {
  696.     .default_brightness = 0x3f,
  697.     .default_brightness_limit = 0,
  698.     .ramp_time = 5,
  699. };
  700.  
  701. static struct regulator_consumer_supply ldo4_consumers[] = {
  702.     {
  703.         .dev = &gta02_pm_bt_dev.dev,
  704.         .supply = "BT_3V2",
  705.     },
  706. };
  707.  
  708. static struct regulator_consumer_supply ldo5_consumers[] = {
  709.     {
  710.         .dev = &gta02_pm_gps_dev.dev,
  711.         .supply = "RF_3V",
  712.     },
  713. };
  714.  
  715. static struct regulator_consumer_supply ldo6_consumers[] = {
  716.     REGULATOR_SUPPLY("VDC", "spi2.0"),
  717.     REGULATOR_SUPPLY("VDDIO", "spi2.0"),
  718. };
  719.  
  720. static struct regulator_consumer_supply hcldo_consumers[] = {
  721.     {
  722.         .dev = &gta02_glamo_dev.dev,
  723.         .supply = "SD_3V3",
  724.     },
  725. };
  726.  
  727. static void gta02_poweroff(void)
  728. {
  729.     pcf50633_reg_set_bit_mask(gta02_pcf, PCF50633_REG_OOCSHDWN, 1, 1);
  730. }
  731.  
  732. struct pcf50633_platform_data gta02_pcf_pdata = {
  733.     .resumers = {
  734.         [0] =   PCF50633_INT1_USBINS |
  735.             PCF50633_INT1_USBREM |
  736.             PCF50633_INT1_ALARM,
  737.         [1] =   PCF50633_INT2_ONKEYF,
  738.         [2] =   PCF50633_INT3_ONKEY1S,
  739.         [3] =   PCF50633_INT4_LOWSYS |
  740.             PCF50633_INT4_LOWBAT |
  741.             PCF50633_INT4_HIGHTMP,
  742.     },
  743.  
  744.     .batteries = gta02_batteries,
  745.     .num_batteries = ARRAY_SIZE(gta02_batteries),
  746.  
  747.     .charger_reference_current_ma = 1000,
  748.  
  749.     .backlight_data = &gta02_backlight_data,
  750.     .gpio_base = GTA02_GPIO_PCF_BASE,
  751.  
  752.     .reg_init_data = {
  753.         [PCF50633_REGULATOR_AUTO] = {
  754.             .constraints = {
  755.                 .min_uV = 3300000,
  756.                 .max_uV = 3300000,
  757.                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
  758.                 .always_on = 1,
  759.                 .apply_uV = 1,
  760.             },
  761.         },
  762.         [PCF50633_REGULATOR_DOWN1] = {
  763.             .constraints = {
  764.                 .min_uV = 1300000,
  765.                 .max_uV = 1600000,
  766.                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
  767.                 .always_on = 0,
  768.                 .apply_uV = 1,
  769.             },
  770.         },
  771.         [PCF50633_REGULATOR_DOWN2] = {
  772.             .constraints = {
  773.                 .min_uV = 1800000,
  774.                 .max_uV = 1800000,
  775.                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
  776.                 .apply_uV = 1,
  777.                 .always_on = 1,
  778.             },
  779.         },
  780.         [PCF50633_REGULATOR_HCLDO] = {
  781.             .constraints = {
  782.                 .min_uV = 2000000,
  783.                 .max_uV = 3300000,
  784.                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
  785.                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
  786.                         REGULATOR_CHANGE_STATUS,
  787.             },
  788.             .num_consumer_supplies = ARRAY_SIZE(hcldo_consumers),
  789.             .consumer_supplies = hcldo_consumers,
  790.         },
  791.         [PCF50633_REGULATOR_LDO1] = {
  792.             .constraints = {
  793.                 .min_uV = 3300000,
  794.                 .max_uV = 3300000,
  795.                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
  796.                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  797.                 .apply_uV = 1,
  798.             },
  799.         },
  800.         [PCF50633_REGULATOR_LDO2] = {
  801.             .constraints = {
  802.                 .min_uV = 3300000,
  803.                 .max_uV = 3300000,
  804.                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
  805.                 .apply_uV = 1,
  806.             },
  807.         },
  808.         [PCF50633_REGULATOR_LDO3] = {
  809.             .constraints = {
  810.                 .min_uV = 3000000,
  811.                 .max_uV = 3000000,
  812.                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
  813.                 .apply_uV = 1,
  814.             },
  815.         },
  816.         [PCF50633_REGULATOR_LDO4] = {
  817.             .constraints = {
  818.                 .min_uV = 3200000,
  819.                 .max_uV = 3200000,
  820.                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
  821.                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  822.                 .apply_uV = 1,
  823.             },
  824.             .num_consumer_supplies = ARRAY_SIZE(ldo4_consumers),
  825.             .consumer_supplies = ldo4_consumers,
  826.         },
  827.         [PCF50633_REGULATOR_LDO5] = {
  828.             .constraints = {
  829.                 .min_uV = 3000000,
  830.                 .max_uV = 3000000,
  831.                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
  832.                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  833.                 .apply_uV = 1,
  834.             },
  835.             .num_consumer_supplies = ARRAY_SIZE(ldo5_consumers),
  836.             .consumer_supplies = ldo5_consumers,
  837.         },
  838.         [PCF50633_REGULATOR_LDO6] = {
  839.             .constraints = {
  840.                 .min_uV = 3000000,
  841.                 .max_uV = 3000000,
  842.                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
  843.                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  844.             },
  845.             .num_consumer_supplies = ARRAY_SIZE(ldo6_consumers),
  846.             .consumer_supplies = ldo6_consumers,
  847.         },
  848.         [PCF50633_REGULATOR_MEMLDO] = {
  849.             .constraints = {
  850.                 .min_uV = 1800000,
  851.                 .max_uV = 1800000,
  852.                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
  853.             },
  854.         },
  855.  
  856.     },
  857.     .probe_done = gta02_pmu_attach_child_devices,
  858.     .mbc_event_callback = gta02_pmu_event_callback,
  859.     .force_shutdown = gta02_poweroff,
  860. };
  861.  
  862.  
  863. /* NOR Flash. */
  864.  
  865. #define GTA02_FLASH_BASE    0x18000000 /* GCS3 */
  866. #define GTA02_FLASH_SIZE    0x200000 /* 2MBytes */
  867.  
  868. static struct physmap_flash_data gta02_nor_flash_data = {
  869.     .width      = 2,
  870. };
  871.  
  872. static struct resource gta02_nor_flash_resource = {
  873.     .start      = GTA02_FLASH_BASE,
  874.     .end        = GTA02_FLASH_BASE + GTA02_FLASH_SIZE - 1,
  875.     .flags      = IORESOURCE_MEM,
  876. };
  877.  
  878. static struct platform_device gta02_nor_flash = {
  879.     .name       = "physmap-flash",
  880.     .id     = 0,
  881.     .dev        = {
  882.         .platform_data  = &gta02_nor_flash_data,
  883.     },
  884.     .resource   = &gta02_nor_flash_resource,
  885.     .num_resources  = 1,
  886. };
  887.  
  888. struct platform_device s3c24xx_pwm_device = {
  889.     .name       = "s3c24xx_pwm",
  890.     .num_resources  = 0,
  891. };
  892.  
  893. static struct platform_device gta02_dfbmcs320_device = {
  894.     .name = "dfbmcs320",
  895. };
  896.  
  897. static struct i2c_board_info gta02_i2c_devs[] __initdata = {
  898.     {
  899.         I2C_BOARD_INFO("pcf50633", 0x73),
  900.         .irq = GTA02_IRQ_PCF50633,
  901.         .platform_data = &gta02_pcf_pdata,
  902.     },
  903.     {
  904.         I2C_BOARD_INFO("wm8753", 0x1a),
  905.     },
  906. };
  907.  
  908. static struct s3c2410_nand_set __initdata gta02_nand_sets[] = {
  909.     [0] = {
  910.         /*
  911.          * This name is also hard-coded in the boot loaders, so
  912.          * changing it would would require all users to upgrade
  913.          * their boot loaders, some of which are stored in a NOR
  914.          * that is considered to be immutable.
  915.          */
  916.         .name       = "neo1973-nand",
  917.         .nr_chips   = 1,
  918.         .flash_bbt  = 1,
  919.     },
  920. };
  921.  
  922. /*
  923.  * Choose a set of timings derived from S3C@2442B MCP54
  924.  * data sheet (K5D2G13ACM-D075 MCP Memory).
  925.  */
  926.  
  927. static struct s3c2410_platform_nand __initdata gta02_nand_info = {
  928.     .tacls      = 0,
  929.     .twrph0     = 25,
  930.     .twrph1     = 15,
  931.     .nr_sets    = ARRAY_SIZE(gta02_nand_sets),
  932.     .sets       = gta02_nand_sets,
  933.     .software_ecc   = 1,
  934. };
  935.  
  936.  
  937. /* Get PMU to set USB current limit accordingly. */
  938. static struct s3c2410_udc_mach_info gta02_udc_cfg __initdata = {
  939.     .vbus_draw  = gta02_udc_vbus_draw,
  940.     .pullup_pin = GTA02_GPIO_USB_PULLUP,
  941. };
  942.  
  943. /* USB */
  944. static struct s3c2410_hcd_info gta02_usb_info __initdata = {
  945.     .port[0]    = {
  946.         .flags  = S3C_HCDFLG_USED,
  947.     },
  948.     .port[1]    = {
  949.         .flags  = 0,
  950.     },
  951. };
  952.  
  953. /* Touchscreen */
  954. static struct s3c2410_ts_mach_info gta02_ts_info = {
  955.     .delay          = 10000,
  956.     .presc          = 0xff, /* slow as we can go */
  957.     .oversampling_shift = 2,
  958. };
  959.  
  960. /* Buttons */
  961. static struct gpio_keys_button gta02_buttons[] = {
  962.     {
  963.         .gpio = GTA02_GPIO_AUX_KEY,
  964.         .code = KEY_PHONE,
  965.         .desc = "Aux",
  966.         .type = EV_KEY,
  967.         .debounce_interval = 100,
  968.     },
  969.     {
  970.         .gpio = GTA02_GPIO_HOLD_KEY,
  971.         .code = KEY_PAUSE,
  972.         .desc = "Hold",
  973.         .type = EV_KEY,
  974.         .debounce_interval = 100,
  975.     },
  976. };
  977.  
  978. static struct gpio_keys_platform_data gta02_buttons_pdata = {
  979.     .buttons = gta02_buttons,
  980.     .nbuttons = ARRAY_SIZE(gta02_buttons),
  981. };
  982.  
  983. static struct platform_device gta02_buttons_device = {
  984.     .name = "gpio-keys",
  985.     .id = -1,
  986.     .dev = {
  987.         .platform_data = &gta02_buttons_pdata,
  988.     },
  989. };
  990.  
  991. /* LEDs */
  992. static struct gpio_led gta02_gpio_leds[] = {
  993.     {
  994.         .name   = "gta02:red:aux",
  995.         .gpio   = GTA02_GPIO_AUX_LED,
  996.     },
  997. };
  998.  
  999. static struct gpio_led_platform_data gta02_gpio_leds_pdata = {
  1000.     .leds = gta02_gpio_leds,
  1001.     .num_leds = ARRAY_SIZE(gta02_gpio_leds),
  1002. };
  1003.  
  1004. static struct platform_device gta02_leds_device = {
  1005.     .name = "leds-gpio",
  1006.     .id   = -1,
  1007.     .dev = {
  1008.         .platform_data = &gta02_gpio_leds_pdata,
  1009.     },
  1010. };
  1011.  
  1012. static inline int gta02_pwm_to_gpio(int pwm_id)
  1013. {
  1014.     return S3C2410_GPB(pwm_id);
  1015. }
  1016.  
  1017. static int gta02_pwm_led_init(struct device *dev, struct led_pwm *led)
  1018. {
  1019.     int ret;
  1020.     int gpio = gta02_pwm_to_gpio(led->pwm_id);
  1021.  
  1022.     ret = gpio_request(gpio, dev_name(dev));
  1023.     if (ret)
  1024.         return ret;
  1025.  
  1026.     gpio_direction_output(gpio, 0);
  1027.  
  1028.     return 0;
  1029. }
  1030.  
  1031. static enum led_brightness gta02_pwm_led_notify(struct device *dev,
  1032.     struct led_pwm *led, enum led_brightness brightness)
  1033. {
  1034.     int gpio = gta02_pwm_to_gpio(led->pwm_id);
  1035.  
  1036.     if (brightness == led->max_brightness || brightness == 0) {
  1037.         s3c2410_gpio_cfgpin(gpio, S3C2410_GPIO_OUTPUT);
  1038.         gpio_set_value(gpio, brightness ? 1 : 0);
  1039.  
  1040.         brightness = 0;
  1041.     } else {
  1042.         s3c2410_gpio_cfgpin(gpio, S3C2410_GPIO_SFN2);
  1043.     }
  1044.  
  1045.     return brightness;
  1046. }
  1047.  
  1048. static void gta02_pwm_led_exit(struct device *dev, struct led_pwm *led)
  1049. {
  1050.     gpio_free(gta02_pwm_to_gpio(led->pwm_id));
  1051. }
  1052.  
  1053. static struct led_pwm gta02_pwm_leds[] = {
  1054.     {
  1055.         .name = "gta02:orange:power",
  1056.         .max_brightness = 0xff,
  1057.         .pwm_period_ns = 1000000,
  1058.         .pwm_id = 0,
  1059.     },
  1060.     {
  1061.         .name = "gta02:blue:power",
  1062.         .max_brightness = 0xff,
  1063.         .pwm_period_ns = 1000000,
  1064.         .pwm_id = 1,
  1065.     },
  1066.     {
  1067.         .name = "gta02::vibrator",
  1068.         .max_brightness = 0x3f,
  1069.         .pwm_period_ns = 60000000,
  1070.         .pwm_id = 3,
  1071.     }
  1072. };
  1073.  
  1074. static struct led_pwm_platform_data gta02_pwm_leds_pdata = {
  1075.     .num_leds = ARRAY_SIZE(gta02_pwm_leds),
  1076.     .leds = gta02_pwm_leds,
  1077.  
  1078.     .init = gta02_pwm_led_init,
  1079.     .notify = gta02_pwm_led_notify,
  1080.     .exit = gta02_pwm_led_exit,
  1081. };
  1082.  
  1083. static struct platform_device gta02_pwm_leds_device = {
  1084.     .name   = "leds_pwm",
  1085.     .id = -1,
  1086.     .dev = {
  1087.         .platform_data = &gta02_pwm_leds_pdata,
  1088.     }
  1089. };
  1090.  
  1091. /* BQ27000 Battery */
  1092.  
  1093. static struct bq27000_platform_data bq27000_pdata = {
  1094.     .read = hdq_read,
  1095.     .name = "battery",
  1096. };
  1097.  
  1098. static struct platform_device bq27000_battery_device = {
  1099.     .name = "bq27000-battery",
  1100.     .dev = {
  1101.         .platform_data = &bq27000_pdata,
  1102.     },
  1103. };
  1104.  
  1105. /* Platform battery */
  1106.  
  1107. /* Capacity of a typical BL-5C dumb battery */
  1108. #define GTA02_BAT_CHARGE_FULL   850000
  1109.  
  1110. static int gta02_bat_voltscale(int volt)
  1111. {
  1112.     /* This table is suggested by SpeedEvil based on analysis of
  1113.      * experimental data */
  1114.     static const int lut[][2] = {
  1115.         { 4120, 100 },
  1116.         { 3900, 60 },
  1117.         { 3740, 25 },
  1118.         { 3600, 5 },
  1119.         { 3000, 0 } };
  1120.     int i, res = 0;
  1121.  
  1122.     if (volt > lut[0][0])
  1123.         res = lut[0][1];
  1124.     else
  1125.         for (i = 0; lut[i][1]; i++) {
  1126.             if (volt <= lut[i][0] && volt >= lut[i+1][0]) {
  1127.                 res = lut[i][1] - (lut[i][0]-volt)*
  1128.                     (lut[i][1]-lut[i+1][1])/
  1129.                     (lut[i][0]-lut[i+1][0]);
  1130.                 break;
  1131.             }
  1132.         }
  1133.     return res;
  1134. }
  1135.  
  1136. static int gta02_bat_get_voltage(void)
  1137. {
  1138.     struct pcf50633 *pcf = gta02_pcf;
  1139.     u16 adc, mv = 0;
  1140.     adc = pcf50633_adc_sync_read(pcf,
  1141.         PCF50633_ADCC1_MUX_BATSNS_RES,
  1142.         PCF50633_ADCC1_AVERAGE_16);
  1143.     /* The formula from DS is for divide-by-two mode, current driver uses
  1144.     divide-by-three */
  1145.     mv = (adc * 6000) / 1023;
  1146.     return mv * 1000;
  1147. }
  1148.  
  1149. static int gta02_bat_get_present(void)
  1150. {
  1151.     /* There is no reliable way to tell if it is present or not */
  1152.     return 1;
  1153. }
  1154.  
  1155. static int gta02_bat_get_status(void)
  1156. {
  1157. #ifdef CONFIG_CHARGER_PCF50633
  1158.     if (gta02_get_charger_active_status())
  1159.         return POWER_SUPPLY_STATUS_CHARGING;
  1160.     else
  1161.         return POWER_SUPPLY_STATUS_DISCHARGING;
  1162. #else
  1163.     return POWER_SUPPLY_STATUS_UNKNOWN;
  1164. #endif
  1165. }
  1166.  
  1167. static int gta02_bat_get_capacity(void)
  1168. {
  1169.     return gta02_bat_voltscale(gta02_bat_get_voltage()/1000);
  1170. }
  1171.  
  1172. static int gta02_bat_get_charge_full(void)
  1173. {
  1174.     return GTA02_BAT_CHARGE_FULL;
  1175. }
  1176.  
  1177. static int gta02_bat_get_charge_now(void)
  1178. {
  1179.     return gta02_bat_get_capacity() * gta02_bat_get_charge_full() / 100;
  1180. }
  1181.  
  1182. static enum power_supply_property gta02_platform_bat_properties[] = {
  1183.     POWER_SUPPLY_PROP_PRESENT,
  1184.     POWER_SUPPLY_PROP_STATUS,
  1185.     POWER_SUPPLY_PROP_VOLTAGE_NOW,
  1186.     POWER_SUPPLY_PROP_CAPACITY,
  1187.     POWER_SUPPLY_PROP_CHARGE_FULL,
  1188.     POWER_SUPPLY_PROP_CHARGE_NOW,
  1189. };
  1190.  
  1191. int (*gta02_platform_bat_get_property[])(void) = {
  1192.     gta02_bat_get_present,
  1193.     gta02_bat_get_status,
  1194.     gta02_bat_get_voltage,
  1195.     gta02_bat_get_capacity,
  1196.     gta02_bat_get_charge_full,
  1197.     gta02_bat_get_charge_now,
  1198. };
  1199.  
  1200. static struct platform_bat_platform_data gta02_platform_bat_pdata = {
  1201.     .name = "battery",
  1202.     .properties = gta02_platform_bat_properties,
  1203.     .num_properties = ARRAY_SIZE(gta02_platform_bat_properties),
  1204.     .get_property = gta02_platform_bat_get_property,
  1205.     .is_present = gta02_bat_get_present,
  1206. };
  1207.  
  1208. struct platform_device gta02_platform_bat = {
  1209.     .name = "platform_battery",
  1210.     .id = -1,
  1211.     .dev = {
  1212.         .platform_data = &gta02_platform_bat_pdata,
  1213.     }
  1214. };
  1215.  
  1216. /* HDQ */
  1217.  
  1218. static void gta02_hdq_gpio_direction_out(void)
  1219. {
  1220.     s3c2410_gpio_cfgpin(GTA02v5_GPIO_HDQ, S3C2410_GPIO_OUTPUT);
  1221. }
  1222.  
  1223. static void gta02_hdq_gpio_direction_in(void)
  1224. {
  1225.     s3c2410_gpio_cfgpin(GTA02v5_GPIO_HDQ, S3C2410_GPIO_INPUT);
  1226. }
  1227.  
  1228. static void gta02_hdq_gpio_set_value(int val)
  1229. {
  1230.     s3c2410_gpio_setpin(GTA02v5_GPIO_HDQ, val);
  1231. }
  1232.  
  1233. static int gta02_hdq_gpio_get_value(void)
  1234. {
  1235.     return s3c2410_gpio_getpin(GTA02v5_GPIO_HDQ);
  1236. }
  1237.  
  1238. struct hdq_platform_data gta02_hdq_platform_data = {
  1239.     .gpio_dir_out = gta02_hdq_gpio_direction_out,
  1240.     .gpio_dir_in = gta02_hdq_gpio_direction_in,
  1241.     .gpio_set = gta02_hdq_gpio_set_value,
  1242.     .gpio_get = gta02_hdq_gpio_get_value,
  1243.  
  1244.     .enable_fiq = gta02_fiq_enable,
  1245.     .disable_fiq = gta02_fiq_disable,
  1246.     .kick_fiq = gta02_fiq_kick,
  1247. };
  1248.  
  1249. struct platform_device gta02_hdq_device = {
  1250.     .name       = "hdq",
  1251.     .id     = -1,
  1252.     .dev        = {
  1253.         .platform_data = &gta02_hdq_platform_data,
  1254.         .parent = &s3c_device_timer[2].dev,
  1255.     },
  1256. };
  1257.  
  1258. static void __init gta02_map_io(void)
  1259. {
  1260.     s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
  1261.     s3c24xx_init_clocks(12000000);
  1262.     s3c24xx_init_uarts(gta02_uartcfgs, ARRAY_SIZE(gta02_uartcfgs));
  1263. }
  1264.  
  1265.  
  1266. /* These are the guys that don't need to be children of PMU. */
  1267.  
  1268. static struct platform_device *gta02_devices[] __initdata = {
  1269.     &s3c_device_ohci,
  1270.     &s3c_device_wdt,
  1271.     &s3c_device_sdi,
  1272.     &s3c_device_usbgadget,
  1273.     &s3c_device_nand,
  1274.     &gta02_nor_flash,
  1275.     &s3c_device_timer[0],
  1276.     &s3c_device_timer[1],
  1277.     &s3c_device_timer[2],
  1278.     &s3c_device_timer[3],
  1279.     &s3c_device_iis,
  1280.     &samsung_asoc_dma,
  1281.     &s3c_device_i2c0,
  1282.     &gta02_dfbmcs320_device,
  1283.     &gta02_buttons_device,
  1284.     &gta02_leds_device,
  1285.     &gta02_pwm_leds_device,
  1286.     &s3c_device_adc,
  1287.     &s3c_device_ts,
  1288.     &gta02_pm_bt_dev,
  1289.     &gta02_pm_gps_dev,
  1290.     &gta02_pm_wlan_dev,
  1291.     &gta02_glamo_dev,
  1292. };
  1293.  
  1294. /* These guys DO need to be children of PMU. */
  1295.  
  1296. static struct platform_device *gta02_devices_pmu_children[] = {
  1297.     &gta02_hdq_device,
  1298.     &gta02_platform_bat,
  1299.     &gta02_resume_reason_device,
  1300.     &s3c_device_spi_acc1,
  1301.     &s3c_device_spi_acc2,
  1302. };
  1303.  
  1304.  
  1305. /*
  1306.  * This is called when pc50633 is probed, quite late in the day since it is an
  1307.  * I2C bus device.  Here we can define platform devices with the advantage that
  1308.  * we can mark the pcf50633 as the parent.  This makes them get suspended and
  1309.  * resumed with their parent the pcf50633 still around.  All devices whose
  1310.  * operation depends on something from pcf50633 must have this relationship
  1311.  * made explicit like this, or suspend and resume will become an unreliable
  1312.  * hellworld.
  1313.  */
  1314.  
  1315. static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf)
  1316. {
  1317.     int n;
  1318.  
  1319.     /* Grab a copy of the now probed PMU pointer. */
  1320.     gta02_pcf = pcf;
  1321.  
  1322.     for (n = 0; n < ARRAY_SIZE(gta02_devices_pmu_children); n++)
  1323.         gta02_devices_pmu_children[n]->dev.parent = pcf->dev;
  1324.  
  1325.     platform_add_devices(gta02_devices_pmu_children,
  1326.                  ARRAY_SIZE(gta02_devices_pmu_children));
  1327. }
  1328.  
  1329. struct gta02_device_children {
  1330.     const char *dev_name;
  1331.     size_t num_children;
  1332.     struct platform_device **children;
  1333.     void (*probed_callback)(struct device *dev);
  1334. };
  1335.  
  1336. static struct platform_device *gta02_glamo_gpio_children[] = {
  1337.     &spigpio_device,
  1338. };
  1339.  
  1340. static struct platform_device *gta02_pcf50633_gpio_children[] = {
  1341.     &gta02_gsm_supply_device,
  1342.     &gta02_usbhost_supply_device,
  1343. };
  1344.  
  1345. static struct platform_device *gta02_gsm_supply_children[] = {
  1346.     &gta02_pm_gsm_dev,
  1347. };
  1348.  
  1349. static struct platform_device* gta02_usbhost_supply_children[] = {
  1350.     &gta02_pm_usbhost_dev,
  1351. };
  1352.  
  1353. static struct platform_device *gta02_hdq_children[] = {
  1354.     &bq27000_battery_device,
  1355. };
  1356.  
  1357.  
  1358. static struct gta02_device_children gta02_device_children[] = {
  1359.     {
  1360.         .dev_name = "glamo-gpio.0",
  1361.         .num_children = ARRAY_SIZE(gta02_glamo_gpio_children),
  1362.         .children = gta02_glamo_gpio_children,
  1363.     },
  1364.     {
  1365.         .dev_name = "pcf50633-gpio",
  1366.         .num_children = 1,
  1367.         .children = gta02_pcf50633_gpio_children,
  1368.     },
  1369.     {
  1370.         .dev_name = "reg-fixed-voltage.1",
  1371.         .num_children = 1,
  1372.         .children = gta02_gsm_supply_children,
  1373.     },
  1374.     {
  1375.         .dev_name = "reg-fixed-voltage.2",
  1376.         .num_children = 1,
  1377.         .children = gta02_usbhost_supply_children,
  1378.     },
  1379.     {
  1380.         .dev_name = "spi2.0",
  1381.         .probed_callback = gta02_jbt6k74_probe_completed,
  1382.     },
  1383.     {
  1384.         .dev_name = "hdq",
  1385.         .num_children = 1,
  1386.         .children = gta02_hdq_children,
  1387.     },
  1388. };
  1389.  
  1390. static int gta02_add_child_devices(struct device *parent,
  1391.         struct platform_device **children, size_t num_children)
  1392. {
  1393.     size_t i;
  1394.  
  1395.     for (i = 0; i < num_children; ++i)
  1396.         children[i]->dev.parent = parent;
  1397.  
  1398.     return platform_add_devices(children, num_children);
  1399. }
  1400.  
  1401. static int gta02_device_registered(struct notifier_block *block,
  1402.         unsigned long action, void *data)
  1403. {
  1404.     struct device *dev = data;
  1405.     const char *devname = dev_name(dev);
  1406.     size_t i;
  1407.  
  1408.     if (action != BUS_NOTIFY_BOUND_DRIVER)
  1409.         return 0;
  1410.  
  1411.     for (i = 0; i < ARRAY_SIZE(gta02_device_children); ++i) {
  1412.         if (strcmp(devname, gta02_device_children[i].dev_name) == 0) {
  1413.             gta02_add_child_devices(dev, gta02_device_children[i].children,
  1414.             gta02_device_children[i].num_children);
  1415.  
  1416.             if (gta02_device_children[i].probed_callback)
  1417.                 gta02_device_children[i].probed_callback(dev);
  1418.             break;
  1419.         }
  1420.     }
  1421.  
  1422.     return 0;
  1423. }
  1424.  
  1425. static struct notifier_block gta02_device_register_notifier = {
  1426.     .notifier_call = gta02_device_registered,
  1427.     .priority = INT_MAX,
  1428. };
  1429.  
  1430.  
  1431. /*
  1432.  * Allow the bootloader to enable hw ecc
  1433.  * hardware_ecc=1|0
  1434.  */
  1435. static int __init hardware_ecc_setup(char *str)
  1436. {
  1437.     if (str && str[0] == '1')
  1438.         gta02_nand_info.software_ecc = 0;
  1439.     return 1;
  1440. }
  1441. __setup("hardware_ecc=", hardware_ecc_setup);
  1442.  
  1443. static void __init gta02_machine_init(void)
  1444. {
  1445.     /* Set the panic callback to turn AUX LED on or off. */
  1446.     panic_blink = gta02_panic_blink;
  1447.  
  1448.     bus_register_notifier(&platform_bus_type, &gta02_device_register_notifier);
  1449.     bus_register_notifier(&spi_bus_type, &gta02_device_register_notifier);
  1450.  
  1451.     s3c_pm_init();
  1452.  
  1453.     /* we need push-pull interrupt from motion sensors */
  1454.     lis302_pdata_top.open_drain = 0;
  1455.     lis302_pdata_bottom.open_drain = 0;
  1456.  
  1457. #ifdef CONFIG_CHARGER_PCF50633
  1458.     INIT_DELAYED_WORK(&gta02_charger_work, gta02_charger_worker);
  1459. #endif
  1460.  
  1461.     s3c24xx_udc_set_platdata(&gta02_udc_cfg);
  1462.     s3c24xx_ts_set_platdata(&gta02_ts_info);
  1463.     s3c_ohci_set_platdata(&gta02_usb_info);
  1464.     s3c_nand_set_platdata(&gta02_nand_info);
  1465.     s3c_i2c0_set_platdata(NULL);
  1466.     spi_register_board_info(gta02_spi_board_info,
  1467.                 ARRAY_SIZE(gta02_spi_board_info));
  1468.  
  1469.     i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
  1470.  
  1471.     platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
  1472.  
  1473.     pm_power_off = gta02_poweroff;
  1474.  
  1475.     regulator_has_full_constraints();
  1476. }
  1477.  
  1478.  
  1479. MACHINE_START(NEO1973_GTA02, "GTA02")
  1480.     /* Maintainer: Nelson Castillo <arhuaco@freaks-unidos.net> */
  1481.     .boot_params    = S3C2410_SDRAM_PA + 0x100,
  1482.     .map_io     = gta02_map_io,
  1483.     .init_irq   = s3c24xx_init_irq,
  1484.     .init_machine   = gta02_machine_init,
  1485.     .timer      = &s3c24xx_timer,
  1486. MACHINE_END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement