Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * AD7879/AD7889 touchscreen (SPI bus)
0004  *
0005  * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
0006  */
0007 
0008 #include <linux/input.h>    /* BUS_SPI */
0009 #include <linux/pm.h>
0010 #include <linux/spi/spi.h>
0011 #include <linux/module.h>
0012 #include <linux/of.h>
0013 #include <linux/regmap.h>
0014 
0015 #include "ad7879.h"
0016 
0017 #define AD7879_DEVID        0x7A    /* AD7879/AD7889 */
0018 
0019 #define MAX_SPI_FREQ_HZ      5000000
0020 
0021 #define AD7879_CMD_MAGIC     0xE0
0022 #define AD7879_CMD_READ      BIT(2)
0023 
0024 static const struct regmap_config ad7879_spi_regmap_config = {
0025     .reg_bits = 16,
0026     .val_bits = 16,
0027     .max_register = 15,
0028     .read_flag_mask = AD7879_CMD_MAGIC | AD7879_CMD_READ,
0029     .write_flag_mask = AD7879_CMD_MAGIC,
0030 };
0031 
0032 static int ad7879_spi_probe(struct spi_device *spi)
0033 {
0034     struct regmap *regmap;
0035 
0036     /* don't exceed max specified SPI CLK frequency */
0037     if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) {
0038         dev_err(&spi->dev, "SPI CLK %d Hz?\n", spi->max_speed_hz);
0039         return -EINVAL;
0040     }
0041 
0042     regmap = devm_regmap_init_spi(spi, &ad7879_spi_regmap_config);
0043     if (IS_ERR(regmap))
0044         return PTR_ERR(regmap);
0045 
0046     return ad7879_probe(&spi->dev, regmap, spi->irq, BUS_SPI, AD7879_DEVID);
0047 }
0048 
0049 #ifdef CONFIG_OF
0050 static const struct of_device_id ad7879_spi_dt_ids[] = {
0051     { .compatible = "adi,ad7879", },
0052     { }
0053 };
0054 MODULE_DEVICE_TABLE(of, ad7879_spi_dt_ids);
0055 #endif
0056 
0057 static struct spi_driver ad7879_spi_driver = {
0058     .driver = {
0059         .name   = "ad7879",
0060         .pm = &ad7879_pm_ops,
0061         .of_match_table = of_match_ptr(ad7879_spi_dt_ids),
0062     },
0063     .probe      = ad7879_spi_probe,
0064 };
0065 
0066 module_spi_driver(ad7879_spi_driver);
0067 
0068 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
0069 MODULE_DESCRIPTION("AD7879(-1) touchscreen SPI bus driver");
0070 MODULE_LICENSE("GPL");
0071 MODULE_ALIAS("spi:ad7879");