viper.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  1. /*
  2. * linux/arch/arm/mach-pxa/viper.c
  3. *
  4. * Support for the Arcom VIPER SBC.
  5. *
  6. * Author: Ian Campbell
  7. * Created: Feb 03, 2003
  8. * Copyright: Arcom Control Systems
  9. *
  10. * Maintained by Marc Zyngier <maz@misterjones.org>
  11. * <marc.zyngier@altran.com>
  12. *
  13. * Based on lubbock.c:
  14. * Author: Nicolas Pitre
  15. * Created: Jun 15, 2001
  16. * Copyright: MontaVista Software Inc.
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License version 2 as
  20. * published by the Free Software Foundation.
  21. */
  22. #include <linux/types.h>
  23. #include <linux/memory.h>
  24. #include <linux/cpu.h>
  25. #include <linux/cpufreq.h>
  26. #include <linux/delay.h>
  27. #include <linux/fs.h>
  28. #include <linux/init.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/major.h>
  31. #include <linux/module.h>
  32. #include <linux/pm.h>
  33. #include <linux/sched.h>
  34. #include <linux/gpio.h>
  35. #include <linux/i2c-gpio.h>
  36. #include <linux/serial_8250.h>
  37. #include <linux/smc91x.h>
  38. #include <linux/pwm_backlight.h>
  39. #include <linux/usb/isp116x.h>
  40. #include <linux/mtd/mtd.h>
  41. #include <linux/mtd/partitions.h>
  42. #include <linux/mtd/physmap.h>
  43. #include <mach/pxa-regs.h>
  44. #include <mach/pxa2xx-regs.h>
  45. #include <mach/bitfield.h>
  46. #include <mach/audio.h>
  47. #include <mach/pxafb.h>
  48. #include <mach/mfp-pxa25x.h>
  49. #include <mach/i2c.h>
  50. #include <mach/viper.h>
  51. #include <asm/setup.h>
  52. #include <asm/mach-types.h>
  53. #include <asm/irq.h>
  54. #include <asm/sizes.h>
  55. #include <asm/mach/arch.h>
  56. #include <asm/mach/map.h>
  57. #include <asm/mach/irq.h>
  58. #include "generic.h"
  59. #include "devices.h"
  60. static unsigned int icr;
  61. static void viper_icr_set_bit(unsigned int bit)
  62. {
  63. icr |= bit;
  64. VIPER_ICR = icr;
  65. }
  66. static void viper_icr_clear_bit(unsigned int bit)
  67. {
  68. icr &= ~bit;
  69. VIPER_ICR = icr;
  70. }
  71. /* This function is used from the pcmcia module to reset the CF */
  72. void viper_cf_rst(int state)
  73. {
  74. if (state)
  75. viper_icr_set_bit(VIPER_ICR_CF_RST);
  76. else
  77. viper_icr_clear_bit(VIPER_ICR_CF_RST);
  78. }
  79. EXPORT_SYMBOL(viper_cf_rst);
  80. /*
  81. * The CPLD version register was not present on VIPER boards prior to
  82. * v2i1. On v1 boards where the version register is not present we
  83. * will just read back the previous value from the databus.
  84. *
  85. * Therefore we do two reads. The first time we write 0 to the
  86. * (read-only) register before reading and the second time we write
  87. * 0xff first. If the two reads do not match or they read back as 0xff
  88. * or 0x00 then we have version 1 hardware.
  89. */
  90. static u8 viper_hw_version(void)
  91. {
  92. u8 v1, v2;
  93. unsigned long flags;
  94. local_irq_save(flags);
  95. VIPER_VERSION = 0;
  96. v1 = VIPER_VERSION;
  97. VIPER_VERSION = 0xff;
  98. v2 = VIPER_VERSION;
  99. v1 = (v1 != v2 || v1 == 0xff) ? 0 : v1;
  100. local_irq_restore(flags);
  101. return v1;
  102. }
  103. /* CPU sysdev */
  104. static int viper_cpu_suspend(struct sys_device *sysdev, pm_message_t state)
  105. {
  106. viper_icr_set_bit(VIPER_ICR_R_DIS);
  107. return 0;
  108. }
  109. static int viper_cpu_resume(struct sys_device *sysdev)
  110. {
  111. viper_icr_clear_bit(VIPER_ICR_R_DIS);
  112. return 0;
  113. }
  114. static struct sysdev_driver viper_cpu_sysdev_driver = {
  115. .suspend = viper_cpu_suspend,
  116. .resume = viper_cpu_resume,
  117. };
  118. static unsigned int current_voltage_divisor;
  119. /*
  120. * If force is not true then step from existing to new divisor. If
  121. * force is true then jump straight to the new divisor. Stepping is
  122. * used because if the jump in voltage is too large, the VCC can dip
  123. * too low and the regulator cuts out.
  124. *
  125. * force can be used to initialize the divisor to a know state by
  126. * setting the value for the current clock speed, since we are already
  127. * running at that speed we know the voltage should be pretty close so
  128. * the jump won't be too large
  129. */
  130. static void viper_set_core_cpu_voltage(unsigned long khz, int force)
  131. {
  132. int i = 0;
  133. unsigned int divisor = 0;
  134. const char *v;
  135. if (khz < 200000) {
  136. v = "1.0"; divisor = 0xfff;
  137. } else if (khz < 300000) {
  138. v = "1.1"; divisor = 0xde5;
  139. } else {
  140. v = "1.3"; divisor = 0x325;
  141. }
  142. pr_debug("viper: setting CPU core voltage to %sV at %d.%03dMHz\n",
  143. v, (int)khz / 1000, (int)khz % 1000);
  144. #define STEP 0x100
  145. do {
  146. int step;
  147. if (force)
  148. step = divisor;
  149. else if (current_voltage_divisor < divisor - STEP)
  150. step = current_voltage_divisor + STEP;
  151. else if (current_voltage_divisor > divisor + STEP)
  152. step = current_voltage_divisor - STEP;
  153. else
  154. step = divisor;
  155. force = 0;
  156. gpio_set_value(VIPER_PSU_CLK_GPIO, 0);
  157. gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 0);
  158. for (i = 1 << 11 ; i > 0 ; i >>= 1) {
  159. udelay(1);
  160. gpio_set_value(VIPER_PSU_DATA_GPIO, step & i);
  161. udelay(1);
  162. gpio_set_value(VIPER_PSU_CLK_GPIO, 1);
  163. udelay(1);
  164. gpio_set_value(VIPER_PSU_CLK_GPIO, 0);
  165. }
  166. udelay(1);
  167. gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 1);
  168. udelay(1);
  169. gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 0);
  170. current_voltage_divisor = step;
  171. } while (current_voltage_divisor != divisor);
  172. }
  173. /* Interrupt handling */
  174. static unsigned long viper_irq_enabled_mask;
  175. static void viper_ack_irq(unsigned int irq)
  176. {
  177. int viper_irq = irq - PXA_ISA_IRQ(0);
  178. if (viper_irq < 8)
  179. VIPER_LO_IRQ_STATUS = 1 << viper_irq;
  180. else
  181. VIPER_HI_IRQ_STATUS = 1 << (viper_irq - 8);
  182. }
  183. static void viper_mask_irq(unsigned int irq)
  184. {
  185. viper_irq_enabled_mask &= ~(1 << (irq - PXA_ISA_IRQ(0)));
  186. }
  187. static void viper_unmask_irq(unsigned int irq)
  188. {
  189. viper_irq_enabled_mask |= (1 << (irq - PXA_ISA_IRQ(0)));
  190. }
  191. static inline unsigned long viper_irq_pending(void)
  192. {
  193. return (VIPER_HI_IRQ_STATUS << 8 | VIPER_LO_IRQ_STATUS) &
  194. viper_irq_enabled_mask;
  195. }
  196. static void viper_irq_handler(unsigned int irq, struct irq_desc *desc)
  197. {
  198. unsigned long pending;
  199. pending = viper_irq_pending();
  200. do {
  201. if (likely(pending)) {
  202. irq = PXA_ISA_IRQ(0) + __ffs(pending);
  203. generic_handle_irq(irq);
  204. }
  205. pending = viper_irq_pending();
  206. } while (pending);
  207. }
  208. static struct irq_chip viper_irq_chip = {
  209. .name = "ISA",
  210. .ack = viper_ack_irq,
  211. .mask = viper_mask_irq,
  212. .unmask = viper_unmask_irq
  213. };
  214. static void __init viper_init_irq(void)
  215. {
  216. const int isa_irqs[] = { 3, 4, 5, 6, 7, 10, 11, 12, 9, 14, 15 };
  217. int irq;
  218. int isa_irq;
  219. pxa25x_init_irq();
  220. /* setup ISA IRQs */
  221. for (irq = 0; irq < ARRAY_SIZE(isa_irqs); irq++) {
  222. isa_irq = isa_irqs[irq];
  223. set_irq_chip(isa_irq, &viper_irq_chip);
  224. set_irq_handler(isa_irq, handle_edge_irq);
  225. set_irq_flags(isa_irq, IRQF_VALID | IRQF_PROBE);
  226. }
  227. set_irq_chained_handler(gpio_to_irq(VIPER_CPLD_GPIO),
  228. viper_irq_handler);
  229. set_irq_type(gpio_to_irq(VIPER_CPLD_GPIO), IRQ_TYPE_EDGE_BOTH);
  230. #ifndef CONFIG_SERIAL_PXA
  231. /*
  232. * 8250 doesn't support IRQ_TYPE being passed as part
  233. * of the plat_serial8250_port structure...
  234. */
  235. set_irq_type(gpio_to_irq(VIPER_UARTA_GPIO), IRQ_TYPE_EDGE_RISING);
  236. set_irq_type(gpio_to_irq(VIPER_UARTB_GPIO), IRQ_TYPE_EDGE_RISING);
  237. #endif
  238. }
  239. /* Flat Panel */
  240. static struct pxafb_mode_info fb_mode_info[] = {
  241. {
  242. .pixclock = 157500,
  243. .xres = 320,
  244. .yres = 240,
  245. .bpp = 16,
  246. .hsync_len = 63,
  247. .left_margin = 7,
  248. .right_margin = 13,
  249. .vsync_len = 20,
  250. .upper_margin = 0,
  251. .lower_margin = 0,
  252. .sync = 0,
  253. },
  254. };
  255. static struct pxafb_mach_info fb_info = {
  256. .modes = fb_mode_info,
  257. .num_modes = 1,
  258. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  259. };
  260. static int viper_backlight_init(struct device *dev)
  261. {
  262. int ret;
  263. /* GPIO9 and 10 control FB backlight. Initialise to off */
  264. ret = gpio_request(VIPER_BCKLIGHT_EN_GPIO, "Backlight");
  265. if (ret)
  266. goto err_request_bckl;
  267. ret = gpio_request(VIPER_LCD_EN_GPIO, "LCD");
  268. if (ret)
  269. goto err_request_lcd;
  270. ret = gpio_direction_output(VIPER_BCKLIGHT_EN_GPIO, 0);
  271. if (ret)
  272. goto err_dir;
  273. ret = gpio_direction_output(VIPER_LCD_EN_GPIO, 0);
  274. if (ret)
  275. goto err_dir;
  276. return 0;
  277. err_dir:
  278. gpio_free(VIPER_LCD_EN_GPIO);
  279. err_request_lcd:
  280. gpio_free(VIPER_BCKLIGHT_EN_GPIO);
  281. err_request_bckl:
  282. dev_err(dev, "Failed to setup LCD GPIOs\n");
  283. return ret;
  284. }
  285. static int viper_backlight_notify(int brightness)
  286. {
  287. gpio_set_value(VIPER_LCD_EN_GPIO, !!brightness);
  288. gpio_set_value(VIPER_BCKLIGHT_EN_GPIO, !!brightness);
  289. return brightness;
  290. }
  291. static void viper_backlight_exit(struct device *dev)
  292. {
  293. gpio_free(VIPER_LCD_EN_GPIO);
  294. gpio_free(VIPER_BCKLIGHT_EN_GPIO);
  295. }
  296. static struct platform_pwm_backlight_data viper_backlight_data = {
  297. .pwm_id = 0,
  298. .max_brightness = 100,
  299. .dft_brightness = 100,
  300. .pwm_period_ns = 1000000,
  301. .init = viper_backlight_init,
  302. .notify = viper_backlight_notify,
  303. .exit = viper_backlight_exit,
  304. };
  305. static struct platform_device viper_backlight_device = {
  306. .name = "pwm-backlight",
  307. .dev = {
  308. .parent = &pxa25x_device_pwm0.dev,
  309. .platform_data = &viper_backlight_data,
  310. },
  311. };
  312. /* Ethernet */
  313. static struct resource smc91x_resources[] = {
  314. [0] = {
  315. .name = "smc91x-regs",
  316. .start = VIPER_ETH_PHYS + 0x300,
  317. .end = VIPER_ETH_PHYS + 0x30f,
  318. .flags = IORESOURCE_MEM,
  319. },
  320. [1] = {
  321. .start = gpio_to_irq(VIPER_ETH_GPIO),
  322. .end = gpio_to_irq(VIPER_ETH_GPIO),
  323. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  324. },
  325. [2] = {
  326. .name = "smc91x-data32",
  327. .start = VIPER_ETH_DATA_PHYS,
  328. .end = VIPER_ETH_DATA_PHYS + 3,
  329. .flags = IORESOURCE_MEM,
  330. },
  331. };
  332. static struct smc91x_platdata viper_smc91x_info = {
  333. .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
  334. .leda = RPC_LED_100_10,
  335. .ledb = RPC_LED_TX_RX,
  336. };
  337. static struct platform_device smc91x_device = {
  338. .name = "smc91x",
  339. .id = -1,
  340. .num_resources = ARRAY_SIZE(smc91x_resources),
  341. .resource = smc91x_resources,
  342. .dev = {
  343. .platform_data = &viper_smc91x_info,
  344. },
  345. };
  346. /* i2c */
  347. static struct i2c_gpio_platform_data i2c_bus_data = {
  348. .sda_pin = VIPER_RTC_I2C_SDA_GPIO,
  349. .scl_pin = VIPER_RTC_I2C_SCL_GPIO,
  350. .udelay = 10,
  351. .timeout = 100,
  352. };
  353. static struct platform_device i2c_bus_device = {
  354. .name = "i2c-gpio",
  355. .id = 1, /* pxa2xx-i2c is bus 0, so start at 1 */
  356. .dev = {
  357. .platform_data = &i2c_bus_data,
  358. }
  359. };
  360. static struct i2c_board_info __initdata viper_i2c_devices[] = {
  361. {
  362. I2C_BOARD_INFO("ds1338", 0x68),
  363. },
  364. };
  365. /*
  366. * Serial configuration:
  367. * You can either have the standard PXA ports driven by the PXA driver,
  368. * or all the ports (PXA + 16850) driven by the 8250 driver.
  369. * Choose your poison.
  370. */
  371. static struct resource viper_serial_resources[] = {
  372. #ifndef CONFIG_SERIAL_PXA
  373. {
  374. .start = 0x40100000,
  375. .end = 0x4010001f,
  376. .flags = IORESOURCE_MEM,
  377. },
  378. {
  379. .start = 0x40200000,
  380. .end = 0x4020001f,
  381. .flags = IORESOURCE_MEM,
  382. },
  383. {
  384. .start = 0x40700000,
  385. .end = 0x4070001f,
  386. .flags = IORESOURCE_MEM,
  387. },
  388. {
  389. .start = VIPER_UARTA_PHYS,
  390. .end = VIPER_UARTA_PHYS + 0xf,
  391. .flags = IORESOURCE_MEM,
  392. },
  393. {
  394. .start = VIPER_UARTB_PHYS,
  395. .end = VIPER_UARTB_PHYS + 0xf,
  396. .flags = IORESOURCE_MEM,
  397. },
  398. #else
  399. {
  400. 0,
  401. },
  402. #endif
  403. };
  404. static struct plat_serial8250_port serial_platform_data[] = {
  405. #ifndef CONFIG_SERIAL_PXA
  406. /* Internal UARTs */
  407. {
  408. .membase = (void *)&FFUART,
  409. .mapbase = __PREG(FFUART),
  410. .irq = IRQ_FFUART,
  411. .uartclk = 921600 * 16,
  412. .regshift = 2,
  413. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  414. .iotype = UPIO_MEM,
  415. },
  416. {
  417. .membase = (void *)&BTUART,
  418. .mapbase = __PREG(BTUART),
  419. .irq = IRQ_BTUART,
  420. .uartclk = 921600 * 16,
  421. .regshift = 2,
  422. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  423. .iotype = UPIO_MEM,
  424. },
  425. {
  426. .membase = (void *)&STUART,
  427. .mapbase = __PREG(STUART),
  428. .irq = IRQ_STUART,
  429. .uartclk = 921600 * 16,
  430. .regshift = 2,
  431. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  432. .iotype = UPIO_MEM,
  433. },
  434. /* External UARTs */
  435. {
  436. .mapbase = VIPER_UARTA_PHYS,
  437. .irq = gpio_to_irq(VIPER_UARTA_GPIO),
  438. .uartclk = 1843200,
  439. .regshift = 1,
  440. .iotype = UPIO_MEM,
  441. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP |
  442. UPF_SKIP_TEST,
  443. },
  444. {
  445. .mapbase = VIPER_UARTB_PHYS,
  446. .irq = gpio_to_irq(VIPER_UARTB_GPIO),
  447. .uartclk = 1843200,
  448. .regshift = 1,
  449. .iotype = UPIO_MEM,
  450. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP |
  451. UPF_SKIP_TEST,
  452. },
  453. #endif
  454. { },
  455. };
  456. static struct platform_device serial_device = {
  457. .name = "serial8250",
  458. .id = 0,
  459. .dev = {
  460. .platform_data = serial_platform_data,
  461. },
  462. .num_resources = ARRAY_SIZE(viper_serial_resources),
  463. .resource = viper_serial_resources,
  464. };
  465. /* USB */
  466. static void isp116x_delay(struct device *dev, int delay)
  467. {
  468. ndelay(delay);
  469. }
  470. static struct resource isp116x_resources[] = {
  471. [0] = { /* DATA */
  472. .start = VIPER_USB_PHYS + 0,
  473. .end = VIPER_USB_PHYS + 1,
  474. .flags = IORESOURCE_MEM,
  475. },
  476. [1] = { /* ADDR */
  477. .start = VIPER_USB_PHYS + 2,
  478. .end = VIPER_USB_PHYS + 3,
  479. .flags = IORESOURCE_MEM,
  480. },
  481. [2] = {
  482. .start = gpio_to_irq(VIPER_USB_GPIO),
  483. .end = gpio_to_irq(VIPER_USB_GPIO),
  484. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  485. },
  486. };
  487. /* (DataBusWidth16|AnalogOCEnable|DREQOutputPolarity|DownstreamPort15KRSel ) */
  488. static struct isp116x_platform_data isp116x_platform_data = {
  489. /* Enable internal resistors on downstream ports */
  490. .sel15Kres = 1,
  491. /* On-chip overcurrent protection */
  492. .oc_enable = 1,
  493. /* INT output polarity */
  494. .int_act_high = 1,
  495. /* INT edge or level triggered */
  496. .int_edge_triggered = 0,
  497. /* WAKEUP pin connected - NOT SUPPORTED */
  498. /* .remote_wakeup_connected = 0, */
  499. /* Wakeup by devices on usb bus enabled */
  500. .remote_wakeup_enable = 0,
  501. .delay = isp116x_delay,
  502. };
  503. static struct platform_device isp116x_device = {
  504. .name = "isp116x-hcd",
  505. .id = -1,
  506. .num_resources = ARRAY_SIZE(isp116x_resources),
  507. .resource = isp116x_resources,
  508. .dev = {
  509. .platform_data = &isp116x_platform_data,
  510. },
  511. };
  512. /* MTD */
  513. static struct resource mtd_resources[] = {
  514. [0] = { /* RedBoot config + filesystem flash */
  515. .start = VIPER_FLASH_PHYS,
  516. .end = VIPER_FLASH_PHYS + SZ_32M - 1,
  517. .flags = IORESOURCE_MEM,
  518. },
  519. [1] = { /* Boot flash */
  520. .start = VIPER_BOOT_PHYS,
  521. .end = VIPER_BOOT_PHYS + SZ_1M - 1,
  522. .flags = IORESOURCE_MEM,
  523. },
  524. [2] = { /*
  525. * SRAM size is actually 256KB, 8bits, with a sparse mapping
  526. * (each byte is on a 16bit boundary).
  527. */
  528. .start = _VIPER_SRAM_BASE,
  529. .end = _VIPER_SRAM_BASE + SZ_512K - 1,
  530. .flags = IORESOURCE_MEM,
  531. },
  532. };
  533. static struct mtd_partition viper_boot_flash_partition = {
  534. .name = "RedBoot",
  535. .size = SZ_1M,
  536. .offset = 0,
  537. .mask_flags = MTD_WRITEABLE, /* force R/O */
  538. };
  539. static struct physmap_flash_data viper_flash_data[] = {
  540. [0] = {
  541. .width = 2,
  542. .parts = NULL,
  543. .nr_parts = 0,
  544. },
  545. [1] = {
  546. .width = 2,
  547. .parts = &viper_boot_flash_partition,
  548. .nr_parts = 1,
  549. },
  550. };
  551. static struct platform_device viper_mtd_devices[] = {
  552. [0] = {
  553. .name = "physmap-flash",
  554. .id = 0,
  555. .dev = {
  556. .platform_data = &viper_flash_data[0],
  557. },
  558. .resource = &mtd_resources[0],
  559. .num_resources = 1,
  560. },
  561. [1] = {
  562. .name = "physmap-flash",
  563. .id = 1,
  564. .dev = {
  565. .platform_data = &viper_flash_data[1],
  566. },
  567. .resource = &mtd_resources[1],
  568. .num_resources = 1,
  569. },
  570. };
  571. static struct platform_device *viper_devs[] __initdata = {
  572. &smc91x_device,
  573. &i2c_bus_device,
  574. &serial_device,
  575. &isp116x_device,
  576. &viper_mtd_devices[0],
  577. &viper_mtd_devices[1],
  578. &viper_backlight_device,
  579. };
  580. static mfp_cfg_t viper_pin_config[] __initdata = {
  581. /* Chip selects */
  582. GPIO15_nCS_1,
  583. GPIO78_nCS_2,
  584. GPIO79_nCS_3,
  585. GPIO80_nCS_4,
  586. GPIO33_nCS_5,
  587. /* FP Backlight */
  588. GPIO9_GPIO, /* VIPER_BCKLIGHT_EN_GPIO */
  589. GPIO10_GPIO, /* VIPER_LCD_EN_GPIO */
  590. GPIO16_PWM0_OUT,
  591. /* Ethernet PHY Ready */
  592. GPIO18_RDY,
  593. /* Serial shutdown */
  594. GPIO12_GPIO | MFP_LPM_DRIVE_HIGH, /* VIPER_UART_SHDN_GPIO */
  595. /* Compact-Flash / PC104 */
  596. GPIO48_nPOE,
  597. GPIO49_nPWE,
  598. GPIO50_nPIOR,
  599. GPIO51_nPIOW,
  600. GPIO52_nPCE_1,
  601. GPIO53_nPCE_2,
  602. GPIO54_nPSKTSEL,
  603. GPIO55_nPREG,
  604. GPIO56_nPWAIT,
  605. GPIO57_nIOIS16,
  606. GPIO8_GPIO, /* VIPER_CF_RDY_GPIO */
  607. GPIO32_GPIO, /* VIPER_CF_CD_GPIO */
  608. GPIO82_GPIO, /* VIPER_CF_POWER_GPIO */
  609. /* Integrated UPS control */
  610. GPIO20_GPIO, /* VIPER_UPS_GPIO */
  611. /* Vcc regulator control */
  612. GPIO6_GPIO, /* VIPER_PSU_DATA_GPIO */
  613. GPIO11_GPIO, /* VIPER_PSU_CLK_GPIO */
  614. GPIO19_GPIO, /* VIPER_PSU_nCS_LD_GPIO */
  615. /* i2c busses */
  616. GPIO26_GPIO, /* VIPER_TPM_I2C_SDA_GPIO */
  617. GPIO27_GPIO, /* VIPER_TPM_I2C_SCL_GPIO */
  618. GPIO83_GPIO, /* VIPER_RTC_I2C_SDA_GPIO */
  619. GPIO84_GPIO, /* VIPER_RTC_I2C_SCL_GPIO */
  620. /* PC/104 Interrupt */
  621. GPIO1_GPIO | WAKEUP_ON_EDGE_RISE, /* VIPER_CPLD_GPIO */
  622. };
  623. static unsigned long viper_tpm;
  624. static int __init viper_tpm_setup(char *str)
  625. {
  626. strict_strtoul(str, 10, &viper_tpm);
  627. return 1;
  628. }
  629. __setup("tpm=", viper_tpm_setup);
  630. static void __init viper_tpm_init(void)
  631. {
  632. struct platform_device *tpm_device;
  633. struct i2c_gpio_platform_data i2c_tpm_data = {
  634. .sda_pin = VIPER_TPM_I2C_SDA_GPIO,
  635. .scl_pin = VIPER_TPM_I2C_SCL_GPIO,
  636. .udelay = 10,
  637. .timeout = 100,
  638. };
  639. char *errstr;
  640. /* Allocate TPM i2c bus if requested */
  641. if (!viper_tpm)
  642. return;
  643. tpm_device = platform_device_alloc("i2c-gpio", 2);
  644. if (tpm_device) {
  645. if (!platform_device_add_data(tpm_device,
  646. &i2c_tpm_data,
  647. sizeof(i2c_tpm_data))) {
  648. if (platform_device_add(tpm_device)) {
  649. errstr = "register TPM i2c bus";
  650. goto error_free_tpm;
  651. }
  652. } else {
  653. errstr = "allocate TPM i2c bus data";
  654. goto error_free_tpm;
  655. }
  656. } else {
  657. errstr = "allocate TPM i2c device";
  658. goto error_tpm;
  659. }
  660. return;
  661. error_free_tpm:
  662. kfree(tpm_device);
  663. error_tpm:
  664. pr_err("viper: Couldn't %s, giving up\n", errstr);
  665. }
  666. static void __init viper_init_vcore_gpios(void)
  667. {
  668. if (gpio_request(VIPER_PSU_DATA_GPIO, "PSU data"))
  669. goto err_request_data;
  670. if (gpio_request(VIPER_PSU_CLK_GPIO, "PSU clock"))
  671. goto err_request_clk;
  672. if (gpio_request(VIPER_PSU_nCS_LD_GPIO, "PSU cs"))
  673. goto err_request_cs;
  674. if (gpio_direction_output(VIPER_PSU_DATA_GPIO, 0) ||
  675. gpio_direction_output(VIPER_PSU_CLK_GPIO, 0) ||
  676. gpio_direction_output(VIPER_PSU_nCS_LD_GPIO, 0))
  677. goto err_dir;
  678. /* c/should assume redboot set the correct level ??? */
  679. viper_set_core_cpu_voltage(get_clk_frequency_khz(0), 1);
  680. return;
  681. err_dir:
  682. gpio_free(VIPER_PSU_nCS_LD_GPIO);
  683. err_request_cs:
  684. gpio_free(VIPER_PSU_CLK_GPIO);
  685. err_request_clk:
  686. gpio_free(VIPER_PSU_DATA_GPIO);
  687. err_request_data:
  688. pr_err("viper: Failed to setup vcore control GPIOs\n");
  689. }
  690. static void __init viper_init_serial_gpio(void)
  691. {
  692. if (gpio_request(VIPER_UART_SHDN_GPIO, "UARTs shutdown"))
  693. goto err_request;
  694. if (gpio_direction_output(VIPER_UART_SHDN_GPIO, 0))
  695. goto err_dir;
  696. return;
  697. err_dir:
  698. gpio_free(VIPER_UART_SHDN_GPIO);
  699. err_request:
  700. pr_err("viper: Failed to setup UART shutdown GPIO\n");
  701. }
  702. #ifdef CONFIG_CPU_FREQ
  703. static int viper_cpufreq_notifier(struct notifier_block *nb,
  704. unsigned long val, void *data)
  705. {
  706. struct cpufreq_freqs *freq = data;
  707. /* TODO: Adjust timings??? */
  708. switch (val) {
  709. case CPUFREQ_PRECHANGE:
  710. if (freq->old < freq->new) {
  711. /* we are getting faster so raise the voltage
  712. * before we change freq */
  713. viper_set_core_cpu_voltage(freq->new, 0);
  714. }
  715. break;
  716. case CPUFREQ_POSTCHANGE:
  717. if (freq->old > freq->new) {
  718. /* we are slowing down so drop the power
  719. * after we change freq */
  720. viper_set_core_cpu_voltage(freq->new, 0);
  721. }
  722. break;
  723. case CPUFREQ_RESUMECHANGE:
  724. viper_set_core_cpu_voltage(freq->new, 0);
  725. break;
  726. default:
  727. /* ignore */
  728. break;
  729. }
  730. return 0;
  731. }
  732. static struct notifier_block viper_cpufreq_notifier_block = {
  733. .notifier_call = viper_cpufreq_notifier
  734. };
  735. static void __init viper_init_cpufreq(void)
  736. {
  737. if (cpufreq_register_notifier(&viper_cpufreq_notifier_block,
  738. CPUFREQ_TRANSITION_NOTIFIER))
  739. pr_err("viper: Failed to setup cpufreq notifier\n");
  740. }
  741. #else
  742. static inline void viper_init_cpufreq(void) {}
  743. #endif
  744. static void viper_power_off(void)
  745. {
  746. pr_notice("Shutting off UPS\n");
  747. gpio_set_value(VIPER_UPS_GPIO, 1);
  748. /* Spin to death... */
  749. while (1);
  750. }
  751. static void __init viper_init(void)
  752. {
  753. u8 version;
  754. pm_power_off = viper_power_off;
  755. pxa2xx_mfp_config(ARRAY_AND_SIZE(viper_pin_config));
  756. /* Wake-up serial console */
  757. viper_init_serial_gpio();
  758. set_pxa_fb_info(&fb_info);
  759. /* v1 hardware cannot use the datacs line */
  760. version = viper_hw_version();
  761. if (version == 0)
  762. smc91x_device.num_resources--;
  763. pxa_set_i2c_info(NULL);
  764. platform_add_devices(viper_devs, ARRAY_SIZE(viper_devs));
  765. viper_init_vcore_gpios();
  766. viper_init_cpufreq();
  767. sysdev_driver_register(&cpu_sysdev_class, &viper_cpu_sysdev_driver);
  768. if (version) {
  769. pr_info("viper: hardware v%di%d detected. "
  770. "CPLD revision %d.\n",
  771. VIPER_BOARD_VERSION(version),
  772. VIPER_BOARD_ISSUE(version),
  773. VIPER_CPLD_REVISION(version));
  774. system_rev = (VIPER_BOARD_VERSION(version) << 8) |
  775. (VIPER_BOARD_ISSUE(version) << 4) |
  776. VIPER_CPLD_REVISION(version);
  777. } else {
  778. pr_info("viper: No version register.\n");
  779. }
  780. i2c_register_board_info(1, ARRAY_AND_SIZE(viper_i2c_devices));
  781. viper_tpm_init();
  782. pxa_set_ac97_info(NULL);
  783. }
  784. static struct map_desc viper_io_desc[] __initdata = {
  785. {
  786. .virtual = VIPER_CPLD_BASE,
  787. .pfn = __phys_to_pfn(VIPER_CPLD_PHYS),
  788. .length = 0x00300000,
  789. .type = MT_DEVICE,
  790. },
  791. {
  792. .virtual = VIPER_PC104IO_BASE,
  793. .pfn = __phys_to_pfn(_PCMCIA1IO),
  794. .length = 0x00800000,
  795. .type = MT_DEVICE,
  796. },
  797. };
  798. static void __init viper_map_io(void)
  799. {
  800. pxa_map_io();
  801. iotable_init(viper_io_desc, ARRAY_SIZE(viper_io_desc));
  802. PCFR |= PCFR_OPDE;
  803. }
  804. MACHINE_START(VIPER, "Arcom/Eurotech VIPER SBC")
  805. /* Maintainer: Marc Zyngier <maz@misterjones.org> */
  806. .phys_io = 0x40000000,
  807. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  808. .boot_params = 0xa0000100,
  809. .map_io = viper_map_io,
  810. .init_irq = viper_init_irq,
  811. .timer = &pxa_timer,
  812. .init_machine = viper_init,
  813. MACHINE_END