Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * u-blox GNSS receiver driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2018 Johan Hovold <johan@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/gnss.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/serdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "serial.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) struct ubx_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	struct regulator *v_bckp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct regulator *vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static int ubx_set_active(struct gnss_serial *gserial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct ubx_data *data = gnss_serial_get_drvdata(gserial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	ret = regulator_enable(data->vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int ubx_set_standby(struct gnss_serial *gserial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct ubx_data *data = gnss_serial_get_drvdata(gserial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	ret = regulator_disable(data->vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static int ubx_set_power(struct gnss_serial *gserial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 				enum gnss_serial_pm_state state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	case GNSS_SERIAL_ACTIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		return ubx_set_active(gserial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	case GNSS_SERIAL_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	case GNSS_SERIAL_STANDBY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		return ubx_set_standby(gserial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static const struct gnss_serial_ops ubx_gserial_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	.set_power = ubx_set_power,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static int ubx_probe(struct serdev_device *serdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct gnss_serial *gserial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct ubx_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	gserial = gnss_serial_allocate(serdev, sizeof(*data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (IS_ERR(gserial)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		ret = PTR_ERR(gserial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	gserial->ops = &ubx_gserial_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	gserial->gdev->type = GNSS_TYPE_UBX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	data = gnss_serial_get_drvdata(gserial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	data->vcc = devm_regulator_get(&serdev->dev, "vcc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (IS_ERR(data->vcc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		ret = PTR_ERR(data->vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		goto err_free_gserial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	data->v_bckp = devm_regulator_get_optional(&serdev->dev, "v-bckp");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (IS_ERR(data->v_bckp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		ret = PTR_ERR(data->v_bckp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		if (ret == -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			data->v_bckp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			goto err_free_gserial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (data->v_bckp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		ret = regulator_enable(data->v_bckp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			goto err_free_gserial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	ret = gnss_serial_register(gserial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		goto err_disable_v_bckp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) err_disable_v_bckp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (data->v_bckp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		regulator_disable(data->v_bckp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) err_free_gserial:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	gnss_serial_free(gserial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static void ubx_remove(struct serdev_device *serdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct gnss_serial *gserial = serdev_device_get_drvdata(serdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct ubx_data *data = gnss_serial_get_drvdata(gserial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	gnss_serial_deregister(gserial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (data->v_bckp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		regulator_disable(data->v_bckp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	gnss_serial_free(gserial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static const struct of_device_id ubx_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	{ .compatible = "u-blox,neo-6m" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	{ .compatible = "u-blox,neo-8" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	{ .compatible = "u-blox,neo-m8" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) MODULE_DEVICE_TABLE(of, ubx_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static struct serdev_device_driver ubx_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		.name		= "gnss-ubx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		.of_match_table	= of_match_ptr(ubx_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		.pm		= &gnss_serial_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	.probe	= ubx_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	.remove	= ubx_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) module_serdev_device_driver(ubx_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) MODULE_AUTHOR("Johan Hovold <johan@kernel.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) MODULE_DESCRIPTION("u-blox GNSS receiver driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) MODULE_LICENSE("GPL v2");