+static inline struct tegra_gpio *to_tegra_gpio(struct gpio_chip *chip)
+{
+ return container_of(chip, struct tegra_gpio, gpio);
+}
+Why not get the port from pins and then calculate with fixed offset.
+static const struct tegra_gpio_port *
+tegra186_gpio_get_port(struct tegra_gpio *gpio, unsigned int *pin)
+{
+ unsigned int start = 0, i;
+
+ for (i = 0; i < gpio->soc->num_ports; i++) {
+ const struct tegra_gpio_port *port = &gpio->soc->ports[i];
+
+ if (*pin >= start && *pin < start + port->pins) {
+ *pin -= start;
+ return port;
+ }
+
+ start += port->pins;
+ }
+
We can directly call the apis instead of function pointer at this point.
+
+static int tegra186_gpio_direction_output(struct gpio_chip *chip,
+ unsigned int offset, int level)
+{
+ struct tegra_gpio *gpio = to_tegra_gpio(chip);
+ void __iomem *base;
+ u32 value;
+
+ /* configure output level first */
+ chip->set(chip, offset, level);
We will have two instance of the driver (normal and AON) and so this will be shared between them.
+
+static struct lock_class_key tegra186_gpio_lock_class;
+Two instance will have same name. Better to say tegra186-gpio and tegra186-gpio-aon.
+ gpio->gpio.label = "tegra186-gpio";
+ gpio->gpio.parent = &pdev->dev;
+
+ gpio->gpio.get_direction = tegra186_gpio_get_direction;
+ gpio->gpio.direction_input = tegra186_gpio_direction_input;
+ gpio->gpio.direction_output = tegra186_gpio_direction_output;
+ gpio->gpio.get = tegra186_gpio_get,
+ gpio->gpio.set = tegra186_gpio_set;
+ gpio->gpio.to_irq = tegra186_gpio_to_irq;
+
+ gpio->gpio.base = -1;
+
+ for (i = 0; i < gpio->soc->num_ports; i++)
+ gpio->gpio.ngpio += gpio->soc->ports[i].pins;
+
Use C99 style initialization which is like
+
+static const struct tegra_gpio_port tegra186_main_ports[] = {
+ [TEGRA_MAIN_GPIO_PORT_A] = { 0x2000, 7 },