Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 22.15 KB | None | 0 0
  1. /*
  2.  * Copyright 2007 Robert Schwebel <r.schwebel@pengutronix.de>, Pengutronix
  3.  * Copyright (C) 2009 Sascha Hauer (kernel@pengutronix.de)
  4.  *
  5.  * This program is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU General Public License
  7.  * as published by the Free Software Foundation; either version 2
  8.  * of the License, or (at your option) any later version.
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17.  * MA 02110-1301, USA.
  18.  */
  19.  
  20. #include <linux/platform_device.h>
  21. #include <linux/mtd/physmap.h>
  22. #include <linux/mtd/plat-ram.h>
  23. #include <linux/io.h>
  24. #include <linux/i2c.h>
  25. #include <linux/i2c/at24.h>
  26. #include <linux/i2c/pca953x.h>
  27. #include <linux/i2c/tsc2007.h>
  28. #include <linux/dma-mapping.h>
  29. #include <linux/spi/spi.h>
  30. #include <linux/spi/eeprom.h>
  31. #include <linux/irq.h>
  32. #include <linux/can/mcp251x.h>
  33. #include <linux/gpio.h>
  34. #include <linux/delay.h>
  35. #include <linux/fsl_devices.h>
  36.  
  37. #include <media/soc_camera.h>
  38.  
  39. #include <asm/mach/arch.h>
  40. #include <asm/mach-types.h>
  41. #include <mach/common.h>
  42. #include <mach/hardware.h>
  43. #include <mach/iomux.h>
  44. #include <mach/i2c.h>
  45. #include <mach/imx_cam.h>
  46. #include <asm/mach/time.h>
  47. #if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
  48. #include <mach/spi.h>
  49. #endif
  50. #include <mach/imx-uart.h>
  51. #include <mach/mxc_nand.h>
  52. #include <mach/irqs.h>
  53. #include <mach/imxfb.h>
  54. #include <mach/mxc_ehci.h>
  55. #include <mach/ulpi.h>
  56. #include <mach/mmc.h>
  57. #include <mach/audmux.h>
  58. #include <mach/ssi.h>
  59.  
  60. #include "devices.h"
  61.  
  62. static int pca100_pins[] = {
  63.     /* UART1 */
  64.     PE12_PF_UART1_TXD,
  65.     PE13_PF_UART1_RXD,
  66.     PE14_PF_UART1_CTS,
  67.     PE15_PF_UART1_RTS,
  68.     /* SDHC */
  69.     PB4_PF_SD2_D0,
  70.     PB5_PF_SD2_D1,
  71.     PB6_PF_SD2_D2,
  72.     PB7_PF_SD2_D3,
  73.     PB8_PF_SD2_CMD,
  74.     PB9_PF_SD2_CLK,
  75.     /* FEC */
  76.     PD0_AIN_FEC_TXD0,
  77.     PD1_AIN_FEC_TXD1,
  78.     PD2_AIN_FEC_TXD2,
  79.     PD3_AIN_FEC_TXD3,
  80.     PD4_AOUT_FEC_RX_ER,
  81.     PD5_AOUT_FEC_RXD1,
  82.     PD6_AOUT_FEC_RXD2,
  83.     PD7_AOUT_FEC_RXD3,
  84.     PD8_AF_FEC_MDIO,
  85.     PD9_AIN_FEC_MDC,
  86.     PD10_AOUT_FEC_CRS,
  87.     PD11_AOUT_FEC_TX_CLK,
  88.     PD12_AOUT_FEC_RXD0,
  89.     PD13_AOUT_FEC_RX_DV,
  90.     PD14_AOUT_FEC_RX_CLK,
  91.     PD15_AOUT_FEC_COL,
  92.     PD16_AIN_FEC_TX_ER,
  93.     PF23_AIN_FEC_TX_EN,
  94.     /* SSI1 */
  95.     PC20_PF_SSI1_FS,
  96.     PC21_PF_SSI1_RXD,
  97.     PC22_PF_SSI1_TXD,
  98.     PC23_PF_SSI1_CLK,
  99.     /* onboard I2C */
  100.     PC5_PF_I2C2_SDA,
  101.     PC6_PF_I2C2_SCL,
  102.     /* external I2C */
  103.     PD17_PF_I2C_DATA,
  104.     PD18_PF_I2C_CLK,
  105.     /* display */
  106.     PA5_PF_LSCLK,
  107.     PA6_PF_LD0,
  108.     PA7_PF_LD1,
  109.     PA8_PF_LD2,
  110.     PA9_PF_LD3,
  111.     PA10_PF_LD4,
  112.     PA11_PF_LD5,
  113.     PA12_PF_LD6,
  114.     PA13_PF_LD7,
  115.     PA14_PF_LD8,
  116.     PA15_PF_LD9,
  117.     PA16_PF_LD10,
  118.     PA17_PF_LD11,
  119.     PA18_PF_LD12,
  120.     PA19_PF_LD13,
  121.     PA20_PF_LD14,
  122.     PA21_PF_LD15,
  123.     PA22_PF_LD16,
  124.     PA23_PF_LD17,
  125. #if 0
  126.     /* not used? */
  127.     PA24_PF_REV,
  128.     PA25_PF_CLS,
  129.     PA26_PF_PS,
  130.     PA27_PF_SPL_SPR,
  131. #endif
  132.     PA28_PF_HSYNC,
  133.     PA29_PF_VSYNC,
  134.     PA30_PF_CONTRAST,
  135.     PA31_PF_OE_ACD,
  136.  
  137.     /* SPI1 */
  138.     PD25_PF_CSPI1_RDY,
  139. //  PD28_PF_CSPI1_SS0,
  140.     PD29_PF_CSPI1_SCLK,
  141.     PD30_PF_CSPI1_MISO,
  142.     PD31_PF_CSPI1_MOSI,
  143.     /* OTG */
  144.     PC7_PF_USBOTG_DATA5,
  145.     PC8_PF_USBOTG_DATA6,
  146.     PC9_PF_USBOTG_DATA0,
  147.     PC10_PF_USBOTG_DATA2,
  148.     PC11_PF_USBOTG_DATA1,
  149.     PC12_PF_USBOTG_DATA4,
  150.     PC13_PF_USBOTG_DATA3,
  151.     PE0_PF_USBOTG_NXT,
  152.     PE1_PF_USBOTG_STP,
  153.     PE2_PF_USBOTG_DIR,
  154.     PE24_PF_USBOTG_CLK,
  155.     PE25_PF_USBOTG_DATA7,
  156.     /* USBH2 */
  157.     PA0_PF_USBH2_CLK,
  158.     PA1_PF_USBH2_DIR,
  159.     PA2_PF_USBH2_DATA7,
  160.     PA3_PF_USBH2_NXT,
  161.     PA4_PF_USBH2_STP,
  162.     PD19_AF_USBH2_DATA4,
  163.     PD20_AF_USBH2_DATA3,
  164.     PD21_AF_USBH2_DATA6,
  165.     PD22_AF_USBH2_DATA0,
  166.     PD23_AF_USBH2_DATA2,
  167.     PD24_AF_USBH2_DATA1,
  168.     PD26_AF_USBH2_DATA5,
  169. };
  170.  
  171. static struct imxuart_platform_data uart_pdata = {
  172.     .flags = IMXUART_HAVE_RTSCTS,
  173. };
  174.  
  175. static struct mxc_nand_platform_data pca100_nand_board_info = {
  176.     .width = 1,
  177.     .hw_ecc = 1,
  178. };
  179.  
  180. /* count of GPIOs that are occupied by the CPU itself */
  181. #define MAX_INTERNAL_GPIO 192
  182.  
  183. static struct pca953x_platform_data pca9536_data = {
  184.     .gpio_base      = MAX_INTERNAL_GPIO,
  185. };
  186.  
  187. static struct i2c_board_info pca100_camera_i2c_devices[] = {
  188.     {
  189.         I2C_BOARD_INFO("mt9v022", 0x48),
  190. //      I2C_BOARD_INFO("mt9v022", 0x49),
  191.     },{
  192.         I2C_BOARD_INFO("mt9m001", 0x5d),
  193.     },
  194. };
  195. #if 1
  196. static unsigned long pca100_camera_query_bus_param(struct soc_camera_link *link)
  197. {
  198.     /* MX27 can apply 8 bit bus width only */
  199.     return SOCAM_DATAWIDTH_8;
  200. }
  201.  
  202. static int pca100_camera_set_bus_param(struct soc_camera_link *link,
  203.                 unsigned long flags)
  204. {
  205.     /* unlike mx31, gpio is set with use_camera_gpio on MX27, hence
  206.      * set_bus_param is a dummy only to make the camera drivers statisfied,
  207.      * since they will otherwise go for 10bit bus width */
  208.     return 0;
  209. }
  210. #endif
  211.  
  212. static struct soc_camera_link iclink[] = {
  213.     {
  214.         .bus_id         = 0, /* Must match with the camera ID */
  215.         .board_info     = &pca100_camera_i2c_devices[0],
  216.         .i2c_adapter_id     = 0,
  217. #if 1
  218.         .query_bus_param    = pca100_camera_query_bus_param,
  219.         .set_bus_param      = pca100_camera_set_bus_param,
  220.         //.flags  = SOCAM_SENSOR_INVERT_PCLK, //FIXME
  221. #endif
  222.         .module_name        = "mt9v022",
  223.     }, {
  224.         .bus_id         = 0, /* Must match with the camera ID */
  225.         .board_info     = &pca100_camera_i2c_devices[1],
  226.         .i2c_adapter_id     = 0,
  227. #if 1
  228.         .query_bus_param    = pca100_camera_query_bus_param,
  229.         .set_bus_param      = pca100_camera_set_bus_param,
  230.         //.flags  = SOCAM_SENSOR_INVERT_PCLK, //FIXME
  231. #endif
  232.         .module_name        = "mt9m001",
  233.     },
  234. };
  235.  
  236. static struct platform_device pca100_camera[] = {
  237.     {
  238.         .name   = "soc-camera-pdrv",
  239.         .id = 0,
  240.         .dev    = {
  241.             .platform_data = &iclink[0],
  242.         },
  243.     }, {
  244.         .name   = "soc-camera-pdrv",
  245.         .id = 1,
  246.         .dev    = {
  247.             .platform_data = &iclink[1],
  248.         },
  249.     },
  250. };
  251.  
  252. static struct platform_device *platform_devices[] __initdata = {
  253.     &mxc_w1_master_device,
  254.     &mxc_fec_device,
  255.     &mxc_vpu_device,
  256.     &pca100_camera[0],
  257.     &pca100_camera[1],
  258. };
  259.  
  260. static struct imxi2c_platform_data pca100_i2c_0_data = {
  261.     .bitrate = 100000,
  262. };
  263.  
  264. static struct imxi2c_platform_data pca100_i2c_1_data = {
  265.     .bitrate = 100000,
  266. };
  267.  
  268. static struct at24_platform_data board_eeprom = {
  269.     .byte_len = 4096,
  270.     .page_size = 32,
  271.     .flags = AT24_FLAG_ADDR16,
  272. };
  273.  
  274. //Touch
  275. static int tsc2007_get_pendown_state(void)
  276. {
  277.     int val = 0;
  278.     gpio_free(GPIO_PORTE + 5);
  279.     gpio_request(GPIO_PORTE + 5, NULL);
  280.     gpio_direction_input(GPIO_PORTE + 5);
  281.     val = gpio_get_value(GPIO_PORTE + 5);
  282.     gpio_free(GPIO_PORTE + 5);
  283.     gpio_request(GPIO_PORTE + 5,NULL);
  284.    
  285.     return val ? 0 : 1;
  286. }
  287.  
  288. static int tsc2007_init(void)
  289. {
  290. #if 0
  291.     int ret = 0;
  292.     printk("tsc2007_init()");
  293.  
  294.     ret = gpio_request(GPIO_PORTE + 5, NULL);  
  295.     gpio_direction_input(GPIO_PORTE + 5);  
  296.     if (ret)
  297.         printk(KERN_ERR
  298.             "tsc2007: Failed to reuest Port\n");
  299.  
  300.     return ret;
  301. #endif
  302.     gpio_request(GPIO_PORTE + 5, NULL);
  303.     return 0;
  304. }
  305.  
  306. void tsc2007_exit(void)
  307. {
  308.  
  309. }
  310.  
  311. static struct tsc2007_platform_data tsc2007_data = {
  312.     .model  = 2007,             /* 2007. */
  313.     .x_plate_ohms = 700,
  314.     .get_pendown_state = tsc2007_get_pendown_state,
  315.     //.clear_penirq = ,     /* If needed, clear 2nd level interrupt source */
  316.     .init_platform_hw = tsc2007_init,
  317.     .exit_platform_hw = tsc2007_exit,
  318. };
  319.  
  320. static struct i2c_board_info pca100_i2c_devices[] = {
  321.     {
  322.         I2C_BOARD_INFO("at24", 0x52), /* E0=0, E1=1, E2=0 */
  323.         .platform_data = &board_eeprom,
  324.     }, {
  325.         I2C_BOARD_INFO("rtc-pcf8563", 0x51),
  326.         .type = "pcf8563"
  327.     }, {
  328.         I2C_BOARD_INFO("lm75", 0x4a),
  329.         .type = "lm75"
  330.     },
  331. #if 1
  332.     {
  333.         I2C_BOARD_INFO("tsc2007", 0x49),
  334.         .type = "tsc2007",
  335.         .platform_data = &tsc2007_data,
  336.         .irq = gpio_to_irq(GPIO_PORTE + 5) //IRQ_GPIOE(5)
  337.     },
  338. #endif
  339. };
  340.  
  341. /* Board I2C devices. */
  342. static struct i2c_board_info __initdata pca100_base_i2c_devices[] = {
  343.     {
  344.          /* Must initialize before the camera(s) */
  345.         I2C_BOARD_INFO("pca953x", 0x41),
  346.         .type = "pca9536",
  347.         .platform_data = &pca9536_data,
  348.     }
  349. };
  350.  
  351. static int mxc_csi_pins[] = {
  352.         PB10_PF_CSI_D0,
  353.         PB11_PF_CSI_D1,
  354.         PB12_PF_CSI_D2,
  355.         PB13_PF_CSI_D3,
  356.         PB14_PF_CSI_D4,
  357.         PB15_PF_CSI_MCLK,
  358.         PB16_PF_CSI_PIXCLK,
  359.         PB17_PF_CSI_D5,
  360.         PB18_PF_CSI_D6,
  361.         PB19_PF_CSI_D7,
  362.         PB20_PF_CSI_VSYNC,
  363.         PB21_PF_CSI_HSYNC
  364. };
  365.  
  366. //FIXME
  367. static int pca100_camera_init(struct platform_device *pdev)
  368. {
  369. #if 0
  370.         struct regulator *regulator;
  371.  
  372.         regulator = regulator_get(&pdev->dev, "imx_cam_vcc");
  373.         if (IS_ERR(regulator))
  374.                 dev_err(&pdev->dev, "unable to get regulator: %ld\n",
  375.                                 PTR_ERR(regulator));
  376.         else
  377.                 regulator_enable(regulator);
  378. #endif
  379.         return mxc_gpio_setup_multiple_pins(mxc_csi_pins,
  380.                         ARRAY_SIZE(mxc_csi_pins), "CSI");
  381. }
  382.  
  383. static int pca100_camera_exit(struct platform_device *pdev)
  384. {
  385.         mxc_gpio_release_multiple_pins(mxc_csi_pins, ARRAY_SIZE(mxc_csi_pins));
  386.  
  387.         return 0;
  388. }
  389.  
  390. struct mx27_camera_platform_data camera_pdata = {
  391.         .init = pca100_camera_init,
  392.         .exit = pca100_camera_exit,
  393.         .clk  = 26600000,
  394.         .flags = MX27_CAMERA_HSYNC_HIGH | MX27_CAMERA_GATED_CLOCK |
  395.                 MX27_CAMERA_PACK_DIR_MSB,
  396. };
  397.  
  398. static struct imx_fb_videomode pca100_modes[] = {
  399.     {
  400.         .mode = {
  401.             .name       = "Primeview-PD050VL1",
  402.             .refresh    = 60,
  403.             .xres       = 640,
  404.             .yres       = 480,
  405.             .pixclock   = 45045, /* in ps (22,2 MHz) */
  406.             .hsync_len  = 32,
  407.             .left_margin    = 112,
  408.             .right_margin   = 36,
  409.             .vsync_len  = 2,
  410.             .upper_margin   = 33,
  411.             .lower_margin   = 33,
  412.         },
  413.         /* phytec */
  414.         .pcr = 0xFAC88080,
  415.         .bpp = 16, //32,
  416.     },
  417.     {
  418.         .mode = {
  419.             .name       = "CASIO-COM57H5137XSC",
  420.             .refresh    = 60,
  421.             .xres       = 640,
  422.             .yres       = 480,
  423.             .pixclock   = 54000, /* in ps (18,52 MHz) */
  424.             .hsync_len  = 30,
  425.             .left_margin    = 114,
  426.             .right_margin   = 1, //46
  427.             .vsync_len  = 3,
  428.             .upper_margin   = 33,
  429.             .lower_margin   = 1, //33
  430.         },
  431.         /* phytec */
  432.         .pcr = 0xFAE80080,
  433.         .bpp = 16,
  434.     },
  435.     {
  436.         .mode = {
  437.             .name       = "EDT-QVGA-C",
  438.             .refresh    = 70,
  439.             .xres       = 320,
  440.             .yres       = 240,
  441.             .pixclock   = 133333, /* in ps (18,52 MHz) */
  442.             .hsync_len  = 40,
  443.             .left_margin    = 29,       /* h - front porch*/
  444.             .right_margin   = 55,       /* h - back porch*/
  445.             .vsync_len  = 3,
  446.             .upper_margin   = 16,       /* v - front porch*/
  447.             .lower_margin   = 7, //33   /* h - back porch*/
  448.         },
  449.         /* phytec */
  450.         .pcr = 0xFCE88080,
  451.         .bpp = 16,
  452.     },
  453.     {
  454.         .mode = {
  455.             .name       = "EDT-QVGA-A",
  456.             .refresh    = 70,
  457.             .xres       = 320,
  458.             .yres       = 240,
  459.             .pixclock   = 133333, /* in ps (18,52 MHz) */
  460.             .hsync_len  = 40,
  461.             .left_margin    = 29,       /* h - front porch*/
  462.             .right_margin   = 55,       /* h - back porch*/
  463.             .vsync_len  = 3,
  464.             .upper_margin   = 16,       /* v - front porch*/
  465.             .lower_margin   = 7, //33   /* h - back porch*/
  466.         },
  467.         /* phytec */
  468.         .pcr = 0xFAE88080,
  469.         .bpp = 16,
  470.     },
  471.  
  472. };
  473.  
  474. static struct imx_fb_platform_data pca100_fb_data = {
  475.     .mode = pca100_modes,
  476.     .num_modes = ARRAY_SIZE(pca100_modes),
  477.  
  478.     .pwmr       = 0x00A903FF,
  479.     .lscr1      = 0x00120300,
  480.     .dmacr      = 0x00020010,
  481. };
  482.  
  483. static int isp1504_set_vbus_power(void __iomem *view, int on)
  484. {
  485.     int vid, pid, ret = 0;
  486.  
  487.     vid = (ulpi_read(ISP1504_VID_HIGH, view) << 8) |
  488.          ulpi_read(ISP1504_VID_LOW, view);
  489.  
  490.     /* the phy returns sometimes erroneous value in the firstread after
  491.      * resetting. The behaviour is not defined clearly in the datasheet.
  492.      * We do a double read here to make sure to work around this */
  493.     if (vid != 0x4cc)
  494.         vid = (ulpi_read(ISP1504_VID_HIGH, view) << 8) |
  495.             ulpi_read(ISP1504_VID_LOW, view);
  496.  
  497.     pid = (ulpi_read(ISP1504_PID_HIGH, view) << 8) |
  498.          ulpi_read(ISP1504_PID_LOW, view);
  499.  
  500.     pr_info("ULPI Vendor ID 0x%x    Product ID 0x%x\n", vid, pid);
  501.     if (vid != 0x4cc || pid != 0x1504) {
  502.         pr_err("No ISP1504 found\n");
  503.         return -1;
  504.     }
  505.  
  506.     if (on) {
  507.         ret = ulpi_set(DRV_VBUS_EXT |   /* enable external Vbus */
  508.                 DRV_VBUS |      /* enable internal Vbus */
  509.                 USE_EXT_VBUS_IND |  /* use external indicator */
  510.                 CHRG_VBUS,      /* charge Vbus */
  511.                 ISP1504_OTGCTL, view);
  512.     } else {
  513.         ret = ulpi_clear(DRV_VBUS_EXT | /* disable external Vbus */
  514.                   DRV_VBUS,     /* disable internal Vbus */
  515.                   ISP1504_OTGCTL, view);
  516.  
  517.         ret |= ulpi_set(USE_EXT_VBUS_IND | /* use external indicator */
  518.                 DISCHRG_VBUS,      /* discharge Vbus */
  519.                 ISP1504_OTGCTL, view);
  520.     }
  521.  
  522.     return ret;
  523. }
  524.  
  525. static int pca100_usbh2_init(struct platform_device *pdev)
  526. {
  527.     int ret;
  528.     uint32_t temp;
  529.  
  530.     ret = gpio_request(GPIO_PORTB + 24, "usb-host-cs");
  531.     if (ret)
  532.         return ret;
  533.     /* disable phy chip select */
  534.     gpio_direction_output(GPIO_PORTB + 24, 1);
  535.  
  536.     temp = readl(IO_ADDRESS(OTG_BASE_ADDR) + 0x600);
  537.     temp &= ~((3 << 21) | 1);
  538.     temp |= (1 << 5) | (1 << 16) | (1 << 19) | (1 << 11) | (1 << 20);
  539.     writel(temp, IO_ADDRESS(OTG_BASE_ADDR) + 0x600);
  540.  
  541.     temp = readl(IO_ADDRESS(OTG_BASE_ADDR) + 0x584);
  542.     temp &= ~(3 << 30);
  543.     temp |= 2 << 30;
  544.     writel(temp, IO_ADDRESS(OTG_BASE_ADDR) + 0x584);
  545.  
  546.     mdelay(10);
  547.  
  548.     /* enable phy */
  549.     gpio_set_value(GPIO_PORTB + 24, 0);
  550.     udelay(10);
  551.  
  552.     ret = isp1504_set_vbus_power(IO_ADDRESS(OTG_BASE_ADDR + 0x570), 1);
  553.     if (ret)
  554.         printk(KERN_ERR "pca100: Failed to enable usbh2 phy (%d)\n", ret);
  555.  
  556.     return ret;
  557. }
  558.  
  559. static struct mxc_usbh_platform_data ehci2_pdata = {
  560.     .init = pca100_usbh2_init,
  561. };
  562.  
  563. static int pca100_otg_phy_cs_req_setval(int cs_value)
  564. {
  565.     int ret;
  566.  
  567.     ret = gpio_request(GPIO_PORTB + 23, "usb-otg-cs");
  568.     if (ret)
  569.         return ret;
  570.  
  571.     gpio_direction_output(GPIO_PORTB + 23, cs_value);
  572.  
  573.     return 0;
  574. }
  575.  
  576. static int pca100_otg_init(struct platform_device *pdev)
  577. {
  578.     int ret;
  579.     unsigned int tmp;
  580.  
  581.     /* request phy /cs line and disable it */
  582.     ret = pca100_otg_phy_cs_req_setval(1);
  583.     if (ret)
  584.         return ret;
  585.  
  586.     tmp = readl(IO_ADDRESS(OTG_BASE_ADDR) + 0x600);
  587.     tmp &= ~((3 << 29) | 1);
  588.     tmp |= (1 << 28) | (1 << 27) | (1 << 24);
  589.     writel(tmp, IO_ADDRESS(OTG_BASE_ADDR) + 0x600);
  590.  
  591.     tmp = readl(IO_ADDRESS(OTG_BASE_ADDR) + 0x184);
  592.     tmp &= ~(3 << 30);
  593.     tmp |= 2 << 30;
  594.  
  595.     writel(tmp, IO_ADDRESS(OTG_BASE_ADDR) + 0x184);
  596.  
  597.     mdelay(10);
  598.  
  599.     /* enable phy */
  600.     gpio_set_value(GPIO_PORTB + 23, 0);
  601.     udelay(10);
  602.  
  603.     ret = isp1504_set_vbus_power(IO_ADDRESS(OTG_BASE_ADDR + 0x170), 1);
  604.     if (ret)
  605.         printk(KERN_ERR "pca100: Failed to enable otg phy (%d)\n", ret);
  606.  
  607.     return ret;
  608. }
  609.  
  610. static struct mxc_usbh_platform_data otg_host_pdata = {
  611.     .init = pca100_otg_init,
  612. };
  613.  
  614. static struct fsl_usb2_platform_data otg_device_pdata = {
  615.     .operating_mode = FSL_USB2_DR_DEVICE,
  616.     .phy_mode   = FSL_USB2_PHY_ULPI,
  617. };
  618.  
  619. #if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
  620. static struct spi_eeprom at25320 = {
  621.     .name       = "at25320an",
  622.     .byte_len   = 4096,
  623.     .page_size  = 32,
  624.     .flags      = EE_ADDR2,
  625. };
  626.  
  627. #if defined(CONFIG_CAN_MCP251X) || defined(CONFIG_CAN_MCP251X_MODULE)
  628. static struct mcp251x_platform_data mcp251x_info = {
  629.     .oscillator_frequency = 16000000,
  630.     .model = CAN_MCP251X_MCP2510,
  631.     .power_enable = NULL,
  632.     .transceiver_enable = NULL,
  633. };
  634. #endif
  635.  
  636. static struct spi_board_info pca100_spi_board_info[] __initdata = {
  637. #if defined(CONFIG_CAN_MCP251X) || defined(CONFIG_CAN_MCP251X_MODULE)
  638.     {
  639.         .modalias = "mcp251x",
  640.         .max_speed_hz = 2*1000*1000,
  641.         .bus_num = 0,
  642.         .chip_select = 0,
  643.         .platform_data = &mcp251x_info,
  644.         .irq = IRQ_GPIOC(29),
  645.     },
  646. #else
  647.     {
  648.         .modalias = "at25",
  649.         .max_speed_hz = 30000,
  650.         .bus_num = 0,
  651.         .chip_select = 1,
  652.         .platform_data = &at25320,
  653.     },
  654. #endif
  655.     {
  656.         .modalias = "at25",
  657.         .max_speed_hz = 30000,
  658.         .bus_num = 0,
  659.         .chip_select = 1,
  660.         .platform_data = &at25320,
  661.     },
  662. };
  663.  
  664. static int pca100_spi_cs[] = {GPIO_PORTD + 28, GPIO_PORTD + 27};
  665.  
  666. static struct spi_imx_master pca100_spi_0_data = {
  667.     .chipselect = pca100_spi_cs,
  668.     .num_chipselect = ARRAY_SIZE(pca100_spi_cs),
  669. };
  670. #endif
  671.  
  672. static int pca100_sdhc2_init(struct device *dev, irq_handler_t detect_irq,
  673.         void *data)
  674. {
  675.     int ret;
  676.  
  677.     ret = request_irq(IRQ_GPIOC(29), detect_irq,
  678.               IRQF_DISABLED | IRQF_TRIGGER_FALLING,
  679.               "imx-mmc-detect", data);
  680.     if (ret)
  681.         printk(KERN_ERR
  682.             "pca100: Failed to reuest irq for sd/mmc detection\n");
  683.  
  684.     return ret;
  685. }
  686.  
  687. static void pca100_sdhc2_exit(struct device *dev, void *data)
  688. {
  689.     free_irq(IRQ_GPIOC(29), data);
  690. }
  691.  
  692. static struct imxmmc_platform_data sdhc_pdata = {
  693.     .init = pca100_sdhc2_init,
  694.     .exit = pca100_sdhc2_exit,
  695. };
  696.  
  697. static void pca100_ac97_warm_reset(struct snd_ac97 *ac97)
  698. {
  699.     printk("%s\n", __func__);
  700.  
  701.     mxc_gpio_mode(GPIO_PORTC | 20 | GPIO_GPIO | GPIO_OUT);
  702.     gpio_set_value(GPIO_PORTC + 20, 1);
  703.     udelay(2);
  704.     gpio_set_value(GPIO_PORTC + 20, 0);
  705.     mxc_gpio_mode(PC20_PF_SSI1_FS);
  706.     msleep(2);
  707. }
  708.  
  709. static void pca100_ac97_cold_reset(struct snd_ac97 *ac97)
  710. {
  711.     printk("%s\n", __func__);
  712.  
  713.     mxc_gpio_mode(GPIO_PORTC | 20 | GPIO_GPIO | GPIO_OUT);  /* FS */
  714.     gpio_set_value(GPIO_PORTC + 20, 0);
  715.     mxc_gpio_mode(GPIO_PORTC | 22 | GPIO_GPIO | GPIO_OUT);  /* TX */
  716.     gpio_set_value(GPIO_PORTC + 22, 0);
  717.     mxc_gpio_mode(GPIO_PORTC | 28 | GPIO_GPIO | GPIO_OUT);  /* reset */
  718.     gpio_set_value(GPIO_PORTC + 28, 0);
  719.     udelay(10);
  720.     gpio_set_value(GPIO_PORTC + 28, 1);
  721.     mxc_gpio_mode(PC20_PF_SSI1_FS);
  722.     mxc_gpio_mode(PC22_PF_SSI1_TXD);
  723.     msleep(2);
  724. }
  725.  
  726. static struct imx_ssi_platform_data pca100_ssi_pdata = {
  727.     .ac97_reset     = pca100_ac97_cold_reset,
  728.     .ac97_warm_reset    = pca100_ac97_warm_reset,
  729.     .flags          = IMX_SSI_USE_AC97,
  730. };
  731.  
  732. static int otg_mode_host;
  733.  
  734. static int __init pca100_otg_mode(char *options)
  735. {
  736.     if (!strcmp(options, "host"))
  737.         otg_mode_host = 1;
  738.     else if (!strcmp(options, "device"))
  739.         otg_mode_host = 0;
  740.     else
  741.         pr_info("pca100_otg_mode neither \"host\" nor \"device\". "
  742.             "Defaulting to device\n");
  743.     return 0;
  744. }
  745. __setup("pca100_otg_mode=", pca100_otg_mode);
  746.  
  747. static void __init pca100_init(void)
  748. {
  749.     int ret;
  750.  
  751.     /* SSI unit */
  752.     mxc_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
  753.                   MXC_AUDMUX_V1_PCR_SYN | /* 4wire mode */
  754.                   MXC_AUDMUX_V1_PCR_TFCSEL(3) |
  755.                   MXC_AUDMUX_V1_PCR_TCLKDIR | /* clock is output */
  756.                   MXC_AUDMUX_V1_PCR_RXDSEL(3));
  757.     mxc_audmux_v1_configure_port(4,
  758.                   MXC_AUDMUX_V1_PCR_SYN | /* 4wire mode */
  759.                   MXC_AUDMUX_V1_PCR_TFCSEL(0) |
  760.                   MXC_AUDMUX_V1_PCR_TFSDIR |
  761.                   MXC_AUDMUX_V1_PCR_RXDSEL(0));
  762.  
  763.     ret = mxc_gpio_setup_multiple_pins(pca100_pins,
  764.             ARRAY_SIZE(pca100_pins), "PCA100");
  765.     if (ret)
  766.         printk(KERN_ERR "pca100: Failed to setup pins (%d)\n", ret);
  767.  
  768.     mxc_register_device(&imx_ssi_device0, &pca100_ssi_pdata);
  769.  
  770.     mxc_register_device(&mxc_fb_device, &pca100_fb_data);
  771.  
  772.     mxc_register_device(&mxc_uart_device0, &uart_pdata);
  773.  
  774.     mxc_gpio_mode(GPIO_PORTC | 29 | GPIO_GPIO | GPIO_IN);
  775.     mxc_register_device(&mxc_sdhc_device1, &sdhc_pdata);
  776.  
  777.     mxc_register_device(&mxc_nand_device, &pca100_nand_board_info);
  778.  
  779.     /* only the i2c master 1 is used on this CPU card */
  780.     i2c_register_board_info(0, pca100_i2c_devices,
  781.                 ARRAY_SIZE(pca100_i2c_devices));
  782.  
  783.     mxc_register_device(&mxc_i2c_device1, &pca100_i2c_1_data);
  784.  
  785.     /* the first i2c master is used for devices on the baseboard */
  786.     i2c_register_board_info(0, pca100_base_i2c_devices,
  787.                 ARRAY_SIZE(pca100_base_i2c_devices));
  788.  
  789.     mxc_register_device(&mxc_i2c_device0, &pca100_i2c_0_data);
  790.  
  791.     /* cs on usbh2 phy */
  792.     mxc_gpio_mode((GPIO_PORTB | 24) | GPIO_GPIO | GPIO_OUT);
  793.     mxc_register_device(&mxc_ehci2, &ehci2_pdata);
  794.  
  795.     /* cs on otg phy */
  796.     mxc_gpio_mode((GPIO_PORTB | 23) | GPIO_GPIO | GPIO_OUT);
  797.     if (otg_mode_host)
  798.         mxc_register_device(&mxc_otg, &otg_host_pdata);
  799.     else {
  800.         /* enable phy by pulling down /cs line */
  801.         ret = pca100_otg_phy_cs_req_setval(0);
  802.         if (ret)
  803.             printk(KERN_ERR "pca100: Failed to enable otg phy\n");
  804.  
  805.         mxc_register_device(&otg_udc_device, &otg_device_pdata);
  806.     }
  807.  
  808.     mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_OUT);
  809.     mxc_gpio_mode(GPIO_PORTD | 27 | GPIO_GPIO | GPIO_OUT);
  810.  
  811.     /* GPIO0_IRQ */
  812.     //mxc_gpio_mode(GPIO_PORTC | 31 | GPIO_GPIO | GPIO_IN);
  813.     /* GPIO1_IRQ */
  814.     mxc_gpio_mode(GPIO_PORTC | 25 | GPIO_GPIO | GPIO_IN);
  815.     /* Backlight */
  816.     //mxc_gpio_mode(GPIO_PORTE | 5 | GPIO_GPIO | GPIO_OUT);
  817.  
  818.         //gpio_request (GPIO_PORTE + 5, "backlight");
  819.         //gpio_direction_output (GPIO_PORTE + 5, 1);
  820.  
  821. #if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
  822.     spi_register_board_info(pca100_spi_board_info,
  823.                 ARRAY_SIZE(pca100_spi_board_info));
  824.     mxc_register_device(&mxc_spi_device0, &pca100_spi_0_data);
  825. #endif
  826.  
  827.     platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
  828. }
  829.  
  830. static void __init pca100_timer_init(void)
  831. {
  832.     mx27_clocks_init(26000000);
  833. }
  834.  
  835. static struct sys_timer pca100_timer = {
  836.     .init = pca100_timer_init,
  837. };
  838.  
  839. MACHINE_START(PCA100, "phyCARD-i.MX27")
  840.     .phys_io        = AIPI_BASE_ADDR,
  841.     .io_pg_offst    = ((AIPI_BASE_ADDR_VIRT) >> 18) & 0xfffc,
  842.     .boot_params    = PHYS_OFFSET + 0x100,
  843.     .map_io         = mx27_map_io,
  844.     .init_irq       = mxc_init_irq,
  845.     .init_machine   = pca100_init,
  846.     .timer          = &pca100_timer,
  847. MACHINE_END
  848.  
  849. /*
  850.  * Ok, we have to deal with several situations here. We connect
  851.  * 10bit image sensors to a 8bit interface and we must make sure
  852.  * that the upper 8bit from the sensor are connected to the image
  853.  * interface. Some sensors have a i2c GPIO expander which controls
  854.  * a bus switch to fixup the routing. Mapper boards >= 1285.2 do
  855.  * the fixup without the need of a gpio switch.
  856.  * Set this parameter to '1' to use a camera with gpio switch on a
  857.  * newer mapper board to prevent the fixup being done twice.
  858.  */
  859. static int use_camera_gpio;
  860. core_param(use_camera_gpio, use_camera_gpio, int, 0444);
  861.  
  862. static int __init pca100_baseboard_init_late(void)
  863. {
  864.         int ret;
  865.  
  866.         if (!machine_is_pca100())
  867.                 return 0;
  868.  
  869.         ret = gpio_request(MAX_INTERNAL_GPIO, "camera");
  870.         if (!ret) {
  871.                 printk(KERN_INFO "pca100 camera: Found GPIO expander on camera, %s using it\n",
  872.                                 use_camera_gpio ? "" : "not");
  873.                 gpio_direction_output(MAX_INTERNAL_GPIO, !!use_camera_gpio);
  874.         } else
  875.                 printk(KERN_INFO "pca100 camera: No GPIO expander on camera found\n");
  876.  
  877.         /* Be sure this registers after the regulators */
  878.         mxc_register_device(&mx27_camera_device, &camera_pdata);
  879.  
  880.     /*Switch Backligth on*/
  881.     gpio_set_value (GPIO_PORTE + 5, 0);
  882.         return 0;
  883. }
  884. late_initcall(pca100_baseboard_init_late);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement