18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * cyttsp_i2c.c
48c2ecf20Sopenharmony_ci * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver.
58c2ecf20Sopenharmony_ci * For use with Cypress  Txx4xx parts.
68c2ecf20Sopenharmony_ci * Supported parts include:
78c2ecf20Sopenharmony_ci * TMA4XX
88c2ecf20Sopenharmony_ci * TMA1036
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc.
118c2ecf20Sopenharmony_ci * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org>
128c2ecf20Sopenharmony_ci * Copyright (C) 2013 Cypress Semiconductor
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "cyttsp4_core.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <linux/i2c.h>
208c2ecf20Sopenharmony_ci#include <linux/input.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define CYTTSP4_I2C_DATA_SIZE	(3 * 256)
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistatic const struct cyttsp4_bus_ops cyttsp4_i2c_bus_ops = {
258c2ecf20Sopenharmony_ci	.bustype	= BUS_I2C,
268c2ecf20Sopenharmony_ci	.write		= cyttsp_i2c_write_block_data,
278c2ecf20Sopenharmony_ci	.read           = cyttsp_i2c_read_block_data,
288c2ecf20Sopenharmony_ci};
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic int cyttsp4_i2c_probe(struct i2c_client *client,
318c2ecf20Sopenharmony_ci				      const struct i2c_device_id *id)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	struct cyttsp4 *ts;
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
368c2ecf20Sopenharmony_ci		dev_err(&client->dev, "I2C functionality not Supported\n");
378c2ecf20Sopenharmony_ci		return -EIO;
388c2ecf20Sopenharmony_ci	}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	ts = cyttsp4_probe(&cyttsp4_i2c_bus_ops, &client->dev, client->irq,
418c2ecf20Sopenharmony_ci			  CYTTSP4_I2C_DATA_SIZE);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	return PTR_ERR_OR_ZERO(ts);
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic int cyttsp4_i2c_remove(struct i2c_client *client)
478c2ecf20Sopenharmony_ci{
488c2ecf20Sopenharmony_ci	struct cyttsp4 *ts = i2c_get_clientdata(client);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	cyttsp4_remove(ts);
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	return 0;
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistatic const struct i2c_device_id cyttsp4_i2c_id[] = {
568c2ecf20Sopenharmony_ci	{ CYTTSP4_I2C_NAME, 0 },
578c2ecf20Sopenharmony_ci	{ }
588c2ecf20Sopenharmony_ci};
598c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, cyttsp4_i2c_id);
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistatic struct i2c_driver cyttsp4_i2c_driver = {
628c2ecf20Sopenharmony_ci	.driver = {
638c2ecf20Sopenharmony_ci		.name	= CYTTSP4_I2C_NAME,
648c2ecf20Sopenharmony_ci		.pm	= &cyttsp4_pm_ops,
658c2ecf20Sopenharmony_ci	},
668c2ecf20Sopenharmony_ci	.probe		= cyttsp4_i2c_probe,
678c2ecf20Sopenharmony_ci	.remove		= cyttsp4_i2c_remove,
688c2ecf20Sopenharmony_ci	.id_table	= cyttsp4_i2c_id,
698c2ecf20Sopenharmony_ci};
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cimodule_i2c_driver(cyttsp4_i2c_driver);
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
748c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Cypress TrueTouch(R) Standard Product (TTSP) I2C driver");
758c2ecf20Sopenharmony_ciMODULE_AUTHOR("Cypress");
76