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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Freescale MPL115A1 pressure/temperature sensor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2016 Akinobu Mita <akinobu.mita@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Datasheet: http://www.nxp.com/files/sensors/doc/data_sheet/MPL115A1.pdf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/spi/spi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "mpl115.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define MPL115_SPI_WRITE(address)	((address) << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define MPL115_SPI_READ(address)	(0x80 | (address) << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) struct mpl115_spi_buf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	u8 tx[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	u8 rx[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static int mpl115_spi_init(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct spi_device *spi = to_spi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct mpl115_spi_buf *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	buf = devm_kzalloc(dev, sizeof(*buf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	spi_set_drvdata(spi, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static int mpl115_spi_read(struct device *dev, u8 address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct spi_device *spi = to_spi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct mpl115_spi_buf *buf = spi_get_drvdata(spi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct spi_transfer xfer = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		.tx_buf = buf->tx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		.rx_buf = buf->rx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		.len = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	buf->tx[0] = MPL115_SPI_READ(address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	buf->tx[2] = MPL115_SPI_READ(address + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	ret = spi_sync_transfer(spi, &xfer, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return (buf->rx[1] << 8) | buf->rx[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static int mpl115_spi_write(struct device *dev, u8 address, u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct spi_device *spi = to_spi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct mpl115_spi_buf *buf = spi_get_drvdata(spi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct spi_transfer xfer = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		.tx_buf = buf->tx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		.len = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	buf->tx[0] = MPL115_SPI_WRITE(address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	buf->tx[1] = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return spi_sync_transfer(spi, &xfer, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static const struct mpl115_ops mpl115_spi_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.init = mpl115_spi_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.read = mpl115_spi_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.write = mpl115_spi_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static int mpl115_spi_probe(struct spi_device *spi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	const struct spi_device_id *id = spi_get_device_id(spi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	return mpl115_probe(&spi->dev, id->name, &mpl115_spi_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static const struct spi_device_id mpl115_spi_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	{ "mpl115", 0 },
^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) MODULE_DEVICE_TABLE(spi, mpl115_spi_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static struct spi_driver mpl115_spi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		.name   = "mpl115",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	.probe = mpl115_spi_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	.id_table = mpl115_spi_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) module_spi_driver(mpl115_spi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) MODULE_DESCRIPTION("Freescale MPL115A1 pressure/temperature driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) MODULE_LICENSE("GPL");