本文主要介绍如何配置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 ... ... } 以MX6Q_PAD_SD1_DAT1__GPIO_1_17举例。 #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 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);
时间: 2024-10-27 12:30:27