1 // SPDX-License-Identifier: GPL-2.0
3 * u-blox GNSS receiver driver
5 * Copyright (C) 2018 Johan Hovold <johan@kernel.org>
8 #include <linux/errno.h>
9 #include <linux/gnss.h>
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
14 #include <linux/regulator/consumer.h>
15 #include <linux/serdev.h>
20 struct regulator *vcc;
23 static int ubx_set_active(struct gnss_serial *gserial)
25 struct ubx_data *data = gnss_serial_get_drvdata(gserial);
28 ret = regulator_enable(data->vcc);
35 static int ubx_set_standby(struct gnss_serial *gserial)
37 struct ubx_data *data = gnss_serial_get_drvdata(gserial);
40 ret = regulator_disable(data->vcc);
47 static int ubx_set_power(struct gnss_serial *gserial,
48 enum gnss_serial_pm_state state)
51 case GNSS_SERIAL_ACTIVE:
52 return ubx_set_active(gserial);
54 case GNSS_SERIAL_STANDBY:
55 return ubx_set_standby(gserial);
61 static const struct gnss_serial_ops ubx_gserial_ops = {
62 .set_power = ubx_set_power,
65 static int ubx_probe(struct serdev_device *serdev)
67 struct gnss_serial *gserial;
68 struct ubx_data *data;
71 gserial = gnss_serial_allocate(serdev, sizeof(*data));
72 if (IS_ERR(gserial)) {
73 ret = PTR_ERR(gserial);
77 gserial->ops = &ubx_gserial_ops;
79 gserial->gdev->type = GNSS_TYPE_UBX;
81 data = gnss_serial_get_drvdata(gserial);
83 data->vcc = devm_regulator_get(&serdev->dev, "vcc");
84 if (IS_ERR(data->vcc)) {
85 ret = PTR_ERR(data->vcc);
86 goto err_free_gserial;
89 ret = devm_regulator_get_enable_optional(&serdev->dev, "v-bckp");
90 if (ret < 0 && ret != -ENODEV)
91 goto err_free_gserial;
93 ret = gnss_serial_register(gserial);
95 goto err_free_gserial;
100 gnss_serial_free(gserial);
105 static void ubx_remove(struct serdev_device *serdev)
107 struct gnss_serial *gserial = serdev_device_get_drvdata(serdev);
109 gnss_serial_deregister(gserial);
110 gnss_serial_free(gserial);
114 static const struct of_device_id ubx_of_match[] = {
115 { .compatible = "u-blox,neo-6m" },
116 { .compatible = "u-blox,neo-8" },
117 { .compatible = "u-blox,neo-m8" },
120 MODULE_DEVICE_TABLE(of, ubx_of_match);
123 static struct serdev_device_driver ubx_driver = {
126 .of_match_table = of_match_ptr(ubx_of_match),
127 .pm = &gnss_serial_pm_ops,
130 .remove = ubx_remove,
132 module_serdev_device_driver(ubx_driver);
134 MODULE_AUTHOR("Johan Hovold <johan@kernel.org>");
135 MODULE_DESCRIPTION("u-blox GNSS receiver driver");
136 MODULE_LICENSE("GPL v2");