1/* 2 * Freescale STMP378X development board support 3 * 4 * Embedded Alley Solutions, Inc <source@embeddedalley.com> 5 * 6 * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved. 7 * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved. 8 */ 9 10/* 11 * The code contained herein is licensed under the GNU General Public 12 * License. You may obtain a copy of the GNU General Public License 13 * Version 2 or later at the following locations: 14 * 15 * http://www.opensource.org/licenses/gpl-license.html 16 * http://www.gnu.org/copyleft/gpl.html 17 */ 18#include <linux/kernel.h> 19#include <linux/init.h> 20#include <linux/io.h> 21#include <linux/platform_device.h> 22#include <linux/delay.h> 23#include <linux/clk.h> 24#include <linux/err.h> 25#include <linux/spi/spi.h> 26 27#include <asm/setup.h> 28#include <asm/mach-types.h> 29#include <asm/mach/arch.h> 30 31#include <mach/pins.h> 32#include <mach/pinmux.h> 33#include <mach/platform.h> 34#include <mach/stmp3xxx.h> 35#include <mach/mmc.h> 36#include <mach/gpmi.h> 37 38#include "stmp378x.h" 39 40static struct platform_device *devices[] = { 41 &stmp3xxx_dbguart, 42 &stmp3xxx_appuart, 43 &stmp3xxx_watchdog, 44 &stmp3xxx_touchscreen, 45 &stmp3xxx_rtc, 46 &stmp3xxx_keyboard, 47 &stmp3xxx_framebuffer, 48 &stmp3xxx_backlight, 49 &stmp3xxx_rotdec, 50 &stmp3xxx_persistent, 51 &stmp3xxx_dcp_bootstream, 52 &stmp3xxx_dcp, 53 &stmp3xxx_battery, 54 &stmp378x_pxp, 55 &stmp378x_i2c, 56}; 57 58static struct pin_desc i2c_pins_desc[] = { 59 { PINID_I2C_SCL, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 60 { PINID_I2C_SDA, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 61}; 62 63static struct pin_group i2c_pins = { 64 .pins = i2c_pins_desc, 65 .nr_pins = ARRAY_SIZE(i2c_pins_desc), 66}; 67 68static struct pin_desc dbguart_pins_0[] = { 69 { PINID_PWM0, PIN_FUN3, }, 70 { PINID_PWM1, PIN_FUN3, }, 71}; 72 73static struct pin_group dbguart_pins[] = { 74 [0] = { 75 .pins = dbguart_pins_0, 76 .nr_pins = ARRAY_SIZE(dbguart_pins_0), 77 }, 78}; 79 80static int dbguart_pins_control(int id, int request) 81{ 82 int r = 0; 83 84 if (request) 85 r = stmp3xxx_request_pin_group(&dbguart_pins[id], "debug uart"); 86 else 87 stmp3xxx_release_pin_group(&dbguart_pins[id], "debug uart"); 88 return r; 89} 90 91static struct pin_desc appuart_pins_0[] = { 92 { PINID_AUART1_CTS, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, }, 93 { PINID_AUART1_RTS, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, }, 94 { PINID_AUART1_RX, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, }, 95 { PINID_AUART1_TX, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, }, 96}; 97 98static struct pin_desc appuart_pins_1[] = { 99}; 100 101static struct pin_desc mmc_pins_desc[] = { 102 { PINID_SSP1_DATA0, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 }, 103 { PINID_SSP1_DATA1, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 }, 104 { PINID_SSP1_DATA2, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 }, 105 { PINID_SSP1_DATA3, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 }, 106 { PINID_SSP1_CMD, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 }, 107 { PINID_SSP1_SCK, PIN_FUN1, PIN_8MA, PIN_3_3V, 0 }, 108 { PINID_SSP1_DETECT, PIN_FUN1, PIN_8MA, PIN_3_3V, 0 }, 109}; 110 111static struct pin_group mmc_pins = { 112 .pins = mmc_pins_desc, 113 .nr_pins = ARRAY_SIZE(mmc_pins_desc), 114}; 115 116static int stmp3xxxmmc_get_wp(void) 117{ 118 return gpio_get_value(PINID_PWM4); 119} 120 121static int stmp3xxxmmc_hw_init_ssp1(void) 122{ 123 int ret; 124 125 ret = stmp3xxx_request_pin_group(&mmc_pins, "mmc"); 126 if (ret) 127 goto out; 128 129 /* Configure write protect GPIO pin */ 130 ret = gpio_request(PINID_PWM4, "mmc wp"); 131 if (ret) 132 goto out_wp; 133 134 gpio_direction_input(PINID_PWM4); 135 136 /* Configure POWER pin as gpio to drive power to MMC slot */ 137 ret = gpio_request(PINID_PWM3, "mmc power"); 138 if (ret) 139 goto out_power; 140 141 gpio_direction_output(PINID_PWM3, 0); 142 mdelay(100); 143 144 return 0; 145 146out_power: 147 gpio_free(PINID_PWM4); 148out_wp: 149 stmp3xxx_release_pin_group(&mmc_pins, "mmc"); 150out: 151 return ret; 152} 153 154static void stmp3xxxmmc_hw_release_ssp1(void) 155{ 156 gpio_free(PINID_PWM3); 157 gpio_free(PINID_PWM4); 158 stmp3xxx_release_pin_group(&mmc_pins, "mmc"); 159} 160 161static void stmp3xxxmmc_cmd_pullup_ssp1(int enable) 162{ 163 stmp3xxx_pin_pullup(PINID_SSP1_CMD, enable, "mmc"); 164} 165 166static unsigned long 167stmp3xxxmmc_setclock_ssp1(void __iomem *base, unsigned long hz) 168{ 169 struct clk *ssp, *parent; 170 char *p; 171 long r; 172 173 ssp = clk_get(NULL, "ssp"); 174 175 /* using SSP1, no timeout, clock rate 1 */ 176 writel(BF(2, SSP_TIMING_CLOCK_DIVIDE) | 177 BF(0xFFFF, SSP_TIMING_TIMEOUT), 178 base + HW_SSP_TIMING); 179 180 p = (hz > 1000000) ? "io" : "osc_24M"; 181 parent = clk_get(NULL, p); 182 clk_set_parent(ssp, parent); 183 r = clk_set_rate(ssp, 2 * hz / 1000); 184 clk_put(parent); 185 clk_put(ssp); 186 187 return hz; 188} 189 190static struct stmp3xxxmmc_platform_data mmc_data = { 191 .hw_init = stmp3xxxmmc_hw_init_ssp1, 192 .hw_release = stmp3xxxmmc_hw_release_ssp1, 193 .get_wp = stmp3xxxmmc_get_wp, 194 .cmd_pullup = stmp3xxxmmc_cmd_pullup_ssp1, 195 .setclock = stmp3xxxmmc_setclock_ssp1, 196}; 197 198 199static struct pin_group appuart_pins[] = { 200 [0] = { 201 .pins = appuart_pins_0, 202 .nr_pins = ARRAY_SIZE(appuart_pins_0), 203 }, 204 [1] = { 205 .pins = appuart_pins_1, 206 .nr_pins = ARRAY_SIZE(appuart_pins_1), 207 }, 208}; 209 210static struct pin_desc ssp1_pins_desc[] = { 211 { PINID_SSP1_SCK, PIN_FUN1, PIN_8MA, PIN_3_3V, 0, }, 212 { PINID_SSP1_CMD, PIN_FUN1, PIN_4MA, PIN_3_3V, 0, }, 213 { PINID_SSP1_DATA0, PIN_FUN1, PIN_4MA, PIN_3_3V, 0, }, 214 { PINID_SSP1_DATA3, PIN_FUN1, PIN_4MA, PIN_3_3V, 0, }, 215}; 216 217static struct pin_desc ssp2_pins_desc[] = { 218 { PINID_GPMI_WRN, PIN_FUN3, PIN_8MA, PIN_3_3V, 0, }, 219 { PINID_GPMI_RDY1, PIN_FUN3, PIN_4MA, PIN_3_3V, 0, }, 220 { PINID_GPMI_D00, PIN_FUN3, PIN_4MA, PIN_3_3V, 0, }, 221 { PINID_GPMI_D03, PIN_FUN3, PIN_4MA, PIN_3_3V, 0, }, 222}; 223 224static struct pin_group ssp1_pins = { 225 .pins = ssp1_pins_desc, 226 .nr_pins = ARRAY_SIZE(ssp1_pins_desc), 227}; 228 229static struct pin_group ssp2_pins = { 230 .pins = ssp1_pins_desc, 231 .nr_pins = ARRAY_SIZE(ssp2_pins_desc), 232}; 233 234static struct pin_desc gpmi_pins_desc[] = { 235 { PINID_GPMI_CE0N, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 236 { PINID_GPMI_CE1N, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 237 { PINID_GMPI_CE2N, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 238 { PINID_GPMI_CLE, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 239 { PINID_GPMI_ALE, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 240 { PINID_GPMI_WPN, PIN_FUN1, PIN_12MA, PIN_3_3V, 0 }, 241 { PINID_GPMI_RDY1, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 242 { PINID_GPMI_D00, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 243 { PINID_GPMI_D01, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 244 { PINID_GPMI_D02, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 245 { PINID_GPMI_D03, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 246 { PINID_GPMI_D04, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 247 { PINID_GPMI_D05, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 248 { PINID_GPMI_D06, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 249 { PINID_GPMI_D07, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 250 { PINID_GPMI_RDY0, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 251 { PINID_GPMI_RDY2, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 252 { PINID_GPMI_RDY3, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 }, 253 { PINID_GPMI_WRN, PIN_FUN1, PIN_12MA, PIN_3_3V, 0 }, 254 { PINID_GPMI_RDN, PIN_FUN1, PIN_12MA, PIN_3_3V, 0 }, 255}; 256 257static struct pin_group gpmi_pins = { 258 .pins = gpmi_pins_desc, 259 .nr_pins = ARRAY_SIZE(gpmi_pins_desc), 260}; 261 262static struct mtd_partition gpmi_partitions[] = { 263 [0] = { 264 .name = "boot", 265 .size = 10 * SZ_1M, 266 .offset = 0, 267 }, 268 [1] = { 269 .name = "data", 270 .size = MTDPART_SIZ_FULL, 271 .offset = MTDPART_OFS_APPEND, 272 }, 273}; 274 275static struct gpmi_platform_data gpmi_data = { 276 .pins = &gpmi_pins, 277 .nr_parts = ARRAY_SIZE(gpmi_partitions), 278 .parts = gpmi_partitions, 279 .part_types = { "cmdline", NULL }, 280}; 281 282static struct spi_board_info spi_board_info[] __initdata = { 283#if defined(CONFIG_ENC28J60) || defined(CONFIG_ENC28J60_MODULE) 284 { 285 .modalias = "enc28j60", 286 .max_speed_hz = 6 * 1000 * 1000, 287 .bus_num = 1, 288 .chip_select = 0, 289 .platform_data = NULL, 290 }, 291#endif 292}; 293 294static void __init stmp378x_devb_init(void) 295{ 296 stmp3xxx_pinmux_init(NR_REAL_IRQS); 297 298 /* init stmp3xxx platform */ 299 stmp3xxx_init(); 300 301 stmp3xxx_dbguart.dev.platform_data = dbguart_pins_control; 302 stmp3xxx_appuart.dev.platform_data = appuart_pins; 303 stmp3xxx_mmc.dev.platform_data = &mmc_data; 304 stmp3xxx_gpmi.dev.platform_data = &gpmi_data; 305 stmp3xxx_spi1.dev.platform_data = &ssp1_pins; 306 stmp3xxx_spi2.dev.platform_data = &ssp2_pins; 307 stmp378x_i2c.dev.platform_data = &i2c_pins; 308 309 /* register spi devices */ 310 spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info)); 311 312 /* add board's devices */ 313 platform_add_devices(devices, ARRAY_SIZE(devices)); 314 315 /* add devices selected by command line ssp1= and ssp2= options */ 316 stmp3xxx_ssp1_device_register(); 317 stmp3xxx_ssp2_device_register(); 318} 319 320MACHINE_START(STMP378X, "STMP378X") 321 .phys_io = 0x80000000, 322 .io_pg_offst = ((0xf0000000) >> 18) & 0xfffc, 323 .boot_params = 0x40000100, 324 .map_io = stmp378x_map_io, 325 .init_irq = stmp378x_init_irq, 326 .timer = &stmp3xxx_timer, 327 .init_machine = stmp378x_devb_init, 328MACHINE_END 329