Commit Graph

113 Commits

Author SHA1 Message Date
Takanori Watanabe
5efca36fbd Distinguish _CID match and _HID match and make lower priority probe
when _CID match.

Reviewed by: jhb, imp
Differential Revision:https://reviews.freebsd.org/D16468
2018-10-26 00:05:46 +00:00
Oleksandr Tymoshenko
f7604b1b27 Align OF_getencprop_alloc API with OF_getencprop and OF_getprop_alloc
Change OF_getencprop_alloc semantics to be combination of malloc and
OF_getencprop and return size of the property, not number of elements
allocated.

For the use cases where number of elements is preferred introduce
OF_getencprop_alloc_multi helper function that copies semantics
of OF_getencprop_alloc prior to this change.

This is to make OF_getencprop_alloc and OF_getencprop_alloc_multi
function signatures consistent with OF_getencprop_alloc and
OF_getencprop_alloc_multi.

Functionality-wise this patch is mostly rename of OF_getencprop_alloc
to OF_getencprop_alloc_multi except two calls in ofw_bus_setup_iinfo
where 1 was used as a block size.
2018-04-09 22:06:16 +00:00
Oleksandr Tymoshenko
217d17bcd3 Clean up OF_getprop_alloc API
OF_getprop_alloc takes element size argument and returns number of
elements in the property. There are valid use cases for such behavior
but mostly API consumers pass 1 as element size to get string
properties. What API users would expect from OF_getprop_alloc is to be
a combination of malloc + OF_getprop with the same semantic of return
value. This patch modifies API signature to match these expectations.

For the valid use cases with element size != 1 and to reduce
modification scope new OF_getprop_alloc_multi function has been
introduced that behaves the same way OF_getprop_alloc behaved prior to
this patch.

Reviewed by:	ian, manu
Differential Revision:	https://reviews.freebsd.org/D14850
2018-04-08 22:59:34 +00:00
Oleksandr Tymoshenko
9b7ae69179 Add SPDX tags for chvgpio driver sources
Also move $FreeBSD$ keyword in header to BSD license

MFC after:	2 weeks
2018-02-24 20:19:31 +00:00
Oleksandr Tymoshenko
94b8a54ae6 [chvgpio] add GPIO driver for Intel Z8xxx SoC family
Add chvgpio(4) driver for Intel Z8xxx SoC family. This product
was formerly known as Cherry Trail but Linux and OpenBSD drivers
refer to it as Cherry View. This driver is derived from OpenBSD
one so the name is kept for alignment with another BSD system.

Submitted by:	Tom Jones <tj@enoti.me>
Reviewed by:	gonzo, wblock(man page)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D13086
2018-02-22 19:12:32 +00:00
Ian Lepore
dc027dc6e2 Provide a public function to acquire a gpio pin by giving the property name
and index.  A private function to do exactly that already existed, so this
renames gpio_pin_get_by_ofw_impl() to gpio_pin_get_by_ofw_propidx() and
provides a declaration for it in a public header.

Previously there were functions to get a pin by property name (assuming
there would only be one pin defined for the name), or by index (asuming
the property has the standard name "gpios").  It turns out there are
devicetree bindings that describe properties with names other than "gpios"
which can describe multiple pins.  Hence the need to retrieve the Nth item
from a named property.
2018-02-18 23:08:43 +00:00
Pedro F. Giffuni
ac2fffa4b7 Revert r327828, r327949, r327953, r328016-r328026, r328041:
Uses of mallocarray(9).

The use of mallocarray(9) has rocketed the required swap to build FreeBSD.
This is likely caused by the allocation size attributes which put extra pressure
on the compiler.

Given that most of these checks are superfluous we have to choose better
where to use mallocarray(9). We still have more uses of mallocarray(9) but
hopefully this is enough to bring swap usage to a reasonable level.

Reported by:	wosch
PR:		225197
2018-01-21 15:42:36 +00:00
Pedro F. Giffuni
26c1d774b5 dev: make some use of mallocarray(9).
Focus on code where we are doing multiplications within malloc(9). None of
these is likely to overflow, however the change is still useful as some
static checkers can benefit from the allocation attributes we use for
mallocarray.

This initial sweep only covers malloc(9) calls with M_NOWAIT. No good
reason but I started doing the changes before r327796 and at that time it
was convenient to make sure the sorrounding code could handle NULL values.
2018-01-13 22:30:30 +00:00
Pedro F. Giffuni
718cf2ccb9 sys/dev: further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.
2017-11-27 14:52:40 +00:00
Ian Lepore
e1275c6805 Add gpio methods to read/write/configure up to 32 pins simultaneously.
Sometimes it is necessary to combine several gpio pins into an ad-hoc bus
and manipulate the pins as a group. In such cases manipulating the pins
individualy is not an option, because the value on the "bus" assumes
potentially-invalid intermediate values as each pin is changed in turn. Note
that the "bus" may be something as simple as a bi-color LED where changing
colors requires changing both gpio pins at once, or something as complex as
a bitbanged multiplexed address/data bus connected to a microcontroller.

In addition to the absolute requirement of simultaneously changing the
output values of driven pins, a desirable feature of these new methods is to
provide a higher-performance mechanism for reading and writing multiple
pins, especially from userland where pin-at-a-time access incurs a noticible
syscall time penalty.

These new interfaces are NOT intended to abstract away all the ugly details
of how gpio is implemented on any given platform. In fact, to use these
properly you absolutely must know something about how the gpio hardware is
organized. Typically there are "banks" of gpio pins controlled by registers
which group several pins together. A bank may be as small as 2 pins or as
big as "all the pins on the device, hundreds of them." In the latter case, a
driver might support this interface by allowing access to any 32 adjacent
pins within the overall collection. Or, more likely, any 32 adjacent pins
starting at any multiple of 32. Whatever the hardware restrictions may be,
you would need to understand them to use this interface.

In additional to defining the interfaces, two example implementations are
included here, for imx5/6, and allwinner. These represent the two primary
types of gpio hardware drivers. imx6 has multiple gpio devices, each
implementing a single bank of 32 pins. Allwinner implements a single large
gpio number space from 1-n pins, and the driver internally translates that
linear number space to a bank+pin scheme based on how the pins are grouped
into control registers. The allwinner implementation imposes the restriction
that the first_pin argument to the new functions must always be pin 0 of a
bank.

Differential Revision:	https://reviews.freebsd.org/D11810
2017-09-10 18:08:25 +00:00
Michael Zhilin
662e30fca3 [gpioths] new driver for temperature/humidity sensor DHT11
This patch adds driver for temperature/humidity sensor connected via GPIO.
To compile it into kernel add "device gpioths". To activate driver, use
hints (.at and .pins) for gpiobus. As result it will provide temperature &
humidity values via sysctl.

DHT11 is cheap & popular temperature/humidity sensor used via GPIO on ARM
or MIPS devices like Raspberry Pi or Onion Omega.

Reviewed by:	adrian
Approved by:	adrian (mentor)
Differential Revision:	https://reviews.freebsd.org/D9185
2017-01-16 15:36:36 +00:00
Luiz Otavio O Souza
4723c14fa9 Convert gpioc to use the make_dev_s(9) KPI. This fix a possible race where
si_drv1 can be accessed before it gets set.

This is inspired on r311700.

MFC after:	3 days
2017-01-08 20:41:32 +00:00
Ian Lepore
ee2c73e559 Only write to *active once, even when GPIO_ACTIVE_LOW is set. 2017-01-07 22:55:23 +00:00
Michael Zhilin
d1c38239e8 [gpiospi] add clock delay to avoid smashing of bits
Submitted by:	Hiroki Mori <yamori83@yahoo.co.jp>
Reviewed by:	loos, ray, mizhka
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D8749
2016-12-13 10:03:29 +00:00
Luiz Otavio O Souza
a9a7fbcc58 Remove a too strict test and instead, just filter the passed flags with the
supported capabilities.

Spotted by:	yamori813@yahoo.co.jp (Hiroki Mori)
MFC after:	2 weeks
2016-12-13 03:36:41 +00:00
Oleksandr Tymoshenko
fd98051117 [bytgpio] prepare bytgpio(4) for modularization
- Add detach method
- module should depend on gpiobus, not gpio
2016-11-21 19:43:01 +00:00
Oleksandr Tymoshenko
06ae3ba328 [bytgpio] Fix USB disconnect event after listsing pins on gpioc2
- Do not set input flag when reading value from GPIO pin, it is not
  required and for gpioc2(S5 bank) setting both input and output flags
  leads to some kind of electric interference (curren drop?) that
  causes USB devices to disconnect

- Check pad configuration when attaching device and provide IN/OUT
  capabilities only for pads that are configured as GPIO. Do not let
  user code to configure or change value of non-GPIO pads. There is
  no information for NC bank in intel's datasheet so for now function
  check is ignored for pins in it

Reported by:	Frank H.
MFC after:	3 days
2016-11-20 18:38:32 +00:00
Ruslan Bukin
8e621af540 Make gpiobus early driver at BUS_PAS_BUS.
The gpiobus driver is attached explicitly and generally should be
at the same pass as its parent. Making it use BUS_PAS_BUS ensures
that it attaches immediately after parent adds it (assuming the
parent itself attached at BUS_PAS_BUS and above).

Submitted by:	kan
Sponsored by:	DARPA, AFRL
2016-11-17 15:37:44 +00:00
Justin Hibbits
099a0e1bea Add a GPIO poweroff and reset driver.
Summary:
This implements part of the gpio-poweroff and gpio-restart device tree
bindings.  Optional properties are not handled currently.  It also currently
only supports level-triggered reset.

Reviewed By: gonzo
Differential Revision: https://reviews.freebsd.org/D8521
2016-11-16 02:14:07 +00:00
Oleksandr Tymoshenko
aabc5ce043 Refactor FDT part of gpioled driver
- Split driver in two parts: FDT and non-FDT
- Instead of reattach gpioled nodes to GPIO bus use
    gpio_pin_get_by_ofw_idx and add ofwbus and simplebus as parrent buses

Reviewed by:	loos
Differential Revision:	https://reviews.freebsd.org/D8233
2016-11-07 21:15:39 +00:00
Oleksandr Tymoshenko
95a3636709 [gpio] Add GPIO driver for Intel Bay Trail SoC
Bay Trail has three banks of GPIOs exposed to userland as /dev/gpiocN,
where N is 1, 2, and 3. Pins in each bank are pre-named to match names
on boards schematics: GPIO_S0_SCnn, GPIO_S0_NCnn, and GPIO_S5_nn.

Controller supports edge-triggered and level-triggered interrupts but
current version of the driver does not have interrupts support
2016-11-04 16:24:38 +00:00
Andrew Turner
1fb2428f1c Stop including a possibly GPLd header from the GPIO code. Add the only
needed macro to ofw_gpiobus.c.

Reported by:	emaste
Sponsored by:	DARPA, AFRL
2016-10-26 12:41:44 +00:00
Jared McNeill
72f1cf0446 Add driver for GPIO controlled regulator.
Reviewed by:		gonzo, manu, mmel
Differential Revision:	https://reviews.freebsd.org/D8257
2016-10-15 20:04:14 +00:00
Adrian Chadd
01decb509d [gpio] include intr.h when building with INTRNG.
Trying to build a MIPS platform that uses INTRNG needs this
for this to work right in gpiobusvar.h :

#ifdef INTRNG
struct intr_map_data_gpio {
        struct intr_map_data    hdr;
...
};
#endif
2016-09-09 04:54:41 +00:00
Michal Meloun
895c8b1c39 INTRNG: Rework handling with resources. Partially revert r301453.
- Read interrupt properties at bus enumeration time and store
   it into global mapping table.
 - At bus_activate_resource() time, given mapping entry is resolved and
   connected to real interrupt source. A copy of mapping entry is attached
   to given resource.
 - At bus_setup_intr() time, mapping entry stored in resource is used
   for delivery of requested interrupt configuration.
 - For MSI/MSIX interrupts, mapping entry is created within
   pci_alloc_msi()/pci_alloc_msix() call.
 - For legacy PCI interrupts, mapping entry must be created within
   pcib_route_interrupt() by pcib driver itself.

Reviewed by: nwhitehorn, andrew
Differential Revision: https://reviews.freebsd.org/D7493
2016-08-19 10:52:39 +00:00
Adrian Chadd
d75e8c5089 [gpioled] add support for inverting the LED polarity.
No, this isn't a star trek science joke - sometimes LEDs are wired
up to be active low, so this is needed.

Submitted by:	Dan Nelson <dnelson_1901@yahoo.com>
2016-07-31 06:24:26 +00:00
Michal Meloun
949883bd72 INTRNG: As follow up of r301451, implement mapping and configuration
of gpio pin interrupts by new way.

Note: This removes last consumer of intr_ddata machinery and we remove it
in separate commit.
2016-06-07 05:08:24 +00:00
Svatopluk Kraus
ad5244ece1 INTRNG - change the way how an interrupt mapping data are provided
to the framework in OFW (FDT) case.

This is a follow-up to r301451.

Differential Revision:	https://reviews.freebsd.org/D6634
2016-06-05 16:20:12 +00:00
Ian Lepore
781ca89cf6 Don't wrap the declaration of gpio_alloc_intr_resource() in #ifdef INTRNG,
wrap the implementation so that it returns an error if INTRNG support is
not available.  It should be possible to write a non-INTRNG implementation
of this function some day.  In the meantime, there is code that contains
calls to this function (so the decl is needed), but have runtime checks to
avoid calling it in the non-INTRNG case.
2016-05-27 20:41:25 +00:00
Ian Lepore
128e3872b9 Add a PPS driver that takes the timing pulse from a gpio pin. Currently
supports only ofw/fdt systems.  Some day, hinted attachment for non-fdt
systems should be possible too.
2016-05-26 23:56:12 +00:00
Ian Lepore
5030d499e7 Add a convenience function to get a gpio pin's capabilties. 2016-05-26 22:35:52 +00:00
Ian Lepore
c45b842250 Rename gpiobus_map_pin() to gpiobus_acquire_pin(), to better reflect the
fact that the caller is requesting exclusive use of the pin, and also to
better match the inverse operation which is named gpiobus_release_pin().
2016-05-26 15:45:36 +00:00
Adrian Chadd
6c6f602b53 [gpiospi] add initial gpio SPI bit bang driver.
Submitted by:	ray
Obtained from:	zrouter
2016-05-26 07:20:33 +00:00
Luiz Otavio O Souza
0397efe813 Sort and remove a couple of unnecessary headers. 2016-05-22 04:02:34 +00:00
Luiz Otavio O Souza
03302aa37f Get rid of two consumers of gpiobus acquire/release.
The GPIO hardware should not be owned by a single device, this defeats any
chance of use of the GPIO controller as an interrupt source.

ow(4) is now the only consumer of this 'feature' before we can remove it
for good.

Discussed with:	ian, bsdimp
2016-05-22 03:55:57 +00:00
Luiz Otavio O Souza
16119eeded Use a better prefix for defines, return BUS_PROBE_DEFAULT for probe routine.
Refuse to attach if the number of given pins is not enough for our needs.
2016-05-22 03:34:18 +00:00
Luiz Otavio O Souza
fc5f218ade Fix probe routine to return BUS_PROBE_DEFAULT instead of BUS_PROBE_SPECIFIC.
While here fix a few style(9) issues.
2016-05-22 03:12:49 +00:00
Michal Meloun
e3da01a384 OFWGPIOBUS: Make ofwgpiobus_devclass externaly visible.
It's needed for binding of gpio controllers.
2016-05-15 14:43:52 +00:00
Oleksandr Tymoshenko
3c977d6f36 Fix detach routine for gpiokeys
- Release pin only when all per=key callouts are stopped
- Unregister keyboard when detaching device node
2016-05-12 20:15:23 +00:00
Oleksandr Tymoshenko
f058b6fbee Properly release mapped pin in gpio_pin_release 2016-05-12 20:13:16 +00:00
Oleksandr Tymoshenko
3381a3898a Add gpiobus_release_pin function to release mapped pin
Add gpiobus_release_pin as a counterpart for gpiobus_map_pin. Without it
it's impossible to properly release pin so if kernel module is reloaded
it can't re-use pins again
2016-05-12 20:12:45 +00:00
Oleksandr Tymoshenko
bc90a48ccf Add OF_prop_free function as a counterpart for OF_*prop_alloc
- Introduce new OF API function OF_prop_free to free memory allocated by
  OF_getprop_alloc and OF_getencprop_alloc. Current code just calls free(9)
  with M_OFWPROP memory class which assumes knowledge about OF_*prop_alloc
  functions' internals and leads to unneccessary code coupling

- Convert some of the free(..., M_OFWPROP) instances to OF_prop_free

Files affected by this commit are the ones I was able to test on real
hardware. The rest of free(..., M_OFWPROP) instances will be handled with
idividual maintainers

Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D6315
2016-05-11 18:20:02 +00:00
Oleksandr Tymoshenko
5a333f6f5f Add gpiokeys driver
gpiokey driver implements functional subset of gpiokeys device-tree bindings:
https://www.kernel.org/doc/Documentation/devicetree/bindings/input/gpio-keys.txt

It acts as a virtual keyboard, so keys are visible through kbdmux(4)

Driver maps linux scancodes for most common keys to FreeBSD scancodes and
also extends spec by introducing freebsd,code property to specify
FreeBSD-native scancodes.

Reviewed by:	mmel, jmcneill
Differential Revision:	https://reviews.freebsd.org/D6279
2016-05-11 17:57:26 +00:00
Oleksandr Tymoshenko
e2a1919df0 Use DEVMETHOD_END instead of its value to indicate end of methods table 2016-05-11 00:34:43 +00:00
Oleksandr Tymoshenko
26c36284a9 Use GPIO pin management API in gpiobacklight
- Get rid of hack with re-parenting gpio-leds node to gpiobus
- Use gpio_pin_set_active to enable/disable backlight, it automatically
    takes care of active-low pins
2016-05-11 00:26:52 +00:00
Oleksandr Tymoshenko
51702162cc Pass device tree node as a part of gpio_pin_get_by_ofw_XXX API
Current API assumes that "gpios" property belongs to the device's node but for
some binding it's not true: gpiokeys has set of child nodes with this property.

Patch adds new argument instead of replacing device_t because device_t will be
used to track ownership for allocated pins

Reviewed by:	mmel
Differential Revision:	https://reviews.freebsd.org/D6277
2016-05-10 20:02:03 +00:00
Michal Meloun
8442087f15 INTRNG: Define 'INTR_IRQ_INVALID' constant and use it consistently
as error indicator.
2016-04-28 12:04:12 +00:00
Michal Meloun
39f6c1bdf4 GPIO: Add support for gpio pin interrupts.
Add new function gpio_alloc_intr_resource(), which allows an allocation
of interrupt resource associated to given gpio pin. It also allows to
specify interrupt configuration.

Note: This functionality is dependent on INTRNG, and must be
implemented in each GPIO controller.
2016-04-28 12:03:22 +00:00
Oleksandr Tymoshenko
71c1e74434 Fix IIC "how" argument dereferencing on big-endian platforms
"how" argument is passed as value of int* pointer to callback
function but dereferenced as char* so only one byte taken into
into account. On little-endian systems it happens to work because
first byte is LSB that contains actual value, on big-endian it's
MSB and in this case it's always equal zero

PR:		207786
Submitted by:	chadf@triularity.org
2016-04-10 23:17:06 +00:00
Justin Hibbits
f8fd3fb518 Fix the resource_list_print_type() calls to use uintmax_t.
Missed a bunch from r297000.
2016-03-22 22:25:08 +00:00