7 Commits

Author SHA1 Message Date
Alistair Delva
1f70bbcd4b ANDROID: gnss: Add command line test driver
This driver enables the "takeover" of a serdev bus device by the GNSS
subsystem. It can be used to test the GNSS subsystem without needing to
write a specific hardware backend.

The new module supports the following parameters:

  gnss_cmdline.serdev=driver/port/serdev
  gnss_cmdline.type=<protocol number>

An example which allows GNSS to wrap a platform serial8250 port and
advertise NMEA-0183 data is:

  gnss_cmdline.serdev=serial8250/serial0/serial0-0
                        ^          ^       ^
                       driver     port    serdev
  gnss_cmdline.type=0
                    ^
                    GNSS_TYPE_NMEA

Bug: 146517987
Change-Id: I421386ee4f2ba8f1f0832d9c56a067a600892d3c
Signed-off-by: Alistair Delva <adelva@google.com>
2019-12-19 17:41:39 -08:00
Johan Hovold
2982283bb0 BACKPORT: serdev: make synchronous write return bytes written
Make the synchronous serdev_device_write() helper behave analogous to
the asynchronous serdev_device_write_buf() by returning the number of
bytes written (or rather buffered) also on timeout.

This will allow drivers to distinguish the case where data was partially
written from the case where no data was written.

Also update the only two users that checked the return value.

Signed-off-by: Johan Hovold <johan@kernel.org>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 0bbf0a88fa29de6a043ba40058409c7e550fc8be)
[adelva: dropped changes to driver that was not backported]
Bug: 146062677
Change-Id: Ib9fb6041808e59f57d78fa23088bf37a8a8d4518
Signed-off-by: Alistair Delva <adelva@google.com>
2019-12-11 12:24:08 -08:00
Johan Hovold
4818e17215 UPSTREAM: gnss: serial: fix synchronous write timeout
Passing a timeout of zero to the synchronous serdev_device_write()
helper does currently not imply to wait forever (unlike passing zero to
serdev_device_wait_until_sent()). Instead, if there's insufficient
room in the write buffer, we'd end up with an incomplete write.

Fixes: 37768b054f20 ("gnss: add generic serial driver")
Cc: stable <stable@vger.kernel.org>     # 4.19
Signed-off-by: Johan Hovold <johan@kernel.org>
(cherry picked from commit 56a6c7268312cba9436b84cac01b3e502c5c511d)
Bug: 146062677
Change-Id: I6c7b31b385b962f2afc44f467b72ccaaab151332
Signed-off-by: Alistair Delva <adelva@google.com>
2019-12-11 12:22:54 -08:00
Dan Carpenter
4743b4fd4a UPSTREAM: gnss: fix potential error pointer dereference
The gnss_allocate_device() function returns a mix of NULL and error
pointers on error.  It should only return one or the other.  Since the
callers both check for NULL, I've modified it to return NULL on error.

Fixes: 2b6a44035143 ("gnss: add GNSS receiver subsystem")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit d9995a0fab40af333b08902ad43a387843ca0e17)
Bug: 146062677
Change-Id: I0d555d6459ab76a8c4eb8208a5bf469d04a16121
Signed-off-by: Alistair Delva <adelva@google.com>
2019-12-11 12:21:53 -08:00
Johan Hovold
38361f5185 BACKPORT: gnss: add receiver type support
Add a "type" device attribute and a "GNSS_TYPE" uevent variable which
can be used to determine the type of a GNSS receiver. The currently
identified types reflect the protocol(s) supported by a receiver:

	"NMEA"	NMEA 0183
	"SiRF"	SiRF Binary
	"UBX"	UBX

Note that both SiRF and UBX type receivers typically support a subset of
NMEA 0183 with vendor extensions (e.g. to allow switching to the vendor
protocol).

Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 10f146639fee5ffaf7cf0081c1af518f7d0c533c)
[adelva: dropped changes to drivers that were not backported]
Bug: 146062677
Change-Id: Id272aaa9aa59df41d5d94014edc835f242e719a6
Signed-off-by: Alistair Delva <adelva@google.com>
2019-12-11 12:19:38 -08:00
Johan Hovold
34c4103cfe UPSTREAM: gnss: add generic serial driver
Add a generic serial GNSS driver (library) which provides a common
implementation for the gnss interface and power management (runtime and
system suspend). This allows GNSS drivers for specific chip to be
implemented by simply providing a set_power() callback to handle three
states: ACTIVE, STANDBY and OFF.

Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 37768b054f2074f40de3cacd492baed482f5d9da)
Bug: 146062677
Change-Id: I7713c82eea2ce4a6a7956d74dfc964e6d012293c
Signed-off-by: Alistair Delva <adelva@google.com>
2019-12-11 12:02:26 -08:00
Johan Hovold
577ec2d381 BACKPORT: gnss: add GNSS receiver subsystem
Add a new subsystem for GNSS (e.g. GPS) receivers.

While GNSS receivers are typically accessed using a UART interface they
often also support other I/O interfaces such as I2C, SPI and USB, while
yet other devices use iomem or even some form of remote-processor
messaging (rpmsg).

The new GNSS subsystem abstracts the underlying interface and provides a
new "gnss" class type, which exposes a character-device interface (e.g.
/dev/gnss0) to user space. This allows GNSS receivers to have a
representation in the Linux device model, something which is important
not least for power management purposes.

Note that the character-device interface provides raw access to whatever
protocol the receiver is (currently) using, such as NMEA 0183, UBX or
SiRF Binary. These protocols are expected to be continued to be handled
by user space for the time being, even if some hybrid solutions are also
conceivable (e.g. to have kernel drivers issue management commands).

This will still allow for better platform integration by allowing GNSS
devices and their resources (e.g. regulators and enable-gpios) to be
described by firmware and managed by kernel drivers rather than
platform-specific scripts and services.

While the current interface is kept minimal, it could be extended using
IOCTLs, sysfs or uevents as needs and proper abstraction levels are
identified and determined (e.g. for device and feature identification).

Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 2b6a440351436d792b1960822da4b7d6e673f568)
[adelva: adjusted for drivers/Makefile conflict, __poll_t->unsigned int,
         EPOLL* -> POLL* for 4.14]
Bug: 146062677
Change-Id: I5704e952766cd8057fba3be3212091a726e0d85a
Signed-off-by: Alistair Delva <adelva@google.com>
2019-12-11 11:32:59 -08:00