Changes in 4.9.276 ALSA: usb-audio: fix rate on Ozone Z90 USB headset media: dvb-usb: fix wrong definition Input: usbtouchscreen - fix control-request directions net: can: ems_usb: fix use-after-free in ems_usb_disconnect() usb: gadget: eem: fix echo command packet response issue USB: cdc-acm: blacklist Heimann USB Appset device ntfs: fix validity check for file name attribute iov_iter_fault_in_readable() should do nothing in xarray case Input: joydev - prevent use of not validated data in JSIOCSBTNMAP ioctl ARM: dts: at91: sama5d4: fix pinctrl muxing btrfs: clear defrag status of a root if starting transaction fails ext4: fix kernel infoleak via ext4_extent_header ext4: correct the cache_nr in tracepoint ext4_es_shrink_exit ext4: remove check for zero nr_to_scan in ext4_es_scan() ext4: fix avefreec in find_group_orlov SUNRPC: Fix the batch tasks count wraparound. SUNRPC: Should wake up the privileged task firstly. s390/cio: dont call css_wait_for_slow_path() inside a lock iio: ltr501: mark register holding upper 8 bits of ALS_DATA{0,1} and PS_DATA as volatile, too iio: ltr501: ltr559: fix initialization of LTR501_ALS_CONTR iio: ltr501: ltr501_read_ps(): add missing endianness conversion serial: sh-sci: Stop dmaengine transfer in sci_stop_tx() serial_cs: Add Option International GSM-Ready 56K/ISDN modem serial_cs: remove wrong GLOBETROTTER.cis entry ath9k: Fix kernel NULL pointer dereference during ath_reset_internal() ssb: sdio: Don't overwrite const buffer if block_write fails seq_buf: Make trace_seq_putmem_hex() support data longer than 8 fuse: check connected before queueing on fpq->io spi: spi-loopback-test: Fix 'tx_buf' might be 'rx_buf' spi: spi-topcliff-pch: Fix potential double free in pch_spi_process_messages() spi: omap-100k: Fix the length judgment problem crypto: nx - add missing MODULE_DEVICE_TABLE media: cpia2: fix memory leak in cpia2_usb_probe media: cobalt: fix race condition in setting HPD media: pvrusb2: fix warning in pvr2_i2c_core_done crypto: qat - check return code of qat_hal_rd_rel_reg() crypto: qat - remove unused macro in FW loader media: v4l2-core: Avoid the dangling pointer in v4l2_fh_release media: bt8xx: Fix a missing check bug in bt878_probe media: st-hva: Fix potential NULL pointer dereferences mmc: via-sdmmc: add a check against NULL pointer dereference crypto: shash - avoid comparing pointers to exported functions under CFI media: dvb_net: avoid speculation from net slot media: siano: fix device register error path btrfs: abort transaction if we fail to update the delayed inode btrfs: disable build on platforms having page size 256K regulator: da9052: Ensure enough delay time for .set_voltage_time_sel ACPI: processor idle: Fix up C-state latency if not ordered block_dump: remove block_dump feature in mark_inode_dirty() fs: dlm: cancel work sync othercon random32: Fix implicit truncation warning in prandom_seed_state() fs: dlm: fix memory leak when fenced ACPI: bus: Call kobject_put() in acpi_init() error path platform/x86: toshiba_acpi: Fix missing error code in toshiba_acpi_setup_keyboard() ACPI: tables: Add custom DSDT file as makefile prerequisite ia64: mca_drv: fix incorrect array size calculation media: s5p_cec: decrement usage count if disabled crypto: ixp4xx - dma_unmap the correct address crypto: ux500 - Fix error return code in hash_hw_final() sata_highbank: fix deferred probing pata_rb532_cf: fix deferred probing media: I2C: change 'RST' to "RSET" to fix multiple build errors pata_octeon_cf: avoid WARN_ON() in ata_host_activate() pata_ep93xx: fix deferred probing media: tc358743: Fix error return code in tc358743_probe_of() media: siano: Fix out-of-bounds warnings in smscore_load_firmware_family2() mmc: usdhi6rol0: fix error return code in usdhi6_probe() media: s5p-g2d: Fix a memory leak on ctx->fh.m2m_ctx hwmon: (max31722) Remove non-standard ACPI device IDs hwmon: (max31790) Fix fan speed reporting for fan7..12 spi: spi-sun6i: Fix chipselect/clock bug crypto: nx - Fix RCU warning in nx842_OF_upd_status ACPI: sysfs: Fix a buffer overrun problem with description_show() ocfs2: fix snprintf() checking net: pch_gbe: Propagate error from devm_gpio_request_one() ehea: fix error return code in ehea_restart_qps() RDMA/rxe: Fix failure during driver load drm: qxl: ensure surf.data is ininitialized wireless: carl9170: fix LEDS build errors & warnings brcmsmac: mac80211_if: Fix a resource leak in an error handling path ath10k: Fix an error code in ath10k_add_interface() netlabel: Fix memory leak in netlbl_mgmt_add_common netfilter: nft_exthdr: check for IPv6 packet before further processing net: ethernet: aeroflex: fix UAF in greth_of_remove net: ethernet: ezchip: fix UAF in nps_enet_remove net: ethernet: ezchip: fix error handling vxlan: add missing rcu_read_lock() in neigh_reduce() i40e: Fix error handling in i40e_vsi_open Bluetooth: mgmt: Fix slab-out-of-bounds in tlv_data_is_valid writeback: fix obtain a reference to a freeing memcg css net: sched: fix warning in tcindex_alloc_perfect_hash tty: nozomi: Fix a resource leak in an error handling function iio: adis_buffer: do not return ints in irq handlers iio: accel: bma180: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: bma220: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: kxcjk-1013: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: stk8312: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: stk8ba50: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: ti-ads1015: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: vf610: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: gyro: bmg160: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: humidity: am2315: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: prox: pulsed-light: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: light: isl29125: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: light: tcs3414: Fix buffer alignment in iio_push_to_buffers_with_timestamp() Input: hil_kbd - fix error return code in hil_dev_connect() char: pcmcia: error out if 'num_bytes_read' is greater than 4 in set_protocol() tty: nozomi: Fix the error handling path of 'nozomi_card_init()' scsi: FlashPoint: Rename si_flags field s390: appldata depends on PROC_SYSCTL staging: gdm724x: check for buffer overflow in gdm_lte_multi_sdu_pkt() staging: gdm724x: check for overflow in gdm_lte_netif_rx() of: Fix truncation of memory sizes on 32-bit platforms scsi: mpt3sas: Fix error return value in _scsih_expander_add() phy: ti: dm816x: Fix the error handling path in 'dm816x_usb_phy_probe() extcon: sm5502: Drop invalid register write in sm5502_reg_data extcon: max8997: Add missing modalias string configfs: fix memleak in configfs_release_bin_file leds: ktd2692: Fix an error handling path mm/huge_memory.c: don't discard hugepage if other processes are mapping it selftests/vm/pkeys: fix alloc_random_pkey() to make it really, really random mmc: vub3000: fix control-request direction scsi: core: Retry I/O for Notify (Enable Spinup) Required error net: pch_gbe: Use proper accessors to BE data in pch_ptp_match() hugetlb: clear huge pte during flush function on mips platform atm: iphase: fix possible use-after-free in ia_module_exit() mISDN: fix possible use-after-free in HFC_cleanup() atm: nicstar: Fix possible use-after-free in nicstar_cleanup() net: Treat __napi_schedule_irqoff() as __napi_schedule() on PREEMPT_RT reiserfs: add check for invalid 1st journal block drm/virtio: Fix double free on probe failure udf: Fix NULL pointer dereference in udf_symlink function e100: handle eeprom as little endian clk: tegra: Ensure that PLLU configuration is applied properly ipv6: use prandom_u32() for ID generation RDMA/cxgb4: Fix missing error code in create_qp() dm space maps: don't reset space map allocation cursor when committing net: micrel: check return value after calling platform_get_resource() fjes: check return value after calling platform_get_resource() selinux: use __GFP_NOWARN with GFP_NOWAIT in the AVC xfrm: Fix error reporting in xfrm_state_construct. wlcore/wl12xx: Fix wl12xx get_mac error if device is in ELP wl1251: Fix possible buffer overflow in wl1251_cmd_scan cw1200: add missing MODULE_DEVICE_TABLE MIPS: add PMD table accounting into MIPS'pmd_alloc_one atm: nicstar: use 'dma_free_coherent' instead of 'kfree' atm: nicstar: register the interrupt handler in the right place RDMA/rxe: Don't overwrite errno from ib_umem_get() sfc: avoid double pci_remove of VFs sfc: error code if SRIOV cannot be disabled wireless: wext-spy: Fix out-of-bounds warning RDMA/cma: Fix rdma_resolve_route() memory leak Bluetooth: Fix the HCI to MGMT status conversion table Bluetooth: Shutdown controller after workqueues are flushed or cancelled Bluetooth: btusb: fix bt fiwmare downloading failure issue for qca btsoc. sctp: add size validation when walking chunks fuse: reject internal errno can: gw: synchronize rcu operations before removing gw job entry can: bcm: delay release of struct bcm_op after synchronize_rcu() mac80211: fix memory corruption in EAPOL handling powerpc/barrier: Avoid collision with clang's __lwsync macro pinctrl/amd: Add device HID for new AMD GPIO controller mmc: sdhci: Fix warning message when accessing RPMB in HS400 mode mmc: core: clear flags before allowing to retune ata: ahci_sunxi: Disable DIPM ASoC: tegra: Set driver_name=tegra for all machine drivers qemu_fw_cfg: Make fw_cfg_rev_attr a proper kobj_attribute ipmi/watchdog: Stop watchdog timer when the current action is 'none' power: supply: ab8500: Fix an old bug seq_buf: Fix overflow in seq_buf_putmem_hex() ipack/carriers/tpci200: Fix a double free in tpci200_pci_probe dm btree remove: assign new_root only when removal succeeds media: dtv5100: fix control-request directions media: zr364xx: fix memory leak in zr364xx_start_readpipe media: gspca/sq905: fix control-request direction media: gspca/sunplus: fix zero-length control requests media: uvcvideo: Fix pixel format change for Elgato Cam Link 4K jfs: fix GPF in diFree smackfs: restrict bytes count in smk_set_cipso() KVM: x86: Use guest MAXPHYADDR from CPUID.0x8000_0008 iff TDP is enabled KVM: X86: Disable hardware breakpoints unconditionally before kvm_x86->run() scsi: core: Fix bad pointer dereference when ehandler kthread is invalid tracing: Do not reference char * as a string in histograms fscrypt: don't ignore minor_hash when hash is 0 tty: serial: fsl_lpuart: fix the potential risk of division or modulo by zero misc/libmasm/module: Fix two use after free in ibmasm_init_one Revert "ALSA: bebob/oxfw: fix Kconfig entry for Mackie d.2 Pro" scsi: lpfc: Fix "Unexpected timeout" error in direct attach topology tty: serial: 8250: serial_cs: Fix a memory leak in error handling path fs/jfs: Fix missing error code in lmLogInit() scsi: iscsi: Add iscsi_cls_conn refcount helpers mfd: da9052/stmpe: Add and modify MODULE_DEVICE_TABLE s390/sclp_vt220: fix console name to match device ALSA: sb: Fix potential double-free of CSP mixer elements powerpc/ps3: Add dma_mask to ps3_dma_region gpio: zynq: Check return value of pm_runtime_get_sync ALSA: ppc: fix error return code in snd_pmac_probe() selftests/powerpc: Fix "no_handler" EBB selftest ASoC: soc-core: Fix the error return code in snd_soc_of_parse_audio_routing() ALSA: bebob: add support for ToneWeal FW66 usb: gadget: f_hid: fix endianness issue with descriptors usb: gadget: hid: fix error return code in hid_bind() powerpc/boot: Fixup device-tree on little endian backlight: lm3630a: Fix return code of .update_status() callback ALSA: hda: Add IRQ check for platform_get_irq() i2c: core: Disable client irq on reboot/shutdown lib/decompress_unlz4.c: correctly handle zero-padding around initrds. pwm: spear: Don't modify HW state in .remove callback power: supply: ab8500: Avoid NULL pointers power: reset: gpio-poweroff: add missing MODULE_DEVICE_TABLE ARM: 9087/1: kprobes: test-thumb: fix for LLVM_IAS=1 watchdog: Fix possible use-after-free in wdt_startup() watchdog: sc520_wdt: Fix possible use-after-free in wdt_turnoff() watchdog: Fix possible use-after-free by calling del_timer_sync() x86/fpu: Return proper error codes from user access functions orangefs: fix orangefs df output. ceph: remove bogus checks and WARN_ONs from ceph_set_page_dirty power: supply: charger-manager: add missing MODULE_DEVICE_TABLE power: supply: ab8500: add missing MODULE_DEVICE_TABLE pwm: tegra: Don't modify HW state in .remove callback ACPI: AMBA: Fix resource name in /proc/iomem virtio-blk: Fix memory leak among suspend/resume procedure virtio_console: Assure used length from device is limited PCI/sysfs: Fix dsm_label_utf16s_to_utf8s() buffer overrun power: supply: rt5033_battery: Fix device tree enumeration um: fix error return code in slip_open() um: fix error return code in winch_tramp() watchdog: aspeed: fix hardware timeout calculation nfs: fix acl memory leak of posix_acl_create() ubifs: Set/Clear I_LINKABLE under i_lock for whiteout inode x86/fpu: Limit xstate copy size in xstateregs_set() ALSA: isa: Fix error return code in snd_cmi8330_probe() hexagon: use common DISCARDS macro ARM: dts: exynos: fix PWM LED max brightness on Odroid XU/XU3 ARM: dts: exynos: fix PWM LED max brightness on Odroid XU4 rtc: fix snprintf() checking in is_rtc_hctosys() ARM: dts: r8a7779, marzen: Fix DU clock names reset: bail if try_module_get() fails memory: fsl_ifc: fix leak of IO mapping on probe failure memory: fsl_ifc: fix leak of private memory on probe failure ARM: dts: am335x: align ti,pindir-d0-out-d1-in property with dt-shema scsi: be2iscsi: Fix an error handling path in beiscsi_dev_probe() mips: always link byteswap helpers into decompressor mips: disable branch profiling in boot/decompress.o MIPS: vdso: Invalid GIC access through VDSO seq_file: disallow extremely large seq buffer allocations Linux 4.9.276 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I595c090068eb1b1934b15a0d54394abc38b4b0cc
823 lines
25 KiB
C
823 lines
25 KiB
C
/*
|
|
* Xilinx Zynq GPIO device driver
|
|
*
|
|
* Copyright (C) 2009 - 2014 Xilinx, Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
* version.
|
|
*/
|
|
|
|
#include <linux/bitops.h>
|
|
#include <linux/clk.h>
|
|
#include <linux/gpio/driver.h>
|
|
#include <linux/init.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/io.h>
|
|
#include <linux/module.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/pm_runtime.h>
|
|
#include <linux/of.h>
|
|
|
|
#define DRIVER_NAME "zynq-gpio"
|
|
|
|
/* Maximum banks */
|
|
#define ZYNQ_GPIO_MAX_BANK 4
|
|
#define ZYNQMP_GPIO_MAX_BANK 6
|
|
|
|
#define ZYNQ_GPIO_BANK0_NGPIO 32
|
|
#define ZYNQ_GPIO_BANK1_NGPIO 22
|
|
#define ZYNQ_GPIO_BANK2_NGPIO 32
|
|
#define ZYNQ_GPIO_BANK3_NGPIO 32
|
|
|
|
#define ZYNQMP_GPIO_BANK0_NGPIO 26
|
|
#define ZYNQMP_GPIO_BANK1_NGPIO 26
|
|
#define ZYNQMP_GPIO_BANK2_NGPIO 26
|
|
#define ZYNQMP_GPIO_BANK3_NGPIO 32
|
|
#define ZYNQMP_GPIO_BANK4_NGPIO 32
|
|
#define ZYNQMP_GPIO_BANK5_NGPIO 32
|
|
|
|
#define ZYNQ_GPIO_NR_GPIOS 118
|
|
#define ZYNQMP_GPIO_NR_GPIOS 174
|
|
|
|
#define ZYNQ_GPIO_BANK0_PIN_MIN(str) 0
|
|
#define ZYNQ_GPIO_BANK0_PIN_MAX(str) (ZYNQ_GPIO_BANK0_PIN_MIN(str) + \
|
|
ZYNQ##str##_GPIO_BANK0_NGPIO - 1)
|
|
#define ZYNQ_GPIO_BANK1_PIN_MIN(str) (ZYNQ_GPIO_BANK0_PIN_MAX(str) + 1)
|
|
#define ZYNQ_GPIO_BANK1_PIN_MAX(str) (ZYNQ_GPIO_BANK1_PIN_MIN(str) + \
|
|
ZYNQ##str##_GPIO_BANK1_NGPIO - 1)
|
|
#define ZYNQ_GPIO_BANK2_PIN_MIN(str) (ZYNQ_GPIO_BANK1_PIN_MAX(str) + 1)
|
|
#define ZYNQ_GPIO_BANK2_PIN_MAX(str) (ZYNQ_GPIO_BANK2_PIN_MIN(str) + \
|
|
ZYNQ##str##_GPIO_BANK2_NGPIO - 1)
|
|
#define ZYNQ_GPIO_BANK3_PIN_MIN(str) (ZYNQ_GPIO_BANK2_PIN_MAX(str) + 1)
|
|
#define ZYNQ_GPIO_BANK3_PIN_MAX(str) (ZYNQ_GPIO_BANK3_PIN_MIN(str) + \
|
|
ZYNQ##str##_GPIO_BANK3_NGPIO - 1)
|
|
#define ZYNQ_GPIO_BANK4_PIN_MIN(str) (ZYNQ_GPIO_BANK3_PIN_MAX(str) + 1)
|
|
#define ZYNQ_GPIO_BANK4_PIN_MAX(str) (ZYNQ_GPIO_BANK4_PIN_MIN(str) + \
|
|
ZYNQ##str##_GPIO_BANK4_NGPIO - 1)
|
|
#define ZYNQ_GPIO_BANK5_PIN_MIN(str) (ZYNQ_GPIO_BANK4_PIN_MAX(str) + 1)
|
|
#define ZYNQ_GPIO_BANK5_PIN_MAX(str) (ZYNQ_GPIO_BANK5_PIN_MIN(str) + \
|
|
ZYNQ##str##_GPIO_BANK5_NGPIO - 1)
|
|
|
|
|
|
/* Register offsets for the GPIO device */
|
|
/* LSW Mask & Data -WO */
|
|
#define ZYNQ_GPIO_DATA_LSW_OFFSET(BANK) (0x000 + (8 * BANK))
|
|
/* MSW Mask & Data -WO */
|
|
#define ZYNQ_GPIO_DATA_MSW_OFFSET(BANK) (0x004 + (8 * BANK))
|
|
/* Data Register-RW */
|
|
#define ZYNQ_GPIO_DATA_RO_OFFSET(BANK) (0x060 + (4 * BANK))
|
|
/* Direction mode reg-RW */
|
|
#define ZYNQ_GPIO_DIRM_OFFSET(BANK) (0x204 + (0x40 * BANK))
|
|
/* Output enable reg-RW */
|
|
#define ZYNQ_GPIO_OUTEN_OFFSET(BANK) (0x208 + (0x40 * BANK))
|
|
/* Interrupt mask reg-RO */
|
|
#define ZYNQ_GPIO_INTMASK_OFFSET(BANK) (0x20C + (0x40 * BANK))
|
|
/* Interrupt enable reg-WO */
|
|
#define ZYNQ_GPIO_INTEN_OFFSET(BANK) (0x210 + (0x40 * BANK))
|
|
/* Interrupt disable reg-WO */
|
|
#define ZYNQ_GPIO_INTDIS_OFFSET(BANK) (0x214 + (0x40 * BANK))
|
|
/* Interrupt status reg-RO */
|
|
#define ZYNQ_GPIO_INTSTS_OFFSET(BANK) (0x218 + (0x40 * BANK))
|
|
/* Interrupt type reg-RW */
|
|
#define ZYNQ_GPIO_INTTYPE_OFFSET(BANK) (0x21C + (0x40 * BANK))
|
|
/* Interrupt polarity reg-RW */
|
|
#define ZYNQ_GPIO_INTPOL_OFFSET(BANK) (0x220 + (0x40 * BANK))
|
|
/* Interrupt on any, reg-RW */
|
|
#define ZYNQ_GPIO_INTANY_OFFSET(BANK) (0x224 + (0x40 * BANK))
|
|
|
|
/* Disable all interrupts mask */
|
|
#define ZYNQ_GPIO_IXR_DISABLE_ALL 0xFFFFFFFF
|
|
|
|
/* Mid pin number of a bank */
|
|
#define ZYNQ_GPIO_MID_PIN_NUM 16
|
|
|
|
/* GPIO upper 16 bit mask */
|
|
#define ZYNQ_GPIO_UPPER_MASK 0xFFFF0000
|
|
|
|
/* For GPIO quirks */
|
|
#define ZYNQ_GPIO_QUIRK_FOO BIT(0)
|
|
|
|
/**
|
|
* struct zynq_gpio - gpio device private data structure
|
|
* @chip: instance of the gpio_chip
|
|
* @base_addr: base address of the GPIO device
|
|
* @clk: clock resource for this controller
|
|
* @irq: interrupt for the GPIO device
|
|
* @p_data: pointer to platform data
|
|
*/
|
|
struct zynq_gpio {
|
|
struct gpio_chip chip;
|
|
void __iomem *base_addr;
|
|
struct clk *clk;
|
|
int irq;
|
|
const struct zynq_platform_data *p_data;
|
|
};
|
|
|
|
/**
|
|
* struct zynq_platform_data - zynq gpio platform data structure
|
|
* @label: string to store in gpio->label
|
|
* @ngpio: max number of gpio pins
|
|
* @max_bank: maximum number of gpio banks
|
|
* @bank_min: this array represents bank's min pin
|
|
* @bank_max: this array represents bank's max pin
|
|
*/
|
|
struct zynq_platform_data {
|
|
const char *label;
|
|
u32 quirks;
|
|
u16 ngpio;
|
|
int max_bank;
|
|
int bank_min[ZYNQMP_GPIO_MAX_BANK];
|
|
int bank_max[ZYNQMP_GPIO_MAX_BANK];
|
|
};
|
|
|
|
static struct irq_chip zynq_gpio_level_irqchip;
|
|
static struct irq_chip zynq_gpio_edge_irqchip;
|
|
|
|
/**
|
|
* zynq_gpio_get_bank_pin - Get the bank number and pin number within that bank
|
|
* for a given pin in the GPIO device
|
|
* @pin_num: gpio pin number within the device
|
|
* @bank_num: an output parameter used to return the bank number of the gpio
|
|
* pin
|
|
* @bank_pin_num: an output parameter used to return pin number within a bank
|
|
* for the given gpio pin
|
|
*
|
|
* Returns the bank number and pin offset within the bank.
|
|
*/
|
|
static inline void zynq_gpio_get_bank_pin(unsigned int pin_num,
|
|
unsigned int *bank_num,
|
|
unsigned int *bank_pin_num,
|
|
struct zynq_gpio *gpio)
|
|
{
|
|
int bank;
|
|
|
|
for (bank = 0; bank < gpio->p_data->max_bank; bank++) {
|
|
if ((pin_num >= gpio->p_data->bank_min[bank]) &&
|
|
(pin_num <= gpio->p_data->bank_max[bank])) {
|
|
*bank_num = bank;
|
|
*bank_pin_num = pin_num -
|
|
gpio->p_data->bank_min[bank];
|
|
return;
|
|
}
|
|
}
|
|
|
|
/* default */
|
|
WARN(true, "invalid GPIO pin number: %u", pin_num);
|
|
*bank_num = 0;
|
|
*bank_pin_num = 0;
|
|
}
|
|
|
|
/**
|
|
* zynq_gpio_get_value - Get the state of the specified pin of GPIO device
|
|
* @chip: gpio_chip instance to be worked on
|
|
* @pin: gpio pin number within the device
|
|
*
|
|
* This function reads the state of the specified pin of the GPIO device.
|
|
*
|
|
* Return: 0 if the pin is low, 1 if pin is high.
|
|
*/
|
|
static int zynq_gpio_get_value(struct gpio_chip *chip, unsigned int pin)
|
|
{
|
|
u32 data;
|
|
unsigned int bank_num, bank_pin_num;
|
|
struct zynq_gpio *gpio = gpiochip_get_data(chip);
|
|
|
|
zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio);
|
|
|
|
data = readl_relaxed(gpio->base_addr +
|
|
ZYNQ_GPIO_DATA_RO_OFFSET(bank_num));
|
|
|
|
return (data >> bank_pin_num) & 1;
|
|
}
|
|
|
|
/**
|
|
* zynq_gpio_set_value - Modify the state of the pin with specified value
|
|
* @chip: gpio_chip instance to be worked on
|
|
* @pin: gpio pin number within the device
|
|
* @state: value used to modify the state of the specified pin
|
|
*
|
|
* This function calculates the register offset (i.e to lower 16 bits or
|
|
* upper 16 bits) based on the given pin number and sets the state of a
|
|
* gpio pin to the specified value. The state is either 0 or non-zero.
|
|
*/
|
|
static void zynq_gpio_set_value(struct gpio_chip *chip, unsigned int pin,
|
|
int state)
|
|
{
|
|
unsigned int reg_offset, bank_num, bank_pin_num;
|
|
struct zynq_gpio *gpio = gpiochip_get_data(chip);
|
|
|
|
zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio);
|
|
|
|
if (bank_pin_num >= ZYNQ_GPIO_MID_PIN_NUM) {
|
|
/* only 16 data bits in bit maskable reg */
|
|
bank_pin_num -= ZYNQ_GPIO_MID_PIN_NUM;
|
|
reg_offset = ZYNQ_GPIO_DATA_MSW_OFFSET(bank_num);
|
|
} else {
|
|
reg_offset = ZYNQ_GPIO_DATA_LSW_OFFSET(bank_num);
|
|
}
|
|
|
|
/*
|
|
* get the 32 bit value to be written to the mask/data register where
|
|
* the upper 16 bits is the mask and lower 16 bits is the data
|
|
*/
|
|
state = !!state;
|
|
state = ~(1 << (bank_pin_num + ZYNQ_GPIO_MID_PIN_NUM)) &
|
|
((state << bank_pin_num) | ZYNQ_GPIO_UPPER_MASK);
|
|
|
|
writel_relaxed(state, gpio->base_addr + reg_offset);
|
|
}
|
|
|
|
/**
|
|
* zynq_gpio_dir_in - Set the direction of the specified GPIO pin as input
|
|
* @chip: gpio_chip instance to be worked on
|
|
* @pin: gpio pin number within the device
|
|
*
|
|
* This function uses the read-modify-write sequence to set the direction of
|
|
* the gpio pin as input.
|
|
*
|
|
* Return: 0 always
|
|
*/
|
|
static int zynq_gpio_dir_in(struct gpio_chip *chip, unsigned int pin)
|
|
{
|
|
u32 reg;
|
|
bool is_zynq_gpio;
|
|
unsigned int bank_num, bank_pin_num;
|
|
struct zynq_gpio *gpio = gpiochip_get_data(chip);
|
|
|
|
is_zynq_gpio = gpio->p_data->quirks & ZYNQ_GPIO_QUIRK_FOO;
|
|
zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio);
|
|
|
|
/*
|
|
* On zynq bank 0 pins 7 and 8 are special and cannot be used
|
|
* as inputs.
|
|
*/
|
|
if (is_zynq_gpio && bank_num == 0 &&
|
|
(bank_pin_num == 7 || bank_pin_num == 8))
|
|
return -EINVAL;
|
|
|
|
/* clear the bit in direction mode reg to set the pin as input */
|
|
reg = readl_relaxed(gpio->base_addr + ZYNQ_GPIO_DIRM_OFFSET(bank_num));
|
|
reg &= ~BIT(bank_pin_num);
|
|
writel_relaxed(reg, gpio->base_addr + ZYNQ_GPIO_DIRM_OFFSET(bank_num));
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* zynq_gpio_dir_out - Set the direction of the specified GPIO pin as output
|
|
* @chip: gpio_chip instance to be worked on
|
|
* @pin: gpio pin number within the device
|
|
* @state: value to be written to specified pin
|
|
*
|
|
* This function sets the direction of specified GPIO pin as output, configures
|
|
* the Output Enable register for the pin and uses zynq_gpio_set to set
|
|
* the state of the pin to the value specified.
|
|
*
|
|
* Return: 0 always
|
|
*/
|
|
static int zynq_gpio_dir_out(struct gpio_chip *chip, unsigned int pin,
|
|
int state)
|
|
{
|
|
u32 reg;
|
|
unsigned int bank_num, bank_pin_num;
|
|
struct zynq_gpio *gpio = gpiochip_get_data(chip);
|
|
|
|
zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio);
|
|
|
|
/* set the GPIO pin as output */
|
|
reg = readl_relaxed(gpio->base_addr + ZYNQ_GPIO_DIRM_OFFSET(bank_num));
|
|
reg |= BIT(bank_pin_num);
|
|
writel_relaxed(reg, gpio->base_addr + ZYNQ_GPIO_DIRM_OFFSET(bank_num));
|
|
|
|
/* configure the output enable reg for the pin */
|
|
reg = readl_relaxed(gpio->base_addr + ZYNQ_GPIO_OUTEN_OFFSET(bank_num));
|
|
reg |= BIT(bank_pin_num);
|
|
writel_relaxed(reg, gpio->base_addr + ZYNQ_GPIO_OUTEN_OFFSET(bank_num));
|
|
|
|
/* set the state of the pin */
|
|
zynq_gpio_set_value(chip, pin, state);
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* zynq_gpio_irq_mask - Disable the interrupts for a gpio pin
|
|
* @irq_data: per irq and chip data passed down to chip functions
|
|
*
|
|
* This function calculates gpio pin number from irq number and sets the
|
|
* bit in the Interrupt Disable register of the corresponding bank to disable
|
|
* interrupts for that pin.
|
|
*/
|
|
static void zynq_gpio_irq_mask(struct irq_data *irq_data)
|
|
{
|
|
unsigned int device_pin_num, bank_num, bank_pin_num;
|
|
struct zynq_gpio *gpio =
|
|
gpiochip_get_data(irq_data_get_irq_chip_data(irq_data));
|
|
|
|
device_pin_num = irq_data->hwirq;
|
|
zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio);
|
|
writel_relaxed(BIT(bank_pin_num),
|
|
gpio->base_addr + ZYNQ_GPIO_INTDIS_OFFSET(bank_num));
|
|
}
|
|
|
|
/**
|
|
* zynq_gpio_irq_unmask - Enable the interrupts for a gpio pin
|
|
* @irq_data: irq data containing irq number of gpio pin for the interrupt
|
|
* to enable
|
|
*
|
|
* This function calculates the gpio pin number from irq number and sets the
|
|
* bit in the Interrupt Enable register of the corresponding bank to enable
|
|
* interrupts for that pin.
|
|
*/
|
|
static void zynq_gpio_irq_unmask(struct irq_data *irq_data)
|
|
{
|
|
unsigned int device_pin_num, bank_num, bank_pin_num;
|
|
struct zynq_gpio *gpio =
|
|
gpiochip_get_data(irq_data_get_irq_chip_data(irq_data));
|
|
|
|
device_pin_num = irq_data->hwirq;
|
|
zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio);
|
|
writel_relaxed(BIT(bank_pin_num),
|
|
gpio->base_addr + ZYNQ_GPIO_INTEN_OFFSET(bank_num));
|
|
}
|
|
|
|
/**
|
|
* zynq_gpio_irq_ack - Acknowledge the interrupt of a gpio pin
|
|
* @irq_data: irq data containing irq number of gpio pin for the interrupt
|
|
* to ack
|
|
*
|
|
* This function calculates gpio pin number from irq number and sets the bit
|
|
* in the Interrupt Status Register of the corresponding bank, to ACK the irq.
|
|
*/
|
|
static void zynq_gpio_irq_ack(struct irq_data *irq_data)
|
|
{
|
|
unsigned int device_pin_num, bank_num, bank_pin_num;
|
|
struct zynq_gpio *gpio =
|
|
gpiochip_get_data(irq_data_get_irq_chip_data(irq_data));
|
|
|
|
device_pin_num = irq_data->hwirq;
|
|
zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio);
|
|
writel_relaxed(BIT(bank_pin_num),
|
|
gpio->base_addr + ZYNQ_GPIO_INTSTS_OFFSET(bank_num));
|
|
}
|
|
|
|
/**
|
|
* zynq_gpio_irq_enable - Enable the interrupts for a gpio pin
|
|
* @irq_data: irq data containing irq number of gpio pin for the interrupt
|
|
* to enable
|
|
*
|
|
* Clears the INTSTS bit and unmasks the given interrupt.
|
|
*/
|
|
static void zynq_gpio_irq_enable(struct irq_data *irq_data)
|
|
{
|
|
/*
|
|
* The Zynq GPIO controller does not disable interrupt detection when
|
|
* the interrupt is masked and only disables the propagation of the
|
|
* interrupt. This means when the controller detects an interrupt
|
|
* condition while the interrupt is logically disabled it will propagate
|
|
* that interrupt event once the interrupt is enabled. This will cause
|
|
* the interrupt consumer to see spurious interrupts to prevent this
|
|
* first make sure that the interrupt is not asserted and then enable
|
|
* it.
|
|
*/
|
|
zynq_gpio_irq_ack(irq_data);
|
|
zynq_gpio_irq_unmask(irq_data);
|
|
}
|
|
|
|
/**
|
|
* zynq_gpio_set_irq_type - Set the irq type for a gpio pin
|
|
* @irq_data: irq data containing irq number of gpio pin
|
|
* @type: interrupt type that is to be set for the gpio pin
|
|
*
|
|
* This function gets the gpio pin number and its bank from the gpio pin number
|
|
* and configures the INT_TYPE, INT_POLARITY and INT_ANY registers.
|
|
*
|
|
* Return: 0, negative error otherwise.
|
|
* TYPE-EDGE_RISING, INT_TYPE - 1, INT_POLARITY - 1, INT_ANY - 0;
|
|
* TYPE-EDGE_FALLING, INT_TYPE - 1, INT_POLARITY - 0, INT_ANY - 0;
|
|
* TYPE-EDGE_BOTH, INT_TYPE - 1, INT_POLARITY - NA, INT_ANY - 1;
|
|
* TYPE-LEVEL_HIGH, INT_TYPE - 0, INT_POLARITY - 1, INT_ANY - NA;
|
|
* TYPE-LEVEL_LOW, INT_TYPE - 0, INT_POLARITY - 0, INT_ANY - NA
|
|
*/
|
|
static int zynq_gpio_set_irq_type(struct irq_data *irq_data, unsigned int type)
|
|
{
|
|
u32 int_type, int_pol, int_any;
|
|
unsigned int device_pin_num, bank_num, bank_pin_num;
|
|
struct zynq_gpio *gpio =
|
|
gpiochip_get_data(irq_data_get_irq_chip_data(irq_data));
|
|
|
|
device_pin_num = irq_data->hwirq;
|
|
zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio);
|
|
|
|
int_type = readl_relaxed(gpio->base_addr +
|
|
ZYNQ_GPIO_INTTYPE_OFFSET(bank_num));
|
|
int_pol = readl_relaxed(gpio->base_addr +
|
|
ZYNQ_GPIO_INTPOL_OFFSET(bank_num));
|
|
int_any = readl_relaxed(gpio->base_addr +
|
|
ZYNQ_GPIO_INTANY_OFFSET(bank_num));
|
|
|
|
/*
|
|
* based on the type requested, configure the INT_TYPE, INT_POLARITY
|
|
* and INT_ANY registers
|
|
*/
|
|
switch (type) {
|
|
case IRQ_TYPE_EDGE_RISING:
|
|
int_type |= BIT(bank_pin_num);
|
|
int_pol |= BIT(bank_pin_num);
|
|
int_any &= ~BIT(bank_pin_num);
|
|
break;
|
|
case IRQ_TYPE_EDGE_FALLING:
|
|
int_type |= BIT(bank_pin_num);
|
|
int_pol &= ~BIT(bank_pin_num);
|
|
int_any &= ~BIT(bank_pin_num);
|
|
break;
|
|
case IRQ_TYPE_EDGE_BOTH:
|
|
int_type |= BIT(bank_pin_num);
|
|
int_any |= BIT(bank_pin_num);
|
|
break;
|
|
case IRQ_TYPE_LEVEL_HIGH:
|
|
int_type &= ~BIT(bank_pin_num);
|
|
int_pol |= BIT(bank_pin_num);
|
|
break;
|
|
case IRQ_TYPE_LEVEL_LOW:
|
|
int_type &= ~BIT(bank_pin_num);
|
|
int_pol &= ~BIT(bank_pin_num);
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
|
|
writel_relaxed(int_type,
|
|
gpio->base_addr + ZYNQ_GPIO_INTTYPE_OFFSET(bank_num));
|
|
writel_relaxed(int_pol,
|
|
gpio->base_addr + ZYNQ_GPIO_INTPOL_OFFSET(bank_num));
|
|
writel_relaxed(int_any,
|
|
gpio->base_addr + ZYNQ_GPIO_INTANY_OFFSET(bank_num));
|
|
|
|
if (type & IRQ_TYPE_LEVEL_MASK) {
|
|
irq_set_chip_handler_name_locked(irq_data,
|
|
&zynq_gpio_level_irqchip, handle_fasteoi_irq, NULL);
|
|
} else {
|
|
irq_set_chip_handler_name_locked(irq_data,
|
|
&zynq_gpio_edge_irqchip, handle_level_irq, NULL);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int zynq_gpio_set_wake(struct irq_data *data, unsigned int on)
|
|
{
|
|
struct zynq_gpio *gpio =
|
|
gpiochip_get_data(irq_data_get_irq_chip_data(data));
|
|
|
|
irq_set_irq_wake(gpio->irq, on);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* irq chip descriptor */
|
|
static struct irq_chip zynq_gpio_level_irqchip = {
|
|
.name = DRIVER_NAME,
|
|
.irq_enable = zynq_gpio_irq_enable,
|
|
.irq_eoi = zynq_gpio_irq_ack,
|
|
.irq_mask = zynq_gpio_irq_mask,
|
|
.irq_unmask = zynq_gpio_irq_unmask,
|
|
.irq_set_type = zynq_gpio_set_irq_type,
|
|
.irq_set_wake = zynq_gpio_set_wake,
|
|
.flags = IRQCHIP_EOI_THREADED | IRQCHIP_EOI_IF_HANDLED |
|
|
IRQCHIP_MASK_ON_SUSPEND,
|
|
};
|
|
|
|
static struct irq_chip zynq_gpio_edge_irqchip = {
|
|
.name = DRIVER_NAME,
|
|
.irq_enable = zynq_gpio_irq_enable,
|
|
.irq_ack = zynq_gpio_irq_ack,
|
|
.irq_mask = zynq_gpio_irq_mask,
|
|
.irq_unmask = zynq_gpio_irq_unmask,
|
|
.irq_set_type = zynq_gpio_set_irq_type,
|
|
.irq_set_wake = zynq_gpio_set_wake,
|
|
.flags = IRQCHIP_MASK_ON_SUSPEND,
|
|
};
|
|
|
|
static void zynq_gpio_handle_bank_irq(struct zynq_gpio *gpio,
|
|
unsigned int bank_num,
|
|
unsigned long pending)
|
|
{
|
|
unsigned int bank_offset = gpio->p_data->bank_min[bank_num];
|
|
struct irq_domain *irqdomain = gpio->chip.irqdomain;
|
|
int offset;
|
|
|
|
if (!pending)
|
|
return;
|
|
|
|
for_each_set_bit(offset, &pending, 32) {
|
|
unsigned int gpio_irq;
|
|
|
|
gpio_irq = irq_find_mapping(irqdomain, offset + bank_offset);
|
|
generic_handle_irq(gpio_irq);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* zynq_gpio_irqhandler - IRQ handler for the gpio banks of a gpio device
|
|
* @irq: irq number of the gpio bank where interrupt has occurred
|
|
* @desc: irq descriptor instance of the 'irq'
|
|
*
|
|
* This function reads the Interrupt Status Register of each bank to get the
|
|
* gpio pin number which has triggered an interrupt. It then acks the triggered
|
|
* interrupt and calls the pin specific handler set by the higher layer
|
|
* application for that pin.
|
|
* Note: A bug is reported if no handler is set for the gpio pin.
|
|
*/
|
|
static void zynq_gpio_irqhandler(struct irq_desc *desc)
|
|
{
|
|
u32 int_sts, int_enb;
|
|
unsigned int bank_num;
|
|
struct zynq_gpio *gpio =
|
|
gpiochip_get_data(irq_desc_get_handler_data(desc));
|
|
struct irq_chip *irqchip = irq_desc_get_chip(desc);
|
|
|
|
chained_irq_enter(irqchip, desc);
|
|
|
|
for (bank_num = 0; bank_num < gpio->p_data->max_bank; bank_num++) {
|
|
int_sts = readl_relaxed(gpio->base_addr +
|
|
ZYNQ_GPIO_INTSTS_OFFSET(bank_num));
|
|
int_enb = readl_relaxed(gpio->base_addr +
|
|
ZYNQ_GPIO_INTMASK_OFFSET(bank_num));
|
|
zynq_gpio_handle_bank_irq(gpio, bank_num, int_sts & ~int_enb);
|
|
}
|
|
|
|
chained_irq_exit(irqchip, desc);
|
|
}
|
|
|
|
static int __maybe_unused zynq_gpio_suspend(struct device *dev)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
int irq = platform_get_irq(pdev, 0);
|
|
struct irq_data *data = irq_get_irq_data(irq);
|
|
|
|
if (!irqd_is_wakeup_set(data))
|
|
return pm_runtime_force_suspend(dev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int __maybe_unused zynq_gpio_resume(struct device *dev)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
int irq = platform_get_irq(pdev, 0);
|
|
struct irq_data *data = irq_get_irq_data(irq);
|
|
|
|
if (!irqd_is_wakeup_set(data))
|
|
return pm_runtime_force_resume(dev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int __maybe_unused zynq_gpio_runtime_suspend(struct device *dev)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
struct zynq_gpio *gpio = platform_get_drvdata(pdev);
|
|
|
|
clk_disable_unprepare(gpio->clk);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int __maybe_unused zynq_gpio_runtime_resume(struct device *dev)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
struct zynq_gpio *gpio = platform_get_drvdata(pdev);
|
|
|
|
return clk_prepare_enable(gpio->clk);
|
|
}
|
|
|
|
static int zynq_gpio_request(struct gpio_chip *chip, unsigned offset)
|
|
{
|
|
int ret;
|
|
|
|
ret = pm_runtime_get_sync(chip->parent);
|
|
|
|
/*
|
|
* If the device is already active pm_runtime_get() will return 1 on
|
|
* success, but gpio_request still needs to return 0.
|
|
*/
|
|
return ret < 0 ? ret : 0;
|
|
}
|
|
|
|
static void zynq_gpio_free(struct gpio_chip *chip, unsigned offset)
|
|
{
|
|
pm_runtime_put(chip->parent);
|
|
}
|
|
|
|
static const struct dev_pm_ops zynq_gpio_dev_pm_ops = {
|
|
SET_SYSTEM_SLEEP_PM_OPS(zynq_gpio_suspend, zynq_gpio_resume)
|
|
SET_RUNTIME_PM_OPS(zynq_gpio_runtime_suspend,
|
|
zynq_gpio_runtime_resume, NULL)
|
|
};
|
|
|
|
static const struct zynq_platform_data zynqmp_gpio_def = {
|
|
.label = "zynqmp_gpio",
|
|
.ngpio = ZYNQMP_GPIO_NR_GPIOS,
|
|
.max_bank = ZYNQMP_GPIO_MAX_BANK,
|
|
.bank_min[0] = ZYNQ_GPIO_BANK0_PIN_MIN(MP),
|
|
.bank_max[0] = ZYNQ_GPIO_BANK0_PIN_MAX(MP),
|
|
.bank_min[1] = ZYNQ_GPIO_BANK1_PIN_MIN(MP),
|
|
.bank_max[1] = ZYNQ_GPIO_BANK1_PIN_MAX(MP),
|
|
.bank_min[2] = ZYNQ_GPIO_BANK2_PIN_MIN(MP),
|
|
.bank_max[2] = ZYNQ_GPIO_BANK2_PIN_MAX(MP),
|
|
.bank_min[3] = ZYNQ_GPIO_BANK3_PIN_MIN(MP),
|
|
.bank_max[3] = ZYNQ_GPIO_BANK3_PIN_MAX(MP),
|
|
.bank_min[4] = ZYNQ_GPIO_BANK4_PIN_MIN(MP),
|
|
.bank_max[4] = ZYNQ_GPIO_BANK4_PIN_MAX(MP),
|
|
.bank_min[5] = ZYNQ_GPIO_BANK5_PIN_MIN(MP),
|
|
.bank_max[5] = ZYNQ_GPIO_BANK5_PIN_MAX(MP),
|
|
};
|
|
|
|
static const struct zynq_platform_data zynq_gpio_def = {
|
|
.label = "zynq_gpio",
|
|
.quirks = ZYNQ_GPIO_QUIRK_FOO,
|
|
.ngpio = ZYNQ_GPIO_NR_GPIOS,
|
|
.max_bank = ZYNQ_GPIO_MAX_BANK,
|
|
.bank_min[0] = ZYNQ_GPIO_BANK0_PIN_MIN(),
|
|
.bank_max[0] = ZYNQ_GPIO_BANK0_PIN_MAX(),
|
|
.bank_min[1] = ZYNQ_GPIO_BANK1_PIN_MIN(),
|
|
.bank_max[1] = ZYNQ_GPIO_BANK1_PIN_MAX(),
|
|
.bank_min[2] = ZYNQ_GPIO_BANK2_PIN_MIN(),
|
|
.bank_max[2] = ZYNQ_GPIO_BANK2_PIN_MAX(),
|
|
.bank_min[3] = ZYNQ_GPIO_BANK3_PIN_MIN(),
|
|
.bank_max[3] = ZYNQ_GPIO_BANK3_PIN_MAX(),
|
|
};
|
|
|
|
static const struct of_device_id zynq_gpio_of_match[] = {
|
|
{ .compatible = "xlnx,zynq-gpio-1.0", .data = (void *)&zynq_gpio_def },
|
|
{ .compatible = "xlnx,zynqmp-gpio-1.0",
|
|
.data = (void *)&zynqmp_gpio_def },
|
|
{ /* end of table */ }
|
|
};
|
|
MODULE_DEVICE_TABLE(of, zynq_gpio_of_match);
|
|
|
|
/**
|
|
* zynq_gpio_probe - Initialization method for a zynq_gpio device
|
|
* @pdev: platform device instance
|
|
*
|
|
* This function allocates memory resources for the gpio device and registers
|
|
* all the banks of the device. It will also set up interrupts for the gpio
|
|
* pins.
|
|
* Note: Interrupts are disabled for all the banks during initialization.
|
|
*
|
|
* Return: 0 on success, negative error otherwise.
|
|
*/
|
|
static int zynq_gpio_probe(struct platform_device *pdev)
|
|
{
|
|
int ret, bank_num;
|
|
struct zynq_gpio *gpio;
|
|
struct gpio_chip *chip;
|
|
struct resource *res;
|
|
const struct of_device_id *match;
|
|
|
|
gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
|
|
if (!gpio)
|
|
return -ENOMEM;
|
|
|
|
match = of_match_node(zynq_gpio_of_match, pdev->dev.of_node);
|
|
if (!match) {
|
|
dev_err(&pdev->dev, "of_match_node() failed\n");
|
|
return -EINVAL;
|
|
}
|
|
gpio->p_data = match->data;
|
|
platform_set_drvdata(pdev, gpio);
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
gpio->base_addr = devm_ioremap_resource(&pdev->dev, res);
|
|
if (IS_ERR(gpio->base_addr))
|
|
return PTR_ERR(gpio->base_addr);
|
|
|
|
gpio->irq = platform_get_irq(pdev, 0);
|
|
if (gpio->irq < 0) {
|
|
dev_err(&pdev->dev, "invalid IRQ\n");
|
|
return gpio->irq;
|
|
}
|
|
|
|
/* configure the gpio chip */
|
|
chip = &gpio->chip;
|
|
chip->label = gpio->p_data->label;
|
|
chip->owner = THIS_MODULE;
|
|
chip->parent = &pdev->dev;
|
|
chip->get = zynq_gpio_get_value;
|
|
chip->set = zynq_gpio_set_value;
|
|
chip->request = zynq_gpio_request;
|
|
chip->free = zynq_gpio_free;
|
|
chip->direction_input = zynq_gpio_dir_in;
|
|
chip->direction_output = zynq_gpio_dir_out;
|
|
chip->base = -1;
|
|
chip->ngpio = gpio->p_data->ngpio;
|
|
|
|
/* Retrieve GPIO clock */
|
|
gpio->clk = devm_clk_get(&pdev->dev, NULL);
|
|
if (IS_ERR(gpio->clk)) {
|
|
dev_err(&pdev->dev, "input clock not found.\n");
|
|
return PTR_ERR(gpio->clk);
|
|
}
|
|
ret = clk_prepare_enable(gpio->clk);
|
|
if (ret) {
|
|
dev_err(&pdev->dev, "Unable to enable clock.\n");
|
|
return ret;
|
|
}
|
|
|
|
pm_runtime_set_active(&pdev->dev);
|
|
pm_runtime_enable(&pdev->dev);
|
|
ret = pm_runtime_get_sync(&pdev->dev);
|
|
if (ret < 0)
|
|
goto err_pm_dis;
|
|
|
|
/* report a bug if gpio chip registration fails */
|
|
ret = gpiochip_add_data(chip, gpio);
|
|
if (ret) {
|
|
dev_err(&pdev->dev, "Failed to add gpio chip\n");
|
|
goto err_pm_put;
|
|
}
|
|
|
|
/* disable interrupts for all banks */
|
|
for (bank_num = 0; bank_num < gpio->p_data->max_bank; bank_num++)
|
|
writel_relaxed(ZYNQ_GPIO_IXR_DISABLE_ALL, gpio->base_addr +
|
|
ZYNQ_GPIO_INTDIS_OFFSET(bank_num));
|
|
|
|
ret = gpiochip_irqchip_add(chip, &zynq_gpio_edge_irqchip, 0,
|
|
handle_level_irq, IRQ_TYPE_NONE);
|
|
if (ret) {
|
|
dev_err(&pdev->dev, "Failed to add irq chip\n");
|
|
goto err_rm_gpiochip;
|
|
}
|
|
|
|
gpiochip_set_chained_irqchip(chip, &zynq_gpio_edge_irqchip, gpio->irq,
|
|
zynq_gpio_irqhandler);
|
|
|
|
pm_runtime_put(&pdev->dev);
|
|
|
|
return 0;
|
|
|
|
err_rm_gpiochip:
|
|
gpiochip_remove(chip);
|
|
err_pm_put:
|
|
pm_runtime_put(&pdev->dev);
|
|
err_pm_dis:
|
|
pm_runtime_disable(&pdev->dev);
|
|
clk_disable_unprepare(gpio->clk);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* zynq_gpio_remove - Driver removal function
|
|
* @pdev: platform device instance
|
|
*
|
|
* Return: 0 always
|
|
*/
|
|
static int zynq_gpio_remove(struct platform_device *pdev)
|
|
{
|
|
struct zynq_gpio *gpio = platform_get_drvdata(pdev);
|
|
int ret;
|
|
|
|
ret = pm_runtime_get_sync(&pdev->dev);
|
|
if (ret < 0)
|
|
dev_warn(&pdev->dev, "pm_runtime_get_sync() Failed\n");
|
|
gpiochip_remove(&gpio->chip);
|
|
clk_disable_unprepare(gpio->clk);
|
|
device_set_wakeup_capable(&pdev->dev, 0);
|
|
pm_runtime_disable(&pdev->dev);
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver zynq_gpio_driver = {
|
|
.driver = {
|
|
.name = DRIVER_NAME,
|
|
.pm = &zynq_gpio_dev_pm_ops,
|
|
.of_match_table = zynq_gpio_of_match,
|
|
},
|
|
.probe = zynq_gpio_probe,
|
|
.remove = zynq_gpio_remove,
|
|
};
|
|
|
|
/**
|
|
* zynq_gpio_init - Initial driver registration call
|
|
*
|
|
* Return: value from platform_driver_register
|
|
*/
|
|
static int __init zynq_gpio_init(void)
|
|
{
|
|
return platform_driver_register(&zynq_gpio_driver);
|
|
}
|
|
postcore_initcall(zynq_gpio_init);
|
|
|
|
static void __exit zynq_gpio_exit(void)
|
|
{
|
|
platform_driver_unregister(&zynq_gpio_driver);
|
|
}
|
|
module_exit(zynq_gpio_exit);
|
|
|
|
MODULE_AUTHOR("Xilinx Inc.");
|
|
MODULE_DESCRIPTION("Zynq GPIO driver");
|
|
MODULE_LICENSE("GPL");
|