Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/cpm2: Drop legacy-of-mm-gpiochip.h header

Remove legacy-of-mm-gpiochip.h header file. The above mentioned
file provides an OF API that's deprecated. There is no agnostic
alternatives to it and we have to open code the logic which was
hidden behind of_mm_gpiochip_add_data(). Note, most of the GPIO
drivers are using their own labeling schemas and resource retrieval
that only a few may gain of the code deduplication, so whenever
alternative is appear we can move drivers again to use that one.

As a side effect this change fixes a potential memory leak on
an error path, if of_mm_gpiochip_add_data() fails.

[text copied from commit 34064c8267a6 ("powerpc/8xx:
Drop legacy-of-mm-gpiochip.h header")]

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/2662f24c539db393f11b27f0feae2dc14bb2f08f.1755518891.git.christophe.leroy@csgroup.eu

authored by

Christophe Leroy and committed by
Madhavan Srinivasan
7f9bcf13 58f5382a

+28 -30
-1
arch/powerpc/platforms/8xx/Kconfig
··· 101 101 config 8xx_GPIO 102 102 bool "GPIO API Support" 103 103 select GPIOLIB 104 - select OF_GPIO_MM_GPIOCHIP 105 104 help 106 105 Saying Y here will cause the ports on an MPC8xx processor to be used 107 106 with the GPIO API. If you say N here, the kernel needs less memory.
-1
arch/powerpc/platforms/Kconfig
··· 243 243 select CPM 244 244 select HAVE_PCI 245 245 select GPIOLIB 246 - select OF_GPIO_MM_GPIOCHIP 247 246 help 248 247 The CPM2 (Communications Processor Module) is a coprocessor on 249 248 embedded CPUs made by Freescale. Selecting this option means that
+28 -28
arch/powerpc/sysdev/cpm_common.c
··· 28 28 29 29 #include <mm/mmu_decl.h> 30 30 31 - #if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO) 32 - #include <linux/gpio/legacy-of-mm-gpiochip.h> 33 - #endif 34 - 35 31 static int __init cpm_init(void) 36 32 { 37 33 struct device_node *np; ··· 87 91 88 92 #if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO) 89 93 94 + #include <linux/gpio/driver.h> 95 + 90 96 struct cpm2_ioports { 91 97 u32 dir, par, sor, odr, dat; 92 98 u32 res[3]; 93 99 }; 94 100 95 101 struct cpm2_gpio32_chip { 96 - struct of_mm_gpio_chip mm_gc; 102 + struct gpio_chip gc; 103 + void __iomem *regs; 97 104 spinlock_t lock; 98 105 99 106 /* shadowed data register to clear/set bits safely */ 100 107 u32 cpdata; 101 108 }; 102 109 103 - static void cpm2_gpio32_save_regs(struct of_mm_gpio_chip *mm_gc) 110 + static void cpm2_gpio32_save_regs(struct cpm2_gpio32_chip *cpm2_gc) 104 111 { 105 - struct cpm2_gpio32_chip *cpm2_gc = 106 - container_of(mm_gc, struct cpm2_gpio32_chip, mm_gc); 107 - struct cpm2_ioports __iomem *iop = mm_gc->regs; 112 + struct cpm2_ioports __iomem *iop = cpm2_gc->regs; 108 113 109 114 cpm2_gc->cpdata = in_be32(&iop->dat); 110 115 } 111 116 112 117 static int cpm2_gpio32_get(struct gpio_chip *gc, unsigned int gpio) 113 118 { 114 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 115 - struct cpm2_ioports __iomem *iop = mm_gc->regs; 119 + struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc); 120 + struct cpm2_ioports __iomem *iop = cpm2_gc->regs; 116 121 u32 pin_mask; 117 122 118 123 pin_mask = 1 << (31 - gpio); ··· 121 124 return !!(in_be32(&iop->dat) & pin_mask); 122 125 } 123 126 124 - static void __cpm2_gpio32_set(struct of_mm_gpio_chip *mm_gc, u32 pin_mask, 125 - int value) 127 + static void __cpm2_gpio32_set(struct cpm2_gpio32_chip *cpm2_gc, u32 pin_mask, int value) 126 128 { 127 - struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(&mm_gc->gc); 128 - struct cpm2_ioports __iomem *iop = mm_gc->regs; 129 + struct cpm2_ioports __iomem *iop = cpm2_gc->regs; 129 130 130 131 if (value) 131 132 cpm2_gc->cpdata |= pin_mask; ··· 135 140 136 141 static int cpm2_gpio32_set(struct gpio_chip *gc, unsigned int gpio, int value) 137 142 { 138 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 139 143 struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc); 140 144 unsigned long flags; 141 145 u32 pin_mask = 1 << (31 - gpio); 142 146 143 147 spin_lock_irqsave(&cpm2_gc->lock, flags); 144 148 145 - __cpm2_gpio32_set(mm_gc, pin_mask, value); 149 + __cpm2_gpio32_set(cpm2_gc, pin_mask, value); 146 150 147 151 spin_unlock_irqrestore(&cpm2_gc->lock, flags); 148 152 ··· 150 156 151 157 static int cpm2_gpio32_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 152 158 { 153 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 154 159 struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc); 155 - struct cpm2_ioports __iomem *iop = mm_gc->regs; 160 + struct cpm2_ioports __iomem *iop = cpm2_gc->regs; 156 161 unsigned long flags; 157 162 u32 pin_mask = 1 << (31 - gpio); 158 163 159 164 spin_lock_irqsave(&cpm2_gc->lock, flags); 160 165 161 166 setbits32(&iop->dir, pin_mask); 162 - __cpm2_gpio32_set(mm_gc, pin_mask, val); 167 + __cpm2_gpio32_set(cpm2_gc, pin_mask, val); 163 168 164 169 spin_unlock_irqrestore(&cpm2_gc->lock, flags); 165 170 ··· 167 174 168 175 static int cpm2_gpio32_dir_in(struct gpio_chip *gc, unsigned int gpio) 169 176 { 170 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 171 177 struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc); 172 - struct cpm2_ioports __iomem *iop = mm_gc->regs; 178 + struct cpm2_ioports __iomem *iop = cpm2_gc->regs; 173 179 unsigned long flags; 174 180 u32 pin_mask = 1 << (31 - gpio); 175 181 ··· 185 193 { 186 194 struct device_node *np = dev->of_node; 187 195 struct cpm2_gpio32_chip *cpm2_gc; 188 - struct of_mm_gpio_chip *mm_gc; 189 196 struct gpio_chip *gc; 190 197 191 - cpm2_gc = kzalloc(sizeof(*cpm2_gc), GFP_KERNEL); 198 + cpm2_gc = devm_kzalloc(dev, sizeof(*cpm2_gc), GFP_KERNEL); 192 199 if (!cpm2_gc) 193 200 return -ENOMEM; 194 201 195 202 spin_lock_init(&cpm2_gc->lock); 196 203 197 - mm_gc = &cpm2_gc->mm_gc; 198 - gc = &mm_gc->gc; 204 + gc = &cpm2_gc->gc; 199 205 200 - mm_gc->save_regs = cpm2_gpio32_save_regs; 206 + gc->base = -1; 201 207 gc->ngpio = 32; 202 208 gc->direction_input = cpm2_gpio32_dir_in; 203 209 gc->direction_output = cpm2_gpio32_dir_out; ··· 204 214 gc->parent = dev; 205 215 gc->owner = THIS_MODULE; 206 216 207 - return of_mm_gpiochip_add_data(np, mm_gc, cpm2_gc); 217 + gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", np); 218 + if (!gc->label) 219 + return -ENOMEM; 220 + 221 + cpm2_gc->regs = devm_of_iomap(dev, np, 0, NULL); 222 + if (IS_ERR(cpm2_gc->regs)) 223 + return PTR_ERR(cpm2_gc->regs); 224 + 225 + cpm2_gpio32_save_regs(cpm2_gc); 226 + 227 + return devm_gpiochip_add_data(dev, gc, cpm2_gc); 208 228 } 209 229 #endif /* CONFIG_CPM2 || CONFIG_8xx_GPIO */