Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | b473ec5 | 2011-11-08 23:18:11 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2004-2006,2010 Freescale Semiconductor, Inc. All Rights Reserved. |
| 4 | * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de> |
| 5 | * Copyright (C) 2009 by Jan Weitzel Phytec Messtechnik GmbH, |
| 6 | * <armlinux@phytec.de> |
Marek Vasut | b473ec5 | 2011-11-08 23:18:11 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 9 | #include <linux/errno.h> |
Marek Vasut | b473ec5 | 2011-11-08 23:18:11 +0000 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <asm/arch/clock.h> |
| 12 | #include <asm/arch/iomux.h> |
| 13 | #include <asm/arch/imx-regs.h> |
| 14 | |
| 15 | #if defined(CONFIG_MX23) |
| 16 | #define DRIVE_OFFSET 0x200 |
| 17 | #define PULL_OFFSET 0x400 |
| 18 | #elif defined(CONFIG_MX28) |
| 19 | #define DRIVE_OFFSET 0x300 |
| 20 | #define PULL_OFFSET 0x600 |
| 21 | #else |
| 22 | #error "Please select CONFIG_MX23 or CONFIG_MX28" |
| 23 | #endif |
| 24 | |
| 25 | /* |
| 26 | * configures a single pad in the iomuxer |
| 27 | */ |
| 28 | int mxs_iomux_setup_pad(iomux_cfg_t pad) |
| 29 | { |
| 30 | u32 reg, ofs, bp, bm; |
| 31 | void *iomux_base = (void *)MXS_PINCTRL_BASE; |
Otavio Salvador | 5309b00 | 2012-08-05 09:05:30 +0000 | [diff] [blame] | 32 | struct mxs_register_32 *mxs_reg; |
Marek Vasut | b473ec5 | 2011-11-08 23:18:11 +0000 | [diff] [blame] | 33 | |
| 34 | /* muxsel */ |
| 35 | ofs = 0x100; |
| 36 | ofs += PAD_BANK(pad) * 0x20 + PAD_PIN(pad) / 16 * 0x10; |
| 37 | bp = PAD_PIN(pad) % 16 * 2; |
| 38 | bm = 0x3 << bp; |
| 39 | reg = readl(iomux_base + ofs); |
| 40 | reg &= ~bm; |
| 41 | reg |= PAD_MUXSEL(pad) << bp; |
| 42 | writel(reg, iomux_base + ofs); |
| 43 | |
| 44 | /* drive */ |
| 45 | ofs = DRIVE_OFFSET; |
| 46 | ofs += PAD_BANK(pad) * 0x40 + PAD_PIN(pad) / 8 * 0x10; |
| 47 | /* mA */ |
| 48 | if (PAD_MA_VALID(pad)) { |
| 49 | bp = PAD_PIN(pad) % 8 * 4; |
| 50 | bm = 0x3 << bp; |
| 51 | reg = readl(iomux_base + ofs); |
| 52 | reg &= ~bm; |
| 53 | reg |= PAD_MA(pad) << bp; |
| 54 | writel(reg, iomux_base + ofs); |
| 55 | } |
| 56 | /* vol */ |
| 57 | if (PAD_VOL_VALID(pad)) { |
| 58 | bp = PAD_PIN(pad) % 8 * 4 + 2; |
Otavio Salvador | 5309b00 | 2012-08-05 09:05:30 +0000 | [diff] [blame] | 59 | mxs_reg = (struct mxs_register_32 *)(iomux_base + ofs); |
Marek Vasut | b473ec5 | 2011-11-08 23:18:11 +0000 | [diff] [blame] | 60 | if (PAD_VOL(pad)) |
| 61 | writel(1 << bp, &mxs_reg->reg_set); |
| 62 | else |
| 63 | writel(1 << bp, &mxs_reg->reg_clr); |
| 64 | } |
| 65 | |
| 66 | /* pull */ |
| 67 | if (PAD_PULL_VALID(pad)) { |
| 68 | ofs = PULL_OFFSET; |
| 69 | ofs += PAD_BANK(pad) * 0x10; |
| 70 | bp = PAD_PIN(pad); |
Otavio Salvador | 5309b00 | 2012-08-05 09:05:30 +0000 | [diff] [blame] | 71 | mxs_reg = (struct mxs_register_32 *)(iomux_base + ofs); |
Marek Vasut | b473ec5 | 2011-11-08 23:18:11 +0000 | [diff] [blame] | 72 | if (PAD_PULL(pad)) |
| 73 | writel(1 << bp, &mxs_reg->reg_set); |
| 74 | else |
| 75 | writel(1 << bp, &mxs_reg->reg_clr); |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | int mxs_iomux_setup_multiple_pads(const iomux_cfg_t *pad_list, unsigned count) |
| 82 | { |
| 83 | const iomux_cfg_t *p = pad_list; |
| 84 | int i; |
| 85 | int ret; |
| 86 | |
| 87 | for (i = 0; i < count; i++) { |
| 88 | ret = mxs_iomux_setup_pad(*p); |
| 89 | if (ret) |
| 90 | return ret; |
| 91 | p++; |
| 92 | } |
| 93 | |
| 94 | return 0; |
| 95 | } |