tsc2005.c 2.2 KB
Newer Older
1 2 3 4
/*
 * TSC2005 touchscreen driver
 *
 * Copyright (C) 2006-2010 Nokia Corporation
5 6
 * Copyright (C) 2015 QWERTY Embedded Design
 * Copyright (C) 2015 EMAC Inc.
7
 *
8
 * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com>
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 */

#include <linux/module.h>
#include <linux/input.h>
#include <linux/spi/spi.h>
24
#include <linux/regmap.h>
25
#include "tsc200x-core.h"
26

27
static int tsc2005_cmd(struct device *dev, u8 cmd)
28
{
29 30
	u8 tx = TSC2005_CMD | TSC2005_CMD_12BIT | cmd;
	struct spi_transfer xfer = {
31 32 33
		.tx_buf         = &tx,
		.len            = 1,
		.bits_per_word  = 8,
34
	};
35
	struct spi_message msg;
36
	struct spi_device *spi = to_spi_device(dev);
37
	int error;
38 39 40

	spi_message_init(&msg);
	spi_message_add_tail(&xfer, &msg);
41

42
	error = spi_sync(spi, &msg);
43
	if (error) {
44
		dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
45 46 47 48 49
			__func__, cmd, error);
		return error;
	}

	return 0;
50 51
}

B
Bill Pemberton 已提交
52
static int tsc2005_probe(struct spi_device *spi)
53
{
54
	int error;
55

56 57 58 59
	spi->mode = SPI_MODE_0;
	spi->bits_per_word = 8;
	if (!spi->max_speed_hz)
		spi->max_speed_hz = TSC2005_SPI_MAX_SPEED_HZ;
60

61 62 63
	error = spi_setup(spi);
	if (error)
		return error;
64

65 66 67
	return tsc200x_probe(&spi->dev, spi->irq, BUS_SPI,
			     devm_regmap_init_spi(spi, &tsc200x_regmap_config),
			     tsc2005_cmd);
68 69
}

B
Bill Pemberton 已提交
70
static int tsc2005_remove(struct spi_device *spi)
71
{
72
	return tsc200x_remove(&spi->dev);
73 74 75
}

static struct spi_driver tsc2005_driver = {
76 77 78
	.driver	= {
		.name	= "tsc2005",
		.owner	= THIS_MODULE,
79
		.pm	= &tsc200x_pm_ops,
80
	},
81
	.probe	= tsc2005_probe,
B
Bill Pemberton 已提交
82
	.remove	= tsc2005_remove,
83
};
84
module_spi_driver(tsc2005_driver);
85

86
MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
87
MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
88
MODULE_LICENSE("GPL");
P
Pali Rohár 已提交
89
MODULE_ALIAS("spi:tsc2005");