pcm990-baseboard.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * arch/arm/mach-pxa/pcm990-baseboard.c
  4. * Support for the Phytec phyCORE-PXA270 Development Platform (PCM-990).
  5. *
  6. * Refer
  7. * http://www.phytec.com/products/rdk/ARM-XScale/phyCORE-XScale-PXA270.html
  8. * for additional hardware info
  9. *
  10. * Author: Juergen Kilb
  11. * Created: April 05, 2005
  12. * Copyright: Phytec Messtechnik GmbH
  13. * e-Mail: [email protected]
  14. *
  15. * based on Intel Mainstone Board
  16. *
  17. * Copyright 2007 Juergen Beisert @ Pengutronix ([email protected])
  18. */
  19. #include <linux/gpio.h>
  20. #include <linux/irq.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/i2c.h>
  23. #include <linux/platform_data/i2c-pxa.h>
  24. #include <linux/pwm.h>
  25. #include <linux/pwm_backlight.h>
  26. #include <asm/mach/map.h>
  27. #include "pxa27x.h"
  28. #include <linux/platform_data/asoc-pxa.h>
  29. #include <linux/platform_data/mmc-pxamci.h>
  30. #include <linux/platform_data/usb-ohci-pxa27x.h>
  31. #include "pcm990_baseboard.h"
  32. #include <linux/platform_data/video-pxafb.h>
  33. #include "devices.h"
  34. #include "generic.h"
  35. static unsigned long pcm990_pin_config[] __initdata = {
  36. /* MMC */
  37. GPIO32_MMC_CLK,
  38. GPIO112_MMC_CMD,
  39. GPIO92_MMC_DAT_0,
  40. GPIO109_MMC_DAT_1,
  41. GPIO110_MMC_DAT_2,
  42. GPIO111_MMC_DAT_3,
  43. /* USB */
  44. GPIO88_USBH1_PWR,
  45. GPIO89_USBH1_PEN,
  46. /* PWM0 */
  47. GPIO16_PWM0_OUT,
  48. /* I2C */
  49. GPIO117_I2C_SCL,
  50. GPIO118_I2C_SDA,
  51. /* AC97 */
  52. GPIO28_AC97_BITCLK,
  53. GPIO29_AC97_SDATA_IN_0,
  54. GPIO30_AC97_SDATA_OUT,
  55. GPIO31_AC97_SYNC,
  56. };
  57. static void __iomem *pcm990_cpld_base;
  58. static u8 pcm990_cpld_readb(unsigned int reg)
  59. {
  60. return readb(pcm990_cpld_base + reg);
  61. }
  62. static void pcm990_cpld_writeb(u8 value, unsigned int reg)
  63. {
  64. writeb(value, pcm990_cpld_base + reg);
  65. }
  66. /*
  67. * pcm990_lcd_power - control power supply to the LCD
  68. * @on: 0 = switch off, 1 = switch on
  69. *
  70. * Called by the pxafb driver
  71. */
  72. #ifndef CONFIG_PCM990_DISPLAY_NONE
  73. static void pcm990_lcd_power(int on, struct fb_var_screeninfo *var)
  74. {
  75. if (on) {
  76. /* enable LCD-Latches
  77. * power on LCD
  78. */
  79. pcm990_cpld_writeb(PCM990_CTRL_LCDPWR + PCM990_CTRL_LCDON,
  80. PCM990_CTRL_REG3);
  81. } else {
  82. /* disable LCD-Latches
  83. * power off LCD
  84. */
  85. pcm990_cpld_writeb(0, PCM990_CTRL_REG3);
  86. }
  87. }
  88. #endif
  89. #if defined(CONFIG_PCM990_DISPLAY_SHARP)
  90. static struct pxafb_mode_info fb_info_sharp_lq084v1dg21 = {
  91. .pixclock = 28000,
  92. .xres = 640,
  93. .yres = 480,
  94. .bpp = 16,
  95. .hsync_len = 20,
  96. .left_margin = 103,
  97. .right_margin = 47,
  98. .vsync_len = 6,
  99. .upper_margin = 28,
  100. .lower_margin = 5,
  101. .sync = 0,
  102. .cmap_greyscale = 0,
  103. };
  104. static struct pxafb_mach_info pcm990_fbinfo __initdata = {
  105. .modes = &fb_info_sharp_lq084v1dg21,
  106. .num_modes = 1,
  107. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  108. .pxafb_lcd_power = pcm990_lcd_power,
  109. };
  110. #elif defined(CONFIG_PCM990_DISPLAY_NEC)
  111. struct pxafb_mode_info fb_info_nec_nl6448bc20_18d = {
  112. .pixclock = 39720,
  113. .xres = 640,
  114. .yres = 480,
  115. .bpp = 16,
  116. .hsync_len = 32,
  117. .left_margin = 16,
  118. .right_margin = 48,
  119. .vsync_len = 2,
  120. .upper_margin = 12,
  121. .lower_margin = 17,
  122. .sync = 0,
  123. .cmap_greyscale = 0,
  124. };
  125. static struct pxafb_mach_info pcm990_fbinfo __initdata = {
  126. .modes = &fb_info_nec_nl6448bc20_18d,
  127. .num_modes = 1,
  128. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  129. .pxafb_lcd_power = pcm990_lcd_power,
  130. };
  131. #endif
  132. static struct pwm_lookup pcm990_pwm_lookup[] = {
  133. PWM_LOOKUP("pxa27x-pwm.0", 0, "pwm-backlight.0", NULL, 78770,
  134. PWM_POLARITY_NORMAL),
  135. };
  136. static struct platform_pwm_backlight_data pcm990_backlight_data = {
  137. .max_brightness = 1023,
  138. .dft_brightness = 1023,
  139. };
  140. static struct platform_device pcm990_backlight_device = {
  141. .name = "pwm-backlight",
  142. .dev = {
  143. .parent = &pxa27x_device_pwm0.dev,
  144. .platform_data = &pcm990_backlight_data,
  145. },
  146. };
  147. /*
  148. * The PCM-990 development baseboard uses PCM-027's hardware in the
  149. * following way:
  150. *
  151. * - LCD support is in use
  152. * - GPIO16 is output for back light on/off with PWM
  153. * - GPIO58 ... GPIO73 are outputs for display data
  154. * - GPIO74 is output output for LCDFCLK
  155. * - GPIO75 is output for LCDLCLK
  156. * - GPIO76 is output for LCDPCLK
  157. * - GPIO77 is output for LCDBIAS
  158. * - MMC support is in use
  159. * - GPIO32 is output for MMCCLK
  160. * - GPIO92 is MMDAT0
  161. * - GPIO109 is MMDAT1
  162. * - GPIO110 is MMCS0
  163. * - GPIO111 is MMCS1
  164. * - GPIO112 is MMCMD
  165. * - IDE/CF card is in use
  166. * - GPIO48 is output /POE
  167. * - GPIO49 is output /PWE
  168. * - GPIO50 is output /PIOR
  169. * - GPIO51 is output /PIOW
  170. * - GPIO54 is output /PCE2
  171. * - GPIO55 is output /PREG
  172. * - GPIO56 is input /PWAIT
  173. * - GPIO57 is output /PIOS16
  174. * - GPIO79 is output PSKTSEL
  175. * - GPIO85 is output /PCE1
  176. * - FFUART is in use
  177. * - GPIO34 is input FFRXD
  178. * - GPIO35 is input FFCTS
  179. * - GPIO36 is input FFDCD
  180. * - GPIO37 is input FFDSR
  181. * - GPIO38 is input FFRI
  182. * - GPIO39 is output FFTXD
  183. * - GPIO40 is output FFDTR
  184. * - GPIO41 is output FFRTS
  185. * - BTUART is in use
  186. * - GPIO42 is input BTRXD
  187. * - GPIO43 is output BTTXD
  188. * - GPIO44 is input BTCTS
  189. * - GPIO45 is output BTRTS
  190. * - IRUART is in use
  191. * - GPIO46 is input STDRXD
  192. * - GPIO47 is output STDTXD
  193. * - AC97 is in use*)
  194. * - GPIO28 is input AC97CLK
  195. * - GPIO29 is input AC97DatIn
  196. * - GPIO30 is output AC97DatO
  197. * - GPIO31 is output AC97SYNC
  198. * - GPIO113 is output AC97_RESET
  199. * - SSP is in use
  200. * - GPIO23 is output SSPSCLK
  201. * - GPIO24 is output chip select to Max7301
  202. * - GPIO25 is output SSPTXD
  203. * - GPIO26 is input SSPRXD
  204. * - GPIO27 is input for Max7301 IRQ
  205. * - GPIO53 is input SSPSYSCLK
  206. * - SSP3 is in use
  207. * - GPIO81 is output SSPTXD3
  208. * - GPIO82 is input SSPRXD3
  209. * - GPIO83 is output SSPSFRM
  210. * - GPIO84 is output SSPCLK3
  211. *
  212. * Otherwise claimed GPIOs:
  213. * GPIO1 -> IRQ from user switch
  214. * GPIO9 -> IRQ from power management
  215. * GPIO10 -> IRQ from WML9712 AC97 controller
  216. * GPIO11 -> IRQ from IDE controller
  217. * GPIO12 -> IRQ from CF controller
  218. * GPIO13 -> IRQ from CF controller
  219. * GPIO14 -> GPIO free
  220. * GPIO15 -> /CS1 selects baseboard's Control CPLD (U7, 16 bit wide data path)
  221. * GPIO19 -> GPIO free
  222. * GPIO20 -> /SDCS2
  223. * GPIO21 -> /CS3 PC card socket select
  224. * GPIO33 -> /CS5 network controller select
  225. * GPIO78 -> /CS2 (16 bit wide data path)
  226. * GPIO80 -> /CS4 (16 bit wide data path)
  227. * GPIO86 -> GPIO free
  228. * GPIO87 -> GPIO free
  229. * GPIO90 -> LED0 on CPU module
  230. * GPIO91 -> LED1 on CPI module
  231. * GPIO117 -> SCL
  232. * GPIO118 -> SDA
  233. */
  234. static unsigned long pcm990_irq_enabled;
  235. static void pcm990_mask_ack_irq(struct irq_data *d)
  236. {
  237. int pcm990_irq = (d->irq - PCM027_IRQ(0));
  238. pcm990_irq_enabled &= ~(1 << pcm990_irq);
  239. pcm990_cpld_writeb(pcm990_irq_enabled, PCM990_CTRL_INTMSKENA);
  240. }
  241. static void pcm990_unmask_irq(struct irq_data *d)
  242. {
  243. int pcm990_irq = (d->irq - PCM027_IRQ(0));
  244. u8 val;
  245. /* the irq can be acknowledged only if deasserted, so it's done here */
  246. pcm990_irq_enabled |= (1 << pcm990_irq);
  247. val = pcm990_cpld_readb(PCM990_CTRL_INTSETCLR);
  248. val |= 1 << pcm990_irq;
  249. pcm990_cpld_writeb(val, PCM990_CTRL_INTSETCLR);
  250. pcm990_cpld_writeb(pcm990_irq_enabled, PCM990_CTRL_INTMSKENA);
  251. }
  252. static struct irq_chip pcm990_irq_chip = {
  253. .irq_mask_ack = pcm990_mask_ack_irq,
  254. .irq_unmask = pcm990_unmask_irq,
  255. };
  256. static void pcm990_irq_handler(struct irq_desc *desc)
  257. {
  258. unsigned int irq;
  259. unsigned long pending;
  260. pending = ~pcm990_cpld_readb(PCM990_CTRL_INTSETCLR);
  261. pending &= pcm990_irq_enabled;
  262. do {
  263. /* clear our parent IRQ */
  264. desc->irq_data.chip->irq_ack(&desc->irq_data);
  265. if (likely(pending)) {
  266. irq = PCM027_IRQ(0) + __ffs(pending);
  267. generic_handle_irq(irq);
  268. }
  269. pending = ~pcm990_cpld_readb(PCM990_CTRL_INTSETCLR);
  270. pending &= pcm990_irq_enabled;
  271. } while (pending);
  272. }
  273. static void __init pcm990_init_irq(void)
  274. {
  275. int irq;
  276. /* setup extra PCM990 irqs */
  277. for (irq = PCM027_IRQ(0); irq <= PCM027_IRQ(3); irq++) {
  278. irq_set_chip_and_handler(irq, &pcm990_irq_chip,
  279. handle_level_irq);
  280. irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
  281. }
  282. /* disable all Interrupts */
  283. pcm990_cpld_writeb(0x0, PCM990_CTRL_INTMSKENA);
  284. pcm990_cpld_writeb(0xff, PCM990_CTRL_INTSETCLR);
  285. irq_set_chained_handler(PCM990_CTRL_INT_IRQ, pcm990_irq_handler);
  286. irq_set_irq_type(PCM990_CTRL_INT_IRQ, PCM990_CTRL_INT_IRQ_EDGE);
  287. }
  288. static int pcm990_mci_init(struct device *dev, irq_handler_t mci_detect_int,
  289. void *data)
  290. {
  291. int err;
  292. err = request_irq(PCM027_MMCDET_IRQ, mci_detect_int, 0,
  293. "MMC card detect", data);
  294. if (err)
  295. printk(KERN_ERR "pcm990_mci_init: MMC/SD: can't request MMC "
  296. "card detect IRQ\n");
  297. return err;
  298. }
  299. static int pcm990_mci_setpower(struct device *dev, unsigned int vdd)
  300. {
  301. struct pxamci_platform_data *p_d = dev->platform_data;
  302. u8 val;
  303. val = pcm990_cpld_readb(PCM990_CTRL_REG5);
  304. if ((1 << vdd) & p_d->ocr_mask)
  305. val |= PCM990_CTRL_MMC2PWR;
  306. else
  307. val &= ~PCM990_CTRL_MMC2PWR;
  308. pcm990_cpld_writeb(PCM990_CTRL_MMC2PWR, PCM990_CTRL_REG5);
  309. return 0;
  310. }
  311. static void pcm990_mci_exit(struct device *dev, void *data)
  312. {
  313. free_irq(PCM027_MMCDET_IRQ, data);
  314. }
  315. #define MSECS_PER_JIFFY (1000/HZ)
  316. static struct pxamci_platform_data pcm990_mci_platform_data = {
  317. .detect_delay_ms = 250,
  318. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  319. .init = pcm990_mci_init,
  320. .setpower = pcm990_mci_setpower,
  321. .exit = pcm990_mci_exit,
  322. };
  323. static struct pxaohci_platform_data pcm990_ohci_platform_data = {
  324. .port_mode = PMM_PERPORT_MODE,
  325. .flags = ENABLE_PORT1 | POWER_CONTROL_LOW | POWER_SENSE_LOW,
  326. .power_on_delay = 10,
  327. };
  328. /*
  329. * system init for baseboard usage. Will be called by pcm027 init.
  330. *
  331. * Add platform devices present on this baseboard and init
  332. * them from CPU side as far as required to use them later on
  333. */
  334. void __init pcm990_baseboard_init(void)
  335. {
  336. pxa2xx_mfp_config(ARRAY_AND_SIZE(pcm990_pin_config));
  337. pcm990_cpld_base = ioremap(PCM990_CTRL_PHYS, PCM990_CTRL_SIZE);
  338. if (!pcm990_cpld_base) {
  339. pr_err("pcm990: failed to ioremap cpld\n");
  340. return;
  341. }
  342. /* register CPLD's IRQ controller */
  343. pcm990_init_irq();
  344. #ifndef CONFIG_PCM990_DISPLAY_NONE
  345. pxa_set_fb_info(NULL, &pcm990_fbinfo);
  346. #endif
  347. pwm_add_table(pcm990_pwm_lookup, ARRAY_SIZE(pcm990_pwm_lookup));
  348. platform_device_register(&pcm990_backlight_device);
  349. /* MMC */
  350. pxa_set_mci_info(&pcm990_mci_platform_data);
  351. /* USB host */
  352. pxa_set_ohci_info(&pcm990_ohci_platform_data);
  353. pxa_set_i2c_info(NULL);
  354. pxa_set_ac97_info(NULL);
  355. printk(KERN_INFO "PCM-990 Evaluation baseboard initialized\n");
  356. }