mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 03:44:45 +01:00
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 34064c8267 ("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
This commit is contained in:
parent
58f5382a48
commit
7f9bcf1306
3 changed files with 28 additions and 30 deletions
|
|
@ -101,7 +101,6 @@ comment "Generic MPC8xx Options"
|
|||
config 8xx_GPIO
|
||||
bool "GPIO API Support"
|
||||
select GPIOLIB
|
||||
select OF_GPIO_MM_GPIOCHIP
|
||||
help
|
||||
Saying Y here will cause the ports on an MPC8xx processor to be used
|
||||
with the GPIO API. If you say N here, the kernel needs less memory.
|
||||
|
|
|
|||
|
|
@ -243,7 +243,6 @@ config CPM2
|
|||
select CPM
|
||||
select HAVE_PCI
|
||||
select GPIOLIB
|
||||
select OF_GPIO_MM_GPIOCHIP
|
||||
help
|
||||
The CPM2 (Communications Processor Module) is a coprocessor on
|
||||
embedded CPUs made by Freescale. Selecting this option means that
|
||||
|
|
|
|||
|
|
@ -28,10 +28,6 @@
|
|||
|
||||
#include <mm/mmu_decl.h>
|
||||
|
||||
#if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO)
|
||||
#include <linux/gpio/legacy-of-mm-gpiochip.h>
|
||||
#endif
|
||||
|
||||
static int __init cpm_init(void)
|
||||
{
|
||||
struct device_node *np;
|
||||
|
|
@ -91,32 +87,33 @@ void __init udbg_init_cpm(void)
|
|||
|
||||
#if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO)
|
||||
|
||||
#include <linux/gpio/driver.h>
|
||||
|
||||
struct cpm2_ioports {
|
||||
u32 dir, par, sor, odr, dat;
|
||||
u32 res[3];
|
||||
};
|
||||
|
||||
struct cpm2_gpio32_chip {
|
||||
struct of_mm_gpio_chip mm_gc;
|
||||
struct gpio_chip gc;
|
||||
void __iomem *regs;
|
||||
spinlock_t lock;
|
||||
|
||||
/* shadowed data register to clear/set bits safely */
|
||||
u32 cpdata;
|
||||
};
|
||||
|
||||
static void cpm2_gpio32_save_regs(struct of_mm_gpio_chip *mm_gc)
|
||||
static void cpm2_gpio32_save_regs(struct cpm2_gpio32_chip *cpm2_gc)
|
||||
{
|
||||
struct cpm2_gpio32_chip *cpm2_gc =
|
||||
container_of(mm_gc, struct cpm2_gpio32_chip, mm_gc);
|
||||
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
||||
struct cpm2_ioports __iomem *iop = cpm2_gc->regs;
|
||||
|
||||
cpm2_gc->cpdata = in_be32(&iop->dat);
|
||||
}
|
||||
|
||||
static int cpm2_gpio32_get(struct gpio_chip *gc, unsigned int gpio)
|
||||
{
|
||||
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
||||
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
||||
struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc);
|
||||
struct cpm2_ioports __iomem *iop = cpm2_gc->regs;
|
||||
u32 pin_mask;
|
||||
|
||||
pin_mask = 1 << (31 - gpio);
|
||||
|
|
@ -124,11 +121,9 @@ static int cpm2_gpio32_get(struct gpio_chip *gc, unsigned int gpio)
|
|||
return !!(in_be32(&iop->dat) & pin_mask);
|
||||
}
|
||||
|
||||
static void __cpm2_gpio32_set(struct of_mm_gpio_chip *mm_gc, u32 pin_mask,
|
||||
int value)
|
||||
static void __cpm2_gpio32_set(struct cpm2_gpio32_chip *cpm2_gc, u32 pin_mask, int value)
|
||||
{
|
||||
struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(&mm_gc->gc);
|
||||
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
||||
struct cpm2_ioports __iomem *iop = cpm2_gc->regs;
|
||||
|
||||
if (value)
|
||||
cpm2_gc->cpdata |= pin_mask;
|
||||
|
|
@ -140,14 +135,13 @@ static void __cpm2_gpio32_set(struct of_mm_gpio_chip *mm_gc, u32 pin_mask,
|
|||
|
||||
static int cpm2_gpio32_set(struct gpio_chip *gc, unsigned int gpio, int value)
|
||||
{
|
||||
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
||||
struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc);
|
||||
unsigned long flags;
|
||||
u32 pin_mask = 1 << (31 - gpio);
|
||||
|
||||
spin_lock_irqsave(&cpm2_gc->lock, flags);
|
||||
|
||||
__cpm2_gpio32_set(mm_gc, pin_mask, value);
|
||||
__cpm2_gpio32_set(cpm2_gc, pin_mask, value);
|
||||
|
||||
spin_unlock_irqrestore(&cpm2_gc->lock, flags);
|
||||
|
||||
|
|
@ -156,16 +150,15 @@ static int cpm2_gpio32_set(struct gpio_chip *gc, unsigned int gpio, int value)
|
|||
|
||||
static int cpm2_gpio32_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
|
||||
{
|
||||
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
||||
struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc);
|
||||
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
||||
struct cpm2_ioports __iomem *iop = cpm2_gc->regs;
|
||||
unsigned long flags;
|
||||
u32 pin_mask = 1 << (31 - gpio);
|
||||
|
||||
spin_lock_irqsave(&cpm2_gc->lock, flags);
|
||||
|
||||
setbits32(&iop->dir, pin_mask);
|
||||
__cpm2_gpio32_set(mm_gc, pin_mask, val);
|
||||
__cpm2_gpio32_set(cpm2_gc, pin_mask, val);
|
||||
|
||||
spin_unlock_irqrestore(&cpm2_gc->lock, flags);
|
||||
|
||||
|
|
@ -174,9 +167,8 @@ static int cpm2_gpio32_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
|
|||
|
||||
static int cpm2_gpio32_dir_in(struct gpio_chip *gc, unsigned int gpio)
|
||||
{
|
||||
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
||||
struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc);
|
||||
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
||||
struct cpm2_ioports __iomem *iop = cpm2_gc->regs;
|
||||
unsigned long flags;
|
||||
u32 pin_mask = 1 << (31 - gpio);
|
||||
|
||||
|
|
@ -193,19 +185,17 @@ int cpm2_gpiochip_add32(struct device *dev)
|
|||
{
|
||||
struct device_node *np = dev->of_node;
|
||||
struct cpm2_gpio32_chip *cpm2_gc;
|
||||
struct of_mm_gpio_chip *mm_gc;
|
||||
struct gpio_chip *gc;
|
||||
|
||||
cpm2_gc = kzalloc(sizeof(*cpm2_gc), GFP_KERNEL);
|
||||
cpm2_gc = devm_kzalloc(dev, sizeof(*cpm2_gc), GFP_KERNEL);
|
||||
if (!cpm2_gc)
|
||||
return -ENOMEM;
|
||||
|
||||
spin_lock_init(&cpm2_gc->lock);
|
||||
|
||||
mm_gc = &cpm2_gc->mm_gc;
|
||||
gc = &mm_gc->gc;
|
||||
gc = &cpm2_gc->gc;
|
||||
|
||||
mm_gc->save_regs = cpm2_gpio32_save_regs;
|
||||
gc->base = -1;
|
||||
gc->ngpio = 32;
|
||||
gc->direction_input = cpm2_gpio32_dir_in;
|
||||
gc->direction_output = cpm2_gpio32_dir_out;
|
||||
|
|
@ -214,6 +204,16 @@ int cpm2_gpiochip_add32(struct device *dev)
|
|||
gc->parent = dev;
|
||||
gc->owner = THIS_MODULE;
|
||||
|
||||
return of_mm_gpiochip_add_data(np, mm_gc, cpm2_gc);
|
||||
gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", np);
|
||||
if (!gc->label)
|
||||
return -ENOMEM;
|
||||
|
||||
cpm2_gc->regs = devm_of_iomap(dev, np, 0, NULL);
|
||||
if (IS_ERR(cpm2_gc->regs))
|
||||
return PTR_ERR(cpm2_gc->regs);
|
||||
|
||||
cpm2_gpio32_save_regs(cpm2_gc);
|
||||
|
||||
return devm_gpiochip_add_data(dev, gc, cpm2_gc);
|
||||
}
|
||||
#endif /* CONFIG_CPM2 || CONFIG_8xx_GPIO */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue