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