viper.c 23 KB

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