From: Johan Hovold <johan@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>
Cc: Andreas Kemnade <andreas@kemnade.info>,
Arnd Bergmann <arnd@arndb.de>,
"H . Nikolaus Schaller" <hns@goldelico.com>,
Pavel Machek <pavel@ucw.cz>,
Marcel Holtmann <marcel@holtmann.org>,
Sebastian Reichel <sebastian.reichel@collabora.co.uk>,
Tony Lindgren <tony@atomide.com>,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
Johan Hovold <johan@kernel.org>
Subject: [PATCH v2 8/8] gnss: add device type support
Date: Wed, 30 May 2018 12:32:42 +0200 [thread overview]
Message-ID: <20180530103242.20773-9-johan@kernel.org> (raw)
In-Reply-To: <20180530103242.20773-1-johan@kernel.org>
Add a "type" device attribute and a "GNSS_TYPE" uevent variable which
can be used to determine the type of a GNSS device. The currently
identified types reflect the protocol(s) supported by a device:
"NMEA" NMEA 0183
"SiRF" SiRF Binary
"UBX" UBX
Note that both SiRF and UBX type devices 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>
---
Documentation/ABI/testing/sysfs-class-gnss | 15 +++++++
MAINTAINERS | 1 +
drivers/gnss/core.c | 49 ++++++++++++++++++++++
drivers/gnss/sirf.c | 1 +
drivers/gnss/ubx.c | 2 +
include/linux/gnss.h | 9 ++++
6 files changed, 77 insertions(+)
create mode 100644 Documentation/ABI/testing/sysfs-class-gnss
diff --git a/Documentation/ABI/testing/sysfs-class-gnss b/Documentation/ABI/testing/sysfs-class-gnss
new file mode 100644
index 000000000000..3bcdf8e2496a
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-gnss
@@ -0,0 +1,15 @@
+What: /sys/class/gnss/gnssN/type
+Date: May 2018
+KernelVersion: 4.18
+Contact: Johan Hovold <johan@kernel.org>
+Description:
+ The GNSS device type. The currently identified types reflect
+ the protocol(s) supported by the device:
+
+ "NMEA" NMEA 0183
+ "SiRF" SiRF Binary
+ "UBX" UBX
+
+ Note that also non-"NMEA" type devices typically support a
+ subset of NMEA 0183 with vendor extensions (e.g. to allow
+ switching to a vendor protocol).
diff --git a/MAINTAINERS b/MAINTAINERS
index fa219e80a1f8..e666bc28a102 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5965,6 +5965,7 @@ F: include/uapi/linux/gigaset_dev.h
GNSS SUBSYSTEM
M: Johan Hovold <johan@kernel.org>
S: Maintained
+F: Documentation/ABI/testing/sysfs-class-gnss
F: Documentation/devicetree/bindings/gnss/
F: drivers/gnss/
F: include/linux/gnss.h
diff --git a/drivers/gnss/core.c b/drivers/gnss/core.c
index 307894ca2725..f30ef8338b3a 100644
--- a/drivers/gnss/core.c
+++ b/drivers/gnss/core.c
@@ -330,6 +330,52 @@ int gnss_insert_raw(struct gnss_device *gdev, const unsigned char *buf,
}
EXPORT_SYMBOL_GPL(gnss_insert_raw);
+static const char * const gnss_type_names[GNSS_TYPE_COUNT] = {
+ [GNSS_TYPE_NMEA] = "NMEA",
+ [GNSS_TYPE_SIRF] = "SiRF",
+ [GNSS_TYPE_UBX] = "UBX",
+};
+
+static const char *gnss_type_name(struct gnss_device *gdev)
+{
+ const char *name = NULL;
+
+ if (gdev->type < GNSS_TYPE_COUNT)
+ name = gnss_type_names[gdev->type];
+
+ if (!name)
+ dev_WARN(&gdev->dev, "type name not defined\n");
+
+ return name;
+}
+
+static ssize_t type_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct gnss_device *gdev = to_gnss_device(dev);
+
+ return sprintf(buf, "%s\n", gnss_type_name(gdev));
+}
+static DEVICE_ATTR_RO(type);
+
+static struct attribute *gnss_attrs[] = {
+ &dev_attr_type.attr,
+ NULL,
+};
+ATTRIBUTE_GROUPS(gnss);
+
+static int gnss_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+ struct gnss_device *gdev = to_gnss_device(dev);
+ int ret;
+
+ ret = add_uevent_var(env, "GNSS_TYPE=%s", gnss_type_name(gdev));
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
static int __init gnss_module_init(void)
{
int ret;
@@ -347,6 +393,9 @@ static int __init gnss_module_init(void)
goto err_unregister_chrdev;
}
+ gnss_class->dev_groups = gnss_groups;
+ gnss_class->dev_uevent = gnss_uevent;
+
pr_info("GNSS driver registered with major %d\n", MAJOR(gnss_first));
return 0;
diff --git a/drivers/gnss/sirf.c b/drivers/gnss/sirf.c
index 5fb0f730db48..79cb98950013 100644
--- a/drivers/gnss/sirf.c
+++ b/drivers/gnss/sirf.c
@@ -267,6 +267,7 @@ static int sirf_probe(struct serdev_device *serdev)
if (!gdev)
return -ENOMEM;
+ gdev->type = GNSS_TYPE_SIRF;
gdev->ops = &sirf_gnss_ops;
gnss_set_drvdata(gdev, data);
diff --git a/drivers/gnss/ubx.c b/drivers/gnss/ubx.c
index ecddfb362a6f..902b6854b7db 100644
--- a/drivers/gnss/ubx.c
+++ b/drivers/gnss/ubx.c
@@ -77,6 +77,8 @@ static int ubx_probe(struct serdev_device *serdev)
gserial->ops = &ubx_gserial_ops;
+ gserial->gdev->type = GNSS_TYPE_UBX;
+
data = gnss_serial_get_drvdata(gserial);
data->vcc = devm_regulator_get(&serdev->dev, "vcc");
diff --git a/include/linux/gnss.h b/include/linux/gnss.h
index e26aeac1e0e2..43546977098c 100644
--- a/include/linux/gnss.h
+++ b/include/linux/gnss.h
@@ -18,6 +18,14 @@
struct gnss_device;
+enum gnss_type {
+ GNSS_TYPE_NMEA = 0,
+ GNSS_TYPE_SIRF,
+ GNSS_TYPE_UBX,
+
+ GNSS_TYPE_COUNT
+};
+
struct gnss_operations {
int (*open)(struct gnss_device *gdev);
void (*close)(struct gnss_device *gdev);
@@ -30,6 +38,7 @@ struct gnss_device {
struct cdev cdev;
int id;
+ enum gnss_type type;
unsigned long flags;
struct rw_semaphore rwsem;
--
2.17.0
next prev parent reply other threads:[~2018-05-30 10:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-30 10:32 [PATCH v2 0/8] gnss: add new GNSS subsystem Johan Hovold
2018-05-30 10:32 ` [PATCH v2 1/8] gnss: add GNSS receiver subsystem Johan Hovold
2018-05-30 10:32 ` [PATCH v2 2/8] dt-bindings: add generic gnss binding Johan Hovold
2018-05-30 10:32 ` [PATCH v2 3/8] gnss: add generic serial driver Johan Hovold
2018-05-30 10:32 ` [PATCH v2 4/8] dt-bindings: gnss: add u-blox binding Johan Hovold
2018-05-31 3:58 ` Rob Herring
2018-05-31 8:22 ` Johan Hovold
2018-05-31 13:55 ` Rob Herring
2018-05-31 14:34 ` Johan Hovold
2018-05-31 15:58 ` Rob Herring
2018-06-01 8:15 ` Johan Hovold
2018-05-30 10:32 ` [PATCH v2 5/8] gnss: add driver for u-blox receivers Johan Hovold
2018-06-02 6:07 ` kbuild test robot
2018-06-02 6:07 ` [RFC PATCH] gnss: ubx_gserial_ops can be static kbuild test robot
2018-05-30 10:32 ` [PATCH v2 6/8] dt-bindings: gnss: add sirfstar binding Johan Hovold
2018-05-30 10:32 ` [PATCH v2 7/8] gnss: add driver for sirfstar-based receivers Johan Hovold
2018-05-30 10:32 ` Johan Hovold [this message]
2018-05-30 14:38 ` [PATCH v2 0/8] gnss: add new GNSS subsystem Richard Cochran
2018-05-31 8:52 ` Johan Hovold
2018-05-31 9:52 ` H. Nikolaus Schaller
2018-05-31 11:47 ` Johan Hovold
2018-05-31 13:33 ` H. Nikolaus Schaller
2018-05-31 13:37 ` Johan Hovold
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180530103242.20773-9-johan@kernel.org \
--to=johan@kernel.org \
--cc=andreas@kemnade.info \
--cc=arnd@arndb.de \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hns@goldelico.com \
--cc=linux-kernel@vger.kernel.org \
--cc=marcel@holtmann.org \
--cc=mark.rutland@arm.com \
--cc=pavel@ucw.cz \
--cc=robh+dt@kernel.org \
--cc=sebastian.reichel@collabora.co.uk \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).