gpio: phytium: switch PCI driver to immutable irq_chip
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/4 gpio: phytium: improve core IRQ and wake handling
Refactor the core GPIO IRQ path to better match gpiolib IRQ chip expectations and suspend/resume behavior.
This updates the core to:
- add IRQ chip print and wake hooks
- handle both single and multi-parent IRQ routing
- fix wake IRQ lookup by checking valid parent IRQs
- use GPIO clear/version macros shared by frontends
- track resume state while restoring IRQ registers
The change also keeps direction/output programming order consistent with other GPIO controllers.
--- drivers/gpio/gpio-phytium-core.c | 114 +++++++++++++++++++++++++------ drivers/gpio/gpio-phytium-core.h | 8 ++- 2 files changed, 102 insertions(+), 20 deletions(-)
drivers/gpio/gpio-phytium-core.c +95 -19
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 /* -* Copyright (c) 2019-2023, Phytium Phytium Technology Co., Ltd. +* Copyright (c) 2019-2023, Phytium Technology Co., Ltd. */ #include <linux/err.h>
@@ -8,11 +8,13 @@#include <linux/irq.h> #include <linux/module.h> #include <linux/bitops.h> +#include <linux/seq_file.h> +#include <linux/interrupt.h> #include "gpio-phytium-core.h" static int get_pin_location (struct phytium_gpio *gpio,unsigned int offset, -struct pin_loc *pl) +struct pin_loc *pl) {int ret;
@@ -32,7 +34,7 @@ static int get_pin_location(struct phytium_gpio *gpio, unsigned int offset, }static void phytium_gpio_toggle_trigger (struct phytium_gpio *gpio, -unsigned int offset) +unsigned int offset) {struct gpio_chip *gc;u32 pol;
@@ -128,14 +130,13 @@ int phytium_gpio_direction_output(struct gpio_chip *gc, unsigned int offset,return -EINVAL ; ddr = gpio->regs +GPIO_SWPORTA_DDR + (loc.port *GPIO_PORT_STRIDE ); +phytium_gpio_set (gc, offset, value);raw_spin_lock_irqsave (&gpio->lock, flags);writel (readl (ddr) |BIT (loc.offset), ddr);raw_spin_unlock_irqrestore (&gpio->lock, flags); -phytium_gpio_set (gc, offset, value); -return 0 ; }EXPORT_SYMBOL_GPL (phytium_gpio_direction_output);
@@ -171,6 +172,8 @@ void phytium_gpio_irq_mask(struct irq_data *d)writel (val, gpio->regs +GPIO_INTMASK );raw_spin_unlock (&gpio->lock); + +gpiochip_disable_irq (gc,irqd_to_hwirq (d)); }EXPORT_SYMBOL_GPL (phytium_gpio_irq_mask);
@@ -184,6 +187,8 @@ void phytium_gpio_irq_unmask(struct irq_data *d)if (irqd_to_hwirq (d) >= gpio->ngpio[0 ])return ; +gpiochip_enable_irq (gc,irqd_to_hwirq (d)); +raw_spin_lock (&gpio->lock); val =readl (gpio->regs +GPIO_INTMASK );
@@ -267,10 +272,14 @@ void phytium_gpio_irq_enable(struct irq_data *d)unsigned long flags;u32 val; +if (gpio->is_resuming) +return ;/* Only port A can provide interrupt source */ if (irqd_to_hwirq (d) >= gpio->ngpio[0 ])return ; +gpiochip_enable_irq (gc,irqd_to_hwirq (d)); +raw_spin_lock_irqsave (&gpio->lock, flags); val =readl (gpio->regs +GPIO_INTEN );
@@ -278,6 +287,8 @@ void phytium_gpio_irq_enable(struct irq_data *d)writel (val, gpio->regs +GPIO_INTEN );raw_spin_unlock_irqrestore (&gpio->lock, flags); + +gpiochip_disable_irq (gc,irqd_to_hwirq (d)); }EXPORT_SYMBOL_GPL (phytium_gpio_irq_enable);
@@ -302,6 +313,14 @@ void phytium_gpio_irq_disable(struct irq_data *d) }EXPORT_SYMBOL_GPL (phytium_gpio_irq_disable); +void phytium_gpio_irq_print_chip (struct irq_data *data,struct seq_file *p) +{ +struct gpio_chip *gc =irq_data_get_irq_chip_data (data); + +seq_printf (p,dev_name (gc->parent)); +} +EXPORT_SYMBOL_GPL (phytium_gpio_irq_print_chip); +void phytium_gpio_irq_handler (struct irq_desc *desc) {struct gpio_chip *gc =irq_desc_get_handler_data (desc);
@@ -309,19 +328,36 @@ void phytium_gpio_irq_handler(struct irq_desc *desc)struct irq_chip *irqchip =irq_desc_get_chip (desc);unsigned long pending;int offset; +int index =-1 ; +unsigned int index_found =0 ;chained_irq_enter (irqchip, desc); pending =readl (gpio->regs +GPIO_INTSTATUS ); + +if (gc->irq.num_parents >1 ) { +for (index =0 ; index < gc->irq.num_parents; index++) { +if (gc->irq.parents[index] == desc->irq_data.irq) { + index_found =1 ; +break ; + } + } +if (index_found ==0 ) { +pr_err ("Can't find index for this gpio interrupt.\n" ); + index =-1 ; + } + } +if (pending) {for_each_set_bit (offset, &pending, gpio->ngpio[0 ]) { -int gpio_irq =irq_find_mapping (gc->irq.domain, - offset); -generic_handle_irq (gpio_irq); - -if ((irq_get_trigger_type (gpio_irq) & -IRQ_TYPE_SENSE_MASK ) ==IRQ_TYPE_EDGE_BOTH ) -phytium_gpio_toggle_trigger (gpio, offset); +if (index ==-1 || offset == index) { +int gpio_irq =irq_find_mapping (gc->irq.domain, + offset); +generic_handle_irq (gpio_irq); +if ((irq_get_trigger_type (gpio_irq) & +IRQ_TYPE_SENSE_MASK ) ==IRQ_TYPE_EDGE_BOTH ) +phytium_gpio_toggle_trigger (gpio, offset); + } } }
@@ -343,13 +379,54 @@ int phytium_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) }EXPORT_SYMBOL_GPL (phytium_gpio_get_direction); -#if CONFIG_SMP -int -phytium_gpio_irq_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force) +int phytium_gpio_irq_set_wake (struct irq_data *d,unsigned int enable) { +struct gpio_chip *gc =irq_data_get_irq_chip_data (d); +struct phytium_gpio *gpio =gpiochip_get_data (gc); +struct phytium_gpio_ctx *ctx = &gpio->ctx; +irq_hw_number_t bit =irqd_to_hwirq (d); +unsigned long flags; +int ret; + +if (gpio->irq[bit] >=0 ) + ret =irq_set_irq_wake (gpio->irq[bit], enable); +else + ret =irq_set_irq_wake (gpio->irq[0 ], enable); + +if (ret <0 ) +dev_err (gc->parent,"set gpio irq wake failed!\n" ); + +raw_spin_lock_irqsave (&gpio->lock, flags); + +if (enable) { + ctx->wake_en |=BIT (bit); +if (gpio->is_resuming ==1 ) { +writel (~ctx->wake_en, gpio->regs +GPIO_INTMASK ); +writel (ctx->wake_en, gpio->regs +GPIO_INTEN ); + } + }else { + ctx->wake_en &= ~BIT (bit); + } + +raw_spin_unlock_irqrestore (&gpio->lock, flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (phytium_gpio_irq_set_wake); + +int phytium_gpio_irq_set_affinity (struct irq_data *d, +const struct cpumask *mask_val,bool force) +{ +int hwirq =irqd_to_hwirq (d);struct gpio_chip *chip_data =irq_data_get_irq_chip_data (d); -struct irq_chip *chip =irq_get_chip (chip_data->irq.num_parents); -struct irq_data *data =irq_get_irq_data (chip_data->irq.num_parents); +struct irq_chip *chip; +struct irq_data *data; + +if (chip_data->irq.num_parents ==1 ) + hwirq =0 ; + + chip =irq_get_chip (chip_data->irq.parents[hwirq]); + data =irq_get_irq_data (chip_data->irq.parents[hwirq]);if (chip && chip->irq_set_affinity)return chip->irq_set_affinity (data, mask_val, force);
@@ -357,7 +434,6 @@ phytium_gpio_irq_set_affinity(struct irq_data *d, const struct cpumask *mask_valreturn -EINVAL ; }EXPORT_SYMBOL_GPL (phytium_gpio_irq_set_affinity); -#endif -MODULE_LICENSE ("GPL v2" ); +MODULE_LICENSE ("GPL" );MODULE_DESCRIPTION ("Phytium GPIO Controller core" );
drivers/gpio/gpio-phytium-core.h +7 -1
@@ -32,6 +32,9 @@#define NGPIO_DEFAULT 8#define NGPIO_MAX 32#define GPIO_PORT_STRIDE (GPIO_EXT_PORTB - GPIO_EXT_PORTA) +#define GPIO_CLEAR_IRQ 0xffffffff + +#define PHYTIUM_GPIO_DRIVER_VERSION "1.1.2"struct pin_loc {unsigned int port;
@@ -54,6 +57,7 @@ struct phytium_gpio_ctx {u32 raw_intstatus;u32 ls_sync;u32 debounce; + u32 wake_en; };#endif
@@ -61,9 +65,9 @@ struct phytium_gpio {raw_spinlock_t lock;void __iomem *regs;struct gpio_chip gc; -struct irq_chip irq_chip;unsigned int ngpio[2 ];int irq[32 ]; +int is_resuming;#ifdef CONFIG_PM_SLEEP struct phytium_gpio_ctx ctx;#endif
@@ -80,8 +84,10 @@ void phytium_gpio_irq_ack(struct irq_data *d);void phytium_gpio_irq_mask (struct irq_data *d);void phytium_gpio_irq_unmask (struct irq_data *d);int phytium_gpio_irq_set_type (struct irq_data *d,unsigned int flow_type); +void phytium_gpio_irq_print_chip (struct irq_data *data,struct seq_file *p);void phytium_gpio_irq_enable (struct irq_data *d);void phytium_gpio_irq_disable (struct irq_data *d);void phytium_gpio_irq_handler (struct irq_desc *desc); +int phytium_gpio_irq_set_wake (struct irq_data *d,unsigned int enable);int phytium_gpio_irq_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force);#endif
Signature · 1 line
2.34.1
PATCH 2/4 gpio: phytium: switch platform driver to immutable irq_chip
In reply to a message not in the archiveUse a static immutable irq_chip and gpio_irq_chip_set_chip() in the platform frontend.
Also initialize and restore interrupt state more explicitly for suspend and resume, and accept both ngpios and nr-gpios child properties when probing GPIO ports.
--- drivers/gpio/gpio-phytium-platform.c | 55 ++++++++++++++++++---------- 1 file changed, 35 insertions(+), 20 deletions(-)
drivers/gpio/gpio-phytium-platform.c +35 -20
@@ -2,7 +2,7 @@/* * Support functions for Phytium GPIO * -* Copyright (c) 2019-2023, Phytium Phytium Technology Co., Ltd. +* Copyright (c) 2019-2023, Phytium Technology Co., Ltd. * * Derived from drivers/gpio/gpio-pl061.c * Copyright (C) 2008, 2009 Provigent Ltd.
@@ -33,6 +33,20 @@ static const struct acpi_device_id phytium_gpio_acpi_match[] = { };MODULE_DEVICE_TABLE (acpi, phytium_gpio_acpi_match); +static const struct irq_chip phytium_gpio_irq_chip = { + .irq_ack = phytium_gpio_irq_ack, + .irq_mask = phytium_gpio_irq_mask, + .irq_unmask = phytium_gpio_irq_unmask, + .irq_set_type = phytium_gpio_irq_set_type, + .irq_print_chip = phytium_gpio_irq_print_chip, + .irq_enable = phytium_gpio_irq_enable, + .irq_disable = phytium_gpio_irq_disable, + .irq_set_wake = phytium_gpio_irq_set_wake, + .irq_set_affinity = phytium_gpio_irq_set_affinity, + .flags =IRQCHIP_IMMUTABLE , +GPIOCHIP_IRQ_RESOURCE_HELPERS , +}; +static int phytium_gpio_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -64,8 +78,10 @@ static int phytium_gpio_probe(struct platform_device *pdev)return -EINVAL ; } -if (fwnode_property_read_u32 (fwnode,"ngpios" , - &gpio->ngpio[idx])) { +if ((fwnode_property_read_u32 (fwnode,"ngpios" , + &gpio->ngpio[idx])) && + (fwnode_property_read_u32 (fwnode,"nr-gpios" , + &gpio->ngpio[idx]))) {dev_info (dev,"failed to get number of gpios for Port%c\n" , idx ?'B' :'A' );
@@ -74,18 +90,11 @@ static int phytium_gpio_probe(struct platform_device *pdev) }/* irq_chip support */ - gpio->irq_chip.name =dev_name (dev); - gpio->irq_chip.irq_ack = phytium_gpio_irq_ack; - gpio->irq_chip.irq_mask = phytium_gpio_irq_mask; - gpio->irq_chip.irq_unmask = phytium_gpio_irq_unmask; - gpio->irq_chip.irq_set_type = phytium_gpio_irq_set_type; - gpio->irq_chip.irq_enable = phytium_gpio_irq_enable; - gpio->irq_chip.irq_disable = phytium_gpio_irq_disable; -#ifdef CONFIG_SMP - gpio->irq_chip.irq_set_affinity = phytium_gpio_irq_set_affinity; -#endif raw_spin_lock_init (&gpio->lock); +writel (0 , gpio->regs +GPIO_INTEN ); +writel (GPIO_CLEAR_IRQ , gpio->regs +GPIO_PORTA_EOI ); + gpio->gc.base =-1 ; gpio->gc.get_direction = phytium_gpio_get_direction; gpio->gc.direction_input = phytium_gpio_direction_input;
@@ -101,20 +110,20 @@ static int phytium_gpio_probe(struct platform_device *pdev) girq->handler = handle_bad_irq; girq->default_type =IRQ_TYPE_NONE ; -for (irq_count =0 ; irq_count < gpio->ngpio[0 ]; irq_count++) { +for (irq_count =0 ; irq_count <platform_irq_count (pdev); irq_count++) { gpio->irq[irq_count] = -ENXIO ; gpio->irq[irq_count] =platform_get_irq (pdev, irq_count);if (gpio->irq[irq_count] <0 ) {dev_warn (dev,"no irq is found.\n" );break ; } - }; + } girq->num_parents = irq_count; girq->parents = gpio->irq; girq->parent_handler = phytium_gpio_irq_handler; - girq->chip = &gpio->irq_chip; +gpio_irq_chip_set_chip (girq, &phytium_gpio_irq_chip); err =devm_gpiochip_add_data (dev, &gpio->gc, gpio);if (err)
@@ -122,7 +131,7 @@ static int phytium_gpio_probe(struct platform_device *pdev)platform_set_drvdata (pdev, gpio);dev_info (dev,"Phytium GPIO controller @%pa registered\n" , - &res->start); + &res->start);return 0 ; }
@@ -144,11 +153,14 @@ static int phytium_gpio_suspend(struct device *dev) gpio->ctx.ext_portb =readl (gpio->regs +GPIO_EXT_PORTB ); gpio->ctx.inten =readl (gpio->regs +GPIO_INTEN ); + gpio->is_resuming =1 ; gpio->ctx.intmask =readl (gpio->regs +GPIO_INTMASK ); gpio->ctx.inttype_level =readl (gpio->regs +GPIO_INTTYPE_LEVEL ); gpio->ctx.int_polarity =readl (gpio->regs +GPIO_INT_POLARITY ); gpio->ctx.debounce =readl (gpio->regs +GPIO_DEBOUNCE ); +writel (~gpio->ctx.wake_en, gpio->regs +GPIO_INTMASK ); +writel (gpio->ctx.wake_en, gpio->regs +GPIO_INTEN );raw_spin_unlock_irqrestore (&gpio->lock, flags);return 0 ;
@@ -169,13 +181,15 @@ static int phytium_gpio_resume(struct device *dev)writel (gpio->ctx.swportb_ddr, gpio->regs +GPIO_SWPORTB_DDR );writel (gpio->ctx.ext_portb, gpio->regs +GPIO_EXT_PORTB ); -writel (gpio->ctx.inten, gpio->regs +GPIO_INTEN );writel (gpio->ctx.intmask, gpio->regs +GPIO_INTMASK );writel (gpio->ctx.inttype_level, gpio->regs +GPIO_INTTYPE_LEVEL );writel (gpio->ctx.int_polarity, gpio->regs +GPIO_INT_POLARITY );writel (gpio->ctx.debounce, gpio->regs +GPIO_DEBOUNCE ); -writel (0xffffffff , gpio->regs +GPIO_PORTA_EOI ); +writel (GPIO_CLEAR_IRQ , gpio->regs +GPIO_PORTA_EOI ); + +writel (gpio->ctx.inten, gpio->regs +GPIO_INTEN ); + gpio->is_resuming =0 ;raw_spin_unlock_irqrestore (&gpio->lock, flags);
@@ -198,6 +212,7 @@ static struct platform_driver phytium_gpio_driver = {module_platform_driver (phytium_gpio_driver); -MODULE_LICENSE ("GPL v2" ); +MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Chen Baozi <[email protected]>" );MODULE_DESCRIPTION ("Phytium GPIO driver" ); +MODULE_VERSION (PHYTIUM_GPIO_DRIVER_VERSION );
Signature · 1 line
2.34.1
PATCH 3/4 gpio: phytium: switch PCI driver to immutable irq_chip
In reply to a message not in the archiveUse a static immutable irq_chip and gpio_irq_chip_set_chip() in the PCI frontend and align interrupt init/restore flow with the core and platform driver paths.
--- drivers/gpio/gpio-phytium-pci.c | 43 ++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-)
drivers/gpio/gpio-phytium-pci.c +29 -14
@@ -13,6 +13,20 @@#include "gpio-phytium-core.h" +static const struct irq_chip phytium_gpio_irq_chip = { + .irq_ack = phytium_gpio_irq_ack, + .irq_mask = phytium_gpio_irq_mask, + .irq_unmask = phytium_gpio_irq_unmask, + .irq_set_type = phytium_gpio_irq_set_type, + .irq_print_chip = phytium_gpio_irq_print_chip, + .irq_enable = phytium_gpio_irq_enable, + .irq_disable = phytium_gpio_irq_disable, + .irq_set_wake = phytium_gpio_irq_set_wake, + .irq_set_affinity = phytium_gpio_irq_set_affinity, + .flags =IRQCHIP_IMMUTABLE , +GPIOCHIP_IRQ_RESOURCE_HELPERS , +}; +static int phytium_gpio_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) {struct device *dev = &pdev->dev;
@@ -50,23 +64,18 @@ static int phytium_gpio_pci_probe(struct pci_dev *pdev, const struct pci_device_pci_set_master (pdev); gpio->irq[0 ] = pdev->irq; -if (gpio->irq <0 ) +if (gpio->irq[0 ] <0 )dev_warn (dev,"no irq is found.\n" );/* There is only one group of Pins at the moment. */ gpio->ngpio[0 ] =NGPIO_MAX ;/* irq_chip support */ - gpio->irq_chip.name =dev_name (dev); - gpio->irq_chip.irq_ack = phytium_gpio_irq_ack; - gpio->irq_chip.irq_mask = phytium_gpio_irq_mask; - gpio->irq_chip.irq_unmask = phytium_gpio_irq_unmask; - gpio->irq_chip.irq_set_type = phytium_gpio_irq_set_type; - gpio->irq_chip.irq_enable = phytium_gpio_irq_enable; - gpio->irq_chip.irq_disable = phytium_gpio_irq_disable; -raw_spin_lock_init (&gpio->lock); +writel (0 , gpio->regs +GPIO_INTEN ); +writel (GPIO_CLEAR_IRQ , gpio->regs +GPIO_PORTA_EOI ); + gpio->gc.base =-1 ; gpio->gc.get_direction = phytium_gpio_get_direction; gpio->gc.direction_input = phytium_gpio_direction_input;
@@ -90,14 +99,14 @@ static int phytium_gpio_pci_probe(struct pci_dev *pdev, const struct pci_device_ girq->parents[0 ] = gpio->irq[0 ]; girq->parent_handler = phytium_gpio_irq_handler; - girq->chip = &gpio->irq_chip; +gpio_irq_chip_set_chip (girq, &phytium_gpio_irq_chip); err =devm_gpiochip_add_data (dev, &gpio->gc, gpio);if (err) goto out;dev_info (dev,"Phytium PCI GPIO controller @%pa registered\n" , - &gpio->regs); + &pdev->resource[0 ].start);pci_set_drvdata (pdev, gpio);
@@ -128,11 +137,14 @@ static int phytium_gpio_pci_suspend(struct device *dev) gpio->ctx.ext_portb =readl (gpio->regs +GPIO_EXT_PORTB ); gpio->ctx.inten =readl (gpio->regs +GPIO_INTEN ); + gpio->is_resuming =1 ; gpio->ctx.intmask =readl (gpio->regs +GPIO_INTMASK ); gpio->ctx.inttype_level =readl (gpio->regs +GPIO_INTTYPE_LEVEL ); gpio->ctx.int_polarity =readl (gpio->regs +GPIO_INT_POLARITY ); gpio->ctx.debounce =readl (gpio->regs +GPIO_DEBOUNCE ); +writel (~gpio->ctx.wake_en, gpio->regs +GPIO_INTMASK ); +writel (gpio->ctx.wake_en, gpio->regs +GPIO_INTEN );raw_spin_unlock_irqrestore (&gpio->lock, flags);return 0 ;
@@ -153,13 +165,15 @@ static int phytium_gpio_pci_resume(struct device *dev)writel (gpio->ctx.swportb_ddr, gpio->regs +GPIO_SWPORTB_DDR );writel (gpio->ctx.ext_portb, gpio->regs +GPIO_EXT_PORTB ); -writel (gpio->ctx.inten, gpio->regs +GPIO_INTEN );writel (gpio->ctx.intmask, gpio->regs +GPIO_INTMASK );writel (gpio->ctx.inttype_level, gpio->regs +GPIO_INTTYPE_LEVEL );writel (gpio->ctx.int_polarity, gpio->regs +GPIO_INT_POLARITY );writel (gpio->ctx.debounce, gpio->regs +GPIO_DEBOUNCE ); -writel (0xffffffff , gpio->regs +GPIO_PORTA_EOI ); +writel (GPIO_CLEAR_IRQ , gpio->regs +GPIO_PORTA_EOI ); + +writel (gpio->ctx.inten, gpio->regs +GPIO_INTEN ); + gpio->is_resuming =0 ;raw_spin_unlock_irqrestore (&gpio->lock, flags);
@@ -182,6 +196,7 @@ static struct pci_driver phytium_gpio_pci_driver = {module_pci_driver (phytium_gpio_pci_driver); -MODULE_LICENSE ("GPL v2" ); +MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Cheng Quan <[email protected]>" );MODULE_DESCRIPTION ("Phytium GPIO PCI Driver" ); +MODULE_VERSION (PHYTIUM_GPIO_DRIVER_VERSION );
Signature · 1 line
2.34.1
PATCH 4/4 gpio: phytium: add ACPI support for SGPIO
In reply to a message not in the archiveAdd ACPI match support for the Phytium SGPIO controller and allow fetching the APB clock frequency from firmware properties when running under ACPI.
Keep the device-tree clock path intact for non-ACPI systems.
--- drivers/gpio/gpio-phytium-sgpio.c | 44 +++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 11 deletions(-)
drivers/gpio/gpio-phytium-sgpio.c +33 -11
@@ -17,6 +17,7 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/string.h> +#include <linux/acpi.h> #define SGPIO_CTL0_REG 0x00#define SGPIO_CTL0_REG_ENABLE BIT(0)
@@ -42,17 +43,21 @@#define SGPIO_RDATA_REG (x) (SGPIO_RDATA0_REG + (x) * 4)#define DEFAULT_L3_L0 0 +#define DEFAULT_CLK 50000000#define GPIO_GROUP (x) ((x) >> 6)#define GPIO_OFFSET (x) ((x) & GENMASK(5, 0))#define GPIO_BIT (x) BIT(GPIO_OFFSET(x) >> 1) +#define GPIO_SGPIO_DRIVER_VERSION "1.1.0" +struct phytium_sgpio {struct gpio_chip gc;void __iomem *regs;unsigned int ngpios;struct clk *pclk; +/* Serialize value access with IRQ completion flow. */ struct mutex lock;struct completion completion; };
@@ -154,7 +159,7 @@ static int phytium_sgpio_get(struct gpio_chip *gc, unsigned int offset) rc = !!(val &GPIO_BIT (offset)); err: -/* Disalbe Rx to hold the value */ +/* Disable Rx to hold the value */ writel (ctl0 |SGPIO_CTL0_REG_RX_DISABLE , gpio->regs +SGPIO_CTL0_REG );mutex_unlock (&gpio->lock);
@@ -229,17 +234,26 @@ static int phytium_sgpio_probe(struct platform_device *pdev)return -EINVAL ; } - gpio->pclk =devm_clk_get (dev,NULL ); -if (IS_ERR (gpio->pclk)) { -dev_err (dev,"Could not get the APB clock property\n" ); -return PTR_ERR (gpio->pclk); - } - rc =clk_prepare_enable (gpio->pclk); -if (rc) { -dev_err (dev,"failed to enable pclk: %d\n" , rc); -return rc; +if (has_acpi_companion (dev)) { +device_property_read_u32 (dev,"pclk_freq" , &pclk_freq); +if (!pclk_freq || pclk_freq !=50000000 ) { +dev_err (dev,"Could not get APB clock property from acpi, use default clk!\n" ); + pclk_freq =DEFAULT_CLK ; + } + + }else { + gpio->pclk =devm_clk_get (dev,NULL ); +if (IS_ERR (gpio->pclk)) { +dev_err (dev,"Could not get the APB clock property\n" ); +return PTR_ERR (gpio->pclk); + } + rc =clk_prepare_enable (gpio->pclk); +if (rc) { +dev_err (dev,"failed to enable pclk: %d\n" , rc); +return rc; + } + pclk_freq =clk_get_rate (gpio->pclk); } - pclk_freq =clk_get_rate (gpio->pclk);/* * From the datasheet:
@@ -287,10 +301,17 @@ static const struct of_device_id phytium_sgpio_of_match[] = { };MODULE_DEVICE_TABLE (of, phytium_sgpio_of_match); +static const struct acpi_device_id phytium_sgpio_acpi_match[] = { + {"PHYT0031" ,0 }, + {}, +}; +MODULE_DEVICE_TABLE (acpi, phytium_sgpio_acpi_match); +static struct platform_driver phytium_sgpio_driver = { .driver = { .name =KBUILD_MODNAME , .of_match_table =of_match_ptr (phytium_sgpio_of_match), + .acpi_match_table =ACPI_PTR (phytium_sgpio_acpi_match), }, .probe = phytium_sgpio_probe, };
@@ -299,3 +320,4 @@ module_platform_driver(phytium_sgpio_driver);MODULE_AUTHOR ("Chen Baozi <[email protected]>" );MODULE_DESCRIPTION ("Phytium SGPIO driver" );MODULE_LICENSE ("GPL" ); +MODULE_VERSION (GPIO_SGPIO_DRIVER_VERSION );
Signature · 1 line
2.34.1
cover gpio: phytium: improve IRQ integration and add SGPIO ACPI support (please ignore)
In reply to a message not in the archivePlease ignore the previously posted v1 series.
It was generated against an incorrect base tree.
I will resend a corrected v2 series.
Thanks,
Zhu Ling
Signature · 1 line
2.34.1