^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // Copyright 2008 Openmoko, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) // Copyright 2008 Simtec Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Ben Dooks <ben@simtec.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // http://armlinux.simtec.co.uk/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) // S3C series GPIO PM code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "gpio-samsung.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "gpio-core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "pm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /* PM GPIO helpers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define OFFS_CON (0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define OFFS_DAT (0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define OFFS_UP (0x08)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static void samsung_gpio_pm_1bit_save(struct samsung_gpio_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) chip->pm_save[0] = __raw_readl(chip->base + OFFS_CON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) chip->pm_save[1] = __raw_readl(chip->base + OFFS_DAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static void samsung_gpio_pm_1bit_resume(struct samsung_gpio_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) void __iomem *base = chip->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u32 old_gpcon = __raw_readl(base + OFFS_CON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) u32 old_gpdat = __raw_readl(base + OFFS_DAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) u32 gps_gpcon = chip->pm_save[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) u32 gps_gpdat = chip->pm_save[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) u32 gpcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* GPACON only has one bit per control / data and no PULLUPs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * GPACON[x] = 0 => Output, 1 => SFN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* first set all SFN bits to SFN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) gpcon = old_gpcon | gps_gpcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) __raw_writel(gpcon, base + OFFS_CON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* now set all the other bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) __raw_writel(gps_gpdat, base + OFFS_DAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) __raw_writel(gps_gpcon, base + OFFS_CON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) S3C_PMDBG("%s: CON %08x => %08x, DAT %08x => %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) chip->chip.label, old_gpcon, gps_gpcon, old_gpdat, gps_gpdat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct samsung_gpio_pm samsung_gpio_pm_1bit = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .save = samsung_gpio_pm_1bit_save,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .resume = samsung_gpio_pm_1bit_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static void samsung_gpio_pm_2bit_save(struct samsung_gpio_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) chip->pm_save[0] = __raw_readl(chip->base + OFFS_CON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) chip->pm_save[1] = __raw_readl(chip->base + OFFS_DAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) chip->pm_save[2] = __raw_readl(chip->base + OFFS_UP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* Test whether the given masked+shifted bits of an GPIO configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * are one of the SFN (special function) modes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static inline int is_sfn(unsigned long con)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return con >= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* Test if the given masked+shifted GPIO configuration is an input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static inline int is_in(unsigned long con)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return con == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* Test if the given masked+shifted GPIO configuration is an output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static inline int is_out(unsigned long con)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return con == 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * samsung_gpio_pm_2bit_resume() - restore the given GPIO bank
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * @chip: The chip information to resume.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * Restore one of the GPIO banks that was saved during suspend. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * not as simple as once thought, due to the possibility of glitches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * from the order that the CON and DAT registers are set in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * The three states the pin can be are {IN,OUT,SFN} which gives us 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * combinations of changes to check. Three of these, if the pin stays
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * in the same configuration can be discounted. This leaves us with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * { IN => OUT } Change DAT first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * { IN => SFN } Change CON first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * { OUT => SFN } Change CON first, so new data will not glitch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * { OUT => IN } Change CON first, so new data will not glitch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * { SFN => IN } Change CON first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * { SFN => OUT } Change DAT first, so new data will not glitch [1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * We do not currently deal with the UP registers as these control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * weak resistors, so a small delay in change should not need to bring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * these into the calculations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * [1] this assumes that writing to a pin DAT whilst in SFN will set the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * state for when it is next output.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static void samsung_gpio_pm_2bit_resume(struct samsung_gpio_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) void __iomem *base = chip->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u32 old_gpcon = __raw_readl(base + OFFS_CON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) u32 old_gpdat = __raw_readl(base + OFFS_DAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) u32 gps_gpcon = chip->pm_save[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) u32 gps_gpdat = chip->pm_save[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) u32 gpcon, old, new, mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) u32 change_mask = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* restore GPIO pull-up settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) __raw_writel(chip->pm_save[2], base + OFFS_UP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* Create a change_mask of all the items that need to have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * their CON value changed before their DAT value, so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * we minimise the work between the two settings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) for (nr = 0, mask = 0x03; nr < 32; nr += 2, mask <<= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) old = (old_gpcon & mask) >> nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) new = (gps_gpcon & mask) >> nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* If there is no change, then skip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (old == new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* If both are special function, then skip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (is_sfn(old) && is_sfn(new))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /* Change is IN => OUT, do not change now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (is_in(old) && is_out(new))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* Change is SFN => OUT, do not change now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (is_sfn(old) && is_out(new))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /* We should now be at the case of IN=>SFN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * OUT=>SFN, OUT=>IN, SFN=>IN. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) change_mask |= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* Write the new CON settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) gpcon = old_gpcon & ~change_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) gpcon |= gps_gpcon & change_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) __raw_writel(gpcon, base + OFFS_CON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* Now change any items that require DAT,CON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) __raw_writel(gps_gpdat, base + OFFS_DAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) __raw_writel(gps_gpcon, base + OFFS_CON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) S3C_PMDBG("%s: CON %08x => %08x, DAT %08x => %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) chip->chip.label, old_gpcon, gps_gpcon, old_gpdat, gps_gpdat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct samsung_gpio_pm samsung_gpio_pm_2bit = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) .save = samsung_gpio_pm_2bit_save,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) .resume = samsung_gpio_pm_2bit_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #if defined(CONFIG_ARCH_S3C64XX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static void samsung_gpio_pm_4bit_save(struct samsung_gpio_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) chip->pm_save[1] = __raw_readl(chip->base + OFFS_CON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) chip->pm_save[2] = __raw_readl(chip->base + OFFS_DAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) chip->pm_save[3] = __raw_readl(chip->base + OFFS_UP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (chip->chip.ngpio > 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) chip->pm_save[0] = __raw_readl(chip->base - 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static u32 samsung_gpio_pm_4bit_mask(u32 old_gpcon, u32 gps_gpcon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) u32 old, new, mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) u32 change_mask = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) int nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) for (nr = 0, mask = 0x0f; nr < 16; nr += 4, mask <<= 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) old = (old_gpcon & mask) >> nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) new = (gps_gpcon & mask) >> nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* If there is no change, then skip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (old == new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* If both are special function, then skip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (is_sfn(old) && is_sfn(new))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* Change is IN => OUT, do not change now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (is_in(old) && is_out(new))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* Change is SFN => OUT, do not change now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (is_sfn(old) && is_out(new))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /* We should now be at the case of IN=>SFN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * OUT=>SFN, OUT=>IN, SFN=>IN. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) change_mask |= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return change_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static void samsung_gpio_pm_4bit_con(struct samsung_gpio_chip *chip, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) void __iomem *con = chip->base + (index * 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) u32 old_gpcon = __raw_readl(con);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) u32 gps_gpcon = chip->pm_save[index + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) u32 gpcon, mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) mask = samsung_gpio_pm_4bit_mask(old_gpcon, gps_gpcon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) gpcon = old_gpcon & ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) gpcon |= gps_gpcon & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) __raw_writel(gpcon, con);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static void samsung_gpio_pm_4bit_resume(struct samsung_gpio_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) void __iomem *base = chip->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) u32 old_gpcon[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) u32 old_gpdat = __raw_readl(base + OFFS_DAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) u32 gps_gpdat = chip->pm_save[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /* First, modify the CON settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) old_gpcon[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) old_gpcon[1] = __raw_readl(base + OFFS_CON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) samsung_gpio_pm_4bit_con(chip, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (chip->chip.ngpio > 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) old_gpcon[0] = __raw_readl(base - 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) samsung_gpio_pm_4bit_con(chip, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /* Now change the configurations that require DAT,CON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) __raw_writel(chip->pm_save[2], base + OFFS_DAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) __raw_writel(chip->pm_save[1], base + OFFS_CON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (chip->chip.ngpio > 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) __raw_writel(chip->pm_save[0], base - 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) __raw_writel(chip->pm_save[2], base + OFFS_DAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) __raw_writel(chip->pm_save[3], base + OFFS_UP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (chip->chip.ngpio > 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) S3C_PMDBG("%s: CON4 %08x,%08x => %08x,%08x, DAT %08x => %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) chip->chip.label, old_gpcon[0], old_gpcon[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) __raw_readl(base - 4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) __raw_readl(base + OFFS_CON),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) old_gpdat, gps_gpdat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) S3C_PMDBG("%s: CON4 %08x => %08x, DAT %08x => %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) chip->chip.label, old_gpcon[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) __raw_readl(base + OFFS_CON),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) old_gpdat, gps_gpdat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct samsung_gpio_pm samsung_gpio_pm_4bit = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) .save = samsung_gpio_pm_4bit_save,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) .resume = samsung_gpio_pm_4bit_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) #endif /* CONFIG_ARCH_S3C64XX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * samsung_pm_save_gpio() - save gpio chip data for suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * @ourchip: The chip for suspend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static void samsung_pm_save_gpio(struct samsung_gpio_chip *ourchip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct samsung_gpio_pm *pm = ourchip->pm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (pm == NULL || pm->save == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) S3C_PMDBG("%s: no pm for %s\n", __func__, ourchip->chip.label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) pm->save(ourchip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * samsung_pm_save_gpios() - Save the state of the GPIO banks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * For all the GPIO banks, save the state of each one ready for going
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * into a suspend mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) void samsung_pm_save_gpios(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) struct samsung_gpio_chip *ourchip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) unsigned int gpio_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) for (gpio_nr = 0; gpio_nr < S3C_GPIO_END;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) ourchip = samsung_gpiolib_getchip(gpio_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (!ourchip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) gpio_nr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) samsung_pm_save_gpio(ourchip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) S3C_PMDBG("%s: save %08x,%08x,%08x,%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) ourchip->chip.label,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) ourchip->pm_save[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) ourchip->pm_save[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) ourchip->pm_save[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) ourchip->pm_save[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) gpio_nr += ourchip->chip.ngpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) gpio_nr += CONFIG_S3C_GPIO_SPACE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * samsung_pm_resume_gpio() - restore gpio chip data after suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * @ourchip: The suspended chip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static void samsung_pm_resume_gpio(struct samsung_gpio_chip *ourchip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct samsung_gpio_pm *pm = ourchip->pm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (pm == NULL || pm->resume == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) S3C_PMDBG("%s: no pm for %s\n", __func__, ourchip->chip.label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) pm->resume(ourchip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) void samsung_pm_restore_gpios(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) struct samsung_gpio_chip *ourchip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) unsigned int gpio_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) for (gpio_nr = 0; gpio_nr < S3C_GPIO_END;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) ourchip = samsung_gpiolib_getchip(gpio_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (!ourchip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) gpio_nr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) samsung_pm_resume_gpio(ourchip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) gpio_nr += ourchip->chip.ngpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) gpio_nr += CONFIG_S3C_GPIO_SPACE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }