Blame view
arch/arm/mach-tegra/pinmux.c
23.6 KB
a4417c845 [ARM] tegra: add ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
/* * linux/arch/arm/mach-tegra/pinmux.c * * Copyright (C) 2010 Google, Inc. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and * may be copied, distributed, and modified under those terms. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ |
c5f04b8d1 [ARM] tegra: pinm... |
16 17 |
#include <linux/init.h> #include <linux/module.h> |
a4417c845 [ARM] tegra: add ... |
18 19 20 21 |
#include <linux/kernel.h> #include <linux/errno.h> #include <linux/spinlock.h> #include <linux/io.h> |
1ebc8496e arm/tegra: Conver... |
22 |
#include <linux/platform_device.h> |
6996e0858 arm/tegra: prepar... |
23 |
#include <linux/of_device.h> |
a4417c845 [ARM] tegra: add ... |
24 25 26 |
#include <mach/iomap.h> #include <mach/pinmux.h> |
a4417c845 [ARM] tegra: add ... |
27 28 29 30 31 32 33 |
#define HSM_EN(reg) (((reg) >> 2) & 0x1) #define SCHMT_EN(reg) (((reg) >> 3) & 0x1) #define LPMD(reg) (((reg) >> 4) & 0x3) #define DRVDN(reg) (((reg) >> 12) & 0x1f) #define DRVUP(reg) (((reg) >> 20) & 0x1f) #define SLWR(reg) (((reg) >> 28) & 0x3) #define SLWF(reg) (((reg) >> 30) & 0x3) |
6996e0858 arm/tegra: prepar... |
34 35 36 37 |
static const struct tegra_pingroup_desc *pingroups; static const struct tegra_drive_pingroup_desc *drive_pingroups; static int pingroup_max; static int drive_max; |
a4417c845 [ARM] tegra: add ... |
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
static char *tegra_mux_names[TEGRA_MAX_MUX] = { [TEGRA_MUX_AHB_CLK] = "AHB_CLK", [TEGRA_MUX_APB_CLK] = "APB_CLK", [TEGRA_MUX_AUDIO_SYNC] = "AUDIO_SYNC", [TEGRA_MUX_CRT] = "CRT", [TEGRA_MUX_DAP1] = "DAP1", [TEGRA_MUX_DAP2] = "DAP2", [TEGRA_MUX_DAP3] = "DAP3", [TEGRA_MUX_DAP4] = "DAP4", [TEGRA_MUX_DAP5] = "DAP5", [TEGRA_MUX_DISPLAYA] = "DISPLAYA", [TEGRA_MUX_DISPLAYB] = "DISPLAYB", [TEGRA_MUX_EMC_TEST0_DLL] = "EMC_TEST0_DLL", [TEGRA_MUX_EMC_TEST1_DLL] = "EMC_TEST1_DLL", [TEGRA_MUX_GMI] = "GMI", [TEGRA_MUX_GMI_INT] = "GMI_INT", [TEGRA_MUX_HDMI] = "HDMI", [TEGRA_MUX_I2C] = "I2C", [TEGRA_MUX_I2C2] = "I2C2", [TEGRA_MUX_I2C3] = "I2C3", [TEGRA_MUX_IDE] = "IDE", [TEGRA_MUX_IRDA] = "IRDA", [TEGRA_MUX_KBC] = "KBC", [TEGRA_MUX_MIO] = "MIO", [TEGRA_MUX_MIPI_HS] = "MIPI_HS", [TEGRA_MUX_NAND] = "NAND", [TEGRA_MUX_OSC] = "OSC", [TEGRA_MUX_OWR] = "OWR", [TEGRA_MUX_PCIE] = "PCIE", [TEGRA_MUX_PLLA_OUT] = "PLLA_OUT", [TEGRA_MUX_PLLC_OUT1] = "PLLC_OUT1", [TEGRA_MUX_PLLM_OUT1] = "PLLM_OUT1", [TEGRA_MUX_PLLP_OUT2] = "PLLP_OUT2", [TEGRA_MUX_PLLP_OUT3] = "PLLP_OUT3", [TEGRA_MUX_PLLP_OUT4] = "PLLP_OUT4", [TEGRA_MUX_PWM] = "PWM", [TEGRA_MUX_PWR_INTR] = "PWR_INTR", [TEGRA_MUX_PWR_ON] = "PWR_ON", [TEGRA_MUX_RTCK] = "RTCK", [TEGRA_MUX_SDIO1] = "SDIO1", [TEGRA_MUX_SDIO2] = "SDIO2", [TEGRA_MUX_SDIO3] = "SDIO3", [TEGRA_MUX_SDIO4] = "SDIO4", [TEGRA_MUX_SFLASH] = "SFLASH", [TEGRA_MUX_SPDIF] = "SPDIF", [TEGRA_MUX_SPI1] = "SPI1", [TEGRA_MUX_SPI2] = "SPI2", [TEGRA_MUX_SPI2_ALT] = "SPI2_ALT", [TEGRA_MUX_SPI3] = "SPI3", [TEGRA_MUX_SPI4] = "SPI4", [TEGRA_MUX_TRACE] = "TRACE", [TEGRA_MUX_TWC] = "TWC", [TEGRA_MUX_UARTA] = "UARTA", [TEGRA_MUX_UARTB] = "UARTB", [TEGRA_MUX_UARTC] = "UARTC", [TEGRA_MUX_UARTD] = "UARTD", [TEGRA_MUX_UARTE] = "UARTE", [TEGRA_MUX_ULPI] = "ULPI", [TEGRA_MUX_VI] = "VI", [TEGRA_MUX_VI_SENSOR_CLK] = "VI_SENSOR_CLK", [TEGRA_MUX_XIO] = "XIO", |
241682c8e arm/tegra: pinmux... |
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
[TEGRA_MUX_BLINK] = "BLINK", [TEGRA_MUX_CEC] = "CEC", [TEGRA_MUX_CLK12] = "CLK12", [TEGRA_MUX_DAP] = "DAP", [TEGRA_MUX_DAPSDMMC2] = "DAPSDMMC2", [TEGRA_MUX_DDR] = "DDR", [TEGRA_MUX_DEV3] = "DEV3", [TEGRA_MUX_DTV] = "DTV", [TEGRA_MUX_VI_ALT1] = "VI_ALT1", [TEGRA_MUX_VI_ALT2] = "VI_ALT2", [TEGRA_MUX_VI_ALT3] = "VI_ALT3", [TEGRA_MUX_EMC_DLL] = "EMC_DLL", [TEGRA_MUX_EXTPERIPH1] = "EXTPERIPH1", [TEGRA_MUX_EXTPERIPH2] = "EXTPERIPH2", [TEGRA_MUX_EXTPERIPH3] = "EXTPERIPH3", [TEGRA_MUX_GMI_ALT] = "GMI_ALT", [TEGRA_MUX_HDA] = "HDA", [TEGRA_MUX_HSI] = "HSI", [TEGRA_MUX_I2C4] = "I2C4", [TEGRA_MUX_I2C5] = "I2C5", [TEGRA_MUX_I2CPWR] = "I2CPWR", [TEGRA_MUX_I2S0] = "I2S0", [TEGRA_MUX_I2S1] = "I2S1", [TEGRA_MUX_I2S2] = "I2S2", [TEGRA_MUX_I2S3] = "I2S3", [TEGRA_MUX_I2S4] = "I2S4", [TEGRA_MUX_NAND_ALT] = "NAND_ALT", [TEGRA_MUX_POPSDIO4] = "POPSDIO4", [TEGRA_MUX_POPSDMMC4] = "POPSDMMC4", [TEGRA_MUX_PWM0] = "PWM0", [TEGRA_MUX_PWM1] = "PWM2", [TEGRA_MUX_PWM2] = "PWM2", [TEGRA_MUX_PWM3] = "PWM3", [TEGRA_MUX_SATA] = "SATA", [TEGRA_MUX_SPI5] = "SPI5", [TEGRA_MUX_SPI6] = "SPI6", [TEGRA_MUX_SYSCLK] = "SYSCLK", [TEGRA_MUX_VGP1] = "VGP1", [TEGRA_MUX_VGP2] = "VGP2", [TEGRA_MUX_VGP3] = "VGP3", [TEGRA_MUX_VGP4] = "VGP4", [TEGRA_MUX_VGP5] = "VGP5", [TEGRA_MUX_VGP6] = "VGP6", |
c5f04b8d1 [ARM] tegra: pinm... |
143 |
[TEGRA_MUX_SAFE] = "<safe>", |
a4417c845 [ARM] tegra: add ... |
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
}; static const char *tegra_drive_names[TEGRA_MAX_DRIVE] = { [TEGRA_DRIVE_DIV_8] = "DIV_8", [TEGRA_DRIVE_DIV_4] = "DIV_4", [TEGRA_DRIVE_DIV_2] = "DIV_2", [TEGRA_DRIVE_DIV_1] = "DIV_1", }; static const char *tegra_slew_names[TEGRA_MAX_SLEW] = { [TEGRA_SLEW_FASTEST] = "FASTEST", [TEGRA_SLEW_FAST] = "FAST", [TEGRA_SLEW_SLOW] = "SLOW", [TEGRA_SLEW_SLOWEST] = "SLOWEST", }; static DEFINE_SPINLOCK(mux_lock); |
6996e0858 arm/tegra: prepar... |
161 |
static const char *pingroup_name(int pg) |
a4417c845 [ARM] tegra: add ... |
162 |
{ |
6996e0858 arm/tegra: prepar... |
163 |
if (pg < 0 || pg >= pingroup_max) |
a4417c845 [ARM] tegra: add ... |
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
return "<UNKNOWN>"; return pingroups[pg].name; } static const char *func_name(enum tegra_mux_func func) { if (func == TEGRA_MUX_RSVD1) return "RSVD1"; if (func == TEGRA_MUX_RSVD2) return "RSVD2"; if (func == TEGRA_MUX_RSVD3) return "RSVD3"; if (func == TEGRA_MUX_RSVD4) return "RSVD4"; if (func == TEGRA_MUX_NONE) return "NONE"; if (func < 0 || func >= TEGRA_MAX_MUX) return "<UNKNOWN>"; return tegra_mux_names[func]; } static const char *tri_name(unsigned long val) { return val ? "TRISTATE" : "NORMAL"; } static const char *pupd_name(unsigned long val) { switch (val) { case 0: return "NORMAL"; case 1: return "PULL_DOWN"; case 2: return "PULL_UP"; default: return "RSVD"; } } |
48f2eceef arm/tegra: pinmux... |
214 215 |
static int nbanks; static void __iomem **regs; |
a4417c845 [ARM] tegra: add ... |
216 |
|
48f2eceef arm/tegra: pinmux... |
217 |
static inline u32 pg_readl(u32 bank, u32 reg) |
a4417c845 [ARM] tegra: add ... |
218 |
{ |
48f2eceef arm/tegra: pinmux... |
219 |
return readl(regs[bank] + reg); |
a4417c845 [ARM] tegra: add ... |
220 |
} |
48f2eceef arm/tegra: pinmux... |
221 |
static inline void pg_writel(u32 val, u32 bank, u32 reg) |
a4417c845 [ARM] tegra: add ... |
222 |
{ |
48f2eceef arm/tegra: pinmux... |
223 |
writel(val, regs[bank] + reg); |
a4417c845 [ARM] tegra: add ... |
224 |
} |
c5f04b8d1 [ARM] tegra: pinm... |
225 |
static int tegra_pinmux_set_func(const struct tegra_pingroup_config *config) |
a4417c845 [ARM] tegra: add ... |
226 227 228 229 230 |
{ int mux = -1; int i; unsigned long reg; unsigned long flags; |
6996e0858 arm/tegra: prepar... |
231 |
int pg = config->pingroup; |
c5f04b8d1 [ARM] tegra: pinm... |
232 |
enum tegra_mux_func func = config->func; |
a4417c845 [ARM] tegra: add ... |
233 |
|
6996e0858 arm/tegra: prepar... |
234 |
if (pg < 0 || pg >= pingroup_max) |
a4417c845 [ARM] tegra: add ... |
235 |
return -ERANGE; |
c5f04b8d1 [ARM] tegra: pinm... |
236 |
if (pingroups[pg].mux_reg < 0) |
a4417c845 [ARM] tegra: add ... |
237 238 239 240 |
return -EINVAL; if (func < 0) return -ERANGE; |
c5f04b8d1 [ARM] tegra: pinm... |
241 242 |
if (func == TEGRA_MUX_SAFE) func = pingroups[pg].func_safe; |
a4417c845 [ARM] tegra: add ... |
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
if (func & TEGRA_MUX_RSVD) { mux = func & 0x3; } else { for (i = 0; i < 4; i++) { if (pingroups[pg].funcs[i] == func) { mux = i; break; } } } if (mux < 0) return -EINVAL; spin_lock_irqsave(&mux_lock, flags); |
48f2eceef arm/tegra: pinmux... |
258 |
reg = pg_readl(pingroups[pg].mux_bank, pingroups[pg].mux_reg); |
a4417c845 [ARM] tegra: add ... |
259 260 |
reg &= ~(0x3 << pingroups[pg].mux_bit); reg |= mux << pingroups[pg].mux_bit; |
48f2eceef arm/tegra: pinmux... |
261 |
pg_writel(reg, pingroups[pg].mux_bank, pingroups[pg].mux_reg); |
a4417c845 [ARM] tegra: add ... |
262 263 264 265 266 |
spin_unlock_irqrestore(&mux_lock, flags); return 0; } |
6996e0858 arm/tegra: prepar... |
267 |
int tegra_pinmux_set_tristate(int pg, enum tegra_tristate tristate) |
a4417c845 [ARM] tegra: add ... |
268 269 270 |
{ unsigned long reg; unsigned long flags; |
6996e0858 arm/tegra: prepar... |
271 |
if (pg < 0 || pg >= pingroup_max) |
a4417c845 [ARM] tegra: add ... |
272 |
return -ERANGE; |
c5f04b8d1 [ARM] tegra: pinm... |
273 |
if (pingroups[pg].tri_reg < 0) |
a4417c845 [ARM] tegra: add ... |
274 275 276 |
return -EINVAL; spin_lock_irqsave(&mux_lock, flags); |
48f2eceef arm/tegra: pinmux... |
277 |
reg = pg_readl(pingroups[pg].tri_bank, pingroups[pg].tri_reg); |
a4417c845 [ARM] tegra: add ... |
278 279 280 |
reg &= ~(0x1 << pingroups[pg].tri_bit); if (tristate) reg |= 1 << pingroups[pg].tri_bit; |
48f2eceef arm/tegra: pinmux... |
281 |
pg_writel(reg, pingroups[pg].tri_bank, pingroups[pg].tri_reg); |
a4417c845 [ARM] tegra: add ... |
282 283 284 285 286 |
spin_unlock_irqrestore(&mux_lock, flags); return 0; } |
6996e0858 arm/tegra: prepar... |
287 |
int tegra_pinmux_set_pullupdown(int pg, enum tegra_pullupdown pupd) |
a4417c845 [ARM] tegra: add ... |
288 289 290 |
{ unsigned long reg; unsigned long flags; |
6996e0858 arm/tegra: prepar... |
291 |
if (pg < 0 || pg >= pingroup_max) |
a4417c845 [ARM] tegra: add ... |
292 |
return -ERANGE; |
c5f04b8d1 [ARM] tegra: pinm... |
293 |
if (pingroups[pg].pupd_reg < 0) |
a4417c845 [ARM] tegra: add ... |
294 295 296 297 298 299 300 301 302 |
return -EINVAL; if (pupd != TEGRA_PUPD_NORMAL && pupd != TEGRA_PUPD_PULL_DOWN && pupd != TEGRA_PUPD_PULL_UP) return -EINVAL; spin_lock_irqsave(&mux_lock, flags); |
48f2eceef arm/tegra: pinmux... |
303 |
reg = pg_readl(pingroups[pg].pupd_bank, pingroups[pg].pupd_reg); |
a4417c845 [ARM] tegra: add ... |
304 305 |
reg &= ~(0x3 << pingroups[pg].pupd_bit); reg |= pupd << pingroups[pg].pupd_bit; |
48f2eceef arm/tegra: pinmux... |
306 |
pg_writel(reg, pingroups[pg].pupd_bank, pingroups[pg].pupd_reg); |
a4417c845 [ARM] tegra: add ... |
307 308 309 310 311 |
spin_unlock_irqrestore(&mux_lock, flags); return 0; } |
c5f04b8d1 [ARM] tegra: pinm... |
312 |
static void tegra_pinmux_config_pingroup(const struct tegra_pingroup_config *config) |
a4417c845 [ARM] tegra: add ... |
313 |
{ |
6996e0858 arm/tegra: prepar... |
314 |
int pingroup = config->pingroup; |
c5f04b8d1 [ARM] tegra: pinm... |
315 316 317 |
enum tegra_mux_func func = config->func; enum tegra_pullupdown pupd = config->pupd; enum tegra_tristate tristate = config->tristate; |
a4417c845 [ARM] tegra: add ... |
318 |
int err; |
c5f04b8d1 [ARM] tegra: pinm... |
319 320 |
if (pingroups[pingroup].mux_reg >= 0) { err = tegra_pinmux_set_func(config); |
a4417c845 [ARM] tegra: add ... |
321 322 323 324 325 |
if (err < 0) pr_err("pinmux: can't set pingroup %s func to %s: %d ", pingroup_name(pingroup), func_name(func), err); } |
c5f04b8d1 [ARM] tegra: pinm... |
326 |
if (pingroups[pingroup].pupd_reg >= 0) { |
a4417c845 [ARM] tegra: add ... |
327 328 329 330 331 332 |
err = tegra_pinmux_set_pullupdown(pingroup, pupd); if (err < 0) pr_err("pinmux: can't set pingroup %s pullupdown to %s: %d ", pingroup_name(pingroup), pupd_name(pupd), err); } |
c5f04b8d1 [ARM] tegra: pinm... |
333 |
if (pingroups[pingroup].tri_reg >= 0) { |
a4417c845 [ARM] tegra: add ... |
334 335 336 337 338 339 340 |
err = tegra_pinmux_set_tristate(pingroup, tristate); if (err < 0) pr_err("pinmux: can't set pingroup %s tristate to %s: %d ", pingroup_name(pingroup), tri_name(func), err); } } |
c5f04b8d1 [ARM] tegra: pinm... |
341 |
void tegra_pinmux_config_table(const struct tegra_pingroup_config *config, int len) |
a4417c845 [ARM] tegra: add ... |
342 343 344 345 |
{ int i; for (i = 0; i < len; i++) |
c5f04b8d1 [ARM] tegra: pinm... |
346 |
tegra_pinmux_config_pingroup(&config[i]); |
a4417c845 [ARM] tegra: add ... |
347 |
} |
6996e0858 arm/tegra: prepar... |
348 |
static const char *drive_pinmux_name(int pg) |
a4417c845 [ARM] tegra: add ... |
349 |
{ |
6996e0858 arm/tegra: prepar... |
350 |
if (pg < 0 || pg >= drive_max) |
a4417c845 [ARM] tegra: add ... |
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
return "<UNKNOWN>"; return drive_pingroups[pg].name; } static const char *enable_name(unsigned long val) { return val ? "ENABLE" : "DISABLE"; } static const char *drive_name(unsigned long val) { if (val >= TEGRA_MAX_DRIVE) return "<UNKNOWN>"; return tegra_drive_names[val]; } static const char *slew_name(unsigned long val) { if (val >= TEGRA_MAX_SLEW) return "<UNKNOWN>"; return tegra_slew_names[val]; } |
6996e0858 arm/tegra: prepar... |
376 |
static int tegra_drive_pinmux_set_hsm(int pg, enum tegra_hsm hsm) |
a4417c845 [ARM] tegra: add ... |
377 378 379 |
{ unsigned long flags; u32 reg; |
6996e0858 arm/tegra: prepar... |
380 |
if (pg < 0 || pg >= drive_max) |
a4417c845 [ARM] tegra: add ... |
381 382 383 384 385 386 |
return -ERANGE; if (hsm != TEGRA_HSM_ENABLE && hsm != TEGRA_HSM_DISABLE) return -EINVAL; spin_lock_irqsave(&mux_lock, flags); |
48f2eceef arm/tegra: pinmux... |
387 |
reg = pg_readl(drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
388 389 390 391 |
if (hsm == TEGRA_HSM_ENABLE) reg |= (1 << 2); else reg &= ~(1 << 2); |
48f2eceef arm/tegra: pinmux... |
392 |
pg_writel(reg, drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
393 394 395 396 397 |
spin_unlock_irqrestore(&mux_lock, flags); return 0; } |
6996e0858 arm/tegra: prepar... |
398 |
static int tegra_drive_pinmux_set_schmitt(int pg, enum tegra_schmitt schmitt) |
a4417c845 [ARM] tegra: add ... |
399 400 401 |
{ unsigned long flags; u32 reg; |
6996e0858 arm/tegra: prepar... |
402 |
if (pg < 0 || pg >= drive_max) |
a4417c845 [ARM] tegra: add ... |
403 404 405 406 407 408 |
return -ERANGE; if (schmitt != TEGRA_SCHMITT_ENABLE && schmitt != TEGRA_SCHMITT_DISABLE) return -EINVAL; spin_lock_irqsave(&mux_lock, flags); |
48f2eceef arm/tegra: pinmux... |
409 |
reg = pg_readl(drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
410 411 412 413 |
if (schmitt == TEGRA_SCHMITT_ENABLE) reg |= (1 << 3); else reg &= ~(1 << 3); |
48f2eceef arm/tegra: pinmux... |
414 |
pg_writel(reg, drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
415 416 417 418 419 |
spin_unlock_irqrestore(&mux_lock, flags); return 0; } |
6996e0858 arm/tegra: prepar... |
420 |
static int tegra_drive_pinmux_set_drive(int pg, enum tegra_drive drive) |
a4417c845 [ARM] tegra: add ... |
421 422 423 |
{ unsigned long flags; u32 reg; |
6996e0858 arm/tegra: prepar... |
424 |
if (pg < 0 || pg >= drive_max) |
a4417c845 [ARM] tegra: add ... |
425 426 427 428 429 430 |
return -ERANGE; if (drive < 0 || drive >= TEGRA_MAX_DRIVE) return -EINVAL; spin_lock_irqsave(&mux_lock, flags); |
48f2eceef arm/tegra: pinmux... |
431 |
reg = pg_readl(drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
432 433 |
reg &= ~(0x3 << 4); reg |= drive << 4; |
48f2eceef arm/tegra: pinmux... |
434 |
pg_writel(reg, drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
435 436 437 438 439 |
spin_unlock_irqrestore(&mux_lock, flags); return 0; } |
6996e0858 arm/tegra: prepar... |
440 |
static int tegra_drive_pinmux_set_pull_down(int pg, |
a4417c845 [ARM] tegra: add ... |
441 442 443 444 |
enum tegra_pull_strength pull_down) { unsigned long flags; u32 reg; |
6996e0858 arm/tegra: prepar... |
445 |
if (pg < 0 || pg >= drive_max) |
a4417c845 [ARM] tegra: add ... |
446 447 448 449 450 451 |
return -ERANGE; if (pull_down < 0 || pull_down >= TEGRA_MAX_PULL) return -EINVAL; spin_lock_irqsave(&mux_lock, flags); |
48f2eceef arm/tegra: pinmux... |
452 |
reg = pg_readl(drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
453 454 |
reg &= ~(0x1f << 12); reg |= pull_down << 12; |
48f2eceef arm/tegra: pinmux... |
455 |
pg_writel(reg, drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
456 457 458 459 460 |
spin_unlock_irqrestore(&mux_lock, flags); return 0; } |
6996e0858 arm/tegra: prepar... |
461 |
static int tegra_drive_pinmux_set_pull_up(int pg, |
a4417c845 [ARM] tegra: add ... |
462 463 464 465 |
enum tegra_pull_strength pull_up) { unsigned long flags; u32 reg; |
6996e0858 arm/tegra: prepar... |
466 |
if (pg < 0 || pg >= drive_max) |
a4417c845 [ARM] tegra: add ... |
467 468 469 470 471 472 |
return -ERANGE; if (pull_up < 0 || pull_up >= TEGRA_MAX_PULL) return -EINVAL; spin_lock_irqsave(&mux_lock, flags); |
48f2eceef arm/tegra: pinmux... |
473 |
reg = pg_readl(drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
474 475 |
reg &= ~(0x1f << 12); reg |= pull_up << 12; |
48f2eceef arm/tegra: pinmux... |
476 |
pg_writel(reg, drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
477 478 479 480 481 |
spin_unlock_irqrestore(&mux_lock, flags); return 0; } |
6996e0858 arm/tegra: prepar... |
482 |
static int tegra_drive_pinmux_set_slew_rising(int pg, |
a4417c845 [ARM] tegra: add ... |
483 484 485 486 |
enum tegra_slew slew_rising) { unsigned long flags; u32 reg; |
6996e0858 arm/tegra: prepar... |
487 |
if (pg < 0 || pg >= drive_max) |
a4417c845 [ARM] tegra: add ... |
488 489 490 491 492 493 |
return -ERANGE; if (slew_rising < 0 || slew_rising >= TEGRA_MAX_SLEW) return -EINVAL; spin_lock_irqsave(&mux_lock, flags); |
48f2eceef arm/tegra: pinmux... |
494 |
reg = pg_readl(drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
495 496 |
reg &= ~(0x3 << 28); reg |= slew_rising << 28; |
48f2eceef arm/tegra: pinmux... |
497 |
pg_writel(reg, drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
498 499 500 501 502 |
spin_unlock_irqrestore(&mux_lock, flags); return 0; } |
6996e0858 arm/tegra: prepar... |
503 |
static int tegra_drive_pinmux_set_slew_falling(int pg, |
a4417c845 [ARM] tegra: add ... |
504 505 506 507 |
enum tegra_slew slew_falling) { unsigned long flags; u32 reg; |
6996e0858 arm/tegra: prepar... |
508 |
if (pg < 0 || pg >= drive_max) |
a4417c845 [ARM] tegra: add ... |
509 510 511 512 513 514 |
return -ERANGE; if (slew_falling < 0 || slew_falling >= TEGRA_MAX_SLEW) return -EINVAL; spin_lock_irqsave(&mux_lock, flags); |
48f2eceef arm/tegra: pinmux... |
515 |
reg = pg_readl(drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
516 517 |
reg &= ~(0x3 << 30); reg |= slew_falling << 30; |
48f2eceef arm/tegra: pinmux... |
518 |
pg_writel(reg, drive_pingroups[pg].reg_bank, drive_pingroups[pg].reg); |
a4417c845 [ARM] tegra: add ... |
519 520 521 522 523 |
spin_unlock_irqrestore(&mux_lock, flags); return 0; } |
6996e0858 arm/tegra: prepar... |
524 |
static void tegra_drive_pinmux_config_pingroup(int pingroup, |
a4417c845 [ARM] tegra: add ... |
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
enum tegra_hsm hsm, enum tegra_schmitt schmitt, enum tegra_drive drive, enum tegra_pull_strength pull_down, enum tegra_pull_strength pull_up, enum tegra_slew slew_rising, enum tegra_slew slew_falling) { int err; err = tegra_drive_pinmux_set_hsm(pingroup, hsm); if (err < 0) pr_err("pinmux: can't set pingroup %s hsm to %s: %d ", drive_pinmux_name(pingroup), enable_name(hsm), err); err = tegra_drive_pinmux_set_schmitt(pingroup, schmitt); if (err < 0) pr_err("pinmux: can't set pingroup %s schmitt to %s: %d ", drive_pinmux_name(pingroup), enable_name(schmitt), err); err = tegra_drive_pinmux_set_drive(pingroup, drive); if (err < 0) pr_err("pinmux: can't set pingroup %s drive to %s: %d ", drive_pinmux_name(pingroup), drive_name(drive), err); err = tegra_drive_pinmux_set_pull_down(pingroup, pull_down); if (err < 0) pr_err("pinmux: can't set pingroup %s pull down to %d: %d ", drive_pinmux_name(pingroup), pull_down, err); err = tegra_drive_pinmux_set_pull_up(pingroup, pull_up); if (err < 0) pr_err("pinmux: can't set pingroup %s pull up to %d: %d ", drive_pinmux_name(pingroup), pull_up, err); err = tegra_drive_pinmux_set_slew_rising(pingroup, slew_rising); if (err < 0) pr_err("pinmux: can't set pingroup %s rising slew to %s: %d ", drive_pinmux_name(pingroup), slew_name(slew_rising), err); err = tegra_drive_pinmux_set_slew_falling(pingroup, slew_falling); if (err < 0) pr_err("pinmux: can't set pingroup %s falling slew to %s: %d ", drive_pinmux_name(pingroup), slew_name(slew_falling), err); } void tegra_drive_pinmux_config_table(struct tegra_drive_pingroup_config *config, int len) { int i; for (i = 0; i < len; i++) tegra_drive_pinmux_config_pingroup(config[i].pingroup, config[i].hsm, config[i].schmitt, config[i].drive, config[i].pull_down, config[i].pull_up, config[i].slew_rising, config[i].slew_falling); } |
c5f04b8d1 [ARM] tegra: pinm... |
600 601 602 603 604 605 606 607 608 |
void tegra_pinmux_set_safe_pinmux_table(const struct tegra_pingroup_config *config, int len) { int i; struct tegra_pingroup_config c; for (i = 0; i < len; i++) { int err; c = config[i]; |
6996e0858 arm/tegra: prepar... |
609 |
if (c.pingroup < 0 || c.pingroup >= pingroup_max) { |
c5f04b8d1 [ARM] tegra: pinm... |
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
WARN_ON(1); continue; } c.func = pingroups[c.pingroup].func_safe; err = tegra_pinmux_set_func(&c); if (err < 0) pr_err("%s: tegra_pinmux_set_func returned %d setting " "%s to %s ", __func__, err, pingroup_name(c.pingroup), func_name(c.func)); } } void tegra_pinmux_config_pinmux_table(const struct tegra_pingroup_config *config, int len) { int i; for (i = 0; i < len; i++) { int err; if (config[i].pingroup < 0 || |
6996e0858 arm/tegra: prepar... |
631 |
config[i].pingroup >= pingroup_max) { |
c5f04b8d1 [ARM] tegra: pinm... |
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 |
WARN_ON(1); continue; } err = tegra_pinmux_set_func(&config[i]); if (err < 0) pr_err("%s: tegra_pinmux_set_func returned %d setting " "%s to %s ", __func__, err, pingroup_name(config[i].pingroup), func_name(config[i].func)); } } void tegra_pinmux_config_tristate_table(const struct tegra_pingroup_config *config, int len, enum tegra_tristate tristate) { int i; int err; |
6996e0858 arm/tegra: prepar... |
650 |
int pingroup; |
c5f04b8d1 [ARM] tegra: pinm... |
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
for (i = 0; i < len; i++) { pingroup = config[i].pingroup; if (pingroups[pingroup].tri_reg >= 0) { err = tegra_pinmux_set_tristate(pingroup, tristate); if (err < 0) pr_err("pinmux: can't set pingroup %s tristate" " to %s: %d ", pingroup_name(pingroup), tri_name(tristate), err); } } } void tegra_pinmux_config_pullupdown_table(const struct tegra_pingroup_config *config, int len, enum tegra_pullupdown pupd) { int i; int err; |
6996e0858 arm/tegra: prepar... |
670 |
int pingroup; |
c5f04b8d1 [ARM] tegra: pinm... |
671 672 673 674 675 676 677 678 679 680 681 682 683 |
for (i = 0; i < len; i++) { pingroup = config[i].pingroup; if (pingroups[pingroup].pupd_reg >= 0) { err = tegra_pinmux_set_pullupdown(pingroup, pupd); if (err < 0) pr_err("pinmux: can't set pingroup %s pullupdown" " to %s: %d ", pingroup_name(pingroup), pupd_name(pupd), err); } } } |
a4417c845 [ARM] tegra: add ... |
684 |
|
6996e0858 arm/tegra: prepar... |
685 |
static struct of_device_id tegra_pinmux_of_match[] __devinitdata = { |
241682c8e arm/tegra: pinmux... |
686 |
#ifdef CONFIG_ARCH_TEGRA_2x_SOC |
6996e0858 arm/tegra: prepar... |
687 |
{ .compatible = "nvidia,tegra20-pinmux", tegra20_pinmux_init }, |
241682c8e arm/tegra: pinmux... |
688 689 690 691 |
#endif #ifdef CONFIG_ARCH_TEGRA_3x_SOC { .compatible = "nvidia,tegra30-pinmux", tegra30_pinmux_init }, #endif |
6996e0858 arm/tegra: prepar... |
692 693 |
{ }, }; |
1ebc8496e arm/tegra: Conver... |
694 695 |
static int __devinit tegra_pinmux_probe(struct platform_device *pdev) { |
48f2eceef arm/tegra: pinmux... |
696 697 698 |
struct resource *res; int i; int config_bad = 0; |
6996e0858 arm/tegra: prepar... |
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 |
const struct of_device_id *match; match = of_match_device(tegra_pinmux_of_match, &pdev->dev); if (match) ((pinmux_init)(match->data))(&pingroups, &pingroup_max, &drive_pingroups, &drive_max); #ifdef CONFIG_ARCH_TEGRA_2x_SOC else /* no device tree available, so we must be on tegra20 */ tegra20_pinmux_init(&pingroups, &pingroup_max, &drive_pingroups, &drive_max); #else pr_warn("non Tegra20 platform requires pinmux devicetree node "); #endif |
48f2eceef arm/tegra: pinmux... |
715 716 717 718 719 720 721 |
for (i = 0; ; i++) { res = platform_get_resource(pdev, IORESOURCE_MEM, i); if (!res) break; } nbanks = i; |
6996e0858 arm/tegra: prepar... |
722 |
for (i = 0; i < pingroup_max; i++) { |
48f2eceef arm/tegra: pinmux... |
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 |
if (pingroups[i].tri_bank >= nbanks) { dev_err(&pdev->dev, "pingroup %d: bad tri_bank ", i); config_bad = 1; } if (pingroups[i].mux_bank >= nbanks) { dev_err(&pdev->dev, "pingroup %d: bad mux_bank ", i); config_bad = 1; } if (pingroups[i].pupd_bank >= nbanks) { dev_err(&pdev->dev, "pingroup %d: bad pupd_bank ", i); config_bad = 1; } } |
6996e0858 arm/tegra: prepar... |
741 |
for (i = 0; i < drive_max; i++) { |
48f2eceef arm/tegra: pinmux... |
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 |
if (drive_pingroups[i].reg_bank >= nbanks) { dev_err(&pdev->dev, "drive pingroup %d: bad reg_bank ", i); config_bad = 1; } } if (config_bad) return -ENODEV; regs = devm_kzalloc(&pdev->dev, nbanks * sizeof(*regs), GFP_KERNEL); if (!regs) { dev_err(&pdev->dev, "Can't alloc regs pointer "); return -ENODEV; } for (i = 0; i < nbanks; i++) { res = platform_get_resource(pdev, IORESOURCE_MEM, i); if (!res) { dev_err(&pdev->dev, "Missing MEM resource "); return -ENODEV; } if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res), dev_name(&pdev->dev))) { dev_err(&pdev->dev, "Couldn't request MEM resource %d ", i); return -ENODEV; } regs[i] = devm_ioremap(&pdev->dev, res->start, resource_size(res)); if (!regs) { dev_err(&pdev->dev, "Couldn't ioremap regs %d ", i); return -ENODEV; } } |
1ebc8496e arm/tegra: Conver... |
785 786 |
return 0; } |
1ebc8496e arm/tegra: Conver... |
787 788 789 790 791 792 793 794 795 796 797 798 799 800 |
static struct platform_driver tegra_pinmux_driver = { .driver = { .name = "tegra-pinmux", .owner = THIS_MODULE, .of_match_table = tegra_pinmux_of_match, }, .probe = tegra_pinmux_probe, }; static int __init tegra_pinmux_init(void) { return platform_driver_register(&tegra_pinmux_driver); } postcore_initcall(tegra_pinmux_init); |
a4417c845 [ARM] tegra: add ... |
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 |
#ifdef CONFIG_DEBUG_FS #include <linux/debugfs.h> #include <linux/seq_file.h> static void dbg_pad_field(struct seq_file *s, int len) { seq_putc(s, ','); while (len-- > -1) seq_putc(s, ' '); } static int dbg_pinmux_show(struct seq_file *s, void *unused) { int i; int len; |
6996e0858 arm/tegra: prepar... |
818 |
for (i = 0; i < pingroup_max; i++) { |
48f2eceef arm/tegra: pinmux... |
819 |
unsigned long reg; |
a4417c845 [ARM] tegra: add ... |
820 821 822 823 824 825 826 |
unsigned long tri; unsigned long mux; unsigned long pupd; seq_printf(s, "\t{TEGRA_PINGROUP_%s", pingroups[i].name); len = strlen(pingroups[i].name); dbg_pad_field(s, 5 - len); |
c5f04b8d1 [ARM] tegra: pinm... |
827 |
if (pingroups[i].mux_reg < 0) { |
a4417c845 [ARM] tegra: add ... |
828 829 830 |
seq_printf(s, "TEGRA_MUX_NONE"); len = strlen("NONE"); } else { |
48f2eceef arm/tegra: pinmux... |
831 832 833 |
reg = pg_readl(pingroups[i].mux_bank, pingroups[i].mux_reg); mux = (reg >> pingroups[i].mux_bit) & 0x3; |
a4417c845 [ARM] tegra: add ... |
834 835 836 837 838 839 840 841 842 843 |
if (pingroups[i].funcs[mux] == TEGRA_MUX_RSVD) { seq_printf(s, "TEGRA_MUX_RSVD%1lu", mux+1); len = 5; } else { seq_printf(s, "TEGRA_MUX_%s", tegra_mux_names[pingroups[i].funcs[mux]]); len = strlen(tegra_mux_names[pingroups[i].funcs[mux]]); } } dbg_pad_field(s, 13-len); |
c5f04b8d1 [ARM] tegra: pinm... |
844 |
if (pingroups[i].pupd_reg < 0) { |
a4417c845 [ARM] tegra: add ... |
845 846 847 |
seq_printf(s, "TEGRA_PUPD_NORMAL"); len = strlen("NORMAL"); } else { |
48f2eceef arm/tegra: pinmux... |
848 849 850 |
reg = pg_readl(pingroups[i].pupd_bank, pingroups[i].pupd_reg); pupd = (reg >> pingroups[i].pupd_bit) & 0x3; |
a4417c845 [ARM] tegra: add ... |
851 852 853 854 |
seq_printf(s, "TEGRA_PUPD_%s", pupd_name(pupd)); len = strlen(pupd_name(pupd)); } dbg_pad_field(s, 9 - len); |
c5f04b8d1 [ARM] tegra: pinm... |
855 |
if (pingroups[i].tri_reg < 0) { |
a4417c845 [ARM] tegra: add ... |
856 857 |
seq_printf(s, "TEGRA_TRI_NORMAL"); } else { |
48f2eceef arm/tegra: pinmux... |
858 859 860 |
reg = pg_readl(pingroups[i].tri_bank, pingroups[i].tri_reg); tri = (reg >> pingroups[i].tri_bit) & 0x1; |
a4417c845 [ARM] tegra: add ... |
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 |
seq_printf(s, "TEGRA_TRI_%s", tri_name(tri)); } seq_printf(s, "}, "); } return 0; } static int dbg_pinmux_open(struct inode *inode, struct file *file) { return single_open(file, dbg_pinmux_show, &inode->i_private); } static const struct file_operations debug_fops = { .open = dbg_pinmux_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }; static int dbg_drive_pinmux_show(struct seq_file *s, void *unused) { int i; int len; |
6996e0858 arm/tegra: prepar... |
886 |
for (i = 0; i < drive_max; i++) { |
a4417c845 [ARM] tegra: add ... |
887 888 889 890 891 892 |
u32 reg; seq_printf(s, "\t{TEGRA_DRIVE_PINGROUP_%s", drive_pingroups[i].name); len = strlen(drive_pingroups[i].name); dbg_pad_field(s, 7 - len); |
48f2eceef arm/tegra: pinmux... |
893 894 |
reg = pg_readl(drive_pingroups[i].reg_bank, drive_pingroups[i].reg); |
a4417c845 [ARM] tegra: add ... |
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 |
if (HSM_EN(reg)) { seq_printf(s, "TEGRA_HSM_ENABLE"); len = 16; } else { seq_printf(s, "TEGRA_HSM_DISABLE"); len = 17; } dbg_pad_field(s, 17 - len); if (SCHMT_EN(reg)) { seq_printf(s, "TEGRA_SCHMITT_ENABLE"); len = 21; } else { seq_printf(s, "TEGRA_SCHMITT_DISABLE"); len = 22; } dbg_pad_field(s, 22 - len); seq_printf(s, "TEGRA_DRIVE_%s", drive_name(LPMD(reg))); len = strlen(drive_name(LPMD(reg))); dbg_pad_field(s, 5 - len); seq_printf(s, "TEGRA_PULL_%d", DRVDN(reg)); len = DRVDN(reg) < 10 ? 1 : 2; dbg_pad_field(s, 2 - len); seq_printf(s, "TEGRA_PULL_%d", DRVUP(reg)); len = DRVUP(reg) < 10 ? 1 : 2; dbg_pad_field(s, 2 - len); seq_printf(s, "TEGRA_SLEW_%s", slew_name(SLWR(reg))); len = strlen(slew_name(SLWR(reg))); dbg_pad_field(s, 7 - len); seq_printf(s, "TEGRA_SLEW_%s", slew_name(SLWF(reg))); seq_printf(s, "}, "); } return 0; } static int dbg_drive_pinmux_open(struct inode *inode, struct file *file) { return single_open(file, dbg_drive_pinmux_show, &inode->i_private); } static const struct file_operations debug_drive_fops = { .open = dbg_drive_pinmux_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }; static int __init tegra_pinmux_debuginit(void) { (void) debugfs_create_file("tegra_pinmux", S_IRUGO, NULL, NULL, &debug_fops); (void) debugfs_create_file("tegra_pinmux_drive", S_IRUGO, NULL, NULL, &debug_drive_fops); return 0; } late_initcall(tegra_pinmux_debuginit); #endif |