imx6 gpio分析

本文主要介绍如何配置IOMUX寄存器,设置IO复用寄存器,配置为GPIO功能。
参考:
  http://www.jianshu.com/p/3c2053508342
  http://www.embest-tech.com/community/index.php?topic=2822.0

查看板级文件 kernel/arch/arm/mach-mx6/board_mx6q_sabresd.c MACHINE_START(MX6Q_SABRESD, "Freescale i.MX 6Quad/DualLite/Solo Sabre-SD Board") /* Maintainer: Freescale Semiconductor, Inc. */ .boot_params = MX6_PHYS_OFFSET + 0x100, .fixup = fixup_mxc_board, .map_io = mx6_map_io, .init_irq = mx6_init_irq, .init_machine = mx6_sabresd_board_init,    //-------------------------------->>> mx6_sabresd_board_init .timer = &mx6_sabresd_timer, .reserve = mx6q_sabresd_reserve, MACHINE_END static void __init mx6_sabresd_board_init(void)  //<<<-------------------------------- mx6_sabresd_board_init { ... ... //这里这里已经将大部分寄存器都进行了配置。 if (cpu_is_mx6q()) mxc_iomux_v3_setup_multiple_pads(mx6q_sabresd_pads,    // ------------------>>> mxc_iomux_v3_setup_multiple_pads ARRAY_SIZE(mx6q_sabresd_pads));             // ----------------->>> mx6q_sabresd_pads else if (cpu_is_mx6dl()) { mxc_iomux_v3_setup_multiple_pads(mx6dl_sabresd_pads, ARRAY_SIZE(mx6dl_sabresd_pads)); } ... ... }
mx6q_sabresd_pads结构体。 kernel
/arch/arm/mach-mx6/board_mx6q_sabresd.h static iomux_v3_cfg_t mx6q_sabresd_pads[] = {          // <<<--------------------- mx6q_sabresd_pads /* AUDMUX */ MX6Q_PAD_CSI0_DAT4__AUDMUX_AUD3_TXC, MX6Q_PAD_CSI0_DAT5__AUDMUX_AUD3_TXD, MX6Q_PAD_CSI0_DAT6__AUDMUX_AUD3_TXFS, MX6Q_PAD_CSI0_DAT7__AUDMUX_AUD3_RXD, MX6Q_PAD_SD1_DAT1__GPIO_1_17, /* FT5X06 RESET */ MX6Q_PAD_NANDF_CS3__GPIO_6_16, //FT5X06_INT ... ... }
文件:kernel/arch/arm/plat-mxc/include/mach/iomux-mx6q.h 以MX6Q_PAD_SD1_DAT1__GPIO_1_17举例。
//MX6Q_PAD_SD1_DAT1表示寄存器,表示IOMUXC_IOMUXC_SW_MUX_CTL_PAD_SD1_DAT1。芯片手册2160页。
//后面的GPIO_1_17表示将该引脚复用为GPIO17.
//0x0724,0x003c表示寄存器地址的偏移量。具体查看上面的参考链接和芯片手册。
#define MX6Q_PAD_SD1_DAT1__GPIO_1_17 \ (_MX6Q_PAD_SD1_DAT1__GPIO_1_17 | MUX_PAD_CTRL(MX6Q_HIGH_DRV)) #define _MX6Q_PAD_SD1_DAT1__GPIO_1_17 \ IOMUX_PAD(0x0724, 0x033C, 5, 0x0000, 0, 0) #define MUX_PAD_CTRL(x) ((iomux_v3_cfg_t)(x) << MUX_PAD_CTRL_SHIFT)

  #define _MX6Q_PAD_SD2_DAT1__USDHC2_DAT1 \
          IOMUX_PAD(0x0360, 0x004C, 0, 0x0000, 0, 0)
  #define _MX6Q_PAD_SD2_DAT1__ECSPI5_SS0 \
         IOMUX_PAD(0x0360, 0x004C, 1, 0x0834, 0, 0)
  #define _MX6Q_PAD_SD2_DAT1__WEIM_WEIM_CS_2 \
      IOMUX_PAD(0x0360, 0x004C, 2, 0x0000, 0, 0)
  #define _MX6Q_PAD_SD2_DAT1__AUDMUX_AUD4_TXFS \
      IOMUX_PAD(0x0360, 0x004C, 3, 0x07C8, 0, 0)
  #define _MX6Q_PAD_SD2_DAT1__KPP_COL_7 \
      IOMUX_PAD(0x0360, 0x004C, 4, 0x08F0, 0, 0)
  #define _MX6Q_PAD_SD2_DAT1__GPIO_1_14 \
      IOMUX_PAD(0x0360, 0x004C, 5, 0x0000, 0, 0)
  #define _MX6Q_PAD_SD2_DAT1__CCM_WAIT \
      IOMUX_PAD(0x0360, 0x004C, 6, 0x0000, 0, 0)
  #define _MX6Q_PAD_SD2_DAT1__ANATOP_ANATOP_TESTO_0 \
      IOMUX_PAD(0x0360, 0x004C, 7, 0x0000, 0, 0)


文件:kernel/arch/arm/plat-mxc/include/mach/iomux-v3.h #define IOMUX_PAD(_pad_ctrl_ofs, _mux_ctrl_ofs, _mux_mode, _sel_input_ofs, \ _sel_input, _pad_ctrl) \ (((iomux_v3_cfg_t)(_mux_ctrl_ofs) << MUX_CTRL_OFS_SHIFT) | \ ((iomux_v3_cfg_t)(_mux_mode) << MUX_MODE_SHIFT) | \ ((iomux_v3_cfg_t)(_pad_ctrl_ofs) << MUX_PAD_CTRL_OFS_SHIFT) | \ ((iomux_v3_cfg_t)(_pad_ctrl) << MUX_PAD_CTRL_SHIFT) | \ ((iomux_v3_cfg_t)(_sel_input_ofs) << MUX_SEL_INPUT_OFS_SHIFT) | \ ((iomux_v3_cfg_t)(_sel_input) << MUX_SEL_INPUT_SHIFT))

int mxc_iomux_v3_setup_multiple_pads(iomux_v3_cfg_t *pad_list, unsigned count)   // <<<-------- mxc_iomux_v3_setup_multiple_pads() { iomux_v3_cfg_t *p = pad_list; int i; int ret; for (i = 0; i < count; i++) { ret = mxc_iomux_v3_setup_pad(*p);          // ------------------------------>>> mxc_iomux_v3_setup_pad() if (ret) return ret; p++; } return 0; } EXPORT_SYMBOL(mxc_iomux_v3_setup_multiple_pads); /* 将定义的宏解析,提取其中数据,设置到寄存器中 */ int mxc_iomux_v3_setup_pad(iomux_v3_cfg_t pad)       // <<<---------------------------- mxc_iomux_v3_setup_pad() { u32 mux_ctrl_ofs = (pad & MUX_CTRL_OFS_MASK) >> MUX_CTRL_OFS_SHIFT; u32 mux_mode = (pad & MUX_MODE_MASK) >> MUX_MODE_SHIFT; u32 sel_input_ofs = (pad & MUX_SEL_INPUT_OFS_MASK) >> MUX_SEL_INPUT_OFS_SHIFT; u32 sel_input = (pad & MUX_SEL_INPUT_MASK) >> MUX_SEL_INPUT_SHIFT; u32 pad_ctrl_ofs = (pad & MUX_PAD_CTRL_OFS_MASK) >> MUX_PAD_CTRL_OFS_SHIFT; u32 pad_ctrl = (pad & MUX_PAD_CTRL_MASK) >> MUX_PAD_CTRL_SHIFT; if (mux_ctrl_ofs) __raw_writel(mux_mode, base + mux_ctrl_ofs); if (sel_input_ofs) __raw_writel(sel_input, base + sel_input_ofs); if (!(pad_ctrl & NO_PAD_CTRL) && pad_ctrl_ofs) __raw_writel(pad_ctrl, base + pad_ctrl_ofs); return 0; } EXPORT_SYMBOL(mxc_iomux_v3_setup_pad);

 

posted @ 2016-04-11 17:57  SuperTao1024  阅读(2753)  评论(0编辑  收藏  举报