[PATCH 2/4] staging: mt7621-gpio: use custom xlate function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The default gpio.of_xlate function assumes there is one gpio chip
for each devicetree node. Device tree had changed to only use one node,
which corresponds to 3 different gpio chips now. For that approach
to work we need a custom xlate function.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@xxxxxxxxx>
---
 drivers/staging/mt7621-gpio/gpio-mt7621.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/staging/mt7621-gpio/gpio-mt7621.c b/drivers/staging/mt7621-gpio/gpio-mt7621.c
index 06024a3..ccf2aa8 100644
--- a/drivers/staging/mt7621-gpio/gpio-mt7621.c
+++ b/drivers/staging/mt7621-gpio/gpio-mt7621.c
@@ -206,6 +206,22 @@ static inline const char * const mediatek_gpio_bank_name(int bank)
 }
 
 static int
+mediatek_gpio_xlate(struct gpio_chip *chip,
+		    const struct of_phandle_args *spec, u32 *flags)
+{
+	int gpio = spec->args[0];
+	struct mtk_gc *rg = to_mediatek_gpio(chip);
+
+	if (rg->bank != gpio / MTK_BANK_WIDTH)
+		return -EINVAL;
+
+	if (flags)
+		*flags = spec->args[1];
+
+	return gpio % MTK_BANK_WIDTH;
+}
+
+static int
 mediatek_gpio_bank_probe(struct platform_device *pdev,
 			 struct device_node *node, int bank)
 {
@@ -220,6 +236,8 @@ mediatek_gpio_bank_probe(struct platform_device *pdev,
 	spin_lock_init(&rg->lock);
 	rg->chip.of_node = node;
 	rg->bank = bank;
+	rg->chip.of_gpio_n_cells = 2;
+	rg->chip.of_xlate = mediatek_gpio_xlate;
 	rg->chip.label = mediatek_gpio_bank_name(rg->bank);
 
 	dat = gpio->gpio_membase + GPIO_REG_DATA + (rg->bank * GPIO_BANK_WIDE);
-- 
2.7.4

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux