viper.c 23 KB

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