Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Murata ZPA2326 SPI pressure and temperature sensor driver
0004  *
0005  * Copyright (c) 2016 Parrot S.A.
0006  *
0007  * Author: Gregor Boirie <gregor.boirie@parrot.com>
0008  */
0009 
0010 #include <linux/module.h>
0011 #include <linux/regmap.h>
0012 #include <linux/spi/spi.h>
0013 #include <linux/mod_devicetable.h>
0014 #include "zpa2326.h"
0015 
0016 /*
0017  * read_flag_mask:
0018  *   - address bit 7 must be set to request a register read operation
0019  *   - address bit 6 must be set to request register address auto increment
0020  */
0021 static const struct regmap_config zpa2326_regmap_spi_config = {
0022     .reg_bits       = 8,
0023     .val_bits       = 8,
0024     .writeable_reg  = zpa2326_isreg_writeable,
0025     .readable_reg   = zpa2326_isreg_readable,
0026     .precious_reg   = zpa2326_isreg_precious,
0027     .max_register   = ZPA2326_TEMP_OUT_H_REG,
0028     .read_flag_mask = BIT(7) | BIT(6),
0029     .cache_type     = REGCACHE_NONE,
0030 };
0031 
0032 static int zpa2326_probe_spi(struct spi_device *spi)
0033 {
0034     struct regmap *regmap;
0035     int            err;
0036 
0037     regmap = devm_regmap_init_spi(spi, &zpa2326_regmap_spi_config);
0038     if (IS_ERR(regmap)) {
0039         dev_err(&spi->dev, "failed to init registers map");
0040         return PTR_ERR(regmap);
0041     }
0042 
0043     /*
0044      * Enforce SPI slave settings to prevent from DT misconfiguration.
0045      *
0046      * Clock is idle high. Sampling happens on trailing edge, i.e., rising
0047      * edge. Maximum bus frequency is 1 MHz. Registers are 8 bits wide.
0048      */
0049     spi->mode = SPI_MODE_3;
0050     spi->max_speed_hz = min(spi->max_speed_hz, 1000000U);
0051     spi->bits_per_word = 8;
0052     err = spi_setup(spi);
0053     if (err < 0)
0054         return err;
0055 
0056     return zpa2326_probe(&spi->dev, spi_get_device_id(spi)->name,
0057                  spi->irq, ZPA2326_DEVICE_ID, regmap);
0058 }
0059 
0060 static void zpa2326_remove_spi(struct spi_device *spi)
0061 {
0062     zpa2326_remove(&spi->dev);
0063 }
0064 
0065 static const struct spi_device_id zpa2326_spi_ids[] = {
0066     { "zpa2326", 0 },
0067     { },
0068 };
0069 MODULE_DEVICE_TABLE(spi, zpa2326_spi_ids);
0070 
0071 static const struct of_device_id zpa2326_spi_matches[] = {
0072     { .compatible = "murata,zpa2326" },
0073     { }
0074 };
0075 MODULE_DEVICE_TABLE(of, zpa2326_spi_matches);
0076 
0077 static struct spi_driver zpa2326_spi_driver = {
0078     .driver = {
0079         .name           = "zpa2326-spi",
0080         .of_match_table = zpa2326_spi_matches,
0081         .pm             = ZPA2326_PM_OPS,
0082     },
0083     .probe    = zpa2326_probe_spi,
0084     .remove   = zpa2326_remove_spi,
0085     .id_table = zpa2326_spi_ids,
0086 };
0087 module_spi_driver(zpa2326_spi_driver);
0088 
0089 MODULE_AUTHOR("Gregor Boirie <gregor.boirie@parrot.com>");
0090 MODULE_DESCRIPTION("SPI driver for Murata ZPA2326 pressure sensor");
0091 MODULE_LICENSE("GPL v2");
0092 MODULE_IMPORT_NS(IIO_ZPA2326);