Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'gpio-v5.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio

Pull GPIO updates from Linus Walleij:
"This is the big slew of GPIO changes for the v5.3 kernel cycle. This
is mostly incremental work this time.

Three important things:

- The FMC subsystem is deleted through my tree. This happens through
GPIO as its demise was discussed in relation to a patch decoupling
its GPIO implementation from the standard way of handling GPIO. As
it turns out, that is not the only subsystem it reimplements and
the authors think it is better do scratch it and start over using
the proper kernel subsystems than try to polish the rust shiny. See
the commit (ACKed by the maintainers) for details.

- Arnd made a small devres patch that was ACKed by Greg and goes into
the device core.

- SPDX header change colissions may happen, because at times I've
seen that quite a lot changed during the -rc:s in regards to SPDX.
(It is good stuff, tglx has me convinced, and it is worth the
occasional pain.)

Apart from this is is nothing controversial or problematic.

Summary:

Core:

- When a gpio_chip request GPIOs from itself, it can now fully
control the line characteristics, both machine and consumer flags.
This makes a lot of sense, but took some time before I figured out
that this is how it has to work.

- Several smallish documentation fixes.

New drivers:

- The PCA953x driver now supports the TI TCA9539.

- The DaVinci driver now supports the K3 AM654 SoCs.

Driver improvements:

- Major overhaul and hardening of the OMAP driver by Russell King.

- Starting to move some drivers to the new API passing irq_chip along
with the gpio_chip when adding the gpio_chip instead of adding it
separately.

Unrelated:

- Delete the FMC subsystem"

* tag 'gpio-v5.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (87 commits)
Revert "gpio: tegra: Clean-up debugfs initialisation"
gpiolib: Use spinlock_t instead of struct spinlock
gpio: stp-xway: allow compile-testing
gpio: stp-xway: get rid of the #include <lantiq_soc.h> dependency
gpio: stp-xway: improve module clock error handling
gpio: stp-xway: simplify error handling in xway_stp_probe()
gpiolib: Clarify use of non-sleeping functions
gpiolib: Fix references to gpiod_[gs]et_*value_cansleep() variants
gpiolib: Document new gpio_chip.init_valid_mask field
Documentation: gpio: Fix reference to gpiod_get_array()
gpio: pl061: drop duplicate printing of device name
gpio: altera: Pass irqchip when adding gpiochip
gpio: siox: Use devm_ managed gpiochip
gpio: siox: Add struct device *dev helper variable
gpio: siox: Pass irqchip when adding gpiochip
drivers: gpio: amd-fch: make resource struct const
devres: allow const resource arguments
gpio: ath79: Pass irqchip when adding gpiochip
gpio: tegra: Clean-up debugfs initialisation
gpio: siox: Switch to IRQ_TYPE_NONE
...

+845 -4220
+18
Documentation/devicetree/bindings/gpio/gpio-davinci.txt
··· 5 5 "ti,keystone-gpio": for Keystone 2 66AK2H/K, 66AK2L, 6 6 66AK2E SoCs 7 7 "ti,k2g-gpio", "ti,keystone-gpio": for 66AK2G 8 + "ti,am654-gpio", "ti,keystone-gpio": for TI K3 AM654 8 9 9 10 - reg: Physical base address of the controller and the size of memory mapped 10 11 registers. ··· 145 144 clock-names = "gpio"; 146 145 ti,ngpio = <32>; 147 146 ti,davinci-gpio-unbanked = <32>; 147 + }; 148 + 149 + Example for K3 AM654: 150 + 151 + wkup_gpio0: wkup_gpio0@42110000 { 152 + compatible = "ti,am654-gpio", "ti,keystone-gpio"; 153 + reg = <0x42110000 0x100>; 154 + gpio-controller; 155 + #gpio-cells = <2>; 156 + interrupt-parent = <&intr_wkup_gpio>; 157 + interrupts = <59 128>, <59 129>, <59 130>, <59 131>; 158 + interrupt-controller; 159 + #interrupt-cells = <2>; 160 + ti,ngpio = <56>; 161 + ti,davinci-gpio-unbanked = <0>; 162 + clocks = <&k3_clks 59 0>; 163 + clock-names = "gpio"; 148 164 };
-10
Documentation/devicetree/bindings/gpio/pl061-gpio.txt
··· 1 - ARM PL061 GPIO controller 2 - 3 - Required properties: 4 - - compatible : "arm,pl061", "arm,primecell" 5 - - #gpio-cells : Should be two. The first cell is the pin number and the 6 - second cell is used to specify optional parameters: 7 - - bit 0 specifies polarity (0 for normal, 1 for inverted) 8 - - gpio-controller : Marks the device node as a GPIO controller. 9 - - interrupts : Interrupt mapping for GPIO IRQ. 10 - - gpio-ranges : Interaction with the PINCTRL subsystem.
+69
Documentation/devicetree/bindings/gpio/pl061-gpio.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/gpio/pl061-gpio.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: ARM PL061 GPIO controller 8 + 9 + maintainers: 10 + - Linus Walleij <linus.walleij@linaro.org> 11 + - Rob Herring <robh@kernel.org> 12 + 13 + # We need a select here so we don't match all nodes with 'arm,primecell' 14 + select: 15 + properties: 16 + compatible: 17 + contains: 18 + const: arm,pl061 19 + required: 20 + - compatible 21 + 22 + properties: 23 + $nodename: 24 + pattern: "^gpio@[0-9a-f]+$" 25 + 26 + compatible: 27 + items: 28 + - const: arm,pl061 29 + - const: arm,primecell 30 + 31 + reg: 32 + maxItems: 1 33 + 34 + interrupts: 35 + oneOf: 36 + - maxItems: 1 37 + - maxItems: 8 38 + 39 + interrupt-controller: true 40 + 41 + "#interrupt-cells": 42 + const: 2 43 + 44 + clocks: 45 + maxItems: 1 46 + 47 + clock-names: true 48 + 49 + "#gpio-cells": 50 + const: 2 51 + 52 + gpio-controller: true 53 + 54 + gpio-ranges: 55 + maxItems: 8 56 + 57 + required: 58 + - compatible 59 + - reg 60 + - interrupts 61 + - interrupt-controller 62 + - "#interrupt-cells" 63 + - clocks 64 + - "#gpio-cells" 65 + - gpio-controller 66 + 67 + additionalProperties: false 68 + 69 + ...
+1 -3
Documentation/driver-api/gpio/consumer.rst
··· 283 283 gpiod_set_value(desc, 1); default (active high) high 284 284 gpiod_set_value(desc, 0); active low high 285 285 gpiod_set_value(desc, 1); active low low 286 - gpiod_set_value(desc, 0); default (active high) low 287 - gpiod_set_value(desc, 1); default (active high) high 288 286 gpiod_set_value(desc, 0); open drain low 289 287 gpiod_set_value(desc, 1); open drain high impedance 290 288 gpiod_set_value(desc, 0); open source high impedance ··· 364 366 The functions take three arguments: 365 367 * array_size - the number of array elements 366 368 * desc_array - an array of GPIO descriptors 367 - * array_info - optional information obtained from gpiod_array_get() 369 + * array_info - optional information obtained from gpiod_get_array() 368 370 * value_bitmap - a bitmap to store the GPIOs' values (get) or 369 371 a bitmap of values to assign to the GPIOs (set) 370 372
+8 -8
Documentation/driver-api/gpio/driver.rst
··· 235 235 GPIO line, and this resistor is software controlled. 236 236 237 237 In discrete designs, a pull-up or pull-down resistor is simply soldered on 238 - the circuit board. This is not something we deal or model in software. The 238 + the circuit board. This is not something we deal with or model in software. The 239 239 most you will think about these lines is that they will very likely be 240 240 configured as open drain or open source (see the section above). 241 241 ··· 292 292 293 293 - HIERARCHICAL INTERRUPT CHIPS: this means that each GPIO line has a dedicated 294 294 irq line to a parent interrupt controller one level up. There is no need 295 - to inquire the GPIO hardware to figure out which line has figured, but it 296 - may still be necessary to acknowledge the interrupt and set up the 297 - configuration such as edge sensitivity. 295 + to inquire the GPIO hardware to figure out which line has fired, but it 296 + may still be necessary to acknowledge the interrupt and set up configuration 297 + such as edge sensitivity. 298 298 299 299 Realtime considerations: a realtime compliant GPIO driver should not use 300 300 spinlock_t or any sleepable APIs (like PM runtime) as part of its irqchip 301 301 implementation. 302 302 303 - - spinlock_t should be replaced with raw_spinlock_t [1]. 303 + - spinlock_t should be replaced with raw_spinlock_t.[1] 304 304 - If sleepable APIs have to be used, these can be done from the .irq_bus_lock() 305 305 and .irq_bus_unlock() callbacks, as these are the only slowpath callbacks 306 - on an irqchip. Create the callbacks if needed [2]. 306 + on an irqchip. Create the callbacks if needed.[2] 307 307 308 308 309 309 Cascaded GPIO irqchips ··· 361 361 362 362 Realtime considerations: this kind of handlers will be forced threaded on -RT, 363 363 and as result the IRQ core will complain that generic_handle_irq() is called 364 - with IRQ enabled and the same work around as for "CHAINED GPIO irqchips" can 364 + with IRQ enabled and the same work-around as for "CHAINED GPIO irqchips" can 365 365 be applied. 366 366 367 367 - NESTED THREADED GPIO IRQCHIPS: these are off-chip GPIO expanders and any ··· 418 418 419 419 If there is a need to exclude certain GPIO lines from the IRQ domain handled by 420 420 these helpers, we can set .irq.need_valid_mask of the gpiochip before 421 - [devm_]gpiochip_add_data() is called. This allocates an .irq.valid_mask with as 421 + ``[devm_]gpiochip_add_data()`` is called. This allocates an .irq.valid_mask with as 422 422 many bits set as there are GPIO lines in the chip, each bit representing line 423 423 0..n-1. Drivers can exclude GPIO lines by clearing bits from this mask. The mask 424 424 must be filled in before gpiochip_irqchip_add() or gpiochip_irqchip_add_nested()
-47
Documentation/fmc/API.txt
··· 1 - Functions Exported by fmc.ko 2 - **************************** 3 - 4 - The FMC core exports the usual 4 functions that are needed for a bus to 5 - work, and a few more: 6 - 7 - int fmc_driver_register(struct fmc_driver *drv); 8 - void fmc_driver_unregister(struct fmc_driver *drv); 9 - int fmc_device_register(struct fmc_device *fmc); 10 - void fmc_device_unregister(struct fmc_device *fmc); 11 - 12 - int fmc_device_register_n(struct fmc_device **fmc, int n); 13 - void fmc_device_unregister_n(struct fmc_device **fmc, int n); 14 - 15 - uint32_t fmc_readl(struct fmc_device *fmc, int offset); 16 - void fmc_writel(struct fmc_device *fmc, uint32_t val, int off); 17 - void *fmc_get_drvdata(struct fmc_device *fmc); 18 - void fmc_set_drvdata(struct fmc_device *fmc, void *data); 19 - 20 - int fmc_reprogram(struct fmc_device *f, struct fmc_driver *d, char *gw, 21 - int sdb_entry); 22 - 23 - The data structure that describe a device is detailed in *note FMC 24 - Device::, the one that describes a driver is detailed in *note FMC 25 - Driver::. Please note that structures of type fmc_device must be 26 - allocated by the caller, but must not be released after unregistering. 27 - The fmc-bus itself takes care of releasing the structure when their use 28 - count reaches zero - actually, the device model does that in lieu of us. 29 - 30 - The functions to register and unregister n devices are meant to be used 31 - by carriers that host more than one mezzanine. The devices must all be 32 - registered at the same time because if the FPGA is reprogrammed, all 33 - devices in the array are affected. Usually, the driver matching the 34 - first device will reprogram the FPGA, so other devices must know they 35 - are already driven by a reprogrammed FPGA. 36 - 37 - If a carrier hosts slots that are driven by different FPGA devices, it 38 - should register as a group only mezzanines that are driven by the same 39 - FPGA, for the reason outlined above. 40 - 41 - Finally, the fmc_reprogram function calls the reprogram method (see 42 - *note The API Offered by Carriers:: and also scans the memory area for 43 - an SDB tree. You can pass -1 as sdb_entry to disable such scan. 44 - Otherwise, the function fails if no tree is found at the specified 45 - entry point. The function is meant to factorize common code, and by 46 - the time you read this it is already used by the spec-sw and fine-delay 47 - modules.
-88
Documentation/fmc/FMC-and-SDB.txt
··· 1 - 2 - FMC (FPGA Mezzanine Card) is the standard we use for our I/O devices, 3 - in the context of White Rabbit and related hardware. 4 - 5 - In our I/O environments we need to write drivers for each mezzanine 6 - card, and such drivers must work regardless of the carrier being used. 7 - To achieve this, we abstract the FMC interface. 8 - 9 - We have a carrier for PCI-E called SPEC and one for VME called SVEC, 10 - but more are planned. Also, we support stand-alone devices (usually 11 - plugged on a SPEC card), controlled through Etherbone, developed by GSI. 12 - 13 - Code and documentation for the FMC bus was born as part of the spec-sw 14 - project, but now it lives in its own project. Other projects, i.e. 15 - software support for the various carriers, should include this as a 16 - submodule. 17 - 18 - The most up to date version of code and documentation is always 19 - available from the repository you can clone from: 20 - 21 - git://ohwr.org/fmc-projects/fmc-bus.git (read-only) 22 - git@ohwr.org:fmc-projects/fmc-bus.git (read-write for developers) 23 - 24 - Selected versions of the documentation, as well as complete tar 25 - archives for selected revisions are placed to the Files section of the 26 - project: `http://www.ohwr.org/projects/fmc-bus/files' 27 - 28 - 29 - What is FMC 30 - *********** 31 - 32 - FMC, as said, stands for "FPGA Mezzanine Card". It is a standard 33 - developed by the VME consortium called VITA (VMEbus International Trade 34 - Association and ratified by ANSI, the American National Standard 35 - Institute. The official documentation is called "ANSI-VITA 57.1". 36 - 37 - The FMC card is an almost square PCB, around 70x75 millimeters, that is 38 - called mezzanine in this document. It usually lives plugged into 39 - another PCB for power supply and control; such bigger circuit board is 40 - called carrier from now on, and a single carrier may host more than one 41 - mezzanine. 42 - 43 - In the typical application the mezzanine is mostly analog while the 44 - carrier is mostly digital, and hosts an FPGA that must be configured to 45 - match the specific mezzanine and the desired application. Thus, you may 46 - need to load different FPGA images to drive different instances of the 47 - same mezzanine. 48 - 49 - FMC, as such, is not a bus in the usual meaning of the term, because 50 - most carriers have only one connector, and carriers with several 51 - connectors have completely separate electrical connections to them. 52 - This package, however, implements a bus as a software abstraction. 53 - 54 - 55 - What is SDB 56 - *********** 57 - 58 - SDB (Self Describing Bus) is a set of data structures that we use for 59 - enumerating the internal structure of an FPGA image. We also use it as 60 - a filesystem inside the FMC EEPROM. 61 - 62 - SDB is not mandatory for use of this FMC kernel bus, but if you have SDB 63 - this package can make good use of it. SDB itself is developed in the 64 - fpga-config-space OHWR project. The link to the repository is 65 - `git://ohwr.org/hdl-core-lib/fpga-config-space.git' and what is used in 66 - this project lives in the sdbfs subdirectory in there. 67 - 68 - SDB support for FMC is described in *note FMC Identification:: and 69 - *note SDB Support:: 70 - 71 - 72 - SDB Support 73 - *********** 74 - 75 - The fmc.ko bus driver exports a few functions to help drivers taking 76 - advantage of the SDB information that may be present in your own FPGA 77 - memory image. 78 - 79 - The module exports the following functions, in the special header 80 - <linux/fmc-sdb.h>. The linux/ prefix in the name is there because we 81 - plan to submit it upstream in the future, and don't want to force 82 - changes on our drivers if that happens. 83 - 84 - int fmc_scan_sdb_tree(struct fmc_device *fmc, unsigned long address); 85 - void fmc_show_sdb_tree(struct fmc_device *fmc); 86 - signed long fmc_find_sdb_device(struct sdb_array *tree, uint64_t vendor, 87 - uint32_t device, unsigned long *sz); 88 - int fmc_free_sdb_tree(struct fmc_device *fmc);
-311
Documentation/fmc/carrier.txt
··· 1 - FMC Device 2 - ********** 3 - 4 - Within the Linux bus framework, the FMC device is created and 5 - registered by the carrier driver. For example, the PCI driver for the 6 - SPEC card fills a data structure for each SPEC that it drives, and 7 - registers an associated FMC device for each card. The SVEC driver can 8 - do exactly the same for the VME carrier (actually, it should do it 9 - twice, because the SVEC carries two FMC mezzanines). Similarly, an 10 - Etherbone driver will be able to register its own FMC devices, offering 11 - communication primitives through frame exchange. 12 - 13 - The contents of the EEPROM within the FMC are used for identification 14 - purposes, i.e. for matching the device with its own driver. For this 15 - reason the device structure includes a complete copy of the EEPROM 16 - (actually, the carrier driver may choose whether or not to return it - 17 - for example we most likely won't have the whole EEPROM available for 18 - Etherbone devices. 19 - 20 - The following listing shows the current structure defining a device. 21 - Please note that all the machinery is in place but some details may 22 - still change in the future. For this reason, there is a version field 23 - at the beginning of the structure. As usual, the minor number will 24 - change for compatible changes (like a new flag) and the major number 25 - will increase when an incompatible change happens (for example, a 26 - change in layout of some fmc data structures). Device writers should 27 - just set it to the value FMC_VERSION, and be ready to get back -EINVAL 28 - at registration time. 29 - 30 - struct fmc_device { 31 - unsigned long version; 32 - unsigned long flags; 33 - struct module *owner; /* char device must pin it */ 34 - struct fmc_fru_id id; /* for EEPROM-based match */ 35 - struct fmc_operations *op; /* carrier-provided */ 36 - int irq; /* according to host bus. 0 == none */ 37 - int eeprom_len; /* Usually 8kB, may be less */ 38 - int eeprom_addr; /* 0x50, 0x52 etc */ 39 - uint8_t *eeprom; /* Full contents or leading part */ 40 - char *carrier_name; /* "SPEC" or similar, for special use */ 41 - void *carrier_data; /* "struct spec *" or equivalent */ 42 - __iomem void *fpga_base; /* May be NULL (Etherbone) */ 43 - __iomem void *slot_base; /* Set by the driver */ 44 - struct fmc_device **devarray; /* Allocated by the bus */ 45 - int slot_id; /* Index in the slot array */ 46 - int nr_slots; /* Number of slots in this carrier */ 47 - unsigned long memlen; /* Used for the char device */ 48 - struct device dev; /* For Linux use */ 49 - struct device *hwdev; /* The underlying hardware device */ 50 - unsigned long sdbfs_entry; 51 - struct sdb_array *sdb; 52 - uint32_t device_id; /* Filled by the device */ 53 - char *mezzanine_name; /* Defaults to ``fmc'' */ 54 - void *mezzanine_data; 55 - }; 56 - 57 - The meaning of most fields is summarized in the code comment above. 58 - 59 - The following fields must be filled by the carrier driver before 60 - registration: 61 - 62 - * version: must be set to FMC_VERSION. 63 - 64 - * owner: set to MODULE_OWNER. 65 - 66 - * op: the operations to act on the device. 67 - 68 - * irq: number for the mezzanine; may be zero. 69 - 70 - * eeprom_len: length of the following array. 71 - 72 - * eeprom_addr: 0x50 for first mezzanine and so on. 73 - 74 - * eeprom: the full content of the I2C EEPROM. 75 - 76 - * carrier_name. 77 - 78 - * carrier_data: a unique pointer for the carrier. 79 - 80 - * fpga_base: the I/O memory address (may be NULL). 81 - 82 - * slot_id: the index of this slot (starting from zero). 83 - 84 - * memlen: if fpga_base is valid, the length of I/O memory. 85 - 86 - * hwdev: to be used in some dev_err() calls. 87 - 88 - * device_id: a slot-specific unique integer number. 89 - 90 - 91 - Please note that the carrier should read its own EEPROM memory before 92 - registering the device, as well as fill all other fields listed above. 93 - 94 - The following fields should not be assigned, because they are filled 95 - later by either the bus or the device driver: 96 - 97 - * flags. 98 - 99 - * fru_id: filled by the bus, parsing the eeprom. 100 - 101 - * slot_base: filled and used by the driver, if useful to it. 102 - 103 - * devarray: an array og all mezzanines driven by a singe FPGA. 104 - 105 - * nr_slots: set by the core at registration time. 106 - 107 - * dev: used by Linux. 108 - 109 - * sdb: FPGA contents, scanned according to driver's directions. 110 - 111 - * sdbfs_entry: SDB entry point in EEPROM: autodetected. 112 - 113 - * mezzanine_data: available for the driver. 114 - 115 - * mezzanine_name: filled by fmc-bus during identification. 116 - 117 - 118 - Note: mezzanine_data may be redundant, because Linux offers the drvdata 119 - approach, so the field may be removed in later versions of this bus 120 - implementation. 121 - 122 - As I write this, she SPEC carrier is already completely functional in 123 - the fmc-bus environment, and is a good reference to look at. 124 - 125 - 126 - The API Offered by Carriers 127 - =========================== 128 - 129 - The carrier provides a number of methods by means of the 130 - `fmc_operations' structure, which currently is defined like this 131 - (again, it is a moving target, please refer to the header rather than 132 - this document): 133 - 134 - struct fmc_operations { 135 - uint32_t (*readl)(struct fmc_device *fmc, int offset); 136 - void (*writel)(struct fmc_device *fmc, uint32_t value, int offset); 137 - int (*reprogram)(struct fmc_device *f, struct fmc_driver *d, char *gw); 138 - int (*validate)(struct fmc_device *fmc, struct fmc_driver *drv); 139 - int (*irq_request)(struct fmc_device *fmc, irq_handler_t h, 140 - char *name, int flags); 141 - void (*irq_ack)(struct fmc_device *fmc); 142 - int (*irq_free)(struct fmc_device *fmc); 143 - int (*gpio_config)(struct fmc_device *fmc, struct fmc_gpio *gpio, 144 - int ngpio); 145 - int (*read_ee)(struct fmc_device *fmc, int pos, void *d, int l); 146 - int (*write_ee)(struct fmc_device *fmc, int pos, const void *d, int l); 147 - }; 148 - 149 - The individual methods perform the following tasks: 150 - 151 - `readl' 152 - `writel' 153 - These functions access FPGA registers by whatever means the 154 - carrier offers. They are not expected to fail, and most of the time 155 - they will just make a memory access to the host bus. If the 156 - carrier provides a fpga_base pointer, the driver may use direct 157 - access through that pointer. For this reason the header offers the 158 - inline functions fmc_readl and fmc_writel that access fpga_base if 159 - the respective method is NULL. A driver that wants to be portable 160 - and efficient should use fmc_readl and fmc_writel. For Etherbone, 161 - or other non-local carriers, error-management is still to be 162 - defined. 163 - 164 - `validate' 165 - Module parameters are used to manage different applications for 166 - two or more boards of the same kind. Validation is based on the 167 - busid module parameter, if provided, and returns the matching 168 - index in the associated array. See *note Module Parameters:: in in 169 - doubt. If no match is found, `-ENOENT' is returned; if the user 170 - didn't pass `busid=', all devices will pass validation. The value 171 - returned by the validate method can be used as index into other 172 - parameters (for example, some drivers use the `lm32=' parameter in 173 - this way). Such "generic parameters" are documented in *note 174 - Module Parameters::, below. The validate method is used by 175 - `fmc-trivial.ko', described in *note fmc-trivial::. 176 - 177 - `reprogram' 178 - The carrier enumerates FMC devices by loading a standard (or 179 - golden) FPGA binary that allows EEPROM access. Each driver, then, 180 - will need to reprogram the FPGA by calling this function. If the 181 - name argument is NULL, the carrier should reprogram the golden 182 - binary. If the gateware name has been overridden through module 183 - parameters (in a carrier-specific way) the file loaded will match 184 - the parameters. Per-device gateware names can be specified using 185 - the `gateware=' parameter, see *note Module Parameters::. Note: 186 - Clients should call rhe new helper, fmc_reprogram, which both 187 - calls this method and parse the SDB tree of the FPGA. 188 - 189 - `irq_request' 190 - `irq_ack' 191 - `irq_free' 192 - Interrupt management is carrier-specific, so it is abstracted as 193 - operations. The interrupt number is listed in the device 194 - structure, and for the mezzanine driver the number is only 195 - informative. The handler will receive the fmc pointer as dev_id; 196 - the flags argument is passed to the Linux request_irq function, 197 - but fmc-specific flags may be added in the future. You'll most 198 - likely want to pass the `IRQF_SHARED' flag. 199 - 200 - `gpio_config' 201 - The method allows to configure a GPIO pin in the carrier, and read 202 - its current value if it is configured as input. See *note The GPIO 203 - Abstraction:: for details. 204 - 205 - `read_ee' 206 - `write_ee' 207 - Read or write the EEPROM. The functions are expected to be only 208 - called before reprogramming and the carrier should refuse them 209 - with `ENODEV' after reprogramming. The offset is expected to be 210 - within 8kB (the current size), but addresses up to 1MB are 211 - reserved to fit bigger I2C devices in the future. Carriers may 212 - offer access to other internal flash memories using these same 213 - methods: for example the SPEC driver may define that its carrier 214 - I2C memory is seen at offset 1M and the internal SPI flash is seen 215 - at offset 16M. This multiplexing of several flash memories in the 216 - same address space is carrier-specific and should only be used 217 - by a driver that has verified the `carrier_name' field. 218 - 219 - 220 - 221 - The GPIO Abstraction 222 - ==================== 223 - 224 - Support for GPIO pins in the fmc-bus environment is not very 225 - straightforward and deserves special discussion. 226 - 227 - While the general idea of a carrier-independent driver seems to fly, 228 - configuration of specific signals within the carrier needs at least 229 - some knowledge of the carrier itself. For this reason, the specific 230 - driver can request to configure carrier-specific GPIO pins, numbered 231 - from 0 to at most 4095. Configuration is performed by passing a 232 - pointer to an array of struct fmc_gpio items, as well as the length of 233 - the array. This is the data structure: 234 - 235 - struct fmc_gpio { 236 - char *carrier_name; 237 - int gpio; 238 - int _gpio; /* internal use by the carrier */ 239 - int mode; /* GPIOF_DIR_OUT etc, from <linux/gpio.h> */ 240 - int irqmode; /* IRQF_TRIGGER_LOW and so on */ 241 - }; 242 - 243 - By specifying a carrier_name for each pin, the driver may access 244 - different pins in different carriers. The gpio_config method is 245 - expected to return the number of pins successfully configured, ignoring 246 - requests for other carriers. However, if no pin is configured (because 247 - no structure at all refers to the current carrier_name), the operation 248 - returns an error so the caller will know that it is running under a 249 - yet-unsupported carrier. 250 - 251 - So, for example, a driver that has been developed and tested on both 252 - the SPEC and the SVEC may request configuration of two different GPIO 253 - pins, and expect one such configuration to succeed - if none succeeds 254 - it most likely means that the current carrier is a still-unknown one. 255 - 256 - If, however, your GPIO pin has a specific known role, you can pass a 257 - special number in the gpio field, using one of the following macros: 258 - 259 - #define FMC_GPIO_RAW(x) (x) /* 4096 of them */ 260 - #define FMC_GPIO_IRQ(x) ((x) + 0x1000) /* 256 of them */ 261 - #define FMC_GPIO_LED(x) ((x) + 0x1100) /* 256 of them */ 262 - #define FMC_GPIO_KEY(x) ((x) + 0x1200) /* 256 of them */ 263 - #define FMC_GPIO_TP(x) ((x) + 0x1300) /* 256 of them */ 264 - #define FMC_GPIO_USER(x) ((x) + 0x1400) /* 256 of them */ 265 - 266 - Use of virtual GPIO numbers (anything but FMC_GPIO_RAW) is allowed 267 - provided the carrier_name field in the data structure is left 268 - unspecified (NULL). Each carrier is responsible for providing a mapping 269 - between virtual and physical GPIO numbers. The carrier may then use the 270 - _gpio field to cache the result of this mapping. 271 - 272 - All carriers must map their I/O lines to the sets above starting from 273 - zero. The SPEC, for example, maps interrupt pins 0 and 1, and test 274 - points 0 through 3 (even if the test points on the PCB are called 275 - 5,6,7,8). 276 - 277 - If, for example, a driver requires a free LED and a test point (for a 278 - scope probe to be plugged at some point during development) it may ask 279 - for FMC_GPIO_LED(0) and FMC_GPIO_TP(0). Each carrier will provide 280 - suitable GPIO pins. Clearly, the person running the drivers will know 281 - the order used by the specific carrier driver in assigning leds and 282 - testpoints, so to make a carrier-dependent use of the diagnostic tools. 283 - 284 - In theory, some form of autodetection should be possible: a driver like 285 - the wr-nic (which uses IRQ(1) on the SPEC card) should configure 286 - IRQ(0), make a test with software-generated interrupts and configure 287 - IRQ(1) if the test fails. This probing step should be used because even 288 - if the wr-nic gateware is known to use IRQ1 on the SPEC, the driver 289 - should be carrier-independent and thus use IRQ(0) as a first bet - 290 - actually, the knowledge that IRQ0 may fail is carrier-dependent 291 - information, but using it doesn't make the driver unsuitable for other 292 - carriers. 293 - 294 - The return value of gpio_config is defined as follows: 295 - 296 - * If no pin in the array can be used by the carrier, `-ENODEV'. 297 - 298 - * If at least one virtual GPIO number cannot be mapped, `-ENOENT'. 299 - 300 - * On success, 0 or positive. The value returned is the number of 301 - high input bits (if no input is configured, the value for success 302 - is 0). 303 - 304 - While I admit the procedure is not completely straightforward, it 305 - allows configuration, input and output with a single carrier operation. 306 - Given the typical use case of FMC devices, GPIO operations are not 307 - expected to ever by in hot paths, and GPIO access so fare has only been 308 - used to configure the interrupt pin, mode and polarity. Especially 309 - reading inputs is not expected to be common. If your device has GPIO 310 - capabilities in the hot path, you should consider using the kernel's 311 - GPIO mechanisms.
-64
Documentation/fmc/fmc-chardev.txt
··· 1 - fmc-chardev 2 - =========== 3 - 4 - This is a simple generic driver, that allows user access by means of a 5 - character device (actually, one for each mezzanine it takes hold of). 6 - 7 - The char device is created as a misc device. Its name in /dev (as 8 - created by udev) is the same name as the underlying FMC device. Thus, 9 - the name can be a silly fmc-0000 look-alike if the device has no 10 - identifiers nor bus_id, a more specific fmc-0400 if the device has a 11 - bus-specific address but no associated name, or something like 12 - fdelay-0400 if the FMC core can rely on both a mezzanine name and a bus 13 - address. 14 - 15 - Currently the driver only supports read and write: you can lseek to the 16 - desired address and read or write a register. 17 - 18 - The driver assumes all registers are 32-bit in size, and only accepts a 19 - single read or write per system call. However, as a result of Unix read 20 - and write semantics, users can simply fread or fwrite bigger areas in 21 - order to dump or store bigger memory areas. 22 - 23 - There is currently no support for mmap, user-space interrupt management 24 - and DMA buffers. They may be added in later versions, if the need 25 - arises. 26 - 27 - The example below shows raw access to a SPEC card programmed with its 28 - golden FPGA file, that features an SDB structure at offset 256 - i.e. 29 - 64 words. The mezzanine's EEPROM in this case is not programmed, so the 30 - default name is fmc-<bus><devfn>, and there are two cards in the system: 31 - 32 - spusa.root# insmod fmc-chardev.ko 33 - [ 1073.339332] spec 0000:02:00.0: Driver has no ID: matches all 34 - [ 1073.345051] spec 0000:02:00.0: Created misc device "fmc-0200" 35 - [ 1073.350821] spec 0000:04:00.0: Driver has no ID: matches all 36 - [ 1073.356525] spec 0000:04:00.0: Created misc device "fmc-0400" 37 - spusa.root# ls -l /dev/fmc* 38 - crw------- 1 root root 10, 58 Nov 20 19:23 /dev/fmc-0200 39 - crw------- 1 root root 10, 57 Nov 20 19:23 /dev/fmc-0400 40 - spusa.root# dd bs=4 skip=64 count=1 if=/dev/fmc-0200 2> /dev/null | od -t x1z 41 - 0000000 2d 42 44 53 >-BDS< 42 - 0000004 43 - 44 - The simple program tools/fmc-mem in this package can access an FMC char 45 - device and read or write a word or a whole area. Actually, the program 46 - is not specific to FMC at all, it just uses lseek, read and write. 47 - 48 - Its first argument is the device name, the second the offset, the third 49 - (if any) the value to write and the optional last argument that must 50 - begin with "+" is the number of bytes to read or write. In case of 51 - repeated reading data is written to stdout; repeated writes read from 52 - stdin and the value argument is ignored. 53 - 54 - The following examples show reading the SDB magic number and the first 55 - SDB record from a SPEC device programmed with its golden image: 56 - 57 - spusa.root# ./fmc-mem /dev/fmc-0200 100 58 - 5344422d 59 - spusa.root# ./fmc-mem /dev/fmc-0200 100 +40 | od -Ax -t x1z 60 - 000000 2d 42 44 53 00 01 02 00 00 00 00 00 00 00 00 00 >-BDS............< 61 - 000010 00 00 00 00 ff 01 00 00 00 00 00 00 51 06 00 00 >............Q...< 62 - 000020 c9 42 a5 e6 02 00 00 00 11 05 12 20 2d 34 42 57 >.B......... -4BW< 63 - 000030 73 6f 72 43 72 61 62 73 49 53 47 2d 00 20 20 20 >sorCrabsISG-. < 64 - 000040
-36
Documentation/fmc/fmc-fakedev.txt
··· 1 - fmc-fakedev 2 - =========== 3 - 4 - This package includes a software-only device, called fmc-fakedev, which 5 - is able to register up to 4 mezzanines (by default it registers one). 6 - Unlike the SPEC driver, which creates an FMC device for each PCI cards 7 - it manages, this module creates a single instance of its set of 8 - mezzanines. 9 - 10 - It is meant as the simplest possible example of how a driver should be 11 - written, and it includes a fake EEPROM image (built using the tools 12 - described in *note FMC Identification::),, which by default is 13 - replicated for each fake mezzanine. 14 - 15 - You can also use this device to verify the match algorithms, by asking 16 - it to test your own EEPROM image. You can provide the image by means of 17 - the eeprom= module parameter: the new EEPROM image is loaded, as usual, 18 - by means of the firmware loader. This example shows the defaults and a 19 - custom EEPROM image: 20 - 21 - spusa.root# insmod fmc-fakedev.ko 22 - [ 99.971247] fake-fmc-carrier: mezzanine 0 23 - [ 99.975393] Manufacturer: fake-vendor 24 - [ 99.979624] Product name: fake-design-for-testing 25 - spusa.root# rmmod fmc-fakedev 26 - spusa.root# insmod fmc-fakedev.ko eeprom=fdelay-eeprom.bin 27 - [ 121.447464] fake-fmc-carrier: Mezzanine 0: eeprom "fdelay-eeprom.bin" 28 - [ 121.462725] fake-fmc-carrier: mezzanine 0 29 - [ 121.466858] Manufacturer: CERN 30 - [ 121.470477] Product name: FmcDelay1ns4cha 31 - spusa.root# rmmod fmc-fakedev 32 - 33 - After loading the device, you can use the write_ee method do modify its 34 - own internal fake EEPROM: whenever the image is overwritten starting at 35 - offset 0, the module will unregister and register again the FMC device. 36 - This is shown in fmc-write-eeprom.txt
-17
Documentation/fmc/fmc-trivial.txt
··· 1 - fmc-trivial 2 - =========== 3 - 4 - The simple module fmc-trivial is just a simple client that registers an 5 - interrupt handler. I used it to verify the basic mechanism of the FMC 6 - bus and how interrupts worked. 7 - 8 - The module implements the generic FMC parameters, so it can program a 9 - different gateware file in each card. The whole list of parameters it 10 - accepts are: 11 - 12 - `busid=' 13 - `gateware=' 14 - Generic parameters. See mezzanine.txt 15 - 16 - 17 - This driver is worth reading, in my opinion.
-98
Documentation/fmc/fmc-write-eeprom.txt
··· 1 - fmc-write-eeprom 2 - ================ 3 - 4 - This module is designed to load a binary file from /lib/firmware and to 5 - write it to the internal EEPROM of the mezzanine card. This driver uses 6 - the `busid' generic parameter. 7 - 8 - Overwriting the EEPROM is not something you should do daily, and it is 9 - expected to only happen during manufacturing. For this reason, the 10 - module makes it unlikely for the random user to change a working EEPROM. 11 - 12 - However, since the EEPROM may include application-specific information 13 - other than the identification, later versions of this packages added 14 - write-support through sysfs. See *note Accessing the EEPROM::. 15 - 16 - To avoid damaging the EEPROM content, the module takes the following 17 - measures: 18 - 19 - * It accepts a `file=' argument (within /lib/firmware) and if no 20 - such argument is received, it doesn't write anything to EEPROM 21 - (i.e. there is no default file name). 22 - 23 - * If the file name ends with `.bin' it is written verbatim starting 24 - at offset 0. 25 - 26 - * If the file name ends with `.tlv' it is interpreted as 27 - type-length-value (i.e., it allows writev(2)-like operation). 28 - 29 - * If the file name doesn't match any of the patterns above, it is 30 - ignored and no write is performed. 31 - 32 - * Only cards listed with `busid=' are written to. If no busid is 33 - specified, no programming is done (and the probe function of the 34 - driver will fail). 35 - 36 - 37 - Each TLV tuple is formatted in this way: the header is 5 bytes, 38 - followed by data. The first byte is `w' for write, the next two bytes 39 - represent the address, in little-endian byte order, and the next two 40 - represent the data length, in little-endian order. The length does not 41 - include the header (it is the actual number of bytes to be written). 42 - 43 - This is a real example: that writes 5 bytes at position 0x110: 44 - 45 - spusa.root# od -t x1 -Ax /lib/firmware/try.tlv 46 - 000000 77 10 01 05 00 30 31 32 33 34 47 - 00000a 48 - spusa.root# insmod /tmp/fmc-write-eeprom.ko busid=0x0200 file=try.tlv 49 - [19983.391498] spec 0000:03:00.0: write 5 bytes at 0x0110 50 - [19983.414615] spec 0000:03:00.0: write_eeprom: success 51 - 52 - Please note that you'll most likely want to use SDBFS to build your 53 - EEPROM image, at least if your mezzanines are being used in the White 54 - Rabbit environment. For this reason the TLV format is not expected to 55 - be used much and is not expected to be developed further. 56 - 57 - If you want to try reflashing fake EEPROM devices, you can use the 58 - fmc-fakedev.ko module (see *note fmc-fakedev::). Whenever you change 59 - the image starting at offset 0, it will deregister and register again 60 - after two seconds. Please note, however, that if fmc-write-eeprom is 61 - still loaded, the system will associate it to the new device, which 62 - will be reprogrammed and thus will be unloaded after two seconds. The 63 - following example removes the module after it reflashed fakedev the 64 - first time. 65 - 66 - spusa.root# insmod fmc-fakedev.ko 67 - [ 72.984733] fake-fmc: Manufacturer: fake-vendor 68 - [ 72.989434] fake-fmc: Product name: fake-design-for-testing 69 - spusa.root# insmod fmc-write-eeprom.ko busid=0 file=fdelay-eeprom.bin; \ 70 - rmmod fmc-write-eeprom 71 - [ 130.874098] fake-fmc: Matching a generic driver (no ID) 72 - [ 130.887845] fake-fmc: programming 6155 bytes 73 - [ 130.894567] fake-fmc: write_eeprom: success 74 - [ 132.895794] fake-fmc: Manufacturer: CERN 75 - [ 132.899872] fake-fmc: Product name: FmcDelay1ns4cha 76 - 77 - 78 - Accessing the EEPROM 79 - ===================== 80 - 81 - The bus creates a sysfs binary file called eeprom for each mezzanine it 82 - knows about: 83 - 84 - spusa.root# cd /sys/bus/fmc/devices; ls -l */eeprom 85 - -r--r--r-- 1 root root 8192 Feb 21 12:30 FmcAdc100m14b4cha-0800/eeprom 86 - -r--r--r-- 1 root root 8192 Feb 21 12:30 FmcDelay1ns4cha-0200/eeprom 87 - -r--r--r-- 1 root root 8192 Feb 21 12:30 FmcDio5cha-0400/eeprom 88 - 89 - Everybody can read the files and the superuser can also modify it, but 90 - the operation may on the carrier driver, if the carrier is unable to 91 - access the I2C bus. For example, the spec driver can access the bus 92 - only with its golden gateware: after a mezzanine driver reprogrammed 93 - the FPGA with a custom circuit, the carrier is unable to access the 94 - EEPROM and returns ENOTSUPP. 95 - 96 - An alternative way to write the EEPROM is the mezzanine driver 97 - fmc-write-eeprom (See *note fmc-write-eeprom::), but the procedure is 98 - more complex.
-168
Documentation/fmc/identifiers.txt
··· 1 - FMC Identification 2 - ****************** 3 - 4 - The FMC standard requires every compliant mezzanine to carry 5 - identification information in an I2C EEPROM. The information must be 6 - laid out according to the "IPMI Platform Management FRU Information", 7 - where IPMI is a lie I'd better not expand, and FRU means "Field 8 - Replaceable Unit". 9 - 10 - The FRU information is an intricate unreadable binary blob that must 11 - live at offset 0 of the EEPROM, and typically extends for a few hundred 12 - bytes. The standard allows the application to use all the remaining 13 - storage area of the EEPROM as it wants. 14 - 15 - This chapter explains how to create your own EEPROM image and how to 16 - write it in your mezzanine, as well as how devices and drivers are 17 - paired at run time. EEPROM programming uses tools that are part of this 18 - package and SDB (part of the fpga-config-space package). 19 - 20 - The first sections are only interesting for manufacturers who need to 21 - write the EEPROM. If you are just a software developer writing an FMC 22 - device or driver, you may jump straight to *note SDB Support::. 23 - 24 - 25 - Building the FRU Structure 26 - ========================== 27 - 28 - If you want to know the internals of the FRU structure and despair, you 29 - can retrieve the document from 30 - `http://download.intel.com/design/servers/ipmi/FRU1011.pdf' . The 31 - standard is awful and difficult without reason, so we only support the 32 - minimum mandatory subset - we create a simple structure and parse it 33 - back at run time, but we are not able to either generate or parse more 34 - arcane features like non-english languages and 6-bit text. If you need 35 - more items of the FRU standard for your boards, please submit patches. 36 - 37 - This package includes the Python script that Matthieu Cattin wrote to 38 - generate the FRU binary blob, based on an helper libipmi by Manohar 39 - Vanga and Matthieu himself. I changed the test script to receive 40 - parameters from the command line or from the environment (the command 41 - line takes precedence) 42 - 43 - To make a long story short, in order to build a standard-compliant 44 - binary file to be burned in your EEPROM, you need the following items: 45 - 46 - Environment Opt Official Name Default 47 - --------------------------------------------------------------------- 48 - FRU_VENDOR -v "Board Manufacturer" fmc-example 49 - FRU_NAME -n "Board Product Name" mezzanine 50 - FRU_SERIAL -s `Board Serial Number" 0001 51 - FRU_PART -p "Board Part Number" sample-part 52 - FRU_OUTPUT -o not applicable /dev/stdout 53 - 54 - The "Official Name" above is what you find in the FRU official 55 - documentation, chapter 11, page 7 ("Board Info Area Format"). The 56 - output option is used to save the generated binary to a specific file 57 - name instead of stdout. 58 - 59 - You can pass the items to the FRU generator either in the environment 60 - or on the command line. This package has currently no support for 61 - specifying power consumption or such stuff, but I plan to add it as 62 - soon as I find some time for that. 63 - 64 - FIXME: consumption etc for FRU are here or in PTS? 65 - 66 - The following example creates a binary image for a specific board: 67 - 68 - ./tools/fru-generator -v CERN -n FmcAdc100m14b4cha \ 69 - -s HCCFFIA___-CR000003 -p EDA-02063-V5-0 > eeprom.bin 70 - 71 - The following example shows a script that builds several binary EEPROM 72 - images for a series of boards, changing the serial number for each of 73 - them. The script uses a mix of environment variables and command line 74 - options, and uses the same string patterns shown above. 75 - 76 - #!/bin/sh 77 - 78 - export FRU_VENDOR="CERN" 79 - export FRU_NAME="FmcAdc100m14b4cha" 80 - export FRU_PART="EDA-02063-V5-0" 81 - 82 - serial="HCCFFIA___-CR" 83 - 84 - for number in $(seq 1 50); do 85 - # build number-string "ns" 86 - ns="$(printf %06d $number)" 87 - ./fru-generator -s "${serial}${ns}" > eeprom-${ns}.bin 88 - done 89 - 90 - 91 - Using SDB-FS in the EEPROM 92 - ========================== 93 - 94 - If you want to use SDB as a filesystem in the EEPROM device within the 95 - mezzanine, you should create one such filesystem using gensdbfs, from 96 - the fpga-config-space package on OHWR. 97 - 98 - By using an SBD filesystem you can cluster several files in a single 99 - EEPROM, so both the host system and a soft-core running in the FPGA (if 100 - any) can access extra production-time information. 101 - 102 - We chose to use SDB as a storage filesystem because the format is very 103 - simple, and both the host system and the soft-core will likely already 104 - include support code for such format. The SDB library offered by the 105 - fpga-config-space is less than 1kB under LM32, so it proves quite up to 106 - the task. 107 - 108 - The SDB entry point (which acts as a directory listing) cannot live at 109 - offset zero in the flash device, because the FRU information must live 110 - there. To avoid wasting precious storage space while still allowing 111 - for more-than-minimal FRU structures, the fmc.ko will look for the SDB 112 - record at address 256, 512 and 1024. 113 - 114 - In order to generate the complete EEPROM image you'll need a 115 - configuration file for gensdbfs: you tell the program where to place 116 - the sdb entry point, and you must force the FRU data file to be placed 117 - at the beginning of the storage device. If needed, you can also place 118 - other files at a special offset (we sometimes do it for backward 119 - compatibility with drivers we wrote before implementing SDB for flash 120 - memory). 121 - 122 - The directory tools/sdbfs of this package includes a well-commented 123 - example that you may want to use as a starting point (the comments are 124 - in the file called -SDB-CONFIG-). Reading documentation for gensdbfs 125 - is a suggested first step anyways. 126 - 127 - This package (generic FMC bus support) only accesses two files in the 128 - EEPROM: the FRU information, at offset zero, with a suggested filename 129 - of IPMI-FRU and the short name for the mezzanine, in a file called 130 - name. The IPMI-FRU name is not mandatory, but a strongly suggested 131 - choice; the name filename is mandatory, because this is the preferred 132 - short name used by the FMC core. For example, a name of "fdelay" may 133 - supplement a Product Name like "FmcDelay1ns4cha" - exactly as 134 - demonstrated in `tools/sdbfs'. 135 - 136 - Note: SDB access to flash memory is not yet supported, so the short 137 - name currently in use is just the "Product Name" FRU string. 138 - 139 - The example in tools/sdbfs includes an extra file, that is needed by 140 - the fine-delay driver, and must live at a known address of 0x1800. By 141 - running gensdbfs on that directory you can output your binary EEPROM 142 - image (here below spusa$ is the shell prompt): 143 - 144 - spusa$ ../fru-generator -v CERN -n FmcDelay1ns4cha -s proto-0 \ 145 - -p EDA-02267-V3 > IPMI-FRU 146 - spusa$ ls -l 147 - total 16 148 - -rw-rw-r-- 1 rubini staff 975 Nov 19 18:08 --SDB-CONFIG-- 149 - -rw-rw-r-- 1 rubini staff 216 Nov 19 18:13 IPMI-FRU 150 - -rw-rw-r-- 1 rubini staff 11 Nov 19 18:04 fd-calib 151 - -rw-rw-r-- 1 rubini staff 7 Nov 19 18:04 name 152 - spusa$ sudo gensdbfs . /lib/firmware/fdelay-eeprom.bin 153 - spusa$ sdb-read -l -e 0x100 /lib/firmware/fdelay-eeprom.bin 154 - /home/rubini/wip/sdbfs/userspace/sdb-read: listing format is to be defined 155 - 46696c6544617461:2e202020 00000100-000018ff . 156 - 46696c6544617461:6e616d65 00000200-00000206 name 157 - 46696c6544617461:66642d63 00001800-000018ff fd-calib 158 - 46696c6544617461:49504d49 00000000-000000d7 IPMI-FRU 159 - spusa$ ../fru-dump /lib/firmware/fdelay-eeprom.bin 160 - /lib/firmware/fdelay-eeprom.bin: manufacturer: CERN 161 - /lib/firmware/fdelay-eeprom.bin: product-name: FmcDelay1ns4cha 162 - /lib/firmware/fdelay-eeprom.bin: serial-number: proto-0 163 - /lib/firmware/fdelay-eeprom.bin: part-number: EDA-02267-V3 164 - 165 - As expected, the output file is both a proper sdbfs object and an IPMI 166 - FRU information blob. The fd-calib file lives at offset 0x1800 and is 167 - over-allocated to 256 bytes, according to the configuration file for 168 - gensdbfs.
-123
Documentation/fmc/mezzanine.txt
··· 1 - FMC Driver 2 - ********** 3 - 4 - An FMC driver is concerned with the specific mezzanine and associated 5 - gateware. As such, it is expected to be independent of the carrier 6 - being used: it will perform I/O accesses only by means of 7 - carrier-provided functions. 8 - 9 - The matching between device and driver is based on the content of the 10 - EEPROM (as mandated by the FMC standard) or by the actual cores 11 - configured in the FPGA; the latter technique is used when the FPGA is 12 - already programmed when the device is registered to the bus core. 13 - 14 - In some special cases it is possible for a driver to directly access 15 - FPGA registers, by means of the `fpga_base' field of the device 16 - structure. This may be needed for high-bandwidth peripherals like fast 17 - ADC cards. If the device module registered a remote device (for example 18 - by means of Etherbone), the `fpga_base' pointer will be NULL. 19 - Therefore, drivers must be ready to deal with NULL base pointers, and 20 - fail gracefully. Most driver, however, are not expected to access the 21 - pointer directly but run fmc_readl and fmc_writel instead, which will 22 - work in any case. 23 - 24 - In even more special cases, the driver may access carrier-specific 25 - functionality: the `carrier_name' string allows the driver to check 26 - which is the current carrier and make use of the `carrier_data' 27 - pointer. We chose to use carrier names rather than numeric identifiers 28 - for greater flexibility, but also to avoid a central registry within 29 - the `fmc.h' file - we hope other users will exploit our framework with 30 - their own carriers. An example use of carrier names is in GPIO setup 31 - (see *note The GPIO Abstraction::), although the name match is not 32 - expected to be performed by the driver. If you depend on specific 33 - carriers, please check the carrier name and fail gracefully if your 34 - driver finds it is running in a yet-unknown-to-it environment. 35 - 36 - 37 - ID Table 38 - ======== 39 - 40 - Like most other Linux drivers, and FMC driver must list all the devices 41 - which it is able to drive. This is usually done by means of a device 42 - table, but in FMC we can match hardware based either on the contents of 43 - their EEPROM or on the actual FPGA cores that can be enumerated. 44 - Therefore, we have two tables of identifiers. 45 - 46 - Matching of FRU information depends on two names, the manufacturer (or 47 - vendor) and the device (see *note FMC Identification::); for 48 - flexibility during production (i.e. before writing to the EEPROM) the 49 - bus supports a catch-all driver that specifies NULL strings. For this 50 - reason, the table is specified as pointer-and-length, not a a 51 - null-terminated array - the entry with NULL names can be a valid entry. 52 - 53 - Matching on FPGA cores depends on two numeric fields: the 64-bit vendor 54 - number and the 32-bit device number. Support for matching based on 55 - class is not yet implemented. Each device is expected to be uniquely 56 - identified by an array of cores (it matches if all of the cores are 57 - instantiated), and for consistency the list is passed as 58 - pointer-and-length. Several similar devices can be driven by the same 59 - driver, and thus the driver specifies and array of such arrays. 60 - 61 - The complete set of involved data structures is thus the following: 62 - 63 - struct fmc_fru_id { char *manufacturer; char *product_name; }; 64 - struct fmc_sdb_one_id { uint64_t vendor; uint32_t device; }; 65 - struct fmc_sdb_id { struct fmc_sdb_one_id *cores; int cores_nr; }; 66 - 67 - struct fmc_device_id { 68 - struct fmc_fru_id *fru_id; int fru_id_nr; 69 - struct fmc_sdb_id *sdb_id; int sdb_id_nr; 70 - }; 71 - 72 - A better reference, with full explanation, is the <linux/fmc.h> header. 73 - 74 - 75 - Module Parameters 76 - ================= 77 - 78 - Most of the FMC drivers need the same set of kernel parameters. This 79 - package includes support to implement common parameters by means of 80 - fields in the `fmc_driver' structure and simple macro definitions. 81 - 82 - The parameters are carrier-specific, in that they rely on the busid 83 - concept, that varies among carriers. For the SPEC, the identifier is a 84 - PCI bus and devfn number, 16 bits wide in total; drivers for other 85 - carriers will most likely offer something similar but not identical, 86 - and some code duplication is unavoidable. 87 - 88 - This is the list of parameters that are common to several modules to 89 - see how they are actually used, please look at spec-trivial.c. 90 - 91 - `busid=' 92 - This is an array of integers, listing carrier-specific 93 - identification numbers. For PIC, for example, `0x0400' represents 94 - bus 4, slot 0. If any such ID is specified, the driver will only 95 - accept to drive cards that appear in the list (even if the FMC ID 96 - matches). This is accomplished by the validate carrier method. 97 - 98 - `gateware=' 99 - The argument is an array of strings. If no busid= is specified, 100 - the first string of gateware= is used for all cards; otherwise the 101 - identifiers and gateware names are paired one by one, in the order 102 - specified. 103 - 104 - `show_sdb=' 105 - For modules supporting it, this parameter asks to show the SDB 106 - internal structure by means of kernel messages. It is disabled by 107 - default because those lines tend to hide more important messages, 108 - if you look at the system console while loading the drivers. 109 - Note: the parameter is being obsoleted, because fmc.ko itself now 110 - supports dump_sdb= that applies to every client driver. 111 - 112 - 113 - For example, if you are using the trivial driver to load two different 114 - gateware files to two different cards, you can use the following 115 - parameters to load different binaries to the cards, after looking up 116 - the PCI identifiers. This has been tested with a SPEC carrier. 117 - 118 - insmod fmc-trivial.ko \ 119 - busid=0x0200,0x0400 \ 120 - gateware=fmc/fine-delay.bin,fmc/simple-dio.bin 121 - 122 - Please note that not all sub-modules support all of those parameters. 123 - You can use modinfo to check what is supported by each module.
-56
Documentation/fmc/parameters.txt
··· 1 - Module Parameters in fmc.ko 2 - *************************** 3 - 4 - The core driver receives two module parameters, meant to help debugging 5 - client modules. Both parameters can be modified by writing to 6 - /sys/module/fmc/parameters/, because they are used when client drivers 7 - are devices are registered, not when fmc.ko is loaded. 8 - 9 - `dump_eeprom=' 10 - If not zero, the parameter asks the bus controller to dump the 11 - EEPROM of any device that is registered, using printk. 12 - 13 - `dump_sdb=' 14 - If not zero, the parameter prints the SDB tree of every FPGA it is 15 - loaded by fmc_reprogram(). If greater than one, it asks to dump 16 - the binary content of SDB records. This currently only dumps the 17 - top-level SDB array, though. 18 - 19 - 20 - EEPROM dumping avoids repeating lines, since most of the contents is 21 - usually empty and all bits are one or zero. This is an example of the 22 - output: 23 - 24 - [ 6625.850480] spec 0000:02:00.0: FPGA programming successful 25 - [ 6626.139949] spec 0000:02:00.0: Manufacturer: CERN 26 - [ 6626.144666] spec 0000:02:00.0: Product name: FmcDelay1ns4cha 27 - [ 6626.150370] FMC: mezzanine 0: 0000:02:00.0 on SPEC 28 - [ 6626.155179] FMC: dumping eeprom 0x2000 (8192) bytes 29 - [ 6626.160087] 0000: 01 00 00 01 00 0b 00 f3 01 0a 00 a5 85 87 c4 43 30 - [ 6626.167069] 0010: 45 52 4e cf 46 6d 63 44 65 6c 61 79 31 6e 73 34 31 - [ 6626.174019] 0020: 63 68 61 c7 70 72 6f 74 6f 2d 30 cc 45 44 41 2d 32 - [ 6626.180975] 0030: 30 32 32 36 37 2d 56 33 da 32 30 31 32 2d 31 31 33 - [...] 34 - [ 6626.371366] 0200: 66 64 65 6c 61 79 0a 00 00 00 00 00 00 00 00 00 35 - [ 6626.378359] 0210: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 36 - [ 6626.385361] [...] 37 - [ 6626.387308] 1800: 70 6c 61 63 65 68 6f 6c 64 65 72 ff ff ff ff ff 38 - [ 6626.394259] 1810: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 39 - [ 6626.401250] [...] 40 - 41 - The dump of SDB looks like the following; the example shows the simple 42 - golden gateware for the SPEC card, removing the leading timestamps to 43 - fit the page: 44 - 45 - spec 0000:02:00.0: SDB: 00000651:e6a542c9 WB4-Crossbar-GSI 46 - spec 0000:02:00.0: SDB: 0000ce42:ff07fc47 WR-Periph-Syscon (00000000-000000ff) 47 - FMC: mezzanine 0: 0000:02:00.0 on SPEC 48 - FMC: poor dump of sdb first level: 49 - 0000: 53 44 42 2d 00 02 01 00 00 00 00 00 00 00 00 00 50 - 0010: 00 00 00 00 00 00 01 ff 00 00 00 00 00 00 06 51 51 - 0020: e6 a5 42 c9 00 00 00 02 20 12 05 11 57 42 34 2d 52 - 0030: 43 72 6f 73 73 62 61 72 2d 47 53 49 20 20 20 00 53 - 0040: 00 00 01 01 00 00 00 07 00 00 00 00 00 00 00 00 54 - 0050: 00 00 00 00 00 00 00 ff 00 00 00 00 00 00 ce 42 55 - 0060: ff 07 fc 47 00 00 00 01 20 12 03 05 57 52 2d 50 56 - 0070: 65 72 69 70 68 2d 53 79 73 63 6f 6e 20 20 20 01
+3 -1
arch/arm/mach-omap1/ams-delta-fiq.c
··· 11 11 * in the MontaVista 2.4 kernel (and the Amstrad changes therein) 12 12 */ 13 13 #include <linux/gpio/consumer.h> 14 + #include <linux/gpio/machine.h> 14 15 #include <linux/gpio/driver.h> 15 16 #include <linux/interrupt.h> 16 17 #include <linux/irq.h> ··· 100 99 } 101 100 102 101 for (i = 0; i < ARRAY_SIZE(irq_data); i++) { 103 - gpiod = gpiochip_request_own_desc(chip, i, pin_name[i], 0); 102 + gpiod = gpiochip_request_own_desc(chip, i, pin_name[i], 103 + GPIO_ACTIVE_HIGH, GPIOD_IN); 104 104 if (IS_ERR(gpiod)) { 105 105 pr_err("%s: failed to get GPIO pin %d (%ld)\n", 106 106 __func__, i, PTR_ERR(gpiod));
+3 -2
arch/arm/mach-omap1/board-ams-delta.c
··· 10 10 */ 11 11 #include <linux/gpio/driver.h> 12 12 #include <linux/gpio/machine.h> 13 + #include <linux/gpio/consumer.h> 13 14 #include <linux/gpio.h> 14 15 #include <linux/kernel.h> 15 16 #include <linux/init.h> ··· 607 606 struct gpio_desc *gpiod; 608 607 609 608 gpiod = gpiochip_request_own_desc(chip, AMS_DELTA_GPIO_PIN_MODEM_IRQ, 610 - "modem_irq", 0); 609 + "modem_irq", GPIO_ACTIVE_HIGH, 610 + GPIOD_IN); 611 611 if (IS_ERR(gpiod)) { 612 612 pr_err("%s: modem IRQ GPIO request failed (%ld)\n", __func__, 613 613 PTR_ERR(gpiod)); 614 614 } else { 615 - gpiod_direction_input(gpiod); 616 615 ams_delta_modem_ports[0].irq = gpiod_to_irq(gpiod); 617 616 } 618 617 }
-2
drivers/Kconfig
··· 188 188 189 189 source "drivers/reset/Kconfig" 190 190 191 - source "drivers/fmc/Kconfig" 192 - 193 191 source "drivers/phy/Kconfig" 194 192 195 193 source "drivers/powercap/Kconfig"
-1
drivers/Makefile
··· 168 168 obj-$(CONFIG_VME_BUS) += vme/ 169 169 obj-$(CONFIG_IPACK_BUS) += ipack/ 170 170 obj-$(CONFIG_NTB) += ntb/ 171 - obj-$(CONFIG_FMC) += fmc/ 172 171 obj-$(CONFIG_POWERCAP) += powercap/ 173 172 obj-$(CONFIG_MCB) += mcb/ 174 173 obj-$(CONFIG_PERF_EVENTS) += perf/
-52
drivers/fmc/Kconfig
··· 1 - # SPDX-License-Identifier: GPL-2.0-only 2 - # 3 - # FMC (ANSI-VITA 57.1) bus support 4 - # 5 - 6 - menuconfig FMC 7 - tristate "FMC support" 8 - help 9 - 10 - FMC (FPGA Mezzanine Carrier) is a mechanical and electrical 11 - standard for mezzanine cards that plug into a carrier board. 12 - This kernel subsystem supports the matching between carrier 13 - and mezzanine based on identifiers stored in the internal I2C 14 - EEPROM, as well as having carrier-independent drivers. 15 - 16 - The framework was born outside of the kernel and at this time 17 - the off-tree code base is more complete. Code and documentation 18 - is at git://ohwr.org/fmc-projects/fmc-bus.git . 19 - 20 - if FMC 21 - 22 - config FMC_FAKEDEV 23 - tristate "FMC fake device (software testing)" 24 - help 25 - This is a fake carrier, bringing a default EEPROM content 26 - that can be rewritten at run time and usef for matching 27 - mezzanines. 28 - 29 - config FMC_TRIVIAL 30 - tristate "FMC trivial mezzanine driver (software testing)" 31 - help 32 - This is a fake mezzanine driver, to show how FMC works and test it. 33 - The driver also handles interrupts (we used it with a real carrier 34 - before the mezzanines were produced) 35 - 36 - config FMC_WRITE_EEPROM 37 - tristate "FMC mezzanine driver to write I2C EEPROM" 38 - help 39 - This driver matches every mezzanine device and can write the 40 - internal EEPROM of the PCB, using the firmware loader to get 41 - its binary and the function carrier->reprogram to actually do it. 42 - It is useful when the mezzanines are produced. 43 - 44 - config FMC_CHARDEV 45 - tristate "FMC mezzanine driver that registers a char device" 46 - help 47 - This driver matches every mezzanine device and allows user 48 - space to read and write registers using a char device. It 49 - can be used to write user-space drivers, or just get 50 - acquainted with a mezzanine before writing its specific driver. 51 - 52 - endif # FMC
-15
drivers/fmc/Makefile
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - 3 - obj-$(CONFIG_FMC) += fmc.o 4 - 5 - fmc-y = fmc-core.o 6 - fmc-y += fmc-match.o 7 - fmc-y += fmc-sdb.o 8 - fmc-y += fru-parse.o 9 - fmc-y += fmc-dump.o 10 - fmc-y += fmc-debug.o 11 - 12 - obj-$(CONFIG_FMC_FAKEDEV) += fmc-fakedev.o 13 - obj-$(CONFIG_FMC_TRIVIAL) += fmc-trivial.o 14 - obj-$(CONFIG_FMC_WRITE_EEPROM) += fmc-write-eeprom.o 15 - obj-$(CONFIG_FMC_CHARDEV) += fmc-chardev.o
-199
drivers/fmc/fmc-chardev.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Copyright (C) 2012 CERN (www.cern.ch) 4 - * Author: Alessandro Rubini <rubini@gnudd.com> 5 - * 6 - * This work is part of the White Rabbit project, a research effort led 7 - * by CERN, the European Institute for Nuclear Research. 8 - */ 9 - #include <linux/module.h> 10 - #include <linux/init.h> 11 - #include <linux/list.h> 12 - #include <linux/slab.h> 13 - #include <linux/fs.h> 14 - #include <linux/miscdevice.h> 15 - #include <linux/spinlock.h> 16 - #include <linux/fmc.h> 17 - #include <linux/uaccess.h> 18 - 19 - static LIST_HEAD(fc_devices); 20 - static DEFINE_SPINLOCK(fc_lock); 21 - 22 - struct fc_instance { 23 - struct list_head list; 24 - struct fmc_device *fmc; 25 - struct miscdevice misc; 26 - }; 27 - 28 - /* at open time, we must identify our device */ 29 - static int fc_open(struct inode *ino, struct file *f) 30 - { 31 - struct fmc_device *fmc; 32 - struct fc_instance *fc; 33 - int minor = iminor(ino); 34 - 35 - list_for_each_entry(fc, &fc_devices, list) 36 - if (fc->misc.minor == minor) 37 - break; 38 - if (fc->misc.minor != minor) 39 - return -ENODEV; 40 - fmc = fc->fmc; 41 - if (try_module_get(fmc->owner) == 0) 42 - return -ENODEV; 43 - 44 - f->private_data = fmc; 45 - return 0; 46 - } 47 - 48 - static int fc_release(struct inode *ino, struct file *f) 49 - { 50 - struct fmc_device *fmc = f->private_data; 51 - module_put(fmc->owner); 52 - return 0; 53 - } 54 - 55 - /* read and write are simple after the default llseek has been used */ 56 - static ssize_t fc_read(struct file *f, char __user *buf, size_t count, 57 - loff_t *offp) 58 - { 59 - struct fmc_device *fmc = f->private_data; 60 - unsigned long addr; 61 - uint32_t val; 62 - 63 - if (count < sizeof(val)) 64 - return -EINVAL; 65 - count = sizeof(val); 66 - 67 - addr = *offp; 68 - if (addr > fmc->memlen) 69 - return -ESPIPE; /* Illegal seek */ 70 - val = fmc_readl(fmc, addr); 71 - if (copy_to_user(buf, &val, count)) 72 - return -EFAULT; 73 - *offp += count; 74 - return count; 75 - } 76 - 77 - static ssize_t fc_write(struct file *f, const char __user *buf, size_t count, 78 - loff_t *offp) 79 - { 80 - struct fmc_device *fmc = f->private_data; 81 - unsigned long addr; 82 - uint32_t val; 83 - 84 - if (count < sizeof(val)) 85 - return -EINVAL; 86 - count = sizeof(val); 87 - 88 - addr = *offp; 89 - if (addr > fmc->memlen) 90 - return -ESPIPE; /* Illegal seek */ 91 - if (copy_from_user(&val, buf, count)) 92 - return -EFAULT; 93 - fmc_writel(fmc, val, addr); 94 - *offp += count; 95 - return count; 96 - } 97 - 98 - static const struct file_operations fc_fops = { 99 - .owner = THIS_MODULE, 100 - .open = fc_open, 101 - .release = fc_release, 102 - .llseek = generic_file_llseek, 103 - .read = fc_read, 104 - .write = fc_write, 105 - }; 106 - 107 - 108 - /* Device part .. */ 109 - static int fc_probe(struct fmc_device *fmc); 110 - static int fc_remove(struct fmc_device *fmc); 111 - 112 - static struct fmc_driver fc_drv = { 113 - .version = FMC_VERSION, 114 - .driver.name = KBUILD_MODNAME, 115 - .probe = fc_probe, 116 - .remove = fc_remove, 117 - /* no table: we want to match everything */ 118 - }; 119 - 120 - /* We accept the generic busid parameter */ 121 - FMC_PARAM_BUSID(fc_drv); 122 - 123 - /* probe and remove must allocate and release a misc device */ 124 - static int fc_probe(struct fmc_device *fmc) 125 - { 126 - int ret; 127 - int index = 0; 128 - 129 - struct fc_instance *fc; 130 - 131 - index = fmc_validate(fmc, &fc_drv); 132 - if (index < 0) 133 - return -EINVAL; /* not our device: invalid */ 134 - 135 - /* Create a char device: we want to create it anew */ 136 - fc = kzalloc(sizeof(*fc), GFP_KERNEL); 137 - if (!fc) 138 - return -ENOMEM; 139 - fc->fmc = fmc; 140 - fc->misc.minor = MISC_DYNAMIC_MINOR; 141 - fc->misc.fops = &fc_fops; 142 - fc->misc.name = kstrdup(dev_name(&fmc->dev), GFP_KERNEL); 143 - 144 - ret = misc_register(&fc->misc); 145 - if (ret < 0) 146 - goto out; 147 - spin_lock(&fc_lock); 148 - list_add(&fc->list, &fc_devices); 149 - spin_unlock(&fc_lock); 150 - dev_info(&fc->fmc->dev, "Created misc device \"%s\"\n", 151 - fc->misc.name); 152 - return 0; 153 - 154 - out: 155 - kfree(fc->misc.name); 156 - kfree(fc); 157 - return ret; 158 - } 159 - 160 - static int fc_remove(struct fmc_device *fmc) 161 - { 162 - struct fc_instance *fc; 163 - 164 - list_for_each_entry(fc, &fc_devices, list) 165 - if (fc->fmc == fmc) 166 - break; 167 - if (fc->fmc != fmc) { 168 - dev_err(&fmc->dev, "remove called but not found\n"); 169 - return -ENODEV; 170 - } 171 - 172 - spin_lock(&fc_lock); 173 - list_del(&fc->list); 174 - spin_unlock(&fc_lock); 175 - misc_deregister(&fc->misc); 176 - kfree(fc->misc.name); 177 - kfree(fc); 178 - 179 - return 0; 180 - } 181 - 182 - 183 - static int fc_init(void) 184 - { 185 - int ret; 186 - 187 - ret = fmc_driver_register(&fc_drv); 188 - return ret; 189 - } 190 - 191 - static void fc_exit(void) 192 - { 193 - fmc_driver_unregister(&fc_drv); 194 - } 195 - 196 - module_init(fc_init); 197 - module_exit(fc_exit); 198 - 199 - MODULE_LICENSE("GPL");
-388
drivers/fmc/fmc-core.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Copyright (C) 2012 CERN (www.cern.ch) 4 - * Author: Alessandro Rubini <rubini@gnudd.com> 5 - * 6 - * This work is part of the White Rabbit project, a research effort led 7 - * by CERN, the European Institute for Nuclear Research. 8 - */ 9 - #include <linux/kernel.h> 10 - #include <linux/module.h> 11 - #include <linux/slab.h> 12 - #include <linux/init.h> 13 - #include <linux/device.h> 14 - #include <linux/fmc.h> 15 - #include <linux/fmc-sdb.h> 16 - 17 - #include "fmc-private.h" 18 - 19 - static int fmc_check_version(unsigned long version, const char *name) 20 - { 21 - if (__FMC_MAJOR(version) != FMC_MAJOR) { 22 - pr_err("%s: \"%s\" has wrong major (has %li, expected %i)\n", 23 - __func__, name, __FMC_MAJOR(version), FMC_MAJOR); 24 - return -EINVAL; 25 - } 26 - 27 - if (__FMC_MINOR(version) != FMC_MINOR) 28 - pr_info("%s: \"%s\" has wrong minor (has %li, expected %i)\n", 29 - __func__, name, __FMC_MINOR(version), FMC_MINOR); 30 - return 0; 31 - } 32 - 33 - static int fmc_uevent(struct device *dev, struct kobj_uevent_env *env) 34 - { 35 - /* struct fmc_device *fdev = to_fmc_device(dev); */ 36 - 37 - /* FIXME: The MODALIAS */ 38 - add_uevent_var(env, "MODALIAS=%s", "fmc"); 39 - return 0; 40 - } 41 - 42 - static int fmc_probe(struct device *dev) 43 - { 44 - struct fmc_driver *fdrv = to_fmc_driver(dev->driver); 45 - struct fmc_device *fdev = to_fmc_device(dev); 46 - 47 - return fdrv->probe(fdev); 48 - } 49 - 50 - static int fmc_remove(struct device *dev) 51 - { 52 - struct fmc_driver *fdrv = to_fmc_driver(dev->driver); 53 - struct fmc_device *fdev = to_fmc_device(dev); 54 - 55 - return fdrv->remove(fdev); 56 - } 57 - 58 - static void fmc_shutdown(struct device *dev) 59 - { 60 - /* not implemented but mandatory */ 61 - } 62 - 63 - static struct bus_type fmc_bus_type = { 64 - .name = "fmc", 65 - .match = fmc_match, 66 - .uevent = fmc_uevent, 67 - .probe = fmc_probe, 68 - .remove = fmc_remove, 69 - .shutdown = fmc_shutdown, 70 - }; 71 - 72 - static void fmc_release(struct device *dev) 73 - { 74 - struct fmc_device *fmc = container_of(dev, struct fmc_device, dev); 75 - 76 - kfree(fmc); 77 - } 78 - 79 - /* 80 - * The eeprom is exported in sysfs, through a binary attribute 81 - */ 82 - 83 - static ssize_t fmc_read_eeprom(struct file *file, struct kobject *kobj, 84 - struct bin_attribute *bin_attr, 85 - char *buf, loff_t off, size_t count) 86 - { 87 - struct device *dev; 88 - struct fmc_device *fmc; 89 - int eelen; 90 - 91 - dev = container_of(kobj, struct device, kobj); 92 - fmc = container_of(dev, struct fmc_device, dev); 93 - eelen = fmc->eeprom_len; 94 - if (off > eelen) 95 - return -ESPIPE; 96 - if (off == eelen) 97 - return 0; /* EOF */ 98 - if (off + count > eelen) 99 - count = eelen - off; 100 - memcpy(buf, fmc->eeprom + off, count); 101 - return count; 102 - } 103 - 104 - static ssize_t fmc_write_eeprom(struct file *file, struct kobject *kobj, 105 - struct bin_attribute *bin_attr, 106 - char *buf, loff_t off, size_t count) 107 - { 108 - struct device *dev; 109 - struct fmc_device *fmc; 110 - 111 - dev = container_of(kobj, struct device, kobj); 112 - fmc = container_of(dev, struct fmc_device, dev); 113 - return fmc->op->write_ee(fmc, off, buf, count); 114 - } 115 - 116 - static struct bin_attribute fmc_eeprom_attr = { 117 - .attr = { .name = "eeprom", .mode = S_IRUGO | S_IWUSR, }, 118 - .size = 8192, /* more or less standard */ 119 - .read = fmc_read_eeprom, 120 - .write = fmc_write_eeprom, 121 - }; 122 - 123 - int fmc_irq_request(struct fmc_device *fmc, irq_handler_t h, 124 - char *name, int flags) 125 - { 126 - if (fmc->op->irq_request) 127 - return fmc->op->irq_request(fmc, h, name, flags); 128 - return -EPERM; 129 - } 130 - EXPORT_SYMBOL(fmc_irq_request); 131 - 132 - void fmc_irq_free(struct fmc_device *fmc) 133 - { 134 - if (fmc->op->irq_free) 135 - fmc->op->irq_free(fmc); 136 - } 137 - EXPORT_SYMBOL(fmc_irq_free); 138 - 139 - void fmc_irq_ack(struct fmc_device *fmc) 140 - { 141 - if (likely(fmc->op->irq_ack)) 142 - fmc->op->irq_ack(fmc); 143 - } 144 - EXPORT_SYMBOL(fmc_irq_ack); 145 - 146 - int fmc_validate(struct fmc_device *fmc, struct fmc_driver *drv) 147 - { 148 - if (fmc->op->validate) 149 - return fmc->op->validate(fmc, drv); 150 - return -EPERM; 151 - } 152 - EXPORT_SYMBOL(fmc_validate); 153 - 154 - int fmc_gpio_config(struct fmc_device *fmc, struct fmc_gpio *gpio, int ngpio) 155 - { 156 - if (fmc->op->gpio_config) 157 - return fmc->op->gpio_config(fmc, gpio, ngpio); 158 - return -EPERM; 159 - } 160 - EXPORT_SYMBOL(fmc_gpio_config); 161 - 162 - int fmc_read_ee(struct fmc_device *fmc, int pos, void *d, int l) 163 - { 164 - if (fmc->op->read_ee) 165 - return fmc->op->read_ee(fmc, pos, d, l); 166 - return -EPERM; 167 - } 168 - EXPORT_SYMBOL(fmc_read_ee); 169 - 170 - int fmc_write_ee(struct fmc_device *fmc, int pos, const void *d, int l) 171 - { 172 - if (fmc->op->write_ee) 173 - return fmc->op->write_ee(fmc, pos, d, l); 174 - return -EPERM; 175 - } 176 - EXPORT_SYMBOL(fmc_write_ee); 177 - 178 - /* 179 - * Functions for client modules follow 180 - */ 181 - 182 - int fmc_driver_register(struct fmc_driver *drv) 183 - { 184 - if (fmc_check_version(drv->version, drv->driver.name)) 185 - return -EINVAL; 186 - drv->driver.bus = &fmc_bus_type; 187 - return driver_register(&drv->driver); 188 - } 189 - EXPORT_SYMBOL(fmc_driver_register); 190 - 191 - void fmc_driver_unregister(struct fmc_driver *drv) 192 - { 193 - driver_unregister(&drv->driver); 194 - } 195 - EXPORT_SYMBOL(fmc_driver_unregister); 196 - 197 - /* 198 - * When a device set is registered, all eeproms must be read 199 - * and all FRUs must be parsed 200 - */ 201 - int fmc_device_register_n_gw(struct fmc_device **devs, int n, 202 - struct fmc_gateware *gw) 203 - { 204 - struct fmc_device *fmc, **devarray; 205 - uint32_t device_id; 206 - int i, ret = 0; 207 - 208 - if (n < 1) 209 - return 0; 210 - 211 - /* Check the version of the first data structure (function prints) */ 212 - if (fmc_check_version(devs[0]->version, devs[0]->carrier_name)) 213 - return -EINVAL; 214 - 215 - devarray = kmemdup(devs, n * sizeof(*devs), GFP_KERNEL); 216 - if (!devarray) 217 - return -ENOMEM; 218 - 219 - /* Make all other checks before continuing, for all devices */ 220 - for (i = 0; i < n; i++) { 221 - fmc = devarray[i]; 222 - if (!fmc->hwdev) { 223 - pr_err("%s: device nr. %i has no hwdev pointer\n", 224 - __func__, i); 225 - ret = -EINVAL; 226 - break; 227 - } 228 - if (fmc->flags & FMC_DEVICE_NO_MEZZANINE) { 229 - dev_info(fmc->hwdev, "absent mezzanine in slot %d\n", 230 - fmc->slot_id); 231 - continue; 232 - } 233 - if (!fmc->eeprom) { 234 - dev_err(fmc->hwdev, "no eeprom provided for slot %i\n", 235 - fmc->slot_id); 236 - ret = -EINVAL; 237 - } 238 - if (!fmc->eeprom_addr) { 239 - dev_err(fmc->hwdev, "no eeprom_addr for slot %i\n", 240 - fmc->slot_id); 241 - ret = -EINVAL; 242 - } 243 - if (!fmc->carrier_name || !fmc->carrier_data || 244 - !fmc->device_id) { 245 - dev_err(fmc->hwdev, 246 - "device nr %i: carrier name, " 247 - "data or dev_id not set\n", i); 248 - ret = -EINVAL; 249 - } 250 - if (ret) 251 - break; 252 - 253 - } 254 - if (ret) { 255 - kfree(devarray); 256 - return ret; 257 - } 258 - 259 - /* Validation is ok. Now init and register the devices */ 260 - for (i = 0; i < n; i++) { 261 - fmc = devarray[i]; 262 - 263 - fmc->nr_slots = n; /* each slot must know how many are there */ 264 - fmc->devarray = devarray; 265 - 266 - device_initialize(&fmc->dev); 267 - fmc->dev.release = fmc_release; 268 - fmc->dev.parent = fmc->hwdev; 269 - 270 - /* Fill the identification stuff (may fail) */ 271 - fmc_fill_id_info(fmc); 272 - 273 - fmc->dev.bus = &fmc_bus_type; 274 - 275 - /* Name from mezzanine info or carrier info. Or 0,1,2.. */ 276 - device_id = fmc->device_id; 277 - if (!fmc->mezzanine_name) 278 - dev_set_name(&fmc->dev, "fmc-%04x", device_id); 279 - else 280 - dev_set_name(&fmc->dev, "%s-%04x", fmc->mezzanine_name, 281 - device_id); 282 - 283 - if (gw) { 284 - /* 285 - * The carrier already know the bitstream to load 286 - * for this set of FMC mezzanines. 287 - */ 288 - ret = fmc->op->reprogram_raw(fmc, NULL, 289 - gw->bitstream, gw->len); 290 - if (ret) { 291 - dev_warn(fmc->hwdev, 292 - "Invalid gateware for FMC mezzanine\n"); 293 - goto out; 294 - } 295 - } 296 - 297 - ret = device_add(&fmc->dev); 298 - if (ret < 0) { 299 - dev_err(fmc->hwdev, "Slot %i: Failed in registering " 300 - "\"%s\"\n", fmc->slot_id, fmc->dev.kobj.name); 301 - goto out; 302 - } 303 - ret = sysfs_create_bin_file(&fmc->dev.kobj, &fmc_eeprom_attr); 304 - if (ret < 0) { 305 - dev_err(&fmc->dev, "Failed in registering eeprom\n"); 306 - goto out1; 307 - } 308 - /* This device went well, give information to the user */ 309 - fmc_dump_eeprom(fmc); 310 - fmc_debug_init(fmc); 311 - } 312 - return 0; 313 - 314 - out1: 315 - device_del(&fmc->dev); 316 - out: 317 - kfree(devarray); 318 - for (i--; i >= 0; i--) { 319 - fmc_debug_exit(devs[i]); 320 - sysfs_remove_bin_file(&devs[i]->dev.kobj, &fmc_eeprom_attr); 321 - device_del(&devs[i]->dev); 322 - fmc_free_id_info(devs[i]); 323 - put_device(&devs[i]->dev); 324 - } 325 - return ret; 326 - 327 - } 328 - EXPORT_SYMBOL(fmc_device_register_n_gw); 329 - 330 - int fmc_device_register_n(struct fmc_device **devs, int n) 331 - { 332 - return fmc_device_register_n_gw(devs, n, NULL); 333 - } 334 - EXPORT_SYMBOL(fmc_device_register_n); 335 - 336 - int fmc_device_register_gw(struct fmc_device *fmc, struct fmc_gateware *gw) 337 - { 338 - return fmc_device_register_n_gw(&fmc, 1, gw); 339 - } 340 - EXPORT_SYMBOL(fmc_device_register_gw); 341 - 342 - int fmc_device_register(struct fmc_device *fmc) 343 - { 344 - return fmc_device_register_n(&fmc, 1); 345 - } 346 - EXPORT_SYMBOL(fmc_device_register); 347 - 348 - void fmc_device_unregister_n(struct fmc_device **devs, int n) 349 - { 350 - int i; 351 - 352 - if (n < 1) 353 - return; 354 - 355 - /* Free devarray first, not used by the later loop */ 356 - kfree(devs[0]->devarray); 357 - 358 - for (i = 0; i < n; i++) { 359 - fmc_debug_exit(devs[i]); 360 - sysfs_remove_bin_file(&devs[i]->dev.kobj, &fmc_eeprom_attr); 361 - device_del(&devs[i]->dev); 362 - fmc_free_id_info(devs[i]); 363 - put_device(&devs[i]->dev); 364 - } 365 - } 366 - EXPORT_SYMBOL(fmc_device_unregister_n); 367 - 368 - void fmc_device_unregister(struct fmc_device *fmc) 369 - { 370 - fmc_device_unregister_n(&fmc, 1); 371 - } 372 - EXPORT_SYMBOL(fmc_device_unregister); 373 - 374 - /* Init and exit are trivial */ 375 - static int fmc_init(void) 376 - { 377 - return bus_register(&fmc_bus_type); 378 - } 379 - 380 - static void fmc_exit(void) 381 - { 382 - bus_unregister(&fmc_bus_type); 383 - } 384 - 385 - module_init(fmc_init); 386 - module_exit(fmc_exit); 387 - 388 - MODULE_LICENSE("GPL");
-172
drivers/fmc/fmc-debug.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Copyright (C) 2015 CERN (www.cern.ch) 4 - * Author: Federico Vaga <federico.vaga@cern.ch> 5 - */ 6 - 7 - #include <linux/module.h> 8 - #include <linux/device.h> 9 - #include <linux/init.h> 10 - #include <linux/fs.h> 11 - #include <linux/debugfs.h> 12 - #include <linux/seq_file.h> 13 - #include <asm/byteorder.h> 14 - 15 - #include <linux/fmc.h> 16 - #include <linux/sdb.h> 17 - #include <linux/fmc-sdb.h> 18 - 19 - #define FMC_DBG_SDB_DUMP "dump_sdb" 20 - 21 - static char *__strip_trailing_space(char *buf, char *str, int len) 22 - { 23 - int i = len - 1; 24 - 25 - memcpy(buf, str, len); 26 - buf[len] = '\0'; 27 - while (i >= 0 && buf[i] == ' ') 28 - buf[i--] = '\0'; 29 - return buf; 30 - } 31 - 32 - #define __sdb_string(buf, field) ({ \ 33 - BUILD_BUG_ON(sizeof(buf) < sizeof(field)); \ 34 - __strip_trailing_space(buf, (void *)(field), sizeof(field)); \ 35 - }) 36 - 37 - /** 38 - * We do not check seq_printf() errors because we want to see things in any case 39 - */ 40 - static void fmc_sdb_dump_recursive(struct fmc_device *fmc, struct seq_file *s, 41 - const struct sdb_array *arr) 42 - { 43 - unsigned long base = arr->baseaddr; 44 - int i, j, n = arr->len, level = arr->level; 45 - char tmp[64]; 46 - 47 - for (i = 0; i < n; i++) { 48 - union sdb_record *r; 49 - struct sdb_product *p; 50 - struct sdb_component *c; 51 - 52 - r = &arr->record[i]; 53 - c = &r->dev.sdb_component; 54 - p = &c->product; 55 - 56 - for (j = 0; j < level; j++) 57 - seq_printf(s, " "); 58 - switch (r->empty.record_type) { 59 - case sdb_type_interconnect: 60 - seq_printf(s, "%08llx:%08x %.19s\n", 61 - __be64_to_cpu(p->vendor_id), 62 - __be32_to_cpu(p->device_id), 63 - p->name); 64 - break; 65 - case sdb_type_device: 66 - seq_printf(s, "%08llx:%08x %.19s (%08llx-%08llx)\n", 67 - __be64_to_cpu(p->vendor_id), 68 - __be32_to_cpu(p->device_id), 69 - p->name, 70 - __be64_to_cpu(c->addr_first) + base, 71 - __be64_to_cpu(c->addr_last) + base); 72 - break; 73 - case sdb_type_bridge: 74 - seq_printf(s, "%08llx:%08x %.19s (bridge: %08llx)\n", 75 - __be64_to_cpu(p->vendor_id), 76 - __be32_to_cpu(p->device_id), 77 - p->name, 78 - __be64_to_cpu(c->addr_first) + base); 79 - if (IS_ERR(arr->subtree[i])) { 80 - seq_printf(s, "SDB: (bridge error %li)\n", 81 - PTR_ERR(arr->subtree[i])); 82 - break; 83 - } 84 - fmc_sdb_dump_recursive(fmc, s, arr->subtree[i]); 85 - break; 86 - case sdb_type_integration: 87 - seq_printf(s, "integration\n"); 88 - break; 89 - case sdb_type_repo_url: 90 - seq_printf(s, "Synthesis repository: %s\n", 91 - __sdb_string(tmp, r->repo_url.repo_url)); 92 - break; 93 - case sdb_type_synthesis: 94 - seq_printf(s, "Bitstream '%s' ", 95 - __sdb_string(tmp, r->synthesis.syn_name)); 96 - seq_printf(s, "synthesized %08x by %s ", 97 - __be32_to_cpu(r->synthesis.date), 98 - __sdb_string(tmp, r->synthesis.user_name)); 99 - seq_printf(s, "(%s version %x), ", 100 - __sdb_string(tmp, r->synthesis.tool_name), 101 - __be32_to_cpu(r->synthesis.tool_version)); 102 - seq_printf(s, "commit %pm\n", 103 - r->synthesis.commit_id); 104 - break; 105 - case sdb_type_empty: 106 - seq_printf(s, "empty\n"); 107 - break; 108 - default: 109 - seq_printf(s, "UNKNOWN TYPE 0x%02x\n", 110 - r->empty.record_type); 111 - break; 112 - } 113 - } 114 - } 115 - 116 - static int fmc_sdb_dump(struct seq_file *s, void *offset) 117 - { 118 - struct fmc_device *fmc = s->private; 119 - 120 - if (!fmc->sdb) { 121 - seq_printf(s, "no SDB information\n"); 122 - return 0; 123 - } 124 - 125 - seq_printf(s, "FMC: %s (%s), slot %i, device %s\n", dev_name(fmc->hwdev), 126 - fmc->carrier_name, fmc->slot_id, dev_name(&fmc->dev)); 127 - /* Dump SDB information */ 128 - fmc_sdb_dump_recursive(fmc, s, fmc->sdb); 129 - 130 - return 0; 131 - } 132 - 133 - 134 - static int fmc_sdb_dump_open(struct inode *inode, struct file *file) 135 - { 136 - struct fmc_device *fmc = inode->i_private; 137 - 138 - return single_open(file, fmc_sdb_dump, fmc); 139 - } 140 - 141 - 142 - const struct file_operations fmc_dbgfs_sdb_dump = { 143 - .owner = THIS_MODULE, 144 - .open = fmc_sdb_dump_open, 145 - .read = seq_read, 146 - .llseek = seq_lseek, 147 - .release = single_release, 148 - }; 149 - 150 - int fmc_debug_init(struct fmc_device *fmc) 151 - { 152 - fmc->dbg_dir = debugfs_create_dir(dev_name(&fmc->dev), NULL); 153 - if (IS_ERR_OR_NULL(fmc->dbg_dir)) { 154 - pr_err("FMC: Cannot create debugfs\n"); 155 - return PTR_ERR(fmc->dbg_dir); 156 - } 157 - 158 - fmc->dbg_sdb_dump = debugfs_create_file(FMC_DBG_SDB_DUMP, 0444, 159 - fmc->dbg_dir, fmc, 160 - &fmc_dbgfs_sdb_dump); 161 - if (IS_ERR_OR_NULL(fmc->dbg_sdb_dump)) 162 - pr_err("FMC: Cannot create debugfs file %s\n", 163 - FMC_DBG_SDB_DUMP); 164 - 165 - return 0; 166 - } 167 - 168 - void fmc_debug_exit(struct fmc_device *fmc) 169 - { 170 - if (fmc->dbg_dir) 171 - debugfs_remove_recursive(fmc->dbg_dir); 172 - }
-58
drivers/fmc/fmc-dump.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Copyright (C) 2013 CERN (www.cern.ch) 4 - * Author: Alessandro Rubini <rubini@gnudd.com> 5 - * 6 - * This work is part of the White Rabbit project, a research effort led 7 - * by CERN, the European Institute for Nuclear Research. 8 - */ 9 - #include <linux/kernel.h> 10 - #include <linux/moduleparam.h> 11 - #include <linux/device.h> 12 - #include <linux/fmc.h> 13 - #include <linux/fmc-sdb.h> 14 - 15 - static int fmc_must_dump_eeprom; 16 - module_param_named(dump_eeprom, fmc_must_dump_eeprom, int, 0644); 17 - 18 - #define LINELEN 16 19 - 20 - /* Dumping 8k takes oh so much: avoid duplicate lines */ 21 - static const uint8_t *dump_line(int addr, const uint8_t *line, 22 - const uint8_t *prev) 23 - { 24 - int i; 25 - 26 - if (!prev || memcmp(line, prev, LINELEN)) { 27 - pr_info("%04x: ", addr); 28 - for (i = 0; i < LINELEN; ) { 29 - printk(KERN_CONT "%02x", line[i]); 30 - i++; 31 - printk(i & 3 ? " " : i & (LINELEN - 1) ? " " : "\n"); 32 - } 33 - return line; 34 - } 35 - /* repeated line */ 36 - if (line == prev + LINELEN) 37 - pr_info("[...]\n"); 38 - return prev; 39 - } 40 - 41 - void fmc_dump_eeprom(const struct fmc_device *fmc) 42 - { 43 - const uint8_t *line, *prev; 44 - int i; 45 - 46 - if (!fmc_must_dump_eeprom) 47 - return; 48 - 49 - pr_info("FMC: %s (%s), slot %i, device %s\n", dev_name(fmc->hwdev), 50 - fmc->carrier_name, fmc->slot_id, dev_name(&fmc->dev)); 51 - pr_info("FMC: dumping eeprom 0x%x (%i) bytes\n", fmc->eeprom_len, 52 - fmc->eeprom_len); 53 - 54 - line = fmc->eeprom; 55 - prev = NULL; 56 - for (i = 0; i < fmc->eeprom_len; i += LINELEN, line += LINELEN) 57 - prev = dump_line(i, line, prev); 58 - }
-355
drivers/fmc/fmc-fakedev.c
··· 1 - /* 2 - * Copyright (C) 2012 CERN (www.cern.ch) 3 - * Author: Alessandro Rubini <rubini@gnudd.com> 4 - * 5 - * Permission to use, copy, modify, and/or distribute this software for any 6 - * purpose with or without fee is hereby granted, provided that the above 7 - * copyright notice and this permission notice appear in all copies. 8 - * 9 - * The software is provided "as is"; the copyright holders disclaim 10 - * all warranties and liabilities, to the extent permitted by 11 - * applicable law. 12 - */ 13 - #include <linux/module.h> 14 - #include <linux/init.h> 15 - #include <linux/string.h> 16 - #include <linux/device.h> 17 - #include <linux/slab.h> 18 - #include <linux/firmware.h> 19 - #include <linux/workqueue.h> 20 - #include <linux/err.h> 21 - #include <linux/fmc.h> 22 - 23 - #define FF_EEPROM_SIZE 8192 /* The standard eeprom size */ 24 - #define FF_MAX_MEZZANINES 4 /* Fakes a multi-mezzanine carrier */ 25 - 26 - /* The user can pass up to 4 names of eeprom images to load */ 27 - static char *ff_eeprom[FF_MAX_MEZZANINES]; 28 - static int ff_nr_eeprom; 29 - module_param_array_named(eeprom, ff_eeprom, charp, &ff_nr_eeprom, 0444); 30 - 31 - /* The user can ask for a multi-mezzanine carrier, with the default eeprom */ 32 - static int ff_nr_dev = 1; 33 - module_param_named(ndev, ff_nr_dev, int, 0444); 34 - 35 - 36 - /* Lazily, don't support the "standard" module parameters */ 37 - 38 - /* 39 - * Eeprom built from these commands: 40 - 41 - ../fru-generator -v fake-vendor -n fake-design-for-testing \ 42 - -s 01234 -p none > IPMI-FRU 43 - 44 - gensdbfs . ../fake-eeprom.bin 45 - */ 46 - static char ff_eeimg[FF_MAX_MEZZANINES][FF_EEPROM_SIZE] = { 47 - { 48 - 0x01, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x00, 0xf2, 0x01, 0x0b, 0x00, 0xb2, 49 - 0x86, 0x87, 0xcb, 0x66, 0x61, 0x6b, 0x65, 0x2d, 0x76, 0x65, 0x6e, 0x64, 50 - 0x6f, 0x72, 0xd7, 0x66, 0x61, 0x6b, 0x65, 0x2d, 0x64, 0x65, 0x73, 0x69, 51 - 0x67, 0x6e, 0x2d, 0x66, 0x6f, 0x72, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x69, 52 - 0x6e, 0x67, 0xc5, 0x30, 0x31, 0x32, 0x33, 0x34, 0xc4, 0x6e, 0x6f, 0x6e, 53 - 0x65, 0xda, 0x32, 0x30, 0x31, 0x32, 0x2d, 0x31, 0x31, 0x2d, 0x31, 0x39, 54 - 0x20, 0x32, 0x32, 0x3a, 0x34, 0x32, 0x3a, 0x33, 0x30, 0x2e, 0x30, 0x37, 55 - 0x34, 0x30, 0x35, 0x35, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 56 - 0x02, 0x02, 0x0d, 0xf7, 0xf8, 0x02, 0xb0, 0x04, 0x74, 0x04, 0xec, 0x04, 57 - 0x00, 0x00, 0x00, 0x00, 0xe8, 0x03, 0x02, 0x02, 0x0d, 0x5c, 0x93, 0x01, 58 - 0x4a, 0x01, 0x39, 0x01, 0x5a, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x0b, 59 - 0x02, 0x02, 0x0d, 0x63, 0x8c, 0x00, 0xfa, 0x00, 0xed, 0x00, 0x06, 0x01, 60 - 0x00, 0x00, 0x00, 0x00, 0xa0, 0x0f, 0x01, 0x02, 0x0d, 0xfb, 0xf5, 0x05, 61 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62 - 0x01, 0x02, 0x0d, 0xfc, 0xf4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 63 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0d, 0xfd, 0xf3, 0x03, 64 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 65 - 0xfa, 0x82, 0x0b, 0xea, 0x8f, 0xa2, 0x12, 0x00, 0x00, 0x1e, 0x44, 0x00, 66 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 67 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 68 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 69 - 0x00, 0x00, 0x00, 0x00, 0x53, 0x44, 0x42, 0x2d, 0x00, 0x03, 0x01, 0x01, 70 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 71 - 0x00, 0x00, 0x01, 0xc4, 0x46, 0x69, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 72 - 0x2e, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 73 - 0x2e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 74 - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 75 - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 76 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc4, 0x46, 0x69, 0x6c, 0x65, 77 - 0x44, 0x61, 0x74, 0x61, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x00, 0x00, 0x01, 78 - 0x00, 0x00, 0x00, 0x00, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x20, 0x20, 0x20, 79 - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 80 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 81 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdf, 82 - 0x46, 0x69, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x49, 0x50, 0x4d, 0x49, 83 - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x49, 0x50, 0x4d, 0x49, 84 - 0x2d, 0x46, 0x52, 0x55, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 85 - 0x20, 0x20, 0x20, 0x01, 0x66, 0x61, 0x6b, 0x65, 0x0a, 86 - }, 87 - }; 88 - 89 - struct ff_dev { 90 - struct fmc_device *fmc[FF_MAX_MEZZANINES]; 91 - struct device dev; 92 - }; 93 - 94 - static struct ff_dev *ff_current_dev; /* We have 1 carrier, 1 slot */ 95 - 96 - static int ff_reprogram(struct fmc_device *fmc, struct fmc_driver *drv, 97 - char *gw) 98 - { 99 - const struct firmware *fw; 100 - int ret; 101 - 102 - if (!gw) { 103 - /* program golden: success */ 104 - fmc->flags &= ~FMC_DEVICE_HAS_CUSTOM; 105 - fmc->flags |= FMC_DEVICE_HAS_GOLDEN; 106 - return 0; 107 - } 108 - 109 - dev_info(&fmc->dev, "reprogramming with %s\n", gw); 110 - ret = request_firmware(&fw, gw, &fmc->dev); 111 - if (ret < 0) { 112 - dev_warn(&fmc->dev, "request firmware \"%s\": error %i\n", 113 - gw, ret); 114 - goto out; 115 - } 116 - fmc->flags &= ~FMC_DEVICE_HAS_GOLDEN; 117 - fmc->flags |= FMC_DEVICE_HAS_CUSTOM; 118 - 119 - out: 120 - release_firmware(fw); 121 - return ret; 122 - } 123 - 124 - static int ff_irq_request(struct fmc_device *fmc, irq_handler_t handler, 125 - char *name, int flags) 126 - { 127 - return -EOPNOTSUPP; 128 - } 129 - 130 - /* FIXME: should also have some fake FMC GPIO mapping */ 131 - 132 - 133 - /* 134 - * This work function is called when we changed the eeprom. It removes the 135 - * current fmc device and registers a new one, with different identifiers. 136 - */ 137 - static struct ff_dev *ff_dev_create(void); /* defined later */ 138 - 139 - static void ff_work_fn(struct work_struct *work) 140 - { 141 - struct ff_dev *ff = ff_current_dev; 142 - int ret; 143 - 144 - fmc_device_unregister_n(ff->fmc, ff_nr_dev); 145 - device_unregister(&ff->dev); 146 - ff_current_dev = NULL; 147 - 148 - ff = ff_dev_create(); 149 - if (IS_ERR(ff)) { 150 - pr_warning("%s: can't re-create FMC devices\n", __func__); 151 - return; 152 - } 153 - ret = fmc_device_register_n(ff->fmc, ff_nr_dev); 154 - if (ret < 0) { 155 - dev_warn(&ff->dev, "can't re-register FMC devices\n"); 156 - device_unregister(&ff->dev); 157 - return; 158 - } 159 - 160 - ff_current_dev = ff; 161 - } 162 - 163 - static DECLARE_DELAYED_WORK(ff_work, ff_work_fn); 164 - 165 - 166 - /* low-level i2c */ 167 - static int ff_eeprom_read(struct fmc_device *fmc, uint32_t offset, 168 - void *buf, size_t size) 169 - { 170 - if (offset > FF_EEPROM_SIZE) 171 - return -EINVAL; 172 - if (offset + size > FF_EEPROM_SIZE) 173 - size = FF_EEPROM_SIZE - offset; 174 - memcpy(buf, fmc->eeprom + offset, size); 175 - return size; 176 - } 177 - 178 - static int ff_eeprom_write(struct fmc_device *fmc, uint32_t offset, 179 - const void *buf, size_t size) 180 - { 181 - if (offset > FF_EEPROM_SIZE) 182 - return -EINVAL; 183 - if (offset + size > FF_EEPROM_SIZE) 184 - size = FF_EEPROM_SIZE - offset; 185 - dev_info(&fmc->dev, "write_eeprom: offset %i, size %zi\n", 186 - (int)offset, size); 187 - memcpy(fmc->eeprom + offset, buf, size); 188 - schedule_delayed_work(&ff_work, HZ * 2); /* remove, replug, in 2s */ 189 - return size; 190 - } 191 - 192 - /* i2c operations for fmc */ 193 - static int ff_read_ee(struct fmc_device *fmc, int pos, void *data, int len) 194 - { 195 - if (!(fmc->flags & FMC_DEVICE_HAS_GOLDEN)) 196 - return -EOPNOTSUPP; 197 - return ff_eeprom_read(fmc, pos, data, len); 198 - } 199 - 200 - static int ff_write_ee(struct fmc_device *fmc, int pos, 201 - const void *data, int len) 202 - { 203 - if (!(fmc->flags & FMC_DEVICE_HAS_GOLDEN)) 204 - return -EOPNOTSUPP; 205 - return ff_eeprom_write(fmc, pos, data, len); 206 - } 207 - 208 - /* readl and writel do not do anything. Don't waste RAM with "base" */ 209 - static uint32_t ff_readl(struct fmc_device *fmc, int offset) 210 - { 211 - return 0; 212 - } 213 - 214 - static void ff_writel(struct fmc_device *fmc, uint32_t value, int offset) 215 - { 216 - return; 217 - } 218 - 219 - /* validate is useful so fmc-write-eeprom will not reprogram every 2 seconds */ 220 - static int ff_validate(struct fmc_device *fmc, struct fmc_driver *drv) 221 - { 222 - int i; 223 - 224 - if (!drv->busid_n) 225 - return 0; /* everyhing is valid */ 226 - for (i = 0; i < drv->busid_n; i++) 227 - if (drv->busid_val[i] == fmc->device_id) 228 - return i; 229 - return -ENOENT; 230 - } 231 - 232 - 233 - 234 - static struct fmc_operations ff_fmc_operations = { 235 - .read32 = ff_readl, 236 - .write32 = ff_writel, 237 - .reprogram = ff_reprogram, 238 - .irq_request = ff_irq_request, 239 - .read_ee = ff_read_ee, 240 - .write_ee = ff_write_ee, 241 - .validate = ff_validate, 242 - }; 243 - 244 - /* This device is kmalloced: release it */ 245 - static void ff_dev_release(struct device *dev) 246 - { 247 - struct ff_dev *ff = container_of(dev, struct ff_dev, dev); 248 - kfree(ff); 249 - } 250 - 251 - static struct fmc_device ff_template_fmc = { 252 - .version = FMC_VERSION, 253 - .owner = THIS_MODULE, 254 - .carrier_name = "fake-fmc-carrier", 255 - .device_id = 0xf001, /* fool */ 256 - .eeprom_len = sizeof(ff_eeimg[0]), 257 - .memlen = 0x1000, /* 4k, to show something */ 258 - .op = &ff_fmc_operations, 259 - .hwdev = NULL, /* filled at creation time */ 260 - .flags = FMC_DEVICE_HAS_GOLDEN, 261 - }; 262 - 263 - static struct ff_dev *ff_dev_create(void) 264 - { 265 - struct ff_dev *ff; 266 - struct fmc_device *fmc; 267 - int i, ret; 268 - 269 - ff = kzalloc(sizeof(*ff), GFP_KERNEL); 270 - if (!ff) 271 - return ERR_PTR(-ENOMEM); 272 - dev_set_name(&ff->dev, "fake-fmc-carrier"); 273 - ff->dev.release = ff_dev_release; 274 - 275 - ret = device_register(&ff->dev); 276 - if (ret < 0) { 277 - put_device(&ff->dev); 278 - return ERR_PTR(ret); 279 - } 280 - 281 - /* Create fmc structures that refer to this new "hw" device */ 282 - for (i = 0; i < ff_nr_dev; i++) { 283 - fmc = kmemdup(&ff_template_fmc, sizeof(ff_template_fmc), 284 - GFP_KERNEL); 285 - fmc->hwdev = &ff->dev; 286 - fmc->carrier_data = ff; 287 - fmc->nr_slots = ff_nr_dev; 288 - /* the following fields are different for each slot */ 289 - fmc->eeprom = ff_eeimg[i]; 290 - fmc->eeprom_addr = 0x50 + 2 * i; 291 - fmc->slot_id = i; 292 - ff->fmc[i] = fmc; 293 - /* increment the identifier, each must be different */ 294 - ff_template_fmc.device_id++; 295 - } 296 - return ff; 297 - } 298 - 299 - /* init and exit */ 300 - static int ff_init(void) 301 - { 302 - struct ff_dev *ff; 303 - const struct firmware *fw; 304 - int i, len, ret = 0; 305 - 306 - /* Replicate the default eeprom for the max number of mezzanines */ 307 - for (i = 1; i < FF_MAX_MEZZANINES; i++) 308 - memcpy(ff_eeimg[i], ff_eeimg[0], sizeof(ff_eeimg[0])); 309 - 310 - if (ff_nr_eeprom > ff_nr_dev) 311 - ff_nr_dev = ff_nr_eeprom; 312 - 313 - ff = ff_dev_create(); 314 - if (IS_ERR(ff)) 315 - return PTR_ERR(ff); 316 - 317 - /* If the user passed "eeprom=" as a parameter, fetch them */ 318 - for (i = 0; i < ff_nr_eeprom; i++) { 319 - if (!strlen(ff_eeprom[i])) 320 - continue; 321 - ret = request_firmware(&fw, ff_eeprom[i], &ff->dev); 322 - if (ret < 0) { 323 - dev_err(&ff->dev, "Mezzanine %i: can't load \"%s\" " 324 - "(error %i)\n", i, ff_eeprom[i], -ret); 325 - } else { 326 - len = min_t(size_t, fw->size, (size_t)FF_EEPROM_SIZE); 327 - memcpy(ff_eeimg[i], fw->data, len); 328 - release_firmware(fw); 329 - dev_info(&ff->dev, "Mezzanine %i: eeprom \"%s\"\n", i, 330 - ff_eeprom[i]); 331 - } 332 - } 333 - 334 - ret = fmc_device_register_n(ff->fmc, ff_nr_dev); 335 - if (ret) { 336 - device_unregister(&ff->dev); 337 - return ret; 338 - } 339 - ff_current_dev = ff; 340 - return ret; 341 - } 342 - 343 - static void ff_exit(void) 344 - { 345 - if (ff_current_dev) { 346 - fmc_device_unregister_n(ff_current_dev->fmc, ff_nr_dev); 347 - device_unregister(&ff_current_dev->dev); 348 - } 349 - cancel_delayed_work_sync(&ff_work); 350 - } 351 - 352 - module_init(ff_init); 353 - module_exit(ff_exit); 354 - 355 - MODULE_LICENSE("Dual BSD/GPL");
-113
drivers/fmc/fmc-match.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Copyright (C) 2012 CERN (www.cern.ch) 4 - * Author: Alessandro Rubini <rubini@gnudd.com> 5 - * 6 - * This work is part of the White Rabbit project, a research effort led 7 - * by CERN, the European Institute for Nuclear Research. 8 - */ 9 - #include <linux/kernel.h> 10 - #include <linux/slab.h> 11 - #include <linux/fmc.h> 12 - #include <linux/ipmi-fru.h> 13 - 14 - /* The fru parser is both user and kernel capable: it needs alloc */ 15 - void *fru_alloc(size_t size) 16 - { 17 - return kzalloc(size, GFP_KERNEL); 18 - } 19 - 20 - /* The actual match function */ 21 - int fmc_match(struct device *dev, struct device_driver *drv) 22 - { 23 - struct fmc_driver *fdrv = to_fmc_driver(drv); 24 - struct fmc_device *fdev = to_fmc_device(dev); 25 - struct fmc_fru_id *fid; 26 - int i, matched = 0; 27 - 28 - /* This currently only matches the EEPROM (FRU id) */ 29 - fid = fdrv->id_table.fru_id; 30 - if (!fid) { 31 - dev_warn(&fdev->dev, "Driver has no ID: matches all\n"); 32 - matched = 1; 33 - } else { 34 - if (!fdev->id.manufacturer || !fdev->id.product_name) 35 - return 0; /* the device has no FRU information */ 36 - for (i = 0; i < fdrv->id_table.fru_id_nr; i++, fid++) { 37 - if (fid->manufacturer && 38 - strcmp(fid->manufacturer, fdev->id.manufacturer)) 39 - continue; 40 - if (fid->product_name && 41 - strcmp(fid->product_name, fdev->id.product_name)) 42 - continue; 43 - matched = 1; 44 - break; 45 - } 46 - } 47 - 48 - /* FIXME: match SDB contents */ 49 - return matched; 50 - } 51 - 52 - /* This function creates ID info for a newly registered device */ 53 - int fmc_fill_id_info(struct fmc_device *fmc) 54 - { 55 - struct fru_common_header *h; 56 - struct fru_board_info_area *bia; 57 - int ret, allocated = 0; 58 - 59 - /* If we know the eeprom length, try to read it off the device */ 60 - if (fmc->eeprom_len && !fmc->eeprom) { 61 - fmc->eeprom = kzalloc(fmc->eeprom_len, GFP_KERNEL); 62 - if (!fmc->eeprom) 63 - return -ENOMEM; 64 - allocated = 1; 65 - ret = fmc_read_ee(fmc, 0, fmc->eeprom, fmc->eeprom_len); 66 - if (ret < 0) 67 - goto out; 68 - } 69 - 70 - /* If no eeprom, continue with other matches */ 71 - if (!fmc->eeprom) 72 - return 0; 73 - 74 - dev_info(fmc->hwdev, "mezzanine %i\n", fmc->slot_id); /* header */ 75 - 76 - /* So we have the eeprom: parse the FRU part (if any) */ 77 - h = (void *)fmc->eeprom; 78 - if (h->format != 1) { 79 - pr_info(" EEPROM has no FRU information\n"); 80 - goto out; 81 - } 82 - if (!fru_header_cksum_ok(h)) { 83 - pr_info(" FRU: wrong header checksum\n"); 84 - goto out; 85 - } 86 - bia = fru_get_board_area(h); 87 - if (!fru_bia_cksum_ok(bia)) { 88 - pr_info(" FRU: wrong board area checksum\n"); 89 - goto out; 90 - } 91 - fmc->id.manufacturer = fru_get_board_manufacturer(h); 92 - fmc->id.product_name = fru_get_product_name(h); 93 - pr_info(" Manufacturer: %s\n", fmc->id.manufacturer); 94 - pr_info(" Product name: %s\n", fmc->id.product_name); 95 - 96 - /* Create the short name (FIXME: look in sdb as well) */ 97 - fmc->mezzanine_name = kstrdup(fmc->id.product_name, GFP_KERNEL); 98 - 99 - out: 100 - if (allocated) { 101 - kfree(fmc->eeprom); 102 - fmc->eeprom = NULL; 103 - } 104 - return 0; /* no error: let other identification work */ 105 - } 106 - 107 - /* Some ID data is allocated using fru_alloc() above, so release it */ 108 - void fmc_free_id_info(struct fmc_device *fmc) 109 - { 110 - kfree(fmc->mezzanine_name); 111 - kfree(fmc->id.manufacturer); 112 - kfree(fmc->id.product_name); 113 - }
-8
drivers/fmc/fmc-private.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 - /* 3 - * Copyright (C) 2015 CERN (www.cern.ch) 4 - * Author: Federico Vaga <federico.vaga@cern.ch> 5 - */ 6 - 7 - extern int fmc_debug_init(struct fmc_device *fmc); 8 - extern void fmc_debug_exit(struct fmc_device *fmc);
-219
drivers/fmc/fmc-sdb.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Copyright (C) 2012 CERN (www.cern.ch) 4 - * Author: Alessandro Rubini <rubini@gnudd.com> 5 - * 6 - * This work is part of the White Rabbit project, a research effort led 7 - * by CERN, the European Institute for Nuclear Research. 8 - */ 9 - #include <linux/module.h> 10 - #include <linux/slab.h> 11 - #include <linux/fmc.h> 12 - #include <linux/sdb.h> 13 - #include <linux/err.h> 14 - #include <linux/fmc-sdb.h> 15 - #include <asm/byteorder.h> 16 - 17 - static uint32_t __sdb_rd(struct fmc_device *fmc, unsigned long address, 18 - int convert) 19 - { 20 - uint32_t res = fmc_readl(fmc, address); 21 - if (convert) 22 - return __be32_to_cpu(res); 23 - return res; 24 - } 25 - 26 - static struct sdb_array *__fmc_scan_sdb_tree(struct fmc_device *fmc, 27 - unsigned long sdb_addr, 28 - unsigned long reg_base, int level) 29 - { 30 - uint32_t onew; 31 - int i, j, n, convert = 0; 32 - struct sdb_array *arr, *sub; 33 - 34 - onew = fmc_readl(fmc, sdb_addr); 35 - if (onew == SDB_MAGIC) { 36 - /* Uh! If we are little-endian, we must convert */ 37 - if (SDB_MAGIC != __be32_to_cpu(SDB_MAGIC)) 38 - convert = 1; 39 - } else if (onew == __be32_to_cpu(SDB_MAGIC)) { 40 - /* ok, don't convert */ 41 - } else { 42 - return ERR_PTR(-ENOENT); 43 - } 44 - /* So, the magic was there: get the count from offset 4*/ 45 - onew = __sdb_rd(fmc, sdb_addr + 4, convert); 46 - n = __be16_to_cpu(*(uint16_t *)&onew); 47 - arr = kzalloc(sizeof(*arr), GFP_KERNEL); 48 - if (!arr) 49 - return ERR_PTR(-ENOMEM); 50 - arr->record = kcalloc(n, sizeof(arr->record[0]), GFP_KERNEL); 51 - arr->subtree = kcalloc(n, sizeof(arr->subtree[0]), GFP_KERNEL); 52 - if (!arr->record || !arr->subtree) { 53 - kfree(arr->record); 54 - kfree(arr->subtree); 55 - kfree(arr); 56 - return ERR_PTR(-ENOMEM); 57 - } 58 - 59 - arr->len = n; 60 - arr->level = level; 61 - arr->fmc = fmc; 62 - for (i = 0; i < n; i++) { 63 - union sdb_record *r; 64 - 65 - for (j = 0; j < sizeof(arr->record[0]); j += 4) { 66 - *(uint32_t *)((void *)(arr->record + i) + j) = 67 - __sdb_rd(fmc, sdb_addr + (i * 64) + j, convert); 68 - } 69 - r = &arr->record[i]; 70 - arr->subtree[i] = ERR_PTR(-ENODEV); 71 - if (r->empty.record_type == sdb_type_bridge) { 72 - struct sdb_component *c = &r->bridge.sdb_component; 73 - uint64_t subaddr = __be64_to_cpu(r->bridge.sdb_child); 74 - uint64_t newbase = __be64_to_cpu(c->addr_first); 75 - 76 - subaddr += reg_base; 77 - newbase += reg_base; 78 - sub = __fmc_scan_sdb_tree(fmc, subaddr, newbase, 79 - level + 1); 80 - arr->subtree[i] = sub; /* may be error */ 81 - if (IS_ERR(sub)) 82 - continue; 83 - sub->parent = arr; 84 - sub->baseaddr = newbase; 85 - } 86 - } 87 - return arr; 88 - } 89 - 90 - int fmc_scan_sdb_tree(struct fmc_device *fmc, unsigned long address) 91 - { 92 - struct sdb_array *ret; 93 - if (fmc->sdb) 94 - return -EBUSY; 95 - ret = __fmc_scan_sdb_tree(fmc, address, 0 /* regs */, 0); 96 - if (IS_ERR(ret)) 97 - return PTR_ERR(ret); 98 - fmc->sdb = ret; 99 - return 0; 100 - } 101 - EXPORT_SYMBOL(fmc_scan_sdb_tree); 102 - 103 - static void __fmc_sdb_free(struct sdb_array *arr) 104 - { 105 - int i, n; 106 - 107 - if (!arr) 108 - return; 109 - n = arr->len; 110 - for (i = 0; i < n; i++) { 111 - if (IS_ERR(arr->subtree[i])) 112 - continue; 113 - __fmc_sdb_free(arr->subtree[i]); 114 - } 115 - kfree(arr->record); 116 - kfree(arr->subtree); 117 - kfree(arr); 118 - } 119 - 120 - int fmc_free_sdb_tree(struct fmc_device *fmc) 121 - { 122 - __fmc_sdb_free(fmc->sdb); 123 - fmc->sdb = NULL; 124 - return 0; 125 - } 126 - EXPORT_SYMBOL(fmc_free_sdb_tree); 127 - 128 - /* This helper calls reprogram and inizialized sdb as well */ 129 - int fmc_reprogram_raw(struct fmc_device *fmc, struct fmc_driver *d, 130 - void *gw, unsigned long len, int sdb_entry) 131 - { 132 - int ret; 133 - 134 - ret = fmc->op->reprogram_raw(fmc, d, gw, len); 135 - if (ret < 0) 136 - return ret; 137 - if (sdb_entry < 0) 138 - return ret; 139 - 140 - /* We are required to find SDB at a given offset */ 141 - ret = fmc_scan_sdb_tree(fmc, sdb_entry); 142 - if (ret < 0) { 143 - dev_err(&fmc->dev, "Can't find SDB at address 0x%x\n", 144 - sdb_entry); 145 - return -ENODEV; 146 - } 147 - 148 - return 0; 149 - } 150 - EXPORT_SYMBOL(fmc_reprogram_raw); 151 - 152 - /* This helper calls reprogram and inizialized sdb as well */ 153 - int fmc_reprogram(struct fmc_device *fmc, struct fmc_driver *d, char *gw, 154 - int sdb_entry) 155 - { 156 - int ret; 157 - 158 - ret = fmc->op->reprogram(fmc, d, gw); 159 - if (ret < 0) 160 - return ret; 161 - if (sdb_entry < 0) 162 - return ret; 163 - 164 - /* We are required to find SDB at a given offset */ 165 - ret = fmc_scan_sdb_tree(fmc, sdb_entry); 166 - if (ret < 0) { 167 - dev_err(&fmc->dev, "Can't find SDB at address 0x%x\n", 168 - sdb_entry); 169 - return -ENODEV; 170 - } 171 - 172 - return 0; 173 - } 174 - EXPORT_SYMBOL(fmc_reprogram); 175 - 176 - void fmc_show_sdb_tree(const struct fmc_device *fmc) 177 - { 178 - pr_err("%s: not supported anymore, use debugfs to dump SDB\n", 179 - __func__); 180 - } 181 - EXPORT_SYMBOL(fmc_show_sdb_tree); 182 - 183 - signed long fmc_find_sdb_device(struct sdb_array *tree, 184 - uint64_t vid, uint32_t did, unsigned long *sz) 185 - { 186 - signed long res = -ENODEV; 187 - union sdb_record *r; 188 - struct sdb_product *p; 189 - struct sdb_component *c; 190 - int i, n = tree->len; 191 - uint64_t last, first; 192 - 193 - /* FIXME: what if the first interconnect is not at zero? */ 194 - for (i = 0; i < n; i++) { 195 - r = &tree->record[i]; 196 - c = &r->dev.sdb_component; 197 - p = &c->product; 198 - 199 - if (!IS_ERR(tree->subtree[i])) 200 - res = fmc_find_sdb_device(tree->subtree[i], 201 - vid, did, sz); 202 - if (res >= 0) 203 - return res + tree->baseaddr; 204 - if (r->empty.record_type != sdb_type_device) 205 - continue; 206 - if (__be64_to_cpu(p->vendor_id) != vid) 207 - continue; 208 - if (__be32_to_cpu(p->device_id) != did) 209 - continue; 210 - /* found */ 211 - last = __be64_to_cpu(c->addr_last); 212 - first = __be64_to_cpu(c->addr_first); 213 - if (sz) 214 - *sz = (typeof(*sz))(last + 1 - first); 215 - return first + tree->baseaddr; 216 - } 217 - return res; 218 - } 219 - EXPORT_SYMBOL(fmc_find_sdb_device);
-103
drivers/fmc/fmc-trivial.c
··· 1 - /* 2 - * Copyright (C) 2012 CERN (www.cern.ch) 3 - * Author: Alessandro Rubini <rubini@gnudd.com> 4 - * 5 - * Permission to use, copy, modify, and/or distribute this software for any 6 - * purpose with or without fee is hereby granted, provided that the above 7 - * copyright notice and this permission notice appear in all copies. 8 - * 9 - * The software is provided "as is"; the copyright holders disclaim 10 - * all warranties and liabilities, to the extent permitted by 11 - * applicable law. 12 - */ 13 - 14 - /* A trivial fmc driver that can load a gateware file and reports interrupts */ 15 - #include <linux/module.h> 16 - #include <linux/init.h> 17 - #include <linux/interrupt.h> 18 - #include <linux/gpio.h> 19 - #include <linux/fmc.h> 20 - 21 - static struct fmc_driver t_drv; /* initialized later */ 22 - 23 - static irqreturn_t t_handler(int irq, void *dev_id) 24 - { 25 - struct fmc_device *fmc = dev_id; 26 - 27 - fmc_irq_ack(fmc); 28 - dev_info(&fmc->dev, "received irq %i\n", irq); 29 - return IRQ_HANDLED; 30 - } 31 - 32 - static struct fmc_gpio t_gpio[] = { 33 - { 34 - .gpio = FMC_GPIO_IRQ(0), 35 - .mode = GPIOF_DIR_IN, 36 - .irqmode = IRQF_TRIGGER_RISING, 37 - }, { 38 - .gpio = FMC_GPIO_IRQ(1), 39 - .mode = GPIOF_DIR_IN, 40 - .irqmode = IRQF_TRIGGER_RISING, 41 - } 42 - }; 43 - 44 - static int t_probe(struct fmc_device *fmc) 45 - { 46 - int ret; 47 - int index = 0; 48 - 49 - index = fmc_validate(fmc, &t_drv); 50 - if (index < 0) 51 - return -EINVAL; /* not our device: invalid */ 52 - 53 - ret = fmc_irq_request(fmc, t_handler, "fmc-trivial", IRQF_SHARED); 54 - if (ret < 0) 55 - return ret; 56 - /* ignore error code of call below, we really don't care */ 57 - fmc_gpio_config(fmc, t_gpio, ARRAY_SIZE(t_gpio)); 58 - 59 - ret = fmc_reprogram(fmc, &t_drv, "", 0); 60 - if (ret == -EPERM) /* programming not supported */ 61 - ret = 0; 62 - if (ret < 0) 63 - fmc_irq_free(fmc); 64 - 65 - /* FIXME: reprogram LM32 too */ 66 - return ret; 67 - } 68 - 69 - static int t_remove(struct fmc_device *fmc) 70 - { 71 - fmc_irq_free(fmc); 72 - return 0; 73 - } 74 - 75 - static struct fmc_driver t_drv = { 76 - .version = FMC_VERSION, 77 - .driver.name = KBUILD_MODNAME, 78 - .probe = t_probe, 79 - .remove = t_remove, 80 - /* no table, as the current match just matches everything */ 81 - }; 82 - 83 - /* We accept the generic parameters */ 84 - FMC_PARAM_BUSID(t_drv); 85 - FMC_PARAM_GATEWARE(t_drv); 86 - 87 - static int t_init(void) 88 - { 89 - int ret; 90 - 91 - ret = fmc_driver_register(&t_drv); 92 - return ret; 93 - } 94 - 95 - static void t_exit(void) 96 - { 97 - fmc_driver_unregister(&t_drv); 98 - } 99 - 100 - module_init(t_init); 101 - module_exit(t_exit); 102 - 103 - MODULE_LICENSE("Dual BSD/GPL");
-175
drivers/fmc/fmc-write-eeprom.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Copyright (C) 2012 CERN (www.cern.ch) 4 - * Author: Alessandro Rubini <rubini@gnudd.com> 5 - * 6 - * This work is part of the White Rabbit project, a research effort led 7 - * by CERN, the European Institute for Nuclear Research. 8 - */ 9 - #include <linux/module.h> 10 - #include <linux/string.h> 11 - #include <linux/firmware.h> 12 - #include <linux/init.h> 13 - #include <linux/fmc.h> 14 - #include <asm/unaligned.h> 15 - 16 - /* 17 - * This module uses the firmware loader to program the whole or part 18 - * of the FMC eeprom. The meat is in the _run functions. However, no 19 - * default file name is provided, to avoid accidental mishaps. Also, 20 - * you must pass the busid argument 21 - */ 22 - static struct fmc_driver fwe_drv; 23 - 24 - FMC_PARAM_BUSID(fwe_drv); 25 - 26 - /* The "file=" is like the generic "gateware=" used elsewhere */ 27 - static char *fwe_file[FMC_MAX_CARDS]; 28 - static int fwe_file_n; 29 - module_param_array_named(file, fwe_file, charp, &fwe_file_n, 0444); 30 - 31 - static int fwe_run_tlv(struct fmc_device *fmc, const struct firmware *fw, 32 - int write) 33 - { 34 - const uint8_t *p = fw->data; 35 - int len = fw->size; 36 - uint16_t thislen, thisaddr; 37 - int err; 38 - 39 - /* format is: 'w' addr16 len16 data... */ 40 - while (len > 5) { 41 - thisaddr = get_unaligned_le16(p+1); 42 - thislen = get_unaligned_le16(p+3); 43 - if (p[0] != 'w' || thislen + 5 > len) { 44 - dev_err(&fmc->dev, "invalid tlv at offset %ti\n", 45 - p - fw->data); 46 - return -EINVAL; 47 - } 48 - err = 0; 49 - if (write) { 50 - dev_info(&fmc->dev, "write %i bytes at 0x%04x\n", 51 - thislen, thisaddr); 52 - err = fmc_write_ee(fmc, thisaddr, p + 5, thislen); 53 - } 54 - if (err < 0) { 55 - dev_err(&fmc->dev, "write failure @0x%04x\n", 56 - thisaddr); 57 - return err; 58 - } 59 - p += 5 + thislen; 60 - len -= 5 + thislen; 61 - } 62 - if (write) 63 - dev_info(&fmc->dev, "write_eeprom: success\n"); 64 - return 0; 65 - } 66 - 67 - static int fwe_run_bin(struct fmc_device *fmc, const struct firmware *fw) 68 - { 69 - int ret; 70 - 71 - dev_info(&fmc->dev, "programming %zi bytes\n", fw->size); 72 - ret = fmc_write_ee(fmc, 0, (void *)fw->data, fw->size); 73 - if (ret < 0) { 74 - dev_info(&fmc->dev, "write_eeprom: error %i\n", ret); 75 - return ret; 76 - } 77 - dev_info(&fmc->dev, "write_eeprom: success\n"); 78 - return 0; 79 - } 80 - 81 - static int fwe_run(struct fmc_device *fmc, const struct firmware *fw, char *s) 82 - { 83 - char *last4 = s + strlen(s) - 4; 84 - int err; 85 - 86 - if (!strcmp(last4, ".bin")) 87 - return fwe_run_bin(fmc, fw); 88 - if (!strcmp(last4, ".tlv")) { 89 - err = fwe_run_tlv(fmc, fw, 0); 90 - if (!err) 91 - err = fwe_run_tlv(fmc, fw, 1); 92 - return err; 93 - } 94 - dev_err(&fmc->dev, "invalid file name \"%s\"\n", s); 95 - return -EINVAL; 96 - } 97 - 98 - /* 99 - * Programming is done at probe time. Morever, only those listed with 100 - * busid= are programmed. 101 - * card is probed for, only one is programmed. Unfortunately, it's 102 - * difficult to know in advance when probing the first card if others 103 - * are there. 104 - */ 105 - static int fwe_probe(struct fmc_device *fmc) 106 - { 107 - int err, index = 0; 108 - const struct firmware *fw; 109 - struct device *dev = &fmc->dev; 110 - char *s; 111 - 112 - if (!fwe_drv.busid_n) { 113 - dev_err(dev, "%s: no busid passed, refusing all cards\n", 114 - KBUILD_MODNAME); 115 - return -ENODEV; 116 - } 117 - 118 - index = fmc_validate(fmc, &fwe_drv); 119 - if (index < 0) { 120 - pr_err("%s: refusing device \"%s\"\n", KBUILD_MODNAME, 121 - dev_name(dev)); 122 - return -ENODEV; 123 - } 124 - if (index >= fwe_file_n) { 125 - pr_err("%s: no filename for device index %i\n", 126 - KBUILD_MODNAME, index); 127 - return -ENODEV; 128 - } 129 - s = fwe_file[index]; 130 - if (!s) { 131 - pr_err("%s: no filename for \"%s\" not programming\n", 132 - KBUILD_MODNAME, dev_name(dev)); 133 - return -ENOENT; 134 - } 135 - err = request_firmware(&fw, s, dev); 136 - if (err < 0) { 137 - dev_err(&fmc->dev, "request firmware \"%s\": error %i\n", 138 - s, err); 139 - return err; 140 - } 141 - fwe_run(fmc, fw, s); 142 - release_firmware(fw); 143 - return 0; 144 - } 145 - 146 - static int fwe_remove(struct fmc_device *fmc) 147 - { 148 - return 0; 149 - } 150 - 151 - static struct fmc_driver fwe_drv = { 152 - .version = FMC_VERSION, 153 - .driver.name = KBUILD_MODNAME, 154 - .probe = fwe_probe, 155 - .remove = fwe_remove, 156 - /* no table, as the current match just matches everything */ 157 - }; 158 - 159 - static int fwe_init(void) 160 - { 161 - int ret; 162 - 163 - ret = fmc_driver_register(&fwe_drv); 164 - return ret; 165 - } 166 - 167 - static void fwe_exit(void) 168 - { 169 - fmc_driver_unregister(&fwe_drv); 170 - } 171 - 172 - module_init(fwe_init); 173 - module_exit(fwe_exit); 174 - 175 - MODULE_LICENSE("GPL");
-80
drivers/fmc/fru-parse.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Copyright (C) 2012 CERN (www.cern.ch) 4 - * Author: Alessandro Rubini <rubini@gnudd.com> 5 - * 6 - * This work is part of the White Rabbit project, a research effort led 7 - * by CERN, the European Institute for Nuclear Research. 8 - */ 9 - #include <linux/ipmi-fru.h> 10 - 11 - /* Some internal helpers */ 12 - static struct fru_type_length * 13 - __fru_get_board_tl(struct fru_common_header *header, int nr) 14 - { 15 - struct fru_board_info_area *bia; 16 - struct fru_type_length *tl; 17 - 18 - bia = fru_get_board_area(header); 19 - tl = bia->tl; 20 - while (nr > 0 && !fru_is_eof(tl)) { 21 - tl = fru_next_tl(tl); 22 - nr--; 23 - } 24 - if (fru_is_eof(tl)) 25 - return NULL; 26 - return tl; 27 - } 28 - 29 - static char *__fru_alloc_get_tl(struct fru_common_header *header, int nr) 30 - { 31 - struct fru_type_length *tl; 32 - char *res; 33 - 34 - tl = __fru_get_board_tl(header, nr); 35 - if (!tl) 36 - return NULL; 37 - 38 - res = fru_alloc(fru_strlen(tl) + 1); 39 - if (!res) 40 - return NULL; 41 - return fru_strcpy(res, tl); 42 - } 43 - 44 - /* Public checksum verifiers */ 45 - int fru_header_cksum_ok(struct fru_common_header *header) 46 - { 47 - uint8_t *ptr = (void *)header; 48 - int i, sum; 49 - 50 - for (i = sum = 0; i < sizeof(*header); i++) 51 - sum += ptr[i]; 52 - return (sum & 0xff) == 0; 53 - } 54 - int fru_bia_cksum_ok(struct fru_board_info_area *bia) 55 - { 56 - uint8_t *ptr = (void *)bia; 57 - int i, sum; 58 - 59 - for (i = sum = 0; i < 8 * bia->area_len; i++) 60 - sum += ptr[i]; 61 - return (sum & 0xff) == 0; 62 - } 63 - 64 - /* Get various stuff, trivial */ 65 - char *fru_get_board_manufacturer(struct fru_common_header *header) 66 - { 67 - return __fru_alloc_get_tl(header, 0); 68 - } 69 - char *fru_get_product_name(struct fru_common_header *header) 70 - { 71 - return __fru_alloc_get_tl(header, 1); 72 - } 73 - char *fru_get_serial_number(struct fru_common_header *header) 74 - { 75 - return __fru_alloc_get_tl(header, 2); 76 - } 77 - char *fru_get_part_number(struct fru_common_header *header) 78 - { 79 - return __fru_alloc_get_tl(header, 3); 80 - }
+8 -12
drivers/gpio/Kconfig
··· 62 62 bool "/sys/class/gpio/... (sysfs interface)" 63 63 depends on SYSFS 64 64 help 65 - Say Y here to add a sysfs interface for GPIOs. 65 + Say Y here to add the legacy sysfs interface for GPIOs. 66 66 67 - This is mostly useful to work around omissions in a system's 68 - kernel support. Those are common in custom and semicustom 69 - hardware assembled using standard kernels with a minimum of 70 - custom patches. In those cases, userspace code may import 71 - a given GPIO from the kernel, if no kernel driver requested it. 72 - 73 - Kernel drivers may also request that a particular GPIO be 74 - exported to userspace; this can be useful when debugging. 67 + This ABI is deprecated. If you want to use GPIO from userspace, 68 + use the character device /dev/gpiochipN with the appropriate 69 + ioctl() operations instead. The character device is always 70 + available. 75 71 76 72 config GPIO_GENERIC 77 73 depends on HAS_IOMEM # Only for IOMEM drivers ··· 174 178 config GPIO_DAVINCI 175 179 bool "TI Davinci/Keystone GPIO support" 176 180 default y if ARCH_DAVINCI 177 - depends on ARM && (ARCH_DAVINCI || ARCH_KEYSTONE) 181 + depends on (ARM || ARM64) && (ARCH_DAVINCI || ARCH_KEYSTONE || ARCH_K3) 178 182 help 179 183 Say yes here to enable GPIO support for TI Davinci/Keystone SoCs. 180 184 ··· 489 493 490 494 config GPIO_STP_XWAY 491 495 bool "XWAY STP GPIOs" 492 - depends on SOC_XWAY 496 + depends on SOC_XWAY || COMPILE_TEST 497 + depends on OF_GPIO 493 498 help 494 499 This enables support for the Serial To Parallel (STP) unit found on 495 500 XWAY SoC. The STP allows the SoC to drive a shift registers cascade, ··· 599 602 600 603 config GPIO_XILINX 601 604 tristate "Xilinx GPIO support" 602 - depends on OF_GPIO 603 605 help 604 606 Say yes here to support the Xilinx FPGA GPIO device 605 607
+148 -148
drivers/gpio/Makefile
··· 17 17 # directly supported by gpio-generic 18 18 gpio-generic-$(CONFIG_GPIO_GENERIC) += gpio-mmio.o 19 19 20 - obj-$(CONFIG_GPIO_104_DIO_48E) += gpio-104-dio-48e.o 21 - obj-$(CONFIG_GPIO_104_IDIO_16) += gpio-104-idio-16.o 22 - obj-$(CONFIG_GPIO_104_IDI_48) += gpio-104-idi-48.o 23 - obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o 24 - obj-$(CONFIG_GPIO_74XX_MMIO) += gpio-74xx-mmio.o 25 - obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o 26 - obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o 27 - obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o 28 - obj-$(CONFIG_GPIO_ALTERA) += gpio-altera.o 29 - obj-$(CONFIG_GPIO_ALTERA_A10SR) += gpio-altera-a10sr.o 30 - obj-$(CONFIG_GPIO_AMD_FCH) += gpio-amd-fch.o 31 - obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o 32 - obj-$(CONFIG_GPIO_AMDPT) += gpio-amdpt.o 33 - obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o 34 - obj-$(CONFIG_GPIO_ATH79) += gpio-ath79.o 35 - obj-$(CONFIG_GPIO_ASPEED) += gpio-aspeed.o 36 - obj-$(CONFIG_GPIO_RASPBERRYPI_EXP) += gpio-raspberrypi-exp.o 37 - obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o 38 - obj-$(CONFIG_GPIO_BD9571MWV) += gpio-bd9571mwv.o 39 - obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o 40 - obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o 41 - obj-$(CONFIG_GPIO_CADENCE) += gpio-cadence.o 42 - obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o 43 - obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o 44 - obj-$(CONFIG_GPIO_CRYSTAL_COVE) += gpio-crystalcove.o 45 - obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o 46 - obj-$(CONFIG_GPIO_DA9055) += gpio-da9055.o 47 - obj-$(CONFIG_GPIO_DAVINCI) += gpio-davinci.o 48 - obj-$(CONFIG_GPIO_DLN2) += gpio-dln2.o 49 - obj-$(CONFIG_GPIO_DWAPB) += gpio-dwapb.o 50 - obj-$(CONFIG_GPIO_EIC_SPRD) += gpio-eic-sprd.o 51 - obj-$(CONFIG_GPIO_EM) += gpio-em.o 52 - obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o 53 - obj-$(CONFIG_GPIO_EXAR) += gpio-exar.o 54 - obj-$(CONFIG_GPIO_F7188X) += gpio-f7188x.o 55 - obj-$(CONFIG_GPIO_FTGPIO010) += gpio-ftgpio010.o 56 - obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o 57 - obj-$(CONFIG_GPIO_GPIO_MM) += gpio-gpio-mm.o 58 - obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o 59 - obj-$(CONFIG_GPIO_GW_PLD) += gpio-gw-pld.o 60 - obj-$(CONFIG_GPIO_HLWD) += gpio-hlwd.o 61 - obj-$(CONFIG_HTC_EGPIO) += gpio-htc-egpio.o 62 - obj-$(CONFIG_GPIO_ICH) += gpio-ich.o 63 - obj-$(CONFIG_GPIO_IOP) += gpio-iop.o 64 - obj-$(CONFIG_GPIO_IXP4XX) += gpio-ixp4xx.o 65 - obj-$(CONFIG_GPIO_IT87) += gpio-it87.o 66 - obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o 67 - obj-$(CONFIG_GPIO_KEMPLD) += gpio-kempld.o 68 - obj-$(CONFIG_ARCH_KS8695) += gpio-ks8695.o 69 - obj-$(CONFIG_GPIO_INTEL_MID) += gpio-intel-mid.o 70 - obj-$(CONFIG_GPIO_LOONGSON) += gpio-loongson.o 71 - obj-$(CONFIG_GPIO_LP3943) += gpio-lp3943.o 72 - obj-$(CONFIG_GPIO_LPC18XX) += gpio-lpc18xx.o 73 - obj-$(CONFIG_ARCH_LPC32XX) += gpio-lpc32xx.o 74 - obj-$(CONFIG_GPIO_LP873X) += gpio-lp873x.o 75 - obj-$(CONFIG_GPIO_LP87565) += gpio-lp87565.o 76 - obj-$(CONFIG_GPIO_LYNXPOINT) += gpio-lynxpoint.o 77 - obj-$(CONFIG_GPIO_MADERA) += gpio-madera.o 78 - obj-$(CONFIG_GPIO_MAX3191X) += gpio-max3191x.o 79 - obj-$(CONFIG_GPIO_MAX730X) += gpio-max730x.o 80 - obj-$(CONFIG_GPIO_MAX7300) += gpio-max7300.o 81 - obj-$(CONFIG_GPIO_MAX7301) += gpio-max7301.o 82 - obj-$(CONFIG_GPIO_MAX732X) += gpio-max732x.o 83 - obj-$(CONFIG_GPIO_MAX77620) += gpio-max77620.o 84 - obj-$(CONFIG_GPIO_MAX77650) += gpio-max77650.o 85 - obj-$(CONFIG_GPIO_MB86S7X) += gpio-mb86s7x.o 86 - obj-$(CONFIG_GPIO_MENZ127) += gpio-menz127.o 87 - obj-$(CONFIG_GPIO_MERRIFIELD) += gpio-merrifield.o 88 - obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o 89 - obj-$(CONFIG_GPIO_MC9S08DZ60) += gpio-mc9s08dz60.o 90 - obj-$(CONFIG_GPIO_MLXBF) += gpio-mlxbf.o 91 - obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o 92 - obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o 93 - obj-$(CONFIG_GPIO_MOCKUP) += gpio-mockup.o 94 - obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o 95 - obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o 96 - obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o 20 + obj-$(CONFIG_GPIO_104_DIO_48E) += gpio-104-dio-48e.o 21 + obj-$(CONFIG_GPIO_104_IDI_48) += gpio-104-idi-48.o 22 + obj-$(CONFIG_GPIO_104_IDIO_16) += gpio-104-idio-16.o 23 + obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o 24 + obj-$(CONFIG_GPIO_74XX_MMIO) += gpio-74xx-mmio.o 25 + obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o 26 + obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o 27 + obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o 28 + obj-$(CONFIG_GPIO_ALTERA_A10SR) += gpio-altera-a10sr.o 29 + obj-$(CONFIG_GPIO_ALTERA) += gpio-altera.o 30 + obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o 31 + obj-$(CONFIG_GPIO_AMD_FCH) += gpio-amd-fch.o 32 + obj-$(CONFIG_GPIO_AMDPT) += gpio-amdpt.o 33 + obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o 34 + obj-$(CONFIG_GPIO_ASPEED) += gpio-aspeed.o 35 + obj-$(CONFIG_GPIO_ATH79) += gpio-ath79.o 36 + obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o 37 + obj-$(CONFIG_GPIO_BD9571MWV) += gpio-bd9571mwv.o 38 + obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o 39 + obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o 40 + obj-$(CONFIG_GPIO_CADENCE) += gpio-cadence.o 41 + obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o 42 + obj-$(CONFIG_GPIO_SNPS_CREG) += gpio-creg-snps.o 43 + obj-$(CONFIG_GPIO_CRYSTAL_COVE) += gpio-crystalcove.o 44 + obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o 45 + obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o 46 + obj-$(CONFIG_GPIO_DA9055) += gpio-da9055.o 47 + obj-$(CONFIG_GPIO_DAVINCI) += gpio-davinci.o 48 + obj-$(CONFIG_GPIO_DLN2) += gpio-dln2.o 49 + obj-$(CONFIG_GPIO_DWAPB) += gpio-dwapb.o 50 + obj-$(CONFIG_GPIO_EIC_SPRD) += gpio-eic-sprd.o 51 + obj-$(CONFIG_GPIO_EM) += gpio-em.o 52 + obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o 53 + obj-$(CONFIG_GPIO_EXAR) += gpio-exar.o 54 + obj-$(CONFIG_GPIO_F7188X) += gpio-f7188x.o 55 + obj-$(CONFIG_GPIO_FTGPIO010) += gpio-ftgpio010.o 56 + obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o 57 + obj-$(CONFIG_GPIO_GPIO_MM) += gpio-gpio-mm.o 58 + obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o 59 + obj-$(CONFIG_GPIO_GW_PLD) += gpio-gw-pld.o 60 + obj-$(CONFIG_GPIO_HLWD) += gpio-hlwd.o 61 + obj-$(CONFIG_HTC_EGPIO) += gpio-htc-egpio.o 62 + obj-$(CONFIG_GPIO_ICH) += gpio-ich.o 63 + obj-$(CONFIG_GPIO_INTEL_MID) += gpio-intel-mid.o 64 + obj-$(CONFIG_GPIO_IOP) += gpio-iop.o 65 + obj-$(CONFIG_GPIO_IT87) += gpio-it87.o 66 + obj-$(CONFIG_GPIO_IXP4XX) += gpio-ixp4xx.o 67 + obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o 68 + obj-$(CONFIG_GPIO_KEMPLD) += gpio-kempld.o 69 + obj-$(CONFIG_ARCH_KS8695) += gpio-ks8695.o 70 + obj-$(CONFIG_GPIO_LOONGSON1) += gpio-loongson1.o 71 + obj-$(CONFIG_GPIO_LOONGSON) += gpio-loongson.o 72 + obj-$(CONFIG_GPIO_LP3943) += gpio-lp3943.o 73 + obj-$(CONFIG_GPIO_LP873X) += gpio-lp873x.o 74 + obj-$(CONFIG_GPIO_LP87565) += gpio-lp87565.o 75 + obj-$(CONFIG_GPIO_LPC18XX) += gpio-lpc18xx.o 76 + obj-$(CONFIG_ARCH_LPC32XX) += gpio-lpc32xx.o 77 + obj-$(CONFIG_GPIO_LYNXPOINT) += gpio-lynxpoint.o 78 + obj-$(CONFIG_GPIO_MADERA) += gpio-madera.o 79 + obj-$(CONFIG_GPIO_MAX3191X) += gpio-max3191x.o 80 + obj-$(CONFIG_GPIO_MAX7300) += gpio-max7300.o 81 + obj-$(CONFIG_GPIO_MAX7301) += gpio-max7301.o 82 + obj-$(CONFIG_GPIO_MAX730X) += gpio-max730x.o 83 + obj-$(CONFIG_GPIO_MAX732X) += gpio-max732x.o 84 + obj-$(CONFIG_GPIO_MAX77620) += gpio-max77620.o 85 + obj-$(CONFIG_GPIO_MAX77650) += gpio-max77650.o 86 + obj-$(CONFIG_GPIO_MB86S7X) += gpio-mb86s7x.o 87 + obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o 88 + obj-$(CONFIG_GPIO_MC9S08DZ60) += gpio-mc9s08dz60.o 89 + obj-$(CONFIG_GPIO_MENZ127) += gpio-menz127.o 90 + obj-$(CONFIG_GPIO_MERRIFIELD) += gpio-merrifield.o 91 + obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o 92 + obj-$(CONFIG_GPIO_MLXBF) += gpio-mlxbf.o 93 + obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o 94 + obj-$(CONFIG_GPIO_MOCKUP) += gpio-mockup.o 95 + obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o 96 + obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o 97 + obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o 97 98 obj-$(CONFIG_GPIO_MT7621) += gpio-mt7621.o 98 - obj-$(CONFIG_GPIO_MVEBU) += gpio-mvebu.o 99 - obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o 100 - obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o 101 - obj-$(CONFIG_GPIO_OCTEON) += gpio-octeon.o 102 - obj-$(CONFIG_GPIO_OMAP) += gpio-omap.o 103 - obj-$(CONFIG_GPIO_PCA953X) += gpio-pca953x.o 104 - obj-$(CONFIG_GPIO_PCF857X) += gpio-pcf857x.o 105 - obj-$(CONFIG_GPIO_PCH) += gpio-pch.o 106 - obj-$(CONFIG_GPIO_PCI_IDIO_16) += gpio-pci-idio-16.o 107 - obj-$(CONFIG_GPIO_PCIE_IDIO_24) += gpio-pcie-idio-24.o 108 - obj-$(CONFIG_GPIO_PISOSR) += gpio-pisosr.o 109 - obj-$(CONFIG_GPIO_PL061) += gpio-pl061.o 99 + obj-$(CONFIG_GPIO_MVEBU) += gpio-mvebu.o 100 + obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o 101 + obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o 102 + obj-$(CONFIG_GPIO_OCTEON) += gpio-octeon.o 103 + obj-$(CONFIG_GPIO_OMAP) += gpio-omap.o 104 + obj-$(CONFIG_GPIO_PALMAS) += gpio-palmas.o 105 + obj-$(CONFIG_GPIO_PCA953X) += gpio-pca953x.o 106 + obj-$(CONFIG_GPIO_PCF857X) += gpio-pcf857x.o 107 + obj-$(CONFIG_GPIO_PCH) += gpio-pch.o 108 + obj-$(CONFIG_GPIO_PCIE_IDIO_24) += gpio-pcie-idio-24.o 109 + obj-$(CONFIG_GPIO_PCI_IDIO_16) += gpio-pci-idio-16.o 110 + obj-$(CONFIG_GPIO_PISOSR) += gpio-pisosr.o 111 + obj-$(CONFIG_GPIO_PL061) += gpio-pl061.o 110 112 obj-$(CONFIG_GPIO_PMIC_EIC_SPRD) += gpio-pmic-eic-sprd.o 111 - obj-$(CONFIG_GPIO_PXA) += gpio-pxa.o 112 - obj-$(CONFIG_GPIO_RC5T583) += gpio-rc5t583.o 113 - obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o 114 - obj-$(CONFIG_GPIO_RCAR) += gpio-rcar.o 115 - obj-$(CONFIG_GPIO_REG) += gpio-reg.o 116 - obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o 113 + obj-$(CONFIG_GPIO_PXA) += gpio-pxa.o 114 + obj-$(CONFIG_GPIO_RASPBERRYPI_EXP) += gpio-raspberrypi-exp.o 115 + obj-$(CONFIG_GPIO_RC5T583) += gpio-rc5t583.o 116 + obj-$(CONFIG_GPIO_RCAR) += gpio-rcar.o 117 + obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o 118 + obj-$(CONFIG_GPIO_REG) += gpio-reg.o 119 + obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o 117 120 obj-$(CONFIG_GPIO_SAMA5D2_PIOBU) += gpio-sama5d2-piobu.o 118 - obj-$(CONFIG_GPIO_SCH) += gpio-sch.o 119 - obj-$(CONFIG_GPIO_SCH311X) += gpio-sch311x.o 120 - obj-$(CONFIG_GPIO_SNPS_CREG) += gpio-creg-snps.o 121 - obj-$(CONFIG_GPIO_SODAVILLE) += gpio-sodaville.o 122 - obj-$(CONFIG_GPIO_SPEAR_SPICS) += gpio-spear-spics.o 123 - obj-$(CONFIG_GPIO_SPRD) += gpio-sprd.o 124 - obj-$(CONFIG_GPIO_STA2X11) += gpio-sta2x11.o 125 - obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o 126 - obj-$(CONFIG_GPIO_STP_XWAY) += gpio-stp-xway.o 127 - obj-$(CONFIG_GPIO_SYSCON) += gpio-syscon.o 128 - obj-$(CONFIG_GPIO_TB10X) += gpio-tb10x.o 129 - obj-$(CONFIG_GPIO_TC3589X) += gpio-tc3589x.o 130 - obj-$(CONFIG_GPIO_TEGRA) += gpio-tegra.o 131 - obj-$(CONFIG_GPIO_TEGRA186) += gpio-tegra186.o 132 - obj-$(CONFIG_GPIO_THUNDERX) += gpio-thunderx.o 133 - obj-$(CONFIG_GPIO_TIMBERDALE) += gpio-timberdale.o 134 - obj-$(CONFIG_GPIO_PALMAS) += gpio-palmas.o 135 - obj-$(CONFIG_GPIO_SIOX) += gpio-siox.o 136 - obj-$(CONFIG_GPIO_TPIC2810) += gpio-tpic2810.o 137 - obj-$(CONFIG_GPIO_TPS65086) += gpio-tps65086.o 138 - obj-$(CONFIG_GPIO_TPS65218) += gpio-tps65218.o 139 - obj-$(CONFIG_GPIO_TPS6586X) += gpio-tps6586x.o 140 - obj-$(CONFIG_GPIO_TPS65910) += gpio-tps65910.o 141 - obj-$(CONFIG_GPIO_TPS65912) += gpio-tps65912.o 142 - obj-$(CONFIG_GPIO_TPS68470) += gpio-tps68470.o 143 - obj-$(CONFIG_GPIO_TQMX86) += gpio-tqmx86.o 144 - obj-$(CONFIG_GPIO_TS4800) += gpio-ts4800.o 145 - obj-$(CONFIG_GPIO_TS4900) += gpio-ts4900.o 146 - obj-$(CONFIG_GPIO_TS5500) += gpio-ts5500.o 147 - obj-$(CONFIG_GPIO_TWL4030) += gpio-twl4030.o 148 - obj-$(CONFIG_GPIO_TWL6040) += gpio-twl6040.o 149 - obj-$(CONFIG_GPIO_UCB1400) += gpio-ucb1400.o 150 - obj-$(CONFIG_GPIO_UNIPHIER) += gpio-uniphier.o 151 - obj-$(CONFIG_GPIO_VF610) += gpio-vf610.o 152 - obj-$(CONFIG_GPIO_VIPERBOARD) += gpio-viperboard.o 153 - obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o 154 - obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o 155 - obj-$(CONFIG_GPIO_WHISKEY_COVE) += gpio-wcove.o 156 - obj-$(CONFIG_GPIO_WINBOND) += gpio-winbond.o 157 - obj-$(CONFIG_GPIO_WM831X) += gpio-wm831x.o 158 - obj-$(CONFIG_GPIO_WM8350) += gpio-wm8350.o 159 - obj-$(CONFIG_GPIO_WM8994) += gpio-wm8994.o 160 - obj-$(CONFIG_GPIO_WS16C48) += gpio-ws16c48.o 161 - obj-$(CONFIG_GPIO_XGENE) += gpio-xgene.o 162 - obj-$(CONFIG_GPIO_XGENE_SB) += gpio-xgene-sb.o 163 - obj-$(CONFIG_GPIO_XILINX) += gpio-xilinx.o 164 - obj-$(CONFIG_GPIO_XLP) += gpio-xlp.o 165 - obj-$(CONFIG_GPIO_XRA1403) += gpio-xra1403.o 166 - obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o 167 - obj-$(CONFIG_GPIO_ZEVIO) += gpio-zevio.o 168 - obj-$(CONFIG_GPIO_ZYNQ) += gpio-zynq.o 169 - obj-$(CONFIG_GPIO_ZX) += gpio-zx.o 170 - obj-$(CONFIG_GPIO_LOONGSON1) += gpio-loongson1.o 121 + obj-$(CONFIG_GPIO_SCH311X) += gpio-sch311x.o 122 + obj-$(CONFIG_GPIO_SCH) += gpio-sch.o 123 + obj-$(CONFIG_GPIO_SIOX) += gpio-siox.o 124 + obj-$(CONFIG_GPIO_SODAVILLE) += gpio-sodaville.o 125 + obj-$(CONFIG_GPIO_SPEAR_SPICS) += gpio-spear-spics.o 126 + obj-$(CONFIG_GPIO_SPRD) += gpio-sprd.o 127 + obj-$(CONFIG_GPIO_STA2X11) += gpio-sta2x11.o 128 + obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o 129 + obj-$(CONFIG_GPIO_STP_XWAY) += gpio-stp-xway.o 130 + obj-$(CONFIG_GPIO_SYSCON) += gpio-syscon.o 131 + obj-$(CONFIG_GPIO_TB10X) += gpio-tb10x.o 132 + obj-$(CONFIG_GPIO_TC3589X) += gpio-tc3589x.o 133 + obj-$(CONFIG_GPIO_TEGRA186) += gpio-tegra186.o 134 + obj-$(CONFIG_GPIO_TEGRA) += gpio-tegra.o 135 + obj-$(CONFIG_GPIO_THUNDERX) += gpio-thunderx.o 136 + obj-$(CONFIG_GPIO_TIMBERDALE) += gpio-timberdale.o 137 + obj-$(CONFIG_GPIO_TPIC2810) += gpio-tpic2810.o 138 + obj-$(CONFIG_GPIO_TPS65086) += gpio-tps65086.o 139 + obj-$(CONFIG_GPIO_TPS65218) += gpio-tps65218.o 140 + obj-$(CONFIG_GPIO_TPS6586X) += gpio-tps6586x.o 141 + obj-$(CONFIG_GPIO_TPS65910) += gpio-tps65910.o 142 + obj-$(CONFIG_GPIO_TPS65912) += gpio-tps65912.o 143 + obj-$(CONFIG_GPIO_TPS68470) += gpio-tps68470.o 144 + obj-$(CONFIG_GPIO_TQMX86) += gpio-tqmx86.o 145 + obj-$(CONFIG_GPIO_TS4800) += gpio-ts4800.o 146 + obj-$(CONFIG_GPIO_TS4900) += gpio-ts4900.o 147 + obj-$(CONFIG_GPIO_TS5500) += gpio-ts5500.o 148 + obj-$(CONFIG_GPIO_TWL4030) += gpio-twl4030.o 149 + obj-$(CONFIG_GPIO_TWL6040) += gpio-twl6040.o 150 + obj-$(CONFIG_GPIO_UCB1400) += gpio-ucb1400.o 151 + obj-$(CONFIG_GPIO_UNIPHIER) += gpio-uniphier.o 152 + obj-$(CONFIG_GPIO_VF610) += gpio-vf610.o 153 + obj-$(CONFIG_GPIO_VIPERBOARD) += gpio-viperboard.o 154 + obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o 155 + obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o 156 + obj-$(CONFIG_GPIO_WHISKEY_COVE) += gpio-wcove.o 157 + obj-$(CONFIG_GPIO_WINBOND) += gpio-winbond.o 158 + obj-$(CONFIG_GPIO_WM831X) += gpio-wm831x.o 159 + obj-$(CONFIG_GPIO_WM8350) += gpio-wm8350.o 160 + obj-$(CONFIG_GPIO_WM8994) += gpio-wm8994.o 161 + obj-$(CONFIG_GPIO_WS16C48) += gpio-ws16c48.o 162 + obj-$(CONFIG_GPIO_XGENE) += gpio-xgene.o 163 + obj-$(CONFIG_GPIO_XGENE_SB) += gpio-xgene-sb.o 164 + obj-$(CONFIG_GPIO_XILINX) += gpio-xilinx.o 165 + obj-$(CONFIG_GPIO_XLP) += gpio-xlp.o 166 + obj-$(CONFIG_GPIO_XRA1403) += gpio-xra1403.o 167 + obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o 168 + obj-$(CONFIG_GPIO_ZEVIO) += gpio-zevio.o 169 + obj-$(CONFIG_GPIO_ZX) += gpio-zx.o 170 + obj-$(CONFIG_GPIO_ZYNQ) += gpio-zynq.o
+40
drivers/gpio/TODO
··· 90 90 The GPIOLIB irqchip is a helper irqchip for "simple cases" that should 91 91 try to cover any generic kind of irqchip cascaded from a GPIO. 92 92 93 + - Convert all the GPIOLIB_IRQCHIP users to pass an irqchip template, 94 + parent and flags before calling [devm_]gpiochip_add[_data](). 95 + Currently we set up the irqchip after setting up the gpiochip 96 + using gpiochip_irqchip_add() and gpiochip_set_[chained|nested]_irqchip(). 97 + This is too complex, so convert all users over to just set up 98 + the irqchip before registering the gpio_chip, typical example: 99 + 100 + /* Typical state container with dynamic irqchip */ 101 + struct my_gpio { 102 + struct gpio_chip gc; 103 + struct irq_chip irq; 104 + }; 105 + 106 + int irq; /* from platform etc */ 107 + struct my_gpio *g; 108 + struct gpio_irq_chip *girq 109 + 110 + /* Set up the irqchip dynamically */ 111 + g->irq.name = "my_gpio_irq"; 112 + g->irq.irq_ack = my_gpio_ack_irq; 113 + g->irq.irq_mask = my_gpio_mask_irq; 114 + g->irq.irq_unmask = my_gpio_unmask_irq; 115 + g->irq.irq_set_type = my_gpio_set_irq_type; 116 + 117 + /* Get a pointer to the gpio_irq_chip */ 118 + girq = &g->gc.irq; 119 + girq->chip = &g->irq; 120 + girq->parent_handler = ftgpio_gpio_irq_handler; 121 + girq->num_parents = 1; 122 + girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), 123 + GFP_KERNEL); 124 + if (!girq->parents) 125 + return -ENOMEM; 126 + girq->default_type = IRQ_TYPE_NONE; 127 + girq->handler = handle_bad_irq; 128 + girq->parents[0] = irq; 129 + 130 + When this is done, we will delete the old APIs for instatiating 131 + GPIOLIB_IRQCHIP and simplify the code. 132 + 93 133 - Look over and identify any remaining easily converted drivers and 94 134 dry-code conversions to gpiolib irqchip for maintainers to test 95 135
+37 -44
drivers/gpio/gpio-altera.c
··· 30 30 raw_spinlock_t gpio_lock; 31 31 int interrupt_trigger; 32 32 int mapped_irq; 33 + struct irq_chip irq_chip; 33 34 }; 34 35 35 36 static void altera_gpio_irq_unmask(struct irq_data *d) ··· 101 100 102 101 return 0; 103 102 } 104 - 105 - static struct irq_chip altera_irq_chip = { 106 - .name = "altera-gpio", 107 - .irq_mask = altera_gpio_irq_mask, 108 - .irq_unmask = altera_gpio_irq_unmask, 109 - .irq_set_type = altera_gpio_irq_set_type, 110 - .irq_startup = altera_gpio_irq_startup, 111 - .irq_shutdown = altera_gpio_irq_mask, 112 - }; 113 103 114 104 static int altera_gpio_get(struct gpio_chip *gc, unsigned offset) 115 105 { ··· 238 246 struct device_node *node = pdev->dev.of_node; 239 247 int reg, ret; 240 248 struct altera_gpio_chip *altera_gc; 249 + struct gpio_irq_chip *girq; 241 250 242 251 altera_gc = devm_kzalloc(&pdev->dev, sizeof(*altera_gc), GFP_KERNEL); 243 252 if (!altera_gc) ··· 266 273 altera_gc->mmchip.gc.owner = THIS_MODULE; 267 274 altera_gc->mmchip.gc.parent = &pdev->dev; 268 275 276 + altera_gc->mapped_irq = platform_get_irq(pdev, 0); 277 + 278 + if (altera_gc->mapped_irq < 0) 279 + goto skip_irq; 280 + 281 + if (of_property_read_u32(node, "altr,interrupt-type", &reg)) { 282 + dev_err(&pdev->dev, 283 + "altr,interrupt-type value not set in device tree\n"); 284 + return -EINVAL; 285 + } 286 + altera_gc->interrupt_trigger = reg; 287 + 288 + altera_gc->irq_chip.name = "altera-gpio"; 289 + altera_gc->irq_chip.irq_mask = altera_gpio_irq_mask; 290 + altera_gc->irq_chip.irq_unmask = altera_gpio_irq_unmask; 291 + altera_gc->irq_chip.irq_set_type = altera_gpio_irq_set_type; 292 + altera_gc->irq_chip.irq_startup = altera_gpio_irq_startup; 293 + altera_gc->irq_chip.irq_shutdown = altera_gpio_irq_mask; 294 + 295 + girq = &altera_gc->mmchip.gc.irq; 296 + girq->chip = &altera_gc->irq_chip; 297 + if (altera_gc->interrupt_trigger == IRQ_TYPE_LEVEL_HIGH) 298 + girq->parent_handler = altera_gpio_irq_leveL_high_handler; 299 + else 300 + girq->parent_handler = altera_gpio_irq_edge_handler; 301 + girq->num_parents = 1; 302 + girq->parents = devm_kcalloc(&pdev->dev, 1, sizeof(*girq->parents), 303 + GFP_KERNEL); 304 + if (!girq->parents) 305 + return -ENOMEM; 306 + girq->default_type = IRQ_TYPE_NONE; 307 + girq->handler = handle_bad_irq; 308 + girq->parents[0] = altera_gc->mapped_irq; 309 + 310 + skip_irq: 269 311 ret = of_mm_gpiochip_add_data(node, &altera_gc->mmchip, altera_gc); 270 312 if (ret) { 271 313 dev_err(&pdev->dev, "Failed adding memory mapped gpiochip\n"); ··· 309 281 310 282 platform_set_drvdata(pdev, altera_gc); 311 283 312 - altera_gc->mapped_irq = platform_get_irq(pdev, 0); 313 - 314 - if (altera_gc->mapped_irq < 0) 315 - goto skip_irq; 316 - 317 - if (of_property_read_u32(node, "altr,interrupt-type", &reg)) { 318 - ret = -EINVAL; 319 - dev_err(&pdev->dev, 320 - "altr,interrupt-type value not set in device tree\n"); 321 - goto teardown; 322 - } 323 - altera_gc->interrupt_trigger = reg; 324 - 325 - ret = gpiochip_irqchip_add(&altera_gc->mmchip.gc, &altera_irq_chip, 0, 326 - handle_bad_irq, IRQ_TYPE_NONE); 327 - 328 - if (ret) { 329 - dev_err(&pdev->dev, "could not add irqchip\n"); 330 - goto teardown; 331 - } 332 - 333 - gpiochip_set_chained_irqchip(&altera_gc->mmchip.gc, 334 - &altera_irq_chip, 335 - altera_gc->mapped_irq, 336 - altera_gc->interrupt_trigger == IRQ_TYPE_LEVEL_HIGH ? 337 - altera_gpio_irq_leveL_high_handler : 338 - altera_gpio_irq_edge_handler); 339 - 340 - skip_irq: 341 284 return 0; 342 - teardown: 343 - of_mm_gpiochip_remove(&altera_gc->mmchip); 344 - pr_err("%pOF: registration failed with status %d\n", 345 - node, ret); 346 - 347 - return ret; 348 285 } 349 286 350 287 static int altera_gpio_remove(struct platform_device *pdev)
+1 -3
drivers/gpio/gpio-amd-fch.c
··· 25 25 #define AMD_FCH_GPIO_FLAG_WRITE BIT(22) 26 26 #define AMD_FCH_GPIO_FLAG_READ BIT(16) 27 27 28 - static struct resource amd_fch_gpio_iores = 28 + static const struct resource amd_fch_gpio_iores = 29 29 DEFINE_RES_MEM_NAMED( 30 30 AMD_FCH_MMIO_BASE + AMD_FCH_GPIO_BANK0_BASE, 31 31 AMD_FCH_GPIO_SIZE, 32 32 "amd-fch-gpio-iomem"); 33 33 34 34 struct amd_fch_gpio_priv { 35 - struct platform_device *pdev; 36 35 struct gpio_chip gc; 37 36 void __iomem *base; 38 37 struct amd_fch_gpio_pdata *pdata; ··· 152 153 return -ENOMEM; 153 154 154 155 priv->pdata = pdata; 155 - priv->pdev = pdev; 156 156 157 157 priv->gc.owner = THIS_MODULE; 158 158 priv->gc.parent = &pdev->dev;
+5 -5
drivers/gpio/gpio-amdpt.c
··· 88 88 89 89 pt_gpio->reg_base = devm_platform_ioremap_resource(pdev, 0); 90 90 if (IS_ERR(pt_gpio->reg_base)) { 91 - dev_err(&pdev->dev, "Failed to map MMIO resource for PT GPIO.\n"); 91 + dev_err(dev, "Failed to map MMIO resource for PT GPIO.\n"); 92 92 return PTR_ERR(pt_gpio->reg_base); 93 93 } 94 94 ··· 98 98 pt_gpio->reg_base + PT_DIRECTION_REG, NULL, 99 99 BGPIOF_READ_OUTPUT_REG_SET); 100 100 if (ret) { 101 - dev_err(&pdev->dev, "bgpio_init failed\n"); 101 + dev_err(dev, "bgpio_init failed\n"); 102 102 return ret; 103 103 } 104 104 ··· 107 107 pt_gpio->gc.free = pt_gpio_free; 108 108 pt_gpio->gc.ngpio = PT_TOTAL_GPIO; 109 109 #if defined(CONFIG_OF_GPIO) 110 - pt_gpio->gc.of_node = pdev->dev.of_node; 110 + pt_gpio->gc.of_node = dev->of_node; 111 111 #endif 112 112 ret = gpiochip_add_data(&pt_gpio->gc, pt_gpio); 113 113 if (ret) { 114 - dev_err(&pdev->dev, "Failed to register GPIO lib\n"); 114 + dev_err(dev, "Failed to register GPIO lib\n"); 115 115 return ret; 116 116 } 117 117 ··· 121 121 writel(0, pt_gpio->reg_base + PT_SYNC_REG); 122 122 writel(0, pt_gpio->reg_base + PT_CLOCKRATE_REG); 123 123 124 - dev_dbg(&pdev->dev, "PT GPIO driver loaded\n"); 124 + dev_dbg(dev, "PT GPIO driver loaded\n"); 125 125 return ret; 126 126 } 127 127
+27 -39
drivers/gpio/gpio-ath79.c
··· 222 222 static int ath79_gpio_probe(struct platform_device *pdev) 223 223 { 224 224 struct ath79_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev); 225 - struct device_node *np = pdev->dev.of_node; 225 + struct device *dev = &pdev->dev; 226 + struct device_node *np = dev->of_node; 226 227 struct ath79_gpio_ctrl *ctrl; 228 + struct gpio_irq_chip *girq; 227 229 struct resource *res; 228 230 u32 ath79_gpio_count; 229 231 bool oe_inverted; 230 232 int err; 231 233 232 - ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL); 234 + ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); 233 235 if (!ctrl) 234 236 return -ENOMEM; 235 237 platform_set_drvdata(pdev, ctrl); ··· 239 237 if (np) { 240 238 err = of_property_read_u32(np, "ngpios", &ath79_gpio_count); 241 239 if (err) { 242 - dev_err(&pdev->dev, "ngpios property is not valid\n"); 240 + dev_err(dev, "ngpios property is not valid\n"); 243 241 return err; 244 242 } 245 243 oe_inverted = of_device_is_compatible(np, "qca,ar9340-gpio"); ··· 247 245 ath79_gpio_count = pdata->ngpios; 248 246 oe_inverted = pdata->oe_inverted; 249 247 } else { 250 - dev_err(&pdev->dev, "No DT node or platform data found\n"); 248 + dev_err(dev, "No DT node or platform data found\n"); 251 249 return -EINVAL; 252 250 } 253 251 254 252 if (ath79_gpio_count >= 32) { 255 - dev_err(&pdev->dev, "ngpios must be less than 32\n"); 253 + dev_err(dev, "ngpios must be less than 32\n"); 256 254 return -EINVAL; 257 255 } 258 256 259 257 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 260 258 if (!res) 261 259 return -EINVAL; 262 - ctrl->base = devm_ioremap_nocache( 263 - &pdev->dev, res->start, resource_size(res)); 260 + ctrl->base = devm_ioremap_nocache(dev, res->start, resource_size(res)); 264 261 if (!ctrl->base) 265 262 return -ENOMEM; 266 263 267 264 raw_spin_lock_init(&ctrl->lock); 268 - err = bgpio_init(&ctrl->gc, &pdev->dev, 4, 265 + err = bgpio_init(&ctrl->gc, dev, 4, 269 266 ctrl->base + AR71XX_GPIO_REG_IN, 270 267 ctrl->base + AR71XX_GPIO_REG_SET, 271 268 ctrl->base + AR71XX_GPIO_REG_CLEAR, ··· 272 271 oe_inverted ? ctrl->base + AR71XX_GPIO_REG_OE : NULL, 273 272 0); 274 273 if (err) { 275 - dev_err(&pdev->dev, "bgpio_init failed\n"); 274 + dev_err(dev, "bgpio_init failed\n"); 276 275 return err; 277 276 } 278 277 /* Use base 0 to stay compatible with legacy platforms */ 279 278 ctrl->gc.base = 0; 280 279 281 - err = gpiochip_add_data(&ctrl->gc, ctrl); 280 + /* Optional interrupt setup */ 281 + if (!np || of_property_read_bool(np, "interrupt-controller")) { 282 + girq = &ctrl->gc.irq; 283 + girq->chip = &ath79_gpio_irqchip; 284 + girq->parent_handler = ath79_gpio_irq_handler; 285 + girq->num_parents = 1; 286 + girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), 287 + GFP_KERNEL); 288 + if (!girq->parents) 289 + return -ENOMEM; 290 + girq->parents[0] = platform_get_irq(pdev, 0); 291 + girq->default_type = IRQ_TYPE_NONE; 292 + girq->handler = handle_simple_irq; 293 + } 294 + 295 + err = devm_gpiochip_add_data(dev, &ctrl->gc, ctrl); 282 296 if (err) { 283 - dev_err(&pdev->dev, 297 + dev_err(dev, 284 298 "cannot add AR71xx GPIO chip, error=%d", err); 285 299 return err; 286 300 } 287 - 288 - if (np && !of_property_read_bool(np, "interrupt-controller")) 289 - return 0; 290 - 291 - err = gpiochip_irqchip_add(&ctrl->gc, &ath79_gpio_irqchip, 0, 292 - handle_simple_irq, IRQ_TYPE_NONE); 293 - if (err) { 294 - dev_err(&pdev->dev, "failed to add gpiochip_irqchip\n"); 295 - goto gpiochip_remove; 296 - } 297 - 298 - gpiochip_set_chained_irqchip(&ctrl->gc, &ath79_gpio_irqchip, 299 - platform_get_irq(pdev, 0), 300 - ath79_gpio_irq_handler); 301 - 302 - return 0; 303 - 304 - gpiochip_remove: 305 - gpiochip_remove(&ctrl->gc); 306 - return err; 307 - } 308 - 309 - static int ath79_gpio_remove(struct platform_device *pdev) 310 - { 311 - struct ath79_gpio_ctrl *ctrl = platform_get_drvdata(pdev); 312 - 313 - gpiochip_remove(&ctrl->gc); 314 301 return 0; 315 302 } 316 303 ··· 308 319 .of_match_table = ath79_gpio_of_match, 309 320 }, 310 321 .probe = ath79_gpio_probe, 311 - .remove = ath79_gpio_remove, 312 322 }; 313 323 314 324 module_platform_driver(ath79_gpio_driver);
+4 -3
drivers/gpio/gpio-davinci.c
··· 297 297 static void gpio_irq_disable(struct irq_data *d) 298 298 { 299 299 struct davinci_gpio_regs __iomem *g = irq2regs(d); 300 - u32 mask = (u32) irq_data_get_irq_handler_data(d); 300 + uintptr_t mask = (uintptr_t)irq_data_get_irq_handler_data(d); 301 301 302 302 writel_relaxed(mask, &g->clr_falling); 303 303 writel_relaxed(mask, &g->clr_rising); ··· 306 306 static void gpio_irq_enable(struct irq_data *d) 307 307 { 308 308 struct davinci_gpio_regs __iomem *g = irq2regs(d); 309 - u32 mask = (u32) irq_data_get_irq_handler_data(d); 309 + uintptr_t mask = (uintptr_t)irq_data_get_irq_handler_data(d); 310 310 unsigned status = irqd_get_trigger_type(d); 311 311 312 312 status &= IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING; ··· 447 447 "davinci_gpio"); 448 448 irq_set_irq_type(irq, IRQ_TYPE_NONE); 449 449 irq_set_chip_data(irq, (__force void *)g); 450 - irq_set_handler_data(irq, (void *)__gpio_mask(hw)); 450 + irq_set_handler_data(irq, (void *)(uintptr_t)__gpio_mask(hw)); 451 451 452 452 return 0; 453 453 } ··· 632 632 633 633 static const struct of_device_id davinci_gpio_ids[] = { 634 634 { .compatible = "ti,keystone-gpio", keystone_gpio_get_irq_chip}, 635 + { .compatible = "ti,am654-gpio", keystone_gpio_get_irq_chip}, 635 636 { .compatible = "ti,dm6441-gpio", davinci_gpio_get_irq_chip}, 636 637 { /* sentinel */ }, 637 638 };
+2 -7
drivers/gpio/gpio-eic-sprd.c
··· 568 568 const struct sprd_eic_variant_data *pdata; 569 569 struct gpio_irq_chip *irq; 570 570 struct sprd_eic *sprd_eic; 571 - struct resource *res; 572 571 int ret, i; 573 572 574 573 pdata = of_device_get_match_data(&pdev->dev); ··· 596 597 * have one bank EIC, thus base[1] and base[2] can be 597 598 * optional. 598 599 */ 599 - res = platform_get_resource(pdev, IORESOURCE_MEM, i); 600 - if (!res) 601 - continue; 602 - 603 - sprd_eic->base[i] = devm_ioremap_resource(&pdev->dev, res); 600 + sprd_eic->base[i] = devm_platform_ioremap_resource(pdev, i); 604 601 if (IS_ERR(sprd_eic->base[i])) 605 - return PTR_ERR(sprd_eic->base[i]); 602 + continue; 606 603 } 607 604 608 605 sprd_eic->chip.label = sprd_eic_label_name[sprd_eic->type];
+10 -24
drivers/gpio/gpio-em.c
··· 270 270 int ret; 271 271 272 272 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); 273 - if (!p) { 274 - ret = -ENOMEM; 275 - goto err0; 276 - } 273 + if (!p) 274 + return -ENOMEM; 277 275 278 276 p->pdev = pdev; 279 277 platform_set_drvdata(pdev, p); ··· 284 286 285 287 if (!io[0] || !io[1] || !irq[0] || !irq[1]) { 286 288 dev_err(&pdev->dev, "missing IRQ or IOMEM\n"); 287 - ret = -EINVAL; 288 - goto err0; 289 + return -EINVAL; 289 290 } 290 291 291 292 p->base0 = devm_ioremap_nocache(&pdev->dev, io[0]->start, 292 293 resource_size(io[0])); 293 - if (!p->base0) { 294 - dev_err(&pdev->dev, "failed to remap low I/O memory\n"); 295 - ret = -ENXIO; 296 - goto err0; 297 - } 294 + if (!p->base0) 295 + return -ENOMEM; 298 296 299 297 p->base1 = devm_ioremap_nocache(&pdev->dev, io[1]->start, 300 298 resource_size(io[1])); 301 - if (!p->base1) { 302 - dev_err(&pdev->dev, "failed to remap high I/O memory\n"); 303 - ret = -ENXIO; 304 - goto err0; 305 - } 299 + if (!p->base1) 300 + return -ENOMEM; 306 301 307 302 if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) { 308 303 dev_err(&pdev->dev, "Missing ngpios OF property\n"); 309 - ret = -EINVAL; 310 - goto err0; 304 + return -EINVAL; 311 305 } 312 306 313 307 gpio_chip = &p->gpio_chip; ··· 329 339 p->irq_domain = irq_domain_add_simple(pdev->dev.of_node, ngpios, 0, 330 340 &em_gio_irq_domain_ops, p); 331 341 if (!p->irq_domain) { 332 - ret = -ENXIO; 333 342 dev_err(&pdev->dev, "cannot initialize irq domain\n"); 334 - goto err0; 343 + return -ENXIO; 335 344 } 336 345 337 346 if (devm_request_irq(&pdev->dev, irq[0]->start, ··· 347 358 goto err1; 348 359 } 349 360 350 - ret = gpiochip_add_data(gpio_chip, p); 361 + ret = devm_gpiochip_add_data(&pdev->dev, gpio_chip, p); 351 362 if (ret) { 352 363 dev_err(&pdev->dev, "failed to add GPIO controller\n"); 353 364 goto err1; ··· 357 368 358 369 err1: 359 370 irq_domain_remove(p->irq_domain); 360 - err0: 361 371 return ret; 362 372 } 363 373 364 374 static int em_gio_remove(struct platform_device *pdev) 365 375 { 366 376 struct em_gio_priv *p = platform_get_drvdata(pdev); 367 - 368 - gpiochip_remove(&p->gpio_chip); 369 377 370 378 irq_domain_remove(p->irq_domain); 371 379 return 0;
+2 -5
drivers/gpio/gpio-ep93xx.c
··· 393 393 static int ep93xx_gpio_probe(struct platform_device *pdev) 394 394 { 395 395 struct ep93xx_gpio *epg; 396 - struct resource *res; 397 396 int i; 398 - struct device *dev = &pdev->dev; 399 397 400 - epg = devm_kzalloc(dev, sizeof(*epg), GFP_KERNEL); 398 + epg = devm_kzalloc(&pdev->dev, sizeof(*epg), GFP_KERNEL); 401 399 if (!epg) 402 400 return -ENOMEM; 403 401 404 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 405 - epg->base = devm_ioremap_resource(dev, res); 402 + epg->base = devm_platform_ioremap_resource(pdev, 0); 406 403 if (IS_ERR(epg->base)) 407 404 return PTR_ERR(epg->base); 408 405
+19 -16
drivers/gpio/gpio-ftgpio010.c
··· 226 226 { 227 227 struct device *dev = &pdev->dev; 228 228 struct ftgpio_gpio *g; 229 + struct gpio_irq_chip *girq; 229 230 int irq; 230 231 int ret; 231 232 ··· 278 277 if (!IS_ERR(g->clk)) 279 278 g->gc.set_config = ftgpio_gpio_set_config; 280 279 280 + g->irq.name = "FTGPIO010"; 281 + g->irq.irq_ack = ftgpio_gpio_ack_irq; 282 + g->irq.irq_mask = ftgpio_gpio_mask_irq; 283 + g->irq.irq_unmask = ftgpio_gpio_unmask_irq; 284 + g->irq.irq_set_type = ftgpio_gpio_set_irq_type; 285 + 286 + girq = &g->gc.irq; 287 + girq->chip = &g->irq; 288 + girq->parent_handler = ftgpio_gpio_irq_handler; 289 + girq->num_parents = 1; 290 + girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), 291 + GFP_KERNEL); 292 + if (!girq->parents) 293 + return -ENOMEM; 294 + girq->default_type = IRQ_TYPE_NONE; 295 + girq->handler = handle_bad_irq; 296 + girq->parents[0] = irq; 297 + 281 298 ret = devm_gpiochip_add_data(dev, &g->gc, g); 282 299 if (ret) 283 300 goto dis_clk; ··· 307 288 308 289 /* Clear any use of debounce */ 309 290 writel(0x0, g->base + GPIO_DEBOUNCE_EN); 310 - 311 - g->irq.name = "FTGPIO010"; 312 - g->irq.irq_ack = ftgpio_gpio_ack_irq; 313 - g->irq.irq_mask = ftgpio_gpio_mask_irq; 314 - g->irq.irq_unmask = ftgpio_gpio_unmask_irq; 315 - g->irq.irq_set_type = ftgpio_gpio_set_irq_type; 316 - 317 - ret = gpiochip_irqchip_add(&g->gc, &g->irq, 318 - 0, handle_bad_irq, 319 - IRQ_TYPE_NONE); 320 - if (ret) { 321 - dev_info(dev, "could not add irqchip\n"); 322 - goto dis_clk; 323 - } 324 - gpiochip_set_chained_irqchip(&g->gc, &g->irq, 325 - irq, ftgpio_gpio_irq_handler); 326 291 327 292 platform_set_drvdata(pdev, g); 328 293 dev_info(dev, "FTGPIO010 @%p registered\n", g->base);
+1 -3
drivers/gpio/gpio-grgpio.c
··· 329 329 void __iomem *regs; 330 330 struct gpio_chip *gc; 331 331 struct grgpio_priv *priv; 332 - struct resource *res; 333 332 int err; 334 333 u32 prop; 335 334 s32 *irqmap; ··· 339 340 if (!priv) 340 341 return -ENOMEM; 341 342 342 - res = platform_get_resource(ofdev, IORESOURCE_MEM, 0); 343 - regs = devm_ioremap_resource(&ofdev->dev, res); 343 + regs = devm_platform_ioremap_resource(ofdev, 0); 344 344 if (IS_ERR(regs)) 345 345 return PTR_ERR(regs); 346 346
+7 -7
drivers/gpio/gpio-ixp4xx.c
··· 205 205 unsigned long *hwirq, 206 206 unsigned int *type) 207 207 { 208 + int ret; 208 209 209 210 /* We support standard DT translation */ 210 211 if (is_of_node(fwspec->fwnode) && fwspec->param_count == 2) { 211 - *hwirq = fwspec->param[0]; 212 - *type = fwspec->param[1]; 213 - return 0; 212 + return irq_domain_translate_twocell(domain, fwspec, 213 + hwirq, type); 214 214 } 215 215 216 216 /* This goes away when we transition to DT */ 217 217 if (is_fwnode_irqchip(fwspec->fwnode)) { 218 - if (fwspec->param_count != 2) 219 - return -EINVAL; 220 - *hwirq = fwspec->param[0]; 221 - *type = fwspec->param[1]; 218 + ret = irq_domain_translate_twocell(domain, fwspec, 219 + hwirq, type); 220 + if (ret) 221 + return ret; 222 222 WARN_ON(*type == IRQ_TYPE_NONE); 223 223 return 0; 224 224 }
+4 -5
drivers/gpio/gpio-janz-ttl.c
··· 140 140 static int ttl_probe(struct platform_device *pdev) 141 141 { 142 142 struct janz_platform_data *pdata; 143 - struct device *dev = &pdev->dev; 144 143 struct ttl_module *mod; 145 144 struct gpio_chip *gpio; 146 145 int ret; 147 146 148 147 pdata = dev_get_platdata(&pdev->dev); 149 148 if (!pdata) { 150 - dev_err(dev, "no platform data\n"); 149 + dev_err(&pdev->dev, "no platform data\n"); 151 150 return -ENXIO; 152 151 } 153 152 154 - mod = devm_kzalloc(dev, sizeof(*mod), GFP_KERNEL); 153 + mod = devm_kzalloc(&pdev->dev, sizeof(*mod), GFP_KERNEL); 155 154 if (!mod) 156 155 return -ENOMEM; 157 156 ··· 176 177 gpio->base = -1; 177 178 gpio->ngpio = 20; 178 179 179 - ret = devm_gpiochip_add_data(dev, gpio, NULL); 180 + ret = devm_gpiochip_add_data(&pdev->dev, gpio, NULL); 180 181 if (ret) { 181 - dev_err(dev, "unable to add GPIO chip\n"); 182 + dev_err(&pdev->dev, "unable to add GPIO chip\n"); 182 183 return ret; 183 184 } 184 185
+1 -5
drivers/gpio/gpio-madera.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 1 + // SPDX-License-Identifier: GPL-2.0-only 2 2 /* 3 3 * GPIO support for Cirrus Logic Madera codecs 4 4 * 5 5 * Copyright (C) 2015-2018 Cirrus Logic 6 - * 7 - * This program is free software; you can redistribute it and/or modify 8 - * it under the terms of the GNU General Public License as published by the 9 - * Free Software Foundation; version 2. 10 6 */ 11 7 12 8 #include <linux/gpio/driver.h>
+16 -29
drivers/gpio/gpio-max732x.c
··· 649 649 case 0x60: 650 650 chip->client_group_a = client; 651 651 if (nr_port > 8) { 652 - c = i2c_new_dummy(client->adapter, addr_b); 653 - if (!c) { 652 + c = devm_i2c_new_dummy_device(&client->dev, 653 + client->adapter, addr_b); 654 + if (IS_ERR(c)) { 654 655 dev_err(&client->dev, 655 656 "Failed to allocate I2C device\n"); 656 - ret = -ENODEV; 657 - goto out_failed; 657 + return PTR_ERR(c); 658 658 } 659 659 chip->client_group_b = chip->client_dummy = c; 660 660 } ··· 662 662 case 0x50: 663 663 chip->client_group_b = client; 664 664 if (nr_port > 8) { 665 - c = i2c_new_dummy(client->adapter, addr_a); 666 - if (!c) { 665 + c = devm_i2c_new_dummy_device(&client->dev, 666 + client->adapter, addr_a); 667 + if (IS_ERR(c)) { 667 668 dev_err(&client->dev, 668 669 "Failed to allocate I2C device\n"); 669 - ret = -ENODEV; 670 - goto out_failed; 670 + return PTR_ERR(c); 671 671 } 672 672 chip->client_group_a = chip->client_dummy = c; 673 673 } ··· 675 675 default: 676 676 dev_err(&client->dev, "invalid I2C address specified %02x\n", 677 677 client->addr); 678 - ret = -EINVAL; 679 - goto out_failed; 678 + return -EINVAL; 680 679 } 681 680 682 681 if (nr_port > 8 && !chip->client_dummy) { 683 682 dev_err(&client->dev, 684 683 "Failed to allocate second group I2C device\n"); 685 - ret = -ENODEV; 686 - goto out_failed; 684 + return -ENODEV; 687 685 } 688 686 689 687 mutex_init(&chip->lock); 690 688 691 689 ret = max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]); 692 690 if (ret) 693 - goto out_failed; 691 + return ret; 694 692 if (nr_port > 8) { 695 693 ret = max732x_readb(chip, is_group_a(chip, 8), &chip->reg_out[1]); 696 694 if (ret) 697 - goto out_failed; 695 + return ret; 698 696 } 699 697 700 - ret = gpiochip_add_data(&chip->gpio_chip, chip); 698 + ret = devm_gpiochip_add_data(&client->dev, &chip->gpio_chip, chip); 701 699 if (ret) 702 - goto out_failed; 700 + return ret; 703 701 704 702 ret = max732x_irq_setup(chip, id); 705 - if (ret) { 706 - gpiochip_remove(&chip->gpio_chip); 707 - goto out_failed; 708 - } 703 + if (ret) 704 + return ret; 709 705 710 706 if (pdata && pdata->setup) { 711 707 ret = pdata->setup(client, chip->gpio_chip.base, ··· 712 716 713 717 i2c_set_clientdata(client, chip); 714 718 return 0; 715 - 716 - out_failed: 717 - i2c_unregister_device(chip->client_dummy); 718 - return ret; 719 719 } 720 720 721 721 static int max732x_remove(struct i2c_client *client) ··· 730 738 return ret; 731 739 } 732 740 } 733 - 734 - gpiochip_remove(&chip->gpio_chip); 735 - 736 - /* unregister any dummy i2c_client */ 737 - i2c_unregister_device(chip->client_dummy); 738 741 739 742 return 0; 740 743 }
+5 -16
drivers/gpio/gpio-mockup.c
··· 315 315 struct gpio_mockup_chip *chip) 316 316 { 317 317 struct gpio_mockup_dbgfs_private *priv; 318 - struct dentry *evfile; 319 318 struct gpio_chip *gc; 320 319 const char *devname; 321 320 char *name; ··· 324 325 devname = dev_name(&gc->gpiodev->dev); 325 326 326 327 chip->dbg_dir = debugfs_create_dir(devname, gpio_mockup_dbg_dir); 327 - if (IS_ERR_OR_NULL(chip->dbg_dir)) 328 - goto err; 329 328 330 329 for (i = 0; i < gc->ngpio; i++) { 331 330 name = devm_kasprintf(dev, GFP_KERNEL, "%d", i); 332 331 if (!name) 333 - goto err; 332 + return; 334 333 335 334 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 336 335 if (!priv) 337 - goto err; 336 + return; 338 337 339 338 priv->chip = chip; 340 339 priv->offset = i; 341 340 priv->desc = &gc->gpiodev->descs[i]; 342 341 343 - evfile = debugfs_create_file(name, 0200, chip->dbg_dir, priv, 344 - &gpio_mockup_debugfs_ops); 345 - if (IS_ERR_OR_NULL(evfile)) 346 - goto err; 342 + debugfs_create_file(name, 0200, chip->dbg_dir, priv, 343 + &gpio_mockup_debugfs_ops); 347 344 } 348 345 349 346 return; 350 - 351 - err: 352 - dev_err(dev, "error creating debugfs files\n"); 353 347 } 354 348 355 349 static int gpio_mockup_name_lines(struct device *dev, ··· 439 447 if (rv) 440 448 return rv; 441 449 442 - if (!IS_ERR_OR_NULL(gpio_mockup_dbg_dir)) 443 - gpio_mockup_debugfs_setup(dev, chip); 450 + gpio_mockup_debugfs_setup(dev, chip); 444 451 445 452 return 0; 446 453 } ··· 492 501 } 493 502 494 503 gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup", NULL); 495 - if (IS_ERR_OR_NULL(gpio_mockup_dbg_dir)) 496 - gpio_mockup_err("error creating debugfs directory\n"); 497 504 498 505 err = platform_driver_register(&gpio_mockup_driver); 499 506 if (err) {
+4 -7
drivers/gpio/gpio-mvebu.c
··· 38 38 #include <linux/err.h> 39 39 #include <linux/gpio/driver.h> 40 40 #include <linux/gpio/consumer.h> 41 + #include <linux/gpio/machine.h> 41 42 #include <linux/init.h> 42 43 #include <linux/io.h> 43 44 #include <linux/irq.h> ··· 619 618 ret = -EBUSY; 620 619 } else { 621 620 desc = gpiochip_request_own_desc(&mvchip->chip, 622 - pwm->hwpwm, "mvebu-pwm", 0); 621 + pwm->hwpwm, "mvebu-pwm", 622 + GPIO_ACTIVE_HIGH, 623 + GPIOD_OUT_LOW); 623 624 if (IS_ERR(desc)) { 624 625 ret = PTR_ERR(desc); 625 - goto out; 626 - } 627 - 628 - ret = gpiod_direction_output(desc, 0); 629 - if (ret) { 630 - gpiochip_free_own_desc(desc); 631 626 goto out; 632 627 } 633 628
+177 -344
drivers/gpio/gpio-omap.c
··· 44 44 }; 45 45 46 46 struct gpio_bank { 47 - struct list_head node; 48 47 void __iomem *base; 48 + const struct omap_gpio_reg_offs *regs; 49 + 49 50 int irq; 50 51 u32 non_wakeup_gpios; 51 52 u32 enabled_non_wakeup_gpios; ··· 73 72 int context_loss_count; 74 73 75 74 void (*set_dataout)(struct gpio_bank *bank, unsigned gpio, int enable); 76 - void (*set_dataout_multiple)(struct gpio_bank *bank, 77 - unsigned long *mask, unsigned long *bits); 78 75 int (*get_context_loss_count)(struct device *dev); 79 - 80 - struct omap_gpio_reg_offs *regs; 81 76 }; 82 77 83 78 #define GPIO_MOD_CTRL_BIT BIT(0) ··· 89 92 return gpiochip_get_data(chip); 90 93 } 91 94 95 + static inline u32 omap_gpio_rmw(void __iomem *reg, u32 mask, bool set) 96 + { 97 + u32 val = readl_relaxed(reg); 98 + 99 + if (set) 100 + val |= mask; 101 + else 102 + val &= ~mask; 103 + 104 + writel_relaxed(val, reg); 105 + 106 + return val; 107 + } 108 + 92 109 static void omap_set_gpio_direction(struct gpio_bank *bank, int gpio, 93 110 int is_input) 94 111 { 95 - void __iomem *reg = bank->base; 96 - u32 l; 97 - 98 - reg += bank->regs->direction; 99 - l = readl_relaxed(reg); 100 - if (is_input) 101 - l |= BIT(gpio); 102 - else 103 - l &= ~(BIT(gpio)); 104 - writel_relaxed(l, reg); 105 - bank->context.oe = l; 112 + bank->context.oe = omap_gpio_rmw(bank->base + bank->regs->direction, 113 + BIT(gpio), is_input); 106 114 } 107 115 108 116 ··· 133 131 static void omap_set_gpio_dataout_mask(struct gpio_bank *bank, unsigned offset, 134 132 int enable) 135 133 { 136 - void __iomem *reg = bank->base + bank->regs->dataout; 137 - u32 gpio_bit = BIT(offset); 138 - u32 l; 139 - 140 - l = readl_relaxed(reg); 141 - if (enable) 142 - l |= gpio_bit; 143 - else 144 - l &= ~gpio_bit; 145 - writel_relaxed(l, reg); 146 - bank->context.dataout = l; 147 - } 148 - 149 - static int omap_get_gpio_datain(struct gpio_bank *bank, int offset) 150 - { 151 - void __iomem *reg = bank->base + bank->regs->datain; 152 - 153 - return (readl_relaxed(reg) & (BIT(offset))) != 0; 154 - } 155 - 156 - static int omap_get_gpio_dataout(struct gpio_bank *bank, int offset) 157 - { 158 - void __iomem *reg = bank->base + bank->regs->dataout; 159 - 160 - return (readl_relaxed(reg) & (BIT(offset))) != 0; 161 - } 162 - 163 - /* set multiple data out values using dedicate set/clear register */ 164 - static void omap_set_gpio_dataout_reg_multiple(struct gpio_bank *bank, 165 - unsigned long *mask, 166 - unsigned long *bits) 167 - { 168 - void __iomem *reg = bank->base; 169 - u32 l; 170 - 171 - l = *bits & *mask; 172 - writel_relaxed(l, reg + bank->regs->set_dataout); 173 - bank->context.dataout |= l; 174 - 175 - l = ~*bits & *mask; 176 - writel_relaxed(l, reg + bank->regs->clr_dataout); 177 - bank->context.dataout &= ~l; 178 - } 179 - 180 - /* set multiple data out values using mask register */ 181 - static void omap_set_gpio_dataout_mask_multiple(struct gpio_bank *bank, 182 - unsigned long *mask, 183 - unsigned long *bits) 184 - { 185 - void __iomem *reg = bank->base + bank->regs->dataout; 186 - u32 l = (readl_relaxed(reg) & ~*mask) | (*bits & *mask); 187 - 188 - writel_relaxed(l, reg); 189 - bank->context.dataout = l; 190 - } 191 - 192 - static unsigned long omap_get_gpio_datain_multiple(struct gpio_bank *bank, 193 - unsigned long *mask) 194 - { 195 - void __iomem *reg = bank->base + bank->regs->datain; 196 - 197 - return readl_relaxed(reg) & *mask; 198 - } 199 - 200 - static unsigned long omap_get_gpio_dataout_multiple(struct gpio_bank *bank, 201 - unsigned long *mask) 202 - { 203 - void __iomem *reg = bank->base + bank->regs->dataout; 204 - 205 - return readl_relaxed(reg) & *mask; 206 - } 207 - 208 - static inline void omap_gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set) 209 - { 210 - int l = readl_relaxed(base + reg); 211 - 212 - if (set) 213 - l |= mask; 214 - else 215 - l &= ~mask; 216 - 217 - writel_relaxed(l, base + reg); 134 + bank->context.dataout = omap_gpio_rmw(bank->base + bank->regs->dataout, 135 + BIT(offset), enable); 218 136 } 219 137 220 138 static inline void omap_gpio_dbck_enable(struct gpio_bank *bank) ··· 178 256 static int omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset, 179 257 unsigned debounce) 180 258 { 181 - void __iomem *reg; 182 259 u32 val; 183 260 u32 l; 184 261 bool enable = !!debounce; ··· 194 273 l = BIT(offset); 195 274 196 275 clk_enable(bank->dbck); 197 - reg = bank->base + bank->regs->debounce; 198 - writel_relaxed(debounce, reg); 276 + writel_relaxed(debounce, bank->base + bank->regs->debounce); 199 277 200 - reg = bank->base + bank->regs->debounce_en; 201 - val = readl_relaxed(reg); 202 - 203 - if (enable) 204 - val |= l; 205 - else 206 - val &= ~l; 278 + val = omap_gpio_rmw(bank->base + bank->regs->debounce_en, l, enable); 207 279 bank->dbck_enable_mask = val; 208 280 209 - writel_relaxed(val, reg); 210 281 clk_disable(bank->dbck); 211 282 /* 212 283 * Enable debounce clock per module. ··· 273 360 void __iomem *base = bank->base; 274 361 u32 gpio_bit = BIT(gpio); 275 362 276 - omap_gpio_rmw(base, bank->regs->leveldetect0, gpio_bit, 363 + omap_gpio_rmw(base + bank->regs->leveldetect0, gpio_bit, 277 364 trigger & IRQ_TYPE_LEVEL_LOW); 278 - omap_gpio_rmw(base, bank->regs->leveldetect1, gpio_bit, 365 + omap_gpio_rmw(base + bank->regs->leveldetect1, gpio_bit, 279 366 trigger & IRQ_TYPE_LEVEL_HIGH); 280 367 281 368 /* ··· 283 370 * to be woken from idle state. Set the appropriate edge detection 284 371 * in addition to the level detection. 285 372 */ 286 - omap_gpio_rmw(base, bank->regs->risingdetect, gpio_bit, 373 + omap_gpio_rmw(base + bank->regs->risingdetect, gpio_bit, 287 374 trigger & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_HIGH)); 288 - omap_gpio_rmw(base, bank->regs->fallingdetect, gpio_bit, 375 + omap_gpio_rmw(base + bank->regs->fallingdetect, gpio_bit, 289 376 trigger & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)); 290 377 291 378 bank->context.leveldetect0 = ··· 297 384 bank->context.fallingdetect = 298 385 readl_relaxed(bank->base + bank->regs->fallingdetect); 299 386 300 - if (likely(!(bank->non_wakeup_gpios & gpio_bit))) { 301 - omap_gpio_rmw(base, bank->regs->wkup_en, gpio_bit, trigger != 0); 302 - bank->context.wake_en = 303 - readl_relaxed(bank->base + bank->regs->wkup_en); 304 - } 387 + bank->level_mask = bank->context.leveldetect0 | 388 + bank->context.leveldetect1; 305 389 306 390 /* This part needs to be executed always for OMAP{34xx, 44xx} */ 307 391 if (!bank->regs->irqctrl && !omap_gpio_is_off_wakeup_capable(bank, gpio)) { ··· 313 403 else 314 404 bank->enabled_non_wakeup_gpios &= ~gpio_bit; 315 405 } 316 - 317 - bank->level_mask = 318 - readl_relaxed(bank->base + bank->regs->leveldetect0) | 319 - readl_relaxed(bank->base + bank->regs->leveldetect1); 320 406 } 321 407 322 - #ifdef CONFIG_ARCH_OMAP1 323 408 /* 324 409 * This only applies to chips that can't do both rising and falling edge 325 410 * detection at once. For all other chips, this function is a noop. 326 411 */ 327 412 static void omap_toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) 328 413 { 329 - void __iomem *reg = bank->base; 330 - u32 l = 0; 414 + if (IS_ENABLED(CONFIG_ARCH_OMAP1) && bank->regs->irqctrl) { 415 + void __iomem *reg = bank->base + bank->regs->irqctrl; 331 416 332 - if (!bank->regs->irqctrl) 333 - return; 334 - 335 - reg += bank->regs->irqctrl; 336 - 337 - l = readl_relaxed(reg); 338 - if ((l >> gpio) & 1) 339 - l &= ~(BIT(gpio)); 340 - else 341 - l |= BIT(gpio); 342 - 343 - writel_relaxed(l, reg); 417 + writel_relaxed(readl_relaxed(reg) ^ BIT(gpio), reg); 418 + } 344 419 } 345 - #else 346 - static void omap_toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) {} 347 - #endif 348 420 349 421 static int omap_set_gpio_triggering(struct gpio_bank *bank, int gpio, 350 422 unsigned trigger) 351 423 { 352 424 void __iomem *reg = bank->base; 353 - void __iomem *base = bank->base; 354 425 u32 l = 0; 355 426 356 427 if (bank->regs->leveldetect0 && bank->regs->wkup_en) { ··· 363 472 l |= 2 << (gpio << 1); 364 473 if (trigger & IRQ_TYPE_EDGE_FALLING) 365 474 l |= BIT(gpio << 1); 366 - 367 - /* Enable wake-up during idle for dynamic tick */ 368 - omap_gpio_rmw(base, bank->regs->wkup_en, BIT(gpio), trigger); 369 - bank->context.wake_en = 370 - readl_relaxed(bank->base + bank->regs->wkup_en); 371 475 writel_relaxed(l, reg); 372 476 } 373 477 return 0; ··· 391 505 392 506 static void omap_disable_gpio_module(struct gpio_bank *bank, unsigned offset) 393 507 { 394 - void __iomem *base = bank->base; 395 - 396 - if (bank->regs->wkup_en && 397 - !LINE_USED(bank->mod_usage, offset) && 398 - !LINE_USED(bank->irq_usage, offset)) { 399 - /* Disable wake-up during idle for dynamic tick */ 400 - omap_gpio_rmw(base, bank->regs->wkup_en, BIT(offset), 0); 401 - bank->context.wake_en = 402 - readl_relaxed(bank->base + bank->regs->wkup_en); 403 - } 404 - 405 508 if (bank->regs->ctrl && !BANK_USED(bank)) { 406 509 void __iomem *reg = bank->base + bank->regs->ctrl; 407 510 u32 ctrl; ··· 501 626 return l; 502 627 } 503 628 504 - static void omap_enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) 505 - { 506 - void __iomem *reg = bank->base; 507 - u32 l; 508 - 509 - if (bank->regs->set_irqenable) { 510 - reg += bank->regs->set_irqenable; 511 - l = gpio_mask; 512 - bank->context.irqenable1 |= gpio_mask; 513 - } else { 514 - reg += bank->regs->irqenable; 515 - l = readl_relaxed(reg); 516 - if (bank->regs->irqenable_inv) 517 - l &= ~gpio_mask; 518 - else 519 - l |= gpio_mask; 520 - bank->context.irqenable1 = l; 521 - } 522 - 523 - writel_relaxed(l, reg); 524 - } 525 - 526 - static void omap_disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) 527 - { 528 - void __iomem *reg = bank->base; 529 - u32 l; 530 - 531 - if (bank->regs->clr_irqenable) { 532 - reg += bank->regs->clr_irqenable; 533 - l = gpio_mask; 534 - bank->context.irqenable1 &= ~gpio_mask; 535 - } else { 536 - reg += bank->regs->irqenable; 537 - l = readl_relaxed(reg); 538 - if (bank->regs->irqenable_inv) 539 - l |= gpio_mask; 540 - else 541 - l &= ~gpio_mask; 542 - bank->context.irqenable1 = l; 543 - } 544 - 545 - writel_relaxed(l, reg); 546 - } 547 - 548 629 static inline void omap_set_gpio_irqenable(struct gpio_bank *bank, 549 630 unsigned offset, int enable) 550 631 { 551 - if (enable) 552 - omap_enable_gpio_irqbank(bank, BIT(offset)); 553 - else 554 - omap_disable_gpio_irqbank(bank, BIT(offset)); 632 + void __iomem *reg = bank->base; 633 + u32 gpio_mask = BIT(offset); 634 + 635 + if (bank->regs->set_irqenable && bank->regs->clr_irqenable) { 636 + if (enable) { 637 + reg += bank->regs->set_irqenable; 638 + bank->context.irqenable1 |= gpio_mask; 639 + } else { 640 + reg += bank->regs->clr_irqenable; 641 + bank->context.irqenable1 &= ~gpio_mask; 642 + } 643 + writel_relaxed(gpio_mask, reg); 644 + } else { 645 + bank->context.irqenable1 = 646 + omap_gpio_rmw(reg + bank->regs->irqenable, gpio_mask, 647 + enable ^ bank->regs->irqenable_inv); 648 + } 649 + 650 + /* 651 + * Program GPIO wakeup along with IRQ enable to satisfy OMAP4430 TRM 652 + * note requiring correlation between the IRQ enable registers and 653 + * the wakeup registers. In any case, we want wakeup from idle 654 + * enabled for the GPIOs which support this feature. 655 + */ 656 + if (bank->regs->wkup_en && 657 + (bank->regs->edgectrl1 || !(bank->non_wakeup_gpios & gpio_mask))) { 658 + bank->context.wake_en = 659 + omap_gpio_rmw(bank->base + bank->regs->wkup_en, 660 + gpio_mask, enable); 661 + } 555 662 } 556 663 557 664 /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ ··· 542 685 struct gpio_bank *bank = omap_irq_data_get_bank(d); 543 686 544 687 return irq_set_irq_wake(bank->irq, enable); 545 - } 546 - 547 - static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) 548 - { 549 - struct gpio_bank *bank = gpiochip_get_data(chip); 550 - unsigned long flags; 551 - 552 - pm_runtime_get_sync(chip->parent); 553 - 554 - raw_spin_lock_irqsave(&bank->lock, flags); 555 - omap_enable_gpio_module(bank, offset); 556 - bank->mod_usage |= BIT(offset); 557 - raw_spin_unlock_irqrestore(&bank->lock, flags); 558 - 559 - return 0; 560 - } 561 - 562 - static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) 563 - { 564 - struct gpio_bank *bank = gpiochip_get_data(chip); 565 - unsigned long flags; 566 - 567 - raw_spin_lock_irqsave(&bank->lock, flags); 568 - bank->mod_usage &= ~(BIT(offset)); 569 - if (!LINE_USED(bank->irq_usage, offset)) { 570 - omap_set_gpio_direction(bank, offset, 1); 571 - omap_clear_gpio_debounce(bank, offset); 572 - } 573 - omap_disable_gpio_module(bank, offset); 574 - raw_spin_unlock_irqrestore(&bank->lock, flags); 575 - 576 - pm_runtime_put(chip->parent); 577 688 } 578 689 579 690 /* ··· 556 731 static irqreturn_t omap_gpio_irq_handler(int irq, void *gpiobank) 557 732 { 558 733 void __iomem *isr_reg = NULL; 559 - u32 enabled, isr, level_mask; 734 + u32 enabled, isr, edge; 560 735 unsigned int bit; 561 736 struct gpio_bank *bank = gpiobank; 562 737 unsigned long wa_lock_flags; ··· 576 751 enabled = omap_get_gpio_irqbank_mask(bank); 577 752 isr = readl_relaxed(isr_reg) & enabled; 578 753 579 - if (bank->level_mask) 580 - level_mask = bank->level_mask & enabled; 581 - else 582 - level_mask = 0; 583 - 584 - /* clear edge sensitive interrupts before handler(s) are 585 - called so that we don't miss any interrupt occurred while 586 - executing them */ 587 - if (isr & ~level_mask) 588 - omap_clear_gpio_irqbank(bank, isr & ~level_mask); 754 + /* 755 + * Clear edge sensitive interrupts before calling handler(s) 756 + * so subsequent edge transitions are not missed while the 757 + * handlers are running. 758 + */ 759 + edge = isr & ~bank->level_mask; 760 + if (edge) 761 + omap_clear_gpio_irqbank(bank, edge); 589 762 590 763 raw_spin_unlock_irqrestore(&bank->lock, lock_flags); 591 764 ··· 630 807 631 808 if (!LINE_USED(bank->mod_usage, offset)) 632 809 omap_set_gpio_direction(bank, offset, 1); 633 - else if (!omap_gpio_is_input(bank, offset)) 634 - goto err; 635 810 omap_enable_gpio_module(bank, offset); 636 811 bank->irq_usage |= BIT(offset); 637 812 ··· 637 816 omap_gpio_unmask_irq(d); 638 817 639 818 return 0; 640 - err: 641 - raw_spin_unlock_irqrestore(&bank->lock, flags); 642 - return -EINVAL; 643 819 } 644 820 645 821 static void omap_gpio_irq_shutdown(struct irq_data *d) ··· 647 829 648 830 raw_spin_lock_irqsave(&bank->lock, flags); 649 831 bank->irq_usage &= ~(BIT(offset)); 650 - omap_set_gpio_irqenable(bank, offset, 0); 651 - omap_clear_gpio_irqstatus(bank, offset); 652 832 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); 833 + omap_clear_gpio_irqstatus(bank, offset); 834 + omap_set_gpio_irqenable(bank, offset, 0); 653 835 if (!LINE_USED(bank->mod_usage, offset)) 654 836 omap_clear_gpio_debounce(bank, offset); 655 837 omap_disable_gpio_module(bank, offset); ··· 670 852 pm_runtime_put(bank->chip.parent); 671 853 } 672 854 673 - static void omap_gpio_ack_irq(struct irq_data *d) 674 - { 675 - struct gpio_bank *bank = omap_irq_data_get_bank(d); 676 - unsigned offset = d->hwirq; 677 - 678 - omap_clear_gpio_irqstatus(bank, offset); 679 - } 680 - 681 855 static void omap_gpio_mask_irq(struct irq_data *d) 682 856 { 683 857 struct gpio_bank *bank = omap_irq_data_get_bank(d); ··· 677 867 unsigned long flags; 678 868 679 869 raw_spin_lock_irqsave(&bank->lock, flags); 680 - omap_set_gpio_irqenable(bank, offset, 0); 681 870 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); 871 + omap_set_gpio_irqenable(bank, offset, 0); 682 872 raw_spin_unlock_irqrestore(&bank->lock, flags); 683 873 } 684 874 ··· 690 880 unsigned long flags; 691 881 692 882 raw_spin_lock_irqsave(&bank->lock, flags); 693 - if (trigger) 694 - omap_set_gpio_triggering(bank, offset, trigger); 695 - 696 883 omap_set_gpio_irqenable(bank, offset, 1); 697 884 698 885 /* ··· 697 890 * is cleared, thus after the handler has run. OMAP4 needs this done 698 891 * after enabing the interrupt to clear the wakeup status. 699 892 */ 700 - if (bank->level_mask & BIT(offset)) 893 + if (bank->regs->leveldetect0 && bank->regs->wkup_en && 894 + trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) 701 895 omap_clear_gpio_irqstatus(bank, offset); 896 + 897 + if (trigger) 898 + omap_set_gpio_triggering(bank, offset, trigger); 702 899 703 900 raw_spin_unlock_irqrestore(&bank->lock, flags); 704 901 } ··· 769 958 770 959 /*---------------------------------------------------------------------*/ 771 960 961 + static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) 962 + { 963 + struct gpio_bank *bank = gpiochip_get_data(chip); 964 + unsigned long flags; 965 + 966 + pm_runtime_get_sync(chip->parent); 967 + 968 + raw_spin_lock_irqsave(&bank->lock, flags); 969 + omap_enable_gpio_module(bank, offset); 970 + bank->mod_usage |= BIT(offset); 971 + raw_spin_unlock_irqrestore(&bank->lock, flags); 972 + 973 + return 0; 974 + } 975 + 976 + static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) 977 + { 978 + struct gpio_bank *bank = gpiochip_get_data(chip); 979 + unsigned long flags; 980 + 981 + raw_spin_lock_irqsave(&bank->lock, flags); 982 + bank->mod_usage &= ~(BIT(offset)); 983 + if (!LINE_USED(bank->irq_usage, offset)) { 984 + omap_set_gpio_direction(bank, offset, 1); 985 + omap_clear_gpio_debounce(bank, offset); 986 + } 987 + omap_disable_gpio_module(bank, offset); 988 + raw_spin_unlock_irqrestore(&bank->lock, flags); 989 + 990 + pm_runtime_put(chip->parent); 991 + } 992 + 772 993 static int omap_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 773 994 { 774 - struct gpio_bank *bank; 775 - unsigned long flags; 776 - void __iomem *reg; 777 - int dir; 995 + struct gpio_bank *bank = gpiochip_get_data(chip); 778 996 779 - bank = gpiochip_get_data(chip); 780 - reg = bank->base + bank->regs->direction; 781 - raw_spin_lock_irqsave(&bank->lock, flags); 782 - dir = !!(readl_relaxed(reg) & BIT(offset)); 783 - raw_spin_unlock_irqrestore(&bank->lock, flags); 784 - return dir; 997 + return !!(readl_relaxed(bank->base + bank->regs->direction) & 998 + BIT(offset)); 785 999 } 786 1000 787 1001 static int omap_gpio_input(struct gpio_chip *chip, unsigned offset) ··· 823 987 824 988 static int omap_gpio_get(struct gpio_chip *chip, unsigned offset) 825 989 { 826 - struct gpio_bank *bank; 827 - 828 - bank = gpiochip_get_data(chip); 990 + struct gpio_bank *bank = gpiochip_get_data(chip); 991 + void __iomem *reg; 829 992 830 993 if (omap_gpio_is_input(bank, offset)) 831 - return omap_get_gpio_datain(bank, offset); 994 + reg = bank->base + bank->regs->datain; 832 995 else 833 - return omap_get_gpio_dataout(bank, offset); 996 + reg = bank->base + bank->regs->dataout; 997 + 998 + return (readl_relaxed(reg) & BIT(offset)) != 0; 834 999 } 835 1000 836 1001 static int omap_gpio_output(struct gpio_chip *chip, unsigned offset, int value) ··· 851 1014 unsigned long *bits) 852 1015 { 853 1016 struct gpio_bank *bank = gpiochip_get_data(chip); 854 - void __iomem *reg = bank->base + bank->regs->direction; 855 - unsigned long in = readl_relaxed(reg), l; 1017 + void __iomem *base = bank->base; 1018 + u32 direction, m, val = 0; 856 1019 857 - *bits = 0; 1020 + direction = readl_relaxed(base + bank->regs->direction); 858 1021 859 - l = in & *mask; 860 - if (l) 861 - *bits |= omap_get_gpio_datain_multiple(bank, &l); 1022 + m = direction & *mask; 1023 + if (m) 1024 + val |= readl_relaxed(base + bank->regs->datain) & m; 862 1025 863 - l = ~in & *mask; 864 - if (l) 865 - *bits |= omap_get_gpio_dataout_multiple(bank, &l); 1026 + m = ~direction & *mask; 1027 + if (m) 1028 + val |= readl_relaxed(base + bank->regs->dataout) & m; 1029 + 1030 + *bits = val; 866 1031 867 1032 return 0; 868 1033 } ··· 917 1078 unsigned long *bits) 918 1079 { 919 1080 struct gpio_bank *bank = gpiochip_get_data(chip); 1081 + void __iomem *reg = bank->base + bank->regs->dataout; 920 1082 unsigned long flags; 1083 + u32 l; 921 1084 922 1085 raw_spin_lock_irqsave(&bank->lock, flags); 923 - bank->set_dataout_multiple(bank, mask, bits); 1086 + l = (readl_relaxed(reg) & ~*mask) | (*bits & *mask); 1087 + writel_relaxed(l, reg); 1088 + bank->context.dataout = l; 924 1089 raw_spin_unlock_irqrestore(&bank->lock, flags); 925 1090 } 926 1091 ··· 958 1115 return; 959 1116 } 960 1117 961 - omap_gpio_rmw(base, bank->regs->irqenable, l, 1118 + omap_gpio_rmw(base + bank->regs->irqenable, l, 962 1119 bank->regs->irqenable_inv); 963 - omap_gpio_rmw(base, bank->regs->irqstatus, l, 1120 + omap_gpio_rmw(base + bank->regs->irqstatus, l, 964 1121 !bank->regs->irqenable_inv); 965 1122 if (bank->regs->debounce_en) 966 1123 writel_relaxed(0, base + bank->regs->debounce_en); ··· 1023 1180 #endif 1024 1181 1025 1182 /* MPUIO is a bit different, reading IRQ status clears it */ 1026 - if (bank->is_mpuio) { 1027 - irqc->irq_ack = dummy_irq_chip.irq_ack; 1028 - if (!bank->regs->wkup_en) 1029 - irqc->irq_set_wake = NULL; 1030 - } 1183 + if (bank->is_mpuio && !bank->regs->wkup_en) 1184 + irqc->irq_set_wake = NULL; 1031 1185 1032 1186 irq = &bank->chip.irq; 1033 1187 irq->chip = irqc; ··· 1055 1215 1056 1216 static void omap_gpio_init_context(struct gpio_bank *p) 1057 1217 { 1058 - struct omap_gpio_reg_offs *regs = p->regs; 1218 + const struct omap_gpio_reg_offs *regs = p->regs; 1059 1219 void __iomem *base = p->base; 1060 1220 1061 1221 p->context.ctrl = readl_relaxed(base + regs->ctrl); ··· 1067 1227 p->context.fallingdetect = readl_relaxed(base + regs->fallingdetect); 1068 1228 p->context.irqenable1 = readl_relaxed(base + regs->irqenable); 1069 1229 p->context.irqenable2 = readl_relaxed(base + regs->irqenable2); 1070 - 1071 - if (regs->set_dataout && p->regs->clr_dataout) 1072 - p->context.dataout = readl_relaxed(base + regs->set_dataout); 1073 - else 1074 - p->context.dataout = readl_relaxed(base + regs->dataout); 1230 + p->context.dataout = readl_relaxed(base + regs->dataout); 1075 1231 1076 1232 p->context_valid = true; 1077 1233 } 1078 1234 1079 1235 static void omap_gpio_restore_context(struct gpio_bank *bank) 1080 1236 { 1081 - writel_relaxed(bank->context.wake_en, 1082 - bank->base + bank->regs->wkup_en); 1083 - writel_relaxed(bank->context.ctrl, bank->base + bank->regs->ctrl); 1084 - writel_relaxed(bank->context.leveldetect0, 1085 - bank->base + bank->regs->leveldetect0); 1086 - writel_relaxed(bank->context.leveldetect1, 1087 - bank->base + bank->regs->leveldetect1); 1088 - writel_relaxed(bank->context.risingdetect, 1089 - bank->base + bank->regs->risingdetect); 1090 - writel_relaxed(bank->context.fallingdetect, 1091 - bank->base + bank->regs->fallingdetect); 1092 - if (bank->regs->set_dataout && bank->regs->clr_dataout) 1093 - writel_relaxed(bank->context.dataout, 1094 - bank->base + bank->regs->set_dataout); 1095 - else 1096 - writel_relaxed(bank->context.dataout, 1097 - bank->base + bank->regs->dataout); 1098 - writel_relaxed(bank->context.oe, bank->base + bank->regs->direction); 1237 + const struct omap_gpio_reg_offs *regs = bank->regs; 1238 + void __iomem *base = bank->base; 1239 + 1240 + writel_relaxed(bank->context.wake_en, base + regs->wkup_en); 1241 + writel_relaxed(bank->context.ctrl, base + regs->ctrl); 1242 + writel_relaxed(bank->context.leveldetect0, base + regs->leveldetect0); 1243 + writel_relaxed(bank->context.leveldetect1, base + regs->leveldetect1); 1244 + writel_relaxed(bank->context.risingdetect, base + regs->risingdetect); 1245 + writel_relaxed(bank->context.fallingdetect, base + regs->fallingdetect); 1246 + writel_relaxed(bank->context.dataout, base + regs->dataout); 1247 + writel_relaxed(bank->context.oe, base + regs->direction); 1099 1248 1100 1249 if (bank->dbck_enable_mask) { 1101 - writel_relaxed(bank->context.debounce, bank->base + 1102 - bank->regs->debounce); 1250 + writel_relaxed(bank->context.debounce, base + regs->debounce); 1103 1251 writel_relaxed(bank->context.debounce_en, 1104 - bank->base + bank->regs->debounce_en); 1252 + base + regs->debounce_en); 1105 1253 } 1106 1254 1107 - writel_relaxed(bank->context.irqenable1, 1108 - bank->base + bank->regs->irqenable); 1109 - writel_relaxed(bank->context.irqenable2, 1110 - bank->base + bank->regs->irqenable2); 1255 + writel_relaxed(bank->context.irqenable1, base + regs->irqenable); 1256 + writel_relaxed(bank->context.irqenable2, base + regs->irqenable2); 1111 1257 } 1112 1258 1113 1259 static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context) 1114 1260 { 1115 1261 struct device *dev = bank->chip.parent; 1116 1262 void __iomem *base = bank->base; 1117 - u32 nowake; 1263 + u32 mask, nowake; 1118 1264 1119 1265 bank->saved_datain = readl_relaxed(base + bank->regs->datain); 1120 1266 1121 1267 if (!bank->enabled_non_wakeup_gpios) 1122 1268 goto update_gpio_context_count; 1269 + 1270 + /* Check for pending EDGE_FALLING, ignore EDGE_BOTH */ 1271 + mask = bank->enabled_non_wakeup_gpios & bank->context.fallingdetect; 1272 + mask &= ~bank->context.risingdetect; 1273 + bank->saved_datain |= mask; 1274 + 1275 + /* Check for pending EDGE_RISING, ignore EDGE_BOTH */ 1276 + mask = bank->enabled_non_wakeup_gpios & bank->context.risingdetect; 1277 + mask &= ~bank->context.fallingdetect; 1278 + bank->saved_datain &= ~mask; 1123 1279 1124 1280 if (!may_lose_context) 1125 1281 goto update_gpio_context_count; ··· 1127 1291 */ 1128 1292 if (!bank->loses_context && bank->enabled_non_wakeup_gpios) { 1129 1293 nowake = bank->enabled_non_wakeup_gpios; 1130 - omap_gpio_rmw(base, bank->regs->fallingdetect, nowake, ~nowake); 1131 - omap_gpio_rmw(base, bank->regs->risingdetect, nowake, ~nowake); 1294 + omap_gpio_rmw(base + bank->regs->fallingdetect, nowake, ~nowake); 1295 + omap_gpio_rmw(base + bank->regs->risingdetect, nowake, ~nowake); 1132 1296 } 1133 1297 1134 1298 update_gpio_context_count: ··· 1257 1421 return NOTIFY_OK; 1258 1422 } 1259 1423 1260 - static struct omap_gpio_reg_offs omap2_gpio_regs = { 1424 + static const struct omap_gpio_reg_offs omap2_gpio_regs = { 1261 1425 .revision = OMAP24XX_GPIO_REVISION, 1262 1426 .direction = OMAP24XX_GPIO_OE, 1263 1427 .datain = OMAP24XX_GPIO_DATAIN, ··· 1280 1444 .fallingdetect = OMAP24XX_GPIO_FALLINGDETECT, 1281 1445 }; 1282 1446 1283 - static struct omap_gpio_reg_offs omap4_gpio_regs = { 1447 + static const struct omap_gpio_reg_offs omap4_gpio_regs = { 1284 1448 .revision = OMAP4_GPIO_REVISION, 1285 1449 .direction = OMAP4_GPIO_OE, 1286 1450 .datain = OMAP4_GPIO_DATAIN, ··· 1289 1453 .clr_dataout = OMAP4_GPIO_CLEARDATAOUT, 1290 1454 .irqstatus = OMAP4_GPIO_IRQSTATUS0, 1291 1455 .irqstatus2 = OMAP4_GPIO_IRQSTATUS1, 1456 + .irqstatus_raw0 = OMAP4_GPIO_IRQSTATUSRAW0, 1457 + .irqstatus_raw1 = OMAP4_GPIO_IRQSTATUSRAW1, 1292 1458 .irqenable = OMAP4_GPIO_IRQSTATUSSET0, 1293 1459 .irqenable2 = OMAP4_GPIO_IRQSTATUSSET1, 1294 1460 .set_irqenable = OMAP4_GPIO_IRQSTATUSSET0, ··· 1366 1528 1367 1529 irqc->irq_startup = omap_gpio_irq_startup, 1368 1530 irqc->irq_shutdown = omap_gpio_irq_shutdown, 1369 - irqc->irq_ack = omap_gpio_ack_irq, 1531 + irqc->irq_ack = dummy_irq_chip.irq_ack, 1370 1532 irqc->irq_mask = omap_gpio_mask_irq, 1371 1533 irqc->irq_unmask = omap_gpio_unmask_irq, 1372 1534 irqc->irq_set_type = omap_gpio_irq_type, ··· 1410 1572 pdata->get_context_loss_count; 1411 1573 } 1412 1574 1413 - if (bank->regs->set_dataout && bank->regs->clr_dataout) { 1575 + if (bank->regs->set_dataout && bank->regs->clr_dataout) 1414 1576 bank->set_dataout = omap_set_gpio_dataout_reg; 1415 - bank->set_dataout_multiple = omap_set_gpio_dataout_reg_multiple; 1416 - } else { 1577 + else 1417 1578 bank->set_dataout = omap_set_gpio_dataout_mask; 1418 - bank->set_dataout_multiple = 1419 - omap_set_gpio_dataout_mask_multiple; 1420 - } 1421 1579 1422 1580 raw_spin_lock_init(&bank->lock); 1423 1581 raw_spin_lock_init(&bank->wa_lock); ··· 1469 1635 struct gpio_bank *bank = platform_get_drvdata(pdev); 1470 1636 1471 1637 cpu_pm_unregister_notifier(&bank->nb); 1472 - list_del(&bank->node); 1473 1638 gpiochip_remove(&bank->chip); 1474 1639 pm_runtime_disable(&pdev->dev); 1475 1640 if (bank->dbck_flag)
+1
drivers/gpio/gpio-pca953x.c
··· 1178 1178 { .compatible = "ti,tca6408", .data = OF_953X( 8, PCA_INT), }, 1179 1179 { .compatible = "ti,tca6416", .data = OF_953X(16, PCA_INT), }, 1180 1180 { .compatible = "ti,tca6424", .data = OF_953X(24, PCA_INT), }, 1181 + { .compatible = "ti,tca9539", .data = OF_953X(16, PCA_INT), }, 1181 1182 1182 1183 { .compatible = "onnn,cat9554", .data = OF_953X( 8, PCA_INT), }, 1183 1184 { .compatible = "onnn,pca9654", .data = OF_953X( 8, PCA_INT), },
+16 -14
drivers/gpio/gpio-pl061.c
··· 283 283 { 284 284 struct device *dev = &adev->dev; 285 285 struct pl061 *pl061; 286 + struct gpio_irq_chip *girq; 286 287 int ret, irq; 287 288 288 289 pl061 = devm_kzalloc(dev, sizeof(*pl061), GFP_KERNEL); ··· 311 310 pl061->gc.parent = dev; 312 311 pl061->gc.owner = THIS_MODULE; 313 312 314 - ret = gpiochip_add_data(&pl061->gc, pl061); 315 - if (ret) 316 - return ret; 317 - 318 313 /* 319 314 * irq_chip support 320 315 */ ··· 329 332 } 330 333 pl061->parent_irq = irq; 331 334 332 - ret = gpiochip_irqchip_add(&pl061->gc, &pl061->irq_chip, 333 - 0, handle_bad_irq, 334 - IRQ_TYPE_NONE); 335 - if (ret) { 336 - dev_info(&adev->dev, "could not add irqchip\n"); 335 + girq = &pl061->gc.irq; 336 + girq->chip = &pl061->irq_chip; 337 + girq->parent_handler = pl061_irq_handler; 338 + girq->num_parents = 1; 339 + girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), 340 + GFP_KERNEL); 341 + if (!girq->parents) 342 + return -ENOMEM; 343 + girq->parents[0] = irq; 344 + girq->default_type = IRQ_TYPE_NONE; 345 + girq->handler = handle_bad_irq; 346 + 347 + ret = devm_gpiochip_add_data(dev, &pl061->gc, pl061); 348 + if (ret) 337 349 return ret; 338 - } 339 - gpiochip_set_chained_irqchip(&pl061->gc, &pl061->irq_chip, 340 - irq, pl061_irq_handler); 341 350 342 351 amba_set_drvdata(adev, pl061); 343 - dev_info(&adev->dev, "PL061 GPIO chip @%pa registered\n", 344 - &adev->res.start); 352 + dev_info(dev, "PL061 GPIO chip registered\n"); 345 353 346 354 return 0; 347 355 }
+1 -1
drivers/gpio/gpio-rcar.c
··· 489 489 irq_chip->irq_unmask = gpio_rcar_irq_enable; 490 490 irq_chip->irq_set_type = gpio_rcar_irq_set_type; 491 491 irq_chip->irq_set_wake = gpio_rcar_irq_set_wake; 492 - irq_chip->flags = IRQCHIP_SET_TYPE_MASKED | IRQCHIP_MASK_ON_SUSPEND; 492 + irq_chip->flags = IRQCHIP_SET_TYPE_MASKED | IRQCHIP_MASK_ON_SUSPEND; 493 493 494 494 ret = gpiochip_add_data(gpio_chip, p); 495 495 if (ret) {
+13 -38
drivers/gpio/gpio-siox.c
··· 211 211 static int gpio_siox_probe(struct siox_device *sdevice) 212 212 { 213 213 struct gpio_siox_ddata *ddata; 214 + struct gpio_irq_chip *girq; 215 + struct device *dev = &sdevice->dev; 214 216 int ret; 215 217 216 - ddata = devm_kzalloc(&sdevice->dev, sizeof(*ddata), GFP_KERNEL); 218 + ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); 217 219 if (!ddata) 218 220 return -ENOMEM; 219 221 220 - dev_set_drvdata(&sdevice->dev, ddata); 222 + dev_set_drvdata(dev, ddata); 221 223 222 224 mutex_init(&ddata->lock); 223 225 spin_lock_init(&ddata->irqlock); 224 226 225 227 ddata->gchip.base = -1; 226 228 ddata->gchip.can_sleep = 1; 227 - ddata->gchip.parent = &sdevice->dev; 229 + ddata->gchip.parent = dev; 228 230 ddata->gchip.owner = THIS_MODULE; 229 231 ddata->gchip.get = gpio_siox_get; 230 232 ddata->gchip.set = gpio_siox_set; ··· 241 239 ddata->ichip.irq_unmask = gpio_siox_irq_unmask; 242 240 ddata->ichip.irq_set_type = gpio_siox_irq_set_type; 243 241 244 - ret = gpiochip_add(&ddata->gchip); 245 - if (ret) { 246 - dev_err(&sdevice->dev, 247 - "Failed to register gpio chip (%d)\n", ret); 248 - goto err_gpiochip; 249 - } 242 + girq = &ddata->gchip.irq; 243 + girq->chip = &ddata->ichip; 244 + girq->default_type = IRQ_TYPE_NONE; 245 + girq->handler = handle_level_irq; 250 246 251 - ret = gpiochip_irqchip_add(&ddata->gchip, &ddata->ichip, 252 - 0, handle_level_irq, IRQ_TYPE_EDGE_RISING); 253 - if (ret) { 254 - dev_err(&sdevice->dev, 255 - "Failed to register irq chip (%d)\n", ret); 256 - err_gpiochip: 257 - gpiochip_remove(&ddata->gchip); 258 - } 247 + ret = devm_gpiochip_add_data(dev, &ddata->gchip, NULL); 248 + if (ret) 249 + dev_err(dev, "Failed to register gpio chip (%d)\n", ret); 259 250 260 251 return ret; 261 252 } 262 253 263 - static int gpio_siox_remove(struct siox_device *sdevice) 264 - { 265 - struct gpio_siox_ddata *ddata = dev_get_drvdata(&sdevice->dev); 266 - 267 - gpiochip_remove(&ddata->gchip); 268 - return 0; 269 - } 270 - 271 254 static struct siox_driver gpio_siox_driver = { 272 255 .probe = gpio_siox_probe, 273 - .remove = gpio_siox_remove, 274 256 .set_data = gpio_siox_set_data, 275 257 .get_data = gpio_siox_get_data, 276 258 .driver = { 277 259 .name = "gpio-siox", 278 260 }, 279 261 }; 280 - 281 - static int __init gpio_siox_init(void) 282 - { 283 - return siox_driver_register(&gpio_siox_driver); 284 - } 285 - module_init(gpio_siox_init); 286 - 287 - static void __exit gpio_siox_exit(void) 288 - { 289 - siox_driver_unregister(&gpio_siox_driver); 290 - } 291 - module_exit(gpio_siox_exit); 262 + module_siox_driver(gpio_siox_driver); 292 263 293 264 MODULE_AUTHOR("Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>"); 294 265 MODULE_DESCRIPTION("SIOX gpio driver");
+17 -16
drivers/gpio/gpio-stp-xway.c
··· 15 15 #include <linux/clk.h> 16 16 #include <linux/err.h> 17 17 18 - #include <lantiq_soc.h> 19 - 20 18 /* 21 19 * The Serial To Parallel (STP) is found on MIPS based Lantiq socs. It is a 22 20 * peripheral controller used to drive external shift register cascades. At most ··· 69 71 #define xway_stp_r32(m, reg) __raw_readl(m + reg) 70 72 #define xway_stp_w32(m, val, reg) __raw_writel(val, m + reg) 71 73 #define xway_stp_w32_mask(m, clear, set, reg) \ 72 - ltq_w32((ltq_r32(m + reg) & ~(clear)) | (set), \ 73 - m + reg) 74 + xway_stp_w32(m, (xway_stp_r32(m, reg) & ~(clear)) | (set), reg) 74 75 75 76 struct xway_stp { 76 77 struct gpio_chip gc; ··· 153 156 154 157 /** 155 158 * xway_stp_hw_init() - Configure the STP unit and enable the clock gate 156 - * @virt: pointer to the remapped register range 159 + * @chip: Pointer to the xway_stp chip structure 157 160 */ 158 - static int xway_stp_hw_init(struct xway_stp *chip) 161 + static void xway_stp_hw_init(struct xway_stp *chip) 159 162 { 160 163 /* sane defaults */ 161 164 xway_stp_w32(chip->virt, 0, XWAY_STP_AR); ··· 198 201 if (chip->reserved) 199 202 xway_stp_w32_mask(chip->virt, XWAY_STP_UPD_MASK, 200 203 XWAY_STP_UPD_FPI, XWAY_STP_CON1); 201 - 202 - return 0; 203 204 } 204 205 205 206 static int xway_stp_probe(struct platform_device *pdev) ··· 253 258 if (!of_find_property(pdev->dev.of_node, "lantiq,rising", NULL)) 254 259 chip->edge = XWAY_STP_FALLING; 255 260 256 - clk = clk_get(&pdev->dev, NULL); 261 + clk = devm_clk_get(&pdev->dev, NULL); 257 262 if (IS_ERR(clk)) { 258 263 dev_err(&pdev->dev, "Failed to get clock\n"); 259 264 return PTR_ERR(clk); 260 265 } 261 - clk_enable(clk); 262 266 263 - ret = xway_stp_hw_init(chip); 264 - if (!ret) 265 - ret = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip); 267 + ret = clk_prepare_enable(clk); 268 + if (ret) 269 + return ret; 266 270 267 - if (!ret) 268 - dev_info(&pdev->dev, "Init done\n"); 271 + xway_stp_hw_init(chip); 269 272 270 - return ret; 273 + ret = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip); 274 + if (ret) { 275 + clk_disable_unprepare(clk); 276 + return ret; 277 + } 278 + 279 + dev_info(&pdev->dev, "Init done\n"); 280 + 281 + return 0; 271 282 } 272 283 273 284 static const struct of_device_id xway_stp_match[] = {
+2 -2
drivers/gpio/gpio-tegra.c
··· 541 541 542 542 static void tegra_gpio_debuginit(struct tegra_gpio_info *tgi) 543 543 { 544 - (void) debugfs_create_file("tegra_gpio", 0444, 545 - NULL, tgi, &tegra_dbg_gpio_fops); 544 + debugfs_create_file("tegra_gpio", 0444, NULL, tgi, 545 + &tegra_dbg_gpio_fops); 546 546 } 547 547 548 548 #else
+8 -6
drivers/gpio/gpio-vf610.c
··· 265 265 return port->irq; 266 266 267 267 port->clk_port = devm_clk_get(dev, "port"); 268 - if (!IS_ERR(port->clk_port)) { 268 + ret = PTR_ERR_OR_ZERO(port->clk_port); 269 + if (!ret) { 269 270 ret = clk_prepare_enable(port->clk_port); 270 271 if (ret) 271 272 return ret; ··· 274 273 port->clk_port); 275 274 if (ret) 276 275 return ret; 277 - } else if (port->clk_port == ERR_PTR(-EPROBE_DEFER)) { 276 + } else if (ret == -EPROBE_DEFER) { 278 277 /* 279 278 * Percolate deferrals, for anything else, 280 279 * just live without the clocking. 281 280 */ 282 - return PTR_ERR(port->clk_port); 281 + return ret; 283 282 } 284 283 285 284 port->clk_gpio = devm_clk_get(dev, "gpio"); 286 - if (!IS_ERR(port->clk_gpio)) { 285 + ret = PTR_ERR_OR_ZERO(port->clk_gpio); 286 + if (!ret) { 287 287 ret = clk_prepare_enable(port->clk_gpio); 288 288 if (ret) 289 289 return ret; ··· 292 290 port->clk_gpio); 293 291 if (ret) 294 292 return ret; 295 - } else if (port->clk_gpio == ERR_PTR(-EPROBE_DEFER)) { 296 - return PTR_ERR(port->clk_gpio); 293 + } else if (ret == -EPROBE_DEFER) { 294 + return ret; 297 295 } 298 296 299 297 gc = &port->gc;
+5 -14
drivers/gpio/gpio-vr41xx.c
··· 467 467 468 468 static int giu_probe(struct platform_device *pdev) 469 469 { 470 - struct resource *res; 471 470 unsigned int trigger, i, pin; 472 471 struct irq_chip *chip; 473 - int irq, ret; 472 + int irq; 474 473 475 474 switch (pdev->id) { 476 475 case GPIO_50PINS_PULLUPDOWN: ··· 488 489 return -ENODEV; 489 490 } 490 491 491 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 492 - if (!res) 493 - return -EBUSY; 494 - 495 - giu_base = ioremap(res->start, resource_size(res)); 496 - if (!giu_base) 497 - return -ENOMEM; 492 + giu_base = devm_platform_ioremap_resource(pdev, 0); 493 + if (IS_ERR(giu_base)) 494 + return PTR_ERR(giu_base); 498 495 499 496 vr41xx_gpio_chip.parent = &pdev->dev; 500 497 501 - ret = gpiochip_add_data(&vr41xx_gpio_chip, NULL); 502 - if (!ret) { 503 - iounmap(giu_base); 498 + if (gpiochip_add_data(&vr41xx_gpio_chip, NULL)) 504 499 return -ENODEV; 505 - } 506 500 507 501 giu_write(GIUINTENL, 0); 508 502 giu_write(GIUINTENH, 0); ··· 526 534 static int giu_remove(struct platform_device *pdev) 527 535 { 528 536 if (giu_base) { 529 - iounmap(giu_base); 530 537 giu_base = NULL; 531 538 } 532 539
+36 -54
drivers/gpio/gpio-xilinx.c
··· 11 11 #include <linux/module.h> 12 12 #include <linux/of_device.h> 13 13 #include <linux/of_platform.h> 14 - #include <linux/of_gpio.h> 15 14 #include <linux/io.h> 16 15 #include <linux/gpio/driver.h> 17 16 #include <linux/slab.h> ··· 32 33 33 34 /** 34 35 * struct xgpio_instance - Stores information about GPIO device 35 - * @mmchip: OF GPIO chip for memory mapped banks 36 + * @gc: GPIO chip 37 + * @regs: register block 36 38 * @gpio_width: GPIO width for every channel 37 39 * @gpio_state: GPIO state shadow register 38 40 * @gpio_dir: GPIO direction shadow register 39 41 * @gpio_lock: Lock used for synchronization 40 42 */ 41 43 struct xgpio_instance { 42 - struct of_mm_gpio_chip mmchip; 44 + struct gpio_chip gc; 45 + void __iomem *regs; 43 46 unsigned int gpio_width[2]; 44 47 u32 gpio_state[2]; 45 48 u32 gpio_dir[2]; ··· 85 84 */ 86 85 static int xgpio_get(struct gpio_chip *gc, unsigned int gpio) 87 86 { 88 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 89 87 struct xgpio_instance *chip = gpiochip_get_data(gc); 90 88 u32 val; 91 89 92 - val = xgpio_readreg(mm_gc->regs + XGPIO_DATA_OFFSET + 90 + val = xgpio_readreg(chip->regs + XGPIO_DATA_OFFSET + 93 91 xgpio_regoffset(chip, gpio)); 94 92 95 93 return !!(val & BIT(xgpio_offset(chip, gpio))); ··· 106 106 static void xgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 107 107 { 108 108 unsigned long flags; 109 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 110 109 struct xgpio_instance *chip = gpiochip_get_data(gc); 111 110 int index = xgpio_index(chip, gpio); 112 111 int offset = xgpio_offset(chip, gpio); ··· 118 119 else 119 120 chip->gpio_state[index] &= ~BIT(offset); 120 121 121 - xgpio_writereg(mm_gc->regs + XGPIO_DATA_OFFSET + 122 + xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + 122 123 xgpio_regoffset(chip, gpio), chip->gpio_state[index]); 123 124 124 125 spin_unlock_irqrestore(&chip->gpio_lock[index], flags); ··· 137 138 unsigned long *bits) 138 139 { 139 140 unsigned long flags; 140 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 141 141 struct xgpio_instance *chip = gpiochip_get_data(gc); 142 142 int index = xgpio_index(chip, 0); 143 143 int offset, i; ··· 148 150 if (*mask == 0) 149 151 break; 150 152 if (index != xgpio_index(chip, i)) { 151 - xgpio_writereg(mm_gc->regs + XGPIO_DATA_OFFSET + 153 + xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + 152 154 xgpio_regoffset(chip, i), 153 155 chip->gpio_state[index]); 154 156 spin_unlock_irqrestore(&chip->gpio_lock[index], flags); ··· 164 166 } 165 167 } 166 168 167 - xgpio_writereg(mm_gc->regs + XGPIO_DATA_OFFSET + 169 + xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + 168 170 xgpio_regoffset(chip, i), chip->gpio_state[index]); 169 171 170 172 spin_unlock_irqrestore(&chip->gpio_lock[index], flags); ··· 182 184 static int xgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) 183 185 { 184 186 unsigned long flags; 185 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 186 187 struct xgpio_instance *chip = gpiochip_get_data(gc); 187 188 int index = xgpio_index(chip, gpio); 188 189 int offset = xgpio_offset(chip, gpio); ··· 190 193 191 194 /* Set the GPIO bit in shadow register and set direction as input */ 192 195 chip->gpio_dir[index] |= BIT(offset); 193 - xgpio_writereg(mm_gc->regs + XGPIO_TRI_OFFSET + 196 + xgpio_writereg(chip->regs + XGPIO_TRI_OFFSET + 194 197 xgpio_regoffset(chip, gpio), chip->gpio_dir[index]); 195 198 196 199 spin_unlock_irqrestore(&chip->gpio_lock[index], flags); ··· 213 216 static int xgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 214 217 { 215 218 unsigned long flags; 216 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 217 219 struct xgpio_instance *chip = gpiochip_get_data(gc); 218 220 int index = xgpio_index(chip, gpio); 219 221 int offset = xgpio_offset(chip, gpio); ··· 224 228 chip->gpio_state[index] |= BIT(offset); 225 229 else 226 230 chip->gpio_state[index] &= ~BIT(offset); 227 - xgpio_writereg(mm_gc->regs + XGPIO_DATA_OFFSET + 231 + xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + 228 232 xgpio_regoffset(chip, gpio), chip->gpio_state[index]); 229 233 230 234 /* Clear the GPIO bit in shadow register and set direction as output */ 231 235 chip->gpio_dir[index] &= ~BIT(offset); 232 - xgpio_writereg(mm_gc->regs + XGPIO_TRI_OFFSET + 236 + xgpio_writereg(chip->regs + XGPIO_TRI_OFFSET + 233 237 xgpio_regoffset(chip, gpio), chip->gpio_dir[index]); 234 238 235 239 spin_unlock_irqrestore(&chip->gpio_lock[index], flags); ··· 239 243 240 244 /** 241 245 * xgpio_save_regs - Set initial values of GPIO pins 242 - * @mm_gc: Pointer to memory mapped GPIO chip structure 246 + * @chip: Pointer to GPIO instance 243 247 */ 244 - static void xgpio_save_regs(struct of_mm_gpio_chip *mm_gc) 248 + static void xgpio_save_regs(struct xgpio_instance *chip) 245 249 { 246 - struct xgpio_instance *chip = 247 - container_of(mm_gc, struct xgpio_instance, mmchip); 248 - 249 - xgpio_writereg(mm_gc->regs + XGPIO_DATA_OFFSET, chip->gpio_state[0]); 250 - xgpio_writereg(mm_gc->regs + XGPIO_TRI_OFFSET, chip->gpio_dir[0]); 250 + xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET, chip->gpio_state[0]); 251 + xgpio_writereg(chip->regs + XGPIO_TRI_OFFSET, chip->gpio_dir[0]); 251 252 252 253 if (!chip->gpio_width[1]) 253 254 return; 254 255 255 - xgpio_writereg(mm_gc->regs + XGPIO_DATA_OFFSET + XGPIO_CHANNEL_OFFSET, 256 + xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + XGPIO_CHANNEL_OFFSET, 256 257 chip->gpio_state[1]); 257 - xgpio_writereg(mm_gc->regs + XGPIO_TRI_OFFSET + XGPIO_CHANNEL_OFFSET, 258 + xgpio_writereg(chip->regs + XGPIO_TRI_OFFSET + XGPIO_CHANNEL_OFFSET, 258 259 chip->gpio_dir[1]); 259 - } 260 - 261 - /** 262 - * xgpio_remove - Remove method for the GPIO device. 263 - * @pdev: pointer to the platform device 264 - * 265 - * This function remove gpiochips and frees all the allocated resources. 266 - * 267 - * Return: 0 always 268 - */ 269 - static int xgpio_remove(struct platform_device *pdev) 270 - { 271 - struct xgpio_instance *chip = platform_get_drvdata(pdev); 272 - 273 - of_mm_gpiochip_remove(&chip->mmchip); 274 - 275 - return 0; 276 260 } 277 261 278 262 /** ··· 316 340 spin_lock_init(&chip->gpio_lock[1]); 317 341 } 318 342 319 - chip->mmchip.gc.ngpio = chip->gpio_width[0] + chip->gpio_width[1]; 320 - chip->mmchip.gc.parent = &pdev->dev; 321 - chip->mmchip.gc.direction_input = xgpio_dir_in; 322 - chip->mmchip.gc.direction_output = xgpio_dir_out; 323 - chip->mmchip.gc.get = xgpio_get; 324 - chip->mmchip.gc.set = xgpio_set; 325 - chip->mmchip.gc.set_multiple = xgpio_set_multiple; 343 + chip->gc.base = -1; 344 + chip->gc.ngpio = chip->gpio_width[0] + chip->gpio_width[1]; 345 + chip->gc.parent = &pdev->dev; 346 + chip->gc.direction_input = xgpio_dir_in; 347 + chip->gc.direction_output = xgpio_dir_out; 348 + chip->gc.get = xgpio_get; 349 + chip->gc.set = xgpio_set; 350 + chip->gc.set_multiple = xgpio_set_multiple; 326 351 327 - chip->mmchip.save_regs = xgpio_save_regs; 352 + chip->gc.label = dev_name(&pdev->dev); 328 353 329 - /* Call the OF gpio helper to setup and register the GPIO device */ 330 - status = of_mm_gpiochip_add_data(np, &chip->mmchip, chip); 354 + chip->regs = devm_platform_ioremap_resource(pdev, 0); 355 + if (IS_ERR(chip->regs)) { 356 + dev_err(&pdev->dev, "failed to ioremap memory resource\n"); 357 + return PTR_ERR(chip->regs); 358 + } 359 + 360 + xgpio_save_regs(chip); 361 + 362 + status = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip); 331 363 if (status) { 332 - pr_err("%pOF: error in probe function with status %d\n", 333 - np, status); 364 + dev_err(&pdev->dev, "failed to add GPIO chip\n"); 334 365 return status; 335 366 } 336 367 ··· 353 370 354 371 static struct platform_driver xgpio_plat_driver = { 355 372 .probe = xgpio_probe, 356 - .remove = xgpio_remove, 357 373 .driver = { 358 374 .name = "gpio-xilinx", 359 375 .of_match_table = xgpio_of_match,
+3 -3
drivers/gpio/gpiolib-acpi.c
··· 217 217 if (!handler) 218 218 return AE_OK; 219 219 220 - desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event", 0); 220 + desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event", 221 + GPIO_ACTIVE_HIGH, GPIOD_IN); 221 222 if (IS_ERR(desc)) { 222 223 dev_err(chip->parent, "Failed to request GPIO\n"); 223 224 return AE_ERROR; 224 225 } 225 - 226 - gpiod_direction_input(desc); 227 226 228 227 ret = gpiochip_lock_as_irq(chip, pin); 229 228 if (ret) { ··· 950 951 const char *label = "ACPI:OpRegion"; 951 952 952 953 desc = gpiochip_request_own_desc(chip, pin, label, 954 + GPIO_ACTIVE_HIGH, 953 955 flags); 954 956 if (IS_ERR(desc)) { 955 957 status = AE_ERROR;
+43
drivers/gpio/gpiolib-of.c
··· 165 165 } 166 166 } 167 167 } 168 + 169 + /* Legacy handling of stmmac's active-low PHY reset line */ 170 + if (IS_ENABLED(CONFIG_STMMAC_ETH) && 171 + !strcmp(propname, "snps,reset-gpio") && 172 + of_property_read_bool(np, "snps,reset-active-low")) 173 + *flags |= OF_GPIO_ACTIVE_LOW; 168 174 } 169 175 170 176 /** ··· 268 262 } 269 263 270 264 /* 265 + * The old Freescale bindings use simply "gpios" as name for the chip select 266 + * lines rather than "cs-gpios" like all other SPI hardware. Account for this 267 + * with a special quirk. 268 + */ 269 + static struct gpio_desc *of_find_spi_cs_gpio(struct device *dev, 270 + const char *con_id, 271 + unsigned int idx, 272 + unsigned long *flags) 273 + { 274 + struct device_node *np = dev->of_node; 275 + 276 + if (!IS_ENABLED(CONFIG_SPI_MASTER)) 277 + return ERR_PTR(-ENOENT); 278 + 279 + /* Allow this specifically for Freescale devices */ 280 + if (!of_device_is_compatible(np, "fsl,spi") && 281 + !of_device_is_compatible(np, "aeroflexgaisler,spictrl")) 282 + return ERR_PTR(-ENOENT); 283 + /* Allow only if asking for "cs-gpios" */ 284 + if (!con_id || strcmp(con_id, "cs")) 285 + return ERR_PTR(-ENOENT); 286 + 287 + /* 288 + * While all other SPI controllers use "cs-gpios" the Freescale 289 + * uses just "gpios" so translate to that when "cs-gpios" is 290 + * requested. 291 + */ 292 + return of_find_gpio(dev, NULL, idx, flags); 293 + } 294 + 295 + /* 271 296 * Some regulator bindings happened before we managed to establish that GPIO 272 297 * properties should be named "foo-gpios" so we have this special kludge for 273 298 * them. ··· 369 332 /* Special handling for SPI GPIOs if used */ 370 333 if (IS_ERR(desc)) 371 334 desc = of_find_spi_gpio(dev, con_id, &of_flags); 335 + if (IS_ERR(desc)) { 336 + /* This quirk looks up flags and all */ 337 + desc = of_find_spi_cs_gpio(dev, con_id, idx, flags); 338 + if (!IS_ERR(desc)) 339 + return desc; 340 + } 372 341 373 342 /* Special handling for regulator GPIOs if used */ 374 343 if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER)
+43 -45
drivers/gpio/gpiolib.c
··· 1644 1644 1645 1645 /** 1646 1646 * gpiochip_set_cascaded_irqchip() - connects a cascaded irqchip to a gpiochip 1647 - * @gpiochip: the gpiochip to set the irqchip chain to 1647 + * @gc: the gpiochip to set the irqchip chain to 1648 1648 * @parent_irq: the irq number corresponding to the parent IRQ for this 1649 1649 * chained irqchip 1650 1650 * @parent_handler: the parent interrupt handler for the accumulated IRQ 1651 1651 * coming out of the gpiochip. If the interrupt is nested rather than 1652 1652 * cascaded, pass NULL in this handler argument 1653 1653 */ 1654 - static void gpiochip_set_cascaded_irqchip(struct gpio_chip *gpiochip, 1654 + static void gpiochip_set_cascaded_irqchip(struct gpio_chip *gc, 1655 1655 unsigned int parent_irq, 1656 1656 irq_flow_handler_t parent_handler) 1657 1657 { 1658 - if (!gpiochip->irq.domain) { 1659 - chip_err(gpiochip, "called %s before setting up irqchip\n", 1658 + struct gpio_irq_chip *girq = &gc->irq; 1659 + struct device *dev = &gc->gpiodev->dev; 1660 + 1661 + if (!girq->domain) { 1662 + chip_err(gc, "called %s before setting up irqchip\n", 1660 1663 __func__); 1661 1664 return; 1662 1665 } 1663 1666 1664 1667 if (parent_handler) { 1665 - if (gpiochip->can_sleep) { 1666 - chip_err(gpiochip, 1668 + if (gc->can_sleep) { 1669 + chip_err(gc, 1667 1670 "you cannot have chained interrupts on a chip that may sleep\n"); 1668 1671 return; 1669 1672 } 1673 + girq->parents = devm_kcalloc(dev, 1, 1674 + sizeof(*girq->parents), 1675 + GFP_KERNEL); 1676 + if (!girq->parents) { 1677 + chip_err(gc, "out of memory allocating parent IRQ\n"); 1678 + return; 1679 + } 1680 + girq->parents[0] = parent_irq; 1681 + girq->num_parents = 1; 1670 1682 /* 1671 1683 * The parent irqchip is already using the chip_data for this 1672 1684 * irqchip, so our callbacks simply use the handler_data. 1673 1685 */ 1674 1686 irq_set_chained_handler_and_data(parent_irq, parent_handler, 1675 - gpiochip); 1676 - 1677 - gpiochip->irq.parent_irq = parent_irq; 1678 - gpiochip->irq.parents = &gpiochip->irq.parent_irq; 1679 - gpiochip->irq.num_parents = 1; 1687 + gc); 1680 1688 } 1681 1689 } 1682 1690 ··· 2511 2503 * @chip: GPIO chip 2512 2504 * @hwnum: hardware number of the GPIO for which to request the descriptor 2513 2505 * @label: label for the GPIO 2514 - * @flags: flags for this GPIO or 0 if default 2506 + * @lflags: lookup flags for this GPIO or 0 if default, this can be used to 2507 + * specify things like line inversion semantics with the machine flags 2508 + * such as GPIO_OUT_LOW 2509 + * @dflags: descriptor request flags for this GPIO or 0 if default, this 2510 + * can be used to specify consumer semantics such as open drain 2515 2511 * 2516 2512 * Function allows GPIO chip drivers to request and use their own GPIO 2517 2513 * descriptors via gpiolib API. Difference to gpiod_request() is that this ··· 2529 2517 */ 2530 2518 struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, 2531 2519 const char *label, 2532 - enum gpiod_flags flags) 2520 + enum gpio_lookup_flags lflags, 2521 + enum gpiod_flags dflags) 2533 2522 { 2534 - unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT; 2535 2523 struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum); 2536 2524 int err; 2537 2525 ··· 2544 2532 if (err < 0) 2545 2533 return ERR_PTR(err); 2546 2534 2547 - err = gpiod_configure_flags(desc, label, lflags, flags); 2535 + err = gpiod_configure_flags(desc, label, lflags, dflags); 2548 2536 if (err) { 2549 2537 chip_err(chip, "setup of own GPIO %s failed\n", label); 2550 2538 gpiod_free_commit(desc); ··· 3031 3019 * Return the GPIO's raw value, i.e. the value of the physical line disregarding 3032 3020 * its ACTIVE_LOW status, or negative errno on failure. 3033 3021 * 3034 - * This function should be called from contexts where we cannot sleep, and will 3022 + * This function can be called from contexts where we cannot sleep, and will 3035 3023 * complain if the GPIO chip functions potentially sleep. 3036 3024 */ 3037 3025 int gpiod_get_raw_value(const struct gpio_desc *desc) 3038 3026 { 3039 3027 VALIDATE_DESC(desc); 3040 - /* Should be using gpio_get_value_cansleep() */ 3028 + /* Should be using gpiod_get_raw_value_cansleep() */ 3041 3029 WARN_ON(desc->gdev->chip->can_sleep); 3042 3030 return gpiod_get_raw_value_commit(desc); 3043 3031 } ··· 3050 3038 * Return the GPIO's logical value, i.e. taking the ACTIVE_LOW status into 3051 3039 * account, or negative errno on failure. 3052 3040 * 3053 - * This function should be called from contexts where we cannot sleep, and will 3041 + * This function can be called from contexts where we cannot sleep, and will 3054 3042 * complain if the GPIO chip functions potentially sleep. 3055 3043 */ 3056 3044 int gpiod_get_value(const struct gpio_desc *desc) ··· 3058 3046 int value; 3059 3047 3060 3048 VALIDATE_DESC(desc); 3061 - /* Should be using gpio_get_value_cansleep() */ 3049 + /* Should be using gpiod_get_value_cansleep() */ 3062 3050 WARN_ON(desc->gdev->chip->can_sleep); 3063 3051 3064 3052 value = gpiod_get_raw_value_commit(desc); ··· 3083 3071 * without regard for their ACTIVE_LOW status. Return 0 in case of success, 3084 3072 * else an error code. 3085 3073 * 3086 - * This function should be called from contexts where we cannot sleep, 3074 + * This function can be called from contexts where we cannot sleep, 3087 3075 * and it will complain if the GPIO chip functions potentially sleep. 3088 3076 */ 3089 3077 int gpiod_get_raw_array_value(unsigned int array_size, ··· 3109 3097 * Read the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status 3110 3098 * into account. Return 0 in case of success, else an error code. 3111 3099 * 3112 - * This function should be called from contexts where we cannot sleep, 3100 + * This function can be called from contexts where we cannot sleep, 3113 3101 * and it will complain if the GPIO chip functions potentially sleep. 3114 3102 */ 3115 3103 int gpiod_get_array_value(unsigned int array_size, ··· 3323 3311 * Set the raw value of the GPIO, i.e. the value of its physical line without 3324 3312 * regard for its ACTIVE_LOW status. 3325 3313 * 3326 - * This function should be called from contexts where we cannot sleep, and will 3314 + * This function can be called from contexts where we cannot sleep, and will 3327 3315 * complain if the GPIO chip functions potentially sleep. 3328 3316 */ 3329 3317 void gpiod_set_raw_value(struct gpio_desc *desc, int value) 3330 3318 { 3331 3319 VALIDATE_DESC_VOID(desc); 3332 - /* Should be using gpiod_set_value_cansleep() */ 3320 + /* Should be using gpiod_set_raw_value_cansleep() */ 3333 3321 WARN_ON(desc->gdev->chip->can_sleep); 3334 3322 gpiod_set_raw_value_commit(desc, value); 3335 3323 } ··· 3364 3352 * Set the logical value of the GPIO, i.e. taking its ACTIVE_LOW, 3365 3353 * OPEN_DRAIN and OPEN_SOURCE flags into account. 3366 3354 * 3367 - * This function should be called from contexts where we cannot sleep, and will 3355 + * This function can be called from contexts where we cannot sleep, and will 3368 3356 * complain if the GPIO chip functions potentially sleep. 3369 3357 */ 3370 3358 void gpiod_set_value(struct gpio_desc *desc, int value) 3371 3359 { 3372 3360 VALIDATE_DESC_VOID(desc); 3361 + /* Should be using gpiod_set_value_cansleep() */ 3373 3362 WARN_ON(desc->gdev->chip->can_sleep); 3374 3363 gpiod_set_value_nocheck(desc, value); 3375 3364 } ··· 3386 3373 * Set the raw values of the GPIOs, i.e. the values of the physical lines 3387 3374 * without regard for their ACTIVE_LOW status. 3388 3375 * 3389 - * This function should be called from contexts where we cannot sleep, and will 3376 + * This function can be called from contexts where we cannot sleep, and will 3390 3377 * complain if the GPIO chip functions potentially sleep. 3391 3378 */ 3392 3379 int gpiod_set_raw_array_value(unsigned int array_size, ··· 3411 3398 * Set the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status 3412 3399 * into account. 3413 3400 * 3414 - * This function should be called from contexts where we cannot sleep, and will 3401 + * This function can be called from contexts where we cannot sleep, and will 3415 3402 * complain if the GPIO chip functions potentially sleep. 3416 3403 */ 3417 3404 int gpiod_set_array_value(unsigned int array_size, ··· 4433 4420 chip = gpiod_to_chip(desc); 4434 4421 hwnum = gpio_chip_hwgpio(desc); 4435 4422 4436 - /* 4437 - * FIXME: not very elegant that we call gpiod_configure_flags() 4438 - * twice here (once inside gpiochip_request_own_desc() and 4439 - * again here), but the gpiochip_request_own_desc() is external 4440 - * and cannot really pass the lflags so this is the lesser evil 4441 - * at the moment. Pass zero as dflags on this first call so we 4442 - * don't screw anything up. 4443 - */ 4444 - local_desc = gpiochip_request_own_desc(chip, hwnum, name, 0); 4423 + local_desc = gpiochip_request_own_desc(chip, hwnum, name, 4424 + lflags, dflags); 4445 4425 if (IS_ERR(local_desc)) { 4446 4426 status = PTR_ERR(local_desc); 4447 4427 pr_err("requesting hog GPIO %s (chip %s, offset %d) failed, %d\n", 4448 4428 name, chip->label, hwnum, status); 4449 - return status; 4450 - } 4451 - 4452 - status = gpiod_configure_flags(desc, name, lflags, dflags); 4453 - if (status < 0) { 4454 - pr_err("setup of hog GPIO %s (chip %s, offset %d) failed, %d\n", 4455 - name, chip->label, hwnum, status); 4456 - gpiochip_free_own_desc(desc); 4457 4429 return status; 4458 4430 } 4459 4431 ··· 4803 4805 static int __init gpiolib_debugfs_init(void) 4804 4806 { 4805 4807 /* /sys/kernel/debug/gpio */ 4806 - (void) debugfs_create_file("gpio", S_IFREG | S_IRUGO, 4807 - NULL, NULL, &gpiolib_operations); 4808 + debugfs_create_file("gpio", S_IFREG | S_IRUGO, NULL, NULL, 4809 + &gpiolib_operations); 4808 4810 return 0; 4809 4811 } 4810 4812 subsys_initcall(gpiolib_debugfs_init);
+1 -1
drivers/gpio/gpiolib.h
··· 210 210 struct gpio_array *array_info, 211 211 unsigned long *value_bitmap); 212 212 213 - extern struct spinlock gpio_lock; 213 + extern spinlock_t gpio_lock; 214 214 extern struct list_head gpio_devices; 215 215 216 216 struct gpio_desc {
+5 -2
drivers/hid/hid-cp2112.c
··· 16 16 * https://www.silabs.com/documents/public/application-notes/an495-cp2112-interface-specification.pdf 17 17 */ 18 18 19 - #include <linux/gpio.h> 19 + #include <linux/gpio/consumer.h> 20 + #include <linux/gpio/machine.h> 20 21 #include <linux/gpio/driver.h> 21 22 #include <linux/hid.h> 22 23 #include <linux/hidraw.h> ··· 1196 1195 return -EINVAL; 1197 1196 1198 1197 dev->desc[pin] = gpiochip_request_own_desc(&dev->gc, pin, 1199 - "HID/I2C:Event", 0); 1198 + "HID/I2C:Event", 1199 + GPIO_ACTIVE_HIGH, 1200 + GPIOD_IN); 1200 1201 if (IS_ERR(dev->desc[pin])) { 1201 1202 dev_err(dev->gc.parent, "Failed to request GPIO\n"); 1202 1203 return PTR_ERR(dev->desc[pin]);
+3 -1
drivers/memory/omap-gpmc.c
··· 19 19 #include <linux/io.h> 20 20 #include <linux/gpio/driver.h> 21 21 #include <linux/gpio/consumer.h> /* GPIO descriptor enum */ 22 + #include <linux/gpio/machine.h> 22 23 #include <linux/interrupt.h> 23 24 #include <linux/irqdomain.h> 24 25 #include <linux/platform_device.h> ··· 2170 2169 2171 2170 waitpin_desc = gpiochip_request_own_desc(&gpmc->gpio_chip, 2172 2171 wait_pin, "WAITPIN", 2173 - 0); 2172 + GPIO_ACTIVE_HIGH, 2173 + GPIOD_IN); 2174 2174 if (IS_ERR(waitpin_desc)) { 2175 2175 dev_err(&pdev->dev, "invalid wait-pin: %d\n", wait_pin); 2176 2176 ret = PTR_ERR(waitpin_desc);
-39
include/linux/fmc-sdb.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* 3 - * This file is separate from sdb.h, because I want that one to remain 4 - * unchanged (as far as possible) from the official sdb distribution 5 - * 6 - * This file and associated functionality are a playground for me to 7 - * understand stuff which will later be implemented in more generic places. 8 - */ 9 - #include <linux/sdb.h> 10 - 11 - /* This is the union of all currently defined types */ 12 - union sdb_record { 13 - struct sdb_interconnect ic; 14 - struct sdb_device dev; 15 - struct sdb_bridge bridge; 16 - struct sdb_integration integr; 17 - struct sdb_empty empty; 18 - struct sdb_synthesis synthesis; 19 - struct sdb_repo_url repo_url; 20 - }; 21 - 22 - struct fmc_device; 23 - 24 - /* Every sdb table is turned into this structure */ 25 - struct sdb_array { 26 - int len; 27 - int level; 28 - unsigned long baseaddr; 29 - struct fmc_device *fmc; /* the device that hosts it */ 30 - struct sdb_array *parent; /* NULL at root */ 31 - union sdb_record *record; /* copies of the struct */ 32 - struct sdb_array **subtree; /* only valid for bridge items */ 33 - }; 34 - 35 - extern int fmc_scan_sdb_tree(struct fmc_device *fmc, unsigned long address); 36 - extern void fmc_show_sdb_tree(const struct fmc_device *fmc); 37 - extern signed long fmc_find_sdb_device(struct sdb_array *tree, uint64_t vendor, 38 - uint32_t device, unsigned long *sz); 39 - extern int fmc_free_sdb_tree(struct fmc_device *fmc);
-269
include/linux/fmc.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 - /* 3 - * Copyright (C) 2012 CERN (www.cern.ch) 4 - * Author: Alessandro Rubini <rubini@gnudd.com> 5 - * 6 - * This work is part of the White Rabbit project, a research effort led 7 - * by CERN, the European Institute for Nuclear Research. 8 - */ 9 - #ifndef __LINUX_FMC_H__ 10 - #define __LINUX_FMC_H__ 11 - #include <linux/types.h> 12 - #include <linux/moduleparam.h> 13 - #include <linux/device.h> 14 - #include <linux/list.h> 15 - #include <linux/interrupt.h> 16 - #include <linux/io.h> 17 - 18 - struct fmc_device; 19 - struct fmc_driver; 20 - 21 - /* 22 - * This bus abstraction is developed separately from drivers, so we need 23 - * to check the version of the data structures we receive. 24 - */ 25 - 26 - #define FMC_MAJOR 3 27 - #define FMC_MINOR 0 28 - #define FMC_VERSION ((FMC_MAJOR << 16) | FMC_MINOR) 29 - #define __FMC_MAJOR(x) ((x) >> 16) 30 - #define __FMC_MINOR(x) ((x) & 0xffff) 31 - 32 - /* 33 - * The device identification, as defined by the IPMI FRU (Field Replaceable 34 - * Unit) includes four different strings to describe the device. Here we 35 - * only match the "Board Manufacturer" and the "Board Product Name", 36 - * ignoring the "Board Serial Number" and "Board Part Number". All 4 are 37 - * expected to be strings, so they are treated as zero-terminated C strings. 38 - * Unspecified string (NULL) means "any", so if both are unspecified this 39 - * is a catch-all driver. So null entries are allowed and we use array 40 - * and length. This is unlike pci and usb that use null-terminated arrays 41 - */ 42 - struct fmc_fru_id { 43 - char *manufacturer; 44 - char *product_name; 45 - }; 46 - 47 - /* 48 - * If the FPGA is already programmed (think Etherbone or the second 49 - * SVEC slot), we can match on SDB devices in the memory image. This 50 - * match uses an array of devices that must all be present, and the 51 - * match is based on vendor and device only. Further checks are expected 52 - * to happen in the probe function. Zero means "any" and catch-all is allowed. 53 - */ 54 - struct fmc_sdb_one_id { 55 - uint64_t vendor; 56 - uint32_t device; 57 - }; 58 - struct fmc_sdb_id { 59 - struct fmc_sdb_one_id *cores; 60 - int cores_nr; 61 - }; 62 - 63 - struct fmc_device_id { 64 - struct fmc_fru_id *fru_id; 65 - int fru_id_nr; 66 - struct fmc_sdb_id *sdb_id; 67 - int sdb_id_nr; 68 - }; 69 - 70 - /* This sizes the module_param_array used by generic module parameters */ 71 - #define FMC_MAX_CARDS 32 72 - 73 - /* The driver is a pretty simple thing */ 74 - struct fmc_driver { 75 - unsigned long version; 76 - struct device_driver driver; 77 - int (*probe)(struct fmc_device *); 78 - int (*remove)(struct fmc_device *); 79 - const struct fmc_device_id id_table; 80 - /* What follows is for generic module parameters */ 81 - int busid_n; 82 - int busid_val[FMC_MAX_CARDS]; 83 - int gw_n; 84 - char *gw_val[FMC_MAX_CARDS]; 85 - }; 86 - #define to_fmc_driver(x) container_of((x), struct fmc_driver, driver) 87 - 88 - /* These are the generic parameters, that drivers may instantiate */ 89 - #define FMC_PARAM_BUSID(_d) \ 90 - module_param_array_named(busid, _d.busid_val, int, &_d.busid_n, 0444) 91 - #define FMC_PARAM_GATEWARE(_d) \ 92 - module_param_array_named(gateware, _d.gw_val, charp, &_d.gw_n, 0444) 93 - 94 - /* 95 - * Drivers may need to configure gpio pins in the carrier. To read input 96 - * (a very uncommon operation, and definitely not in the hot paths), just 97 - * configure one gpio only and get 0 or 1 as retval of the config method 98 - */ 99 - struct fmc_gpio { 100 - char *carrier_name; /* name or NULL for virtual pins */ 101 - int gpio; 102 - int _gpio; /* internal use by the carrier */ 103 - int mode; /* GPIOF_DIR_OUT etc, from <linux/gpio.h> */ 104 - int irqmode; /* IRQF_TRIGGER_LOW and so on */ 105 - }; 106 - 107 - /* The numbering of gpio pins allows access to raw pins or virtual roles */ 108 - #define FMC_GPIO_RAW(x) (x) /* 4096 of them */ 109 - #define __FMC_GPIO_IS_RAW(x) ((x) < 0x1000) 110 - #define FMC_GPIO_IRQ(x) ((x) + 0x1000) /* 256 of them */ 111 - #define FMC_GPIO_LED(x) ((x) + 0x1100) /* 256 of them */ 112 - #define FMC_GPIO_KEY(x) ((x) + 0x1200) /* 256 of them */ 113 - #define FMC_GPIO_TP(x) ((x) + 0x1300) /* 256 of them */ 114 - #define FMC_GPIO_USER(x) ((x) + 0x1400) /* 256 of them */ 115 - /* We may add SCL and SDA, or other roles if the need arises */ 116 - 117 - /* GPIOF_DIR_IN etc are missing before 3.0. copy from <linux/gpio.h> */ 118 - #ifndef GPIOF_DIR_IN 119 - # define GPIOF_DIR_OUT (0 << 0) 120 - # define GPIOF_DIR_IN (1 << 0) 121 - # define GPIOF_INIT_LOW (0 << 1) 122 - # define GPIOF_INIT_HIGH (1 << 1) 123 - #endif 124 - 125 - /* 126 - * The operations are offered by each carrier and should make driver 127 - * design completely independent of the carrier. Named GPIO pins may be 128 - * the exception. 129 - */ 130 - struct fmc_operations { 131 - uint32_t (*read32)(struct fmc_device *fmc, int offset); 132 - void (*write32)(struct fmc_device *fmc, uint32_t value, int offset); 133 - int (*validate)(struct fmc_device *fmc, struct fmc_driver *drv); 134 - int (*reprogram_raw)(struct fmc_device *f, struct fmc_driver *d, 135 - void *gw, unsigned long len); 136 - int (*reprogram)(struct fmc_device *f, struct fmc_driver *d, char *gw); 137 - int (*irq_request)(struct fmc_device *fmc, irq_handler_t h, 138 - char *name, int flags); 139 - void (*irq_ack)(struct fmc_device *fmc); 140 - int (*irq_free)(struct fmc_device *fmc); 141 - int (*gpio_config)(struct fmc_device *fmc, struct fmc_gpio *gpio, 142 - int ngpio); 143 - int (*read_ee)(struct fmc_device *fmc, int pos, void *d, int l); 144 - int (*write_ee)(struct fmc_device *fmc, int pos, const void *d, int l); 145 - }; 146 - 147 - /* Prefer this helper rather than calling of fmc->reprogram directly */ 148 - int fmc_reprogram_raw(struct fmc_device *fmc, struct fmc_driver *d, 149 - void *gw, unsigned long len, int sdb_entry); 150 - extern int fmc_reprogram(struct fmc_device *f, struct fmc_driver *d, char *gw, 151 - int sdb_entry); 152 - 153 - /* 154 - * The device reports all information needed to access hw. 155 - * 156 - * If we have eeprom_len and not contents, the core reads it. 157 - * Then, parsing of identifiers is done by the core which fills fmc_fru_id.. 158 - * Similarly a device that must be matched based on SDB cores must 159 - * fill the entry point and the core will scan the bus (FIXME: sdb match) 160 - */ 161 - struct fmc_device { 162 - unsigned long version; 163 - unsigned long flags; 164 - struct module *owner; /* char device must pin it */ 165 - struct fmc_fru_id id; /* for EEPROM-based match */ 166 - struct fmc_operations *op; /* carrier-provided */ 167 - int irq; /* according to host bus. 0 == none */ 168 - int eeprom_len; /* Usually 8kB, may be less */ 169 - int eeprom_addr; /* 0x50, 0x52 etc */ 170 - uint8_t *eeprom; /* Full contents or leading part */ 171 - char *carrier_name; /* "SPEC" or similar, for special use */ 172 - void *carrier_data; /* "struct spec *" or equivalent */ 173 - __iomem void *fpga_base; /* May be NULL (Etherbone) */ 174 - __iomem void *slot_base; /* Set by the driver */ 175 - struct fmc_device **devarray; /* Allocated by the bus */ 176 - int slot_id; /* Index in the slot array */ 177 - int nr_slots; /* Number of slots in this carrier */ 178 - unsigned long memlen; /* Used for the char device */ 179 - struct device dev; /* For Linux use */ 180 - struct device *hwdev; /* The underlying hardware device */ 181 - unsigned long sdbfs_entry; 182 - struct sdb_array *sdb; 183 - uint32_t device_id; /* Filled by the device */ 184 - char *mezzanine_name; /* Defaults to ``fmc'' */ 185 - void *mezzanine_data; 186 - 187 - struct dentry *dbg_dir; 188 - struct dentry *dbg_sdb_dump; 189 - }; 190 - #define to_fmc_device(x) container_of((x), struct fmc_device, dev) 191 - 192 - #define FMC_DEVICE_HAS_GOLDEN 1 193 - #define FMC_DEVICE_HAS_CUSTOM 2 194 - #define FMC_DEVICE_NO_MEZZANINE 4 195 - #define FMC_DEVICE_MATCH_SDB 8 /* fmc-core must scan sdb in fpga */ 196 - 197 - /* 198 - * If fpga_base can be used, the carrier offers no readl/writel methods, and 199 - * this expands to a single, fast, I/O access. 200 - */ 201 - static inline uint32_t fmc_readl(struct fmc_device *fmc, int offset) 202 - { 203 - if (unlikely(fmc->op->read32)) 204 - return fmc->op->read32(fmc, offset); 205 - return readl(fmc->fpga_base + offset); 206 - } 207 - static inline void fmc_writel(struct fmc_device *fmc, uint32_t val, int off) 208 - { 209 - if (unlikely(fmc->op->write32)) 210 - fmc->op->write32(fmc, val, off); 211 - else 212 - writel(val, fmc->fpga_base + off); 213 - } 214 - 215 - /* pci-like naming */ 216 - static inline void *fmc_get_drvdata(const struct fmc_device *fmc) 217 - { 218 - return dev_get_drvdata(&fmc->dev); 219 - } 220 - 221 - static inline void fmc_set_drvdata(struct fmc_device *fmc, void *data) 222 - { 223 - dev_set_drvdata(&fmc->dev, data); 224 - } 225 - 226 - struct fmc_gateware { 227 - void *bitstream; 228 - unsigned long len; 229 - }; 230 - 231 - /* The 5 access points */ 232 - extern int fmc_driver_register(struct fmc_driver *drv); 233 - extern void fmc_driver_unregister(struct fmc_driver *drv); 234 - extern int fmc_device_register(struct fmc_device *tdev); 235 - extern int fmc_device_register_gw(struct fmc_device *tdev, 236 - struct fmc_gateware *gw); 237 - extern void fmc_device_unregister(struct fmc_device *tdev); 238 - 239 - /* Three more for device sets, all driven by the same FPGA */ 240 - extern int fmc_device_register_n(struct fmc_device **devs, int n); 241 - extern int fmc_device_register_n_gw(struct fmc_device **devs, int n, 242 - struct fmc_gateware *gw); 243 - extern void fmc_device_unregister_n(struct fmc_device **devs, int n); 244 - 245 - /* Internal cross-calls between files; not exported to other modules */ 246 - extern int fmc_match(struct device *dev, struct device_driver *drv); 247 - extern int fmc_fill_id_info(struct fmc_device *fmc); 248 - extern void fmc_free_id_info(struct fmc_device *fmc); 249 - extern void fmc_dump_eeprom(const struct fmc_device *fmc); 250 - 251 - /* helpers for FMC operations */ 252 - extern int fmc_irq_request(struct fmc_device *fmc, irq_handler_t h, 253 - char *name, int flags); 254 - extern void fmc_irq_free(struct fmc_device *fmc); 255 - extern void fmc_irq_ack(struct fmc_device *fmc); 256 - extern int fmc_validate(struct fmc_device *fmc, struct fmc_driver *drv); 257 - extern int fmc_gpio_config(struct fmc_device *fmc, struct fmc_gpio *gpio, 258 - int ngpio); 259 - extern int fmc_read_ee(struct fmc_device *fmc, int pos, void *d, int l); 260 - extern int fmc_write_ee(struct fmc_device *fmc, int pos, const void *d, int l); 261 - 262 - /* helpers for FMC operations */ 263 - extern int fmc_irq_request(struct fmc_device *fmc, irq_handler_t h, 264 - char *name, int flags); 265 - extern void fmc_irq_free(struct fmc_device *fmc); 266 - extern void fmc_irq_ack(struct fmc_device *fmc); 267 - extern int fmc_validate(struct fmc_device *fmc, struct fmc_driver *drv); 268 - 269 - #endif /* __LINUX_FMC_H__ */
+13 -16
include/linux/gpio/driver.h
··· 18 18 struct gpio_device; 19 19 struct module; 20 20 enum gpiod_flags; 21 + enum gpio_lookup_flags; 21 22 22 23 #ifdef CONFIG_GPIOLIB 23 24 ··· 103 102 unsigned int num_parents; 104 103 105 104 /** 106 - * @parent_irq: 107 - * 108 - * For use by gpiochip_set_cascaded_irqchip() 109 - */ 110 - unsigned int parent_irq; 111 - 112 - /** 113 105 * @parents: 114 106 * 115 107 * A list of interrupt parents of a GPIO chip. This is owned by the ··· 161 167 */ 162 168 void (*irq_disable)(struct irq_data *data); 163 169 }; 164 - #endif 170 + #endif /* CONFIG_GPIOLIB_IRQCHIP */ 165 171 166 172 /** 167 173 * struct gpio_chip - abstract a GPIO controller ··· 194 200 * @dbg_show: optional routine to show contents in debugfs; default code 195 201 * will be used when this is omitted, but custom code can show extra 196 202 * state (such as pullup/pulldown configuration). 203 + * @init_valid_mask: optional routine to initialize @valid_mask, to be used if 204 + * not all GPIOs are valid. 197 205 * @base: identifies the first GPIO number handled by this chip; 198 206 * or, if negative during registration, requests dynamic ID allocation. 199 207 * DEPRECATION: providing anything non-negative and nailing the base ··· 303 307 spinlock_t bgpio_lock; 304 308 unsigned long bgpio_data; 305 309 unsigned long bgpio_dir; 306 - #endif 310 + #endif /* CONFIG_GPIO_GENERIC */ 307 311 308 312 #ifdef CONFIG_GPIOLIB_IRQCHIP 309 313 /* ··· 318 322 * used to handle IRQs for most practical cases. 319 323 */ 320 324 struct gpio_irq_chip irq; 321 - #endif 325 + #endif /* CONFIG_GPIOLIB_IRQCHIP */ 322 326 323 327 /** 324 328 * @need_valid_mask: ··· 365 369 */ 366 370 int (*of_xlate)(struct gpio_chip *gc, 367 371 const struct of_phandle_args *gpiospec, u32 *flags); 368 - #endif 372 + #endif /* CONFIG_OF_GPIO */ 369 373 }; 370 374 371 375 extern const char *gpiochip_is_requested(struct gpio_chip *chip, ··· 408 412 }) 409 413 #else 410 414 #define gpiochip_add_data(chip, data) gpiochip_add_data_with_key(chip, data, NULL, NULL) 411 - #endif 415 + #endif /* CONFIG_LOCKDEP */ 412 416 413 417 static inline int gpiochip_add(struct gpio_chip *chip) 414 418 { ··· 463 467 #define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */ 464 468 #define BGPIOF_NO_OUTPUT BIT(5) /* only input */ 465 469 466 - #endif 470 + #endif /* CONFIG_GPIO_GENERIC */ 467 471 468 472 #ifdef CONFIG_GPIOLIB_IRQCHIP 469 473 ··· 533 537 handler, type, true, 534 538 &lock_key, &request_key); 535 539 } 536 - #else 540 + #else /* ! CONFIG_LOCKDEP */ 537 541 static inline int gpiochip_irqchip_add(struct gpio_chip *gpiochip, 538 542 struct irq_chip *irqchip, 539 543 unsigned int first_irq, ··· 584 588 unsigned int gpio_offset, const char *pin_group); 585 589 void gpiochip_remove_pin_ranges(struct gpio_chip *chip); 586 590 587 - #else 591 + #else /* ! CONFIG_PINCTRL */ 588 592 589 593 static inline int 590 594 gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, ··· 610 614 611 615 struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, 612 616 const char *label, 613 - enum gpiod_flags flags); 617 + enum gpio_lookup_flags lflags, 618 + enum gpiod_flags dflags); 614 619 void gpiochip_free_own_desc(struct gpio_desc *desc); 615 620 616 621 void devprop_gpiochip_set_names(struct gpio_chip *chip,
+1 -1
include/linux/gpio/gpio-reg.h
··· 11 11 12 12 int gpio_reg_resume(struct gpio_chip *gc); 13 13 14 - #endif 14 + #endif /* GPIO_REG_H */
+2 -2
include/linux/gpio/machine.h
··· 97 97 void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n); 98 98 void gpiod_remove_lookup_table(struct gpiod_lookup_table *table); 99 99 void gpiod_add_hogs(struct gpiod_hog *hogs); 100 - #else 100 + #else /* ! CONFIG_GPIOLIB */ 101 101 static inline 102 102 void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {} 103 103 static inline ··· 105 105 static inline 106 106 void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {} 107 107 static inline void gpiod_add_hogs(struct gpiod_hog *hogs) {} 108 - #endif 108 + #endif /* CONFIG_GPIOLIB */ 109 109 110 110 #endif /* __LINUX_GPIO_MACHINE_H */
+1 -1
include/linux/platform_data/gpio-omap.h
··· 186 186 bool is_mpuio; /* whether the bank is of type MPUIO */ 187 187 u32 non_wakeup_gpios; 188 188 189 - struct omap_gpio_reg_offs *regs; 189 + const struct omap_gpio_reg_offs *regs; 190 190 191 191 /* Return context loss count due to PM states changing */ 192 192 int (*get_context_loss_count)(struct device *dev);
+10
include/linux/siox.h
··· 72 72 { 73 73 return driver_unregister(&sdriver->driver); 74 74 } 75 + 76 + /* 77 + * module_siox_driver() - Helper macro for drivers that don't do 78 + * anything special in module init/exit. This eliminates a lot of 79 + * boilerplate. Each module may only use this macro once, and 80 + * calling it replaces module_init() and module_exit() 81 + */ 82 + #define module_siox_driver(__siox_driver) \ 83 + module_driver(__siox_driver, siox_driver_register, \ 84 + siox_driver_unregister)
+1 -1
tools/gpio/.gitignore
··· 1 1 gpio-event-mon 2 2 gpio-hammer 3 3 lsgpio 4 - 4 + include/linux/gpio.h