diff options
author | Tarun Kanti DebBarma <tarun.kanti@ti.com> | 2011-09-28 19:17:25 -0400 |
---|---|---|
committer | Tarun Kanti DebBarma <tarun.kanti@ti.com> | 2012-02-06 03:43:40 -0500 |
commit | 60a3437dc9a61c7f4b199c2bac3dcc7b611b1178 (patch) | |
tree | c115df789b5da33b843ee7dddf34ddf58e2ae49d /drivers/gpio/gpio-omap.c | |
parent | 6d62e216b2ccbb8176dca73b6899b12a417bb22d (diff) |
gpio/omap: handle save/restore context in GPIO driver
Modify omap_gpio_prepare_for_idle() & omap_gpio_resume_after_idle() functions
to handle save context & restore context respectively in the OMAP GPIO driver
itself instead of calling these functions from pm specific files.
For this, in gpio_prepare_for_idle(), call *_get_context_loss_count() and in
gpio_resume_after_idle() call it again. If the count is different, do restore
context.
Signed-off-by: Charulatha V <charu@ti.com>
Signed-off-by: Tarun Kanti DebBarma <tarun.kanti@ti.com>
Reviewed-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
Acked-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Kevin Hilman <khilman@ti.com>
Signed-off-by: Kevin Hilman <khilman@ti.com>
Diffstat (limited to 'drivers/gpio/gpio-omap.c')
-rw-r--r-- | drivers/gpio/gpio-omap.c | 131 |
1 files changed, 58 insertions, 73 deletions
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c index 6788c8a2a770..a1a3b9dca178 100644 --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c | |||
@@ -72,9 +72,11 @@ struct gpio_bank { | |||
72 | bool loses_context; | 72 | bool loses_context; |
73 | int stride; | 73 | int stride; |
74 | u32 width; | 74 | u32 width; |
75 | int context_loss_count; | ||
75 | u16 id; | 76 | u16 id; |
76 | 77 | ||
77 | void (*set_dataout)(struct gpio_bank *bank, int gpio, int enable); | 78 | void (*set_dataout)(struct gpio_bank *bank, int gpio, int enable); |
79 | int (*get_context_loss_count)(struct device *dev); | ||
78 | 80 | ||
79 | struct omap_gpio_reg_offs *regs; | 81 | struct omap_gpio_reg_offs *regs; |
80 | }; | 82 | }; |
@@ -1179,6 +1181,7 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev) | |||
1179 | bank->stride = pdata->bank_stride; | 1181 | bank->stride = pdata->bank_stride; |
1180 | bank->width = pdata->bank_width; | 1182 | bank->width = pdata->bank_width; |
1181 | bank->loses_context = pdata->loses_context; | 1183 | bank->loses_context = pdata->loses_context; |
1184 | bank->get_context_loss_count = pdata->get_context_loss_count; | ||
1182 | bank->regs = pdata->regs; | 1185 | bank->regs = pdata->regs; |
1183 | 1186 | ||
1184 | if (bank->regs->set_dataout && bank->regs->clr_dataout) | 1187 | if (bank->regs->set_dataout && bank->regs->clr_dataout) |
@@ -1323,11 +1326,11 @@ static struct syscore_ops omap_gpio_syscore_ops = { | |||
1323 | 1326 | ||
1324 | #ifdef CONFIG_ARCH_OMAP2PLUS | 1327 | #ifdef CONFIG_ARCH_OMAP2PLUS |
1325 | 1328 | ||
1326 | static int workaround_enabled; | 1329 | static void omap_gpio_save_context(struct gpio_bank *bank); |
1330 | static void omap_gpio_restore_context(struct gpio_bank *bank); | ||
1327 | 1331 | ||
1328 | void omap2_gpio_prepare_for_idle(int off_mode) | 1332 | void omap2_gpio_prepare_for_idle(int off_mode) |
1329 | { | 1333 | { |
1330 | int c = 0; | ||
1331 | struct gpio_bank *bank; | 1334 | struct gpio_bank *bank; |
1332 | 1335 | ||
1333 | list_for_each_entry(bank, &omap_gpio_list, node) { | 1336 | list_for_each_entry(bank, &omap_gpio_list, node) { |
@@ -1347,7 +1350,7 @@ void omap2_gpio_prepare_for_idle(int off_mode) | |||
1347 | * non-wakeup GPIOs. Otherwise spurious IRQs will be | 1350 | * non-wakeup GPIOs. Otherwise spurious IRQs will be |
1348 | * generated. See OMAP2420 Errata item 1.101. */ | 1351 | * generated. See OMAP2420 Errata item 1.101. */ |
1349 | if (!(bank->enabled_non_wakeup_gpios)) | 1352 | if (!(bank->enabled_non_wakeup_gpios)) |
1350 | continue; | 1353 | goto save_gpio_context; |
1351 | 1354 | ||
1352 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { | 1355 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
1353 | bank->saved_datain = __raw_readl(bank->base + | 1356 | bank->saved_datain = __raw_readl(bank->base + |
@@ -1384,13 +1387,13 @@ void omap2_gpio_prepare_for_idle(int off_mode) | |||
1384 | __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT); | 1387 | __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT); |
1385 | } | 1388 | } |
1386 | 1389 | ||
1387 | c++; | 1390 | save_gpio_context: |
1388 | } | 1391 | if (bank->get_context_loss_count) |
1389 | if (!c) { | 1392 | bank->context_loss_count = |
1390 | workaround_enabled = 0; | 1393 | bank->get_context_loss_count(bank->dev); |
1391 | return; | 1394 | |
1395 | omap_gpio_save_context(bank); | ||
1392 | } | 1396 | } |
1393 | workaround_enabled = 1; | ||
1394 | } | 1397 | } |
1395 | 1398 | ||
1396 | void omap2_gpio_resume_after_idle(void) | 1399 | void omap2_gpio_resume_after_idle(void) |
@@ -1398,6 +1401,7 @@ void omap2_gpio_resume_after_idle(void) | |||
1398 | struct gpio_bank *bank; | 1401 | struct gpio_bank *bank; |
1399 | 1402 | ||
1400 | list_for_each_entry(bank, &omap_gpio_list, node) { | 1403 | list_for_each_entry(bank, &omap_gpio_list, node) { |
1404 | int context_lost_cnt_after; | ||
1401 | u32 l = 0, gen, gen0, gen1; | 1405 | u32 l = 0, gen, gen0, gen1; |
1402 | int j; | 1406 | int j; |
1403 | 1407 | ||
@@ -1407,8 +1411,13 @@ void omap2_gpio_resume_after_idle(void) | |||
1407 | for (j = 0; j < hweight_long(bank->dbck_enable_mask); j++) | 1411 | for (j = 0; j < hweight_long(bank->dbck_enable_mask); j++) |
1408 | clk_enable(bank->dbck); | 1412 | clk_enable(bank->dbck); |
1409 | 1413 | ||
1410 | if (!workaround_enabled) | 1414 | if (bank->get_context_loss_count) { |
1411 | continue; | 1415 | context_lost_cnt_after = |
1416 | bank->get_context_loss_count(bank->dev); | ||
1417 | if (context_lost_cnt_after != bank->context_loss_count | ||
1418 | || !context_lost_cnt_after) | ||
1419 | omap_gpio_restore_context(bank); | ||
1420 | } | ||
1412 | 1421 | ||
1413 | if (!(bank->enabled_non_wakeup_gpios)) | 1422 | if (!(bank->enabled_non_wakeup_gpios)) |
1414 | continue; | 1423 | continue; |
@@ -1486,74 +1495,50 @@ void omap2_gpio_resume_after_idle(void) | |||
1486 | } | 1495 | } |
1487 | } | 1496 | } |
1488 | } | 1497 | } |
1489 | |||
1490 | } | 1498 | } |
1491 | 1499 | ||
1492 | #endif | 1500 | static void omap_gpio_save_context(struct gpio_bank *bank) |
1493 | |||
1494 | #ifdef CONFIG_ARCH_OMAP3 | ||
1495 | void omap_gpio_save_context(void) | ||
1496 | { | 1501 | { |
1497 | struct gpio_bank *bank; | 1502 | bank->context.irqenable1 = |
1498 | 1503 | __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1); | |
1499 | list_for_each_entry(bank, &omap_gpio_list, node) { | 1504 | bank->context.irqenable2 = |
1500 | 1505 | __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2); | |
1501 | if (!bank->loses_context) | 1506 | bank->context.wake_en = |
1502 | continue; | 1507 | __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN); |
1503 | 1508 | bank->context.ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL); | |
1504 | bank->context.irqenable1 = | 1509 | bank->context.oe = __raw_readl(bank->base + OMAP24XX_GPIO_OE); |
1505 | __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1); | 1510 | bank->context.leveldetect0 = |
1506 | bank->context.irqenable2 = | 1511 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0); |
1507 | __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2); | 1512 | bank->context.leveldetect1 = |
1508 | bank->context.wake_en = | 1513 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
1509 | __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN); | 1514 | bank->context.risingdetect = |
1510 | bank->context.ctrl = | 1515 | __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT); |
1511 | __raw_readl(bank->base + OMAP24XX_GPIO_CTRL); | 1516 | bank->context.fallingdetect = |
1512 | bank->context.oe = | 1517 | __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
1513 | __raw_readl(bank->base + OMAP24XX_GPIO_OE); | 1518 | bank->context.dataout = |
1514 | bank->context.leveldetect0 = | 1519 | __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT); |
1515 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0); | ||
1516 | bank->context.leveldetect1 = | ||
1517 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1); | ||
1518 | bank->context.risingdetect = | ||
1519 | __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT); | ||
1520 | bank->context.fallingdetect = | ||
1521 | __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT); | ||
1522 | bank->context.dataout = | ||
1523 | __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT); | ||
1524 | } | ||
1525 | } | 1520 | } |
1526 | 1521 | ||
1527 | void omap_gpio_restore_context(void) | 1522 | static void omap_gpio_restore_context(struct gpio_bank *bank) |
1528 | { | 1523 | { |
1529 | struct gpio_bank *bank; | 1524 | __raw_writel(bank->context.irqenable1, |
1530 | 1525 | bank->base + OMAP24XX_GPIO_IRQENABLE1); | |
1531 | list_for_each_entry(bank, &omap_gpio_list, node) { | 1526 | __raw_writel(bank->context.irqenable2, |
1532 | 1527 | bank->base + OMAP24XX_GPIO_IRQENABLE2); | |
1533 | if (!bank->loses_context) | 1528 | __raw_writel(bank->context.wake_en, |
1534 | continue; | 1529 | bank->base + OMAP24XX_GPIO_WAKE_EN); |
1535 | 1530 | __raw_writel(bank->context.ctrl, bank->base + OMAP24XX_GPIO_CTRL); | |
1536 | __raw_writel(bank->context.irqenable1, | 1531 | __raw_writel(bank->context.oe, bank->base + OMAP24XX_GPIO_OE); |
1537 | bank->base + OMAP24XX_GPIO_IRQENABLE1); | 1532 | __raw_writel(bank->context.leveldetect0, |
1538 | __raw_writel(bank->context.irqenable2, | 1533 | bank->base + OMAP24XX_GPIO_LEVELDETECT0); |
1539 | bank->base + OMAP24XX_GPIO_IRQENABLE2); | 1534 | __raw_writel(bank->context.leveldetect1, |
1540 | __raw_writel(bank->context.wake_en, | 1535 | bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
1541 | bank->base + OMAP24XX_GPIO_WAKE_EN); | 1536 | __raw_writel(bank->context.risingdetect, |
1542 | __raw_writel(bank->context.ctrl, | 1537 | bank->base + OMAP24XX_GPIO_RISINGDETECT); |
1543 | bank->base + OMAP24XX_GPIO_CTRL); | 1538 | __raw_writel(bank->context.fallingdetect, |
1544 | __raw_writel(bank->context.oe, | 1539 | bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
1545 | bank->base + OMAP24XX_GPIO_OE); | 1540 | __raw_writel(bank->context.dataout, |
1546 | __raw_writel(bank->context.leveldetect0, | 1541 | bank->base + OMAP24XX_GPIO_DATAOUT); |
1547 | bank->base + OMAP24XX_GPIO_LEVELDETECT0); | ||
1548 | __raw_writel(bank->context.leveldetect1, | ||
1549 | bank->base + OMAP24XX_GPIO_LEVELDETECT1); | ||
1550 | __raw_writel(bank->context.risingdetect, | ||
1551 | bank->base + OMAP24XX_GPIO_RISINGDETECT); | ||
1552 | __raw_writel(bank->context.fallingdetect, | ||
1553 | bank->base + OMAP24XX_GPIO_FALLINGDETECT); | ||
1554 | __raw_writel(bank->context.dataout, | ||
1555 | bank->base + OMAP24XX_GPIO_DATAOUT); | ||
1556 | } | ||
1557 | } | 1542 | } |
1558 | #endif | 1543 | #endif |
1559 | 1544 | ||