Received: by 10.192.165.148 with SMTP id m20csp4881930imm; Tue, 24 Apr 2018 09:54:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx49h9q9aoBIbljoqQp9jkbes8e7iz1+f7DfdsBbXNf41I/mttC6ibGn7YbdqPgtbIEJf8oav X-Received: by 10.99.176.8 with SMTP id h8mr20854896pgf.448.1524588867078; Tue, 24 Apr 2018 09:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524588867; cv=none; d=google.com; s=arc-20160816; b=WmFQ4PdOBcT6MxU2f9LNopoaNDdKkyFgrctRvt5q9qRN3dWK+bFKX+8/CXj5+8tWHM c12tHvfmZ7w6AU6nARUA3mT/A64va4/mU/K77j2aRXu2up0UAKFQQ0NTa7EBa5mkHqmB h8Wqwqp9gwAhP/A1+OMrhXvUh/x7OY0C8mt4LGEQxiq/2KisvMFklQ+MEEapPXyz/cSA Yaq3hZAKtrN3SgH71gr2Eh8ZmmgGwGutuDZkbyc2S1f5y+F0xUv/hXmMhvznJ/vqvyHi Yp96jE/oKvCUpx8aJ2+1kTABUbsz5boDjGZwAWdOL62GUEvjuLrmKfgcXAuuoPxoVdjS 5c0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=ObXg4l/kVak6gliRmKsWYJqBBwDYsaqAprR++xnaDFQ=; b=ZCtOytc3Lz/PVX+UDCxjqpEK5HGggC420J/CnXVTrGK0UgCcncTnClNpCOAEffwC/W X0VeSd0FwvpkVbVWXjGJdfkmUitzHoaEvLNWMPI9TfLMmruheNGbjW0d7h/UrMRNCcML 0lm//es+NV2ckf+uOmYL1YqrIm9GkfHR7db37RwWcWshT5DO8JK0ep7i7yvN27SVhsjH Ot5DVLsPc7DRnFrzm84FrLXhSjChTGeQAPh5T2IWEcRslYt3Z2yFMv+VrqfcR35iG6tt 5PFfbSvk5hxDHpZHqkf/SuK2E3MStYNWUThxyAQqjJTZE/hXCi4KP+AQMtXRCcuVZBbT Md3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=fj3i7AqP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n86si13969095pfj.86.2018.04.24.09.54.12; Tue, 24 Apr 2018 09:54:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=fj3i7AqP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751567AbeDXQwU (ORCPT + 99 others); Tue, 24 Apr 2018 12:52:20 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:41671 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751280AbeDXQur (ORCPT ); Tue, 24 Apr 2018 12:50:47 -0400 Received: by mail-lf0-f67.google.com with SMTP id o123-v6so18747885lfe.8; Tue, 24 Apr 2018 09:50:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ObXg4l/kVak6gliRmKsWYJqBBwDYsaqAprR++xnaDFQ=; b=fj3i7AqPdMBK/xkqHFNHSjcVSo7CBdmpAF4aMIuB9Rd35lbMFS2EIUbesivRl9AwAL ByJbOcO/HMGVsOVz/FyNhb8RZ2Os1dg7J6eDah0a8AYgvwlWPAcKXdwtTL2xbYdP/1vn u63XP/0SNa8jpx3wemuOL5xCWXv8RqVFHJnbBK396K46OWD4sAvrufMX76OQeT/vqefs L1B2G8ykRibc7UWhFsJbndrMz9rvF4Bs1BB6UGiKSeXvLqZtQ7l8ToUBZI6L7BNAuxjx xcn2tF1o3wuxkpasvCYtALijBkO0BaYA5CALMY8ppRL+U5bshH/QJ+3Dyr0Me9EjmOpj RYoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ObXg4l/kVak6gliRmKsWYJqBBwDYsaqAprR++xnaDFQ=; b=aF/NlE7ElvU+UuOrgOd5n3mpuTmk5YO2JweEajGeufqN6NtgP4YfzDZYYPD/B4GUcj 1DSul89n7OZzpnQFMWPhR2xOXb9bbwUiqn/OIoRee7DoQVYT8tIhxV4FMgeVBhzjwZMi 6KZt+Ja/2ahPq9d+sTc5+oK7RtEeckFK18s3xeIArhK7tB356fEJqEYKk910dfvAtqq0 TqmMuNLGwoJkNx0LI/jRSC7h9I5M9LeKi6v4rJHzE8cGxZOBirQHdmuHXEdlmSQCG/+k 7VkNqnOkdmFd6VS034SS8PzdkDAn7E1UZtUo/mzZqLBcyX9x1DrtIBVPenQJt5xeuqVz gVpg== X-Gm-Message-State: ALQs6tC9cFWWVyZUMRuMJS87NN4mv3tW6AQKl7SMV/83K+Hi1ACqbnV1 Cr13j4diekh0mgtSgIHe/js= X-Received: by 10.46.89.212 with SMTP id g81mr18096251ljf.4.1524588646037; Tue, 24 Apr 2018 09:50:46 -0700 (PDT) Received: from xi.terra (c-8bb2e655.07-184-6d6c6d4.cust.bredbandsbolaget.se. [85.230.178.139]) by smtp.gmail.com with ESMTPSA id r83-v6sm2063667lff.93.2018.04.24.09.50.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 09:50:44 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.90_1) (envelope-from ) id 1fB19K-0004Tv-12; Tue, 24 Apr 2018 18:50:38 +0200 From: Johan Hovold To: Greg Kroah-Hartman , Rob Herring , Mark Rutland Cc: Andreas Kemnade , Arnd Bergmann , "H . Nikolaus Schaller" , Pavel Machek , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Johan Hovold Subject: [PATCH 5/7] gnss: add driver for u-blox receivers Date: Tue, 24 Apr 2018 18:34:56 +0200 Message-Id: <20180424163458.11947-6-johan@kernel.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180424163458.11947-1-johan@kernel.org> References: <20180424163458.11947-1-johan@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add driver for serial-connected u-blox GNSS receivers. Note that the driver uses the generic GNSS serial implementation and therefore essentially only manages power abstracted into three power states: ACTIVE, STANDBY, and OFF. For u-blox receivers with a single supply and no enable-gpios, this simply means that the main supply is disabled in STANDBY and OFF. Note that timepulse-support is not yet implemented. Signed-off-by: Johan Hovold --- drivers/gnss/Kconfig | 13 +++++ drivers/gnss/Makefile | 3 + drivers/gnss/ubx.c | 133 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 drivers/gnss/ubx.c diff --git a/drivers/gnss/Kconfig b/drivers/gnss/Kconfig index f8ee54f99a8d..784b8c0367d9 100644 --- a/drivers/gnss/Kconfig +++ b/drivers/gnss/Kconfig @@ -15,4 +15,17 @@ if GNSS config GNSS_SERIAL tristate +config GNSS_UBX_SERIAL + tristate "u-blox GNSS receiver support" + depends on SERIAL_DEV_BUS + select GNSS_SERIAL + ---help--- + Say Y here if you have a u-blox GNSS receiver which uses a serial + interface. + + To compile this driver as a module, choose M here: the module will + be called gnss-ubx. + + If unsure, say N. + endif # GNSS diff --git a/drivers/gnss/Makefile b/drivers/gnss/Makefile index 171aba71684d..d9295b20b7bc 100644 --- a/drivers/gnss/Makefile +++ b/drivers/gnss/Makefile @@ -8,3 +8,6 @@ gnss-y := core.o obj-$(CONFIG_GNSS_SERIAL) += gnss-serial.o gnss-serial-y := serial.o + +obj-$(CONFIG_GNSS_UBX_SERIAL) += gnss-ubx.o +gnss-ubx-y := ubx.o diff --git a/drivers/gnss/ubx.c b/drivers/gnss/ubx.c new file mode 100644 index 000000000000..2f2f00202b5b --- /dev/null +++ b/drivers/gnss/ubx.c @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * u-blox GNSS receiver driver + * + * Copyright (C) 2018 Johan Hovold + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "serial.h" + +struct ubx_data { + struct regulator *vcc; +}; + +static int ubx_set_active(struct gnss_serial *gserial) +{ + struct ubx_data *data = gnss_serial_get_drvdata(gserial); + int ret; + + dev_dbg(&gserial->serdev->dev, "%s\n", __func__); + + ret = regulator_enable(data->vcc); + if (ret) + return ret; + + return 0; +} + +static int ubx_set_standby(struct gnss_serial *gserial) +{ + struct ubx_data *data = gnss_serial_get_drvdata(gserial); + int ret; + + dev_dbg(&gserial->serdev->dev, "%s\n", __func__); + + ret = regulator_disable(data->vcc); + if (ret) + return ret; + + return 0; +} + +static int +ubx_set_power(struct gnss_serial *gserial, enum gnss_serial_pm_state state) +{ + switch (state) { + case GNSS_SERIAL_ACTIVE: + return ubx_set_active(gserial); + case GNSS_SERIAL_OFF: + case GNSS_SERIAL_STANDBY: + return ubx_set_standby(gserial); + } + + return -EINVAL; +} + +const struct gnss_serial_ops ubx_gserial_ops = { + .set_power = ubx_set_power, +}; + +static int ubx_probe(struct serdev_device *serdev) +{ + struct gnss_serial *gserial; + struct ubx_data *data; + int ret; + + gserial = gnss_serial_allocate(serdev, sizeof(*data)); + if (IS_ERR(gserial)) { + ret = PTR_ERR(gserial); + return ret; + } + + gserial->ops = &ubx_gserial_ops; + + data = gnss_serial_get_drvdata(gserial); + + data->vcc = devm_regulator_get(&serdev->dev, "vcc"); + if (IS_ERR(data->vcc)) { + ret = PTR_ERR(data->vcc); + goto err_free_gserial; + } + + ret = gnss_serial_register(gserial); + if (ret) + goto err_free_gserial; + + return 0; + +err_free_gserial: + gnss_serial_free(gserial); + + return ret; +} + +static void ubx_remove(struct serdev_device *serdev) +{ + struct gnss_serial *gserial = serdev_device_get_drvdata(serdev); + + gnss_serial_deregister(gserial); + gnss_serial_free(gserial); +}; + +#ifdef CONFIG_OF +static const struct of_device_id ubx_of_match[] = { + { .compatible = "u-blox,neo-8" }, + { .compatible = "u-blox,neo-m8" }, + {}, +}; +MODULE_DEVICE_TABLE(of, ubx_of_match); +#endif + +static struct serdev_device_driver ubx_driver = { + .driver = { + .name = "gnss-ubx", + .of_match_table = of_match_ptr(ubx_of_match), + .pm = &gnss_serial_pm_ops, + }, + .probe = ubx_probe, + .remove = ubx_remove, +}; +module_serdev_device_driver(ubx_driver); + +MODULE_AUTHOR("Johan Hovold "); +MODULE_DESCRIPTION("u-blox GNSS receiver driver"); +MODULE_LICENSE("GPL v2"); -- 2.17.0