linux/drivers/input/touchscreen/ad7879-spi.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0-or-later
   2/*
   3 * AD7879/AD7889 touchscreen (SPI bus)
   4 *
   5 * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
   6 */
   7
   8#include <linux/input.h>        /* BUS_SPI */
   9#include <linux/pm.h>
  10#include <linux/spi/spi.h>
  11#include <linux/module.h>
  12#include <linux/of.h>
  13#include <linux/regmap.h>
  14
  15#include "ad7879.h"
  16
  17#define AD7879_DEVID            0x7A    /* AD7879/AD7889 */
  18
  19#define MAX_SPI_FREQ_HZ      5000000
  20
  21#define AD7879_CMD_MAGIC     0xE0
  22#define AD7879_CMD_READ      BIT(2)
  23
  24static const struct regmap_config ad7879_spi_regmap_config = {
  25        .reg_bits = 16,
  26        .val_bits = 16,
  27        .max_register = 15,
  28        .read_flag_mask = AD7879_CMD_MAGIC | AD7879_CMD_READ,
  29        .write_flag_mask = AD7879_CMD_MAGIC,
  30};
  31
  32static int ad7879_spi_probe(struct spi_device *spi)
  33{
  34        struct regmap *regmap;
  35
  36        /* don't exceed max specified SPI CLK frequency */
  37        if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) {
  38                dev_err(&spi->dev, "SPI CLK %d Hz?\n", spi->max_speed_hz);
  39                return -EINVAL;
  40        }
  41
  42        regmap = devm_regmap_init_spi(spi, &ad7879_spi_regmap_config);
  43        if (IS_ERR(regmap))
  44                return PTR_ERR(regmap);
  45
  46        return ad7879_probe(&spi->dev, regmap, spi->irq, BUS_SPI, AD7879_DEVID);
  47}
  48
  49#ifdef CONFIG_OF
  50static const struct of_device_id ad7879_spi_dt_ids[] = {
  51        { .compatible = "adi,ad7879", },
  52        { }
  53};
  54MODULE_DEVICE_TABLE(of, ad7879_spi_dt_ids);
  55#endif
  56
  57static struct spi_driver ad7879_spi_driver = {
  58        .driver = {
  59                .name   = "ad7879",
  60                .pm     = &ad7879_pm_ops,
  61                .of_match_table = of_match_ptr(ad7879_spi_dt_ids),
  62        },
  63        .probe          = ad7879_spi_probe,
  64};
  65
  66module_spi_driver(ad7879_spi_driver);
  67
  68MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
  69MODULE_DESCRIPTION("AD7879(-1) touchscreen SPI bus driver");
  70MODULE_LICENSE("GPL");
  71MODULE_ALIAS("spi:ad7879");
  72