2019-05-29 16:57:44 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2016-01-16 01:00:03 +09:00
|
|
|
/*
|
|
|
|
* Freescale MPL115A1 pressure/temperature sensor
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Akinobu Mita <akinobu.mita@gmail.com>
|
|
|
|
*
|
|
|
|
* Datasheet: http://www.nxp.com/files/sensors/doc/data_sheet/MPL115A1.pdf
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
|
|
|
|
#include "mpl115.h"
|
|
|
|
|
|
|
|
#define MPL115_SPI_WRITE(address) ((address) << 1)
|
|
|
|
#define MPL115_SPI_READ(address) (0x80 | (address) << 1)
|
|
|
|
|
|
|
|
struct mpl115_spi_buf {
|
|
|
|
u8 tx[4];
|
|
|
|
u8 rx[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
static int mpl115_spi_init(struct device *dev)
|
|
|
|
{
|
|
|
|
struct spi_device *spi = to_spi_device(dev);
|
|
|
|
struct mpl115_spi_buf *buf;
|
|
|
|
|
|
|
|
buf = devm_kzalloc(dev, sizeof(*buf), GFP_KERNEL);
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
spi_set_drvdata(spi, buf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpl115_spi_read(struct device *dev, u8 address)
|
|
|
|
{
|
|
|
|
struct spi_device *spi = to_spi_device(dev);
|
|
|
|
struct mpl115_spi_buf *buf = spi_get_drvdata(spi);
|
|
|
|
struct spi_transfer xfer = {
|
|
|
|
.tx_buf = buf->tx,
|
|
|
|
.rx_buf = buf->rx,
|
|
|
|
.len = 4,
|
|
|
|
};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
buf->tx[0] = MPL115_SPI_READ(address);
|
|
|
|
buf->tx[2] = MPL115_SPI_READ(address + 1);
|
|
|
|
|
|
|
|
ret = spi_sync_transfer(spi, &xfer, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return (buf->rx[1] << 8) | buf->rx[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpl115_spi_write(struct device *dev, u8 address, u8 value)
|
|
|
|
{
|
|
|
|
struct spi_device *spi = to_spi_device(dev);
|
|
|
|
struct mpl115_spi_buf *buf = spi_get_drvdata(spi);
|
|
|
|
struct spi_transfer xfer = {
|
|
|
|
.tx_buf = buf->tx,
|
|
|
|
.len = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
buf->tx[0] = MPL115_SPI_WRITE(address);
|
|
|
|
buf->tx[1] = value;
|
|
|
|
|
|
|
|
return spi_sync_transfer(spi, &xfer, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct mpl115_ops mpl115_spi_ops = {
|
|
|
|
.init = mpl115_spi_init,
|
|
|
|
.read = mpl115_spi_read,
|
|
|
|
.write = mpl115_spi_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int mpl115_spi_probe(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
const struct spi_device_id *id = spi_get_device_id(spi);
|
|
|
|
|
|
|
|
return mpl115_probe(&spi->dev, id->name, &mpl115_spi_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spi_device_id mpl115_spi_ids[] = {
|
|
|
|
{ "mpl115", 0 },
|
2025-04-11 15:49:34 -05:00
|
|
|
{ }
|
2016-01-16 01:00:03 +09:00
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(spi, mpl115_spi_ids);
|
|
|
|
|
|
|
|
static struct spi_driver mpl115_spi_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "mpl115",
|
2022-10-10 23:07:20 +05:30
|
|
|
.pm = pm_ptr(&mpl115_dev_pm_ops),
|
2016-01-16 01:00:03 +09:00
|
|
|
},
|
|
|
|
.probe = mpl115_spi_probe,
|
|
|
|
.id_table = mpl115_spi_ids,
|
|
|
|
};
|
|
|
|
module_spi_driver(mpl115_spi_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");
|
|
|
|
MODULE_DESCRIPTION("Freescale MPL115A1 pressure/temperature driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
module: Convert symbol namespace to string literal
Clean up the existing export namespace code along the same lines of
commit 33def8498fdd ("treewide: Convert macro and uses of __section(foo)
to __section("foo")") and for the same reason, it is not desired for the
namespace argument to be a macro expansion itself.
Scripted using
git grep -l -e MODULE_IMPORT_NS -e EXPORT_SYMBOL_NS | while read file;
do
awk -i inplace '
/^#define EXPORT_SYMBOL_NS/ {
gsub(/__stringify\(ns\)/, "ns");
print;
next;
}
/^#define MODULE_IMPORT_NS/ {
gsub(/__stringify\(ns\)/, "ns");
print;
next;
}
/MODULE_IMPORT_NS/ {
$0 = gensub(/MODULE_IMPORT_NS\(([^)]*)\)/, "MODULE_IMPORT_NS(\"\\1\")", "g");
}
/EXPORT_SYMBOL_NS/ {
if ($0 ~ /(EXPORT_SYMBOL_NS[^(]*)\(([^,]+),/) {
if ($0 !~ /(EXPORT_SYMBOL_NS[^(]*)\(([^,]+), ([^)]+)\)/ &&
$0 !~ /(EXPORT_SYMBOL_NS[^(]*)\(\)/ &&
$0 !~ /^my/) {
getline line;
gsub(/[[:space:]]*\\$/, "");
gsub(/[[:space:]]/, "", line);
$0 = $0 " " line;
}
$0 = gensub(/(EXPORT_SYMBOL_NS[^(]*)\(([^,]+), ([^)]+)\)/,
"\\1(\\2, \"\\3\")", "g");
}
}
{ print }' $file;
done
Requested-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://mail.google.com/mail/u/2/#inbox/FMfcgzQXKWgMmjdFwwdsfgxzKpVHWPlc
Acked-by: Greg KH <gregkh@linuxfoundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2024-12-02 15:59:47 +01:00
|
|
|
MODULE_IMPORT_NS("IIO_MPL115");
|