summaryrefslogtreecommitdiffstats
path: root/drivers/gnss/core.c
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2018-06-01 10:22:59 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-06-28 20:32:51 +0900
commit10f146639fee5ffaf7cf0081c1af518f7d0c533c (patch)
tree1fdc31ab3bf22339c89db3b7ba134c6aad9579cf /drivers/gnss/core.c
parentd2efbbd18b1e26ac79401841089e4a4b97d745c3 (diff)
downloadlinux-10f146639fee5ffaf7cf0081c1af518f7d0c533c.tar.bz2
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>
Diffstat (limited to 'drivers/gnss/core.c')
-rw-r--r--drivers/gnss/core.c49
1 files changed, 49 insertions, 0 deletions
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;